OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 1:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Interrupts doesnt work in GRUB[solved]
PostPosted: Tue Sep 04, 2018 9:06 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
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?

_________________
https://github.com/VendelinSlezak/BleskOS


Last edited by Klakap on Mon Sep 17, 2018 11:11 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Tue Sep 04, 2018 11:03 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Mon Sep 10, 2018 11:51 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
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?

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Mon Sep 10, 2018 1:25 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Mon Sep 10, 2018 2:06 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
Code:
gdt_desc:
   db gdt_end - gdt
   dw gdt
should be:
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Tue Sep 11, 2018 9:25 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Thank you, GDT is load correctly. But interrupts doesnt work :( .

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Wed Sep 12, 2018 8:11 pm 
Offline
User avatar

Joined: Thu Jul 19, 2018 9:40 pm
Posts: 24
Klakap wrote:
Thank you, GDT is load correctly. But interrupts doesnt work :( .

Did you attempt to set up an IDT as well?


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Thu Sep 13, 2018 12:20 pm 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
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.

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Thu Sep 13, 2018 2:23 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Sat Sep 15, 2018 11:29 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Oh, there is my code in assember https://github.com/Klaykap/LightningOS/issues/4

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Sat Sep 15, 2018 12:31 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Sat Sep 15, 2018 1:02 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
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.


Top
 Profile  
 
 Post subject: Re: Interrupts doesnt work in GRUB
PostPosted: Mon Sep 17, 2018 11:10 am 
Offline
Member
Member

Joined: Sat Mar 10, 2018 10:16 am
Posts: 296
Very thank for replies! When I set up gdt with your code, interrupts works!

_________________
https://github.com/VendelinSlezak/BleskOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 205 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group