ABI.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. =========================
  2. MN10300 FUNCTION CALL ABI
  3. =========================
  4. =======
  5. GENERAL
  6. =======
  7. The MN10300/AM33 kernel runs in little-endian mode; big-endian mode is not
  8. supported.
  9. The stack grows downwards, and should always be 32-bit aligned. There are
  10. separate stack pointer registers for userspace and the kernel.
  11. ================
  12. ARGUMENT PASSING
  13. ================
  14. The first two arguments (assuming up to 32-bits per argument) to a function are
  15. passed in the D0 and D1 registers respectively; all other arguments are passed
  16. on the stack.
  17. If 64-bit arguments are being passed, then they are never split between
  18. registers and the stack. If the first argument is a 64-bit value, it will be
  19. passed in D0:D1. If the first argument is not a 64-bit value, but the second
  20. is, the second will be passed entirely on the stack and D1 will be unused.
  21. Arguments smaller than 32-bits are not coalesced within a register or a stack
  22. word. For example, two byte-sized arguments will always be passed in separate
  23. registers or word-sized stack slots.
  24. =================
  25. CALLING FUNCTIONS
  26. =================
  27. The caller must allocate twelve bytes on the stack for the callee's use before
  28. it inserts a CALL instruction. The CALL instruction will write into the TOS
  29. word, but won't actually modify the stack pointer; similarly, the RET
  30. instruction reads from the TOS word of the stack, but doesn't move the stack
  31. pointer beyond it.
  32. Stack:
  33. | |
  34. | |
  35. |---------------| SP+20
  36. | 4th Arg |
  37. |---------------| SP+16
  38. | 3rd Arg |
  39. |---------------| SP+12
  40. | D1 Save Slot |
  41. |---------------| SP+8
  42. | D0 Save Slot |
  43. |---------------| SP+4
  44. | Return Addr |
  45. |---------------| SP
  46. | |
  47. | |
  48. The caller must leave space on the stack (hence an allocation of twelve bytes)
  49. in which the callee may store the first two arguments.
  50. ============
  51. RETURN VALUE
  52. ============
  53. The return value is passed in D0 for an integer (or D0:D1 for a 64-bit value),
  54. or A0 for a pointer.
  55. If the return value is a value larger than 64-bits, or is a structure or an
  56. array, then a hidden first argument will be passed to the callee by the caller:
  57. this will point to a piece of memory large enough to hold the result of the
  58. function. In this case, the callee will return the value in that piece of
  59. memory, and no value will be returned in D0 or A0.
  60. ===================
  61. REGISTER CLOBBERING
  62. ===================
  63. The values in certain registers may be clobbered by the callee, and other
  64. values must be saved:
  65. Clobber: D0-D1, A0-A1, E0-E3
  66. Save: D2-D3, A2-A3, E4-E7, SP
  67. All other non-supervisor-only registers are clobberable (such as MDR, MCRL,
  68. MCRH).
  69. =================
  70. SPECIAL REGISTERS
  71. =================
  72. Certain ordinary registers may carry special usage for the compiler:
  73. A3: Frame pointer
  74. E2: TLS pointer
  75. ==========
  76. KERNEL ABI
  77. ==========
  78. The kernel may use a slightly different ABI internally.
  79. (*) E2
  80. If CONFIG_MN10300_CURRENT_IN_E2 is defined, then the current task pointer
  81. will be kept in the E2 register, and that register will be marked
  82. unavailable for the compiler to use as a scratch register.
  83. Normally the kernel uses something like:
  84. MOV SP,An
  85. AND 0xFFFFE000,An
  86. MOV (An),Rm // Rm holds current
  87. MOV (yyy,Rm) // Access current->yyy
  88. To find the address of current; but since this option permits current to
  89. be carried globally in an register, it can use:
  90. MOV (yyy,E2) // Access current->yyy
  91. instead.
  92. ===============
  93. SYSTEM CALL ABI
  94. ===============
  95. System calls are called with the following convention:
  96. REGISTER ENTRY EXIT
  97. =============== ======================= =======================
  98. D0 Syscall number Return value
  99. A0 1st syscall argument Saved
  100. D1 2nd syscall argument Saved
  101. A3 3rd syscall argument Saved
  102. A2 4th syscall argument Saved
  103. D3 5th syscall argument Saved
  104. D2 6th syscall argument Saved
  105. All other registers are saved. The layout is a consequence of the way the MOVM
  106. instruction stores registers onto the stack.