CeDOS - Commit 000c77f8

syscall: Added syscall for memory usage
Celina Sophie Kalus
Sun, 26 Nov 2023 22:22:12 +0100
6 files changed, 28 insertions(+), 1 deletions(-)
M include/cedos/mm/page_allocator.hinclude/cedos/mm/page_allocator.h

@@ -4,6 +4,8 @@ */

#ifndef PAGE_ALLOCATOR_H #define PAGE_ALLOCATOR_H +#include <stdint.h> + /*! * Returns a free page and marks it as used. * \return Address of the first byte on the page or NULL if no page was allocated.

@@ -15,5 +17,7 @@ * Adds a previously allocated page as free.

* \param page_addr Pointer to any byte within the page to be freed. */ void mark_as_free(void* page_addr); + +uint32_t mem_usage(void); #endif
M src/kernel/mm/page_allocator.csrc/kernel/mm/page_allocator.c

@@ -1,12 +1,17 @@

#include "cedos/mm/page_allocator.h" #include "cedos/mm/paging.h" +#include "cedos/core.h" -uint8_t* first_free = (uint8_t*)0x00200000; +uint8_t* first_free = (uint8_t*)0x00500000; void* get_free_page() { void* res = first_free; first_free += PAGE_SIZE; return res; +} + +uint32_t mem_usage(void) { + return (uint32_t)(first_free); } void mark_as_free(void* page_addr) {
M src/kernel/syscall.csrc/kernel/syscall.c

@@ -4,6 +4,7 @@ #include "cedos/sched/sched.h"

#include "cedos/file.h" #include "cedos/drivers/graphics.h" #include "cedos/time.h" +#include "cedos/mm/page_allocator.h" void test(uint32_t ebx, uint32_t ecx, uint32_t edx) { printk("SYSCALL 0x01: EBX=%i ECX=%X EDX=%X\n", ebx, ecx, edx);

@@ -23,6 +24,7 @@ file_dir_next,

file_lseek, file_tell, time_get_ticks, + mem_usage }; extern void syscall_interrupt(void);
M src/libcedos/cedos.csrc/libcedos/cedos.c

@@ -90,3 +90,8 @@ interrupt(0x30, res, 12, 0, 0, 0);

return res; } +uint32_t sc_mem_usage(void) { + volatile int res = 0; + interrupt(0x30, res, 13, 0, 0, 0); + return res; +}
M src/libcedos/include/cedos.hsrc/libcedos/include/cedos.h

@@ -25,5 +25,7 @@

int dir_next(int fd, int index, char *fname_buffer); int sc_time_get_ticks(void); +uint32_t sc_mem_usage(void); + #endif
A src/shell/memusage.c

@@ -0,0 +1,9 @@

+#include "cedos.h" +#include "stdio.h" + +#include <stdint.h> + +void main(char *args) { + uint32_t memusage = sc_mem_usage(); + printf("%i KB\n", memusage / 1000); +}