Compare commits

...

5 Commits

Author SHA1 Message Date
hheik 22adda17cc Hotfix to previous commit 2024-05-15 00:42:56 +03:00
hheik 48ae217e41 Fixed C-string usage 2024-05-15 00:41:50 +03:00
hheik 1d51f09bd1 Fixed C-string usage 2024-05-15 00:19:42 +03:00
hheik 24df740c4d Merge branch 'feat/start' into riscv 2024-05-07 12:07:19 +03:00
hheik 9374b8a3bf Merge branch 'feat/main' into feat/start 2024-05-07 12:06:42 +03:00
4 changed files with 16 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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