Compare commits
2 Commits
50322be602
...
6f65bbea34
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f65bbea34 | |||
| 65c36cfa60 |
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "acid_alloc"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b28c4f9c0c9c9c8f1045f71a22fd5f7524f562c086f604929492ea410dae8348"
|
||||||
|
dependencies = [
|
||||||
|
"sptr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "acpi"
|
name = "acpi"
|
||||||
version = "6.0.1"
|
version = "6.0.1"
|
||||||
@ -122,6 +131,7 @@ dependencies = [
|
|||||||
name = "gila"
|
name = "gila"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"acid_alloc",
|
||||||
"acpi",
|
"acpi",
|
||||||
"enumflags2",
|
"enumflags2",
|
||||||
"fdt",
|
"fdt",
|
||||||
@ -312,6 +322,12 @@ dependencies = [
|
|||||||
"lock_api",
|
"lock_api",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sptr"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5cdeee85371b1ec1f4b305c91787271a39f56b66e673bdbd73b7742150de5b0e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.106"
|
version = "2.0.106"
|
||||||
|
|||||||
@ -4,6 +4,7 @@ version = "0.3.1"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
acid_alloc = { version = "0.1.0", features = ["alloc"] }
|
||||||
acpi = { version = "6.0.1", optional = true }
|
acpi = { version = "6.0.1", optional = true }
|
||||||
enumflags2 = "0.7.12"
|
enumflags2 = "0.7.12"
|
||||||
fdt = { git = "https://github.com/repnop/fdt", version = "0.2.0-alpha1", optional = true }
|
fdt = { git = "https://github.com/repnop/fdt", version = "0.2.0-alpha1", optional = true }
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![feature(allocator_api)]
|
|
||||||
#![feature(str_from_raw_parts)]
|
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
|
|
||||||
mod arch;
|
mod arch;
|
||||||
@ -17,11 +15,12 @@ mod log;
|
|||||||
mod memory;
|
mod memory;
|
||||||
mod panic;
|
mod panic;
|
||||||
mod process;
|
mod process;
|
||||||
#[macro_use]
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use arch::x86_64::interrupts::IDT;
|
use arch::x86_64::interrupts::IDT;
|
||||||
|
use arch::x86_64::serial::SerialPort;
|
||||||
use boot::{BASE_REVISION, params, *};
|
use boot::{BASE_REVISION, params, *};
|
||||||
|
use constants::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use memory::alloc::{
|
use memory::alloc::{
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
@ -31,8 +30,6 @@ use memory::alloc::{
|
|||||||
};
|
};
|
||||||
use params::*;
|
use params::*;
|
||||||
|
|
||||||
use crate::arch::x86_64::serial::SerialPort;
|
|
||||||
use crate::constants::*;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use limine::firmware_type::FirmwareType;
|
use limine::firmware_type::FirmwareType;
|
||||||
use spin::mutex::Mutex;
|
use spin::mutex::Mutex;
|
||||||
@ -141,8 +138,6 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
log_info!("Hypervisor: {:?}", string.identify());
|
log_info!("Hypervisor: {:?}", string.identify());
|
||||||
}
|
}
|
||||||
|
|
||||||
SERIAL_3F8.lock().log_write("hi");
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
arch::asm::nop();
|
arch::asm::nop();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use crate::boot::modules::MODULE_RESPONSE;
|
|||||||
use crate::boot::params::EXECUTABLE_FILE_RESPONSE;
|
use crate::boot::params::EXECUTABLE_FILE_RESPONSE;
|
||||||
use crate::{LOGGER, LogLevel, format, log_info, log_trace};
|
use crate::{LOGGER, LogLevel, format, log_info, log_trace};
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
|
||||||
use free_list::{AllocError, FreeList, PAGE_SIZE, PageRange};
|
use free_list::{AllocError, FreeList, PAGE_SIZE, PageRange};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use limine::response::MemoryMapResponse;
|
use limine::response::MemoryMapResponse;
|
||||||
@ -27,6 +28,22 @@ lazy_static! {
|
|||||||
.expect("Bootloader did not supply memory map");
|
.expect("Bootloader did not supply memory map");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn round_up_to(multiple: usize, input: usize) -> usize {
|
||||||
|
if input.is_multiple_of(multiple) {
|
||||||
|
input
|
||||||
|
} else {
|
||||||
|
input - (input % multiple) + multiple
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn round_down_to(multiple: usize, input: usize) -> usize {
|
||||||
|
if input.is_multiple_of(multiple) {
|
||||||
|
input
|
||||||
|
} else {
|
||||||
|
input - (input % multiple)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deallocate_usable() -> Result<(), AllocError> {
|
pub fn deallocate_usable() -> Result<(), AllocError> {
|
||||||
init_statics();
|
init_statics();
|
||||||
let mut any_error: Option<AllocError> = None;
|
let mut any_error: Option<AllocError> = None;
|
||||||
@ -58,31 +75,19 @@ pub fn deallocate_hardware() -> Result<(), AllocError> {
|
|||||||
| (entry.entry_type == EntryType::FRAMEBUFFER)
|
| (entry.entry_type == EntryType::FRAMEBUFFER)
|
||||||
{
|
{
|
||||||
if let Err(error) = {
|
if let Err(error) = {
|
||||||
// Special handling for regions that are too small
|
let base: usize = round_down_to(PAGE_SIZE, entry.base as usize);
|
||||||
// TODO: fix
|
let mut length = entry.length as usize + (entry.base as usize - base);
|
||||||
let adjusted_base = if (entry.length as usize) < PAGE_SIZE {
|
length = round_up_to(PAGE_SIZE, length);
|
||||||
entry.base as usize - (PAGE_SIZE - entry.length as usize)
|
let range = PageRange::from_start_len(base, length);
|
||||||
} else {
|
|
||||||
entry.base as usize
|
|
||||||
};
|
|
||||||
let adjusted_length = if (entry.length as usize) < PAGE_SIZE {
|
|
||||||
PAGE_SIZE
|
|
||||||
} else {
|
|
||||||
entry.length as usize
|
|
||||||
};
|
|
||||||
let range = PageRange::from_start_len(adjusted_base, adjusted_length);
|
|
||||||
log_trace!(
|
|
||||||
"Deallocating 0x{:x} @ 0x{:x} hardware reserved memory",
|
|
||||||
adjusted_length,
|
|
||||||
adjusted_base
|
|
||||||
);
|
|
||||||
match range {
|
match range {
|
||||||
Ok(range_inner) => unsafe { HW_FREELIST.lock().deallocate(range_inner) },
|
Ok(range_inner) => unsafe { HW_FREELIST.lock().deallocate(range_inner) },
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log_error!(
|
log_error!(
|
||||||
"Failed to convert range 0x{:x} @ 0x{:x}: {}",
|
"Failed to convert range 0x{:x} @ 0x{:x} (original: 0x{:x} @ 0x{:x}): {}",
|
||||||
adjusted_length,
|
length,
|
||||||
adjusted_base,
|
base,
|
||||||
|
entry.length,
|
||||||
|
entry.base,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -170,6 +175,7 @@ pub fn log_memory() {
|
|||||||
);
|
);
|
||||||
log_trace!("Deallocating available memory...");
|
log_trace!("Deallocating available memory...");
|
||||||
let _ = deallocate_usable();
|
let _ = deallocate_usable();
|
||||||
|
log_trace!("Deallocating hardware reserved memory...");
|
||||||
let _ = deallocate_hardware();
|
let _ = deallocate_hardware();
|
||||||
let free_bytes = { FREELIST.lock().free_space() };
|
let free_bytes = { FREELIST.lock().free_space() };
|
||||||
log_info!(
|
log_info!(
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
// Copyright (c) 2025 shibedrill
|
// Copyright (c) 2025 shibedrill
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
use core::arch::asm;
|
|
||||||
use core::panic::*;
|
use core::panic::*;
|
||||||
|
|
||||||
use crate::format;
|
use crate::format;
|
||||||
|
|
||||||
use crate::{LOGGER, LogLevel};
|
use crate::{LOGGER, LogLevel};
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
@ -14,8 +12,6 @@ pub fn panic(info: &PanicInfo) -> ! {
|
|||||||
// TODO: If any userspace facilities are still working, *attempt* to flush panic info and
|
// TODO: If any userspace facilities are still working, *attempt* to flush panic info and
|
||||||
// logs to disk or whatever else. Then kill all processes and reboot.
|
// logs to disk or whatever else. Then kill all processes and reboot.
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
crate::arch::asm::nop();
|
||||||
asm!("nop");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user