lunixbochs / lib43

portable libc optimized for code size and readability
MIT License
80 stars 6 forks source link

apple syscall touches registers for no reason #11

Closed lunixbochs closed 9 years ago

tmcarthur commented 9 years ago

In syscall.c, _start, or somewhere else? It uses same code as Linux unless I'm mistaken, right?

lunixbochs commented 9 years ago

OS X uses the stack for syscalls iirc, only uses eax/rax for the syscall number.

tmcarthur commented 9 years ago

I think that's true for i386, though I can't test since I don't have an i386 box right now - I'll try to grab one - in the case of x86_64 though I'm fairly sure it uses the same ABI for system calls as Linux (System V w/ AMD64 support). Maybe I'm mistaken though? I know general function calls pass parameters either in GP registers and/or stack though - and reserves stack space if you use GP registers (I think?).

tmcarthur commented 9 years ago

More info: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/140-x86-64_Function_Calling_Conventions/x86_64.html#//apple_ref/doc/uid/TP40005035-SW1

lunixbochs commented 9 years ago

I'm in the process of improving processor configuration at build time (and adding preliminary mips support) so even if it only applies to i386, it still matters here as I'm actually able to build/run 32-bit lib43 on OS X now.

tmcarthur commented 9 years ago

Okay cool - was just curious :)

lunixbochs commented 9 years ago

i386 syscall prologue can probably be changed to pop eax?

tmcarthur commented 9 years ago

Agreed. Will also need to make sure OS X sys calls using i386 ABI don't add the 2 << 30 offset we add to 64-bit - it's only used for 64-bit sys calls

lunixbochs commented 9 years ago

grr, i386 is broken on OS X. Try the latest master with -DCPU=i386

tmcarthur commented 9 years ago

Fun! Do you want to fix it, or do you want me to submit a pull req to?

lunixbochs commented 9 years ago

I'm not sure what exactly is breaking (I already fixed the _start), it does make it to syscall() before it hangs.

I'm in the middle of moving syscalls from C to assembly (now that the arch stuff is more fleshed out) so you shouldn't pull req just yet if it comes to that.

tmcarthur commented 9 years ago

Sounds good - I'll have a look and then need to run some errands - but I'll check out where things are this evening and can submit pull req to fix it then unless you already have it taken care of if that works?

Oh also let me know if you have any issues w/ arm pull req - I can fix merge conflicts once you update stuff on that one if you'd prefer as well - thanks.

lunixbochs commented 9 years ago

After my updates today (especially with mips support), the arm pull request will hopefully just need to be syscall and crt0 _start asm blobs (besides the div stuff).

You should take a look at my updates to CMakeLists, as I did change it a bit for sanity.

tmcarthur commented 9 years ago

Yeah - I figured as much - that's a good thing! The div stuff I'm going to do in separate commit in day or two because I want to optimize it so it isn't slow/crappy and it handles all the corner cases (meaning all the variants that ARM expects, idiv, uidiv, etc), for now just planning to send pull req for armv7+

Yeah I saw that - it's a lot cleaner now and it's going to be easier to support multiple architectures which will be nice.

Cool - I'll hold off on making any more pull reqs for now then and just wait for you to finish your refactoring. Could you just let me know over this or twitter once you're done so I know when I'm good to go? Thanks!

lunixbochs commented 9 years ago

Fixed by e07c45de562cd550c1cbd0b6820c66bbebee19ec