floppy disk interrupt

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sigler
Posts: 15
Joined: Wed Oct 31, 2007 11:37 am

floppy disk interrupt

Post by sigler »

Hello,

I'm trying to write a floppy disk driver. The first problem that I've encountered is that the floppy interrupt isn't getting called. Here's parts of my code:


The interrupt handler:

Code: Select all


global _floppy_int

_floppy_int:

	mov byte[0xb8000],'F'
	mov byte[0xb8002],'L'
	mov byte[0xb8004],'O'
	mov byte[0xb8006],'P'
	mov byte[0xb8008],'P'
	mov byte[0xb800A],'Y'

	jmp $


I setup the idt entries like this:

Code: Select all


		load_idt_entry(32, timer_int, 8, 0x8E);
		load_idt_entry(33, keyboard_int, 8, 0x8E);
		load_idt_entry(38, floppy_int, 8, 0x8E/*BITS_32 | PRESENT | INT_GATE | RING_0*/);
I'm not sure if I should use INT_GATE or TRAP_GATE?


I initialize the pic like this:

Code: Select all

void pic_init()
{
	outb(MASTER_PORT_A, 0x11);		// ICW 1
	outb(SLAVE_PORT_A, 0x11);		// 7 | 6 | 5 | 4 | 3  | 2 | 1  |
						// 0 | 0 | 0 | 1 |Trig|M/S|ICW4|
						// Master Slave Configuration
						// IC4 needed                            

	outb(MASTER_PORT_B, 0x20);		// ICW 2

	outb(SLAVE_PORT_B, 0x28);		// INT 0x20-0x27 mapped to IRQ 0 to IRQ 7
						// INT 0x28-0x2F mapped to IRQ 8 to IRQ 15
	

	outb(MASTER_PORT_B, 0x04);   		 // ICW 3 

	outb(SLAVE_PORT_B, 0x02);      		// IR 2 of master is connected to slave pic
						// IRQ on master this slave is connected to
	
	outb(MASTER_PORT_B, 0x01);		// ICW 4

	outb(SLAVE_PORT_B, 0x01);		// Master, Fully Nested Mode
						// Slave, Fully Nested Mode

	outb(MASTER_PORT_B, 0xFF);		// All interrupts except IRQ 0 are disabled

	outb(SLAVE_PORT_B, 0xFF);
}
I enable irqs like this:

Code: Select all

void enable_irq(byte irq_num)
{
	byte mask = 1 << irq_num;
	irq_status_master |= mask;
	
	outb(MASTER_PORT_B,(byte)~irq_status_master);
}
Then I do:

Code: Select all


#define FLOPPY 0x6
	enable_irq(FLOPPY);

Then I program the floppy disk controller

Code: Select all


#define FLOPPY_PRIMARY_BASE     0x03F0
#define DIGITAL_OUTPUT_REG      0x0002
#define DOR_ENABLE		0x04	/* enable controller (= !reset) */
#define DOR_IRQDMA		0x08	/* IRQ & DMA enabled */

	outportb((base+DIGITAL_OUTPUT_REG),0x00); /*disable controller*/


	outportb((base+DIGITAL_OUTPUT_REG), (DOR_ENABLE | DOR_IRQDMA)/*0x0c*/); /*enable controller*/
Documentation says that I should receive a floppy interrupt after doing that, but I don't.

I've tried on a real computer as well as on VMWare

timer and keyboard interrupts work just fine.

I hope someone can help me with this, thanks.

--
Sigurd Lerstad
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

You would think that since the floppy drive is so old it would work the same on every computer and stick to the specifications but it doesn't seem to. Anyways in my code I just skip waiting for the first interrupt after reseting the drive and go straight to issuing the sense interrupt command 4 times. That seems to work in every emulator and every real computer I have tried it on.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Floppy controller work the same, eg: if your code works on one real PC, it will work on all, if you discard things like delay timing.
So you need to re-look at your code.

Now once you move on to things like ATAPI, you will see how constant floppy controller are.
Post Reply