Page 1 of 2

Interrupts in long mode?

Posted: Wed Aug 24, 2016 5:35 pm
by chris13524
I'm trying to port my 32-bit interrupt code to 64-bits, however, when I try to boot, it randomly triple faults (some clock interrupt?) and reboots.

I've got my C and ASM files on GitHub: I'm currently not setting up any GDT or TSS stuff, as I understand it, UEFI will do this for me.

Any ideas would be extremely helpful!

Re: Interrupts in long mode?

Posted: Wed Aug 24, 2016 7:37 pm
by SpyderTL
UEFI will set up a long mode GDT for you, but you probably shouldn't rely on it too much. You will need to set up your own GDT and IDT to make sure you actually have access to all of the memory space and have all of the interrupts covered.

Re: Interrupts in long mode?

Posted: Wed Aug 24, 2016 8:06 pm
by konacake
It's also generally not a good idea to assume things, you should either check for it or do it yourself (with everything)

Re: Interrupts in long mode?

Posted: Thu Aug 25, 2016 9:02 am
by chris13524
Is it necessary to setup a GDT? I am running in 64-bit mode, isn't that just flat address space?

Re: Interrupts in long mode?

Posted: Thu Aug 25, 2016 9:21 am
by Octocontrabass
The GDT isn't used as much in long mode as it is in protected mode, but you still need it.

Re: Interrupts in long mode?

Posted: Thu Aug 25, 2016 9:39 am
by SpyderTL
And you will need to set up your own paging tables, as well.

Re: Interrupts in long mode?

Posted: Tue Sep 06, 2016 7:13 pm
by chris13524
Would it be possible that the IDT doesn't work because I haven't called ExitBootServices yet?

Re: Interrupts in long mode?

Posted: Tue Sep 06, 2016 8:54 pm
by FallenAvatar
chris13524 wrote:Would it be possible that the IDT doesn't work because I haven't called ExitBootServices yet?
Only if you are booting from UEFI, and NOT Multiboot. They are for all intents and purposes mutualy exclusive.

I WOULD however like to see your grub.cfg from/for your bootable image (whether for HD, Floppy, CD or something else)

- Monk

Re: Interrupts in long mode?

Posted: Tue Sep 06, 2016 10:05 pm
by chris13524
tjmonk15 wrote:
chris13524 wrote:Would it be possible that the IDT doesn't work because I haven't called ExitBootServices yet?
Only if you are booting from UEFI, and NOT Multiboot. They are for all intents and purposes mutualy exclusive.

I WOULD however like to see your grub.cfg from/for your bootable image (whether for HD, Floppy, CD or something else)

- Monk
I am not supporting booting other than from UEFI. One, it makes it much easier, and two, UEFI is a standard that everybody should be supporting anyways soo...

So I am right in assuming I need to call ExitBootServices before I can use the IDT?

Re: Interrupts in long mode?

Posted: Tue Sep 06, 2016 10:40 pm
by thepowersgang
Yes. If you've been loaded as a UEFI application, then until you call ExitBootServices, you're an application - and have no direct hardware access (it's quite likely you're in usermode - probably depends on the implementation)

Re: Interrupts in long mode?

Posted: Wed Sep 07, 2016 12:44 am
by FallenAvatar
-SNIP-

Ugh, completely wrong thread for this reply. Sorry.

Re: Interrupts in long mode?

Posted: Wed Sep 07, 2016 4:37 am
by chris13524
So you are targeting UEFI? And don't understand what "qemu -kernel kernel.img" actually means... *sigh* go read the Wiki/Google until you understand the difference between Multiboot and UEFI. THEN you can ask questions why.

- Monk

P.S. Pretty much your code does not work ever. It happens to work by chance when using Multiboot from Qemu, but since you are targeting Uefi, that is a false positive and means nothing. In reality, your code is horribly broken in every way. Including using a tutorial meant for multiboot when you didnt have a clue what that meant. Honestly, you need to learn research skills before we spend any time helping you
What are you talking about? I do not support multiboot. If you are looking at the source code, the multiboot file is only there incase I wanted to add support again, I will likely remove it soon.
And don't understand what "qemu -kernel kernel.img" actually means...
I am not running this command, I am building a FAT partition and copying my UEFI image to it. Take a look at my makefile, it's all there. I can even confirm it works in VirtualBox and on real hardware.

Like I said, I'm not using multiboot, I don't know why you think I am.

Re: Interrupts in long mode?

Posted: Wed Sep 07, 2016 5:39 am
by thepowersgang
I suspect that @tjmonk15 got their threads mixed up, and confused you with another user.

From a quick look at your codebase, you never call ExitBootServices - So, yes, you'll want to do that before you try and set up your own IDT etc.
Do note that you can't use the UEFI console after calling that (nor anything else from the boot services structure)

Re: Interrupts in long mode?

Posted: Wed Sep 07, 2016 7:05 am
by chris13524
Do note that you can't use the UEFI console after calling that (nor anything else from the boot services structure)
Are you sure about this? Reading the specifications it says that some protocols will still be available after calling ExitBootServices (and some will not). I do not see where it says which ones are which.

Re: Interrupts in long mode?

Posted: Wed Sep 07, 2016 7:09 am
by Octocontrabass
chris13524 wrote:I do not see where it says which ones are which.
Try section 2.2.2 of the current UEFI specification (2.6).