PORTING 4.6 KB

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