Search
lxdream.org :: lxdream/src/sh4/ia32abi.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/ia32abi.h
changeset 586:2a3ba82cf243
prev539:75f3e594d4a7
next590:4db6a084ca3c
author nkeynes
date Tue Jan 15 20:50:23 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Merged lxdream-mmu r570:596 to trunk
file annotate diff log raw
1.1 --- a/src/sh4/ia32abi.h Wed Nov 21 11:40:15 2007 +0000
1.2 +++ b/src/sh4/ia32abi.h Tue Jan 15 20:50:23 2008 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: sh4x86.in,v 1.20 2007-11-08 11:54:16 nkeynes Exp $
1.6 + * $Id$
1.7 *
1.8 * Provides the implementation for the ia32 ABI (eg prologue, epilogue, and
1.9 * calling conventions)
1.10 @@ -80,19 +80,16 @@
1.11 {
1.12 PUSH_r32(addr);
1.13 call_func0(sh4_read_long);
1.14 - POP_r32(addr);
1.15 + POP_r32(R_ECX);
1.16 PUSH_r32(R_EAX);
1.17 - ADD_imm8s_r32( 4, addr );
1.18 - PUSH_r32(addr);
1.19 + ADD_imm8s_r32( 4, R_ECX );
1.20 + PUSH_r32(R_ECX);
1.21 call_func0(sh4_read_long);
1.22 ADD_imm8s_r32( 4, R_ESP );
1.23 MOV_r32_r32( R_EAX, arg2b );
1.24 POP_r32(arg2a);
1.25 }
1.26
1.27 -#define EXIT_BLOCK_SIZE 29
1.28 -
1.29 -
1.30 /**
1.31 * Emit the 'start of block' assembly. Sets up the stack frame and save
1.32 * SI/DI as required
1.33 @@ -108,7 +105,9 @@
1.34 sh4_x86.fpuen_checked = FALSE;
1.35 sh4_x86.branch_taken = FALSE;
1.36 sh4_x86.backpatch_posn = 0;
1.37 + sh4_x86.recovery_posn = 0;
1.38 sh4_x86.block_start_pc = pc;
1.39 + sh4_x86.tlb_on = IS_MMU_ENABLED();
1.40 sh4_x86.tstate = TSTATE_NONE;
1.41 #ifdef STACK_ALIGN
1.42 sh4_x86.stack_posn = 8;
1.43 @@ -119,16 +118,23 @@
1.44 * Exit the block with sh4r.pc already written
1.45 * Bytes: 15
1.46 */
1.47 -void exit_block_pcset( pc )
1.48 +void exit_block_pcset( sh4addr_t pc )
1.49 {
1.50 load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
1.51 ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) ); // 6
1.52 load_spreg( R_EAX, REG_OFFSET(pc) );
1.53 - call_func1(xlat_get_code,R_EAX);
1.54 + if( sh4_x86.tlb_on ) {
1.55 + call_func1(xlat_get_code_by_vma,R_EAX);
1.56 + } else {
1.57 + call_func1(xlat_get_code,R_EAX);
1.58 + }
1.59 POP_r32(R_EBP);
1.60 RET();
1.61 }
1.62
1.63 +#define EXIT_BLOCK_SIZE(pc) (24 + (IS_IN_ICACHE(pc)?5:CALL_FUNC1_SIZE))
1.64 +
1.65 +
1.66 /**
1.67 * Exit the block to an absolute PC
1.68 */
1.69 @@ -136,7 +142,37 @@
1.70 {
1.71 load_imm32( R_ECX, pc ); // 5
1.72 store_spreg( R_ECX, REG_OFFSET(pc) ); // 3
1.73 - MOV_moff32_EAX( xlat_get_lut_entry(pc) ); // 5
1.74 + if( IS_IN_ICACHE(pc) ) {
1.75 + MOV_moff32_EAX( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) ); // 5
1.76 + } else if( sh4_x86.tlb_on ) {
1.77 + call_func1(xlat_get_code_by_vma,R_ECX);
1.78 + } else {
1.79 + call_func1(xlat_get_code,R_ECX);
1.80 + }
1.81 + AND_imm8s_r32( 0xFC, R_EAX ); // 3
1.82 + load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
1.83 + ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) ); // 6
1.84 + POP_r32(R_EBP);
1.85 + RET();
1.86 +}
1.87 +
1.88 +#define EXIT_BLOCK_REL_SIZE(pc) (27 + (IS_IN_ICACHE(pc)?5:CALL_FUNC1_SIZE))
1.89 +
1.90 +/**
1.91 + * Exit the block to a relative PC
1.92 + */
1.93 +void exit_block_rel( sh4addr_t pc, sh4addr_t endpc )
1.94 +{
1.95 + load_imm32( R_ECX, pc - sh4_x86.block_start_pc ); // 5
1.96 + ADD_sh4r_r32( R_PC, R_ECX );
1.97 + store_spreg( R_ECX, REG_OFFSET(pc) ); // 3
1.98 + if( IS_IN_ICACHE(pc) ) {
1.99 + MOV_moff32_EAX( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) ); // 5
1.100 + } else if( sh4_x86.tlb_on ) {
1.101 + call_func1(xlat_get_code_by_vma,R_ECX);
1.102 + } else {
1.103 + call_func1(xlat_get_code,R_ECX);
1.104 + }
1.105 AND_imm8s_r32( 0xFC, R_EAX ); // 3
1.106 load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
1.107 ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) ); // 6
1.108 @@ -150,48 +186,87 @@
1.109 void sh4_translate_end_block( sh4addr_t pc ) {
1.110 if( sh4_x86.branch_taken == FALSE ) {
1.111 // Didn't exit unconditionally already, so write the termination here
1.112 - exit_block( pc, pc );
1.113 + exit_block_rel( pc, pc );
1.114 }
1.115 if( sh4_x86.backpatch_posn != 0 ) {
1.116 + unsigned int i;
1.117 + // Raise exception
1.118 uint8_t *end_ptr = xlat_output;
1.119 - // Exception termination. Jump block for various exception codes:
1.120 - PUSH_imm32( EXC_DATA_ADDR_READ );
1.121 - JMP_rel8( 33, target1 );
1.122 - PUSH_imm32( EXC_DATA_ADDR_WRITE );
1.123 - JMP_rel8( 26, target2 );
1.124 - PUSH_imm32( EXC_ILLEGAL );
1.125 - JMP_rel8( 19, target3 );
1.126 - PUSH_imm32( EXC_SLOT_ILLEGAL );
1.127 - JMP_rel8( 12, target4 );
1.128 - PUSH_imm32( EXC_FPU_DISABLED );
1.129 - JMP_rel8( 5, target5 );
1.130 - PUSH_imm32( EXC_SLOT_FPU_DISABLED );
1.131 - // target
1.132 - JMP_TARGET(target1);
1.133 - JMP_TARGET(target2);
1.134 - JMP_TARGET(target3);
1.135 - JMP_TARGET(target4);
1.136 - JMP_TARGET(target5);
1.137 - // Raise exception
1.138 - load_spreg( R_ECX, REG_OFFSET(pc) );
1.139 + MOV_r32_r32( R_EDX, R_ECX );
1.140 ADD_r32_r32( R_EDX, R_ECX );
1.141 - ADD_r32_r32( R_EDX, R_ECX );
1.142 - store_spreg( R_ECX, REG_OFFSET(pc) );
1.143 + ADD_r32_sh4r( R_ECX, R_PC );
1.144 MOV_moff32_EAX( &sh4_cpu_period );
1.145 MUL_r32( R_EDX );
1.146 ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
1.147
1.148 call_func0( sh4_raise_exception );
1.149 ADD_imm8s_r32( 4, R_ESP );
1.150 - load_spreg( R_EAX, REG_OFFSET(pc) );
1.151 - call_func1(xlat_get_code,R_EAX);
1.152 + load_spreg( R_EAX, R_PC );
1.153 + if( sh4_x86.tlb_on ) {
1.154 + call_func1(xlat_get_code_by_vma,R_EAX);
1.155 + } else {
1.156 + call_func1(xlat_get_code,R_EAX);
1.157 + }
1.158 POP_r32(R_EBP);
1.159 RET();
1.160
1.161 - sh4_x86_do_backpatch( end_ptr );
1.162 + // Exception already raised - just cleanup
1.163 + uint8_t *preexc_ptr = xlat_output;
1.164 + MOV_r32_r32( R_EDX, R_ECX );
1.165 + ADD_r32_r32( R_EDX, R_ECX );
1.166 + ADD_r32_sh4r( R_ECX, R_SPC );
1.167 + MOV_moff32_EAX( &sh4_cpu_period );
1.168 + MUL_r32( R_EDX );
1.169 + ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
1.170 + load_spreg( R_EAX, R_PC );
1.171 + if( sh4_x86.tlb_on ) {
1.172 + call_func1(xlat_get_code_by_vma,R_EAX);
1.173 + } else {
1.174 + call_func1(xlat_get_code,R_EAX);
1.175 + }
1.176 + POP_r32(R_EBP);
1.177 + RET();
1.178 +
1.179 + for( i=0; i< sh4_x86.backpatch_posn; i++ ) {
1.180 + *sh4_x86.backpatch_list[i].fixup_addr =
1.181 + xlat_output - ((uint8_t *)sh4_x86.backpatch_list[i].fixup_addr) - 4;
1.182 + if( sh4_x86.backpatch_list[i].exc_code == -1 ) {
1.183 + load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount );
1.184 + int rel = preexc_ptr - xlat_output;
1.185 + JMP_rel(rel);
1.186 + } else {
1.187 + PUSH_imm32( sh4_x86.backpatch_list[i].exc_code );
1.188 + load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount );
1.189 + int rel = end_ptr - xlat_output;
1.190 + JMP_rel(rel);
1.191 + }
1.192 + }
1.193 }
1.194 }
1.195
1.196 +void *xlat_get_native_pc()
1.197 +{
1.198 + void *result = NULL;
1.199 + asm(
1.200 + "mov %%ebp, %%eax\n\t"
1.201 + "mov $0x8, %%ecx\n\t"
1.202 + "mov %1, %%edx\n"
1.203 +"frame_loop: test %%eax, %%eax\n\t"
1.204 + "je frame_not_found\n\t"
1.205 + "cmp (%%eax), %%edx\n\t"
1.206 + "je frame_found\n\t"
1.207 + "sub $0x1, %%ecx\n\t"
1.208 + "je frame_not_found\n\t"
1.209 + "movl (%%eax), %%eax\n\t"
1.210 + "jmp frame_loop\n"
1.211 +"frame_found: movl 0x4(%%eax), %0\n"
1.212 +"frame_not_found:"
1.213 + : "=r" (result)
1.214 + : "r" (&sh4r)
1.215 + : "eax", "ecx", "edx" );
1.216 + return result;
1.217 +}
1.218 +
1.219 #endif
1.220
1.221
.