From f17eedb8856ae568ebb9b45b367ef6edf1bb7318 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Wed, 13 Feb 2019 18:53:01 +0100 Subject: Initialize SP to safe RAM area. Address under 0xc0000000 corresponds to typical Linux stack on 32-bit systems. If SP is initialized to 0x00000000 then it can overwrite programs tarting at RAM begin and overflow to top of physical address-space which is reserved for uncached peripherals. Signed-off-by: Pavel Pisa --- qtmips_machine/registers.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'qtmips_machine') diff --git a/qtmips_machine/registers.cpp b/qtmips_machine/registers.cpp index b51be85..fa9731a 100644 --- a/qtmips_machine/registers.cpp +++ b/qtmips_machine/registers.cpp @@ -42,6 +42,7 @@ using namespace machine; ////////////////////////////////////////////////////////////////////////////// /// Program counter initial value #define PC_INIT 0x80020000 +#define SP_INIT 0xbfffff00 ////////////////////////////////////////////////////////////////////////////// Registers::Registers() : QObject() { @@ -136,6 +137,7 @@ void Registers::reset() { pc_abs_jmp(PC_INIT); // Initialize to beginning program section for (int i = 1; i < 32; i++) write_gp(i, 0); + write_gp(29, SP_INIT); // initialize to safe RAM area - corresponds to Linux write_hi_lo(false, 0); write_hi_lo(true, 0); } -- cgit v1.2.3