summaryrefslogtreecommitdiff
path: root/src/user/include
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2020-09-06 00:48:07 -0400
committerBenji Dial <benji6283@gmail.com>2020-09-06 00:48:07 -0400
commite8c6577617bffa4402c07c7aa20e3c24f03c1c20 (patch)
tree2fb9230b62d2344a44453117de9e656892219788 /src/user/include
parent7ff724fe8f709440da9c730fdb8dcbaa4f989ed5 (diff)
downloadportland-os-e8c6577617bffa4402c07c7aa20e3c24f03c1c20.tar.gz
program loading, others
big kernel additions: paging, elf loading, separate kernel and user page allocation it now properly loads and runs sd0:bin/init.elf still need to determine which disk was booted from, and start the init on that disk
Diffstat (limited to 'src/user/include')
-rw-r--r--src/user/include/canyo/file.h9
-rw-r--r--src/user/include/knob/block.h8
-rw-r--r--src/user/include/knob/env.h9
-rw-r--r--src/user/include/knob/file.h17
-rw-r--r--src/user/include/knob/format.h9
-rw-r--r--src/user/include/knob/heap.h9
-rw-r--r--src/user/include/knob/quit.h7
-rw-r--r--src/user/include/knob/user.h12
-rw-r--r--src/user/include/pland.h157
-rw-r--r--src/user/include/pland/syscall.h139
10 files changed, 210 insertions, 166 deletions
diff --git a/src/user/include/canyo/file.h b/src/user/include/canyo/file.h
deleted file mode 100644
index 5f09387..0000000
--- a/src/user/include/canyo/file.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#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/knob/block.h b/src/user/include/knob/block.h
new file mode 100644
index 0000000..53b3deb
--- /dev/null
+++ b/src/user/include/knob/block.h
@@ -0,0 +1,8 @@
+#ifndef KNOB_BLOCK_H
+#define KNOB_BLOCK_H
+
+#include <stdint.h>
+
+void blockcpy(void *to, const void *from, uint32_t count);
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/env.h b/src/user/include/knob/env.h
new file mode 100644
index 0000000..6d750ae
--- /dev/null
+++ b/src/user/include/knob/env.h
@@ -0,0 +1,9 @@
+#ifndef KNOB_ENV_H
+#define KNOB_ENV_H
+
+#include <stdint.h>
+
+//not implemented yet
+extern uint32_t current_drive;
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/file.h b/src/user/include/knob/file.h
new file mode 100644
index 0000000..6068077
--- /dev/null
+++ b/src/user/include/knob/file.h
@@ -0,0 +1,17 @@
+#ifndef KNOB_FILE_H
+#define KNOB_FILE_H
+
+#include <stdint.h>
+
+struct file;
+
+struct file *open_file(const char *path);
+void close_file(struct file *f);
+
+uint32_t read_from_file(struct file *f, uint32_t max, void *buf);
+uint32_t seek_file_to(struct file *f, uint32_t to);
+int32_t seek_file_by(struct file *f, int32_t by);
+
+uint32_t file_size(struct file *f) __attribute__ ((pure));
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h
new file mode 100644
index 0000000..16d3d83
--- /dev/null
+++ b/src/user/include/knob/format.h
@@ -0,0 +1,9 @@
+#ifndef KNOB_FORMAT_H
+#define KNOB_FORMAT_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+bool try_sntoi(const char *s, uint32_t n, uint32_t *out);
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/heap.h b/src/user/include/knob/heap.h
new file mode 100644
index 0000000..32dc44c
--- /dev/null
+++ b/src/user/include/knob/heap.h
@@ -0,0 +1,9 @@
+#ifndef KNOB_HEAP_H
+#define KNOB_HEAP_H
+
+#include <stdint.h>
+
+void *get_block(uint32_t bytes) __attribute__ ((malloc));
+void free_block(void *block);
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/quit.h b/src/user/include/knob/quit.h
new file mode 100644
index 0000000..7b10d09
--- /dev/null
+++ b/src/user/include/knob/quit.h
@@ -0,0 +1,7 @@
+#ifndef KNOB_QUIT_H
+#define KNOB_QUIT_H
+
+void on_quit(void (*run_f)());
+void quit() __attribute__ ((noreturn));
+
+#endif \ No newline at end of file
diff --git a/src/user/include/knob/user.h b/src/user/include/knob/user.h
new file mode 100644
index 0000000..c4ec7db
--- /dev/null
+++ b/src/user/include/knob/user.h
@@ -0,0 +1,12 @@
+#ifndef KNOB_USER_H
+#define KNOB_USER_H
+
+#include <stdint.h>
+
+void tell_user_sz(const char *sz);
+void tell_user_n(uint32_t n);
+
+//return value and max_length both include null terminator
+uint32_t ask_user_line_sz(char *sz, uint32_t max_length);
+
+#endif \ No newline at end of file
diff --git a/src/user/include/pland.h b/src/user/include/pland.h
deleted file mode 100644
index f174a51..0000000
--- a/src/user/include/pland.h
+++ /dev/null
@@ -1,157 +0,0 @@
-#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/include/pland/syscall.h b/src/user/include/pland/syscall.h
new file mode 100644
index 0000000..01f7151
--- /dev/null
+++ b/src/user/include/pland/syscall.h
@@ -0,0 +1,139 @@
+#ifndef PLAND_SYSCALL_H
+#define PLAND_SYSCALL_H
+
+#include <stdint.h>
+
+typedef uint32_t _file_handle_t;
+typedef uint32_t _task_handle_t;
+typedef uint32_t _drive_number_t;
+typedef enum {
+ _KEY_BACKSPACE = '\b',
+ _KEY_RETURN = '\n',
+ //etc.
+
+ _KEY_LSHIFT = 0x00000100,
+ _KEY_RSHIFT = 0x00000200,
+ _KEY_CAPS = 0x00000400,
+ _KEY_INSERT = 0x00000800,
+ _KEY_NUM = 0x00001000,
+ _KEY_SCROLL = 0x00002000,
+ _KEY_LALT = 0x00004000,
+ _KEY_RALT = 0x00008000,
+ _KEY_LCTRL = 0x00010000,
+ _KEY_RCTRL = 0x00020000,
+ _KEY_LMETA = 0x00040000,
+ _KEY_RMETA = 0x00080000,
+
+ _KEY_SHIFT = 0x00000300,
+ _KEY_SCAPS = 0x00000700,
+ _KEY_ALT = 0x0000c000,
+ _KEY_CTRL = 0x00030000,
+ _KEY_META = 0x000c0000,
+} _key_code_t;
+
+enum _scn {
+ _SCN_OPEN_FILE,
+ _SCN_CLOSE_FILE,
+ _SCN_FILE_READ,
+ _SCN_FILE_SIZE,
+ _SCN_START_TASK,
+ _SCN_LOG_STRING,
+ _SCN_GET_KEY,
+ _SCN_ALLOCATE_RAM
+};
+
+static inline uint32_t _sc0(enum _scn eax) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax) : "ecx", "edx");
+ return out;
+}
+
+static inline uint32_t _sc1(enum _scn eax, uint32_t ebx) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax), "b" (ebx) : "ecx", "edx");
+ return out;
+}
+
+static inline uint32_t _sc2(enum _scn eax, uint32_t ebx, uint32_t ecx) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx) : "edx");
+ return out;
+}
+
+static inline uint32_t _sc3(enum _scn eax, uint32_t ebx, uint32_t ecx, uint32_t edx) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx));
+ return out;
+}
+
+static inline uint32_t _sc4(enum _scn eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi));
+ return out;
+}
+
+static inline uint32_t _sc5(enum _scn eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi) {
+ volatile uint32_t out;
+ asm (
+ "int $0x30"
+ : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi));
+ return out;
+}
+
+static inline void _yield_task() {
+ asm (
+ "int $0x39"
+ );
+}
+
+__attribute__ ((noreturn))
+static inline void _exit_task() {
+ asm (
+ "int $0x38"
+ );
+ __builtin_unreachable();
+}
+
+static inline _file_handle_t _open_file(_drive_number_t drive_number, const char *path) {
+ return _sc2(_SCN_OPEN_FILE, drive_number, (uint32_t)path);
+}
+
+static inline void _close_file(_file_handle_t handle) {
+ _sc1(_SCN_CLOSE_FILE, handle);
+}
+
+static inline uint32_t _file_read(_file_handle_t handle, uint32_t file_offset, uint32_t count, void *buffer) {
+ return _sc4(_SCN_FILE_READ, handle, file_offset, count, (uint32_t)buffer);
+}
+
+static inline uint32_t _file_size(_file_handle_t handle) {
+ return _sc1(_SCN_FILE_SIZE, handle);
+}
+
+static inline void _start_task(_drive_number_t drive_number, char *path) {
+ _sc2(_SCN_START_TASK, drive_number, (uint32_t)path);
+}
+
+static inline void _log_string(const char *sz) {
+ _sc1(_SCN_LOG_STRING, (uint32_t)sz);
+}
+
+static inline _key_code_t _get_key() {
+ return _sc0(_SCN_GET_KEY);
+}
+
+static inline void *_allocate_ram(uint32_t pages) {
+ return (void *)_sc1(_SCN_ALLOCATE_RAM, pages);
+}
+
+#endif \ No newline at end of file