[GOOD] BUILD 0.1.0.470 DATE 8/30/2011 AT 6:40 PM

====================================================
Mainly changed: HAL.VFS
+ Designed virtual file system
+ Completed the VFS
+ Added verbose mode for VFS
+ Updated shell script, now shows build number when building
? TODO: Implement one file system (most likely FAT12)
? TODO: Mount floppy device
This commit is contained in:
2021-09-14 18:50:50 +03:00
parent 913e65b856
commit 0372dcee81
75 changed files with 377 additions and 636 deletions

View File

@ -82,3 +82,12 @@ void* kmalloc_ap(uint32 size, uint32* phys)
else ret = _malloc_init2(size,1,phys);
return (void*)ret;
}
void* kmrealloc (void* original, uint32 newsz)
{
void* re = kmalloc(newsz);
memcpy (re, original, newsz);
kfree(original);
return re;
}

View File

@ -1,87 +0,0 @@
/*
* memory_alloc.c
*
* Created on: Aug 27, 2011
* Author: Tiberiu
*/
#include <memory-add.h>
extern uint32 mem_kernel_end;
extern uint8 mem_initialized;
// Used prior to proper initialization
uint32 _malloc_init1 (uint32 size, uint8 page_aligned)
{
uint32 ret = mem_kernel_end;
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);
return (ret);
}
uint32 _malloc_init2 (uint32 size, uint8 page_aligned, uint32* phys)
{
uint32 ret = MemHeapAlloc(size, page_aligned, KernelHeap, KernelDirectory);
if (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);
}
else {
LogMem("%#Allocated %u bytes (%spage aligned) at address 0x%x.\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret);
}
return ret;
}
// Allocate 'size' bytes
void* kmalloc (uint32 size)
{
if (!mem_initialized) return 0;
if (mem_initialized == 1) return (void*)_malloc_init1(size, 0);
return (void*)_malloc_init2(size,0,0);
}
// Allocate 'size' bytes, page aligned
void* kmalloc_a(uint32 size)
{
if (!mem_initialized) return 0;
if (mem_initialized == 1) return (void*)_malloc_init1(size, 1);
return (void*)_malloc_init2(size,1,0);
}
void* kmalloc_p(uint32 size, uint32* phys)
{
if (!mem_initialized) return 0;
if (mem_initialized == 1) {
*phys = _malloc_init1(size,0);
return (void*)(*phys);
}
return (void*)_malloc_init2(size,0,phys);
}
void* kmalloc_ap(uint32 size, uint32* phys)
{
if (!mem_initialized) return 0;
uint32 ret;
if (mem_initialized == 1) {
*phys = ret = _malloc_init1(size,1);
}
else ret = _malloc_init2(size,1,phys);
LogMem("%#kmalloc_ap requested, returned 0x%x, phys = 0x%x.\n", ColorMagenta, ret, *phys);
return (void*)ret;
}

View File

@ -1,48 +0,0 @@
/*
* memory_info.c
*
* Created on: Aug 27, 2011
* Author: Tiberiu
*/
#include <memory-add.h>
// MemoryGetFree(), MemoryGetTotal(), MemoryGet blah blah...
// Returns total physical memory in bytes
uint32 MemoryGetTotal()
{
return (TotalMemory);
}
// Returns total free physical memory in bytes
uint32 MemoryGetFree()
{
return (TotalFrames - UsedFrames) * 0x4;
}
// Total used physical memory in bytes
uint32 MemoryGetUsed()
{
return UsedFrames * 0x4;
}
// Same as above functions, but in frames
uint32 MemoryGetFrameSize()
{
return 0x1000;
}
uint32 MemoryGetFramesTotal()
{
return TotalFrames;
}
uint32 MemoryGetFramesUsed()
{
return UsedFrames;
}
uint32 MemoryGetFramesFree()
{
return (TotalFrames - UsedFrames);
}

View File

@ -1,92 +0,0 @@
/*
* memory-init.c
*
* Created on: Aug 27, 2011
* Author: Tiberiu
*/
#include <memory-add.h>
#include <multiboot.h>
#include <debugio.h>
#include "../../drivers/cmos/cmos.h"
#include <stdio.h>
uint32 mem_kernel_end = 0;
uint8 mem_initialized = 0;
uint32 _memory_get_total_mem(MultibootInfo* info)
{
// Grub was nice enough to give us info
if (info->Flags & MultibootInfo_MEMORY) return (1024 + info->MemoryUpper);
// No? Get info from CMOS
uint8 low, high;
uint32 total;
low = CmosRead(0x30);
high = CmosRead(0x31);
total = (uint32)(low | high<<8) + 1024;
ErrorMem("%#Missing memory info from bootloader. Reading from CMOS: %ukb\n", ColorLightRed, total);
return total;
}
void _memory_reserve_system(MultibootInfo* info)
{
MagicBreakpoint();
if ((info->Flags & MultibootInfo_MEM_MAP) != 0)
{
MultibootMemoryMapEntry* location = (MultibootMemoryMapEntry*)info->MemoryMapAddress;
while ((uint32)location < (info->MemoryMapAddress + info->MemoryMapLength))
{
if (location->Type > 1)
MemPhReserveFrames((uint32)location->Address, (uint32)location->Length);
location = (MultibootMemoryMapEntry*) ((uint32)location + location->Size + sizeof(uint32));
}
}
else
{
ErrorMem("%#Missing %#memory map%# info from bootloader.\n", ColorLightRed, ColorWhite, ColorLightRed);
// Standard memory hole at 15mb
MemPhReserveFrames(0x00F00000, 0x00100000);
}
// Standard reserved memory areas
MemPhReserveFrames(0x0, 0x400 + 256); // Real mode IVT, BDA
MemPhReserveFrames(0x1000, 0x2400); // DMA buffer
MemPhReserveFrames(0x9FC00, 385*1024); // EBDA, Video memory, ROM area
}
void MemoryInitialize (MultibootInfo* info)
{
uint32 totalSystemMemory = _memory_get_total_mem(info);
MemPhInitialize(totalSystemMemory);
PagingInitialize(0x200000);
LogMem("Reserving important areas...\n");
_memory_reserve_system(info);
LogMem("Allocating kernel heap...\n");
KernelHeap = MemHeapCreate(KERNEL_HEAP_START, KERNEL_HEAP_START
+ KERNEL_HEAP_INITIAL_SIZE, 0xCFFFF000, 3); // is kernel, writeable
LogMem("Done initializing memory!");
mem_initialized = 2;
}
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);
}