Skip to content

Commit

Permalink
Change knight-native heap to be an offset from the start of stack
Browse files Browse the repository at this point in the history
rather than a fixed address
  • Loading branch information
oriansj committed Feb 3, 2021
1 parent cb87098 commit 259f067
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions knight/Native/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#define NULL 0
#define __PATH_MAX 4096
#define EOF 0xFFFFFFFF

void* malloc(unsigned size);

Expand Down
17 changes: 14 additions & 3 deletions knight/libc-native-file.M1
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@
LOADUI R0 0x1100
FOPEN_READ

LOADR32 R12 @HEAP ; Setup HEAP pointer
LOADUI R15 $STACK ; Setup initial stack pointer
LOADR R15 4
JUMP 4
&STACK ; Setup initial stack pointer
COPY R14 R15 ; Setup initial base pointer

LOADR32 R12 @HEAP ; Setup HEAP pointer
ADD R12 R12 R15 ; After Stack ends

;; Setup for FILE*
LOADR R0 4
JUMP 4
&FUNCTION___init_io
CALL R0 R15

LOADR R0 4
JUMP 4
&FUNCTION_main
CALL R0 R15
HALT ; Exit to kernel

;; Our default heap pointer
;; Our default heap offset (how big our stack ia)
:HEAP
'00100000'
7 changes: 4 additions & 3 deletions knight/libc-native.M1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.

:_start
LOADR32 R12 @HEAP ; Setup HEAP pointer

; Setup initial stack pointer
LOADR R15 4
JUMP 4
&STACK

LOADR32 R12 @HEAP ; Setup HEAP pointer
ADD R12 R12 R15 ; After Stack

; Setup initial base pointer
COPY R14 R15

Expand All @@ -33,6 +34,6 @@

HALT ; Exit to kernel

;; Our default heap pointer
;; Our default heap pointer (offset from start of stack)
:HEAP
'00100000'

0 comments on commit 259f067

Please sign in to comment.