commit fb7fe4047c21fd43a1c085a6314b7f8ee4ec5647
parent aaad65a71fff59ac5811a30ec1fedc19ff2ae119
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 7 Nov 2024 12:55:38 +0100
libc: Fix compilation of i386
Diffstat:
9 files changed, 336 insertions(+), 140 deletions(-)
diff --git a/include/bits/i386/arch/stdint.h b/include/bits/i386/arch/stdint.h
@@ -1,120 +0,0 @@
-#define INT8_C(c) c
-#define INT16_C(c) c
-#define INT32_C(c) c
-
-#define UINT8_C(c) c
-#define UINT16_C(c) c
-#define UINT32_C(c) c ## U
-
-#define INT8_MAX 0x7F
-#define INT8_MIN (-INT8_MAX-1)
-#define UINT8_MAX 0xFF
-
-#define INT16_MAX 0x7FFF
-#define INT16_MIN (-INT16_MAX-1)
-#define UINT16_MAX 0xFFFF
-
-#define INT32_MAX 0x7FFFFFFF
-#define INT32_MIN (-INT32_MAX-1)
-#define UINT32_MAX 0xFFFFFFFF
-
-#define INT64_MAX 0x7FFFFFFFFFFFFFFF
-#define INT64_MIN (-INT64_MAX-1)
-#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
-
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-#define INT_FAST8_MIN INT32_MIN
-#define INT_FAST8_MAX INT32_MAX
-#define UINT_FAST8_MAX UINT32_MAX
-
-#define INT_FAST16_MIN INT32_MIN
-#define INT_FAST16_MAX INT32_MAX
-#define UINT_FAST16_MAX UINT32_MAX
-
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-#define INTPTR_MIN INT32_MIN
-#define INTPTR_MAX INT32_MAX
-#define UINTPTR_MAX UINT32_MAX
-
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-#define PTRDIFF_MIN INT32_MIN
-#define PTRDIFF_MAX INT32_MAX
-
-#define SIG_ATOMIC_MIN INT32_MIN
-#define SIG_ATOMIC_MAX INT32_MAX
-
-#define SIZE_MAX UINT32_MAX
-
-#define INT8_C(x) x
-#define INT16_C(x) x
-#define INT32_C(x) x
-#define INT64_C(x) x ## LL
-
-#define UINT8_C(x) x
-#define UINT16_C(x) x
-#define UINT32_C(x) x ## U
-#define UINT64_C(x) x ## ULL
-
-#define INTMAX_C(x) x ## LL
-#define UINTMAX_C(x) x ## ULL
-
-typedef signed char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned uint32_t;
-typedef unsigned long long uint64_t;
-
-typedef signed char int_least8_t;
-typedef short int_least16_t;
-typedef int int_least32_t;
-typedef long long int_least64_t;
-
-typedef unsigned char uint_least8_t;
-typedef unsigned short uint_least16_t;
-typedef unsigned uint_least32_t;
-typedef unsigned long long uint_least64_t;
-
-typedef int int_fast8_t;
-typedef int int_fast16_t;
-typedef int int_fast32_t;
-typedef long long int_fast64_t;
-
-typedef unsigned uint_fast8_t;
-typedef unsigned uint_fast16_t;
-typedef unsigned uint_fast32_t;
-typedef unsigned long long uint_fast64_t;
-
-typedef int intptr_t;
-typedef unsigned uintptr_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
diff --git a/include/bits/linux/i386/arch/inttypes.h b/include/bits/linux/i386/arch/inttypes.h
@@ -0,0 +1,181 @@
+#define PRId8 "hhd"
+#define PRIi8 "hhi"
+#define PRIo8 "hho"
+#define PRIu8 "hhu"
+#define PRIx8 "hhx"
+#define PRIX8 "hhX"
+
+#define PRId16 "hd"
+#define PRIi16 "hi"
+#define PRIo16 "ho"
+#define PRIu16 "hu"
+#define PRIx16 "hx"
+#define PRIX16 "hX"
+
+#define PRId32 "d"
+#define PRIi32 "i"
+#define PRIo32 "o"
+#define PRIu32 "u"
+#define PRIx32 "x"
+#define PRIX32 "X"
+
+#define PRId64 "lld"
+#define PRIi64 "lli"
+#define PRIo64 "llo"
+#define PRIu64 "llu"
+#define PRIx64 "llx"
+#define PRIX64 "llX"
+
+#define PRIdLEAST8 "hhd"
+#define PRIiLEAST8 "hhi"
+#define PRIoLEAST8 "hho"
+#define PRIuLEAST8 "hhu"
+#define PRIxLEAST8 "hhx"
+#define PRIXLEAST8 "hhX"
+
+#define PRIdLEAST16 "hd"
+#define PRIiLEAST16 "hi"
+#define PRIoLEAST16 "ho"
+#define PRIuLEAST16 "hu"
+#define PRIxLEAST16 "hx"
+#define PRIXLEAST16 "hX"
+
+#define PRIdLEAST32 "d"
+#define PRIiLEAST32 "i"
+#define PRIoLEAST32 "o"
+#define PRIuLEAST32 "u"
+#define PRIxLEAST32 "x"
+#define PRIXLEAST32 "X"
+
+#define PRIdLEAST64 "lld"
+#define PRIiLEAST64 "lli"
+#define PRIoLEAST64 "llo"
+#define PRIuLEAST64 "llu"
+#define PRIxLEAST64 "llx"
+#define PRIXLEAST64 "llX"
+
+#define PRIdFAST8 "hhd"
+#define PRIiFAST8 "hhi"
+#define PRIoFAST8 "hho"
+#define PRIuFAST8 "hhu"
+#define PRIxFAST8 "hhx"
+#define PRIXFAST8 "hhX"
+
+#define PRIdFAST16 "d"
+#define PRIiFAST16 "i"
+#define PRIoFAST16 "o"
+#define PRIuFAST16 "u"
+#define PRIxFAST16 "x"
+#define PRIXFAST16 "X"
+
+#define PRIdFAST32 "d"
+#define PRIiFAST32 "i"
+#define PRIoFAST32 "o"
+#define PRIuFAST32 "u"
+#define PRIxFAST32 "x"
+#define PRIXFAST32 "X"
+
+#define PRIdFAST64 "lld"
+#define PRIiFAST64 "lli"
+#define PRIoFAST64 "llo"
+#define PRIuFAST64 "llu"
+#define PRIxFAST64 "llx"
+#define PRIXFAST64 "llX"
+
+#define PRIdPTR "ld"
+#define PRIiPTR "li"
+#define PRIoPTR "lo"
+#define PRIuPTR "lu"
+#define PRIxPTR "lx"
+#define PRIXPTR "lX"
+
+#define PRIdMAX "lld"
+#define PRIiMAX "lli"
+#define PRIoMAX "llo"
+#define PRIuMAX "llu"
+#define PRIxMAX "llx"
+#define PRIXMAX "llX"
+
+#define SCNd8 "hhd"
+#define SCNi8 "hhi"
+#define SCNo8 "hho"
+#define SCNu8 "hhu"
+#define SCNx8 "hhx"
+
+#define SCNd16 "hd"
+#define SCNi16 "hi"
+#define SCNo16 "ho"
+#define SCNu16 "hu"
+#define SCNx16 "hx"
+
+#define SCNd32 "d"
+#define SCNi32 "i"
+#define SCNo32 "o"
+#define SCNu32 "u"
+#define SCNx32 "x"
+
+#define SCNd64 "lld"
+#define SCNi64 "lli"
+#define SCNo64 "llo"
+#define SCNu64 "llu"
+#define SCNx64 "llx"
+
+#define SCNdLEAST8 "hhd"
+#define SCNiLEAST8 "hhi"
+#define SCNoLEAST8 "hho"
+#define SCNuLEAST8 "hhu"
+#define SCNxLEAST8 "hhx"
+
+#define SCNdLEAST16 "hd"
+#define SCNiLEAST16 "hi"
+#define SCNoLEAST16 "ho"
+#define SCNuLEAST16 "hu"
+#define SCNxLEAST16 "hx"
+
+#define SCNdLEAST32 "d"
+#define SCNiLEAST32 "i"
+#define SCNoLEAST32 "o"
+#define SCNuLEAST32 "u"
+#define SCNxLEAST32 "x"
+
+#define SCNdLEAST64 "lld"
+#define SCNiLEAST64 "lli"
+#define SCNoLEAST64 "llo"
+#define SCNuLEAST64 "llu"
+#define SCNxLEAST64 "llx"
+
+#define SCNdFAST8 "hhd"
+#define SCNiFAST8 "hhi"
+#define SCNoFAST8 "hho"
+#define SCNuFAST8 "hhu"
+#define SCNxFAST8 "hhx"
+
+#define SCNdFAST16 "d"
+#define SCNiFAST16 "i"
+#define SCNoFAST16 "o"
+#define SCNuFAST16 "u"
+#define SCNxFAST16 "x"
+
+#define SCNdFAST32 "d"
+#define SCNiFAST32 "i"
+#define SCNoFAST32 "o"
+#define SCNuFAST32 "u"
+#define SCNxFAST32 "x"
+
+#define SCNdFAST64 "lld"
+#define SCNiFAST64 "lli"
+#define SCNoFAST64 "llo"
+#define SCNuFAST64 "llu"
+#define SCNxFAST64 "llx"
+
+#define SCNdPTR "ld"
+#define SCNiPTR "li"
+#define SCNoPTR "lo"
+#define SCNuPTR "lu"
+#define SCNxPTR "lx"
+
+#define SCNdMAX "lld"
+#define SCNiMAX "lli"
+#define SCNoMAX "llo"
+#define SCNuMAX "llu"
+#define SCNxMAX "llx"
diff --git a/include/bits/linux/i386/arch/sigaction.h b/include/bits/linux/i386/arch/sigaction.h
@@ -0,0 +1,10 @@
+#define SA_RESTORER 0x04000000
+
+struct sigaction {
+ void (*sa_handler)(int);
+ unsigned long sa_flags;
+ void (*sa_restorer)(void);
+ unsigned sa_mask[2];
+};
+
+extern int __sigaction(int, struct sigaction *, struct sigaction *, size_t);
diff --git a/include/bits/linux/i386/arch/stdint.h b/include/bits/linux/i386/arch/stdint.h
@@ -0,0 +1,112 @@
+#define INT8_MAX 0x7F
+#define INT8_MIN (-INT8_MAX - 1)
+#define UINT8_MAX 0xFF
+
+#define INT16_MAX 0x7FFF
+#define INT16_MIN (-INT16_MAX - 1)
+#define UINT16_MAX 0xFFFF
+
+#define INT32_MAX 0x7FFFFFFF
+#define INT32_MIN (-INT32_MAX - 1)
+#define UINT32_MAX 0xFFFFFFFF
+
+#define INT64_MAX 0x7FFFFFFFFFFFFFFF
+#define INT64_MIN (-INT64_MAX - 1)
+#define UINT64_MAX 0xFFFFFFFFFFFFFFFF
+
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+
+#define INT_FAST16_MIN INT32_MIN
+#define INT_FAST16_MAX INT32_MAX
+#define UINT_FAST16_MAX UINT32_MAX
+
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+#define INTPTR_MIN INT32_MIN
+#define INTPTR_MAX INT32_MAX
+#define UINTPTR_MAX UINT32_MAX
+
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+#define PTRDIFF_MIN INT32_MIN
+#define PTRDIFF_MAX INT32_MAX
+
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+#define SIZE_MAX UINT32_MAX
+
+#define INT8_C(x) x
+#define INT16_C(x) x
+#define INT32_C(x) x
+#define INT64_C(x) x ## LL
+
+#define UINT8_C(x) x
+#define UINT16_C(x) x
+#define UINT32_C(x) x ## U
+#define UINT64_C(x) x ## ULL
+
+#define INTMAX_C(x) x ## LL
+#define UINTMAX_C(x) x ## ULL
+
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_least_t;
+typedef short int16_least_t;
+typedef int int32_least_t;
+typedef long long int64_least_t;
+
+typedef unsigned char uint8_least_t;
+typedef unsigned short uint16_least_t;
+typedef unsigned int uint32_least_t;
+typedef unsigned long long uint64_least_t;
+
+typedef signed char int8_fast_t;
+typedef int int16_fast_t;
+typedef int int32_fast_t;
+typedef long long int64_fast_t;
+
+typedef unsigned char uint8_fast_t;
+typedef unsigned int uint16_fast_t;
+typedef unsigned int uint32_fast_t;
+typedef unsigned long long uint64_fast_t;
+
+typedef long intptr_t;
+typedef unsigned long uintptr_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
diff --git a/include/bits/linux/i386/arch/time.h b/include/bits/linux/i386/arch/time.h
@@ -0,0 +1,5 @@
+#define _MAXYEAR 2038
+
+typedef long time_t;
+typedef long clock_t;
+typedef long __suseconds_t;
diff --git a/scripts/build/conf/i386-linux.mk b/scripts/build/conf/i386-linux.mk
@@ -0,0 +1,5 @@
+ARCH = i386
+ABI = sysv
+SYS = linux
+FORMAT = elf
+O = 8l
diff --git a/src/libc/arch/i386/linux/.gitignore b/src/libc/arch/i386/linux/.gitignore
@@ -1,5 +1,6 @@
_access.s
_close.s
+_execve.s
_exit.s
_fork.s
_getpid.s
@@ -10,5 +11,6 @@ _read.s
_rename.s
_sigaction.s
_sys_brk.s
+_sys_errlist.c
_wait4.s
_write.s
diff --git a/src/libc/arch/i386/linux/Makefile b/src/libc/arch/i386/linux/Makefile
@@ -30,10 +30,11 @@ OBJS =\
all: $(OBJS) $(CRT)
-crt.$O: ../crt-posix.s
+$(CRT): ../crt-posix.s
-$(GENSRC): syscall.lst
- ./gensys.sh $(@:.s=)
+$(GENOBJS): syscall.lst
+ ./gensys.sh $(@:.$O=)
+ $(AS) $(PROJ_ASFLAGS) -o $@ $(@:.$O=.s)
clean:
- rm -f $(GENSRC) _sys_errlist.c
+ rm -f $(GENOBJS:.$O=.s) _sys_errlist.c
diff --git a/src/libc/arch/i386/linux/gensys.sh b/src/libc/arch/i386/linux/gensys.sh
@@ -5,16 +5,16 @@ awk '! /^#/ && $2 == "'$1'" {
fname=$2".s"
noper=$3
- printf "\t.file\t"
- "\"fname\"\n"
- "\t.globl\t%s\n"
- "%s:\n"
- "\tpushl\t%%ebp\n"
- "\tpushl\t%%ebx\n"
- "\tpushl\t%%esi\n\n",
- "\tpushl\t%%edi\n"
- "\tmovl\t%%esp,%%ebp\n"
- syscall, syscall
+ printf("\t.file\t"\
+ "\"fname\"\n"\
+ "\t.globl\t%s\n"\
+ "%s:\n"\
+ "\tpushl\t%%ebp\n"\
+ "\tpushl\t%%ebx\n"\
+ "\tpushl\t%%esi\n\n"\
+ "\tpushl\t%%edi\n"\
+ "\tmovl\t%%esp,%%ebp\n",
+ syscall, syscall)
if (noper > 0)
printf "\tmovl\t20(%%ebp),%%ebx\n"
@@ -27,12 +27,12 @@ awk '! /^#/ && $2 == "'$1'" {
if (noper > 4)
printf "\tmovl\t28(%%ebp),%%edi\n"
- printf "\tmovl\t$%d,%%eax\n"
- "\tint\t$0x80\n"
- "\tpopl\t%%edi\n"
- "\tpopl\t%%esi\n"
- "\tpopl\t%%ebx\n"
- "\tpopl\t%%ebp\n"
+ printf "\tmovl\t$%d,%%eax\n"\
+ "\tint\t$0x80\n"\
+ "\tpopl\t%%edi\n"\
+ "\tpopl\t%%esi\n"\
+ "\tpopl\t%%ebx\n"\
+ "\tpopl\t%%ebp\n"\
"\tjmp\t_cerrno\n", $1
} ' syscall.lst > $1.s