From 64e26c9eea4c1f77647ec1f982bab0191809818e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 24 Nov 2021 20:43:57 +0100 Subject: [PATCH 1/4] Use new inline assembly syntax --- src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3ccac477..21b8ceae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![feature(lang_items)] #![feature(global_asm)] -#![feature(llvm_asm)] +#![feature(asm)] #![no_std] #![no_main] @@ -42,8 +42,9 @@ global_asm!(include_str!("video_mode/vga_320x200.s")); global_asm!(include_str!("video_mode/vga_text_80x25.s")); unsafe fn context_switch(boot_info: VirtAddr, entry_point: VirtAddr, stack_pointer: VirtAddr) -> ! { - llvm_asm!("call $1; ${:private}.spin.${:uid}: jmp ${:private}.spin.${:uid}" :: - "{rsp}"(stack_pointer), "r"(entry_point), "{rdi}"(boot_info) :: "intel"); + asm!("movq {1}, %rsp; callq *{0}; 0: jmp 0b", + in(reg) entry_point.as_u64(), in(reg) stack_pointer.as_u64(), in("rdi") boot_info.as_u64(), + options(att_syntax)); ::core::hint::unreachable_unchecked() } @@ -88,8 +89,12 @@ extern "C" { #[no_mangle] pub unsafe extern "C" fn stage_4() -> ! { // Set stack segment - llvm_asm!("mov bx, 0x0 - mov ss, bx" ::: "bx" : "intel"); + asm!( + "push rbx + mov bx, 0x0 + mov ss, bx + pop rbx" + ); let kernel_start = 0x400000; let kernel_size = &_kernel_size as *const _ as u64; From 4057db1bed8c2851a7627466867d40d84bf53a0f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 24 Nov 2021 20:44:47 +0100 Subject: [PATCH 2/4] Properly mark mmap_ent as global It currently happens to work fine using cg_llvm as the global_asm!() ends up in the same cgu as the use of this global. There is no guarantee that this will always be the case and in fact in case of cg_clif this happens to not be the case, thus causing a linker error. --- src/e820.s | 1 + 1 file changed, 1 insertion(+) diff --git a/src/e820.s b/src/e820.s index 59d9c78b..cb07e8e1 100644 --- a/src/e820.s +++ b/src/e820.s @@ -51,4 +51,5 @@ do_e820: stc # "function unsupported" error exit ret +.global mmap_ent mmap_ent: .word 0 From 4331e0d582bdefa8f962d4fa76b4fa4049be1186 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 9 Jan 2022 15:47:41 +0100 Subject: [PATCH 3/4] Use intel syntax again --- src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21b8ceae..209218cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,9 +42,8 @@ global_asm!(include_str!("video_mode/vga_320x200.s")); global_asm!(include_str!("video_mode/vga_text_80x25.s")); unsafe fn context_switch(boot_info: VirtAddr, entry_point: VirtAddr, stack_pointer: VirtAddr) -> ! { - asm!("movq {1}, %rsp; callq *{0}; 0: jmp 0b", - in(reg) entry_point.as_u64(), in(reg) stack_pointer.as_u64(), in("rdi") boot_info.as_u64(), - options(att_syntax)); + asm!("mov rsp, {1}; call {0}; 2: jmp 2b", + in(reg) entry_point.as_u64(), in(reg) stack_pointer.as_u64(), in("rdi") boot_info.as_u64()); ::core::hint::unreachable_unchecked() } From bdb49cd0677d12294e11e40e79abcc7c8b335b93 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 9 Jan 2022 15:52:15 +0100 Subject: [PATCH 4/4] Update for latest nightly changes --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index 209218cf..207a16d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ compile_error!("The bootloader crate must be compiled for the `x86_64-bootloader extern crate rlibc; use bootloader::bootinfo::{BootInfo, FrameRange}; +use core::arch::asm; use core::convert::TryInto; use core::panic::PanicInfo; use core::{mem, slice};