Commit ea60a8a8 authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

cannon: use constant instead of magic value (#12386)

* use constant instead of magic value

* address comments

* address comments

* add RegSyscallErrno
parent 86e5f636
package exec
// FYI: https://en.wikibooks.org/wiki/MIPS_Assembly/Register_File
//
// https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
const (
// syscall number; 1st return value
RegV0 = 2
// syscall arguments; returned unmodified
RegA0 = 4
RegA1 = 5
RegA2 = 6
// 4th syscall argument; set to 0/1 for success/error
RegA3 = 7
)
// FYI: https://web.archive.org/web/20231223163047/https://www.linux-mips.org/wiki/Syscall
const (
RegSyscallNum = RegV0
RegSyscallErrno = RegA3
RegSyscallRet1 = RegV0
RegSyscallParam1 = RegA0
RegSyscallParam2 = RegA1
RegSyscallParam3 = RegA2
RegSyscallParam4 = RegA3
)
...@@ -99,12 +99,12 @@ const ( ...@@ -99,12 +99,12 @@ const (
) )
func GetSyscallArgs(registers *[32]Word) (syscallNum, a0, a1, a2, a3 Word) { func GetSyscallArgs(registers *[32]Word) (syscallNum, a0, a1, a2, a3 Word) {
syscallNum = registers[2] // v0 syscallNum = registers[RegSyscallNum] // v0
a0 = registers[4] a0 = registers[RegSyscallParam1]
a1 = registers[5] a1 = registers[RegSyscallParam2]
a2 = registers[6] a2 = registers[RegSyscallParam3]
a3 = registers[7] a3 = registers[RegSyscallParam4]
return syscallNum, a0, a1, a2, a3 return syscallNum, a0, a1, a2, a3
} }
...@@ -281,8 +281,8 @@ func HandleSysFcntl(a0, a1 Word) (v0, v1 Word) { ...@@ -281,8 +281,8 @@ func HandleSysFcntl(a0, a1 Word) (v0, v1 Word) {
} }
func HandleSyscallUpdates(cpu *mipsevm.CpuScalars, registers *[32]Word, v0, v1 Word) { func HandleSyscallUpdates(cpu *mipsevm.CpuScalars, registers *[32]Word, v0, v1 Word) {
registers[2] = v0 registers[RegSyscallRet1] = v0
registers[7] = v1 registers[RegSyscallErrno] = v1
cpu.PC = cpu.NextPC cpu.PC = cpu.NextPC
cpu.NextPC = cpu.NextPC + 4 cpu.NextPC = cpu.NextPC + 4
......
...@@ -59,8 +59,8 @@ func (m *InstrumentedState) handleSyscall() error { ...@@ -59,8 +59,8 @@ func (m *InstrumentedState) handleSyscall() error {
newThread.Registers[29] = a1 newThread.Registers[29] = a1
// the child will perceive a 0 value as returned value instead, and no error // the child will perceive a 0 value as returned value instead, and no error
newThread.Registers[2] = 0 newThread.Registers[exec.RegSyscallRet1] = 0
newThread.Registers[7] = 0 newThread.Registers[exec.RegSyscallErrno] = 0
m.state.NextThreadId++ m.state.NextThreadId++
// Preempt this thread for the new one. But not before updating PCs // Preempt this thread for the new one. But not before updating PCs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment