|
| 1 | +//! Syscall implementations for `mips`. |
| 2 | +
|
| 3 | +use super::{StatfsBuf, SysInfo, UtsNameBuf}; |
| 4 | + |
| 5 | +pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { |
| 6 | + unsafe { |
| 7 | + let ret: i32; |
| 8 | + core::arch::asm!( |
| 9 | + "syscall", |
| 10 | + "beqz $7, 1f", |
| 11 | + "nop", |
| 12 | + "subu $2, $0, $2", |
| 13 | + "1:", |
| 14 | + inlateout("$2") 4000i32 + 5 => ret, // SYS_open |
| 15 | + in("$4") path, |
| 16 | + in("$5") flags, |
| 17 | + in("$6") 0i32, // mode |
| 18 | + lateout("$7") _, |
| 19 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 20 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 21 | + lateout("$24") _, lateout("$25") _, |
| 22 | + options(nostack) |
| 23 | + ); |
| 24 | + ret |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { |
| 29 | + unsafe { |
| 30 | + let ret: i32; |
| 31 | + core::arch::asm!( |
| 32 | + "syscall", |
| 33 | + "beqz $7, 1f", |
| 34 | + "nop", |
| 35 | + "subu $2, $0, $2", |
| 36 | + "1:", |
| 37 | + inlateout("$2") 4000i32 + 3 => ret, // SYS_read |
| 38 | + in("$4") fd, |
| 39 | + in("$5") buf, |
| 40 | + in("$6") count, |
| 41 | + lateout("$7") _, |
| 42 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 43 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 44 | + lateout("$24") _, lateout("$25") _, |
| 45 | + options(nostack) |
| 46 | + ); |
| 47 | + ret as isize |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { |
| 52 | + unsafe { |
| 53 | + let ret: i32; |
| 54 | + core::arch::asm!( |
| 55 | + "syscall", |
| 56 | + "beqz $7, 1f", |
| 57 | + "nop", |
| 58 | + "subu $2, $0, $2", |
| 59 | + "1:", |
| 60 | + inlateout("$2") 4000i32 + 4 => ret, // SYS_write |
| 61 | + in("$4") fd, |
| 62 | + in("$5") buf, |
| 63 | + in("$6") count, |
| 64 | + lateout("$7") _, |
| 65 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 66 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 67 | + lateout("$24") _, lateout("$25") _, |
| 68 | + options(nostack) |
| 69 | + ); |
| 70 | + ret as isize |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +pub(super) unsafe fn sys_close(fd: i32) -> i32 { |
| 75 | + unsafe { |
| 76 | + let ret: i32; |
| 77 | + core::arch::asm!( |
| 78 | + "syscall", |
| 79 | + "beqz $7, 1f", |
| 80 | + "nop", |
| 81 | + "subu $2, $0, $2", |
| 82 | + "1:", |
| 83 | + inlateout("$2") 4000i32 + 6 => ret, // SYS_close |
| 84 | + in("$4") fd, |
| 85 | + lateout("$7") _, |
| 86 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 87 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 88 | + lateout("$24") _, lateout("$25") _, |
| 89 | + options(nostack) |
| 90 | + ); |
| 91 | + ret |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { |
| 96 | + unsafe { |
| 97 | + let ret: i32; |
| 98 | + core::arch::asm!( |
| 99 | + "syscall", |
| 100 | + "beqz $7, 1f", |
| 101 | + "nop", |
| 102 | + "subu $2, $0, $2", |
| 103 | + "1:", |
| 104 | + inlateout("$2") 4000i32 + 122 => ret, // SYS_newuname |
| 105 | + in("$4") buf, |
| 106 | + lateout("$7") _, |
| 107 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 108 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 109 | + lateout("$24") _, lateout("$25") _, |
| 110 | + options(nostack) |
| 111 | + ); |
| 112 | + ret |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { |
| 117 | + unsafe { |
| 118 | + let ret: i32; |
| 119 | + core::arch::asm!( |
| 120 | + "syscall", |
| 121 | + "beqz $7, 1f", |
| 122 | + "nop", |
| 123 | + "subu $2, $0, $2", |
| 124 | + "1:", |
| 125 | + inlateout("$2") 4000i32 + 255 => ret, // SYS_statfs64 |
| 126 | + in("$4") path, |
| 127 | + in("$5") core::mem::size_of::<StatfsBuf>(), |
| 128 | + in("$6") buf, |
| 129 | + lateout("$7") _, |
| 130 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 131 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 132 | + lateout("$24") _, lateout("$25") _, |
| 133 | + options(nostack) |
| 134 | + ); |
| 135 | + ret |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { |
| 140 | + unsafe { |
| 141 | + let ret: i32; |
| 142 | + core::arch::asm!( |
| 143 | + "syscall", |
| 144 | + "beqz $7, 1f", |
| 145 | + "nop", |
| 146 | + "subu $2, $0, $2", |
| 147 | + "1:", |
| 148 | + inlateout("$2") 4000_i32 + 116 => ret, // __NR_sysinfo |
| 149 | + in("$4") info, |
| 150 | + lateout("$7") _, |
| 151 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 152 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 153 | + lateout("$24") _, lateout("$25") _, |
| 154 | + options(nostack) |
| 155 | + ); |
| 156 | + i64::from(ret) |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +pub(super) unsafe fn sys_sched_getaffinity( |
| 161 | + pid: i32, |
| 162 | + mask_size: usize, |
| 163 | + mask: *mut u8, |
| 164 | +) -> i32 { |
| 165 | + unsafe { |
| 166 | + let ret: i32; |
| 167 | + core::arch::asm!( |
| 168 | + "syscall", |
| 169 | + "beqz $7, 1f", |
| 170 | + "nop", |
| 171 | + "subu $2, $0, $2", |
| 172 | + "1:", |
| 173 | + inlateout("$2") 4000i32 + 240 => ret, // __NR_sched_getaffinity |
| 174 | + in("$4") pid, |
| 175 | + in("$5") mask_size, |
| 176 | + in("$6") mask, |
| 177 | + lateout("$7") _, |
| 178 | + lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, |
| 179 | + lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, |
| 180 | + lateout("$24") _, lateout("$25") _, |
| 181 | + options(nostack) |
| 182 | + ); |
| 183 | + ret |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +pub(super) unsafe fn sys_exit(code: i32) -> ! { |
| 188 | + unsafe { |
| 189 | + core::arch::asm!( |
| 190 | + "syscall", |
| 191 | + in("$2") 4000i32 + 1, // SYS_exit |
| 192 | + in("$4") code, |
| 193 | + options(noreturn, nostack) |
| 194 | + ); |
| 195 | + } |
| 196 | +} |
0 commit comments