Replaced main.c
parent
d3ba78c326
commit
7797ae7810
1
Makefile
1
Makefile
|
|
@ -8,7 +8,6 @@ OBJS = \
|
|||
$K/kalloc.o \
|
||||
$K/spinlock.o \
|
||||
$K/string.o \
|
||||
$K/main.o \
|
||||
$K/vm.o \
|
||||
$K/proc.o \
|
||||
$K/swtch.o \
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
#include "types.h"
|
||||
#include "param.h"
|
||||
#include "memlayout.h"
|
||||
#include "riscv.h"
|
||||
#include "defs.h"
|
||||
|
||||
volatile static int started = 0;
|
||||
|
||||
// start() jumps here in supervisor mode on all CPUs.
|
||||
void main() {
|
||||
if (cpuid() == 0) {
|
||||
consoleinit();
|
||||
printfinit();
|
||||
printf("\n");
|
||||
printf("xv6 kernel is booting\n");
|
||||
printf("\n");
|
||||
kinit(); // physical page allocator
|
||||
kvminit(); // create kernel page table
|
||||
kvminithart(); // turn on paging
|
||||
procinit(); // process table
|
||||
trapinit(); // trap vectors
|
||||
trapinithart(); // install kernel trap vector
|
||||
plicinit(); // set up interrupt controller
|
||||
plicinithart(); // ask PLIC for device interrupts
|
||||
binit(); // buffer cache
|
||||
iinit(); // inode table
|
||||
fileinit(); // file table
|
||||
virtio_disk_init(); // emulated hard disk
|
||||
userinit(); // first user process
|
||||
__sync_synchronize();
|
||||
started = 1;
|
||||
} else {
|
||||
while (started == 0)
|
||||
;
|
||||
__sync_synchronize();
|
||||
printf("hart %d starting\n", cpuid());
|
||||
kvminithart(); // turn on paging
|
||||
trapinithart(); // install kernel trap vector
|
||||
plicinithart(); // ask PLIC for device interrupts
|
||||
}
|
||||
|
||||
scheduler();
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
use crate::riscv;
|
||||
|
||||
extern "C" {
|
||||
fn cpuid() -> u64;
|
||||
fn consoleinit();
|
||||
fn printfinit();
|
||||
// fn printf();
|
||||
fn kinit();
|
||||
fn kvminit();
|
||||
fn kvminithart();
|
||||
fn procinit();
|
||||
fn trapinit();
|
||||
fn trapinithart();
|
||||
fn plicinit();
|
||||
fn plicinithart();
|
||||
fn binit();
|
||||
fn iinit();
|
||||
fn fileinit();
|
||||
fn virtio_disk_init();
|
||||
fn userinit();
|
||||
fn scheduler();
|
||||
}
|
||||
|
||||
pub static mut started: bool = false;
|
||||
|
||||
pub unsafe fn kmain() {
|
||||
if cpuid() == 0 {
|
||||
consoleinit();
|
||||
printfinit();
|
||||
// printf("\n");
|
||||
// printf("xv6 kernel is booting\n");
|
||||
// printf("\n");
|
||||
kinit(); // physical page allocator
|
||||
kvminit(); // create kernel page table
|
||||
kvminithart(); // turn on paging
|
||||
procinit(); // process table
|
||||
trapinit(); // trap vectors
|
||||
trapinithart(); // install kernel trap vector
|
||||
plicinit(); // set up interrupt controller
|
||||
plicinithart(); // ask PLIC for device interrupts
|
||||
binit(); // buffer cache
|
||||
iinit(); // inode table
|
||||
fileinit(); // file table
|
||||
virtio_disk_init(); // emulated hard disk
|
||||
userinit(); // first user process
|
||||
riscv::barrier();
|
||||
started = true;
|
||||
} else {
|
||||
while !started {}
|
||||
riscv::barrier();
|
||||
// printf("hart %d starting\n", cpuid());
|
||||
kvminithart(); // turn on paging
|
||||
trapinithart(); // install kernel trap vector
|
||||
plicinithart(); // ask PLIC for device interrupts
|
||||
}
|
||||
|
||||
scheduler();
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#![no_std]
|
||||
#![crate_type = "staticlib"]
|
||||
|
||||
pub mod kmain;
|
||||
pub mod memlayout;
|
||||
pub mod param;
|
||||
pub mod riscv;
|
||||
|
|
|
|||
|
|
@ -327,3 +327,9 @@ pub fn PX(level: u64, va: u64) -> u64 {
|
|||
// Sv39, to avoid having to sign-extend virtual addresses
|
||||
// that have the high bit set.
|
||||
pub const MAXVA: u64 = 1 << (9 + 9 + 9 + 12 - 1);
|
||||
|
||||
/// Hardware memory barrier
|
||||
#[inline]
|
||||
pub unsafe fn barrier() {
|
||||
asm!("fence")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use core::arch::asm;
|
||||
use core::usize;
|
||||
|
||||
use crate::kmain::kmain;
|
||||
use crate::memlayout::{CLINT_MTIME, CLINT_MTIMECMP};
|
||||
use crate::param::NCPU;
|
||||
use crate::riscv as rv;
|
||||
|
|
@ -8,9 +9,6 @@ use crate::riscv as rv;
|
|||
extern "C" {
|
||||
// assembly code in kernelvec.S for machine-mode timer interrupt.
|
||||
fn timervec();
|
||||
|
||||
// main.c
|
||||
fn main();
|
||||
}
|
||||
|
||||
#[repr(align(16))]
|
||||
|
|
@ -34,7 +32,7 @@ pub unsafe extern "C" fn start() {
|
|||
|
||||
// set M Exception Program Counter to main, for mret.
|
||||
// requires gcc -mcmodel=medany
|
||||
rv::w_mepc(main as *const () as u64);
|
||||
rv::w_mepc(kmain as *const () as u64);
|
||||
|
||||
// disable paging for now.
|
||||
rv::w_satp(0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue