nkeynes@586: /** nkeynes@1021: * $Id$ nkeynes@586: * nkeynes@586: * This file defines the public functions and definitions exported by the SH4 nkeynes@586: * modules. nkeynes@586: * nkeynes@586: * Copyright (c) 2005 Nathan Keynes. nkeynes@586: * nkeynes@586: * This program is free software; you can redistribute it and/or modify nkeynes@586: * it under the terms of the GNU General Public License as published by nkeynes@586: * the Free Software Foundation; either version 2 of the License, or nkeynes@586: * (at your option) any later version. nkeynes@586: * nkeynes@586: * This program is distributed in the hope that it will be useful, nkeynes@586: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@586: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@586: * GNU General Public License for more details. nkeynes@586: */ nkeynes@586: nkeynes@586: #ifndef lxdream_sh4_H nkeynes@586: #define lxdream_sh4_H 1 nkeynes@586: nkeynes@586: #include "lxdream.h" nkeynes@586: #include "mem.h" nkeynes@586: nkeynes@586: #ifdef __cplusplus nkeynes@586: extern "C" { nkeynes@586: #endif nkeynes@586: nkeynes@586: nkeynes@586: /** nkeynes@586: * SH4 is running normally nkeynes@586: */ nkeynes@586: #define SH4_STATE_RUNNING 1 nkeynes@586: /** nkeynes@586: * SH4 is not executing instructions but all peripheral modules are still nkeynes@586: * running nkeynes@586: */ nkeynes@586: #define SH4_STATE_SLEEP 2 nkeynes@586: /** nkeynes@586: * SH4 is not executing instructions, DMAC is halted, but all other peripheral nkeynes@586: * modules are still running nkeynes@586: */ nkeynes@586: #define SH4_STATE_DEEP_SLEEP 3 nkeynes@586: /** nkeynes@586: * SH4 is not executing instructions and all peripheral modules are also nkeynes@586: * stopped. As close as you can get to powered-off without actually being nkeynes@586: * off. nkeynes@586: */ nkeynes@586: #define SH4_STATE_STANDBY 4 nkeynes@586: nkeynes@586: /** nkeynes@586: * sh4r.event_types flag indicating a pending IRQ nkeynes@586: */ nkeynes@586: #define PENDING_IRQ 1 nkeynes@586: nkeynes@586: /** nkeynes@586: * sh4r.event_types flag indicating a pending event (from the event queue) nkeynes@586: */ nkeynes@586: #define PENDING_EVENT 2 nkeynes@586: nkeynes@586: /** nkeynes@586: * SH4 register structure nkeynes@586: */ nkeynes@586: struct sh4_registers { nkeynes@586: uint32_t r[16]; nkeynes@903: uint32_t sr, pr, pc; nkeynes@669: union { nkeynes@736: int32_t i; nkeynes@736: float f; nkeynes@669: } fpul; nkeynes@903: uint32_t t, m, q, s; /* really boolean - 0 or 1 */ nkeynes@904: float fr[2][16]; /* Must be aligned on 16-byte boundary */ nkeynes@903: uint32_t fpscr; nkeynes@883: uint32_t pad; /* Pad up to 64-bit boundaries */ nkeynes@586: uint64_t mac; nkeynes@586: uint32_t gbr, ssr, spc, sgr, dbr, vbr; nkeynes@586: nkeynes@586: uint32_t r_bank[8]; /* hidden banked registers */ nkeynes@586: int32_t store_queue[16]; /* technically 2 banks of 32 bytes */ nkeynes@736: nkeynes@586: uint32_t new_pc; /* Not a real register, but used to handle delay slots */ nkeynes@586: uint32_t event_pending; /* slice cycle time of the next pending event, or FFFFFFFF nkeynes@586: when no events are pending */ nkeynes@586: uint32_t event_types; /* bit 0 = IRQ pending, bit 1 = general event pending */ nkeynes@586: int in_delay_slot; /* flag to indicate the current instruction is in nkeynes@736: * a delay slot (certain rules apply) */ nkeynes@586: uint32_t slice_cycle; /* Current nanosecond within the timeslice */ nkeynes@958: uint32_t bus_cycle; /* Nanosecond within the timeslice that the bus will be free */ nkeynes@586: int sh4_state; /* Current power-on state (one of the SH4_STATE_* values ) */ nkeynes@936: nkeynes@936: /* Not saved */ nkeynes@936: int xlat_sh4_mode; /* Collection of execution mode flags (derived) from fpscr, sr, etc */ nkeynes@586: }; nkeynes@586: nkeynes@586: extern struct sh4_registers sh4r; nkeynes@586: nkeynes@998: extern const struct cpu_desc_struct sh4_cpu_desc; nkeynes@998: nkeynes@1125: typedef enum { nkeynes@1125: SH4_INTERPRET, nkeynes@1125: SH4_TRANSLATE, nkeynes@1125: SH4_SHADOW nkeynes@1125: } sh4core_t; nkeynes@1125: nkeynes@586: /** nkeynes@586: * Switch between translation and emulation execution modes. Note that this nkeynes@586: * should only be used while the system is stopped. If the system was built nkeynes@586: * without translation support, this method has no effect. nkeynes@586: * nkeynes@586: * @param use TRUE for translation mode, FALSE for emulation mode. nkeynes@586: */ nkeynes@1125: void sh4_set_core( sh4core_t core ); nkeynes@586: nkeynes@586: /** nkeynes@586: * Test if system is currently using the translation engine. nkeynes@586: */ nkeynes@740: gboolean sh4_translate_is_enabled(); nkeynes@586: nkeynes@586: /** nkeynes@586: * Explicitly set the SH4 PC to the supplied value - this will be the next nkeynes@586: * instruction executed. This should only be called while the system is stopped. nkeynes@586: */ nkeynes@586: void sh4_set_pc( int pc ); nkeynes@586: nkeynes@586: /** nkeynes@1187: * Set the time of the next pending event within the current timeslice. nkeynes@1187: */ nkeynes@1187: void sh4_set_event_pending( uint32_t cycles ); nkeynes@1187: nkeynes@1187: /** nkeynes@1187: * Handle an event that's due (note caller is responsible for ensuring that the nkeynes@1187: * event is in fact due). nkeynes@1187: */ nkeynes@1189: void sh4_handle_pending_events(); nkeynes@1187: nkeynes@1187: /** nkeynes@586: * Execute (using the emulator) a single instruction (in other words, perform a nkeynes@586: * single-step operation). nkeynes@586: */ nkeynes@586: gboolean sh4_execute_instruction( void ); nkeynes@586: nkeynes@586: /* SH4 breakpoints */ nkeynes@586: void sh4_set_breakpoint( uint32_t pc, breakpoint_type_t type ); nkeynes@586: gboolean sh4_clear_breakpoint( uint32_t pc, breakpoint_type_t type ); nkeynes@586: int sh4_get_breakpoint( uint32_t pc ); nkeynes@586: nkeynes@1091: /** Dump current SH4 core state (for crashdump purposes) */ nkeynes@1091: void sh4_crashdump(); nkeynes@1091: nkeynes@1094: /** Dump a translated block with SH4 and target assembly side by side. */ nkeynes@1094: void sh4_translate_dump_block( uint32_t pc ); nkeynes@1094: nkeynes@1218: /** nkeynes@1218: * Enable/disable basic block profiling (Note only supported by translation cores) nkeynes@1218: */ nkeynes@1218: void sh4_set_profile_blocks( gboolean flag ); nkeynes@1218: nkeynes@1218: /** nkeynes@1218: * Get the boolean flag indicating whether block profiling is on. nkeynes@1218: */ nkeynes@1218: gboolean sh4_get_profile_blocks(); nkeynes@1218: nkeynes@1300: struct sh4_symbol { nkeynes@1300: const char *name; nkeynes@1300: sh4addr_t address; nkeynes@1300: unsigned size; nkeynes@1300: }; nkeynes@1218: nkeynes@1300: typedef void (*sh4_symtab_destroy_cb)(struct sh4_symbol *table, unsigned size); nkeynes@1300: nkeynes@1300: /** nkeynes@1300: * Set the active symbol table used for disassembly. The table will be modified nkeynes@1300: * to sort it by address and eliminate duplicates. nkeynes@1300: * The callback supplied is invoked whenever the table is changed nkeynes@1300: * or removed. nkeynes@1300: */ nkeynes@1300: void sh4_set_symbol_table( struct sh4_symbol *table, unsigned symtab_size, sh4_symtab_destroy_cb callback ); nkeynes@1218: nkeynes@586: #ifdef __cplusplus nkeynes@586: } nkeynes@586: #endif nkeynes@586: #endif /* !lxdream_sh4_H */