aboutsummaryrefslogtreecommitdiffstats
path: root/picosoc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2017-09-15 19:55:22 +0200
committerClifford Wolf <clifford@clifford.at>2017-09-15 19:55:22 +0200
commit76124b8649c85e4e7218b776733d93d364e28845 (patch)
treee45d52f766490d76bc502e30aa9cff9b8e5c5ca7 /picosoc
parent1c8266869ad5179e99f5c063ad203c80f37b65c5 (diff)
downloadpicorv32-76124b8649c85e4e7218b776733d93d364e28845.tar.gz
picorv32-76124b8649c85e4e7218b776733d93d364e28845.zip
Removed UB from picosoc demo firmware
Diffstat (limited to 'picosoc')
-rw-r--r--picosoc/firmware.c8
-rw-r--r--picosoc/sections.lds1
2 files changed, 7 insertions, 2 deletions
diff --git a/picosoc/firmware.c b/picosoc/firmware.c
index 660ef56..ce766fc 100644
--- a/picosoc/firmware.c
+++ b/picosoc/firmware.c
@@ -1,5 +1,9 @@
#include <stdint.h>
+// a pointer to this is a null pointer, but the compiler does not
+// know that because "sram" is a linker symbol from sections.lds.
+extern uint32_t sram;
+
#define reg_spictrl (*(volatile uint32_t*)0x02000000)
#define reg_uart_clkdiv (*(volatile uint32_t*)0x02000004)
#define reg_uart_data (*(volatile uint32_t*)0x02000008)
@@ -53,12 +57,12 @@ extern uint32_t cmd_read_spi_flash_id_worker_end;
void cmd_read_spi_flash_id()
{
uint32_t *src_ptr = &cmd_read_spi_flash_id_worker_begin;
- uint32_t *dst_ptr = (uint32_t*)0;
+ uint32_t *dst_ptr = &sram;
while (src_ptr != &cmd_read_spi_flash_id_worker_end)
*(dst_ptr++) = *(src_ptr++);
- ((void(*)())0)();
+ ((void(*)())&sram)();
}
// --------------------------------------------------------
diff --git a/picosoc/sections.lds b/picosoc/sections.lds
index 1fe7919..6c59cb8 100644
--- a/picosoc/sections.lds
+++ b/picosoc/sections.lds
@@ -1,5 +1,6 @@
SECTIONS {
.memory : {
+ sram = 0;
. = 0x100000;
start*(.text);
*(.text);