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.
So, i have ELF kernel that has one part written in C and the other in NASM. These two parts are linked into the ELF kernel and converted to plain BIN with objcopy. The kernel has to be started from primary bootloader (I'm using one from MikeOS). But bootloader starts up, finds kernel, jumps to it and hangs the system. And i don't know where the problem is.
ASM part of kernel (_start is the entry point):
There seems to be a lot missing. Do you have a more complete project on Github or similar service? I don't see where you enter protected mode but it seems like you are then trying call into 32-bit code while still in real mode? If so, that won't work. You shouldn't start the stack pointer on an odd address like 0xffff. Set it to 0x0000 then the first values pushed will end up at the top of the segment at 0xffff and 0xfffe after the first push (in real mode). This is a problem to:
. In that code you have placed data before the instructions so that data will be executed as code as well and gosh knows what that'll do (if anything). There may be other things as well but not visible in the code provided.
MichaelPetch wrote:it seems like you are then trying call into 32-bit code while still in real mode? If so, that won't work. You shouldn't start the stack pointer on an odd address like 0xffff. Set it to 0x0000 then the first values pushed will end up at the top of the segment at 0xffff and 0xfffe after the first push (in real mode).
Oh, yes. Fixed it.
MichaelPetch wrote:In that code you have placed data before the instructions so that data will be executed as code
The data was placed there just to check the entry point, I removed it.
Looking at that code I don't see where you enter protected mode before calling into your kernel_main function. Without entering protected mode you can't expect to have kernel_main and your 32-bit code to run properly.
As well in your linker script you use 1M as your origin point in memory (Starting Virtual Memory Address) but that's not the location in RAM you loaded kernel.bin. That will also cause issues.