Fixup std lib includes for full build from scratch with just basic gcc

This commit is contained in:
K. Lange 2018-03-16 22:40:23 +09:00 committed by Kevin Lange
parent 3f4293d357
commit 627ebc3195
50 changed files with 979 additions and 28 deletions

3
.gitignore vendored
View File

@ -7,3 +7,6 @@ cdrom/kernel
cdrom/mod/*
cdrom/ramdisk.img
cdrom/boot/boot.sys
util/tarballs
util/build
util/local

View File

@ -8,8 +8,8 @@ KNM = $(KERNEL_TARGET)-nm
CC=i686-pc-toaru-gcc
AR=i686-pc-toaru-ar
CFLAGS=-nodefaultlibs -O3 -m32 -Wa,--32 -g -std=c99 -I. -Iapps -isystem include -Lbase/lib
LIBS=-lnihc -lgcc
CFLAGS= -O3 -m32 -Wa,--32 -g -std=c99 -I. -Iapps
LIBS=
LIBC_OBJS=$(patsubst %.c,%.o,$(wildcard libc/*.c))
@ -81,18 +81,23 @@ dirs: base/dev base/tmp base/proc base/bin base/lib cdrom/boot
# C Library
libc/%.o: libc/%.c
$(CC) -fPIC -c -m32 -Wa,--32 -O3 -isystem include -o $@ $<
crts: base/lib/crt0.o base/lib/crti.o base/lib/crtn.o | dirs
base/lib/libnihc.a: ${LIBC_OBJS} | dirs
base/lib/crt%.o: libc/crt%.s
yasm -f elf -o $@ $<
libc/%.o: libc/%.c
$(CC) -fPIC -c -m32 -Wa,--32 -O3 -o $@ $<
base/lib/libc.a: ${LIBC_OBJS} | dirs crts
$(AR) cr $@ $^
base/lib/libnihc.so: ${LIBC_OBJS} | dirs
$(CC) -o $@ $(CFLAGS) -shared -fPIC $^
base/lib/libc.so: ${LIBC_OBJS} | dirs crts
$(CC) -nodefaultlibs -o $@ $(CFLAGS) -shared -fPIC $^ -lgcc
# Userspace Linker/Loader
base/lib/ld.so: linker/linker.c base/lib/libnihc.a | dirs
base/lib/ld.so: linker/linker.c base/lib/libc.a | dirs
$(CC) -static -Wl,-static $(CFLAGS) -o $@ -Os -T linker/link.ld $< $(LIBS)
# Shared Libraries
@ -143,54 +148,54 @@ base/lib/libtoaru-decor-fancy.so: decors/decor-fancy.c lib/decorations.h base/li
# Init
base/bin/init: apps/init.c base/lib/libnihc.a | dirs
base/bin/init: apps/init.c base/lib/libc.a | dirs
$(CC) -static -Wl,-static $(CFLAGS) -o $@ $< $(LIBS)
# Userspace
base/bin/sh: apps/sh.c base/lib/libnihc.so base/lib/libtoaru_list.so base/lib/libtoaru_rline.so
base/bin/sh: apps/sh.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_rline.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_rline -ltoaru_list -ltoaru_kbd $(LIBS)
base/bin/migrate: apps/migrate.c base/lib/libnihc.so base/lib/libtoaru_list.so base/lib/libtoaru_hashmap.so
base/bin/migrate: apps/migrate.c base/lib/libc.so base/lib/libtoaru_list.so base/lib/libtoaru_hashmap.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/sysinfo: apps/sysinfo.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_termemu.so
base/bin/sysinfo: apps/sysinfo.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_termemu.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_graphics -ltoaru_termemu $(LIBS)
base/bin/terminal: apps/terminal.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_decorations.so base/lib/libtoaru_dlfcn.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so base/lib/libtoaru_pex.so base/lib/libtoaru_hashmap.so
base/bin/terminal: apps/terminal.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_decorations.so base/lib/libtoaru_dlfcn.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so base/lib/libtoaru_pex.so base/lib/libtoaru_hashmap.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_decorations -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_hashmap -ltoaru_dlfcn -ltoaru_kbd -ltoaru_list $(LIBS)
base/bin/terminal-vga: apps/terminal-vga.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so
base/bin/terminal-vga: apps/terminal-vga.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_kbd.so base/lib/libtoaru_termemu.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_termemu -ltoaru_graphics -ltoaru_kbd $(LIBS)
base/bin/background: apps/background.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so base/lib/libtoaru_drawstring.so
base/bin/background: apps/background.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so base/lib/libtoaru_drawstring.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_drawstring -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/drawlines: apps/drawlines.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
base/bin/drawlines: apps/drawlines.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/yutani-query: apps/yutani-query.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
base/bin/yutani-query: apps/yutani-query.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/yutani-test: apps/yutani-test.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
base/bin/yutani-test: apps/yutani-test.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_yutani.so base/lib/libtoaru_pthread.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_graphics -ltoaru_pex -ltoaru_pthread -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/compositor: apps/compositor.c base/lib/libnihc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_pthread.so base/lib/libtoaru_pex.so base/lib/libtoaru_yutani.so base/lib/libtoaru_hashmap.so
base/bin/compositor: apps/compositor.c base/lib/libc.so base/lib/libtoaru_graphics.so base/lib/libtoaru_list.so base/lib/libtoaru_kbd.so base/lib/libtoaru_pthread.so base/lib/libtoaru_pex.so base/lib/libtoaru_yutani.so base/lib/libtoaru_hashmap.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_yutani -ltoaru_pthread -ltoaru_pex -ltoaru_graphics -ltoaru_kbd -ltoaru_hashmap -ltoaru_list $(LIBS)
base/bin/ls: apps/ls.c base/lib/libnihc.so base/lib/libtoaru_list.so
base/bin/ls: apps/ls.c base/lib/libc.so base/lib/libtoaru_list.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
base/bin/nyancat: apps/nyancat/nyancat.c base/lib/libnihc.so
base/bin/nyancat: apps/nyancat/nyancat.c base/lib/libc.so
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
base/bin/ps: apps/ps.c base/lib/libnihc.so base/lib/libtoaru_list.so
base/bin/ps: apps/ps.c base/lib/libc.so base/lib/libtoaru_list.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_list $(LIBS)
base/bin/pstree: apps/pstree.c base/lib/libnihc.so base/lib/libtoaru_tree.so base/lib/libtoaru_list.so
base/bin/pstree: apps/pstree.c base/lib/libc.so base/lib/libtoaru_tree.so base/lib/libtoaru_list.so
$(CC) $(CFLAGS) -o $@ $< -ltoaru_tree -ltoaru_list $(LIBS)
base/bin/%: apps/%.c base/lib/libnihc.so | dirs
base/bin/%: apps/%.c base/lib/libc.so | dirs
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
# Ramdisk
@ -217,7 +222,7 @@ boot/boot.o: boot/boot.s
.PHONY: clean
clean:
rm -f base/lib/*.so
rm -f base/lib/libnihc.a
rm -f base/lib/libc.a
rm -f ${APPS_X}
rm -f libc/*.o
rm -f image.iso

View File

@ -14,6 +14,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#define CHUNK_SIZE 4096

View File

@ -0,0 +1,8 @@
#pragma once
#ifdef __GNUC__
#define alloca(size) __builtin_alloca(size)
#else
#error alloca requested but this isn't gcc
#endif

View File

@ -0,0 +1,18 @@
#pragma once
#include <stdint.h>
typedef struct dirent {
uint32_t d_ino;
char d_name[256];
} dirent;
typedef struct DIR {
int fd;
int cur_entry;
} DIR;
DIR * opendir (const char * dirname);
int closedir (DIR * dir);
struct dirent * readdir (DIR * dirp);

2
base/usr/include/ctype.h Normal file
View File

@ -0,0 +1,2 @@
#pragma once

View File

@ -0,0 +1,3 @@
#pragma once
#include <bits/dirent.h>

13
base/usr/include/fcntl.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#define O_RDONLY 0x0000
#define O_WRONLY 0x0001
#define O_RDWR 0x0002
#define O_APPEND 0x0008
#define O_CREAT 0x0200
#define O_TRUNC 0x0400
#define O_EXCL 0x0800
#define O_NOFOLLOW 0x1000
#define O_PATH 0x2000
extern int open (const char *, int, ...);

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,9 @@
#pragma once
/* i386 */
#define _JBLEN 9
typedef int jmp_buf[_JBLEN];
extern void longjmp(jmp_buf j, int r);
extern int setjmp(jmp_buf j);

493
base/usr/include/stdint.h Normal file
View File

@ -0,0 +1,493 @@
/*
* Copyright (c) 2004, 2005 by
* Ralf Corsepius, Ulm/Germany. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
#ifndef _STDINT_H
#define _STDINT_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__GNUC__) && \
( (__GNUC__ >= 4) || \
( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
/* gcc > 3.2 implicitly defines the values we are interested */
#define __STDINT_EXP(x) __##x##__
#else
#define __STDINT_EXP(x) x
#include <limits.h>
#endif
/* Check if "long long" is 64bit wide */
/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */
#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
|| ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
#define __have_longlong64 1
#endif
/* Check if "long" is 64bit or 32bit wide */
#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
#define __have_long64 1
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
#define __have_long32 1
#endif
#if __STDINT_EXP(SCHAR_MAX) == 0x7f
typedef signed char int8_t ;
typedef unsigned char uint8_t ;
#define __int8_t_defined 1
#endif
#if __int8_t_defined
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
#define __int_least8_t_defined 1
#endif
#if __STDINT_EXP(SHRT_MAX) == 0x7fff
typedef signed short int16_t;
typedef unsigned short uint16_t;
#define __int16_t_defined 1
#elif __STDINT_EXP(INT_MAX) == 0x7fff
typedef signed int int16_t;
typedef unsigned int uint16_t;
#define __int16_t_defined 1
#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff
typedef signed char int16_t;
typedef unsigned char uint16_t;
#define __int16_t_defined 1
#endif
#if __int16_t_defined
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
#define __int_least16_t_defined 1
#if !__int_least8_t_defined
typedef int16_t int_least8_t;
typedef uint16_t uint_least8_t;
#define __int_least8_t_defined 1
#endif
#endif
#if __have_long32
typedef signed long int32_t;
typedef unsigned long uint32_t;
#define __int32_t_defined 1
#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL
typedef signed int int32_t;
typedef unsigned int uint32_t;
#define __int32_t_defined 1
#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL
typedef signed short int32_t;
typedef unsigned short uint32_t;
#define __int32_t_defined 1
#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL
typedef signed char int32_t;
typedef unsigned char uint32_t;
#define __int32_t_defined 1
#endif
#if __int32_t_defined
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
#define __int_least32_t_defined 1
#if !__int_least8_t_defined
typedef int32_t int_least8_t;
typedef uint32_t uint_least8_t;
#define __int_least8_t_defined 1
#endif
#if !__int_least16_t_defined
typedef int32_t int_least16_t;
typedef uint32_t uint_least16_t;
#define __int_least16_t_defined 1
#endif
#endif
#if __have_long64
typedef signed long int64_t;
typedef unsigned long uint64_t;
#define __int64_t_defined 1
#elif __have_longlong64
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#define __int64_t_defined 1
#elif __STDINT_EXP(INT_MAX) > 0x7fffffff
typedef signed int int64_t;
typedef unsigned int uint64_t;
#define __int64_t_defined 1
#endif
#if __int64_t_defined
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
#define __int_least64_t_defined 1
#if !__int_least8_t_defined
typedef int64_t int_least8_t;
typedef uint64_t uint_least8_t;
#define __int_least8_t_defined 1
#endif
#if !__int_least16_t_defined
typedef int64_t int_least16_t;
typedef uint64_t uint_least16_t;
#define __int_least16_t_defined 1
#endif
#if !__int_least32_t_defined
typedef int64_t int_least32_t;
typedef uint64_t uint_least32_t;
#define __int_least32_t_defined 1
#endif
#endif
/*
* Fastest minimum-width integer types
*
* Assume int to be the fastest type for all types with a width
* less than __INT_MAX__ rsp. INT_MAX
*/
#if __STDINT_EXP(INT_MAX) >= 0x7f
typedef signed int int_fast8_t;
typedef unsigned int uint_fast8_t;
#define __int_fast8_t_defined 1
#endif
#if __STDINT_EXP(INT_MAX) >= 0x7fff
typedef signed int int_fast16_t;
typedef unsigned int uint_fast16_t;
#define __int_fast16_t_defined 1
#endif
#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
typedef signed int int_fast32_t;
typedef unsigned int uint_fast32_t;
#define __int_fast32_t_defined 1
#endif
#if __STDINT_EXP(INT_MAX) > 0x7fffffff
typedef signed int int_fast64_t;
typedef unsigned int uint_fast64_t;
#define __int_fast64_t_defined 1
#endif
/*
* Fall back to [u]int_least<N>_t for [u]int_fast<N>_t types
* not having been defined, yet.
* Leave undefined, if [u]int_least<N>_t should not be available.
*/
#if !__int_fast8_t_defined
#if __int_least8_t_defined
typedef int_least8_t int_fast8_t;
typedef uint_least8_t uint_fast8_t;
#define __int_fast8_t_defined 1
#endif
#endif
#if !__int_fast16_t_defined
#if __int_least16_t_defined
typedef int_least16_t int_fast16_t;
typedef uint_least16_t uint_fast16_t;
#define __int_fast16_t_defined 1
#endif
#endif
#if !__int_fast32_t_defined
#if __int_least32_t_defined
typedef int_least32_t int_fast32_t;
typedef uint_least32_t uint_fast32_t;
#define __int_fast32_t_defined 1
#endif
#endif
#if !__int_fast64_t_defined
#if __int_least64_t_defined
typedef int_least64_t int_fast64_t;
typedef uint_least64_t uint_fast64_t;
#define __int_fast64_t_defined 1
#endif
#endif
/* Greatest-width integer types */
/* Modern GCCs provide __INTMAX_TYPE__ */
#if defined(__INTMAX_TYPE__)
typedef __INTMAX_TYPE__ intmax_t;
#elif __have_longlong64
typedef signed long long intmax_t;
#else
typedef signed long intmax_t;
#endif
/* Modern GCCs provide __UINTMAX_TYPE__ */
#if defined(__UINTMAX_TYPE__)
typedef __UINTMAX_TYPE__ uintmax_t;
#elif __have_longlong64
typedef unsigned long long uintmax_t;
#else
typedef unsigned long uintmax_t;
#endif
/*
* GCC doesn't provide an appropriate macro for [u]intptr_t
* For now, use __PTRDIFF_TYPE__
*/
#if defined(__PTRDIFF_TYPE__)
typedef signed __PTRDIFF_TYPE__ intptr_t;
typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
#define INTPTR_MAX PTRDIFF_MAX
#define INTPTR_MIN PTRDIFF_MIN
#ifdef __UINTPTR_MAX__
#define UINTPTR_MAX __UINTPTR_MAX__
#else
#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
#endif
#else
/*
* Fallback to hardcoded values,
* should be valid on cpu's with 32bit int/32bit void*
*/
typedef signed long intptr_t;
typedef unsigned long uintptr_t;
#define INTPTR_MAX __STDINT_EXP(LONG_MAX)
#define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
#define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
#endif
/* Limits of Specified-Width Integer Types */
#if __int8_t_defined
#define INT8_MIN -128
#define INT8_MAX 127
#define UINT8_MAX 255
#endif
#if __int_least8_t_defined
#define INT_LEAST8_MIN -128
#define INT_LEAST8_MAX 127
#define UINT_LEAST8_MAX 255
#else
#error required type int_least8_t missing
#endif
#if __int16_t_defined
#define INT16_MIN -32768
#define INT16_MAX 32767
#define UINT16_MAX 65535
#endif
#if __int_least16_t_defined
#define INT_LEAST16_MIN -32768
#define INT_LEAST16_MAX 32767
#define UINT_LEAST16_MAX 65535
#else
#error required type int_least16_t missing
#endif
#if __int32_t_defined
#if __have_long32
#define INT32_MIN (-2147483647L-1)
#define INT32_MAX 2147483647L
#define UINT32_MAX 4294967295UL
#else
#define INT32_MIN (-2147483647-1)
#define INT32_MAX 2147483647
#define UINT32_MAX 4294967295U
#endif
#endif
#if __int_least32_t_defined
#if __have_long32
#define INT_LEAST32_MIN (-2147483647L-1)
#define INT_LEAST32_MAX 2147483647L
#define UINT_LEAST32_MAX 4294967295UL
#else
#define INT_LEAST32_MIN (-2147483647-1)
#define INT_LEAST32_MAX 2147483647
#define UINT_LEAST32_MAX 4294967295U
#endif
#else
#error required type int_least32_t missing
#endif
#if __int64_t_defined
#if __have_long64
#define INT64_MIN (-9223372036854775807L-1L)
#define INT64_MAX 9223372036854775807L
#define UINT64_MAX 18446744073709551615U
#elif __have_longlong64
#define INT64_MIN (-9223372036854775807LL-1LL)
#define INT64_MAX 9223372036854775807LL
#define UINT64_MAX 18446744073709551615ULL
#endif
#endif
#if __int_least64_t_defined
#if __have_long64
#define INT_LEAST64_MIN (-9223372036854775807L-1L)
#define INT_LEAST64_MAX 9223372036854775807L
#define UINT_LEAST64_MAX 18446744073709551615U
#elif __have_longlong64
#define INT_LEAST64_MIN (-9223372036854775807LL-1LL)
#define INT_LEAST64_MAX 9223372036854775807LL
#define UINT_LEAST64_MAX 18446744073709551615ULL
#endif
#endif
#if __int_fast8_t_defined
#if __STDINT_EXP(INT_MAX) >= 0x7f
#define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1)
#define INT_FAST8_MAX __STDINT_EXP(INT_MAX)
#define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
#else
#define INT_FAST8_MIN INT_LEAST8_MIN
#define INT_FAST8_MAX INT_LEAST8_MAX
#define UINT_FAST8_MAX UINT_LEAST8_MAX
#endif
#endif
#if __int_fast16_t_defined
#if __STDINT_EXP(INT_MAX) >= 0x7fff
#define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1)
#define INT_FAST16_MAX __STDINT_EXP(INT_MAX)
#define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
#else
#define INT_FAST16_MIN INT_LEAST16_MIN
#define INT_FAST16_MAX INT_LEAST16_MAX
#define UINT_FAST16_MAX UINT_LEAST16_MAX
#endif
#endif
#if __int_fast32_t_defined
#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
#define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1)
#define INT_FAST32_MAX __STDINT_EXP(INT_MAX)
#define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
#else
#define INT_FAST32_MIN INT_LEAST32_MIN
#define INT_FAST32_MAX INT_LEAST32_MAX
#define UINT_FAST32_MAX UINT_LEAST32_MAX
#endif
#endif
#if __int_fast64_t_defined
#if __STDINT_EXP(INT_MAX) > 0x7fffffff
#define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1)
#define INT_FAST64_MAX __STDINT_EXP(INT_MAX)
#define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U)
#else
#define INT_FAST64_MIN INT_LEAST64_MIN
#define INT_FAST64_MAX INT_LEAST64_MAX
#define UINT_FAST64_MAX UINT_LEAST64_MAX
#endif
#endif
#ifdef __INTMAX_MAX__
#define INTMAX_MAX __INTMAX_MAX__
#define INTMAX_MIN (-INTMAX_MAX - 1)
#elif defined(__INTMAX_TYPE__)
/* All relevant GCC versions prefer long to long long for intmax_t. */
#define INTMAX_MAX INT64_MAX
#define INTMAX_MIN INT64_MIN
#endif
#ifdef __UINTMAX_MAX__
#define UINTMAX_MAX __UINTMAX_MAX__
#elif defined(__UINTMAX_TYPE__)
/* All relevant GCC versions prefer long to long long for intmax_t. */
#define UINTMAX_MAX UINT64_MAX
#endif
/* This must match size_t in stddef.h, currently long unsigned int */
#ifdef __SIZE_MAX__
#define SIZE_MAX __SIZE_MAX__
#else
#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
#endif
/* This must match sig_atomic_t in <signal.h> (currently int) */
#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX)
/* This must match ptrdiff_t in <stddef.h> (currently long int) */
#ifdef __PTRDIFF_MAX__
#define PTRDIFF_MAX __PTRDIFF_MAX__
#else
#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)
#endif
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
#ifdef __WCHAR_MAX__
#define WCHAR_MAX __WCHAR_MAX__
#endif
#ifdef __WCHAR_MIN__
#define WCHAR_MIN __WCHAR_MIN__
#endif
/* wint_t is unsigned int on almost all GCC targets. */
#ifdef __WINT_MAX__
#define WINT_MAX __WINT_MAX__
#else
#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
#endif
#ifdef __WINT_MIN__
#define WINT_MIN __WINT_MIN__
#else
#define WINT_MIN 0U
#endif
/** Macros for minimum-width integer constant expressions */
#define INT8_C(x) x
#if __STDINT_EXP(INT_MAX) > 0x7f
#define UINT8_C(x) x
#else
#define UINT8_C(x) x##U
#endif
#define INT16_C(x) x
#if __STDINT_EXP(INT_MAX) > 0x7fff
#define UINT16_C(x) x
#else
#define UINT16_C(x) x##U
#endif
#if __have_long32
#define INT32_C(x) x##L
#define UINT32_C(x) x##UL
#else
#define INT32_C(x) x
#define UINT32_C(x) x##U
#endif
#if __int64_t_defined
#if __have_long64
#define INT64_C(x) x##L
#define UINT64_C(x) x##UL
#else
#define INT64_C(x) x##LL
#define UINT64_C(x) x##ULL
#endif
#endif
/** Macros for greatest-width integer constant expression */
#if __have_long64
#define INTMAX_C(x) x##L
#define UINTMAX_C(x) x##UL
#else
#define INTMAX_C(x) x##LL
#define UINTMAX_C(x) x##ULL
#endif
#ifdef __cplusplus
}
#endif
#endif /* _STDINT_H */

19
base/usr/include/stdlib.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <stddef.h>
extern void exit(int status);
extern char * getenv(const char *name);
extern void *malloc(size_t size);
extern void free(void *ptr);
extern void *calloc(size_t nmemb, size_t size);
extern void *realloc(void *ptr, size_t size);
extern void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void*,const void*));
extern int system(const char * command);
extern int abs(int j);
#define NULL 0

View File

@ -0,0 +1,9 @@
#pragma once
#include <sys/types.h>
#define WNOHANG 1
#define WUNTRACED 2
extern pid_t wait(int*);
extern pid_t waitpid(pid_t, int *, int);

51
base/usr/include/unistd.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#include <stddef.h>
#include <sys/types.h>
extern char **environ;
extern pid_t getpid(void);
extern int close(int fd);
extern pid_t fork(void);
extern int execl(const char *path, const char *arg, ...);
extern int execlp(const char *file, const char *arg, ...);
extern int execle(const char *path, const char *arg, ...);
extern int execv(const char *path, char *const argv[]);
extern int execvp(const char *file, char *const argv[]);
extern int execvpe(const char *file, char *const argv[], char *const envp[]);
extern void _exit(int status);
extern uid_t getuid(void);
extern uid_t geteuid(void);
extern char * getcwd(char *buf, size_t size);
extern int pipe(int pipefd[2]);
extern int dup(int oldfd);
extern int dup2(int oldfd, int newfd);
extern pid_t tcgetpgrp(int fd);
extern int tcsetpgrp(int fd, pid_t pgrp);
extern ssize_t write(int fd, const void * buf, size_t count);
extern ssize_t read(int fd, void * buf, size_t count);
extern ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);
extern int chdir(const char *path);
extern int fchdir(int fd);
extern int isatty(int fd);
extern int usleep(useconds_t usec);
extern off_t lseek(int fd, off_t offset, int whence);
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

5
base/usr/include/wchar.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <stddef.h>
extern int wcwidth(wchar_t c);

1
include Symbolic link
View File

@ -0,0 +1 @@
base/usr/include

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdint.h>
#include "../../../include/stdint.h"
#define SND_MAX_KNOBS 256
#define SND_KNOB_NAME_SIZE 256

View File

@ -6,7 +6,7 @@
#define NULL ((void *)0UL)
#include <stdint.h>
#include "../../include/stdint.h"
typedef unsigned long size_t;
#define CHAR_BIT 8

View File

@ -74,8 +74,13 @@ PORTABILITY
* SUCH DAMAGE.
*/
#include <_ansi.h>
//#include <_ansi.h>
#include <stdlib.h>
#include <stddef.h>
#define _PARAMS(paramlist) paramlist
#define _DEFUN(name, arglist, args) name arglist args;
#define _AND ;
#ifndef __GNUC__
#define inline

15
libc/crt0.s Normal file
View File

@ -0,0 +1,15 @@
; ToAruOS User CRT0
BITS 32
global _start
_start: ; Global entry point
pop eax ; Our stack is slightly off
extern pre_main ;
extern main
push main
call pre_main ; call C main function
; vim:syntax=nasm
; vim:noexpandtab
; vim:tabstop=4
; vim:shiftwidth=4

19
libc/crti.s Normal file
View File

@ -0,0 +1,19 @@
; ToAruOS User CRT0
BITS 32
section .init
global _init
_init:
push ebp
; .init goes here
section .fini
global _fini
_fini:
push ebp
; .fini goes here
; vim:syntax=nasm
; vim:noexpandtab
; vim:tabstop=4
; vim:shiftwidth=4

17
libc/crtn.s Normal file
View File

@ -0,0 +1,17 @@
; ToAruOS User CRT0
BITS 32
section .init
; .init goes here
pop ebp
ret
section .fini
; .fini goes here
pop ebp
ret
; vim:syntax=nasm
; vim:noexpandtab
; vim:tabstop=4
; vim:shiftwidth=4

4
util/activate.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH="$DIR/local/bin:$PATH"

59
util/build-gcc.sh Normal file
View File

@ -0,0 +1,59 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TARGET=i686-pc-toaru
PREFIX="$DIR/local"
TOARU_SYSROOT="$DIR/../base"
cd "$DIR"
mkdir -p tarballs
pushd tarballs
if [ ! -e "binutils-2.27.tar.gz" ]; then
wget "http://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz"
fi
if [ ! -e "gcc-6.4.0.tar.gz" ]; then
wget "http://www.netgull.com/gcc/releases/gcc-6.4.0/gcc-6.4.0.tar.gz"
fi
if [ ! -d "binutils-2.27" ]; then
tar -xf "binutils-2.27.tar.gz"
pushd "binutils-2.27"
patch -p1 < $DIR/patches/binutils.patch > /dev/null
popd
fi
if [ ! -d "gcc-6.4.0" ]; then
tar -xf "gcc-6.4.0.tar.gz"
pushd "gcc-6.4.0"
patch -p1 < $DIR/patches/gcc.patch > /dev/null
popd
fi
popd
mkdir -p local
mkdir -p build
mkdir -p build/binutils
mkdir -p build/gcc
pushd build
unset PKG_CONFIG_LIBDIR # Just in case
#pushd binutils
# $DIR/tarballs/binutils-2.27/configure --target=$TARGET --prefix=$PREFIX --with-sysroot=$TOARU_SYSROOT --disable-werror || exit 1
# make -j4
# make install
#popd
pushd gcc
$DIR/tarballs/gcc-6.4.0/configure --target=i686-pc-toaru --prefix=$PREFIX --with-sysroot=$TOARU_SYSROOT --disable-nls --enable-languages=c --disable-libssp --with-newlib || baiol
make all-gcc all-target-libgcc
make install-gcc install-target-libgcc
popd
popd

View File

@ -0,0 +1,64 @@
diff --git a/bfd/config.bfd b/bfd/config.bfd
index b998830..3d6bdc4 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -661,6 +661,10 @@ case "${targ}" in
targ_defvec=i386_elf32_vec
targ_selvecs="iamcu_elf32_vec i386_nlm32_vec i386_coff_vec i386_aout_vec"
;;
+ i[3-7]86-*-toaru*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs=
+ ;;
i[3-7]86-*-linux*aout*)
targ_defvec=i386_aout_linux_vec
targ_selvecs="i386_elf32_vec iamcu_elf32_vec"
diff --git a/config.sub b/config.sub
index 2377e13..19fa153 100755
--- a/config.sub
+++ b/config.sub
@@ -1375,6 +1375,7 @@ case $os in
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+ | -toaru* \
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
diff --git a/gas/configure.tgt b/gas/configure.tgt
index e2df659..72a6bbf 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -283,6 +283,7 @@ case ${generic_target} in
i386-*-chaos) fmt=elf ;;
i386-*-rdos*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
+ i386-*-toaru*) fmt=elf ;;
i860-*-*) fmt=elf endian=little ;;
diff --git a/ld/configure.tgt b/ld/configure.tgt
index a3db909..13c4387 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -269,6 +269,7 @@ x86_64-*-linux-*) targ_emul=elf_x86_64
targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om"
tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/'`
tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` ;;
+i[3-7]86-*-toaru*) targ_emul=elf_i386 ;;
i[3-7]86-*-sysv[45]*) targ_emul=elf_i386
targ_extra_emuls=elf_iamcu ;;
i[3-7]86-*-solaris2*) targ_emul=elf_i386_sol2
diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
index b08e661..7bd4bd5 100644
--- a/ld/emulparams/elf_i386.sh
+++ b/ld/emulparams/elf_i386.sh
@@ -33,4 +33,8 @@ case "$target" in
;;
esac
;;
+ i[3-7]86*-toaru*)
+ TEXT_START_ADDR=0x40000000
+ ;;
esac
+

127
util/patches/gcc.patch Normal file
View File

@ -0,0 +1,127 @@
diff --git a/config.sub b/config.sub
index 41146e1..8438e24 100755
--- a/config.sub
+++ b/config.sub
@@ -1375,6 +1375,7 @@ case $os in
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+ | -toaru* \
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
index 0d96c8c..1ae6bdc 100755
--- a/fixincludes/mkfixinc.sh
+++ b/fixincludes/mkfixinc.sh
@@ -13,6 +13,7 @@ target=fixinc.sh
case $machine in
i?86-*-cygwin* | \
i?86-*-mingw32* | \
+ i?86-*-toaru* | \
x86_64-*-mingw32* | \
i?86-*-interix* | \
powerpc-*-eabisim* | \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 1d5b23f..603a22b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -820,6 +820,11 @@ case ${target} in
gnu_ld=yes
default_use_cxa_atexit=yes
;;
+*-*-toaru*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ ;;
*-*-rtems*)
case ${enable_threads} in
"" | yes | rtems) thread_file='rtems' ;;
@@ -1441,6 +1446,9 @@ x86_64-*-rdos*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/rdos.h i386/rdos64.h"
tmake_file="i386/t-i386elf t-svr4"
;;
+*-*-toaru*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h toaru.h"
+ ;;
i[34567]86-*-dragonfly*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h dragonfly.h dragonfly-stdint.h i386/dragonfly.h"
tmake_file="${tmake_file} i386/t-crtstuff"
diff --git a/gcc/config/toaru.h b/gcc/config/toaru.h
new file mode 100644
index 0000000..9157525
--- /dev/null
+++ b/gcc/config/toaru.h
@@ -0,0 +1,26 @@
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do { \
+ builtin_define_std ("toaru"); \
+ builtin_define_std ("unix"); \
+ builtin_assert ("system=toaru"); \
+ builtin_assert ("system=unix"); \
+ } while (0);
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!shared: %{!pg:crt0.o%s}} crti.o%s %{!shared:crtbegin.o%s}"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "%{!shared:crtend.o%s} crtn.o%s"
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!shared: %{!static: %{rdynamic:-export-dynamic} %{!dynamic-linker:-dynamic-linker /lib/ld.so}}}"
+
+#undef LIB_SPEC
+#define LIB_SPEC "%{pthread:-lpthread} -lc"
+
+#undef OBJECT_FORMAT_ELF
+#define OBJECT_FORMAT_ELF
+
+#undef NO_IMPLICIT_EXTERN_C
+#define NO_IMPLICIT_EXTERN_C 1
diff --git a/libgcc/config.host b/libgcc/config.host
index 124f2ce..c865054 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -656,6 +656,10 @@ i[34567]86-*-solaris2* | x86_64-*-solaris2.1[0-9]*)
;;
i[4567]86-wrs-vxworks|i[4567]86-wrs-vxworksae)
;;
+i[34567]86-*-toaru*)
+ extra_parts="$extra_parts crtbegin.o crtend.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
i[34567]86-*-cygwin*)
extra_parts="crtbegin.o crtbeginS.o crtend.o crtfastmath.o"
if test x$enable_vtable_verify = xyes; then
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index ece1256..97566e6 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -248,6 +248,12 @@ case "${host}" in
GLIBCXX_CHECK_MATH_SUPPORT
GLIBCXX_CHECK_STDLIB_SUPPORT
;;
+ *-toaru*)
+ GLIBCXX_CHECK_COMPILER_FEATURES
+ GLIBCXX_CHECK_LINKER_FEATURES
+ GLIBCXX_CHECK_MATH_SUPPORT
+ GLIBCXX_CHECK_STDLIB_SUPPORT
+ ;;
*-vxworks)
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 03e198a..e0eb9d6 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -38,7 +38,7 @@
#include <bits/c++config.h>
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
-# if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__)
+# if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__) && 0
namespace std
{
typedef __UINT_LEAST16_TYPE__ uint_least16_t;