Adds fgetat,fgettype,fgetmod. Seperates constants to multiple files

This commit is contained in:
2025-07-27 14:11:44 +02:00
parent 5b6831a501
commit dbf2af0253
8 changed files with 320 additions and 234 deletions

View File

@@ -112,9 +112,10 @@ eprintf:
; See printf description above, +
; 1) Return value can be amount of printed characters or -errno (eg if bad FD was passed, -EBADF is returned)
; 2) FD has to be passed via RAX (this is clearly an INTERNAL function so passed arguments are slightly different, that is, RAX required for FD)
; 3) <!> <!> FOR DEVS: When writing an I/O function that calls this wrapper, make sure that:
; 3) When writing a function(/wrapper) that calls this function, make sure that:
; - That function has function prologue (ie push rbp + mov rbp, rsp)
; - __INTERNAL_fmt is called via CALL and not a simple JMP like in printf
; - Arguments from function/wrapper are all shifted
; This is because in such I/O functions, first argument should be file descriptor, and following SYS V ABI, that first argument is passed to RDI
; However since __INTERNAL_fmt expects FD via RAX, all arguments have to be shifted. Due to this, argument in R9 becomes a stack argument
; Because of that, __INTERNAL_fmt has to load from stack with a different offset; +24 bytes extra (extra +8 for function call, extra +8 for function prologue and extra +8 to account for possible R9 arg becoming a stack arg)
@@ -126,8 +127,8 @@ __INTERNAL_fmt:
jmp %%continue
%%fromStack:
cmp r15, FD_stderr
jle %%stackNoShift ;simple jle (for test r15,2); entry of this wrapper quits early if passed FD is less than 1, so this simple check is safe enough
mov %1, [rbp + (RBP_OFFSET_CALLER*2 + SIZE_QWORD) + ((r14-5) * SIZE_QWORD)] ;non-printf functions calling __INTERNAL_fmt require RDI to be FD, all args shifted and rbp+RBP_OFFSET_CALLER to r9. Also requires function prologue and a CALL to __INTERNAL_fmt (not a JMP like in printf); hence the RBP_OFFSET_CALLER*2
jle %%stackNoShift
mov %1, [rbp + (RBP_OFFSET_CALLER*2 + SIZE_QWORD) + ((r14-5) * SIZE_QWORD)]
jmp %%continue
%%stackNoShift:
mov %1, [rbp + RBP_OFFSET_CALLER + ((r14-5) * SIZE_QWORD)]