Browse Source

CPU now can execute instructions, at least in simulation!!

H. Peter Anvin 3 years ago
parent
commit
265fb7692e

+ 1 - 1
.gitignore

@@ -1,6 +1,6 @@
 db/
 incremental_db/
-simulation/
+modelsim/
 greybox_tmp/
 *~
 \#*

+ 1 - 1
fpga/Makefile

@@ -58,7 +58,7 @@ $(outdir)/%.jic:  %jic.cof $(outdir)/%.sof
 	$(PERL) scripts/qsfdeps.pl $< $* > $@
 
 clean:
-	rm -rf db incremental_db simulation \
+	rm -rf db incremental_db simulation/modelsim \
 	greybox_tmp */greybox_tmp \
 	$(outdir)/*.rpt $(outdir)/*.rpt \
 	$(outdir)/*.summary $(outdir)/*.smsg \

+ 1 - 1
fpga/fast_mem.sv

@@ -10,7 +10,7 @@ module fast_mem
     input 	  write,
     input 	  read,
     input [3:0]   wstrb,
-    input [11:0]  addr,
+    input [10:0]  addr,
     input [31:0]  wdata,
     output [31:0] rdata
     );

+ 2 - 1
fpga/functions.sv

@@ -4,7 +4,8 @@
 
 // ceil(ilog2(a))
 function int ilog2c(int a);
-  int b = 0;
+   int b;
+   b = 0;
    while ((1 << b) < a)
      b++;
    ilog2c = b;

+ 9 - 1
fpga/max80.qsf

@@ -51,7 +51,7 @@ set_global_assignment -name DEVICE_FILTER_PIN_COUNT 144
 set_global_assignment -name DEVICE_FILTER_SPEED_GRADE 8
 set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 256
 set_global_assignment -name EDA_SIMULATION_TOOL "ModelSim-Altera (Verilog)"
-set_global_assignment -name EDA_TIME_SCALE "1 ps" -section_id eda_simulation
+set_global_assignment -name EDA_TIME_SCALE "100 ps" -section_id eda_simulation
 set_global_assignment -name EDA_OUTPUT_DATA_FORMAT "VERILOG HDL" -section_id eda_simulation
 set_global_assignment -name EDA_GENERATE_FUNCTIONAL_NETLIST OFF -section_id eda_board_design_timing
 set_global_assignment -name EDA_GENERATE_FUNCTIONAL_NETLIST OFF -section_id eda_board_design_symbol
@@ -170,4 +170,12 @@ set_global_assignment -name SDC_FILE max80.sdc
 set_global_assignment -name SYSTEMVERILOG_FILE max80.sv
 set_global_assignment -name SOURCE_FILE max80.pins
 set_global_assignment -name SOURCE_TCL_SCRIPT_FILE scripts/pins.tcl
+set_global_assignment -name EDA_TEST_BENCH_ENABLE_STATUS TEST_BENCH_MODE -section_id eda_simulation
+set_global_assignment -name EDA_NATIVELINK_SIMULATION_TEST_BENCH testclk -section_id eda_simulation
+set_global_assignment -name EDA_TEST_BENCH_NAME testclk -section_id eda_simulation
+set_global_assignment -name EDA_DESIGN_INSTANCE_NAME max80 -section_id testclk
+set_global_assignment -name EDA_TEST_BENCH_RUN_SIM_FOR "1 ms" -section_id testclk
+set_global_assignment -name EDA_TEST_BENCH_MODULE_NAME testclk -section_id testclk
+set_global_assignment -name EDA_TEST_BENCH_FILE simulation/testclk.sv -section_id testclk
+set_global_assignment -name EDA_NATIVELINK_PORTABLE_FILE_PATHS ON -section_id eda_simulation
 set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top

+ 4 - 3
fpga/max80.sv

@@ -332,6 +332,7 @@ module max80 (
 
    wire       abc_rack;
    wire       abc_wack;
+   wire       abc_rvalid;
    wire [7:0] abc_sr_rd;
 
    always @(posedge sdram_clk or negedge rst_n)
@@ -461,7 +462,7 @@ module max80 (
 	      .ENABLE_IRQ_QREGS ( 1 ),
 	      .ENABLE_IRQ_TIMER ( 1 ),
 	      .REGS_INIT_ZERO ( 1 ),
-	      .STACKADDR ( 3'h4 << cpu_fast_mem_bits )
+	      .STACKADDR ( 32'h4 << cpu_fast_mem_bits )
 	      )
    cpu (
 	.clk ( clk ),
@@ -503,8 +504,8 @@ module max80 (
    fast_mem(
 	    .rst_n ( rst_n ),
 	    .clk   ( clk ),
-	    .read  ( mem_la_read  & cpu_la_addr[31:30] == 2'b00 ),
-	    .write ( mem_la_write & cpu_la_addr[31:30] == 2'b00 ),
+	    .read  ( cpu_la_read  & cpu_la_addr[31:30] == 2'b00 ),
+	    .write ( cpu_la_write & cpu_la_addr[31:30] == 2'b00 ),
 	    .wstrb ( cpu_la_wstrb ),
 	    .addr  ( cpu_la_addr[12:2] ),
 	    .wdata ( cpu_la_wdata ),

File diff suppressed because it is too large
+ 1533 - 382
fpga/output_files/max80.jam


BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


+ 1 - 1
fpga/output_files/max80.map

@@ -10,7 +10,7 @@ Quad-Serial configuration device dummy clock cycle: 8
 
 Notes:
 
-- Data checksum for this conversion is 0xF772717A
+- Data checksum for this conversion is 0xF76CAFE0
 
 - All the addresses in this file are byte addresses
 

BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


+ 2 - 0
fpga/sdram.sv

@@ -108,6 +108,8 @@ module sdram
 	      output reg	wack1
 	      );
 
+`include "functions.sv"		// For modelsim
+
    // Mode register data
    wire			    mrd_wburst = 1'b1;     // Write bursts enabled
    wire [2:0]		    mrd_cl     = t_cl;

+ 1 - 0
fpga/simulation/fw

@@ -0,0 +1 @@
+../../fw

+ 21 - 0
fpga/simulation/testclk.sv

@@ -0,0 +1,21 @@
+`timescale 1 ns / 100 ps
+
+module testclk;
+   reg clock_48 = 1'b0;
+
+   wire [2:0] led;
+
+   real       mhz96_ns = 1000.0/96.0;
+
+   initial
+     begin
+	forever
+	  #(mhz96_ns) clock_48 = !clock_48;
+     end
+
+   max80 max80 (
+		.clock_48 ( clock_48 ),
+		.led ( led )
+		);
+endmodule // testclk
+

+ 1 - 0
fw/.gitignore

@@ -3,5 +3,6 @@
 *.s
 *.elf
 *.bin
+*.ver
 *.build/
 tools/gnu/

+ 1 - 0
fw/Makefile

@@ -11,6 +11,7 @@ CPPFLAGS  = $(INCLUDE) $(riscv_flags)
 CFLAGS    = $(CPPFLAGS)
 SFLAGS    = $(CPPFLAGS) -D__ASSEMBLY__
 LDFLAGS   = $(CFLAGS) \
+	    -nostdlib \
 	    -Wl,--section-start=.init=0 -Wl,-q \
 	    -Wl,-z,common-page-size=16 -Wl,-z,max-page-size=16
 

+ 8 - 497
fw/boot.mif

@@ -4,504 +4,15 @@ WIDTH = 32;
 ADDRESS_RADIX = HEX;
 DATA_RADIX = HEX;
 CONTENT BEGIN
-000 : 03A0006F;
+000 : 0160006F;
 001 : 00000000;
 002 : 00000000;
 003 : 00000000;
-004 : 0A40006F;
-005 : 36400293;
-006 : C00006B7;
-007 : 0002C703;
-008 : A001E311;
-009 : 00E68023;
-00A : BFCD0285;
-00B : 00000793;
-00C : 0513C781;
-00D : A48D2A20;
-00E : 11978082;
-00F : 81930000;
-010 : 0513F861;
-011 : 06137CC0;
-012 : 8E097E80;
-013 : 20D54581;
-014 : 00000517;
-015 : 24850513;
-016 : 0517C511;
-017 : 05130000;
-018 : 2C1D2485;
-019 : 450220B5;
-01A : 4601004C;
-01B : A0A13765;
-01C : C4221141;
-01D : 7CC04783;
-01E : EF89C606;
-01F : 00000793;
-020 : 0513C799;
-021 : 00973840;
-022 : 00E70000;
-023 : 47850000;
-024 : 7CF00623;
-025 : 442240B2;
-026 : 80820141;
-027 : 00000793;
-028 : 0593CB89;
-029 : 05137D00;
-02A : 03173840;
-02B : 00670000;
-02C : 80820000;
-02D : 1141A001;
-02E : C4224581;
-02F : 842AC606;
-030 : 25032A29;
-031 : 5D5C7C00;
-032 : 9782C391;
-033 : 2C858522;
-034 : C4221141;
-035 : 0793C04A;
-036 : 09133880;
-037 : 09333880;
-038 : C60640F9;
-039 : 5913C226;
-03A : 0B634029;
-03B : 04130009;
-03C : 44813880;
-03D : 0485401C;
-03E : 97820411;
-03F : FE991CE3;
-040 : 38800793;
-041 : 39000913;
-042 : 40F90933;
-043 : 40295913;
-044 : 00090B63;
-045 : 38800413;
-046 : 401C4481;
-047 : 04110485;
-048 : 1CE39782;
-049 : 40B2FE99;
-04A : 44924422;
-04B : 01414902;
-04C : 433D8082;
-04D : 7363872A;
-04E : 779302C3;
-04F : EFBD00F7;
-050 : 7693E5AD;
-051 : 8A3DFF06;
-052 : C30C96BA;
-053 : C70CC34C;
-054 : 0741C74C;
-055 : FED76BE3;
-056 : 8082E211;
-057 : 40C306B3;
-058 : 0297068A;
-059 : 96960000;
-05A : 00A68067;
-05B : 00B70723;
-05C : 00B706A3;
-05D : 00B70623;
-05E : 00B705A3;
-05F : 00B70523;
-060 : 00B704A3;
-061 : 00B70423;
-062 : 00B703A3;
-063 : 00B70323;
-064 : 00B702A3;
-065 : 00B70223;
-066 : 00B701A3;
-067 : 00B70123;
-068 : 00B700A3;
-069 : 00B70023;
-06A : F5938082;
-06B : 96930FF5;
-06C : 8DD50085;
-06D : 01059693;
-06E : B7618DD5;
-06F : 00279693;
-070 : 00000297;
-071 : 82869696;
-072 : FA8680E7;
-073 : 17C18096;
-074 : 963E8F1D;
-075 : F8C374E3;
-076 : 7179B7A5;
-077 : 2A03CC52;
-078 : D04A7C00;
-079 : 2903D606;
-07A : D422148A;
-07B : CE4ED226;
-07C : C85ACA56;
-07D : C462C65E;
-07E : 02090863;
-07F : 8BAE8B2A;
-080 : 59FD4A85;
-081 : 00492483;
-082 : FFF48413;
-083 : 00044E63;
-084 : 94CA048A;
-085 : 020B8663;
-086 : 1044A783;
-087 : 03778263;
-088 : 14F1147D;
-089 : FF3418E3;
-08A : 542250B2;
-08B : 59025492;
-08C : 4A6249F2;
-08D : 4B424AD2;
-08E : 4C224BB2;
-08F : 80826145;
-090 : 00492783;
-091 : 17FD40D4;
-092 : 04878263;
-093 : 0004A223;
-094 : 2783DAE1;
-095 : 97331889;
-096 : 2C03008A;
-097 : 8FF90049;
-098 : 9682EF89;
-099 : 00492703;
-09A : 148A2783;
-09B : 01871463;
-09C : FB2788E3;
-09D : 893EDBD5;
-09E : 2783B771;
-09F : A58318C9;
-0A0 : 8F7D0844;
-0A1 : 855AE719;
-0A2 : BFE99682;
-0A3 : 00892223;
-0A4 : 852EB7C1;
-0A5 : B7F99682;
-0A6 : 468185AA;
-0A7 : 45014601;
-0A8 : 1141A80D;
-0A9 : 0793C422;
-0AA : 04133900;
-0AB : 8C1D3940;
-0AC : C606C226;
-0AD : 40245493;
-0AE : 1471C881;
-0AF : 401C943E;
-0B0 : 147114FD;
-0B1 : FCE59782;
-0B2 : 442240B2;
-0B3 : 01414492;
-0B4 : 27038082;
-0B5 : 27837C00;
-0B6 : C3A11487;
-0B7 : 487D43D8;
-0B8 : 04E84D63;
-0B9 : 00271813;
-0BA : 8333C11D;
-0BB : 24230107;
-0BC : A88308C3;
-0BD : 46051887;
-0BE : 00E61633;
-0BF : 00C8E8B3;
-0C0 : 1917A423;
-0C1 : 10D32423;
-0C2 : 0D634689;
-0C3 : 070500D5;
-0C4 : 97C2C3D8;
-0C5 : 4501C78C;
-0C6 : 07938082;
-0C7 : 242314C7;
-0C8 : BF6D14F7;
-0C9 : 18C7A683;
-0CA : C3D80705;
-0CB : A6238ED1;
-0CC : 97C218D7;
-0CD : 4501C78C;
-0CE : 557D8082;
-0CF : 08938082;
-0D0 : 007305D0;
-0D1 : 43630000;
-0D2 : A0010005;
-0D3 : C4221141;
-0D4 : C606842A;
-0D5 : 40800433;
-0D6 : C1002019;
-0D7 : 2503A001;
-0D8 : 80827C80;
-0D9 : 6C6C6548;
-0DA : 57202C6F;
-0DB : 646C726F;
-0DC : 000A0D21;
-0DD : 00000000;
-0DE : 00000000;
-0DF : 00000000;
-0E0 : 00000000;
-0E1 : 00000000;
-0E2 : 0000002C;
-0E3 : 0000009C;
-0E4 : 00000070;
-0E5 : 00000000;
-0E6 : 00000000;
-0E7 : 00000684;
-0E8 : 000006EC;
-0E9 : 00000754;
-0EA : 00000000;
-0EB : 00000000;
-0EC : 00000000;
-0ED : 00000000;
-0EE : 00000000;
-0EF : 00000000;
-0F0 : 00000000;
-0F1 : 00000000;
-0F2 : 00000000;
-0F3 : 00000000;
-0F4 : 00000000;
-0F5 : 00000000;
-0F6 : 00000000;
-0F7 : 00000000;
-0F8 : 00000000;
-0F9 : 00000000;
-0FA : 00000000;
-0FB : 00000000;
-0FC : 00000000;
-0FD : 00000000;
-0FE : 00000000;
-0FF : 00000000;
-100 : 00000000;
-101 : 00000000;
-102 : 00000000;
-103 : 00000000;
-104 : 00000000;
-105 : 00000000;
-106 : 00000000;
-107 : 00000000;
-108 : 00000000;
-109 : 00000000;
-10A : 00000000;
-10B : 00000000;
-10C : 00000000;
-10D : 00000000;
-10E : 00000000;
-10F : 00000000;
-110 : 00000001;
-111 : 00000000;
-112 : ABCD330E;
-113 : E66D1234;
-114 : 0005DEEC;
-115 : 0000000B;
-116 : 00000000;
-117 : 00000000;
-118 : 00000000;
-119 : 00000000;
-11A : 00000000;
-11B : 00000000;
-11C : 00000000;
-11D : 00000000;
-11E : 00000000;
-11F : 00000000;
-120 : 00000000;
-121 : 00000000;
-122 : 00000000;
-123 : 00000000;
-124 : 00000000;
-125 : 00000000;
-126 : 00000000;
-127 : 00000000;
-128 : 00000000;
-129 : 00000000;
-12A : 00000000;
-12B : 00000000;
-12C : 00000000;
-12D : 00000000;
-12E : 00000000;
-12F : 00000000;
-130 : 00000000;
-131 : 00000000;
-132 : 00000000;
-133 : 00000000;
-134 : 00000000;
-135 : 00000000;
-136 : 00000000;
-137 : 00000000;
-138 : 00000000;
-139 : 00000000;
-13A : 00000000;
-13B : 00000000;
-13C : 00000000;
-13D : 00000000;
-13E : 00000000;
-13F : 00000000;
-140 : 00000000;
-141 : 00000000;
-142 : 00000000;
-143 : 00000000;
-144 : 00000000;
-145 : 00000000;
-146 : 00000000;
-147 : 00000000;
-148 : 00000000;
-149 : 00000000;
-14A : 00000000;
-14B : 00000000;
-14C : 00000000;
-14D : 00000000;
-14E : 00000000;
-14F : 00000000;
-150 : 00000000;
-151 : 00000000;
-152 : 00000000;
-153 : 00000000;
-154 : 00000000;
-155 : 00000000;
-156 : 00000000;
-157 : 00000000;
-158 : 00000000;
-159 : 00000000;
-15A : 00000000;
-15B : 00000000;
-15C : 00000000;
-15D : 00000000;
-15E : 00000000;
-15F : 00000000;
-160 : 00000000;
-161 : 00000000;
-162 : 00000000;
-163 : 00000000;
-164 : 00000000;
-165 : 00000000;
-166 : 00000000;
-167 : 00000000;
-168 : 00000000;
-169 : 00000000;
-16A : 00000000;
-16B : 00000000;
-16C : 00000000;
-16D : 00000000;
-16E : 00000000;
-16F : 00000000;
-170 : 00000000;
-171 : 00000000;
-172 : 00000000;
-173 : 00000000;
-174 : 00000000;
-175 : 00000000;
-176 : 00000000;
-177 : 00000000;
-178 : 00000000;
-179 : 00000000;
-17A : 00000000;
-17B : 00000000;
-17C : 00000000;
-17D : 00000000;
-17E : 00000000;
-17F : 00000000;
-180 : 00000000;
-181 : 00000000;
-182 : 00000000;
-183 : 00000000;
-184 : 00000000;
-185 : 00000000;
-186 : 00000000;
-187 : 00000000;
-188 : 00000000;
-189 : 00000000;
-18A : 00000000;
-18B : 00000000;
-18C : 00000000;
-18D : 00000000;
-18E : 00000000;
-18F : 00000000;
-190 : 00000000;
-191 : 00000000;
-192 : 00000000;
-193 : 00000000;
-194 : 00000000;
-195 : 00000000;
-196 : 00000000;
-197 : 00000000;
-198 : 00000000;
-199 : 00000000;
-19A : 00000000;
-19B : 00000000;
-19C : 00000000;
-19D : 00000000;
-19E : 00000000;
-19F : 00000000;
-1A0 : 00000000;
-1A1 : 00000000;
-1A2 : 00000000;
-1A3 : 00000000;
-1A4 : 00000000;
-1A5 : 00000000;
-1A6 : 00000000;
-1A7 : 00000000;
-1A8 : 00000000;
-1A9 : 00000000;
-1AA : 00000000;
-1AB : 00000000;
-1AC : 00000000;
-1AD : 00000000;
-1AE : 00000000;
-1AF : 00000000;
-1B0 : 00000000;
-1B1 : 00000000;
-1B2 : 00000000;
-1B3 : 00000000;
-1B4 : 00000000;
-1B5 : 00000000;
-1B6 : 00000000;
-1B7 : 00000000;
-1B8 : 00000000;
-1B9 : 00000000;
-1BA : 00000000;
-1BB : 00000000;
-1BC : 00000000;
-1BD : 00000000;
-1BE : 00000000;
-1BF : 00000000;
-1C0 : 00000000;
-1C1 : 00000000;
-1C2 : 00000000;
-1C3 : 00000000;
-1C4 : 00000000;
-1C5 : 00000000;
-1C6 : 00000000;
-1C7 : 00000000;
-1C8 : 00000000;
-1C9 : 00000000;
-1CA : 00000000;
-1CB : 00000000;
-1CC : 00000000;
-1CD : 00000000;
-1CE : 00000000;
-1CF : 00000000;
-1D0 : 00000000;
-1D1 : 00000000;
-1D2 : 00000000;
-1D3 : 00000000;
-1D4 : 00000000;
-1D5 : 00000000;
-1D6 : 00000000;
-1D7 : 00000000;
-1D8 : 00000000;
-1D9 : 00000000;
-1DA : 00000000;
-1DB : 00000000;
-1DC : 00000000;
-1DD : 00000000;
-1DE : 00000000;
-1DF : 00000000;
-1E0 : 00000000;
-1E1 : 00000000;
-1E2 : 00000000;
-1E3 : 00000000;
-1E4 : 00000000;
-1E5 : 00000000;
-1E6 : 00000000;
-1E7 : 00000000;
-1E8 : 00000000;
-1E9 : 00000000;
-1EA : 00000000;
-1EB : 00000000;
-1EC : 00000000;
-1ED : 00000000;
-1EE : 00000000;
-1EF : 00000000;
-1F0 : 00000398;
-1F1 : 00000000;
-1F2 : 00000398;
-[1F3..7FF] : 00;
+004 : 0040006F;
+005 : 4781A001;
+006 : 00178713;
+007 : C0F00023;
+008 : 0FF77793;
+009 : BFD5;
+[00A..7FF] : 00;
 END;

+ 25 - 6
fw/hello.c

@@ -1,4 +1,10 @@
-#define CONSOLE (*(volatile unsigned char *)0xc0000000)
+#include <stddef.h>
+#include <stdint.h>
+
+#define IODEVB(d,r) (*(volatile uint8_t *)(0xfffffc00+((d) << 6)+((r) << 2)))
+
+#define LED     IODEVB(0,0)
+#define CONSOLE IODEVB(1,0)
 
 void die(void)
 {
@@ -6,16 +12,29 @@ void die(void)
 	;
 }
 
-int main(void)
+void _start(void)
 {
     static const char hello[] = "Hello, World!\r\n";
     const char *p;
-    int x = 1;
+    uint8_t led = 0;
+
+    while ( 1 )
+      LED = led++;
+
+#if 0
 
-    for (p = hello; *p; p++) {
+    LED = led = 0;
+
+    for (p = hello; *p; p++)
 	CONSOLE = *p;
-	x *= *p;
-    }
 
+    while ( 1 ) {
+      for (int x = 0; x < 1000000; x++)
+	/* nothing */;
+
+      LED = ++led;
+    }
+#endif
+    
     die();
 }

+ 2 - 1
riscv-opts.mk

@@ -6,4 +6,5 @@ riscv_target_flags =	-fvisibility=hidden -fno-pic \
 
 # Additional flags during application build
 riscv_flags = $(riscv_target_flags) \
-			-Os -ggdb3 -fwrapv -fno-strict-aliasing
+			 -specs=nano.specs -Os -ggdb3 -fwrapv \
+			-fno-strict-aliasing

Some files were not shown because too many files changed in this diff