Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asm and global_asm macros #10

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/riscv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate opensbi_rt;
use riscv::register::scause::{Exception as E, Scause, Trap};
use riscv::register::{scause, stval};
use trapframe::{GeneralRegs, TrapFrame, UserContext};
use core::arch::asm;

#[no_mangle]
extern "C" fn main() {
Expand Down
1 change: 1 addition & 0 deletions examples/uefi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use trapframe::{GeneralRegs, TrapFrame, UserContext};
use uefi::prelude::*;
use x86_64::registers::control::*;
use x86_64::structures::paging::{PageTable, PageTableFlags};
use core::arch::asm;

#[entry]
fn efi_main(_image: Handle, st: SystemTable<Boot>) -> uefi::Status {
Expand Down
2 changes: 2 additions & 0 deletions src/arch/aarch64/fncall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Because we will store values in their pthread structure.

use super::UserContext;
use core::arch::global_asm;

global_asm!(include_str!("fncall.S"));

Expand Down Expand Up @@ -41,6 +42,7 @@ impl UserContext {
#[cfg(test)]
mod tests {
use crate::*;
use core::arch::global_asm;

// Mock user program to dump registers at stack.
global_asm!(
Expand Down
1 change: 1 addition & 0 deletions src/arch/aarch64/trap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use core::arch::{asm, global_asm};

global_asm!(include_str!("trap.S"));

Expand Down
7 changes: 6 additions & 1 deletion src/arch/mipsel/trap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::arch::{asm, global_asm};

global_asm!(include_str!("trap.S"));

/// Initialize interrupt handling for the current HART.
Expand All @@ -11,7 +13,10 @@ global_asm!(include_str!("trap.S"));
/// You **MUST NOT** modify these registers later.
pub unsafe fn init() {
// Set cp0 ebase(15, 1) register to trap entry
llvm_asm!("mtc0 $0, $$15, 1":: "r"(trap_entry as usize) :: "volatile");
asm!(
"mtc0 {trap_entry}, $15, 1",
trap_entry = in(reg) trap_entry,
);
Comment on lines +16 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems right to me, but I'm not 100% sure. The MIPS target is least used, so maybe we can revisit it in the future.

}

#[no_mangle]
Expand Down
2 changes: 2 additions & 0 deletions src/arch/riscv/trap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::arch::{asm, global_asm};

#[cfg(target_arch = "riscv32")]
global_asm!(
r"
Expand Down
2 changes: 2 additions & 0 deletions src/arch/x86_64/fncall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Because we will store values in their pthread structure.

use super::UserContext;
use core::arch::global_asm;

extern "sysv64" {
/// The syscall entry of function call.
Expand Down Expand Up @@ -230,6 +231,7 @@ syscall_fn_return:
#[cfg(test)]
mod tests {
use crate::*;
use core::arch::global_asm;

#[cfg(target_os = "macos")]
global_asm!(".set _dump_registers, dump_registers");
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use alloc::boxed::Box;
use alloc::vec::Vec;
use core::arch::asm;
use core::mem::size_of;

use x86_64::instructions::tables::{lgdt, load_tss};
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/idt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::boxed::Box;
use core::arch::asm;
use x86_64::structures::idt::*;
use x86_64::structures::DescriptorTablePointer;
use x86_64::{PrivilegeLevel, VirtAddr};
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::UserContext;
use core::arch::global_asm;
use x86_64::registers::model_specific::{Efer, EferFlags, LStar, SFMask};
use x86_64::registers::rflags::RFlags;
use x86_64::VirtAddr;
Expand Down
2 changes: 2 additions & 0 deletions src/arch/x86_64/trap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::arch::global_asm;

global_asm!(include_str!("trap.S"));
global_asm!(include_str!(concat!(env!("OUT_DIR"), "/vector.S")));

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_std]
#![feature(llvm_asm, asm, global_asm, linkage)]
#![feature(linkage)]
#![deny(warnings)]
#![cfg_attr(target_arch = "mips", feature(asm_experimental_arch))]

extern crate alloc;

Expand Down