1) REALLY fix strcat crash (git restored wrong file in previous commit) 2) fopen: less labels ffs

This commit is contained in:
2025-07-27 21:17:59 +02:00
parent ca6d6e6d31
commit f18de90868
2 changed files with 13 additions and 10 deletions

View File

@@ -97,7 +97,7 @@ fgetmod:
; rdi (arg) Pointer to string holding (path+)file name ; rdi (arg) Pointer to string holding (path+)file name
; rsi Mode to open the file with (see description above) ; rsi Mode to open the file with (see description above)
fopen: fopen:
%macro createFile 1 %macro createFile 0
push rdi push rdi
push rsi push rsi
call fexist call fexist
@@ -105,7 +105,7 @@ fopen:
pop rdi pop rdi
test rax, 1 test rax, 1
jz %%createFile jz %%createFile
jmp %1 jmp %%cnt
%%createFile: %%createFile:
push rsi push rsi
push rdi push rdi
@@ -119,6 +119,7 @@ fopen:
syscall syscall
pop rdi pop rdi
pop rsi pop rsi
%%cnt:
%endmacro %endmacro
;;; ;;;
;;; ENTRY ;;; ENTRY
@@ -144,26 +145,22 @@ fopen:
mov rsi, O_RDONLY mov rsi, O_RDONLY
jmp .open jmp .open
.setMode_w: .setMode_w:
createFile .open_w createFile
.open_w:
mov rsi, O_WRONLY | O_TRUNC mov rsi, O_WRONLY | O_TRUNC
jmp .open jmp .open
.setMode_a: .setMode_a:
createFile .open_a createFile
.open_a:
mov rsi, O_WRONLY | O_APPEND mov rsi, O_WRONLY | O_APPEND
jmp .open jmp .open
.setMode_R: .setMode_R:
mov rsi, O_RDWR mov rsi, O_RDWR
jmp .open jmp .open
.setMode_W: .setMode_W:
createFile .open_W createFile
.open_W:
mov rsi, O_RDWR | O_TRUNC mov rsi, O_RDWR | O_TRUNC
jmp .open jmp .open
.setMode_A: .setMode_A:
createFile .open_A createFile
.open_A:
mov rsi, O_RDWR | O_APPEND mov rsi, O_RDWR | O_APPEND
jmp .open jmp .open

View File

@@ -66,10 +66,12 @@ strcpy:
; r8* Backup for rdi (point to start of dest) ; r8* Backup for rdi (point to start of dest)
; r9* Backup for rsi ; r9* Backup for rsi
; r10* Backup for rdi (point to end of dest) ; r10* Backup for rdi (point to end of dest)
; r11* Backup for strlen(dest)
strcat: strcat:
mov r8, rdi mov r8, rdi
mov r9, rsi mov r9, rsi
call strlen call strlen
mov r11, rax
sub rdx, rax sub rdx, rax
dec rdi dec rdi
mov r10, rdi mov r10, rdi
@@ -78,13 +80,17 @@ strcat:
cmp rax, rdx cmp rax, rdx
jb .copy jb .copy
dec rdx dec rdx
.copy: .copy:
cmp rdx, r11
jle .quit
mov rcx, rdx mov rcx, rdx
mov rsi, r9 mov rsi, r9
mov rdi, r10 mov rdi, r10
cld cld
rep movsb rep movsb
mov byte [rdi], EOS mov byte [rdi], EOS
.quit:
mov rax, r8 mov rax, r8
ret ret