From cf3fd0ec93995ac4aab3290cc183be4c7d92b558 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sun, 21 Apr 2019 15:45:26 +0800 Subject: [PATCH] Fix ioctl numbers and sys_poll for mipsel --- kernel/src/arch/mipsel/cpu.rs | 8 +++++--- kernel/src/arch/mipsel/interrupt.rs | 8 ++------ kernel/src/drivers/console/fonts/font8x16.rs | 3 +-- kernel/src/fs/stdio.rs | 21 ++++++++++++++++++++ kernel/src/syscall/fs.rs | 21 ++++++++++++++------ kernel/src/syscall/mod.rs | 11 +++++----- kernel/src/syscall/proc.rs | 8 ++++++-- 7 files changed, 56 insertions(+), 24 deletions(-) diff --git a/kernel/src/arch/mipsel/cpu.rs b/kernel/src/arch/mipsel/cpu.rs index 764d472..9ee6b4a 100644 --- a/kernel/src/arch/mipsel/cpu.rs +++ b/kernel/src/arch/mipsel/cpu.rs @@ -1,7 +1,7 @@ -use mips::registers::cp0; -use mips::instructions; use crate::consts::MAX_CPU_NUM; use core::ptr::{read_volatile, write_volatile}; +use mips::instructions; +use mips::registers::cp0; static mut STARTED: [bool; MAX_CPU_NUM] = [false; MAX_CPU_NUM]; @@ -22,7 +22,9 @@ pub unsafe fn start_others(hart_mask: usize) { } pub fn halt() { - unsafe { instructions::wait(); } + unsafe { + instructions::wait(); + } } pub unsafe fn exit_in_qemu(error_code: u8) -> ! { diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 1036ffb..56757c4 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -201,9 +201,7 @@ fn set_trapframe_register(rt: usize, val: usize, tf: &mut TrapFrame) { } fn reserved_inst(tf: &mut TrapFrame) -> bool { - let inst = unsafe { - *(tf.epc as *const usize) - }; + let inst = unsafe { *(tf.epc as *const usize) }; let opcode = inst >> 26; let rt = (inst >> 16) & 0b11111; @@ -218,9 +216,7 @@ fn reserved_inst(tf: &mut TrapFrame) -> bool { fn _cur_tls(); } - let tls = unsafe { - *(_cur_tls as *const usize) - }; + let tls = unsafe { *(_cur_tls as *const usize) }; set_trapframe_register(rt, tls, tf); info!("Read TLS by rdhdr {:x} to register {:?}", tls, rt); diff --git a/kernel/src/drivers/console/fonts/font8x16.rs b/kernel/src/drivers/console/fonts/font8x16.rs index abea5bf..e559db6 100644 --- a/kernel/src/drivers/console/fonts/font8x16.rs +++ b/kernel/src/drivers/console/fonts/font8x16.rs @@ -33,8 +33,7 @@ impl Font for Font8x16 { // + Character row offset (row 0 = 0, row 1 = (192 * 8) = 1536) // + X offset for the pixel block that comprises this char // + Y offset for pixel block - let bitmap_bit_index = char_x + x - + (FONT_IMAGE_WIDTH * (char_y + y)); + let bitmap_bit_index = char_x + x + (FONT_IMAGE_WIDTH * (char_y + y)); let bitmap_byte = bitmap_bit_index / 8; let bitmap_bit = 7 - (bitmap_bit_index % 8); diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index 14e8c31..28bb934 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -41,10 +41,31 @@ lazy_static! { pub static ref STDOUT: Arc = Arc::new(Stdout::default()); } +// 32bits total, command in lower 16bits, size of the parameter structure in the lower 14 bits of the upper 16 bits +// higher 2 bits: 01 = write, 10 = read + +#[cfg(not(target_arch = "mips"))] const TCGETS: u32 = 0x5401; +#[cfg(target_arch = "mips")] +const TCGETS: u32 = 0x540D; + +#[cfg(not(target_arch = "mips"))] const TIOCGPGRP: u32 = 0x540F; +// _IOR('t', 119, int) +#[cfg(target_arch = "mips")] +const TIOCGPGRP: u32 = 0x4_004_74_77; + +#[cfg(not(target_arch = "mips"))] const TIOCSPGRP: u32 = 0x5410; +// _IOW('t', 118, int) +#[cfg(target_arch = "mips")] +const TIOCSPGRP: u32 = 0x8_004_74_76; + +#[cfg(not(target_arch = "mips"))] const TIOCGWINSZ: u32 = 0x5413; +// _IOR('t', 104, struct winsize) +#[cfg(target_arch = "mips")] +const TIOCGWINSZ: u32 = 0x4_008_74_68; // TODO: better way to provide default impl? macro_rules! impl_inode { diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 3c79da0..e859eb9 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -465,7 +465,7 @@ pub fn sys_dup2(fd1: usize, fd2: usize) -> SysResult { pub fn sys_ioctl(fd: usize, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult { info!( - "ioctl: fd: {}, request: {}, args: {} {} {}", + "ioctl: fd: {}, request: {:x}, args: {} {} {}", fd, request, arg1, arg2, arg3 ); let mut proc = process(); @@ -1032,7 +1032,7 @@ pub struct Stat { blocks: u64, } -#[cfg(not(any(target_arch = "x86_64", target_arch = "mips"))] +#[cfg(not(any(target_arch = "x86_64", target_arch = "mips")))] #[repr(C)] #[derive(Debug)] pub struct Stat { @@ -1174,16 +1174,25 @@ impl From for Stat { size: info.size as u64, blksize: info.blk_size as u32, blocks: info.blocks as u64, - atime: Timespec { sec: info.atime.sec as i32, nsec: info.atime.nsec }, - mtime: Timespec { sec: info.mtime.sec as i32, nsec: info.mtime.nsec }, - ctime: Timespec { sec: info.ctime.sec as i32, nsec: info.ctime.nsec }, + atime: Timespec { + sec: info.atime.sec as i32, + nsec: info.atime.nsec, + }, + mtime: Timespec { + sec: info.mtime.sec as i32, + nsec: info.mtime.nsec, + }, + ctime: Timespec { + sec: info.ctime.sec as i32, + nsec: info.ctime.nsec, + }, __pad1: 0, __pad2: 0, __pad3: 0, } } - #[cfg(not(any(target_arch = "x86_64", target_arch="mips")))] + #[cfg(not(any(target_arch = "x86_64", target_arch = "mips")))] fn from(info: Metadata) -> Self { Stat { dev: info.dev as u64, diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 15498e2..1baea3c 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -350,9 +350,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { #[cfg(target_arch = "mips")] fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option { let ret = match id { - SYS_FORK => sys_fork(tf), SYS_OPEN => sys_open(args[0] as *const u8, args[1], args[2]), + SYS_POLL => sys_poll(args[0] as *mut PollFd, args[1], args[2]), SYS_DUP2 => sys_dup2(args[0], args[1]), + SYS_FORK => sys_fork(tf), SYS_MMAP2 => sys_mmap(args[0], args[1], args[2], args[3], args[4], args[5] * 4096), SYS_FSTAT64 => sys_fstat(args[0], args[1] as *mut Stat), SYS_LSTAT64 => sys_lstat(args[0] as *const u8, args[1] as *mut Stat), @@ -366,10 +367,10 @@ fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option Err(err) + } + Err(err) => Err(err), } - }, + } SYS_GETPGID => { warn!("sys_getpgid is unimplemented"); Ok(0) @@ -381,7 +382,7 @@ fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option { warn!("sys_fcntl64 is unimplemented"); Ok(0) - }, + } SYS_SET_THREAD_AREA => { info!("set_thread_area: tls: 0x{:x}", args[0]); extern "C" { diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 89b7765..c6c6b1f 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -33,9 +33,13 @@ pub fn sys_clone( warn!("sys_clone is calling sys_fork instead, ignoring other args"); return sys_fork(tf); } - if (flags != 0x7d0f00) && (flags!= 0x5d0f00) { //0x5d0f00 is the args from gcc of alpine linux + if (flags != 0x7d0f00) && (flags != 0x5d0f00) { + //0x5d0f00 is the args from gcc of alpine linux //warn!("sys_clone only support musl pthread_create"); - panic!("sys_clone only support sys_fork OR musl pthread_create without flags{:x}", flags); + panic!( + "sys_clone only support sys_fork OR musl pthread_create without flags{:x}", + flags + ); //return Err(SysError::ENOSYS); } {