Mercurial > repos > blastem
annotate backend.h @ 564:316facea756d
Fix PC displacement mode check in disassembler so that jmps involving a register are handled correctly
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 01 Mar 2014 17:07:33 -0800 |
parents | c8fefa140c80 |
children | 8e395210f50f |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
2 Copyright 2013 Michael Pavone |
555
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
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. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
5 */ |
557
acec5464fa1e
Rename x86_backend.h and x86_backend.c to backend.h and backend.c respectively
Mike Pavone <pavone@retrodev.com>
parents:
556
diff
changeset
|
6 #ifndef BACKEND_H_ |
acec5464fa1e
Rename x86_backend.h and x86_backend.c to backend.h and backend.c respectively
Mike Pavone <pavone@retrodev.com>
parents:
556
diff
changeset
|
7 #define BACKEND_H_ |
211 | 8 |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
9 #include <stdint.h> |
556 | 10 #include <stdio.h> |
563
c8fefa140c80
Moved some generic stuff from backend.h gen_arm.h and gen_arm.c into gen.h and gen.c. Added a couple fields to cpu_options so that gen_mem_fun can be made guest CPU generic
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
11 #include "gen.h" |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
12 |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
13 #define INVALID_OFFSET 0xFFFFFFFF |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
14 #define EXTENSION_WORD 0xFFFFFFFE |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
15 |
211 | 16 typedef struct { |
17 int32_t disp; | |
18 uint8_t mode; | |
19 uint8_t base; | |
20 uint8_t index; | |
21 uint8_t cycles; | |
22 } x86_ea; | |
23 | |
24 typedef struct { | |
25 uint8_t *base; | |
26 int32_t *offsets; | |
27 } native_map_slot; | |
28 | |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
29 typedef struct deferred_addr { |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
30 struct deferred_addr *next; |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
31 code_ptr dest; |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
32 uint32_t address; |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
33 } deferred_addr; |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
34 |
555
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
35 typedef enum { |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
36 READ_16, |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
37 READ_8, |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
38 WRITE_16, |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
39 WRITE_8 |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
40 } ftype; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
41 |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
42 typedef struct { |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
43 uint32_t flags; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
44 native_map_slot *native_code_map; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
45 deferred_addr *deferred; |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
46 code_ptr cur_code; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
47 code_ptr code_end; |
555
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
48 uint8_t **ram_inst_sizes; |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
49 code_ptr save_context; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
50 code_ptr load_context; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
51 code_ptr handle_cycle_limit; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
52 code_ptr handle_cycle_limit_int; |
555
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
53 uint8_t context_reg; |
563
c8fefa140c80
Moved some generic stuff from backend.h gen_arm.h and gen_arm.c into gen.h and gen.c. Added a couple fields to cpu_options so that gen_mem_fun can be made guest CPU generic
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
54 uint8_t cycles; |
c8fefa140c80
Moved some generic stuff from backend.h gen_arm.h and gen_arm.c into gen.h and gen.c. Added a couple fields to cpu_options so that gen_mem_fun can be made guest CPU generic
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
55 uint8_t limit; |
555
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
56 uint8_t scratch1; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
57 uint8_t scratch2; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
58 } cpu_options; |
5af986d2b9da
Start work on refactoring some of the backend code to allow more sharing between M68K and Z80 cores and possibly also between x86 and the ARM backend when it exists
Michael Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
59 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
60 |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
61 #define MMAP_READ 0x01 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
62 #define MMAP_WRITE 0x02 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
63 #define MMAP_CODE 0x04 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
64 #define MMAP_PTR_IDX 0x08 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
65 #define MMAP_ONLY_ODD 0x10 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
66 #define MMAP_ONLY_EVEN 0x20 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
67 #define MMAP_FUNC_NULL 0x40 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
68 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
69 typedef uint16_t (*read_16_fun)(uint32_t address, void * context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
70 typedef uint8_t (*read_8_fun)(uint32_t address, void * context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
71 typedef void * (*write_16_fun)(uint32_t address, void * context, uint16_t value); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
72 typedef void * (*write_8_fun)(uint32_t address, void * context, uint8_t value); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
73 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
74 typedef struct { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
75 uint32_t start; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
76 uint32_t end; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
77 uint32_t mask; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
78 uint16_t ptr_index; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
79 uint16_t flags; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
80 void * buffer; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
81 read_16_fun read_16; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
82 write_16_fun write_16; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
83 read_8_fun read_8; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
84 write_8_fun write_8; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
85 } memmap_chunk; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
282
diff
changeset
|
86 |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
87 typedef uint8_t * (*native_addr_func)(void * context, uint32_t address); |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
88 |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
89 deferred_addr * defer_address(deferred_addr * old_head, uint32_t address, uint8_t *dest); |
282
7b8a49220e3b
Remove deferred address entries from abandoned translations inside z80_retrans_inst
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
90 void remove_deferred_until(deferred_addr **head_ptr, deferred_addr * remove_to); |
235
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
91 void process_deferred(deferred_addr ** head_ptr, void * context, native_addr_func get_native); |
d9bf8e61c33c
Get Z80 core working for simple programs
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
92 |
557
acec5464fa1e
Rename x86_backend.h and x86_backend.c to backend.h and backend.c respectively
Mike Pavone <pavone@retrodev.com>
parents:
556
diff
changeset
|
93 #endif //BACKEND_H_ |
211 | 94 |