Skip to content

Commit c0f3f2f

Browse files
committed
refactor: don't import arch module
1 parent 1217b18 commit c0f3f2f

8 files changed

Lines changed: 30 additions & 35 deletions

File tree

src/executor/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use smoltcp::socket::dns;
1414
use smoltcp::wire::{EthernetAddress, HardwareAddress, IpCidr, Ipv4Address, Ipv4Cidr};
1515

1616
use super::network::{NetworkInterface, NetworkState};
17-
use crate::arch;
17+
use crate::arch::kernel::systemtime;
1818
#[cfg(feature = "write-pcap-file")]
1919
use crate::drivers::Driver;
2020
use crate::drivers::net::NetworkDriver;
@@ -80,7 +80,7 @@ impl<'a> NetworkInterface<'a> {
8080

8181
// use the current time based on the wall-clock time as seed
8282
let mut config = Config::new(hardware_addr);
83-
config.random_seed = (arch::kernel::systemtime::now_micros()) / 1_000_000;
83+
config.random_seed = systemtime::now_micros() / 1_000_000;
8484
if capabilities.medium == Medium::Ethernet {
8585
config.hardware_addr = hardware_addr;
8686
}

src/executor/network.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use smoltcp::wire::{DnsQueryType, IpAddress};
2222
#[cfg(feature = "dhcpv4")]
2323
use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr};
2424

25-
use crate::arch;
25+
use crate::arch::kernel::systemtime;
2626
use crate::drivers::net::{NetworkDevice, NetworkDriver};
2727
#[cfg(feature = "dns")]
2828
use crate::errno::Errno;
@@ -123,7 +123,7 @@ fn start_endpoint() -> u16 {
123123

124124
#[inline]
125125
pub(crate) fn now() -> Instant {
126-
Instant::from_micros_const(arch::kernel::systemtime::now_micros().try_into().unwrap())
126+
Instant::from_micros_const(systemtime::now_micros().try_into().unwrap())
127127
}
128128

129129
#[cfg(feature = "dhcpv4")]

src/scheduler/task/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use memory_addresses::VirtAddr;
1919
#[cfg(not(feature = "common-os"))]
2020
use self::tls::Tls;
2121
use super::timer_interrupts::{Source, create_timer_abs};
22-
use crate::arch;
2322
use crate::arch::core_local::*;
23+
use crate::arch::processor::{self, FPUState};
2424
use crate::arch::scheduler::TaskStacks;
2525
use crate::fd::{Fd, RawFd, stdio};
2626
use crate::scheduler::CoreId;
@@ -373,7 +373,7 @@ pub(crate) struct Task {
373373
/// Last stack pointer on the user stack before jumping to kernel space
374374
pub user_stack_pointer: VirtAddr,
375375
/// Last FPU state before a context switch to another task using the FPU
376-
pub last_fpu_state: arch::processor::FPUState,
376+
pub last_fpu_state: FPUState,
377377
/// ID of the core this task is running on
378378
pub core_id: CoreId,
379379
/// Stack of the task
@@ -410,14 +410,14 @@ impl Task {
410410
prio: task_prio,
411411
last_stack_pointer: VirtAddr::zero(),
412412
user_stack_pointer: VirtAddr::zero(),
413-
last_fpu_state: arch::processor::FPUState::new(),
413+
last_fpu_state: FPUState::new(),
414414
core_id,
415415
stacks,
416416
object_map,
417417
#[cfg(not(feature = "common-os"))]
418418
tls: None,
419419
#[cfg(all(target_arch = "x86_64", feature = "common-os"))]
420-
root_page_table: arch::create_new_root_page_table(),
420+
root_page_table: crate::arch::create_new_root_page_table(),
421421
}
422422
}
423423

@@ -458,7 +458,7 @@ impl Task {
458458
prio: IDLE_PRIO,
459459
last_stack_pointer: VirtAddr::zero(),
460460
user_stack_pointer: VirtAddr::zero(),
461-
last_fpu_state: arch::processor::FPUState::new(),
461+
last_fpu_state: FPUState::new(),
462462
core_id,
463463
stacks: TaskStacks::from_boot_stacks(),
464464
object_map: OBJECT_MAP.get().unwrap().clone(),
@@ -602,7 +602,7 @@ impl BlockedTaskQueue {
602602
/// at least one task has elapsed.
603603
pub fn handle_waiting_tasks(&mut self, ready_queue: &mut PriorityTaskQueue) {
604604
// Get the current time.
605-
let time = arch::processor::get_timer_ticks();
605+
let time = processor::get_timer_ticks();
606606

607607
// Get the wakeup time of this task and check if we have reached the first task
608608
// that hasn't elapsed yet or waits indefinitely.

src/syscalls/entropy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::slice;
22

33
use hermit_sync::TicketMutex;
44

5-
use crate::arch;
5+
use crate::arch::processor;
66
use crate::entropy::{self, Flags};
77
use crate::errno::Errno;
88

@@ -115,7 +115,7 @@ pub extern "C" fn sys_srand(seed: u32) {
115115
}
116116

117117
pub(crate) fn init_entropy() {
118-
let seed: u32 = arch::processor::get_timestamp() as u32;
118+
let seed: u32 = processor::get_timestamp() as u32;
119119

120120
*PARK_MILLER_LEHMER_SEED.lock() = seed;
121121
}

src/syscalls/mman.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use free_list::{FreeList, PageLayout, PageRange};
1313
use hermit_sync::SpinMutex;
1414
use memory_addresses::{PhysAddr, VirtAddr};
1515

16-
use crate::arch;
1716
#[cfg(target_arch = "x86_64")]
1817
use crate::arch::mm::paging::PageTableEntryFlagsExt;
19-
use crate::arch::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
18+
use crate::arch::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags};
2019
use crate::mm::{FrameAlloc, PageAlloc, PageRangeAllocator};
2120

2221
bitflags! {
@@ -67,7 +66,7 @@ pub extern "C" fn sys_mmap(size: usize, prot_flags: MemoryProtection, ret: &mut
6766
flags.execute_disable();
6867
}
6968

70-
arch::mm::paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
69+
paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
7170

7271
*ret = virtual_address.as_mut_ptr();
7372

@@ -86,11 +85,8 @@ pub extern "C" fn sys_munmap(ptr: *mut u8, size: usize) -> i32 {
8685
return 0;
8786
}
8887

89-
if let Some(physical_address) = arch::mm::paging::virtual_to_physical(virtual_address) {
90-
arch::mm::paging::unmap::<BasePageSize>(
91-
virtual_address,
92-
size / BasePageSize::SIZE as usize,
93-
);
88+
if let Some(physical_address) = paging::virtual_to_physical(virtual_address) {
89+
paging::unmap::<BasePageSize>(virtual_address, size / BasePageSize::SIZE as usize);
9490
debug!("Unmapping {virtual_address:X} ({size}) -> {physical_address:X}");
9591

9692
let frame_range =
@@ -127,14 +123,14 @@ pub extern "C" fn sys_mprotect(ptr: *mut u8, size: usize, prot_flags: MemoryProt
127123
let virtual_address = VirtAddr::from_ptr(ptr);
128124

129125
debug!("Mprotect {virtual_address:X} ({size}) -> {prot_flags:?})");
130-
if let Some(physical_address) = arch::mm::paging::virtual_to_physical(virtual_address) {
131-
arch::mm::paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
126+
if let Some(physical_address) = paging::virtual_to_physical(virtual_address) {
127+
paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
132128
0
133129
} else {
134130
let frame_layout = PageLayout::from_size(size).unwrap();
135131
let frame_range = FrameAlloc::allocate(frame_layout).unwrap();
136132
let physical_address = PhysAddr::from(frame_range.start());
137-
arch::mm::paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
133+
paging::map::<BasePageSize>(virtual_address, physical_address, count, flags);
138134
0
139135
}
140136
}

src/syscalls/timer.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::arch;
1+
use crate::arch::kernel::systemtime;
2+
use crate::arch::processor;
23
use crate::errno::Errno;
34
use crate::syscalls::usleep;
45
use crate::time::{itimerval, timespec, timeval};
@@ -63,11 +64,11 @@ pub unsafe extern "C" fn sys_clock_gettime(clock_id: clockid_t, tp: *mut timespe
6364

6465
match clock_id {
6566
CLOCK_REALTIME => {
66-
*result = timespec::from_usec(arch::kernel::systemtime::now_micros() as i64);
67+
*result = timespec::from_usec(systemtime::now_micros() as i64);
6768
0
6869
}
6970
CLOCK_MONOTONIC => {
70-
*result = timespec::from_usec(arch::processor::get_timer_ticks() as i64);
71+
*result = timespec::from_usec(processor::get_timer_ticks() as i64);
7172
0
7273
}
7374
_ => {
@@ -111,9 +112,9 @@ pub unsafe extern "C" fn sys_clock_nanosleep(
111112

112113
if flags & TIMER_ABSTIME > 0 {
113114
if clock_id == CLOCK_REALTIME {
114-
microseconds -= arch::kernel::systemtime::now_micros();
115+
microseconds -= systemtime::now_micros();
115116
} else {
116-
microseconds -= arch::processor::get_timer_ticks();
117+
microseconds -= processor::get_timer_ticks();
117118
}
118119
}
119120

@@ -144,7 +145,7 @@ pub unsafe extern "C" fn sys_gettimeofday(tp: *mut timeval, tz: usize) -> i32 {
144145
if let Some(result) = unsafe { tp.as_mut() } {
145146
// Return the current time based on the wallclock time when we were booted up
146147
// plus the current timer ticks.
147-
let microseconds = arch::kernel::systemtime::now_micros();
148+
let microseconds = systemtime::now_micros();
148149
*result = timeval::from_usec(microseconds as i64);
149150
}
150151

src/time.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::time::Duration;
22

3-
use crate::arch;
3+
use crate::arch::kernel::systemtime;
44

55
#[allow(non_camel_case_types)]
66
pub type time_t = i64;
@@ -80,9 +80,7 @@ impl SystemTime {
8080

8181
/// Returns the system time corresponding to "now".
8282
pub fn now() -> Self {
83-
Self(timespec::from_usec(
84-
arch::kernel::systemtime::now_micros() as i64
85-
))
83+
Self(timespec::from_usec(systemtime::now_micros() as i64))
8684
}
8785

8886
/// Returns the amount of time elapsed from an earlier point in time.

src/uhyve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use uhyve_interface::GuestPhysAddr;
55
use uhyve_interface::v2::parameters::SerialWriteBufferParams;
66
use uhyve_interface::v2::{Hypercall, HypercallAddress};
77

8-
use crate::arch;
8+
use crate::arch::kernel::processor;
99
use crate::arch::mm::paging::virtual_to_physical;
1010

1111
#[cfg(target_os = "none")]
@@ -93,6 +93,6 @@ pub(crate) fn uhyve_hypercall(hypercall: Hypercall<'_>) {
9393
pub fn shutdown(error_code: i32) -> ! {
9494
uhyve_hypercall(Hypercall::Exit(error_code));
9595
loop {
96-
arch::processor::halt();
96+
processor::halt();
9797
}
9898
}

0 commit comments

Comments
 (0)