diff --git a/.cproject b/.cproject
index 8d7bfa2..4a4e660 100644
--- a/.cproject
+++ b/.cproject
@@ -27,7 +27,7 @@
-
diff --git a/Build/main.o b/Build/main.o
index c9b39ef..7afe337 100644
Binary files a/Build/main.o and b/Build/main.o differ
diff --git a/Kernel/debug/commands.c b/Kernel/debug/commands.c
index 7393ead..2782440 100644
--- a/Kernel/debug/commands.c
+++ b/Kernel/debug/commands.c
@@ -4,6 +4,7 @@
#include
#include "../hal/mouse/mouse.h"
#include "../drivers/floppy/floppy.h"
+#include
string ConsoleCommands[] =
{
@@ -18,9 +19,11 @@ string ConsoleCommands[] =
"read",
"reboot",
"restart",
+ "dir",
+ "cat"
};
-int32 ConsoleCommandsCount = 11;
+int32 ConsoleCommandsCount = 13;
/*****************************************
* osver - get os info *
@@ -253,3 +256,67 @@ void CommandRead(string argv[], int32 argc)
uint32 sector = ConvertStringToUInt(argv[1]);
ConsoleWrite("Returned value: 0x%x\n", FloppyRead(0, sector));
}
+
+
+extern MountPoint* mpArray;
+extern uint32 mpCount;
+void CommandDir (string argv[], int32 argc)
+{
+ if (argc < 2)
+ {
+ ConsoleWrite ("Content of root: \n\n");
+ uint32 i = 0;
+
+ for (i = 0; i < mpCount; i++)
+ ConsoleWrite ("\t\t[DEV] %s\n", mpArray[i].Name);
+
+ return;
+ }
+
+ DirectoryEntry* temp = VfsTest(argv[1]);
+
+ if (temp == NULL)
+ {
+ ConsoleWrite("%#! Invalid path!\n", ColorLightRed);
+ return;
+ }
+
+ ConsoleWrite ("Content of directory %#%s:\n\n", ColorWhite, argv[1]);
+
+ FILE dir; VfsOpen(&dir, argv[1]);
+ uint32 i;
+
+ temp = VfsReadDirectory(&dir,0);
+ for (i = 1; temp != NULL; i++, temp = VfsReadDirectory(&dir, 0))
+ {
+ ConsoleWrite ("\t\t[%s] ", (temp->Flags & 0x1) ? "FIL" : "DIR" );
+ ConsoleWrite ("%s", temp->Name);
+ Point p = {60, -1}; ConsoleCursorGoto(p);
+ ConsoleWrite ("%u bytes\n", temp->Size);
+ }
+
+ VfsClose(&dir);
+}
+
+void CommandCat (string argv[], int32 argc)
+{
+ if (argc < 2) {
+ ConsoleWrite("%#! Missing parameter - complete file path.\n", ColorLightRed);
+ return;
+ }
+
+ ConsoleWrite("Contents of file %s:\n--------------------------\n");
+ FILE f;
+ VfsOpen(&f, argv[1]);
+ uint8* buffer = kmalloc(0x1000);
+ uint32 sz, i;
+
+ while ((sz = VfsRead(&f, 1, 0x1000, buffer)))
+ {
+ for (i = 0; i < sz; i++) ConsoleWrite("%c", buffer[i]);
+ }
+
+ ConsoleWrite("\n--------------------------\n");
+ kfree(buffer);
+ VfsClose(&f);
+}
diff --git a/Kernel/debug/console.c b/Kernel/debug/console.c
index b98ba17..4d819df 100644
--- a/Kernel/debug/console.c
+++ b/Kernel/debug/console.c
@@ -71,6 +71,8 @@ void _process_command (string params[CONSOLE_MAX_PARAMS], int32 count)
case 8: CommandRead(params, count); break;
case 9:
case 10: SystemReboot(); break;
+ case 11: CommandDir(params, count); break;
+ case 12: CommandCat(params, count); break;
default: ConsoleWrite ("%#! Command %#%s%# was not implemented (yet)!\n",
Color(0,ColorLightRed), Color(0,ColorWhite), params[0], Color(0,ColorLightRed)); break;
diff --git a/Kernel/debug/logger.c b/Kernel/debug/logger.c
new file mode 100644
index 0000000..9548277
--- /dev/null
+++ b/Kernel/debug/logger.c
@@ -0,0 +1,122 @@
+/*
+ * logger.c
+ *
+ * Created on: Sep 2, 2011
+ * Author: Tiberiu
+ */
+#include
+#include
+
+string LogAllowedDevices[] = {
+ "drivers",
+ //"floppy",
+ "hal",
+ "fat",
+ "initrd",
+ "system",
+ "vfs",
+ //"mem",
+ "console",
+ 0x0,
+ 0x0
+};
+
+
+extern uint8 ConsoleDefaultColor;
+extern void _write_char(char c);
+extern void _write_string (string s);
+
+int32 LogWrite (uint8 error, string device, string format, ...)
+{
+ if (!format || !*format || !device || !*device) return 0;
+
+ // Print logged information
+ va_list args;
+ va_start (args, format);
+ uint32 i, len = strlen(format);
+ uint8 temp_color = ConsoleDefaultColor;
+
+ // Check if device is allowed. Errors are allowed
+ uint8 allowed = error;
+ for (i = 0; LogAllowedDevices[i] != 0 && !allowed; i++)
+ if (strcasecmp(device, LogAllowedDevices[i]) == 0) allowed = 1;
+
+ if (allowed)
+ {
+ ConsoleDefaultColor = (error) ? Color(ColorRed, ColorWhite) : (1 + (i % 15)) ;
+ _write_char('[');
+ _write_string(device);
+ _write_char(']');
+
+ ConsoleDefaultColor = temp_color;
+ _write_char(' ');
+ }
+
+ for (i = 0; i < len; i++)
+ if (format[i] != '%' && allowed) _write_char(format[i]);
+ else
+ {
+ ++i;
+ switch (format[i]) {
+ // Character
+ case 'c': {
+ char c = va_arg (args, char);
+ if (allowed) _write_char(c);
+ break;
+ }
+
+ // String
+ case 's': {
+ int32* c = (int32*) va_arg (args, string);
+ if (allowed) _write_string((string)c);
+ break;
+ }
+
+ // Integers
+ case 'd':
+ case 'i': {
+ int32 c = va_arg(args, int32); char temp[32];
+ if (allowed) {
+ ConvertIntToString(temp, c, 10);
+ _write_string(temp);
+ }
+ break;
+ }
+
+ // Integers - hex
+ case 'X':
+ case 'x': {
+ int32 c = va_arg(args, int32); char temp[32];
+ if (allowed) {
+ ConvertUIntToString(temp, c, 16);
+ _write_string(temp);
+ }
+ break;
+ }
+
+ // Integers - unsigned
+ case 'u': {
+ int32 c = va_arg(args, uint32); char temp[32];
+ if (allowed) {
+ ConvertUIntToString (temp, c, 10);
+ _write_string(temp);
+ }
+ break;
+ }
+
+ // Colors
+ case '#': {
+ uint8 c = va_arg(args, uint8);
+ ConsoleDefaultColor = c;
+ break; }
+
+ default: va_end(args); return 1;
+ };
+ }
+
+ va_end(args);
+
+ ConsoleDefaultColor = 0x7;
+ ConsoleCursorUpdateHardware();
+ return i;
+}
diff --git a/Kernel/drivers/drivers.c b/Kernel/drivers/drivers.c
index fd4e1ff..ea27307 100644
--- a/Kernel/drivers/drivers.c
+++ b/Kernel/drivers/drivers.c
@@ -5,6 +5,7 @@
#include "time.h"
#include "../hal/cpu/irq.h"
#include
+#include
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);
}
diff --git a/Kernel/drivers/floppy/floppy.c b/Kernel/drivers/floppy/floppy.c
index caa5999..2bbce86 100644
--- a/Kernel/drivers/floppy/floppy.c
+++ b/Kernel/drivers/floppy/floppy.c
@@ -7,9 +7,10 @@
#include
#include
-#include
+#include
#include
#include
+#include
#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);
+}
diff --git a/Kernel/drivers/floppy/floppy.h b/Kernel/drivers/floppy/floppy.h
index 1f1e8c7..de4154d 100644
--- a/Kernel/drivers/floppy/floppy.h
+++ b/Kernel/drivers/floppy/floppy.h
@@ -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_ */
diff --git a/Kernel/hal/filesys/fat/fat.c b/Kernel/hal/filesys/fat/fat.c
new file mode 100644
index 0000000..8961ae6
--- /dev/null
+++ b/Kernel/hal/filesys/fat/fat.c
@@ -0,0 +1,80 @@
+/*
+ * fat.c
+ *
+ * Created on: Aug 31, 2011
+ * Author: Tiberiu
+ */
+
+#include
+#include
+#include "fat.h"
+
+// Buffer should contain boot sector
+uint32 FatDetect (void* buffer)
+{
+ FatBootSector* boot = (FatBootSector*)buffer;
+ uint32 correct_features = 0;
+ uint32 total_features = 0;
+
+ // Try the asm 'jmp' instruction
+ if ((boot->bpb.AsmJmp[0] == 0x6B || boot->bpb.AsmJmp[0]==0xEB) && boot->bpb.AsmJmp[2] == 0x90)
+ correct_features++;
+ total_features ++;
+
+ // Try the OemId. First char is often 'm' or 'M' (mkdosfs or MSDOS??/MSWIN??)
+ if (boot->bpb.OemId[0] == 'm' || boot->bpb.OemId[0] == 'M') correct_features++;
+ total_features ++;
+
+ // Try the bytes per sector. Most often, it is 512.
+ if (boot->bpb.BytesPerSector == 512) correct_features++;
+ total_features ++;
+
+ // Try the sectors per cluster. This is always a power of 2.
+ uint8 sectclust = boot->bpb.SectorsPerCluster;
+ uint8 count = 0;
+ while (sectclust) { count += sectclust&1; sectclust>>=1; }
+ if (count != 1) return 0;
+
+ // Number of fats, can be 2 or (rarely) 1. Important feature.
+ if (boot->bpb.FatsCount == 1 || boot->bpb.FatsCount == 2) correct_features+=2;
+ total_features+=2;
+
+ // This tells us what type of disk this is. Usually values are above 0xf0.
+ if (boot->bpb.MediaDescriptorType >= 0xF0) correct_features++;
+ total_features++;
+
+ // Calculate number of clusters
+ uint32 clusters = (boot->bpb.TotalSectors * boot->bpb.SectorsPerCluster);
+ if (clusters == 0) clusters = (boot->bpb.TotalSectorsLarge * boot->bpb.SectorsPerCluster);
+ // Calculate fat type
+ uint32 fat = (clusters < 4085) ? 12 : 16 ;
+ if (clusters > 65524) fat = 32;
+
+
+ // Try the extended info
+ if (fat == 32) {
+ if (boot->ext.fat32.Signature == 0x28 || boot->ext.fat32.Signature == 0x29) correct_features++;
+ total_features++;
+ }
+
+ else {
+ if (boot->ext.fat16.Signature == 0x28 || boot->ext.fat16.Signature == 0x29) correct_features++;
+ total_features++;
+ }
+
+ Log("Fat", "Correct features: %u out of %u. Type should be fat%u.\n", correct_features, total_features, fat);
+ // See what we have.
+ if (correct_features > (total_features/2)) return 0; // insuficcient correct features?
+
+ return fat; // return FAT type
+}
+
+
+void FatInstall()
+{
+ FileSystem fat12 = {0, "fat12", Fat12Detect, 0,0,0,0,0,0,0,0};
+ FileSystem fat16 = {0, "fat16", Fat16Detect, 0,0,0,0,0,0,0,0};
+ FileSystem fat32 = {0, "fat32", Fat32Detect, 0,0,0,0,0,0,0,0};
+
+ VfsInstallFs(&fat12); VfsInstallFs(&fat16); VfsInstallFs(&fat32);
+}
diff --git a/Kernel/hal/filesys/fat/fat.h b/Kernel/hal/filesys/fat/fat.h
new file mode 100644
index 0000000..0a9d3af
--- /dev/null
+++ b/Kernel/hal/filesys/fat/fat.h
@@ -0,0 +1,135 @@
+/*
+ * fat.h
+ *
+ * Created on: Aug 31, 2011
+ * Author: Tiberiu
+ */
+
+#ifndef FAT_H_
+#define FAT_H_
+
+#include
+
+/*******************************************************
+ * FAT: Bios Parameter Block *
+ *******************************************************/
+typedef struct {
+ uint8 AsmJmp[3];
+ char OemId[8];
+ uint16 BytesPerSector;
+ uint8 SectorsPerCluster;
+ uint16 ReservedSectors;
+ uint8 FatsCount;
+ uint16 DirectoryEntriesCount;
+ uint16 TotalSectors;
+ uint8 MediaDescriptorType;
+ uint32 SectorsPerFat;
+ uint16 SectorsPerTrack;
+ uint16 Heads;
+ uint32 HiddenSectors;
+ uint32 TotalSectorsLarge;
+} __attribute__((packed)) FatBiosParameterBlock ;
+
+/*******************************************************
+ * FAT12/FAT16: Extended boot record *
+ *******************************************************/
+typedef struct {
+ uint8 DriveNumber; // Useless
+ uint8 NtFlags;
+ uint8 Signature; // Must be 0x28/0x29
+ uint32 VolumeIdSerial;
+ char VolumeLabel[11];
+ char SystemId[8];
+} __attribute__((packed)) Fat16ExtendedBootRecord; // fat12 or 16
+
+/*******************************************************
+ * FAT32: Extended boot record *
+ *******************************************************/
+typedef struct {
+ uint32 SectorsPerFat;
+ uint16 Flags;
+ uint16 FatVersion; // High byte=major version, low=minor
+ uint32 RootDirectoryCluster;
+ uint16 FsInfoCluster;
+ uint16 BackupBootSectorCluster;
+ uint8 Reserved[12]; // Should be set to 0 when formatting
+ uint8 DriveNumber;
+ uint8 NtFlags;
+ uint8 Signature; // Must be 0x28/0x29
+ uint32 VolumeIdSerial;
+ char VolumeLabel[11];
+ char SystemId[8]; // Always "FAT32 "
+} __attribute__((packed)) Fat32ExtendedBootRecord;
+
+/*******************************************************
+ * FAT: Extended boot record (union of above 2 fields) *
+ *******************************************************/
+union FatExtendedBootRecord
+{
+ Fat16ExtendedBootRecord fat16;
+ Fat32ExtendedBootRecord fat32;
+};
+
+/*******************************************************
+ * FAT: Complete boot sector info *
+ *******************************************************/
+typedef struct {
+ FatBiosParameterBlock bpb;
+ union FatExtendedBootRecord ext;
+} __attribute__((packed)) FatBootSector;
+
+
+/*******************************************************
+ * FAT: Directory entry *
+ *******************************************************/
+typedef struct {
+ char FileName[8];
+ char FileExt[3];
+ uint8 Attributes;
+ uint8 _reserved;
+ uint8 CreateTimeFine; // hundreds (0.01) of a second, up to 199
+ uint16 CreateTime; // 15-11 hour; 10-5 mins; 4-0 secs/2;
+ uint16 CreateDate; // 15-9 year (since 1980); 8-5 mon; 4-0 day
+ uint16 AccessDate;
+
+ uint16 FirstClusterHigh; // Fat32; EA-index in fat12,fat16
+
+ uint16 LastModifiedTime;
+ uint16 LastModifiedDate;
+
+ uint16 FirstClusterLow;
+ uint32 Size;
+} __attribute__((packed)) FatDirectoryEntry;
+
+
+/*******************************************************
+ * FAT: Long file name entry *
+ *******************************************************/
+typedef struct {
+ uint8 SequenceNo;
+ uint16 Name1[5]; // Encoded in UTF-16
+ uint8 Attributes; // Should be 0xF;
+ uint8 _reserved;
+ uint16 Name2[6];
+ uint16 FirstCluster;// Should be 0x0000
+ uint16 Name3[2];
+} FatLongFileName;
+
+
+/*******************************************************
+ * FAT: Directory entry (union of above 2 fields) *
+ *******************************************************/
+union FatDirEntryUnion {
+ FatDirectoryEntry d;
+ FatLongFileName lfn;
+};
+
+
+extern uint32 FatDetect (void* buffer);
+extern void FatInstall();
+
+extern uint32 Fat12Detect (DevReadRoutine r, uint32 blocksz);
+extern uint32 Fat16Detect (DevReadRoutine r, uint32 blocksz);
+extern uint32 Fat32Detect (DevReadRoutine r, uint32 blocksz);
+
+#endif /* FAT_H_ */
diff --git a/Kernel/hal/filesys/fat/fat12.c b/Kernel/hal/filesys/fat/fat12.c
new file mode 100644
index 0000000..83ebbd5
--- /dev/null
+++ b/Kernel/hal/filesys/fat/fat12.c
@@ -0,0 +1,25 @@
+/*
+ * fat12.c
+ *
+ * Created on: Aug 29, 2011
+ * Author: Tiberiu
+ */
+#include
+#include
+#include "fat.h"
+
+uint32 Fat12Detect (DevReadRoutine r, uint32 blocksz)
+{
+ if (!r) return 0;
+
+ // Allocate buffer and call read routine
+ void* buffer = kmalloc(blocksz);
+ if (!(*r)(0,buffer)) return 0;
+
+ // Result of detection
+ uint32 res = FatDetect(buffer);
+
+ // Cleanup
+ kfree(buffer);
+ return (res == 12);
+}
diff --git a/Kernel/hal/filesys/fat/fat16.c b/Kernel/hal/filesys/fat/fat16.c
new file mode 100644
index 0000000..8db1269
--- /dev/null
+++ b/Kernel/hal/filesys/fat/fat16.c
@@ -0,0 +1,26 @@
+/*
+ * fat16.c
+ *
+ * Created on: Aug 31, 2011
+ * Author: Tiberiu
+ */
+#include
+#include
+#include "fat.h"
+
+uint32 Fat16Detect (DevReadRoutine r, uint32 blocksz)
+{
+ if (!r) return 0;
+
+ // Allocate buffer and call read routine
+ void* buffer = kmalloc(blocksz);
+ if (!(*r)(0,buffer)) return 0;
+
+ // Result of detection
+ uint32 res = FatDetect(buffer);
+
+ // Cleanup
+ kfree(buffer);
+ return (res == 16);
+}
+
diff --git a/Kernel/hal/filesys/fat/fat32.c b/Kernel/hal/filesys/fat/fat32.c
new file mode 100644
index 0000000..3350cba
--- /dev/null
+++ b/Kernel/hal/filesys/fat/fat32.c
@@ -0,0 +1,26 @@
+/*
+ * fat32.c
+ *
+ * Created on: Aug 31, 2011
+ * Author: Tiberiu
+ */
+#include
+#include
+#include "fat.h"
+
+uint32 Fat32Detect (DevReadRoutine r, uint32 blocksz)
+{
+ if (!r) return 0;
+
+ // Allocate buffer and call read routine
+ void* buffer = kmalloc(blocksz);
+ if (!(*r)(0,buffer)) return 0;
+
+ // Result of detection
+ uint32 res = FatDetect(buffer);
+
+ // Cleanup
+ kfree(buffer);
+ return (res == 32);
+}
+
diff --git a/Kernel/hal/filesys/fat12.c b/Kernel/hal/filesys/fat12.c
deleted file mode 100644
index df8ad6d..0000000
--- a/Kernel/hal/filesys/fat12.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * fat12.c
- *
- * Created on: Aug 29, 2011
- * Author: Tiberiu
- */
-
-
diff --git a/Kernel/hal/filesys/initrd/initrd.c b/Kernel/hal/filesys/initrd/initrd.c
new file mode 100644
index 0000000..ac1da20
--- /dev/null
+++ b/Kernel/hal/filesys/initrd/initrd.c
@@ -0,0 +1,202 @@
+/*
+ * initrd.c
+ *
+ * Created on: Sep 1, 2011
+ * Author: Tiberiu
+ */
+
+#define LUXMAGIC 0xCC23AA90
+#define OEMSTR "luxram"
+
+#include
+#include
+#include
+#include
+#include
+#include "initrd.h"
+
+
+luxDEVICE *luxDevices;
+uint32 luxDeviceCount;
+
+luxFILE *luxFiles;
+uint32 luxFileCount;
+uint32 luxFilesAllocated;
+
+
+/**************************************
+ * DEVICE 'FAKE' READ ROUTINE *
+ **************************************/
+uint32 luxDevRead (uint32 UNUSED(offset), void* UNUSED(buffer))
+{
+ return LUXMAGIC;
+}
+
+/**************************************
+ * INITIALIZATION ROUTINE *
+ **************************************/
+void luxInitrdInstall (MultibootInfo* info)
+{
+ // Install filesystem
+ FileSystem fs = {0, "luxinitrd", luxDetect, 0, 0,
+ luxOpen, luxClose, luxRead, 0, luxTest, luxReadDir};
+
+ VfsInstallFs(&fs);
+
+
+ // See what modules are loaded in the multiboot info
+ if ((info->Flags & 8) == 0 || info->ModulesCount == 0) return; // nothing was loaded
+
+ uint32 i;
+ MultibootModule* modules = (MultibootModule*) info->ModulesAddress;
+ luxDevices = kmalloc(sizeof(luxDEVICE) * info->ModulesCount);
+ luxDeviceCount = 0;
+
+ for (i = 0; i < info->ModulesCount; i++) {
+
+ // Check magic number, to make sure module is a initrd image
+ luxHeader* head = (luxHeader*) modules[i].ModuleStart;
+ if (head->Magic != LUXMAGIC) {
+ Log("Initrd", "Magic = 0x%x [bad] ModuleStart = 0x%x\n", head->Magic, modules[i].ModuleStart);
+ continue;
+ }
+
+ // Set up entry
+ luxDevices[luxDeviceCount].Data = (void*) modules[i].ModuleStart;
+ luxDevices[luxDeviceCount].Size = modules[i].ModuleEnd - modules[i].ModuleStart;
+
+ // Register virtual device. Instead of blocksize, we give the dev no, so we can identify it later
+ VfsMount("initrd", luxDevRead, 0, luxDeviceCount);
+ ++luxDeviceCount;
+ }
+
+}
+
+
+/**************************************
+ * OTHER USEFUL ROUTINES *
+ **************************************/
+uint32 luxGetFileSlot()
+{
+ // Find an empty slot
+ uint32 i = 0;
+ for (i = 0; i < luxFileCount; i++)
+ if (luxFiles[i].Id == 0xffffffff) return i;
+
+ // Nothing found? Allocate more slots if necessary
+ if (luxFileCount >= luxFilesAllocated)
+ {
+ luxFilesAllocated += 4;
+ luxFiles = kmrealloc(luxFiles, luxFilesAllocated);
+ }
+
+ // Give last slot
+ ++luxFileCount;
+ return (luxFileCount-1);
+}
+
+// Navigates and returns the directory entry that contains the file/folder
+luxDirectoryEntry* luxGetFile (string path, uint32 dev)
+{
+ luxHeader* root = (luxHeader*) luxDevices[dev].Data;
+ luxDirectory* current = root->Root;
+ luxDirectoryEntry rt = {"root", 0xB68, 0, 0, 0, {0,0}, {0,0}, {0,0}, (uint32)&root->Root};
+
+ if (path[0] != '\\')
+ return &rt;
+
+ path = path + 1;
+
+
+ while (path)
+ {
+ // Trim the next path separator
+ string tmp = strchr(path, '\\');
+ if (tmp) {
+ *tmp = 0; tmp = tmp + 1;
+ if (!*tmp) tmp = 0;
+ }
+
+ // Find the folder/file in current directory
+ uint32 i, found = 0xffffffff;
+ for (i = 0; i < current->Count && found == 0xffffffff; i++)
+ if (strcmp(path, current->Entries[i].Name) == 0) found = i;
+
+ // Check if the file/folder was found
+ if (found == 0xffffffff) return NULL;
+
+ // Return entry pointer if done
+ if (!tmp) return ¤t->Entries[found];
+
+ // Go inside
+ current = (luxDirectory*) (current->Entries[found].Offset + (uint32)root);
+ path = tmp;
+ }
+
+ // We shouldn't get here
+ return NULL;
+}
+
+
+/**************************************
+ * FILE SYSTEM INTERFACE ROUTINES *
+ **************************************/
+uint32 luxDetect (DevReadRoutine rd, uint32 blocksz)
+{
+ // Check magic result, which is returned by our device read function
+ void* buffer = kmalloc(blocksz);
+ uint32 result = (*rd)(0, buffer);
+ kfree(buffer);
+
+ return (result == LUXMAGIC);
+}
+
+// Returns element count read
+uint32 luxRead (const MountPoint* UNUSED(mp), FILE* f, uint32 elemsz, uint32 n, uint8* buffer)
+{
+ uint32 temp = Min(n*elemsz, luxFiles[f->Id].Size);
+
+ memcpy(buffer, luxFiles[f->Id].Pos, temp);
+ luxFiles[f->Id].Size -= temp;
+
+ return temp;
+}
+
+FILE* luxOpen (const MountPoint* mp, FILE* f, string path)
+{
+ f->Id = luxGetFileSlot();
+ luxDirectoryEntry* entry = luxGetFile(path, mp->BlockSize);
+
+ f->Name = entry->Name;
+ f->Flags = entry->Flags;
+ f->GroupId = entry->GroupId;
+ f->OwnerId = entry->OwnerId;
+ f->Size = entry->Size;
+
+ luxFiles[f->Id].Id = f->Id;
+ luxFiles[f->Id].Pos = luxFiles[f->Id].Start = entry->Offset + luxDevices[mp->BlockSize].Data;
+ luxFiles[f->Id].Size = entry->Size;
+
+ return f;
+}
+
+DirectoryEntry* luxTest (const MountPoint* mp, string path)
+{
+ return (DirectoryEntry*) luxGetFile(path, mp->BlockSize);
+}
+
+FILE* luxClose (const MountPoint* UNUSED(mp), FILE* f)
+{
+ luxFiles[f->Id].Id = NULL;
+
+ return f;
+}
+
+DirectoryEntry* luxReadDir (const MountPoint* UNUSED(mp), FILE* f, uint32 index)
+{
+ luxDirectory* dir = luxFiles[f->Id].Start;
+
+ if (index > dir->Count) return NULL;
+ return (DirectoryEntry*) &dir->Entries[index];
+}
+
diff --git a/Kernel/hal/filesys/initrd/initrd.h b/Kernel/hal/filesys/initrd/initrd.h
new file mode 100644
index 0000000..03e9357
--- /dev/null
+++ b/Kernel/hal/filesys/initrd/initrd.h
@@ -0,0 +1,56 @@
+/*
+ * initdr.h
+ *
+ * Created on: Sep 1, 2011
+ * Author: Tiberiu
+ */
+
+#ifndef INITDR_H_
+#define INITDR_H_
+
+#include
+#include
+
+typedef struct {
+ char Name[256];
+ uint32 Flags, OwnerId, GroupId, Size;
+ TimeSystem TimeCreated, TimeModified, TimeAccessed;
+ uint32 Offset;
+} luxDirectoryEntry;
+
+typedef struct {
+ uint32 Count;
+ luxDirectoryEntry* Entries;
+} luxDirectory;
+
+typedef struct {
+ uint32 Magic;
+ char Oem[6];
+ luxDirectory* Root;
+} luxHeader;
+
+typedef struct {
+ uint32 DeviceId;
+ uint32 Size;
+ void* Data;
+} luxDEVICE;
+
+typedef struct {
+ uint32 Id;
+ uint32 Size;
+ void* Start;
+ void* Pos;
+} luxFILE;
+
+
+extern uint32 luxDevRead (uint32 offset, void* buffer);
+extern void luxInitrdInstall (MultibootInfo* info);
+extern uint32 luxDetect (DevReadRoutine rd, uint32 blocksz);
+extern uint32 luxRead (const MountPoint* mp, FILE* f, uint32 elemsz, uint32 n, uint8* buffer);
+extern FILE* luxOpen (const MountPoint* mp, FILE* f, string path);
+extern DirectoryEntry* luxTest (const MountPoint* mp, string path);
+extern FILE* luxClose (const MountPoint* mp, FILE* f);
+extern DirectoryEntry* luxReadDir (const MountPoint* mp, FILE* f, uint32 index);
+
+
+#endif /* INITDR_H_ */
diff --git a/Kernel/hal/hal.c b/Kernel/hal/hal.c
index a290d7d..782a8d5 100644
--- a/Kernel/hal/hal.c
+++ b/Kernel/hal/hal.c
@@ -8,32 +8,35 @@
#include "keyboard/keyboard.h"
#include "mouse/mouse.h"
+#include "filesys/fat/fat.h"
+
#include
#include
void HalInitialize()
{
// Initialize cpu
- GdtInstall(); Log("%#[HAL] %#Installed GDT\n", ColorYellow, ColorLightGreen);
- IdtInstall(); Log("%#[HAL] %#Installed IDT\n", ColorYellow, ColorLightGreen);
- IsrsInstall(); Log("%#[HAL] %#Installed ISRs\n", ColorYellow, ColorLightGreen);
- IrqInstall(); Log("%#[HAL] %#Installed IRQs\n", ColorYellow, ColorLightGreen);
+ GdtInstall(); Log("HAL", "Installed GDT\n");
+ IdtInstall(); Log("HAL", "Installed IDT\n");
+ IsrsInstall(); Log("HAL", "Installed ISRs\n");
+ IrqInstall(); Log("HAL", "Installed IRQs\n");
// Start interrupts
asm volatile ("sti");
- Log("%#[HAL] %#Interrupts are started...\n", ColorYellow, ColorLightMagenta);
+ Log("HAL", "%#Interrupts are started...\n", ColorLightMagenta);
// Install keyboard
IrqInstallHandler(0, TimeHandler);
IrqInstallHandler(1, KeyboardHandler);
IrqInstallHandler(12, MouseHandler);
- KeyboardInstallA(); Log("%#[HAL] %#Installing keyboard... %#[1/2] ", ColorYellow, ColorLightGray, ColorLightGreen);
- KeyboardInstallB(); Log("%#[2/2]\n", ColorLightGreen);
+ KeyboardInstallA(); Log("HAL", "Installing keyboard... %#[1/2] ", ColorLightGreen);
+ KeyboardInstallB(); Log("HAL", "%#[2/2]\n", ColorLightGreen);
// Install mouse driver
- MouseInstall(); Log("%#[HAL] %#Installed mouse driver\n", ColorYellow, ColorLightGreen);
+ MouseInstall(); Log("HAL", "Installed mouse driver\n");
// Install VFS
VfsInstall();
+ FatInstall();
}
diff --git a/Kernel/hal/reboot.c b/Kernel/hal/system.c
similarity index 78%
rename from Kernel/hal/reboot.c
rename to Kernel/hal/system.c
index 71733d8..f6728eb 100644
--- a/Kernel/hal/reboot.c
+++ b/Kernel/hal/system.c
@@ -11,13 +11,20 @@
#include
#include "keyboard/keyboard.h"
+void SystemPanic()
+{
+ asm("cli");
+ asm("hlt");
+}
+
void SystemReboot()
{
- Log("Rebooting system...\n");
+ Log("System", "Rebooting system...\n");
KeyboardWaitOutport();
outportb (0x64, 0xFE);
- asm("cli");
- asm("hlt");
+ SystemPanic();
}
+
+
diff --git a/Kernel/hal/vfs.c b/Kernel/hal/vfs.c
index 9f9f248..110c4f6 100644
--- a/Kernel/hal/vfs.c
+++ b/Kernel/hal/vfs.c
@@ -13,9 +13,6 @@ MountPoint* mpArray;
uint32 mpCount;
uint32 mpAllocated;
-#define LogVfs(...) { Log("%#[Vfs] ", ColorLightBlue); Log(__VA_ARGS__); }
-#define ErrorVfs(...) { Error("%#[Vfs] ", ColorLightBlue); Error(__VA_ARGS__); }
-
void VfsInstall ()
{
fsArray = (FileSystem*) kmalloc(MAX_FS_COUNT * sizeof(FileSystem));
@@ -25,13 +22,13 @@ void VfsInstall ()
mpCount = 0;
mpAllocated = 32;
- LogVfs("%#VFS now in business.\n", ColorLightGreen);
+ Log("VFS", "%#VFS now in business.\n", ColorLightGreen);
}
uint8 VfsInstallFs (FileSystem* fs)
{
if (fsCount >= MAX_FS_COUNT) {
- ErrorVfs("%#Failed to install file system '%s': FS count reached.\n", ColorLightRed, fs->Name);
+ Error("VFS", "%#Failed to install file system '%s': FS count reached.\n", ColorLightRed, fs->Name);
return 0;
}
@@ -39,7 +36,7 @@ uint8 VfsInstallFs (FileSystem* fs)
fsArray[fsCount].Id = fsCount;
++fsCount;
- LogVfs("Installed file system %#.\n", ColorWhite, fs->Name);
+ Log("VFS", "Installed file system %#%s.\n", ColorWhite, fs->Name);
return 1;
}
@@ -47,7 +44,7 @@ uint32 VfsFindDevice (string dev)
{
uint32 i;
for (i = 0; i < mpCount; i++)
- if (strcmp(dev, mpArray[i].Name) == 0)
+ if (mpArray[i].Id != BAD && strcmp(dev, mpArray[i].Name) == 0)
return i;
return BAD;
@@ -75,10 +72,11 @@ uint8 VfsMount (string Name, DevReadRoutine R, DevWriteRoutine W, uint32 BlockSi
// Try to figure out the file system
for (i = 0; i < fsCount && fsId == BAD; i++)
- if (fsArray->Detect && fsArray->Detect(R, BlockSize)) fsId = i;
+ if (fsArray[i].Detect && fsArray[i].Detect(R, BlockSize))
+ fsId = i;
if (fsId == BAD) {
- ErrorVfs("%#Failed to mount device %s: no file system found.\n", ColorLightRed, Name)
+ Error("VFS", "%#Failed to mount device %s: no file system found.\n", ColorLightRed, Name)
return 0; // No file system, no good
}
@@ -131,14 +129,22 @@ uint8 VfsMount (string Name, DevReadRoutine R, DevWriteRoutine W, uint32 BlockSi
if (!success) return 0;
}
- memcpy(mpArray[mpCount].Name, Name, sizeof(char) * 128);
+ memcpy(mpArray[mpIndex].Name, Name, sizeof(char) * MAX_MOUNTPOINTNAME_LEN);
- LogVfs("Mounted device %#%s", ColorWhite, Name);
+ // Tell file system to mount the device
+ if (fsArray[mpArray[mpIndex].FsId].MountDevice)
+ fsArray[mpArray[mpIndex].FsId].MountDevice(&mpArray[mpIndex]);
+
+ Log("VFS", "Mounted device %#%s%# using the %#%s%# file system.\n", ColorWhite, Name,
+ ColorLightGray, ColorWhite, fsArray[fsId].Name, ColorLightGray);
return 1;
}
void VfsUnmount (uint32 dev_id)
{
+ if (fsArray[mpArray[dev_id].FsId].UnmountDevice)
+ fsArray[mpArray[dev_id].FsId].UnmountDevice(&mpArray[dev_id]);
+
mpArray[dev_id].Id = BAD;
mpCount--;
}
diff --git a/Kernel/include/debugio.h b/Kernel/include/debugio.h
index 54c6518..ce41720 100644
--- a/Kernel/include/debugio.h
+++ b/Kernel/include/debugio.h
@@ -2,7 +2,6 @@
#define __DEBUGIO__H
#include
-#include
#include
enum Colors
@@ -62,27 +61,14 @@ extern void ConsoleReadString (string s, int32 buffer_size, char end_char);
// Console main loop
extern void ConsoleMain();
+
+// External test routines
+extern void SystemPanic();
+extern int32 LogWrite (uint8 error, string device, string format, ...);
+
// Debug print
-#if VERBOSE_MODE==1
-#define Log(...) ConsoleWrite(__VA_ARGS__)
-#else
-#define Log(...)
-#endif
-
-// Error print
-#if VERBOSE_ERROR==1
-#define Error(...) ConsoleWrite(__VA_ARGS__)
-#else
-#define Error(...)
-#endif
-
-// Panic
-#if VERBOSE_PANIC==1
-#define Panic(...) { ConsoleWrite("%#[PANIC] KERNEL PANIC: ", ColorLightRed); \
- ConsoleWrite(__VA_ARGS__); \
- asm volatile ("cli\nhlt"); }
-#else
-#define Panic(...)
-#endif
+#define Log(dev, ...) { LogWrite(0, dev, __VA_ARGS__); }
+#define Error(dev, ...) { LogWrite(1, dev, __VA_ARGS__); }
+#define Panic(dev, ...) { LogWrite(1, dev, __VA_ARGS__); SystemPanic(); }
#endif
diff --git a/Kernel/include/fileio.h b/Kernel/include/fileio.h
index ce9a5f2..5161fa4 100644
--- a/Kernel/include/fileio.h
+++ b/Kernel/include/fileio.h
@@ -11,6 +11,9 @@
#include
#include
+#define MAX_FILENAME_LEN 256
+#define MAX_MOUNTPOINTNAME_LEN 64
+
// Device routines, will read/write 'BlockSize' bytes per call
typedef uint32 (*DevReadRoutine)(uint32 offset, void* buffer);
typedef uint32 (*DevWriteRoutine)(uint32 offset, void* buffer);
@@ -37,11 +40,12 @@ enum FileFlags
};
-typedef struct _FILE
+typedef struct
{
uint32 DeviceId; // The VFS identifies the mounted device that uses this
uint32 Id; // The FS idenitifies files using this field
- char Name[128];
+ //char Name[MAX_FILENAME_LEN];
+ char* Name;
/*** Looks like this:
* bits description
@@ -52,7 +56,8 @@ typedef struct _FILE
* 12 hidden
* 13-31 (unassigned yet)
*
- * Note: In windows FS, the readonly and system attributes are set using permissions and userid */
+ * Note: In windows FS, the readonly and system
+ * attributes are set using permissions and owner id */
uint32 Flags;
uint32 OwnerId, GroupId;
uint32 Size;
@@ -61,7 +66,7 @@ typedef struct _FILE
typedef struct _DirectoryEntry
{
- char Name[128];
+ char Name[MAX_FILENAME_LEN];
uint32 Flags, OwnerId, GroupId, Size;
TimeSystem TimeCreated, TimeModified, TimeAccessed;
@@ -71,7 +76,7 @@ typedef struct _DirectoryEntry
typedef struct {
uint32 Id;
uint32 FsId;
- char Name[128];
+ char Name[MAX_MOUNTPOINTNAME_LEN];
uint32 BlockSize;
DevReadRoutine Read;
@@ -88,18 +93,23 @@ typedef FILE* (*FsCloseRoutine)(const MountPoint*, FILE*);
typedef DirectoryEntry* (*FsReadDirRoutine)(const MountPoint*,FILE*,uint32);
typedef uint32 (*FsDetectRoutine) (DevReadRoutine, uint32 blocksz);
+typedef void (*FsMountRoutine) (const MountPoint*);
+typedef void (*FsUnmountRoutine) (const MountPoint*);
// File system structure
typedef struct {
uint32 Id;
char Name[16];
- FsDetectRoutine Detect;
+ FsDetectRoutine Detect; // Returns 0 if detection failed, something positive otherwise
+ FsMountRoutine MountDevice; // Tells FS a device has to be mounted. This way, the FS can cache data for faster access
+ FsUnmountRoutine UnmountDevice; // Tells FS a device has been unmounted. This way, the FS can free cached data.
+
FsOpenRoutine Open;
FsCloseRoutine Close;
FsReadRoutine Read;
FsWriteRoutine Write;
- FsTestRoutine Test; // See if file exists without having to open it
+ FsTestRoutine Test; // See if file exists without having to open it
FsReadDirRoutine ReadDirectory;
} FileSystem;
diff --git a/Kernel/include/memory-add.h b/Kernel/include/memory-add.h
index e423cff..abe856d 100644
--- a/Kernel/include/memory-add.h
+++ b/Kernel/include/memory-add.h
@@ -89,9 +89,4 @@ extern uint32 MemHeapContract(uint32 newsz, MemHeap* heap, PageDirectory* pd);
extern uint32 MemHeapAlloc (uint32 size, uint8 isPageAligned, MemHeap* heap, PageDirectory* pd);
extern void MemHeapFree (uint32 address, MemHeap* heap, PageDirectory* pd);
-
-#define LogMem(...) { Log("%#[Mem] ", ColorLightCyan); Log(__VA_ARGS__); }
-#define ErrorMem(...) { Error("%#[Mem] ", ColorLightCyan); Error(__VA_ARGS__); }
-
-
#endif /* MEMORY_ADD_H_ */
diff --git a/Kernel/include/settings.h b/Kernel/include/settings.h
index 4c0382a..bf7b528 100644
--- a/Kernel/include/settings.h
+++ b/Kernel/include/settings.h
@@ -17,9 +17,9 @@
#include
// Logger
-#define VERBOSE_MODE 1
-#define VERBOSE_ERROR 1
-#define VERBOSE_PANIC 1
+#define LOGGER_ALLOW 1
+#define LOGGER_ALLOW_ERROR 1
+#define LOGGER_ALLOW_PANIC 1
// Clock
diff --git a/Kernel/include/stdlib.h b/Kernel/include/stdlib.h
index eb69f19..4d53203 100644
--- a/Kernel/include/stdlib.h
+++ b/Kernel/include/stdlib.h
@@ -23,6 +23,7 @@
***************************************************/
extern uint32 strlen (string s);
extern int32 strcmp (string a, string b);
+extern int32 strcasecmp (string a, string b);
extern string strcpy (string s1, const string s2);
extern char* strchr (string s, int c);
extern char* strrchr (string s, int c);
diff --git a/Kernel/include/version.h b/Kernel/include/version.h
index 6fc1c9f..a4e91e8 100644
--- a/Kernel/include/version.h
+++ b/Kernel/include/version.h
@@ -1 +1 @@
-#define OS_BUILD "0.1.0.470"
+#define OS_BUILD "0.1.0.551"
diff --git a/Kernel/library/memory/memory_alloc.c b/Kernel/library/memory/memory_alloc.c
index d0f33cc..4b7c4ea 100644
--- a/Kernel/library/memory/memory_alloc.c
+++ b/Kernel/library/memory/memory_alloc.c
@@ -18,7 +18,7 @@ uint32 _malloc_init1 (uint32 size, uint8 page_aligned)
if (page_aligned && (ret & 0xfff)) ret = (ret & 0xfffff000) + 0x1000;
mem_kernel_end = size + ret;
- LogMem("%#Allocated %u bytes (%spage aligned) at end of kernel (0x%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret);
+ Log("Mem","%#Allocated %u bytes (%spage aligned) at end of kernel (0x%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret);
return (ret);
}
@@ -31,11 +31,11 @@ uint32 _malloc_init2 (uint32 size, uint8 page_aligned, uint32* phys)
Page *pg = PagingGetPage(ret, 0, KernelDirectory);
*phys = (*pg & PageFrame) + (ret & 0xFFF);
- LogMem("%#Allocated %u bytes (%spage aligned) at address 0x%x (phys=%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret, *phys);
+ Log("Mem","%#Allocated %u bytes (%spage aligned) at address 0x%x (phys=%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret, *phys);
}
else {
- LogMem("%#Allocated %u bytes (%spage aligned) at address 0x%x.\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret);
+ Log("Mem","%#Allocated %u bytes (%spage aligned) at address 0x%x.\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret);
}
return ret;
diff --git a/Kernel/library/memory/memory_free.c b/Kernel/library/memory/memory_free.c
index a61b9fc..33777e4 100644
--- a/Kernel/library/memory/memory_free.c
+++ b/Kernel/library/memory/memory_free.c
@@ -12,7 +12,7 @@ extern uint8 mem_initialized;
void kfree(void* addr)
{
if (mem_initialized < 2) {
- ErrorMem("%#Tried to free at address 0x%x when memory manager is uninitialized.\n", ColorLightRed, (uint32)addr);
+ Error("Mem", "%#Tried to free at address 0x%x when memory manager is uninitialized.\n", ColorLightRed, (uint32)addr);
return;
}
diff --git a/Kernel/library/memory/memory_init.c b/Kernel/library/memory/memory_init.c
index 1fd66dc..cb87d01 100644
--- a/Kernel/library/memory/memory_init.c
+++ b/Kernel/library/memory/memory_init.c
@@ -27,7 +27,7 @@ uint32 _memory_get_total_mem(MultibootInfo* info)
high = CmosRead(0x31);
total = (uint32)(low | high<<8) + 1024;
- ErrorMem("%#Missing memory info from bootloader. Reading from CMOS: %ukb\n", ColorLightRed, total);
+ Error("Mem", "%#Missing memory info from bootloader. Reading from CMOS: %ukb\n", ColorLightRed, total);
return total;
}
@@ -50,7 +50,7 @@ void _memory_reserve_system(MultibootInfo* info)
else
{
- ErrorMem("%#Missing %#memory map%# info from bootloader.\n", ColorLightRed, ColorWhite, ColorLightRed);
+ Error("Mem", "%#Missing %#memory map%# info from bootloader.\n", ColorLightRed, ColorWhite, ColorLightRed);
// Standard memory hole at 15mb
MemPhReserveFrames(0x00F00000, 0x00100000);
@@ -75,7 +75,7 @@ void MemoryInitialize (MultibootInfo* info)
KernelHeap = MemHeapCreate(KERNEL_HEAP_START, KERNEL_HEAP_START
+ KERNEL_HEAP_INITIAL_SIZE, 0xCFFFF000, 3); // is kernel, writeable
- LogMem("Done initializing memory!");
+ Log("Mem", "Done initializing memory!");
mem_initialized = 2;
}
@@ -84,5 +84,5 @@ void MemoryTempInitialize (uint32 kernel_end)
{
mem_initialized = 1;
mem_kernel_end = kernel_end;
- LogMem("Initialized temporary memory manager, allocating from %#0x%x.\n", kernel_end);
+ Log("Mem", "Initialized temporary memory manager, allocating from %#0x%x.\n", kernel_end);
}
diff --git a/Kernel/library/stdlib/str_ops.c b/Kernel/library/stdlib/str_ops.c
index 40c5598..f96ea79 100644
--- a/Kernel/library/stdlib/str_ops.c
+++ b/Kernel/library/stdlib/str_ops.c
@@ -5,6 +5,7 @@
* Author: Tiberiu
*/
#include
+#include
uint32 strlen (string s)
{
@@ -28,6 +29,19 @@ int32 strcmp (string a, string b)
return ((c1 < c2) ? -1 : (c1 > c2));
}
+int32 strcasecmp (string a, string b)
+{
+ unsigned char c1, c2;
+
+ while (*a != '\0' && *b != '\0' && tolower(*a) == tolower(*b)) {
+ a++; b++;
+ }
+
+ c1 = tolower(*(unsigned char*) a);
+ c2 = tolower(*(unsigned char*) b);
+ return ((c1 < c2) ? -1 : (c1 > c2));
+}
+
string strcpy (string s1, const string s2)
{
char *dst = s1;
diff --git a/Kernel/main.c b/Kernel/main.c
index 2e69775..2c5bb3c 100644
--- a/Kernel/main.c
+++ b/Kernel/main.c
@@ -9,21 +9,33 @@
extern uint32 _end;
+extern void luxInitrdInstall (MultibootInfo* info);
+
void k_main(MultibootInfo* info)
{
uint32 KernelEnd = (uint32)&_end;
+ // Find kernel's end
+ if (info->Flags & 0x8) {
+
+ uint32 i = 0;
+ MultibootModule* modules = (MultibootModule*) info->ModulesAddress;
+
+ for (i = 0; i < info->ModulesCount; i++)
+ KernelEnd = Max(KernelEnd, modules[i].ModuleEnd);
+ }
+
ConsoleClear();
MemoryTempInitialize(KernelEnd);
MemoryInitialize(info);
HalInitialize();
+ luxInitrdInstall(info);
+
DriversInstall();
// Set up memory manager
-
-
- Log("All ready. Starting console...\n\n");
+ Log("Console", "All ready. Starting console...\n\n");
ConsoleMain();
}
diff --git a/Kernel/memory/mem-paging.c b/Kernel/memory/mem-paging.c
index 6c4e3d8..f9c3904 100644
--- a/Kernel/memory/mem-paging.c
+++ b/Kernel/memory/mem-paging.c
@@ -17,7 +17,7 @@ PageDirectory* KernelDirectory;
*******************************/
void PagingInitialize(uint32 kernel_used)
{
- LogMem("Virtual memory manager initialization started. End of kernel = 0x%x\n", kernel_used);
+ Log("Mem", "Virtual memory manager initialization started. End of kernel = 0x%x\n", kernel_used);
PageDirectory* kernelPd = (PageDirectory*) kmalloc_a(sizeof(PageDirectory));
memset(kernelPd, 0, sizeof(PageDirectory));
@@ -28,12 +28,12 @@ void PagingInitialize(uint32 kernel_used)
for (i = 0; i < kernel_used; i+=0x1000)
MemPhAllocFrame(PagingGetPage(i, 1, kernelPd), 0, 0);
- LogMem("Identity mapped first 0x%x bytes.\n", kernel_used);
+ Log("Mem", "Identity mapped first 0x%x bytes.\n", kernel_used);
for (i = KERNEL_HEAP_START; i < KERNEL_HEAP_END; i+=0x1000)
MemPhAllocFrame(PagingGetPage(i, 1, kernelPd), 1, 1);
- LogMem("Mapped kernel space.\n");
+ Log("Mem", "Mapped kernel space.\n");
PagingSwitchPageDirectory (kernelPd);
}
@@ -48,7 +48,7 @@ void PagingSwitchPageDirectory (PageDirectory* dir)
cr0 |= 0x80000000;
asm volatile ("mov %0, %%cr0":: "r"(cr0));
- LogMem("Enabled paging.\n");
+ Log("Mem", "Enabled paging.\n");
}
Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir)
diff --git a/Kernel/memory/mem-phys.c b/Kernel/memory/mem-phys.c
index b19038b..6f7b47a 100644
--- a/Kernel/memory/mem-phys.c
+++ b/Kernel/memory/mem-phys.c
@@ -67,7 +67,7 @@ void MemPhAllocFrame(Page* page, uint8 isKernel, uint8 isWriteable)
uint32 free = MemPhFindFreeFrame();
if (free == 0xffffffff) {
- Panic("%#Failed allocation free=0x%x page=0x%x\n", ColorRed, free, *page);
+ Panic("Mem", "%#Failed allocation free=0x%x page=0x%x\n", ColorRed, free, *page);
return;
}
@@ -94,7 +94,7 @@ void MemPhInitialize(uint32 SystemMemoryKb)
FrameMap = (uint32*) kmalloc(sizeof(uint32) * (1 + (TotalFrames>>5)));
memset(FrameMap, 0, sizeof(uint32) * (1 + (TotalFrames>>5)));
- LogMem("%#Started physical memory manager ok!, found %ukb\n", ColorLightGreen, SystemMemoryKb);
+ Log("Mem", "%#Started physical memory manager ok!, found %ukb\n", ColorLightGreen, SystemMemoryKb);
}
void MemPhReserveFrames (uint32 address, uint32 length)
diff --git a/Modules/Rom image maker/langspecs.txt b/Modules/Rom image maker/langspecs.txt
new file mode 100644
index 0000000..83d1f8f
--- /dev/null
+++ b/Modules/Rom image maker/langspecs.txt
@@ -0,0 +1,14 @@
+CREATE "filename" ; creates a new ramdisk with the filename
+MKDIR "name" ; creates a new directory (in current dir)
+CD "\path" ; sets current directory
+ADD "filename" ; adds a file to current directory!
+SETFLAGS 1A1B01 ; sets flags for next added files, number is in hex using this mask:
+ * bits description
+ * 0-2 file type; ignored, autocompleted at writing
+ * 3-5 owner permissions (rwx); w ignored (read only device)
+ * 6-8 group permissions (rwx); w ignored
+ * 9-11 other permissions (rwx); w ignored
+ * 12 hidden
+ ; default mask is: B68 (no write, everyone can execute and read)
+#asdf ; comment
+CLOSE ; writes and closes the ramdisk. You must close before opening another one
\ No newline at end of file
diff --git a/build.sh b/build.sh
index f86ce26..29f41db 100644
--- a/build.sh
+++ b/build.sh
@@ -18,7 +18,7 @@ BuildC()
File=${line##*/}
File=${File%%.*}
$COMPILER -Wall -Wextra -O -nostdinc -fno-builtin -I./Kernel/include -c -o $OBJ/$File.o $line -nostdlib -nostartfiles -nodefaultlibs
- Percent=$(($Percent + 2)) #Increase PERCENT
+ Percent=$(($Percent + 1)) #Increase PERCENT
done < $1
return 0
diff --git a/build/console.o b/build/console.o
index fabd524..daa1b25 100644
Binary files a/build/console.o and b/build/console.o differ
diff --git a/build/drivers.o b/build/drivers.o
index 287856a..acdaeca 100644
Binary files a/build/drivers.o and b/build/drivers.o differ
diff --git a/build/fat.o b/build/fat.o
new file mode 100644
index 0000000..d56285f
Binary files /dev/null and b/build/fat.o differ
diff --git a/build/fat12.o b/build/fat12.o
index 63d2f64..08268b1 100644
Binary files a/build/fat12.o and b/build/fat12.o differ
diff --git a/build/fat16.o b/build/fat16.o
new file mode 100644
index 0000000..4c416c2
Binary files /dev/null and b/build/fat16.o differ
diff --git a/build/fat32.o b/build/fat32.o
new file mode 100644
index 0000000..46a6484
Binary files /dev/null and b/build/fat32.o differ
diff --git a/build/floppy.o b/build/floppy.o
index 9a42009..75233fe 100644
Binary files a/build/floppy.o and b/build/floppy.o differ
diff --git a/build/hal.o b/build/hal.o
index 4826c3f..6ddcb19 100644
Binary files a/build/hal.o and b/build/hal.o differ
diff --git a/build/initrd.o b/build/initrd.o
new file mode 100644
index 0000000..cb06e5a
Binary files /dev/null and b/build/initrd.o differ
diff --git a/build/logger.o b/build/logger.o
new file mode 100644
index 0000000..ec5a3e0
Binary files /dev/null and b/build/logger.o differ
diff --git a/build/mem-paging.o b/build/mem-paging.o
index 7b51f4f..042d5e9 100644
Binary files a/build/mem-paging.o and b/build/mem-paging.o differ
diff --git a/build/mem-phys.o b/build/mem-phys.o
index a120a3e..3d7efca 100644
Binary files a/build/mem-phys.o and b/build/mem-phys.o differ
diff --git a/build/memory_alloc.o b/build/memory_alloc.o
index 23e4ea4..e031b45 100644
Binary files a/build/memory_alloc.o and b/build/memory_alloc.o differ
diff --git a/build/memory_free.o b/build/memory_free.o
index 52df197..cfacf35 100644
Binary files a/build/memory_free.o and b/build/memory_free.o differ
diff --git a/build/memory_init.o b/build/memory_init.o
index 98d5884..cd123a8 100644
Binary files a/build/memory_init.o and b/build/memory_init.o differ
diff --git a/build/reboot.o b/build/reboot.o
deleted file mode 100644
index 6094f37..0000000
Binary files a/build/reboot.o and /dev/null differ
diff --git a/build/str_ops.o b/build/str_ops.o
index f10f816..fe50c3b 100644
Binary files a/build/str_ops.o and b/build/str_ops.o differ
diff --git a/build/system.o b/build/system.o
new file mode 100644
index 0000000..0055484
Binary files /dev/null and b/build/system.o differ
diff --git a/build/vfs.o b/build/vfs.o
index a56eb05..bd1d0a2 100644
Binary files a/build/vfs.o and b/build/vfs.o differ
diff --git a/change.log b/change.log
index cec6f00..730d60d 100644
--- a/change.log
+++ b/change.log
@@ -1,3 +1,11 @@
+[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
+
[GOOD] BUILD 0.1.0.470 DATE 8/30/2011 AT 6:40 PM
====================================================
Mainly changed: HAL.VFS
diff --git a/filelistC.txt b/filelistC.txt
index dced3d4..407a86b 100644
--- a/filelistC.txt
+++ b/filelistC.txt
@@ -13,6 +13,9 @@ Kernel/debug/console-out.c
Debug :: Console input
Kernel/debug/console-in.c
+Debug :: Logger
+Kernel/debug/logger.c
+
Drivers
Kernel/drivers/drivers.c
@@ -58,14 +61,26 @@ Kernel/hal/keyboard/keyboard.c
HAL :: Mouse
Kernel/hal/mouse/mouse.c
-HAL :: System reboot
-Kernel/hal/reboot.c
+HAL :: System
+Kernel/hal/system.c
HAL :: File systems :: Virtual file system
Kernel/hal/vfs.c
+HAL :: File systems :: FAT
+Kernel/hal/filesys/fat/fat.c
+
HAL :: File systems :: FAT12
-Kernel/hal/filesys/fat12.c
+Kernel/hal/filesys/fat/fat12.c
+
+HAL :: File systems :: FAT16
+Kernel/hal/filesys/fat/fat16.c
+
+HAL :: File systems :: FAT32
+Kernel/hal/filesys/fat/fat32.c
+
+HAL :: File systems :: Initial ram disk
+Kernel/hal/filesys/initrd/initrd.c
Libraries :: Character types
Kernel/library/ctype.c
diff --git a/kernel.bin b/kernel.bin
index e1a8b4d..11eb52b 100644
Binary files a/kernel.bin and b/kernel.bin differ
diff --git a/luxos.img b/luxos.img
deleted file mode 100644
index de2df85..0000000
Binary files a/luxos.img and /dev/null differ
diff --git a/scripts/run.bat b/scripts/run.bat
index 7108c70..afe0658 100644
--- a/scripts/run.bat
+++ b/scripts/run.bat
@@ -2,5 +2,6 @@
set virtualbox=C:\PROGRA~1\oracle\Virtua~1\
set machineName="lux Testbed"
+set VBOX_GUI_DBG_ENABLED=true
-%virtualbox%\vboxmanage startvm %machineName%
\ No newline at end of file
+%virtualbox%\virtualbox --startvm %machineName% --dbg
\ No newline at end of file
diff --git a/scripts/version.txt b/scripts/version.txt
index 5f476b6..0eedeef 100644
--- a/scripts/version.txt
+++ b/scripts/version.txt
@@ -1 +1 @@
-470
+551