Run first app from ramdisk!
This commit is contained in:
@@ -6,8 +6,9 @@
|
||||
#include <mm/pmm.h>
|
||||
#include <mm/types.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/mm.h>
|
||||
|
||||
/* Porting */
|
||||
spin_lock_t _liballoc_lock = SPIN_LOCK_INIT;
|
||||
|
||||
int liballoc_lock (void) {
|
||||
@@ -28,6 +29,7 @@ void* liballoc_alloc (int pages) {
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
uintptr_t addr = (uintptr_t)(p_addr + hhdm->offset);
|
||||
|
||||
return (void*)addr;
|
||||
}
|
||||
|
||||
@@ -55,18 +57,9 @@ int liballoc_free (void* ptr, int pages) {
|
||||
|
||||
#define MODE MODE_BEST
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
struct boundary_tag* l_freePages[MAXEXP]; //< Allowing for 2^MAXEXP blocks
|
||||
int l_completePages[MAXEXP]; //< Allowing for 2^MAXEXP blocks
|
||||
|
||||
#ifdef DEBUG
|
||||
unsigned int l_allocated = 0; //< The real amount of memory allocated.
|
||||
unsigned int l_inuse = 0; //< The amount of memory in use (malloc'ed).
|
||||
#endif
|
||||
|
||||
static int l_initialized = 0; //< Flag to indicate initialization.
|
||||
static int l_pageSize = 4096; //< Individual page size
|
||||
static int l_pageCount = 16; //< Minimum number of pages to allocate.
|
||||
@@ -79,9 +72,6 @@ static int l_pageCount = 16; //< Minimum number of pages to allocate.
|
||||
*/
|
||||
static inline int getexp (unsigned int size) {
|
||||
if (size < (1 << MINEXP)) {
|
||||
#ifdef DEBUG
|
||||
printf ("getexp returns -1 for %i less than MINEXP\n", size);
|
||||
#endif
|
||||
return -1; // Smaller than the quantum.
|
||||
}
|
||||
|
||||
@@ -93,10 +83,6 @@ static inline int getexp (unsigned int size) {
|
||||
shift += 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("getexp returns %i (%i bytes) for %i size\n", shift - 1, (1 << (shift - 1)), size);
|
||||
#endif
|
||||
|
||||
return shift - 1;
|
||||
}
|
||||
|
||||
@@ -130,37 +116,6 @@ static void* liballoc_memcpy (void* s1, const void* s2, size_t n) {
|
||||
return s1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void dump_array () {
|
||||
int i = 0;
|
||||
struct boundary_tag* tag = NULL;
|
||||
|
||||
printf ("------ Free pages array ---------\n");
|
||||
printf ("System memory allocated: %i\n", l_allocated);
|
||||
printf ("Memory in used (malloc'ed): %i\n", l_inuse);
|
||||
|
||||
for (i = 0; i < MAXEXP; i++) {
|
||||
printf ("%.2i(%i): ", i, l_completePages[i]);
|
||||
|
||||
tag = l_freePages[i];
|
||||
while (tag != NULL) {
|
||||
if (tag->split_left != NULL)
|
||||
printf ("*");
|
||||
printf ("%i", tag->real_size);
|
||||
if (tag->split_right != NULL)
|
||||
printf ("*");
|
||||
|
||||
printf (" ");
|
||||
tag = tag->next;
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
printf ("'*' denotes a split to the left/right of a tag\n");
|
||||
fflush (stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void insert_tag (struct boundary_tag* tag, int index) {
|
||||
int realIndex;
|
||||
|
||||
@@ -281,15 +236,6 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
|
||||
tag->split_left = NULL;
|
||||
tag->split_right = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("Resource allocated %x of %i pages (%i bytes) for %i size.\n", tag, pages,
|
||||
pages * l_pageSize, size);
|
||||
|
||||
l_allocated += pages * l_pageSize;
|
||||
|
||||
printf ("Total memory usage = %i KB\n", (int)((l_allocated / (1024))));
|
||||
#endif
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -301,9 +247,6 @@ void* malloc (size_t size) {
|
||||
liballoc_lock ();
|
||||
|
||||
if (l_initialized == 0) {
|
||||
#ifdef DEBUG
|
||||
printf ("%s\n", "liballoc initializing.");
|
||||
#endif
|
||||
for (index = 0; index < MAXEXP; index++) {
|
||||
l_freePages[index] = NULL;
|
||||
l_completePages[index] = 0;
|
||||
@@ -320,10 +263,6 @@ void* malloc (size_t size) {
|
||||
while (tag != NULL) {
|
||||
// If there's enough space in this tag.
|
||||
if ((tag->real_size - sizeof (struct boundary_tag)) >= (size + sizeof (struct boundary_tag))) {
|
||||
#ifdef DEBUG
|
||||
printf ("Tag search found %i >= %i\n", (tag->real_size - sizeof (struct boundary_tag)),
|
||||
(size + sizeof (struct boundary_tag)));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -351,13 +290,6 @@ void* malloc (size_t size) {
|
||||
|
||||
// Removed... see if we can re-use the excess space.
|
||||
|
||||
#ifdef DEBUG
|
||||
printf (
|
||||
"Found tag with %i bytes available (requested %i bytes, leaving %i), which has exponent: %i (%i bytes)\n",
|
||||
tag->real_size - sizeof (struct boundary_tag), size,
|
||||
tag->real_size - size - sizeof (struct boundary_tag), index, 1 << index);
|
||||
#endif
|
||||
|
||||
unsigned int remainder =
|
||||
tag->real_size - size - sizeof (struct boundary_tag) * 2; // Support a new tag + remainder
|
||||
|
||||
@@ -365,30 +297,14 @@ void* malloc (size_t size) {
|
||||
int childIndex = getexp (remainder);
|
||||
|
||||
if (childIndex >= 0) {
|
||||
#ifdef DEBUG
|
||||
printf ("Seems to be splittable: %i >= 2^%i .. %i\n", remainder, childIndex,
|
||||
(1 << childIndex));
|
||||
#endif
|
||||
|
||||
struct boundary_tag* new_tag = split_tag (tag);
|
||||
|
||||
(void)new_tag;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("Old tag has become %i bytes, new tag is now %i bytes (%i exp)\n", tag->real_size,
|
||||
new_tag->real_size, new_tag->index);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
ptr = (void*)((uintptr_t)tag + sizeof (struct boundary_tag));
|
||||
|
||||
#ifdef DEBUG
|
||||
l_inuse += size;
|
||||
printf ("malloc: %x, %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024);
|
||||
dump_array ();
|
||||
#endif
|
||||
|
||||
liballoc_unlock ();
|
||||
return ptr;
|
||||
}
|
||||
@@ -409,29 +325,14 @@ void free (void* ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
l_inuse -= tag->size;
|
||||
printf ("free: %x, %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024);
|
||||
#endif
|
||||
|
||||
// MELT LEFT...
|
||||
while ((tag->split_left != NULL) && (tag->split_left->index >= 0)) {
|
||||
#ifdef DEBUG
|
||||
printf ("Melting tag left into available memory. Left was %i, becomes %i (%i)\n",
|
||||
tag->split_left->real_size, tag->split_left->real_size + tag->real_size,
|
||||
tag->split_left->real_size);
|
||||
#endif
|
||||
tag = melt_left (tag);
|
||||
remove_tag (tag);
|
||||
}
|
||||
|
||||
// MELT RIGHT...
|
||||
while ((tag->split_right != NULL) && (tag->split_right->index >= 0)) {
|
||||
#ifdef DEBUG
|
||||
printf ("Melting tag right into available memory. This was was %i, becomes %i (%i)\n",
|
||||
tag->real_size, tag->split_right->real_size + tag->real_size,
|
||||
tag->split_right->real_size);
|
||||
#endif
|
||||
tag = absorb_right (tag);
|
||||
}
|
||||
|
||||
@@ -453,12 +354,6 @@ void free (void* ptr) {
|
||||
|
||||
liballoc_free (tag, pages);
|
||||
|
||||
#ifdef DEBUG
|
||||
l_allocated -= pages * l_pageSize;
|
||||
printf ("Resource freeing %x of %i pages\n", tag, pages);
|
||||
dump_array ();
|
||||
#endif
|
||||
|
||||
liballoc_unlock ();
|
||||
return;
|
||||
}
|
||||
@@ -470,12 +365,6 @@ void free (void* ptr) {
|
||||
|
||||
insert_tag (tag, index);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("Returning tag with %i bytes (requested %i bytes), which has exponent: %i\n",
|
||||
tag->real_size, tag->size, index);
|
||||
dump_array ();
|
||||
#endif
|
||||
|
||||
liballoc_unlock ();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user