linux/Documentation/mn10300/ABI.txt
<<
>>
Prefs
   1                           =========================
   2                           MN10300 FUNCTION CALL ABI
   3                           =========================
   4
   5=======
   6GENERAL
   7=======
   8
   9The MN10300/AM33 kernel runs in little-endian mode; big-endian mode is not
  10supported.
  11
  12The stack grows downwards, and should always be 32-bit aligned. There are
  13separate stack pointer registers for userspace and the kernel.
  14
  15
  16================
  17ARGUMENT PASSING
  18================
  19
  20The first two arguments (assuming up to 32-bits per argument) to a function are
  21passed in the D0 and D1 registers respectively; all other arguments are passed
  22on the stack.
  23
  24If 64-bit arguments are being passed, then they are never split between
  25registers and the stack. If the first argument is a 64-bit value, it will be
  26passed in D0:D1. If the first argument is not a 64-bit value, but the second
  27is, the second will be passed entirely on the stack and D1 will be unused.
  28
  29Arguments smaller than 32-bits are not coalesced within a register or a stack
  30word. For example, two byte-sized arguments will always be passed in separate
  31registers or word-sized stack slots.
  32
  33
  34=================
  35CALLING FUNCTIONS
  36=================
  37
  38The caller must allocate twelve bytes on the stack for the callee's use before
  39it inserts a CALL instruction. The CALL instruction will write into the TOS
  40word, but won't actually modify the stack pointer; similarly, the RET
  41instruction reads from the TOS word of the stack, but doesn't move the stack
  42pointer beyond it.
  43
  44
  45        Stack:
  46        |               |
  47        |               |
  48        |---------------| SP+20
  49        | 4th Arg       |
  50        |---------------| SP+16
  51        | 3rd Arg       |
  52        |---------------| SP+12
  53        | D1 Save Slot  |
  54        |---------------| SP+8
  55        | D0 Save Slot  |
  56        |---------------| SP+4
  57        | Return Addr   |
  58        |---------------| SP
  59        |               |
  60        |               |
  61
  62
  63The caller must leave space on the stack (hence an allocation of twelve bytes)
  64in which the callee may store the first two arguments.
  65
  66
  67============
  68RETURN VALUE
  69============
  70
  71The return value is passed in D0 for an integer (or D0:D1 for a 64-bit value),
  72or A0 for a pointer.
  73
  74If the return value is a value larger than 64-bits, or is a structure or an
  75array, then a hidden first argument will be passed to the callee by the caller:
  76this will point to a piece of memory large enough to hold the result of the
  77function. In this case, the callee will return the value in that piece of
  78memory, and no value will be returned in D0 or A0.
  79
  80
  81===================
  82REGISTER CLOBBERING
  83===================
  84
  85The values in certain registers may be clobbered by the callee, and other
  86values must be saved:
  87
  88        Clobber:        D0-D1, A0-A1, E0-E3
  89        Save:           D2-D3, A2-A3, E4-E7, SP
  90
  91All other non-supervisor-only registers are clobberable (such as MDR, MCRL,
  92MCRH).
  93
  94
  95=================
  96SPECIAL REGISTERS
  97=================
  98
  99Certain ordinary registers may carry special usage for the compiler:
 100
 101        A3:     Frame pointer
 102        E2:     TLS pointer
 103
 104
 105==========
 106KERNEL ABI
 107==========
 108
 109The kernel may use a slightly different ABI internally.
 110
 111 (*) E2
 112
 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.
 116
 117     Normally the kernel uses something like:
 118
 119        MOV     SP,An
 120        AND     0xFFFFE000,An
 121        MOV     (An),Rm         // Rm holds current
 122        MOV     (yyy,Rm)        // Access current->yyy
 123
 124     To find the address of current; but since this option permits current to
 125     e clarri(id="L121" class="line" name="L121"> 121 118
 117     Normally the kerpassed en1tirely on the stack and 1D1 wi127f="Documentation/mn10300/E2I.txt#L123" id="L123" class="line" name="L123"> 123
  29Arguments smaller than 132-bits a1re not coalesced within 1a reg1220" id="L1ve tea name="L11">  11
 111 (*) E2
  12The stack grows downward/mn10300/1ABI.txt#L33" id="L33" cl1ass="1ine" n class="line" name="L98">  98
   3                          1ef="Docum1entation/mn10300/ABI.txt1#L35"1id="L35" class="line"e="L3">   3                          1e" class="entation/mn10300/ABI.txt1#L36"13ne" name="L16">  16================
 118
  38The caller must allocat1e twelve 1bytes on the stack for t1he ca13ion/mn10300/AL83" clas03" id="NTRY                   EXIname="L41">  41instruction reads from 1uction. T1he CALL instruction will1 writ1320" id="L120"5" class="line"" id="L4" class="line" n" id="L4" class="line" name="L14">  14
  14
 115     unavailable for ref="Docu1mentation/mn10300/ABI.tx1t#L4314ef="DocumentaD1              2/mn1y x" c ntation/m 0300/A" name="L115"> 115     unavailable for registers ABI.txt#L44" id="L44" cl1ass="14t#L54" id="L5A3               cla1y x" c ntation/m 0300/A" name="L115"> 115     unavailable for rmn10300/ABBI.txt#L15" id="L15" clasL35"14BI.txt#L55" iA2               cla1y x" c ntation/m 0300/A" name="L115"> 115     unavailable for r" class="ation/mn10300/ABI.txt#L416" id1"L46" class="lD3              5cla1y x" c ntation/m 0300/A" name="L115"> 115     unavailable for rf="Docum1f="Documentation/mn103001/ABI.1xt#L47" id="L4D2              6cla1y x" c ntation/m 0300/A" name="L115"> 115     unavailable for rmn10300/1f="Documentation/mn103001/ABI.14ne" name="L38">  38The caller must allocat1-| SP+20
1  38The caller must allocat1-ction. T1f="Documentation/mn103001/ABI.1xt#L50ve the stackt#L65sa/mn10300/Aoss="lineine" name="L23">  23

mn10original LXR18"ftwtatio.txt#Lme="L23">http://sourcne" ge.net/projects/lx0">LXR1communityBI.t,xt#L12exL12i
l v00/tacko.tme="L23">mailto:lx0@lc/gf.no">lx0@lc/gf.noBI.t.
" id="3/ac/cref="Dosubfoo300">
lx0.lc/gf.no k
http://www.redpill-lc/pro.no">Redpill Lc/pro ASBI.t,xprovidlassf Lc/ux"consultss="="linL12