Move x86 specific code out of main.rs
This commit is contained in:
parent
c84d3ae273
commit
383642e4d1
@ -8,7 +8,7 @@ env_scripts = [
|
||||
set_env LIMINEBIN "BOOTX64.EFI"
|
||||
else if eq ${TARGET} "aarch64-unknown-none"
|
||||
set_env ARCH "aarch64"
|
||||
set_env QEMUCOMMAND "qemu-system-aarch64"
|
||||
set_env QEMUCOMMAND "qemu-system-aarch64 -M virt -m 4G -bios build/aarch64/u-boot.bin"
|
||||
set_env LIMINEBIN "BOOTAA64.EFI"
|
||||
else if eq ${TARGET} "riscv64gc-unknown-none-elf"
|
||||
set_env ARCH "riscv64"
|
||||
|
||||
@ -115,13 +115,6 @@ Gila ~~currently supports~~ aims to support four different CPU architectures:
|
||||
It currently only builds on `x86_64`, and will continue to only support it
|
||||
until I can implement support for important features in other architectures.
|
||||
|
||||
All these architectures are supported by Limine, and the appropriate backends
|
||||
are present in the Makefile to compile and build bootable images for each.
|
||||
While Limine (the bootloader) and rustc also support `IA32` (also referred to
|
||||
as `i686`), the Limine boot protocol cannot work on a 32-bit architecture, as
|
||||
it relies heavily on 64-bit pointers. Compilation will fail if a build for an
|
||||
unsupported target is attempted.
|
||||
|
||||
EFI boot is presently supported, at least on `x86_64`. No features depend on
|
||||
EFI, and as such, the `uefi` feature can be safely disabled when booting
|
||||
through BIOS.
|
||||
|
||||
@ -62,25 +62,7 @@ Servers can perform many different tasks, such as:
|
||||
|
||||
Servers do one thing each, and one thing well. If a server needs to do a lot of
|
||||
the same thing, it should fork into several processes, so inter-process
|
||||
isolation can improve security. For example, if there are multiple of the same
|
||||
device in the system, the driver server should fork for each instance. This
|
||||
ensures that any one server can crash or be compromised without crashing or
|
||||
compromising all the others.
|
||||
|
||||
Another scenario might involve running separate login server processes for
|
||||
every single user on the system. Running all these servers in one process
|
||||
introduces a serious security risk, as any compromise or failure of the login
|
||||
server could result in security failures, resource exhaustion, denial of
|
||||
service, or other undesirable events, affecting all other users on the system.
|
||||
|
||||
### Boot Security
|
||||
|
||||
Since Gila is just a kernel, the complexity of its userspace is up to the
|
||||
operating system developer. The developer/integrator may choose to include some
|
||||
or all of their software in the initramfs, rather than store it on a disk. By
|
||||
properly hashing all boot modules + the config file, embedding the config hash
|
||||
in Limine, and enabling Secure Boot, a chain of trust rooted in the hardware
|
||||
can be established.
|
||||
isolation can improve security.
|
||||
|
||||
### Userspace Security Model
|
||||
|
||||
@ -92,22 +74,6 @@ processes, aside from very limited functionality regarding system calls, to
|
||||
enforce the Biba security model at the boundary between kernelspace and
|
||||
userspace.
|
||||
|
||||
### Namespaces
|
||||
|
||||
Namespaces will be a critical part of how process isolation works. Details are
|
||||
still TBD, but I want each process to start in its own empty namespace, unless
|
||||
the parent process specifies that the child should share the parent's
|
||||
namespace. As device drivers and protocol drivers are simply processes, and
|
||||
subject to the same namespace rules as any other process, the kernel can
|
||||
enforce access to any kind of function or resource for any process arbitrarily.
|
||||
The same could eventually go for virtual machines.
|
||||
|
||||
Namespaces are a way by which the resources available to a process are isolated
|
||||
and controlled. Mainly, this affects inter-process communication (IPC) as it's
|
||||
the primary method processes will use to do useful things, but it will also
|
||||
affect shared memory regions. A process cannot establish IPC unless it is part
|
||||
of some namespace the target process is also part of.
|
||||
|
||||
### Capability based MAC
|
||||
|
||||
Gila has no concept of ambient authority. Resource access is not governed
|
||||
@ -117,10 +83,14 @@ cannot defer a resource access to a process which already has the capability,
|
||||
it must *copy* or *transfer* its own capability to that resource, to the
|
||||
process which will access it.
|
||||
|
||||
Namespaces will be enforced using capabilities, where a process holds a
|
||||
capability object representing the namespace it is in, and the rights it has
|
||||
within that namespace. By default, processes have no such capabilities, but
|
||||
a parent process can choose to copy one of its own and delegate it to the
|
||||
child process.
|
||||
Gila initializes all capabilities on startup, before handing them over to
|
||||
the userboot process. This process can derive additional capabilities from
|
||||
these initial capabilities, and distribute copies while maintaining the
|
||||
initial capability. Thus, upon revocation by that process, all derived
|
||||
capabilities are revoked as well, even ones held by other processes.
|
||||
|
||||
Details are still a work in progress.
|
||||
Capabilities are stored in memory regions associated with, but not mapped into
|
||||
the address spaces of, the processes that control them. They are managed
|
||||
through a tree-like structure, so the processes are forced to account for the
|
||||
memory their capabilities use by using their own capabilities as storage
|
||||
spaces.
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::arch::x86_64::gdt::SELECTORS;
|
||||
use crate::{LOGGER, SERIAL_3F8, format, log_info, log_trace};
|
||||
use crate::{LOGGER, format, log_info, log_trace};
|
||||
use crate::{LogLevel, log_error};
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::PhysAddr;
|
||||
@ -73,7 +73,6 @@ extern "x86-interrupt" fn double_fault(info: InterruptStackFrame, _: u64) -> ! {
|
||||
|
||||
#[allow(dead_code)]
|
||||
extern "x86-interrupt" fn page_fault(info: InterruptStackFrame, errcode: PageFaultErrorCode) {
|
||||
SERIAL_3F8.lock().log_writeln("Page fault, baby!");
|
||||
let page_fault_addr = x86_64::registers::control::Cr2::read();
|
||||
log_trace!(
|
||||
"Fault: Page fault with {}, error code 0b{:b}",
|
||||
|
||||
@ -3,18 +3,58 @@ use x86_64::{
|
||||
registers::{rflags::RFlags, segmentation::Segment},
|
||||
structures::idt::InterruptStackFrameValue,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use spin::mutex::Mutex;
|
||||
|
||||
use crate::{
|
||||
arch::{
|
||||
asm::ltr,
|
||||
x86_64::{gdt::SELECTORS, interrupts::IDT},
|
||||
x86_64::{
|
||||
gdt::SELECTORS,
|
||||
interrupts::IDT,
|
||||
serial::SerialPort,
|
||||
},
|
||||
},
|
||||
log::{LOGGER, LogLevel},
|
||||
log_info,
|
||||
log_trace,
|
||||
memory::alloc::format,
|
||||
memory::alloc::vec,
|
||||
memory::alloc::boxed::Box,
|
||||
boot::params::PARAMS,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SERIAL_3F8: Mutex<SerialPort> = Mutex::new(
|
||||
SerialPort::try_from_port(0x3f8).expect("Could not create port")
|
||||
);
|
||||
}
|
||||
|
||||
pub fn init() -> Result<(), ()> {
|
||||
|
||||
// Set up logging level from params
|
||||
// Nothing we can do here if this fails since no log subscribers are initialized yet
|
||||
if let Some(level) = PARAMS.get("-loglevel")
|
||||
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
|
||||
{
|
||||
LOGGER.lock().level = parsed_level;
|
||||
}
|
||||
// Add subscribers to logger
|
||||
if let Some(device) = PARAMS.get("-logdev") {
|
||||
let log_device_list: vec::Vec<&str> = device.split(',').collect();
|
||||
if log_device_list.contains(&"display") {
|
||||
// Append display console to log subs
|
||||
}
|
||||
if log_device_list.contains(&"serial") {
|
||||
// TODO: Set up device discovery
|
||||
let serial_logger = |msg: &str| SERIAL_3F8.lock().log_writeln(msg);
|
||||
LOGGER.lock().add_device(Box::new(serial_logger));
|
||||
}
|
||||
log_trace!("Configured kernel logging devices");
|
||||
let log_level = LOGGER.lock().level;
|
||||
log_info!("Log level: {:?}", log_level);
|
||||
}
|
||||
|
||||
// Load IDT
|
||||
IDT.load();
|
||||
log_info!("IDT loaded!");
|
||||
|
||||
@ -5,7 +5,7 @@ use core::pin;
|
||||
#[repr(C, packed)]
|
||||
pub struct Capability<'a> {
|
||||
resource: ResourceIdentifier<'a>, // Can point to a capability of any type
|
||||
child: pin::Pin<&'a mut Capability<'a>>, // Derived capability, 1 byte
|
||||
child: pin::Pin<&'a mut Capability<'a>>, // Derived capability, 1 byte
|
||||
parent: pin::Pin<&'a mut Capability<'a>>, // Parent capability, 1 byte
|
||||
}
|
||||
|
||||
@ -18,10 +18,14 @@ pub enum ResourceIdentifier<'a> {
|
||||
Null,
|
||||
}
|
||||
|
||||
// TODO: Figure out representation for kernel objects
|
||||
// We can figure this out, all we need is a way to opaquely
|
||||
// reference a page using a fat pointer.
|
||||
|
||||
pub struct PageCap {
|
||||
addr: u64,
|
||||
}
|
||||
|
||||
pub struct CapabilityBlock<'a> {
|
||||
caps: [Capability<'a>; 128],
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,24 +17,15 @@ mod panic;
|
||||
mod process;
|
||||
mod util;
|
||||
|
||||
use arch::x86_64::serial::SerialPort;
|
||||
use boot::{BASE_REVISION, params};
|
||||
use constants::*;
|
||||
use log::*;
|
||||
use memory::alloc::{boxed::Box, format, vec};
|
||||
use memory::alloc::format;
|
||||
use params::*;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use spin::mutex::Mutex;
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
use crate::{arch::x86_64::gdt, boot::modules::MODULE_RESPONSE};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SERIAL_3F8: Mutex<SerialPort> = Mutex::new(
|
||||
arch::x86_64::serial::SerialPort::try_from_port(0x3f8).expect("Could not create port")
|
||||
);
|
||||
}
|
||||
use crate::boot::modules::MODULE_RESPONSE;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn main() -> ! {
|
||||
@ -45,29 +36,6 @@ unsafe extern "C" fn main() -> ! {
|
||||
// Assert supported bootloader version
|
||||
assert!(BASE_REVISION.is_supported());
|
||||
|
||||
// Set up logging level from params
|
||||
// Nothing we can do here if this fails since no log subscribers are initialized yet
|
||||
if let Some(level) = PARAMS.get("-loglevel")
|
||||
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
|
||||
{
|
||||
LOGGER.lock().level = parsed_level;
|
||||
}
|
||||
// Add subscribers to logger
|
||||
if let Some(device) = PARAMS.get("-logdev") {
|
||||
let log_device_list: vec::Vec<&str> = device.split(',').collect();
|
||||
if log_device_list.contains(&"display") {
|
||||
// Append display console to log subs
|
||||
}
|
||||
if log_device_list.contains(&"serial") {
|
||||
// TODO: Set up device discovery
|
||||
let serial_logger = |msg: &str| SERIAL_3F8.lock().log_writeln(msg);
|
||||
LOGGER.lock().add_device(Box::new(serial_logger));
|
||||
}
|
||||
log_trace!("Configured kernel logging devices");
|
||||
let log_level = LOGGER.lock().level;
|
||||
log_info!("Log level: {:?}", log_level);
|
||||
}
|
||||
|
||||
// END OF CRITICAL AREA
|
||||
// Fallible code can be placed below this comment
|
||||
|
||||
@ -80,16 +48,6 @@ unsafe extern "C" fn main() -> ! {
|
||||
EXECUTABLE_FILE_RESPONSE.executable_file().path(),
|
||||
EXECUTABLE_FILE_RESPONSE.executable_file().cmdline()
|
||||
);
|
||||
|
||||
// Branding
|
||||
for line in ASCII_LOGO {
|
||||
let mut locked = SERIAL_3F8.lock();
|
||||
locked.log_write("\t\t");
|
||||
locked.log_writeln(line);
|
||||
}
|
||||
SERIAL_3F8
|
||||
.lock()
|
||||
.log_writeln("\tWelcome to the Gila microkernel!\n");
|
||||
log_info!("Booting gila version {}", kernel_version_string());
|
||||
|
||||
log_info!("Trans rights!");
|
||||
@ -99,7 +57,6 @@ unsafe extern "C" fn main() -> ! {
|
||||
boot::modules::log_modules();
|
||||
memory::log_memory();
|
||||
memory::log_address();
|
||||
gdt::dump_gdt();
|
||||
|
||||
if let Some(modules_list) = *MODULE_RESPONSE
|
||||
&& modules_list.modules()[0].path().ends_with("/userboot.bin")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user