Polling PMode Floppy Driver

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
benjidial
Posts: 1
Joined: Sat May 23, 2020 1:13 pm

Polling PMode Floppy Driver

Post by benjidial »

I'm currently writing a floppy driver for a 32-bit protected mode OS. I'm planning not to use DMA or any other asynchronous things for now, as my OS is single-tasking. I have interrupts disabled in the floppy controller for the same reason. I read the wiki page here on the floppy controller, but I can't figure out how to read a sector from a drive properly. My current floppy driver source code (32-bit GNU C) is attached. panic prints the supplied message and a stacktrace, then halts. SPT is the sectors per track, taken from the FAT record in the boot sector. On boot, my kernel calls init_floppy, then uses read_sectors to read the FAT from disk into memory. When I run my kernel, the panic function on line 95 in floppy_out is called. Going up the stack, this is called from line 102 in floppy_sense, from line 168 in read_sector, from line 192 in read_sectors. I'm not sure what's going wrong here. Am I not supposed to do a sense interrupt after issuing a read command? Is my read command malformed? Is there an earlier error that goes undetected until now?
Attachments
floppy.c
(4.29 KiB) Downloaded 25 times
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: Polling PMode Floppy Driver

Post by Octocontrabass »

benjidial wrote:Am I not supposed to do a sense interrupt after issuing a read command?
You're supposed to poll MSR. The sense interrupt command is meant to be used with the seek and recalibrate commands.

(I'd argue that you're supposed to use DMA and IRQs, but it's your OS and you can make it however you want.)
Post Reply