1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

Added kernel support for floating point registers.

This commit is contained in:
Stephen Marz 2020-05-15 13:01:57 -04:00
parent c649947707
commit 3793ad1e87
3 changed files with 75 additions and 3 deletions

View File

@ -96,7 +96,7 @@ _start:
sub sp, sp, t0 sub sp, sp, t0
# The parked harts will be put into machine mode with interrupts enabled. # The parked harts will be put into machine mode with interrupts enabled.
li t0, 0b11 << 11 | (1 << 7) li t0, 0b11 << 11 | (1 << 7) | (1 << 13)
csrw mstatus, t0 csrw mstatus, t0
# Allow for MSIP (Software interrupt). We will write the MSIP from hart #0 to # Allow for MSIP (Software interrupt). We will write the MSIP from hart #0 to
# awaken these parked harts. # awaken these parked harts.

View File

@ -54,11 +54,24 @@ m_trap_vector:
# Restore the kernel trap frame into mscratch # Restore the kernel trap frame into mscratch
csrw mscratch, t5 csrw mscratch, t5
# csrw mie, zero
csrr t1, mstatus
srli t0, t1, 13
andi t0, t0, 3
beqz t0, 1f
# Save floating point registers
.set i, 0
.rept 32
save_fp %i, t5
.set i, i+1
.endr
1:
# Get ready to go into Rust (trap.rs) # Get ready to go into Rust (trap.rs)
# We don't want to write into the user's stack or whomever # We don't want to write into the user's stack or whomever
# messed with us here. # messed with us here.
# csrw mie, zero # csrw mie, zero
csrr a0, mepc csrr a0, mepc
sd a0, 520(t5) sd a0, 520(t5)
csrr a1, mtval csrr a1, mtval
@ -78,6 +91,17 @@ m_trap_vector:
# Now load the trap frame back into t6 # Now load the trap frame back into t6
csrr t6, mscratch csrr t6, mscratch
csrr t1, mstatus
srli t0, t1, 13
andi t0, t0, 3
beqz t0, 1f
.set i, 0
.rept 32
load_fp %i
.set i, i+1
.endr
1:
# Restore all GP registers # Restore all GP registers
.set i, 1 .set i, 1
.rept 31 .rept 31
@ -108,7 +132,7 @@ switch_to_user:
# 1 << 7 is MPIE # 1 << 7 is MPIE
# Since user mode is 00, we don't need to set anything # Since user mode is 00, we don't need to set anything
# in MPP (bits 12:11) # in MPP (bits 12:11)
li t0, 1 << 7 | 1 << 5 li t0, 1 << 7 | 1 << 5 | 1 << 13
# Combine enable bits with mode bits. # Combine enable bits with mode bits.
slli a3, a3, 11 slli a3, a3, 11
or t0, t0, a3 or t0, t0, a3
@ -127,6 +151,17 @@ switch_to_user:
# A0 is the context frame, so we need to reload it back # A0 is the context frame, so we need to reload it back
# and mret so we can start running the program. # and mret so we can start running the program.
mv t6, a0 mv t6, a0
csrr t1, mstatus
srli t0, t1, 13
andi t0, t0, 3
beqz t0, 1f
.set i, 0
.rept 32
load_fp %i
.set i, i+1
.endr
1:
.set i, 1 .set i, 1
.rept 31 .rept 31
load_gp %i, t6 load_gp %i, t6

View File

@ -63,6 +63,43 @@ pub enum Registers {
T6 T6
} }
// Floating point registers
#[repr(usize)]
pub enum FRegisters {
Ft0,
Ft1,
Ft2,
Ft3,
Ft4,
Ft5,
Ft6,
Ft7,
Fs0,
Fs1,
Fa0, /* 10 */
Fa1,
Fa2,
Fa3,
Fa4,
Fa5,
Fa6,
Fa7,
Fs2,
Fs3,
Fs4, /* 20 */
Fs5,
Fs6,
Fs7,
Fs8,
Fs9,
Fs10,
Fs11,
Ft8,
Ft9,
Ft10, /* 30 */
Ft11
}
/// The trap frame is set into a structure /// The trap frame is set into a structure
/// and packed into each hart's mscratch register. /// and packed into each hart's mscratch register.
/// This allows for quick reference and full /// This allows for quick reference and full