Minor refactor
This commit is contained in:
parent
1db789889c
commit
bf202a42ba
@ -1,105 +1,9 @@
|
||||
use bitflags::bitflags;
|
||||
use core::arch::asm;
|
||||
use core::{fmt, ops::Deref};
|
||||
|
||||
use crate::os::EFlags;
|
||||
|
||||
use super::VirtAddr;
|
||||
|
||||
bitflags! {
|
||||
/// The EFLAGS register. All bit patterns are valid representations for this type.
|
||||
///
|
||||
/// See https://wiki.osdev.org/CPU_Registers_x86#EFLAGS_Register
|
||||
#[repr(transparent)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
||||
pub struct EFlags: u32 {
|
||||
/// Processor feature identification flag.
|
||||
///
|
||||
/// If this flag is modifiable, the CPU supports CPUID.
|
||||
const ID = 1 << 21;
|
||||
|
||||
/// Indicates that an external, maskable interrupt is pending.
|
||||
///
|
||||
/// Used when virtual-8086 mode extensions (CR4.VME) or protected-mode virtual
|
||||
/// interrupts (CR4.PVI) are activated.
|
||||
const VIRTUAL_INTERRUPT_PENDING = 1 << 20;
|
||||
|
||||
/// Virtual image of the INTERRUPT_FLAG bit.
|
||||
///
|
||||
/// Used when virtual-8086 mode extensions (CR4.VME) or protected-mode virtual
|
||||
/// interrupts (CR4.PVI) are activated.
|
||||
const VIRTUAL_INTERRUPT = 1 << 19;
|
||||
|
||||
/// Enable automatic alignment checking if CR0.AM is set. Only works if CPL is 3.
|
||||
const ALIGNMENT_CHECK = 1 << 18;
|
||||
|
||||
/// Enable the virtual-8086 mode.
|
||||
const VIRTUAL_8086_MODE = 1 << 17;
|
||||
|
||||
/// Allows to restart an instruction following an instruction breakpoint.
|
||||
const RESUME_FLAG = 1 << 16;
|
||||
|
||||
/// Used by `iret` in hardware task switch mode to determine if current task is nested.
|
||||
const NESTED_TASK = 1 << 14;
|
||||
|
||||
/// The high bit of the I/O Privilege Level field.
|
||||
///
|
||||
/// Specifies the privilege level required for executing I/O address-space instructions.
|
||||
const IOPL_HIGH = 1 << 13;
|
||||
|
||||
/// The low bit of the I/O Privilege Level field.
|
||||
///
|
||||
/// Specifies the privilege level required for executing I/O address-space instructions.
|
||||
const IOPL_LOW = 1 << 12;
|
||||
|
||||
/// Set by hardware to indicate that the sign bit of the result of the last signed integer
|
||||
/// operation differs from the source operands.
|
||||
const OVERFLOW_FLAG = 1 << 11;
|
||||
|
||||
/// Determines the order in which strings are processed.
|
||||
const DIRECTION_FLAG = 1 << 10;
|
||||
|
||||
/// Enable interrupts.
|
||||
const INTERRUPT_FLAG = 1 << 9;
|
||||
|
||||
/// Enable single-step mode for debugging.
|
||||
const TRAP_FLAG = 1 << 8;
|
||||
|
||||
/// Set by hardware if last arithmetic operation resulted in a negative value.
|
||||
const SIGN_FLAG = 1 << 7;
|
||||
|
||||
/// Set by hardware if last arithmetic operation resulted in a zero value.
|
||||
const ZERO_FLAG = 1 << 6;
|
||||
|
||||
/// Set by hardware if last arithmetic operation generated a carry ouf of bit 3 of the
|
||||
/// result.
|
||||
const AUXILIARY_CARRY_FLAG = 1 << 4;
|
||||
|
||||
/// Set by hardware if last result has an even number of 1 bits (only for some operations).
|
||||
const PARITY_FLAG = 1 << 2;
|
||||
|
||||
/// Set by hardware if last arithmetic operation generated a carry out of the
|
||||
/// most-significant bit of the result.
|
||||
const CARRY_FLAG = 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl EFlags {
|
||||
#[inline]
|
||||
pub fn read() -> EFlags {
|
||||
EFlags::from_bits_truncate(EFlags::read_raw())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_raw() -> u32 {
|
||||
let r: u32;
|
||||
|
||||
unsafe {
|
||||
asm!("pushfd; pop {0:e}", out(reg) r, options(nomem, preserves_flags));
|
||||
}
|
||||
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type for the interrupt stack frame pushed by the CPU.
|
||||
///
|
||||
/// This type derefs to an [`InterruptStackFrameValue`], which allows reading the actual values.
|
||||
|
@ -12,8 +12,8 @@ use spin::Mutex;
|
||||
use drivers::{pic::PICDriver, vga::Vga13h};
|
||||
use idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use os::{
|
||||
thunk::ThunkData,
|
||||
util::{sti, without_interrupts},
|
||||
ThunkData,
|
||||
};
|
||||
use tetrisboard::{FallingTetromino, TetrisBoard};
|
||||
|
||||
@ -148,8 +148,7 @@ pub unsafe extern "C" fn start(thunk10: extern "C" fn()) -> ! {
|
||||
pic.init();
|
||||
}
|
||||
|
||||
// We're ready for interrupts,
|
||||
// enable them
|
||||
// We're ready for interrupts, enable them
|
||||
sti();
|
||||
|
||||
let mut last_t = 0;
|
||||
|
98
tetros/src/os/eflags.rs
Normal file
98
tetros/src/os/eflags.rs
Normal file
@ -0,0 +1,98 @@
|
||||
use bitflags::bitflags;
|
||||
use core::arch::asm;
|
||||
|
||||
bitflags! {
|
||||
/// The EFLAGS register. All bit patterns are valid representations for this type.
|
||||
///
|
||||
/// See https://wiki.osdev.org/CPU_Registers_x86#EFLAGS_Register
|
||||
#[repr(transparent)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
||||
pub struct EFlags: u32 {
|
||||
/// Processor feature identification flag.
|
||||
///
|
||||
/// If this flag is modifiable, the CPU supports CPUID.
|
||||
const ID = 1 << 21;
|
||||
|
||||
/// Indicates that an external, maskable interrupt is pending.
|
||||
///
|
||||
/// Used when virtual-8086 mode extensions (CR4.VME) or protected-mode virtual
|
||||
/// interrupts (CR4.PVI) are activated.
|
||||
const VIRTUAL_INTERRUPT_PENDING = 1 << 20;
|
||||
|
||||
/// Virtual image of the INTERRUPT_FLAG bit.
|
||||
///
|
||||
/// Used when virtual-8086 mode extensions (CR4.VME) or protected-mode virtual
|
||||
/// interrupts (CR4.PVI) are activated.
|
||||
const VIRTUAL_INTERRUPT = 1 << 19;
|
||||
|
||||
/// Enable automatic alignment checking if CR0.AM is set. Only works if CPL is 3.
|
||||
const ALIGNMENT_CHECK = 1 << 18;
|
||||
|
||||
/// Enable the virtual-8086 mode.
|
||||
const VIRTUAL_8086_MODE = 1 << 17;
|
||||
|
||||
/// Allows to restart an instruction following an instruction breakpoint.
|
||||
const RESUME_FLAG = 1 << 16;
|
||||
|
||||
/// Used by `iret` in hardware task switch mode to determine if current task is nested.
|
||||
const NESTED_TASK = 1 << 14;
|
||||
|
||||
/// The high bit of the I/O Privilege Level field.
|
||||
///
|
||||
/// Specifies the privilege level required for executing I/O address-space instructions.
|
||||
const IOPL_HIGH = 1 << 13;
|
||||
|
||||
/// The low bit of the I/O Privilege Level field.
|
||||
///
|
||||
/// Specifies the privilege level required for executing I/O address-space instructions.
|
||||
const IOPL_LOW = 1 << 12;
|
||||
|
||||
/// Set by hardware to indicate that the sign bit of the result of the last signed integer
|
||||
/// operation differs from the source operands.
|
||||
const OVERFLOW_FLAG = 1 << 11;
|
||||
|
||||
/// Determines the order in which strings are processed.
|
||||
const DIRECTION_FLAG = 1 << 10;
|
||||
|
||||
/// Enable interrupts.
|
||||
const INTERRUPT_FLAG = 1 << 9;
|
||||
|
||||
/// Enable single-step mode for debugging.
|
||||
const TRAP_FLAG = 1 << 8;
|
||||
|
||||
/// Set by hardware if last arithmetic operation resulted in a negative value.
|
||||
const SIGN_FLAG = 1 << 7;
|
||||
|
||||
/// Set by hardware if last arithmetic operation resulted in a zero value.
|
||||
const ZERO_FLAG = 1 << 6;
|
||||
|
||||
/// Set by hardware if last arithmetic operation generated a carry ouf of bit 3 of the
|
||||
/// result.
|
||||
const AUXILIARY_CARRY_FLAG = 1 << 4;
|
||||
|
||||
/// Set by hardware if last result has an even number of 1 bits (only for some operations).
|
||||
const PARITY_FLAG = 1 << 2;
|
||||
|
||||
/// Set by hardware if last arithmetic operation generated a carry out of the
|
||||
/// most-significant bit of the result.
|
||||
const CARRY_FLAG = 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl EFlags {
|
||||
#[inline]
|
||||
pub fn read() -> EFlags {
|
||||
EFlags::from_bits_truncate(EFlags::read_raw())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_raw() -> u32 {
|
||||
let r: u32;
|
||||
|
||||
unsafe {
|
||||
asm!("pushfd; pop {0:e}", out(reg) r, options(nomem, preserves_flags));
|
||||
}
|
||||
|
||||
r
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
pub mod thunk;
|
||||
mod thunk;
|
||||
pub use thunk::*;
|
||||
|
||||
mod eflags;
|
||||
pub use eflags::*;
|
||||
|
||||
pub mod util;
|
||||
|
||||
#[macro_use]
|
||||
pub mod panic;
|
||||
|
||||
const THUNK_STACK_ADDR: usize = 0x7C00; // Grows downwards
|
||||
|
@ -1,6 +1,7 @@
|
||||
use core::ptr;
|
||||
|
||||
use super::THUNK_STACK_ADDR;
|
||||
// Grows downwards
|
||||
const THUNK_STACK_ADDR: usize = 0x7C00;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[repr(C, packed)]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use core::arch::asm;
|
||||
|
||||
use crate::idt::EFlags;
|
||||
use super::EFlags;
|
||||
|
||||
/// Disable interrupts
|
||||
#[inline]
|
||||
|
Loading…
x
Reference in New Issue
Block a user