110#define ADDR_SPACE_NONE ((addr_space_t)0)
113#define MMU_FLAG_PRESENT (1u << 0)
114#define MMU_FLAG_WRITE (1u << 1)
115#define MMU_FLAG_USER (1u << 2)
116#define MMU_FLAG_SHARED (1u << 3)
119#define MMU_USER_RW (MMU_FLAG_PRESENT | MMU_FLAG_WRITE | MMU_FLAG_USER)
255#define ARCH_TLB_FLUSH_CEILING 33u
284#define ARCH_FPU_STATE_SIZE 512
bool arch_copy_user_space(addr_space_t dst, addr_space_t src)
copy the user half of an address space into a new, empty one (fork).
Definition arch_impl.c:165
void arch_map_wc_page(uintptr_t virt, phys_addr_t phys)
like arch_map_kernel_page(), but write-combining if the CPU can do it (uncached otherwise): for a fra...
Definition arch_impl.c:227
void arch_disable_interrupts(void)
arch-neutral cpu primitives.
Definition arch_impl.c:10
phys_addr_t arch_translate_in(addr_space_t as, uintptr_t virt)
translate a virtual address to its physical address within a given address space.
Definition arch_impl.c:255
void arch_safe_halt(void)
enable interrupts and halt until the next interrupt, as one step: an interrupt that comes after the l...
Definition arch_impl.c:62
void arch_fpu_init_core(void)
turn on the FPU (and SSE) on the core that runs the call.
Definition fpu.c:44
void arch_fpu_sanitize(void *area)
make a state that came from user memory safe to load (a signal frame).
Definition fpu.c:109
void arch_map_device_page(uintptr_t virt, phys_addr_t phys)
like arch_map_kernel_page(), but the page is not cached: for device registers, where each read and wr...
Definition arch_impl.c:222
void arch_tlb_flush_local(uintptr_t start, uintptr_t end)
drop the TLB entries of the core that runs the call for the pages in [start, end),...
Definition arch_impl.c:139
void arch_fpu_save(void *area)
save the CPU's FPU/SSE registers.
Definition fpu.c:79
uintptr_t addr_space_t
an address space handle.
Definition arch.h:105
void arch_destroy_address_space(addr_space_t as)
tear down an address space created with arch_create_address_space(), freeing its user page tables and...
Definition arch_impl.c:175
bool arch_protect_page(addr_space_t as, uintptr_t virt, uint32_t flags)
change the protection of a mapped user page, keeping its frame.
Definition arch_impl.c:250
bool arch_hw_random(uintptr_t *out)
a random word from the CPU's own generator (RDSEED, else RDRAND).
Definition arch_impl.c:379
phys_addr_t arch_unmap_page(addr_space_t as, uintptr_t virt)
remove a user page mapping (and its TLB entry).
Definition arch_impl.c:245
uint32_t arch_count_user_pages(addr_space_t as)
count the pages of RAM mapped in the user half of an address space (a process's resident memory).
Definition arch_impl.c:170
void arch_halt(void)
halt the cpu until the next interrupt arrives.
Definition arch_impl.c:57
void arch_irq_restore(uint32_t flags)
restore a previously saved interrupt state.
Definition arch_impl.c:36
bool arch_user_access_ok(addr_space_t as, uintptr_t addr, size_t len, bool write)
check that user code in an address space could access a whole range: every page present and user-acce...
Definition arch_impl.c:240
void arch_fpu_clean(void *area)
fill an area with the state of a fresh program.
Definition fpu.c:104
void arch_enable_interrupts(void)
enable hardware interrupts.
Definition arch_impl.c:15
void arch_reserve_kernel_range(uintptr_t start, uintptr_t end)
set aside a kernel-only virtual range whose mappings every address space shares.
Definition arch_impl.c:212
uintptr_t arch_get_stack_pointer(void)
read the current stack pointer.
Definition arch_impl.c:77
void arch_halt_forever(void) __attribute__((noreturn))
disable interrupts and halt permanently.
Definition arch_impl.c:69
addr_space_t arch_kernel_address_space(void)
return the handle for the kernel's own address space.
Definition arch_impl.c:154
int arch_stack_walk(uintptr_t frame, uintptr_t *pcs, int max)
walk a chain of saved frame pointers and collect return addresses.
Definition arch_impl.c:99
int arch_map_page(addr_space_t as, uintptr_t virt, phys_addr_t phys, uint32_t flags)
map one page into a given address space.
Definition arch_impl.c:203
void arch_unmap_kernel_page(uintptr_t virt)
remove a page mapped with arch_map_kernel_page().
Definition arch_impl.c:235
uint32_t arch_irq_save(void)
disable interrupts and return the prior interrupt state.
Definition arch_impl.c:20
void arch_switch_address_space(addr_space_t as)
switch the active address space.
Definition arch_impl.c:133
uint64_t arch_cycle_count(void)
a fast counter that goes up with each CPU cycle (the TSC on x86).
Definition arch_impl.c:338
void arch_set_tls(uintptr_t base)
set the thread pointer user code reaches its thread-local storage through: the FS base on x86_64 (fs:...
Definition arch_impl.c:274
void arch_jump_to_usermode(uintptr_t entry, uintptr_t user_esp) __attribute__((noreturn))
drop to usermode (ring 3) and begin executing at entry with the given stack.
Definition arch_impl.c:285
void arch_fpu_init(void)
turn on the FPU (and SSE) for user programs and make the clean state a new program starts with.
Definition fpu.c:69
bool arch_irqs_enabled(void)
check whether hardware interrupts are currently enabled.
Definition arch_impl.c:48
void arch_fpu_restore(const void *area)
load the FPU/SSE registers.
Definition fpu.c:92
void arch_map_kernel_page(uintptr_t virt, phys_addr_t phys)
map one kernel-only, writable page inside a reserved kernel range.
Definition arch_impl.c:217
addr_space_t arch_create_address_space(void)
create a new address space that shares the kernel mappings.
Definition arch_impl.c:159
uint32_t base
Definition gdt.c:1
uint8_t flags
Definition idt.c:3
unsigned int uint32_t
Definition fb.h:17
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:19
uintptr_t phys_addr_t
physical addresses and the conversion between physical and virtual.
Definition phys.h:18
ELF32 file header.
Definition elf.h:51
ssize_t write(int fd, const void *buf, size_t count)
write bytes to a file descriptor.