gdt - swap usermode CS & SS

This commit is contained in:
RaphProductions 2025-05-16 08:48:15 +02:00
parent b2ec036055
commit ca489e986a
4 changed files with 6 additions and 7 deletions

View file

@ -16,8 +16,8 @@ gdt_table def_table = {{
0x00af9b000000ffff, // 0x28 64 bit code cs 0x00af9b000000ffff, // 0x28 64 bit code cs
0x00af93000000ffff, // 0x30 64 bit data ss 0x00af93000000ffff, // 0x30 64 bit data ss
0x00affb000000ffff, // 0x38 user mode code cs 0x00aff3000000ffff, // 0x38 user mode data ss
0x00aff3000000ffff, // 0x40 user mode data ss 0x00affb000000ffff, // 0x40 user mode code cs
}, },
{}}; {}};

View file

@ -10,8 +10,7 @@ void __x86_64_syscall_init() {
wrmsr(IA32_EFER, efer); wrmsr(IA32_EFER, efer);
uint64_t star = 0; uint64_t star = 0;
star |= ((uint64_t)0x28 << 32); // kernel cs star |= ((uint64_t)0x28 << 32); // kernel cs
star |= ((uint64_t)0x30 star |= ((uint64_t)0x30 << 48); // user cs base (SYSCALL adds 16 for CS=0x38, 24 for SS=0x40)
<< 48); // user cs base (SYSCALL adds 16 for CS=0x38, 24 for SS=0x40)
wrmsr(IA32_STAR, star); wrmsr(IA32_STAR, star);
wrmsr(IA32_LSTAR, (uint64_t)syscall_entry); wrmsr(IA32_LSTAR, (uint64_t)syscall_entry);
wrmsr(IA32_CSTAR, 0x0); wrmsr(IA32_CSTAR, 0x0);

View file

@ -87,8 +87,8 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm,
proc->regs.cs = 0x28; // Run in kernel mode proc->regs.cs = 0x28; // Run in kernel mode
proc->regs.ss = 0x30; proc->regs.ss = 0x30;
} else if (flags == SCHED_USER_PROCESS) { } else if (flags == SCHED_USER_PROCESS) {
proc->regs.cs = 0x38 | 3; // Run in user mode proc->regs.cs = 0x40 | 3; // Run in user mode
proc->regs.ss = 0x40 | 3; proc->regs.ss = 0x38 | 3;
} }
proc->regs.rflags = 0x202; // Enable interrupts proc->regs.rflags = 0x202; // Enable interrupts
proc->regs.rsp = (uint64_t)proc->stack_end; proc->regs.rsp = (uint64_t)proc->stack_end;

View file

@ -20,7 +20,7 @@ void syscall_handle(registers_t *regs) {
return; return;
} }
if (curr_proc == NULL || curr_proc->regs.cs != 0x3B) { if (curr_proc == NULL || curr_proc->regs.cs != 0x43) {
log("syscall - syscall_handle was called by the kernel. is this wanted?\n"); log("syscall - syscall_handle was called by the kernel. is this wanted?\n");
return; return;
} }