diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/hello/hello.asm | 15 | ||||
-rw-r--r-- | src/user/include/canyo/file.h | 9 | ||||
-rw-r--r-- | src/user/include/pland.h | 157 | ||||
-rw-r--r-- | src/user/init/main.c | 16 | ||||
-rw-r--r-- | src/user/libcanyo/file.c | 15 |
5 files changed, 212 insertions, 0 deletions
diff --git a/src/user/hello/hello.asm b/src/user/hello/hello.asm new file mode 100644 index 0000000..345abb4 --- /dev/null +++ b/src/user/hello/hello.asm @@ -0,0 +1,15 @@ +global _entry + +section .text +_entry: + mov eax, 3 + mov ebx, msg + int 0x32 + + int 0x30 + +section .rodata +msg db "Hello, world!", 0x0a, 0x00 + +section .bss +stack resb 8
\ No newline at end of file diff --git a/src/user/include/canyo/file.h b/src/user/include/canyo/file.h new file mode 100644 index 0000000..5f09387 --- /dev/null +++ b/src/user/include/canyo/file.h @@ -0,0 +1,9 @@ +#ifndef CANYO_FILE_H +#define CANYO_FILE_H + +#include <stdint.h> +#include <pland.h> + +uint32_t read_line(fs_handle handle, uint32_t max_length, void *buffer); + +#endif
\ No newline at end of file diff --git a/src/user/include/pland.h b/src/user/include/pland.h new file mode 100644 index 0000000..f174a51 --- /dev/null +++ b/src/user/include/pland.h @@ -0,0 +1,157 @@ +#ifndef PLAND_H +#define PLAND_H + +#include <stdint.h> +#include <stdbool.h> + +typedef uint8_t fs_handle; +typedef uint8_t task_handle; + +static inline void exit() __attribute__ ((noreturn)) { + asm volatile ("int $0x30"); + __builtin_unreachable(); +} + +static inline void yield() { + asm volatile ("int $0x31"); +} + +static inline uint32_t data_extend(uint32_t amount) { + uint32_t actual_amount; + asm volatile ( + "int $0x33" + : "eax" (actual_amount) : "eax" (amount)); + return actual_amount; +} + +static inline void vga_blank() { + asm volatile ( + "xor %%eax, %%eax\n" + "int $0x32" + : : : "eax"); +} + +static inline void vga_set_color(uint8_t color) { + asm volatile ( + "mov $0x1, %%eax\n" + "int $0x32" + : : "ebx" (color) : "eax"); +} + +static inline void vga_printch(uint8_t ch) { + asm volatile ( + "mov $0x2, %%eax\n" + "int $0x32" + : : "ebx" (ch) : "eax"); +} + +static inline void vga_printsz(uint8_t *sz) { + asm volatile ( + "mov $0x3, %%eax\n" + "int $0x32" + : : "ebx" (sz) : "eax"); +} + +static inline void vga_printsn(uint8_t *sn, uint8_t length) { + asm volatile ( + "mov $0x4, %%eax\n" + "int $0x32" + : : "ebx" (sn), "ecx" (length) : "eax"); +} + +static inline fs_handle fs_open(uint8_t *path) { + fs_handle handle; + asm volatile ( + "mov $0x5, %%eax\n" + "int $0x32" + : "eax" (handle) : "ebx" (path)); + return handle; +} + +static inline fs_handle fs_open_root() { + fs_handle handle; + asm volatile ( + "mov $0x6, %%eax\n" + "int $0x32" + : "eax" (handle)); + return handle; +} + +static inline fs_handle fs_new(uint8_t *path) { + fs_handle handle; + asm volatile ( + "mov $0x7, %%eax\n" + "int $0x32" + : "eax" (handle) : "ebx" (path)); + return handle; +} + +static inline void fs_close(fs_handle handle) { + asm volatile ( + "mov $0x8, %%eax\n" + "int $0x32" + : : "ebx" (handle) : "eax"); +} + +static inline void fs_delete(uint8_t *path) { + asm volatile ( + "mov $0x9, %%eax\n" + "int $0x32" + : : "ebx" (path) : "eax"); +} + +static inline bool fs_exists(uint8_t *path) { + bool does; + asm volatile ( + "mov $0xa, %%eax\n" + "int $0x32" + : "eax" (does) : "ebx" (path)); + return does; +} + +static inline int32_t fs_seek(fs_handle handle, int32_t by) { + int32_t seeked_by; + asm volatile ( + "mov $0xb, %%eax\n" + "int $0x32" + : "eax" (seeked_by) : "ebx" (handle), "ecx" (by)); + return seeked_by; +} + +static inline uint32_t fs_tell(fs_handle handle) { + uint32_t position; + asm volatile ( + "mov $0xc, %%eax\n" + "int $0x32" + : "eax" (position) : "ebx" (handle)); + return position; +} + +static inline uint32_t fs_read(fs_handle handle, uint32_t max, void *buffer) { + uint32_t read; + asm volatile ( + "mov %0xd, %%eax\n" + "int $0x32" + : "eax" (read) : "ebx" (handle), "ecx" (max), "edx" (buffer) : "memory"); + return read; +} + +static inline uint32_t fs_write(fs_handle handle, uint32_t max, void *buffer) { + uint32_t written; + asm volatile ( + "mov %0xe, %%eax\n" + "int $0x32" + : "eax" (written) : "ebx" (handle), "ecx" (max), "edx" (buffer)); + return written; +} + +static inline task_handle plef_run(uint8_t *image_path) { + task_handle handle; + asm volatile ( + "mov %0xf, %%eax\n" + "int $0x32" + : "eax" (handle) : "ebx" (image_path)); + return handle; +} + +#endif diff --git a/src/user/init/main.c b/src/user/init/main.c new file mode 100644 index 0000000..002fd92 --- /dev/null +++ b/src/user/init/main.c @@ -0,0 +1,16 @@ +#include <pland.h> +#include <canyo/file.h> + +void main() { + fs_handle f = fs_open("sys/startup.rc"); + if (!f) { + vga_printsz("Couldn't open sys/startup.rc\n"); + return; + } + + uint8_t line_buffer[128]; + while (read_line(f, 128, line_buffer)) + plef_run(line_buffer); + + fs_close(f); +} diff --git a/src/user/libcanyo/file.c b/src/user/libcanyo/file.c new file mode 100644 index 0000000..d314887 --- /dev/null +++ b/src/user/libcanyo/file.c @@ -0,0 +1,15 @@ +#include <stdint.h> +#include <pland.h> + +//max_length and return value include null-terminator +uint32_t read_line(fs_handle handle, uint32_t max_length, void *buffer) { + int index = 0; + + while (++index < max_length) { + if (!fs_read(handle, 1, buffer + index - 1) || (*(uint8_t *)(buffer + index - 1) == '\n')) + break; + } + + *(uint8_t *)(buffer + index - 1) = '\0'; + return index; +}
\ No newline at end of file |