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
7171 /* function call context */
7272 typedef struct GFuncContext {
7373 int args_size;
74+ int func_call; /* func call type (FUNC_STDCALL or FUNC_CDECL) */
7475 } GFuncContext;
7576
7677 /******************************************************/
7778
7879 static int *func_sub_sp_ptr;
7980 static unsigned char *func_bound_ptr;
81+static int func_ret_sub;
8082
8183 void g(int c)
8284 {
@@ -279,9 +281,10 @@ void store(int r, SValue *v) · 196 unmodified lines
279281 }
280282
281283 /* start function call and return function call context */
282−void gfunc_start(GFuncContext *c)
284+void gfunc_start(GFuncContext *c, int func_call)
283285 {
284286 c->args_size = 0;
287+ c->func_call = func_call;
285288 }
286289
287290 /* push function parameter which is in (vtop->t, vtop->c). Stack entry
@@ -356,7 +359,7 @@ void gfunc_call(GFuncContext *c) · 68 unmodified lines
356359 o(0xff); /* call *r */
357360 o(0xd0 + r);
358361 }
359− if (c->args_size)
362+ if (c->args_size && c->func_call == FUNC_CDECL)
360363 oad(0xc481, c->args_size); /* add $xxx, %esp */
361364 vtop--;
362365 }
@@ -364,10 +367,11 @@ void gfunc_call(GFuncContext *c) · 1 unmodified line
364367 /* generate function prolog of type 't' */
365368 void gfunc_prolog(int t)
366369 {
367− int addr, align, size, u;
370+ int addr, align, size, u, func_call;
368371 Sym *sym;
369372
370373 sym = sym_find((unsigned)t >> VT_STRUCT_SHIFT);
374+ func_call = sym->r;
371375 addr = 8;
372376 /* if the function returns a structure, then add an
373377 implicit pointer parameter */
@@ -391,6 +395,10 @@ void gfunc_prolog(int t) · 17 unmodified lines
391395 #endif
392396 addr += size;
393397 }
398+ func_ret_sub = 0;
399+ /* pascal type call ? */
400+ if (func_call == FUNC_STDCALL)
401+ func_ret_sub = addr - 8;
394402 o(0xe58955); /* push %ebp, mov %esp, %ebp */
395403 func_sub_sp_ptr = (int *)oad(0xec81, 0); /* sub $xxx, %esp */
396404 /* leave some room for bound checking code */
@@ -423,7 +431,14 @@ void gfunc_epilog(void) · 26 unmodified lines
423431 oad(0xe8, (int)__bound_local_delete - ind - 5);
424432 o(0x585a); /* restore returned value, if any */
425433 }
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+ }
427442 /* align local size to word & save local variables */
428443 *func_sub_sp_ptr = (-loc + 3) & -4;
429444 }
@@ -613,7 +628,7 @@ void gen_opi(int op) · 183 unmodified lines
613628 /* XXX: need to use ST1 too */
614629 void gen_opf(int op)
615630 {
616− int a, ft, fc, swapped;
631+ int a, ft, fc, swapped, r;
617632
618633 /* convert constants to memory references */
619634 if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
@@ -634,6 +649,7 @@ void gen_opf(int op) · 14 unmodified lines
634649 if (op >= TOK_ULT && op <= TOK_GT) {
635650 /* load on stack second operand */
636651 load(REG_ST0, vtop);
652+ save_reg(REG_EAX); /* eax is used by FP comparison code */
637653 if (op == TOK_GE || op == TOK_GT)
638654 o(0xc9d9); /* fxch %st(1) */
639655 o(0xe9da); /* fucompp */
@@ -694,11 +710,23 @@ void gen_opf(int op) · 54 unmodified lines
694710 o(0xde); /* fxxxp %st, %st(1) */
695711 o(0xc1 + (a << 3));
696712 } 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+
697725 if ((ft & VT_BTYPE) == VT_DOUBLE)
698726 o(0xdc);
699727 else
700728 o(0xd8);
701− gen_modrm(a, vtop->r, fc);
729+ gen_modrm(a, r, fc);
702730 }
703731 vtop--;
704732 }
@@ -714,6 +742,7 @@ static unsigned short __tcc_int_fpu_control = 0x137f | 0x0c00; · 9 unmodified lines
714742 and 'long long' cases. */
715743 void gen_cvt_itof(int t)
716744 {
745+ save_reg(REG_ST0);
717746 gv(RC_INT);
718747 if ((vtop->t & VT_BTYPE) == VT_LLONG) {
719748 /* 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