Interrupts doesnt work in GRUB[solved]
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?
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?
Last edited by Klakap on Mon Sep 17, 2018 11:11 am, edited 1 time in total.
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
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.
That is just a guess, but it could be something else, but without more information/code it is hard to tell.
Re: Interrupts doesnt work in GRUB
When I tried to set up the GDT, the linker gave me error:
This is my code:
Please, what is wrong?
Code: Select all
compile/kasm.o: In function `gdt_end':
kernel.asm:(.text+0x45): relocation truncated to fit: R_386_16 against `.text'
Code: Select all
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
- Schol-R-LEA
- Member
- Posts: 1925
- Joined: Fri Oct 27, 2006 9:42 am
- Location: Athens, GA, USA
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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: Interrupts doesnt work in GRUB
Code: Select all
gdt_desc:
db gdt_end - gdt
dw gdt
Code: Select all
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
Re: Interrupts doesnt work in GRUB
Thank you, GDT is load correctly. But interrupts doesnt work .
Re: Interrupts doesnt work in GRUB
Did you attempt to set up an IDT as well?Klakap wrote:Thank you, GDT is load correctly. But interrupts doesnt work .
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.
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
Re: Interrupts doesnt work in GRUB
I see some issues with random snippets of code, but not the code to your entire project.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.
Re: Interrupts doesnt work in GRUB
Oh, there is my code in assember https://github.com/Klaykap/LightningOS/issues/4
-
- Member
- Posts: 799
- Joined: Fri Aug 26, 2016 1:41 pm
- Libera.chat IRC: mpetch
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.
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:
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:
Third: Just after fix_cs you should put new values in other segment registers
To summarize. Your start function should look more like this:
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.
First:
Code: Select all
xor ax, ax
mov ds, ax
Second:
You need to fix up CS register after loading new GDT. You do that by performing a far jump. Something like that:
Code: Select all
...
lgdt [gdt_desc]
jmp 0x0008:fix_cs ; 0x0008 is just an example but should work with your GDT
fix_cs:
...
To summarize. Your start function should look more like this:
Code: Select all
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
Re: Interrupts doesnt work in GRUB
Very thank for replies! When I set up gdt with your code, interrupts works!