Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions fs/Iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,40 @@

#define ISO9660_SECTOR_SIZE 2048

static uint8_t cdrom_drive = 0xFF; // Auto-detect CD-ROM drive

// Function to detect CD-ROM drive
static int DetectCdromDrive(void) {
if (cdrom_drive != 0xFF) return cdrom_drive;

uint8_t sector_buffer[512];
for (uint8_t drive = 0; drive < 4; drive++) {
for (int sector_offset = 0; sector_offset < 4; sector_offset++) {
if (IdeReadSector(drive, 16 * 4 + sector_offset, sector_buffer) == 0) {
for (int offset = 0; offset < 512 - 5; offset++) {
if (FastMemcmp(sector_buffer + offset + 1, "CD001", 5) == 0 &&
sector_buffer[offset] == 1) {
cdrom_drive = drive;
PrintKernelF("[ISO] CD-ROM detected on drive %d\n", drive);
return drive;
}
}
}
}
}
return -1;
}

// Function to read a sector from the ISO
static int ReadSector(uint32_t lba, void* buffer) {
// ISO9660 sector size is 2048, but IDE reads in 512-byte sectors.
// So, we need to read 4 IDE sectors to get one ISO sector.
int drive = DetectCdromDrive();
if (drive < 0) return -1;

uint32_t start_lba = lba * 4;
for (int i = 0; i < 4; i++) {
if (IdeReadSector(0, start_lba + i, (uint8_t*)buffer + (i * 512)) != 0) {
int result = IdeReadSector(drive, start_lba + i, (uint8_t*)buffer + (i * 512));
if (result != 0) {
PrintKernelF("[ISO] Failed to read sector %u from drive %d\n", start_lba + i, drive);
return -1;
}
}
Expand Down Expand Up @@ -50,7 +77,7 @@ static Iso9660DirEntry* FindFileInDir(uint32_t dir_lba, uint32_t dir_size, const
name_len = sizeof(entry_filename) - 1;
FastMemcpy(entry_filename, entry->file_id, name_len);
entry_filename[name_len] = 0;

PrintKernelF("[ISO] Found entry: '%s' (looking for '%s')\n", entry_filename, filename);
char* semicolon = FastStrChr(entry_filename, ';');
if (semicolon) {
*semicolon = 0;
Expand Down Expand Up @@ -79,6 +106,7 @@ static Iso9660DirEntry* FindFileInDir(uint32_t dir_lba, uint32_t dir_size, const

int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
// Allocate a buffer for one sector
PrintKernelF("ISO9660: Reading '%s'\n", path);
uint8_t* sector_buffer = KernelMemoryAlloc(ISO9660_SECTOR_SIZE);
if (!sector_buffer) {
PrintKernelError("Out of memory\n");
Expand All @@ -90,10 +118,11 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
for (uint32_t lba = 16; lba < 32; lba++) {
if (ReadSector(lba, sector_buffer) != 0) {
KernelFree(sector_buffer);
PrintKernelError("Failed to read sector\n");
return -1; // Failed to read sector
}
Iso9660Pvd* cand = (Iso9660Pvd*)sector_buffer;
if (cand->type == 1 && FastStrCmp(cand->id, "CD001") == 0) {
if (cand->type == 1 && FastMemcmp(cand->id, "CD001", 5) == 0) {
pvd = KernelMemoryAlloc(ISO9660_SECTOR_SIZE);
if (!pvd) {
KernelFree(sector_buffer);
Expand Down Expand Up @@ -131,6 +160,7 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
if (FastStrCmp(path, "/") == 0) {
KernelFree(path_copy);
KernelFree(pvd);
PrintKernelError("Nothing to read\n");
return 0; // Not an error, but nothing to read
}

Expand All @@ -154,6 +184,7 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
if (!current_entry) {
KernelFree(path_copy);
KernelFree(pvd);
PrintKernelError("Path not found\n");
return -1; // Path not found
}

Expand All @@ -171,6 +202,7 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {

if (!current_entry) {
KernelFree(pvd);
PrintKernelError("This should not happen\n");
return -1; // Should not happen
}

Expand All @@ -180,8 +212,11 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
KernelFree(current_entry);
}
KernelFree(pvd);
PrintKernelError("Path is a directory\n");
return -1;
}
PrintKernelF("[ISO] Found file: data_length_le=%u, extent_loc_le=%u\n",
current_entry->data_length_le, current_entry->extent_loc_le);
// Read the file data
const uint32_t file_size = current_entry->data_length_le;
const uint32_t file_lba = current_entry->extent_loc_le;
Expand Down Expand Up @@ -243,7 +278,7 @@ static Iso9660DirEntry** Iso9660ListDir(const char* path) {
KernelFree(sector_buffer);
return NULL;
}
if (FastStrCmp(((Iso9660Pvd*)sector_buffer)->id, "CD001") == 0 && ((Iso9660Pvd*)sector_buffer)->type == 1) {
if (FastMemcmp(((Iso9660Pvd*)sector_buffer)->id, "CD001", 5) == 0 && ((Iso9660Pvd*)sector_buffer)->type == 1) {
pvd = KernelMemoryAlloc(ISO9660_SECTOR_SIZE);
if (!pvd) {
KernelFree(sector_buffer);
Expand Down
88 changes: 88 additions & 0 deletions include/Scheduler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: GPL-2.0-only
///@brief Unified wrapper for multiple scheduler implementations
#ifndef VOIDFRAME_SCHEDULER_H
#define VOIDFRAME_SCHEDULER_H
#include "MLFQ.h"

static inline __attribute__((always_inline)) int SchedulerInit() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQSchedInit();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return 0; // not implemented
#endif
return -1;
}

static inline __attribute__((always_inline)) uint32_t CreateProcess(const char * name, void (*entry_point)()) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQCreateProcess(name ,entry_point);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return 0; // not implemented
#endif
return -1;
}

static inline __attribute__((always_inline))
#if defined(VF_CONFIG_SCHED_MLFQ)
MLFQProcessControlBlock*
#elif defined(VF_CONFIG_SCHED_CFS)
void // not implemented
#else
void
#endif
GetCurrentProcess() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQGetCurrentProcess();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

static inline __attribute__((always_inline))
#if defined(VF_CONFIG_SCHED_MLFQ)
MLFQProcessControlBlock*
#elif defined(VF_CONFIG_SCHED_CFS)
void // not implemented
#else
void
#endif
GetProcessByPID(uint32_t pid) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQGetCurrentProcessByPID(pid);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

static inline __attribute__((always_inline)) void Yield() {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQYield();
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

static inline __attribute__((always_inline)) void Schedule(Registers* regs) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQSchedule(regs);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

static inline __attribute__((always_inline)) void KillProcess(uint32_t pid) {
#ifdef VF_CONFIG_SCHED_MLFQ
return MLFQKillProcess(pid);
#endif
#ifdef VF_CONFIG_SCHED_CFS
return; // not implemented
#endif
}

#endif // VOIDFRAME_SCHEDULER_H
3 changes: 3 additions & 0 deletions kernel/core/Kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern uint8_t _kernel_phys_end[];
// Global variable to store the Multiboot2 info address
static uint32_t g_multiboot_info_addr = 0;
bool g_svgaII_active = false;
bool g_HasKernelStarted = false;

void ParseMultibootInfo(uint32_t info) {
g_multiboot_info_addr = info;
Expand Down Expand Up @@ -809,6 +810,8 @@ void KernelMainHigherHalf(void) {
Unsnooze();
#endif

g_HasKernelStarted = true;

sti();

while (1) {
Expand Down
4 changes: 1 addition & 3 deletions kernel/elf/ELFloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ uint32_t CreateProcessFromElf(const char* filename, const ElfLoadOptions* option
void* adjusted_entry = (uint8_t*)process_memory + (entry_point - base_vaddr);

// 9. Create sched with enhanced security
uint32_t pid = MLFQCreateProcess(
(void (*)(void))adjusted_entry
);
uint32_t pid = MLFQCreateProcess(filename, (void (*)(void))adjusted_entry);

// Clean up temporary ELF data
VMemFreeWithGuards(elf_data, file_size);
Expand Down
9 changes: 4 additions & 5 deletions kernel/etc/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void ClearHandler(const char * args) {

static void ARPTestHandler(const char * args) {
(void)args;
MLFQCreateProcess(ArpRequestTestProcess);
MLFQCreateProcess("ARPTest", ArpRequestTestProcess);
}

static void VersionHandler(const char * args) {
Expand Down Expand Up @@ -331,7 +331,7 @@ static void MemstatHandler(const char * args) {
static void LsPCIHandler(const char * args) {
(void)args;

MLFQCreateProcess(PciEnumerate);
MLFQCreateProcess("PCIEnumerate", PciEnumerate);
}

static void VmemFreeListHandler(const char * args) {
Expand Down Expand Up @@ -373,8 +373,7 @@ static void PanicHandler(const char * args) {

static void LsUSBHandler(const char * args) {
(void)args;

MLFQCreateProcess(xHCIEnumerate);
MLFQCreateProcess("xHCIEnumerate", xHCIEnumerate);
}

static void BeepHandler(const char * args) {
Expand Down Expand Up @@ -1036,7 +1035,7 @@ void nothing(void) {

void TestHandler(const char* args) {
(void)args;
MLFQCreateProcess(nothing);
MLFQCreateProcess("nothing", nothing);
}

static void IsoCpHandler(const char* args) {
Expand Down
Loading