History

stdcall added + floating point fixes

bellard committed 24 years ago

Commit 621b3fc1 parent 0b8f3521 file · +35 −6Browse files

Unified · Split

i386-gen.c+35−6
@@ -71,12 +71,14 @@ int reg_classes[NB_REGS] = { · 70 unmodified lines
71/* function call context */71/* function call context */
72typedef struct GFuncContext {72typedef struct GFuncContext {
73 int args_size;73 int args_size;
74 int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */
74} GFuncContext;75} GFuncContext;
75 76
76/******************************************************/77/******************************************************/
77 78
78static int *func_sub_sp_ptr;79static int *func_sub_sp_ptr;
79static unsigned char *func_bound_ptr;80static unsigned char *func_bound_ptr;
81static int func_ret_sub;
80 82
81void g(int c)83void g(int c)
82{84{
@@ -279,9 +281,10 @@ void store(int r, SValue *v) · 196 unmodified lines
279}281}
280 282
281/* start function call and return function call context */283/* start function call and return function call context */
282void gfunc_start(GFuncContext *c)284void gfunc_start(GFuncContext *c, int func_call)
283{285{
284 c->args_size = 0;286 c->args_size = 0;
287 c->func_call = func_call;
285}288}
286 289
287/* push function parameter which is in (vtop->t, vtop->c). Stack entry290/* push function parameter which is in (vtop->t, vtop->c). Stack entry
@@ -356,7 +359,7 @@ void gfunc_call(GFuncContext *c) · 68 unmodified lines
356 o(0xff); /* call *r */359 o(0xff); /* call *r */
357 o(0xd0 + r);360 o(0xd0 + r);
358 }361 }
359 if (c->args_size)362 if (c->args_size && c->func_call == FUNC_CDECL)
360 oad(0xc481, c->args_size); /* add $xxx, %esp */363 oad(0xc481, c->args_size); /* add $xxx, %esp */
361 vtop--;364 vtop--;
362}365}
@@ -364,10 +367,11 @@ void gfunc_call(GFuncContext *c) · 1 unmodified line
364/* generate function prolog of type 't' */367/* generate function prolog of type 't' */
365void gfunc_prolog(int t)368void gfunc_prolog(int t)
366{369{
367 int addr, align, size, u;370 int addr, align, size, u, func_call;
368 Sym *sym;371 Sym *sym;
369 372
370 sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT);373 sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
374 func_call = sym->r;
371 addr = 8;375 addr = 8;
372 /* if the function returns a structure, then add an376 /* if the function returns a structure, then add an
373 implicit pointer parameter */377 implicit pointer parameter */
@@ -391,6 +395,10 @@ void gfunc_prolog(int t) · 17 unmodified lines
391#endif395#endif
392 addr += size;396 addr += size;
393 }397 }
398 func_ret_sub = 0;
399 /* pascal type call ? */
400 if (func_call == FUNC_STDCALL)
401 func_ret_sub = addr - 8;
394 o(0xe58955); /* push %ebp, mov %esp, %ebp */402 o(0xe58955); /* push %ebp, mov %esp, %ebp */
395 func_sub_sp_ptr = (int *)oad(0xec81, 0); /* sub $xxx, %esp */403 func_sub_sp_ptr = (int *)oad(0xec81, 0); /* sub $xxx, %esp */
396 /* leave some room for bound checking code */404 /* leave some room for bound checking code */
@@ -423,7 +431,14 @@ void gfunc_epilog(void) · 26 unmodified lines
423 oad(0xe8, (int)__bound_local_delete - ind - 5);431 oad(0xe8, (int)__bound_local_delete - ind - 5);
424 o(0x585a); /* restore returned value, if any */432 o(0x585a); /* restore returned value, if any */
425 }433 }
426 o(0xc3c9); /* leave, ret */434 o(0xc9); /* leave */
435 if (func_ret_sub == 0) {
436 o(0xc3); /* ret */
437 } else {
438 o(0xc2); /* ret n */
439 g(func_ret_sub);
440 g(func_ret_sub >> 8);
441 }
427 /* align local size to word & save local variables */442 /* align local size to word & save local variables */
428 *func_sub_sp_ptr = (-loc + 3) & -4; 443 *func_sub_sp_ptr = (-loc + 3) & -4;
429}444}
@@ -613,7 +628,7 @@ void gen_opi(int op) · 183 unmodified lines
613/* XXX: need to use ST1 too */628/* XXX: need to use ST1 too */
614void gen_opf(int op)629void gen_opf(int op)
615{630{
616 int a, ft, fc, swapped;631 int a, ft, fc, swapped, r;
617 632
618 /* convert constants to memory references */633 /* convert constants to memory references */
619 if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {634 if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
@@ -634,6 +649,7 @@ void gen_opf(int op) · 14 unmodified lines
634 if (op >= TOK_ULT && op <= TOK_GT) {649 if (op >= TOK_ULT && op <= TOK_GT) {
635 /* load on stack second operand */650 /* load on stack second operand */
636 load(REG_ST0, vtop);651 load(REG_ST0, vtop);
652 save_reg(REG_EAX); /* eax is used by FP comparison code */
637 if (op == TOK_GE || op == TOK_GT)653 if (op == TOK_GE || op == TOK_GT)
638 o(0xc9d9); /* fxch %st(1) */654 o(0xc9d9); /* fxch %st(1) */
639 o(0xe9da); /* fucompp */655 o(0xe9da); /* fucompp */
@@ -694,11 +710,23 @@ void gen_opf(int op) · 54 unmodified lines
694 o(0xde); /* fxxxp %st, %st(1) */710 o(0xde); /* fxxxp %st, %st(1) */
695 o(0xc1 + (a << 3));711 o(0xc1 + (a << 3));
696 } else {712 } else {
713 /* if saved lvalue, then we must reload it */
714 r = vtop->r;
715 if ((r & VT_VALMASK) == VT_LLOCAL) {
716 SValue v1;
717 r = get_reg(RC_INT);
718 v1.t = VT_INT;
719 v1.r = VT_LOCAL | VT_LVAL;
720 v1.c.ul = fc;
721 load(r, &v1);
722 fc = 0;
723 }
724
697 if ((ft & VT_BTYPE) == VT_DOUBLE)725 if ((ft & VT_BTYPE) == VT_DOUBLE)
698 o(0xdc);726 o(0xdc);
699 else727 else
700 o(0xd8);728 o(0xd8);
701 gen_modrm(a, vtop->r, fc);729 gen_modrm(a, r, fc);
702 }730 }
703 vtop--;731 vtop--;
704 }732 }
@@ -714,6 +742,7 @@ static unsigned short __tcc_int_fpu_control = 0x137f | 0x0c00; · 9 unmodified lines
714 and 'long long' cases. */742 and 'long long' cases. */
715void gen_cvt_itof(int t)743void gen_cvt_itof(int t)
716{744{
745 save_reg(REG_ST0);
717 gv(RC_INT);746 gv(RC_INT);
718 if ((vtop->t & VT_BTYPE) == VT_LLONG) {747 if ((vtop->t & VT_BTYPE) == VT_LLONG) {
719 /* signed long long to float/double/long double (unsigned case748 /* signed long long to float/double/long double (unsigned case

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t