From 7c89bfe7d3fb2c2b44c4188ed9ddb10370430d00 Mon Sep 17 00:00:00 2001 From: Kwarde Date: Thu, 31 Jul 2025 13:04:09 +0200 Subject: [PATCH] console.asm: printf** variables renamed to __fmt_** args since printf->__INTERNAL_fmt --- src/console.asm | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/console.asm b/src/console.asm index 495747c..5ed4698 100644 --- a/src/console.asm +++ b/src/console.asm @@ -6,10 +6,10 @@ extern utoa section .rodata mNL db NL - printfBuffLen equ 128 + __fmt_BuffLen equ 128 section .bss - printfBuff resb printfBuffLen - printfArgs resq 5 ;5=>rsi,rdx,rcx,r8,r9 + __fmt_Buff resb __fmt_BuffLen + __fmt_Args resq 5 ;5=>rsi,rdx,rcx,r8,r9 readsCBuff resb 1 section .text global __INTERNAL_fmt @@ -94,7 +94,7 @@ puts: ; rcx* (optional arg) >> Stores arg for %x/%X ; r8* (optional arg) >> Used for moving characters ; r9* (optional arg) >> Keeps track of where to jump after flushing buffer -; r10* Keeps track of current index of printfBuff +; r10* Keeps track of current index of __fmt_Buff ; r11* Keeps track of total characters (return value) ; r12 Padding length ; r13 Bitmask, 1 = insert specifier yes/no, 2 = use zeroes for padding yes/no @@ -125,7 +125,7 @@ __INTERNAL_fmt: %macro load_arg 1 cmp r14, 4 ja %%fromStack - mov %1, [printfArgs + SIZE_QWORD * r14] + mov %1, [__fmt_Args + SIZE_QWORD * r14] jmp %%continue %%fromStack: cmp r15, FD_stderr @@ -199,11 +199,11 @@ __INTERNAL_fmt: je .emptyStr ; Store arguments to memory - easier to load data + more available registers (= less stack usage) - mov [rel printfArgs + SIZE_QWORD * 0], rsi - mov [rel printfArgs + SIZE_QWORD * 1], rdx - mov [rel printfArgs + SIZE_QWORD * 2], rcx - mov [rel printfArgs + SIZE_QWORD * 3], r8 - mov [rel printfArgs + SIZE_QWORD * 4], r9 + mov [rel __fmt_Args + SIZE_QWORD * 0], rsi + mov [rel __fmt_Args + SIZE_QWORD * 1], rdx + mov [rel __fmt_Args + SIZE_QWORD * 2], rcx + mov [rel __fmt_Args + SIZE_QWORD * 3], r8 + mov [rel __fmt_Args + SIZE_QWORD * 4], r9 xor rdx, rdx xor r10, r10 @@ -214,7 +214,7 @@ __INTERNAL_fmt: cmp byte [rdi], EOS je .wrapup xor r9b, r9b - cmp r10, printfBuffLen-1 + cmp r10, __fmt_BuffLen-1 je .flushBuffer .flushReturn_0: cmp byte [rdi], '\' @@ -222,7 +222,7 @@ __INTERNAL_fmt: cmp byte [rdi], '%' je .argReplacement mov r8b, [rdi] - mov [printfBuff+r10], r8b + mov [__fmt_Buff+r10], r8b inc r10 inc r11 inc rdi @@ -245,10 +245,10 @@ __INTERNAL_fmt: .replaceAscii: mov r8b, r9b mov r9b, 2 - cmp r10, printfBuffLen-1 + cmp r10, __fmt_BuffLen-1 je .flushBuffer .flushReturn_2: - mov [printfBuff + r10], r8b + mov [__fmt_Buff + r10], r8b add rdi, 2 inc r10 inc r11 @@ -342,7 +342,7 @@ __INTERNAL_fmt: cmp byte [rdi + 1], '\' je .invalidReplacement_specialChar; '%\n' would become "'%','\','n'" instead of "'%',EOS" when inserting full invalid specifier. mov r9w, word [rdi] - mov [printfBuff+r10], r9w + mov [__fmt_Buff+r10], r9w add rdi, 2 add r10, 2 add r11, 2 @@ -350,7 +350,7 @@ __INTERNAL_fmt: jmp .process .invalidReplacement_specialChar: mov r9b, byte [rdi] - mov [printfBuff+r10], r9b + mov [__fmt_Buff+r10], r9b inc rdi inc r10 inc r11 @@ -407,12 +407,12 @@ __INTERNAL_fmt: jnz .doInsertString ;rsi = NULL: mov r9b, 3 - cmp r10, printfBuffLen-7 + cmp r10, __fmt_BuffLen-7 je .flushBuffer .flushReturn_3: - mov byte [printfBuff + r10], '(' - mov qword [printfBuff + r10 + 1], 'null' - mov byte [printfBuff + r10 + 5], ')' + mov byte [__fmt_Buff + r10], '(' + mov qword [__fmt_Buff + r10 + 1], 'null' + mov byte [__fmt_Buff + r10 + 5], ')' add r10, 6 add r11, 6 jmp .endInsertString @@ -421,11 +421,11 @@ __INTERNAL_fmt: cmp byte [rsi], EOS je .endInsertString mov r9b, 1 - cmp r10, printfBuffLen-1 + cmp r10, __fmt_BuffLen-1 je .flushBuffer .flushReturn_1: mov r8b, byte [rsi] - mov [printfBuff + r10], r8b + mov [__fmt_Buff + r10], r8b inc rsi inc r10 inc r11 @@ -438,7 +438,7 @@ __INTERNAL_fmt: ;--- Insert char to buffer ---; .insertChar: - mov [printfBuff + r10], sil + mov [__fmt_Buff + r10], sil add rdi, 2 add r10, 1 add r11, 1 @@ -453,7 +453,7 @@ __INTERNAL_fmt: push r11 mov rax, NR_write mov rdi, r15 - lea rsi, [rel printfBuff] + lea rsi, [rel __fmt_Buff] mov rdx, r10 syscall pop r11 @@ -476,7 +476,7 @@ __INTERNAL_fmt: .wrapup: mov rax, NR_write mov rdi, r15 - lea rsi, [rel printfBuff] + lea rsi, [rel __fmt_Buff] mov rdx, r10 mov r10, r11 syscall