diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2014-04-09 16:00:01 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2014-04-09 16:00:01 -0700 |
commit | aed6821b52456a4c538c9097999adba451e49248 (patch) | |
tree | 7e551716a5a5114c86aa2e6854e9c5740ba21dbe | |
parent | fe3dff23a604af5c96060574bcdb4e723b977627 (diff) | |
download | klibc-aed6821b52456a4c538c9097999adba451e49248.tar.gz |
[klibc] Move architecture-specific initialization to arch/
Move out architecture-specific initialization code (currently only for
i386) into the arch/ directory and define a configuration variable
_KLIBC_HAS_ARCHINIT to indicate its presence.
For consistency, change __init_stdio() to __libc_init_stdio().
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r-- | usr/include/arch/i386/klibc/archconfig.h | 3 | ||||
-rw-r--r-- | usr/include/klibc/sysconfig.h | 9 | ||||
-rw-r--r-- | usr/klibc/arch/i386/Kbuild | 2 | ||||
-rw-r--r-- | usr/klibc/arch/i386/archinit.c | 18 | ||||
-rw-r--r-- | usr/klibc/libc_init.c | 21 | ||||
-rw-r--r-- | usr/klibc/stdio/fdopen.c | 2 |
6 files changed, 41 insertions, 14 deletions
diff --git a/usr/include/arch/i386/klibc/archconfig.h b/usr/include/arch/i386/klibc/archconfig.h index b409a213626431..d8db763e70052d 100644 --- a/usr/include/arch/i386/klibc/archconfig.h +++ b/usr/include/arch/i386/klibc/archconfig.h @@ -12,4 +12,7 @@ /* The i386 <asm/signal.h> is still not clean enough for this... */ #define _KLIBC_USE_RT_SIG 0 +/* We have __libc_arch_init() */ +#define _KLIBC_HAS_ARCHINIT 1 + #endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/klibc/sysconfig.h b/usr/include/klibc/sysconfig.h index 5fa9b60020954d..ab947c0bfc0077 100644 --- a/usr/include/klibc/sysconfig.h +++ b/usr/include/klibc/sysconfig.h @@ -216,4 +216,13 @@ # define _KLIBC_ARM_USE_BX 0 #endif +/* + * _KLIBC_HAS_ARCHINIT + * + * This architecture uses __libc_archinit() + */ +#ifndef _KLIBC_HAS_ARCHINIT +# define _KLIBC_HAS_ARCHINIT 0 +#endif + #endif /* _KLIBC_SYSCONFIG_H */ diff --git a/usr/klibc/arch/i386/Kbuild b/usr/klibc/arch/i386/Kbuild index edc7b3ccfd653c..16423742919c13 100644 --- a/usr/klibc/arch/i386/Kbuild +++ b/usr/klibc/arch/i386/Kbuild @@ -2,7 +2,7 @@ # klibc .o files for i386 # -klib-y := socketcall.o setjmp.o syscall.o varsyscall.o +klib-y := archinit.o socketcall.o setjmp.o syscall.o varsyscall.o klib-y += open.o openat.o vfork.o klib-y += libgcc/__ashldi3.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o klib-y += libgcc/__muldi3.o libgcc/__negdi2.o diff --git a/usr/klibc/arch/i386/archinit.c b/usr/klibc/arch/i386/archinit.c new file mode 100644 index 00000000000000..111d130d356b44 --- /dev/null +++ b/usr/klibc/arch/i386/archinit.c @@ -0,0 +1,18 @@ +/* + * arch/i386/archinit.c + * + * Architecture-specific libc initialization + */ + +#include <stdint.h> +#include <klibc/compiler.h> +#include <elf.h> +#include <sys/auxv.h> + +extern void (*__syscall_entry)(int, ...); + +void __libc_archinit(void) +{ + if (__auxval[AT_SYSINFO]) + __syscall_entry = (void (*)(int, ...)) __auxval[AT_SYSINFO]; +} diff --git a/usr/klibc/libc_init.c b/usr/klibc/libc_init.c index 1c6180b77680be..c54d0224281786 100644 --- a/usr/klibc/libc_init.c +++ b/usr/klibc/libc_init.c @@ -25,6 +25,7 @@ #include <klibc/compiler.h> #include <elf.h> #include <sys/auxv.h> +#include <klibc/sysconfig.h> #include "atexit.h" /* This file is included from __static_init.c or __shared_init.c */ @@ -40,7 +41,8 @@ struct auxentry { unsigned long v; }; -extern void __init_stdio(void); +extern void __libc_init_stdio(void); +extern void __libc_archinit(void); unsigned long __auxval[_AUXVAL_MAX]; @@ -90,20 +92,11 @@ __noreturn __libc_init(uintptr_t * elfdata, void (*onexit) (void)) __page_size = page_size = __auxval[AT_PAGESZ]; -#ifdef __i386__ - { - extern void (*__syscall_entry)(int, ...); - if (__auxval[AT_SYSINFO]) - __syscall_entry = (void (*)(int, ...)) - __auxval[AT_SYSINFO]; - } -#endif - #if __GNUC__ >= 4 /* unsigned int is 32 bits on all our architectures */ page_shift = __builtin_clz(page_size) ^ 31; #elif defined(__i386__) || defined(__x86_64__) - asm("bsrl %1,%0": "=r"(page_shift):"r"(page_size)); + asm("bsrl %1,%0" : "=r" (page_shift) : "r" (page_size)); #else while (page_size > 1) { page_shift++; @@ -112,7 +105,11 @@ __noreturn __libc_init(uintptr_t * elfdata, void (*onexit) (void)) #endif __page_shift = page_shift; - __init_stdio(); +#if _KLIBC_HAS_ARCHINIT + __libc_archinit(); +#endif + + __libc_init_stdio(); environ = envp; exit(MAIN(argc, argv, envp)); diff --git a/usr/klibc/stdio/fdopen.c b/usr/klibc/stdio/fdopen.c index 51285baeeb123c..cdc35ccc3b511f 100644 --- a/usr/klibc/stdio/fdopen.c +++ b/usr/klibc/stdio/fdopen.c @@ -48,7 +48,7 @@ err: return NULL; } -void __init_stdio(void) +void __libc_init_stdio(void) { stdin = fdopen(0, NULL); stdout = fdopen(1, NULL); |