flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Questions about processor IRQ

Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
Hello, i have questions about IDT and 32 first entries. 0x0 to 0x07 entries are for processor interrupt.

Is it possible to code him for return just message error ? And eventually do something when an error occurred ?

My second question: i have the best way to test if CPUID is present is to test if there is invalid opcode error when i execute cpuid. But how to catch him ? With IRQ ?
Post 31 Mar 2020, 10:08
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
I have performed that. It's work.
But i would like to alert my code when this error occured to do something else. I have tested to move byte stored into label address to indicate actual state error, but it don't work... How can i do that ?

Code:
format binary as "img"

use16
org 0x7C00

cli
lgdt [GDTR]

mov eax,cr0
or eax,0x1
mov cr0,eax

jmp 0x8:ProtectedMode

use32

ProtectedMode:
.Initialize:
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
lidt [IDTR]
sti

xor bx,bx
div bx

Main:
hlt
jmp Main

include "IDT.fasm"

GDT: db 0, 0, 0, 0, 0, 0, 0, 0
GDTCS: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10011011b, 11011111b, 0x0
GDTDS: db 0xFF, 0xFF, 0x0, 0x0, 0x0, 10010011b, 11011111b, 0x0
@@:

GDTR:
dw @b-GDT-1
dd GDT

IDTR:
.limit: dw @f-IDTDescriptor-1
.base: dd IDTDescriptor

IDTDescriptor:
.idt0: dw IDT.idt0,0x8,0x8E00,0x0
.idt1: dw IDT.idt1,0x8,0x8E00,0x0
.idt2: dw IDT.idt2,0x8,0x8E00,0x0
.idt3: dw IDT.idt3,0x8,0x8E00,0x0
.idt4: dw IDT.idt4,0x8,0x8E00,0x0
.idt5: dw IDT.idt5,0x8,0x8E00,0x0
.idt6: dw IDT.idt6,0x8,0x8E00,0x0
.idt7: dw IDT.idt7,0x8,0x8E00,0x0
.idt8: dw IDT.idt8,0x8,0x8E00,0x0
.idt9: dw IDT.idt9,0x8,0x8E00,0x0
.idt10: dw IDT.idt10,0x8,0x8E00,0x0
.idt11: dw IDT.idt11,0x8,0x8E00,0x0
.idt12: dw IDT.idt12,0x8,0x8E00,0x0
.idt13: dw IDT.idt13,0x8,0x8E00,0x0
.idt14: dw IDT.idt14,0x8,0x8E00,0x0
.idt15: dw IDT.idt15,0x8,0x8E00,0x0
.idt16: dw IDT.idt16,0x8,0x8E00,0x0
.idt17: dw IDT.idt17,0x8,0x8E00,0x0
.idt18: dw IDT.idt18,0x8,0x8E00,0x0
.idt19: dw IDT.idt19,0x8,0x8E00,0x0
.idt20: dw IDT.idt20,0x8,0x8E00,0x0
.idt21: dw IDT.idt21,0x8,0x8E00,0x0
.idt22: dw IDT.idt22,0x8,0x8E00,0x0
.idt23: dw IDT.idt23,0x8,0x8E00,0x0
.idt24: dw IDT.idt24,0x8,0x8E00,0x0
.idt25: dw IDT.idt25,0x8,0x8E00,0x0
.idt26: dw IDT.idt26,0x8,0x8E00,0x0
.idt27: dw IDT.idt27,0x8,0x8E00,0x0
.idt28: dw IDT.idt28,0x8,0x8E00,0x0
.idt29: dw IDT.idt29,0x8,0x8E00,0x0
.idt30: dw IDT.idt30,0x8,0x8E00,0x0
.idt31: dw IDT.idt31,0x8,0x8E00,0x0
.idt32: dw IDT.idt32,0x8,0x8E00,0x0
@@:

db 510-($-$$) dup 0x90
dw 0xAA55
    


Code:
IDT:
.idt0:
mov byte [0xB8000],'*'
mov byte [0xB8001],00000010b
mov byte [0xB8002],' '
mov byte [0xB8003],00000111b
mov byte [0xB8004],'Z'
mov byte [0xB8005],00000111b
mov byte [0xB8006],'e'
mov byte [0xB8007],00000111b
mov byte [0xB8008],'r'
mov byte [0xB8009],00000111b
mov byte [0xB800A],'o'
mov byte [0xB800B],00000111b
iret
.idt1: iret
.idt2: iret
.idt3: iret
.idt4: iret
.idt5: iret
.idt6: iret
.idt7: iret
.idt8: iret
.idt9: iret
.idt10: iret
.idt11: iret
.idt12: iret
.idt13: iret
.idt14: iret
.idt15: iret
.idt16: iret
.idt17: iret
.idt18: iret
.idt19: iret
.idt20: iret
.idt21: iret
.idt22: iret
.idt23: iret
.idt24: iret
.idt25: iret
.idt26: iret
.idt27: iret
.idt28: iret
.idt29: iret
.idt30: iret
.idt31: iret
.idt32: iret    
Post 31 Mar 2020, 12:04
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
try to lidt [IDTR] before pm switch. right after lgdt [GDTR] in the real mode code section.
plus, where do you execute code able to generate the isr0 routine?

you also have to reprogram the pic in order to don't conflicts with cpu irq.
Post 31 Mar 2020, 13:17
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
My code work, he generate int 0 routine, but if i code some code to save state into some data byte, he don't work.

Generated division zero error:
Code:
xor bx,bx
div bx    


If i had something that:
Code:
BoleanErrorByte: db 0x0    


And add this instruction into my 0 IDT entry:
Code:
mov byte [BoleanErrorByte],0x1    

This doesn't work, my byte isn't changed. But i would like to send change when this error occurred...
Post 31 Mar 2020, 14:13
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
where is located the BoleanErrorByte variable?
where is it in source?
Post 31 Mar 2020, 15:48
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
It's an example, i have removed it because nothing append...
Post 31 Mar 2020, 15:54
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 317
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
You must init new stack pointer in esp (not only ss). You also need this code:
Code:
macro   Delay
{
times 3 jmp     short $+2
}

SetPIC: mov     al,11h
        out     20h,al
        Delay
        out     $A0,al
        mov     al,bl
        Delay
        out     21h,al
        mov     al,bh
        Delay
        out     $A1,al
        mov     al,04h
        Delay
        out     21h,al
        mov     al,02h
        Delay
        out     $A1,al
        mov     al,01h
        Delay
        out     21h,al
        Delay
        out     $A1,al
        ret    

Copy this code below after LGDT instruction.
Code:
        mov     bl,20h  ;Master IRQ 32..39 (20h..27h)
        mov     bh,28h  ;Slave IRQ 40..47 (28h..2Fh)
        call    SetPIC    

Code:
.idt32:
.idt33:
.idt34:
.idt35:
.idt36:
.idt37:
.idt38:
.idt39:
        push    ax
        mov     al,20h
        out     0x20,al
        pop     ax
        iret

.idt40:
.idt41:
.idt42:
.idt43:
.idt44:
.idt45:
.idt46:
.idt47:
        push    ax
        mov     al,20h
        out     0x20,al
        out     0xA0,al
        pop     ax
        iret    

_________________
smaller is better
Post 31 Mar 2020, 16:30
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
In fact, if i understand good, i need to pass interrupt output into stack ? But how can i notify to my system interrupt have added something into stack ? I don't undertand
Post 31 Mar 2020, 19:28
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 317
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
You must set the top of the stack. Add only instructions:
Code:
mov ss,ax
StackSize = 1024
mov esp,7C00h+StackSize    

You must also define which interrupts will be IRQ (by default they are 0x8 for master and 0x70 for slave). Because the first 32 interrupts in IDT are reserved for exceptions, to prevent conflicts (so that they do not repeat/overlap) you need to set them to e.g. 20h for master and 28h for slave.

_________________
smaller is better
Post 31 Mar 2020, 21:35
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 200
Fulgurance
What ? Shocked
I don't understand what you would like to do...
Post 31 Mar 2020, 21:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.