Adds _initializor to handle entry/exit. 'tests' now exits with 'amount of failed tests' as exit code

This commit is contained in:
2025-08-04 12:44:44 +02:00
parent 02580e9b0b
commit f790f5948c
4 changed files with 65 additions and 4 deletions

30
' Normal file
View 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

View File

@@ -3,6 +3,7 @@ DIR_BLD := build
DIR_BIN := $(DIR_BLD)/bin DIR_BIN := $(DIR_BLD)/bin
OBJS := $(DIR_BLD)/tests.o \ OBJS := $(DIR_BLD)/tests.o \
$(DIR_BLD)/_initializor.o \
$(DIR_BLD)/constants.o \ $(DIR_BLD)/constants.o \
$(DIR_BLD)/core.o \ $(DIR_BLD)/core.o \
$(DIR_BLD)/console.o \ $(DIR_BLD)/console.o \

25
src/_initializor.asm Normal file
View 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

View File

@@ -440,8 +440,11 @@ section .bss
statBuff2 resb STATBUFF_SIZE statBuff2 resb STATBUFF_SIZE
section .text section .text
global _start global main
_start: main:
push rbp
mov rbp, rsp
xor r13, r13 ;total tests xor r13, r13 ;total tests
xor r14, r14 ;OK tests (assert => true) xor r14, r14 ;OK tests (assert => true)
@@ -1691,8 +1694,10 @@ _start:
mov rdx, r14 mov rdx, r14
mov rcx, r13 mov rcx, r13
sub rcx, r14 sub rcx, r14
mov r15, rcx
call printf call printf
;--- exit() ;--- exit()
xor rdi, rdi leave
call exit mov rax, r15
ret