feat: added a basic malloc implementation and started work on memory

management
This commit is contained in:
2024-03-29 21:25:14 +01:00
parent 21f15f4575
commit 32ca1bfe18
7 changed files with 984 additions and 11 deletions

View File

@@ -0,0 +1,83 @@
#ifndef YAK_LIBALLOC_H
#define YAK_LIBALLOC_H
#include <stddef.h>
#include <stdint.h>
// retrieved from https://github.com/blanham/liballoc/blob/master/liballoc_1_1.h
/** \defgroup ALLOCHOOKS liballoc hooks
*
* These are the OS specific functions which need to
* be implemented on any platform that the library
* is expected to work on.
*/
/** @{ */
// If we are told to not define our own size_t, then we skip the define.
//#define _HAVE_UINTPTR_T
//typedef unsigned long uintptr_t;
//This lets you prefix malloc and friends
//#define PREFIX(func) k ## func
#define PREFIX(func) func
#ifdef __cplusplus
extern "C" {
#endif
/** This function is supposed to lock the memory data structures. It
* could be as simple as disabling interrupts or acquiring a spinlock.
* It's up to you to decide.
*
* \return 0 if the lock was acquired successfully. Anything else is
* failure.
*/
extern int liballoc_lock();
/** This function unlocks what was previously locked by the liballoc_lock
* function. If it disabled interrupts, it enables interrupts. If it
* had acquiried a spinlock, it releases the spinlock. etc.
*
* \return 0 if the lock was successfully released.
*/
extern int liballoc_unlock();
/** This is the hook into the local system which allocates pages. It
* accepts an integer parameter which is the number of pages
* required. The page size was set up in the liballoc_init function.
*
* \return NULL if the pages were not allocated.
* \return A pointer to the allocated memory.
*/
extern void *liballoc_alloc(size_t);
/** This frees previously allocated memory. The void* parameter passed
* to the function is the exact same value returned from a previous
* liballoc_alloc call.
*
* The integer value is the number of pages to free.
*
* \return 0 if the memory was successfully freed.
*/
extern int liballoc_free(void *, size_t);
extern void *PREFIX(malloc)(size_t); ///< The standard function.
extern void *PREFIX(realloc)(void *, size_t); ///< The standard function.
extern void *PREFIX(calloc)(size_t, size_t); ///< The standard function.
extern void PREFIX(free)(void *); ///< The standard function.
#ifdef __cplusplus
}
#endif
/** @} */
#endif

View File

@@ -0,0 +1,20 @@
//
// Created by rick on 18-10-23.
//
#ifndef YAK_MEMMAP_H
#define YAK_MEMMAP_H
#define MMAP_TYPE_UNDEFINED 0
#define MMAP_TYPE_AVAILABLE 1
#define MMAP_TYPE_RESERVED 2
#define MMAP_TYPE_ACPI_RECLAIMABLE 3
#define MMAP_TYPE_NVS 4
#define MMAP_TYPE_BADRAM 5
#define MMAP_TYPE_KERNEL 6
#define MMAP_TYPE_PAGING 7
#define MMAP_LAST_TYPE MMAP_TYPE_PAGING
void memmap_put_entry(uintptr_t address, size_t length, uint8_t type);
#endif //YAK_MEMMAP_H