Skip to content

Commit

Permalink
optimize for x86_64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Mar 8, 2024
1 parent ebcefce commit cfbf990
Show file tree
Hide file tree
Showing 30 changed files with 588 additions and 480 deletions.
39 changes: 35 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ flash: k210-build
debug: fs-img build
@tmux new-session -d \
"$(QEMU_EXEC) -s -S && echo '按任意键继续' && read -n 1" && \
tmux split-window -h "gdb-multiarch -ex 'file $(KERNEL_ELF)' -ex 'target remote localhost:1234'" && \
tmux split-window -h "gdb-multiarch $(KERNEL_ELF) -ex 'target remote localhost:1234' -ex 'disp /16i $pc' " && \
tmux -2 attach-session -d

clean:
Expand Down
4 changes: 0 additions & 4 deletions arch/src/aarch64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ impl ContextOps for Context {
self.regs.x2 = ret;
}

fn clear(&mut self) {
*self = Default::default();
}

#[inline]
fn set_tls(&mut self, tls: usize) {
self.tpidr = tls
Expand Down
2 changes: 1 addition & 1 deletion arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![feature(stdsimd)]
#![feature(const_mut_refs)]
#![feature(const_slice_from_raw_parts_mut)]
#![cfg_attr(target_arch = "riscv64", feature(riscv_ext_intrinsics))]

extern crate alloc;

Expand Down Expand Up @@ -60,7 +61,6 @@ pub trait ContextOps {
fn syscall_ok(&mut self);

fn set_ret(&mut self, ret: usize);
fn clear(&mut self);
fn set_tls(&mut self, tls: usize);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/src/loongarch64/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ unsafe extern "C" fn _start() -> ! {
entry = sym super::rust_tmp_main,
options(noreturn),
)
}
}
13 changes: 2 additions & 11 deletions arch/src/loongarch64/console.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use core::fmt::Write;

use spin::Mutex;
Expand Down Expand Up @@ -57,14 +56,6 @@ impl Write for Uart {

/// Writes a byte to the console.
pub fn console_putchar(c: u8) {
// let mut uart = COM1.lock();
// match c {
// b'\n' => {
// uart.putchar(b'\r');
// uart.putchar(b'\n');
// }
// c => uart.putchar(c),
// }
COM1.lock().putchar(c)
}

Expand All @@ -73,7 +64,7 @@ pub fn write_fmt(args: core::fmt::Arguments) {
COM1.lock().write_fmt(args).unwrap();
}

/// Reads a byte from the console, or returns [`None`] if no input is available.
/// read a byte, return -1 if nothing exists.
pub fn console_getchar() -> u8 {
COM1.lock().getchar().unwrap_or(u8::MAX)
}
}
4 changes: 0 additions & 4 deletions arch/src/loongarch64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ impl ContextOps for Context {
self.regs.x2 = ret;
}

fn clear(&mut self) {
*self = Default::default();
}

#[inline]
fn set_tls(&mut self, tls: usize) {
self.tpidr = tls
Expand Down
7 changes: 5 additions & 2 deletions arch/src/loongarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ mod timer;
mod trap;

use alloc::vec::Vec;
pub use console::{console_getchar, console_putchar};
pub use consts::*;
pub use context::Context;
use fdt::Fdt;
pub use page_table::*;
pub use console::{console_getchar, console_putchar};
pub use timer::get_time;
pub use trap::{enable_external_irq, enable_irq, init_interrupt, trap_pre_handle, user_restore};

Expand All @@ -22,7 +22,10 @@ pub fn rust_tmp_main(hart_id: usize) {
ArchInterface::init_logging();
allocator::init();

ArchInterface::add_memory_region(VIRT_ADDR_START | 0x9000_0000, VIRT_ADDR_START | (0x9000_0000 + 0x2f00_0000));
ArchInterface::add_memory_region(
VIRT_ADDR_START | 0x9000_0000,
VIRT_ADDR_START | (0x9000_0000 + 0x2f00_0000),
);
info!("hart_id: {}", hart_id);

ArchInterface::prepare_drivers();
Expand Down
6 changes: 0 additions & 6 deletions arch/src/riscv64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ impl ContextOps for Context {
self.x[12] = ret;
}

fn clear(&mut self) {
self.x.fill(0);
self.sepc = 0;
self.sstatus = sstatus::read();
}

#[inline]
fn set_tls(&mut self, tls: usize) {
self.x[4] = tls;
Expand Down
2 changes: 2 additions & 0 deletions arch/src/x86_64/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pub const USER_ADDR_MAX: usize = 0xbf_ffff_ffff;
pub const PAGE_SIZE: usize = 4096;
pub const PAGE_ITEM_COUNT: usize = 512;
pub const SIG_RETURN_ADDR: usize = 0xFFFF_FF80_0000_0000;

pub const SYSCALL_VECTOR: usize = usize::MAX / 2;
21 changes: 13 additions & 8 deletions arch/src/x86_64/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::ContextOps;

use super::gdt::GdtStruct;

/// Saved registers when a trap (interrupt or exception) occurs.
#[allow(missing_docs)]
#[repr(C)]
Expand All @@ -21,8 +23,8 @@ pub struct Context {
pub r14: usize,
pub r15: usize,

// pub fs_base: usize,
// pub gs_base: usize,
pub fs_base: usize,
pub gs_base: usize,

// Pushed by `trap.S`
pub vector: usize,
Expand All @@ -40,7 +42,14 @@ impl Context {
// 创建上下文信息
#[inline]
pub fn new() -> Self {
debug!(
"new_user cs: {:#x}, ss: {:#x}",
GdtStruct::UCODE64_SELECTOR.0,
GdtStruct::UDATA_SELECTOR.0
);
Self {
cs: GdtStruct::UCODE64_SELECTOR.0 as _,
ss: GdtStruct::UDATA_SELECTOR.0 as _,
..Default::default()
}
}
Expand Down Expand Up @@ -107,12 +116,8 @@ impl ContextOps for Context {
self.rdx = ret;
}

fn clear(&mut self) {
*self = Default::default();
}

#[inline]
fn set_tls(&mut self, _tls: usize) {
unimplemented!("set tls is unimplemented!")
fn set_tls(&mut self, tls: usize) {
self.fs_base = tls;
}
}
59 changes: 0 additions & 59 deletions arch/src/x86_64/entry.rs

This file was deleted.

Loading

0 comments on commit cfbf990

Please sign in to comment.