Every instruction comes from main memory/RAM.
In a bootloader, at least on Intel and IBM PC firmware and designations, you
have BIOS jump to a memory address to begin fetching instructions for whatever
purpose, usually to load a kernel, when or where does the instance of a process begin?
The hardware stacks are limited, but does using them constitute for a process or thread?
My point simply is what makes something a “thread” or “process”, as to opposed to
just more bytes from memory? Where is the line drawn in this situation?
9
The BIOS finds the kernel bootloader and jumps to that. The kernel loads process zero — at this point the kernel has total control over the processor and RAM. When the kernel wants to start a new process, it saves the state of the current process, allocates space in memory for the new process, and loads the initial state of the new process. The stack is just some available space given to a process by the kernel. It works like the memory is allocated before the process starts and freed after the process ends. The stack is limited because for C it needs to be contiguous — to extend the stack, the kernel has to use the MMU to map a space in memory. If you don’t ask the kernel first, you go past the end of the stack into a region that the MMU marked as unreadable, causing an overflow.
There are a few ways to separate tasks.
Green threads are done by saving state and switching tasks without kernel support. The process would need to allocate new stack space or share stack space. Switching with green threads requires them to release control of the CPU and give it to another with a yield
command or similar.
Kernel threads are given their own stack and task switching is done by the kernel’s scheduler, and the kernel creates space for the thread’s stack, but they belong to the same process so they can access the same memory.
Processes are segregated by the kernel, so they cannot access the memory of other processes under normal conditions. fork
ing creates a new process with a copy (on write) of the memory used by the parent process.
I think these definitions are fairly typical, but a lot does depend on what the kernel and even language writers decided. For example, in Erlang, they use what I would refer to as “green threading” to create very light-weight threads, but describe these as “processes” (not unjustifiably, since they don’t share memory).