AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1#ifndef _X86_ARCH_H
2#define _X86_ARCH_H
3
4#include <cpu/cpu.h>
5
6/* x86's side of the kernel's arch_* interface (core/arch.h): the thread's
7 * own state, and where user space ends. */
8
9/* user mode's stack and code segments, and its starting EFLAGS
10 * (interrupts enabled) */
11#define X86_SS (0x20 | 3)
12#define X86_EFLAGS (0x200)
13#define X86_CS (0x18 | 3)
14
16struct x86_thread {
17 uintptr_t kstack; /* the kernel stack's top, where the user context is */
18 uintptr_t kstack_base; /* where the kernel stack was allocated */
19
20#if ARCH_BITS==32
21 uintptr_t eip;
22 uintptr_t esp;
23 uintptr_t ebp;
24 uintptr_t eflags;
25 uintptr_t eax; /* a system call's result, for a thread that hasn't run yet */
26#else
31 uintptr_t rax; /* a system call's result, for a thread that hasn't run yet */
32#endif
33
34 struct x86_regs *regs; /* user mode's registers, on the kernel stack */
35 void *fpu_context; /* its FPU state, while the FPU doesn't hold it */
36
37 int fpu_enabled; /* it has used the FPU (fpu.c) */
38};
39
40MALLOC_DECLARE(M_X86_THREAD);
41MALLOC_DECLARE(M_KERN_STACK);
42
51void arch_syscall(struct x86_regs *r);
52
53#if ARCH_BITS==32
54#define USER_STACK (0xC0000000UL)
55#else
56/* the top of the lower half, which is user space */
57#define USER_STACK (0x0000800000000000UL)
58#endif
59#define USER_STACK_BASE (USER_STACK - USER_STACK_SIZE)
60
61/* the sigcode page (sys/signal.c), below the stack */
62#define SIGCODE_ADDR (USER_STACK_BASE - 0x1000)
63
64#if ARCH_BITS==32
65#define KERN_STACK_SIZE (8192U) /* 8 KiB */
66#else
67/* Frames are bigger: a loop of symbolic links is 8 lookups deep, with a
68 * 4 KiB path parsed at the end. */
69#define KERN_STACK_SIZE (16384U) /* 16 KiB */
70#endif
71
72static inline void arch_interrupts_enable(void)
73{
74 asm volatile ("sti");
75}
76
77static inline void arch_interrupts_disable(void)
78{
79 asm volatile ("cli");
80}
81
82/* Start running in user mode, and jump to an address with a frame pointer
83 * and a stack (cpu.S). */
84void x86_jump_user(uintptr_t eax, uintptr_t eip, uintptr_t cs, uintptr_t eflags, uintptr_t esp, uintptr_t ss) __attribute__((noreturn));
85void x86_goto(uintptr_t eip, uintptr_t ebp, uintptr_t esp) __attribute__((noreturn));
86
87#include_next <core/arch.h>
88
89#endif /* ! _X86_ARCH_H */
void arch_syscall(struct aarch64_regs *r)
Definition syscall.c:23
static void arch_interrupts_disable(void)
Masks IRQs.
Definition arch.h:77
static void arch_interrupts_enable(void)
Unmasks IRQs (DAIF.I).
Definition arch.h:71
void x86_goto(uintptr_t eip, uintptr_t ebp, uintptr_t esp)
void x86_jump_user(uintptr_t eax, uintptr_t eip, uintptr_t cs, uintptr_t eflags, uintptr_t esp, uintptr_t ss)
#define MALLOC_DECLARE(type)
Definition kvmem.h:29
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
The registers an interrupt or exception saved, on the kernel stack, as cpu.S's stubs push them: the g...
Definition cpu.h:12
uint64_t cs
Definition cpu.h:24
uint64_t ss
Definition cpu.h:24
A thread's x86 state: its kernel stack, and where it resumes.
Definition arch.h:16
uintptr_t kstack_base
Definition arch.h:18
uintptr_t rip
Definition arch.h:27
int fpu_enabled
Definition arch.h:37
void * fpu_context
Definition arch.h:35
uintptr_t rflags
Definition arch.h:30
uintptr_t rbp
Definition arch.h:29
uintptr_t rsp
Definition arch.h:28
uintptr_t rax
Definition arch.h:31
struct x86_regs * regs
Definition arch.h:34
uintptr_t kstack
Definition arch.h:17