浏览代码

cpu: move the reset vector away from 0

Address 0 is the default reset vector for picorv32, but it is also a
NULL pointer. Make the firmware a bit more robust against NULL pointer
references by providing a 16-byte guard zone at the start of memory.
H. Peter Anvin 3 年之前
父节点
当前提交
9ca2889add
共有 9 个文件被更改,包括 73 次插入56 次删除
  1. 2 2
      fpga/max80.sv
  2. 二进制
      fpga/output_files/max80.jbc
  3. 二进制
      fpga/output_files/max80.jic
  4. 二进制
      fpga/output_files/max80.pof
  5. 二进制
      fpga/output_files/max80.sof
  6. 50 50
      fw/boot.mif
  7. 10 1
      fw/head.S
  8. 9 1
      fw/max80.ld
  9. 2 2
      fw/sys.h

+ 2 - 2
fpga/max80.sv

@@ -456,8 +456,8 @@ module max80 (
 	.resetn ( rst_n ),
 	.trap ( cpu_trap ),
 
-	.progaddr_reset ( 32'h0000_0000 ),
-	.progaddr_irq   ( 32'h0000_0010 ),
+	.progaddr_reset ( 32'h0000_0010 ),
+	.progaddr_irq   ( 32'h0000_0020 ),
 
 	.mem_instr ( cpu_mem_instr ),
 	.mem_ready ( cpu_mem_ready ),

二进制
fpga/output_files/max80.jbc


二进制
fpga/output_files/max80.jic


二进制
fpga/output_files/max80.pof


二进制
fpga/output_files/max80.sof


+ 50 - 50
fw/boot.mif

@@ -4,54 +4,54 @@ WIDTH = 32;
 ADDRESS_RADIX = HEX;
 DATA_RADIX = HEX;
 CONTENT BEGIN
-0000 : C0102473;
-0001 : 00008137;
-0002 : 3380006F;
+0000 : 00000000;
+0001 : 00000000;
+0002 : 00000000;
 0003 : 00000000;
-0004 : 0001210B;
-0005 : 00000493;
-0006 : 0FFDF293;
-0007 : 00029663;
-0008 : 008DDD93;
-0009 : 02048493;
-000A : 00FDF293;
+0004 : C0102473;
+0005 : 00008137;
+0006 : 3280006F;
+0007 : 00000000;
+0008 : 0001210B;
+0009 : 00000493;
+000A : 0FFDF293;
 000B : 00029663;
-000C : 004DDD93;
-000D : 01048493;
-000E : 003DF293;
+000C : 008DDD93;
+000D : 02048493;
+000E : 00FDF293;
 000F : 00029663;
-0010 : 002DDD93;
-0011 : 00848493;
-0012 : 001DF293;
+0010 : 004DDD93;
+0011 : 01048493;
+0012 : 003DF293;
 0013 : 00029663;
-0014 : 001DDD93;
-0015 : 00448493;
-0016 : 07C4A283;
-0017 : 0024D513;
-0018 : 000D0593;
-0019 : 000280E7;
-001A : 001DDD93;
-001B : 00448493;
-001C : FA0D94E3;
-001D : 30200073;
-001E : 00000000;
-001F : 000006BE;
-0020 : 000006BE;
-0021 : 000006BE;
-0022 : 00000710;
+0014 : 002DDD93;
+0015 : 00848493;
+0016 : 001DF293;
+0017 : 00029663;
+0018 : 001DDD93;
+0019 : 00448493;
+001A : 08C4A283;
+001B : 0024D513;
+001C : 000D0593;
+001D : 000280E7;
+001E : 001DDD93;
+001F : 00448493;
+0020 : FA0D94E3;
+0021 : 30200073;
+0022 : 00000000;
 0023 : 000006BE;
-0024 : 0000072E;
+0024 : 000006BE;
 0025 : 000006BE;
-0026 : 000006BE;
+0026 : 00000710;
 0027 : 000006BE;
-0028 : 000006BE;
-0029 : 40085D20;
-002A : 00000001;
-002B : 00005C6C;
-002C : 00000000;
-002D : 00000000;
-002E : 00000000;
-002F : 00000000;
+0028 : 0000072E;
+0029 : 000006BE;
+002A : 000006BE;
+002B : 000006BE;
+002C : 000006BE;
+002D : 40085D20;
+002E : 00000001;
+002F : 00005C6C;
 0030 : 00000000;
 0031 : 00000000;
 0032 : 00000000;
@@ -292,7 +292,7 @@ CONTENT BEGIN
 011D : 55DDC010;
 011E : 06B0078B;
 011F : 069326D9;
-0120 : 428C0A80;
+0120 : 428C0B80;
 0121 : 05136815;
 0122 : 87135348;
 0123 : C2980015;
@@ -440,7 +440,7 @@ CONTENT BEGIN
 01B1 : FFF54293;
 01B2 : 0655050B;
 01B3 : 02938082;
-01B4 : 872A0A40;
+01B4 : 872A0B40;
 01B5 : 0002A503;
 01B6 : 404866B7;
 01B7 : D2068393;
@@ -4699,7 +4699,7 @@ CONTENT BEGIN
 1254 : B33D157D;
 1255 : 45014581;
 1256 : 25038082;
-1257 : 80820AC0;
+1257 : 80820BC0;
 1258 : C4221141;
 1259 : 6419C226;
 125A : 87936499;
@@ -4740,7 +4740,7 @@ CONTENT BEGIN
 127D : D8CADCA2;
 127E : C93AC736;
 127F : CF46CD42;
-1280 : 0AC02483;
+1280 : 0BC02483;
 1281 : 0005DC63;
 1282 : 08B00513;
 1283 : 557DC088;
@@ -4797,7 +4797,7 @@ CONTENT BEGIN
 12B6 : BF650003;
 12B7 : 86B28736;
 12B8 : 85AA862E;
-12B9 : 0AC02503;
+12B9 : 0BC02503;
 12BA : 1101B779;
 12BB : AB03C05A;
 12BC : CC220085;
@@ -5567,10 +5567,10 @@ CONTENT BEGIN
 15B8 : 6F206465;
 15B9 : 4F203A6E;
 15BA : 32207463;
-15BB : 30322031;
-15BC : 32203132;
-15BD : 34343A32;
-15BE : 0A34303A;
+15BB : 30322033;
+15BC : 30203132;
+15BD : 35343A30;
+15BE : 0A30323A;
 15BF : 5452000A;
 15C0 : 49203A43;
 15C1 : 53204332;

+ 10 - 1
fw/head.S

@@ -7,7 +7,16 @@
 	// don't use compressed instructions (there are very few anyway)
 	.option norvc
 
-	// The linker ensures that section .init is first
+	// NULL pointer guard area
+	// This needs to be an explicitly allocated section or the binary
+	// memory initialization file ends up broken.
+	.section ".null","a"
+	.globl _NULL
+_NULL:	.space _PC_RESET
+	.type	_NULL, @object
+	.size	_NULL, _PC_RESET
+
+	// The linker will always assign this to _PC_RESET
 	.section ".init.reset","ax"
 	.globl _reset
 _reset:

+ 9 - 1
fw/max80.ld

@@ -43,7 +43,15 @@ SECTIONS
 		*crt0.o(*)
 	}
 
-	PROVIDE (__executable_start = _PC_RESET);
+	PROVIDE (__executable_start = 0);
+
+	/*
+	 * Make sure the output binary starts at address 0
+	 */
+	.null 0 : {
+		PROVIDE(___NULL = .);
+		KEEP (*(SORT_NONE(.null)))
+	} >SRAM
 
 	.init.reset _PC_RESET : ALIGN(4) {
 		PROVIDE (___reset = .);

+ 2 - 2
fw/sys.h

@@ -25,7 +25,7 @@
 #define SDRAM_END       (SDRAM_ADDR + SDRAM_SIZE)
 
 /* This need to match the corresponding Verilog constants */
-#define _PC_RESET	0
-#define _PC_IRQ		0x10
+#define _PC_RESET	0x10
+#define _PC_IRQ		0x20
 
 #endif /* SYS_H */