diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/kernel/fs/elf.c | 4 | ||||
-rw-r--r-- | src/kernel/fs/elf.h | 2 | ||||
-rw-r--r-- | src/kernel/fs/ext2.c | 2 | ||||
-rw-r--r-- | src/kernel/fs/ext2.h | 2 | ||||
-rw-r--r-- | src/kernel/kernel.c | 10 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_exec.c | 7 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_getch.c | 11 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 14 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.h | 4 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 34 | ||||
-rw-r--r-- | src/kernel/tasks/process.h | 6 | ||||
-rw-r--r-- | src/userspace/libc/math.h | 20 | ||||
-rw-r--r-- | src/userspace/libc/stdarg.h | 6 | ||||
-rw-r--r-- | src/userspace/libc/stdbool.h | 11 | ||||
-rw-r--r-- | src/userspace/libc/stddef.h | 8 | ||||
-rw-r--r-- | src/userspace/libc/stdint.h | 18 | ||||
-rw-r--r-- | src/userspace/libc/stdio.h | 8 | ||||
-rw-r--r-- | src/userspace/libc/stdlib.h | 10 | ||||
-rw-r--r-- | src/userspace/libc/syscall.c | 10 | ||||
-rw-r--r-- | src/userspace/libc/syscall.h | 10 | ||||
-rw-r--r-- | src/userspace/programs/init.c | 7 | ||||
-rw-r--r-- | src/userspace/programs/sh.c | 2 |
23 files changed, 169 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a650621..d77fb54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ target_include_directories(userspace_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src foreach(loop_file ${user_sources}) get_filename_component(testname ${loop_file} NAME_WE) add_executable(${testname} ${loop_file}) + target_compile_options(${testname} PRIVATE "-nostdinc") target_include_directories(${testname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/libc/") target_link_libraries(${testname} userspace_lib "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld") set_target_properties(${testname} PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/user/${testname}") diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index 9ca98f0..a4c78ba 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -40,7 +40,7 @@ struct process *elf_load(char *path) } struct process *proc = process_make_new(); - proc->name = "ROOT"; + proc->name = path; proc->registers.eip = header->entry; paging_switch_directory(proc->cr3); @@ -71,4 +71,4 @@ struct process *elf_load(char *path) paging_switch_directory(paging_root_directory); return proc; -}
\ No newline at end of file +} diff --git a/src/kernel/fs/elf.h b/src/kernel/fs/elf.h index 8c7d38a..0fe435b 100644 --- a/src/kernel/fs/elf.h +++ b/src/kernel/fs/elf.h @@ -76,4 +76,4 @@ struct elf_program_header { int is_elf(struct elf_header *header); struct process *elf_load(char *path); -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c index 5fb0158..4e4f617 100644 --- a/src/kernel/fs/ext2.c +++ b/src/kernel/fs/ext2.c @@ -251,4 +251,4 @@ uint8_t *read_file(char *path) warn("File not found"); return NULL; } -}
\ No newline at end of file +} diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h index 88515a3..7fbe493 100644 --- a/src/kernel/fs/ext2.h +++ b/src/kernel/fs/ext2.h @@ -139,4 +139,4 @@ uint32_t ext2_look_up_path(char *path); uint8_t *read_file(char *path); -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 90b967f..8056055 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -67,14 +67,8 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) printf("Content of /etc/test: %s", read_file("/etc/test")); syscalls_install(); - struct process *proc = elf_load("/bin/init"); - if (proc) { - proc->stdin = NULL; - proc->stdout = NULL; - proc->stderr = NULL; - process_init(proc); - } + kexec("/bin/init"); halt_loop(); // asm ("div %0" :: "r"(0)); // Exception testing x/0 -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/actions/sys_exec.c b/src/kernel/syscall/actions/sys_exec.c new file mode 100644 index 0000000..dc1e9c6 --- /dev/null +++ b/src/kernel/syscall/actions/sys_exec.c @@ -0,0 +1,7 @@ +#include <stdint.h> +#include <kernel/tasks/process.h> + +uint32_t sys_exec(char *path) +{ + return uexec(path); +} diff --git a/src/kernel/syscall/actions/sys_getch.c b/src/kernel/syscall/actions/sys_getch.c index f1e4dfb..91ccda7 100644 --- a/src/kernel/syscall/actions/sys_getch.c +++ b/src/kernel/syscall/actions/sys_getch.c @@ -1,10 +1,11 @@ #include <stdint.h> #include <kernel/lib/stdio.h> -#include <kernel/input/input.h> -#include <kernel/lib/lib.h> -#include <kernel/lib/string.h> +#include <kernel/io/io.h> uint32_t sys_getch() { - return (uint32_t)getch(); -}
\ No newline at end of file + sti(); + uint32_t key = getch(); + cli(); + return key; +} diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index ca12118..d0b2b96 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -8,14 +8,15 @@ typedef uint32_t (*syscall_func)(uint32_t, ...); uint32_t (*syscalls[])() = { [0] = (uint32_t(*)())halt_loop, // DEBUG! - [1] = (uint32_t(*)())sys_putch, - [2] = sys_getch, - [3] = sys_malloc, - [4] = sys_free }; + [1] = sys_exec, + [2] = (uint32_t(*)())sys_putch, + [3] = sys_getch, + [4] = sys_malloc, + [5] = sys_free }; void syscall_handler(struct regs *r) { - sti(); + cli(); log("Received syscall!"); if (r->eax >= sizeof(syscalls) / sizeof(*syscalls)) @@ -29,9 +30,10 @@ void syscall_handler(struct regs *r) r->edx, r->esi, r->edi); r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi); + sti(); } void syscalls_install() { isr_install_handler(0x80, syscall_handler); -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/syscall.h b/src/kernel/syscall/syscall.h index b2bdc6d..5c21d58 100644 --- a/src/kernel/syscall/syscall.h +++ b/src/kernel/syscall/syscall.h @@ -7,6 +7,8 @@ extern void idt_syscall(); void syscalls_install(); +uint32_t sys_exec(char *path); + uint32_t sys_putch(char ch); uint32_t sys_getch(); @@ -15,4 +17,4 @@ uint32_t sys_malloc(uint32_t count); uint32_t sys_free(uint32_t ptr); -#endif
\ No newline at end of file +#endif diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index 4cb8d8c..a4c525a 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -8,6 +8,7 @@ #include <kernel/memory/paging.h> #include <kernel/memory/alloc.h> #include <kernel/timer/timer.h> +#include <kernel/fs/elf.h> uint32_t pid = 0; struct process *root; @@ -203,4 +204,35 @@ struct process *process_make_new() proc->pid = pid++; return proc; -}
\ No newline at end of file +} + +uint32_t kexec(char *path) +{ + struct process *proc = elf_load(path); + if (proc == NULL) + return -1; + + // TODO: Add stdin etc support (?) + proc->stdin = NULL; + proc->stdout = NULL; + proc->stderr = NULL; + process_init(proc); +} + +uint32_t uexec(char *path) +{ + process_suspend(current_proc->pid); + + struct process *proc = elf_load(path); + if (proc == NULL) + return -1; + + proc->stdin = NULL; + proc->stdout = NULL; + proc->stderr = NULL; + + proc->parent = current_proc; + proc->gid = current_proc->pid; + process_spawn(proc); + return 0; +} diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h index 1a5c607..5230ea4 100644 --- a/src/kernel/tasks/process.h +++ b/src/kernel/tasks/process.h @@ -54,6 +54,10 @@ void process_init(struct process *proc); struct process *process_make_new(); +uint32_t kexec(char *path); + +uint32_t uexec(char *path); + extern struct process *current_proc; extern uint32_t stack_hold; @@ -70,4 +74,4 @@ extern uint32_t stack_hold; #define WAIT_ERROR (-1) #define WAIT_OKAY 0 -#endif
\ No newline at end of file +#endif diff --git a/src/userspace/libc/math.h b/src/userspace/libc/math.h new file mode 100644 index 0000000..2683535 --- /dev/null +++ b/src/userspace/libc/math.h @@ -0,0 +1,20 @@ +#ifndef MELVIX_MATH_H +#define MELVIX_MATH_H + +// Trigonometric + +// Hyperbolic + +// Exponential and logarithmic + +// Power + +// Error and gamma + +// Rounding and remainder + +// Floating point manipulation + +// Minimum, maximum, difference + +#endif diff --git a/src/userspace/libc/stdarg.h b/src/userspace/libc/stdarg.h new file mode 100644 index 0000000..41583f9 --- /dev/null +++ b/src/userspace/libc/stdarg.h @@ -0,0 +1,6 @@ +#ifndef MELVIX_STDARG_H +#define MELVIX_STDARG_H + +// va_{list,start,arg,end,copy} + +#endif diff --git a/src/userspace/libc/stdbool.h b/src/userspace/libc/stdbool.h new file mode 100644 index 0000000..b445c80 --- /dev/null +++ b/src/userspace/libc/stdbool.h @@ -0,0 +1,11 @@ +#ifndef MELVIX_STDBOOL_H +#define MELVIX_STDBOOL_H + +#define true 1 +#define false 0 + +// For the strange people in the world +#define TRUE 1 +#define FALSE 0 + +#endif diff --git a/src/userspace/libc/stddef.h b/src/userspace/libc/stddef.h new file mode 100644 index 0000000..531cee3 --- /dev/null +++ b/src/userspace/libc/stddef.h @@ -0,0 +1,8 @@ +#ifndef MELVIX_STDDEF_H +#define MELVIX_STDDEF_H + +// size_t + +#define NULL ((void *)0) + +#endif diff --git a/src/userspace/libc/stdint.h b/src/userspace/libc/stdint.h new file mode 100644 index 0000000..be28300 --- /dev/null +++ b/src/userspace/libc/stdint.h @@ -0,0 +1,18 @@ +#ifndef MELVIX_STDINT_H +#define MELVIX_STDINT_H + +// TODO: Use shorter fixed length integers as stdint in kernel + +typedef signed char s8; +typedef unsigned char u8; + +typedef signed short s16; +typedef unsigned short u16; + +typedef signed int s32; +typedef unsigned int u32; + +typedef signed long s64; +typedef unsigned long u64; + +#endif diff --git a/src/userspace/libc/stdio.h b/src/userspace/libc/stdio.h new file mode 100644 index 0000000..03dfd1a --- /dev/null +++ b/src/userspace/libc/stdio.h @@ -0,0 +1,8 @@ +#ifndef MELVIX_STDIO_H +#define MELVIX_STDIO_H + +// File operations + +// Character input/output + +#endif diff --git a/src/userspace/libc/stdlib.h b/src/userspace/libc/stdlib.h new file mode 100644 index 0000000..ab6bff4 --- /dev/null +++ b/src/userspace/libc/stdlib.h @@ -0,0 +1,10 @@ +#ifndef MELVIX_STDLIB_H +#define MELVIX_STDLIB_H + +// String conversion + +// Exit functions + +// Memory management + +#endif diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c index fd27ef5..42786d4 100644 --- a/src/userspace/libc/syscall.c +++ b/src/userspace/libc/syscall.c @@ -5,10 +5,12 @@ */ DEFN_SYSCALL0(halt, 0); -DEFN_SYSCALL1(putch, 1, const char *); +DEFN_SYSCALL1(exec, 1, char *); -DEFN_SYSCALL0(getch, 2); +DEFN_SYSCALL1(putch, 2, char *); -DEFN_SYSCALL1(malloc, 3, uint32_t); +DEFN_SYSCALL0(getch, 3); -DEFN_SYSCALL1(free, 4, uint32_t);
\ No newline at end of file +DEFN_SYSCALL1(malloc, 4, u32); + +DEFN_SYSCALL1(free, 5, u32); diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h index 61ffecc..394118c 100644 --- a/src/userspace/libc/syscall.h +++ b/src/userspace/libc/syscall.h @@ -70,12 +70,14 @@ */ DECL_SYSCALL0(halt); -DECL_SYSCALL1(putch, const char *); +DECL_SYSCALL1(exec, char *); + +DECL_SYSCALL1(putch, char *); DECL_SYSCALL0(getch); -DECL_SYSCALL1(malloc, uint32_t); +DECL_SYSCALL1(malloc, u32); -DECL_SYSCALL1(free, uint32_t); +DECL_SYSCALL1(free, u32); -#endif
\ No newline at end of file +#endif diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c index bf3c7f4..3011530 100644 --- a/src/userspace/programs/init.c +++ b/src/userspace/programs/init.c @@ -1,6 +1,9 @@ +#include <syscall.h> + void main() { - // TODO: Exec shell + syscall_exec("/bin/sh"); + while (1) { }; -}
\ No newline at end of file +} diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c index 6dcb206..f477d6e 100644 --- a/src/userspace/programs/sh.c +++ b/src/userspace/programs/sh.c @@ -11,4 +11,4 @@ void main() } syscall_halt(); -}
\ No newline at end of file +} |