6 #define TMP_ADDR 0x0001
10 #define LOC_SYM 0x0800
11 #define LOC_LOCAL 0x1000
12 #define LOC_MASK 0xff00
50 #define MIN(a, b) ((a) < (b) ? (a) : (b))
52 #define R_BYTEMASK (1 << R_RAX | 1 << R_RDX | 1 << R_RCX)
53 #define TMP_BT(t) ((t)->flags & TMP_ADDR ? 8 : (t)->bt)
54 #define TMP_REG(t) ((t)->flags & LOC_REG ? (t)->addr : reg_get(~0))
55 #define TMP_REG2(t, r) ((t)->flags & LOC_REG && (t)->addr != r ? \
56 (t)->addr : reg_get(~(1 << r)))
57 #define TMP_BYTEREG(t) ((t)->flags & LOC_REG && \
58 (1 << (t)->addr) & R_BYTEMASK ? \
59 (t)->addr : reg_get(R_BYTEMASK))
60 #define BT_TMPBT(bt) (BT_SZ(bt) >= 4 ? (bt) : (bt) & BT_SIGNED | 4)
62 static char buf
[SECSIZE
];
66 static long spsub_addr
;
71 long off
; /* used for LOC_SYM; offset from a symbol address */
79 static struct tmp
*regs
[NREGS
];
80 static int tmpregs
[] = {R_RAX
, R_RDI
, R_RSI
, R_RDX
, R_RCX
, R_R8
, R_R9
};
82 #define MAXRET (1 << 8)
84 static long ret
[MAXRET
];
90 static void putint(char *s
, long n
, int l
)
100 static void os(char *s
, int n
)
108 static void oi(long n
, int l
)
116 static long codeaddr(void)
121 static void o_op(int *op
, int nop
, int r1
, int r2
, unsigned bt
)
131 if (rex
|| (bt
& BT_SZMASK
) == 8)
133 if ((bt
& BT_SZMASK
) == 2)
135 if ((bt
& BT_SZMASK
) == 1)
137 for (i
= 0; i
< nop
; i
++)
141 static void memop(int *op
, int nop
, int src
, int base
, int off
, unsigned bt
)
143 int dis
= off
== (char) off
? 1 : 4;
144 int mod
= dis
== 4 ? 2 : 1;
145 o_op(op
, nop
, src
, base
, bt
);
148 oi((mod
<< 6) | ((src
& 0x07) << 3) | (base
& 0x07), 1);
153 static void memop1(int op
, int src
, int base
, int off
, unsigned bt
)
155 memop(&op
, 1, src
, base
, off
, bt
);
158 static void regop(int *op
, int nop
, int src
, int dst
, unsigned bt
)
160 o_op(op
, nop
, src
, dst
, bt
);
161 oi((3 << 6) | (src
<< 3) | (dst
& 0x07), 1);
164 static void regop1(int op
, int src
, int dst
, unsigned bt
)
166 regop(&op
, 1, src
, dst
, bt
);
169 static long sp_push(int size
)
177 #define LOC_NEW(f, l) (((f) & ~LOC_MASK) | (l))
179 static void tmp_mem(struct tmp
*tmp
)
182 if (!(tmp
->flags
& LOC_REG
))
186 tmp
->addr
= -sp_push(8);
187 memop1(MOV_R2X
, src
, R_RBP
, tmp
->addr
, BT_TMPBT(TMP_BT(tmp
)));
189 tmp
->flags
= LOC_NEW(tmp
->flags
, LOC_MEM
);
192 static int *movxx_x2r(int bt
)
194 static int movxx
[2] = {0x0f};
196 movxx
[1] = bt
& BT_SIGNED
? 0xbe : 0xb6;
198 movxx
[1] = bt
& BT_SIGNED
? 0xbf : 0xb7;
204 static void mov_r2r(int r1
, int r2
, unsigned bt1
, unsigned bt2
)
206 int s1
= bt1
& BT_SIGNED
;
207 int s2
= bt2
& BT_SIGNED
;
208 int sz1
= BT_SZ(bt1
);
209 int sz2
= BT_SZ(bt2
);
210 if (sz2
< 4 && (sz1
>= sz2
&& s1
!= s2
)) {
211 regop(movxx_x2r(bt2
), 2, r1
, r2
, 4);
214 if (sz1
== 4 && sz2
== 8) {
215 regop1(MOVSXD
, r2
, r1
, sz2
);
218 if (r1
!= r2
|| sz1
> sz2
)
219 regop1(MOV_R2X
, r1
, r2
, BT_TMPBT(bt2
));
222 static void mov_m2r(int dst
, int base
, int off
, int bt1
, int bt2
)
224 if (BT_SZ(bt1
) < 4) {
225 memop(movxx_x2r(bt1
), 2, dst
, base
, off
,
226 bt1
& BT_SIGNED
&& BT_SZ(bt2
) == 8 ? 8 : 4);
227 mov_r2r(dst
, dst
, bt1
, bt2
);
229 memop1(MOV_M2R
, dst
, base
, off
, bt1
);
230 mov_r2r(dst
, dst
, bt1
, bt2
);
234 static void num_cast(struct tmp
*t
, unsigned bt
)
236 if (!(bt
& BT_SIGNED
) && BT_SZ(bt
) != 8)
237 t
->addr
&= ((1l << (long) (BT_SZ(bt
) * 8)) - 1);
238 if (bt
& BT_SIGNED
&& BT_SZ(bt
) != 8 &&
239 t
->addr
> (1l << (BT_SZ(bt
) * 8 - 1)))
240 t
->addr
= -((1l << (BT_SZ(bt
) * 8)) - t
->addr
);
244 static void num_reg(int reg
, unsigned bt
, long num
)
246 int op
= MOV_I2R
+ (reg
& 7);
247 if (BT_SZ(bt
) == 8 && num
>= 0 && num
== (unsigned) num
)
249 o_op(&op
, 1, 0, reg
, bt
);
253 static void tmp_reg(struct tmp
*tmp
, int dst
, unsigned bt
, int deref
)
255 if (!(tmp
->flags
& TMP_ADDR
))
258 tmp
->flags
&= ~TMP_ADDR
;
259 if (tmp
->flags
& LOC_NUM
) {
261 tmp
->bt
= BT_TMPBT(bt
);
262 num_reg(dst
, tmp
->bt
, tmp
->addr
);
265 tmp
->flags
= LOC_NEW(tmp
->flags
, LOC_REG
);
267 if (tmp
->flags
& LOC_SYM
) {
268 regop1(MOV_I2X
, 0, dst
, TMP_BT(tmp
));
270 out_rela(tmp
->addr
, codeaddr(), 0);
274 tmp
->flags
= LOC_NEW(tmp
->flags
, LOC_REG
);
276 if (tmp
->flags
& LOC_REG
) {
278 mov_m2r(dst
, tmp
->addr
, 0, tmp
->bt
, bt
);
280 mov_r2r(tmp
->addr
, dst
, TMP_BT(tmp
), bt
);
281 regs
[tmp
->addr
] = NULL
;
283 tmp
->bt
= BT_TMPBT(bt
);
287 if (tmp
->flags
& LOC_LOCAL
) {
289 mov_m2r(dst
, R_RBP
, tmp
->addr
, tmp
->bt
, bt
);
291 memop1(LEA_M2R
, dst
, R_RBP
, tmp
->addr
, 8);
293 if (tmp
->flags
& LOC_MEM
) {
294 mov_m2r(dst
, R_RBP
, tmp
->addr
,
295 deref
? 8 : TMP_BT(tmp
), deref
? 8 : bt
);
297 mov_m2r(dst
, dst
, 0, tmp
->bt
, bt
);
300 tmp
->bt
= BT_TMPBT(bt
);
302 tmp
->flags
= LOC_NEW(tmp
->flags
, LOC_REG
);
305 static void reg_free(int reg
)
310 for (i
= 0; i
< ARRAY_SIZE(tmpregs
); i
++)
311 if (!regs
[tmpregs
[i
]]) {
312 tmp_reg(regs
[reg
], tmpregs
[i
], regs
[reg
]->bt
, 0);
318 static void reg_for(int reg
, struct tmp
*t
)
320 if (regs
[reg
] && regs
[reg
] != t
)
324 static void tmp_pop_bt(unsigned bt
, int reg
)
326 struct tmp
*t
= &tmp
[--ntmp
];
328 tmp_reg(t
, reg
, bt
, 1);
332 static unsigned tmp_pop(int deref
, int reg
)
334 struct tmp
*t
= &tmp
[--ntmp
];
336 tmp_reg(t
, reg
, deref
? t
->bt
: TMP_BT(t
), deref
);
341 static struct tmp
*tmp_new(void)
347 static void tmp_push_reg(unsigned bt
, unsigned reg
)
349 struct tmp
*t
= tmp_new();
356 void o_local(long addr
, unsigned bt
)
358 struct tmp
*t
= tmp_new();
361 t
->flags
= LOC_LOCAL
| TMP_ADDR
;
364 void o_num(long num
, unsigned bt
)
366 struct tmp
*t
= tmp_new();
372 void o_symaddr(long addr
, unsigned bt
)
374 struct tmp
*t
= tmp_new();
377 t
->flags
= LOC_SYM
| TMP_ADDR
;
381 void o_tmpdrop(int n
)
385 if (n
== -1 || n
> ntmp
)
388 for (i
= ntmp
; i
< ntmp
+ n
; i
++)
389 if (tmp
[i
].flags
& LOC_REG
)
390 regs
[tmp
[i
].addr
] = NULL
;
398 #define FORK_REG R_RAX
402 struct tmp
*t
= &tmp
[ntmp
- 1];
403 reg_for(FORK_REG
, t
);
404 tmp_reg(t
, FORK_REG
, t
->bt
, 1);
410 struct tmp
*t
= &tmp
[ntmp
- 1];
411 reg_for(FORK_REG
, t
);
412 tmp_reg(t
, FORK_REG
, t
->bt
, 1);
417 struct tmp
*t1
= &tmp
[ntmp
- 1];
418 struct tmp
*t2
= &tmp
[ntmp
- 2];
420 memcpy(&t
, t1
, sizeof(t
));
421 memcpy(t1
, t2
, sizeof(t
));
422 memcpy(t2
, &t
, sizeof(t
));
425 static int reg_get(int mask
)
428 for (i
= 0; i
< ARRAY_SIZE(tmpregs
); i
++)
429 if ((1 << tmpregs
[i
]) & mask
&& !regs
[tmpregs
[i
]])
431 for (i
= 0; i
< ARRAY_SIZE(tmpregs
); i
++)
432 if ((1 << tmpregs
[i
]) & mask
) {
433 reg_free(tmpregs
[i
]);
441 struct tmp
*t1
= &tmp
[ntmp
- 1];
442 struct tmp
*t2
= tmp_new();
443 memcpy(t2
, t1
, sizeof(*t1
));
444 if (!(t1
->flags
& (LOC_REG
| LOC_MEM
)))
446 if (t1
->flags
& LOC_MEM
) {
447 tmp_reg(t2
, reg_get(~0), t2
->bt
, 0);
448 } else if (t1
->flags
& LOC_REG
) {
449 t2
->addr
= reg_get(~t1
->addr
);
450 regop1(MOV_R2X
, t1
->addr
, t2
->addr
, BT_TMPBT(TMP_BT(t1
)));
452 t2
->flags
= t1
->flags
;
455 void o_cast(unsigned bt
)
457 struct tmp
*t
= &tmp
[ntmp
- 1];
461 if (t
->flags
& LOC_NUM
) {
465 reg
= BT_SZ(bt
) == 1 ? TMP_BYTEREG(t
) : TMP_REG(t
);
467 tmp_push_reg(bt
, reg
);
470 long o_func_beg(char *name
, int global
)
472 long addr
= out_func_beg(name
, global
);
474 os("\x55", 1); /* push %rbp */
475 os("\x48\x89\xe5", 3); /* mov %rsp, %rbp */
482 memset(regs
, 0, sizeof(regs
));
483 os("\x48\x81\xec", 3); /* sub $xxx, %rsp */
484 spsub_addr
= codeaddr();
489 void o_deref(unsigned bt
)
491 struct tmp
*t
= &tmp
[ntmp
- 1];
492 if (t
->flags
& TMP_ADDR
)
493 tmp_reg(t
, TMP_REG(t
), 8, 1);
495 t
->flags
|= TMP_ADDR
;
500 struct tmp
*t
= &tmp
[ntmp
- 1];
501 tmp_reg(t
, TMP_REG(t
), t
->bt
, 1);
504 static unsigned bt_op(unsigned bt1
, unsigned bt2
)
506 unsigned s1
= BT_SZ(bt1
);
507 unsigned s2
= BT_SZ(bt2
);
508 unsigned bt
= (bt1
| bt2
) & BT_SIGNED
| (s1
> s2
? s1
: s2
);
512 #define TMP_CONST(t) ((t)->flags & LOC_NUM && !((t)->flags & TMP_ADDR))
513 #define LOCAL_PTR(t) ((t)->flags & LOC_LOCAL && !((t)->flags & TMP_ADDR))
514 #define SYM_PTR(t) ((t)->flags & LOC_LOCAL && !((t)->flags & TMP_ADDR))
516 int o_popnum(long *c
)
518 struct tmp
*t
= &tmp
[ntmp
- 1];
526 static int c_binop(long (*cop
)(long a
, long b
, unsigned bt
), unsigned bt
)
528 struct tmp
*t1
= &tmp
[ntmp
- 1];
529 struct tmp
*t2
= &tmp
[ntmp
- 2];
530 int locals
= LOCAL_PTR(t1
) + LOCAL_PTR(t2
);
531 int syms
= SYM_PTR(t1
) + SYM_PTR(t2
);
532 int nums
= TMP_CONST(t1
) + TMP_CONST(t2
);
533 if (syms
== 2 || syms
&& locals
|| syms
+ nums
+ locals
!= 2)
537 bt
= syms
? 8 : bt_op(t1
->bt
, t2
->bt
);
544 long o1
= SYM_PTR(t1
) ? t1
->off
: t1
->addr
;
545 long o2
= SYM_PTR(t2
) ? t2
->off
: t2
->addr
;
546 long ret
= cop(o2
, o1
, bt
);
552 long ret
= cop(t2
->addr
, t1
->addr
, locals
? 4 | BT_SIGNED
: bt
);
564 static int c_op(long (*cop
)(long a
, unsigned bt
), unsigned bt
)
566 struct tmp
*t1
= &tmp
[ntmp
- 1];
572 ret
= cop(t1
->addr
, bt
);
578 static void shx(int uop
, int sop
)
580 struct tmp
*t
= &tmp
[ntmp
- 2];
582 unsigned reg
= TMP_REG2(t
, R_RCX
);
584 bt
= tmp_pop(1, reg
);
585 regop1(SHX_REG
, bt
& BT_SIGNED
? sop
: uop
, reg
, BT_TMPBT(bt
));
586 tmp_push_reg(bt
, reg
);
589 static long c_shl(long a
, long b
, unsigned bt
)
596 if (!c_binop(c_shl
, 0))
601 static long c_shr(long a
, long b
, unsigned bt
)
606 return (unsigned long) a
>> b
;
611 if (!c_binop(c_shr
, 0))
616 static int mulop(int uop
, int sop
, int reg
)
618 struct tmp
*t1
= &tmp
[ntmp
- 1];
619 struct tmp
*t2
= &tmp
[ntmp
- 2];
620 int bt1
= TMP_BT(t1
);
621 int bt2
= TMP_BT(t2
);
622 int bt
= bt_op(bt1
, bt2
);
623 if (t1
->flags
& LOC_REG
&& t1
->addr
!= R_RAX
&& t1
->addr
!= R_RDX
)
626 tmp_reg(t1
, reg
, bt
, 1);
628 tmp_reg(t2
, R_RAX
, bt
, 1);
632 regop1(MUL_A2X
, bt
& BT_SIGNED
? sop
: uop
, reg
, BT_TMPBT(bt2
));
636 static long c_mul(long a
, long b
, unsigned bt
)
644 if (!c_binop(c_mul
, 0))
646 bt
= mulop(4, 5, R_RDX
);
647 tmp_push_reg(bt
, R_RAX
);
650 static long c_div(long a
, long b
, unsigned bt
)
658 if (!c_binop(c_div
, 0))
660 bt
= mulop(6, 7, R_RCX
);
661 tmp_push_reg(bt
, R_RAX
);
664 static long c_mod(long a
, long b
, unsigned bt
)
672 if (!c_binop(c_mod
, 0))
674 bt
= mulop(6, 7, R_RCX
);
675 tmp_push_reg(bt
, R_RDX
);
680 tmp
[ntmp
- 1].flags
&= ~TMP_ADDR
;
681 tmp
[ntmp
- 1].bt
= 8;
684 void o_ret(unsigned bt
)
687 tmp_pop_bt(bt
, R_RAX
);
689 os("\x31\xc0", 2); /* xor %eax, %eax */
690 ret
[nret
++] = o_jmp(0);
693 static int binop(int op
, int *reg
)
695 struct tmp
*t1
= &tmp
[ntmp
- 1];
696 struct tmp
*t2
= &tmp
[ntmp
- 2];
700 *reg
= TMP_REG2(t2
, r1
);
701 bt
= bt_op(t1
->bt
, t2
->bt
);
703 tmp_pop_bt(bt
, *reg
);
704 regop1(op
, *reg
, r1
, bt
);
708 static long c_add(long a
, long b
, unsigned bt
)
717 if (!c_binop(c_add
, 0))
719 bt
= binop(ADD_R2X
, ®
);
720 tmp_push_reg(bt
, reg
);
723 static long c_xor(long a
, long b
, unsigned bt
)
732 if (!c_binop(c_xor
, 0))
734 bt
= binop(XOR_R2X
, ®
);
735 tmp_push_reg(bt
, reg
);
738 static long c_and(long a
, long b
, unsigned bt
)
747 if (!c_binop(c_and
, 0))
749 bt
= binop(AND_R2X
, ®
);
750 tmp_push_reg(bt
, reg
);
753 static long c_or(long a
, long b
, unsigned bt
)
762 if (!c_binop(c_or
, 0))
764 bt
= binop(OR_R2X
, ®
);
765 tmp_push_reg(bt
, reg
);
768 static long c_sub(long a
, long b
, unsigned bt
)
777 if (!c_binop(c_sub
, 0))
779 bt
= binop(SUB_R2X
, ®
);
780 tmp_push_reg(bt
, reg
);
783 static void o_cmp(int uop
, int sop
)
785 char set
[] = "\x0f\x00\xc0";
787 int bt
= binop(CMP_R2X
, ®
);
788 set
[1] = bt
& BT_SIGNED
? sop
: uop
;
790 cmp_setl
= codeaddr();
791 os(set
, 3); /* setl %al */
792 os("\x0f\xb6\xc0", 3); /* movzbl %al, %eax */
793 tmp_push_reg(4 | BT_SIGNED
, R_RAX
);
794 cmp_last
= codeaddr();
797 static long c_lt(long a
, long b
, unsigned bt
)
804 if (!c_binop(c_lt
, 4))
809 static long c_gt(long a
, long b
, unsigned bt
)
816 if (!c_binop(c_gt
, 4))
821 static long c_le(long a
, long b
, unsigned bt
)
828 if (!c_binop(c_le
, 4))
833 static long c_ge(long a
, long b
, unsigned bt
)
840 if (!c_binop(c_ge
, 4))
845 static long c_eq(long a
, long b
, unsigned bt
)
852 if (!c_binop(c_eq
, 4))
857 static long c_neq(long a
, long b
, unsigned bt
)
864 if (!c_binop(c_neq
, 4))
869 static long c_lnot(long a
, unsigned bt
)
876 if (!c_op(c_lnot
, 4))
878 if (cmp_last
== codeaddr()) {
879 buf
[cmp_setl
+ 1] ^= 0x10;
881 o_num(0, 4 | BT_SIGNED
);
886 static long c_neg(long a
, unsigned bt
)
893 struct tmp
*t
= &tmp
[ntmp
- 1];
895 unsigned bt
= BT_TMPBT(t
->bt
);
896 if (!c_op(c_neg
, t
->bt
| BT_SIGNED
))
900 regop1(NEG_REG
, 3, reg
, bt
);
901 tmp_push_reg(bt
, reg
);
904 static long c_not(long a
, unsigned bt
)
911 struct tmp
*t
= &tmp
[ntmp
- 1];
913 unsigned bt
= BT_TMPBT(t
->bt
);
918 regop1(NOT_REG
, 2, reg
, bt
);
919 tmp_push_reg(t
->bt
, reg
);
922 void o_func_end(void)
925 for (i
= 0; i
< nret
; i
++)
927 os("\xc9\xc3", 2); /* leave; ret; */
928 putint(buf
+ spsub_addr
, (maxsp
+ 7) & ~0x07, 4);
929 out_func_end(buf
, cur
- buf
);
932 long o_mklocal(int size
)
934 return sp_push((size
+ 7) & ~0x07);
937 void o_rmlocal(long addr
, int sz
)
942 static int arg_regs
[] = {R_RDI
, R_RSI
, R_RDX
, R_RCX
, R_R8
, R_R9
};
944 #define R_NARGS ARRAY_SIZE(arg_regs)
946 long o_arg(int i
, unsigned bt
)
950 addr
= o_mklocal(BT_SZ(bt
));
951 memop1(MOV_R2X
, arg_regs
[i
], R_RBP
, -addr
, bt
);
953 addr
= -8 * (i
- R_NARGS
+ 2);
958 void o_assign(unsigned bt
)
960 struct tmp
*t1
= &tmp
[ntmp
- 1];
961 struct tmp
*t2
= &tmp
[ntmp
- 2];
962 int r1
= BT_SZ(bt
) > 1 ? TMP_REG(t1
) : TMP_BYTEREG(t1
);
965 tmp_pop_bt(BT_TMPBT(bt
), r1
);
966 if (t2
->flags
& LOC_LOCAL
) {
971 reg
= TMP_REG2(t2
, r1
);
975 memop1(MOV_R2X
, r1
, reg
, off
, bt
);
976 tmp_push_reg(bt
, r1
);
979 static void tmp_to(struct tmp
*t
, int reg
)
982 tmp_reg(t
, reg
, t
->bt
, 0);
985 void o_memcpy(int sz
)
987 struct tmp
*t0
= &tmp
[ntmp
];
988 struct tmp
*t1
= &tmp
[ntmp
- 1];
989 struct tmp
*t2
= &tmp
[ntmp
- 2];
994 os("\xf3\xa4", 2); /* rep movs */
998 void o_memset(int x
, int sz
)
1000 struct tmp
*t0
= &tmp
[ntmp
+ 1];
1001 struct tmp
*t1
= &tmp
[ntmp
];
1002 struct tmp
*t2
= &tmp
[ntmp
- 1];
1008 os("\xf3\xaa", 2); /* rep stosb */
1012 long o_mklabel(void)
1017 static long jx(int x
, long addr
)
1019 char op
[2] = {0x0f};
1021 os(op
, 2); /* jx $addr */
1022 oi(addr
- codeaddr() - 4, 4);
1023 return codeaddr() - 4;
1026 static long jxtest(int x
, long addr
)
1028 int bt
= tmp_pop(1, R_RAX
);
1029 regop1(TEST_R2R
, R_RAX
, R_RAX
, bt
);
1033 static long jxcmp(long addr
, int inv
)
1036 if (codeaddr() != cmp_last
)
1039 cur
= buf
+ cmp_setl
;
1040 x
= (unsigned char) buf
[cmp_setl
+ 1];
1041 return jx((inv
? x
: x
^ 0x01) & ~0x10, addr
);
1044 long o_jz(long addr
)
1046 long ret
= jxcmp(addr
, 0);
1047 return ret
!= -1 ? ret
: jxtest(0x84, addr
);
1050 long o_jnz(long addr
)
1052 long ret
= jxcmp(addr
, 1);
1053 return ret
!= -1 ? ret
: jxtest(0x85, addr
);
1056 long o_jmp(long addr
)
1058 os("\xe9", 1); /* jmp $addr */
1059 oi(addr
- codeaddr() - 4, 4);
1060 return codeaddr() - 4;
1063 void o_filljmp2(long addr
, long jmpdst
)
1065 putint(buf
+ addr
, jmpdst
- addr
- 4, 4);
1068 void o_filljmp(long addr
)
1070 o_filljmp2(addr
, codeaddr());
1073 void o_call(int argc
, unsigned *bt
, unsigned ret_bt
)
1077 for (i
= 0; i
< ARRAY_SIZE(tmpregs
); i
++)
1078 if (regs
[tmpregs
[i
]] && regs
[tmpregs
[i
]] - tmp
< ntmp
- argc
)
1079 tmp_mem(regs
[tmpregs
[i
]]);
1080 if (argc
> R_NARGS
) {
1081 long addr
= sp_push(8 * (argc
- R_NARGS
));
1082 for (i
= argc
- 1; i
>= R_NARGS
; --i
) {
1083 int reg
= TMP_REG(&tmp
[ntmp
- 1]);
1084 tmp_pop_bt(bt
[i
], reg
);
1085 memop1(MOV_R2X
, reg
, R_RBP
,
1086 -(addr
- (i
- R_NARGS
) * 8), BT_TMPBT(bt
[i
]));
1089 for (i
= MIN(argc
, R_NARGS
) - 1; i
>= 0; i
--)
1090 tmp_pop_bt(bt
[i
], arg_regs
[i
]);
1092 if (t
->flags
& LOC_SYM
) {
1093 os("\x31\xc0", 2); /* xor %eax, %eax */
1094 os("\xe8", 1); /* call $x */
1096 out_rela(t
->addr
, codeaddr(), 1);
1101 regop1(CALL_REG
, 2, R_RAX
, 4);
1104 tmp_push_reg(ret_bt
, R_RAX
);
1117 void o_datset(long addr
, int off
, unsigned bt
)
1119 struct tmp
*t
= &tmp
[ntmp
- 1];
1120 if (t
->flags
& LOC_NUM
&& !(t
->flags
& TMP_ADDR
)) {
1122 out_datcpy(addr
, off
, (void *) &t
->addr
, BT_SZ(bt
));
1124 if (t
->flags
& LOC_SYM
&& !(t
->flags
& TMP_ADDR
)) {
1125 out_datrela(tmp
->addr
, addr
, off
);
1126 out_datcpy(addr
, off
, (void *) &t
->off
, BT_SZ(bt
));