1.1 --- a/src/sh4/sh4.c Tue Jan 22 09:45:21 2008 +0000
1.2 +++ b/src/sh4/sh4.c Tue Jan 29 10:39:56 2008 +0000
1.5 #define MODULE sh4_module
1.9 #include "dreamcast.h"
1.10 #include "sh4/sh4core.h"
1.12 #include "sh4/intc.h"
1.13 #include "sh4/xltcache.h"
1.14 #include "sh4/sh4stat.h"
1.15 +#include "sh4/sh4trans.h"
1.18 #include "syscall.h"
1.19 @@ -332,16 +334,80 @@
1.24 + * Enter sleep mode (eg by executing a SLEEP instruction).
1.25 + * Sets sh4_state appropriately and ensures any stopping peripheral modules
1.28 void sh4_sleep(void)
1.30 if( MMIO_READ( CPG, STBCR ) & 0x80 ) {
1.31 sh4r.sh4_state = SH4_STATE_STANDBY;
1.32 + /* Bring all running peripheral modules up to date, and then halt them. */
1.33 + TMU_run_slice( sh4r.slice_cycle );
1.34 + SCIF_run_slice( sh4r.slice_cycle );
1.36 - sh4r.sh4_state = SH4_STATE_SLEEP;
1.37 + if( MMIO_READ( CPG, STBCR2 ) & 0x80 ) {
1.38 + sh4r.sh4_state = SH4_STATE_DEEP_SLEEP;
1.39 + /* Halt DMAC but other peripherals still running */
1.42 + sh4r.sh4_state = SH4_STATE_SLEEP;
1.45 + if( sh4_xlat_is_running() ) {
1.46 + sh4_translate_exit( XLAT_EXIT_SLEEP );
1.51 + * Wakeup following sleep mode (IRQ or reset). Sets state back to running,
1.52 + * and restarts any peripheral devices that were stopped.
1.54 +void sh4_wakeup(void)
1.56 + switch( sh4r.sh4_state ) {
1.57 + case SH4_STATE_STANDBY:
1.59 + case SH4_STATE_DEEP_SLEEP:
1.61 + case SH4_STATE_SLEEP:
1.64 + sh4r.sh4_state = SH4_STATE_RUNNING;
1.68 + * Run a time slice (or portion of a timeslice) while the SH4 is sleeping.
1.69 + * Returns when either the SH4 wakes up (interrupt received) or the end of
1.70 + * the slice is reached. Updates sh4.slice_cycle with the exit time and
1.71 + * returns the same value.
1.73 +uint32_t sh4_sleep_run_slice( uint32_t nanosecs )
1.75 + int sleep_state = sh4r.sh4_state;
1.76 + assert( sleep_state != SH4_STATE_RUNNING );
1.77 + while( sh4r.event_pending < nanosecs ) {
1.78 + sh4r.slice_cycle = sh4r.event_pending;
1.79 + if( sh4r.event_types & PENDING_EVENT ) {
1.82 + if( sh4r.event_types & PENDING_IRQ ) {
1.84 + nanosecs = sh4r.event_pending;
1.88 + sh4r.slice_cycle = nanosecs;
1.89 + if( sleep_state != SH4_STATE_STANDBY ) {
1.90 + TMU_run_slice( nanosecs );
1.91 + SCIF_run_slice( nanosecs );
1.93 + return sh4r.slice_cycle;
1.98 * Compute the matrix tranform of fv given the matrix xf.
1.99 * Both fv and xf are word-swapped as per the sh4r.fr banks