Comments (11)
Making syscalls look as much like function calls as possible is a reasonable goal. In one respect, they are quite different, though: syscalls preserve all registers, except a0. I assume we want to keep it that way.
I'm fine with t1, since syscalls could be in millicode routines that would then have to juggle the return address.
from riscv-elf-psabi-doc.
This might have been premature…
-
Linux is not fully representative in returning only one register from syscalls using the negated errno trick. The BSDs typically return two values, errno-or-return and which-was-it (the latter is usually the carry flag, but it's $a3 on MIPS). We can pretend this is a struct, but since we defined C return for small types as "exactly as passing one argument", there's a single obvious way to extend the calling convention to multiple return values.
-
L4-ish systems like to pass and return several registers unchanged (by treating them as fixed in the kernel; L4s like to treat synchronous IPC as the kernel hot path). This seems to be mostly a special case of "multiple return values", though.
-
I'm not necessarily opposed to declaring one or more registers as possibly-clobber. There's design space out there for future/alternate privileged architectures to implement ECALL without the full sscratch dance; if you want to, let's say, take a system call with interrupts automatically enabled, "sepc" has to be rerouted somewhere else, and it could be a GPR or a CSR. Not something I want to persue myself any time soon.
-
The biggest advantage of this proposal is that there's one obvious way to extend it. If someone wants 8 or 9 arguments, they can, and there's no question about how. (9 requires reading user sp, but i386 kernels already do that regularly.) Everyone on x86_64 uses argument registers a bit differently, which would be nice to avoid.
-
The biggest disadvantage is that anything that's not already broken by the calling convention changes and the ELF flag changes will no longer be able to make system calls.
from riscv-elf-psabi-doc.
Number 5 is a non-trivial concern to me, since it falls to me to do all the work.
from riscv-elf-psabi-doc.
I don't follow number 4. Either strategy supports more arguments pretty seamlessly, right?
from riscv-elf-psabi-doc.
I don't think 3 is worth considering for this privileged architecture.
from riscv-elf-psabi-doc.
The L4 approach seems roughly compatible (preserve all arguments that would not be clobbered by the syscall itself), yeah?
from riscv-elf-psabi-doc.
The errno-return style the MIPS ABI employed never made much sense to me, but treating it as an a0/a1 struct seems compatible. The trick here is the entire ABI has to know about it; presently, all glibc syscalls are treated as clobbering only a0.
from riscv-elf-psabi-doc.
The situation I was trying to avoid is: I'm porting some niche/homebrew OS to RISC-V, and I follow the Linux convention because Schelling point. Then I get to a syscall with 8 arguments. Do I (a) pass the eight argument on the stack, (b) move the syscall number somewhere else, (c) put the eight argument in a non-a-register?
Anyway, it's probably not worth changing Linux at this point. Leaving final discretion about whether to close this up to you.
from riscv-elf-psabi-doc.
@palmer-dabbelt any thoughts? I'm leaning towards "it doesn't really matter much, so let's avoid the hassle."
from riscv-elf-psabi-doc.
There are a few other nice effects of having a common ABI between function calls and syscalls, one of which is uniformity of debugging, and another of which is emulation. The two are connected - as an example, on Exherbo seccomp mode 2 is used with SECCOMP_RET_PTRACE
to sandbox package building.
In addition, a common ABI between functions and syscalls makes it entirely feasible to replace an (ADDI t1, zero, NR; ECALL) sequence with (AUIPC t1, table; JALR whatever, t1, NR) or some similar sequence at relocation time in order to substitute a non-privileged syscall implementation.
This is immensely useful for anything akin to "zones", etc, and would make foreign binaries vastly easier to support - currently, the midipix
project builds a custom musl in order to sub out syscalls so Linux programs can run on Windows. Using a common ABI could reduce that kind of use case to nothing more than an ELF loader patch.
from riscv-elf-psabi-doc.
This ship has already sailed. Linux does one thing and FreeBSD does another (more sensible IMO, putting the syscall number in t0 rather than wasting an argument register). Besides, this is an OS-specific concern that does not affect toolchains.
from riscv-elf-psabi-doc.
Related Issues (20)
- Specify relocation overflow checks HOT 1
- Specify a platform reserved register HOT 20
- Should calling convention also define ptrdiff_t? HOT 1
- Should we use lw/sw in push pop when we used ILP32, whether it's RV32 or RV64 HOT 3
- Operation semantics of __bf16 datatype HOT 2
- representation of GNU C fixed-size vectors HOT 4
- Deprecate R_RISCV_RVC_LUI? HOT 4
- Define GOT-Relative data relocation HOT 8
- Embedding R_RISCV_RELAX to another relocations HOT 7
- Define gp(x3) as global VLENB HOT 4
- Bitfield integer calling convention garbled
- Calling convention uses RV64GQ without definition or reference HOT 3
- Calling convention description of va_list et al. are unclear HOT 2
- Interpretation of floating-point types
- Linux ABI for Pointer Masking HOT 19
- New ABI for stack layout and frame pointer scheme HOT 4
- Change branch from "master" to "main" HOT 1
- Add CREL support HOT 3
- Add RELR support HOT 6
- Question about medlow's single 2 GiB address range HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from riscv-elf-psabi-doc.