From b8284137d4e0eec11c78bc14047243fce6a51373 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 15:47:06 -0400 Subject: minor changes, redoing makefile, meminfo program --- src/user/hello/hello.c | 2 +- src/user/include/knob/format.h | 1 + src/user/include/pland/syscall.h | 27 +++++++++++++++++++++++++-- src/user/init/init.c | 31 +++++++++++++++++++++++++++++++ src/user/init/main.c | 31 ------------------------------- src/user/knob/format.c | 18 ++++++++++++++++++ src/user/meminfo/meminfo.c | 19 +++++++++++++++++++ 7 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 src/user/init/init.c delete mode 100644 src/user/init/main.c create mode 100644 src/user/meminfo/meminfo.c (limited to 'src/user') diff --git a/src/user/hello/hello.c b/src/user/hello/hello.c index 65e23f0..00d33b5 100644 --- a/src/user/hello/hello.c +++ b/src/user/hello/hello.c @@ -1,5 +1,5 @@ #include void main() { - tell_user_sz("\nHello, world!\nThis is a userspace program that has been started by init."); + tell_user_sz("Hello, world!\n"); } \ No newline at end of file diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h index 16d3d83..6c4aa5d 100644 --- a/src/user/include/knob/format.h +++ b/src/user/include/knob/format.h @@ -5,5 +5,6 @@ #include bool try_sntoi(const char *s, uint32_t n, uint32_t *out); +void itosz(uint32_t i, char *out); #endif \ No newline at end of file diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index 5858d16..298fc51 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -7,6 +7,8 @@ typedef uint32_t _file_handle_t; typedef uint32_t _task_handle_t; typedef uint32_t _drive_number_t; +typedef uint32_t _pages_t; + typedef enum { _KEY_BACKSPACE = '\b', _KEY_RETURN = '\n', @@ -40,7 +42,8 @@ enum _scn { _SCN_START_TASK, _SCN_LOG_STRING, _SCN_GET_KEY, - _SCN_ALLOCATE_RAM + _SCN_ALLOCATE_RAM, + _SCN_MEMORY_INFO }; static inline uint32_t _sc0(enum _scn eax) { @@ -133,8 +136,28 @@ static inline _key_code_t _get_key() { return _sc0(_SCN_GET_KEY); } -static inline void *_allocate_ram(uint32_t pages) { +static inline void *_allocate_ram(_pages_t pages) { return (void *)_sc1(_SCN_ALLOCATE_RAM, pages); } +static inline _pages_t _kernel_dynamic_area_size() { + return _sc1(_SCN_MEMORY_INFO, 0x0); +} + +static inline _pages_t _kernel_dynamic_area_left() { + return _sc1(_SCN_MEMORY_INFO, 0x1); +} + +static inline _pages_t _total_userspace_size() { + return _sc1(_SCN_MEMORY_INFO, 0x2); +} + +static inline _pages_t _total_userspace_left() { + return _sc1(_SCN_MEMORY_INFO, 0x3); +} + +static inline _pages_t _this_process_memory_left() { + return _sc1(_SCN_MEMORY_INFO, 0x4); +} + #endif \ No newline at end of file diff --git a/src/user/init/init.c b/src/user/init/init.c new file mode 100644 index 0000000..b8536be --- /dev/null +++ b/src/user/init/init.c @@ -0,0 +1,31 @@ +#include +#include +#include + +void main() { + struct file *f = open_file("SYS/STARTUP.RC"); + if (!f) { + tell_user_sz("Could not open SYS/STARTUP.RC\n"); + return; + } + + char buf[1024]; + char *bufp = buf; + while (read_from_file(f, 1, bufp)) { + if (*bufp == '\n') { + if (bufp == buf) + continue; + *bufp = '\0'; + try_run_command(buf); + bufp = buf; + } + else + ++bufp; + } + if (bufp != buf) { + *bufp = '\0'; + try_run_command(buf); + } + + close_file(f); +} diff --git a/src/user/init/main.c b/src/user/init/main.c deleted file mode 100644 index c301a78..0000000 --- a/src/user/init/main.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -void main() { - struct file *f = open_file("SYS/STARTUP.RC"); - if (!f) { - tell_user_sz("\nCould not open SYS/STARTUP.RC"); - return; - } - - char buf[1024]; - char *bufp = buf; - while (read_from_file(f, 1, bufp)) { - if (*bufp == '\n') { - if (bufp == buf) - continue; - *bufp = '\0'; - try_run_command(buf); - bufp = buf; - } - else - ++bufp; - } - if (bufp != buf) { - *bufp = '\0'; - try_run_command(buf); - } - - close_file(f); -} diff --git a/src/user/knob/format.c b/src/user/knob/format.c index f55e857..087f6fd 100644 --- a/src/user/knob/format.c +++ b/src/user/knob/format.c @@ -10,4 +10,22 @@ bool try_sntoi(const char *s, uint32_t n, uint32_t *out) { } *out = calc; return true; +} + +void itosz(uint32_t i, char *out) { + if (!i) { + *(uint16_t *)out = (uint16_t)'0'; + return; + } + bool zero = false; + for (uint32_t m = 1000000000; m; m /= 10) { + uint8_t d = (i / m) % 10; + if (zero) + *(out++) = d + '0'; + else if (d) { + zero = true; + *(out++) = d + '0'; + } + } + *out = '\0'; } \ No newline at end of file diff --git a/src/user/meminfo/meminfo.c b/src/user/meminfo/meminfo.c new file mode 100644 index 0000000..dd1d371 --- /dev/null +++ b/src/user/meminfo/meminfo.c @@ -0,0 +1,19 @@ +#include +#include +#include + +void main() { + char nbuf[11]; + + tell_user_sz("Kernel dynamic memory remaining: "); + + itosz(_kernel_dynamic_area_left() * 4, nbuf); + tell_user_sz(nbuf); + tell_user_sz("k\n"); + + tell_user_sz("Userspace memory remaining: "); + + itosz(_total_userspace_left() * 4, nbuf); + tell_user_sz(nbuf); + tell_user_sz("k\n"); +} \ No newline at end of file -- cgit v1.2.3