diff --git a/Cargo.lock b/Cargo.lock index 3f218724..f58063e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,26 +17,20 @@ version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94476c7ef97af4c4d998b3f422c1b01d5211aad57c80ed200baf148d1f1efab6" dependencies = [ - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", "log", ] [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] -[[package]] -name = "autocfg" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" - [[package]] name = "bare-metal" version = "0.2.5" @@ -60,9 +54,9 @@ checksum = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" @@ -72,9 +66,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bitmap-allocator" @@ -113,9 +107,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cortex-a" @@ -169,8 +163,8 @@ version = "0.1.0" dependencies = [ "aarch64-cpu", "acpi", - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", "bitmap-allocator", "bitvec", "buddy_system_allocator", @@ -194,6 +188,8 @@ dependencies = [ "sbi-spec 0.0.8", "spin 0.10.0", "tock-registers", + "uefi-raw", + "uguid", "x2apic", "x86", "x86_64", @@ -210,19 +206,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "loongArch64" @@ -230,15 +225,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c9f0d275c70310e2a9d2fc23250c5ac826a73fa828a5f256401f85c5c554283" dependencies = [ - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", ] [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "numeric-enum-macro" @@ -277,9 +272,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] @@ -290,6 +285,26 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b6fb7be1022539b1ea394ff4bcbad807a55c93841bb12c733f0be1048ea3e53" +[[package]] +name = "ptr_meta" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "qemu-exit" version = "3.0.2" @@ -298,9 +313,9 @@ checksum = "8bb0fd6580eeed0103c054e3fba2c2618ff476943762f28a645b63b8692b21c9" [[package]] name = "quote" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] @@ -322,9 +337,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -334,9 +349,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -345,9 +360,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "riscv" @@ -355,7 +370,7 @@ version = "0.6.0" source = "git+https://github.com/rcore-os/riscv#11d43cf7cccb3b62a3caaf3e07a1db7449588f9a" dependencies = [ "bare-metal", - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "log", "riscv-target", @@ -376,9 +391,9 @@ dependencies = [ [[package]] name = "riscv-decode" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8b4cfb0da0528321d22daee4299a23a8c5ac8848623d716e898d2a9eec0694" +checksum = "68b59d645e392e041ad18f5e529ed13242d8405c66bb192f59703ea2137017d0" [[package]] name = "riscv-macros" @@ -388,7 +403,7 @@ checksum = "e8c4aa1ea1af6dcc83a61be12e8189f9b293c3ba5a487778a4cd89fb060fdbbc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.111", ] [[package]] @@ -429,9 +444,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "sbi-rt" @@ -501,15 +516,26 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.2.0" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "syn" -version = "2.0.100" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -528,11 +554,28 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" +[[package]] +name = "uefi-raw" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d465de2c918779dafb769a5a4fe8d6e4fb7cc4cc6cb1a735f2f6ec68beea4" +dependencies = [ + "bitflags 2.10.0", + "ptr_meta", + "uguid", +] + +[[package]] +name = "uguid" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533" + [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "volatile" @@ -568,7 +611,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" dependencies = [ - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "raw-cpuid", ] @@ -579,7 +622,7 @@ version = "0.14.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "100555a863c0092238c2e0e814c1096c1e5cf066a309c696a87e907b5f8c5d69" dependencies = [ - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "rustversion", "volatile", diff --git a/Cargo.toml b/Cargo.toml index dc84847b..978406c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,8 @@ x86_64 = "=0.14.10" x2apic = "=0.4.3" raw-cpuid = "=10.7.0" acpi = "=5.2.0" +uguid = "=2.2.0" +uefi-raw = "=0.9.0" [features] ############# general ############## @@ -93,7 +95,7 @@ loongson_3a6000 = [] ############# x86_64 ############### graphics = [] - +split_screen = [] [profile.dev] # panic = "abort" # avoid cargo test failure, this is a bug of cargo diff --git a/platform/aarch64/rk3568/board.rs b/platform/aarch64/rk3568/board.rs index 120370f3..32ed5d3c 100644 --- a/platform/aarch64/rk3568/board.rs +++ b/platform/aarch64/rk3568/board.rs @@ -14,6 +14,7 @@ // Authors: // +use crate::pci_dev; use crate::{ arch::{ mmu::MemoryType, @@ -22,7 +23,6 @@ use crate::{ config::*, pci::vpci_dev::VpciDevType, }; -use crate::pci_dev; pub const BOARD_NAME: &str = "rk3568"; @@ -50,8 +50,8 @@ pub const BOARD_PHYSMEM_LIST: &[(u64, u64, MemoryType)] = &[ ]; pub const ROOT_ZONE_DTB_ADDR: u64 = 0xa0000000; -pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x00280000 ; -pub const ROOT_ZONE_ENTRY: u64 = 0x00280000 ; +pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x00280000; +pub const ROOT_ZONE_ENTRY: u64 = 0x00280000; //pub const ROOT_ZONE_CPUS: u64 = (1 << 0) ; pub const ROOT_ZONE_CPUS: u64 = (1 << 0) | (1 << 1); @@ -339,20 +339,18 @@ pub const ROOT_PCI_CONFIG: &[HvPciConfig] = &[ pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_DWC_ATU_CONFIG: &[HvDwcAtuConfig] = &[ - HvDwcAtuConfig { - ecam_base: 0x3c0400000, - dbi_base: 0x3c0400000, - dbi_size: 0x10000, - apb_base: 0xfe270000, - apb_size: 0x10000, - cfg_base: 0xf2000000, - cfg_size: 0x80000*2, - io_cfg_atu_shared: 0, - }, -]; +pub const ROOT_DWC_ATU_CONFIG: &[HvDwcAtuConfig] = &[HvDwcAtuConfig { + ecam_base: 0x3c0400000, + dbi_base: 0x3c0400000, + dbi_size: 0x10000, + apb_base: 0xfe270000, + apb_size: 0x10000, + cfg_base: 0xf2000000, + cfg_size: 0x80000 * 2, + io_cfg_atu_shared: 0, +}]; pub const ROOT_PCI_DEVS: [HvPciDevConfig; 2] = [ pci_dev!(0x0, 0x00, 0x0, 0x0, VpciDevType::Physical), pci_dev!(0x0, 0x01, 0x0, 0x0, VpciDevType::Physical), -]; \ No newline at end of file +]; diff --git a/platform/loongarch64/ls3a5000/board.rs b/platform/loongarch64/ls3a5000/board.rs index b373f9b7..541d73a8 100644 --- a/platform/loongarch64/ls3a5000/board.rs +++ b/platform/loongarch64/ls3a5000/board.rs @@ -14,8 +14,8 @@ // Authors: // Yulong Han // -use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; pub const BOARD_NAME: &str = "ls3a5000"; @@ -156,24 +156,22 @@ pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[]); pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { dummy: 0 }; pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ - HvPciConfig { - ecam_base: 0xfe00000000, - ecam_size: 0x20000000, - io_base: 0x18408000, - io_size: 0x8000, - pci_io_base: 0x00008000, - mem32_base: 0x0, - mem32_size: 0x0, - pci_mem32_base: 0x0, - mem64_base: 0x60000000, - mem64_size: 0x30000000, - pci_mem64_base: 0x60000000, - bus_range_begin: 0, - bus_range_end: 0xff, - domain: 0x0, - } -]; +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + ecam_base: 0xfe00000000, + ecam_size: 0x20000000, + io_base: 0x18408000, + io_size: 0x8000, + pci_io_base: 0x00008000, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x60000000, + mem64_size: 0x30000000, + pci_mem64_base: 0x60000000, + bus_range_begin: 0, + bus_range_end: 0xff, + domain: 0x0, +}]; /* 00:00.0, 00:00.1, 00:00.2, 00:00.3, 00:04.0, 00:04.1*/ /* 00:05.0, 00:05.1, 00:06.0, 00:06.1, 00:06.2 */ @@ -185,36 +183,34 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ /* BUS 6 on X4 slot */ /* 06:00.0, 06:00.1, 06:00.2, 06:00.3 net */ pub const ROOT_PCI_DEVS: &[HvPciDevConfig] = &[ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 - pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 - pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 - pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 - pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 - pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 - pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 - pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 + pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 + pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 + pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 + pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 + pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 + pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 + pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 // pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 // pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 // pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 - pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 - pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 - pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 - pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 - pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 - pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 - pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 - pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 + pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 + pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 + pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 + pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 + pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 + pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 + pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 + pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 pci_dev!(0x0, 0x0, 0x10, 0x0, VpciDevType::Physical), // 00:10.0 pci_dev!(0x0, 0x0, 0x13, 0x0, VpciDevType::Physical), // 00:13.0 pci_dev!(0x0, 0x0, 0x16, 0x0, VpciDevType::Physical), // 00:16.0 pci_dev!(0x0, 0x0, 0x19, 0x0, VpciDevType::Physical), // 00:19.0 - pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 - pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 - pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 + pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 + pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 + pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 ]; - - // bus << 8 | dev << 5 | func << 3 // pub const ROOT_PCI_DEVS: [u64; 0] = []; diff --git a/platform/loongarch64/ls3a6000/board.rs b/platform/loongarch64/ls3a6000/board.rs index 8e99e9fa..6bd74afa 100644 --- a/platform/loongarch64/ls3a6000/board.rs +++ b/platform/loongarch64/ls3a6000/board.rs @@ -14,8 +14,8 @@ // Authors: // Yulong Han // -use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; pub const BOARD_NAME: &str = "ls3a5000"; @@ -156,24 +156,22 @@ pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[]); pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { dummy: 0 }; pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ - HvPciConfig { - bus_range_begin: 0x0, - bus_range_end: 0x1f, - ecam_base: 0xfe00000000, - ecam_size: 0x20000000, - io_base: 0x18408000, - io_size: 0x8000, - pci_io_base: 0x00008000, - mem32_base: 0x0, - mem32_size: 0x0, - pci_mem32_base: 0x0, - mem64_base: 0x60000000, - mem64_size: 0x20000000, - pci_mem64_base: 0x60000000, - domain: 0x0, - } -]; +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + bus_range_begin: 0x0, + bus_range_end: 0x1f, + ecam_base: 0xfe00000000, + ecam_size: 0x20000000, + io_base: 0x18408000, + io_size: 0x8000, + pci_io_base: 0x00008000, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x60000000, + mem64_size: 0x20000000, + pci_mem64_base: 0x60000000, + domain: 0x0, +}]; /* 00:00.0, 00:00.1, 00:00.2, 00:00.3, 00:04.0, 00:04.1*/ /* 00:05.0, 00:05.1, 00:06.0, 00:06.1, 00:06.2 */ @@ -185,35 +183,34 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ /* BUS 6 on X4 slot */ /* 06:00.0, 06:00.1, 06:00.2, 06:00.3 net */ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 26] = [ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 - pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 - pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 - pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 - pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 - pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 - pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 - pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 - pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 - pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 - pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 - pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 - pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 - pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 - pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 - pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 - pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 - pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 - pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 + pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 + pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 + pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 + pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 + pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 + pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 + pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 + pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 + pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 + pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 + pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 + pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 + pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 + pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 + pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 + pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 + pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 + pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 pci_dev!(0x0, 0x0, 0x10, 0x0, VpciDevType::Physical), // 00:10.0 pci_dev!(0x0, 0x0, 0x13, 0x0, VpciDevType::Physical), // 00:13.0 pci_dev!(0x0, 0x0, 0x16, 0x0, VpciDevType::Physical), // 00:16.0 pci_dev!(0x0, 0x0, 0x19, 0x0, VpciDevType::Physical), // 00:19.0 - pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 - pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 - pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 + pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 + pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 + pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 ]; - // bus << 8 | dev << 5 | func << 3 // pub const ROOT_PCI_DEVS: [u64; 0] = []; diff --git a/platform/riscv64/hifive-premier-p550/board.rs b/platform/riscv64/hifive-premier-p550/board.rs index 06e6d03c..4424db5d 100644 --- a/platform/riscv64/hifive-premier-p550/board.rs +++ b/platform/riscv64/hifive-premier-p550/board.rs @@ -155,7 +155,7 @@ pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x20; // Note: all here's irqs are hardware irqs, // only these irq can be transferred to the physical PLIC. pub const HW_IRQS: [u32; 21] = [ - 0x1, 0x2, 0x3, 0x4, // cache controller + 0x1, 0x2, 0x3, 0x4, // cache controller 0x4f, // emmc 0x51, // sd-card 0x64, // uart0 @@ -163,17 +163,17 @@ pub const HW_IRQS: [u32; 21] = [ 0x183, // npu 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox 0x123, // i2c - // 0x01, 0x03, 0x04, 0x02, // cache controller + // 0x01, 0x03, 0x04, 0x02, // cache controller ]; // irqs belong to the root zone. pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[ - 0x1, 0x2, 0x3, 0x4, // cache controller + 0x1, 0x2, 0x3, 0x4, // cache controller 0x51, // sd-card 0x64, // uart0 0x164, 0x168, 0x165, 0x166, // iommu 0x183, // npu - 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox + 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox 0x123, // i2c ]); diff --git a/platform/riscv64/qemu-aia/board.rs b/platform/riscv64/qemu-aia/board.rs index 61bab9d6..951d93a6 100644 --- a/platform/riscv64/qemu-aia/board.rs +++ b/platform/riscv64/qemu-aia/board.rs @@ -102,7 +102,8 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 9] = [ pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x20; pub const HW_IRQS: [u32; 11] = [1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]; -pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]); // ARCH= riscv .It doesn't matter temporarily. +pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = + &get_irqs_bitmap(&[1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]); // ARCH= riscv .It doesn't matter temporarily. pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { plic_base: 0x0, diff --git a/platform/x86_64/ecx-2300f-peg/board.rs b/platform/x86_64/ecx-2300f-peg/board.rs new file mode 100644 index 00000000..59e338f7 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/board.rs @@ -0,0 +1,179 @@ +// Copyright (c) 2025 Syswonder +// hvisor is licensed under Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +// FIT FOR A PARTICULAR PURPOSE. +// See the Mulan PSL v2 for more details. +// +// Syswonder Website: +// https://www.syswonder.org +// +// Authors: +// +use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr}; + +pub const MEM_TYPE_RESERVED: u32 = 5; + +pub const BOARD_NCPUS: usize = 16; + +pub const ROOT_ZONE_DTB_ADDR: u64 = 0x00000000; +pub const ROOT_ZONE_BOOT_STACK: GuestPhysAddr = 0x7000; +pub const ROOT_ZONE_ENTRY: u64 = 0x8000; +pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x500_0000; // hpa +pub const ROOT_ZONE_CPUS: u64 = + (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); + +const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x50e_0000, + virtual_start: 0xe_0000, + size: 0x2_0000, +}; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; + +const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x3a30_0000, // hpa + virtual_start: 0x3530_0000, // gpa + size: 0x10_0000, // modify size accordingly +}; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; + +pub const ROOT_ZONE_NAME: &str = "root-linux"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all efi=noruntime root=/dev/sda2 rw init=/init rootwait\0"; +// pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; +//"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic +// video=vesafb + +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 11] = [ + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x500_0000, + virtual_start: 0x0, + size: 0xe_0000, + }, // ram + ROOT_ZONE_RSDP_REGION, // rsdp + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x510_0000, + virtual_start: 0x10_0000, + size: 0x14f0_0000, + }, // ram + ROOT_ZONE_UEFI_REGION, // uefi + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, + }, + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a30_0000, + virtual_start: 0x1530_0000, + size: 0x2000_0000, + }, // ram + ROOT_ZONE_ACPI_REGION, // acpi + HvConfigMemoryRegion { + mem_type: MEM_TYPE_IO, + physical_start: 0xfed0_0000, + virtual_start: 0xfed0_0000, + size: 0x1000, + }, // hpet + // TODO: e820 mem space probe + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x1_0000_0000, + virtual_start: 0x1_0000_0000, + size: 0x7_0000_0000, + }, // zone 1 + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0xfd00_0000, + virtual_start: 0xfd00_0000, + size: 0x100_0000, + }, // reserved + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x9000_0000, + virtual_start: 0x9000_0000, + size: 0x1000_0000, + }, // reserved +]; + +const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000; +const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xa000; +const ROOT_ZONE_VMLINUX_ENTRY_ADDR: GuestPhysAddr = 0x10_0000; +const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0x8000_0000; + +pub const ROOT_ZONE_IRQS: [u32; 32] = [0; 32]; +pub const ROOT_ZONE_IOAPIC_BASE: usize = 0xfec0_0000; +pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { + ioapic_base: ROOT_ZONE_IOAPIC_BASE, + ioapic_size: 0x1000, + kernel_entry_gpa: ROOT_ZONE_VMLINUX_ENTRY_ADDR, + cmdline_load_gpa: ROOT_ZONE_CMDLINE_ADDR, + setup_load_gpa: ROOT_ZONE_SETUP_ADDR, + initrd_load_gpa: 0, // 0x1500_0000, + initrd_size: 0, // 0x26_b000, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, + // not longer than 32 bits + screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, +}; + +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + ecam_base: 0xe0000000, + ecam_size: 0x400000, + io_base: 0x0, + io_size: 0x0, + pci_io_base: 0x0, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x0, + mem64_size: 0x0, + pci_mem64_base: 0x0, +}]; + +pub const ROOT_PCI_MAX_BUS: usize = 3; +pub const ROOT_PCI_DEVS: [HvPciDevConfig; 19] = [ + pci_dev!(0x0, 0x0, 0x0), // host bridge + pci_dev!(0x0, 0x1, 0x0), // PCI bridge + pci_dev!(0x0, 0x1, 0x1), // PCI bridge + // pci_dev!(0x0, 0x2, 0x0), // display controller + pci_dev!(0x0, 0x8, 0x0), // system peripheral + pci_dev!(0x0, 0x12, 0x0), // signal processing controller + pci_dev!(0x0, 0x14, 0x0), // USB controller + pci_dev!(0x0, 0x14, 0x2), // RAM memory + pci_dev!(0x0, 0x14, 0x5), // SD host controller + pci_dev!(0x0, 0x15, 0x0), // serial bus controller + pci_dev!(0x0, 0x16, 0x0), // communication controller + pci_dev!(0x0, 0x16, 0x3), // serial controller + pci_dev!(0x0, 0x17, 0x0), // SATA controller + pci_dev!(0x0, 0x1d, 0x0), // PCI bridge + // pci_dev!(0x0, 0x1f, 0x0), // ISA bridge + pci_dev!(0x0, 0x1f, 0x3), // audio device + pci_dev!(0x0, 0x1f, 0x4), // SMBus + pci_dev!(0x0, 0x1f, 0x5), // serial bus controller + // pci_dev!(0x0, 0x1f, 0x6), // ethernet controller + pci_dev!(0x2, 0x0, 0x0), // VGA controller + pci_dev!(0x2, 0x0, 0x1), // audio device + pci_dev!(0x3, 0x0, 0x0), // ethernet controller +]; + +#[cfg(all(feature = "graphics"))] +pub const GRAPHICS_FONT: &[u8] = + include_bytes!("../../platform/x86_64/qemu/image/font/spleen-6x12.psf"); diff --git a/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml b/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml new file mode 100644 index 00000000..a454e986 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml @@ -0,0 +1,10 @@ +[target.x86_64-unknown-none] +linker = "rust-lld" +rustflags = [ + "-Clink-arg=-Tplatform/__ARCH__/__BOARD__/linker.ld", + "-Clink-arg=-no-pie", + "-Clinker-flavor=ld.lld", + "-Cforce-frame-pointers=yes", + "-Ctarget-feature=-mmx,-sse,+soft-float", + "-Cno-redzone=yes", +] \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/cargo/features b/platform/x86_64/ecx-2300f-peg/cargo/features new file mode 100644 index 00000000..e4ad1c13 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/cargo/features @@ -0,0 +1,2 @@ +pci +uart16550a diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S new file mode 100644 index 00000000..9b979b63 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S @@ -0,0 +1,41 @@ +.section .text +.code16 +.global entry16 +entry16: + cli + cld + + mov ecx, eax + xor ax, ax + mov ds, ax + mov es, ax + mov ss, ax + + lgdt [prot_gdt_desc] + mov eax, cr0 + or eax, 0x1 + mov cr0, eax + + ljmp 0x8, entry32 + +.code32 +.global entry32 +entry32: + mov ax, 0x10 + mov ds, ax + mov es, ax + mov ss, ax + mov fs, ax + mov gs, ax + + jmp ecx + +.balign 16 +prot_gdt: + .quad 0x0000000000000000 # 0x00: null + .quad 0x00cf9b000000ffff # 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) + .quad 0x00cf93000000ffff # 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) + +prot_gdt_desc: + .short prot_gdt_desc - prot_gdt - 1 # limit + .long prot_gdt # base diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld new file mode 100644 index 00000000..3f96b209 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld @@ -0,0 +1,15 @@ +OUTPUT_ARCH(i386) +BASE_ADDRESS = 0x8000; + +ENTRY(entry16) +SECTIONS +{ + . = BASE_ADDRESS; + .text : { + *(.text .text.*) + } + + /DISCARD/ : { + *(.eh_frame) *(.eh_frame_hdr) + } +} diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk new file mode 100644 index 00000000..e23e4540 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk @@ -0,0 +1,36 @@ +boot_dir := $(image_dir)/bootloader +boot_out_dir := $(image_dir)/bootloader/out + +boot_src := $(boot_dir)/boot.S +boot_lds := $(boot_dir)/boot.ld + +boot_o := $(boot_out_dir)/boot.o +boot_elf := $(boot_out_dir)/boot.elf +boot_bin := $(boot_out_dir)/boot.bin +boot_disa := $(boot_out_dir)/boot.asm + +AS ?= as +LD ?= ld +OBJCOPY ?= objcopy +OBJDUMP ?= objdump + +boot: mkout $(boot_bin) + +disasm: + $(OBJDUMP) -d -m i8086 -M intel $(boot_elf) | less + +mkout: + rm -rf $(boot_out_dir) + mkdir -p $(boot_out_dir) + +$(boot_o): $(boot_src) + $(AS) --32 -msyntax=intel -mnaked-reg $< -o $@ + +$(boot_elf): $(boot_o) $(boot_lds) + $(LD) -T$(boot_lds) $< -o $@ + $(OBJDUMP) -d -m i8086 -M intel $@ > $(boot_disa) + +$(boot_bin): $(boot_elf) + $(OBJCOPY) $< --strip-all -O binary $@ + +.PHONY: all disasm \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf b/platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf new file mode 100644 index 00000000..071330e9 Binary files /dev/null and b/platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf differ diff --git a/platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf b/platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf new file mode 100644 index 00000000..892d085c Binary files /dev/null and b/platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf differ diff --git a/platform/x86_64/ecx-2300f-peg/image/iso/boot/grub/grub.cfg b/platform/x86_64/ecx-2300f-peg/image/iso/boot/grub/grub.cfg new file mode 100644 index 00000000..dea4571a --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/iso/boot/grub/grub.cfg @@ -0,0 +1,27 @@ +set timeout=10 # waiting time befo automatic booting +set default=0 # default menu entry index + +insmod all_video + +menuentry "Hvisor" { + multiboot2 /boot/hvisor # use multiboot spec to boot + module2 /boot/kernel/boot.bin 0 + module2 /boot/kernel/boot.bin 5008000 + module2 /boot/kernel/setup.bin 500a000 + module2 /boot/kernel/vmlinux.bin 5100000 + boot +} + +if [ ${grub_platform} == "efi" ]; then + menuentry "UEFI Setting" { + fwsetup + } +fi + +menuentry "System Reboot" --class=reboot { + reboot +} + +menuentry "System Shutdown" --class=halt { + halt +} \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/linker.ld b/platform/x86_64/ecx-2300f-peg/linker.ld new file mode 100644 index 00000000..a0096daa --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/linker.ld @@ -0,0 +1,53 @@ +ENTRY(arch_entry) +BASE_ADDRESS = 0xffffff8000200000; + +SECTIONS +{ + . = BASE_ADDRESS; + skernel = .; + + stext = .; + .text : { + KEEP(*(.text.header)) + *(.text.entry) + *(.text.entry32) + *(.text.entry64) + *(.text .text.*) + } + + . = ALIGN(4K); + etext = .; + srodata = .; + .rodata : { + *(.rodata .rodata.*) + *(.srodata .srodata.*) + } + + . = ALIGN(4K); + erodata = .; + sdata = .; + .data : { + *(.data.entry_page_table) + *(.data .data.*) + *(.sdata .sdata.*) + } + + . = ALIGN(4K); + edata = .; + .bss : { + *(.bss.stack) + sbss = .; + *(.bss .bss.*) + *(.sbss .sbss.*) + } + + . = ALIGN(4K); + ebss = .; + ekernel = .; + + /DISCARD/ : { + *(.eh_frame) + } + . = ALIGN(4K); + __core_end = .; +} \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/platform.mk b/platform/x86_64/ecx-2300f-peg/platform.mk new file mode 100644 index 00000000..db763ed5 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/platform.mk @@ -0,0 +1,51 @@ +QEMU := qemu-system-x86_64 + +zone0_boot := $(image_dir)/bootloader/out/boot.bin +zone0_setup := $(image_dir)/kernel/setup.bin +zone0_vmlinux := $(image_dir)/kernel/vmlinux.bin +zone0_initrd := $(image_dir)/virtdisk/initramfs.cpio.gz +zone0_rootfs := $(image_dir)/virtdisk/rootfs1.img +zone1_rootfs := $(image_dir)/virtdisk/rootfs2.img + +QEMU_ARGS := -machine q35,kernel-irqchip=split +QEMU_ARGS += -cpu host,+x2apic,+invtsc,+vmx -accel kvm +QEMU_ARGS += -smp 4 +QEMU_ARGS += -serial mon:stdio +QEMU_ARGS += -m 4G +QEMU_ARGS += -bios /usr/share/ovmf/OVMF.fd +QEMU_ARGS += -vga std +# QEMU_ARGS += -nographic + +QEMU_ARGS += -device intel-iommu,intremap=on,eim=on,caching-mode=on,device-iotlb=on,aw-bits=48 +QEMU_ARGS += -device ioh3420,id=pcie.1,chassis=1 +QEMU_ARGS += -drive if=none,file="$(zone0_rootfs)",id=X10008000,format=raw +QEMU_ARGS += -device virtio-blk-pci,bus=pcie.1,drive=X10008000,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on + +# QEMU_ARGS += -drive if=none,file="$(zone1_rootfs)",id=X10009000,format=raw +# QEMU_ARGS += -device virtio-blk-pci,bus=pcie.1,drive=X10009000,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on +# QEMU_ARGS += -netdev tap,id=net0,ifname=tap0,script=no,downscript=no +# QEMU_ARGS += -device virtio-net-pci,bus=pcie.1,netdev=net0,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on +# QEMU_ARGS += -netdev tap,id=net0,vhostforce=on +# QEMU_ARGS += -device virtio-net-pci,bus=pcie.1,netdev=net0,disable-legacy=on,disable-modern=off,iommu_platform=on,ats=on +# QEMU_ARGS += --trace "virtio_*" --trace "virtqueue_*" --trace "vtd_dma*" --trace "iommu_*" + +# QEMU_ARGS += -kernel $(hvisor_elf) +QEMU_ARGS += -drive file=$(image_dir)/virtdisk/hvisor.iso,format=raw,index=0,media=disk + +# QEMU_ARGS += -device loader,file="$(zone0_boot)",addr=0x5008000,force-raw=on +# QEMU_ARGS += -device loader,file="$(zone0_setup)",addr=0x500a000,force-raw=on +# QEMU_ARGS += -device loader,file="$(zone0_vmlinux)",addr=0x5100000,force-raw=on +# QEMU_ARGS += -device loader,file="$(zone0_initrd)",addr=0x20000000,force-raw=on +# QEMU_ARGS += -append "initrd_size=$(shell stat -c%s $(zone0_initrd))" + +$(hvisor_bin): elf boot + $(OBJCOPY) $(hvisor_elf) --strip-all -O binary $@ + cp $(hvisor_elf) $(image_dir)/iso/boot + mkdir -p $(image_dir)/iso/boot/kernel + cp $(zone0_boot) $(image_dir)/iso/boot/kernel + cp $(zone0_setup) $(image_dir)/iso/boot/kernel + cp $(zone0_vmlinux) $(image_dir)/iso/boot/kernel + mkdir -p $(image_dir)/virtdisk + grub-mkrescue /usr/lib/grub/x86_64-efi -o $(image_dir)/virtdisk/hvisor.iso $(image_dir)/iso + +include $(image_dir)/bootloader/boot.mk \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/test/runner.sh b/platform/x86_64/ecx-2300f-peg/test/runner.sh new file mode 100644 index 00000000..e69de29b diff --git a/platform/x86_64/nuc14mnk/board.rs b/platform/x86_64/nuc14mnk/board.rs index 8cf71387..1f3f8319 100644 --- a/platform/x86_64/nuc14mnk/board.rs +++ b/platform/x86_64/nuc14mnk/board.rs @@ -32,6 +32,7 @@ const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0xe_0000, size: 0x2_0000, }; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -39,14 +40,23 @@ const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0x3530_0000, // gpa size: 0x10_0000, // modify size accordingly }; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; -pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all root=/dev/sda2 rw init=/init rootwait\0"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/nvme0n1p5 rw init=/init rootwait\0"; // pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 14] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 15] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -60,11 +70,12 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 14] = [ virtual_start: 0x10_0000, size: 0x14f0_0000, }, // ram + ROOT_ZONE_UEFI_REGION, // uefi HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, - physical_start: 0x1a00_0000, - virtual_start: 0x1500_0000, - size: 0x30_0000, + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, }, // ram HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -84,7 +95,7 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 14] = [ mem_type: MEM_TYPE_RESERVED, physical_start: 0x1_0000_0000, virtual_start: 0x1_0000_0000, - size: 0x2000_0000, + size: 0x2_0000_0000, }, // zone 1 HvConfigMemoryRegion { mem_type: MEM_TYPE_RESERVED, @@ -140,8 +151,9 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { setup_load_gpa: ROOT_ZONE_SETUP_ADDR, initrd_load_gpa: 0, // 0x1500_0000, initrd_size: 0, // 0x26_b000, - rsdp_memory_region_id: 0x1, - acpi_memory_region_id: 0x5, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, // not longer than 32 bits screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, }; @@ -161,6 +173,12 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { }]; pub const ROOT_PCI_MAX_BUS: usize = 2; +pub const ROOT_PCI_DEVS: [HvPciDevConfig; 17] = [ + pci_dev!(0x0, 0x0, 0x0), // host bridge + pci_dev!(0x0, 0x2, 0x0), // VGA controller + pci_dev!(0x0, 0x4, 0x0), + pci_dev!(0x0, 0x8, 0x0), + pci_dev!(0x0, 0xa, 0x0), pub const ROOT_PCI_DEVS: [HvPciDevConfig; 18] = [ pci_dev!(0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge pci_dev!(0x0, 0x2, 0x0, VpciDevType::Physical), // VGA controller diff --git a/platform/x86_64/nuc14mnk/cargo/features b/platform/x86_64/nuc14mnk/cargo/features index f8ee525a..69fb95c9 100644 --- a/platform/x86_64/nuc14mnk/cargo/features +++ b/platform/x86_64/nuc14mnk/cargo/features @@ -1,4 +1,6 @@ pci ecam_pcie no_pcie_bar_realloc -uart16550a \ No newline at end of file +uart16550a +graphics +split_screen \ No newline at end of file diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index 08e48eca..bff9e8f8 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -14,7 +14,9 @@ // Authors: // use crate::pci_dev; -use crate::{arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr, pci::vpci_dev::VpciDevType}; +use crate::{ + arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr, pci::vpci_dev::VpciDevType, +}; pub const MEM_TYPE_RESERVED: u32 = 5; @@ -32,6 +34,7 @@ const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0xe_0000, size: 0x2_0000, }; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -39,14 +42,24 @@ const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0x3530_0000, // gpa size: 0xf000, // modify size accordingly }; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; pub const ROOT_ZONE_CMDLINE: &str = - "console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0"; + "console=tty0 console=ttyS0 earlycon=efifb earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/sbin/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb +// /lib/systemd/systemd -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 8] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -60,11 +73,12 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 8] = [ virtual_start: 0x10_0000, size: 0x14f0_0000, }, // ram + ROOT_ZONE_UEFI_REGION, // uefi HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, - physical_start: 0x1a00_0000, - virtual_start: 0x1500_0000, - size: 0x30_0000, + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, }, // ram HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -86,12 +100,18 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 8] = [ virtual_start: 0x4030_0000, size: 0x2000_0000, }, // zone 1 + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x1_0000_0000, + virtual_start: 0x1_0000_0000, + size: 0x7000_0000, + }, // zone 1 ]; const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000; const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xa000; const ROOT_ZONE_VMLINUX_ENTRY_ADDR: GuestPhysAddr = 0x10_0000; -const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0; +const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0x7000_0000; pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x6; pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[0; 32]); @@ -104,8 +124,9 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { setup_load_gpa: ROOT_ZONE_SETUP_ADDR, initrd_load_gpa: 0, // 0x1500_0000, initrd_size: 0, //0x26_b000, - rsdp_memory_region_id: 0x1, - acpi_memory_region_id: 0x5, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, // not longer than 32 bits screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, }; @@ -129,14 +150,14 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { pub const ROOT_PCI_MAX_BUS: usize = 1; pub const ROOT_PCI_DEVS: [HvPciDevConfig; 8] = [ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge - pci_dev!(0x0, 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller - pci_dev!(0x0, 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller - pci_dev!(0x0, 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge + pci_dev!(0x0, 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller + pci_dev!(0x0, 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller + pci_dev!(0x0, 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge pci_dev!(0x0, 0x0, 0x1f, 0x0, VpciDevType::Physical), // ISA bridge pci_dev!(0x0, 0x0, 0x1f, 0x2, VpciDevType::Physical), // SATA controller pci_dev!(0x0, 0x0, 0x1f, 0x3, VpciDevType::Physical), // SMBus - pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller + pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller ]; #[cfg(all(feature = "graphics"))] diff --git a/platform/x86_64/qemu/cargo/features b/platform/x86_64/qemu/cargo/features index f8ee525a..1c961621 100644 --- a/platform/x86_64/qemu/cargo/features +++ b/platform/x86_64/qemu/cargo/features @@ -1,4 +1,5 @@ pci ecam_pcie no_pcie_bar_realloc -uart16550a \ No newline at end of file +uart16550a +iommu \ No newline at end of file diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index 319e62b7..c99d9838 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -23,6 +23,7 @@ use crate::{ platform::MEM_TYPE_RESERVED, }; use alloc::string::{String, ToString}; +use bit_field::BitField; use core::{ arch::{self, global_asm}, ffi::{c_char, CStr}, @@ -31,6 +32,15 @@ use core::{ }; use multiboot_tag::{Modules, MultibootTags}; use spin::{Mutex, Once}; +use uefi_raw::table::{ + boot::{MemoryAttribute, MemoryDescriptor, MemoryType}, + configuration::ConfigurationTable, + system::SystemTable, + Header, Revision, +}; +use uguid::{guid, Guid}; + +const ACPI_20_TABLE_GUID: Guid = guid!("8868E871-E4F1-11D3-BC22-0080C73C8881"); mod multiboot_tag { pub const END: u32 = 0; @@ -92,6 +102,11 @@ static MULTIBOOT_TAGS: Once = Once::new(); const E820_MAX_ENTRIES_ZEROPAGE: usize = 128; +const EFI64_LOADER_SIGNATURE: u32 = 0x34364c45; // EL64 + +const VIDEO_TYPE_VLFB: u8 = 0x23; +const VIDEO_TYPE_EFI: u8 = 0x70; + bitflags::bitflags! { #[derive(Clone, Copy, Debug)] /// https://www.kernel.org/doc/html/latest/arch/x86/boot.html @@ -123,7 +138,9 @@ pub enum E820Type { /// The so-called "zeropage" pub struct BootParams { screen_info: ScreenInfo, - pad0: [u8; 0x1a8], + pad9: [u8; 0x180], + efi_info: EfiInfo, + pad0: [u8; 0x8], e820_entries: u8, pad1: [u8; 0x8], setup_sects: u8, @@ -213,26 +230,29 @@ impl BootParams { boot_params.set_screen_info(config, gpm); } + // set efi_info + // if (config.zone_id == 0) { + boot_params.set_uefi_info(config); + // } + Ok(()) } fn set_e820_entries(&mut self, config: &HvZoneConfig) { let mut index = 0; for i in 0..config.memory_regions().len() { - let mem_region = config.memory_regions()[i]; + let mem_region = &config.memory_regions()[i]; let mut e820_type = E820Type::E820_DEFAULT; if i == config.arch_config.rsdp_memory_region_id || i == config.arch_config.acpi_memory_region_id { e820_type = E820Type::E820_ACPI; + } else if i == config.arch_config.uefi_memory_region_id { + e820_type = E820Type::E820_RESERVED; } else if mem_region.mem_type == MEM_TYPE_RAM { e820_type = E820Type::E820_RAM; - } /* - else if config.arch_config.initrd_load_gpa != 0 - && i == config.arch_config.initrd_memory_region_id - { - } */ + } if e820_type != E820Type::E820_DEFAULT { self.e820_table[index] = BootE820Entry { @@ -254,18 +274,130 @@ impl BootParams { self.e820_entries = index as _; } + fn set_efi_mem_map(&mut self, config: &HvZoneConfig, paddr: usize) -> usize { + let mut cnt = 0; + let mem_map_cnt = config.memory_regions().len(); + let mut mem_map = unsafe { paddr as *mut MemoryDescriptor }; + for i in 0..mem_map_cnt { + let mem_region = &config.memory_regions()[i]; + let mem_desc = unsafe { &mut *mem_map }; + + let mut mem_desc_type = MemoryType::RESERVED; + + if i == config.arch_config.rsdp_memory_region_id + || i == config.arch_config.acpi_memory_region_id + { + mem_desc_type = MemoryType::ACPI_RECLAIM; + } else if i == config.arch_config.uefi_memory_region_id { + mem_desc_type = MemoryType::RUNTIME_SERVICES_DATA; + } else if mem_region.mem_type == MEM_TYPE_RAM { + mem_desc_type = MemoryType::CONVENTIONAL; + } + + if mem_desc_type != MemoryType::RESERVED { + *mem_desc = MemoryDescriptor { + ty: mem_desc_type, + phys_start: mem_region.virtual_start, + virt_start: mem_region.virtual_start, + page_count: mem_region.size / (PAGE_SIZE as u64), + att: MemoryAttribute::WRITE_BACK, + }; + cnt += 1; + mem_map = mem_map.wrapping_add(1); + } + } + + let mem_desc = unsafe { &mut *mem_map }; + *mem_desc = MemoryDescriptor { + ty: MemoryType::MMIO, + phys_start: config.pci_config[0].ecam_base, + virt_start: config.pci_config[0].ecam_base, + page_count: config.pci_config[0].ecam_size / (PAGE_SIZE as u64), + att: MemoryAttribute::UNCACHEABLE, + }; + cnt += 1; + + cnt + } + fn set_initrd(&mut self, ramdisk_image: u32, ramdisk_size: u32) { self.ramdisk_image = ramdisk_image; self.ramdisk_size = ramdisk_size; info!("initrd size: {}", self.ramdisk_size); } + fn set_uefi_info(&mut self, config: &HvZoneConfig) { + self.efi_info.loader_signature = EFI64_LOADER_SIGNATURE; + + let uefi_region = &config.memory_regions()[config.arch_config.uefi_memory_region_id]; + let mut vaddr = uefi_region.virtual_start as usize; + let mut paddr = uefi_region.physical_start as usize; + + // set system table + self.efi_info.systab = vaddr.get_bits(0..32) as _; + self.efi_info.systab_hi = vaddr.get_bits(32..64) as _; + let system_table = unsafe { &mut *(paddr as usize as *mut SystemTable) }; + + let system_table_header = Header { + signature: SystemTable::SIGNATURE, + revision: Revision::EFI_2_90, + size: size_of::() as u32, + crc: 0, + reserved: 0, + }; + + // start of the efi memmap + vaddr += size_of::(); + paddr += size_of::(); + + let mem_desc_cnt = self.set_efi_mem_map(config, paddr); + let mem_map_tot_size = size_of::() * mem_desc_cnt; + self.efi_info.memmap = vaddr.get_bits(0..32) as _; + self.efi_info.memmap_hi = vaddr.get_bits(32..64) as _; + self.efi_info.memdesc_size = size_of::() as _; + self.efi_info.memmap_size = mem_map_tot_size as _; + self.efi_info.memdesc_version = MemoryDescriptor::VERSION; + + // start of the config table + vaddr += size_of::() * mem_desc_cnt; + paddr += size_of::() * mem_desc_cnt; + + const CONFIG_TABLE_ENTRIES: usize = 1; + let config_table = + unsafe { &mut *(paddr as *mut [ConfigurationTable; CONFIG_TABLE_ENTRIES]) }; + + // ACPI_20_TABLE_GUID + let rsdp_region = &config.memory_regions()[config.arch_config.rsdp_memory_region_id]; + config_table[0].vendor_guid = ACPI_20_TABLE_GUID; + config_table[0].vendor_table = unsafe { rsdp_region.virtual_start as _ }; + + *system_table = SystemTable { + header: system_table_header, + firmware_vendor: core::ptr::null_mut(), + firmware_revision: 0, + stdin_handle: core::ptr::null_mut(), + stdin: core::ptr::null_mut(), + stdout_handle: core::ptr::null_mut(), + stdout: core::ptr::null_mut(), + stderr_handle: core::ptr::null_mut(), + stderr: core::ptr::null_mut(), + runtime_services: core::ptr::null_mut(), + boot_services: core::ptr::null_mut(), + number_of_configuration_table_entries: CONFIG_TABLE_ENTRIES, + configuration_table: unsafe { vaddr as *mut ConfigurationTable }, + }; + } + fn set_screen_info(&mut self, config: &HvZoneConfig, gpm: &mut MemorySet) { let fb_info = &get_multiboot_tags().framebuffer; let bytes_per_pixel = (fb_info.bpp as usize) / 8; let width = fb_info.width as usize; + + #[cfg(not(feature = "split_screen"))] let height = fb_info.height as usize; + #[cfg(all(feature = "split_screen"))] + let height = (fb_info.height / 2) as usize; self.screen_info.lfb_base = config.arch_config.screen_base as _; self.screen_info.lfb_width = width as _; @@ -283,7 +415,7 @@ impl BootParams { self.screen_info.red_pos = 16; self.screen_info.alpha_size = 8; self.screen_info.alpha_pos = 24; - self.screen_info.orig_video_is_vga = 0x23; // VESA + self.screen_info.orig_video_is_vga = VIDEO_TYPE_EFI; self.screen_info.capabilities = 0; self.vid_mode = 0xffff; diff --git a/src/arch/x86_64/cpu.rs b/src/arch/x86_64/cpu.rs index 5eeaee4f..a662a5b1 100644 --- a/src/arch/x86_64/cpu.rs +++ b/src/arch/x86_64/cpu.rs @@ -254,7 +254,6 @@ impl ArchCpu { unsafe { PARKING_MEMORY_SET.get().unwrap().activate(); - info!("before vmx launch"); self.vmx_launch(); } } diff --git a/src/arch/x86_64/graphics.rs b/src/arch/x86_64/graphics.rs index af5453d8..2097e401 100644 --- a/src/arch/x86_64/graphics.rs +++ b/src/arch/x86_64/graphics.rs @@ -85,15 +85,28 @@ pub fn font_init(psf: &'static [u8]) { }); let framebuffer = &get_multiboot_tags().framebuffer; + let mid_addr = framebuffer.addr + + (framebuffer.width as u64) + * ((framebuffer.height as u64) / 2) + * ((framebuffer.bpp as u64) / 8); FRAMEBUFFER_INFO.call_once(|| { Mutex::new(FramebufferInfo { cursor_x: 0, cursor_y: 0, max_char_nr_x: (framebuffer.width / font_width) as _, + #[cfg(not(feature = "split_screen"))] max_char_nr_y: (framebuffer.height / psf_header.height) as _, + #[cfg(all(feature = "split_screen"))] + max_char_nr_y: (framebuffer.height / 2 / psf_header.height) as _, + #[cfg(not(feature = "split_screen"))] addr: framebuffer.addr as _, + #[cfg(all(feature = "split_screen"))] + addr: mid_addr as _, width: framebuffer.width as _, + #[cfg(not(feature = "split_screen"))] height: framebuffer.height as _, + #[cfg(all(feature = "split_screen"))] + height: (framebuffer.height / 2) as _, }) }); diff --git a/src/arch/x86_64/pio.rs b/src/arch/x86_64/pio.rs index feee7537..f89a5564 100644 --- a/src/arch/x86_64/pio.rs +++ b/src/arch/x86_64/pio.rs @@ -88,10 +88,10 @@ impl PortIoBitmap { bitmap.set_range_intercept(PCI_CONFIG_ADDR_PORT, true); bitmap.set_range_intercept(PCI_CONFIG_DATA_PORT, true); - if zone_id == 0 { - #[cfg(feature = "graphics")] - bitmap.set_range_intercept(UART_COM1_PORT, true); - } + // if zone_id == 0 { + #[cfg(feature = "graphics")] + bitmap.set_range_intercept(UART_COM1_PORT, true); + // } // i8042, we won't use it, but intercept its ports might block linux init bitmap.set_range_intercept(0x60..0x65, false); diff --git a/src/arch/x86_64/zone.rs b/src/arch/x86_64/zone.rs index e0c3a67d..6a3b5f0c 100644 --- a/src/arch/x86_64/zone.rs +++ b/src/arch/x86_64/zone.rs @@ -54,6 +54,7 @@ pub struct HvArchZoneConfig { /// no restriction on start gpa and size, but its type should be MEM_TYPE_RAM as well. /// Usually, the DSDT table is large, so the size of this region should be large enough. pub acpi_memory_region_id: usize, + pub uefi_memory_region_id: usize, /// If you want to use a graphical console, set screen_base to a preferred gpa /// as the start of the framebuffer. Otherwise, leave it as zero. /// No need to add a memory region for the framebuffer, diff --git a/src/event.rs b/src/event.rs index 5bc2e0b7..f31b1159 100644 --- a/src/event.rs +++ b/src/event.rs @@ -93,6 +93,7 @@ pub fn check_events() -> bool { } Some(IPI_EVENT_SHUTDOWN) => { cpu_data.arch_cpu.idle(); + false } Some(IPI_EVENT_VIRTIO_INJECT_IRQ) => { handle_virtio_irq();