Globals & function params crash my x32 kernel + x64 fails
Posted: Sun Jan 13, 2019 4:14 pm
Hello everyone,
I've been following Brokenthorn's tutorial, but went for long mode instead. I can load an x86 kernel, but it has the following problems: I cannot use globals and function parameters, the kernel just crashes if I do. Also, I tried compiling the kernel as x64 instead (I am using VS2017) for this and in this case, the kernel does not load..
The kernel is loaded at 0x120000. Here's a picture of the loading part: https://imgur.com/a/jbbj5Qi ; IMAGE_PMODE_BASE holds the afore-mentioned address.
This is my kernel's main function (in the called main(), I try to print something to the screen.. it works, but not if try to access the parameters of any function or a global variable): http://prntscr.com/m6qsj4
I'm attaching logs of what Bochs gives me on each of the following cases:
1. x32 kernel when using a function parameter -> x32_using_function_parameter.txt
CODE SNIPPET: http://prntscr.com/m6qwkx
2. Also x32 kernel when writing to a global -> x32_writing_global.txt
CODE SNIPPET: http://prntscr.com/m6qz3u
3. x64 kernel.. doesn't properly call C? x64_kernel.txt
CODE SNIPPET: http://prntscr.com/m6r002
Should it matter, this is my GDT:
http://prntscr.com/m6qt6r
and this is my long mode setup routine:
http://prntscr.com/m6qtv8
Other than that, I'd like to note that visual studio warns me that I should use a load address higher than 4GB for best ASLR optimization. Also, the only pages I've allocated are those for identity mapping the first 2MiB's of memory.. could this be problematic?
Here's a link to my Bitbucket project (it's very messy, I really apologize).. to run it, one would have to set 'src/boot/boot.bin' as floppy drive A:'s boot sector and then one would run 'run.bat' (it requires Bochs to be intsalled). The 'root/failing.img' file contains a diskette image that has the bootsector written and the necessary files for the bootloader & kernel written to.
https://bitbucket.org/PhantomR13/cut2-myos/src/master/
EDIT: I apologize, I've just now pushed the files to the repository.. sorry for the delay.
Thank you so much!
I've been following Brokenthorn's tutorial, but went for long mode instead. I can load an x86 kernel, but it has the following problems: I cannot use globals and function parameters, the kernel just crashes if I do. Also, I tried compiling the kernel as x64 instead (I am using VS2017) for this and in this case, the kernel does not load..
The kernel is loaded at 0x120000. Here's a picture of the loading part: https://imgur.com/a/jbbj5Qi ; IMAGE_PMODE_BASE holds the afore-mentioned address.
This is my kernel's main function (in the called main(), I try to print something to the screen.. it works, but not if try to access the parameters of any function or a global variable): http://prntscr.com/m6qsj4
I'm attaching logs of what Bochs gives me on each of the following cases:
1. x32 kernel when using a function parameter -> x32_using_function_parameter.txt
CODE SNIPPET: http://prntscr.com/m6qwkx
2. Also x32 kernel when writing to a global -> x32_writing_global.txt
CODE SNIPPET: http://prntscr.com/m6qz3u
3. x64 kernel.. doesn't properly call C? x64_kernel.txt
CODE SNIPPET: http://prntscr.com/m6r002
Should it matter, this is my GDT:
http://prntscr.com/m6qt6r
and this is my long mode setup routine:
http://prntscr.com/m6qtv8
Other than that, I'd like to note that visual studio warns me that I should use a load address higher than 4GB for best ASLR optimization. Also, the only pages I've allocated are those for identity mapping the first 2MiB's of memory.. could this be problematic?
Here's a link to my Bitbucket project (it's very messy, I really apologize).. to run it, one would have to set 'src/boot/boot.bin' as floppy drive A:'s boot sector and then one would run 'run.bat' (it requires Bochs to be intsalled). The 'root/failing.img' file contains a diskette image that has the bootsector written and the necessary files for the bootloader & kernel written to.
https://bitbucket.org/PhantomR13/cut2-myos/src/master/
EDIT: I apologize, I've just now pushed the files to the repository.. sorry for the delay.
Thank you so much!