mem: align upper bound on PAGE_SIZE

stole some macro from linux kernel
This commit is contained in:
Mathieu Maret 2018-11-09 22:32:21 +01:00
parent 93c8c87285
commit 4043eb50f7
2 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#include "mem.h"
#include "list.h"
#include "types.h"
#include "vga.h"
static struct mem_desc *page_desc = (struct mem_desc *)&__ld_kernel_end;
@ -10,7 +11,10 @@ static unsigned long top_mem;
int memSetup(unsigned long upper_mem)
{
printf("Free Mem from %d to %d\n", &__ld_kernel_end, upper_mem * 1024);
// Align upper mem (in kB) on page size even if it does loose a page
upper_mem = ALIGN_DOWN(upper_mem, PAGE_SIZE / 1024);
printf("Available Mem from %d to %d \n", &__ld_kernel_end, upper_mem * 1024);
// Memory description is stored after the kernel. We need some place to store it
unsigned long memdesc_end =
(unsigned long)page_desc +

View File

@ -1,5 +1,15 @@
#pragma once
#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a)-1)
#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
/* @a is a power of 2 value */
#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
#define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a)-1), (a))
#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask))
#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a)-1)) == 0)
// Virtual address
typedef unsigned long vaddr_t;