Adds _initializor to handle entry/exit. 'tests' now exits with 'amount of failed tests' as exit code
This commit is contained in:
30
'
Normal file
30
'
Normal file
@@ -0,0 +1,30 @@
|
||||
%include "src/constants/sizes.asm"
|
||||
|
||||
extern exit
|
||||
extern main
|
||||
|
||||
section .text
|
||||
global _start
|
||||
global stack_is_top
|
||||
|
||||
_start:
|
||||
mov rdi, [rsp]
|
||||
lea rsi, [rsp + SIZE_QWORD]
|
||||
push rsp ;Can maybe used as a method to find out if we're at top of the stack
|
||||
push -1
|
||||
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
|
||||
stack_is_top:
|
||||
xor rax, rax
|
||||
mov rdi, rsp
|
||||
cmp rdi, [rsp]
|
||||
je .yes
|
||||
jmp .q
|
||||
.yes:
|
||||
inc al
|
||||
.q:
|
||||
ret
|
1
Makefile
1
Makefile
@@ -3,6 +3,7 @@ DIR_BLD := build
|
||||
DIR_BIN := $(DIR_BLD)/bin
|
||||
|
||||
OBJS := $(DIR_BLD)/tests.o \
|
||||
$(DIR_BLD)/_initializor.o \
|
||||
$(DIR_BLD)/constants.o \
|
||||
$(DIR_BLD)/core.o \
|
||||
$(DIR_BLD)/console.o \
|
||||
|
25
src/_initializor.asm
Normal file
25
src/_initializor.asm
Normal file
@@ -0,0 +1,25 @@
|
||||
%include "src/constants/sizes.asm"
|
||||
|
||||
extern exit
|
||||
extern main
|
||||
|
||||
section .text
|
||||
global _start
|
||||
|
||||
_start:
|
||||
; Store argc and argv
|
||||
mov rdi, [rsp]
|
||||
lea rsi, [rsp + SIZE_QWORD]
|
||||
|
||||
; Increase stack (fill with zeroes)
|
||||
; Some functions(wrappers) like format() will try to read beyond stack when:
|
||||
; - No args were passed
|
||||
; - Stack is at top
|
||||
; This prevents that
|
||||
push 0
|
||||
push 0
|
||||
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
@@ -440,8 +440,11 @@ section .bss
|
||||
statBuff2 resb STATBUFF_SIZE
|
||||
|
||||
section .text
|
||||
global _start
|
||||
_start:
|
||||
global main
|
||||
main:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
xor r13, r13 ;total tests
|
||||
xor r14, r14 ;OK tests (assert => true)
|
||||
|
||||
@@ -1691,8 +1694,10 @@ _start:
|
||||
mov rdx, r14
|
||||
mov rcx, r13
|
||||
sub rcx, r14
|
||||
mov r15, rcx
|
||||
call printf
|
||||
|
||||
;--- exit()
|
||||
xor rdi, rdi
|
||||
call exit
|
||||
leave
|
||||
mov rax, r15
|
||||
ret
|
||||
|
Reference in New Issue
Block a user