15 edi, esi, ebp, ebx, ecx, edx, eax,
18 eip,
cs, eflags, esp,
ss;
31 printk(
"Registers dump:\n");
33 printk(
"edi = %p\n", regs->edi);
34 printk(
"esi = %p\n", regs->esi);
35 printk(
"ebp = %p\n", regs->ebp);
36 printk(
"ebx = %p\n", regs->ebx);
37 printk(
"ecx = %p\n", regs->ecx);
38 printk(
"edx = %p\n", regs->edx);
39 printk(
"eax = %p\n", regs->eax);
40 printk(
"gs = %p\n", regs->gs );
41 printk(
"fs = %p\n", regs->fs );
42 printk(
"es = %p\n", regs->es );
43 printk(
"ds = %p\n", regs->ds );
44 printk(
"eip = %p\n", regs->eip);
46 printk(
"eflags = %p\n", regs->eflags);
47 printk(
"esp = %p\n", regs->esp);
118#define X86_SEL_CPU (X86_GDT_CPU << 3)
147 asm volatile(
"movl %%gs:0, %0" :
"=r"(
cpu));
149 asm volatile(
"movq %%gs:0, %0" :
"=r"(
cpu));
155#define CR0_PG _BV(31)
156#define CR0_WP _BV(16)
163#define CR4_PSE _BV(4)
164#define CR4_OSFXSR _BV(9)
165#define CR4_OSXMMEXCPT _BV(10)
172 asm volatile(
"mov %%cr0, %%eax":
"=a"(retval));
174 asm volatile(
"movq %%cr0, %%rax":
"=a"(retval));
183 asm volatile(
"mov %%cr1, %%eax":
"=a"(retval));
185 asm volatile(
"movq %%cr1, %%rax":
"=a"(retval));
194 asm volatile(
"mov %%cr2, %%eax":
"=a"(retval));
196 asm volatile(
"movq %%cr2, %%rax":
"=a"(retval));
205 asm volatile(
"mov %%cr3, %%eax":
"=a"(retval));
207 asm volatile(
"movq %%cr3, %%rax":
"=a"(retval));
216 asm volatile(
"mov %%cr4, %%eax":
"=a"(retval));
218 asm volatile(
"movq %%cr4, %%rax":
"=a"(retval));
226 asm volatile(
"mov %%eax, %%cr0"::
"a"(val));
228 asm volatile(
"movq %%rax, %%cr0"::
"a"(val));
235 asm volatile(
"mov %%eax, %%cr1"::
"a"(val));
237 asm volatile(
"movq %%rax, %%cr1"::
"a"(val));
244 asm volatile(
"mov %%eax, %%cr2"::
"a"(val));
246 asm volatile(
"movq %%rax, %%cr2"::
"a"(val));
253 asm volatile(
"mov %%eax, %%cr3"::
"a"(val));
255 asm volatile(
"movq %%rax, %%cr3"::
"a"(val));
262 asm volatile(
"mov %%eax, %%cr4"::
"a"(val));
264 asm volatile(
"movq %%rax, %%cr4"::
"a"(val));
294#include_next <cpu/cpu.h>
static struct cpu * curcpu(void)
Returns the running CPU's struct cpu, which TPIDR_EL1, the register meant for it, holds.
static uintptr_t read_cr0(void)
static void write_cr1(uintptr_t val)
static uintptr_t read_cr2(void)
static void write_cr3(uintptr_t val)
static void write_cr2(uintptr_t val)
static void write_cr4(uintptr_t val)
void x86_return_to_user(struct x86_regs *r, int syscall)
Delivers the current process's pending signals on the way back to user mode: stops and default action...
static void x86_dump_registers(struct x86_regs *regs)
static uintptr_t read_cr4(void)
static void write_cr0(uintptr_t val)
static uintptr_t read_cr3(void)
static uintptr_t read_cr1(void)
void x86_fpu_load_from(const void *buf, int valid)
Gives the current thread back the FPU state saved in a signal frame, at sigreturn.
void x86_fpu_trap(void)
Handles #NM, the current thread's first FPU or SSE instruction since it was switched in: it saves the...
int x86_fpu_save_to(void *buf)
Copies the current thread's FPU state, for a signal handler's frame (sys/signal.c).
void x86_fpu_disable(void)
Makes the next FPU instruction trap (sets CR0.TS).
void x86_fpu_setup(void)
Sets up the FPU on the running CPU, at boot: CR0.TS set so that the first FPU or SSE instruction rais...
void x86_fpu_enable(void)
Lets the running CPU use the FPU without trapping (clears CR0.TS).
void x86_fpu_reset(void)
Makes the current thread start with a clean FPU state at its next use of the FPU, as a signal handler...
void x86_fpu_switch_out(void)
Saves the current thread's FPU state when it is switched out, if the FPU holds it,...
void x86_kernel_stack_set(uintptr_t sp)
Sets the kernel stack that interrupts from user mode switch to, on the running CPU: the thread that i...
void x86_gdt_setup(struct cpu *cpu, uintptr_t sp)
Sets up and loads the running CPU's GDT and TSS, and points gs (or the GS base, on x86_64) at its str...
void x86_idt_gate_user_set(uint32_t id, uintptr_t offset)
Sets an interrupt gate that user mode may raise with int too: the system call vector.
void x86_idt_gate_set(uint32_t id, uintptr_t offset)
Sets an interrupt gate that only the hardware (and the kernel) can raise: an exception or a device in...
void x86_idt_setup()
Loads the IDT on the running CPU.
void x86_isr_setup(void)
Sets the IDT's gates for the exceptions and the system call vector.
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
unsigned long long int uint64_t
A CPU's aarch64 state (struct cpu's arch).
struct thread * fpu_thread
struct x86_gdt_entry gdt[X86_GDT_NR]
struct x86_regs * irq_regs
A processor, and what runs on it.
An address space's page tables, on x86.
A segment descriptor, an entry of the GDT.
The registers an interrupt or exception saved, on the kernel stack, as cpu.S's stubs push them: the g...