Early stages of OS, DIY bootloader, GCC 0x08040000 address?
Posted: Sun Dec 06, 2020 9:56 pm
Hello OSDev! Thank you for keeping up the forums and the wiki.
I was hoping to talk someone about an issue I'm currently experiencing.
I'm writing my own operating system here https://github.com/isaprykin/os and it's early days. The OS is peculiar in that it uses its own bootloader and CMake. So far it reads loads the 512 bytes of the bootable partition which then runs the kernel C code at the fixed 0x1000 address. I was trying to follow all the typical OS tutorials on the internet and they had me implement IDT handlers next. However that's not going well because GCC generates addresses north of 0x08040000.
So if my C code that is located at 0x1000 has a global static variable such as `struct idt_interrupt_gate idt_entries[2];`, its address is going to be 0x0804xxxx. I read that it's a pretty much hardcoded behavior in GCC. I can add RAM to my Bochs config , but after some reading I feel that's where I'm supposed to add paging. I'm assuming that's what folks would suggest here too, although I remember reading about tricks with GDT where addresses wrap around.
I have two questions:
1) I know that I'm going to have to manipulate pages in the OS and I don't want to do anything smart in the ASM layer rather I want to keep the complexity in the C code. But C variables that aren't automatic/local don't work without paging. What's a good design that allows me to keep paging to the minimum in the ASM layer and enable the C code? I remember that I expected to figure that out after I learn about "identity mapping", however it's still not clear.
2) In my research I looked at the GRUB 0.97 version that was mentioned @ https://asghonim.wordpress.com/2013/11/ ... urce-code/. It mixes the ASM code with C code just like I'm trying to, but it doesn't do anything with paging. How does it work then?
--------------------
I wanted to write this post for around 4 weeks so I thought the points through but there's a small chance I missed a detail, although I don't think so. I also have notes of the IDT failure here https://gist.github.com/isaprykin/af53b ... 0806906cc0 from my early debugging.
I was hoping to talk someone about an issue I'm currently experiencing.
I'm writing my own operating system here https://github.com/isaprykin/os and it's early days. The OS is peculiar in that it uses its own bootloader and CMake. So far it reads loads the 512 bytes of the bootable partition which then runs the kernel C code at the fixed 0x1000 address. I was trying to follow all the typical OS tutorials on the internet and they had me implement IDT handlers next. However that's not going well because GCC generates addresses north of 0x08040000.
So if my C code that is located at 0x1000 has a global static variable such as `struct idt_interrupt_gate idt_entries[2];`, its address is going to be 0x0804xxxx. I read that it's a pretty much hardcoded behavior in GCC. I can add RAM to my Bochs config , but after some reading I feel that's where I'm supposed to add paging. I'm assuming that's what folks would suggest here too, although I remember reading about tricks with GDT where addresses wrap around.
I have two questions:
1) I know that I'm going to have to manipulate pages in the OS and I don't want to do anything smart in the ASM layer rather I want to keep the complexity in the C code. But C variables that aren't automatic/local don't work without paging. What's a good design that allows me to keep paging to the minimum in the ASM layer and enable the C code? I remember that I expected to figure that out after I learn about "identity mapping", however it's still not clear.
2) In my research I looked at the GRUB 0.97 version that was mentioned @ https://asghonim.wordpress.com/2013/11/ ... urce-code/. It mixes the ASM code with C code just like I'm trying to, but it doesn't do anything with paging. How does it work then?
--------------------
I wanted to write this post for around 4 weeks so I thought the points through but there's a small chance I missed a detail, although I don't think so. I also have notes of the IDT failure here https://gist.github.com/isaprykin/af53b ... 0806906cc0 from my early debugging.