X-Git-Url: http://git.dujemihanovic.xyz/projects?a=blobdiff_plain;f=kernel%2Fentry.s;h=a02df92d4703df4ada20654b433158c80ee1373f;hb=668fa121eb74d3317a73c2289f8805aaf1c84d7e;hp=236b81e967e459e4c6f684d137726dbf42743677;hpb=c9f2bccb44c5437f1cae0862b2c84d3af47eade8;p=nameless-os.git diff --git a/kernel/entry.s b/kernel/entry.s index 236b81e..a02df92 100644 --- a/kernel/entry.s +++ b/kernel/entry.s @@ -1,5 +1,12 @@ - bits 32 - extern _start +; when our kernel source has functions before _start and we blindly transfer control to the beginning +; of the kernel binary, it will wrongly execute the other functions +; the solution is to link a small assembly routine (this) which executes a known label within the kernel +; so that this routine comes before the kernel in the resulting binary +; we cannot link the boot sector code and the kernel because the former needs to be a raw binary, while the +; kernel is compiled into an ELF object file which contains some metadata on the kernel code - call _start - jmp $ + bits 32 ; this is started in protected mode + extern _start ; the known label in the kernel source we will execute is, well, not in this assembly routine + + call _start ; call the known label + jmp $ ; it should never return, but hang forever if it does