X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/925ff94a516478164fdd01d53332637455e0074d..4bf3072e34661918a8e6c5e95c3e2ab05c76089b:/base/asm-common.h diff --git a/base/asm-common.h b/base/asm-common.h index d6a8b012..3560ec55 100644 --- a/base/asm-common.h +++ b/base/asm-common.h @@ -24,6 +24,9 @@ /// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, /// MA 02111-1307, USA. +#ifndef CATACOMB_ASM_COMMON_H +#define CATACOMB_ASM_COMMON_H + ///-------------------------------------------------------------------------- /// General definitions. @@ -255,10 +258,10 @@ name: # define _DECOR_abcd_q(reg) r##reg##x #endif -#define _DECOR_xp_b(reg) reg##l #define _DECOR_xp_w(reg) reg #define _DECOR_xp_d(reg) e##reg #if CPUFAM_AMD64 +# define _DECOR_xp_b(reg) reg##l # define _DECOR_xp_q(reg) r##reg #endif @@ -276,22 +279,33 @@ name: # define _DECOR_rn_r(reg) reg #endif +#define _DECOR_mem_b(addr) byte ptr addr +#define _DECOR_mem_w(addr) word ptr addr +#define _DECOR_mem_d(addr) dword ptr addr +#if CPUFAM_AMD64 +# define _DECOR_mem_q(addr) qword ptr addr +#endif + +#define _DECOR_imm_b(imm) byte imm +#define _DECOR_imm_w(imm) word imm +#define _DECOR_imm_d(imm) dword imm +#if CPUFAM_AMD64 +# define _DECOR_imm_q(imm) qword imm +#endif + #if CPUFAM_X86 # define _DECOR_abcd_r(reg) e##reg##x # define _DECOR_xp_r(reg) e##reg # define _DECOR_ip_r(reg) e##reg +# define _DECOR_mem_r(addr) dword ptr addr +# define _DECOR_imm_r(imm) dword imm #endif #if CPUFAM_AMD64 # define _DECOR_abcd_r(reg) r##reg##x # define _DECOR_xp_r(reg) r##reg # define _DECOR_ip_r(reg) r##reg -#endif - -#define _DECOR_mem_b(addr) byte ptr addr -#define _DECOR_mem_w(addr) word ptr addr -#define _DECOR_mem_d(addr) dword ptr addr -#if CPUFAM_AMD64 -# define _DECOR_mem_q(addr) qword ptr addr +# define _DECOR_mem_r(addr) qword ptr addr +# define _DECOR_imm_r(imm) qword imm #endif // R_r(decor) applies decoration decor to register r, which is an internal @@ -321,6 +335,9 @@ name: // address addr (which should supply its own square-brackets). #define MEM(decor, addr) _DECOR(mem, decor, addr) +// Refer to an immediate datum of the type implied by decor. +#define IMM(decor, imm) _DECOR(mem, decor, imm) + // Applies decoration decor to assembler-level register name reg. #define _REGFORM(reg, decor) _GLUE(_REGFORM_, reg)(decor) @@ -436,7 +453,7 @@ name: #define WHOLE(reg) _REGFORM(reg, r) // Stack management and unwinding. -.macro setfp fp, offset = 0 +.macro setfp fp, offset=0 .if \offset == 0 mov \fp, R_sp(r) #if __ELF__ @@ -459,7 +476,7 @@ name: .macro dropfp; _dropfp \fp, \offset; .endm .endm -.macro _dropfp fp, offset = 0 +.macro _dropfp fp, offset=0 .if \offset == 0 mov R_sp(r), \fp #if __ELF__ @@ -706,12 +723,12 @@ name: #if WANT_PIC ldr\cond \reg, .L$_leaextq$\@ .L$_leaextq_pc$\@: - .if .L$_pcoff == 8 + .if .L$_pcoff == 8 ldr\cond \reg, [pc, \reg] - .else + .else add\cond \reg, pc ldr\cond \reg, [\reg] - .endif + .endif _LIT .balign 4 .L$_leaextq$\@: @@ -972,7 +989,7 @@ name: #define QQ(qlo, qhi) D0(qlo)-D1(qhi) // Stack management and unwinding. -.macro setfp fp, offset = 0 +.macro setfp fp, offset=0 .if \offset == 0 mov \fp, sp .setfp \fp, sp @@ -984,7 +1001,7 @@ name: .L$_frameptr_p = -1 .endm -.macro _dropfp fp, offset = 0 +.macro _dropfp fp, offset=0 .if \offset == 0 mov sp, \fp .else @@ -1057,7 +1074,7 @@ name: .endm // Stack management and unwinding. -.macro setfp fp, offset = 0 +.macro setfp fp, offset=0 // If you're just going through the motions with a fixed-size stack frame, // then you want to say `add x29, sp, #OFFSET' directly, which will avoid // pointlessly restoring sp later. @@ -1073,7 +1090,7 @@ name: .L$_frameptr_p = -1 .endm -.macro _dropfp fp, offset = 0 +.macro _dropfp fp, offset=0 .if \offset == 0 mov sp, \fp .cfi_def_cfa_register sp @@ -1096,8 +1113,8 @@ name: .cfi_adjust_cfa_offset -\n .endm -.macro pushreg x, y= - .ifeqs "\y", "" +.macro pushreg x, y=nil + .ifeqs "\y", "nil" str \x, [sp, #-16]! .cfi_adjust_cfa_offset +16 .cfi_rel_offset \x, 0 @@ -1109,8 +1126,8 @@ name: .endif .endm -.macro popreg x, y= - .ifeqs "\y", "" +.macro popreg x, y=nil + .ifeqs "\y", "nil" ldr \x, [sp], #16 .cfi_restore \x .cfi_adjust_cfa_offset -16 @@ -1122,9 +1139,9 @@ name: .endif .endm -.macro savereg x, y, z= - .ifeqs "\z", "" - str \x, [sp, #\y] +.macro savereg x, y, z=nil + .ifeqs "\z", "nil" + str \x, [sp, \y] .cfi_rel_offset \x, \y .else stp \x, \y, [sp, #\z] @@ -1133,9 +1150,9 @@ name: .endif .endm -.macro rstrreg x, y, z= - .ifeqs "\z", "" - ldr \x, [sp, #\y] +.macro rstrreg x, y, z=nil + .ifeqs "\z", "nil" + ldr \x, [sp, \y] .cfi_restore \x .else ldp \x, \y, [sp, #\z] @@ -1181,3 +1198,5 @@ name: #endif ///----- That's all, folks -------------------------------------------------- + +#endif