aboutsummaryrefslogtreecommitdiffstats
path: root/picosoc/firmware.c
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/firmware.c
parent1c8266869ad5179e99f5c063ad203c80f37b65c5 (diff)
downloadpicorv32-76124b8649c85e4e7218b776733d93d364e28845.tar.gz
picorv32-76124b8649c85e4e7218b776733d93d364e28845.zip
Removed UB from picosoc demo firmware
Diffstat (limited to 'picosoc/firmware.c')
-rw-r--r--picosoc/firmware.c8
1 files changed, 6 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)();
}
// --------------------------------------------------------