Made malloc() and free()! They're in header stdlib.h as syscalls 3 & 4.

This commit is contained in:
2024-05-24 18:08:33 +02:00
parent f009bbdac9
commit f879ca122f
7 changed files with 211 additions and 15 deletions
-1
View File
@@ -1,6 +1,5 @@
#include <stdio.h>
__attribute__ ((section ("entry")))
void main() {
char msg[8] = { 'H','e','l','l','o','!','\n',0 };
print(msg);
+2 -1
View File
@@ -1,6 +1,6 @@
ENTRY("main");
SECTIONS {
.text : {
*(entry);
*(.text*);
}
.data : {
@@ -13,3 +13,4 @@ SECTIONS {
*(.bss*);
}
}
+23 -1
View File
@@ -16,6 +16,7 @@
#include <sound/notes.h>
#include <memory/virtual.h>
#include <memory/addresses.h>
#include <memory/malloc.h>
#define PROMPT "#> "
@@ -303,8 +304,29 @@ void main() {
diskRead(sector, size, entryPoint);
if (strcmp(fileType, "bin") == 0) { // TODO: Improve this
if (strcmp(fileType, "bin") == 0) {
// Reset malloc
mallocListHead = NULL;
mallocVirtualAddr = (uint32_t)entryPoint + neededPages * PAGE_SIZE;
mallocPhysicalAddr = 0;
mallocPages = 0;
((void(*)(void))entryPoint)(); // Call program
for (uint32_t i = 0, virtualAddr = mallocVirtualAddr; i < mallocPages; i++, virtualAddr += PAGE_SIZE) {
ptEntry_t* page = getPage(virtualAddr);
if (PAGE_PHYS_ADDRESS(page) && TEST_ATTR(page, PTE_PRESENT)) {
freePage(page);
unmapPage((void*)virtualAddr);
flushTlbEntry(virtualAddr);
}
}
mallocListHead = NULL;
mallocVirtualAddr = 0;
mallocPhysicalAddr = 0;
mallocPages = 0;
} else if (strcmp(fileType, "tab") == 0) {
printFiletable(entryPoint);
} else if (strcmp(fileType, "fnt") == 0) {