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, yeah, I was optimizing my IDT, and I thought it'd be agreat idea to replace the idt_entry struct with a uint64_t, and then use bit shifting. But it doesn't work, and grub throws the above error. I'm going to post the relevant snippet here. Please help me out TAT
I doubt that is the relevant snippet as it doesn't show where, and how, you are defining your multiboot header. In any case, I'd have said that the struct was the best type for the IDT entries, rather than a simple integer.
It shouldn't matter where I've defined my mboot header, since all I'm trying to do is create and identical structure, similar to the struct, but of type uint64_t, and as long as the underlying data structure is the same, it shouldn't matter. And since my OS seems to work with normal structs, I don't see why it wouldn't work with the int
I have a feeling that the file which contained your multiboot header was linked in first, which allowed it to work, but you havent enforced this rule explicitly and now, for whatever reason, it is not being linked in first.
I put my multiboot header (along with a bunch of 32-bit code which enters long mode and calls the 64-bit kernel etc) in a special section, and i ensure, using a linker script that it is the first section to be linked in.
It definitely has nothing to do with your IDT code.
So, replacing the uint64_t with a uint32_t[2] fixes my problems..... (with obvious changes in the code). Does it have anything to do with the fact that 86 is 32-bit? I was under the impression that the compiler would "assemble" the 64 bit int as most embedded compilers do, and since the intrisical data structure is the same, there shouldn't have been any problem for the CPU to load it.....
animefreak1233 wrote:since the intrisical data structure is the same, there shouldn't have been any problem for the CPU to load it.....
Does that mean that you have examined the generated code in each case and confirmed that the data structures are the same? Or are you just assuming this is so?
When you start working with 64-bit numbers in GCC on a 32-bit platform, GCC needs some helper code that it links in from libgcc to handle things like 64-bit bitshifts and division. This code is likely being linked into your binary wherever ld feels it should be linked in, and in this case, it displaces your multiboot header.
This is merely a symptom of a different problem, and is like taking some paracetamol to treat a fever caused by influenza and calling yourself healthy.
As you still haven't shown us where and how you define your multiboot header my guess would be:
1. It's in your data section.
2. When using structs the code section is small enough to keep the header near enough the start of the file.
3. When using 64-bit integers the code section is large enough to push the header too far away from the start of the file.
This does contradict your assertions that where you define the header is immaterial and that the code generated in both cases is identical. But I'll ignore that as both are obviously incorrect. And it's just a guess as you haven't given us enough information to work with.
The answer, as has already been said, is to ensure that the header comes at the start of the file.