Skip to content

Commit

Permalink
feat: add vbe and stack_trace
Browse files Browse the repository at this point in the history
Characters can be printed on the screen. Support partial stack backtracking
  • Loading branch information
Godones committed Aug 4, 2022
1 parent f08094a commit 430b877
Show file tree
Hide file tree
Showing 46 changed files with 2,355 additions and 776 deletions.
28 changes: 28 additions & 0 deletions loongrCore/Cargo.lock

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

2 changes: 2 additions & 0 deletions loongrCore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ buddy_system_allocator = "0.6.0"
easy-fs = {path = "../easy-fs"}
pci = {path = "../pci"}
isomorphic_drivers = { path = "../isomorphic_drivers" }
vbe = {path = "../vbe"}
stack_trace = {path = "../stack_trace"}

[dependencies.lazy_static]
version = "1.4.0"
Expand Down
3 changes: 2 additions & 1 deletion loongrCore/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ ifeq ($(BOARD),qemu)
-smp 1 \
-bios $(BOOTLOADER) \
-kernel $(KERNEL_ELF) \
-vga none -nographic \
-vga none \
-nographic \
-drive file=$(FS_IMG),if=none,format=raw,id=x0 \
-device ahci,id=ahci0 \
-device ide-hd,drive=x0,bus=ahci0.0
Expand Down
17 changes: 14 additions & 3 deletions loongrCore/src/lang_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::arch::asm;
use crate::{print, println};

use core::arch::asm;
/// 这个函数将在 panic 时被调用
///
#[lang = "eh_personality"]
Expand All @@ -19,11 +18,23 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
info.message().unwrap()
);
} else {
println!("[kernel] Panicked: {}", info.message().unwrap());
println!("no location information available");
}
let mut trace = stack_trace::Trace::new();
let data = include_bytes!("../target/loongarch64-unknown-linux-gnu/release/loongrCore");
trace.init(data);
unsafe {
trace.trace().iter().for_each(|frame| {
println!("{}", frame);
});
}

abort();
}




#[no_mangle]
pub(crate) extern "C" fn abort() -> ! {
loop {
Expand Down
2 changes: 1 addition & 1 deletion loongrCore/src/loong_arch/driver/ahci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl provider::Provider for Provider {
assert_eq!(frame_pa, base + i * PAGE_SIZE);
}
let base_page = base / PAGE_SIZE;
info!("virtio_dma_alloc: {:#x} {}",base_page , pages);
info!("virtio_dma_alloc: {:#x} {}", base_page, pages);
(base, base)
}

Expand Down
3 changes: 3 additions & 0 deletions loongrCore/src/loong_arch/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod ahci;
pub mod pci;
/// !键盘驱动
mod pckbd;
mod vbe;

use crate::loong_arch::pci::pci_init;
pub use ahci::AHCIDriver;
Expand All @@ -13,6 +14,8 @@ use easy_fs::BlockDevice;
use log::info;
pub use pckbd::{i8042_init, kbd_has_data, kbd_read_scancode};

pub use self::vbe::vbe_test;

/// Used only for initialization hacks.
pub const DUMMY_BLOCK_DEVICE: *const dyn BlockDevice =
unsafe { transmute(&0 as *const _ as *const ahci::AHCIDriver as *const dyn BlockDevice) };
Expand Down
16 changes: 16 additions & 0 deletions loongrCore/src/loong_arch/driver/vbe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use vbe::{VbeDriver,VbeInfo};



pub fn vbe_test() {
let vbe_info = VbeInfo::new(1280,800,8,16,0x40000000,4);
let mut vbe = VbeDriver::new(vbe_info,0);
for _ in 0..800/16 {
vbe.print_string("hello world\n");
}
vbe.print_string_with_color("hello\n",0x0,0x00ff00ff);
vbe.print_string("\thello\n");
vbe.put_rect(1280/2,800/2,100,100,0x00ff00ff);
}


2 changes: 1 addition & 1 deletion loongrCore/src/loong_arch/register/cpuid.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 该寄存器中存有处理器核编号信息。

use core::arch::asm;
use super::csr::CSR_CPUID;
use crate::Register;
use core::arch::asm;
pub struct Cpuid {
bits: u32,
}
Expand Down
8 changes: 5 additions & 3 deletions loongrCore/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern crate pci;
extern crate rlibc;
extern crate xmas_elf;


// use log::info;
use crate::boot_param::boot_params_interface::BootParamsInterface;
use crate::info::print_machine_info;
Expand All @@ -51,9 +52,7 @@ use config::FLAG;
use core::arch::{asm, global_asm};

use crate::fs::list_apps;
use crate::loong_arch::{
ahci_init, extioi_init, i8042_init, ls7a_intc_init, rtc_init, rtc_time_read,
};
use crate::loong_arch::{ahci_init, extioi_init, i8042_init, ls7a_intc_init, rtc_init, rtc_time_read, vbe_test};
pub use log::{debug, error, info, trace, warn};

global_asm!(include_str!("head.S"));
Expand Down Expand Up @@ -82,6 +81,8 @@ pub extern "C" fn main(
_boot_params_interface as usize
);
mm::init();
// vbe_test();

trap::init();
print_machine_info();
ahci_init();
Expand All @@ -92,3 +93,4 @@ pub extern "C" fn main(
task::run_tasks(); //运行程序
panic!("main end");
}

2 changes: 1 addition & 1 deletion loongrCore/src/mm/frame_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloc::vec::Vec;

use core::fmt::{self, Debug, Formatter};
use lazy_static::*;
use log::{info};
use log::info;

#[derive(Clone)]
pub struct FrameTracker {
Expand Down
4 changes: 4 additions & 0 deletions loongrCore/src/mm/system_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod bump_allocator;
mod common;
mod linked_list;

use alloc::vec;
use crate::config::KERNEL_HEAP_SIZE;
use crate::info;
use crate::mm::system_allocator::bump_allocator::BumpAllocator;
Expand Down Expand Up @@ -35,12 +36,15 @@ pub fn init_heap() {

#[allow(unused)]
pub fn heap_test() {

use alloc::boxed::Box; //使用Box包装器
use alloc::vec::Vec; //使用vec数组
extern "C" {
fn sbss();
fn ebss();
}
let vec = vec![1, 2, 3, 4, 5];
panic!("{:?}", vec);

let bss_range = ebss as usize..sbss as usize;

Expand Down
10 changes: 5 additions & 5 deletions loongrCore/src/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod up;
mod condvar;
mod mutex;
mod semaphore;
mod condvar;
mod up;

pub use condvar::Condvar;
pub use mutex::{Mutex, MutexBlocking, MutexSpin};
pub use semaphore::Semaphore;
pub use up::UPSafeCell;
pub use mutex::{Mutex,MutexSpin,MutexBlocking};
pub use semaphore::{Semaphore};
pub use condvar::Condvar;
6 changes: 3 additions & 3 deletions loongrCore/src/syscall/fs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::fs::{make_pipe, open_file, OpenFlags};
use crate::list_apps;
use crate::mm::{translated_byte_buffer, translated_refmut, translated_str, UserBuffer};
use crate::task::{current_process, current_user_token};
use alloc::sync::Arc;
use crate::list_apps;

const FD_STDOUT: usize = 1;
const FD_STDIN: usize = 0;
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn sys_dup(fd: usize) -> isize {
new_fd as isize
}

pub fn sys_ls()->isize{
pub fn sys_ls() -> isize {
list_apps();
0
}
}
4 changes: 0 additions & 4 deletions loongrCore/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ const SYSCALL_FORK: usize = 220;
const SYSCALL_EXEC: usize = 221;
const SYSCALL_WAITPID: usize = 260;


const SYSCALL_THREAD_CREATE: usize = 1000;
const SYSCALL_GETTID: usize = 1001;
const SYSCALL_WAITTID: usize = 1002;


const SYSCALL_MUTEX_CREATE: usize = 1010;
const SYSCALL_MUTEX_LOCK: usize = 1011;
const SYSCALL_MUTEX_UNLOCK: usize = 1012;
Expand All @@ -45,14 +43,12 @@ const SYSCALL_CONDVAR_SIGNAL: usize = 1031;
const SYSCALL_CONDVAR_WAIT: usize = 1032;
const SYSCALL_LS: usize = 1040;


mod fs;
mod process;
mod signal;
mod sync;
mod thread;


use fs::*;
use process::*;
use signal::*;
Expand Down
9 changes: 5 additions & 4 deletions loongrCore/src/syscall/process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::get_time_ms;
use crate::mm::{translated_ref, translated_refmut, translated_str};
use crate::task::{ current_process, current_task, current_user_token, exit_current_and_run_next, suspend_current_and_run_next};
use crate::task::{
current_process, current_task, current_user_token, exit_current_and_run_next,
suspend_current_and_run_next,
};
use alloc::string::String;
// use crate::timer::get_time_ms;
use crate::fs::{open_file, OpenFlags};
Expand Down Expand Up @@ -65,8 +68,6 @@ pub fn sys_exec(path: *const u8, mut args: *const usize) -> isize {
}
}



pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize {
let process = current_process();
// find a child process
Expand Down Expand Up @@ -99,4 +100,4 @@ pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize {
-2
}
// ---- release current PCB automatically
}
}
5 changes: 1 addition & 4 deletions loongrCore/src/syscall/signal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::task::{SignalFlags, pid2process};
use crate::task::{pid2process, SignalFlags};

pub fn sys_kill(pid: usize, signal: u32) -> isize {
if let Some(process) = pid2process(pid) {
Expand All @@ -13,7 +13,6 @@ pub fn sys_kill(pid: usize, signal: u32) -> isize {
}
}


fn check_sigaction_error(signal: SignalFlags, action: usize, old_action: usize) -> bool {
if action == 0
|| old_action == 0
Expand All @@ -25,5 +24,3 @@ fn check_sigaction_error(signal: SignalFlags, action: usize, old_action: usize)
false
}
}


Loading

0 comments on commit 430b877

Please sign in to comment.