Search
lxdream.org :: lxdream/src/sh4/ia64abi.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/ia64abi.h
changeset 539:75f3e594d4a7
next547:d6e00ffc4adc
author nkeynes
date Wed Nov 21 11:40:15 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add support for the darwin ABI
view annotate diff log raw
     1 /**
     2  * $Id: ia64abi.in,v 1.20 2007-11-08 11:54:16 nkeynes Exp $
     3  * 
     4  * Provides the implementation for the ia32 ABI (eg prologue, epilogue, and
     5  * calling conventions)
     6  *
     7  * Copyright (c) 2007 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #ifndef __lxdream_x86_64abi_H
    21 #define __lxdream_x86_64abi_H 1
    24 #define load_ptr( reg, ptr ) load_imm64( reg, (uint64_t)ptr );
    26 /**
    27  * Note: clobbers EAX to make the indirect call - this isn't usually
    28  * a problem since the callee will usually clobber it anyway.
    29  * Size: 12 bytes
    30  */
    31 #define CALL_FUNC0_SIZE 12
    32 static inline void call_func0( void *ptr )
    33 {
    34     load_imm64(R_EAX, (uint64_t)ptr);
    35     CALL_r32(R_EAX);
    36 }
    38 #define CALL_FUNC1_SIZE 14
    39 static inline void call_func1( void *ptr, int arg1 )
    40 {
    41     MOV_r32_r32(arg1, R_EDI);
    42     call_func0(ptr);
    43 }
    45 #define CALL_FUNC2_SIZE 16
    46 static inline void call_func2( void *ptr, int arg1, int arg2 )
    47 {
    48     MOV_r32_r32(arg1, R_EDI);
    49     MOV_r32_r32(arg2, R_ESI);
    50     call_func0(ptr);
    51 }
    53 #define MEM_WRITE_DOUBLE_SIZE 39
    54 /**
    55  * Write a double (64-bit) value into memory, with the first word in arg2a, and
    56  * the second in arg2b
    57  */
    58 static inline void MEM_WRITE_DOUBLE( int addr, int arg2a, int arg2b )
    59 {
    60     PUSH_r32(arg2b);
    61     PUSH_r32(addr);
    62     call_func2(sh4_write_long, addr, arg2a);
    63     POP_r32(addr);
    64     POP_r32(arg2b);
    65     ADD_imm8s_r32(4, addr);
    66     call_func2(sh4_write_long, addr, arg2b);
    67 }
    69 #define MEM_READ_DOUBLE_SIZE 35
    70 /**
    71  * Read a double (64-bit) value from memory, writing the first word into arg2a
    72  * and the second into arg2b. The addr must not be in EAX
    73  */
    74 static inline void MEM_READ_DOUBLE( int addr, int arg2a, int arg2b )
    75 {
    76     PUSH_r32(addr);
    77     call_func1(sh4_read_long, addr);
    78     POP_r32(R_EDI);
    79     PUSH_r32(R_EAX);
    80     ADD_imm8s_r32(4, R_EDI);
    81     call_func0(sh4_read_long);
    82     MOV_r32_r32(R_EAX, arg2b);
    83     POP_r32(arg2a);
    84 }
    87 /**
    88  * Emit the 'start of block' assembly. Sets up the stack frame and save
    89  * SI/DI as required
    90  */
    91 void sh4_translate_begin_block( sh4addr_t pc ) 
    92 {
    93     PUSH_r32(R_EBP);
    94     /* mov &sh4r, ebp */
    95     load_ptr( R_EBP, &sh4r );
    97     sh4_x86.in_delay_slot = FALSE;
    98     sh4_x86.priv_checked = FALSE;
    99     sh4_x86.fpuen_checked = FALSE;
   100     sh4_x86.branch_taken = FALSE;
   101     sh4_x86.backpatch_posn = 0;
   102     sh4_x86.block_start_pc = pc;
   103     sh4_x86.tstate = TSTATE_NONE;
   104     sh4_x86.stack_posn = 0;
   105 }
   107 /**
   108  * Exit the block with sh4r.pc already written
   109  * Bytes: 15
   110  */
   111 void exit_block_pcset( pc )
   112 {
   113     load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
   114     ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );    // 6
   115     load_spreg( R_EAX, REG_OFFSET(pc) );
   116     call_func1(xlat_get_code,R_EAX);
   117     POP_r32(R_EBP);
   118     RET();
   119 }
   121 #define EXIT_BLOCK_SIZE 35
   122 /**
   123  * Exit the block to an absolute PC
   124  */
   125 void exit_block( sh4addr_t pc, sh4addr_t endpc )
   126 {
   127     load_imm32( R_ECX, pc );                            // 5
   128     store_spreg( R_ECX, REG_OFFSET(pc) );               // 3
   129     REXW(); MOV_moff32_EAX( xlat_get_lut_entry(pc) );
   130     REXW(); AND_imm8s_r32( 0xFC, R_EAX ); // 3
   131     load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
   132     ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
   133     POP_r32(R_EBP);
   134     RET();
   135 }
   138 /**
   139  * Write the block trailer (exception handling block)
   140  */
   141 void sh4_translate_end_block( sh4addr_t pc ) {
   142     if( sh4_x86.branch_taken == FALSE ) {
   143 	// Didn't exit unconditionally already, so write the termination here
   144 	exit_block( pc, pc );
   145     }
   146     if( sh4_x86.backpatch_posn != 0 ) {
   147 	uint8_t *end_ptr = xlat_output;
   148 	// Exception termination. Jump block for various exception codes:
   149 	load_imm32( R_EDI, EXC_DATA_ADDR_READ );
   150 	JMP_rel8( 33, target1 );
   151 	load_imm32( R_EDI, EXC_DATA_ADDR_WRITE );
   152 	JMP_rel8( 26, target2 );
   153 	load_imm32( R_EDI, EXC_ILLEGAL );
   154 	JMP_rel8( 19, target3 );
   155 	load_imm32( R_EDI, EXC_SLOT_ILLEGAL ); 
   156 	JMP_rel8( 12, target4 );
   157 	load_imm32( R_EDI, EXC_FPU_DISABLED ); 
   158 	JMP_rel8( 5, target5 );
   159 	load_imm32( R_EDI, EXC_SLOT_FPU_DISABLED );
   160 	// target
   161 	JMP_TARGET(target1);
   162 	JMP_TARGET(target2);
   163 	JMP_TARGET(target3);
   164 	JMP_TARGET(target4);
   165 	JMP_TARGET(target5);
   166 	// Raise exception
   167 	load_spreg( R_ECX, REG_OFFSET(pc) );
   168 	ADD_r32_r32( R_EDX, R_ECX );
   169 	ADD_r32_r32( R_EDX, R_ECX );
   170 	store_spreg( R_ECX, REG_OFFSET(pc) );
   171 	MOV_moff32_EAX( &sh4_cpu_period );
   172 	MUL_r32( R_EDX );
   173 	ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
   175 	call_func0( sh4_raise_exception );
   176 	load_spreg( R_EAX, REG_OFFSET(pc) );
   177 	call_func1(xlat_get_code,R_EAX);
   178 	POP_r32(R_EBP);
   179 	RET();
   181 	sh4_x86_do_backpatch( end_ptr );
   182     }
   183 }
   185 #endif
.