From 31fdc8f17590399a6c0f9d9e0b061c90979fdc1e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Sep 2016 17:52:38 -0600 Subject: [PATCH] Cleanup usermode jump --- arch/x86_64/src/start.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/x86_64/src/start.rs b/arch/x86_64/src/start.rs index 3cdf65a..11a1290 100644 --- a/arch/x86_64/src/start.rs +++ b/arch/x86_64/src/start.rs @@ -187,23 +187,24 @@ pub unsafe extern fn kstart_ap(cpu_id: usize, page_table: usize, stack_start: us pub unsafe fn usermode(ip: usize, sp: usize) -> ! { // Go to usermode - asm!("mov rax, 0x2B # Set segment pointers + asm!("xchg bx, bx mov ds, ax mov es, ax mov fs, ax mov gs, ax - - push rax # Push stack segment - push rbx # Push stack pointer - mov rax, 3 << 12 | 1 << 9 # Set IOPL and interrupt enable flag - push rax # Push rflags - mov rax, 0x23 - push rax # Push code segment - push rcx # Push rip + push rax + push rbx + push rcx + push rdx + push rsi iretq" - : - : "{rbx}"(sp), "{rcx}"(ip) - : "rax", "sp" + : // No output because it never returns + : "{rax}"(gdt::GDT_USER_DATA << 3 | 3), // Stack segment + "{rbx}"(sp), // Stack pointer + "{rcx}"(3 << 12 | 1 << 9), // Flags - Set IOPL and interrupt enable flag + "{rdx}"(gdt::GDT_USER_CODE << 3 | 3), // Code segment + "{rsi}"(ip) // IP + : // No clobers because it never returns : "intel", "volatile"); unreachable!(); }