From 4f02dac9b065b894446e0da4dcc79998699b96fe Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Thu, 12 Feb 2026 04:36:52 -0300 Subject: [PATCH] =?utf8?q?feat:=20ulibc=20extensions=20for=20DOOM=20?= =?utf8?q?=E2=80=94=20mmap,=20munmap,=20ioctl,=20nanosleep,=20clock=5Fgett?= =?utf8?q?ime?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Added userspace wrappers required for the DOOM port: - sys/mman.h + mman.c: mmap() and munmap() for framebuffer mapping - sys/ioctl.h + ioctl.c: ioctl() for framebuffer info queries - time.h + time.c: nanosleep() and clock_gettime() for frame timing All wrappers use the existing INT 0x80 syscall interface. --- user/ulibc/include/sys/ioctl.h | 6 ++++++ user/ulibc/include/sys/mman.h | 21 +++++++++++++++++++++ user/ulibc/include/time.h | 17 +++++++++++++++++ user/ulibc/src/ioctl.c | 7 +++++++ user/ulibc/src/mman.c | 17 +++++++++++++++++ user/ulibc/src/time.c | 11 +++++++++++ 6 files changed, 79 insertions(+) create mode 100644 user/ulibc/include/sys/ioctl.h create mode 100644 user/ulibc/include/sys/mman.h create mode 100644 user/ulibc/include/time.h create mode 100644 user/ulibc/src/ioctl.c create mode 100644 user/ulibc/src/mman.c create mode 100644 user/ulibc/src/time.c diff --git a/user/ulibc/include/sys/ioctl.h b/user/ulibc/include/sys/ioctl.h new file mode 100644 index 0000000..25c0d56 --- /dev/null +++ b/user/ulibc/include/sys/ioctl.h @@ -0,0 +1,6 @@ +#ifndef ULIBC_SYS_IOCTL_H +#define ULIBC_SYS_IOCTL_H + +int ioctl(int fd, unsigned long cmd, void* arg); + +#endif diff --git a/user/ulibc/include/sys/mman.h b/user/ulibc/include/sys/mman.h new file mode 100644 index 0000000..33cf649 --- /dev/null +++ b/user/ulibc/include/sys/mman.h @@ -0,0 +1,21 @@ +#ifndef ULIBC_SYS_MMAN_H +#define ULIBC_SYS_MMAN_H + +#include + +#define PROT_NONE 0x0 +#define PROT_READ 0x1 +#define PROT_WRITE 0x2 +#define PROT_EXEC 0x4 + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 + +#define MAP_FAILED ((void*)-1) + +void* mmap(void* addr, size_t length, int prot, int flags, int fd, int offset); +int munmap(void* addr, size_t length); + +#endif diff --git a/user/ulibc/include/time.h b/user/ulibc/include/time.h new file mode 100644 index 0000000..d69af90 --- /dev/null +++ b/user/ulibc/include/time.h @@ -0,0 +1,17 @@ +#ifndef ULIBC_TIME_H +#define ULIBC_TIME_H + +#include + +struct timespec { + uint32_t tv_sec; + uint32_t tv_nsec; +}; + +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 + +int nanosleep(const struct timespec* req, struct timespec* rem); +int clock_gettime(int clk_id, struct timespec* tp); + +#endif diff --git a/user/ulibc/src/ioctl.c b/user/ulibc/src/ioctl.c new file mode 100644 index 0000000..8b324a3 --- /dev/null +++ b/user/ulibc/src/ioctl.c @@ -0,0 +1,7 @@ +#include "sys/ioctl.h" +#include "syscall.h" +#include "errno.h" + +int ioctl(int fd, unsigned long cmd, void* arg) { + return __syscall_ret(_syscall3(SYS_IOCTL, fd, (int)cmd, (int)arg)); +} diff --git a/user/ulibc/src/mman.c b/user/ulibc/src/mman.c new file mode 100644 index 0000000..0a28821 --- /dev/null +++ b/user/ulibc/src/mman.c @@ -0,0 +1,17 @@ +#include "sys/mman.h" +#include "syscall.h" +#include "errno.h" + +void* mmap(void* addr, size_t length, int prot, int flags, int fd, int offset) { + int ret = _syscall5(SYS_MMAP, (int)addr, (int)length, prot, flags, fd); + (void)offset; + if (ret < 0 && ret > -4096) { + errno = -ret; + return MAP_FAILED; + } + return (void*)ret; +} + +int munmap(void* addr, size_t length) { + return __syscall_ret(_syscall2(SYS_MUNMAP, (int)addr, (int)length)); +} diff --git a/user/ulibc/src/time.c b/user/ulibc/src/time.c new file mode 100644 index 0000000..8f1b5f4 --- /dev/null +++ b/user/ulibc/src/time.c @@ -0,0 +1,11 @@ +#include "time.h" +#include "syscall.h" +#include "errno.h" + +int nanosleep(const struct timespec* req, struct timespec* rem) { + return __syscall_ret(_syscall2(SYS_NANOSLEEP, (int)req, (int)rem)); +} + +int clock_gettime(int clk_id, struct timespec* tp) { + return __syscall_ret(_syscall2(SYS_CLOCK_GETTIME, clk_id, (int)tp)); +} -- 2.43.0