wip: memory change

This commit is contained in:
2024-10-18 14:45:37 +02:00
parent 9e85807a09
commit 7128f2640a
21 changed files with 121 additions and 76 deletions

View File

@ -8,12 +8,10 @@
// Remove this and replace it with <assert.h> header
// for debugging purposes
/* #include <assert.h> */
#define assert(bool)
// BPZ = Blocks Per Zone, which is the max
// number of blocks for a new zone
enum { BPZ = 128, PAGES_TINY = 16, PAGES_SMALL = 64, MEM_ALIGN = 8 };
enum { BPZ = 128, PAGES_TINY = 16, PAGES_SMALL = 64, MEM_ALIGN = 4 };
typedef enum { TINY, SMALL, LARGE } block_type_t;
@ -34,7 +32,6 @@ typedef enum { TINY, SMALL, LARGE } block_type_t;
* available blocks (Block *free in struct Zone)
*/
typedef struct Block {
void *ptr;
size_t size;
size_t sub_size;
@ -54,12 +51,12 @@ typedef struct Block {
* in_use
*/
typedef struct Zone {
Block *free;
Block *used;
size_t size;
struct Zone *prev;
struct Zone *next;
block_type_t type;
Block *free;
Block *used;
} Zone;
/* Linked list to store all the zones (pages) mapped.
@ -89,5 +86,5 @@ void vfree(void *ptr);
void *vrealloc(void *ptr, size_t size);
void show_kalloc_mem(void);
void show_valloc_mem(void);
size_t ksize(void* virt_addr);
size_t vsize(void* virt_addr);
size_t ksize(void *virt_addr);
size_t vsize(void *virt_addr);

View File

@ -1,9 +1,18 @@
#pragma once
#include "kpanic.h"
#include "kprintf.h"
#include <stdint.h>
#define PRINT_VAR(var) kprintf("%s: %d\n", #var, var)
#define PRINT_PTR(X) kprintf("%s: %p\n", #X, X)
#define PRINT_INT(X) kprintf("%s: %d\n", #X, X)
#define assert(X) \
do { \
if (!(X)) { \
kpanic("ASSERT_FAIL %s:%u %s\n", __FILE__, __LINE__, \
#X); \
} \
} while (0)
struct function_entry {
uint32_t addr;

View File

@ -1,3 +1,3 @@
#pragma once
void kpanic(const char *format, ...);
void kpanic(const char *format, ...);

View File

@ -8,7 +8,7 @@
#define ACCESSED (1 << 4)
#define INIT_FLAGS (PRESENT | RW | SUPERVISOR)
#define PAGE_SIZE 4096
#define KERN_START 0xC0000000
#define HEAP_END 0xC0000000
void init_memory(void);
void *alloc_frames(size_t size);