-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
350 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ limitations under the License. | |
* [Demystifying the RISC-V Linux software stack](https://www.european-processor-initiative.eu/wp-content/uploads/2022/06/[email protected]) | ||
* [6.S081: Interrupts](https://pdos.csail.mit.edu/6.828/2021/slides/6s081-lec-interrupts.pdf) | ||
* [RISC-V Bytes: Introduction to Instruction Formats](https://danielmangum.com/posts/risc-v-bytes-intro-instruction-formats/) | ||
* [RISC-V System, Booting, And Interrupts](https://marz.utk.edu/my-courses/cosc562/riscv/) | ||
|
||
### Device Trees | ||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::sync::Arc; | ||
use std::{env, fs}; | ||
|
||
use log::error; | ||
|
||
use rriscv::bus::DynBus; | ||
use rriscv::hart::Hart; | ||
use rriscv::ram::Ram; | ||
use rriscv::reg::treg; | ||
use rriscv::rom::Rom; | ||
use rriscv::rtc::Rtc; | ||
use rriscv::uart::Uart8250; | ||
use rriscv::virtio::BlkDevice; | ||
use rriscv::{clint, dt, plic}; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
env_logger::init(); | ||
|
||
let args: Vec<String> = env::args().collect(); | ||
let image_file = args.get(1).expect("expect u-boot file"); | ||
let disk_file = args.get(2).expect("expect disc file"); | ||
|
||
let bin_data = fs::read(image_file).expect("file"); | ||
|
||
let bus = Arc::new(DynBus::new()); | ||
let ram = Ram::sized(1024 * 1024 * 128); | ||
let pc: usize = 0x80000000; | ||
ram.write(0, bin_data.to_vec()); | ||
|
||
let s = ram.size(); | ||
bus.map(ram, pc..(pc + s)); | ||
|
||
// Add low ram | ||
let ram = Ram::sized(0x10000); | ||
bus.map(ram, 0x0..0x10000); | ||
|
||
let rtc = Rtc::new(); | ||
bus.map(rtc, 0x40000..0x40020); | ||
|
||
let console = Uart8250::new(); | ||
bus.map(console, 0x10000000..0x10000010); | ||
|
||
// virtio block device vda | ||
let vda = BlkDevice::new(disk_file, bus.clone()); | ||
bus.map(vda, 0x10001000..0x10002000); | ||
|
||
let clint = clint::Clint::new(bus.clone(), 0x40000); | ||
bus.map(clint, 0x2000000..0x2010000); | ||
|
||
let plic = plic::Plic::new(); | ||
bus.map(plic, 0xc000000..0xc600000); | ||
|
||
let device_tree = dt::load("linux"); | ||
let dtb_start = 0x80000; | ||
let dtb_end = dtb_start + device_tree.len(); | ||
let dtb = Rom::new(device_tree); | ||
bus.map(dtb, 0x80000..dtb_end); | ||
|
||
let mut hart = Hart::new(0, pc, bus.clone()); | ||
|
||
// linux register state | ||
hart.set_register(treg("a0"), 0); | ||
hart.set_register(treg("a1"), dtb_start as u64); | ||
hart.set_csr(rriscv::csr::SATP, 0); | ||
|
||
loop { | ||
match hart.tick() { | ||
Ok(_) => {} | ||
Err(err) => { | ||
error!("err: {:?}", err); | ||
return Ok(()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.