AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
mm.h
Go to the documentation of this file.
1
#ifndef _I386_MM_H
2
#define _I386_MM_H
3
4
#include <
core/system.h
>
5
#include <
cpu/cpu.h
>
6
7
/* x86: the layout of the address space, and the physical and virtual
8
* address types. */
9
10
#define NR_PAGE_SIZE 2
11
12
#if ARCH_BITS==32
13
/*
14
* i386: user space is below 3 GiB. Above it, RAM is mapped from
15
* 0xC0000000 (the direct map, with the kernel at 1 MiB in it: _VMA), 768
16
* MiB of it at most (the rest isn't used). Then come the kernel's heap,
17
* its small objects, the devices, and a window for the memory past the
18
* direct map that the kernel maps (the boot loader's modules, ACPI's
19
* tables, the devices' registers).
20
*/
21
#define ARCH_DMAP_BASE (0xC0000000UL)
22
#define ARCH_DMAP_SIZE (0x30000000UL)
/* 768 MiB */
23
#define ARCH_RAM_MAX ARCH_DMAP_SIZE
24
#define ARCH_KVMEM_BASE (0xF0000000UL)
25
#define ARCH_KVMEM_SIZE (0x04000000UL)
/* 64 MiB */
26
#define ARCH_SLAB_BASE (0xF4000000UL)
27
#define ARCH_SLAB_SIZE (0x04000000UL)
/* 64 MiB */
28
#define ARCH_VESA_BASE (0xF8000000UL)
29
#define ARCH_EARLYFB_BASE (0xF9000000UL)
30
#define ARCH_ACPI_BASE (0xFA000000UL)
31
#define ARCH_PHYS_WINDOW_BASE (0xFA400000UL)
32
#define ARCH_PHYS_WINDOW_SIZE (0x05800000UL)
/* 88 MiB */
33
34
/* the boot code maps all of the direct map */
35
#define ARCH_BOOT_MAPPED ARCH_DMAP_SIZE
36
#else
37
/*
38
* x86_64: user space is the lower half. In the upper half, all of
39
* physical memory is mapped at ARCH_DMAP_BASE (the direct map); then come
40
* the devices, the kernel's heap, and the kernel itself, at -2 GiB
41
* (_VMA).
42
*/
43
#define ARCH_DMAP_BASE (0xFFFF800000000000ULL)
44
#define ARCH_VESA_BASE (0xFFFFC00000000000ULL)
45
#define ARCH_EARLYFB_BASE (0xFFFFC00100000000ULL)
46
#define ARCH_ACPI_BASE (0xFFFFC00200000000ULL)
47
#define ARCH_MMIO_BASE (0xFFFFC00300000000ULL)
/* devices' registers */
48
#define ARCH_MMIO_SIZE (64ULL << 30)
/* 64 GiB */
49
#define ARCH_KVMEM_BASE (0xFFFFD00000000000ULL)
50
#define ARCH_KVMEM_SIZE (1ULL << 30)
/* 1 GiB */
51
#define ARCH_SLAB_BASE (0xFFFFE00000000000ULL)
52
#define ARCH_SLAB_SIZE (16ULL << 30)
/* 16 GiB */
53
54
/* The boot code maps the kernel, and what follows it of the first GiB, at
55
* -2 GiB (mm_setup() puts pages[], 32 bytes a page, there). */
56
#define ARCH_BOOT_MAPPED (1024UL * 1024 * 1024)
/* 1 GiB */
57
#endif
58
59
/* a physical address in the direct map */
60
#define PHYS2VIRT(paddr) ((void *) (ARCH_DMAP_BASE + (uintptr_t) (paddr)))
61
62
extern
char
_VMA
;
/* the kernel's virtual base, from the linker script */
63
64
/* VMA() is the kernel's address of a physical address in the kernel's
65
* image (or in the memory below it, mapped with it), and LMA() the other
66
* way around. A pointer stays a pointer; a narrower integer (a 32-bit
67
* physical address) becomes a uintptr_t. */
68
#define __VMA_ADD(obj, op) ((uintptr_t) (obj) op (uintptr_t) &_VMA)
69
#define __VMA_TYPED(obj, op) \
70
__builtin_choose_expr(sizeof(obj) == sizeof(uintptr_t), \
71
(typeof(obj)) __VMA_ADD(obj, op), __VMA_ADD(obj, op))
72
#define VMA(obj) __VMA_TYPED(obj, +)
73
#define LMA(obj) __VMA_TYPED(obj, -)
74
75
/* Flushes the running CPU's TLB (but its global pages). */
76
static
inline
void
tlb_flush
(
void
)
77
{
78
write_cr3(
read_cr3
());
79
}
80
81
#if ARCH_BITS==32
82
typedef
uint32_t
paddr_t
;
83
typedef
uint32_t
vaddr_t
;
84
#else
85
typedef
uint64_t
paddr_t
;
86
typedef
uint64_t
vaddr_t
;
87
#endif
88
97
int
arch_mm_page_fault
(
vaddr_t
vaddr,
int
err);
98
99
#include_next <mm/mm.h>
100
101
#endif
/* ! _I386_MM_H */
paddr_t
uint64_t paddr_t
Definition
mm.h:39
_VMA
char _VMA
tlb_flush
static void tlb_flush(void)
Flushes every translation from this CPU's TLB.
Definition
mm.h:43
vaddr_t
uint64_t vaddr_t
Definition
mm.h:40
read_cr3
static uintptr_t read_cr3(void)
Definition
cpu.h:201
arch_mm_page_fault
int arch_mm_page_fault(vaddr_t vaddr, int err)
Handles a page fault: turns the CPU's error code into the kernel's PF_* flags, and calls mm_page_faul...
Definition
i386.c:449
system.h
cpu.h
uint32_t
unsigned int uint32_t
Definition
stddef.h:22
uint64_t
unsigned long long int uint64_t
Definition
stddef.h:23
kernel
arch
i386
include
mm
mm.h
Generated by
1.18.0