Tutorial 15: Errors, Exceptions, Interruptions

Announcements, Test requests, Job openings, Updates, or just make your web site known to everyone!

Moderator: Moderators

Tutorial 15: Errors, Exceptions, Interruptions

Postby Mike » Thu Feb 14, 2008 9:43 pm

Hey everyone,

Tutorial 15 is planned for release this weekend. Its another fairly large tutorial that covers:<ul><li>Error Handling</li><li>Exception Handling</li><li>IRs, IRQs, ISRs</li><li>Gates: Traps, Interrupts, Tasks</li><li>IDTs and IVTs</li><li>IDTR processor register</li><li>LIDT and SIDT instructions</li><li>FLIHs and SLIHs</li><li>How interrupts work, stack, error codes</li><li>Developing a kernel panic error screen. ie, BSoD</li></ul>The tutorial itself is now completed. The demo should be completed either today or tomorrow, and will be uploaded with the tutorial.

After this tutorial, we should no onger see triple faults, and will be able to re-enable interrupts in protected mode.

Its going to be fun... ;)

*edit: Fixed formatting
Last edited by Mike on Sun Feb 17, 2008 3:22 am, edited 1 time in total.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby juFo » Sat Feb 16, 2008 1:47 pm

nice :D
juFo
 
Posts: 14
Joined: Sat Feb 02, 2008 1:41 pm

Postby pathos » Tue Mar 11, 2008 1:39 pm

Any news on when the demo will be up?
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Postby Mike » Wed Mar 12, 2008 3:52 am

pathos wrote:Any news on when the demo will be up?


I was hoping alot sooner, but we ran into a pretty nasty bug in the kernel that prevented us to continue.

The problem was with random instructions getting executed before the kernel do to global data being placed by MSVC++ before our entry point (but still at base 1MB). This caused odd global and static variable issues as it would cause the kernel to crash, before it even gets executed.

Here is the new Stage 3 for the stage 2 bootloader that should fix this, and possible future problems. All tutorials will be updated with this, and it seems to execute the entry routine flawlessly without error. ...And, of course, fixes the above problem ;)

Code: Select all
   ;---------------------------------------;
   ;   Execute Kernel         ;
   ;---------------------------------------;

   mov   ebx, [0x100000+60]      ; e_lfanew is a 4 byte offset address of the PE header; it is 60th byte.
   add   ebx, 0x100000         ; Add base address. EBX now points to file sig (PE00)

   ; jump over to optional header (Although it isnt optional o.0 )

   add   ebx, 24
   mov   eax, [ebx]         ; _IMAGE_FILE_HEADER is 20 bytes + size of sig (4 bytes)

   add   ebx, 20            ; address of entry point

   mov   ebp, dword [ebx]   ; get entry point offset in code section   
   add ebp, 0x100000      ; add image base

   jmp   ebp               ; Execute Kernel
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby pathos » Wed Mar 12, 2008 1:41 pm

Thanks for the update =)
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Postby Mike » Thu Mar 13, 2008 1:35 am

pathos wrote:Thanks for the update =)


The next demo will be up soon. It is fairly complex at the moment as it abstracts hardware dependencies behind the HAL, installs a new GDT for the HAL/Kernel to manage, and will, of course, be setting up a good IDT interface as well for the kernel to use.

We are able to set a new gdt without any need for far jumping, so we can do everything using inline assembly.

I will be covering the code a little bit in the tutorial when it is updated, but most of it should not be too hard. It (Hopefully) will be uploaded within the next week or so.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby Mike » Thu Mar 13, 2008 3:08 am

The idt interface I am developing is pretty cool. It allows us to register our own callback handlers that are called automatically whenever an interrupt is fired.

Because the idt implementation also installs its own default handlers, we will only need to install our own handlers when needed. Any other INT that is generated that we have not set a handler for will be handled by the idt code automatically.

Ill explain how everything works in the tutorial...
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby Mike » Fri Mar 14, 2008 2:06 am

The demo is now planned to be uploaded this weekend. Everything is good, we are now finalizing the demo.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby pathos » Fri Mar 14, 2008 1:35 pm

Mike wrote:The demo is now planned to be uploaded this weekend. Everything is good, we are now finalizing the demo.


Awesome. I look forward to it.
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Postby dev » Thu Mar 20, 2008 6:09 am

Mike wrote:The demo is now planned to be uploaded this weekend. Everything is good, we are now finalizing the demo.

How's the demo coming along?
User avatar
dev
 
Posts: 3
Joined: Fri Jan 11, 2008 7:32 am

Postby Mike » Fri Mar 21, 2008 3:02 am

dev wrote:
Mike wrote:The demo is now planned to be uploaded this weekend. Everything is good, we are now finalizing the demo.

How's the demo coming along?


Everything is already completed. I have not had much time this week to upload it :( Thanks to the weekend, it will be up tomorrow.

The next tutorial in the main series (Tutorial 16) integrates the 8259A PIC and 8253 PIT into the HAL. Because we are handling hardware interrupts in the next demo, we may also create a simple debugging command shell. We shall see...

Tutorial 17, We are thinking about implementing memory management, and programming the MMU, paging, perhaps loading the kernel to a 3GB virtual address space. We are still deciding everything though.

Cant wait 'til tomorrow :D
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby pathos » Wed Apr 02, 2008 8:02 pm

I've been busy the past few weeks with work and other projects, but I finally got a chance to dip into the latest demo this morning and check it out.

Everything's looking good, and I can't wait to handle hardware interrupts in the next demo!
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Postby pathos » Fri Apr 04, 2008 5:42 pm

Two quick questions.

First, when I go and write my own IRs, is there a way to get the address where the exception occured so I can display it with my handler?

Second, with the Tutorial 15 setup, I remapped my PIC, but my hardware interrupts are only firing once. Any thoughts why?
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Postby Mike » Sat Apr 05, 2008 3:24 am

pathos wrote:First, when I go and write my own IRs, is there a way to get the address where the exception occured so I can display it with my handler?

Sometimes the processor will push cs:eip on the stack when the exception fires. This depends on the exception, though. (Fault handlers are not guaranteed to push anything on the stack as the software is not expected to continue.)

Under the section Inside of our interrupt handler contains the basic stack frame when the interrupt is fired. Just offset into esp to get the information you need.

For an example, assuming the INT pushes an error code, offset 4 bytes into esp to get eip:
Code: Select all
; get eip of faulting instruction
mov  eax, dword [esp+4]

; stores faulting instruction opcode into eax
mov  edx, dword [eax]

(Hm... That stack frame does not include everything pushed by the cpu. I will see if I can add to that section)

pathos wrote:Second, with the Tutorial 15 setup, I remapped my PIC, but my hardware interrupts are only firing once. Any thoughts why?

Hm... We might need to see how you have set everything up to answer that one. I assume you enabled hardware interrupts (sti instruction)?

What hardware interrupts have you tried?
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Postby pathos » Sun Apr 06, 2008 12:19 am

Mike wrote:Hm... We might need to see how you have set everything up to answer that one. I assume you enabled hardware interrupts (sti instruction)?

What hardware interrupts have you tried?


Thanks for the reply. The interrupts I have tried is 0 and 1 for the timer and the keyboard. The keyboard never fires, because the timer goes first, and then they all stop. However, I disabled all IRQs once except the one for the keyboard, and then it let me hit one key, then they all stopped.

Yes, I did use sti.

I don't have my code on this computer, but all it is is tutorial 15 + the information from your PIC tutorial to remap the PIC + writing the timer handler and the keyboard handler to IRs 32 and 33. My timer and keyboard code isn't the problem though because I tried setting the handlers to just a simple handler to print some text, and it still only triggers once.

[edit]
I'll try to give a bit more information.
After the HAL is initialized, I remap the PIC, then set the the timer and keyboard to their respective IRs, then I use sti. I commented out the asm code in kmain() before "for(;; );" because it was clearing interrupts and I didn't know if that was the problem. I've moved sti around to see if that helped (like before I set the handlers), but still no luck.

[edit x2]
As it turns out, this is affecting all my interrupts. For example, I forced a divide by zero exception. The handler fired. Then I tried another one right behind it, and the handler didn't fire. At first I thought maybe the system was halting after each interrupts, but I placed some DebugPrintf messages after where I forced the exception, and they displayed. So it seems my interrupts are getting disabled all together.

[edit x3]
Just wanted to point out one more thing. When I use geninterrupt(0), it takes me to the default handler; however, if I use _asm int 0, it takes me to my interrupt 0 handler.

[edit x4]
This pertains to the geninterrupt problem. It works (as in, it triggers the right handler), but immediately after it generates an invalid opcode exception.

[edit x5]
Hardware interrupt problem solved. I put "_asm cli;" at the beginning of my handler and "outportb(0x20,0x20); _asm sti;" at the end, and it works now. However, I'm still having an issue with firing the same software interrupt back-to-back.
pathos
Moderator
 
Posts: 97
Joined: Thu Jan 10, 2008 6:43 pm
Location: USA

Next

Return to Your Announcements

Who is online

Users browsing this forum: No registered users and 1 guest

cron