Skip to content

remove dependencies to rust feature "naked functions" #95

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

Merged
merged 4 commits into from
Aug 30, 2020
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
13 changes: 11 additions & 2 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub use crate::arch::x86_64::kernel::processor;
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::scheduler;
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::switch::{switch_to_fpu_owner, switch_to_task};
#[cfg(target_arch = "x86_64")]
pub use crate::arch::x86_64::kernel::systemtime::get_boot_time;
#[cfg(not(test))]
#[cfg(target_arch = "x86_64")]
Expand All @@ -72,3 +70,14 @@ pub use crate::arch::x86_64::kernel::{
pub use crate::arch::x86_64::kernel::{
get_processor_count, message_output_init, output_message_buf, output_message_byte,
};

#[cfg(test)]
pub fn switch_to_task(_old_stack: *mut usize, _new_stack: usize) {}
#[cfg(test)]
pub fn switch_to_fpu_owner(_old_stack: *mut usize, _new_stack: usize) {}

#[cfg(not(test))]
extern "C" {
pub fn switch_to_task(old_stack: *mut usize, new_stack: usize);
pub fn switch_to_fpu_owner(old_stack: *mut usize, new_stack: usize);
}
9 changes: 6 additions & 3 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ pub fn init_next_processor_variables(core_id: CoreId) {
}
}

extern "C" {
fn _start();
}

/// Boot all Application Processors
/// This algorithm is derived from Intel MultiProcessor Specification 1.4, B.4, but testing has shown
/// that a second STARTUP IPI and setting the BIOS Reset Vector are no longer necessary.
Expand Down Expand Up @@ -559,10 +563,9 @@ pub fn boot_application_processors() {
// Set entry point
debug!(
"Set entry point for application processor to 0x{:x}",
arch::x86_64::kernel::start::_start as u64
_start as u64
);
*((SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_ENTRY).as_mut_ptr()) =
arch::x86_64::kernel::start::_start as u64;
*((SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_ENTRY).as_mut_ptr()) = _start as u64;
*((SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_BOOTINFO).as_mut_ptr()) = BOOT_INFO as u64;
}

Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/kernel/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn add_current_core() {
}

#[inline(never)]
#[no_mangle]
pub fn set_current_kernel_stack() {
core_scheduler().set_current_kernel_stack();
}
28 changes: 24 additions & 4 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ pub mod scheduler;
pub mod serial;
#[cfg(not(test))]
mod smp_boot_code;
#[cfg(not(test))]
mod start;
pub mod switch;
pub mod systemtime;
#[cfg(feature = "vga")]
mod vga;
Expand All @@ -49,7 +46,12 @@ use core::convert::TryInto;
#[cfg(feature = "newlib")]
use core::slice;
use core::{intrinsics, ptr};
use x86::controlregs::{cr0, cr4};
use x86::controlregs::{cr0, cr0_write, cr4, Cr0};

#[cfg(not(test))]
global_asm!(include_str!("start.s"));
#[cfg(not(test))]
global_asm!(include_str!("switch.s"));

const SERIAL_PORT_BAUDRATE: u32 = 115_200;

Expand Down Expand Up @@ -403,3 +405,21 @@ pub fn print_statistics() {
}
}
}

#[cfg(not(test))]
#[inline(never)]
#[no_mangle]
unsafe fn pre_init(boot_info: &'static mut BootInfo) -> ! {
// Enable caching
let mut cr0 = cr0();
cr0.remove(Cr0::CR0_CACHE_DISABLE | Cr0::CR0_NOT_WRITE_THROUGH);
cr0_write(cr0);

BOOT_INFO = boot_info as *mut BootInfo;

if boot_info.cpu_online == 0 {
crate::boot_processor_main()
} else {
crate::application_processor_main()
}
}
14 changes: 10 additions & 4 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,17 @@ impl Clone for TaskTLS {
}

#[cfg(test)]
extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) {}
extern "C" fn task_start(func: extern "C" fn(usize), arg: usize, user_stack: u64) {}

#[cfg(not(test))]
extern "C" {
fn task_start(func: extern "C" fn(usize), arg: usize, user_stack: u64);
}

#[inline(never)]
#[naked]
#[no_mangle]
extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) -> ! {
// Call the actual entry point of the task.
switch_to_user!();
func(arg);
switch_to_kernel!();

Expand Down Expand Up @@ -366,7 +369,7 @@ impl TaskFrame for Task {
if let Some(tls) = &self.tls {
(*state).fs = tls.get_fs().as_u64();
}
(*state).rip = task_entry as u64;
(*state).rip = task_start as u64;
(*state).rdi = func as u64;
(*state).rsi = arg as u64;

Expand All @@ -377,6 +380,9 @@ impl TaskFrame for Task {
self.last_stack_pointer = stack;
self.user_stack_pointer =
self.stacks.get_user_stack() + self.stacks.get_user_stack_size() - 0x10u64;

// rdx is required to intialize the stack
(*state).rdx = self.user_stack_pointer.as_u64() - mem::size_of::<u64>() as u64;
}
}
}
Expand Down
48 changes: 0 additions & 48 deletions src/arch/x86_64/kernel/start.rs

This file was deleted.

32 changes: 32 additions & 0 deletions src/arch/x86_64/kernel/start.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2020 Stefan Lankes, RWTH Aachen University
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

.section .text
.global _start
.global task_start
.extern pre_init
.extern task_entry

.align 16
_start:
// initialize stack pointer
mov $0x7ff0,%rax
add 0x38(%rdi),%rax
mov %rax, %rsp
mov %rsp, %rbp

call pre_init

l1:
jmp l1

.align 16
task_start:
mov %rdx, %rsp
sti
jmp task_entry
jmp l1
132 changes: 0 additions & 132 deletions src/arch/x86_64/kernel/switch.rs

This file was deleted.

Loading