README.standalone 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. Design Notes on Exporting U-Boot Functions to Standalone Applications:
  2. ======================================================================
  3. 1. Add a field to the global_data structure, the pointer to a jump
  4. table.
  5. 2. Jump table itself is allocated and filled in the same way as the
  6. syscall table is (allocated with malloc() after the code has been
  7. relocated to RAM); a special function, fixed to the table element
  8. number 0, will be added which returns the ABI version so
  9. applications can check for compatibility issues.
  10. 3. It is application's responsibility to check the ABI version and
  11. act accordingly.
  12. 4. Pointer to the global_data is passed to the application in the
  13. dedicated register that is used in the U-Boot to hold this
  14. pointer. This assumes that the application is built with the same
  15. register- allocation flags as the U-Boot itself. (Actually, this
  16. is a requirement even now, as the 'go' command does not perform
  17. any actions to protect this register against being clobbered by
  18. the application).
  19. This approach won't work on the x86 architecture. See below.
  20. 5. Application now calls standard library functions like printf()
  21. instead of specially prefixed names like mon_printf() as it did
  22. before. Present implementation of these functions (using the
  23. system calls mechanism) will be replaced with jump stubs.
  24. 6. To export additional functions, the following steps will have to be
  25. taken:
  26. - Add the xxx() U-Boot function to the EXPORT_FUNC list
  27. - Add initialization of the appropriate slot in the jump table
  28. 7. To port to a new architecture, the appropriate stub code should be
  29. provided. No other machine-dependent code is used. Once the stub
  30. template is available, no additional coding is needed when
  31. exporting new U-Boot functions. A pre-processor macro will be used
  32. to automatically instantiate the stub definition for each exported
  33. function.
  34. Note the following:
  35. - This approach uses a jump table with fixed slot allocation. That
  36. said, to retain the ABI compatibility, no table reordering,
  37. inserting new functions in the middle of the list or deleting
  38. functions from the list is allowed. Any such action will break the
  39. ABI compatibility.
  40. - The x86 architecture does not use a dedicated register to store the
  41. pointer to the global_data structure. There are the following
  42. approaches available:
  43. * Pass the global_data pointer to the application in a register or
  44. as an additional argument. This requires special machine-
  45. dependent startup code to be compiled into the application.
  46. * Make the x86 consistent with the rest of architectures and use a
  47. dedicated register. This renders one register unusable in the
  48. rest of the U-Boot code and thus increases the size of the U-Boot
  49. binary and decreases it performance.
  50. The following changes will be made:
  51. - The syscall handling code will be removed.
  52. - The include/_exports.h file will be introduced, containing the list
  53. of the exported functions in the following form:
  54. EXPORT_FUNC(getc)
  55. EXPORT_FUNC(tstc)
  56. ...
  57. This list will be used to assign the slot numbers in the jump
  58. table, to determine the size of the jump table and to generate the
  59. code for the stub functions.
  60. - The include/exports.h file will be introduced, containing the
  61. prototypes of the exported functions and the assigned slot numbers.
  62. - The examples/stubs.c file will be introduced, containing the code
  63. for the jump stubs for each of the exported functions.
  64. Implementation Notes on Exporting U-Boot Functions:
  65. ===================================================
  66. 1. The patch was applied against TOT as of 7/24 12:50 MEST; the
  67. resulting images were tested on the following boards:
  68. * lwmon (PowerPC)
  69. * trab (ARM)
  70. * inca (MIPS)
  71. The hello_world application was loaded and executed then:
  72. [lwmon]
  73. => tftp 0x40000 /tftpboot/LWMON/hello_world.bin-avn
  74. => go 0x40004
  75. [trab]
  76. TRAB # tftp 0xc100000 /tftpboot/TRAB/hello_world.bin-avn
  77. TRAB # go 0xc100000
  78. [inca]
  79. INCA-IP # tftp 0x80200000 /tftpboot/INCA/hello_world.bin-avn
  80. INCA-IP # go 0x80200000
  81. 2. As neither of supported x86 boards can be built from the TOT
  82. sources currently, the patch build was verified by manually
  83. running the following command in the U-Boot top directory:
  84. > make -C examples TOPDIR=`pwd` ARCH=i386 CROSS_COMPILE=
  85. The rest of the code is mostly machine-independent and was not
  86. verified.
  87. 3. To test the x86 assembly code, a small standalone application was
  88. written. It was built and run on the RedHat Linux 8.0 (x86). The
  89. application performs a jump using a pointer to jump table and a
  90. function's index in it.
  91. 4. For the MIPS architecture, the linker script is also provided for
  92. linking applications. The default linker script places the .text
  93. and .data sections too far from each other so that the resulting
  94. .bin files span about 256Mb in size.
  95. 5. Several example applications required updating for the new API.
  96. These applications relied upon the bd_t pointer being passed as
  97. the 1st argument to the main function; this had changed when the
  98. system calls were introduced, but apparently, these applications
  99. weren't fixed at that moment. This is fixed now.
  100. 6. GCC issues warnings for the 'sched' application. Since now the
  101. mon_printf() function is renamed to printf(), GCC applies its
  102. knowledge of the format specifiers to check the arguments,
  103. complaining about ints passed as longs and vice versa. This is not
  104. fixed yet.
  105. 7. Only the hello_world example application was modified to make use
  106. of the newly supplied get_version() function. The application now
  107. prints two ABI versions, the one that the application was compiled
  108. for and the other, actual ABI version.
  109. 8. The following new files were added:
  110. common/exports.c
  111. examples/mips.lds
  112. examples/stubs.c
  113. include/_exports.h
  114. include/exports.h
  115. doc/README.standalone
  116. The following files are no longer used and will be removed:
  117. examples/syscall.S
  118. include/syscall.h