Search
lxdream.org :: lxdream/src/sh4/sh4core.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.h
changeset 23:1ec3acd0594d
prev10:c898b37506e0
next27:1ef09a52cd1e
author nkeynes
date Fri Dec 23 11:44:55 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Start of "real" time slices, general structure in place now
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@23
     2
 * $Id: sh4core.h,v 1.4 2005-12-23 11:44:55 nkeynes Exp $
nkeynes@10
     3
 * 
nkeynes@10
     4
 * This file defines the public functions exported by the SH4 core, except
nkeynes@10
     5
 * for disassembly functions defined in sh4dasm.h
nkeynes@10
     6
 *
nkeynes@10
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@10
     8
 *
nkeynes@10
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@10
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@10
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@10
    12
 * (at your option) any later version.
nkeynes@10
    13
 *
nkeynes@10
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@10
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@10
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@10
    17
 * GNU General Public License for more details.
nkeynes@1
    18
 */
nkeynes@1
    19
#ifndef sh4core_H
nkeynes@1
    20
#define sh4core_H 1
nkeynes@1
    21
nkeynes@1
    22
#include <stdint.h>
nkeynes@23
    23
#include <stdio.h>
nkeynes@1
    24
nkeynes@1
    25
#ifdef __cplusplus
nkeynes@1
    26
extern "C" {
nkeynes@1
    27
#if 0
nkeynes@1
    28
}
nkeynes@1
    29
#endif
nkeynes@1
    30
#endif
nkeynes@1
    31
nkeynes@1
    32
struct sh4_registers {
nkeynes@1
    33
    uint32_t r[16];
nkeynes@1
    34
    uint32_t r_bank[8]; /* hidden banked registers */
nkeynes@1
    35
    uint32_t sr, gbr, ssr, spc, sgr, dbr, vbr;
nkeynes@1
    36
    uint32_t pr, pc, fpul, fpscr;
nkeynes@1
    37
    uint64_t mac;
nkeynes@1
    38
    uint32_t m, q, s, t; /* really boolean - 0 or 1 */
nkeynes@1
    39
    float fr[2][16];
nkeynes@1
    40
nkeynes@2
    41
    int32_t store_queue[16]; /* technically 2 banks of 32 bytes */
nkeynes@2
    42
    
nkeynes@1
    43
    uint32_t new_pc; /* Not a real register, but used to handle delay slots */
nkeynes@1
    44
    uint32_t icount; /* Also not a real register, instruction counter */
nkeynes@1
    45
    uint32_t int_pending; /* flag set by the INTC = pending priority level */
nkeynes@2
    46
    int in_delay_slot; /* flag to indicate the current instruction is in
nkeynes@2
    47
                             * a delay slot (certain rules apply) */
nkeynes@1
    48
};
nkeynes@1
    49
nkeynes@1
    50
extern struct sh4_registers sh4r;
nkeynes@1
    51
nkeynes@1
    52
/* Public functions */
nkeynes@1
    53
nkeynes@1
    54
void sh4_init( void );
nkeynes@1
    55
void sh4_reset( void );
nkeynes@1
    56
void sh4_run( void );
nkeynes@1
    57
void sh4_runto( uint32_t pc, uint32_t count );
nkeynes@1
    58
void sh4_runfor( uint32_t count );
nkeynes@1
    59
int sh4_isrunning( void );
nkeynes@1
    60
void sh4_stop( void );
nkeynes@1
    61
void sh4_set_pc( int );
nkeynes@1
    62
void sh4_execute_instruction( void );
nkeynes@1
    63
void sh4_raise_exception( int, int );
nkeynes@23
    64
void sh4_set_breakpoint( uint32_t pc, int type );
nkeynes@23
    65
nkeynes@23
    66
#define BREAK_ONESHOT 1
nkeynes@23
    67
#define BREAK_PERM 2
nkeynes@1
    68
nkeynes@10
    69
/* SH4 Memory */
nkeynes@10
    70
int32_t sh4_read_long( uint32_t addr );
nkeynes@10
    71
int32_t sh4_read_word( uint32_t addr );
nkeynes@10
    72
int32_t sh4_read_byte( uint32_t addr );
nkeynes@10
    73
void sh4_write_long( uint32_t addr, uint32_t val );
nkeynes@10
    74
void sh4_write_word( uint32_t addr, uint32_t val );
nkeynes@10
    75
void sh4_write_byte( uint32_t addr, uint32_t val );
nkeynes@10
    76
int32_t sh4_read_phys_word( uint32_t addr );
nkeynes@10
    77
nkeynes@23
    78
/* Peripheral functions */
nkeynes@23
    79
void DMAC_run_slice( int );
nkeynes@23
    80
void TMU_run_slice( int );
nkeynes@23
    81
void SCIF_run_slice( int );
nkeynes@23
    82
void SCIF_save_state( FILE *f );
nkeynes@23
    83
int SCIF_load_state( FILE *f );
nkeynes@1
    84
nkeynes@1
    85
#define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
nkeynes@1
    86
#define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
nkeynes@1
    87
#define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
nkeynes@1
    88
#define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
nkeynes@1
    89
#define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
nkeynes@1
    90
#define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
nkeynes@1
    91
nkeynes@1
    92
/* Status Register (SR) bits */
nkeynes@1
    93
#define SR_MD    0x40000000 /* Processor mode ( User=0, Privileged=1 ) */ 
nkeynes@1
    94
#define SR_RB    0x20000000 /* Register bank (priviledged mode only) */
nkeynes@1
    95
#define SR_BL    0x10000000 /* Exception/interupt block (1 = masked) */
nkeynes@1
    96
#define SR_FD    0x00008000 /* FPU disable */
nkeynes@1
    97
#define SR_M     0x00000200
nkeynes@1
    98
#define SR_Q     0x00000100
nkeynes@1
    99
#define SR_IMASK 0x000000F0 /* Interrupt mask level */
nkeynes@1
   100
#define SR_S     0x00000002 /* Saturation operation for MAC instructions */
nkeynes@1
   101
#define SR_T     0x00000001 /* True/false or carry/borrow */
nkeynes@1
   102
#define SR_MASK  0x700083F3
nkeynes@1
   103
#define SR_MQSTMASK 0xFFFFFCFC /* Mask to clear the flags we're keeping separately */
nkeynes@1
   104
nkeynes@1
   105
#define IS_SH4_PRIVMODE() (sh4r.sr&SR_MD)
nkeynes@1
   106
#define SH4_INTMASK() ((sh4r.sr&SR_IMASK)>>4)
nkeynes@2
   107
#define SH4_INT_PENDING() (sh4r.int_pending && !sh4r.in_delay_slot)
nkeynes@1
   108
nkeynes@1
   109
#define FPSCR_FR     0x00200000 /* FPU register bank */
nkeynes@1
   110
#define FPSCR_SZ     0x00100000 /* FPU transfer size (0=32 bits, 1=64 bits) */
nkeynes@1
   111
#define FPSCR_PR     0x00080000 /* Precision (0=32 bites, 1=64 bits) */
nkeynes@1
   112
#define FPSCR_DN     0x00040000 /* Denormalization mode (1 = treat as 0) */
nkeynes@1
   113
#define FPSCR_CAUSE  0x0003F000
nkeynes@1
   114
#define FPSCR_ENABLE 0x00000F80
nkeynes@1
   115
#define FPSCR_FLAG   0x0000007C
nkeynes@1
   116
#define FPSCR_RM     0x00000003 /* Rounding mode (0=nearest, 1=to zero) */
nkeynes@1
   117
nkeynes@1
   118
#define IS_FPU_DOUBLEPREC() (sh4r.fpscr&FPSCR_PR)
nkeynes@1
   119
#define IS_FPU_DOUBLESIZE() (sh4r.fpscr&FPSCR_SZ)
nkeynes@1
   120
#define IS_FPU_ENABLED() ((sh4r.sr&SR_FD)==0)
nkeynes@1
   121
nkeynes@1
   122
#define FR sh4r.fr[(sh4r.fpscr&FPSCR_FR)>>21]
nkeynes@2
   123
#define XF sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21]
nkeynes@1
   124
nkeynes@1
   125
/* Exceptions (for use with sh4_raise_exception) */
nkeynes@1
   126
nkeynes@1
   127
#define EX_ILLEGAL_INSTRUCTION 0x180, 0x100
nkeynes@1
   128
#define EX_SLOT_ILLEGAL        0x1A0, 0x100
nkeynes@1
   129
#define EX_TLB_MISS_READ       0x040, 0x400
nkeynes@1
   130
#define EX_TLB_MISS_WRITE      0x060, 0x400
nkeynes@1
   131
#define EX_INIT_PAGE_WRITE     0x080, 0x100
nkeynes@1
   132
#define EX_TLB_PROT_READ       0x0A0, 0x100
nkeynes@1
   133
#define EX_TLB_PROT_WRITE      0x0C0, 0x100
nkeynes@1
   134
#define EX_DATA_ADDR_READ      0x0E0, 0x100
nkeynes@1
   135
#define EX_DATA_ADDR_WRITE     0x100, 0x100
nkeynes@1
   136
#define EX_FPU_EXCEPTION       0x120, 0x100
nkeynes@1
   137
#define EX_TRAPA               0x160, 0x100
nkeynes@1
   138
#define EX_BREAKPOINT          0x1E0, 0x100
nkeynes@1
   139
#define EX_FPU_DISABLED        0x800, 0x100
nkeynes@1
   140
#define EX_SLOT_FPU_DISABLED   0x820, 0x100
nkeynes@1
   141
nkeynes@2
   142
#define SH4_WRITE_STORE_QUEUE(addr,val) sh4r.store_queue[(addr>>2)&0xF] = val;
nkeynes@1
   143
nkeynes@1
   144
#ifdef __cplusplus
nkeynes@1
   145
}
nkeynes@1
   146
#endif
nkeynes@1
   147
#endif
.