flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Device driver FDC in virtual or protected mode

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
other sources of interrupts may exist that need to be handled. you refuse to compensate for them in PM. thats the problem.
Post 25 Jul 2014, 13:20
View user's profile Send private message Visit poster's website Reply with quote
neo-92



Joined: 26 Feb 2014
Posts: 25
neo-92
As a test, i build a ISR for a print character and work.
Code:
use32

lidt[idt]
int 0
jmp $

idt:
dw end_idt-idt_table-1
dd idt_table

idt_table:
dw isr0
dw 8 ;CPL 0 32 bit
db 0
db 8eh
dw 0

end_idt:

isr0:
pusha
mov byte[0b8000h],41h
popa
iret
    

Is sure that i need to complete the IDT? I'll give it a look...
Post 25 Jul 2014, 14:52
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
you need to post the entire thing for anyone to be able to check it.

this code is partial but it's representative of the initialization sequence:

Code:
    ;segment definitions.
    cpu.select.code = 2 shl 3
    
    ;the PIC-relative vector number.
    Floppy.int = 6
    clock.int  = 0
    
    PIC8259.Primary     = 0x20
    PIC8259.ICW1        = 10001b
    PIC8259.FirstVector = 0x20;Begin the table at interrupt 32 (hex 20).
    PIC8259.mask.floppy = 1 shl Floppy.int; bit 6 corresponds to the floppy interrupt.
    PIC8259.mask.timer  = 1 shl clock.int
    
    ;initialize the PIC first. block all interrupts except the floppy. you'll want to enable more later.
    mov al, PIC8259.ICW1
    out PIC8259.Primary, al        ; PIC8259.ICW1
    mov al, PIC8259.FirstVector
    out PIC8259.Primary+1, al        ; ((PIC8259.FirstVector+X) shl 8)
    mov al, 100b
    out PIC8259.Primary+1, al        ; (100b shl 16)
    mov al, 1
    out PIC8259.Primary+1, al        ; (1 shl 24)
    mov al, 255 - PIC8259.mask.floppy - PIC8259.mask.timer;enable the timer and the floppy.
    out PIC8259.Primary+1, al        ; this is the mask. writing a 1 will disable the corresponding interrupt.
    
    
    ;build the IDT immediately after the Real Mode IVT.
    IDT = 4*256
    
    ;build the exceptions portion of the IDT (Vector 0 -> 31).
    mov edi, IDT
    mov edx, 0x8E00+ (ex and 0xFFFF0000)
    mov eax, cpu.select.code shl 16 + (ex and 0xFFFF)
    mov ecx, PIC8259.FirstVector
    @@:
    mov[edi+ 0],eax
    mov[edi+ 4],edx
    add edi, 8
    loop @b
    
    ;build the interrupts portion of the IDT (Vector 32-> 255).
    mov edx, 0x8F00+ (int.default and 0xFFFF0000)
    mov eax, cpu.select.code shl 16 + (int.default and 0xFFFF)
    add ecx, 8
    @@:
    mov[edi+ 0],eax
    mov[edi+ 4],edx
    add edi, 8
    loop @b
    
    ;initialize the remaining interrupt descriptors.
    mov edx, 0x8F00+ (int.procedure and 0xFFFF0000)
    mov eax, cpu.select.code shl 16 + (int.procedure and 0xFFFF)
    mov ecx, 256-8-PIC8259.FirstVector
    @@:
    mov[edi+ 0],eax
    mov[edi+ 4],edx
    add edi, 8
    loop @b
    
    ;the floppy interrupt:
    mov word [IDT+PIC8259.FirstVector*8+ Floppy.int*8], Floppy.Interrupt; "start"
    
    ;the clock interrupt.
    mov word [IDT+PIC8259.FirstVector*8+  clock.int*8], clock; "start"
    
    ;your glorified procedure:
    mov word [IDT+49*8], Floppy.Function; you keep changing the name.
    
    lidt[ptr.idt]
    sti
    mov dword [0xB8000], 'H i '
    mov dword [0xB8000+80*2], '  ! '
    jmp $
    
    align 2
    ptr.idt:
    dw 256*8-1
    dd IDT
    
    int.default:
        
        psh eax
            
            mov al, 0x20
            out 0x20, al
            
        pop eax
        
    iret
    
    clock:
        
        inc byte [0xB8000+80*2]
        psh eax
            
            mov al, 0x20
            out 0x20, al
            
        pop eax
        
    iret
    
    int.procedure:
    mov edi, 0xB8000
    mov dword [edi+0*4], 'I S '
    mov dword [edi+1*4], 'R ! '
    jmp $
    ex:
    mov edi, 0xB8000
    mov dword [edi+0*4], 'E X '
    mov dword [edi+1*4], '    '
    jmp $
    
    ;this part is fucked because it's patchwork. you need something more sophisticated for general use.
    Floppy.Interrupt:
    mov al, 0x20
    out 0x20, al
    sti
    jmp start    

_________________
byte me.
Post 25 Jul 2014, 20:37
View user's profile Send private message Visit poster's website Reply with quote
neo-92



Joined: 26 Feb 2014
Posts: 25
neo-92
Hi Stefan, i followed step to step the building IDT and output this:
Code:
org 7c00h

use16 

cli
lgdt[gdt]
mov eax,cr0 
or al,1 
mov cr0,eax 
jmp code32-table1:kernel 

use32 

kernel: 
mov ax,data32-table1 
mov gs,ax 
mov fs,ax 
mov ds,ax 
mov es,ax 
mov ss,ax 
mov esp,9fffch
mov al,11h
out 20h,al
mov al,20h
out 21h,al
mov al,4
out 21h,al
mov al,1
out 21h,al
mov al,255-1 shl 6-1 shl 0
out 21h,al
mov edi, idt
mov edx, 0x8E00+ (ex and 0xFFFF0000) 
mov eax, 8 shl 16 + (ex and 0xFFFF)
mov ecx, 20h
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b 
     
;build the interrupts portion of the IDT (Vector 32-> 255). 
mov edx, 0x8F00+ (int.default and 0xFFFF0000) 
mov eax, 8 shl 16 + (int.default and 0xFFFF)
add ecx, 8 
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b 
     
;initialize the remaining interrupt descriptors. 
mov edx, 0x8F00+ (int.procedure and 0xFFFF0000) 
mov eax, 8 shl 16 + (int.procedure and 0xFFFF)
mov ecx, 256-8-20h
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b
mov word [idt+20h*8+ 6*8], floppy.interrupt; "start"
     
;the clock interrupt. 
mov word [idt+20h*8+  0*8], clock; "start"
     
;your glorified procedure: 
mov word [idt+49*8], floppy.function; you keep changing the name.
     
lidt[ptr.idt]
sti
int 49
jmp $

int.default:
push eax
mov al,20h
out 20h,al
pop eax
iret

clock:
inc byte[0b8000h+80*2]
push eax
mov al,20h
out 20h,al
pop eax
iret

int.procedure:
mov edi,0b8000h
mov dword[edi*4],'I S '
mov dword[edi+1*4],'R ! '
jmp $
ex:
mov edi,0b8000h
mov dword[edi*4],'E X '
mov dword[edi+1*4],'    '
jmp $

floppy.interrupt:
mov al,20h
out 20h,al
sti
jmp start

floppy.function:
mov dx,3f2h
mov al,1ch
out dx,al
call readmsr
mov al,6
out 0ah,al
mov al,0ffh
out 0ch,al
mov ax,start
out 4,al
mov al,ah
out 4,al
mov al,0ffh
out 0ch,al
out 5,al
mov al,1
out 5,al
mov al,code32-table1
out 81h,al
mov al,2
out 0ah,al
call readmsr
mov dx,3f5h
mov al,66h
out dx,al
mov al,0
out dx,al
mov al,0
out dx,al
mov al,0
out dx,al
mov al,2
out dx,al
mov al,2
out dx,al
mov al,18
out dx,al
mov al,27
out dx,al
mov al,0ffh
out dx,al
jmp $

readmsr:
mov dx,3f4h
in al,dx
and al,0c0h
cmp al,80h
jne readmsr
ret

gdt: 
dw end_gdt-table1-1 
dd table1 

table1: 
dq 0 

code32: 
dw 0ffffh 
dw 0 
db 0 
db 9ah
db 0cfh 
db 0 

data32: 
dw 0ffffh 
dw 0 
db 0 
db 92h
db 0cfh 
db 0

end_gdt:

align 2
ptr.idt:
dw 256*8-1
dd idt

idt = 4*256

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

start:
mov di,0b800h
mov es,di
mov di,0
mov byte[es:di],42h
mov byte[es:di+1],7
jmp $

times 512-($-start) db 0
    

There is particular something, print two empty character of green color and one with the letter 'U', what can it be? Surprised Shocked
Code:
;this part is fucked because it's patchwork. you need something more sophisticated for general use. 
floppy.interrupt:
mov al,20h
out 20h,al
sti
jmp start
    

I try use 'jmp' but doesn't know register 'start' why? What did you mean before?
Post 28 Jul 2014, 21:35
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
you didn't listen to me when I told you the third byte sent to the DMA controller is the Highest byte of the address (bits 23..16) instead of the Segment (the segment, by the way, is 16 bits not 8).

Code:
org 7c00h

use16 

cli
lgdt[gdt]
mov eax,cr0 
or al,1 
mov cr0,eax 
jmp code32-table1:kernel 

use32 

kernel: 
mov ax,data32-table1 
mov gs,ax 
mov fs,ax 
mov ds,ax 
mov es,ax 
mov ss,ax 
mov esp,9fffch
mov al,11h
out 20h,al
mov al,20h
out 21h,al

mov al,4
out 21h,al

mov al,1
out 21h,al

mov al,255-1 shl 6-1 shl 0
out 21h,al

mov edi, idt
mov edx, 0x8E00+ (ex and 0xFFFF0000) 
mov eax, (code32-table1) shl 16 + (ex and 0xFFFF)
mov ecx, 20h
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b 
     
;build the interrupts portion of the IDT (Vector 32-> 255). 
mov edx, 0x8F00+ (int.default and 0xFFFF0000) 
mov eax, (code32-table1) shl 16 + (int.default and 0xFFFF)
add ecx, 8 
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b 
     
;initialize the remaining interrupt descriptors. 
mov edx, 0x8F00+ (int.procedure and 0xFFFF0000) 
mov eax, (code32-table1) shl 16 + (int.procedure and 0xFFFF)
mov ecx, 256-8-20h
@@: 
mov[edi+ 0],eax 
mov[edi+ 4],edx 
add edi, 8 
loop @b
mov word [idt+20h*8+ 6*8], start
mov word [idt+20h*8+ 0*8], clock

;your glorified procedure: 
mov word [idt+49*8], floppy.function; you keep changing the name.

lidt[ptr.idt]
mov dword [0xB8000],"H i "
sti
int 49
jmp $

int.default:
push eax
mov dword [0xB8000+80*2*2],"I N "
mov al,20h
out 20h,al
pop eax
iret

clock:
inc byte[0xB8000+80*2*1]
push eax
mov al,20h
out 20h,al
pop eax
iret

int.procedure:
mov edi,0b8000h
mov dword[edi+0*4],'I S '
mov dword[edi+1*4],'R ! '
jmp $
ex:
mov edi,0b8000h
mov dword[edi+0*4],'E X '
mov dword[edi+1*4],'    '
jmp $

floppy.function:
mov dx, 3f2h
mov al, 1ch
out dx, al

mov al, 6
out 0ah,al; DMA Mode Register.
mov al,0ffh
out 0ch,al ; Clear Flip Flop.

mov al, 0; Address register low
out 4,al 
mov al,(start shr 8) and 255; Address register middle.
out 4,al 
mov al, start shr 16
out 81h,al ; Address Register High (Page Register). 0

mov al,0ffh
out 5,al ; Count Port Low
mov al,1
out 5,al ; Count Port High

mov al,2
out 0ah,al ; DMA Mode Register. enable DMA.

mov dx,3f5h
mov al,66h
out dx,al
mov al,0
out dx,al
mov al,0
out dx,al
mov al,0
out dx,al
mov al,2
out dx,al
mov al,2
out dx,al
mov al,18
out dx,al
mov al,27
out dx,al
mov al,0ffh
mov dword[0b8000h+80*2*9],'! ! '
out dx,al
jmp $

readmsr:
mov dx,3f4h
in al,dx
and al,0c0h
cmp al,80h
jne readmsr
ret

gdt: 
dw end_gdt-table1-1 
dd table1 

table1: 
dq 0 

code32: 
dw 0ffffh 
dw 0 
db 0 
db 9ah
db 0cfh 
db 0 

data32: 
dw 0ffffh 
dw 0 
db 0 
db 92h
db 0cfh 
db 0

end_gdt:

align 2
ptr.idt:
dw 256*8-1
dd idt

idt = 4*256

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

start:
mov dword[0xB8000+80*2*4],'! ! '
jmp $

times 510-($-start) db 0 
dw 0aa55h    


you also changed a couple of the addresses in the ISRs (edi*4?).

- Stefan

_________________
byte me.
Post 29 Jul 2014, 05:29
View user's profile Send private message Visit poster's website Reply with quote
neo-92



Joined: 26 Feb 2014
Posts: 25
neo-92
Ok, thanks Stefan. I needed just this explanation, work! Very Happy. I apologize if i had not understood before but wanted to learn, there is in front of me the answer Smile. Thanks again and all. Bye Stefan Wink
Post 29 Jul 2014, 13:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

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