From d65a73601271fe12fff89f1e559fba665b9a444e Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 10 May 2026 19:33:29 +0200 Subject: [PATCH 1/9] freestanding headers --- docs/SOFTWARE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/SOFTWARE.md b/docs/SOFTWARE.md index c7e57a0..29c5370 100644 --- a/docs/SOFTWARE.md +++ b/docs/SOFTWARE.md @@ -6,6 +6,19 @@ Honestly I have no idea. Maybe you have too much free time. Keep in mind that the Pepper kernel is a personal project and it's full of bugs, inconsistencies, weird ways of doing things (and I don't care because it's my toy). Now if you still want to write something for this OS, thank you. Follow along. +## Headers available in userspace + +Of course, all of the freestanding headers are available: +- ``: macros for floating-point types +- ``: macros for integer types +- ``: macros for bitwise and logical operators +- ``: variadic function support +- ``: definitions for `size_t`, `ptrdiff_t`, and others +- ``: definitions for boolean types +- ``: definitions for `int_t` and `uint_t` types + +Also available is the `` header that gives access to low-level system call interface, notably the `syscallX` function family, X being the amount of arguments to use. + ## 1. Write the source code PepperOS is able to run programs written in x86 assembly, and C programs. From 01911bdd32381cf5fd53a4e9e6618f4ebc351c7e Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 10 May 2026 19:34:35 +0200 Subject: [PATCH 2/9] atoi --- include/string/string.h | 1 + src/string/string.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/string/string.h b/include/string/string.h index f01dbb9..382cda9 100644 --- a/include/string/string.h +++ b/include/string/string.h @@ -14,5 +14,6 @@ char *strcat(char *dest, const char *src); void strncpy(char* dst, const char* src, size_t n); int strncmp(const char* s1, const char* s2, size_t n); size_t strlen(const char* str); +int atoi(const char* str); #endif \ No newline at end of file diff --git a/src/string/string.c b/src/string/string.c index a42d0e6..5516b1d 100644 --- a/src/string/string.c +++ b/src/string/string.c @@ -71,7 +71,6 @@ void strncpy(char* dst, const char* src, size_t n) while(i++ != n && (*dst++ = *src++)); } - /* * strncmp - compare two strings up to n characters * @s1: first string @@ -100,10 +99,36 @@ int strncmp(const char* s1, const char* s2, size_t n) } } -// BSD implementation +/* + * strlen - get length of a string (BSD implementation) + * @str: NULL-terminated string + * + * Return: + * %len - length of string + */ size_t strlen(const char* str) { const char* s; for (s = str; *s; ++s); return (s - str); +} + +/* + * atoi - ascii to integer (PureDOOM implementation) + * @str: ASCII string to convert + * + * Return: + * %i - integer represented in @str + */ +int atoi(const char* str) +{ + int i = 0; + int c; + + while ((c = *str++) != 0) { + i *= 10; + i += c - '0'; + } + + return i; } \ No newline at end of file From 1142699c4811061972bfaeb08cfff7a7820b0d15 Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 10 May 2026 19:36:01 +0200 Subject: [PATCH 3/9] Alloc extra pages for raw binary --- include/config.h | 2 ++ src/mem/vmm.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 11c6fe9..55d9c6f 100644 --- a/include/config.h +++ b/include/config.h @@ -44,6 +44,8 @@ #define USER_STACK_TOP 0x80000000 #define USER_STACK_PAGES 16 // 16*4096 = 64kb #define USER_CODE_START 0x400000 // like linux +#define USER_RAW_EXTRA_PAGES 8192 // Extra writable pages after raw image for .bss/heap + // TODO: throw this away and make an ELF loader instead bruh /* paging */ #define PAGING_MAX_PHYS 0x200000000 diff --git a/src/mem/vmm.c b/src/mem/vmm.c index 2c851de..6ad0af9 100644 --- a/src/mem/vmm.c +++ b/src/mem/vmm.c @@ -18,6 +18,7 @@ compared to the PMM which allocs/frees 4kb frames ("physical pages"). #include #include #include +#include #include extern uint64_t *kernel_pml4; @@ -116,6 +117,8 @@ void* vmm_map(uint64_t* pml4, uint64_t virt, uint64_t flags) panic(NULL, "VMM/PMM out of memory!"); } + memset(PHYS_TO_VIRT(phys), 0, PAGE_SIZE); + paging_map_page(pml4, virt, phys, flags | PTE_PRESENT); return (void*)virt; } @@ -255,8 +258,9 @@ uintptr_t vmm_alloc_user_code(uint64_t* pml4, void* code_addr, uint64_t code_siz // Round code_size up to next page boundary uint64_t code_size_aligned = (code_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + uint64_t mapped_size = code_size_aligned + ((uint64_t)USER_RAW_EXTRA_PAGES * PAGE_SIZE); - for (uint64_t i=code_start; i Date: Sun, 10 May 2026 19:37:32 +0200 Subject: [PATCH 4/9] Line discipline for carriage return + ps/kill kshell commands --- src/io/term/term.c | 16 ++++++++++ src/kapps/kshell.c | 77 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/io/term/term.c b/src/io/term/term.c index e3bd2ca..e7af50e 100644 --- a/src/io/term/term.c +++ b/src/io/term/term.c @@ -50,9 +50,17 @@ void internal_putc(int c, void *_) if (init.terminal) { if (panic_count == 0) { spinlock_acquire(&term_lock); + if (ch == '\n') { + char cr = '\r'; + flanterm_write(ft_ctx, &cr, 1); + } flanterm_write(ft_ctx, &ch, 1); spinlock_release(&term_lock); } else { + if (ch == '\n') { + char cr = '\r'; + flanterm_write(ft_ctx, &cr, 1); + } flanterm_write(ft_ctx, &ch, 1); } } @@ -82,9 +90,17 @@ void debug_putc(int c, void *_) if (init.terminal && (!init.all || panic_count > 0)) { if (panic_count == 0) { spinlock_acquire(&term_lock); + if (ch == '\n') { + char cr = '\r'; + flanterm_write(ft_ctx, &cr, 1); + } flanterm_write(ft_ctx, &ch, 1); spinlock_release(&term_lock); } else { + if (ch == '\n') { + char cr = '\r'; + flanterm_write(ft_ctx, &cr, 1); + } flanterm_write(ft_ctx, &ch, 1); } } diff --git a/src/kapps/kshell.c b/src/kapps/kshell.c index fa44b51..01f0dd4 100644 --- a/src/kapps/kshell.c +++ b/src/kapps/kshell.c @@ -13,6 +13,7 @@ #include #include