mirror of
https://github.com/rkujawa/rk65c02.git
synced 2025-04-13 23:37:21 +00:00
Minimal JIT infrastructure (does not recompile anything yet).
This commit is contained in:
parent
a1785ae68d
commit
9bca902a3a
@ -1,7 +1,7 @@
|
||||
CLI=rk65c02cli
|
||||
CLI_OBJS=rk65c02cli.o
|
||||
|
||||
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o
|
||||
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o jit_lightning.o
|
||||
LIB_SO=librk65c02.so
|
||||
LIB_STATIC=librk65c02.a
|
||||
|
||||
|
50
src/jit_lightning.c
Normal file
50
src/jit_lightning.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include "jit_lightning.h"
|
||||
|
||||
|
||||
rkjit_t
|
||||
rkjit_init(bus_t *b)
|
||||
{
|
||||
rkjit_t rj;
|
||||
|
||||
rj.b = b;
|
||||
|
||||
init_jit(NULL);
|
||||
|
||||
return rj;
|
||||
}
|
||||
|
||||
void
|
||||
rkjit_finish(rkjit_t *rj)
|
||||
{
|
||||
finish_jit();
|
||||
}
|
||||
|
||||
rkjit_block_t
|
||||
rkjit_block_recompile(rkjit_t *rj, uint16_t offset)
|
||||
{
|
||||
jit_state_t *_jit;
|
||||
rkjit_block_t jb;
|
||||
|
||||
jb.offset = offset;
|
||||
|
||||
_jit = jit_new_state();
|
||||
jit_prolog();
|
||||
jit_ret();
|
||||
jit_epilog();
|
||||
|
||||
jb.generated = jit_emit();
|
||||
|
||||
jit_clear_state();
|
||||
jit_disassemble();
|
||||
|
||||
jit_destroy_state();
|
||||
|
||||
return jb;
|
||||
}
|
||||
|
||||
/*bool
|
||||
rkjit_nblock_analyze(rkjit_nblock *, uint16_t offset)
|
||||
{
|
||||
|
||||
}*/
|
||||
|
27
src/jit_lightning.h
Normal file
27
src/jit_lightning.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef _JIT_LIGHTNING_H_
|
||||
#define _JIT_LIGHTNING_H_
|
||||
|
||||
#include <lightning/lightning.h>
|
||||
|
||||
#include "bus.h"
|
||||
|
||||
typedef void (*rkjit_native_code)(void);
|
||||
|
||||
struct rkjit_tag {
|
||||
bus_t *b;
|
||||
};
|
||||
|
||||
struct rkjit_block_tag {
|
||||
uint16_t offset;
|
||||
rkjit_native_code generated;
|
||||
};
|
||||
|
||||
typedef struct rkjit_tag rkjit_t;
|
||||
typedef struct rkjit_block_tag rkjit_block_t;
|
||||
|
||||
rkjit_t rkjit_init(bus_t *b);
|
||||
void rkjit_finish(rkjit_t *rj);
|
||||
rkjit_block_t rkjit_block_recompile(rkjit_t *rj, uint16_t offset);
|
||||
|
||||
#endif /* _JIT_LIGHTNING_H_ */
|
||||
|
@ -5,7 +5,7 @@ VASM=vasm6502_std
|
||||
VASMFLAGS=-Fbin -c02
|
||||
UTILS=utils.o
|
||||
|
||||
TESTS=test_bus test_emulation test_stepping test_assemble test_interrupt test_debug test_device_serial
|
||||
TESTS=test_bus test_emulation test_stepping test_assemble test_interrupt test_debug test_device_serial test_jit
|
||||
TESTROMS:=$(addsuffix .rom,$(basename $(wildcard *.s)))
|
||||
|
||||
all : $(TESTS) $(TESTROMS)
|
||||
@ -31,6 +31,9 @@ test_debug: test_debug.o $(UTILS) $(RK6502LIB)
|
||||
test_device_serial: test_device_serial.o $(UTILS) $(RK6502LIB)
|
||||
$(CC) -o $@ $(LDFLAGS) $< $(UTILS) $(RK6502LIB)
|
||||
|
||||
test_jit : test_jit.o $(UTILS) $(RK6502LIB)
|
||||
$(CC) -o $@ $(LDFLAGS) -llightning $< $(UTILS) $(RK6502LIB)
|
||||
|
||||
%.rom : %.s
|
||||
$(VASM) $(VASMFLAGS) -o $@ $<
|
||||
|
||||
|
40
test/test_jit.c
Normal file
40
test/test_jit.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "utils.h"
|
||||
#include "jit_lightning.h"
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(jit_1);
|
||||
ATF_TC_BODY(jit_1, tc)
|
||||
{
|
||||
// rk65c02emu_t e;
|
||||
bus_t b;
|
||||
rkjit_t rj;
|
||||
rkjit_block_t jb;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
rj = rkjit_init(&b);
|
||||
// e = rk65c02_init(&b);
|
||||
// e.regs.PC = ROM_LOAD_ADDR;
|
||||
|
||||
ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR,
|
||||
rom_path("test_emulation_inc_a.rom", tc)));
|
||||
|
||||
jb = rkjit_block_recompile(&rj, ROM_LOAD_ADDR);
|
||||
|
||||
jb.generated();
|
||||
|
||||
//rkjit_finish(&rj);
|
||||
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, jit_1);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user