1 #ifndef INCLUDED_ARGS_H
2 #define INCLUDED_ARGS_H
6 /* This defines the calling sequences for integers and floats. */
27 unsigned long _ulong
[2];
36 extern void (*callthis
)(void);
37 extern unsigned long rax
,rbx
,rcx
,rdx
,rsi
,rdi
,rsp
,rbp
,r8
,r9
,r10
,r11
,r12
,r13
,r14
,r15
;
40 extern volatile unsigned long volatile_var
;
41 extern void snapshot (void);
42 extern void snapshot_ret (void);
43 #define WRAP_CALL(N) \
44 (callthis = (void (*)()) (N), (typeof (&N)) snapshot)
46 (callthis = (void (*)()) (N), (typeof (&N)) snapshot_ret)
48 /* Clear all integer registers. */
49 #define clear_int_hardware_registers \
50 asm __volatile__ ("xor %%rax, %%rax\n\t" \
51 "xor %%rbx, %%rbx\n\t" \
52 "xor %%rcx, %%rcx\n\t" \
53 "xor %%rdx, %%rdx\n\t" \
54 "xor %%rsi, %%rsi\n\t" \
55 "xor %%rdi, %%rdi\n\t" \
56 "xor %%r8, %%r8\n\t" \
57 "xor %%r9, %%r9\n\t" \
58 "xor %%r10, %%r10\n\t" \
59 "xor %%r11, %%r11\n\t" \
60 "xor %%r12, %%r12\n\t" \
61 "xor %%r13, %%r13\n\t" \
62 "xor %%r14, %%r14\n\t" \
63 "xor %%r15, %%r15\n\t" \
64 ::: "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", \
65 "r9", "r10", "r11", "r12", "r13", "r14", "r15");
67 /* This is the list of registers available for passing arguments. Not all of
68 these are used or even really available. */
69 struct IntegerRegisters
71 unsigned long rax
, rbx
, rcx
, rdx
, rsi
, rdi
, r8
, r9
, r10
, r11
, r12
, r13
, r14
, r15
;
75 double mm0
, mm1
, mm2
, mm3
, mm4
, mm5
, mm6
, mm7
;
76 ldouble st0
, st1
, st2
, st3
, st4
, st5
, st6
, st7
;
77 XMM_T xmm0
, xmm1
, xmm2
, xmm3
, xmm4
, xmm5
, xmm6
, xmm7
, xmm8
, xmm9
,
78 xmm10
, xmm11
, xmm12
, xmm13
, xmm14
, xmm15
;
81 /* Implemented in scalarargs.c */
82 extern struct IntegerRegisters iregs
;
83 extern struct FloatRegisters fregs
;
84 extern unsigned int num_iregs
, num_fregs
;
86 #define check_int_arguments do { \
87 assert (num_iregs <= 0 || iregs.I0 == I0); \
88 assert (num_iregs <= 1 || iregs.I1 == I1); \
89 assert (num_iregs <= 2 || iregs.I2 == I2); \
90 assert (num_iregs <= 3 || iregs.I3 == I3); \
91 assert (num_iregs <= 4 || iregs.I4 == I4); \
92 assert (num_iregs <= 5 || iregs.I5 == I5); \
95 #define check_char_arguments check_int_arguments
96 #define check_short_arguments check_int_arguments
97 #define check_long_arguments check_int_arguments
99 /* Clear register struct. */
100 #define clear_struct_registers \
101 rax = rbx = rcx = rdx = rdi = rsi = rbp = rsp \
102 = r8 = r9 = r10 = r11 = r12 = r13 = r14 = r15 = 0; \
103 memset (&iregs, 0, sizeof (iregs)); \
104 memset (&fregs, 0, sizeof (fregs)); \
105 memset (xmm_regs, 0, sizeof (xmm_regs)); \
106 memset (x87_regs, 0, sizeof (x87_regs));
108 /* Clear both hardware and register structs for integers. */
109 #define clear_int_registers \
110 clear_struct_registers \
111 clear_int_hardware_registers
113 /* TODO: Do the checking. */
114 #define check_f_arguments(T) { \
115 assert (num_fregs <= 0 || fregs.xmm0._ ## T [0] == xmm_regs[0]._ ## T [0]); \
116 assert (num_fregs <= 1 || fregs.xmm1._ ## T [0] == xmm_regs[1]._ ## T [0]); \
117 assert (num_fregs <= 2 || fregs.xmm2._ ## T [0] == xmm_regs[2]._ ## T [0]); \
118 assert (num_fregs <= 3 || fregs.xmm3._ ## T [0] == xmm_regs[3]._ ## T [0]); \
119 assert (num_fregs <= 4 || fregs.xmm4._ ## T [0] == xmm_regs[4]._ ## T [0]); \
120 assert (num_fregs <= 5 || fregs.xmm5._ ## T [0] == xmm_regs[5]._ ## T [0]); \
121 assert (num_fregs <= 6 || fregs.xmm6._ ## T [0] == xmm_regs[6]._ ## T [0]); \
122 assert (num_fregs <= 7 || fregs.xmm7._ ## T [0] == xmm_regs[7]._ ## T [0]); \
125 #define check_float_arguments check_f_arguments(float)
126 #define check_double_arguments check_f_arguments(double)
128 /* ldoubles are not passed in registers */
129 #define check_ldouble_arguments
131 /* TODO: Do the clearing. */
132 #define clear_float_hardware_registers
133 #define clear_x87_hardware_registers
135 #define clear_float_registers \
136 clear_struct_registers \
137 clear_float_hardware_registers
139 #define clear_x87_registers \
140 clear_struct_registers \
141 clear_x87_hardware_registers
144 #endif /* INCLUDED_ARGS_H */