bug fix: x86_64 rsp aliged error

This commit is contained in:
DeathWish5 2022-04-06 16:41:58 +08:00
parent 090b6af383
commit 9156ebc6dd
11 changed files with 32 additions and 20 deletions

View File

@ -82,9 +82,8 @@ impl Scheme for Apic {
fn handle_irq(&self, vector: usize) {
Self::local_apic().eoi();
let res = if vector >= X86_INT_LOCAL_APIC_BASE {
self.manager_lapic
.lock()
.handle(vector - X86_INT_LOCAL_APIC_BASE)
let handler = self.manager_lapic.lock();
handler.handle(vector - X86_INT_LOCAL_APIC_BASE)
} else {
self.manager_ioapic.lock().handle(vector)
};

View File

@ -14,8 +14,7 @@ fn breakpoint(sepc: &mut usize) {
pub(super) fn super_timer() {
super::timer::timer_set_next();
crate::timer::timer_tick();
debug!("time interrupt in kernel, runtime sched yield");
executor::sched_yield();
executor::handle_timeout();
//发生外界中断时epc的指令还没有执行故无需修改epc到下一条
}

View File

@ -25,7 +25,7 @@ pub(super) fn init() -> DeviceResult {
drivers::all_uart().first_unwrap().upcast(),
)?;
irq.unmask(trap::X86_ISA_IRQ_COM1)?;
irq.register_local_apic_handler(trap::X86_INT_APIC_TIMER, Box::new(crate::timer::timer_tick))?;
irq.register_local_apic_handler(trap::X86_INT_APIC_TIMER, Box::new(super::trap::super_timer))?;
drivers::add_device(Device::Irq(irq));
#[cfg(feature = "graphic")]

View File

@ -24,6 +24,11 @@ fn breakpoint() {
panic!("\nEXCEPTION: Breakpoint");
}
pub(super) fn super_timer() {
crate::timer::timer_tick();
executor::handle_timeout();
}
#[no_mangle]
pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
trace!(

View File

@ -60,11 +60,11 @@ async fn run_user(thread: CurrentThread) {
}
// run
trace!("go to user: {:#x?}", ctx);
trace!("go to user: tid = {} ctx = {:#x?}", thread.id(), ctx);
kernel_hal::interrupt::intr_off(); // trapframe can't be interrupted
ctx.enter_uspace();
kernel_hal::interrupt::intr_on();
trace!("back from user: {:#x?}", ctx);
trace!("back from user: tid = {}, ctx = {:#x?}", thread.id(), ctx);
// handle trap/interrupt/syscall
if let Err(err) = handle_user_trap(&thread, ctx).await {
thread.exit_linux(err as i32);

View File

@ -1,7 +1,8 @@
set confirm off
set architecture riscv:rv64
target remote 127.0.0.1:15234
symbol-file ../target/riscv64/release/zcore
display/10i $pc
break *0x8020004a
break
symbol-file ../target/x86_64/release/zcore
b _start
# b __alltraps
# b syscall_return
# b syscall_entry
display/10i $rip

7
zCore/.gdbinit_riscv Normal file
View File

@ -0,0 +1,7 @@
set confirm off
set architecture riscv:rv64
target remote 127.0.0.1:15234
symbol-file ../target/riscv64/release/zcore
display/10i $pc
break *0x8020004a
break

View File

@ -64,7 +64,7 @@ lock = { git = "https://github.com/DeathWish5/kernel-sync", features = ["libos"]
# Bare-metal mode
[target.'cfg(target_os = "none")'.dependencies]
buddy_system_allocator = "0.7"
buddy_system_allocator = "0.8"
executor = { git = "https://github.com/DeathWish5/PreemptiveScheduler" }
lock = { git = "https://github.com/DeathWish5/kernel-sync" }

View File

@ -226,6 +226,10 @@ endif
.PHONY: debugrun
debugrun: $(qemu_disk)
ifeq ($(ARCH), x86_64)
$(sed) 's#initramfs=.*#initramfs=\\EFI\\zCore\\$(notdir $(user_img))#' $(esp)/EFI/Boot/rboot.conf
$(sed) 's#cmdline=.*#cmdline=$(CMDLINE)#' $(esp)/EFI/Boot/rboot.conf
endif
$(qemu) $(qemu_opts) -S -gdb tcp::15234 &
@sleep 1
$(gdb)

View File

@ -37,14 +37,10 @@ fn primary_main(config: kernel_hal::KernelConfig) {
memory::init_frame_allocator(&kernel_hal::mem::free_pmem_regions());
kernel_hal::primary_init();
STARTED.store(true, Ordering::SeqCst);
kernel_hal::interrupt::intr_on();
cfg_if! {
if #[cfg(all(feature = "linux", feature = "zircon"))] {
panic!("Feature `linux` and `zircon` cannot be enabled at the same time!");
} else if #[cfg(feature = "linux")] {
log::info!("run prog");
let args = options.root_proc.split('?').map(Into::into).collect(); // parse "arg0?arg1?arg2"
let envs = alloc::vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin".into()];
let rootfs = fs::rootfs();

View File

@ -77,13 +77,14 @@ pub fn frame_dealloc(target: PhysAddr) {
cfg_if! {
if #[cfg(not(feature = "libos"))] {
const ORDER: usize = 32;
use buddy_system_allocator::LockedHeap;
/// Global heap allocator
///
/// Available after `memory::init_heap()`.
#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::new();
static HEAP_ALLOCATOR: LockedHeap<ORDER> = LockedHeap::<ORDER>::new();
/// Initialize the global heap allocator.
pub fn init_heap() {