Search
lxdream.org :: lxdream/src/sh4/sh4core.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.h
changeset 27:1ef09a52cd1e
prev23:1ec3acd0594d
next30:89b30313d757
author nkeynes
date Sun Dec 25 01:28:39 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Refactor all the GUI bits out of the main directory (except for a couple
lingering temporarily in loader.c
Fix a few timeslice issues
view annotate diff log raw
     1 /**
     2  * $Id: sh4core.h,v 1.5 2005-12-25 01:28:39 nkeynes Exp $
     3  * 
     4  * This file defines the public functions exported by the SH4 core, except
     5  * for disassembly functions defined in sh4dasm.h
     6  *
     7  * Copyright (c) 2005 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  */
    19 #ifndef sh4core_H
    20 #define sh4core_H 1
    22 #include <glib/gtypes.h>
    23 #include <stdint.h>
    24 #include <stdio.h>
    26 #ifdef __cplusplus
    27 extern "C" {
    28 #if 0
    29 }
    30 #endif
    31 #endif
    34 /**
    35  * SH4 is running normally 
    36  */
    37 #define SH4_STATE_RUNNING 1
    38 /**
    39  * SH4 is not executing instructions but all peripheral modules are still
    40  * running
    41  */
    42 #define SH4_STATE_SLEEP 2
    43 /**
    44  * SH4 is not executing instructions, DMAC is halted, but all other peripheral
    45  * modules are still running
    46  */
    47 #define SH4_STATE_DEEP_SLEEP 3
    48 /**
    49  * SH4 is not executing instructions and all peripheral modules are also
    50  * stopped. As close as you can get to powered-off without actually being
    51  * off.
    52  */
    53 #define SH4_STATE_STANDBY 4
    56 struct sh4_registers {
    57     uint32_t r[16];
    58     uint32_t r_bank[8]; /* hidden banked registers */
    59     uint32_t sr, gbr, ssr, spc, sgr, dbr, vbr;
    60     uint32_t pr, pc, fpul, fpscr;
    61     uint64_t mac;
    62     uint32_t m, q, s, t; /* really boolean - 0 or 1 */
    63     float fr[2][16];
    65     int32_t store_queue[16]; /* technically 2 banks of 32 bytes */
    67     uint32_t new_pc; /* Not a real register, but used to handle delay slots */
    68     uint32_t icount; /* Also not a real register, instruction counter */
    69     uint32_t int_pending; /* flag set by the INTC = pending priority level */
    70     int in_delay_slot; /* flag to indicate the current instruction is in
    71                              * a delay slot (certain rules apply) */
    72     int sh4_state; /* Current power-on state (one of the SH4_STATE_* values ) */
    73 };
    75 extern struct sh4_registers sh4r;
    77 /* Public functions */
    79 void sh4_init( void );
    80 void sh4_reset( void );
    81 void sh4_run( void );
    82 void sh4_runto( uint32_t pc, uint32_t count );
    83 void sh4_runfor( uint32_t count );
    84 int sh4_isrunning( void );
    85 void sh4_stop( void );
    86 void sh4_set_pc( int );
    87 gboolean sh4_execute_instruction( void );
    88 void sh4_raise_exception( int, int );
    89 void sh4_set_breakpoint( uint32_t pc, int type );
    91 #define BREAK_ONESHOT 1
    92 #define BREAK_PERM 2
    94 /* SH4 Memory */
    95 int32_t sh4_read_long( uint32_t addr );
    96 int32_t sh4_read_word( uint32_t addr );
    97 int32_t sh4_read_byte( uint32_t addr );
    98 void sh4_write_long( uint32_t addr, uint32_t val );
    99 void sh4_write_word( uint32_t addr, uint32_t val );
   100 void sh4_write_byte( uint32_t addr, uint32_t val );
   101 int32_t sh4_read_phys_word( uint32_t addr );
   103 /* Peripheral functions */
   104 void DMAC_run_slice( int );
   105 void TMU_run_slice( int );
   106 void SCIF_run_slice( int );
   107 void SCIF_save_state( FILE *f );
   108 int SCIF_load_state( FILE *f );
   110 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
   111 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
   112 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
   113 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
   114 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
   115 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
   117 /* Status Register (SR) bits */
   118 #define SR_MD    0x40000000 /* Processor mode ( User=0, Privileged=1 ) */ 
   119 #define SR_RB    0x20000000 /* Register bank (priviledged mode only) */
   120 #define SR_BL    0x10000000 /* Exception/interupt block (1 = masked) */
   121 #define SR_FD    0x00008000 /* FPU disable */
   122 #define SR_M     0x00000200
   123 #define SR_Q     0x00000100
   124 #define SR_IMASK 0x000000F0 /* Interrupt mask level */
   125 #define SR_S     0x00000002 /* Saturation operation for MAC instructions */
   126 #define SR_T     0x00000001 /* True/false or carry/borrow */
   127 #define SR_MASK  0x700083F3
   128 #define SR_MQSTMASK 0xFFFFFCFC /* Mask to clear the flags we're keeping separately */
   130 #define IS_SH4_PRIVMODE() (sh4r.sr&SR_MD)
   131 #define SH4_INTMASK() ((sh4r.sr&SR_IMASK)>>4)
   132 #define SH4_INT_PENDING() (sh4r.int_pending && !sh4r.in_delay_slot)
   134 #define FPSCR_FR     0x00200000 /* FPU register bank */
   135 #define FPSCR_SZ     0x00100000 /* FPU transfer size (0=32 bits, 1=64 bits) */
   136 #define FPSCR_PR     0x00080000 /* Precision (0=32 bites, 1=64 bits) */
   137 #define FPSCR_DN     0x00040000 /* Denormalization mode (1 = treat as 0) */
   138 #define FPSCR_CAUSE  0x0003F000
   139 #define FPSCR_ENABLE 0x00000F80
   140 #define FPSCR_FLAG   0x0000007C
   141 #define FPSCR_RM     0x00000003 /* Rounding mode (0=nearest, 1=to zero) */
   143 #define IS_FPU_DOUBLEPREC() (sh4r.fpscr&FPSCR_PR)
   144 #define IS_FPU_DOUBLESIZE() (sh4r.fpscr&FPSCR_SZ)
   145 #define IS_FPU_ENABLED() ((sh4r.sr&SR_FD)==0)
   147 #define FR sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21]
   148 #define XF sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21]
   150 /* Exceptions (for use with sh4_raise_exception) */
   152 #define EX_ILLEGAL_INSTRUCTION 0x180, 0x100
   153 #define EX_SLOT_ILLEGAL        0x1A0, 0x100
   154 #define EX_TLB_MISS_READ       0x040, 0x400
   155 #define EX_TLB_MISS_WRITE      0x060, 0x400
   156 #define EX_INIT_PAGE_WRITE     0x080, 0x100
   157 #define EX_TLB_PROT_READ       0x0A0, 0x100
   158 #define EX_TLB_PROT_WRITE      0x0C0, 0x100
   159 #define EX_DATA_ADDR_READ      0x0E0, 0x100
   160 #define EX_DATA_ADDR_WRITE     0x100, 0x100
   161 #define EX_FPU_EXCEPTION       0x120, 0x100
   162 #define EX_TRAPA               0x160, 0x100
   163 #define EX_BREAKPOINT          0x1E0, 0x100
   164 #define EX_FPU_DISABLED        0x800, 0x100
   165 #define EX_SLOT_FPU_DISABLED   0x820, 0x100
   167 #define SH4_WRITE_STORE_QUEUE(addr,val) sh4r.store_queue[(addr>>2)&0xF] = val;
   169 #ifdef __cplusplus
   170 }
   171 #endif
   172 #endif
.