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 Next |
Author |
|
BAiC 22 Jul 2014, 16:07
please post the Real Mode code that your claiming works.
|
|||
22 Jul 2014, 16:07 |
|
neo-92 22 Jul 2014, 19:01
Here it is:
Code: org 7c00h use16 jmp 0:x86 x86: mov ax,0 mov gs,ax mov fs,ax mov ds,ax mov es,ax mov ss,ax mov sp,0fffeh sti mov dx,3f2h mov al,1ch out dx,al mov al,6 out 0ah,al mov al,0ffh out 0ch,al mov al,[start] out 4,al mov al,0 out 4,al mov al,0ffh out 0ch,al out 5,al mov al,1 out 5,al mov al,0 out 81h,al mov al,2 out 0ah,al 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 $ 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 times 510-($-start) db 0 |
|||
22 Jul 2014, 19:01 |
|
BAiC 23 Jul 2014, 07:15
the reason it appears to work is because your writing over the IVT with the new code which is zero at the entry for the Floppy Interrupt.
first of all: your writing the sector to address 0 in memory (which is the IVT for Real Mode). second; when the processor looks for the address of the floppy interrupt it sees 0:0 (because the region of the sector is zero there). this is an Initial Value Problem. you simply didn't initialize all of your data. _________________ byte me. |
|||
23 Jul 2014, 07:15 |
|
neo-92 23 Jul 2014, 14:48
Hi Stefan, if you mean the segment and offset i have already taken steps to fix but the get same result, recapitulate we have the ports number 0x4 and 0x81 of which the port 0x4 has low byte buffer and middle byte buffer while the port 0x81 has high byte buffer, said this is each byte 8-bit, then:
1) The low byte is null. 2) The middle byte is offset '[start]'. 3) The high byte is code segment 32 bit. Right? Or something wrong? It should work this way... |
|||
23 Jul 2014, 14:48 |
|
BAiC 23 Jul 2014, 15:11
first of all; you should be dealing with building an interrupt handler for when the code finishes.
as to your list; the code successfully transfers the sector to memory. the problem is that your writing it to address 0 (the IVT). if your putting the sector at the same address as "start" then the low byte of the address will be zero since it's aligned on a 512 byte boundary (I'm not sure if it's aligned any further). this is the code. Code: out 0xC, al;clear the flip flop by writing any value. mov al, start and 255 out 4, al mov al,(start shr 8) and 255 out 4, al mov al, start shr 16 out 0x81, al the hardware doesn't deal with segments. if you were dealing with dynamic memory (unknown addresses) then you would have to calculate the physical address instead of using the constant expressions in the earlier code. -Stefan _________________ byte me. |
|||
23 Jul 2014, 15:11 |
|
neo-92 23 Jul 2014, 16:07
Nothing.
Code: use32 mov al,6 out 0ah,al mov al,0ffh out 0ch,al mov al,start and 255 out 4,al mov al,(start shr 8) and 255 out 4,al shr al,start shr 16 out 81h,al mov al,0ffh out 0ch,al out 5,al mov al,1 out 5,al mov al,2 out 0ah,al Second sector: Code: use32 start: mov byte[0b8000h+2],42h times 510-($-start) db 0 I don't understand, i don't see nothing wrong, reads 510/512 byte in the second sector, I added also read msr register in the floppy controller for timeout, but why not read the dma buffers? The buffer is right, i'm beginning to doubt the emulator... |
|||
23 Jul 2014, 16:07 |
|
BAiC 23 Jul 2014, 16:22
when you get the interrupt handler done you'll do something like this:
Initialize the IVT entry for the Floppy Interrupt by writing to the IVT: Code: mov dword [0+8*4+4*6], (handler shr 4) shl 16 + (handler and 15);store the SEG:OFF address of the handler into the IVT (real mode address) it doesn't change the code much but here is the patched version: Code: org 7c00h use16 jmp 0:x86 x86: mov ax, 0 mov gs, ax mov fs, ax mov ds, ax mov es, ax mov ss, ax mov sp, 0x7C0 ;inform the IVT where the Floppy Interrupt Handler is... mov dword [0+8*4+ 4*6], (start shr 4) shl 16 + (start and 15) sti 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,0ffh out 5,al ; Count Port Low mov al,1 out 5,al ; Count Port High mov al, start shr 16 out 81h,al ; Address Register High (Page Register). 0 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 out dx,al jmp $ times 510-($-$$) db 0 dw 0aa55h start: mov di, 0b800h mov ds, di xor di, di mov eax, "H i " mov[di],eax jmp $ times 510-($-start) db 12 dw 0aa55h the last line is required for VirtualBox (the signature 0xAA55) to boot successfully. also; I changed how the text is printed to the screen (it says "Hi"). the emulator your using might be bad. I'm testing with VirtualBox and VMware (i usually use VMware for my own OS). -Stefan _________________ byte me. Last edited by BAiC on 23 Jul 2014, 16:28; edited 1 time in total |
|||
23 Jul 2014, 16:22 |
|
BAiC 23 Jul 2014, 16:24
Code: mov byte[0b8000h+2],42h writing a byte to screen memory won't do anything if the attribute byte is zero (foreground and background are black for zero). _________________ byte me. |
|||
23 Jul 2014, 16:24 |
|
neo-92 23 Jul 2014, 16:58
also applies to the protected mode the same procedure? Because is it here that I'm banging my head in to see why it does not work.
|
|||
23 Jul 2014, 16:58 |
|
BAiC 23 Jul 2014, 17:29
first of all; your trying to step through a very complex process with partial code sections. you need the FULL set of routines before you can successfully use a driver.
line 18 in the full Read Mode code needs an equivalent version for Protected Mode. YOU NEED AN INTERRUPT HANDLER -Stefan _________________ byte me. |
|||
23 Jul 2014, 17:29 |
|
neo-92 23 Jul 2014, 18:18
This can be of help?
http://prodebug.sourceforge.net/pmtut.html#Interrupt%20Handling Because i would like create just a driver |
|||
23 Jul 2014, 18:18 |
|
BAiC 24 Jul 2014, 03:53
when you first boot into Real Mode the BIOS has already built an Interrupt Vector Table for itself. you can patch it (as I did in my edit of your code) by writing over a single entry although this is atypical and not recommended in general.
in general you need to: ) clear interrupts so none fire while your working. ) initialize the PIC. the minimum is the 8259 (you only _need_ to initialize the first one, but you can initialize both). read the Long Mode boot example as it includes a PIC initialization. ) build an Interrupt Descriptor Table (it doesn't exist otherwise) somewhere in memory. ) include an entry for the Floppy handler. this is Interrupt 14 in the BIOS-built table. once you initialize the PIC it might be different (the Floppy is Interrupt 6). ) issue the 'LIDT' instruction. ) do rest of interrupt blocking work THEN allow interrupts again. -Stefan _________________ byte me. |
|||
24 Jul 2014, 03:53 |
|
neo-92 24 Jul 2014, 17:03
Hi Stefan, i used 'cli' for disable the hardware interrupts, i build the interrupt descriptor table with 'lidt', the initialize PIC 8259 i tried but i have need understand on website http://wiki.osdev.org/8259_PIC. The interrupt 6 of floppy, how do i activate it if in protected mode exception triple fault?
|
|||
24 Jul 2014, 17:03 |
|
BAiC 24 Jul 2014, 18:18
you disable all interrupts (in the PIC) except the ones that have handlers within the IDT. masking the pins involve writing ones to the mask register. initializing the first PIC is as simple as this:
Code: PIC8259.Primary = 0x20;the port address of the PIC. PIC8259.ICW1 = 10001b;a constant that tells the hardware to expect 4 bytes of configuration data from the port address + 1. PIC8259.FirstVector = 0x20;Begin the table at interrupt 32 (hex 20). the floppy interrupt will occupy vector 38 (hex 26) in this case. PIC8259.mask.floppy = 1 shl 6; bit 6 corresponds to the floppy interrupt. mov al, PIC8259.ICW1 out PIC8259.Primary, al ; PIC8259.ICW1 mov al, PIC8259.FirstVector out PIC8259.Primary+1, al ; this is where the set of interrupt handlers begin. mov al, 100b out PIC8259.Primary+1, al mov al, 1 out PIC8259.Primary+1, al mov al, 255 - PIC8259.mask.floppy out PIC8259.Primary+1, al ; this is the mask. writing a 1 will disable the corresponding interrupt. you don't need to deal with the secondary controller to use the floppy. Quote: i build the interrupt descriptor table with 'lidt', you don't "build" the IDT with the 'lidt' instruction. you build the IDT with a seqeunce of writes (usually a loop) to memory THEN you use the LIDT instruction: Code: ;build IDT FIRST! store it at "TABLE_ADDRESS". the table should include the descriptor for the floppy Interrupt Service Routine. push 0 push TABLE_ADDRESS shr 16 push (TABLE_ADDRESS and 0xFFFF) shl 16 + (256*8 - 1) lidt [esp] add esp, 12 - Stefan _________________ byte me. |
|||
24 Jul 2014, 18:18 |
|
neo-92 25 Jul 2014, 11:31
Hi Stefan, but it is not the same thing on this website?
INIT_IDT The interrupt handler i had already understand... INT_HANDLER However, there is something wrong. The ISR work in this case: Code: mov eax,isr_fdc mov [table2+49*8],ax mov word[table2+49*8+2],code32-table1 mov word[table2+49*8+4],8e00h shr eax,16 mov [table2+49*8+6],ax int 49 Can be a problem of floppy timekeeping? |
|||
25 Jul 2014, 11:31 |
|
BAiC 25 Jul 2014, 12:55
Code: int 49 is NOT an interrupt. it's just a really complicated procedure call. you need an actual interrupt. |
|||
25 Jul 2014, 12:55 |
|
revolution 25 Jul 2014, 13:00
Perhaps there is a need to properly define the difference between software interrupts (the INT instruction) and hardware interrupts (the INTR pin on the CPU).
|
|||
25 Jul 2014, 13:00 |
|
neo-92 25 Jul 2014, 13:08
I know perfectly the difference between interrupt software and interrupt hardware, how do to call this procedure for the controller floppy? Just to clarify... the BIOS interrupt 0x13 doesn't work in protected mode.
|
|||
25 Jul 2014, 13:08 |
|
BAiC 25 Jul 2014, 13:18
until you take control of the interrupt controllers an interrupt may fire during PM execution. the webpage you provided is assuming a set of true interrupt handlers exist for whatever hardware exists.
this is one example: the timer IRQ0 is a standard source of interrupts regardless of cpu mode. you don't provide an interrupt handler for it therefore when your in PM with interrupts enabled the TIMER interrupt executes but the IDT is invalid there (the real mode IVT data is still there). YOU NEED TO INITIALIZE THE FULL IDT. It is NOT sufficient to write a single IDT entry. _________________ byte me. |
|||
25 Jul 2014, 13:18 |
|
Goto page Previous 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.