Back to index

plt-scheme  4.2.1
asm.h
Go to the documentation of this file.
00001 /* -----------------------------------------------------------------------
00002    asm.h - Copyright (c) 1998 Geoffrey Keating
00003 
00004    PowerPC Assembly glue.
00005 
00006    Permission is hereby granted, free of charge, to any person obtaining
00007    a copy of this software and associated documentation files (the
00008    ``Software''), to deal in the Software without restriction, including
00009    without limitation the rights to use, copy, modify, merge, publish,
00010    distribute, sublicense, and/or sell copies of the Software, and to
00011    permit persons to whom the Software is furnished to do so, subject to
00012    the following conditions:
00013 
00014    The above copyright notice and this permission notice shall be included
00015    in all copies or substantial portions of the Software.
00016 
00017    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00020    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
00021    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00022    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00023    OTHER DEALINGS IN THE SOFTWARE.
00024    ----------------------------------------------------------------------- */
00025 
00026 #define ASM_GLOBAL_DIRECTIVE .globl
00027 
00028 
00029 #define C_SYMBOL_NAME(name) name
00030 /* Macro for a label.  */
00031 #ifdef __STDC__
00032 #define C_LABEL(name)              name##:
00033 #else
00034 #define C_LABEL(name)              name:
00035 #endif
00036 
00037 /* This seems to always be the case on PPC.  */
00038 #define ALIGNARG(log2) log2
00039 /* For ELF we need the `.type' directive to make shared libs work right.  */
00040 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
00041 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
00042 
00043 /* If compiled for profiling, call `_mcount' at the start of each function.  */
00044 #ifdef PROF
00045 /* The mcount code relies on a the return address being on the stack
00046    to locate our caller and so it can restore it; so store one just
00047    for its benefit.  */
00048 #ifdef PIC
00049 #define CALL_MCOUNT                                                  \
00050   .pushsection;                                                             \
00051   .section ".data";                                                  \
00052   .align ALIGNARG(2);                                                       \
00053 0:.long 0;                                                           \
00054   .previous;                                                         \
00055   mflr  %r0;                                                         \
00056   stw   %r0,4(%r1);                                                  \
00057   bl    _GLOBAL_OFFSET_TABLE_@local-4;                                      \
00058   mflr  %r11;                                                        \
00059   lwz   %r0,0b@got(%r11);                                            \
00060   bl    JUMPTARGET(_mcount);
00061 #else  /* PIC */
00062 #define CALL_MCOUNT                                                  \
00063   .section ".data";                                                  \
00064   .align ALIGNARG(2);                                                       \
00065 0:.long 0;                                                           \
00066   .previous;                                                         \
00067   mflr  %r0;                                                         \
00068   lis   %r11,0b@ha;                                                  \
00069   stw   %r0,4(%r1);                                                  \
00070   addi  %r0,%r11,0b@l;                                                      \
00071   bl    JUMPTARGET(_mcount);
00072 #endif /* PIC */
00073 #else  /* PROF */
00074 #define CALL_MCOUNT         /* Do nothing.  */
00075 #endif /* PROF */
00076 
00077 #define       ENTRY(name)                                                   \
00078   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                 \
00079   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                        \
00080   .align ALIGNARG(2);                                                       \
00081   C_LABEL(name)                                                             \
00082   CALL_MCOUNT
00083 
00084 #define EALIGN_W_0  /* No words to insert.  */
00085 #define EALIGN_W_1  nop
00086 #define EALIGN_W_2  nop;nop
00087 #define EALIGN_W_3  nop;nop;nop
00088 #define EALIGN_W_4  EALIGN_W_3;nop
00089 #define EALIGN_W_5  EALIGN_W_4;nop
00090 #define EALIGN_W_6  EALIGN_W_5;nop
00091 #define EALIGN_W_7  EALIGN_W_6;nop
00092 
00093 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
00094    past a 2^align boundary.  */
00095 #ifdef PROF
00096 #define EALIGN(name, alignt, words)                                         \
00097   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                 \
00098   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                        \
00099   .align ALIGNARG(2);                                                       \
00100   C_LABEL(name)                                                             \
00101   CALL_MCOUNT                                                        \
00102   b 0f;                                                                     \
00103   .align ALIGNARG(alignt);                                           \
00104   EALIGN_W_##words;                                                  \
00105   0:
00106 #else /* PROF */
00107 #define EALIGN(name, alignt, words)                                         \
00108   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                 \
00109   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                        \
00110   .align ALIGNARG(alignt);                                           \
00111   EALIGN_W_##words;                                                  \
00112   C_LABEL(name)
00113 #endif
00114 
00115 #define END(name)                                                    \
00116   ASM_SIZE_DIRECTIVE(name)
00117 
00118 #ifdef PIC
00119 #define JUMPTARGET(name) name##@plt
00120 #else
00121 #define JUMPTARGET(name) name
00122 #endif
00123 
00124 /* Local labels stripped out by the linker.  */
00125 #define L(x) .L##x