comment handler NMI and PF / reduce wait in NMI loop

This commit is contained in:
2023-06-03 17:19:02 +02:00
parent d1db3570ce
commit 811179cc28
2 changed files with 14 additions and 9 deletions

View File

@@ -106,7 +106,7 @@ nmi_handler!(non_maskable, |stack| {
// wait
let mut a = 545614;
for i in 0..10_000_000_000_u128 {
for i in 0..5_000_000_000_u128 {
match i % 3 {
0 => a/= 465,
_ => a*=146564,
@@ -220,15 +220,18 @@ interrupt_error!(page, |stack| {
println!(" CS: {}", stack.inner.iret.cs);
println!(" RIP: {:>016X}", stack.inner.iret.rip);
// import for PF handling
use crate::arch::paging::PAGE_SIZE;
use crate::rmm::KernelMapper;
use rmm::PageFlags;
use rmm::VirtualAddress;
// find page of the faulting address
let aligned_addr: usize = cr2 / PAGE_SIZE * PAGE_SIZE;
println!("Aligned address: {:x?}", aligned_addr);
// Since NMI are in kernel we use the KernelMapper
// With the KernelMapper we map the page with the write flags
let mut km = KernelMapper::lock();
let km = km.get_mut().expect("pls");
let mut flags = PageFlags::new();
@@ -236,7 +239,7 @@ interrupt_error!(page, |stack| {
println!("{:?}", flags);
let _ = km.map(VirtualAddress::new(aligned_addr), flags);
// generate a random value and write it to the newmy mapped address
let mut tmp = 0_u16;
core::arch::x86_64::_rdrand16_step(&mut tmp);

View File

@@ -469,16 +469,18 @@ macro_rules! nmi_handler {
core::arch::asm!(concat!(
"
push rdx
",
// check if from kernel
"
cmp QWORD PTR [rsp + 8*2], {GDT_KERNEL_CODE}
jne first_nmi
",
// not from user space
// check nmi var
"
cmp QWORD PTR [rsp - 8], $1
je nested_nmi
",
// if nmi stack
// check if interrupted is in nmi stack
"
lea rdx, [rsp + 6*8]
cmp rdx, [rsp + 4*8]
@@ -499,7 +501,7 @@ macro_rules! nmi_handler {
cmp rdx, [rsp + 8]
ja nested_nmi_out
",
// prepare for return
// prepare iret stack for interrupted nmi
"
1:
lea rdx, [rsp - 8]
@@ -527,7 +529,7 @@ macro_rules! nmi_handler {
mov rdx, [rsp]
push $1
",
// first copy (saved)
// first copy (saved frame)
"
sub rsp, $(5*8)
@@ -535,7 +537,7 @@ macro_rules! nmi_handler {
push [rsp + 11*8]
.endr
",
//second copy
//second copy (iret frame)
"
repeat_nmi:
mov QWORD PTR [rsp + 10*8], $1