feature: both physical and virtual allocators should be done
This commit is contained in:
@ -4,9 +4,9 @@
|
||||
|
||||
#include "kprintf.h"
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_FRAMES 1048319
|
||||
#define CEIL(x, y) (((x) + (y) - 1) / (y))
|
||||
#define GET_FRAME(i) (frame_table[i / 8] & (1 << (i % 8)))
|
||||
#define SET_FRAME(i, used) \
|
||||
do { \
|
||||
@ -21,7 +21,7 @@ extern uint32_t end_kernel;
|
||||
static uint8_t frame_table[CEIL(MAX_FRAMES, 8)];
|
||||
static uint32_t remaining_frames = MAX_FRAMES;
|
||||
|
||||
void *kalloc_frame(size_t size)
|
||||
void *alloc_frames(size_t size)
|
||||
{
|
||||
const uint32_t nb_frames = CEIL(size, PAGE_SIZE);
|
||||
if (nb_frames > remaining_frames) {
|
||||
@ -50,15 +50,15 @@ end:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int kfree_frame(void *frame, size_t size)
|
||||
int free_frames(void *frame_ptr, size_t size)
|
||||
{
|
||||
const uint32_t nb_frames = CEIL(size, PAGE_SIZE);
|
||||
const uint32_t start = (frame - (void *)&end_kernel) / PAGE_SIZE;
|
||||
const uint32_t start = (frame_ptr - (void *)&end_kernel) / PAGE_SIZE;
|
||||
|
||||
if (start > MAX_FRAMES || frame < (void *)&end_kernel) {
|
||||
if (start > MAX_FRAMES || frame_ptr < (void *)&end_kernel) {
|
||||
kprintf(KERN_WARNING "Address out of range\n");
|
||||
return -1;
|
||||
} else if ((uint32_t)frame % PAGE_SIZE) {
|
||||
} else if ((uint32_t)frame_ptr % PAGE_SIZE) {
|
||||
kprintf(KERN_WARNING "Invalid address\n");
|
||||
return -1;
|
||||
} else if (start + nb_frames > MAX_FRAMES) {
|
||||
|
Reference in New Issue
Block a user