Unified · Split
| @@ -320,12 +320,14 @@ static void gcall_or_jmp(int is_jmp) · 319 unmodified lines | |||
| 320 | } | 320 | } |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX }; | ||
| 324 | |||
| 323 | /* Generate function call. The function address is pushed first, then | 325 | /* Generate function call. The function address is pushed first, then |
| 324 | all the parameters in call order. This functions pops all the | 326 | all the parameters in call order. This functions pops all the |
| 325 | parameters and the function address. */ | 327 | parameters and the function address. */ |
| 326 | void gfunc_call(int nb_args) | 328 | void gfunc_call(int nb_args) |
| 327 | { | 329 | { |
| 328 | int size, align, r, args_size, i; | 330 | int size, align, r, args_size, i, func_call; |
| 329 | Sym *func_sym; | 331 | Sym *func_sym; |
| 330 | 332 | ||
| 331 | args_size = 0; | 333 | args_size = 0; |
| @@ -377,8 +379,21 @@ void gfunc_call(int nb_args) · 45 unmodified lines | |||
| 377 | } | 379 | } |
| 378 | save_regs(0); /* save used temporary registers */ | 380 | save_regs(0); /* save used temporary registers */ |
| 379 | func_sym = vtop->type.ref; | 381 | func_sym = vtop->type.ref; |
| 382 | func_call = func_sym->r; | ||
| 383 | /* fast call case */ | ||
| 384 | if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) { | ||
| 385 | int fastcall_nb_regs; | ||
| 386 | fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; | ||
| 387 | for(i = 0;i < fastcall_nb_regs; i++) { | ||
| 388 | if (args_size <= 0) | ||
| 389 | break; | ||
| 390 | o(0x58 + fastcall_regs[i]); /* pop r */ | ||
| 391 | /* XXX: incorrect for struct/floats */ | ||
| 392 | args_size -= 4; | ||
| 393 | } | ||
| 394 | } | ||
| 380 | gcall_or_jmp(0); | 395 | gcall_or_jmp(0); |
| 381 | if (args_size && func_sym->r == FUNC_CDECL) | 396 | if (args_size && func_sym->r != FUNC_STDCALL) |
| 382 | gadd_sp(args_size); | 397 | gadd_sp(args_size); |
| 383 | vtop--; | 398 | vtop--; |
| 384 | } | 399 | } |
| @@ -386,25 +401,37 @@ void gfunc_call(int nb_args) · 1 unmodified line | |||
| 386 | /* generate function prolog of type 't' */ | 401 | /* generate function prolog of type 't' */ |
| 387 | void gfunc_prolog(CType *func_type) | 402 | void gfunc_prolog(CType *func_type) |
| 388 | { | 403 | { |
| 389 | int addr, align, size, func_call; | 404 | int addr, align, size, func_call, fastcall_nb_regs; |
| 405 | int param_index, param_addr; | ||
| 390 | Sym *sym; | 406 | Sym *sym; |
| 391 | CType *type; | 407 | CType *type; |
| 392 | 408 | ||
| 393 | sym = func_type->ref; | 409 | sym = func_type->ref; |
| 394 | func_call = sym->r; | 410 | func_call = sym->r; |
| 395 | addr = 8; | 411 | addr = 8; |
| 412 | loc = 0; | ||
| 413 | if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) { | ||
| 414 | fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1; | ||
| 415 | } else { | ||
| 416 | fastcall_nb_regs = 0; | ||
| 417 | } | ||
| 418 | param_index = 0; | ||
| 419 | |||
| 420 | o(0xe58955); /* push %ebp, mov %esp, %ebp */ | ||
| 421 | func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */ | ||
| 422 | |||
| 396 | /* if the function returns a structure, then add an | 423 | /* if the function returns a structure, then add an |
| 397 | implicit pointer parameter */ | 424 | implicit pointer parameter */ |
| 398 | func_vt = sym->type; | 425 | func_vt = sym->type; |
| 399 | if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { | 426 | if ((func_vt.t & VT_BTYPE) == VT_STRUCT) { |
| 427 | /* XXX: fastcall case ? */ | ||
| 400 | func_vc = addr; | 428 | func_vc = addr; |
| 401 | addr += 4; | 429 | addr += 4; |
| 430 | param_index++; | ||
| 402 | } | 431 | } |
| 403 | /* define parameters */ | 432 | /* define parameters */ |
| 404 | while ((sym = sym->next) != NULL) { | 433 | while ((sym = sym->next) != NULL) { |
| 405 | type = &sym->type; | 434 | type = &sym->type; |
| 406 | sym_push(sym->v & ~SYM_FIELD, type, | ||
| 407 | VT_LOCAL | VT_LVAL, addr); | ||
| 408 | size = type_size(type, &align); | 435 | size = type_size(type, &align); |
| 409 | size = (size + 3) & ~3; | 436 | size = (size + 3) & ~3; |
| 410 | #ifdef FUNC_STRUCT_PARAM_AS_PTR | 437 | #ifdef FUNC_STRUCT_PARAM_AS_PTR |
| @@ -413,21 +440,31 @@ void gfunc_prolog(CType *func_type) · 2 unmodified lines | |||
| 413 | size = 4; | 440 | size = 4; |
| 414 | } | 441 | } |
| 415 | #endif | 442 | #endif |
| 416 | addr += size; | 443 | if (param_index < fastcall_nb_regs) { |
| 444 | /* save FASTCALL register */ | ||
| 445 | loc -= 4; | ||
| 446 | o(0x89); /* movl */ | ||
| 447 | gen_modrm(fastcall_regs[param_index], VT_LOCAL, NULL, loc); | ||
| 448 | param_addr = loc; | ||
| 449 | } else { | ||
| 450 | param_addr = addr; | ||
| 451 | addr += size; | ||
| 452 | } | ||
| 453 | sym_push(sym->v & ~SYM_FIELD, type, | ||
| 454 | VT_LOCAL | VT_LVAL, param_addr); | ||
| 455 | param_index++; | ||
| 417 | } | 456 | } |
| 418 | func_ret_sub = 0; | 457 | func_ret_sub = 0; |
| 419 | /* pascal type call ? */ | 458 | /* pascal type call ? */ |
| 420 | if (func_call == FUNC_STDCALL) | 459 | if (func_call == FUNC_STDCALL) |
| 421 | func_ret_sub = addr - 8; | 460 | func_ret_sub = addr - 8; |
| 422 | o(0xe58955); /* push %ebp, mov %esp, %ebp */ | 461 | |
| 423 | func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */ | ||
| 424 | /* leave some room for bound checking code */ | 462 | /* leave some room for bound checking code */ |
| 425 | if (do_bounds_check) { | 463 | if (do_bounds_check) { |
| 426 | oad(0xb8, 0); /* lbound section pointer */ | 464 | oad(0xb8, 0); /* lbound section pointer */ |
| 427 | oad(0xb8, 0); /* call to function */ | 465 | oad(0xb8, 0); /* call to function */ |
| 428 | func_bound_offset = lbounds_section->data_offset; | 466 | func_bound_offset = lbounds_section->data_offset; |
| 429 | } | 467 | } |
| 430 | loc = 0; | ||
| 431 | } | 468 | } |
| 432 | 469 | ||
| 433 | /* generate function epilog */ | 470 | /* generate function epilog */ |