flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Keyboard Interrupt Problem

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Hey,

I've dug up some old IDT, ISR, & IRQ code I had written a while back (and formatted it to my current style of coding, and have mixed it in with my new project. However, for some reason the input doesn't want to work correctly.

Here's some code if anyone's willing to help tackle it:

os1.bin code
Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 0Ah
mov cl, 02h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0000h:0600h

times 510-($-$$) db 0
dw 0AA55h

org 0600h
Begin:
;push cs
;push cs
;pop ds
;pop ss
mov ax, 0
mov ds, ax
mov ss, ax

; Used for testing.
;pop cs
;pop ax
;mov bx, 0B800h
;mov es, bx
;xor bx, bx
;sub al, '0'
;mov [es:bx], al

jmp Start

; Data Goes Here
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
use32
Start32:
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx
mov esp, 90000h

; Move video memory into EBX
mov eax, 0B8000h

; Load a smiley into video memory!
mov bx, 0201h
mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

; Reroute PICS so that an exception doesn't occur every time an interrupt is called!
call Reroute_PICs

; Load Interrupt Descriptor Table
lidt [idtp]

; Enable Interrupts! =D
sti

;int 21h
;cmp al, 1Ch
;je Smiley

call CmdPrintFunc

Hang:
jmp Hang

Smiley:
mov eax, 0B8000h
mov bx, 0201h
mov word [ds:eax], bx
ret

include "interrupts.inc"
;times 1474560-512-($-$$) db 0
    


interrupts.inc
Code:
;INTERRUPTS!!! YAY

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

;Side data for PrintF
TxtClr db 2

Done2:
        ret

ClrScrn:
        mov ax, 10h
        mov ds, ax
        mov ebx, 0B8000h
        mov ax, 0
        clrloop:
                cmp ax, 2000
                je Done2
                mov byte [ds:ebx], ' '
                inc ebx
                mov byte [ds:ebx], 1Bh
                inc ebx
                inc ax
                jmp clrloop

CmdPrintFunc:
        mov ax, 10h
        mov es, ax
        mov edi, 0B8000h
        xor eax, eax
        cmdloop:
                int 21h
                cmp al, 1Ch
                je Done2
                mov esi, eax
                mov cl, [esi+KeyBoard]
                mov byte [es:edi],cl
                inc edi
                mov byte [es:edi], 02h
                inc edi
                jmp cmdloop

Reroute_PICs:
        ;send ICW1(Interrupt Control Word1)
        mov al, 11h
        ;out PIC1, ICW1
        out 20h, al
        ;out PIC2 ICW1
        out 0A0h, al

        ;send ICW2
        mov al, 20h
        ;out PIC1 + 1, IRQ0 start point
        out 21h, al
        mov al, 28h
        ;out PIC2 + 1, IRQ8 start point
        out 0A1h, al

        ;send ICW3
        ;IRQ2 to Connection to Slave PIC
        mov al, 04h
        out 21h, al
        mov al, 02h
        out 0A1h, al

        ;send ICW4
        mov al, 01h
        out 21h, al
        out 0A1h, al

        ;disable IRQs
        mov al, 0FFh
        out 0A1h, al
        out 021h, al
        ret

isr0:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err00
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr1:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err01
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr2:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err02
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr3:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err03
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr4:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err04
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr5:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err05
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr6:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err06
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr7:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err07
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr8:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err08
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr9:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err09
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr10:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err10
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr11:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err11
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr12:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err12
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr13:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err13
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr14:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err14
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr15:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err15
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr16:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err16
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr17:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err17
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr18:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err18
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr19:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr20:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr21:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr22:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr23:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr24:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr25:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr26:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr27:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr28:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr29:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr30:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr31:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

irq0:
        mov si, TimerEnabled
        call PrintF
        mov al, 20h
        out 20h, al
        iret

irq1:
        pushad
        push es
        push ds

        in al, 60h
        mov byte [ScanCode], al

        mov al, 20h
        out 20h, al

        pop ds
        pop es
        popad
        mov al, byte [ScanCode]
        iret

idt_start:

        ;Interrupt Example
        ; dw start_address
        ; dw code_selector where ISR is being held
        ; dw type_settings for ISRs
        ; dw start_address2(bits 31-16)
        ; start_address2 should be 0 because the
        ; start address should be no more than 1
        ; word value.


        ;FOR HISTORIC REFERENCE PURPOSES ONLY
        ;Original ISRS looked like the following
        ;
        ;dw 0h000
        ;dw 0h8
        ;dw 8E00h
        ;dw 0h8
        ;
        ;END OF HISTORIC REFERENCE

        ;SERVICE REQUEST INTS
        ;int0
        dw isr0
        dw 08h
        dw 8E00h
        dw 0h
        ;int1
        dw isr1
        dw 08h
        dw 8E00h
        dw 0h
        ;int2
        dw isr2
        dw 08h
        dw 0E00h
        dw 0h
        ;int3
        dw isr3
        dw 08h
        dw 8E00h
        dw 0h
        ;int4
        dw isr4
        dw 08h
        dw 8E00h
        dw 0h
        ;int5
        dw isr5
        dw 08h
        dw 8E00h
        dw 0h
        ;int6
        dw isr6
        dw 08h
        dw 8E00h
        dw 0h
        ;int7
        dw isr7
        dw 08h
        dw 8E00h
        dw 0h
        ;int8
        dw isr8
        dw 08h
        dw 8E00h
        dw 0h
        ;int9
        dw isr9
        dw 08h
        dw 8E00h
        dw 0h
        ;int10
        dw isr10
        dw 08h
        dw 8E00h
        dw 0h
        ;int11
        dw isr11
        dw 08h
        dw 8E00h
        dw 0h
        ;int12
        dw isr12
        dw 08h
        dw 8E00h
        dw 0h
        ;int13
        dw isr13
        dw 08h
        dw 8E00h
        dw 0h
        ;int14
        dw isr14
        dw 08h
        dw 8E00h
        dw 0h
        ;int15
        dw isr15
        dw 08h
        dw 0E00h
        dw 0h
        ;int16
        dw isr16
        dw 08h
        dw 0E00h
        dw 0h
        ;int17
        dw isr17
        dw 08h
        dw 0E00h
        dw 0h
        ;int18
        dw isr18
        dw 08h
        dw 0E00h
        dw 0h
       ;int19
        dw isr19
        dw 08h
        dw 0E00h
        dw 0h
       ;int20
        dw isr20
        dw 08h
        dw 0E00h
        dw 0h
       ;int21
        dw isr21
        dw 08h
        dw 0E00h
        dw 0h
       ;int22
        dw isr22
        dw 08h
        dw 0E00h
        dw 0h
       ;int23
        dw isr23
        dw 08h
        dw 0E00h
        dw 0h
       ;int24
        dw isr24
        dw 08h
        dw 0E00h
        dw 0h
       ;int25
        dw isr25
        dw 08h
        dw 0E00h
        dw 0h
       ;int26
        dw isr26
        dw 08h
        dw 0E00h
        dw 0h
       ;int27
        dw isr27
        dw 08h
        dw 0E00h
        dw 0h
       ;int28
        dw isr28
        dw 08h
        dw 0E00h
        dw 0h
       ;int29
        dw isr29
        dw 08h
        dw 0E00h
        dw 0h
       ;int30
        dw isr30
        dw 08h
        dw 0E00h
        dw 0h
       ;int31
        dw isr31
        dw 08h
        dw 0E00h
        dw 0h

       ;HARDWARE INTERRUPT REQUESTS
       ;int32
        dw irq0
        dw 08h
        dw 8E00h
        dw 0h
       ;int33
        dw irq1
        dw 08h
        dw 8E00h
        dw 0h

idt_end:

idtp:
        dw idt_end - idt_start - 1
        dd idt_start

TimerEnabled db "Timer Interrupt Enabled!", 0
Err00 db "Error 00 - Division By Zero",0
Err01 db "Error 01 - Debug",0
Err02 db "Error 02 - Non Maskable Interrupt",0
Err03 db "Error 03 - Breakpoint Exception",0
Err04 db "Error 04 - Into Detected Overflow",0
Err05 db "Error 05 - Out of Bounds",0
Err06 db "Error 06 - Invalid Opcode",0
Err07 db "Error 07 - No Coprocessor",0
Err08 db "Error 08 - Double Fault",0
Err09 db "Error 09 - Coprocessor Segment Overrun",0
Err10 db "Error 10 - Bad TSS",0
Err11 db "Error 11 - Segment Not Present",0
Err12 db "Error 12 - Stack Fault",0
Err13 db "Error 13 - General Protection Fault",0
Err14 db "Error 14 - Page Fault",0
Err15 db "Error 15 - Unknown Interrupt",0
Err16 db "Error 16 - Coprocessor Fault",0
Err17 db "Error 17 - Alignment Check",0
Err18 db "Error 18 - Machine Check",0
ErrRes db "Error - Reserved",0

KeyBoard db 0, 0, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", 0, 0, "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", 0, 0, "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", 0, "\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", 0, "*", 0
ScanCode db 0
    


Any help would be greatly appreciated. Thanks!
Post 06 Nov 2007, 04:23
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Oh, and I forgot to mention that when I tried the bit of commented code in os1.asm (mistakenly typed up above as "os1.bin") to try to load the smiley after hitting the enter key utilizing interrupt 21h, it gave me a general protection fault error.
Post 06 Nov 2007, 04:25
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
Just a sugestion: I would add a cli/sti into your irq1,ect to stop ints until the ints are done also I would add a jmp $+2 into your reroute_pic....

iqr1:
cli
pusha

;//code

popa
sti
iret



Reroute_PIC:
;send ICW1(Interrupt Control Word1)
mov al, 11h
;out PIC1, ICW1
out 20h, al
;out PIC2 ICW1
out 0A0h, al
jmp $+2 ;;example

I tryed to compile your code to test:
I get an error:
out of stack space ????


also: from prev posts- I have read its not a good idea to use org multible times...
Post 06 Nov 2007, 08:13
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
This is strange... I looked at some of my old code and noticed I was missing a snippit from it, which I tried to copy over. It still doesn't work, and when I tried to call int 21h in my os1.asm text file, it gives a general protection fault error. However, whenever I try to call int 21h from the command line function, it calls the timer interrupt! Shocked

Something doesn't seem quite right with that...

Anyhoo, here's the most recent code:

os1.asm
Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 0Ah
mov cl, 02h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0000h:0600h

times 510-($-$$) db 0
dw 0AA55h

org 0600h
Begin:
;push cs
;push cs
;pop ds
;pop ss
mov ax, 0
mov ds, ax
mov ss, ax

; Used for testing.
;pop cs
;pop ax
;mov bx, 0B800h
;mov es, bx
;xor bx, bx
;sub al, '0'
;mov [es:bx], al

jmp Start

; Data Goes Here
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
use32
Start32:
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx
mov esp, 90000h

; Move video memory into EBX
mov eax, 0B8000h

; Load a smiley into video memory!
mov bx, 0201h
mov word [ds:eax], bx

; Print Welcome Message
mov si, WelcomeStr
call PrintF

; Reroute PICS so that an exception doesn't occur every time an interrupt is called!
call Reroute_PICs

; Load Interrupt Descriptor Table
lidt [idtp]

; Enable Interrupts! =D
push ax
mov al, 0
out 0A1h, al
out 21h, al
sti
pop ax

int 21h
;cmp al, 1Ch
;je Smiley

;call CmdPrintFunc

Hang:
jmp Hang

Smiley:
mov eax, 0B8000h
mov bx, 0201h
mov word [ds:eax], bx
ret

include "interrupts.inc"
;times 1474560-512-($-$$) db 0
    


interrupts.inc
Code:
;INTERRUPTS!!! YAY

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

;Side data for PrintF
TxtClr db 2

Done2:
        ret

ClrScrn:
        mov ax, 10h
        mov ds, ax
        mov ebx, 0B8000h
        mov ax, 0
        clrloop:
                cmp ax, 2000
                je Done2
                mov byte [ds:ebx], ' '
                inc ebx
                mov byte [ds:ebx], 1Bh
                inc ebx
                inc ax
                jmp clrloop

CmdPrintFunc:
        mov ax, 10h
        mov es, ax
        mov edi, 0B8000h
        xor eax, eax
        cmdloop:
                int 21h
                cmp al, 1Ch
                je Done2
                mov esi, eax
                mov cl, [esi+KeyBoard]
                mov byte [es:edi],cl
                inc edi
                mov byte [es:edi], 02h
                inc edi
                jmp cmdloop

Reroute_PICs:
        ;send ICW1(Interrupt Control Word1)
        mov al, 11h
        ;out PIC1, ICW1
        out 20h, al
        ;out PIC2 ICW1
        out 0A0h, al

        ;send ICW2
        mov al, 20h
        ;out PIC1 + 1, IRQ0 start point
        out 21h, al
        mov al, 28h
        ;out PIC2 + 1, IRQ8 start point
        out 0A1h, al

        ;send ICW3
        ;IRQ2 to Connection to Slave PIC
        mov al, 04h
        out 21h, al
        mov al, 02h
        out 0A1h, al

        ;send ICW4
        mov al, 01h
        out 21h, al
        out 0A1h, al

        ;disable IRQs
        mov al, 0FFh
        out 0A1h, al
        out 021h, al
        ret

isr0:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err00
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr1:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err01
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr2:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err02
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr3:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err03
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr4:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err04
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr5:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err05
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr6:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err06
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr7:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err07
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr8:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err08
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr9:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err09
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr10:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err10
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr11:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err11
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr12:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err12
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr13:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err13
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr14:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err14
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr15:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err15
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr16:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err16
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr17:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err17
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr18:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err18
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr19:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr20:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr21:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr22:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr23:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr24:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr25:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr26:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr27:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr28:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr29:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr30:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr31:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

irq0:
        mov si, TimerEnabled
        call PrintF
        mov al, 20h
        out 20h, al
        iret

irq1:
        pushad
        push es
        push ds

        in al, 60h
        mov byte [ScanCode], al

        mov al, 20h
        out 20h, al

        pop ds
        pop es
        popad
        mov al, byte [ScanCode]
        iret

idt_start:

        ;Interrupt Example
        ; dw start_address
        ; dw code_selector where ISR is being held
        ; dw type_settings for ISRs
        ; dw start_address2(bits 31-16)
        ; start_address2 should be 0 because the
        ; start address should be no more than 1
        ; word value.


        ;FOR HISTORIC REFERENCE PURPOSES ONLY
        ;Original ISRS looked like the following
        ;
        ;dw 0h000
        ;dw 0h8
        ;dw 8E00h
        ;dw 0h8
        ;
        ;END OF HISTORIC REFERENCE

        ;SERVICE REQUEST INTS
        ;int0
        dw isr0
        dw 08h
        dw 8E00h
        dw 0h
        ;int1
        dw isr1
        dw 08h
        dw 8E00h
        dw 0h
        ;int2
        dw isr2
        dw 08h
        dw 0E00h
        dw 0h
        ;int3
        dw isr3
        dw 08h
        dw 8E00h
        dw 0h
        ;int4
        dw isr4
        dw 08h
        dw 8E00h
        dw 0h
        ;int5
        dw isr5
        dw 08h
        dw 8E00h
        dw 0h
        ;int6
        dw isr6
        dw 08h
        dw 8E00h
        dw 0h
        ;int7
        dw isr7
        dw 08h
        dw 8E00h
        dw 0h
        ;int8
        dw isr8
        dw 08h
        dw 8E00h
        dw 0h
        ;int9
        dw isr9
        dw 08h
        dw 8E00h
        dw 0h
        ;int10
        dw isr10
        dw 08h
        dw 8E00h
        dw 0h
        ;int11
        dw isr11
        dw 08h
        dw 8E00h
        dw 0h
        ;int12
        dw isr12
        dw 08h
        dw 8E00h
        dw 0h
        ;int13
        dw isr13
        dw 08h
        dw 8E00h
        dw 0h
        ;int14
        dw isr14
        dw 08h
        dw 8E00h
        dw 0h
        ;int15
        dw isr15
        dw 08h
        dw 0E00h
        dw 0h
        ;int16
        dw isr16
        dw 08h
        dw 0E00h
        dw 0h
        ;int17
        dw isr17
        dw 08h
        dw 0E00h
        dw 0h
        ;int18
        dw isr18
        dw 08h
        dw 0E00h
        dw 0h
       ;int19
        dw isr19
        dw 08h
        dw 0E00h
        dw 0h
       ;int20
        dw isr20
        dw 08h
        dw 0E00h
        dw 0h
       ;int21
        dw isr21
        dw 08h
        dw 0E00h
        dw 0h
       ;int22
        dw isr22
        dw 08h
        dw 0E00h
        dw 0h
       ;int23
        dw isr23
        dw 08h
        dw 0E00h
        dw 0h
       ;int24
        dw isr24
        dw 08h
        dw 0E00h
        dw 0h
       ;int25
        dw isr25
        dw 08h
        dw 0E00h
        dw 0h
       ;int26
        dw isr26
        dw 08h
        dw 0E00h
        dw 0h
       ;int27
        dw isr27
        dw 08h
        dw 0E00h
        dw 0h
       ;int28
        dw isr28
        dw 08h
        dw 0E00h
        dw 0h
       ;int29
        dw isr29
        dw 08h
        dw 0E00h
        dw 0h
       ;int30
        dw isr30
        dw 08h
        dw 0E00h
        dw 0h
       ;int31
        dw isr31
        dw 08h
        dw 0E00h
        dw 0h

       ;HARDWARE INTERRUPT REQUESTS
       ;int32
        dw irq0
        dw 08h
        dw 8E00h
        dw 0h
       ;int33
        dw irq1
        dw 08h
        dw 8E00h
        dw 0h

idt_end:

idtp:
        dw idt_end - idt_start - 1
        dd idt_start

TimerEnabled db "Timer Interrupt Enabled!", 0
Err00 db "Error 00 - Division By Zero",0
Err01 db "Error 01 - Debug",0
Err02 db "Error 02 - Non Maskable Interrupt",0
Err03 db "Error 03 - Breakpoint Exception",0
Err04 db "Error 04 - Into Detected Overflow",0
Err05 db "Error 05 - Out of Bounds",0
Err06 db "Error 06 - Invalid Opcode",0
Err07 db "Error 07 - No Coprocessor",0
Err08 db "Error 08 - Double Fault",0
Err09 db "Error 09 - Coprocessor Segment Overrun",0
Err10 db "Error 10 - Bad TSS",0
Err11 db "Error 11 - Segment Not Present",0
Err12 db "Error 12 - Stack Fault",0
Err13 db "Error 13 - General Protection Fault",0
Err14 db "Error 14 - Page Fault",0
Err15 db "Error 15 - Unknown Interrupt",0
Err16 db "Error 16 - Coprocessor Fault",0
Err17 db "Error 17 - Alignment Check",0
Err18 db "Error 18 - Machine Check",0
ErrRes db "Error - Reserved",0

KeyBoard db 0, 0, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", 0, 0, "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", 0, 0, "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", 0, "\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", 0, "*", 0
ScanCode db 0
    



BTW, it makes no sense to me why I'd want to disable IRQs after I reroute the PICs.

Also... I looked into a ports file called ports.txt to see about the ports, and I don't know why I'm sending 0 to ports 21h and A1h, unless it's OCW2.

Any help would be greatly appreciated.

And I've enclosed the ports list file with this message for anyone who needs it as reference.


Description:
Download
Filename: ports.txt
Filesize: 267.76 KB
Downloaded: 692 Time(s)

Post 07 Nov 2007, 03:54
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Even more odd is that I can call int 32 (int 20h) from os1.asm just fine (loads up the timer), however int 21 gives a general protection fault error, but when I try to call int 21h from the CmdPrintFunc label, it acts like it's calling the timer, and int 22h gives the general protection fault error.
Post 07 Nov 2007, 04:13
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
When you are in protected mode, the first 32 interrupts are exceptions etc.
The next interrupts (20h-27h, 28h-2fh) are usually programmed to be the IRQs.
When you try to issue INT 21h, you are actually issuing IRQ1 - the keyboard.

Code:
; Enable Interrupts! =D 
push ax 
mov al, 0 
out 0A1h, al 
out 21h, al 
sti 
pop ax 
    

That code enables IRQ0-IRQ7 via port 21h and IRQ8-IRQ15 via port A1h.
That means that any IRQ (timer,keyboard,mouse,hdd etc.) can trigger an INT, but you have no code for it --> GPF.

The usual way to init the PIC is to set it up and then mask off all IRQs:
Code:
; DISABLE Interrupts! =D 
mov al, 0ffh
out 21h, al 
out 0A1h, al 
    

Then you allow certain IRQs that you have code for. The way you've set it up means that any IRQ above 1 (keyboard) can't be handled, since the IDT isn't long enough.
Post 07 Nov 2007, 05:59
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks sinsi, that helps clarify quite a few things. So it gives me a General Protection Fault because it's looking for an interrupt that isn't there! However, I still find it odd that it isn't recognizing int 21h directly, when I have it programmed already.
Post 07 Nov 2007, 06:37
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
What are you calling INT 21h for anyway? Like I said, it's set up to be the keyboard IRQ, so you shouldn't be calling it.

You aren't trying to call DOS's INT 21h are you? DOS don't exist...
Post 07 Nov 2007, 07:40
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
I noticed that the many USR routines are the same, except that they print different message. A better way would be to create one generic ISR routine and then load the message pointer into si useing a table lookup. ie: have a look at the PIC then load the pointer for the approppaite message

_________________
New User.. Hayden McKay.
Post 07 Nov 2007, 09:16
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
sinsi wrote:
What are you calling INT 21h for anyway? Like I said, it's set up to be the keyboard IRQ, so you shouldn't be calling it.

You aren't trying to call DOS's INT 21h are you? DOS don't exist...


I'm calling it so that I can use it for input, unless it's a hardware int in which case I don't need to call it to use it? Or do I still need to put in an int command for it to work?
Post 07 Nov 2007, 18:59
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
The first 32 ISRs are for the various exceptions.
You reprogram the PIC (as you did) to have your 16 IRQ handlers (PIT, keyboard, FDC, LPT, etc) right after those 32 ISRs.
You should NEVER call an IRQ handler directly.
Once you enable an IRQ line, it will be fired AUTOMATICALLY once data is sent (eg: when a key is pressed -- for the keyboard).
The keyboard IRQ handler should handle the keyboard ports and store the scan code in some buffer.
You should have another "user" interrupt (int 48 and above) that will simply read that buffer and get the scan code (or convert it to ASCII or whatever) to the user.
Post 08 Nov 2007, 10:20
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
ManOfSteel wrote:
The first 32 ISRs are for the various exceptions.
You reprogram the PIC (as you did) to have your 16 IRQ handlers (PIT, keyboard, FDC, LPT, etc) right after those 32 ISRs.
You should NEVER call an IRQ handler directly.
Once you enable an IRQ line, it will be fired AUTOMATICALLY once data is sent (eg: when a key is pressed -- for the keyboard).
The keyboard IRQ handler should handle the keyboard ports and store the scan code in some buffer.
You should have another "user" interrupt (int 48 and above) that will simply read that buffer and get the scan code (or convert it to ASCII or whatever) to the user.


So you're saying I don't need to call int 21h every time I want to get input, as it's automatically done by the hardware, however I can write another IRQ which can read from a buffer where the automatic hardware interrupt stores the data?
Post 09 Nov 2007, 00:50
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I just realized that if I call no interrupts or anything, it automatically comes up with the "Timer enabled!" message. And if I just hit a key, it gives me a GPF... but that IRQ is coded, so I don't know what it's whining about.
Post 09 Nov 2007, 01:00
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
sinsi wrote:
When you are in protected mode, the first 32 interrupts are exceptions etc.
The next interrupts (20h-27h, 28h-2fh) are usually programmed to be the IRQs.
When you try to issue INT 21h, you are actually issuing IRQ1 - the keyboard.

Code:
; Enable Interrupts! =D 
push ax 
mov al, 0 
out 0A1h, al 
out 21h, al 
sti 
pop ax 
    

That code enables IRQ0-IRQ7 via port 21h and IRQ8-IRQ15 via port A1h.
That means that any IRQ (timer,keyboard,mouse,hdd etc.) can trigger an INT, but you have no code for it --> GPF.

The usual way to init the PIC is to set it up and then mask off all IRQs:
Code:
; DISABLE Interrupts! =D 
mov al, 0ffh
out 21h, al 
out 0A1h, al 
    

Then you allow certain IRQs that you have code for. The way you've set it up means that any IRQ above 1 (keyboard) can't be handled, since the IDT isn't long enough.


Ah! So I don't need to disable all the interrupts, and then re-enable them all like I have been doing, I can just turn on the one's I want (the first two), right? And what I'm sending is actually the Output Control Word 1 (OCW1), am I correct?
Post 09 Nov 2007, 01:15
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I think I have it figured out a bit better now, and when I go into my IRQ1 routine, if I comment out pushing es and ds onto the stack then popping it back off, it will display a message correctly. My stack size can't be that small though that it would run out that quickly.

Here's the new code if anyone could explain why just putting those two segments onto the stack would cause a GPF:

os1.asm
Code:
org 7C00h

BootStart:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 9C00h

; Set up VESA text mode 10Ch (132x60)
mov ax, 4F02h
mov bx, 10Ch
int 10h

mov ax, 0060h
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 0Ah
mov cl, 02h
mov ch, 00h
mov dh, 00h
int 13h
jmp 0000h:0600h

times 510-($-$$) db 0
dw 0AA55h

org 0600h
Begin:
;push cs
;push cs
;pop ds
;pop ss
mov ax, 0
mov ds, ax
mov ss, ax

; Used for testing.
;pop cs
;pop ax
;mov bx, 0B800h
;mov es, bx
;xor bx, bx
;sub al, '0'
;mov [es:bx], al

jmp Start

; Data Goes Here
  WelcomeStr db "Welcome to TR2-DOS!",0

  gdt:
  db 00h, 00h, 00h, 00h, 00h, 00h, 00h, 00h ; NULL SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10011010b, 11001111b, 00h ; CODE SEGMENT
  db 0FFh, 0FFh, 00h, 00h, 00h, 10010010b, 11001111b, 00h ; DATA SEGMENT
  gdt_end:

  ;Global Descriptor Table Descriptor is set up as follows:
  ; -------------------------
  ;| DESCRIPTION  |  SIZE    |
  ;|------------------------ |
  ;| SIZE         |  WORD    |
  ;| TABLE        |  DWORD   |
  ; -------------------------
  gdt_desc: dw gdt_end - gdt - 1
            dd gdt
; Data Ends Here

Start:

; Clear interrupts for move to 32-bit mode
cli

;Load Global Descriptor Table (GDT) Register
lgdt [gdt_desc]

;Set up control register to get into Protected Mode
mov eax, cr0
or al, 1
mov cr0, eax

;Do far jump to first (filled in) selector - the code selector.
jmp 8h:Start32

; Welcome to the world of 32-Bit mode! =-D
use32
Start32:
; Start off by setting the data segment to the data selector.
xor bx, bx
mov bx, 10h
mov ds, bx
mov ss, bx
mov esp, 90000h

; Move video memory into EBX
mov eax, 0B8000h

; Print Welcome Message
mov si, WelcomeStr
call PrintF

; Reroute PICS so that an exception doesn't occur every time an interrupt is called!
call Reroute_PICs

; Load Interrupt Descriptor Table
lidt [idtp]

; Enable Interrupts! =D
push ax
mov al, 1b ;Enable all except for IRQ0 - The timer.
out 0A1h, al
out 21h, al
sti
pop ax

;call CmdPrintFunc

Hang:
jmp Hang

include "interrupts.inc"
;times 1474560-512-($-$$) db 0
    


interrupts.inc
Code:
;INTERRUPTS!!! YAY

PrintF:
push ebx
push eax
mov ebx, 0B8000h
PutCh:
lodsb
cmp al, 0
je Done
mov ah, [TxtClr]
mov word [ds:ebx], ax
add bx, 2
jmp PutCh

Done:
pop eax
pop ebx
ret

;Side data for PrintF
TxtClr db 2

Done2:
        ret

ClrScrn:
        mov ax, 10h
        mov ds, ax
        mov ebx, 0B8000h
        mov ax, 0
        clrloop:
                cmp ax, 2000
                je Done2
                mov byte [ds:ebx], ' '
                inc ebx
                mov byte [ds:ebx], 1Bh
                inc ebx
                inc ax
                jmp clrloop

CmdPrintFunc:
        mov ax, 10h
        mov es, ax
        mov edi, 0B8000h
        xor eax, eax
        cmdloop:
                int 21h
                cmp al, 1Ch
                je Done2
                mov esi, eax
                mov cl, [esi+KeyBoard]
                mov byte [es:edi],cl
                inc edi
                mov byte [es:edi], 02h
                inc edi
                jmp cmdloop

Reroute_PICs:
        ;send ICW1(Interrupt Control Word1)
        mov al, 11h
        ;out PIC1, ICW1
        out 20h, al
        ;out PIC2 ICW1
        out 0A0h, al

        ;send ICW2
        mov al, 20h
        ;out PIC1 + 1, IRQ0 start point
        out 21h, al
        mov al, 28h
        ;out PIC2 + 1, IRQ8 start point
        out 0A1h, al

        ;send ICW3
        ;IRQ2 to Connection to Slave PIC
        mov al, 04h
        out 21h, al
        mov al, 02h
        out 0A1h, al

        ;send ICW4
        mov al, 01h
        out 21h, al
        out 0A1h, al

        ;disable IRQs
        mov al, 0FFh
        out 0A1h, al
        out 021h, al
        ret

isr0:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err00
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr1:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err01
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr2:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err02
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr3:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err03
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr4:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err04
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr5:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err05
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr6:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err06
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr7:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err07
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr8:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err08
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr9:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err09
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr10:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err10
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr11:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err11
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr12:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err12
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr13:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err13
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr14:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err14
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr15:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err15
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr16:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err16
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr17:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err17
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr18:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, Err18
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr19:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr20:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr21:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr22:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr23:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr24:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr25:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr26:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr27:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr28:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr29:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr30:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

isr31:
        pusha
        push gs
        push fs
        push ds
        push es
        mov si, ErrRes
        call PrintF
        cli
        hlt
        pop es
        pop ds
        pop fs
        pop gs
        popa
        iret

irq0:
        cli
        mov si, TimerEnabled
        call PrintF
        mov al, 20h
        out 20h, al
        sti
        iret

irq1:
        cli
        push eax
        ;push es
        ;push ds

        in al, 60h
        mov byte [ScanCode], al

        mov si, KeyPressed
        call PrintF

        mov al, 20h
        out 20h, al

        ;pop ds
        ;pop es
        pop eax
        sti
        iret

idt_start:

        ;Interrupt Example
        ; dw start_address
        ; dw code_selector where ISR is being held
        ; dw type_settings for ISRs
        ; dw start_address2(bits 31-16)
        ; start_address2 should be 0 because the
        ; start address should be no more than 1
        ; word value.


        ;FOR HISTORIC REFERENCE PURPOSES ONLY
        ;Original ISRS looked like the following
        ;
        ;dw 0h000
        ;dw 0h8
        ;dw 8E00h
        ;dw 0h8
        ;
        ;END OF HISTORIC REFERENCE

        ;SERVICE REQUEST INTS
        ;int0
        dw isr0
        dw 08h
        dw 8E00h
        dw 0h
        ;int1
        dw isr1
        dw 08h
        dw 8E00h
        dw 0h
        ;int2
        dw isr2
        dw 08h
        dw 0E00h
        dw 0h
        ;int3
        dw isr3
        dw 08h
        dw 8E00h
        dw 0h
        ;int4
        dw isr4
        dw 08h
        dw 8E00h
        dw 0h
        ;int5
        dw isr5
        dw 08h
        dw 8E00h
        dw 0h
        ;int6
        dw isr6
        dw 08h
        dw 8E00h
        dw 0h
        ;int7
        dw isr7
        dw 08h
        dw 8E00h
        dw 0h
        ;int8
        dw isr8
        dw 08h
        dw 8E00h
        dw 0h
        ;int9
        dw isr9
        dw 08h
        dw 8E00h
        dw 0h
        ;int10
        dw isr10
        dw 08h
        dw 8E00h
        dw 0h
        ;int11
        dw isr11
        dw 08h
        dw 8E00h
        dw 0h
        ;int12
        dw isr12
        dw 08h
        dw 8E00h
        dw 0h
        ;int13
        dw isr13
        dw 08h
        dw 8E00h
        dw 0h
        ;int14
        dw isr14
        dw 08h
        dw 8E00h
        dw 0h
        ;int15
        dw isr15
        dw 08h
        dw 0E00h
        dw 0h
        ;int16
        dw isr16
        dw 08h
        dw 0E00h
        dw 0h
        ;int17
        dw isr17
        dw 08h
        dw 0E00h
        dw 0h
        ;int18
        dw isr18
        dw 08h
        dw 0E00h
        dw 0h
       ;int19
        dw isr19
        dw 08h
        dw 0E00h
        dw 0h
       ;int20
        dw isr20
        dw 08h
        dw 0E00h
        dw 0h
       ;int21
        dw isr21
        dw 08h
        dw 0E00h
        dw 0h
       ;int22
        dw isr22
        dw 08h
        dw 0E00h
        dw 0h
       ;int23
        dw isr23
        dw 08h
        dw 0E00h
        dw 0h
       ;int24
        dw isr24
        dw 08h
        dw 0E00h
        dw 0h
       ;int25
        dw isr25
        dw 08h
        dw 0E00h
        dw 0h
       ;int26
        dw isr26
        dw 08h
        dw 0E00h
        dw 0h
       ;int27
        dw isr27
        dw 08h
        dw 0E00h
        dw 0h
       ;int28
        dw isr28
        dw 08h
        dw 0E00h
        dw 0h
       ;int29
        dw isr29
        dw 08h
        dw 0E00h
        dw 0h
       ;int30
        dw isr30
        dw 08h
        dw 0E00h
        dw 0h
       ;int31
        dw isr31
        dw 08h
        dw 0E00h
        dw 0h

       ;HARDWARE INTERRUPT REQUESTS
       ;int32
        dw irq0
        dw 08h
        dw 8E00h
        dw 0h
       ;int33
        dw irq1
        dw 08h
        dw 8E00h
        dw 0h

idt_end:

idtp:
        dw idt_end - idt_start - 1
        dd idt_start

TimerEnabled db "Timer Interrupt Enabled!", 0
KeyPressed db "Keyboard Key pressed!", 0
Err00 db "Error 00 - Division By Zero",0
Err01 db "Error 01 - Debug",0
Err02 db "Error 02 - Non Maskable Interrupt",0
Err03 db "Error 03 - Breakpoint Exception",0
Err04 db "Error 04 - Into Detected Overflow",0
Err05 db "Error 05 - Out of Bounds",0
Err06 db "Error 06 - Invalid Opcode",0
Err07 db "Error 07 - No Coprocessor",0
Err08 db "Error 08 - Double Fault",0
Err09 db "Error 09 - Coprocessor Segment Overrun",0
Err10 db "Error 10 - Bad TSS",0
Err11 db "Error 11 - Segment Not Present",0
Err12 db "Error 12 - Stack Fault",0
Err13 db "Error 13 - General Protection Fault",0
Err14 db "Error 14 - Page Fault",0
Err15 db "Error 15 - Unknown Interrupt",0
Err16 db "Error 16 - Coprocessor Fault",0
Err17 db "Error 17 - Alignment Check",0
Err18 db "Error 18 - Machine Check",0
ErrRes db "Error - Reserved",0

KeyBoard db 0, 0, "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", 0, 0, "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", 0, 0, "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", 0, "\", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", 0, "*", 0
ScanCode db 0
    
Post 09 Nov 2007, 01:27
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
In your ISR routines for IRQ0 and IRQ1 you need to save ALL registers that you use - both those routines use SI which could cause a problem.
Don't forget that an IRQ can be triggered in the middle of any code (yours, the BIOS etc.) and changing a register can have dire consequences when the IRQ returns to the code it interrupted.

Edit: Don't forget that you are in 32-bit mode, so use ESI as well...
Post 09 Nov 2007, 07:09
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I got everything working! =D The reason why it wouldn't work whenever I'd put the segment registers on the stack and take them off was because the extra segment wasn't initiated, so I'd be putting a value onto the stack that didn't exist and when I'd take it off I'd get a GPF.
Post 14 Nov 2007, 21:14
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
it's funny, all bugs in asm coding are always stupid! don't you find it's true?
the best is when the stack overwrite some code! or simply a bad addressing, [xxx] instead of xxx & vice versa

Rhyno degreat, you have a idt that works, fine!
me i am still seeking how to implement this.
and i'm fear of all the code i shall write for INT to be supported
and irq too!

the most difficult is to start! and achieve step by step all the project!
Post 15 Nov 2007, 00:49
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
edfed wrote:
it's funny, all bugs in asm coding are always stupid! don't you find it's true?
the best is when the stack overwrite some code! or simply a bad addressing, [xxx] instead of xxx & vice versa

Rhyno degreat, you have a idt that works, fine!
me i am still seeking how to implement this.
and i'm fear of all the code i shall write for INT to be supported
and irq too!

the most difficult is to start! and achieve step by step all the project!


I need to put in comments for my code, which I shall do ASAP (my teacher needs them so that he knows what's going on), and I will do my best to explain how the interrupt code works.

Until then, edfed, my suggestion to you is to take a glimpse at the following links:

http://www.osdever.net/tutorials/pic.php

NOTE: for the PIC remapping, I would suggest taking a look at that ports.txt, finding ports 20h, 21h, A0h, and A1h in it, and then reading the info it has about them. I found that exceptionally helpful.

http://www.osdever.net/tutorials/interrupts.1.php
http://www.osdever.net/tutorials/interrupts.2.php
http://www.osdever.net/tutorials/interrupts.3.php

These were how I originally formed my IDT and IRQs, and you will notice that my style follows that of how this is set up on those sites. However, you will notice a major difference, which is the first WORD of each IDT entry being an address (label) to a certain area in memory, whereas they foolishly put "dw 0x0000" as the first WORD.

Also, the IDT is loaded into the IDT Register just like the GDT is.

idtp:
dw idt_end - idt_start - 1
dd idt_start

And then:

lidt [idtp]

I hope this helps some. My best advice would be to look at the interrupts.inc file I have posted, it might be a good starting place.
Post 15 Nov 2007, 01:37
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
thank you

is it a good idea to compile a separate idt & interrupt bin file?
loading that at boot time?
and then configure PIC & sti
Post 15 Nov 2007, 20:50
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4  Next

< 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.

Powered by rwasa.