console.asm: printf** variables renamed to __fmt_** args since printf->__INTERNAL_fmt

This commit is contained in:
2025-07-31 13:04:09 +02:00
parent 93c606541d
commit 7c89bfe7d3

View File

@@ -6,10 +6,10 @@ extern utoa
section .rodata section .rodata
mNL db NL mNL db NL
printfBuffLen equ 128 __fmt_BuffLen equ 128
section .bss section .bss
printfBuff resb printfBuffLen __fmt_Buff resb __fmt_BuffLen
printfArgs resq 5 ;5=>rsi,rdx,rcx,r8,r9 __fmt_Args resq 5 ;5=>rsi,rdx,rcx,r8,r9
readsCBuff resb 1 readsCBuff resb 1
section .text section .text
global __INTERNAL_fmt global __INTERNAL_fmt
@@ -94,7 +94,7 @@ puts:
; rcx* (optional arg) >> Stores arg for %x/%X ; rcx* (optional arg) >> Stores arg for %x/%X
; r8* (optional arg) >> Used for moving characters ; r8* (optional arg) >> Used for moving characters
; r9* (optional arg) >> Keeps track of where to jump after flushing buffer ; 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) ; r11* Keeps track of total characters (return value)
; r12 Padding length ; r12 Padding length
; r13 Bitmask, 1 = insert specifier yes/no, 2 = use zeroes for padding yes/no ; r13 Bitmask, 1 = insert specifier yes/no, 2 = use zeroes for padding yes/no
@@ -125,7 +125,7 @@ __INTERNAL_fmt:
%macro load_arg 1 %macro load_arg 1
cmp r14, 4 cmp r14, 4
ja %%fromStack ja %%fromStack
mov %1, [printfArgs + SIZE_QWORD * r14] mov %1, [__fmt_Args + SIZE_QWORD * r14]
jmp %%continue jmp %%continue
%%fromStack: %%fromStack:
cmp r15, FD_stderr cmp r15, FD_stderr
@@ -199,11 +199,11 @@ __INTERNAL_fmt:
je .emptyStr je .emptyStr
; Store arguments to memory - easier to load data + more available registers (= less stack usage) ; Store arguments to memory - easier to load data + more available registers (= less stack usage)
mov [rel printfArgs + SIZE_QWORD * 0], rsi mov [rel __fmt_Args + SIZE_QWORD * 0], rsi
mov [rel printfArgs + SIZE_QWORD * 1], rdx mov [rel __fmt_Args + SIZE_QWORD * 1], rdx
mov [rel printfArgs + SIZE_QWORD * 2], rcx mov [rel __fmt_Args + SIZE_QWORD * 2], rcx
mov [rel printfArgs + SIZE_QWORD * 3], r8 mov [rel __fmt_Args + SIZE_QWORD * 3], r8
mov [rel printfArgs + SIZE_QWORD * 4], r9 mov [rel __fmt_Args + SIZE_QWORD * 4], r9
xor rdx, rdx xor rdx, rdx
xor r10, r10 xor r10, r10
@@ -214,7 +214,7 @@ __INTERNAL_fmt:
cmp byte [rdi], EOS cmp byte [rdi], EOS
je .wrapup je .wrapup
xor r9b, r9b xor r9b, r9b
cmp r10, printfBuffLen-1 cmp r10, __fmt_BuffLen-1
je .flushBuffer je .flushBuffer
.flushReturn_0: .flushReturn_0:
cmp byte [rdi], '\' cmp byte [rdi], '\'
@@ -222,7 +222,7 @@ __INTERNAL_fmt:
cmp byte [rdi], '%' cmp byte [rdi], '%'
je .argReplacement je .argReplacement
mov r8b, [rdi] mov r8b, [rdi]
mov [printfBuff+r10], r8b mov [__fmt_Buff+r10], r8b
inc r10 inc r10
inc r11 inc r11
inc rdi inc rdi
@@ -245,10 +245,10 @@ __INTERNAL_fmt:
.replaceAscii: .replaceAscii:
mov r8b, r9b mov r8b, r9b
mov r9b, 2 mov r9b, 2
cmp r10, printfBuffLen-1 cmp r10, __fmt_BuffLen-1
je .flushBuffer je .flushBuffer
.flushReturn_2: .flushReturn_2:
mov [printfBuff + r10], r8b mov [__fmt_Buff + r10], r8b
add rdi, 2 add rdi, 2
inc r10 inc r10
inc r11 inc r11
@@ -342,7 +342,7 @@ __INTERNAL_fmt:
cmp byte [rdi + 1], '\' cmp byte [rdi + 1], '\'
je .invalidReplacement_specialChar; '%\n' would become "'%','\','n'" instead of "'%',EOS" when inserting full invalid specifier. je .invalidReplacement_specialChar; '%\n' would become "'%','\','n'" instead of "'%',EOS" when inserting full invalid specifier.
mov r9w, word [rdi] mov r9w, word [rdi]
mov [printfBuff+r10], r9w mov [__fmt_Buff+r10], r9w
add rdi, 2 add rdi, 2
add r10, 2 add r10, 2
add r11, 2 add r11, 2
@@ -350,7 +350,7 @@ __INTERNAL_fmt:
jmp .process jmp .process
.invalidReplacement_specialChar: .invalidReplacement_specialChar:
mov r9b, byte [rdi] mov r9b, byte [rdi]
mov [printfBuff+r10], r9b mov [__fmt_Buff+r10], r9b
inc rdi inc rdi
inc r10 inc r10
inc r11 inc r11
@@ -407,12 +407,12 @@ __INTERNAL_fmt:
jnz .doInsertString jnz .doInsertString
;rsi = NULL: ;rsi = NULL:
mov r9b, 3 mov r9b, 3
cmp r10, printfBuffLen-7 cmp r10, __fmt_BuffLen-7
je .flushBuffer je .flushBuffer
.flushReturn_3: .flushReturn_3:
mov byte [printfBuff + r10], '(' mov byte [__fmt_Buff + r10], '('
mov qword [printfBuff + r10 + 1], 'null' mov qword [__fmt_Buff + r10 + 1], 'null'
mov byte [printfBuff + r10 + 5], ')' mov byte [__fmt_Buff + r10 + 5], ')'
add r10, 6 add r10, 6
add r11, 6 add r11, 6
jmp .endInsertString jmp .endInsertString
@@ -421,11 +421,11 @@ __INTERNAL_fmt:
cmp byte [rsi], EOS cmp byte [rsi], EOS
je .endInsertString je .endInsertString
mov r9b, 1 mov r9b, 1
cmp r10, printfBuffLen-1 cmp r10, __fmt_BuffLen-1
je .flushBuffer je .flushBuffer
.flushReturn_1: .flushReturn_1:
mov r8b, byte [rsi] mov r8b, byte [rsi]
mov [printfBuff + r10], r8b mov [__fmt_Buff + r10], r8b
inc rsi inc rsi
inc r10 inc r10
inc r11 inc r11
@@ -438,7 +438,7 @@ __INTERNAL_fmt:
;--- Insert char to buffer ---; ;--- Insert char to buffer ---;
.insertChar: .insertChar:
mov [printfBuff + r10], sil mov [__fmt_Buff + r10], sil
add rdi, 2 add rdi, 2
add r10, 1 add r10, 1
add r11, 1 add r11, 1
@@ -453,7 +453,7 @@ __INTERNAL_fmt:
push r11 push r11
mov rax, NR_write mov rax, NR_write
mov rdi, r15 mov rdi, r15
lea rsi, [rel printfBuff] lea rsi, [rel __fmt_Buff]
mov rdx, r10 mov rdx, r10
syscall syscall
pop r11 pop r11
@@ -476,7 +476,7 @@ __INTERNAL_fmt:
.wrapup: .wrapup:
mov rax, NR_write mov rax, NR_write
mov rdi, r15 mov rdi, r15
lea rsi, [rel printfBuff] lea rsi, [rel __fmt_Buff]
mov rdx, r10 mov rdx, r10
mov r10, r11 mov r10, r11
syscall syscall