Feat: add memalloc command

This commit is contained in:
2025-03-18 10:11:37 +08:00
parent c0e474fa32
commit ed2ced5caf
3 changed files with 19 additions and 8 deletions

View File

@@ -6,6 +6,7 @@
void help(void);
void hello(void);
void hwinfo(void);
void memalloc(size_t size);
void ls(file_node_t *root);
void cat(file_node_t *root, const char *filename);
void reboot(void);

View File

@@ -16,8 +16,7 @@ void *simple_alloc(size_t size)
_heap_top = (void *)&__heap_start;
}
if (size & 0xff)
size = (size & ~0xff) + 0x100;
size = (size_t)ALIGN8(size);
if ((uint64_t)_heap_top + size >= (uint64_t)&__heap_end)
exit(ERR_NO_MEM);

View File

@@ -1,4 +1,5 @@
#include <stddef.h>
#include <kmalloc.h>
#include <utils.h>
#include <string.h>
#include <uart.h>
@@ -18,6 +19,7 @@ void help (void)
"help : print this help menu" ENDL
"hello : print Hello World!" ENDL
"hwinfo : print hardware info" ENDL
"memalloc : alloate memory and print" ENDL
"ls : list directory contents" ENDL
"cat : concatenate files and print" ENDL
"reboot : reboot the device" ENDL
@@ -49,6 +51,13 @@ void hwinfo (void)
uart_puts(ENDL);
}
void memalloc(size_t size)
{
DEBUG(size);
void *addr = kmalloc(size);
DEBUG(addr);
}
void ls_initrd_callback(file_node_t *tr)
{
uart_puts(tr->filename);
@@ -118,6 +127,8 @@ int shell(file_node_t *initrd_root)
hello();
} else if (!strcmp(bin, "hwinfo")) {
hwinfo();
} else if (!strcmp(bin, "memalloc")){
memalloc((size_t)atoi32(param));
} else if (!strcmp(bin, "ls")) {
ls(initrd_root);
} else if (!strcmp(bin, "cat")) {