1 =========================
2 MN10300 FUNCTION CALL ABI
3 =========================
9 The MN10300/AM33 kernel runs in little-endian mode; big-endian mode is not
12 The stack grows downwards, and should always be 32-bit aligned. There are
13 separate stack pointer registers for userspace and the kernel.
20 The first two arguments (assuming up to 32-bits per argument) to a function are
21 passed in the D0 and D1 registers respectively; all other arguments are passed
24 If 64-bit arguments are being passed, then they are never split between
25 registers and the stack. If the first argument is a 64-bit value, it will be
26 passed in D0:D1. If the first argument is not a 64-bit value, but the second
27 is, the second will be passed entirely on the stack and D1 will be unused.
29 Arguments smaller than 32-bits are not coalesced within a register or a stack
30 word. For example, two byte-sized arguments will always be passed in separate
31 registers or word-sized stack slots.
38 The caller must allocate twelve bytes on the stack for the callee's use before
39 it inserts a CALL instruction. The CALL instruction will write into the TOS
40 word, but won't actually modify the stack pointer; similarly, the RET
41 instruction reads from the TOS word of the stack, but doesn't move the stack
48 |---------------| SP+20
50 |---------------| SP+16
52 |---------------| SP+12
54 |---------------| SP+8
56 |---------------| SP+4
63 The caller must leave space on the stack (hence an allocation of twelve bytes)
64 in which the callee may store the first two arguments.
71 The return value is passed in D0 for an integer (or D0:D1 for a 64-bit value),
74 If the return value is a value larger than 64-bits, or is a structure or an
75 array, then a hidden first argument will be passed to the callee by the caller:
76 this will point to a piece of memory large enough to hold the result of the
77 function. In this case, the callee will return the value in that piece of
78 memory, and no value will be returned in D0 or A0.
85 The values in certain registers may be clobbered by the callee, and other
88 Clobber: D0-D1, A0-A1, E0-E3
89 Save: D2-D3, A2-A3, E4-E7, SP
91 All other non-supervisor-only registers are clobberable (such as MDR, MCRL,
99 Certain ordinary registers may carry special usage for the compiler:
109 The kernel may use a slightly different ABI internally.
113 If CONFIG_MN10300_CURRENT_IN_E2 is defined, then the current task pointer
114 will be kept in the E2 register, and that register will be marked
115 unavailable for the compiler to use as a scratch register.
117 Normally the kernel uses something like:
121 MOV (An),Rm // Rm holds current
122 MOV (yyy,Rm) // Access current->yyy
124 To find the address of current; but since this option permits current to
125 be carried globally in an register, it can use:
127 MOV (yyy,E2) // Access current->yyy
136 System calls are called with the following convention:
139 =============== ======================= =======================
140 D0 Syscall number Return value
141 A0 1st syscall argument Saved
142 D1 2nd syscall argument Saved
143 A3 3rd syscall argument Saved
144 A2 4th syscall argument Saved
145 D3 5th syscall argument Saved
146 D2 6th syscall argument Saved
148 All other registers are saved. The layout is a consequence of the way the MOVM
149 instruction stores registers onto the stack.