diff options
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | backend.h | 9 | ||||
-rw-r--r-- | gen.c | 15 | ||||
-rw-r--r-- | gen.h | 22 | ||||
-rw-r--r-- | gen_arm.c | 21 | ||||
-rw-r--r-- | gen_arm.h | 8 |
6 files changed, 51 insertions, 36 deletions
@@ -24,13 +24,15 @@ endif -TRANSOBJS=gen_x86.o backend.o mem.o +TRANSOBJS=gen.o backend.o mem.o M68KOBJS=68kinst.o m68k_to_x86.o ifeq ($(CPU),x86_64) M68KOBJS+= runtime.o +TRANSOBJS+= gen_x86.o else ifeq ($(CPU),i686) M68KOBJS+= runtime_32.o +TRANSOBJS+= gen_x86.o endif endif @@ -85,11 +87,11 @@ vgmplay : vgmplay.o render_sdl.o $(CONFIGOBJS) $(AUDIOOBJS) testgst : testgst.o gst.o $(CC) -o testgst testgst.o gst.o -test_x86 : test_x86.o gen_x86.o - $(CC) -o test_x86 test_x86.o gen_x86.o +test_x86 : test_x86.o gen_x86.o gen.o + $(CC) -o test_x86 test_x86.o gen_x86.o gen.o -test_arm : test_arm.o gen_arm.o mem.o - $(CC) -o test_arm test_arm.o gen_arm.o mem.o +test_arm : test_arm.o gen_arm.o mem.o gen.o + $(CC) -o test_arm test_arm.o gen_arm.o mem.o gen.o gen_fib : gen_fib.o gen_x86.o mem.o $(CC) -o gen_fib gen_fib.o gen_x86.o mem.o @@ -8,6 +8,7 @@ #include <stdint.h> #include <stdio.h> +#include "gen.h" #define INVALID_OFFSET 0xFFFFFFFF #define EXTENSION_WORD 0xFFFFFFFE @@ -20,12 +21,6 @@ typedef struct { uint8_t cycles; } x86_ea; -#if defined(X86_64) || defined(X86_32) -typedef uint8_t* code_ptr; -#else -typedef uint32_t* code_ptr; -#endif - typedef struct { uint8_t *base; int32_t *offsets; @@ -56,6 +51,8 @@ typedef struct { code_ptr handle_cycle_limit; code_ptr handle_cycle_limit_int; uint8_t context_reg; + uint8_t cycles; + uint8_t limit; uint8_t scratch1; uint8_t scratch2; } cpu_options; @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <stdlib.h> +#include "gen.h" +#include "mem.h" + +void init_code_info(code_info *code) +{ + size_t size = CODE_ALLOC_SIZE; + code->cur = alloc_code(&size); + if (!code->cur) { + fputs("Failed to allocate memory for generated code\n", stderr); + exit(1); + } + code->last = code->cur + size/sizeof(code_word) - RESERVE_WORDS; +} @@ -0,0 +1,22 @@ +#ifndef GEN_H_ +#define GEN_H_ +#include <stdint.h> + +#if defined(X86_64) || defined(X86_32) +typedef uint8_t code_word; +#define RESERVE_WORDS 5 //opcode + 4-byte displacement +#else +typedef uint32_t code_word; +#define RESERVE_WORDS 4 //1 push + 1 ldr + 1bx + 1 constant +#endif +typedef code_word * code_ptr; +#define CODE_ALLOC_SIZE (1024*1024) + +typedef struct { + code_ptr cur; + code_ptr last; +} code_info; + +void init_code_info(code_info *code); + +#endif //GEN_H_ @@ -57,10 +57,6 @@ #define REG 0u - -#define RESERVE_INSTRUCTIONS 4 //1 ldr + 1bx + 1 constant -#define CODE_ALLOC_SIZE (1024*1024) - uint32_t make_immed(uint32_t val) { uint32_t rot_amount = 0; @@ -74,17 +70,6 @@ uint32_t make_immed(uint32_t val) return INVALID_IMMED; } -void init_code_info(code_info *code) -{ - size_t size = CODE_ALLOC_SIZE; - code->cur = alloc_code(&size); - if (!code->cur) { - fputs("Failed to allocate memory for generated code\n", stderr); - exit(1); - } - code->last = code->cur + size/sizeof(uint32_t) - RESERVE_INSTRUCTIONS; -} - void check_alloc_code(code_info *code) { if (code->cur == code->last) { @@ -94,9 +79,9 @@ void check_alloc_code(code_info *code) fputs("Failed to allocate memory for generated code\n", stderr); exit(1); } - if (next_code = code->last + RESERVE_INSTRUCTIONS) { + if (next_code = code->last + RESERVE_WORDS) { //new chunk is contiguous with the current one - code->last = next_code + size/sizeof(uint32_t) - RESERVE_INSTRUCTIONS; + code->last = next_code + size/sizeof(code_word) - RESERVE_WORDS; } else { uint32_t * from = code->cur + 2; if (next_code - from < 0x400000 || from - next_code <= 0x400000) { @@ -115,7 +100,7 @@ void check_alloc_code(code_info *code) } //branch to address in r0 *from = CC_AL | OP_BX; - code->last = next_code + size/sizeof(uint32_t) - RESERVE_INSTRUCTIONS; + code->last = next_code + size/sizeof(code_word) - RESERVE_WORDS; //pop r0 *(next_code++) = CC_AL | POP; code->cur = next_code; @@ -7,11 +7,7 @@ #define GEN_ARM_H_ #include <stdint.h> - -typedef struct { - uint32_t *cur; - uint32_t *last; -} code_info; +#include "gen.h" #define SET_COND 0x100000u #define NO_COND 0u @@ -73,8 +69,6 @@ enum { #define LR 0x4000 #define PC 0x8000 -void init_code_info(code_info *code); - uint32_t and(code_info *code, uint32_t dst, uint32_t src1, uint32_t src2, uint32_t set_cond); uint32_t andi(code_info *code, uint32_t dst, uint32_t src1, uint32_t immed, uint32_t set_cond); uint32_t and_cc(code_info *code, uint32_t dst, uint32_t src1, uint32_t src2, uint32_t cc, uint32_t set_cond); |