From 379d4e81c536e3036aa2a26ec2452f17118d6caf Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 8 Apr 2024 12:39:29 +0800 Subject: [PATCH] cleanup swap top mod now that most of the implementation is done --- loader/src/swap.rs | 59 ++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/loader/src/swap.rs b/loader/src/swap.rs index a3cbf6103..d8b42b670 100644 --- a/loader/src/swap.rs +++ b/loader/src/swap.rs @@ -1,4 +1,17 @@ -use crate::{bootconfig::BootConfig, PageTable}; +/// Virtual address fields: +/// 31 22 21 12 11 0 +/// | L1 index | L2 index | LSB of addr | +/// +/// L1 PTE thus consists of 1024 entries, each resolving to a 22-bit number. +/// - The bottom 10 bits are flags +/// - The top 2 bits are 0 +/// - The middle 20 bits are the MSB of the address to the PA of the L2 PTE +/// +/// L2 PTE thus consists of 1024 entries, each resolving to a 22-bit number. It is +/// indexed by the "L2 index" bits. +/// - The bottom 10 bits are flags +/// - The top 2 bits are 0 +/// - The middle 20 bits are the MSB of the address to the PA of the target page #[repr(C)] pub struct SwapDescriptor { @@ -26,46 +39,4 @@ pub struct RawPage { pub data: [u8; 4096], } -/// Mapping pages to swap. -/// -/// Given a virtual address and PID, map to a physical offset in swap. -/* -bitfield! { - #[derive(Copy, Clone, Eq)] - impl Debug; - pub u32, -} -pub struct SwapPte {} -*/ - -const FLG_VALID: usize = 0x1; - -/// Virtual address fields: -/// 31 22 21 12 11 0 -/// | L1 index | L2 index | LSB of addr | -/// -/// L1 PTE thus consists of 1024 entries, each resolving to a 22-bit number. -/// - The bottom 10 bits are flags -/// - The top 2 bits are 0 -/// - The middle 20 bits are the MSB of the address to the PA of the L2 PTE -pub fn set_l1_pte(from_va: usize, to_pa: usize, root_pt: &mut PageTable) { - let index = from_va >> 22; - root_pt.entries[index] = ((to_pa & 0xFFFF_FC00) >> 2) // top 2 bits of PA are not used, we don't do 34-bit PA featured by Sv32 - | FLG_VALID; -} - -/// Virtual address fields: -/// 31 22 21 12 11 0 -/// | L1 index | L2 index | LSB of addr | -/// -/// L2 PTE thus consists of 1024 entries, each resolving to a 22-bit number. It is -/// indexed by the "L2 index" bits. -/// - The bottom 10 bits are flags -/// - The top 2 bits are 0 -/// - The middle 20 bits are the MSB of the address to the PA of the target page -pub fn set_l2_pte(from_va: usize, to_pa: usize, l2_pt: &mut PageTable, flags: usize) { - let index = (from_va >> 12) & 0x3_FF; - l2_pt.entries[index] = ((to_pa & 0xFFFF_FC00) >> 2) // top 2 bits of PA are not used, we don't do 34-bit PA featured by Sv32 - | flags - | FLG_VALID; -} +pub const SWAP_PT_VADDR: usize = 0xE000_0000;