Sergey Bugaev <[email protected]> writes: > Hi! > > I know next to nothing about LoongArch, but generally, the informal > principle appears to be: make syscalls look a lot like regular > function calls, except pass the syscall number in a register not > normally used for arguments. For AArch64, that's x8, because regular > arguments are passed in x0-x7. On x86_64, that's rax, which is also > not normally used for passing args. > > Quickly looking at LoongArch64, it looks like r4-r11 (a0-a7) are all > used by the calling convention to pass values. That would make r12 > (t0) the natural syscall number register. > > > Well, as said, I don't know anything about LoongArch so I can't judge > what he meant exactly. If the point is just that t0 is a temporary > (caller-saved) register, than that should not be a concern. The kernel > can preserve whatever it wants (in fact it works out better for the > kernel to preserve all registers over syscalls except the one used for > the return value, since the thread state may also be saved when a > thread is interrupted involuntarily), and a* registers are also > equally temporary. But a LoongArch engineer would certainly know and > understand that better than I do (and if you're working on a port, you > do too); perhaps there is a different mechanism in LoongArch that > makes t0 unsuitable here. > >> On the other hand, if we use $a7, vm_map() would need one additional >> register move: we would have to move the original value of $a7 to the >> stack before putting the syscall number in $a7. > > Consider also that syscall bodies (in userland) are not implemented > individually, but instead generated from Mach headers, specifically > <syscall_sw.h>. You could define the kernel_trap macro differently > depending on 'number_args', but it makes things simpler if you don't > have to.
Hi Sergey! :) I've carefully considered your suggestions and discussed with LoongArch engineer, We currently lean towards to use $t8(r20) as the syscall number reg. The concern with $t0 is that GCC/llvm and other toolschains may use it quite frequently for temp values and reg allocation though it should not affect correctness. What do you think of this approach ? :) -- Donjuanplatinum, Yifei Yao <[email protected]> GPG: 1C9E EEE5 4C8E D5A8 3039 1C87 A9F6 8632 D259 40E6 满堂兮美人 忽独与余兮目成
