Skip to content

Commit 5887cc1

Browse files
committed
fixes
1 parent 8666da0 commit 5887cc1

File tree

2 files changed

+61
-45
lines changed

2 files changed

+61
-45
lines changed

cores/gba/rtl/cpu/ControlUnit.sv

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ module GBA_ControlUnit (
770770

771771
// First cycle: Prefetch and calculate first address
772772
if (cycle == 8'd0) begin
773-
if (decoder_bus.instr_type == ARM_INSTR_STM) begin
774-
end else if (decoder_bus.instr_type == ARM_INSTR_LDM) begin
773+
if (decoder_bus.instr_type == ARM_INSTR_LDM) begin
775774
$display("[ControlUnit] Cycle 0 of LDM instruction, calculating address");
776775
control_signals |= fetch_instr_early();
777776
end
@@ -945,6 +944,10 @@ module GBA_ControlUnit (
945944
control_signals.Rp_imm =
946945
get_ith_bit(4'(cycle - 8'd2), decoder_bus.word.arm.block.reg_list);
947946

947+
if (get_ith_bit(4'(cycle - 8'd2), decoder_bus.word.arm.block.reg_list) == 4'd15) begin
948+
control_signals.force_no_align_pc = 1'b0;
949+
end
950+
948951
// Let the B_bus word pass through the ALU unmodified for the writeback
949952
control_signals.ALU_op = ALU_OP_MOV;
950953

cores/gba/rtl/cpu/Decoder.sv

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ module GBA_Decoder (
286286

287287
// Software Interrupt
288288
16'b1101_1111_????_????: begin
289-
$display("[Decoder] Detected THUMB SWI instruction with IR=0x%08x", IR_THUMB);
289+
bus.instr_type = ARM_INSTR_SWI;
290+
291+
// Overwrite Rn and Rd
292+
bus.decoded_regs.Rn = 4'd15;
293+
bus.decoded_regs.Rd = 4'd14;
294+
295+
$display("[GBA_Decoder] Detected THUMB SWI instruction with IR=0x%08x", IR_THUMB);
290296
end
291297

292298
// Unconditional Branch
@@ -299,7 +305,7 @@ module GBA_Decoder (
299305

300306
bus.word.arm.branch.imm24 = {{13{IR_THUMB[10]}}, IR_THUMB[10:0]};
301307

302-
$display("[Decoder] Detected THUMB B instruction with IR=0x%08x", IR_THUMB);
308+
$display("[GBA_Decoder] Detected THUMB B instruction with IR=0x%08x", IR_THUMB);
303309
end
304310

305311
// Conditional Branch
@@ -315,7 +321,7 @@ module GBA_Decoder (
315321

316322
bus.word.arm.branch.imm24 = {{16{IR_THUMB[7]}}, IR_THUMB[7:0]};
317323

318-
$display("[Decoder] Detected THUMB B<cond> instruction with IR=0x%08x", IR_THUMB);
324+
$display("[GBA_Decoder] Detected THUMB B<cond> instruction with IR=0x%08x", IR_THUMB);
319325
end
320326

321327
// Block Data Transfer
@@ -339,7 +345,7 @@ module GBA_Decoder (
339345

340346
bus.decoded_regs.Rn = 4'(IR_THUMB[10:8]);
341347

342-
$display("[Decoder] Detected THUMB LDM/STM instruction with IR=0x%08x", IR_THUMB);
348+
$display("[GBA_Decoder] Detected THUMB LDM/STM instruction with IR=0x%08x", IR_THUMB);
343349
end
344350

345351
// Long Branch with Link
@@ -354,7 +360,7 @@ module GBA_Decoder (
354360
bus.decoded_regs.Rd = 4'd14;
355361

356362
bus.word.arm.branch.imm24 = {{13{IR_THUMB[10]}}, IR_THUMB[10:0]};
357-
$display("[Decoder] Detected THUMB BL instruction with IR=0x%08x", IR_THUMB);
363+
$display("[GBA_Decoder] Detected THUMB BL instruction with IR=0x%08x", IR_THUMB);
358364
end else begin
359365
bus.instr_type = ARM_INSTR_THUMB_LONG_BRANCH_LINK_1;
360366

@@ -363,8 +369,8 @@ module GBA_Decoder (
363369
bus.decoded_regs.Rd = 4'd14;
364370

365371
bus.word.arm.branch.imm24 = 24'(IR_THUMB[10:0]);
366-
// $display("[Decoder] Detected THUMB BL instruction (2nd half) with Imm=0x%06x", {
367-
// {13{IR_THUMB[10]}}, IR_THUMB[10:0]});
372+
$display("[GBA_Decoder] Detected THUMB BL instruction (2nd half) with Imm=0x%06x",
373+
24'(IR_THUMB[10:0]));
368374
end
369375
end
370376

@@ -383,7 +389,7 @@ module GBA_Decoder (
383389
bus.decoded_regs.Rd = 4'd13;
384390
bus.decoded_regs.Rn = 4'd13;
385391

386-
$display("[Decoder] Detected THUMB ADD SP instruction with IR=0x%08x", IR_THUMB);
392+
$display("[GBA_Decoder] Detected THUMB ADD SP instruction with IR=0x%08x", IR_THUMB);
387393
end
388394

389395
// Push / Pop Registers
@@ -409,7 +415,7 @@ module GBA_Decoder (
409415
bus.word.arm.block.reg_list[15] = 1'b1; // PC = R15
410416
end
411417

412-
$display("[Decoder] Detected THUMB POP instruction (reg_list=0x%02x, PC=%0d)",
418+
$display("[GBA_Decoder] Detected THUMB POP instruction (reg_list=0x%02x, PC=%0d)",
413419
IR_THUMB[7:0], IR_THUMB[8]);
414420

415421
end else begin
@@ -423,10 +429,10 @@ module GBA_Decoder (
423429
bus.word.arm.block.reg_list[14] = 1'b1; // LR = R14
424430
end
425431

426-
$display("[Decoder] Detected THUMB PUSH instruction (reg_list=0x%02x, LR=%0d)",
432+
$display("[GBA_Decoder] Detected THUMB PUSH instruction (reg_list=0x%02x, LR=%0d)",
427433
IR_THUMB[7:0], IR_THUMB[8]);
428434
end
429-
$display("[Decoder] Detected THUMB PUSH/POP instruction with IR=0x%08x", IR_THUMB);
435+
$display("[GBA_Decoder] Detected THUMB PUSH/POP instruction with IR=0x%08x", IR_THUMB);
430436
end
431437

432438
// Load / Store Halfword
@@ -449,7 +455,7 @@ module GBA_Decoder (
449455
bus.decoded_regs.Rn = 4'(IR_THUMB[5:3]);
450456
bus.decoded_regs.Rd = 4'(IR_THUMB[2:0]);
451457

452-
$display("[Decoder] Detected THUMB LDRH/STRH instruction with IR=0x%08x", IR_THUMB);
458+
$display("[GBA_Decoder] Detected THUMB LDRH/STRH instruction with IR=0x%08x", IR_THUMB);
453459
end
454460

455461
// SP Relative Load / Store
@@ -468,7 +474,8 @@ module GBA_Decoder (
468474
bus.decoded_regs.Rn = 4'd13; // SP
469475
bus.decoded_regs.Rd = 4'(IR_THUMB[10:8]);
470476

471-
$display("[Decoder] Detected THUMB LDR/STR SP instruction with IR=0x%08x", IR_THUMB);
477+
$display("[GBA_Decoder] Detected THUMB LDR/STR SP instruction with IR=0x%08x",
478+
IR_THUMB);
472479
end
473480

474481
// Load Address
@@ -490,7 +497,7 @@ module GBA_Decoder (
490497
bus.word.arm.data_proc_imm.rotate = 4'd1;
491498
bus.word.arm.data_proc_imm.use_lsl = 1'b1;
492499

493-
$display("[Decoder] Detected THUMB ADD Rd, PC, #imm instruction with IR=0x%08x",
500+
$display("[GBA_Decoder] Detected THUMB ADD Rd, PC, #imm instruction with IR=0x%08x",
494501
IR_THUMB);
495502
end
496503

@@ -510,7 +517,7 @@ module GBA_Decoder (
510517
bus.decoded_regs.Rd = 4'(IR_THUMB[2:0]);
511518

512519
$display(
513-
"[Decoder] Detected THUMB LDR/STR with immediate offset instruction with IR=0x%08x",
520+
"[GBA_Decoder] Detected THUMB LDR/STR with immediate offset instruction with IR=0x%08x",
514521
IR_THUMB);
515522
end
516523

@@ -528,7 +535,7 @@ module GBA_Decoder (
528535
bus.decoded_regs.Rm = 4'(IR_THUMB[10:6]);
529536

530537
$display(
531-
"[Decoder] Detected THUMB LDR/STR with register offset instruction with IR=0x%08x",
538+
"[GBA_Decoder] Detected THUMB LDR/STR with register offset instruction with IR=0x%08x",
532539
IR_THUMB);
533540
end
534541

@@ -564,13 +571,14 @@ module GBA_Decoder (
564571
bus.decoded_regs.Rn = 4'(IR_THUMB[5:3]);
565572
bus.decoded_regs.Rd = 4'(IR_THUMB[2:0]);
566573

567-
$display("[Decoder] Detected THUMB STRH/LDSB/LDRSB/LDRSH instruction with IR=0x%08x",
568-
IR_THUMB);
574+
$display(
575+
"[GBA_Decoder] Detected THUMB STRH/LDSB/LDRSB/LDRSH instruction with IR=0x%08x",
576+
IR_THUMB);
569577
end
570578

571579
// PC Relative Load
572580
16'b0100_1???_????_????: begin
573-
$display("[Decoder] Detected THUMB PC-relative load instruction with IR=0x%08x",
581+
$display("[GBA_Decoder] Detected THUMB PC-relative load instruction with IR=0x%08x",
574582
IR_THUMB);
575583

576584
bus.word.arm.ls.I = ARM_LDR_STR_IMMEDIATE;
@@ -593,7 +601,7 @@ module GBA_Decoder (
593601
16'b0100_01??_????_????: begin
594602
unique case (IR_THUMB[9:8])
595603
2'd0: begin
596-
$display("[Decoder] Detected THUMB ADD Rd, Hs instruction with IR=0x%08x",
604+
$display("[GBA_Decoder] Detected THUMB ADD Rd, Hs instruction with IR=0x%08x",
597605
IR_THUMB);
598606
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
599607

@@ -612,7 +620,7 @@ module GBA_Decoder (
612620
end
613621

614622
2'd1: begin
615-
$display("[Decoder] Detected THUMB CMP Rd, Hs instruction with IR=0x%08x",
623+
$display("[GBA_Decoder] Detected THUMB CMP Rd, Hs instruction with IR=0x%08x",
616624
IR_THUMB);
617625
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
618626

@@ -629,7 +637,7 @@ module GBA_Decoder (
629637

630638
2'd2: begin
631639
// TODO: Nop if R8 == R8
632-
$display("[Decoder] Detected THUMB MOV Rd, Hs instruction with IR=0x%08x",
640+
$display("[GBA_Decoder] Detected THUMB MOV Rd, Hs instruction with IR=0x%08x",
633641
IR_THUMB);
634642
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
635643

@@ -647,7 +655,7 @@ module GBA_Decoder (
647655

648656
2'd3: begin
649657
$display(
650-
"[Decoder] Detected THUMB BX instruction with Hs as operand instruction with IR=0x%08x",
658+
"[GBA_Decoder] Detected THUMB BX instruction with Hs as operand instruction with IR=0x%08x",
651659
IR_THUMB);
652660

653661
if (IR_THUMB[7] == 1'b0) begin
@@ -657,7 +665,7 @@ module GBA_Decoder (
657665
bus.instr_type = ARM_INSTR_BRANCH_EX;
658666

659667
$display(
660-
"[Decoder] Detected THUMB BLX instruction with Hs as operand instruction with IR=0x%08x, but BLX is not yet implemented, treating as BX for now",
668+
"[GBA_Decoder] Detected THUMB BLX instruction with Hs as operand instruction with IR=0x%08x, but BLX is not yet implemented, treating as BX for now",
661669
IR_THUMB);
662670
end
663671

@@ -669,7 +677,7 @@ module GBA_Decoder (
669677
endcase
670678

671679
$display(
672-
"[Decoder] Detected THUMB Hi register operation or branch exchange instruction with IR=0x%08x",
680+
"[GBA_Decoder] Detected THUMB Hi register operation or branch exchange instruction with IR=0x%08x",
673681
IR_THUMB);
674682
end
675683

@@ -678,11 +686,12 @@ module GBA_Decoder (
678686
// Rs: 5-3
679687
// Rd: 2-0
680688
16'b0100_00??_????_????: begin
681-
$display("[Decoder] Detected THUMB ALU operation instruction with IR=0x%08x", IR_THUMB);
689+
$display("[GBA_Decoder] Detected THUMB ALU operation instruction with IR=0x%08x",
690+
IR_THUMB);
682691

683692
unique case (IR_THUMB[9:6])
684693
4'h0, 4'h1, 4'h5, 4'h6, 4'h8, 4'hA, 4'hB, 4'hC, 4'hE, 4'hF: begin
685-
$display("[Decoder] Detected THUMB AND instruction with IR=0x%08x", IR_THUMB);
694+
$display("[GBA_Decoder] Detected THUMB AND instruction with IR=0x%08x", IR_THUMB);
686695
bus.word.arm.data_proc_reg_imm.opcode = decoder_util_pkg::THUMB_ALU_LUT[IR_THUMB[9:6]];
687696

688697
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
@@ -698,7 +707,7 @@ module GBA_Decoder (
698707
end
699708

700709
4'h2, 4'h3, 4'h4, 4'h7: begin
701-
$display("[Decoder] Detected THUMB LSL/LSR/ASR/ROR instruction with IR=0x%08x",
710+
$display("[GBA_Decoder] Detected THUMB LSL/LSR/ASR/ROR instruction with IR=0x%08x",
702711
IR_THUMB);
703712
bus.word.arm.data_proc_reg_reg.opcode = ALU_OP_MOV;
704713
bus.instr_type = ARM_INSTR_DATAPROC_REG_REG;
@@ -712,7 +721,7 @@ module GBA_Decoder (
712721
end
713722

714723
4'h9: begin
715-
$display("[Decoder] Detected THUMB NEG instruction with IR=0x%08x", IR_THUMB);
724+
$display("[GBA_Decoder] Detected THUMB NEG instruction with IR=0x%08x", IR_THUMB);
716725
bus.word.arm.data_proc_imm.opcode = ALU_OP_SUB_REVERSED;
717726
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
718727

@@ -726,7 +735,7 @@ module GBA_Decoder (
726735
end
727736

728737
4'hD: begin
729-
$display("[Decoder] Detected THUMB MUL instruction with IR=0x%08x", IR_THUMB);
738+
$display("[GBA_Decoder] Detected THUMB MUL instruction with IR=0x%08x", IR_THUMB);
730739
bus.instr_type = ARM_INSTR_MULTIPLY;
731740
bus.word.arm.mul.opcode = ARM_MUL;
732741

@@ -742,7 +751,7 @@ module GBA_Decoder (
742751
// Move / Compare / Add / Subtract Immediate
743752
16'b001?_????_????_????: begin
744753
$display(
745-
"[Decoder] Detected THUMB move/compare/add/subtract immediate instruction with IR=0x%08x",
754+
"[GBA_Decoder] Detected THUMB move/compare/add/subtract immediate instruction with IR=0x%08x",
746755
IR_THUMB);
747756

748757
// Performs
@@ -758,27 +767,28 @@ module GBA_Decoder (
758767

759768
unique case (IR_THUMB[12:11])
760769
2'b00: begin
761-
$display("[Decoder] Detected THUMB MOV immediate instruction with IR=0x%08x",
770+
$display("[GBA_Decoder] Detected THUMB MOV immediate instruction with IR=0x%08x",
762771
IR_THUMB);
763772
bus.word.arm.data_proc_imm.opcode = ALU_OP_MOV;
764773
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
765774
end
766775
2'b01: begin
767776
$display(
768-
"[Decoder] Detected THUMB CMP instruction with register operand with IR=0x%08x",
777+
"[GBA_Decoder] Detected THUMB CMP instruction with register operand with IR=0x%08x",
769778
IR_THUMB);
770779
bus.word.arm.data_proc_imm.opcode = ALU_OP_CMP;
771780
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
772781
end
773782
2'b10: begin
774-
$display("[Decoder] Detected THUMB add immediate instruction with IR=0x%08x",
783+
$display("[GBA_Decoder] Detected THUMB add immediate instruction with IR=0x%08x",
775784
IR_THUMB);
776785
bus.word.arm.data_proc_imm.opcode = ALU_OP_ADD;
777786
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
778787
end
779788
2'b11: begin
780-
$display("[Decoder] Detected THUMB subtract immediate instruction with IR=0x%08x",
781-
IR_THUMB);
789+
$display(
790+
"[GBA_Decoder] Detected THUMB subtract immediate instruction with IR=0x%08x",
791+
IR_THUMB);
782792
bus.word.arm.data_proc_imm.opcode = ALU_OP_SUB;
783793
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
784794
end
@@ -797,7 +807,7 @@ module GBA_Decoder (
797807
unique case (IR_THUMB[10:9])
798808
2'b00: begin
799809
$display(
800-
"[Decoder] Detected THUMB add instruction with register operand with IR=0x%08x",
810+
"[GBA_Decoder] Detected THUMB add instruction with register operand with IR=0x%08x",
801811
IR_THUMB);
802812
bus.word.arm.data_proc_reg_imm.opcode = ALU_OP_ADD;
803813
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
@@ -809,7 +819,7 @@ module GBA_Decoder (
809819
end
810820
2'b01: begin
811821
$display(
812-
"[Decoder] Detected THUMB subtract instruction with register operand with IR=0x%08x",
822+
"[GBA_Decoder] Detected THUMB subtract instruction with register operand with IR=0x%08x",
813823
IR_THUMB);
814824
bus.word.arm.data_proc_reg_imm.opcode = ALU_OP_SUB;
815825
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
@@ -821,7 +831,7 @@ module GBA_Decoder (
821831
end
822832
2'b10: begin
823833
$display(
824-
"[Decoder] Detected THUMB add instruction with immediate operand with IR=0x%08x",
834+
"[GBA_Decoder] Detected THUMB add instruction with immediate operand with IR=0x%08x",
825835
IR_THUMB);
826836
bus.word.arm.data_proc_imm.opcode = ALU_OP_ADD;
827837
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
@@ -832,7 +842,7 @@ module GBA_Decoder (
832842
end
833843
2'b11: begin
834844
$display(
835-
"[Decoder] Detected THUMB subtract instruction with immediate operand with IR=0x%08x",
845+
"[GBA_Decoder] Detected THUMB subtract instruction with immediate operand with IR=0x%08x",
836846
IR_THUMB);
837847
bus.word.arm.data_proc_imm.opcode = ALU_OP_SUB;
838848
bus.instr_type = ARM_INSTR_DATAPROC_IMM;
@@ -846,8 +856,9 @@ module GBA_Decoder (
846856

847857
// Move Shifted Register
848858
16'b000?_????_????_????: begin
849-
$display("[Decoder] Detected THUMB move shifted register instruction with IR=0x%08x",
850-
IR_THUMB);
859+
$display(
860+
"[GBA_Decoder] Detected THUMB move shifted register instruction with IR=0x%08x",
861+
IR_THUMB);
851862
bus.instr_type = ARM_INSTR_DATAPROC_REG_IMM;
852863

853864
bus.word.arm.data_proc_reg_imm.opcode = ALU_OP_MOV;
@@ -856,7 +867,9 @@ module GBA_Decoder (
856867
bus.word.arm.data_proc_reg_imm.shift_type = shift_type_t'(IR_THUMB[12:11]);
857868
bus.word.arm.data_proc_reg_imm.shift_amount = IR_THUMB[10:6];
858869

859-
bus.decoded_regs.Rn = 4'd0;
870+
bus.decoded_regs.Rm = 4'(IR_THUMB[5:3]);
871+
872+
bus.decoded_regs.Rn = 4'(IR_THUMB[5:3]);
860873
end
861874

862875
default: begin

0 commit comments

Comments
 (0)