Skip to content

Commit 4415d29

Browse files
author
Jaroslav
committed
NORA ISAFIX: Ban SEP/REP in Emulation mode
1 parent 0b0df89 commit 4415d29

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

fpga-nora/src/cpu_observer.v

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module cpu_observer
1414
input is_isync_i, // opcode fetch?
1515
input [7:0] cpu_dbo_i, // DB output to the CPU
1616
input cef_i, // Emulation flag?
17+
input stopped_cpu_i, // is the CPU stopped by ICD?
1718
// Bus signals
1819
input release_wr_i, // wr-phase
1920
input release_cs_i, // cs-phase
@@ -22,7 +23,8 @@ module cpu_observer
2223
// Control outputs
2324
output reg map_pblrom_o, // command to map the PBL ROM
2425
output reg unmap_pblrom_o, // command to unmap the PBL ROM
25-
output bad_opc6502_abortn // command to ABORT the current instruction
26+
output bad_opc6502_abortn, // command to ABORT the current instruction
27+
output reg brk00_opc_o // BRK opcode detected
2628
);
2729
// IMPLEMENTATION
2830

@@ -31,8 +33,10 @@ module cpu_observer
3133
// wire isafix816_enabled;
3234

3335
// detect bad opcodes of 6502 used in 65816 CPU:
34-
wire is_bad_opcode6502 = (cpu_dbo_i[2:0] == 3'b111) && !cputype02_i && is_isync_i /*&& !internal_cpu_res*/;
36+
wire is_opc_sep_rep = (cpu_dbo_i[7:0] == 8'hC2) || (cpu_dbo_i[7:0] == 8'hE2);
37+
wire is_bad_opcode6502 = ((cpu_dbo_i[2:0] == 3'b111) || is_opc_sep_rep) && !cputype02_i && is_isync_i /*&& !internal_cpu_res*/;
3538
wire is_rti_opcode = (cpu_dbo_i == 8'h40) && is_isync_i /*&& !internal_cpu_res*/;
39+
wire is_brk_opcode = (cpu_dbo_i == 8'h00) && is_isync_i;
3640

3741
// ABORTn generated by a bad opcode; signal active low
3842
reg bad_opc6502_abort1n, bad_opc6502_abort2n;
@@ -50,6 +54,7 @@ module cpu_observer
5054
// icd_cpu_stop <= 0;
5155
map_pblrom_o <= 0;
5256
unmap_pblrom_o <= 0;
57+
brk00_opc_o <= 0;
5358
end else begin
5459
// icd_cpu_stop <= 0;
5560
map_pblrom_o <= 0;
@@ -87,6 +92,8 @@ module cpu_observer
8792
// -> yes, then clear the ROMBLOCK bits 7 and 6 to remove the PBL ROM from the map.
8893
unmap_pblrom_o <= 1;
8994
end
95+
96+
brk00_opc_o <= is_brk_opcode;
9097
end
9198

9299
// first u-cycle after PHI2 falling?
@@ -95,6 +102,12 @@ module cpu_observer
95102
bad_opc6502_abort2n <= bad_opc6502_abort1n; // shift
96103
bad_opc6502_abort1n <= 1; // 1=inactivate!
97104
end
105+
106+
// if the CPU is stopped, then clear the BRK opcode flag
107+
if (stopped_cpu_i)
108+
begin
109+
brk00_opc_o <= 0;
110+
end
98111
end
99112
end
100113

fpga-nora/src/nora.v

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ module top (
281281
crwn_r // bit[0]: CPU R/W signal
282282
};
283283

284-
wire icd_cpu_stop;
284+
wire scrb_cpu_stop, brk00_opc;
285+
wire icd_cpu_stop = scrb_cpu_stop /*| brk00_opc */;
285286
wire map_pblrom, unmap_pblrom;
286287
wire bad_opc6502_abortn;
287288
// wire [7:0] romblock_nr;
@@ -298,6 +299,7 @@ module top (
298299
.is_isync_i (csync_vpa_r && cvda_r),
299300
.cpu_dbo_i (cpu_db_o),
300301
.cef_i (cef_r),
302+
.stopped_cpu_i (stopped_cpu),
301303
// Bus signals
302304
.release_wr_i (release_wr),
303305
.release_cs_i (release_cs),
@@ -306,7 +308,8 @@ module top (
306308
// Control outputs
307309
.map_pblrom_o (map_pblrom),
308310
.unmap_pblrom_o (unmap_pblrom),
309-
.bad_opc6502_abortn (bad_opc6502_abortn)
311+
.bad_opc6502_abortn (bad_opc6502_abortn),
312+
.brk00_opc_o (brk00_opc)
310313
);
311314

312315
/* ICD SPI Slave - MISO driver */
@@ -923,7 +926,7 @@ module top (
923926
.map_bootrom_i (map_pblrom), // Map PBL ROM to $E000-$FFFF (for ISAFIX handler)
924927
.unmap_bootrom_i (unmap_pblrom), // Unmap PBL ROM from $E000-$FFFF (for ISAFIX handler)
925928
// SYSCTRL
926-
.cpu_stop_req_o (icd_cpu_stop),
929+
.cpu_stop_req_o (scrb_cpu_stop),
927930
.cpu_reset_req_o (icd_cpu_reset),
928931
.abrt02_en_o (isafix816_enabled),
929932
// SPI Master interface for accessing the flash memory

sw-spiflash/common/isafix.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ TMP_BITNR = $F9
7676
; and store it to our scratchpad.
7777
STA TMP_IBYTE
7878

79+
; Is the faulting instruction REP (0xC2) ?
80+
CMP #$C2
81+
beq handle_rep ; yes -> jump
82+
; Is the faulting instruction SEP (0xE2) ?
83+
CMP #$E2
84+
beq handle_sep ; yes -> jump
85+
7986
; Load the ZP byte, which is in fact an address into zero page, and store to scratchpad
8087
LDA a:1, X ; 8-bit load
8188
STA TMP_ZPBYTE ; zp byte from the code
@@ -203,6 +210,15 @@ handle_rmb: ; Reset memory bit
203210
STA (TMP_ZPBYTE) ; write back
204211
; BRA done_rmb_smb fall through
205212

213+
; -------------------------------------
214+
; Handling the SEP/REP instructions, which are valid but for X16 ROM reasons
215+
; we want to emulate them as NOP.
216+
; These instructions are 2 bytes.
217+
handle_rep:
218+
handle_sep:
219+
; Just skip the REP/SEP by incrementing return address by 2...
220+
221+
206222
done_rmb_smb:
207223
; SMB/RMB is done.
208224
; Fix the return address on the stack - increment by two.

sw-spiflash/sbl-for-cx16/config-sbl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
config_payload_block = 192
88

99
; how many 8k blocks of the payload (not counting this 8k SBL); 32 == 256k
10-
config_payload_bcount = 32
10+
config_payload_bcount = 34
1111

1212
; Configure NORA_RMBCTRL_REG config. to enable the following features necessary for CX16:
1313
; MIRROR_ZP = mirror RAMBLOCK and ROMBLOCK registers in the zero page ($00=RAMBLOCK and $01=RAMBLOCK)

0 commit comments

Comments
 (0)