mem: align upper bound on PAGE_SIZE
stole some macro from linux kernel
This commit is contained in:
parent
93c8c87285
commit
4043eb50f7
@ -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 +
|
||||
|
10
core/types.h
10
core/types.h
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user