先直接上c库代码,见 ports/mips64/syscall.S
NESTED (syscall, SZREG, ra) .mask 0x00010000, -SZREG .fmask 0x00000000, 0 PTR_ADDIU sp, -SZREG REG_S s0, (sp) move s0, a0 move a0, a1 /* shift arg1 - arg7. */ move a1, a2 move a2, a3 move a3, a4 move a4, a5 move a5, a6 move a6, a7 move v0, s0 /* Syscall number -> v0 */ syscall /* Do the system call. */ REG_L s0, (sp) PTR_ADDIU sp, SZREG bne a3, zero, L(error) ret L(error): SETUP_GP64 (a0, syscall) PTR_LA t9, __syscall_error RESTORE_GP64 jr t9 END (syscall)line7-line14 直接寄存器传参;
__syscall_error函数在ports/sysdeps/unix/mips/sysdep.S:
ENTRY(__syscall_error) REG_S v0, V0OFF(sp) jal __errno_location /* Store the error value. */ REG_L t0, V0OFF(sp) sw t0, 0(v0) li v0, -1 j ra END(__syscall_error)line2先保存错误码v0;
NESTED(handle_sys, PT_SIZE, sp) beqz t0, not_o32_scall 1: lw a4, 16(t0) # argument #5 from usp 2: lw a5, 20(t0) # argument #6 from usp 3: lw a6, 24(t0) # argument #7 from usp 4: lw a7, 28(t0) # argument #8 from usp (for indirect syscalls) li t0, -EMAXERRNO - 1 # error? sltu t0, t0, v0 sd t0, PT_R7(sp) # set error flag beqz t0, 1f dnegu v0 # error sd v0, PT_R0(sp) # flag for syscall restarting 1: sd v0, PT_R2(sp) # result END(handle_sys)line2根据系统调用号判断是不是o32的调用,o32的范围(0-6000)