diff --git a/docs/stack.md b/docs/stack.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/lib/libstring.asm b/examples/lib/libstring.asm new file mode 100644 index 0000000..e69de29 diff --git a/fibs.asm b/fibs.asm index 0782ce3..ca485dc 100644 --- a/fibs.asm +++ b/fibs.asm @@ -1,3 +1,4 @@ + .stack 0xFFFF .data 0x200 fibs: .space 56 diff --git a/riscemu/Executable.py b/riscemu/Executable.py index 0402aea..9597a6a 100644 --- a/riscemu/Executable.py +++ b/riscemu/Executable.py @@ -221,8 +221,9 @@ class LoadedMemorySection: print(FMT_BOLD + FMT_MAGENTA + "..." + FMT_NONE) def __repr__(self): - return "{} at 0x{:08X} (size={}bytes, flags={}, owner={})".format( + return "{}[{}] at 0x{:08X} (size={}bytes, flags={}, owner={})".format( self.__class__.__name__, + self.name, self.base, self.size, self.flags, @@ -258,20 +259,6 @@ class LoadedExecutable: self.exported_symbols = dict() self.global_symbol_table = dict() - # stack/heap if wanted - if exe.stack_pref is not None: - self.sections.append(LoadedMemorySection( - 'stack', - base_addr, - exe.stack_pref, - bytearray(exe.stack_pref), - MemoryFlags(read_only=False, executable=False), - self.name - )) - self.stack_heap = (self.base_addr, self.base_addr + exe.stack_pref) - else: - self.stack_heap = (0, 0) - curr = base_addr for sec in exe.sections.values(): loaded_sec = LoadedMemorySection( @@ -286,6 +273,21 @@ class LoadedExecutable: self.sections_by_name[loaded_sec.name] = loaded_sec curr = align_addr(loaded_sec.size + curr) + + # stack/heap if wanted + if exe.stack_pref is not None: + self.sections.append(LoadedMemorySection( + 'stack', + curr, + exe.stack_pref, + bytearray(exe.stack_pref), + MemoryFlags(read_only=False, executable=False), + self.name + )) + self.stack_heap = (curr, curr + exe.stack_pref) + else: + self.stack_heap = (0, 0) + for name, (sec_name, offset) in exe.symbols.items(): if sec_name == '_static_': self.symbols[name] = offset diff --git a/riscemu/ExecutableParser.py b/riscemu/ExecutableParser.py index eda87bf..f8a438f 100644 --- a/riscemu/ExecutableParser.py +++ b/riscemu/ExecutableParser.py @@ -98,7 +98,7 @@ class ExecutableParser: def op_stack(self, op: 'RiscVPseudoOpToken'): ASSERT_LEN(op.args, 1) - size = parse_numeric_argument(op.args) + size = parse_numeric_argument(op.args[0]) self.stack_pref = size def op_global(self, op: 'RiscVPseudoOpToken'):