filename | src/sh4/sh4core.h |
changeset | 374:8f80a795513e |
prev | 369:4b4223e7d720 |
next | 378:f10fbdd4e24b |
author | nkeynes |
date | Tue Sep 11 02:14:46 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Cache the pointer to the last FR bank (speeds fp ops up by about 10%) Implement experimental fix for FLOAT/FTRC Make read/write sr functions non-static (share with translator) Much more translator WIP |
view | annotate | diff | log | raw |
1 /**
2 * $Id: sh4core.h,v 1.22 2007-09-11 02:14:46 nkeynes Exp $
3 *
4 * This file defines the internal functions exported/used by the SH4 core,
5 * except 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 */
20 #ifndef sh4core_H
21 #define sh4core_H 1
23 #include <glib/gtypes.h>
24 #include <stdint.h>
25 #include <stdio.h>
27 #ifdef __cplusplus
28 extern "C" {
29 #if 0
30 }
31 #endif
32 #endif
35 /**
36 * SH4 is running normally
37 */
38 #define SH4_STATE_RUNNING 1
39 /**
40 * SH4 is not executing instructions but all peripheral modules are still
41 * running
42 */
43 #define SH4_STATE_SLEEP 2
44 /**
45 * SH4 is not executing instructions, DMAC is halted, but all other peripheral
46 * modules are still running
47 */
48 #define SH4_STATE_DEEP_SLEEP 3
49 /**
50 * SH4 is not executing instructions and all peripheral modules are also
51 * stopped. As close as you can get to powered-off without actually being
52 * off.
53 */
54 #define SH4_STATE_STANDBY 4
56 #define PENDING_IRQ 1
57 #define PENDING_EVENT 2
59 struct sh4_registers {
60 uint32_t r[16];
61 uint32_t sr, pr, pc, fpscr;
62 uint32_t t, m, q, s; /* really boolean - 0 or 1 */
63 int32_t fpul;
64 float *fr_bank;
65 float fr[2][16];
66 uint64_t mac;
67 uint32_t gbr, ssr, spc, sgr, dbr, vbr;
69 uint32_t r_bank[8]; /* hidden banked registers */
70 int32_t store_queue[16]; /* technically 2 banks of 32 bytes */
72 uint32_t new_pc; /* Not a real register, but used to handle delay slots */
73 uint32_t event_pending; /* slice cycle time of the next pending event, or FFFFFFFF
74 when no events are pending */
75 uint32_t event_types; /* bit 0 = IRQ pending, bit 1 = general event pending */
76 int in_delay_slot; /* flag to indicate the current instruction is in
77 * a delay slot (certain rules apply) */
78 uint32_t slice_cycle; /* Current nanosecond within the timeslice */
79 int sh4_state; /* Current power-on state (one of the SH4_STATE_* values ) */
80 };
82 extern struct sh4_registers sh4r;
84 /* Public functions */
86 void sh4_init( void );
87 void sh4_reset( void );
88 void sh4_run( void );
89 void sh4_runto( uint32_t pc, uint32_t count );
90 void sh4_runfor( uint32_t count );
91 int sh4_isrunning( void );
92 void sh4_stop( void );
93 void sh4_set_pc( int );
94 gboolean sh4_execute_instruction( void );
95 gboolean sh4_raise_exception( int );
96 gboolean sh4_raise_slot_exception( int, int );
97 gboolean sh4_raise_tlb_exception( int );
98 void sh4_set_breakpoint( uint32_t pc, int type );
99 gboolean sh4_clear_breakpoint( uint32_t pc, int type );
100 int sh4_get_breakpoint( uint32_t pc );
102 #define BREAK_ONESHOT 1
103 #define BREAK_PERM 2
105 /* SH4 Memory */
106 int32_t sh4_read_long( uint32_t addr );
107 int32_t sh4_read_word( uint32_t addr );
108 int32_t sh4_read_byte( uint32_t addr );
109 void sh4_write_long( uint32_t addr, uint32_t val );
110 void sh4_write_word( uint32_t addr, uint32_t val );
111 void sh4_write_byte( uint32_t addr, uint32_t val );
112 int32_t sh4_read_phys_word( uint32_t addr );
113 void sh4_flush_store_queue( uint32_t addr );
115 /* SH4 Support methods */
116 uint32_t sh4_read_sr(void);
117 void sh4_write_sr(uint32_t val);
119 /* Peripheral functions */
120 void CPG_reset( void );
121 void TMU_run_slice( uint32_t );
122 void TMU_update_clocks( void );
123 void TMU_reset( void );
124 void TMU_save_state( FILE * );
125 int TMU_load_state( FILE * );
126 void DMAC_reset( void );
127 void DMAC_run_slice( uint32_t );
128 void DMAC_save_state( FILE * );
129 int DMAC_load_state( FILE * );
130 void SCIF_reset( void );
131 void SCIF_run_slice( uint32_t );
132 void SCIF_save_state( FILE *f );
133 int SCIF_load_state( FILE *f );
134 void INTC_reset( void );
135 void INTC_save_state( FILE *f );
136 int INTC_load_state( FILE *f );
137 void MMU_init( void );
138 void MMU_reset( void );
139 void MMU_save_state( FILE *f );
140 int MMU_load_state( FILE *f );
142 #define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
143 #define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
144 #define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
145 #define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
146 #define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
147 #define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
149 /* Status Register (SR) bits */
150 #define SR_MD 0x40000000 /* Processor mode ( User=0, Privileged=1 ) */
151 #define SR_RB 0x20000000 /* Register bank (priviledged mode only) */
152 #define SR_BL 0x10000000 /* Exception/interupt block (1 = masked) */
153 #define SR_FD 0x00008000 /* FPU disable */
154 #define SR_M 0x00000200
155 #define SR_Q 0x00000100
156 #define SR_IMASK 0x000000F0 /* Interrupt mask level */
157 #define SR_S 0x00000002 /* Saturation operation for MAC instructions */
158 #define SR_T 0x00000001 /* True/false or carry/borrow */
159 #define SR_MASK 0x700083F3
160 #define SR_MQSTMASK 0xFFFFFCFC /* Mask to clear the flags we're keeping separately */
162 #define IS_SH4_PRIVMODE() (sh4r.sr&SR_MD)
163 #define SH4_INTMASK() ((sh4r.sr&SR_IMASK)>>4)
164 #define SH4_EVENT_PENDING() (sh4r.event_pending <= sh4r.slice_cycle && !sh4r.in_delay_slot)
166 #define FPSCR_FR 0x00200000 /* FPU register bank */
167 #define FPSCR_SZ 0x00100000 /* FPU transfer size (0=32 bits, 1=64 bits) */
168 #define FPSCR_PR 0x00080000 /* Precision (0=32 bites, 1=64 bits) */
169 #define FPSCR_DN 0x00040000 /* Denormalization mode (1 = treat as 0) */
170 #define FPSCR_CAUSE 0x0003F000
171 #define FPSCR_ENABLE 0x00000F80
172 #define FPSCR_FLAG 0x0000007C
173 #define FPSCR_RM 0x00000003 /* Rounding mode (0=nearest, 1=to zero) */
175 #define IS_FPU_DOUBLEPREC() (sh4r.fpscr&FPSCR_PR)
176 #define IS_FPU_DOUBLESIZE() (sh4r.fpscr&FPSCR_SZ)
177 #define IS_FPU_ENABLED() ((sh4r.sr&SR_FD)==0)
179 #define FR(x) sh4r.fr_bank[(x)^1]
180 #define DRF(x) ((double *)sh4r.fr_bank)[x]
181 #define XF(x) sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21][(x)^1]
182 #define XDR(x) ((double *)(sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21]))[x]
183 #define DRb(x,b) ((double *)(sh4r.fr[((b ? (~sh4r.fpscr) : sh4r.fpscr)&FPSCR_FR)>>21]))[x]
184 #define DR(x) DRb((x>>1), (x&1))
185 #define FPULf *((float *)&sh4r.fpul)
186 #define FPULi (sh4r.fpul)
188 /* CPU-generated exception code/vector pairs */
189 #define EXC_POWER_RESET 0x000 /* vector special */
190 #define EXC_MANUAL_RESET 0x020
191 #define EXC_DATA_ADDR_READ 0x0E0
192 #define EXC_DATA_ADDR_WRITE 0x100
193 #define EXC_SLOT_ILLEGAL 0x1A0
194 #define EXC_ILLEGAL 0x180
195 #define EXC_TRAP 0x160
196 #define EXC_FPU_DISABLED 0x800
197 #define EXC_SLOT_FPU_DISABLED 0x820
199 /* Exceptions (for use with sh4_raise_exception) */
201 #define EX_ILLEGAL_INSTRUCTION 0x180, 0x100
202 #define EX_SLOT_ILLEGAL 0x1A0, 0x100
203 #define EX_TLB_MISS_READ 0x040, 0x400
204 #define EX_TLB_MISS_WRITE 0x060, 0x400
205 #define EX_INIT_PAGE_WRITE 0x080, 0x100
206 #define EX_TLB_PROT_READ 0x0A0, 0x100
207 #define EX_TLB_PROT_WRITE 0x0C0, 0x100
208 #define EX_DATA_ADDR_READ 0x0E0, 0x100
209 #define EX_DATA_ADDR_WRITE 0x100, 0x100
210 #define EX_FPU_EXCEPTION 0x120, 0x100
211 #define EX_TRAPA 0x160, 0x100
212 #define EX_BREAKPOINT 0x1E0, 0x100
213 #define EX_FPU_DISABLED 0x800, 0x100
214 #define EX_SLOT_FPU_DISABLED 0x820, 0x100
216 #define SH4_WRITE_STORE_QUEUE(addr,val) sh4r.store_queue[(addr>>2)&0xF] = val;
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif
.