OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Oct 22, 2019 12:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: OS get frozen when installing IDT
PostPosted: Fri Jan 25, 2019 6:52 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Location: Chile
Hello again, I've been coding an IDT, ISR and an IRQ. But when the IDT is installed, my OS is frozen.
I've been following this tutorial to do it: http://www.osdever.net/bkerndev/Docs/idt.htm
Here's an extract of kmain.c:
Code:
    idt_install(); // <- Gets stuck here
    isrs_install();
    irq_install();
    __asm__ __volatile__ ("sti");
    init_serial();
    init_video();

Here is the complete code of my OS: https://gitlab.com/hextakatt/experimentalos
Please be patient, especially with my horrible code. ;)


Top
 Profile  
 
 Post subject: Re: OS get frozen when installing IDT
PostPosted: Fri Jan 25, 2019 8:06 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 488
At first glance. In boot2.asm you have this:
Code:
bits 16
%include "gdt.inc"
%include "a20.inc"
%include "idt.inc"
idt.inc is being included under a bits 16 directive so everything in idt.inc will be encoded as 16-bit instructions (your idt.inc doesn't specify any bits directives so it takes on whatever bits directives were specified before it while being included in boot2.asm). That won't work when running in 32-bit protected mode. As an experiment what happens if you do:
Code:
bits 16
%include "gdt.inc"
%include "a20.inc"
bits 32
%include "idt.inc"
bits 16
Preferably your INC files should be using the appropriate BITS directive.


Top
 Profile  
 
 Post subject: Re: OS get frozen when installing IDT
PostPosted: Fri Jan 25, 2019 8:26 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Location: Chile
Oh, what a silly error I made!
Now works, but, seems that something is messing with my VRAM (the green dot):
Image
That green dot is not only green, it changes to all the 16 colors constantly (the entire ASCII charset that you see on the screen is not related, is intentionally produced by me)
Serial communication does not work, and ISR does not work, I tried to divide by zero, the ISR should trigger, which should make the screen appear "Division by zero", but that doesn't happen!


Top
 Profile  
 
 Post subject: Re: OS get frozen when installing IDT
PostPosted: Fri Jan 25, 2019 9:21 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 488
In idt,h you have:
Code:
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
{
   idt[num].base_lo = (unsigned char) (base & 0xFF);
   idt[num].base_hi = (unsigned char) ((base >> 16) & 0xFF);
   idt[num].sel = sel;
   idt[num].always0 = 0;
   idt[num].flags = flags;
}
It is unclear why you are casting to an unsigned char.lo and hi are unsigned shorts.You are alsomasking off too many bits with &0xff. Pretty sure you want 0xFFFFF. I think it should look like:
Code:
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
{
   idt[num].base_lo = (unsigned short) (base & 0xFFFF);
   idt[num].base_hi = (unsigned short) ((base >> 16) & 0xFFFF);
   idt[num].sel = sel;
   idt[num].always0 = 0;
   idt[num].flags = flags;
}
Your version is truncating the pointers to the interrupt handlers and sending the CPU off into neverland when interrupts occur. You may also wish to review the function irq_install. I don't believe the majority of the calls to idt_set_gate are using the correct first parameter.
I also have a recommendation. A serious one. You should stop including non static functions as code from in header files. Non static functions should be placed in separate .c files and you compile them just like you did with kmain.c and then you add the extra objects to your linker line.


Top
 Profile  
 
 Post subject: Re: OS get frozen when installing IDT
PostPosted: Sat Jan 26, 2019 9:50 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Location: Chile
Still working, but when I press a key, system crashes with General protection fault. I think that is some problem with the IDT again...
But for my surprise, my entire OS has no code of any keyboard communication! or drivers...


Top
 Profile  
 
 Post subject: Re: OS get frozen when installing IDT
PostPosted: Sat Jan 26, 2019 9:56 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 488
I mentioned (a hint) in my previous comment about irq_install routine? You happened to map most of the IRQs to a single vector.
Code:
idt_set_gate(32, (unsigned)irq0, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq1, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq2, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq3, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq4, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq5, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq6, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq7, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq8, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq9, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq10, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq11, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq12, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq13, 0x08, 0x8E);
    idt_set_gate(32, (unsigned)irq14, 0x08, 0x8E);
    idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E);
Notice how the first parameter is all 32 except for the last one. IMHO They should be numbered 32 through 47. You've effectively overwritten entry 32 many times leaving most interrupts with no valid interrupt handler. Effectively iRQ1 through IRQ14 will fault when they occur. IRQ1 is the keyboard handler. IRQ0 and IRQ15 won't fault because they were actually initialised.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], yanayg and 9 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