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

isr

Post by mobruan »

Hi, why this code didnt work? It supposed to interrupt and print a 'a' on the screen.
thanks

mov ax, 0x07c0
mov ds, ax

mov ax, 0x07c0 ;selector
mov [36], word ax
lea ax, [isr] ;offset
mov [38], word ax

mov [12], word 255 ; lidt limit
mov [14], word 0 ; start of idt
mov [16], word 0

lidt [12]

int 9 ; interrupt

jmp $

isr:
mov ax, 0xb800
mov ds, ax

mov [0x0000], byte 0x61 ;print 'a'
mov [0x0001], byte 01110010b
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: isr

Post by Combuster »

You're not writing to the IVT, but to some random place in your code.
"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 ]
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: isr

Post by CodeCat »

I assume you're using real mode here, so why exactly are you using 'lidt'? I thought the idt was hardwired at address 0 in real mode.

And you also need an 'iret' at the end of your isr.
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: isr

Post by mobruan »

Hi, i dont understood combuster.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: isr

Post by neon »

Hi, i dont understood combuster.
The current data segment that is being used is 0x7c0, but the ivt is at address 0. You need to use a null segment when writing the interrupt entry in the ivt in order for your code to work.

Also, your use of LIDT is error prone here and not needed.
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: isr

Post by mobruan »

I do the following and the computer resets:

mov ax, word 0x0000
mov ds, ax

mov ax, 0x07c0
mov [36], word ax
lea ax, [isr]
mov [38], word ax

int9

jmp $

isr:
mov ax, 0xb800
mov ds, ax

mov [0x0000], byte 0x61
mov [0x0001], byte 01110010b

jmp $
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: isr

Post by ru2aqare »

It should be

Code: Select all

mov ax, 0x07c0
mov [9*4+2], word ax
lea ax, [isr]
mov [9*4+0], word ax
The point is that in real mode, a far address is specified as a segment-offset pair, and the offset goes to [address+0], segment goes to [address+2].
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: isr

Post by mobruan »

Thanks a lot, it work!
I was inverting the order of the offset and selector.
Post Reply