OSDN Git Service

be more specific as to what arguments to __uClibc_main() people can skim on during...
[uclinux-h8/uClibc.git] / docs / PORTING
1 Some notes to help future porters.  Replace 'ARCH' with whatever arch
2 you are hacking on.
3
4 ====================
5 === Config Files ===
6 ====================
7 - create extra/Configs/Config.ARCH
8    See the other arch files for some good examples.  powerpc/sparc/alpha
9    should be pretty simple templates.
10 - add ARCH to the 'Target Architecture' list in extra/Configs/Config.in
11 - Initially you will want to disable shared libraries, since making
12    the shared library loader work requires you first have basic architecture
13    support working.  Thus you should add HAVE_NO_SHARED and ARCH_HAS_NO_LDSO
14    to Config.ARCH's TARGET_ARCH
15
16 ====================
17 === libc sysdeps ===
18 ====================
19 (note: if glibc has already been ported to your arch, you can usually just
20        copy a lot of files from them rather than coding from scratch)
21 - create libc/sysdeps/linux/ARCH
22 - copy Makefile and Makefile.arch from libc/sysdeps/linux/i386/
23 - set CSRC and SSRC to nothing in Makefile.arch for now
24
25 - create crt1.S which defines the _start function ... you will probably want
26   to clear the frame pointer to make gdb happy, and then you will want to call
27   the funcion __uClibc_main() which takes these parameters:
28    __uClibc_main(main(), argc, argv, _init(), _fini())
29   Initially if you wish to make things easier on yourself, you can disable the
30   UCLIBC_CTOR_DTOR option and just set the init/fini arguments to NULL.
31   glibc generally stores this function in libc/sysdeps/ARCH/elf/start.S
32
33 - create these additional files in ARCH/bits/
34
35   (template versions can be found in common/bits/ for you to tweak)
36   endian.h  fcntl.h  setjmp.h  stackinfo.h  uClibc_arch_features.h  wordsize.h
37
38   kernel_types.h should be created based upon linux asm-ARCH/posix_types.h
39
40   copy linux asm-ARCH/stat.h to bits/kernel_stat.h
41
42   create syscalls.h based upon linux's unistd.h / glibc's sysdeps.h ... really
43   you just want to define the _syscall[0-6] macros.  It is important that
44   these syscalls should be PIC safe (or you should provide a PIC and non-PIC
45   version) if you wish to properly support shared libraries.
46
47 - at this point, you should have enough to generate a working HELLO WORLD
48   static binary (see test/silly/*.c files)
49
50 - if you want UCLIBC_CTOR_DTOR support, you will need to create crti.S and
51   crtn.S files which define function prologues/epilogues.
52
53 - for a more stable static port, you will need to create these files (and
54   update the Makefile.arch values accordingly)
55     __longjmp  bsd-_setjmp  bsd-setjmp  brk  clone  setjmp  syscall  vfork
56   usually these are written in assembler, but you may be able to cheat and
57   write them in C ... see other ports for more information
58
59 ====================
60 === pthread deps ===
61 ====================
62
63 TODO: nptl / linuxthreads / linuxthreads.old
64
65 ====================
66 === ldso sysdeps ===
67 ====================
68 - enable ldso/shared options in your extra/Configs/Config.ARCH file
69 - you will need to create the following files in ldso/ldso/ARCH/
70   dl-debug.h  dl-startup.h  dl-syscalls.h  dl-sysdep.h  elfinterp.c  resolve.S
71
72 - dl-debug.h: define string versions of all the relocations of your arch in the
73   _dl_reltypes_tab array ... the index should match the actual reloc type, so
74   if the value of say R_X86_64_PC16 is 13, then "R_X86_64_PC16" better be at
75   index 13 of the array
76
77 - dl-startup.h:
78   - define the _start function which should call _dl_start which takes just one
79     parameter ... a pointer to argc (usually on the stack)
80     glibc stores this function in libc/sysdeps/ARCH/dl-machine.h as RTLD_START
81   - define the GET_ARGV() macro which calculates the value of argv based upon
82     the parameter passed to _dl_start (usually it's simply just ARGS+1)
83   - define PERFORM_BOOTSTRAP_RELOC() macro which will handle just the relocs
84     that the ldso itself will generate
85
86 - dl-syscalls.h:
87   if you wrote your bits/syscalls.h file correctly in the libc step above, you
88   can simply copy this file from another arch and be done ... otherwise you
89   will have to define the syscall[0-6] macros again, but this time setting
90   _dl_errno instead of just errno
91
92 - dl-sysdep.h:
93   misc cruft goes in here ... you want to:
94   - either define or undefine ELF_USES_RELOCA
95   - define the INIT_GOT macro
96   - define MAGIC1 to the EM_### value your ELF arch uses
97   - define ELF_TARGET to a string name for your arch
98   - define the do_rem() macro
99   - define misc ALIGN macro's
100   - define elf_machine_type_class() macro
101   - define the inline functions elf_machine_dynamic, elf_machine_load_address,
102     and elf_machine_relative
103   glibc stores a bunch of these values in libc/sysdeps/ARCH/dl-machine.h
104
105 - elfinterp.c:
106   define all the relocation functions ... it's best if you just copy from
107   another arch which uses the same type of relocations (REL or RELA) and
108   start from there.
109
110 - resolve.S:
111   front end of lazy relocation ... define the _dl_linux_resolve symbol which
112   is called by a PLT entry which has yet to be setup ... you will want to:
113   - set up arguments for _dl_linux_resolver()
114   - call _dl_linux_resolver()
115   - clean up after call
116   - jump to function address now stored in PLT
117   glibc stores this function in libc/sysdeps/ARCH/dl-trampoline.S