mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-23 08:26:17 +04:00
Basic syscall
This commit is contained in:
parent
09147732bc
commit
7cdfb9e6e2
@ -4,7 +4,7 @@
|
|||||||
/// http://www.intel.com/design/chipsets/datashts/29056601.pdf
|
/// http://www.intel.com/design/chipsets/datashts/29056601.pdf
|
||||||
/// See also picirq.c.
|
/// See also picirq.c.
|
||||||
|
|
||||||
use syscall::io::{Io, Mmio};
|
use redox_syscall::io::{Io, Mmio};
|
||||||
use bit_field::BitField;
|
use bit_field::BitField;
|
||||||
use arch::interrupt::consts::T_IRQ0;
|
use arch::interrupt::consts::T_IRQ0;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Copy from Redox
|
// Copy from Redox
|
||||||
|
|
||||||
use syscall::io::*;
|
use redox_syscall::io::*;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
|
||||||
static MASTER: Mutex<Pic> = Mutex::new(Pic::new(0x20));
|
static MASTER: Mutex<Pic> = Mutex::new(Pic::new(0x20));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use syscall::io::{Io, Pio};
|
use redox_syscall::io::{Io, Pio};
|
||||||
|
|
||||||
static mut PIT: Pit = Pit::new(0x40);
|
static mut PIT: Pit = Pit::new(0x40);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use syscall::io::{Io, Pio, Mmio, ReadOnly};
|
use redox_syscall::io::{Io, Pio, Mmio, ReadOnly};
|
||||||
|
|
||||||
pub static COM1: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
|
pub static COM1: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
|
||||||
pub static COM2: Mutex<Serial> = Mutex::new(Serial::new(0x2F8));
|
pub static COM2: Mutex<Serial> = Mutex::new(Serial::new(0x2F8));
|
||||||
|
@ -26,6 +26,7 @@ pub const IRQ_COM1 : u8 = 4;
|
|||||||
pub const IRQ_IDE : u8 = 14;
|
pub const IRQ_IDE : u8 = 14;
|
||||||
pub const IRQ_ERROR : u8 = 19;
|
pub const IRQ_ERROR : u8 = 19;
|
||||||
pub const IRQ_SPURIOUS : u8 = 31;
|
pub const IRQ_SPURIOUS : u8 = 31;
|
||||||
pub const T_SYSCALL : u8 = 0x80; // SYSCALL, ONLY FOR THIS PROJ
|
pub const T_SYSCALL: u8 = 0x40;
|
||||||
|
// SYSCALL, ONLY FOR THIS PROJ
|
||||||
pub const T_SWITCH_TOU : u8 = 120; // user/kernel switch
|
pub const T_SWITCH_TOU : u8 = 120; // user/kernel switch
|
||||||
pub const T_SWITCH_TOK : u8 = 121; // user/kernel switch
|
pub const T_SWITCH_TOK : u8 = 121; // user/kernel switch
|
@ -101,5 +101,7 @@ interrupt_stack_p!(to_kernel, stack, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
interrupt_stack_p!(syscall, stack, {
|
interrupt_stack_p!(syscall, stack, {
|
||||||
println!("\nInterupt: Syscall");
|
println!("\nInterupt: Syscall {}", stack.scratch.rax);
|
||||||
|
use syscall::syscall;
|
||||||
|
syscall(stack);
|
||||||
});
|
});
|
@ -48,3 +48,11 @@ pub fn print(args: fmt::Arguments) {
|
|||||||
pub fn debug(args: fmt::Arguments) {
|
pub fn debug(args: fmt::Arguments) {
|
||||||
print_in_color(args, Color::LightRed);
|
print_in_color(args, Color::LightRed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write(fd: usize, base: *const u8, len: usize) {
|
||||||
|
// debug!("write: fd: {}, base: {:?}, len: {:#x}", fd, base, len);
|
||||||
|
use core::slice;
|
||||||
|
use core::str;
|
||||||
|
let slice = unsafe { slice::from_raw_parts(base, len) };
|
||||||
|
print!("{}", str::from_utf8(slice).unwrap());
|
||||||
|
}
|
@ -31,7 +31,7 @@ extern crate linked_list_allocator;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
extern crate bit_field;
|
extern crate bit_field;
|
||||||
extern crate syscall;
|
extern crate syscall as redox_syscall;
|
||||||
extern crate xmas_elf;
|
extern crate xmas_elf;
|
||||||
|
|
||||||
#[macro_use] // print!
|
#[macro_use] // print!
|
||||||
@ -43,6 +43,7 @@ mod util;
|
|||||||
mod macros;
|
mod macros;
|
||||||
mod consts;
|
mod consts;
|
||||||
mod process;
|
mod process;
|
||||||
|
mod syscall;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
@ -69,3 +69,7 @@ extern fn idle_thread() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fork(tf: &TrapFrame) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
49
src/syscall.rs
Normal file
49
src/syscall.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use super::*;
|
||||||
|
use process;
|
||||||
|
use arch::interrupt::TrapFrame;
|
||||||
|
|
||||||
|
pub unsafe fn syscall(tf: &TrapFrame) -> i32 {
|
||||||
|
let id = tf.scratch.rax;
|
||||||
|
// For ucore:
|
||||||
|
// let args = [tf.scratch.rdx, tf.scratch.rcx, tf.preserved.rbx, tf.scratch.rdi, tf.scratch.rsi];
|
||||||
|
// For xv6 x86_64
|
||||||
|
let args = [tf.scratch.rdi, tf.scratch.rsi, tf.scratch.rdx, tf.scratch.rcx, tf.scratch.r8, tf.scratch.r9];
|
||||||
|
|
||||||
|
match id {
|
||||||
|
SYS_FORK => {
|
||||||
|
process::fork(tf);
|
||||||
|
0
|
||||||
|
}
|
||||||
|
SYS_WRITE => {
|
||||||
|
io::write(args[0], args[1] as *const u8, args[2]);
|
||||||
|
0
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
debug!("unknown syscall {}", id);
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const SYS_FORK: usize = 1;
|
||||||
|
const SYS_EXIT: usize = 2;
|
||||||
|
const SYS_WAIT: usize = 3;
|
||||||
|
const SYS_PIPE: usize = 4;
|
||||||
|
const SYS_READ: usize = 5;
|
||||||
|
const SYS_KILL: usize = 6;
|
||||||
|
const SYS_EXEC: usize = 7;
|
||||||
|
const SYS_FSTAT: usize = 8;
|
||||||
|
const SYS_CHDIR: usize = 9;
|
||||||
|
const SYS_DUP: usize = 10;
|
||||||
|
const SYS_GETPID: usize = 11;
|
||||||
|
const SYS_SBRK: usize = 12;
|
||||||
|
const SYS_SLEEP: usize = 13;
|
||||||
|
const SYS_UPTIME: usize = 14;
|
||||||
|
const SYS_OPEN: usize = 15;
|
||||||
|
const SYS_WRITE: usize = 16;
|
||||||
|
const SYS_MKNOD: usize = 17;
|
||||||
|
const SYS_UNLINK: usize = 18;
|
||||||
|
const SYS_LINK: usize = 19;
|
||||||
|
const SYS_MKDIR: usize = 20;
|
||||||
|
const SYS_CLOSE: usize = 21;
|
||||||
|
const SYS_CHMOD: usize = 22;
|
Loading…
Reference in New Issue
Block a user