home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Headers / architecture / hppa / asm_help.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-25  |  6.6 KB  |  254 lines

  1. /* Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved.
  2.  *
  3.  *    File:    architecture/hppa/asm_help.h
  4.  *    Author:    Joshua Doenias, NeXT Computer, Inc.
  5.  *
  6.  *    This header file defines macros useful when writing assembly code
  7.  *    for the HP PA-RISC family processors.
  8.  *
  9.  * HISTORY
  10.  * 9-Aug-93  Joshua Doenias (josh@next.com)
  11.  *    Created.
  12.  *
  13.  * 28-June-95 Matt Watson (mwatson@next.com)
  14.  *    Added dynamic/PIC macros
  15.  *
  16.  * 25-July-95 Umesh Vaishampayan (umeshv@NeXT.com)
  17.  *      Added alignment directive to .non_lazy_symbol_pointer section
  18.  */
  19.  
  20. #ifndef    _ARCH_HPPA_ASM_HELP_H_
  21. #define    _ARCH_HPPA_ASM_HELP_H_
  22.  
  23. #ifdef    __ASSEMBLER__
  24.  
  25. /*  Interesting register aliases */
  26.  
  27. #define zero    %r0    // architecturally defined to be 0
  28. #define rp    %r2    // return pointer
  29. #define fp    %r4    // frame pointer
  30. #define arg0    %r26    // general args
  31. #define arg1    %r25
  32. #define arg2    %r24
  33. #define arg3    %r23
  34. #define ret0    %r28    // return values
  35. #define ret1    %r29
  36. #define sp    %r30    // stack pointer
  37.  
  38. #define fdarg0    %fr5    // double arg 0
  39. #define fdarg1    %fr7    // double arg 1
  40. #define fsarg0    %fr4    // float arg 0
  41. #define fsarg1    %fr5    // float arg 1
  42. #define fsarg2  %fr6    // float arg 2
  43. #define fsarg3  %fr7    // float arg 3
  44. #define fret    %fr4    // return val
  45.  
  46. /* 
  47.  * This is what the hppa stack looks like at the time the function is called.
  48.  * Note that this is set up BY THE CALLER.  The called function only has
  49.  * to set up a frame if it is going to call other functions, or use local
  50.  * space.
  51.  *
  52.  *                            High addresses
  53.  * 
  54.  * SP  ----> callee allocates locals here   ( old fp saved here if needed )
  55.  *          +----------------------------+
  56.  * SP-4     |   16 bytes (unused in NS)  |
  57.  *          +----------------------------+
  58.  * SP-20    |       old RP home          |
  59.  *          +----------------------------+
  60.  * SP-24    |     12 byte frame area     |
  61.  *          |    (unused in NEXTSTEP)    |
  62.  *          +----------------------------+
  63.  * SP-36    |        arg 0 home          |
  64.  *          +----------------------------+
  65.  * SP-40    |        arg 1 home          |
  66.  *          +----------------------------+
  67.  *          |        arg 2 home          |
  68.  *          +----------------------------+
  69.  *          |        arg 3 home area     |
  70.  *          +----------------------------+
  71.  * SP-52    | additional args on stack.. |        Low addresses
  72.  *
  73.  *  If a procedure will call another proc, it needs to allocate the above
  74.  *  48 bytes on its stack.  Additional space is allocated for local vars.
  75.  *  The whole shebang is rounded up to a multiple of 64 bytes.
  76.  */
  77.  
  78. /* ARG(n)  offset to argument area.  These are 0 based -- ARG(0) is 
  79.  * the first argument.
  80.  * Note that at the time the procedure is called, only arg words 4 and >
  81.  * are on the stack.  0-3 are in registers, although a homing area is 
  82.  * available for them.
  83.  * In a leaf procedure with no locals, this macro can be used as a stack
  84.  * offset.  In a nested procedure or a leaf with locals declared, this 
  85.  * macro is actually a frame offset.
  86.  */
  87. #define ARG(n)  (((n)*4) - 36)
  88.  
  89. /* LOCAL_VAR(n)  frame offset to local variable area.  These are 0 based --
  90.  * LOCAL_VAR(0) is the first local word.
  91.  * This is an index into the local argument words.  If the function is putting
  92.  * anything other than words into local storage, it must account for them
  93.  * itself.
  94.  * Also, this macro is only valid if the function has been declared using
  95.  * either LEAF() or NESTED() with a local variable size greater than 0.
  96.  *
  97.  * It can be used as follows:
  98.  *   ldw     LOCAL_VAR(0)(0,fp), ret0    ; loads first local in return val
  99.  *   stw      arg0, LOCAL_VAR(0)(0,fp)    ; stores first arg in first local
  100.  */
  101.  
  102. #define LOCAL_VAR(n)  (((n)+1)*4)
  103.  
  104.  
  105.  
  106.  
  107. /* Macros for building stack frame */
  108.  
  109.  
  110. /* Stack is always aligned to 64 bytes */
  111. #define STACK_INCR    64
  112. #define ROUND_TO_STACK(len)            \
  113.     (((len) + STACK_INCR - 1) & ~(STACK_INCR-1))
  114.  
  115. #define NESTED_FUNCTION_PROLOGUE(localvarsize)             \
  116.     stw    rp,-20(0,%r30)                  @\
  117.     .set    __framesize,ROUND_TO_STACK(localvarsize+52)    @\
  118.     .set     __nested_function,1                @\
  119.     copy    fp,%r1                        @\
  120.     copy    sp,fp                        @\
  121.     stwm    %r1,__framesize(0,sp)
  122.  
  123. #define LEAF_FUNCTION_PROLOGUE(localvarsize)            \
  124.     .set  __nested_function,0                @\
  125.     .if localvarsize                    @\
  126.       .set __framesize,ROUND_TO_STACK(localvarsize+4)    @\
  127.       copy  fp,%r1                        @\
  128.       copy    sp,fp                        @\
  129.       stwm    %r1,__framesize(0,sp)                @\
  130.     .else                             @\
  131.       .set __framesize,0                    @\
  132.     .endif
  133.  
  134. #define FUNCTION_EPILOGUE                    \
  135.     .if __nested_function                    @\
  136.        ldw -20(0,fp),rp                    @\
  137.     .endif                            @\
  138.     .if __framesize                        @\
  139.       bv 0(rp)                        @\
  140.       ldwm -__framesize(0,sp),fp                @\
  141.     .else                            @\
  142.       bv,n 0(rp)                        @\
  143.     .endif        
  144.       
  145. /*
  146.  * LEAF - declare global leaf procedure
  147.  */
  148. #define LEAF(name,localvarsize)                    \
  149.     .align 2                        @\
  150.     .globl name                        @\
  151. name:                                @\
  152.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  153.     
  154. /*
  155.  * P_LEAF - declare private leaf procedure
  156.  */
  157. #define P_LEAF(name,localvarsize)                \
  158.     .align 2                        @\
  159. name:                                @\
  160.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  161.  
  162.  
  163. /*
  164.  * NESTED -- declare procedure that invokes other procedures
  165.  */
  166. #define NESTED(name,localvarsize)                \
  167.     .align 2                        @\
  168.     .globl name                        @\
  169. name:                                @\
  170.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  171.  
  172. /*
  173.  * P_NESTED -- declare private procedure that invokes other procedures
  174.  */
  175. #define P_NESTED(name,localvarsize)                \
  176.     .align 2                        @\
  177. name:                                @\
  178.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  179.  
  180. /*
  181.  * END -- mark end of procedure
  182.  */
  183. #define END(name)                        \
  184.      FUNCTION_EPILOGUE
  185.  
  186. #define    X_NESTED(name, value)                \
  187.     .globl    name                    @\
  188.     .set    name,value
  189.  
  190.  
  191. /*
  192.  * dynamic/PIC macros for routines which reference external symbols
  193.  */
  194.  
  195. #if defined(__DYNAMIC__)
  196. #define PICIFY(var)                        \
  197.     bl    1f,%r19                        @ \
  198.     dep    %r0,31,2,%r19                    @ \
  199. 1:                                @ \
  200.     addil    L`L ## var ## $non_lazy_ptr-1b,%r19        @ \
  201.     ldw    R`L ## var ## $non_lazy_ptr-1b(%r1),%r19
  202.  
  203. #define CALL_EXTERN_AGAIN(var)    \
  204.     PICIFY(var)        @ \
  205.     ble    0(%sr4,%r19)    @ \
  206.     copy    %r31, rp
  207.  
  208. #define NON_LAZY_STUB(var)    \
  209. .non_lazy_symbol_pointer    @ \
  210. .align 2            @ \
  211. L ## var ## $non_lazy_ptr:    @ \
  212. .indirect_symbol var        @ \
  213. .long 0                @ \
  214. .text                @ \
  215. .align 2
  216.  
  217. #define    BRANCH_EXTERN(var)    \
  218.     PICIFY(var)        @ \
  219.     be,n    0(%sr4,%r19)    @ \
  220.     NON_LAZY_STUB(var)
  221.  
  222. #define CALL_EXTERN(var)    \
  223.     CALL_EXTERN_AGAIN(var)    @ \
  224.     NON_LAZY_STUB(var)
  225.  
  226. #define REG_TO_EXTERN(reg, var)    \
  227.     PICIFY(var)        @ \
  228.     stw    reg, 0(0,%r19)    @ \
  229.     NON_LAZY_STUB(var)
  230.  
  231. #else
  232. #define BRANCH_EXTERN(var)        \
  233.     ldil    L` ## var,%r1        @ \
  234.     be,n    R` ## var(%sr4,%r1)
  235.  
  236. #define CALL_EXTERN(var)        \
  237.     ldil    L` ## var,%r1        @ \
  238.     ble    R` ## var(%sr4,%r1)    @ \
  239.     copy    %r31, rp
  240.  
  241. #define CALL_EXTERN_AGAIN(var)    \
  242.     CALL_EXTERN(var)
  243.  
  244. #define REG_TO_EXTERN(reg, var)    \
  245.     ldil L`## var,%r19    @ \
  246.     stw reg, R`## var(%r19)
  247. #endif
  248.  
  249. #define LONG_CALL(name)    \
  250.     CALL_EXTERN(name)
  251.  
  252. #endif  __ASSEMBLER__
  253. #endif    _ARCH_HPPA_ASM_HELP_H_
  254.