Compare commits

..

No commits in common. "riscv" and "feat/main" have entirely different histories.

4 changed files with 13 additions and 16 deletions

View File

@ -4,7 +4,7 @@ extern "C" {
fn cpuid() -> u64; fn cpuid() -> u64;
fn consoleinit(); fn consoleinit();
fn printfinit(); fn printfinit();
fn printf(msg: *const i8); // fn printf();
fn kinit(); fn kinit();
fn kvminit(); fn kvminit();
fn kvminithart(); fn kvminithart();
@ -27,9 +27,9 @@ pub unsafe fn kmain() {
if cpuid() == 0 { if cpuid() == 0 {
consoleinit(); consoleinit();
printfinit(); printfinit();
printf(c"\n".as_ptr()); // printf("\n");
printf(c"xv6 kernel is booting\n".as_ptr()); // printf("xv6 kernel is booting\n");
printf(c"\n".as_ptr()); // printf("\n");
kinit(); // physical page allocator kinit(); // physical page allocator
kvminit(); // create kernel page table kvminit(); // create kernel page table
kvminithart(); // turn on paging kvminithart(); // turn on paging

View File

@ -1,8 +1,6 @@
#![no_std] #![no_std]
#![crate_type = "staticlib"] #![crate_type = "staticlib"]
use core::ffi::CStr;
pub mod kmain; pub mod kmain;
pub mod memlayout; pub mod memlayout;
pub mod param; pub mod param;
@ -13,16 +11,17 @@ pub mod uart;
extern "C" { extern "C" {
// printf.c // printf.c
fn panic(s: *const i8); fn panic(s: *const u8);
} }
static PANIC_MSG: &CStr = c"!RUST PANIC!"; /// '!RUST PANIC!\0'
static PANIC_MSG: [u8; 13] = [33, 82, 85, 83, 84, 32, 80, 65, 78, 73, 67, 33, 0];
#[panic_handler] #[panic_handler]
#[no_mangle] #[no_mangle]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! { fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
unsafe { unsafe {
panic(PANIC_MSG.as_ptr()); panic(core::ptr::addr_of!(PANIC_MSG[0]));
} }
loop {} loop {}
} }

View File

@ -6,12 +6,12 @@ pub struct SpinLock {
// Is the lock held? // Is the lock held?
pub locked: u32, // C boolean pub locked: u32, // C boolean
// For debugging: // For debugging:
pub name: *const i8, // Name of lock. pub name: *const u8, // Name of lock.
pub cpu: *mut (), // The cpu holding the lock. pub cpu: *mut (), // The cpu holding the lock.
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn initlock(lock: *mut SpinLock, name: *const i8) { pub unsafe extern "C" fn initlock(lock: *mut SpinLock, name: *const u8) {
(*lock).name = name; (*lock).name = name;
(*lock).locked = 0; (*lock).locked = 0;
(*lock).cpu = null_mut(); (*lock).cpu = null_mut();

View File

@ -2,10 +2,7 @@ use crate::{
memlayout::UART0, memlayout::UART0,
spinlock::{initlock, SpinLock}, spinlock::{initlock, SpinLock},
}; };
use core::{ use core::ptr::{addr_of_mut, null, null_mut};
ffi::CStr,
ptr::{addr_of_mut, null, null_mut},
};
extern "C" { extern "C" {
// spinlock.c // spinlock.c
@ -69,7 +66,8 @@ static mut uart_tx_lock: crate::spinlock::SpinLock = crate::spinlock::SpinLock {
name: null(), name: null(),
}; };
static UART_LOCK_NAME: &CStr = c"uart"; // NOTE: string 'uart\0' for c-implmentation of spinlock. Stupid but works.
static UART_LOCK_NAME: [u8; 5] = [0x75, 0x61, 0x72, 0x74, 0];
const UART_TX_BUF_SIZE: usize = 32; const UART_TX_BUF_SIZE: usize = 32;
static mut uart_tx_buf: [u8; UART_TX_BUF_SIZE] = [0; UART_TX_BUF_SIZE]; static mut uart_tx_buf: [u8; UART_TX_BUF_SIZE] = [0; UART_TX_BUF_SIZE];