main
m68k_core.h
1/*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5*/
6#ifndef M68K_CORE_H_
7#define M68K_CORE_H_
8#include <stdint.h>
9#include <stdio.h>
10#include "backend.h"
11#include "serialize.h"
12//#include "68kinst.h"
13struct m68kinst;
14
15#define NUM_MEM_AREAS 8
16#define NATIVE_MAP_CHUNKS (64*1024)
17#define NATIVE_CHUNK_SIZE ((16 * 1024 * 1024 / NATIVE_MAP_CHUNKS))
18#define MAX_NATIVE_SIZE 255
19
20#define M68K_OPT_BROKEN_READ_MODIFY 1
21
22#define INT_PENDING_SR_CHANGE 254
23#define INT_PENDING_NONE 255
24
25#define M68K_STATUS_TRACE 0x80
26
27typedef void (*start_fun)(uint8_t * addr, void * context);
28
29typedef struct {
30 code_ptr impl;
31 uint16_t reglist;
32 uint8_t reg_to_mem;
33 uint8_t size;
34 int8_t dir;
35} movem_fun;
36
37typedef struct {
38 cpu_options gen;
39
40 int8_t dregs[8];
41 int8_t aregs[8];
42 int8_t flag_regs[5];
43 FILE *address_log;
44 code_ptr read_16;
45 code_ptr write_16;
46 code_ptr read_8;
47 code_ptr write_8;
48 code_ptr read_32;
49 code_ptr write_32_lowfirst;
50 code_ptr write_32_highfirst;
51 code_ptr do_sync;
52 code_ptr handle_int_latch;
53 code_ptr trap;
54 start_fun start_context;
55 code_ptr retrans_stub;
56 code_ptr native_addr;
57 code_ptr native_addr_and_sync;
58 code_ptr get_sr;
59 code_ptr set_sr;
60 code_ptr set_ccr;
61 code_ptr bp_stub;
62 code_info extra_code;
63 movem_fun *big_movem;
64 uint32_t num_movem;
65 uint32_t movem_storage;
66 code_word prologue_start;
67} m68k_options;
68
69typedef struct m68k_context m68k_context;
70typedef void (*m68k_debug_handler)(m68k_context *context, uint32_t pc);
71
72typedef struct {
73 m68k_debug_handler handler;
74 uint32_t address;
75} m68k_breakpoint;
76
77struct m68k_context {
78 uint8_t flags[5];
79 uint8_t status;
80 uint16_t int_ack;
81 uint32_t dregs[8];
82 uint32_t aregs[9];
83 uint32_t target_cycle; //cycle at which the next synchronization or interrupt occurs
84 uint32_t current_cycle;
85 uint32_t sync_cycle;
86 uint32_t int_cycle;
87 uint32_t int_num;
88 uint32_t last_prefetch_address;
89 uint16_t *mem_pointers[NUM_MEM_AREAS];
90 code_ptr resume_pc;
91 code_ptr reset_handler;
92 m68k_options *options;
93 void *system;
94 m68k_breakpoint *breakpoints;
95 uint32_t num_breakpoints;
96 uint32_t bp_storage;
97 uint8_t int_pending;
98 uint8_t trace_pending;
99 uint8_t should_return;
100 uint8_t ram_code_flags[];
101};
102
103typedef m68k_context *(*m68k_reset_handler)(m68k_context *context);
104
105
106void translate_m68k_stream(uint32_t address, m68k_context * context);
107void start_68k_context(m68k_context * context, uint32_t address);
108void resume_68k(m68k_context *context);
109void init_m68k_opts(m68k_options * opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider);
110m68k_context * init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler);
111void m68k_reset(m68k_context * context);
112void m68k_options_free(m68k_options *opts);
113void insert_breakpoint(m68k_context * context, uint32_t address, m68k_debug_handler bp_handler);
114void remove_breakpoint(m68k_context * context, uint32_t address);
115m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context);
116uint32_t get_instruction_start(m68k_options *opts, uint32_t address);
117uint16_t m68k_get_ir(m68k_context *context);
118void m68k_print_regs(m68k_context * context);
119void m68k_invalidate_code_range(m68k_context *context, uint32_t start, uint32_t end);
120void m68k_serialize(m68k_context *context, uint32_t pc, serialize_buffer *buf);
121void m68k_deserialize(deserialize_buffer *buf, void *vcontext);
122
123#endif //M68K_CORE_H_
124