AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
16
struct
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
27
uintptr_t
rip
;
28
uintptr_t
rsp
;
29
uintptr_t
rbp
;
30
uintptr_t
rflags
;
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
40
MALLOC_DECLARE
(M_X86_THREAD);
41
MALLOC_DECLARE
(M_KERN_STACK);
42
51
void
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
72
static
inline
void
arch_interrupts_enable
(
void
)
73
{
74
asm
volatile
(
"sti"
);
75
}
76
77
static
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). */
84
void
x86_jump_user
(
uintptr_t
eax,
uintptr_t
eip,
uintptr_t
cs
,
uintptr_t
eflags,
uintptr_t
esp,
uintptr_t
ss
) __attribute__((noreturn));
85
void
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 */
arch_syscall
void arch_syscall(struct aarch64_regs *r)
Definition
syscall.c:23
arch_interrupts_disable
static void arch_interrupts_disable(void)
Masks IRQs.
Definition
arch.h:77
arch_interrupts_enable
static void arch_interrupts_enable(void)
Unmasks IRQs (DAIF.I).
Definition
arch.h:71
x86_goto
void x86_goto(uintptr_t eip, uintptr_t ebp, uintptr_t esp)
x86_jump_user
void x86_jump_user(uintptr_t eax, uintptr_t eip, uintptr_t cs, uintptr_t eflags, uintptr_t esp, uintptr_t ss)
cpu.h
MALLOC_DECLARE
#define MALLOC_DECLARE(type)
Definition
kvmem.h:29
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
x86_regs
The registers an interrupt or exception saved, on the kernel stack, as cpu.S's stubs push them: the g...
Definition
cpu.h:12
x86_regs::cs
uint64_t cs
Definition
cpu.h:24
x86_regs::ss
uint64_t ss
Definition
cpu.h:24
x86_thread
A thread's x86 state: its kernel stack, and where it resumes.
Definition
arch.h:16
x86_thread::kstack_base
uintptr_t kstack_base
Definition
arch.h:18
x86_thread::rip
uintptr_t rip
Definition
arch.h:27
x86_thread::fpu_enabled
int fpu_enabled
Definition
arch.h:37
x86_thread::fpu_context
void * fpu_context
Definition
arch.h:35
x86_thread::rflags
uintptr_t rflags
Definition
arch.h:30
x86_thread::rbp
uintptr_t rbp
Definition
arch.h:29
x86_thread::rsp
uintptr_t rsp
Definition
arch.h:28
x86_thread::rax
uintptr_t rax
Definition
arch.h:31
x86_thread::regs
struct x86_regs * regs
Definition
arch.h:34
x86_thread::kstack
uintptr_t kstack
Definition
arch.h:17
kernel
arch
i386
include
core
arch.h
Generated by
1.18.0