Changeset 14916 in vbox for trunk/src/recompiler_new/tcg/i386
- Timestamp:
- Dec 2, 2008 3:41:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/recompiler_new/tcg/i386/tcg-target.c
r14881 r14916 547 547 548 548 #ifdef RT_OS_DARWIN 549 550 /* could be any register, not used for argument passing */ 551 #define BIAS_REG TCG_REG_EDI 552 /* Call out stack alignement, must be power of 2 for mask below to be right */ 553 #define CALLOUT_FRAME_ALIGN 16 554 #define CALLOUT_FRAME_MASK ~(CALLOUT_FRAME_ALIGN - 1) 555 556 static void tcg_align_frame_pre(TCGContext* s, int args_size) 557 { 558 int8_t bias; 559 560 bias = CALLOUT_FRAME_ALIGN - args_size; 561 562 while (bias <= 0) 563 bias += CALLOUT_FRAME_ALIGN; 564 565 tcg_out_push(s, BIAS_REG); 566 tcg_out_opc(s, 0x8d); tcg_out8(s, 0x74 | (BIAS_REG <<3)); tcg_out8(s, 0x20 | TCG_REG_ESP); tcg_out8(s, -args_size-4); /* lea -(args_size+4)(%esp),%bias */ 567 tcg_out8(s, 0x83); tcg_out8(s, 0xe0 | BIAS_REG); tcg_out8(s, CALLOUT_FRAME_MASK); /* andl $CALLOUT_FRAME_MASK, %bias */ 568 tcg_out_modrm(s, 0x01 | (ARITH_SUB << 3), TCG_REG_ESP, BIAS_REG); /* sub %esp,%bias */ 569 tcg_out8(s, 0x8d); tcg_out8(s, 0x64); tcg_out8(s, TCG_REG_ESP |(BIAS_REG << 3)); tcg_out8(s, args_size+4);/* lea args_size+4(%esp,%bias),%esp */ 570 tcg_out_push(s, BIAS_REG); 571 /* restore old bias_reg value, so nobody notices */ 572 tcg_out8(s, 0xf7); tcg_out8(s, 0xd8 | BIAS_REG); /* neg bias_reg */ 573 tcg_out8(s, 0x8b); tcg_out8(s, 0x44 | (BIAS_REG << 3)); tcg_out8(s, TCG_REG_ESP |(BIAS_REG << 3)); tcg_out8(s, -args_size);/* mov -args_size(%esp,%bias),%bias */ 574 575 /* how stack is ready for args to be pushed */ 576 } 577 578 static void tcg_align_frame_post(TCGContext* s, int args_size) 579 { 580 tcg_out8(s, 0x8b); tcg_out8(s, 0x44 | (BIAS_REG << 3)); tcg_out8(s, TCG_REG_ESP |(TCG_REG_ESP << 3)); tcg_out8(s, args_size);/* mov args_size(%esp),%bias */ 581 tcg_out_modrm(s, 0x01 | (ARITH_SUB << 3), BIAS_REG, TCG_REG_ESP); /* sub %bias, %esp */ 582 tcg_out_pop(s, BIAS_REG); 583 } 584 549 585 static void tcg_out_vbox_phys_read(TCGContext *s, int index, 550 586 int addr_reg, … … 555 591 /** @todo: should we make phys addess accessors fastcalls - probably not a big deal */ 556 592 /* out parameter (address), note that phys address is always 64-bit */ 557 AssertMsg(sizeof(RTGCPHYS) == 8, ("Physical address must be 64-bits, update caller\n")); 558 559 tcg_out8(s, 0xf7); tcg_out8(s, 0xc4); tcg_out32(s, 0xf); /* test $0xf, %esp */ 560 tcg_out8(s, 0x74); tcg_out8(s, 0x4); /* je 1 */ 561 tcg_out8(s, 0x8d); tcg_out8(s, 0x64); tcg_out8(s, 0x24); tcg_out8(s, 0xf8); /* lea -0x8(%esp),%esp */ 562 /* 1: */ 563 tcg_out8(s, 0x6a); tcg_out8(s, 0x00); /* push $0 */ 593 AssertMsg(sizeof(RTGCPHYS) == 8, ("Physical address must be 64-bits, update caller\n")); 594 tcg_align_frame_pre(s, 8); 595 596 /* push arguments */ 597 tcg_out8(s, 0x6a); tcg_out8(s, 0x00); /* push $0 */ 564 598 tcg_out_push(s, addr_reg); 565 599 566 tcg_out8(s, 0xe8); tcg_out32(s, 0); /* call 2 */ 567 /* 2: */ 568 tcg_out8(s, 0x74); tcg_out8(s, 0x6); /* je 3 */ 569 tcg_out8(s, 0x83); tcg_out8(s, 0x04); tcg_out8(s, 0x24); tcg_out8(s, 0x11); /* addl $0x11,(%esp) */ 570 tcg_out8(s, 0xeb); tcg_out8(s, 0x04); /* jmp 4 */ 571 /* 3: */ 572 tcg_out8(s, 0x83); tcg_out8(s, 0x04); tcg_out8(s, 0x24); tcg_out8(s, 0x14); /* addl $0x14,(%esp) */ 573 /* 4: */ 574 tcg_out_long_jmp(s, vbox_ld_helpers[index]); 575 576 /* return point 1: clear both parameter and alignment */ 577 tcg_out8(s, 0x83); tcg_out8(s, 0xc4); tcg_out8(s, 0x08); /* add $0x8,%esp */ 578 /* return point 2: clear only parameter */ 579 tcg_out8(s, 0x83); tcg_out8(s, 0xc4); tcg_out8(s, 0x08); /* add $0x8,%esp */ 580 /* mov %eax, data_reg */ 600 tcg_out_long_call(s, vbox_ld_helpers[index]); 601 tcg_align_frame_post(s, 8); 602 581 603 tcg_out_mov(s, data_reg, TCG_REG_EAX); 582 583 604 /* returned 64-bit value */ 584 605 if (useReg2) 585 606 tcg_out_mov(s, data_reg2, TCG_REG_EDX); 586 607 } 608 static void tcg_out_vbox_phys_write(TCGContext *s, int index, 609 int addr_reg, 610 int val_reg, int val_reg2) { 611 int use_reg2 = ((index & 3) == 3); 612 int args_size = 8 + (use_reg2 ? 8 : 4); 613 int temp_val_reg = 0; 614 615 /** @todo: should we make phys addess accessors fastcalls - probably not a big deal */ 616 tcg_align_frame_pre(s, args_size); 617 /* out parameter (value2) */ 618 if (use_reg2) 619 tcg_out_push(s, val_reg2); 620 /* out parameter (value) */ 621 tcg_out_push(s, val_reg); 622 /* out parameter (address), note that phys address is always 64-bit */ 623 AssertMsg(sizeof(RTGCPHYS) == 8, ("Physical address must be 64-bits, update caller\n")); 624 tcg_out8(s, 0x6a); tcg_out8(s, 0x00); /* push $0 */ 625 tcg_out_push(s, addr_reg); 626 627 /* call it */ 628 tcg_out_long_call(s, vbox_st_helpers[index]); 629 630 tcg_align_frame_post(s, args_size); 631 } 632 587 633 #else 588 634 static void tcg_out_vbox_phys_read(TCGContext *s, int index, … … 610 656 tcg_out_addi(s, TCG_REG_ESP, 8); 611 657 } 612 #endif613 614 658 615 659 static void tcg_out_vbox_phys_write(TCGContext *s, int index, … … 634 678 /* clean stack after us */ 635 679 tcg_out_addi(s, TCG_REG_ESP, 8 + (useReg2 ? 8 : 4)); 636 637 } 680 } 681 #endif 682 638 683 #endif 639 684 … … 1376 1421 TCG_REG_EBP, 1377 1422 TCG_REG_EBX, 1378 /* TCG_REG_ESI ,*/ /* currently used for the global env, so no1423 /* TCG_REG_ESI, */ /* currently used for the global env, so no 1379 1424 need to save */ 1380 1425 TCG_REG_EDI,
Note:
See TracChangeset
for help on using the changeset viewer.