mirror of
https://github.com/toyoshim/Applerm-II.git
synced 2024-05-31 15:41:29 +00:00
Bug fix: manage r12 correctly, and TXS used a wrong register
To use r12 in assembly code: - use -fomit-frame-pointer for test.c - save and restore on calling libc functions
This commit is contained in:
parent
dbf8142e61
commit
91c94746d8
31
6502.S
31
6502.S
|
@ -12,9 +12,8 @@
|
||||||
.extern prn
|
.extern prn
|
||||||
.macro prn reg
|
.macro prn reg
|
||||||
push {r0-r3}
|
push {r0-r3}
|
||||||
mov r0, \reg
|
bl prn
|
||||||
bl prn
|
pop {r0-r3}
|
||||||
pop {r0-r3}
|
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
#define T0 r4
|
#define T0 r4
|
||||||
|
@ -36,7 +35,18 @@
|
||||||
#define FLAG_C (1 << 0)
|
#define FLAG_C (1 << 0)
|
||||||
|
|
||||||
.macro _ldb
|
.macro _ldb
|
||||||
|
.ifdef USE_FRAMEPOINTER
|
||||||
|
// If -fomit-frame-pointer is not specified, save and restore r12 here.
|
||||||
|
push {r1}
|
||||||
|
mov r1, r12
|
||||||
|
push {r1}
|
||||||
|
.endif
|
||||||
bl cpu6502_load
|
bl cpu6502_load
|
||||||
|
.ifdef USE_FRAMEPOINTER
|
||||||
|
pop {r1}
|
||||||
|
mov r12, r1
|
||||||
|
pop {r1}
|
||||||
|
.endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro _ldw
|
.macro _ldw
|
||||||
|
@ -50,7 +60,17 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro _stb
|
.macro _stb
|
||||||
|
.ifdef USE_FRAMEPOINTER
|
||||||
|
push {r1}
|
||||||
|
mov r1, r12
|
||||||
|
push {r1}
|
||||||
|
.endif
|
||||||
bl cpu6502_store
|
bl cpu6502_store
|
||||||
|
.ifdef USE_FRAMEPOINTER
|
||||||
|
pop {r1}
|
||||||
|
mov r12, r1
|
||||||
|
pop {r1}
|
||||||
|
.endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro _stw
|
.macro _stw
|
||||||
|
@ -1244,7 +1264,10 @@ op99: // STA - Absolute, Y
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op9a: // TXS
|
op9a: // TXS
|
||||||
_t RX, SR
|
_t RX, SP
|
||||||
|
movs r0, #1
|
||||||
|
lsls r0, r0, #8
|
||||||
|
add SP, SP, r0
|
||||||
_decode
|
_decode
|
||||||
|
|
||||||
op9d: // STA - Absolute, X
|
op9d: // STA - Absolute, X
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -13,6 +13,8 @@ CLOCK = 12000
|
||||||
ROM = applebasic
|
ROM = applebasic
|
||||||
ROMOBJ = $(ROM).o
|
ROMOBJ = $(ROM).o
|
||||||
ROMFLAG = -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata
|
ROMFLAG = -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata
|
||||||
|
FRAMEPTR= -fomit-frame-pointer
|
||||||
|
#FRAMEPTR= -DUSE_FRAMEPOINTER
|
||||||
OBJS = vectors.o reset.o 6502.o apple2.o uart.o $(ROMOBJ)
|
OBJS = vectors.o reset.o 6502.o apple2.o uart.o $(ROMOBJ)
|
||||||
|
|
||||||
$(APP).bin: $(APP)
|
$(APP).bin: $(APP)
|
||||||
|
@ -37,8 +39,8 @@ $(ROM).rom:
|
||||||
--strip-symbol _binary_$(ROM)_rom_size
|
--strip-symbol _binary_$(ROM)_rom_size
|
||||||
|
|
||||||
# Test binary that runs on qemu user mode emulation for testing
|
# Test binary that runs on qemu user mode emulation for testing
|
||||||
test: 6502.o test.c
|
test: 6502.S test.c
|
||||||
$(CC) -mthumb -static test.c 6502.o -o test && qemu-arm test
|
$(CC) -mthumb -static $(FRAMEPTR) test.c 6502.S -o test && qemu-arm test
|
||||||
|
|
||||||
# Assume a CQ Mary comaptible board.
|
# Assume a CQ Mary comaptible board.
|
||||||
run: $(APP).bin
|
run: $(APP).bin
|
||||||
|
|
12
test.c
12
test.c
|
@ -5,27 +5,39 @@
|
||||||
uint8_t mem[0x10000];
|
uint8_t mem[0x10000];
|
||||||
|
|
||||||
void prn(int c) {
|
void prn(int c) {
|
||||||
|
uint8_t fp;
|
||||||
|
__asm__("movs %0, r12": "=r"(fp));
|
||||||
printf("### $%02x ###\n", c);
|
printf("### $%02x ###\n", c);
|
||||||
|
__asm__("movs r12, %0":: "r"(fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpu6502_dump(
|
void cpu6502_dump(
|
||||||
uint16_t pc, uint8_t a, uint8_t x, uint8_t y, uint8_t sp, uint8_t sr) {
|
uint16_t pc, uint8_t a, uint8_t x, uint8_t y, uint8_t sp, uint8_t sr) {
|
||||||
|
uint8_t fp;
|
||||||
|
__asm__("movs %0, r12": "=r"(fp));
|
||||||
printf("*** dump *** PC=$%04x A=$%02x X=$%02x Y=$%02x SP=$%02x "
|
printf("*** dump *** PC=$%04x A=$%02x X=$%02x Y=$%02x SP=$%02x "
|
||||||
"NV-B_DIZC=%d%d-%d_%d%d%d%d\n",
|
"NV-B_DIZC=%d%d-%d_%d%d%d%d\n",
|
||||||
pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1,
|
pc, a, x, y, sp, (sr >> 7) & 1, (sr >> 6) & 1, (sr >> 4) & 1,
|
||||||
(sr >> 3) & 1, (sr >> 2) & 1, (sr >> 1) & 1, sr & 1);
|
(sr >> 3) & 1, (sr >> 2) & 1, (sr >> 1) & 1, sr & 1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
__asm__("movs r12, %0":: "r"(fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cpu6502_load(uint16_t addr) {
|
uint8_t cpu6502_load(uint16_t addr) {
|
||||||
|
uint8_t fp;
|
||||||
|
__asm__("movs %0, r12": "=r"(fp));
|
||||||
printf("load $%04x => $%02x\n", addr, mem[addr]);
|
printf("load $%04x => $%02x\n", addr, mem[addr]);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
__asm__("movs r12, %0":: "r"(fp));
|
||||||
return mem[addr];
|
return mem[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpu6502_store(uint16_t addr, uint8_t data) {
|
void cpu6502_store(uint16_t addr, uint8_t data) {
|
||||||
|
uint8_t fp;
|
||||||
|
__asm__("movs %0, r12": "=r"(fp));
|
||||||
printf("store $%04x <= $%02x\n", addr, data);
|
printf("store $%04x <= $%02x\n", addr, data);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
__asm__("movs r12, %0":: "r"(fp));
|
||||||
mem[addr] = data;
|
mem[addr] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user