From fe055ba344820ca39cc9de76227137564ab76dc6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 11 Aug 2018 19:04:01 +0200 Subject: [PATCH] mescc: Mes C Library: Add x86_64 libc+gnu support. * include/linux/x86/syscall.h: Move SYS_ defines from gnu.c. * include/linux/x86_64/syscall.h: Add SYS_ defines for gnu. * lib/linux/gnu.c: Update. * lib/linux/gnu.c (signal)[__x86_64__]: Implement using rt_sigaction. * lib/stdlib/abort.c: Support x86_64. --- build-aux/build-cc.sh | 4 ++-- include/linux/x86/syscall.h | 22 ++++++++++++++++++++++ include/linux/x86_64/syscall.h | 19 +++++++++++++++++++ lib/linux/gnu.c | 30 ++++++++++++------------------ lib/stdlib/abort.c | 4 ---- 5 files changed, 55 insertions(+), 24 deletions(-) diff --git a/build-aux/build-cc.sh b/build-aux/build-cc.sh index 3c4efd59..723d7dbe 100755 --- a/build-aux/build-cc.sh +++ b/build-aux/build-cc.sh @@ -53,11 +53,11 @@ ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64-mes-gcc/c # ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/linux/x86_64/crtn ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc -# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+gnu -# ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libg ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libgetopt ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+tcc ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libtcc1 +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libc+gnu +ARCHDIR=1 NOLINK=1 sh ${srcdest}build-aux/cc64-mes.sh lib/libg sh ${srcdest}build-aux/cc64-mes.sh scaffold/main sh ${srcdest}build-aux/cc64-mes.sh scaffold/hello diff --git a/include/linux/x86/syscall.h b/include/linux/x86/syscall.h index aa8bca28..1b5639a4 100644 --- a/include/linux/x86/syscall.h +++ b/include/linux/x86/syscall.h @@ -45,4 +45,26 @@ #define SYS_stat 0x6a #define SYS_getcwd 0xb7 +// libc+gnu +#define SYS_link 0x09 +#define SYS_getpid 0x14 +#define SYS_getuid 0x18 +#define SYS_kill 0x25 +#define SYS_rename 0x26 +#define SYS_mkdir 0x27 +#define SYS_dup 0x29 +#define SYS_pipe 0x2a +#define SYS_getgid 0x2f +#define SYS_signal 0x30 +#define SYS_sigaction 0x43 +#define SYS_rt_sigaction 0xae +#define SYS_signal 0x30 +#define SYS_fcntl 0x37 +#define SYS_dup2 0x3f +#define SYS_getrusage 0x4d +#define SYS_lstat 0x6b +#define SYS_setitimer 0x68 +#define SYS_fstat 0x6c +#define SYS_nanosleep 0xa2 + #endif // __MES_LINUX_X86_SYSCALL_H diff --git a/include/linux/x86_64/syscall.h b/include/linux/x86_64/syscall.h index c8846d73..c5b33c33 100644 --- a/include/linux/x86_64/syscall.h +++ b/include/linux/x86_64/syscall.h @@ -45,4 +45,23 @@ #define SYS_stat 0x04 #define SYS_getcwd 0x4f +// libc+gnu +#define SYS_link 0x56 +#define SYS_getpid 0x27 +#define SYS_getuid 0x66 +#define SYS_kill 0x3e +#define SYS_rename 0x52 +#define SYS_mkdir 0x53 +#define SYS_dup 0x20 +#define SYS_pipe 0x16 +#define SYS_getgid 0x68 +#define SYS_rt_sigaction 0x0d +#define SYS_fcntl 0x48 +#define SYS_dup2 0x21 +#define SYS_getrusage 0x62 +#define SYS_lstat 0x06 +#define SYS_setitimer 0x26 +#define SYS_fstat 0x05 +#define SYS_nanosleep 0x33 + #endif // __MES_LINUX_X86_64_SYSCALL_H diff --git a/lib/linux/gnu.c b/lib/linux/gnu.c index 582c18bc..e756b060 100644 --- a/lib/linux/gnu.c +++ b/lib/linux/gnu.c @@ -18,24 +18,6 @@ * along with GNU Mes. If not, see . */ -#define SYS_link 0x09 -#define SYS_getpid 0x14 -#define SYS_getuid 0x18 -#define SYS_kill 0x25 -#define SYS_rename 0x26 -#define SYS_mkdir 0x27 -#define SYS_dup 0x29 -#define SYS_pipe 0x2a -#define SYS_getgid 0x2f -#define SYS_signal 0x30 -#define SYS_fcntl 0x37 -#define SYS_dup2 0x3f -#define SYS_getrusage 0x4d -#define SYS_lstat 0x6b -#define SYS_setitimer 0x68 -#define SYS_fstat 0x6c -#define SYS_nanosleep 0xa2 - #include int @@ -86,6 +68,7 @@ getgid () return _sys_call (SYS_getgid); } +#if __i386__ #if __MESC__ void * signal (int signum, void * action) @@ -96,6 +79,17 @@ signal (int signum, sighandler_t action) { return _sys_call2 (SYS_signal, signum, action); } +#elif __x86_64__ +sighandler_t +signal (int signum, sighandler_t action) +{ + sighandler_t old; + _sys_call3 (SYS_rt_sigaction, signum, action, &old); + return old; +} +#else +#error arch not supported +#endif int fcntl (int filedes, int command, ...) diff --git a/lib/stdlib/abort.c b/lib/stdlib/abort.c index 6f6be919..bc93a329 100644 --- a/lib/stdlib/abort.c +++ b/lib/stdlib/abort.c @@ -21,9 +21,5 @@ void abort (void) { -#if __i386__ asm ("hlt"); -#else - asm ("break 0"); -#endif }