Fix ioctl numbers and sys_poll for mipsel

master
Jiajie Chen 6 years ago
parent c9303466b4
commit cf3fd0ec93

@ -1,7 +1,7 @@
use mips::registers::cp0;
use mips::instructions;
use crate::consts::MAX_CPU_NUM; use crate::consts::MAX_CPU_NUM;
use core::ptr::{read_volatile, write_volatile}; 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]; 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() { pub fn halt() {
unsafe { instructions::wait(); } unsafe {
instructions::wait();
}
} }
pub unsafe fn exit_in_qemu(error_code: u8) -> ! { pub unsafe fn exit_in_qemu(error_code: u8) -> ! {

@ -201,9 +201,7 @@ fn set_trapframe_register(rt: usize, val: usize, tf: &mut TrapFrame) {
} }
fn reserved_inst(tf: &mut TrapFrame) -> bool { fn reserved_inst(tf: &mut TrapFrame) -> bool {
let inst = unsafe { let inst = unsafe { *(tf.epc as *const usize) };
*(tf.epc as *const usize)
};
let opcode = inst >> 26; let opcode = inst >> 26;
let rt = (inst >> 16) & 0b11111; let rt = (inst >> 16) & 0b11111;
@ -218,9 +216,7 @@ fn reserved_inst(tf: &mut TrapFrame) -> bool {
fn _cur_tls(); fn _cur_tls();
} }
let tls = unsafe { let tls = unsafe { *(_cur_tls as *const usize) };
*(_cur_tls as *const usize)
};
set_trapframe_register(rt, tls, tf); set_trapframe_register(rt, tls, tf);
info!("Read TLS by rdhdr {:x} to register {:?}", tls, rt); info!("Read TLS by rdhdr {:x} to register {:?}", tls, rt);

@ -33,8 +33,7 @@ impl Font for Font8x16 {
// + Character row offset (row 0 = 0, row 1 = (192 * 8) = 1536) // + Character row offset (row 0 = 0, row 1 = (192 * 8) = 1536)
// + X offset for the pixel block that comprises this char // + X offset for the pixel block that comprises this char
// + Y offset for pixel block // + Y offset for pixel block
let bitmap_bit_index = char_x + x let bitmap_bit_index = char_x + x + (FONT_IMAGE_WIDTH * (char_y + y));
+ (FONT_IMAGE_WIDTH * (char_y + y));
let bitmap_byte = bitmap_bit_index / 8; let bitmap_byte = bitmap_bit_index / 8;
let bitmap_bit = 7 - (bitmap_bit_index % 8); let bitmap_bit = 7 - (bitmap_bit_index % 8);

@ -41,10 +41,31 @@ lazy_static! {
pub static ref STDOUT: Arc<Stdout> = Arc::new(Stdout::default()); pub static ref STDOUT: Arc<Stdout> = 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; const TCGETS: u32 = 0x5401;
#[cfg(target_arch = "mips")]
const TCGETS: u32 = 0x540D;
#[cfg(not(target_arch = "mips"))]
const TIOCGPGRP: u32 = 0x540F; 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; 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; 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? // TODO: better way to provide default impl?
macro_rules! impl_inode { macro_rules! impl_inode {

@ -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 { pub fn sys_ioctl(fd: usize, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult {
info!( info!(
"ioctl: fd: {}, request: {}, args: {} {} {}", "ioctl: fd: {}, request: {:x}, args: {} {} {}",
fd, request, arg1, arg2, arg3 fd, request, arg1, arg2, arg3
); );
let mut proc = process(); let mut proc = process();
@ -1032,7 +1032,7 @@ pub struct Stat {
blocks: u64, blocks: u64,
} }
#[cfg(not(any(target_arch = "x86_64", target_arch = "mips"))] #[cfg(not(any(target_arch = "x86_64", target_arch = "mips")))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct Stat { pub struct Stat {
@ -1174,9 +1174,18 @@ impl From<Metadata> for Stat {
size: info.size as u64, size: info.size as u64,
blksize: info.blk_size as u32, blksize: info.blk_size as u32,
blocks: info.blocks as u64, blocks: info.blocks as u64,
atime: Timespec { sec: info.atime.sec as i32, nsec: info.atime.nsec }, atime: Timespec {
mtime: Timespec { sec: info.mtime.sec as i32, nsec: info.mtime.nsec }, sec: info.atime.sec as i32,
ctime: Timespec { sec: info.ctime.sec as i32, nsec: info.ctime.nsec }, 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, __pad1: 0,
__pad2: 0, __pad2: 0,
__pad3: 0, __pad3: 0,

@ -350,9 +350,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
#[cfg(target_arch = "mips")] #[cfg(target_arch = "mips")]
fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<SysResult> { fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<SysResult> {
let ret = match id { let ret = match id {
SYS_FORK => sys_fork(tf),
SYS_OPEN => sys_open(args[0] as *const u8, args[1], args[2]), 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_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_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_FSTAT64 => sys_fstat(args[0], args[1] as *mut Stat),
SYS_LSTAT64 => sys_lstat(args[0] as *const u8, 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<SysRe
tf.v1 = *(fd_ptr.add(1)) as usize; tf.v1 = *(fd_ptr.add(1)) as usize;
} }
Ok(tf.v0) Ok(tf.v0)
},
Err(err) => Err(err)
} }
}, Err(err) => Err(err),
}
}
SYS_GETPGID => { SYS_GETPGID => {
warn!("sys_getpgid is unimplemented"); warn!("sys_getpgid is unimplemented");
Ok(0) Ok(0)
@ -381,7 +382,7 @@ fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<SysRe
SYS_FCNTL64 => { SYS_FCNTL64 => {
warn!("sys_fcntl64 is unimplemented"); warn!("sys_fcntl64 is unimplemented");
Ok(0) Ok(0)
}, }
SYS_SET_THREAD_AREA => { SYS_SET_THREAD_AREA => {
info!("set_thread_area: tls: 0x{:x}", args[0]); info!("set_thread_area: tls: 0x{:x}", args[0]);
extern "C" { extern "C" {

@ -33,9 +33,13 @@ pub fn sys_clone(
warn!("sys_clone is calling sys_fork instead, ignoring other args"); warn!("sys_clone is calling sys_fork instead, ignoring other args");
return sys_fork(tf); 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"); //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); //return Err(SysError::ENOSYS);
} }
{ {

Loading…
Cancel
Save