Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

_start call ABI #13

Open
chorman0773 opened this issue Dec 31, 2020 · 8 comments
Open

_start call ABI #13

chorman0773 opened this issue Dec 31, 2020 · 8 comments

Comments

@chorman0773
Copy link
Member

This does not need to be fully decided until we are at userspace, but it is probably a good idea to decide on this now.

Basically, how should we call the entry point of user applications, or of the interpreter when there is a PT_INTERP segment.

Obviously, we need to store the arguments on the stack before the function, and then an array of pointers to them. Should we then push a pointer to that array, or pass it in rdi/rsi (if so, do we pass argc first in rdi?). Should we pass environment variables in the same way, or provide a system call to access them.

I'd note that there really isn't an "incorrect" way of doing this, since we'd need assembly anyways to far jmp into user code with CPL=3.

@rdrpenguin04
Copy link
Member

I'd prefer not passing environment variables, since that then requires macro hackery to get the environment variables cross-platform, besides the existing hackery required to use the variables.

@chorman0773
Copy link
Member Author

Well, there needs to be a way to get environment variables for, at the very least, getenv.

@rdrpenguin04
Copy link
Member

rdrpenguin04 commented Dec 31, 2020

Yeah, I'm going to have to recommend a syscall. I definitely do not recommend passing environment variables to main. (or _start for that matter, since that itself encourages passing to main)

@chorman0773
Copy link
Member Author

Any comment on the other two (argc and argv) being passed into start.

@rdrpenguin04
Copy link
Member

I think that sounds good, as they're more likely than not going to be used.

@chorman0773
Copy link
Member Author

Well, they need to be available to be passed into main. My question is if they should be in rdi and rsi (like Sys-V) or just store them on the stack like unix does and glibc's crt1.S handles.

@rdrpenguin04
Copy link
Member

Probably put them on the stack so that initialization can do other things (which, it almost always will) without needing to specifically push rdi and rsi.

@chorman0773
Copy link
Member Author

Apparently Sys-V specifies this as well, so we should probably conform with it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants