[GOOD] BUILD 0.1.0.551 DATE 9/03/2011 AT 9:25 AM
==================================================== Mainly changed: HAL.FSs + Updated 'mount' call in floppy driver, now done after controller is initialized + Added 'detect' function for FAT file systems + Implemented 'initdr' driver, however still bugged + Improved logger
This commit is contained in:
		@@ -5,6 +5,7 @@
 | 
			
		||||
#include "time.h"
 | 
			
		||||
#include "../hal/cpu/irq.h"
 | 
			
		||||
#include <debugio.h>
 | 
			
		||||
#include <settings.h>
 | 
			
		||||
 | 
			
		||||
void DriversInstall_Clock()
 | 
			
		||||
{
 | 
			
		||||
@@ -17,8 +18,7 @@ void DriversInstall_Clock()
 | 
			
		||||
 | 
			
		||||
	TimeSetInternalTime(ConvertTimeToTimeSystem(time));
 | 
			
		||||
 | 
			
		||||
	Log("%#[Drivers] %#Read RTC time: ", ColorWhite, ColorLightGray);
 | 
			
		||||
	Log("%#%u/%u/%u %u:%u:%u.%u\n", ColorLightCyan, time.Month, time.Day,
 | 
			
		||||
	Log("Drivers", "Read RTC time: %#%u/%u/%u %u:%u:%u.%u\n", ColorLightCyan, time.Month, time.Day,
 | 
			
		||||
			time.Year, time.Hour, time.Minute, time.Second, time.Milisecond);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,9 +7,10 @@
 | 
			
		||||
 | 
			
		||||
#include <debugio.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <types.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <storage.h>
 | 
			
		||||
#include <fileio.h>
 | 
			
		||||
#include "floppy.h"
 | 
			
		||||
#include "../dma/dma.h"
 | 
			
		||||
#include "../cmos/cmos.h"
 | 
			
		||||
@@ -54,7 +55,7 @@ void FloppyWaitIrq()
 | 
			
		||||
	while (!FloppyIrqFired && !TimerIsDone());
 | 
			
		||||
 | 
			
		||||
	if (!FloppyIrqFired) {
 | 
			
		||||
		Error("%#[Floppy] %#Irq timeout [%ums] !\n", ColorBrown, ColorLightRed, fdTypes[4].InterruptTimeout);
 | 
			
		||||
		Error("Floppy", "Irq timeout [%ums] !\n", fdTypes[4].InterruptTimeout);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -73,17 +74,12 @@ void FloppyInitialize()
 | 
			
		||||
	if (fd1 > 6) fd1 = 0;
 | 
			
		||||
 | 
			
		||||
	if (!fd0 && !fd1) {
 | 
			
		||||
		Error("%#[Floppy] %#No supported floppy drives found.", ColorBrown, ColorLightRed);
 | 
			
		||||
		Error("Floppy", "No supported floppy drives found.");
 | 
			
		||||
		outportb(FloppyRegisterDigitalOutput, 0);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	Log("%#[Floppy] %#Detected floppy drives:", ColorBrown, ColorLightGray);
 | 
			
		||||
	if (fd0) Log(" %#fd0=%#%s", ColorLightCyan, Color(ColorCyan, ColorWhite), fdTypes[fd0].Name);
 | 
			
		||||
	if (fd1) Log(" %#fd1=%#%s", ColorLightCyan, Color(ColorCyan, ColorWhite), fdTypes[fd1].Name);
 | 
			
		||||
	Log("\n");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	Log("Floppy", "Detected floppy drives: %#fd0=%#%s %#fd1=%#%s\n", ColorLightCyan, Color(ColorCyan, ColorWhite), fdTypes[fd0].Name, ColorLightCyan, Color(ColorCyan, ColorWhite), fdTypes[fd1].Name);
 | 
			
		||||
	// Reset floppy controller
 | 
			
		||||
	FloppyReset();
 | 
			
		||||
 | 
			
		||||
@@ -106,6 +102,11 @@ void FloppyInitialize()
 | 
			
		||||
 | 
			
		||||
	// Initialize DMA
 | 
			
		||||
	FloppyInitDma();
 | 
			
		||||
 | 
			
		||||
	// Mount
 | 
			
		||||
	if (fd0) VfsMount("fd0", Floppy0ReadRoutine, Floppy0WriteRoutine, Min (fdTypes[fd0].SectorsPerTrack * 512, 0x2400));
 | 
			
		||||
	if (fd1) VfsMount("fd1", Floppy1ReadRoutine, Floppy1WriteRoutine, Min (fdTypes[fd1].SectorsPerTrack * 512, 0x2400));
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FloppyInitDma()
 | 
			
		||||
@@ -127,7 +128,7 @@ void FloppyReset()
 | 
			
		||||
{
 | 
			
		||||
	FloppyIrqFired = 0; int32 i = 0;
 | 
			
		||||
 | 
			
		||||
	Log("%#[Floppy] %#Resetting...\n", ColorBrown, ColorLightGray);
 | 
			
		||||
	Log("Floppy", "Resetting...\n");
 | 
			
		||||
 | 
			
		||||
	// Clear reset bit from DOR
 | 
			
		||||
	outportb(FloppyRegisterDigitalOutput, 0);
 | 
			
		||||
@@ -226,7 +227,7 @@ void FloppyMotor (uint8 fd_number, uint8 status)
 | 
			
		||||
	if (status) TimerStart(fdTypes[fd].Spinup);
 | 
			
		||||
	else TimerStart(fdTypes[fd].Spindown);
 | 
			
		||||
 | 
			
		||||
	Log("%#[Floppy] %#Waiting for motor...\n", ColorBrown, ColorLightGray);
 | 
			
		||||
	Log("Floppy", "Waiting for motor...\n");
 | 
			
		||||
	while (!TimerIsDone());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -259,7 +260,7 @@ void FloppyRecalibrate(uint8 fd_number)
 | 
			
		||||
 | 
			
		||||
	uint8 st0, cyl, timeout = 10;
 | 
			
		||||
	do {
 | 
			
		||||
		Log("%#[Floppy] %#Recalibrating: attempt %u/10\n", ColorBrown, ColorLightGray, 11-timeout);
 | 
			
		||||
		Log("Floppy", "Recalibrating: attempt %u/10\n", 11-timeout);
 | 
			
		||||
		FloppyIrqFired = 0;
 | 
			
		||||
		FloppySendCommand(FloppyCommandRecalibrate);
 | 
			
		||||
		FloppySendCommand(fd_number);
 | 
			
		||||
@@ -281,7 +282,7 @@ void FloppySeek(uint8 fd_number, uint8 cylinder, uint8 head)
 | 
			
		||||
 | 
			
		||||
	uint8 st0, cyl, timeout = 10;
 | 
			
		||||
	do {
 | 
			
		||||
		Log("%#[Floppy] %#Seeking: attempt %u/10\n", ColorBrown, ColorLightGray, 11-timeout);
 | 
			
		||||
		Log("Floppy", "Seeking: attempt %u/10\n", 11-timeout);
 | 
			
		||||
		FloppyIrqFired = 0;
 | 
			
		||||
		FloppySendCommand(FloppyCommandSeek);
 | 
			
		||||
		FloppySendCommand(head<<2 | fd_number);
 | 
			
		||||
@@ -309,7 +310,7 @@ void FloppyRW(uint8 isWrite, uint8 fd_number, uint8 head, uint8 cylinder, uint8
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		error = 0;
 | 
			
		||||
		Log("%#[Floppy] %#Read/write operation: attempt %u/10\n", ColorBrown, ColorLightGray, 11-timeout);
 | 
			
		||||
		Log("Floppy", "Read/write operation: attempt %u/10\n", 11-timeout);
 | 
			
		||||
		FloppyIrqFired = 0;
 | 
			
		||||
 | 
			
		||||
		if (isWrite) FloppySendCommand(FloppyCommandWriteData | FloppyModeMultitrack | FloppyModeMagneticEncoding);
 | 
			
		||||
@@ -332,7 +333,7 @@ void FloppyRW(uint8 isWrite, uint8 fd_number, uint8 head, uint8 cylinder, uint8
 | 
			
		||||
		// Disk is write protected, don't try again
 | 
			
		||||
		if (result[1] & 2)
 | 
			
		||||
		{
 | 
			
		||||
			Error("%#[Floppy] %#Error: disk is write protected!\n", ColorBrown, ColorLightRed);
 | 
			
		||||
			Error("Floppy", "Error: disk is write protected!\n");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -354,7 +355,7 @@ uint32 FloppyRead(uint8 drive, uint32 lba)
 | 
			
		||||
	// Convert LBA to CHS
 | 
			
		||||
	uint32 cyl=0, head=0, sect=1;
 | 
			
		||||
	ConvertLbaToChs(fdTypes[fd].SectorsPerTrack, lba, &cyl, &head, §);
 | 
			
		||||
	Log("%#[Floppy] %#Converted LBA=%u to Cyl=%u Head=%u Sect=%u\n", ColorBrown, ColorLightGray, lba, cyl, head, sect);
 | 
			
		||||
	Log("Floppy", "Converted LBA=%u to Cyl=%u Head=%u Sect=%u\n", lba, cyl, head, sect);
 | 
			
		||||
 | 
			
		||||
	FloppyInitDma();
 | 
			
		||||
 | 
			
		||||
@@ -381,4 +382,71 @@ uint32 FloppyRead(uint8 drive, uint32 lba)
 | 
			
		||||
	return 0x1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Log("%#[Drivers] %#Initializing blah blah %d...", ColorWhite, ColorLightGray,PIT_FREQUENCY);
 | 
			
		||||
uint32 FloppyWrite(uint8 drive, uint32 lba)
 | 
			
		||||
{
 | 
			
		||||
	if (drive >= 2) return 0;
 | 
			
		||||
	uint8 fd = (drive == 0) ? fd0 : fd1;
 | 
			
		||||
 | 
			
		||||
	// Convert LBA to CHS
 | 
			
		||||
	uint32 cyl=0, head=0, sect=1;
 | 
			
		||||
	ConvertLbaToChs(fdTypes[fd].SectorsPerTrack, lba, &cyl, &head, §);
 | 
			
		||||
	Log("Floppy", "Converted LBA=%u to Cyl=%u Head=%u Sect=%u\n", lba, cyl, head, sect);
 | 
			
		||||
 | 
			
		||||
	FloppyInitDma();
 | 
			
		||||
 | 
			
		||||
	// Reset drive if necessary
 | 
			
		||||
	if ((inportb(FloppyRegisterMainStatus) & 0xC0) != 0x80)
 | 
			
		||||
		FloppyReset();
 | 
			
		||||
 | 
			
		||||
	// Start motor, select drive
 | 
			
		||||
	FloppyMotor(drive, 1);
 | 
			
		||||
	FloppySelectDrive(drive);
 | 
			
		||||
 | 
			
		||||
	// Seek to correct location
 | 
			
		||||
	FloppySeek(drive, cyl, head);
 | 
			
		||||
 | 
			
		||||
	// Start DMA write
 | 
			
		||||
	DmaMaskChannel(2);
 | 
			
		||||
	DmaSetMode(2, 0x4A);
 | 
			
		||||
	DmaUnmaskChannel(2);
 | 
			
		||||
 | 
			
		||||
	FloppyRW(0, drive, head, cyl, sect);
 | 
			
		||||
 | 
			
		||||
	FloppyMotor(drive, 0);
 | 
			
		||||
 | 
			
		||||
	return 0x1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*** Theses are for the VFS ***/
 | 
			
		||||
uint32 Floppy0ReadRoutine (uint32 offset, void* buffer)
 | 
			
		||||
{
 | 
			
		||||
	uint32 ret = FloppyRead(0, offset);
 | 
			
		||||
 | 
			
		||||
	if (!ret) return NULL;
 | 
			
		||||
	memcpy(buffer, (const void*) ret, 0x2400);
 | 
			
		||||
 | 
			
		||||
	return (uint32)buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32 Floppy1ReadRoutine (uint32 offset, void* buffer)
 | 
			
		||||
{
 | 
			
		||||
	uint32 ret = FloppyRead(1, offset);
 | 
			
		||||
 | 
			
		||||
	if (!ret) return NULL;
 | 
			
		||||
	memcpy(buffer, (const void*) ret, 0x2400);
 | 
			
		||||
 | 
			
		||||
	return (uint32)buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32 Floppy0WriteRoutine (uint32 offset, void* buffer)
 | 
			
		||||
{
 | 
			
		||||
	memcpy((void*)0x1000, buffer, 0x2400);
 | 
			
		||||
	return FloppyWrite(0, offset);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32 Floppy1WriteRoutine (uint32 offset, void* buffer)
 | 
			
		||||
{
 | 
			
		||||
	memcpy((void*)0x1000, buffer, 0x2400);
 | 
			
		||||
	return FloppyWrite(1, offset);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -82,5 +82,11 @@ extern void FloppySelectDrive(uint8 number);
 | 
			
		||||
extern void FloppyRecalibrate(uint8 fd_number);
 | 
			
		||||
extern void FloppyRW(uint8 isWrite, uint8 fd_number, uint8 head, uint8 cylinder, uint8 sector);
 | 
			
		||||
extern uint32 FloppyRead(uint8 drive, uint32 lba);
 | 
			
		||||
extern uint32 FloppyWrite(uint8 drive, uint32 lba);
 | 
			
		||||
 | 
			
		||||
extern uint32 Floppy0ReadRoutine (uint32 offset, void* buffer);
 | 
			
		||||
extern uint32 Floppy1ReadRoutine (uint32 offset, void* buffer);
 | 
			
		||||
extern uint32 Floppy0WriteRoutine (uint32 offset, void* buffer);
 | 
			
		||||
extern uint32 Floppy1WriteRoutine (uint32 offset, void* buffer);
 | 
			
		||||
 | 
			
		||||
#endif /* FLOPPY_H_ */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user