Why Xinu OS rounds stack size when creating a new process?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
rrd
Posts: 6
Joined: Wed Mar 14, 2018 8:07 am

Why Xinu OS rounds stack size when creating a new process?

Post by rrd »

I'm taking a look into the Xinu's code trying to understand what some parts of the code does in the system.

In the function create, that creates a new process, the stack size of the process, an argument defined by the user, is rounded with a function called roundew. I read the docs but I'm not sure if I understand exactly what that function does and why is needed to do that with size of the stack.

Is it just a 4-byte memory alignment? I'm learning about this subject right now, so I don't understand exactly why memory alignment is so important and how an OS implements it.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Why Xinu OS rounds stack size when creating a new proces

Post by BrightLight »

On i386, the stack should be 4-byte aligned. On x86_64, the stack should be 8-byte aligned. But to comply with the System V ABI, the stack must be 16-byte aligned when you call a function. I haven't looked into the source code you mention, nor have I ever heard about it, but this is what I do know about stack alignment on the x86.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Why Xinu OS rounds stack size when creating a new proces

Post by zaval »

Aligning stack pointer on 8 bytes on 32 bits and on 16 bytes on 64 bits is common not only on x86. An old mips supplement from SCO, that that describes calling conventions and all those elf platform specific things, honestly admits, that even though the processor wants 4-byte alignment for its words (4 bytes) at the best, OS environment "traditionally" wanted it to be 8-byte aligned... It's as much a mystery, roots of which have sank in history, as this XINU thing I guess. :D
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Post Reply