Commit 4043eb50 authored by Mathieu Maret's avatar Mathieu Maret

mem: align upper bound on PAGE_SIZE

stole some macro from linux kernel
parent 93c8c872
#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 +
#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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment