src/musashi/m68k.h

changeset 0
8bf1bf91a36d
child 19
ea417ac1d83a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/musashi/m68k.h	Sat Nov 27 01:13:12 2010 +0000
     1.3 @@ -0,0 +1,339 @@
     1.4 +#ifndef M68K__HEADER
     1.5 +#define M68K__HEADER
     1.6 +
     1.7 +/* ======================================================================== */
     1.8 +/* ========================= LICENSING & COPYRIGHT ======================== */
     1.9 +/* ======================================================================== */
    1.10 +/*
    1.11 + *                                  MUSASHI
    1.12 + *                                Version 3.3
    1.13 + *
    1.14 + * A portable Motorola M680x0 processor emulation engine.
    1.15 + * Copyright 1998-2001 Karl Stenerud.  All rights reserved.
    1.16 + *
    1.17 + * This code may be freely used for non-commercial purposes as long as this
    1.18 + * copyright notice remains unaltered in the source code and any binary files
    1.19 + * containing this code in compiled form.
    1.20 + *
    1.21 + * All other lisencing terms must be negotiated with the author
    1.22 + * (Karl Stenerud).
    1.23 + *
    1.24 + * The latest version of this code can be obtained at:
    1.25 + * http://kstenerud.cjb.net
    1.26 + */
    1.27 +
    1.28 +
    1.29 +
    1.30 +/* ======================================================================== */
    1.31 +/* ============================ GENERAL DEFINES =========================== */
    1.32 +
    1.33 +/* ======================================================================== */
    1.34 +
    1.35 +/* There are 7 levels of interrupt to the 68K.
    1.36 + * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
    1.37 + */
    1.38 +#define M68K_IRQ_NONE 0
    1.39 +#define M68K_IRQ_1    1
    1.40 +#define M68K_IRQ_2    2
    1.41 +#define M68K_IRQ_3    3
    1.42 +#define M68K_IRQ_4    4
    1.43 +#define M68K_IRQ_5    5
    1.44 +#define M68K_IRQ_6    6
    1.45 +#define M68K_IRQ_7    7
    1.46 +
    1.47 +
    1.48 +/* Special interrupt acknowledge values.
    1.49 + * Use these as special returns from the interrupt acknowledge callback
    1.50 + * (specified later in this header).
    1.51 + */
    1.52 +
    1.53 +/* Causes an interrupt autovector (0x18 + interrupt level) to be taken.
    1.54 + * This happens in a real 68K if VPA or AVEC is asserted during an interrupt
    1.55 + * acknowledge cycle instead of DTACK.
    1.56 + */
    1.57 +#define M68K_INT_ACK_AUTOVECTOR    0xffffffff
    1.58 +
    1.59 +/* Causes the spurious interrupt vector (0x18) to be taken
    1.60 + * This happens in a real 68K if BERR is asserted during the interrupt
    1.61 + * acknowledge cycle (i.e. no devices responded to the acknowledge).
    1.62 + */
    1.63 +#define M68K_INT_ACK_SPURIOUS      0xfffffffe
    1.64 +
    1.65 +
    1.66 +/* CPU types for use in m68k_set_cpu_type() */
    1.67 +enum
    1.68 +{
    1.69 +	M68K_CPU_TYPE_INVALID,
    1.70 +	M68K_CPU_TYPE_68000,
    1.71 +	M68K_CPU_TYPE_68010,
    1.72 +	M68K_CPU_TYPE_68EC020,
    1.73 +	M68K_CPU_TYPE_68020,
    1.74 +	M68K_CPU_TYPE_68030,	/* Supported by disassembler ONLY */
    1.75 +	M68K_CPU_TYPE_68040		/* Supported by disassembler ONLY */
    1.76 +};
    1.77 +
    1.78 +/* Registers used by m68k_get_reg() and m68k_set_reg() */
    1.79 +typedef enum
    1.80 +{
    1.81 +	/* Real registers */
    1.82 +	M68K_REG_D0,		/* Data registers */
    1.83 +	M68K_REG_D1,
    1.84 +	M68K_REG_D2,
    1.85 +	M68K_REG_D3,
    1.86 +	M68K_REG_D4,
    1.87 +	M68K_REG_D5,
    1.88 +	M68K_REG_D6,
    1.89 +	M68K_REG_D7,
    1.90 +	M68K_REG_A0,		/* Address registers */
    1.91 +	M68K_REG_A1,
    1.92 +	M68K_REG_A2,
    1.93 +	M68K_REG_A3,
    1.94 +	M68K_REG_A4,
    1.95 +	M68K_REG_A5,
    1.96 +	M68K_REG_A6,
    1.97 +	M68K_REG_A7,
    1.98 +	M68K_REG_PC,		/* Program Counter */
    1.99 +	M68K_REG_SR,		/* Status Register */
   1.100 +	M68K_REG_SP,		/* The current Stack Pointer (located in A7) */
   1.101 +	M68K_REG_USP,		/* User Stack Pointer */
   1.102 +	M68K_REG_ISP,		/* Interrupt Stack Pointer */
   1.103 +	M68K_REG_MSP,		/* Master Stack Pointer */
   1.104 +	M68K_REG_SFC,		/* Source Function Code */
   1.105 +	M68K_REG_DFC,		/* Destination Function Code */
   1.106 +	M68K_REG_VBR,		/* Vector Base Register */
   1.107 +	M68K_REG_CACR,		/* Cache Control Register */
   1.108 +	M68K_REG_CAAR,		/* Cache Address Register */
   1.109 +
   1.110 +	/* Assumed registers */
   1.111 +	/* These are cheat registers which emulate the 1-longword prefetch
   1.112 +	 * present in the 68000 and 68010.
   1.113 +	 */ 
   1.114 +	M68K_REG_PREF_ADDR,	/* Last prefetch address */
   1.115 +	M68K_REG_PREF_DATA,	/* Last prefetch data */
   1.116 +
   1.117 +	/* Convenience registers */
   1.118 +	M68K_REG_PPC,		/* Previous value in the program counter */
   1.119 +	M68K_REG_IR,		/* Instruction register */
   1.120 +	M68K_REG_CPU_TYPE	/* Type of CPU being run */
   1.121 +} m68k_register_t;
   1.122 +
   1.123 +/* ======================================================================== */
   1.124 +/* ====================== FUNCTIONS CALLED BY THE CPU ===================== */
   1.125 +/* ======================================================================== */
   1.126 +
   1.127 +/* You will have to implement these functions */
   1.128 +
   1.129 +/* read/write functions called by the CPU to access memory.
   1.130 + * while values used are 32 bits, only the appropriate number
   1.131 + * of bits are relevant (i.e. in write_memory_8, only the lower 8 bits
   1.132 + * of value should be written to memory).
   1.133 + *
   1.134 + * NOTE: I have separated the immediate and PC-relative memory fetches
   1.135 + *       from the other memory fetches because some systems require
   1.136 + *       differentiation between PROGRAM and DATA fetches (usually
   1.137 + *       for security setups such as encryption).
   1.138 + *       This separation can either be achieved by setting
   1.139 + *       M68K_SEPARATE_READS in m68kconf.h and defining
   1.140 + *       the read functions, or by setting M68K_EMULATE_FC and
   1.141 + *       making a function code callback function.
   1.142 + *       Using the callback offers better emulation coverage
   1.143 + *       because you can also monitor whether the CPU is in SYSTEM or
   1.144 + *       USER mode, but it is also slower.
   1.145 + */
   1.146 +
   1.147 +/* Read from anywhere */
   1.148 +unsigned int  m68k_read_memory_8(unsigned int address);
   1.149 +unsigned int  m68k_read_memory_16(unsigned int address);
   1.150 +unsigned int  m68k_read_memory_32(unsigned int address);
   1.151 +
   1.152 +/* Read data immediately following the PC */
   1.153 +unsigned int  m68k_read_immediate_16(unsigned int address);
   1.154 +unsigned int  m68k_read_immediate_32(unsigned int address);
   1.155 +
   1.156 +/* Read data relative to the PC */
   1.157 +unsigned int  m68k_read_pcrelative_8(unsigned int address);
   1.158 +unsigned int  m68k_read_pcrelative_16(unsigned int address);
   1.159 +unsigned int  m68k_read_pcrelative_32(unsigned int address);
   1.160 +
   1.161 +/* Memory access for the disassembler */
   1.162 +unsigned int m68k_read_disassembler_8  (unsigned int address);
   1.163 +unsigned int m68k_read_disassembler_16 (unsigned int address);
   1.164 +unsigned int m68k_read_disassembler_32 (unsigned int address);
   1.165 +
   1.166 +/* Write to anywhere */
   1.167 +void m68k_write_memory_8(unsigned int address, unsigned int value);
   1.168 +void m68k_write_memory_16(unsigned int address, unsigned int value);
   1.169 +void m68k_write_memory_32(unsigned int address, unsigned int value);
   1.170 +
   1.171 +
   1.172 +
   1.173 +/* ======================================================================== */
   1.174 +/* ============================== CALLBACKS =============================== */
   1.175 +/* ======================================================================== */
   1.176 +
   1.177 +/* These functions allow you to set callbacks to the host when specific events
   1.178 + * occur.  Note that you must enable the corresponding value in m68kconf.h
   1.179 + * in order for these to do anything useful.
   1.180 + * Note: I have defined default callbacks which are used if you have enabled
   1.181 + * the corresponding #define in m68kconf.h but either haven't assigned a
   1.182 + * callback or have assigned a callback of NULL.
   1.183 + */
   1.184 +
   1.185 +/* Set the callback for an interrupt acknowledge.
   1.186 + * You must enable M68K_EMULATE_INT_ACK in m68kconf.h.
   1.187 + * The CPU will call the callback with the interrupt level being acknowledged.
   1.188 + * The host program must return either a vector from 0x02-0xff, or one of the
   1.189 + * special interrupt acknowledge values specified earlier in this header.
   1.190 + * If this is not implemented, the CPU will always assume an autovectored
   1.191 + * interrupt, and will automatically clear the interrupt request when it
   1.192 + * services the interrupt.
   1.193 + * Default behavior: return M68K_INT_ACK_AUTOVECTOR.
   1.194 + */
   1.195 +void m68k_set_int_ack_callback(int  (*callback)(int int_level));
   1.196 +
   1.197 +
   1.198 +/* Set the callback for a breakpoint acknowledge (68010+).
   1.199 + * You must enable M68K_EMULATE_BKPT_ACK in m68kconf.h.
   1.200 + * The CPU will call the callback with whatever was in the data field of the
   1.201 + * BKPT instruction for 68020+, or 0 for 68010.
   1.202 + * Default behavior: do nothing.
   1.203 + */
   1.204 +void m68k_set_bkpt_ack_callback(void (*callback)(unsigned int data));
   1.205 +
   1.206 +
   1.207 +/* Set the callback for the RESET instruction.
   1.208 + * You must enable M68K_EMULATE_RESET in m68kconf.h.
   1.209 + * The CPU calls this callback every time it encounters a RESET instruction.
   1.210 + * Default behavior: do nothing.
   1.211 + */
   1.212 +void m68k_set_reset_instr_callback(void  (*callback)(void));
   1.213 +
   1.214 +
   1.215 +/* Set the callback for informing of a large PC change.
   1.216 + * You must enable M68K_MONITOR_PC in m68kconf.h.
   1.217 + * The CPU calls this callback with the new PC value every time the PC changes
   1.218 + * by a large value (currently set for changes by longwords).
   1.219 + * Default behavior: do nothing.
   1.220 + */
   1.221 +void m68k_set_pc_changed_callback(void  (*callback)(unsigned int new_pc));
   1.222 +
   1.223 +
   1.224 +/* Set the callback for CPU function code changes.
   1.225 + * You must enable M68K_EMULATE_FC in m68kconf.h.
   1.226 + * The CPU calls this callback with the function code before every memory
   1.227 + * access to set the CPU's function code according to what kind of memory
   1.228 + * access it is (supervisor/user, program/data and such).
   1.229 + * Default behavior: do nothing.
   1.230 + */
   1.231 +void m68k_set_fc_callback(void  (*callback)(unsigned int new_fc));
   1.232 +
   1.233 +
   1.234 +/* Set a callback for the instruction cycle of the CPU.
   1.235 + * You must enable M68K_INSTRUCTION_HOOK in m68kconf.h.
   1.236 + * The CPU calls this callback just before fetching the opcode in the
   1.237 + * instruction cycle.
   1.238 + * Default behavior: do nothing.
   1.239 + */
   1.240 +void m68k_set_instr_hook_callback(void  (*callback)(void));
   1.241 +
   1.242 +
   1.243 +
   1.244 +/* ======================================================================== */
   1.245 +/* ====================== FUNCTIONS TO ACCESS THE CPU ===================== */
   1.246 +/* ======================================================================== */
   1.247 +
   1.248 +/* Use this function to set the CPU type you want to emulate.
   1.249 + * Currently supported types are: M68K_CPU_TYPE_68000, M68K_CPU_TYPE_68010,
   1.250 + * M68K_CPU_TYPE_EC020, and M68K_CPU_TYPE_68020.
   1.251 + */
   1.252 +void m68k_set_cpu_type(unsigned int cpu_type);
   1.253 +
   1.254 +/* Pulse the RESET pin on the CPU.
   1.255 + * You *MUST* reset the CPU at least once to initialize the emulation
   1.256 + * Note: If you didn't call m68k_set_cpu_type() before resetting
   1.257 + *       the CPU for the first time, the CPU will be set to
   1.258 + *       M68K_CPU_TYPE_68000.
   1.259 + */
   1.260 +void m68k_pulse_reset(void);
   1.261 +
   1.262 +/* execute num_cycles worth of instructions.  returns number of cycles used */
   1.263 +int m68k_execute(int num_cycles);
   1.264 +
   1.265 +/* These functions let you read/write/modify the number of cycles left to run
   1.266 + * while m68k_execute() is running.
   1.267 + * These are useful if the 68k accesses a memory-mapped port on another device
   1.268 + * that requires immediate processing by another CPU.
   1.269 + */
   1.270 +int m68k_cycles_run(void);              /* Number of cycles run so far */
   1.271 +int m68k_cycles_remaining(void);        /* Number of cycles left */
   1.272 +void m68k_modify_timeslice(int cycles); /* Modify cycles left */
   1.273 +void m68k_end_timeslice(void);          /* End timeslice now */
   1.274 +
   1.275 +/* Set the IPL0-IPL2 pins on the CPU (IRQ).
   1.276 + * A transition from < 7 to 7 will cause a non-maskable interrupt (NMI).
   1.277 + * Setting IRQ to 0 will clear an interrupt request.
   1.278 + */
   1.279 +void m68k_set_irq(unsigned int int_level);
   1.280 +
   1.281 +
   1.282 +/* Halt the CPU as if you pulsed the HALT pin. */
   1.283 +void m68k_pulse_halt(void);
   1.284 +
   1.285 +
   1.286 +/* Context switching to allow multiple CPUs */
   1.287 +
   1.288 +/* Get the size of the cpu context in bytes */
   1.289 +unsigned int m68k_context_size(void);
   1.290 +
   1.291 +/* Get a cpu context */
   1.292 +unsigned int m68k_get_context(void* dst);
   1.293 +
   1.294 +/* set the current cpu context */
   1.295 +void m68k_set_context(void* dst);
   1.296 +
   1.297 +/* Save the current cpu context to disk.
   1.298 + * You must provide a function pointer of the form:
   1.299 + * void save_value(char* identifier, unsigned int value)
   1.300 + */
   1.301 +void m68k_save_context(	void (*save_value)(char* identifier, unsigned int value));
   1.302 +
   1.303 +/* Load a cpu context from disk.
   1.304 + * You must provide a function pointer of the form:
   1.305 + * unsigned int load_value(char* identifier)
   1.306 + */
   1.307 +void m68k_load_context(unsigned int (*load_value)(char* identifier));
   1.308 +
   1.309 +
   1.310 +
   1.311 +/* Peek at the internals of a CPU context.  This can either be a context
   1.312 + * retrieved using m68k_get_context() or the currently running context.
   1.313 + * If context is NULL, the currently running CPU context will be used.
   1.314 + */
   1.315 +unsigned int m68k_get_reg(void* context, m68k_register_t reg);
   1.316 +
   1.317 +/* Poke values into the internals of the currently running CPU context */
   1.318 +void m68k_set_reg(m68k_register_t reg, unsigned int value);
   1.319 +
   1.320 +/* Check if an instruction is valid for the specified CPU type */
   1.321 +unsigned int m68k_is_valid_instruction(unsigned int instruction, unsigned int cpu_type);
   1.322 +
   1.323 +/* Disassemble 1 instruction using the epecified CPU type at pc.  Stores
   1.324 + * disassembly in str_buff and returns the size of the instruction in bytes.
   1.325 + */
   1.326 +unsigned int m68k_disassemble(char* str_buff, unsigned int pc, unsigned int cpu_type);
   1.327 +
   1.328 +
   1.329 +/* ======================================================================== */
   1.330 +/* ============================= CONFIGURATION ============================ */
   1.331 +/* ======================================================================== */
   1.332 +
   1.333 +/* Import the configuration for this build */
   1.334 +#include "m68kconf.h"
   1.335 +
   1.336 +
   1.337 +
   1.338 +/* ======================================================================== */
   1.339 +/* ============================== END OF FILE ============================= */
   1.340 +/* ======================================================================== */
   1.341 +
   1.342 +#endif /* M68K__HEADER */