# HG changeset patch # User Michael Pavone # Date 1393264524 28800 # Node ID c8fefa140c8029b0584784f6e7ec9f17ee75a8c3 # Parent dc9f178085a054f44952b4223bfb923ecbefaea4 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 diff -r dc9f178085a0 -r c8fefa140c80 Makefile --- a/Makefile Mon Feb 24 01:30:16 2014 -0800 +++ b/Makefile Mon Feb 24 09:55:24 2014 -0800 @@ -24,13 +24,15 @@ -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 @@ 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 diff -r dc9f178085a0 -r c8fefa140c80 backend.h --- a/backend.h Mon Feb 24 01:30:16 2014 -0800 +++ b/backend.h Mon Feb 24 09:55:24 2014 -0800 @@ -8,6 +8,7 @@ #include #include +#include "gen.h" #define INVALID_OFFSET 0xFFFFFFFF #define EXTENSION_WORD 0xFFFFFFFE @@ -20,12 +21,6 @@ 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 @@ 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; diff -r dc9f178085a0 -r c8fefa140c80 gen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gen.c Mon Feb 24 09:55:24 2014 -0800 @@ -0,0 +1,15 @@ +#include +#include +#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; +} diff -r dc9f178085a0 -r c8fefa140c80 gen.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gen.h Mon Feb 24 09:55:24 2014 -0800 @@ -0,0 +1,22 @@ +#ifndef GEN_H_ +#define GEN_H_ +#include + +#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_ diff -r dc9f178085a0 -r c8fefa140c80 gen_arm.c --- a/gen_arm.c Mon Feb 24 01:30:16 2014 -0800 +++ b/gen_arm.c Mon Feb 24 09:55:24 2014 -0800 @@ -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 @@ 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 @@ 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 @@ } //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; diff -r dc9f178085a0 -r c8fefa140c80 gen_arm.h --- a/gen_arm.h Mon Feb 24 01:30:16 2014 -0800 +++ b/gen_arm.h Mon Feb 24 09:55:24 2014 -0800 @@ -7,11 +7,7 @@ #define GEN_ARM_H_ #include - -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 @@ #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);