2018-09-04 22:07:07 +00:00
|
|
|
#
|
|
|
|
! Declare segments (the order is important).
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
.sect .rom
|
|
|
|
.sect .data
|
|
|
|
.sect .bss
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
|
|
|
|
#define EINVAL 22
|
|
|
|
|
|
|
|
! Perform a Linux system call.
|
|
|
|
|
|
|
|
.define __syscall
|
|
|
|
__syscall:
|
2018-09-09 16:57:12 +00:00
|
|
|
lw r2, 0(sp) ! syscall number
|
|
|
|
addiu r2, r2, 4000 ! MIPS uses non-standard numbers
|
|
|
|
lw r4, 4(sp)
|
|
|
|
lw r5, 8(sp)
|
|
|
|
lw r6, 12(sp)
|
2018-09-04 22:07:07 +00:00
|
|
|
syscall 0
|
|
|
|
|
2018-09-09 16:57:12 +00:00
|
|
|
beq r7, zero, exit ! branch on success
|
|
|
|
nop
|
|
|
|
|
|
|
|
/* The result (in r2) is the errno. */
|
|
|
|
lui at, ha16[_errno]
|
|
|
|
sw r2, lo16[_errno] (at)
|
|
|
|
li r2, -1
|
|
|
|
exit:
|
|
|
|
jr ra
|
|
|
|
nop
|
|
|
|
|