Bad return after INT 0x15 ah=e820
Bad return after INT 0x15 ah=e820
Hi!
This issue might be obvious, but maybe some could help out.
I've been writing a 64bit kernel and want to detect the memory size and layout for the kernel heap.
Since - as far as I've read and understand - grub only reports up to 4GB of RAM, I started looking at the INT 15h e820 BIOS call.
After GRUB2 handoff, I disable interrupts and do the INT 15 ah=0xe820 call, however it never returns to the caller function or ASM snippet but always to address 0xe05b.
In this case the return address should be 0x507d - so it's not an address turncation issue.
1) Any ideas what the reason might be?
2) Is there a better way to detect memory above 4GB?
I skipped the code, since I don't belive it will to be relevant. How ever if requested I will post it.
Regards,
Mao
This issue might be obvious, but maybe some could help out.
I've been writing a 64bit kernel and want to detect the memory size and layout for the kernel heap.
Since - as far as I've read and understand - grub only reports up to 4GB of RAM, I started looking at the INT 15h e820 BIOS call.
After GRUB2 handoff, I disable interrupts and do the INT 15 ah=0xe820 call, however it never returns to the caller function or ASM snippet but always to address 0xe05b.
In this case the return address should be 0x507d - so it's not an address turncation issue.
1) Any ideas what the reason might be?
2) Is there a better way to detect memory above 4GB?
I skipped the code, since I don't belive it will to be relevant. How ever if requested I will post it.
Regards,
Mao
-
- Member
- Posts: 5604
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Bad return after INT 0x15 ah=e820
Have you switched everything back to the real-mode defaults?mao wrote:After GRUB2 handoff,
Re: Bad return after INT 0x15 ah=e820
No, I have not. In ignorance I assumed grub had left the state in protected mode.
That is of course not the case, the machine is in protected mode.
Thanks!
That is of course not the case, the machine is in protected mode.
Thanks!
- Bender
- Member
- Posts: 449
- Joined: Wed Aug 21, 2013 3:53 am
- Libera.chat IRC: bender|
- Location: Asia, Singapore
Re: Bad return after INT 0x15 ah=e820
<OT>mao wrote:No, I have not. In ignorance I assumed grub had left the state in protected mode.
That is of course not the case, the machine is in protected mode.
Thanks!
*My brain resulted in an invalid opcode exception while trying to parse the above sentence*
Here's the log:
Code: Select all
Error at sentence 2 word 12: Unexpected Word: protected
Invalid Opcode.
Failed to understand the current sentence. Moving to next one.
Serious: Maybe you meant that you assumed GRUB left you in Real Mode, but the machine was in Protected Mode?
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
(R3X Runtime VM)(CHIP8 Interpreter OS)
Re: Bad return after INT 0x15 ah=e820
Hmm. GRUB is able to report more than 4 GiB of RAM when giving the memory map to my 64-bit multiboot operating system, for instance my desktop has 6 GB.
Re: Bad return after INT 0x15 ah=e820
Wouldn't that be long mode (If I have learnt correctly, correct me if I am wrong here). So does that mean GRUB goes to long mode in order to accurately tell you the RAM size?
CookieOS. Want a cookie? Its only black and white for now though, probably as bad as my baking skills.
Re: Bad return after INT 0x15 ah=e820
No. One switches mode of CPU to _use_ high parts of RAM but this is not required to just enumerate usable memory. After all, the only right™ way to find accessible memory regions is to ask firmware or the bootloader that loaded your code (which is the same for GRUB, so it just asks firmware and gives you converted result).hometue wrote:So does that mean GRUB goes to long mode in order to accurately tell you the RAM size?
Re: Bad return after INT 0x15 ah=e820
Yes. Grub 2 does return memory above 4GB. I can't find the references that claimed it doesn't right now. However http://wiki.osdev.org/Detecting_Memory_ ... p_Via_GRUB does explain that "GRUB simply uses INT 15h, EAX=E820"
So, this got embarrassing.
So, this got embarrassing.
Re: Bad return after INT 0x15 ah=e820
What is embarrassing here? GRUB (and BIOS function that it uses) gives you just addresses and length of memory regions. You can return 64-bit variables (and do some arithmetic operations with them) in any mode of CPU, one have to switch to unreal/protected/long mode only to use memory after these pointers.mao wrote:Yes. Grub 2 does return memory above 4GB. I can't find the references that claimed it doesn't right now. However http://wiki.osdev.org/Detecting_Memory_ ... p_Via_GRUB does explain that "GRUB simply uses INT 15h, EAX=E820"
So, this got embarrassing.
http://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820 - this function sets 64-bit fields in corresponding structure, so it's obvious that it's can tell you about the presence of high (even > 4G) memory regions.
Re: Bad return after INT 0x15 ah=e820
The emabrassing part is that I made assumptions about grub and did not RFTM properly.
Any how, thanks. Made som progress now.
Any how, thanks. Made som progress now.