chiark / gitweb /
Make run_directory.c stat the place it is going to try to run.
[elogind.git] / klibc / klibc / arch / README
1 To port klibc to a new architecture, you need:
2
3 a) A directory structure
4
5 Each archtecture has an arch/ directory, which should include an
6 MCONFIG and a Makefile.inc file.
7
8 b) Startup code (arch/*/crt0.S)
9
10 The crt0.S assembly routine typically corresponds to the following
11 pseudo-C code.  In addition, each architecture needs any support
12 routines that gcc-generated code expects to find in the system library
13 -- Alpha, for example, needs divide subroutines.
14
15 The "getenvtest" test program is a very good test for proper crt0.S
16 functionality.
17
18
19 extern __noreturn __libc_init(void *, void *);
20
21 __noreturn _start(void)
22 {
23   void *elf_data   = get_elf_data_address(); /* Usually the stack address */
24   void *atexit_ptr = get_atexit_ptr();       /* Usually in a register */ 
25
26   /* Some architectures need this for debugging to work */
27   setup_null_stack_frame_if_necessary();
28
29   __libc_init(elf_data, atexit_ptr);
30 }
31
32
33 c) A setenv implementation (arch/*/setjmp.S, arch/*/include/klibc/archsetjmp.h)
34
35 On most (but not all!) architectures, this entails creating a setjmp
36 buffer big enough to hold all callee-saved registers, plus the stack
37 pointer and the return address.  In setjmp.S you have:
38
39 * A "setjmp" function that writes out the callee-saved registers, the
40   stack pointer and the return address to the buffer pointed to by the
41   first argument, and then returns zero normally.
42
43   On some architectures you need to take some kind of action to make
44   sure the contents of the stack is actually manifest in memory and
45   not cached in the CPU.  In some cases (e.g. on SPARC) this will
46   automatically spill the registers onto the stack; then they don't
47   need to be spilled into the jmp_buf.
48
49 * A "longjmp" function that read back these same registers from the
50   jmp_buf pointed to by the first argument, and returns the second
51   argument *to the address specified in the jmp_buf*.
52
53   On some architectures you need to take some kind of action to flush
54   any cached stack data or return stack.
55
56
57 d) Any support functions needed by gcc, *unless* they are in libgcc
58   *and* libgcc is usable for klibc on your particular platform.  If
59   libgcc isn't usable for klibc (on MIPS, for example, libgcc is
60   compiled in a way that is not compatible with klibc) there are
61   reasonably good clones of most of the libgcc functions in the libgcc
62   directory.  To use them, add them to ARCHOBJS in
63   arch/*/Makefile.inc.
64
65
66 e) A link location for the shared klibc.  This should be specified in
67   SHAREDFLAGS in arch/*/MCONFIG.