protected mode isr

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

protected mode isr

Post by mobruan »

Hi, im sing the code neon corrected to go into protected. After i put some apic code referencing vector 1 - keyboard to generate a interrupt, and finally a isr who write on screen.
The code is without error but dont print on the screen. Any ideias?

bits 16
org 0x7c00

jmp main

main:

mov ax, word 0x0000
mov ds, ax

mov ax, word isr
mov [2008], word ax
mov [2010], word 0x8
mov [2012], word 1000111000000000b ; interrupt descriptor
mov [2014], word 0x0000

mov [2016], word 255
mov [2018], word 2000
mov [2020], word 0


mov [528], word 0xffff
mov [530], word 0x0000
mov [532], byte 0x00
mov [533], byte 0x9a
mov [534], byte 0xcf
mov [535], byte 0x00

mov [536], word 0xffff
mov [538], word 0x0000
mov [540], byte 0x00
mov [541], byte 0x92
mov [542], byte 0xcf
mov [543], byte 0x00

mov [1000], word 23
mov [1002], word 520
mov [1004], word 0x0000

cli
lgdt [1000]
mov eax,cr0
or al,0x01
mov cr0,eax

jmp 8:pm

jmp $

bits 32

pm:

mov ax, 8*2
mov ds,ax


lidt [2016]

mov eax, 0x12
mov [0xfec00000], dword eax
mov [0xfec00010], dword 0x00000001 ;apic

mov eax, 0x13
mov [0xfec00000], dword eax ;apic -
mov [0xfec00010], dword 0x00000000

jmp $

isr:

mov [0xb8000], byte 'A'
mov [0xb8001], byte 0x17
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: protected mode isr

Post by Combuster »

Neon also told you to rewrite that code. I can't read this, let alone figure what it does or is meant to do.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: protected mode isr

Post by neon »

I hope that is not the complete code. If it is, it will triple fault when the ISR is called because you are not returning from it.

If this is a hardware interrupt, you need to enable interrupts first (STI instruction). Make sure you have mapped the PIT to a valid int handler first though.

Lastly, if this is a 1st stage boot loader, keep in mind that you are limited to 512 bytes. The assembler wont tell you, so if you go beyond 512 bytes you will run into problems.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: protected mode isr

Post by mobruan »

hi, whats PIT?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: protected mode isr

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: protected mode isr

Post by mobruan »

why i need to remap pit?
thanks
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: protected mode isr

Post by AJ »

I think that was a typo - he meant PIC.

Cheers,
Adam
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: protected mode isr

Post by neon »

I think that was a typo - he meant PIC
You are right--I was thinking PIT (Because it uses IRQ 0), but you need to map the PIC. Thanks for the correction :)
why i need to remap pit?
If you want hardware exceptions enabled, and the PIC IRQ0 isnt mapped to use a valid IRQ handler defined by you, then almost as soon as you enable hardware interrupts, IRQ 0 will fire and execute invalid code.

Thus, you need to remap the PICs to use a valid base IRQ address in your IDT and define interrupt handlers for them. Search the Wiki or Google...there are alot of good info on the PIC.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply