From 5dc6b1124daea31bd96458b3ebbe049b116642ce Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 10 May 2026 21:44:54 +0200 Subject: [PATCH] fix syscalls --- docs/SYSCALLS.md | 6 ++++++ src/syscall/files.c | 16 ++++++++-------- src/syscall/screen.c | 4 ++-- src/syscall/syscall.c | 13 ++++++------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/docs/SYSCALLS.md b/docs/SYSCALLS.md index 5faa69a..1cb5e0d 100644 --- a/docs/SYSCALLS.md +++ b/docs/SYSCALLS.md @@ -8,4 +8,10 @@ Name | Number (%rax) | arg0 (%rdi) | arg1 (%rsi) | arg2 (%rdx) | | sys_write | 1 | unsigned int fd | const char* buf | size_t count | | sys_open | 2 | const char* filename | int flags | | | sys_close | 3 | unsigned int fd | | | + +| sys_lseek | 8 | unsigned int fd | int offset | int whence | +| sys_tell | 9 | unsigned int fd | +| sys_eof | 10 | unsigned int fd | +| sys_draw | 11 | const uint8_t* src | int width | int height | int channels | + | sys_exit | 60 | int error_code | | | \ No newline at end of file diff --git a/src/syscall/files.c b/src/syscall/files.c index de897cd..9679767 100644 --- a/src/syscall/files.c +++ b/src/syscall/files.c @@ -77,9 +77,9 @@ int sys_open(const char* filename, int flags) * %0 - file closed * %-EBADFD - bad file descriptor */ -int sys_close(int fd) +int sys_close(unsigned int fd) { - if (fd < 0 || fd >= FDT_MAX) { + if (fd >= FDT_MAX) { return -EBADFD; } @@ -109,9 +109,9 @@ int sys_close(int fd) * %new_cursor - the new cursor value * On error, a negative value corresponding to an error code is returned. */ -int sys_lseek(int fd, int offset, int whence) +int sys_lseek(unsigned int fd, int offset, int whence) { - if (fd < 0 || fd >= FDT_MAX) { + if (fd >= FDT_MAX) { return -EBADFD; } if (!current_process->fdt[fd].open) { @@ -148,9 +148,9 @@ int sys_lseek(int fd, int offset, int whence) * %cursor - cursor position of the file descriptor * On error, a negative value with the corresponding error code is set. */ -int sys_tell(int fd) +int sys_tell(unsigned int fd) { - if (fd < 0 || fd >= FDT_MAX) { + if (fd >= FDT_MAX) { return -EBADFD; } if (!current_process->fdt[fd].open) { @@ -171,9 +171,9 @@ int sys_tell(int fd) * %>0 - we are at or past EOF * %0 - not yet (still have bytes to read) */ -int sys_eof(int fd) +int sys_eof(unsigned int fd) { - if (fd < 0 || fd >= FDT_MAX) { + if (fd >= FDT_MAX) { return -EBADFD; } if (!current_process->fdt[fd].open) { diff --git a/src/syscall/screen.c b/src/syscall/screen.c index fb280be..5c6b559 100644 --- a/src/syscall/screen.c +++ b/src/syscall/screen.c @@ -41,7 +41,7 @@ static uint32_t pack_rgba_to_fb(uint8_t r, uint8_t g, uint8_t b) } /* - * sys_draw_fb - Draw a framebuffer subset + * sys_draw - Draw a framebuffer subset * @src: Source frame * @width: width of the frame * @height: height of the frame @@ -55,7 +55,7 @@ static uint32_t pack_rgba_to_fb(uint8_t r, uint8_t g, uint8_t b) * %0 - on success * On error, a negative value with an error code is returned. */ -int sys_draw_fb(const uint8_t* src, int width, int height, int channels) +int sys_draw(const uint8_t* src, int width, int height, int channels) { if (!boot_ctx.fb || !src) { return -EINVAL; diff --git a/src/syscall/syscall.c b/src/syscall/syscall.c index b3cd3ec..bae2b12 100644 --- a/src/syscall/syscall.c +++ b/src/syscall/syscall.c @@ -19,14 +19,14 @@ extern struct process* current_process; int sys_open(const char* filename, int flags); -int sys_close(int fd); -int sys_lseek(int fd, int offset, int whence); -int sys_tell(int fd); // needed by doom, therefore TOP PRIORITY -int sys_eof(int fd); // same +int sys_close(unsigned int fd); +int sys_lseek(unsigned int fd, int offset, int whence); +int sys_tell(unsigned int fd); // needed by doom, therefore TOP PRIORITY +int sys_eof(unsigned int fd); // same int sys_read(unsigned int fd, char* buf, size_t count); int sys_write(unsigned int fd, const char* buf, size_t count); int sys_exit(int error_code); -int sys_draw_fb(const uint8_t* src, int width, int height, int channels); +int sys_draw(const uint8_t* src, int width, int height, int channels); /* * syscall_handler - System call dispatcher @@ -79,7 +79,7 @@ struct cpu_status* syscall_handler(struct cpu_status* regs) regs->rax = sys_eof(regs->rdi); break; case 11: // No DEBUG() here because it makes significant overhead - regs->rax = sys_draw_fb((const uint8_t*)regs->rdi, regs->rsi, regs->rdx, regs->r10); + regs->rax = sys_draw((const uint8_t*)regs->rdi, regs->rsi, regs->rdx, regs->r10); break; case 60: DEBUG("sys_exit(error_code=%d)", regs->rdi); @@ -92,7 +92,6 @@ struct cpu_status* syscall_handler(struct cpu_status* regs) break; } - // save overhead for present_fb //DEBUG("returned rax=%p (%u)", regs->rax, regs->rax); return regs;