-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.h
46 lines (33 loc) · 1.05 KB
/
memory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef __MEMORY_H__
#define __MEMORY_H__
#define PAGE_BITS 12
#define PAGE_SIZE (1 << 12)
#define PAGE_MASK (PAGE_SIZE - 1)
#define KERNEL_BASE 0xffffffff80000000
#define HIGH_BASE 0xffff800000000000
#define PHYSICAL_BASE 0x0000000000000000
#define KERNEL_CODE 0x18
#define KERNEL_DATA 0x20
#define KERNEL_PHYS(x) ((x) - KERNEL_BASE)
#define KERNEL_VIRT(x) ((x) + KERNEL_BASE)
#define PA(x) ((x) - HIGH_BASE)
#define VA(x) ((x) + HIGH_BASE)
#ifndef __ASM_FILE__
#include <stdint.h>
#define BOOTMEM_SIZE (4ull * 1024ull * 1024ull * 1024ull)
typedef uintptr_t phys_t;
typedef uintptr_t virt_t;
static inline uintptr_t kernel_phys(void *addr) {
return KERNEL_PHYS((uintptr_t) addr);
}
static inline void *kernel_virt(uintptr_t addr) {
return (void *) KERNEL_VIRT(addr);
}
static inline phys_t pa(const void *addr) {
return PA((virt_t) addr);
}
static inline void *va(phys_t addr) {
return (void *) VA(addr);
}
#endif /*__ASM_FILE__*/
#endif /*__MEMORY_H__*/