Search
lxdream.org :: lxdream/src/sh4/sh4core.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.h
changeset 564:dc7b5ffb0535
prev561:533f6b478071
next569:a1c49e1e8776
author nkeynes
date Tue Jan 01 08:37:26 2008 +0000 (14 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Refactor sh4core.h to extract the "public" material into a new sh4.h
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@10
     3
 * 
nkeynes@54
     4
 * This file defines the internal functions exported/used by the SH4 core, 
nkeynes@54
     5
 * except 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@30
    19
nkeynes@1
    20
#ifndef sh4core_H
nkeynes@1
    21
#define sh4core_H 1
nkeynes@1
    22
nkeynes@27
    23
#include <glib/gtypes.h>
nkeynes@1
    24
#include <stdint.h>
nkeynes@23
    25
#include <stdio.h>
nkeynes@378
    26
#include "mem.h"
nkeynes@564
    27
#include "sh4/sh4.h"
nkeynes@1
    28
nkeynes@1
    29
#ifdef __cplusplus
nkeynes@1
    30
extern "C" {
nkeynes@1
    31
#endif
nkeynes@1
    32
nkeynes@564
    33
/* Breakpoint data structure */
nkeynes@378
    34
extern struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
nkeynes@378
    35
extern int sh4_breakpoint_count;
nkeynes@378
    36
nkeynes@564
    37
/* SH4 module functions */
nkeynes@1
    38
void sh4_init( void );
nkeynes@1
    39
void sh4_reset( void );
nkeynes@1
    40
void sh4_run( void );
nkeynes@1
    41
void sh4_stop( void );
nkeynes@564
    42
nkeynes@564
    43
/* SH4 peripheral module functions */
nkeynes@564
    44
void CPG_reset( void );
nkeynes@564
    45
void DMAC_reset( void );
nkeynes@564
    46
void DMAC_run_slice( uint32_t );
nkeynes@564
    47
void DMAC_save_state( FILE * );
nkeynes@564
    48
int DMAC_load_state( FILE * );
nkeynes@564
    49
void INTC_reset( void );
nkeynes@564
    50
void INTC_save_state( FILE *f );
nkeynes@564
    51
int INTC_load_state( FILE *f );
nkeynes@564
    52
void MMU_init( void );
nkeynes@564
    53
void MMU_reset( void );
nkeynes@564
    54
void MMU_save_state( FILE *f );
nkeynes@564
    55
int MMU_load_state( FILE *f );
nkeynes@564
    56
void MMU_ldtlb();
nkeynes@564
    57
void SCIF_reset( void );
nkeynes@564
    58
void SCIF_run_slice( uint32_t );
nkeynes@564
    59
void SCIF_save_state( FILE *f );
nkeynes@564
    60
int SCIF_load_state( FILE *f );
nkeynes@564
    61
void SCIF_update_line_speed(void);
nkeynes@564
    62
void TMU_reset( void );
nkeynes@564
    63
void TMU_run_slice( uint32_t );
nkeynes@564
    64
void TMU_save_state( FILE * );
nkeynes@564
    65
int TMU_load_state( FILE * );
nkeynes@564
    66
void TMU_update_clocks( void );
nkeynes@564
    67
nkeynes@564
    68
/* SH4 instruction support methods */
nkeynes@401
    69
void sh4_sleep( void );
nkeynes@401
    70
void sh4_fsca( uint32_t angle, float *fr );
nkeynes@401
    71
void sh4_ftrv( float *fv, float *xmtrx );
nkeynes@564
    72
uint32_t sh4_read_sr(void);
nkeynes@564
    73
void sh4_write_sr(uint32_t val);
nkeynes@401
    74
void signsat48(void);
nkeynes@378
    75
nkeynes@10
    76
/* SH4 Memory */
nkeynes@559
    77
uint64_t mmu_vma_to_phys_read( sh4addr_t addr );
nkeynes@559
    78
uint64_t mmu_vma_to_phys_write( sh4addr_t addr );
nkeynes@559
    79
uint64_t mmu_vma_to_phys_exec( sh4addr_t addr );
nkeynes@559
    80
nkeynes@527
    81
int64_t sh4_read_quad( sh4addr_t addr );
nkeynes@559
    82
int64_t sh4_read_long( sh4addr_t addr );
nkeynes@559
    83
int64_t sh4_read_word( sh4addr_t addr );
nkeynes@559
    84
int64_t sh4_read_byte( sh4addr_t addr );
nkeynes@527
    85
void sh4_write_quad( sh4addr_t addr, uint64_t val );
nkeynes@559
    86
int32_t sh4_write_long( sh4addr_t addr, uint32_t val );
nkeynes@559
    87
int32_t sh4_write_word( sh4addr_t addr, uint32_t val );
nkeynes@559
    88
int32_t sh4_write_byte( sh4addr_t addr, uint32_t val );
nkeynes@527
    89
int32_t sh4_read_phys_word( sh4addr_t addr );
nkeynes@527
    90
void sh4_flush_store_queue( sh4addr_t addr );
nkeynes@559
    91
sh4ptr_t sh4_get_region_by_vma( sh4addr_t addr );
nkeynes@10
    92
nkeynes@564
    93
/* SH4 Exceptions */
nkeynes@564
    94
#define EXC_POWER_RESET     0x000 /* reset vector */
nkeynes@564
    95
#define EXC_MANUAL_RESET    0x020 /* reset vector */
nkeynes@564
    96
#define EXC_TLB_MISS_READ   0x040 /* TLB vector */
nkeynes@564
    97
#define EXC_TLB_MISS_WRITE  0x060 /* TLB vector */
nkeynes@564
    98
#define EXC_INIT_PAGE_WRITE 0x080
nkeynes@564
    99
#define EXC_TLB_PROT_READ   0x0A0
nkeynes@564
   100
#define EXC_TLB_PROT_WRITE  0x0C0
nkeynes@564
   101
#define EXC_DATA_ADDR_READ  0x0E0
nkeynes@564
   102
#define EXC_DATA_ADDR_WRITE 0x100
nkeynes@564
   103
#define EXC_TLB_MULTI_HIT   0x140
nkeynes@564
   104
#define EXC_SLOT_ILLEGAL    0x1A0
nkeynes@564
   105
#define EXC_ILLEGAL         0x180
nkeynes@564
   106
#define EXC_TRAP            0x160
nkeynes@564
   107
#define EXC_FPU_DISABLED    0x800
nkeynes@564
   108
#define EXC_SLOT_FPU_DISABLED 0x820
nkeynes@374
   109
nkeynes@564
   110
#define EXV_EXCEPTION    0x100  /* General exception vector */
nkeynes@564
   111
#define EXV_TLBMISS      0x400  /* TLB-miss exception vector */
nkeynes@564
   112
#define EXV_INTERRUPT    0x600  /* External interrupt vector */
nkeynes@564
   113
nkeynes@564
   114
gboolean sh4_raise_exception( int );
nkeynes@564
   115
gboolean sh4_raise_reset( int );
nkeynes@564
   116
gboolean sh4_raise_trap( int );
nkeynes@564
   117
gboolean sh4_raise_slot_exception( int, int );
nkeynes@564
   118
gboolean sh4_raise_tlb_exception( int );
nkeynes@564
   119
void sh4_accept_interrupt( void );
nkeynes@1
   120
nkeynes@1
   121
#define SIGNEXT4(n) ((((int32_t)(n))<<28)>>28)
nkeynes@1
   122
#define SIGNEXT8(n) ((int32_t)((int8_t)(n)))
nkeynes@1
   123
#define SIGNEXT12(n) ((((int32_t)(n))<<20)>>20)
nkeynes@1
   124
#define SIGNEXT16(n) ((int32_t)((int16_t)(n)))
nkeynes@1
   125
#define SIGNEXT32(n) ((int64_t)((int32_t)(n)))
nkeynes@1
   126
#define SIGNEXT48(n) ((((int64_t)(n))<<16)>>16)
nkeynes@559
   127
#define ZEROEXT32(n) ((int64_t)((uint64_t)((uint32_t)(n))))
nkeynes@1
   128
nkeynes@1
   129
/* Status Register (SR) bits */
nkeynes@1
   130
#define SR_MD    0x40000000 /* Processor mode ( User=0, Privileged=1 ) */ 
nkeynes@1
   131
#define SR_RB    0x20000000 /* Register bank (priviledged mode only) */
nkeynes@1
   132
#define SR_BL    0x10000000 /* Exception/interupt block (1 = masked) */
nkeynes@1
   133
#define SR_FD    0x00008000 /* FPU disable */
nkeynes@1
   134
#define SR_M     0x00000200
nkeynes@1
   135
#define SR_Q     0x00000100
nkeynes@1
   136
#define SR_IMASK 0x000000F0 /* Interrupt mask level */
nkeynes@1
   137
#define SR_S     0x00000002 /* Saturation operation for MAC instructions */
nkeynes@1
   138
#define SR_T     0x00000001 /* True/false or carry/borrow */
nkeynes@1
   139
#define SR_MASK  0x700083F3
nkeynes@1
   140
#define SR_MQSTMASK 0xFFFFFCFC /* Mask to clear the flags we're keeping separately */
nkeynes@1
   141
nkeynes@1
   142
#define IS_SH4_PRIVMODE() (sh4r.sr&SR_MD)
nkeynes@1
   143
#define SH4_INTMASK() ((sh4r.sr&SR_IMASK)>>4)
nkeynes@265
   144
#define SH4_EVENT_PENDING() (sh4r.event_pending <= sh4r.slice_cycle && !sh4r.in_delay_slot)
nkeynes@1
   145
nkeynes@1
   146
#define FPSCR_FR     0x00200000 /* FPU register bank */
nkeynes@1
   147
#define FPSCR_SZ     0x00100000 /* FPU transfer size (0=32 bits, 1=64 bits) */
nkeynes@1
   148
#define FPSCR_PR     0x00080000 /* Precision (0=32 bites, 1=64 bits) */
nkeynes@1
   149
#define FPSCR_DN     0x00040000 /* Denormalization mode (1 = treat as 0) */
nkeynes@1
   150
#define FPSCR_CAUSE  0x0003F000
nkeynes@1
   151
#define FPSCR_ENABLE 0x00000F80
nkeynes@1
   152
#define FPSCR_FLAG   0x0000007C
nkeynes@1
   153
#define FPSCR_RM     0x00000003 /* Rounding mode (0=nearest, 1=to zero) */
nkeynes@1
   154
nkeynes@1
   155
#define IS_FPU_DOUBLEPREC() (sh4r.fpscr&FPSCR_PR)
nkeynes@1
   156
#define IS_FPU_DOUBLESIZE() (sh4r.fpscr&FPSCR_SZ)
nkeynes@1
   157
#define IS_FPU_ENABLED() ((sh4r.sr&SR_FD)==0)
nkeynes@1
   158
nkeynes@374
   159
#define FR(x) sh4r.fr_bank[(x)^1]
nkeynes@374
   160
#define DRF(x) ((double *)sh4r.fr_bank)[x]
nkeynes@84
   161
#define XF(x) sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21][(x)^1]
nkeynes@95
   162
#define XDR(x) ((double *)(sh4r.fr[((~sh4r.fpscr)&FPSCR_FR)>>21]))[x]
nkeynes@95
   163
#define DRb(x,b) ((double *)(sh4r.fr[((b ? (~sh4r.fpscr) : sh4r.fpscr)&FPSCR_FR)>>21]))[x]
nkeynes@359
   164
#define DR(x) DRb((x>>1), (x&1))
nkeynes@359
   165
#define FPULf   *((float *)&sh4r.fpul)
nkeynes@359
   166
#define FPULi    (sh4r.fpul)
nkeynes@359
   167
nkeynes@2
   168
#define SH4_WRITE_STORE_QUEUE(addr,val) sh4r.store_queue[(addr>>2)&0xF] = val;
nkeynes@1
   169
nkeynes@1
   170
#ifdef __cplusplus
nkeynes@1
   171
}
nkeynes@1
   172
#endif
nkeynes@1
   173
#endif
nkeynes@359
   174
.