Skip to content

Commit 84e6b96

Browse files
author
Jomocool
committed
解决冲突
2 parents 3e162cf + 45626c8 commit 84e6b96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3329
-577
lines changed

kernel/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ smoltcp = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/smoltcp.g
4444
system_error = { path = "crates/system_error" }
4545
unified-init = { path = "crates/unified-init" }
4646
virtio-drivers = { git = "https://git.mirrors.dragonos.org/DragonOS-Community/virtio-drivers.git", rev = "f1d1cbb" }
47+
fdt = "0.1.5"
4748

4849
# target为x86_64时,使用下面的依赖
4950
[target.'cfg(target_arch = "x86_64")'.dependencies]
@@ -52,6 +53,11 @@ x86 = "0.52.0"
5253
x86_64 = "0.14.10"
5354

5455

56+
# target为riscv64时,使用下面的依赖
57+
[target.'cfg(target_arch = "riscv64")'.dependencies]
58+
59+
60+
5561
# 构建时依赖项
5662
[build-dependencies]
5763
kernel_build = { path = "../build-scripts/kernel_build" }

kernel/src/arch/riscv64/init/mod.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,71 @@
11
use core::intrinsics::unreachable;
22

3-
use crate::{init::init_before_mem_init, kinfo, mm::PhysAddr};
3+
use fdt::node::FdtNode;
4+
5+
use crate::{
6+
driver::open_firmware::fdt::open_firmware_fdt_driver,
7+
init::{boot_params, init_before_mem_init},
8+
kinfo,
9+
mm::{PhysAddr, VirtAddr},
10+
print, println,
11+
};
12+
13+
#[derive(Debug)]
14+
pub struct ArchBootParams {
15+
/// 启动时的fdt物理地址
16+
pub fdt_paddr: PhysAddr,
17+
}
18+
19+
impl ArchBootParams {
20+
pub const DEFAULT: Self = ArchBootParams {
21+
fdt_paddr: PhysAddr::new(0),
22+
};
23+
}
424

525
#[no_mangle]
626
unsafe extern "C" fn kernel_main(hartid: usize, fdt_paddr: usize) -> ! {
727
let fdt_paddr = PhysAddr::new(fdt_paddr);
828
init_before_mem_init();
29+
boot_params().write().arch.fdt_paddr = fdt_paddr;
930
kinfo!(
1031
"DragonOS kernel is running on hart {}, fdt address:{:?}",
1132
hartid,
1233
fdt_paddr
1334
);
35+
36+
let fdt = fdt::Fdt::from_ptr(fdt_paddr.data() as *const u8).expect("Failed to parse fdt!");
37+
print_node(fdt.find_node("/").unwrap(), 0);
38+
39+
parse_dtb();
40+
1441
loop {}
1542
unreachable()
1643
}
44+
45+
fn print_node(node: FdtNode<'_, '_>, n_spaces: usize) {
46+
(0..n_spaces).for_each(|_| print!(" "));
47+
println!("{}/", node.name);
48+
node.properties().for_each(|p| {
49+
(0..n_spaces + 4).for_each(|_| print!(" "));
50+
println!("{}: {:?}", p.name, p.value);
51+
});
52+
53+
for child in node.children() {
54+
print_node(child, n_spaces + 4);
55+
}
56+
}
57+
58+
/// 解析fdt,获取内核启动参数
59+
unsafe fn parse_dtb() {
60+
let fdt_paddr = boot_params().read().arch.fdt_paddr;
61+
if fdt_paddr.is_null() {
62+
panic!("Failed to get fdt address!");
63+
}
64+
65+
open_firmware_fdt_driver()
66+
.set_fdt_vaddr(VirtAddr::new(fdt_paddr.data()))
67+
.unwrap();
68+
open_firmware_fdt_driver()
69+
.early_scan_device_tree()
70+
.expect("Failed to scan device tree at boottime.");
71+
}

kernel/src/arch/riscv64/mm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl MemoryManagementArch for RiscV64MMArch {
5353

5454
const USER_STACK_START: crate::mm::VirtAddr = VirtAddr::new(0x0000_001f_ffa0_0000);
5555

56-
unsafe fn init() -> &'static [crate::mm::PhysMemoryArea] {
56+
unsafe fn init() {
5757
todo!()
5858
}
5959

kernel/src/arch/riscv64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod asm;
22
pub mod cpu;
33
pub mod driver;
4-
mod init;
4+
pub mod init;
55
pub mod interrupt;
66
pub mod ipc;
77
mod kvm;

kernel/src/arch/x86_64/driver/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod apic;
22
mod c_adapter;
33
pub mod hpet;
44
pub mod tsc;
5+
pub mod video;

kernel/src/arch/x86_64/driver/tsc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl TSCManager {
2929
///
3030
/// 目前由于未支持acpi pm timer, 因此调用该函数时,HPET应当完成初始化,否则将无法校准TSC
3131
///
32-
/// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#1511
32+
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#1511
3333
pub fn init() -> Result<(), SystemError> {
3434
let cpuid = x86::cpuid::CpuId::new();
3535
let feat = cpuid.get_feature_info().ok_or(SystemError::ENODEV)?;
@@ -57,7 +57,7 @@ impl TSCManager {
5757
///
5858
/// - `early`:是否在早期初始化
5959
///
60-
/// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#1438
60+
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#1438
6161
fn determine_cpu_tsc_frequency(early: bool) -> Result<(), SystemError> {
6262
if unlikely(Self::cpu_khz() != 0 || Self::tsc_khz() != 0) {
6363
kwarn!("TSC and CPU frequency already determined");
@@ -237,7 +237,7 @@ impl TSCManager {
237237
/// 尝试使用PIT来校准tsc时间,并且返回tsc的频率(khz)。
238238
/// 如果失败,那么返回None
239239
///
240-
/// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#389
240+
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#389
241241
fn pit_calibrate_tsc(latch: u64, ms: u64, loopmin: u64) -> Option<u64> {
242242
// 当前暂时没写legacy pic的驱动,因此这里直接返回
243243
let has_legacy_pic = false;
@@ -307,7 +307,7 @@ impl TSCManager {
307307
///
308308
/// - `Ok((tsc, ref))`:tsc和参考值
309309
///
310-
/// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#317
310+
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#317
311311
fn read_refs(hpet_enabled: bool) -> (u64, u64) {
312312
let thresh = if Self::tsc_khz() == 0 {
313313
Self::DEFAULT_THRESHOLD
@@ -335,7 +335,7 @@ impl TSCManager {
335335

336336
/// 根据HPET的参考值计算tsc的频率
337337
///
338-
/// https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#339
338+
/// https://code.dragonos.org.cn/xref/linux-6.1.9/arch/x86/kernel/tsc.c#339
339339
fn calc_hpet_ref(mut deltatsc: u64, ref1: u64, mut ref2: u64) -> u64 {
340340
if ref2 <= ref1 {
341341
ref2 += 0x100000000;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use system_error::SystemError;
2+
3+
use crate::driver::video::fbdev::vesafb::vesafb_early_init;
4+
5+
/// 在内存管理初始化之前,初始化视频驱动(架构相关)
6+
pub fn arch_video_early_init() -> Result<(), SystemError> {
7+
vesafb_early_init()?;
8+
return Ok(());
9+
}

kernel/src/arch/x86_64/init/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[derive(Debug)]
2+
pub struct ArchBootParams {}
3+
4+
impl ArchBootParams {
5+
pub const DEFAULT: Self = ArchBootParams {};
6+
}

kernel/src/arch/x86_64/ipc/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ fn handle_signal(
536536
oldset: &SigSet,
537537
frame: &mut TrapFrame,
538538
) -> Result<i32, SystemError> {
539-
// TODO 这里要补充一段逻辑,好像是为了保证引入线程之后的地址空间不会出问题。详见https://opengrok.ringotek.cn/xref/linux-6.1.9/arch/mips/kernel/signal.c#830
539+
// TODO 这里要补充一段逻辑,好像是为了保证引入线程之后的地址空间不会出问题。详见https://code.dragonos.org.cn/xref/linux-6.1.9/arch/mips/kernel/signal.c#830
540540

541541
// 设置栈帧
542542
return setup_frame(sig, sigaction, info, oldset, frame);

kernel/src/arch/x86_64/mm/bump.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::{
2-
kdebug,
32
libs::align::{page_align_down, page_align_up},
43
mm::{
5-
allocator::bump::BumpAllocator, MemoryManagementArch, PhysAddr, PhysMemoryArea, VirtAddr,
4+
allocator::bump::BumpAllocator, memblock::mem_block_manager, MemoryManagementArch,
5+
PhysAddr, PhysMemoryArea, VirtAddr,
66
},
77
};
88

9-
use super::{X86_64MMBootstrapInfo, BOOTSTRAP_MM_INFO, PHYS_MEMORY_AREAS};
9+
use super::{X86_64MMBootstrapInfo, BOOTSTRAP_MM_INFO};
1010

1111
impl<MMA: MemoryManagementArch> BumpAllocator<MMA> {
1212
pub unsafe fn arch_remain_areas(
@@ -23,7 +23,7 @@ impl<MMA: MemoryManagementArch> BumpAllocator<MMA> {
2323
let offset_end = page_align_down(kernel_code_start - 16384);
2424

2525
// 把内核代码前的空间加入到可用内存区域中
26-
for area in &PHYS_MEMORY_AREAS {
26+
for area in mem_block_manager().to_iter() {
2727
let area_base = area.area_base_aligned().data();
2828
let area_end = area.area_end_aligned().data();
2929
if area_base >= offset_end {
@@ -44,7 +44,6 @@ impl<MMA: MemoryManagementArch> BumpAllocator<MMA> {
4444
ret_areas[res_count] =
4545
PhysMemoryArea::new(PhysAddr::new(new_start), new_end - new_start);
4646

47-
kdebug!("new arch remain area: {:?}", ret_areas[res_count]);
4847
res_count += 1;
4948
}
5049

0 commit comments

Comments
 (0)