Search
lxdream.org :: lxdream/src/sh4/ia32abi.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/ia32abi.h
changeset 968:6fb1481859a4
prev956:4c1ed9e03985
next991:60c7fab9c880
author nkeynes
date Thu Jan 15 11:23:20 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Fix various compile-time warnings
file annotate diff log raw
nkeynes@539
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@539
     3
 * 
nkeynes@926
     4
 * Provides the implementation for the ia32 ABI variant 
nkeynes@926
     5
 * (eg prologue, epilogue, and calling conventions). Stack frame is
nkeynes@926
     6
 * aligned on 16-byte boundaries for the benefit of OS X (which 
nkeynes@926
     7
 * requires it).
nkeynes@539
     8
 *
nkeynes@539
     9
 * Copyright (c) 2007 Nathan Keynes.
nkeynes@539
    10
 *
nkeynes@539
    11
 * This program is free software; you can redistribute it and/or modify
nkeynes@539
    12
 * it under the terms of the GNU General Public License as published by
nkeynes@539
    13
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@539
    14
 * (at your option) any later version.
nkeynes@539
    15
 *
nkeynes@539
    16
 * This program is distributed in the hope that it will be useful,
nkeynes@539
    17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@539
    18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@539
    19
 * GNU General Public License for more details.
nkeynes@539
    20
 */
nkeynes@539
    21
nkeynes@926
    22
#ifndef lxdream_ia32mac_H
nkeynes@926
    23
#define lxdream_ia32mac_H 1
nkeynes@539
    24
nkeynes@539
    25
#define load_ptr( reg, ptr ) load_imm32( reg, (uint32_t)ptr );
nkeynes@539
    26
nkeynes@968
    27
static inline void decode_address( int addr_reg )
nkeynes@953
    28
{
nkeynes@953
    29
    uintptr_t base = (sh4r.xlat_sh4_mode&SR_MD) ? (uintptr_t)sh4_address_space : (uintptr_t)sh4_user_address_space;
nkeynes@953
    30
    MOV_r32_r32( addr_reg, R_ECX ); 
nkeynes@953
    31
    SHR_imm8_r32( 12, R_ECX ); 
nkeynes@953
    32
    MOV_r32disp32x4_r32( R_ECX, base, R_ECX );
nkeynes@953
    33
}
nkeynes@953
    34
nkeynes@539
    35
/**
nkeynes@539
    36
 * Note: clobbers EAX to make the indirect call - this isn't usually
nkeynes@539
    37
 * a problem since the callee will usually clobber it anyway.
nkeynes@539
    38
 */
nkeynes@539
    39
static inline void call_func0( void *ptr )
nkeynes@539
    40
{
nkeynes@953
    41
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
    42
    CALL_r32(R_ECX);
nkeynes@539
    43
}
nkeynes@539
    44
nkeynes@905
    45
#ifdef HAVE_FASTCALL
nkeynes@905
    46
static inline void call_func1( void *ptr, int arg1 )
nkeynes@905
    47
{
nkeynes@905
    48
    if( arg1 != R_EAX ) {
nkeynes@905
    49
        MOV_r32_r32( arg1, R_EAX );
nkeynes@905
    50
    }
nkeynes@953
    51
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
    52
    CALL_r32(R_ECX);
nkeynes@953
    53
}
nkeynes@953
    54
nkeynes@953
    55
static inline void call_func1_r32( int addr_reg, int arg1 )
nkeynes@953
    56
{
nkeynes@953
    57
    if( arg1 != R_EAX ) {
nkeynes@953
    58
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
    59
    }
nkeynes@953
    60
    CALL_r32(addr_reg);
nkeynes@953
    61
}
nkeynes@953
    62
nkeynes@953
    63
static inline void call_func1_r32disp8( int preg, uint32_t disp8, int arg1 )
nkeynes@953
    64
{
nkeynes@953
    65
    if( arg1 != R_EAX ) {
nkeynes@953
    66
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
    67
    }
nkeynes@953
    68
    CALL_r32disp8(preg, disp8);
nkeynes@953
    69
}
nkeynes@953
    70
nkeynes@953
    71
static inline void call_func1_r32disp8_exc( int preg, uint32_t disp8, int arg1, int pc )
nkeynes@953
    72
{
nkeynes@953
    73
    if( arg1 != R_EAX ) {
nkeynes@953
    74
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
    75
    }
nkeynes@953
    76
    load_exc_backpatch(R_EDX);
nkeynes@953
    77
    CALL_r32disp8(preg, disp8);
nkeynes@905
    78
}
nkeynes@905
    79
nkeynes@905
    80
static inline void call_func2( void *ptr, int arg1, int arg2 )
nkeynes@905
    81
{
nkeynes@905
    82
    if( arg2 != R_EDX ) {
nkeynes@905
    83
        MOV_r32_r32( arg2, R_EDX );
nkeynes@905
    84
    }
nkeynes@905
    85
    if( arg1 != R_EAX ) {
nkeynes@905
    86
        MOV_r32_r32( arg1, R_EAX );
nkeynes@905
    87
    }
nkeynes@953
    88
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
    89
    CALL_r32(R_ECX);
nkeynes@905
    90
}
nkeynes@905
    91
nkeynes@953
    92
static inline void call_func2_r32( int addr_reg, int arg1, int arg2 )
nkeynes@953
    93
{
nkeynes@953
    94
    if( arg2 != R_EDX ) {
nkeynes@953
    95
        MOV_r32_r32( arg2, R_EDX );
nkeynes@953
    96
    }
nkeynes@953
    97
    if( arg1 != R_EAX ) {
nkeynes@953
    98
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
    99
    }
nkeynes@953
   100
    CALL_r32(addr_reg);
nkeynes@953
   101
}
nkeynes@953
   102
nkeynes@953
   103
static inline void call_func2_r32disp8( int preg, uint32_t disp8, int arg1, int arg2 )
nkeynes@953
   104
{
nkeynes@953
   105
    if( arg2 != R_EDX ) {
nkeynes@953
   106
        MOV_r32_r32( arg2, R_EDX );
nkeynes@953
   107
    }
nkeynes@953
   108
    if( arg1 != R_EAX ) {
nkeynes@953
   109
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
   110
    }
nkeynes@953
   111
    CALL_r32disp8(preg, disp8);
nkeynes@953
   112
}
nkeynes@953
   113
nkeynes@953
   114
static inline void call_func2_r32disp8_exc( int preg, uint32_t disp8, int arg1, int arg2, int pc )
nkeynes@953
   115
{
nkeynes@953
   116
    if( arg2 != R_EDX ) {
nkeynes@953
   117
        MOV_r32_r32( arg2, R_EDX );
nkeynes@953
   118
    }
nkeynes@953
   119
    if( arg1 != R_EAX ) {
nkeynes@953
   120
        MOV_r32_r32( arg1, R_EAX );
nkeynes@953
   121
    }
nkeynes@953
   122
    MOV_backpatch_esp8( 0 );
nkeynes@953
   123
    CALL_r32disp8(preg, disp8);
nkeynes@953
   124
}
nkeynes@953
   125
nkeynes@953
   126
nkeynes@953
   127
nkeynes@927
   128
static inline void call_func1_exc( void *ptr, int arg1, int pc )
nkeynes@927
   129
{
nkeynes@927
   130
    if( arg1 != R_EAX ) {
nkeynes@927
   131
        MOV_r32_r32( arg1, R_EAX );
nkeynes@927
   132
    }
nkeynes@927
   133
    load_exc_backpatch(R_EDX);
nkeynes@953
   134
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
   135
    CALL_r32(R_ECX);
nkeynes@927
   136
}   
nkeynes@927
   137
nkeynes@927
   138
static inline void call_func2_exc( void *ptr, int arg1, int arg2, int pc )
nkeynes@927
   139
{
nkeynes@927
   140
    if( arg2 != R_EDX ) {
nkeynes@927
   141
        MOV_r32_r32( arg2, R_EDX );
nkeynes@927
   142
    }
nkeynes@927
   143
    if( arg1 != R_EAX ) {
nkeynes@927
   144
        MOV_r32_r32( arg1, R_EAX );
nkeynes@927
   145
    }
nkeynes@953
   146
    MOV_backpatch_esp8(0);
nkeynes@953
   147
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
   148
    CALL_r32(R_ECX);
nkeynes@927
   149
}
nkeynes@927
   150
nkeynes@905
   151
#else
nkeynes@539
   152
static inline void call_func1( void *ptr, int arg1 )
nkeynes@539
   153
{
nkeynes@926
   154
    SUB_imm8s_r32( 12, R_ESP );
nkeynes@539
   155
    PUSH_r32(arg1);
nkeynes@953
   156
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
   157
    CALL_r32(R_ECX);
nkeynes@926
   158
    ADD_imm8s_r32( 16, R_ESP );
nkeynes@539
   159
}
nkeynes@539
   160
nkeynes@539
   161
static inline void call_func2( void *ptr, int arg1, int arg2 )
nkeynes@539
   162
{
nkeynes@926
   163
    SUB_imm8s_r32( 8, R_ESP );
nkeynes@539
   164
    PUSH_r32(arg2);
nkeynes@539
   165
    PUSH_r32(arg1);
nkeynes@953
   166
    load_imm32(R_ECX, (uint32_t)ptr);
nkeynes@953
   167
    CALL_r32(R_ECX);
nkeynes@926
   168
    ADD_imm8s_r32( 16, R_ESP );
nkeynes@539
   169
}
nkeynes@926
   170
nkeynes@905
   171
#endif
nkeynes@539
   172
nkeynes@539
   173
/**
nkeynes@539
   174
 * Emit the 'start of block' assembly. Sets up the stack frame and save
nkeynes@539
   175
 * SI/DI as required
nkeynes@926
   176
 * Allocates 8 bytes for local variables, which also has the convenient
nkeynes@926
   177
 * side-effect of aligning the stack.
nkeynes@539
   178
 */
nkeynes@901
   179
void enter_block( ) 
nkeynes@539
   180
{
nkeynes@539
   181
    PUSH_r32(R_EBP);
nkeynes@669
   182
    load_ptr( R_EBP, ((uint8_t *)&sh4r) + 128 );
nkeynes@926
   183
    SUB_imm8s_r32( 8, R_ESP ); 
nkeynes@926
   184
}
nkeynes@736
   185
nkeynes@926
   186
static inline void exit_block( )
nkeynes@926
   187
{
nkeynes@926
   188
    ADD_imm8s_r32( 8, R_ESP );
nkeynes@926
   189
    POP_r32(R_EBP);
nkeynes@926
   190
    RET();
nkeynes@539
   191
}
nkeynes@539
   192
nkeynes@539
   193
/**
nkeynes@926
   194
 * Exit the block with sh4r.new_pc written with the target pc
nkeynes@539
   195
 */
nkeynes@586
   196
void exit_block_pcset( sh4addr_t pc )
nkeynes@539
   197
{
nkeynes@539
   198
    load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@539
   199
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );    // 6
nkeynes@590
   200
    load_spreg( R_EAX, R_PC );
nkeynes@590
   201
    if( sh4_x86.tlb_on ) {
nkeynes@736
   202
        call_func1(xlat_get_code_by_vma,R_EAX);
nkeynes@590
   203
    } else {
nkeynes@736
   204
        call_func1(xlat_get_code,R_EAX);
nkeynes@926
   205
    }
nkeynes@926
   206
    exit_block();
nkeynes@590
   207
}
nkeynes@590
   208
nkeynes@590
   209
/**
nkeynes@590
   210
 * Exit the block with sh4r.new_pc written with the target pc
nkeynes@590
   211
 */
nkeynes@590
   212
void exit_block_newpcset( sh4addr_t pc )
nkeynes@590
   213
{
nkeynes@590
   214
    load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@590
   215
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );    // 6
nkeynes@590
   216
    load_spreg( R_EAX, R_NEW_PC );
nkeynes@590
   217
    store_spreg( R_EAX, R_PC );
nkeynes@586
   218
    if( sh4_x86.tlb_on ) {
nkeynes@736
   219
        call_func1(xlat_get_code_by_vma,R_EAX);
nkeynes@586
   220
    } else {
nkeynes@736
   221
        call_func1(xlat_get_code,R_EAX);
nkeynes@926
   222
    }
nkeynes@926
   223
    exit_block();
nkeynes@539
   224
}
nkeynes@539
   225
nkeynes@586
   226
nkeynes@539
   227
/**
nkeynes@539
   228
 * Exit the block to an absolute PC
nkeynes@539
   229
 */
nkeynes@926
   230
void exit_block_abs( sh4addr_t pc, sh4addr_t endpc )
nkeynes@539
   231
{
nkeynes@539
   232
    load_imm32( R_ECX, pc );                            // 5
nkeynes@539
   233
    store_spreg( R_ECX, REG_OFFSET(pc) );               // 3
nkeynes@586
   234
    if( IS_IN_ICACHE(pc) ) {
nkeynes@736
   235
        MOV_moff32_EAX( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) ); // 5
nkeynes@926
   236
        AND_imm8s_r32( 0xFC, R_EAX ); // 3
nkeynes@586
   237
    } else if( sh4_x86.tlb_on ) {
nkeynes@736
   238
        call_func1(xlat_get_code_by_vma,R_ECX);
nkeynes@586
   239
    } else {
nkeynes@736
   240
        call_func1(xlat_get_code,R_ECX);
nkeynes@586
   241
    }
nkeynes@586
   242
    load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@586
   243
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@926
   244
    exit_block();
nkeynes@586
   245
}
nkeynes@586
   246
nkeynes@586
   247
/**
nkeynes@586
   248
 * Exit the block to a relative PC
nkeynes@586
   249
 */
nkeynes@586
   250
void exit_block_rel( sh4addr_t pc, sh4addr_t endpc )
nkeynes@586
   251
{
nkeynes@586
   252
    load_imm32( R_ECX, pc - sh4_x86.block_start_pc );   // 5
nkeynes@586
   253
    ADD_sh4r_r32( R_PC, R_ECX );
nkeynes@586
   254
    store_spreg( R_ECX, REG_OFFSET(pc) );               // 3
nkeynes@586
   255
    if( IS_IN_ICACHE(pc) ) {
nkeynes@736
   256
        MOV_moff32_EAX( xlat_get_lut_entry(GET_ICACHE_PHYS(pc)) ); // 5
nkeynes@926
   257
        AND_imm8s_r32( 0xFC, R_EAX ); // 3
nkeynes@586
   258
    } else if( sh4_x86.tlb_on ) {
nkeynes@736
   259
        call_func1(xlat_get_code_by_vma,R_ECX);
nkeynes@586
   260
    } else {
nkeynes@736
   261
        call_func1(xlat_get_code,R_ECX);
nkeynes@586
   262
    }
nkeynes@539
   263
    load_imm32( R_ECX, ((endpc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@539
   264
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@926
   265
    exit_block();
nkeynes@539
   266
}
nkeynes@539
   267
nkeynes@539
   268
/**
nkeynes@956
   269
 * Exit unconditionally with a general exception
nkeynes@956
   270
 */
nkeynes@956
   271
void exit_block_exc( int code, sh4addr_t pc )
nkeynes@956
   272
{
nkeynes@956
   273
    load_imm32( R_ECX, pc - sh4_x86.block_start_pc );   // 5
nkeynes@956
   274
    ADD_r32_sh4r( R_ECX, R_PC );
nkeynes@956
   275
    load_imm32( R_ECX, ((pc - sh4_x86.block_start_pc)>>1)*sh4_cpu_period ); // 5
nkeynes@956
   276
    ADD_r32_sh4r( R_ECX, REG_OFFSET(slice_cycle) );     // 6
nkeynes@956
   277
    load_imm32( R_EAX, code );
nkeynes@956
   278
    call_func1( sh4_raise_exception, R_EAX );
nkeynes@956
   279
    
nkeynes@956
   280
    load_spreg( R_EAX, R_PC );
nkeynes@956
   281
    if( sh4_x86.tlb_on ) {
nkeynes@956
   282
        call_func1(xlat_get_code_by_vma,R_EAX);
nkeynes@956
   283
    } else {
nkeynes@956
   284
        call_func1(xlat_get_code,R_EAX);
nkeynes@956
   285
    }
nkeynes@956
   286
nkeynes@956
   287
    exit_block();
nkeynes@956
   288
}    
nkeynes@956
   289
nkeynes@956
   290
/**
nkeynes@539
   291
 * Write the block trailer (exception handling block)
nkeynes@539
   292
 */
nkeynes@539
   293
void sh4_translate_end_block( sh4addr_t pc ) {
nkeynes@539
   294
    if( sh4_x86.branch_taken == FALSE ) {
nkeynes@736
   295
        // Didn't exit unconditionally already, so write the termination here
nkeynes@736
   296
        exit_block_rel( pc, pc );
nkeynes@539
   297
    }
nkeynes@539
   298
    if( sh4_x86.backpatch_posn != 0 ) {
nkeynes@736
   299
        unsigned int i;
nkeynes@736
   300
        // Raise exception
nkeynes@736
   301
        uint8_t *end_ptr = xlat_output;
nkeynes@736
   302
        MOV_r32_r32( R_EDX, R_ECX );
nkeynes@736
   303
        ADD_r32_r32( R_EDX, R_ECX );
nkeynes@736
   304
        ADD_r32_sh4r( R_ECX, R_PC );
nkeynes@736
   305
        MOV_moff32_EAX( &sh4_cpu_period );
nkeynes@736
   306
        MUL_r32( R_EDX );
nkeynes@736
   307
        ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
nkeynes@539
   308
nkeynes@926
   309
        POP_r32(R_EAX);
nkeynes@907
   310
        call_func1( sh4_raise_exception, R_EAX );
nkeynes@736
   311
        load_spreg( R_EAX, R_PC );
nkeynes@736
   312
        if( sh4_x86.tlb_on ) {
nkeynes@736
   313
            call_func1(xlat_get_code_by_vma,R_EAX);
nkeynes@736
   314
        } else {
nkeynes@736
   315
            call_func1(xlat_get_code,R_EAX);
nkeynes@736
   316
        }
nkeynes@926
   317
        exit_block();
nkeynes@539
   318
nkeynes@736
   319
        // Exception already raised - just cleanup
nkeynes@736
   320
        uint8_t *preexc_ptr = xlat_output;
nkeynes@736
   321
        MOV_r32_r32( R_EDX, R_ECX );
nkeynes@736
   322
        ADD_r32_r32( R_EDX, R_ECX );
nkeynes@736
   323
        ADD_r32_sh4r( R_ECX, R_SPC );
nkeynes@736
   324
        MOV_moff32_EAX( &sh4_cpu_period );
nkeynes@736
   325
        MUL_r32( R_EDX );
nkeynes@736
   326
        ADD_r32_sh4r( R_EAX, REG_OFFSET(slice_cycle) );
nkeynes@736
   327
        load_spreg( R_EAX, R_PC );
nkeynes@736
   328
        if( sh4_x86.tlb_on ) {
nkeynes@736
   329
            call_func1(xlat_get_code_by_vma,R_EAX);
nkeynes@736
   330
        } else {
nkeynes@736
   331
            call_func1(xlat_get_code,R_EAX);
nkeynes@736
   332
        }
nkeynes@926
   333
        exit_block();
nkeynes@586
   334
nkeynes@736
   335
        for( i=0; i< sh4_x86.backpatch_posn; i++ ) {
nkeynes@736
   336
            uint32_t *fixup_addr = (uint32_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset];
nkeynes@736
   337
            if( sh4_x86.backpatch_list[i].exc_code < 0 ) {
nkeynes@927
   338
                if( sh4_x86.backpatch_list[i].exc_code == -2 ) {
nkeynes@927
   339
                    *fixup_addr = (uint32_t)xlat_output;
nkeynes@927
   340
                } else {
nkeynes@927
   341
                    *fixup_addr += xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4;
nkeynes@927
   342
                }
nkeynes@736
   343
                load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount );
nkeynes@736
   344
                int rel = preexc_ptr - xlat_output;
nkeynes@736
   345
                JMP_rel(rel);
nkeynes@736
   346
            } else {
nkeynes@927
   347
                *fixup_addr += xlat_output - (uint8_t *)&xlat_current_block->code[sh4_x86.backpatch_list[i].fixup_offset] - 4;
nkeynes@736
   348
                PUSH_imm32( sh4_x86.backpatch_list[i].exc_code );
nkeynes@736
   349
                load_imm32( R_EDX, sh4_x86.backpatch_list[i].fixup_icount );
nkeynes@736
   350
                int rel = end_ptr - xlat_output;
nkeynes@736
   351
                JMP_rel(rel);
nkeynes@736
   352
            }
nkeynes@736
   353
        }
nkeynes@539
   354
    }
nkeynes@539
   355
}
nkeynes@539
   356
nkeynes@926
   357
nkeynes@899
   358
/**
nkeynes@899
   359
 * The unwind methods only work if we compiled with DWARF2 frame information
nkeynes@899
   360
 * (ie -fexceptions), otherwise we have to use the direct frame scan.
nkeynes@899
   361
 */
nkeynes@899
   362
#ifdef HAVE_EXCEPTIONS
nkeynes@899
   363
#include <unwind.h>
nkeynes@899
   364
nkeynes@899
   365
struct UnwindInfo {
nkeynes@926
   366
    uintptr_t block_start;
nkeynes@926
   367
    uintptr_t block_end;
nkeynes@926
   368
    void *pc;
nkeynes@899
   369
};
nkeynes@899
   370
nkeynes@899
   371
_Unwind_Reason_Code xlat_check_frame( struct _Unwind_Context *context, void *arg )
nkeynes@899
   372
{
nkeynes@926
   373
    struct UnwindInfo *info = arg;
nkeynes@926
   374
    void *pc = (void *)_Unwind_GetIP(context);
nkeynes@926
   375
    if( ((uintptr_t)pc) >= info->block_start && ((uintptr_t)pc) < info->block_end ) {
nkeynes@926
   376
        info->pc = pc;
nkeynes@899
   377
        return _URC_NORMAL_STOP;
nkeynes@899
   378
    }
nkeynes@899
   379
nkeynes@899
   380
    return _URC_NO_REASON;
nkeynes@899
   381
}
nkeynes@899
   382
nkeynes@906
   383
void *xlat_get_native_pc( void *code, uint32_t code_size )
nkeynes@899
   384
{
nkeynes@899
   385
    struct _Unwind_Exception exc;
nkeynes@899
   386
    struct UnwindInfo info;
nkeynes@899
   387
nkeynes@926
   388
    info.pc = NULL;
nkeynes@926
   389
    info.block_start = (uintptr_t)code;
nkeynes@926
   390
    info.block_end = info.block_start + code_size;
nkeynes@899
   391
    void *result = NULL;
nkeynes@899
   392
    _Unwind_Backtrace( xlat_check_frame, &info );
nkeynes@926
   393
    return info.pc;
nkeynes@899
   394
}
nkeynes@899
   395
#else 
nkeynes@906
   396
void *xlat_get_native_pc( void *code, uint32_t code_size )
nkeynes@586
   397
{
nkeynes@586
   398
    void *result = NULL;
nkeynes@586
   399
    asm(
nkeynes@736
   400
        "mov %%ebp, %%eax\n\t"
nkeynes@736
   401
        "mov $0x8, %%ecx\n\t"
nkeynes@736
   402
        "mov %1, %%edx\n"
nkeynes@736
   403
        "frame_loop: test %%eax, %%eax\n\t"
nkeynes@736
   404
        "je frame_not_found\n\t"
nkeynes@736
   405
        "cmp (%%eax), %%edx\n\t"
nkeynes@736
   406
        "je frame_found\n\t"
nkeynes@736
   407
        "sub $0x1, %%ecx\n\t"
nkeynes@736
   408
        "je frame_not_found\n\t"
nkeynes@736
   409
        "movl (%%eax), %%eax\n\t"
nkeynes@736
   410
        "jmp frame_loop\n"
nkeynes@736
   411
        "frame_found: movl 0x4(%%eax), %0\n"
nkeynes@736
   412
        "frame_not_found:"
nkeynes@736
   413
        : "=r" (result)
nkeynes@736
   414
        : "r" (((uint8_t *)&sh4r) + 128 )
nkeynes@736
   415
        : "eax", "ecx", "edx" );
nkeynes@586
   416
    return result;
nkeynes@586
   417
}
nkeynes@899
   418
#endif
nkeynes@586
   419
nkeynes@926
   420
#endif /* !lxdream_ia32mac.h */
nkeynes@539
   421
nkeynes@539
   422
.