I'm trying to understand operating system internals, but I'm having a bit of a problem. I'm wondering how operating systems give out virtual memory, assert that programs are not writing in and out of bounds (this would require some sort of validation by the operating system for each instruction that will be run, which seems odd), and manage/handle system calls.
In addition, I'm trying to find the difference between a boot executable that contains assembly code and a regular executable containing assembly instructions on a UNIX operating system. They obviously have different permissions, but to what degree, and how does it's memory layout differ? It seems that a regular assembly program would have a .bss, a .data, .text, etc.
To summarize:
How does an operating system set up an environment for an assembly program to run? How does it differ to an assembly program that is not running on an OS, but are direct instructions to the CPU?
Thanks!