summaryrefslogtreecommitdiff
path: root/kernel/floppy.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/floppy.c')
-rw-r--r--kernel/floppy.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/kernel/floppy.c b/kernel/floppy.c
index a373ec7..557df2a 100644
--- a/kernel/floppy.c
+++ b/kernel/floppy.c
@@ -17,6 +17,10 @@
#include "x86.h"
+#include "../lib/logger/log.h" // logger facilities
+#define FOOLOS_MODULE_NAME "floppy"
+
+
#define FLPY_SECTORS_PER_TRACK 18
static volatile int _CurrentDrive=0;
@@ -26,7 +30,6 @@ static volatile uint8_t _FloppyDiskIRQ = 0;
//! initialize DMA to use phys addr 1k-64k
void flpydsk_initialize_dma () {
- scr_put_string_nl("dma: initialize direct memory access");
x86_outb (0x0a,0x06); //mask dma channel 2
x86_outb (0xd8,0xff); //reset master flip-flop
@@ -39,15 +42,15 @@ void flpydsk_initialize_dma () {
x86_outb (0x05, 0x23);
x86_outb (0x80, 0); //external page register = 0
x86_outb (0x0a, 0x02); //unmask dma channel 2
+ log("dma",FOOLOS_LOG_INFO,"initialized");
}
//! prepare the DMA for read transfer
void flpydsk_dma_read () {
-
x86_outb (0x0a, 0x06); //mask dma channel 2
x86_outb (0x0b, 0x56); //single transfer, address increment, autoinit, read, channel 2
x86_outb (0x0a, 0x02); //unmask dma channel 2
- scr_put_string_nl("dma: configured for reading");
+ log("dma",FOOLOS_LOG_INFO,"configured for reading");
}
//! prepare the DMA for write transfer
@@ -56,7 +59,7 @@ void flpydsk_dma_write () {
x86_outb (0x0a, 0x06); //mask dma channel 2
x86_outb (0x0b, 0x5a); //single transfer, address increment, autoinit, write, channel 2
x86_outb (0x0a, 0x02); //unmask dma channel 2
- scr_put_string_nl("dma: configured for writing");
+ log("dma",FOOLOS_LOG_INFO,"configured for writing");
}
//
//
@@ -157,7 +160,7 @@ void sleep(int i)
void flpydsk_motor_on()
{
- scr_put_string("floppy: starting motor...");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"starting motor...");
//x86_outb (FLPYDSK_DOR, FLPYDSK_DOR_MASK_DRIVE0_MOTOR | FLPYDSK_DOR_MASK_RESET);
x86_outb (FLPYDSK_DOR, 0x1c);
sleep(20);
@@ -165,7 +168,7 @@ void flpydsk_motor_on()
}
void flpydsk_motor_off()
{
- scr_put_string("floppy: stopping motor...");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"stopping motor...");
x86_outb (FLPYDSK_DOR, 0x0c);
//x86_outb (FLPYDSK_DOR,FLPYDSK_DOR_MASK_RESET);
scr_put_string_nl("ok");
@@ -178,7 +181,7 @@ int flpydsk_calibrate (uint32_t drive) {
if (drive >= 4)
{
- scr_put_string_nl("floppy: ERROR");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ERROR!");
return -2;
}
@@ -188,7 +191,7 @@ int flpydsk_calibrate (uint32_t drive) {
int i;
for (i = 0; i < 10; i++) {
- scr_put_string_nl("floppy: calibrate");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating");
//! send command
flpydsk_send_command ( FDC_CMD_CALIBRATE );
flpydsk_send_command ( drive );
@@ -198,14 +201,14 @@ 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!");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating FAILED!");
}
// flpydsk_control_motor (false);
flpydsk_motor_off();
return 0;
}
}
- scr_put_string_nl("floppy: calibration FAILED!");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"calibrating FAILED!");
// flpydsk_control_motor (false);
flpydsk_motor_off();
@@ -239,7 +242,7 @@ uint8_t flpydsk_read_data () {
if ( flpydsk_read_status () & FLPYDSK_MSR_MASK_DATAREG )
return x86_inb (FLPYDSK_FIFO);
- scr_put_string_nl("floppy: read data fail!");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading data FAILED!");
}
void flpydsk_send_command (uint8_t cmd) {
@@ -251,7 +254,7 @@ void flpydsk_send_command (uint8_t cmd) {
x86_outb(FLPYDSK_FIFO, cmd);
return;
}
- scr_put_string_nl("floppy: write data fail!");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing data FAILED!");
}
void flpydsk_drive_data (uint32_t stepr, uint32_t loadt, uint32_t unloadt, int dma ) {
@@ -272,7 +275,7 @@ void flpydsk_reset()
uint32_t st0, cyl;
//! reset the controller
- scr_put_string_nl("floppy: reset controller");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reset controller");
flpydsk_disable_controller ();
flpydsk_enable_controller ();
flpydsk_wait_irq ();
@@ -301,7 +304,7 @@ void int_floppy_handler()
{
X86_IRQ_BEGIN
- scr_put_string_nl("floppy: inside interrupt handler.");
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"handling interrupt");
_FloppyDiskIRQ=1;
X86_IRQ_END
@@ -309,10 +312,10 @@ void int_floppy_handler()
void flpydsk_wait_irq()
{
- scr_put_string_nl("floppy: wait for irq6");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"waiting for irq6");
while ( _FloppyDiskIRQ == 0);
_FloppyDiskIRQ = 0;
- scr_put_string_nl("floppy: ok received ");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"irq6 received");
}
void flpydsk_check_int (uint32_t* st0, uint32_t* cyl) {
@@ -325,12 +328,12 @@ void flpydsk_check_int (uint32_t* st0, uint32_t* cyl) {
void flpydsk_write_sector_imp (uint8_t head, uint8_t track, uint8_t sector) {
- sector=1;
+ //sector=1;
//! set the DMA for read transfer
flpydsk_dma_write ();
//flpydsk_drive_data (13, 1, 0xf, 0);
- scr_put_string_nl("floppy: writing (head/track/sector)");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing head/track/sector");
uint32_t st0, cyl;
@@ -372,7 +375,7 @@ void flpydsk_read_sector_imp (uint8_t head, uint8_t track, uint8_t sector) {
flpydsk_dma_read ();
//flpydsk_drive_data (13, 1, 0xf, 0);
- scr_put_string_nl("floppy: reading (head/track/sector)");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading head/track/sector");
uint32_t st0, cyl;
@@ -422,11 +425,7 @@ int flpydsk_seek ( uint32_t cyl, uint32_t head )
int i;
for (i = 0; i < 10; i++ ) {
- scr_put_string("floppy: seeking (cyl/head) : ");
- scr_put_hex(cyl);
- scr_put_string("/");
- scr_put_hex(head);
- scr_put_string_nl("");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"seeking cyl: %d, head: %d",cyl,head);
//! send the command
flpydsk_send_command (FDC_CMD_SEEK);
@@ -462,9 +461,7 @@ void flpydsk_lba_to_chs (int lba,int *head,int *track,int *sector) {
uint8_t* flpydsk_read_sector (int sectorLBA) {
- scr_put_string("floppy: reading sector:");
- scr_put_hex(sectorLBA);
- scr_put_string_nl(".");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"reading sector: %d",sectorLBA);
if (_CurrentDrive >= 4)
@@ -495,10 +492,7 @@ uint8_t* flpydsk_read_sector (int sectorLBA) {
uint8_t* flpydsk_write_sector (int sectorLBA) {
- scr_put_string("floppy: writing sector:");
- scr_put_hex(sectorLBA);
- scr_put_string_nl(".");
-
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"writing sector: %d",sectorLBA);
if (_CurrentDrive >= 4)
return 0;
@@ -533,8 +527,8 @@ void floppy_init()
_CurrentDrive=0;
_FloppyDiskIRQ = 0;
-
- scr_put_string_nl("floppy: init floppy driver.");
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"driver init");
flpydsk_reset ();
// flpydsk_drive_data (13, 1, 0xf, 0);
@@ -543,18 +537,19 @@ void floppy_init()
//
//
- scr_put_string_nl("floppy: test read (sector 0).");
- flpydsk_read_sector(64); //0x8000 here the data starts!
- scr_put_string_nl("floppy: data: ");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test read (sector: 1)");
+ 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("");
-
- /*
- scr_put_string_nl("floppy: test write (sector 100).");
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test read 0x%04x ",dma[i]);
+ }
+
+/*
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"test write (sector: 100)");
flpydsk_write_sector(100);
*/