flat assembler
Message board for the users of flat assembler.

Index > OS Construction > set up idt (help me, please)

Author
Thread Post new topic Reply to topic
mounter



Joined: 13 Apr 2007
Posts: 2
mounter 13 Apr 2007, 09:05
I wanna set IDT.
If press any key, it must print 'X' on screen.
Though many try and error, I can't fix it.
Help me, please.
Code:
; jumped from menuetos bootloader

org 0
use16

start:
        mov ax, cs
        mov ds, ax
        xor ax, ax
        mov ss, ax

        cli             ; Clear Interrupt Flag

        ; ICW1
        mov al, 0x11
        out 0x20, al
        dw 0x00eb, 0x00eb
        out 0xa0, al
        dw 0x00eb, 0x00eb

        ; ICW2
        mov al, 0x20
        out 0x21, al
        dw 0x00eb, 0x00eb
        mov al, 0x28
        out 0xa1, al
        dw 0x00eb, 0x00eb

        ; ICW3
        mov al, 0x04
        out 0x21, al
        dw 0x00eb, 0x00eb
        mov al, 0x02
        out 0xa1, al
        dw 0x00eb, 0x00eb

        ; ICW4
        mov al, 0x01
        out 0x21, al
        dw 0x00eb, 0x00eb
        out 0xa1, al
        dw 0x00eb, 0x00eb

        mov al, 0xFF
        out 0xa1, al
        dw 0x00eb, 0x00eb
        mov al, 0xfb
        out 0x21, al


        lgdt[gdtr]

        mov eax, cr0
        or eax, 0x00000001
        mov cr0, eax

        jmp $+2
        nop
        nop

        jmp dword 0x08:PM_Start

use32
PM_Start:
        mov bx, 0x10
        mov ds, bx

        mov es, bx
        mov fs, bx
        mov gs, bx
        mov ss, bx

        lea esp, [PM_Start]

        cld

        mov ax, 0x10
        mov es, ax
        xor eax, eax
        xor ecx, ecx
        mov ax, 256
        mov edi, 0

loop_idt:
        lea esi, [IDT_NOTHING]
        mov cx, 8
        rep movsb
        dec ax
        jnz loop_idt 


        mov edi, 8*0x21
        lea esi, [IDT_KEYBOARD]
        mov cx, 8
        rep movsb

        lidt[IDTR]

        mov al, 0xFD
        out 0x21, al

        sti

        jmp $

; Interrupt Descriptor Table Register
IDTR:
        dw 256*8-1
        dd 0

INTERRUPT_NOTHING:
        pushad
        push gs
        push fs
        push es
        push ds
        pushfd

        popfd
        pop ds
        pop es
        pop fs
        pop gs
        popad

        iret

INTERRUPT_KEYBOARD:

        pushad
        push gs
        push fs
        push es
        push ds
        pushfd

        in al, 0x60
        mov al, 0x20
        out 0x20, al

        mov ax, 0x18
        mov es, ax      
        mov di, 0       
        mov ax, word [msgBack]  ; 'X'
        mov cx, 0x7FF   

paint:                          ; with 'X'
        mov word [es:di], ax    
        add di, 2
        dec cx  
        jnz paint       

        inc byte [msgBack+1]

        popfd
        pop ds
        pop es
        pop fs
        pop gs
        popad

        iret

IDT_KEYBOARD:
        dw INTERRUPT_KEYBOARD
        dw 0x08              
        db 0                 
        db 0x8E              
        dw 0x0001

IDT_NOTHING:
        dw INTERRUPT_NOTHING 
        dw 0x08              
        db 0                 
        db 0x8E              
        dw 0x0001

; Interrupt Descriptor Table Register



msgBack db 'X' , 0x67


; -------------------------------------
; Global Descriptr Table
; -------------------------------------

gdtr:
        dw gdt_end - gdt - 1    
        dd 0x10000 + gdt        

gdt:
        dw 0 
        dw 0 
        db 0 
        db 0 
        db 0 
        db 0 

; code
        dw 0xffff 
        dw 0x0000 
        db 0x01   
        db 0x9a   
        db 0xcf   
        db 0x00   

; data
        dw 0xffff 
        dw 0x0000 
        db 0x01   
        db 0x92   
        db 0xcf   
        db 0x00   

; video
        dw 0xffff  
        dw 0x8000  
        db 0x0B    
        db 0x92    
        db 0x40    
        db 0x00    
gdt_end:

    
Post 13 Apr 2007, 09:05
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 13 Apr 2007, 16:44
Have you tryed using something like this, in the IDT_NOTHING int's
Code:
        mov   ax,18h    mov   es,ax   mov   byte [es:0], "W"    

As you will be able to test if any work, also try puting this to see how far you get
Code:
        mov   ax,18h   mov   es,ax   mov   byte [es:0x09E], "1";some code        mov   ax,18h    mov   es,ax   mov   byte [es:0x09E], "2";some code        mov   ax,18h    mov   es,ax   mov   byte [es:0x09E], "3";some code        mov   ax,18h    mov   es,ax   mov   byte [es:0x09E], "4";some code and so on    

This is a good way to debug it.
Post 13 Apr 2007, 16:44
View user's profile Send private message Reply with quote
mounter



Joined: 13 Apr 2007
Posts: 2
mounter 14 Apr 2007, 17:05
Thanks for your concern, Dex4u.
Using nasm compiler, it works.
I can't understand why it doesn't work properly.


Code:
; jumped from menuetos bootloader  (1000:0000)
.......
        jmp dword 0x08:PM_Start 
.......
use32 
PM_Start: 
        mov edi, 0   <-------------------- question #1
........
; Interrupt Descriptor Table Register 
IDTR: 
        dw 256*8-1 
        dd 0            <-------------------- question #2
..........
IDT_KEYBOARD: 
        dw INTERRUPT_KEYBOARD 
        dw 0x08               
        db 0                  
        db 0x8E               
        dw 0x0001    <-------------------- question #3
    
Post 14 Apr 2007, 17:05
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.