Search
lxdream.org :: lxdream/src/sh4/sh4trans.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.c
changeset 359:c588dce7ebde
next368:36fac4c42322
author nkeynes
date Thu Aug 23 12:33:27 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Commit decoder generator
Translator work in progress
Fix mac.l, mac.w in emu core
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/sh4/sh4trans.c Thu Aug 23 12:33:27 2007 +0000
1.3 @@ -0,0 +1,105 @@
1.4 +/**
1.5 + * $Id: sh4trans.c,v 1.1 2007-08-23 12:33:27 nkeynes Exp $
1.6 + *
1.7 + * SH4 translation core module. This part handles the non-target-specific
1.8 + * section of the translation.
1.9 + *
1.10 + * Copyright (c) 2005 Nathan Keynes.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + */
1.22 +
1.23 +#include "sh4core.h"
1.24 +#include "sh4trans.h"
1.25 +#include "xltcache.h"
1.26 +
1.27 +/**
1.28 + * Execute a timeslice using translated code only (ie translate/execute loop)
1.29 + * Note this version does not support breakpoints
1.30 + */
1.31 +uint32_t sh4_xlat_run_slice( uint32_t nanosecs )
1.32 +{
1.33 + int i, result = 1;
1.34 + sh4r.slice_cycle = 0;
1.35 +
1.36 + if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
1.37 + if( sh4r.event_pending < nanosecs ) {
1.38 + sh4r.sh4_state = SH4_STATE_RUNNING;
1.39 + sh4r.slice_cycle = sh4r.event_pending;
1.40 + }
1.41 + }
1.42 +
1.43 + for( ; sh4r.slice_cycle < nanosecs && result != 0; sh4r.slice_cycle ) {
1.44 + if( SH4_EVENT_PENDING() ) {
1.45 + if( sh4r.event_types & PENDING_EVENT ) {
1.46 + event_execute();
1.47 + }
1.48 + /* Eventq execute may (quite likely) deliver an immediate IRQ */
1.49 + if( sh4r.event_types & PENDING_IRQ ) {
1.50 + sh4_accept_interrupt();
1.51 + }
1.52 + }
1.53 +
1.54 + int (*code)() = xlat_get_code(sh4r.pc);
1.55 + if( code == NULL ) {
1.56 + code = sh4_translate_basic_block( sh4r.pc );
1.57 + }
1.58 + result = code();
1.59 + sh4r.slice_cycle += result;
1.60 + }
1.61 +
1.62 + /* If we aborted early, but the cpu is still technically running,
1.63 + * we're doing a hard abort - cut the timeslice back to what we
1.64 + * actually executed
1.65 + */
1.66 + if( sh4r.slice_cycle < nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
1.67 + nanosecs = sh4r.slice_cycle;
1.68 + }
1.69 + if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
1.70 + TMU_run_slice( nanosecs );
1.71 + SCIF_run_slice( nanosecs );
1.72 + }
1.73 + return nanosecs;
1.74 +}
1.75 +
1.76 +uint8_t *xlat_output;
1.77 +
1.78 +/**
1.79 + * Translate a linear basic block, ie all instructions from the start address
1.80 + * (inclusive) until the next branch/jump instruction or the end of the page
1.81 + * is reached.
1.82 + * @return the address of the translated block
1.83 + * eg due to lack of buffer space.
1.84 + */
1.85 +void * sh4_translate_basic_block( sh4addr_t start )
1.86 +{
1.87 + uint32_t pc = start;
1.88 + int done;
1.89 + xlat_cache_block_t block = xlat_start_block( start );
1.90 + xlat_output = (uint8_t *)block->code;
1.91 + uint8_t *eob = xlat_output + block->size;
1.92 + sh4_translate_begin_block();
1.93 +
1.94 + while( (done = sh4_x86_translate_instruction( pc )) == 0 ) {
1.95 + if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
1.96 + uint8_t *oldstart = block->code;
1.97 + block = xlat_extend_block();
1.98 + xlat_output = block->code + (xlat_output - oldstart);
1.99 + eob = block->code + block->size;
1.100 + }
1.101 + pc += 2;
1.102 + }
1.103 + sh4_translate_end_block(done);
1.104 + xlat_commit_block( xlat_output - block->size, pc-start );
1.105 + return block->code;
1.106 +}
1.107 +
1.108 +
.