diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-08-20 19:04:41 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-08-20 19:04:41 +0200 |
| commit | 72857991ed93a55dd0f14f95a19de48574db7cc3 (patch) | |
| tree | ed564f10da183dcaf501ddcba166befe3d1ccf3a /kernel/floppy.c | |
| parent | dc164927e71d760a41494ab1edf8e3deeda401db (diff) | |
functional floppy driver (in emulators at least)
Diffstat (limited to 'kernel/floppy.c')
| -rw-r--r-- | kernel/floppy.c | 104 |
1 files changed, 73 insertions, 31 deletions
diff --git a/kernel/floppy.c b/kernel/floppy.c index 2c71cdb..a3c1c2a 100644 --- a/kernel/floppy.c +++ b/kernel/floppy.c @@ -1,3 +1,22 @@ +/* + * Fool OS Simple Floppy Driver. + * + * coded by M.idziorek <m.i@gmx.at> on 20th of august 2014 A.D + * + * tested in : bochs, qemu and virutalbox so far + * + * resources: + * + * * http://wiki.osdev.org/Floppy_Disk_Controller#DMA_Data_Transfers + * * http://forum.osdev.org/viewtopic.php?f=1&t=13538 + * * http://www.brokenthorn.com/Resources/OSDev20.html + * * http://bochs.sourceforge.net/cgi-bin/lxr/source/iodev/floppy.cc + * + * + * + * + * + */ #include "x86.h" #define FLPY_SECTORS_PER_TRACK 80 @@ -14,7 +33,7 @@ void flpydsk_initialize_dma () { //changed to 0x000 (Address) x86_outb (0x04, 0x0); //low - x86_outb (0x04, 0xa0); //high + x86_outb (0x04, 0xb0); //high x86_outb (0xd8, 0xff); //reset master flip-flop x86_outb (0x05, 0xff); //count to 0x23ff (number of bytes in a 3.5" floppy disk track) @@ -140,14 +159,16 @@ void sleep(int i) void flpydsk_motor_on() { scr_put_string("floppy: starting motor..."); - x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET); + //x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET); + x86_outb (FLPYDSK_DOR, 0x1c); sleep(20); scr_put_string_nl("ok"); } void flpydsk_motor_off() { scr_put_string("floppy: stopping motor..."); - x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET); + x86_outb (FLPYDSK_DOR, 0x0c); + //x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET); scr_put_string_nl("ok"); } @@ -177,12 +198,15 @@ int flpydsk_calibrate (uint32_t drive) { //! did we fine cylinder 0? if so, we are done if (!cyl) { - + if(st0 & 0xC0) { + scr_put_string_nl("floppy: calibration FAILED!"); + } // flpydsk_control_motor (false); flpydsk_motor_off(); return 0; } } + scr_put_string_nl("floppy: calibration FAILED!"); // flpydsk_control_motor (false); flpydsk_motor_off(); @@ -215,6 +239,8 @@ uint8_t flpydsk_read_data () { for (i = 0; i < 500; i++ ) if ( flpydsk_read_status () & FLPYDSK_MSR_MASK_DATAREG ) return x86_inb (FLPYDSK_FIFO); + + scr_put_string_nl("floppy: read data fail!"); } void flpydsk_send_command (uint8_t cmd) { @@ -226,9 +252,10 @@ void flpydsk_send_command (uint8_t cmd) { x86_outb(FLPYDSK_FIFO, cmd); return; } + scr_put_string_nl("floppy: write data fail!"); } -void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int nondma ) { +void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int dma ) { uint32_t data = 0; @@ -237,7 +264,7 @@ void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int n data = ( (stepr & 0xf) << 4) | (unloadt & 0xf); flpydsk_send_command (data); - data = (loadt) << 1 | nondma; + data = (loadt) << 1 | dma; flpydsk_send_command (data); } @@ -260,31 +287,22 @@ void flpydsk_reset() flpydsk_write_ccr (0); //! pass mechanical drive info. steprate=3ms, unload time=240ms, load time=16ms - flpydsk_drive_data (3,16,240,0); +// flpydsk_drive_data (3,16,240,0); +// + + flpydsk_send_command (FDC_CMD_SPECIFY); + flpydsk_send_command (0xdf); /* steprate = 3ms, unload time = 240ms */ + flpydsk_send_command (0x02); /* load time = 16ms, no-DMA = 0 */ //! calibrate the disk flpydsk_calibrate ( _CurrentDrive ); } -void floppy_init() -{ - // init dma - flpydsk_initialize_dma (); - - _CurrentDrive=0; - _FloppyDiskIRQ = 0; - - scr_put_string_nl("floppy: init floppy driver."); - - flpydsk_reset (); - flpydsk_drive_data (13, 1, 0xf, 0); - -} - void int_floppy_handler() { X86_IRQ_BEGIN + scr_put_string_nl("floppy: inside interrupt handler."); _FloppyDiskIRQ=1; X86_IRQ_END @@ -311,8 +329,8 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) { //! set the DMA for read transfer flpydsk_dma_read (); - flpydsk_drive_data (13, 1, 0xf, 0); - scr_put_string_nl("floppy: reading sector (2)"); + //flpydsk_drive_data (13, 1, 0xf, 0); + scr_put_string_nl("floppy: reading (head/track/sector)"); uint32_t st0, cyl; @@ -333,7 +351,7 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) { flpydsk_send_command ( 0xff ); //! wait for irq - //flpydsk_wait_irq (); + flpydsk_wait_irq (); //! read status info int j; @@ -346,6 +364,8 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) { int flpydsk_seek ( uint32_t cyl, uint32_t head ) { + cyl=1; + head=1; uint32_t st0, cyl0; @@ -363,12 +383,12 @@ int flpydsk_seek ( uint32_t cyl, uint32_t head ) //! send the command flpydsk_send_command (FDC_CMD_SEEK); - flpydsk_send_command ( (head) << 2 | _CurrentDrive); + flpydsk_send_command ( (head << 2) | _CurrentDrive); flpydsk_send_command (cyl); + //! wait for the results phase IRQ - //flpydsk_wait_irq (); - + flpydsk_wait_irq (); flpydsk_check_int (&st0,&cyl0); //! found the cylinder? @@ -389,8 +409,6 @@ void flpydsk_lba_to_chs (int lba,int *head,int *track,int *sector) { uint8_t* flpydsk_read_sector (int sectorLBA) { - sectorLBA=0x10; - scr_put_string("floppy: reading sector:"); scr_put_hex(sectorLBA); scr_put_string_nl("."); @@ -405,7 +423,6 @@ uint8_t* flpydsk_read_sector (int sectorLBA) { //! turn motor on and seek to track -// flpydsk_control_motor (true); // start motor flpydsk_motor_on(); @@ -424,3 +441,28 @@ uint8_t* flpydsk_read_sector (int sectorLBA) { } +void floppy_init() +{ + // init dma + flpydsk_initialize_dma (); + + _CurrentDrive=0; + _FloppyDiskIRQ = 0; + + scr_put_string_nl("floppy: init floppy driver."); + + flpydsk_reset (); +// flpydsk_drive_data (13, 1, 0xf, 0); + // flpydsk_drive_data (3,16,240,0); + // + flpydsk_read_sector(1); + uint16_t *dma=0xb000; + int i; + for(i=0;i<10;i++) + scr_put_hex(dma[i]); + + + scr_put_string_nl(""); + +} + |
