diff options
author | Benji Dial <benji6283@gmail.com> | 2020-09-19 14:53:29 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2020-09-19 14:53:29 -0400 |
commit | de20d7430df08731d9108acb83e1234ba7f1fe16 (patch) | |
tree | 8646f3d1bae3d30391df34766e3e58c0c2af8aab /src/user/include | |
parent | 20853582d5385d12421433d21910e783caa00764 (diff) | |
download | portland-os-de20d7430df08731d9108acb83e1234ba7f1fe16.tar.gz |
file manager
Diffstat (limited to 'src/user/include')
-rw-r--r-- | src/user/include/knob/block.h | 3 | ||||
-rw-r--r-- | src/user/include/knob/file.h | 5 | ||||
-rw-r--r-- | src/user/include/knob/quit.h | 7 | ||||
-rw-r--r-- | src/user/include/knob/user.h | 3 | ||||
-rw-r--r-- | src/user/include/pland/pcrt.h | 16 | ||||
-rw-r--r-- | src/user/include/pland/syscall.h | 182 |
6 files changed, 171 insertions, 45 deletions
diff --git a/src/user/include/knob/block.h b/src/user/include/knob/block.h index 4625577..43137e1 100644 --- a/src/user/include/knob/block.h +++ b/src/user/include/knob/block.h @@ -7,4 +7,7 @@ void blockcpy(void *to, const void *from, uint32_t size); bool blockequ(const void *a, const void *b, uint32_t size) __attribute__ ((__pure__)); +//returns length without null-terminator +uint32_t strcpy(char *to, const char *from); + #endif
\ No newline at end of file diff --git a/src/user/include/knob/file.h b/src/user/include/knob/file.h index a0d084f..8862098 100644 --- a/src/user/include/knob/file.h +++ b/src/user/include/knob/file.h @@ -2,6 +2,7 @@ #define KNOB_FILE_H #include <stdint.h> +#include <pland/syscall.h> struct file; @@ -9,7 +10,6 @@ const char *remove_prefix(const char *path, uint8_t *dn_out); struct file *open_file(const char *path); void close_file(struct file *f); -void _close_all_files(); uint32_t read_from_file(struct file *f, uint32_t max, void *buf); //return value and max_length don't include null terminator @@ -19,4 +19,7 @@ int32_t seek_file_by(struct file *f, int32_t by); uint32_t file_size(struct file *f) __attribute__ ((pure)); +//return value must be manually freed, unless it is a null pointer +_dir_info_entry_t *get_directory_info(const char *path, uint32_t *count_out); + #endif
\ No newline at end of file diff --git a/src/user/include/knob/quit.h b/src/user/include/knob/quit.h deleted file mode 100644 index 7b10d09..0000000 --- a/src/user/include/knob/quit.h +++ /dev/null @@ -1,7 +0,0 @@ -#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 index 479a731..cd7676c 100644 --- a/src/user/include/knob/user.h +++ b/src/user/include/knob/user.h @@ -2,6 +2,9 @@ #define KNOB_USER_H #include <stdint.h> +#include <pland/syscall.h> + +char key_to_char(_key_code_t key) __attribute__ ((const)); void tell_user_sz(const char *sz); diff --git a/src/user/include/pland/pcrt.h b/src/user/include/pland/pcrt.h new file mode 100644 index 0000000..07ad453 --- /dev/null +++ b/src/user/include/pland/pcrt.h @@ -0,0 +1,16 @@ +#ifndef PLAND_PCRT_H +#define PLAND_PCRT_H + +#define BEFORE_MAIN(f) \ + __attribute__ ((section (".__pcrt_before_main"))) \ + __attribute__ ((unused)) \ + void (*const __pcrt_bm_##f)() = &f; + +#define BEFORE_QUIT(f) \ + __attribute__ ((section (".__pcrt_before_quit"))) \ + __attribute__ ((unused)) \ + void (*const __pcrt_bq_##f)() = &f; + +void __pcrt_quit() __attribute__ ((noreturn)); + +#endif
\ No newline at end of file diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index e16a7fb..331002e 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -7,14 +7,9 @@ typedef uint32_t _file_handle_t; typedef uint32_t _task_handle_t; typedef uint32_t _drive_number_t; -typedef uint32_t _pages_t; typedef uint32_t _process_handle_t; typedef enum { - _KEY_BACKSPACE = '\b', - _KEY_RETURN = '\n', - //etc. - _KEY_LSHIFT = 0x00000100, _KEY_RSHIFT = 0x00000200, _KEY_CAPS = 0x00000400, @@ -33,8 +28,103 @@ typedef enum { _KEY_ALT = 0x0000c000, _KEY_CTRL = 0x00030000, _KEY_META = 0x000c0000, + + _KEY_BEGIN_CAPS = 0x80, + _KEY_BEGIN_INSERT, + _KEY_BEGIN_NUM, + _KEY_BEGIN_SCROLL, + _KEY_BEGIN_LSHIFT, + _KEY_BEGIN_RSHIFT, + _KEY_BEGIN_LALT, + _KEY_BEGIN_RALT, + _KEY_BEGIN_LCTRL, + _KEY_BEGIN_RCTRL, + _KEY_BEGIN_LMETA, + _KEY_BEGIN_RMETA, + /* 0x8c - 0x97 reserved */ + /* 0x98 - 0x9f unassigned */ + _KEY_F1 = 0xa0, + _KEY_F2, + _KEY_F3, + _KEY_F4, + _KEY_F5, + _KEY_F6, + _KEY_F7, + _KEY_F8, + _KEY_F9, + _KEY_F10, + _KEY_F11, + _KEY_F12, + /* 0xac - 0xaf unassigned */ + _KEY_NUM0 = 0xb0, + _KEY_NUM1, + _KEY_NUM2, + _KEY_NUM3, + _KEY_NUM4, + _KEY_NUM5, + _KEY_NUM6, + _KEY_NUM7, + _KEY_NUM8, + _KEY_NUM9, + _KEY_NTIMES, + _KEY_NPLUS, + _KEY_NENTER, + _KEY_NMINUS, + _KEY_NDOT, + _KEY_NSLASH, + /* 0xc0 unassigned */ + _KEY_DELETE, + _KEY_HOME, + _KEY_END, + _KEY_PUP, + _KEY_PDOWN, + _KEY_UP, + _KEY_DOWN, + _KEY_LEFT, + _KEY_RIGHT, + _KEY_ESC, + _KEY_MENU, + _KEY_PAUSE, + _KEY_PRSCR, + /* 0xce - 0xef unassigned */ } _key_code_t; +typedef enum { + _COLOR_FG_BLACK = 0x00, + _COLOR_FG_BLUE = 0x01, + _COLOR_FG_GREEN = 0x02, + _COLOR_FG_CYAN = 0x03, + _COLOR_FG_RED = 0x04, + _COLOR_FG_MAGENTA = 0x05, + _COLOR_FG_BROWN = 0x06, + _COLOR_FG_LGRAY = 0x07, + + _COLOR_FG_DGRAY = 0x08, + _COLOR_FG_LBLUE = 0x09, + _COLOR_FG_LGREEN = 0x0a, + _COLOR_FG_LCYAN = 0x0b, + _COLOR_FG_LRED = 0x0c, + _COLOR_FG_PINK = 0x0d, + _COLOR_FG_YELLOW = 0x0e, + _COLOR_FG_WHITE = 0x0f, + + _COLOR_BG_BLACK = 0x00, + _COLOR_BG_BLUE = 0x10, + _COLOR_BG_GREEN = 0x20, + _COLOR_BG_CYAN = 0x30, + _COLOR_BG_RED = 0x40, + _COLOR_BG_MAGENTA = 0x50, + _COLOR_BG_BROWN = 0x60, + _COLOR_BG_LGRAY = 0x70 +} _vga_color_t; + +typedef struct __attribute__ ((packed)) { + char name[100]; + uint32_t size; + bool is_dir; + uint8_t pad[23]; +} _dir_info_entry_t; + enum _scn { _SCN_OPEN_FILE, _SCN_CLOSE_FILE, @@ -46,72 +136,74 @@ enum _scn { _SCN_ALLOCATE_RAM, _SCN_MEMORY_INFO, _SCN_WAIT_FOR_TASK, - _SCN_ENUMERATE_DIR + _SCN_ENUMERATE_DIR, + _SCN_PRINT_AT, + _SCN_COUNT_OF_DIR, + _SCN_CLEAR_SCREEN, + _SCN_SET_COLOR }; -typedef struct { - bool is_dir; - char name[100]; - uint32_t size; -} _dir_info_entry; - static inline uint32_t _sc0(enum _scn eax) { - volatile uint32_t out; - asm ( + uint32_t out; + asm volatile ( "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 ( + uint32_t out; + asm volatile ( "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 ( + uint32_t out; + uint32_t dummy; + asm volatile ( "int $0x30" - : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx) : "edx"); + : "=a" (out), "=c" (dummy) : "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 ( + uint32_t out; + uint32_t dummy; + asm volatile ( "int $0x30" - : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx)); + : "=a" (out), "=c" (dummy), "=d" (dummy) : "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 ( + uint32_t out; + uint32_t dummy; + asm volatile ( "int $0x30" - : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi)); + : "=a" (out), "=c" (dummy), "=d" (dummy) : "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 ( + uint32_t out; + uint32_t dummy; + asm volatile ( "int $0x30" - : "=a" (out) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi)); + : "=a" (out), "=c" (dummy), "=d" (dummy) : "a" (eax), "b" (ebx), "c" (ecx), "d" (edx), "S" (esi), "D" (edi)); return out; } static inline void _yield_task() { - asm ( + asm volatile ( "int $0x39" : : : "eax"); } __attribute__ ((noreturn)) static inline void _exit_task() { - asm ( + asm volatile ( "int $0x38" ); __builtin_unreachable(); @@ -145,27 +237,27 @@ static inline _key_code_t _get_key() { return _sc0(_SCN_GET_KEY); } -static inline void *_allocate_ram(_pages_t pages) { +static inline void *_allocate_ram(uint32_t pages) { return (void *)_sc1(_SCN_ALLOCATE_RAM, pages); } -static inline _pages_t _kernel_dynamic_area_size() { +static inline uint32_t _kernel_dynamic_area_size() { return _sc1(_SCN_MEMORY_INFO, 0x0); } -static inline _pages_t _kernel_dynamic_area_left() { +static inline uint32_t _kernel_dynamic_area_left() { return _sc1(_SCN_MEMORY_INFO, 0x1); } -static inline _pages_t _total_userspace_size() { +static inline uint32_t _total_userspace_size() { return _sc1(_SCN_MEMORY_INFO, 0x2); } -static inline _pages_t _total_userspace_left() { +static inline uint32_t _total_userspace_left() { return _sc1(_SCN_MEMORY_INFO, 0x3); } -static inline _pages_t _this_process_memory_left() { +static inline uint32_t _this_process_memory_left() { return _sc1(_SCN_MEMORY_INFO, 0x4); } @@ -173,8 +265,24 @@ static inline void _wait_for_task(_process_handle_t handle) { _sc1(_SCN_WAIT_FOR_TASK, handle); } -static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry *buffer, uint32_t max_count) { +static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry_t *buffer, uint32_t max_count) { return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count); } +static inline void _print_at(uint8_t row, uint8_t col, const char *sz) { + _sc2(_SCN_PRINT_AT, (row << 8) | col, (uint32_t)sz); +} + +static inline uint32_t _count_of_dir(uint8_t drive_number, const char *path) { + return _sc2(_SCN_COUNT_OF_DIR, drive_number, (uint32_t)path); +} + +static inline void _clear_screen() { + _sc0(_SCN_CLEAR_SCREEN); +} + +static inline void _set_color(_vga_color_t color) { + _sc1(_SCN_SET_COLOR, color); +} + #endif
\ No newline at end of file |