Skip to content

Commit

Permalink
Update to latest nightly and fix various small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockna committed Aug 19, 2024
1 parent 6972a34 commit 3c0bb4e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
42 changes: 21 additions & 21 deletions build/targets/x86_64.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"disable-redzone": true,
"panic-strategy": "abort",
"features": "-mmx,-sse,+soft-float",
"code-model": "kernel",
"pre-link-args": {
"ld.lld": [
"--gc-sections",
"--script=./build/linker-scripts/kernel.ld"
]
}
}
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"disable-redzone": true,
"panic-strategy": "abort",
"features": "-mmx,-sse,+soft-float",
"code-model": "kernel",
"pre-link-args": {
"ld.lld": [
"--gc-sections",
"--script=./build/linker-scripts/kernel.ld"
]
}
}
1 change: 0 additions & 1 deletion crates/libxernel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![no_std]
#![feature(inline_const)]
#![allow(unused)]

pub mod boot;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2024-01-01
nightly
22 changes: 11 additions & 11 deletions xernel/kernel/src/arch/amd64/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ pub fn init() {
let mut tss = TaskStateSegment::new();
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
let stack_start = VirtAddr::from_ptr(unsafe { addr_of!(BSP_IST_STACK) });
stack_start + IST_STACK_SIZE
stack_start + IST_STACK_SIZE as u64
};

TSS.set_once(tss);

let mut gdt = GlobalDescriptorTable::new();

let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
let data_selector = gdt.add_entry(Descriptor::kernel_data_segment());
let code_selector = gdt.append(Descriptor::kernel_code_segment());
let data_selector = gdt.append(Descriptor::kernel_data_segment());

// let kernel_data_flags = DescriptorFlags::USER_SEGMENT | DescriptorFlags::PRESENT | DescriptorFlags::WRITABLE;
// let data_selector = gdt.add_entry(Descriptor::UserSegment(kernel_data_flags.bits()));

// System segment descriptors (which the TSS descriptor is) are 16-bytes and take up 2 slots in the GDT
// This results in user code having index 5, user data index 6
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
let user_data_selector = gdt.add_entry(Descriptor::user_data_segment());
let user_code_selector = gdt.add_entry(Descriptor::user_code_segment());
let tss_selector = gdt.append(Descriptor::tss_segment(&TSS));
let user_data_selector = gdt.append(Descriptor::user_data_segment());
let user_code_selector = gdt.append(Descriptor::user_code_segment());
GDT_BSP.set_once((
gdt,
Selectors {
Expand All @@ -85,10 +85,10 @@ pub fn init_ap(ap_id: usize) {
let mut gdt_ap = GDT_AP.lock();

let gdt: &'static mut GlobalDescriptorTable = Box::leak(Box::new(GlobalDescriptorTable::new()));
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
let data_selector = gdt.add_entry(Descriptor::kernel_data_segment());
let user_data_selector = gdt.add_entry(Descriptor::user_data_segment());
let user_code_selector = gdt.add_entry(Descriptor::user_code_segment());
let code_selector = gdt.append(Descriptor::kernel_code_segment());
let data_selector = gdt.append(Descriptor::kernel_data_segment());
let user_data_selector = gdt.append(Descriptor::user_data_segment());
let user_code_selector = gdt.append(Descriptor::user_code_segment());

let mut boxed_tss = Box::new(TaskStateSegment::new());

Expand All @@ -97,7 +97,7 @@ pub fn init_ap(ap_id: usize) {
unsafe { VirtAddr::from_ptr(ist0.add(IST_STACK_SIZE)) };

let tss: &'static mut TaskStateSegment = Box::leak(boxed_tss);
let tss_selector = gdt.add_entry(Descriptor::tss_segment(tss));
let tss_selector = gdt.append(Descriptor::tss_segment(tss));

gdt_ap.push(Gdt {
gdt,
Expand Down
4 changes: 2 additions & 2 deletions xernel/kernel/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ pub fn register_cpu() {
}));

// use KERNEL_GS_BASE to store the cpu_data
unsafe { wrmsr(KERNEL_GS_BASE, (cpu_data as *const Cpu).expose_addr() as u64) }
unsafe { wrmsr(KERNEL_GS_BASE, (cpu_data as *const Cpu).expose_provenance() as u64) }
}

pub fn current_cpu() -> Pin<&'static Cpu> {
if !CPU_COUNT.is_completed() || *CPU_COUNT != CPU_ID_COUNTER.load(Ordering::SeqCst) {
panic!("current_cpu called before all cpus registered");
}

unsafe { Pin::new_unchecked(&*core::ptr::from_exposed_addr(rdmsr(KERNEL_GS_BASE) as usize)) }
unsafe { Pin::new_unchecked(&*core::ptr::with_exposed_provenance(rdmsr(KERNEL_GS_BASE) as usize)) }
}

pub fn current_thread() -> Arc<Thread> {
Expand Down
1 change: 0 additions & 1 deletion xernel/kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_main]
#![feature(abi_x86_interrupt)]
#![feature(naked_functions)]
#![feature(exclusive_range_pattern)]
#![feature(let_chains)]
#![feature(strict_provenance)]
#![feature(exposed_provenance)]
Expand Down
6 changes: 3 additions & 3 deletions xernel/kernel/src/mem/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct VmEntry {

impl VmEntry {
pub fn end(&self) -> VirtAddr {
self.start + self.length
self.start + self.length as u64
}

pub fn unmap(&self) {
Expand Down Expand Up @@ -72,8 +72,8 @@ impl Vm {
pub fn is_available(&self, start: VirtAddr, length: usize) -> bool {
!self.entries.iter().any(|(_, entry)| {
entry.start < start && entry.end() + Size4KiB::SIZE > start
|| start + length + Size4KiB::SIZE > entry.start
&& (start + length + Size4KiB::SIZE).as_u64() < Size4KiB::SIZE
|| start + length as u64 + Size4KiB::SIZE > entry.start
&& (start + length as u64 + Size4KiB::SIZE).as_u64() < Size4KiB::SIZE
})
}

Expand Down

0 comments on commit 3c0bb4e

Please sign in to comment.