@ -66,6 +66,7 @@
use super ::consts ::* ;
use super ::consts ::* ;
use super ::TrapFrame ;
use super ::TrapFrame ;
use log ::* ;
global_asm! ( include_str! ( " trap.asm " ) ) ;
global_asm! ( include_str! ( " trap.asm " ) ) ;
global_asm! ( include_str! ( " vector.asm " ) ) ;
global_asm! ( include_str! ( " vector.asm " ) ) ;
@ -82,7 +83,7 @@ pub extern fn rust_trap(tf: &mut TrapFrame) {
let irq = tf . trap_num as u8 - T_IRQ0 ;
let irq = tf . trap_num as u8 - T_IRQ0 ;
super ::ack ( irq ) ; // must ack before switching
super ::ack ( irq ) ; // must ack before switching
match irq {
match irq {
IRQ_TIMER = > ::trap ::timer ( ) ,
IRQ_TIMER = > crate ::trap ::timer ( ) ,
IRQ_KBD = > keyboard ( ) ,
IRQ_KBD = > keyboard ( ) ,
IRQ_COM1 = > com1 ( ) ,
IRQ_COM1 = > com1 ( ) ,
IRQ_COM2 = > com2 ( ) ,
IRQ_COM2 = > com2 ( ) ,
@ -112,7 +113,7 @@ fn page_fault(tf: &mut TrapFrame) {
let addr : usize ;
let addr : usize ;
unsafe { asm! ( " mov %cr2, $0 " : " =r " ( addr ) ) ; }
unsafe { asm! ( " mov %cr2, $0 " : " =r " ( addr ) ) ; }
if ::memory ::page_fault_handler ( addr ) {
if crate ::memory ::page_fault_handler ( addr ) {
return ;
return ;
}
}
error! ( " \n EXCEPTION: Page Fault @ {:#x}, code: {:#x} " , addr , tf . error_code ) ;
error! ( " \n EXCEPTION: Page Fault @ {:#x}, code: {:#x} " , addr , tf . error_code ) ;
@ -120,21 +121,21 @@ fn page_fault(tf: &mut TrapFrame) {
}
}
fn keyboard ( ) {
fn keyboard ( ) {
use arch ::driver ::keyboard ;
use crate ::arch ::driver ::keyboard ;
trace! ( " \n Interupt: Keyboard " ) ;
trace! ( " \n Interupt: Keyboard " ) ;
if let Some ( c ) = keyboard ::receive ( ) {
if let Some ( c ) = keyboard ::receive ( ) {
::trap ::serial ( c ) ;
crate ::trap ::serial ( c ) ;
}
}
}
}
fn com1 ( ) {
fn com1 ( ) {
use arch ::driver ::serial ::* ;
use crate ::arch ::driver ::serial ::* ;
trace! ( " \n Interupt: COM1 " ) ;
trace! ( " \n Interupt: COM1 " ) ;
::trap ::serial ( COM1 . lock ( ) . receive ( ) as char ) ;
crate ::trap ::serial ( COM1 . lock ( ) . receive ( ) as char ) ;
}
}
fn com2 ( ) {
fn com2 ( ) {
use arch ::driver ::serial ::* ;
use crate ::arch ::driver ::serial ::* ;
trace! ( " \n Interupt: COM2 " ) ;
trace! ( " \n Interupt: COM2 " ) ;
COM2 . lock ( ) . receive ( ) ;
COM2 . lock ( ) . receive ( ) ;
}
}
@ -144,7 +145,7 @@ fn ide() {
}
}
fn to_user ( tf : & mut TrapFrame ) {
fn to_user ( tf : & mut TrapFrame ) {
use arch ::gdt ;
use crate ::arch ::gdt ;
info! ( " \n Interupt: To User " ) ;
info! ( " \n Interupt: To User " ) ;
tf . cs = gdt ::UCODE_SELECTOR . 0 as usize ;
tf . cs = gdt ::UCODE_SELECTOR . 0 as usize ;
tf . ss = gdt ::UDATA_SELECTOR . 0 as usize ;
tf . ss = gdt ::UDATA_SELECTOR . 0 as usize ;
@ -152,7 +153,7 @@ fn to_user(tf: &mut TrapFrame) {
}
}
fn to_kernel ( tf : & mut TrapFrame ) {
fn to_kernel ( tf : & mut TrapFrame ) {
use arch ::gdt ;
use crate ::arch ::gdt ;
info! ( " \n Interupt: To Kernel " ) ;
info! ( " \n Interupt: To Kernel " ) ;
tf . cs = gdt ::KCODE_SELECTOR . 0 as usize ;
tf . cs = gdt ::KCODE_SELECTOR . 0 as usize ;
tf . ss = gdt ::KDATA_SELECTOR . 0 as usize ;
tf . ss = gdt ::KDATA_SELECTOR . 0 as usize ;
@ -160,25 +161,23 @@ fn to_kernel(tf: &mut TrapFrame) {
fn syscall ( tf : & mut TrapFrame ) {
fn syscall ( tf : & mut TrapFrame ) {
trace! ( " \n Interupt: Syscall {:#x?} " , tf . rax ) ;
trace! ( " \n Interupt: Syscall {:#x?} " , tf . rax ) ;
use syscall ::syscall ;
let ret = crate ::syscall ::syscall ( tf . rax , [ tf . rdi , tf . rsi , tf . rdx , tf . rcx , tf . r8 , tf . r9 ] , tf ) ;
let ret = syscall ( tf . rax , [ tf . rdi , tf . rsi , tf . rdx , tf . rcx , tf . r8 , tf . r9 ] , tf ) ;
tf . rax = ret as usize ;
tf . rax = ret as usize ;
}
}
fn syscall32 ( tf : & mut TrapFrame ) {
fn syscall32 ( tf : & mut TrapFrame ) {
trace! ( " \n Interupt: Syscall {:#x?} " , tf . rax ) ;
trace! ( " \n Interupt: Syscall {:#x?} " , tf . rax ) ;
use syscall ::syscall ;
let ret = crate ::syscall ::syscall ( tf . rax , [ tf . rdx , tf . rcx , tf . rbx , tf . rdi , tf . rsi , 0 ] , tf ) ;
let ret = syscall ( tf . rax , [ tf . rdx , tf . rcx , tf . rbx , tf . rdi , tf . rsi , 0 ] , tf ) ;
tf . rax = ret as usize ;
tf . rax = ret as usize ;
}
}
fn error ( tf : & TrapFrame ) {
fn error ( tf : & TrapFrame ) {
::trap ::error ( tf ) ;
crate ::trap ::error ( tf ) ;
}
}
#[ no_mangle ]
#[ no_mangle ]
pub extern fn set_return_rsp ( tf : & TrapFrame ) {
pub extern fn set_return_rsp ( tf : & TrapFrame ) {
use arch ::gdt ::Cpu ;
use crate ::arch ::gdt ::Cpu ;
use core ::mem ::size_of ;
use core ::mem ::size_of ;
if tf . cs & 0x3 = = 3 {
if tf . cs & 0x3 = = 3 {
Cpu ::current ( ) . set_ring0_rsp ( tf as * const _ as usize + size_of ::< TrapFrame > ( ) ) ;
Cpu ::current ( ) . set_ring0_rsp ( tf as * const _ as usize + size_of ::< TrapFrame > ( ) ) ;