OSDev.org https://forum.osdev.org/ |
|
Interrupts doesnt work in GRUB[solved] https://forum.osdev.org/viewtopic.php?f=1&t=33160 |
Page 1 of 1 |
Author: | Klakap [ Tue Sep 04, 2018 9:06 am ] |
Post subject: | Interrupts doesnt work in GRUB[solved] |
Good day! When I'm into my kernel put GRUB, after the setting of the IDT table Virtualbox has get a severe error. Qemu also. While I GRUB did not, IDT and interrupts was working. Please how I can in GRUB do interrupts? |
Author: | MichaelPetch [ Tue Sep 04, 2018 11:03 am ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Without seeing your code it is hard to tell, but one common issue when booting GRUB is that people don't follow the GRUB documentation that suggests you can't rely on the GDTR being set properly. Try creating your own GDT to ensure you have a valid one. If you don't it is possible when you load the IDT and an interrupt eventually fires it tries to use a bad descriptor. That is just a guess, but it could be something else, but without more information/code it is hard to tell. |
Author: | Klakap [ Mon Sep 10, 2018 11:51 am ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
When I tried to set up the GDT, the linker gave me error: Code: compile/kasm.o: In function `gdt_end': kernel.asm:(.text+0x45): relocation truncated to fit: R_386_16 against `.text' This is my code: Code: gdt: gdt_null: dq 0 gdt_code: dw 0FFFFh dw 0 db 0 db 10011010b db 11001111b db 0 gdt_data: dw 0FFFFh dw 0 db 0 db 10010010b db 11001111b db 0 gdt_end gdt_desc: db gdt_end - gdt dw gdt Please, what is wrong? |
Author: | Schol-R-LEA [ Mon Sep 10, 2018 1:25 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
If you don't mind me asking, did you ever set up a public repo for your project, as I recommended some time back? If you have, you could post a link to the repo so we can review the code without you having to post large sections of it here. |
Author: | MichaelPetch [ Mon Sep 10, 2018 2:06 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Code: gdt_desc: should be:db gdt_end - gdt dw gdt Code: gdt_desc: dw gdt_end - gdt - 1 dd gdt The size is a word (not byte) and the address is a dword and not a word. The GDT size should also have 1 subtracted from it. |
Author: | Klakap [ Tue Sep 11, 2018 9:25 am ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Thank you, GDT is load correctly. But interrupts doesnt work . |
Author: | Ender [ Wed Sep 12, 2018 8:11 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Klakap wrote: Thank you, GDT is load correctly. But interrupts doesnt work . Did you attempt to set up an IDT as well? |
Author: | Klakap [ Thu Sep 13, 2018 12:20 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Yes, while I have not used grub(I worked in the QEMU -kernel) IDT worked well. My code is at https://github.com/Klaykap/LightningOS/issues/2. |
Author: | MichaelPetch [ Thu Sep 13, 2018 2:23 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Klakap wrote: Yes, while I have not used grub(I worked in the QEMU -kernel) IDT worked well. My code is at https://github.com/Klaykap/LightningOS/issues/2. I see some issues with random snippets of code, but not the code to your entire project. |
Author: | Klakap [ Sat Sep 15, 2018 11:29 am ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Oh, there is my code in assember https://github.com/Klaykap/LightningOS/issues/4 |
Author: | MichaelPetch [ Sat Sep 15, 2018 12:31 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
You are probably new to github. You shouldn't be putting your files into issues. You should be uploading them into the code repository.Also helps if you provide any shells scripts / makefiles / linker scripts you are using as well to build your kernel. |
Author: | pvc [ Sat Sep 15, 2018 1:02 pm ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
I am not sure if that's the main problem but I see that you're missing segment register setup after loading new GDT in start. First: Code: xor ax, ax mov ds, ax It makes DS register set to 0 which is invalid in protected mode (loading null segment selector). Second: You need to fix up CS register after loading new GDT. You do that by performing a far jump. Something like that: Code: ... lgdt [gdt_desc] jmp 0x0008:fix_cs ; 0x0008 is just an example but should work with your GDT fix_cs: ... Third: Just after fix_cs you should put new values in other segment registers To summarize. Your start function should look more like this: Code: start: cli ;block interrupts ;we must load gdt lgdt [gdt_desc] jmp 0x0008:fix_cs fix_cs: mov ax, 0x0010 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax mov esp, stack_space ;set stack pointer call kmain jmp $ ;halt the CPU Using interrupts involves pushing and popping CS register on the stack. QEMU internal loader uses 0x08 for code and 0x10 for data segment selector values. While GRUB uses 0x10 for code and 0x18 for data (at least in versions I've dealt with). With that in mind, think what would happen after returning from ISR. At entry CPU pushed current CS value on the stack (which is 0x10 for GRUB). Then it did it's thing and tried to pop CS register (again 0x10 for GRUB). But in your new GDT 0x10 is DATA!! segment selector. And these can't be loaded into CS. |
Author: | Klakap [ Mon Sep 17, 2018 11:10 am ] |
Post subject: | Re: Interrupts doesnt work in GRUB |
Very thank for replies! When I set up gdt with your code, interrupts works! |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |