[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:
2021-09-14 18:51:43 +03:00
parent 0372dcee81
commit caa7718af9
59 changed files with 991 additions and 112 deletions

View File

@ -4,6 +4,7 @@
#include <memory-add.h>
#include "../hal/mouse/mouse.h"
#include "../drivers/floppy/floppy.h"
#include <fileio.h>
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);
}

View File

@ -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;

122
Kernel/debug/logger.c Normal file
View File

@ -0,0 +1,122 @@
/*
* logger.c
*
* Created on: Sep 2, 2011
* Author: Tiberiu
*/
#include <debugio.h>
#include <stdlib.h>
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;
}

View File

@ -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);
}

View File

@ -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, &sect);
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, &sect);
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);
}

View File

@ -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_ */

View File

@ -0,0 +1,80 @@
/*
* fat.c
*
* Created on: Aug 31, 2011
* Author: Tiberiu
*/
#include <fileio.h>
#include <debugio.h>
#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);
}

View File

@ -0,0 +1,135 @@
/*
* fat.h
*
* Created on: Aug 31, 2011
* Author: Tiberiu
*/
#ifndef FAT_H_
#define FAT_H_
#include <fileio.h>
/*******************************************************
* 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_ */

View File

@ -0,0 +1,25 @@
/*
* fat12.c
*
* Created on: Aug 29, 2011
* Author: Tiberiu
*/
#include <fileio.h>
#include <memory.h>
#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);
}

View File

@ -0,0 +1,26 @@
/*
* fat16.c
*
* Created on: Aug 31, 2011
* Author: Tiberiu
*/
#include <fileio.h>
#include <memory.h>
#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);
}

View File

@ -0,0 +1,26 @@
/*
* fat32.c
*
* Created on: Aug 31, 2011
* Author: Tiberiu
*/
#include <fileio.h>
#include <memory.h>
#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);
}

View File

@ -1,8 +0,0 @@
/*
* fat12.c
*
* Created on: Aug 29, 2011
* Author: Tiberiu
*/

View File

@ -0,0 +1,202 @@
/*
* initrd.c
*
* Created on: Sep 1, 2011
* Author: Tiberiu
*/
#define LUXMAGIC 0xCC23AA90
#define OEMSTR "luxram"
#include <fileio.h>
#include <stdlib.h>
#include <multiboot.h>
#include <memory.h>
#include <debugio.h>
#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 &current->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];
}

View File

@ -0,0 +1,56 @@
/*
* initdr.h
*
* Created on: Sep 1, 2011
* Author: Tiberiu
*/
#ifndef INITDR_H_
#define INITDR_H_
#include <types.h>
#include <fileio.h>
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_ */

View File

@ -8,32 +8,35 @@
#include "keyboard/keyboard.h"
#include "mouse/mouse.h"
#include "filesys/fat/fat.h"
#include <fileio.h>
#include <debugio.h>
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();
}

View File

@ -11,13 +11,20 @@
#include <debugio.h>
#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();
}

View File

@ -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--;
}

View File

@ -2,7 +2,6 @@
#define __DEBUGIO__H
#include <types.h>
#include <settings.h>
#include <stdarg.h>
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

View File

@ -11,6 +11,9 @@
#include <types.h>
#include <time.h>
#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;

View File

@ -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_ */

View File

@ -17,9 +17,9 @@
#include <version.h>
// 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

View File

@ -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);

View File

@ -1 +1 @@
#define OS_BUILD "0.1.0.470"
#define OS_BUILD "0.1.0.551"

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -5,6 +5,7 @@
* Author: Tiberiu
*/
#include <types.h>
#include <ctype.h>
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;

View File

@ -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();
}

View File

@ -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)

View File

@ -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)