Compare commits
1 Commits
master
...
bad-versio
Author | SHA1 | Date | |
---|---|---|---|
a58fee7200 |
@ -1,4 +1,4 @@
|
||||
Log created: 2011-09-20T09:23:01.130988600Z
|
||||
Log created: 2011-09-08T09:15:29.377663100Z
|
||||
Executable: C:\PROGRA~1\oracle\Virtua~1\VirtualBox.exe
|
||||
Commandline: C:\PROGRA~1\oracle\Virtua~1\\virtualbox --startvm "lux Testbed" --dbg
|
||||
fatal error in recompiler cpu: triple fault
|
4
2011-09-08-09-21-27.088-VirtualBox.exe-4884.log
Normal file
4
2011-09-08-09-21-27.088-VirtualBox.exe-4884.log
Normal file
@ -0,0 +1,4 @@
|
||||
Log created: 2011-09-08T09:21:27.881741000Z
|
||||
Executable: C:\PROGRA~1\oracle\Virtua~1\VirtualBox.exe
|
||||
Commandline: C:\PROGRA~1\oracle\Virtua~1\\virtualbox --startvm "lux Testbed" --dbg
|
||||
fatal error in recompiler cpu: triple fault
|
BIN
Build/loader.o
BIN
Build/loader.o
Binary file not shown.
BIN
Build/main.o
BIN
Build/main.o
Binary file not shown.
@ -21,7 +21,7 @@ string ConsoleCommands[] =
|
||||
"restart",
|
||||
"dir",
|
||||
"cat",
|
||||
"task"
|
||||
"fork"
|
||||
};
|
||||
|
||||
int32 ConsoleCommandsCount = 14;
|
||||
@ -174,7 +174,7 @@ void _CommandMemPrintMemmap()
|
||||
blocks = n - old;
|
||||
used = 0;
|
||||
for (; old < n; old++)
|
||||
used += (MemPhGetBlock (old) != 0);
|
||||
used += (MemPhGetFrame(old) != 0);
|
||||
|
||||
if (used <= blocks / 5) c = ' ';
|
||||
else if (used > 4 * blocks / 5) c = 219;
|
||||
@ -338,29 +338,39 @@ void CommandCat (string argv[], int32 argc)
|
||||
}
|
||||
|
||||
#include <tasking.h>
|
||||
void task()
|
||||
{
|
||||
Point p = {5, 1};
|
||||
uint32 t = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ConsoleCursorGoto(p);
|
||||
ConsoleWrite("Hello world! %u ", t++);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandTask()
|
||||
void CommandFork()
|
||||
{
|
||||
ConsoleClear();
|
||||
TaskCreate(task);
|
||||
|
||||
Point p = {5, 2};
|
||||
uint32 t = 0;
|
||||
Point a = {5,1};
|
||||
Point b = {5,2};
|
||||
|
||||
while (1)
|
||||
// Child?
|
||||
if (Fork() == 0)
|
||||
{
|
||||
ConsoleCursorGoto(p);
|
||||
ConsoleWrite("%#Hello world! %u ", ColorLightBlue, t++);
|
||||
uint32 i;
|
||||
for (i = 0; i < 0x7fffffff; i++)
|
||||
{
|
||||
ConsoleCursorGoto(a);
|
||||
ConsoleWrite ("[c] Hello %u", i);
|
||||
|
||||
if (i > 0x7ffffff0) i = 0;
|
||||
}
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
// Not child?
|
||||
else {
|
||||
uint32 i;
|
||||
for (i = 0; i < 0x7fffffff; i++)
|
||||
{
|
||||
ConsoleCursorGoto(b);
|
||||
ConsoleWrite ("[p] world %u", i);
|
||||
|
||||
if (i > 0x7ffffff0) i = 0;
|
||||
}
|
||||
|
||||
for (;;);
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ loop:
|
||||
case 10: SystemReboot(); break;
|
||||
case 11: CommandDir(params, count); break;
|
||||
case 12: CommandCat(params, count); break;
|
||||
case 13: CommandTask(); break;
|
||||
case 13: CommandFork(); break;
|
||||
|
||||
default: ConsoleWrite ("%#! Command %#%s%# was not implemented (yet)!\n",
|
||||
Color(0,ColorLightRed), Color(0,ColorWhite), params[0], Color(0,ColorLightRed)); break;
|
||||
|
@ -17,6 +17,7 @@ string LogAllowedDevices[] = {
|
||||
"vfs",
|
||||
//"mem",
|
||||
"console",
|
||||
"tasking",
|
||||
0x0,
|
||||
0x0
|
||||
};
|
||||
@ -118,9 +119,3 @@ int32 LogWrite (uint8 error, string device, string format, ...)
|
||||
ConsoleCursorUpdateHardware();
|
||||
return i;
|
||||
}
|
||||
|
||||
void LogAssert (int32 condition, string file, int32 line)
|
||||
{
|
||||
if (!condition)
|
||||
Panic("Assert", "Assertion failed in file %s line %d.\n", file, line);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ void DriversInstall()
|
||||
DriversInstall_Clock();
|
||||
|
||||
// Install fdc
|
||||
Error ("Floppy", "Floppy driver is currently disabled.\n");
|
||||
|
||||
Error("Floppy", "Floppy driver is currently disabled.\n");
|
||||
//IrqInstallHandler(6, FloppyIrqHandler);
|
||||
//FloppyInitialize();
|
||||
}
|
||||
|
@ -6,12 +6,14 @@
|
||||
volatile TimeSystem _internal_time;
|
||||
uint32 _internal_frequency_hz;
|
||||
|
||||
extern void TaskSwitch (_RegsStack32* regs);
|
||||
extern void TaskingScheduler();
|
||||
|
||||
void TimeHandler(_RegsStack32* r)
|
||||
void TimeHandler(_RegsStack32* UNUSED(r))
|
||||
{
|
||||
// Make sure it is initialised
|
||||
if (_internal_frequency_hz == 0) return;
|
||||
|
||||
// Timer tick
|
||||
_internal_time.Time += 1000/_internal_frequency_hz;
|
||||
if (_internal_time.Time >= MILISECONDS_IN_DAY)
|
||||
{
|
||||
@ -19,5 +21,6 @@ void TimeHandler(_RegsStack32* r)
|
||||
_internal_time.Time-=MILISECONDS_IN_DAY;
|
||||
}
|
||||
|
||||
TaskSwitch(r);
|
||||
// Launch scheduler
|
||||
TaskingScheduler();
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ void CrashMessage(_RegsStack32 *r)
|
||||
ConsoleCursorGoto(c); ConsoleWrite("eflags=0x%x", r->eflags);
|
||||
ConsoleCursorGoto(d); ConsoleWrite("useresp=0x%x\n", r->useresp);
|
||||
|
||||
ConsoleCursorGoto(a); ConsoleWrite("ss=0x%x", r->ss);
|
||||
ConsoleCursorGoto(b); ConsoleWrite("int_no=0x%x", r->int_no);
|
||||
ConsoleCursorGoto(a); ConsoleWrite("gs=0x%x", r->ss);
|
||||
ConsoleCursorGoto(b); ConsoleWrite("fs=0x%x", r->int_no);
|
||||
ConsoleCursorGoto(c); ConsoleWrite("err_code=0x%x", r->err_code);
|
||||
|
||||
// Useful info about page fault
|
||||
|
@ -180,16 +180,13 @@ void luxInitrdInstall (MultibootInfo* info)
|
||||
VfsInstallFs(&fs);
|
||||
|
||||
// Check for multiboot info flags to see if any modules are loaded
|
||||
if ((info->Flags & 8) == 0) {
|
||||
Error("Initrd", "No boot modules found!");
|
||||
return;
|
||||
}
|
||||
if ((info->Flags & 8) == 0) return;
|
||||
|
||||
// Loop through each module and if it is an initrd image, mount it
|
||||
MultibootModule* modules = (MultibootModule*) info->ModulesAddress;
|
||||
|
||||
for (i = 0; i < info->ModulesCount; i++)
|
||||
if (*((uint32*) modules[i].ModuleStart) == LUXMAGIC)
|
||||
if ((*(uint32*) modules[i].ModuleStart) == LUXMAGIC)
|
||||
{
|
||||
// Mount the device
|
||||
Log("Initrd", "Found initrd image at 0x%x.\n", modules[i].ModuleStart);
|
||||
@ -199,7 +196,4 @@ void luxInitrdInstall (MultibootInfo* info)
|
||||
mp->FsData[0] = modules[i].ModuleStart;
|
||||
mp->FsData[1] = modules[i].ModuleEnd;
|
||||
}
|
||||
else {
|
||||
Log("Initrd", "Found module @ 0x%x, but not initrd image.\n", modules[i].ModuleStart);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ void HalInitialize()
|
||||
KeyboardInstallB(); Log("HAL", "%#[2/2]\n", ColorLightGreen);
|
||||
|
||||
// Install mouse driver
|
||||
//MouseInstall(); Log("HAL", "Installed mouse driver\n");
|
||||
MouseInstall(); Log("HAL", "Installed mouse driver\n");
|
||||
|
||||
// Install VFS
|
||||
VfsInstall();
|
||||
|
@ -65,12 +65,10 @@ extern void ConsoleMain();
|
||||
// External test routines
|
||||
extern void SystemPanic();
|
||||
extern int32 LogWrite (uint8 error, string device, string format, ...);
|
||||
extern void LogAssert (int32 condition, string file, int32 line);
|
||||
|
||||
// Debug print
|
||||
#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(); }
|
||||
#define Assert(c) { LogAssert(c, __FILE__, __LINE__); }
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,8 @@ enum PageFlags
|
||||
PageFrame = 0xFFFFF000
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
Page Pages[1024];
|
||||
} PageTable;
|
||||
@ -46,28 +48,28 @@ typedef struct {
|
||||
extern PageDirectory* CurrentDirectory;
|
||||
extern PageDirectory* KernelDirectory;
|
||||
|
||||
extern void PagingEnable ();
|
||||
extern void PagingDisable ();
|
||||
extern void PagingSwitchDirectory (PageDirectory* dir);
|
||||
extern void PagingFlushTlb ();
|
||||
extern void PagingInitialize (uint32* kernelEnd);
|
||||
extern void PagingMapPage (uint32 phys, uint32 virt, uint32 flags, PageDirectory* pd);
|
||||
extern void PagingUnmapPage (uint32 virt, PageDirectory* pd);
|
||||
extern uint32 PagingGetPhysical (uint32 virt, PageDirectory* pd);
|
||||
extern void PagingInitialize(volatile uint32* SystemMemory);
|
||||
extern void PagingSwitchPageDirectory (PageDirectory* dir);
|
||||
extern Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir);
|
||||
extern void PagingCopyPagePhysical (uint32, uint32);
|
||||
extern PageTable* PagingCloneTable (PageTable* src, uint32* physAddr);
|
||||
extern PageDirectory* PagingCloneDirectory (PageDirectory* src);
|
||||
|
||||
|
||||
/***************************************************
|
||||
* Physical memory manager *
|
||||
***************************************************/
|
||||
extern uint32 TotalBlocks;
|
||||
extern uint32 TotalFrames;
|
||||
extern uint32 TotalMemory;
|
||||
extern uint32 UsedBlocks;
|
||||
extern uint32 UsedFrames;
|
||||
|
||||
extern void MemPhInitialize (uint32 SystemMemoryKb);
|
||||
extern void MemPhSetBlock (uint32 Block, uint8 value);
|
||||
extern uint32 MemPhGetBlock (uint32 Block);
|
||||
extern uint32 MemPhAllocateBlock ();
|
||||
extern void MemPhFreeBlock (uint32 addr);
|
||||
extern void MemPhReserveBlocks (uint32 address, uint32 length);
|
||||
void MemPhInitialize(uint32 SystemMemoryKb);
|
||||
extern void MemPhSetFrame (uint32 frame, uint8 value);
|
||||
uint32 MemPhGetFrame (uint32 frame);
|
||||
uint32 MemPhFindFreeFrame();
|
||||
void MemPhAllocFrame(Page* page, uint8 isKernel, uint8 isWriteable);
|
||||
void MemPhFreeFrame(Page* page);
|
||||
void MemPhReserveFrames (uint32 address, uint32 length);
|
||||
|
||||
|
||||
/***************************************************
|
||||
@ -83,12 +85,12 @@ typedef struct
|
||||
|
||||
extern MemHeap* KernelHeap;
|
||||
|
||||
extern uint32 MemHeapFindSmallestHole (uint32 size, uint8 page_align, MemHeap* heap);
|
||||
extern int32 MemHeapCompare (uint32 a, uint32 b);
|
||||
extern MemHeap* MemHeapCreate (uint32 start, uint32 end, uint32 max, uint8 flags);
|
||||
extern uint32 MemHeapExpand (uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
||||
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);
|
||||
extern uint32 MemHeapFindSmallestHole (uint32 size, uint8 page_align, MemHeap* heap);
|
||||
extern int32 MemHeapCompare (uint32 a, uint32 b);
|
||||
extern MemHeap* MemHeapCreate(uint32 start, uint32 end, uint32 max, uint8 flags);
|
||||
extern void MemHeapExpand(uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
||||
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);
|
||||
|
||||
#endif /* MEMORY_ADD_H_ */
|
||||
|
@ -32,7 +32,7 @@
|
||||
// Memory manager
|
||||
#define KERNEL_HEAP_START 0xC0000000
|
||||
#define KERNEL_HEAP_INITIAL_SIZE 0x100000
|
||||
#define KERNEL_HEAP_END (KERNEL_HEAP_START + KERNEL_HEAP_INITIAL_SIZE)
|
||||
#define KERNEL_HEAP_END (KERNEL_HEAP_START + KERNEL_HEAP_INITIAL_SIZE)
|
||||
|
||||
|
||||
#endif /* SETTINGS_H_ */
|
||||
|
@ -1,28 +1,33 @@
|
||||
/*
|
||||
* tasking.h
|
||||
*
|
||||
* Created on: Sep 8, 2011
|
||||
* Created on: Sep 7, 2011
|
||||
* Author: Tiberiu
|
||||
*/
|
||||
|
||||
#ifndef TASKING_H_
|
||||
#define TASKING_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <memory-add.h>
|
||||
|
||||
typedef struct _Task {
|
||||
uint32 Pid;
|
||||
uint32 Eip, Esp, Ebp;
|
||||
PageDirectory* Pd;
|
||||
uint32 StackLowerBase;
|
||||
uint32 StackUpperBase;
|
||||
uint8 Initialized;
|
||||
struct _Task* Next;
|
||||
typedef struct _Task{
|
||||
uint32 Pid; // Process ID
|
||||
uint32 Esp, Ebp, Eip; // Stack, base and instruction pointers
|
||||
PageDirectory* Pd; // Page dir
|
||||
struct _Task *Next; // Next task in a linked list
|
||||
} Task;
|
||||
|
||||
extern void TaskInitialize();
|
||||
extern void TaskSwitch ();
|
||||
extern void TaskCreate (void (*func)());
|
||||
extern void TaskingInitialize();
|
||||
extern void TaskingScheduler();
|
||||
extern void TaskingSwitch();
|
||||
|
||||
extern int32 Fork();
|
||||
|
||||
extern void TaskingSetInitialStack(uint32 addr);
|
||||
extern void TaskingMoveStack (uint32 newstart, uint32 size);
|
||||
|
||||
extern int32 GetPid();
|
||||
|
||||
extern uint32 TaskingReadEip();
|
||||
|
||||
#endif /* TASKING_H_ */
|
||||
|
@ -1 +1 @@
|
||||
#define OS_BUILD "0.1.1.50"
|
||||
#define OS_BUILD "0.1.1.48"
|
||||
|
@ -28,7 +28,8 @@ uint32 _malloc_init2 (uint32 size, uint8 page_aligned, uint32* phys)
|
||||
|
||||
if (phys)
|
||||
{
|
||||
*phys = PagingGetPhysical(ret, KernelDirectory) + (ret & 0xFFF);
|
||||
Page *pg = PagingGetPage(ret, 0, KernelDirectory);
|
||||
*phys = (*pg & PageFrame) + (ret & 0xFFF);
|
||||
|
||||
Log("Mem","%#Allocated %u bytes (%spage aligned) at address 0x%x (phys=%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret, *phys);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <memory-add.h>
|
||||
// MemoryGetFree(), MemoryGetTotal(), MemoryGet blah blah...
|
||||
|
||||
// Returns total physical memory in bytes
|
||||
uint32 MemoryGetTotal()
|
||||
@ -16,13 +17,13 @@ uint32 MemoryGetTotal()
|
||||
// Returns total free physical memory in bytes
|
||||
uint32 MemoryGetFree()
|
||||
{
|
||||
return (TotalBlocks - UsedBlocks) * 0x4;
|
||||
return (TotalFrames - UsedFrames) * 0x4;
|
||||
}
|
||||
|
||||
// Total used physical memory in bytes
|
||||
uint32 MemoryGetUsed()
|
||||
{
|
||||
return UsedBlocks * 0x4;
|
||||
return UsedFrames * 0x4;
|
||||
}
|
||||
|
||||
// Same as above functions, but in frames
|
||||
@ -33,15 +34,15 @@ uint32 MemoryGetFrameSize()
|
||||
|
||||
uint32 MemoryGetFramesTotal()
|
||||
{
|
||||
return TotalBlocks;
|
||||
return TotalFrames;
|
||||
}
|
||||
|
||||
uint32 MemoryGetFramesUsed()
|
||||
{
|
||||
return UsedBlocks;
|
||||
return UsedFrames;
|
||||
}
|
||||
|
||||
uint32 MemoryGetFramesFree()
|
||||
{
|
||||
return (TotalBlocks - UsedBlocks);
|
||||
return (TotalFrames - UsedFrames);
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
#include "../../drivers/cmos/cmos.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
uint32 mem_kernel_end = 0;
|
||||
uint8 mem_initialized = 0;
|
||||
|
||||
@ -41,7 +42,7 @@ void _memory_reserve_system(MultibootInfo* info)
|
||||
while ((uint32)location < (info->MemoryMapAddress + info->MemoryMapLength))
|
||||
{
|
||||
if (location->Type > 1)
|
||||
MemPhReserveBlocks((uint32)location->Address, (uint32)location->Length);
|
||||
MemPhReserveFrames((uint32)location->Address, (uint32)location->Length);
|
||||
|
||||
location = (MultibootMemoryMapEntry*) ((uint32)location + location->Size + sizeof(uint32));
|
||||
}
|
||||
@ -52,35 +53,29 @@ void _memory_reserve_system(MultibootInfo* info)
|
||||
Error("Mem", "%#Missing %#memory map%# info from bootloader.\n", ColorLightRed, ColorWhite, ColorLightRed);
|
||||
|
||||
// Standard memory hole at 15mb
|
||||
MemPhReserveBlocks(0x00F00000, 0x00100000);
|
||||
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)
|
||||
{
|
||||
// Get total system memory
|
||||
uint32 totalSystemMemory = _memory_get_total_mem(info);
|
||||
|
||||
// Initialize physical & virtual memory managers
|
||||
uint32 end = mem_kernel_end + 0x80000;
|
||||
MemPhInitialize(totalSystemMemory);
|
||||
PagingInitialize(&end);
|
||||
PagingInitialize((volatile uint32*)&mem_kernel_end);
|
||||
|
||||
// Reserve physical blocks
|
||||
_memory_reserve_system(info);
|
||||
|
||||
uint32 i;
|
||||
// Allocate some space for the kernel heap
|
||||
for (i = KERNEL_HEAP_START; i <= KERNEL_HEAP_END; i += 0x1000)
|
||||
PagingMapPage(MemPhAllocateBlock(), i, PageWriteable, KernelDirectory);
|
||||
|
||||
// Create the kernel heap
|
||||
KernelHeap = MemHeapCreate(KERNEL_HEAP_START, KERNEL_HEAP_START
|
||||
+ KERNEL_HEAP_INITIAL_SIZE, 0xCFFFF000, 3); // is kernel, writeable
|
||||
|
||||
Log("Mem", "Done initializing memory!\n");
|
||||
Log("Mem", "Done initializing memory!");
|
||||
|
||||
mem_initialized = 2;
|
||||
}
|
||||
@ -89,5 +84,5 @@ void MemoryTempInitialize (uint32 kernel_end)
|
||||
{
|
||||
mem_initialized = 1;
|
||||
mem_kernel_end = kernel_end;
|
||||
Log("Mem", "Initialized temporary memory manager, allocating from %#0x%x.\n", ColorWhite, mem_kernel_end);
|
||||
Log("Mem", "Initialized temporary memory manager, allocating from %#0x%x.\n", kernel_end);
|
||||
}
|
||||
|
@ -39,9 +39,6 @@ start:
|
||||
extern k_main
|
||||
call k_main
|
||||
|
||||
cli
|
||||
hlt
|
||||
|
||||
; Show error message, and halt system
|
||||
.bad:
|
||||
|
||||
|
@ -12,8 +12,10 @@ extern uint32 _end;
|
||||
|
||||
extern void luxInitrdInstall (MultibootInfo* info);
|
||||
|
||||
void k_main(MultibootInfo* info)
|
||||
void k_main(MultibootInfo* info, uint32 initial_stack)
|
||||
{
|
||||
TaskingSetInitialStack(initial_stack);
|
||||
|
||||
uint32 KernelEnd = (uint32)&_end;
|
||||
|
||||
// Find kernel's end
|
||||
@ -30,7 +32,7 @@ void k_main(MultibootInfo* info)
|
||||
MemoryTempInitialize(KernelEnd);
|
||||
MemoryInitialize(info);
|
||||
|
||||
TaskInitialize();
|
||||
TaskingInitialize();
|
||||
|
||||
HalInitialize();
|
||||
luxInitrdInstall(info);
|
||||
|
@ -6,6 +6,9 @@
|
||||
#define MEMHEAP_INDEX_SIZE 0x20000
|
||||
#define MEMHEAP_MINIM_SIZE 0x70000
|
||||
|
||||
#define FlagsKernel 1
|
||||
#define FlagsWriteable 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 Magic;
|
||||
@ -95,31 +98,30 @@ MemHeap* MemHeapCreate(uint32 start, uint32 end, uint32 max, uint8 flags)
|
||||
}
|
||||
|
||||
|
||||
uint32 MemHeapExpand(uint32 newsz, MemHeap* heap, PageDirectory* pd)
|
||||
void MemHeapExpand(uint32 newsz, MemHeap* heap, PageDirectory* pd)
|
||||
{
|
||||
if (newsz <= heap->EndAddress - heap->StartAddress) return heap->EndAddress - heap->StartAddress;
|
||||
if (newsz <= heap->EndAddress - heap->StartAddress) return;
|
||||
|
||||
if (newsz & 0xfff) newsz = (newsz & 0xfffff000) + 0x1000;
|
||||
if (newsz + heap->StartAddress >= heap->MaxAddress) return heap->EndAddress - heap->StartAddress;
|
||||
if (newsz + heap->StartAddress >= heap->MaxAddress) return;
|
||||
|
||||
uint32 i;
|
||||
for (i = heap->EndAddress; i < heap->StartAddress + newsz; i+=0x1000)
|
||||
PagingMapPage(MemPhAllocateBlock(), i, heap->Flags, pd);
|
||||
for (i = heap->EndAddress - heap->StartAddress; i < heap->StartAddress + newsz; i+=0x1000)
|
||||
MemPhAllocFrame(PagingGetPage(i, 1, pd), heap->Flags & FlagsKernel, heap->Flags & FlagsWriteable);
|
||||
|
||||
heap->EndAddress = heap->StartAddress + newsz;
|
||||
return newsz;
|
||||
}
|
||||
|
||||
uint32 MemHeapContract(uint32 newsz, MemHeap* heap, PageDirectory* pd)
|
||||
{
|
||||
if (newsz >= heap->EndAddress - heap->StartAddress) return heap->EndAddress - heap->StartAddress;
|
||||
if (newsz >= heap->EndAddress - heap->StartAddress) return 0;
|
||||
|
||||
if (newsz & 0xfff) newsz = (newsz & 0xfffff000) + 0x1000; // page align
|
||||
newsz = Max(newsz, MEMHEAP_MINIM_SIZE);
|
||||
|
||||
uint32 i;
|
||||
for (i = heap->EndAddress - 0x1000; i > heap->StartAddress + newsz; i-=0x1000)
|
||||
PagingUnmapPage(i, pd);
|
||||
for (i = heap->EndAddress - heap->StartAddress - 0x1000; i > newsz; i-=0x1000)
|
||||
MemPhFreeFrame(PagingGetPage(i, 0, pd));
|
||||
|
||||
heap->EndAddress = heap->StartAddress + newsz;
|
||||
return newsz;
|
||||
|
@ -6,123 +6,132 @@
|
||||
*/
|
||||
#include <memory-add.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*******************************
|
||||
* Data *
|
||||
*******************************/
|
||||
PageDirectory* CurrentDirectory;
|
||||
PageDirectory* KernelDirectory;
|
||||
|
||||
void PagingEnable()
|
||||
/*******************************
|
||||
* Useful routines *
|
||||
*******************************/
|
||||
void PagingInitialize(volatile uint32* kernel_used)
|
||||
{
|
||||
uint32 tmp;
|
||||
asm volatile ("mov %%cr0, %0" : "=r"(tmp));
|
||||
tmp |= 0x80000000;
|
||||
asm volatile ("mov %0, %%cr0" : : "r"(tmp));
|
||||
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));
|
||||
|
||||
kernelPd->PhysicalAddr = (uint32)kernelPd->TablesPhysical;
|
||||
KernelDirectory = kernelPd;
|
||||
|
||||
uint32 i;
|
||||
|
||||
// Map some kernel space
|
||||
for (i = KERNEL_HEAP_START; i < KERNEL_HEAP_END; i+=0x1000)
|
||||
PagingGetPage(i, 1, kernelPd);
|
||||
|
||||
// Identity map
|
||||
for (i = 0; i < (volatile uint32) kernel_used + 0x1000; i+=0x1000)
|
||||
MemPhAllocFrame(PagingGetPage(i, 1, kernelPd), 0, 0);
|
||||
|
||||
// Allocate kernel space
|
||||
for (i = KERNEL_HEAP_START; i < KERNEL_HEAP_END; i+=0x1000)
|
||||
MemPhAllocFrame (PagingGetPage(i, 1, kernelPd), 0, 0);
|
||||
|
||||
PagingSwitchPageDirectory (kernelPd);
|
||||
PageDirectory* temp = PagingCloneDirectory(kernelPd);
|
||||
PagingSwitchPageDirectory (temp);
|
||||
}
|
||||
|
||||
void PagingDisable()
|
||||
{
|
||||
uint32 tmp;
|
||||
asm volatile ("mov %%cr0, %0" : "=r"(tmp));
|
||||
tmp &= 0x7FFFFFFF;
|
||||
asm volatile ("mov %0, %%cr0" : : "r"(tmp));
|
||||
}
|
||||
|
||||
void PagingSwitchDirectory(PageDirectory* dir)
|
||||
void PagingSwitchPageDirectory (PageDirectory* dir)
|
||||
{
|
||||
CurrentDirectory = dir;
|
||||
asm volatile ("mov %0, %%cr3" : : "r"(dir->PhysicalAddr));
|
||||
asm volatile ("mov %0, %%cr3":: "r"(dir->PhysicalAddr));
|
||||
|
||||
// Enable paging
|
||||
uint32 cr0;
|
||||
asm volatile ("mov %%cr0, %0": "=r"(cr0));
|
||||
cr0 |= 0x80000000;
|
||||
asm volatile ("mov %0, %%cr0":: "r"(cr0));
|
||||
|
||||
Log("Mem", "Enabled paging.\n");
|
||||
}
|
||||
|
||||
void PagingFlushTlb ()
|
||||
Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir)
|
||||
{
|
||||
uint32 tmp;
|
||||
asm volatile ("mov %%cr3, %0" : "=r"(tmp));
|
||||
asm volatile ("mov %0, %%cr3" : : "r" (tmp));
|
||||
}
|
||||
addr >>= 12;
|
||||
|
||||
void PagingInitialize(uint32* kernelEnd)
|
||||
{
|
||||
// Create the kernel page directory
|
||||
PageDirectory* kdir = kmalloc_a(sizeof(PageDirectory));
|
||||
memset(kdir, 0, sizeof(PageDirectory));
|
||||
uint32 tableIndex = addr >> 10;
|
||||
|
||||
KernelDirectory = kdir;
|
||||
if (dir->Tables[tableIndex])
|
||||
return &dir->Tables[tableIndex]->Pages[addr&0x3ff];
|
||||
|
||||
// Set up physical address of PDEs.
|
||||
kdir->PhysicalAddr = (uint32) kdir->TablesPhysical;
|
||||
|
||||
// Identity map the kernel
|
||||
uint32 i = 0;
|
||||
while (i <= *kernelEnd + 1024)
|
||||
else if (make)
|
||||
{
|
||||
PagingMapPage(i, i, PageWriteable, kdir);
|
||||
i += 0x1000;
|
||||
uint32 temp;
|
||||
dir->Tables[tableIndex] = (PageTable*)kmalloc_ap(sizeof(PageTable), &temp);
|
||||
memset (dir->Tables[tableIndex], 0, 0x1000);
|
||||
dir->TablesPhysical[tableIndex] = temp | 0x7;
|
||||
return &dir->Tables[tableIndex]->Pages[addr&0x3ff];
|
||||
}
|
||||
|
||||
// Reserve the identity mapped blocks
|
||||
MemPhReserveBlocks(0x0, *kernelEnd);
|
||||
|
||||
PagingSwitchDirectory(kdir);
|
||||
PagingEnable();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void PagingMapPage (uint32 phys, uint32 virt, uint32 flags, PageDirectory* pd)
|
||||
|
||||
PageTable* PagingCloneTable (PageTable* src, uint32* physAddr)
|
||||
{
|
||||
// Calculate pde and pte
|
||||
uint32 pde = virt >> 22;
|
||||
uint32 pte = (virt >> 12) & 0x3ff;
|
||||
PageTable* tab = (PageTable*) kmalloc_ap(sizeof(PageTable), physAddr);
|
||||
memset (tab, 0, sizeof(PageTable));
|
||||
|
||||
phys &= 0xFFFFF000; // Make sure address is page aligned
|
||||
flags &= 0xFFF; // Make sure flags don't overflow
|
||||
|
||||
// See if page table exists
|
||||
if (!pd->Tables[pde])
|
||||
uint32 i;
|
||||
for (i=0; i<1024; i++)
|
||||
{
|
||||
// No? allocate it
|
||||
uint32 ph;
|
||||
PageTable* pt = kmalloc_ap(sizeof(PageTable), &ph);
|
||||
memset(pt, 0, sizeof(PageTable));
|
||||
if (!(src->Pages[i] & PageFrame)) continue;
|
||||
MemPhAllocFrame(&tab->Pages[i], 1, 0);
|
||||
|
||||
pd->Tables[pde] = pt;
|
||||
pd->TablesPhysical[pde] = ph | 0x7;
|
||||
if (src->Pages[i] & PagePresent) tab->Pages[i] |= PagePresent;
|
||||
if (src->Pages[i] & PageWriteable) tab->Pages[i] |= PageWriteable;
|
||||
if (src->Pages[i] & PageUser) tab->Pages[i] |= PageUser;
|
||||
if (src->Pages[i] & PageAccessed) tab->Pages[i] |= PageAccessed;
|
||||
if (src->Pages[i] & PageDirty) tab->Pages[i] |= PageDirty;
|
||||
|
||||
PagingCopyPagePhysical (src->Pages[i] & PageFrame, tab->Pages[i] & PageFrame);
|
||||
}
|
||||
|
||||
// Set up the page
|
||||
pd->Tables[pde]->Pages[pte] = phys | flags | 0x1; // Present, and flags
|
||||
|
||||
// If it is the current directory, flush the tlb to notice the change
|
||||
if (pd == CurrentDirectory) PagingFlushTlb();
|
||||
return tab;
|
||||
}
|
||||
|
||||
void PagingUnmapPage (uint32 virt, PageDirectory* pd)
|
||||
PageDirectory* PagingCloneDirectory (PageDirectory* src)
|
||||
{
|
||||
// Calculate pde and pte
|
||||
uint32 pde = virt >> 22;
|
||||
uint32 pte = (virt >> 12) & 0x3ff;
|
||||
uint32 phys;
|
||||
PageDirectory* dir = (PageDirectory*)kmalloc_ap(sizeof(PageDirectory), &phys);
|
||||
|
||||
if (!pd->Tables[pde] || !pd->Tables[pde]->Pages[pte]) return;
|
||||
memset(dir, 0, sizeof(PageDirectory));
|
||||
|
||||
// Get physical address
|
||||
uint32 phys = pd->Tables[pde]->Pages[pte] & PageFrame;
|
||||
uint32 offset = (uint32)dir->TablesPhysical - (uint32)dir;
|
||||
dir->PhysicalAddr = phys + offset;
|
||||
|
||||
// Free page
|
||||
pd->Tables[pde]->Pages[pte] = 0;
|
||||
MemPhFreeBlock(phys);
|
||||
uint32 i;
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
if (!src->Tables[i]) continue;
|
||||
|
||||
// If it is the current directory, flush the tlb to notice the change
|
||||
if (pd == CurrentDirectory) PagingFlushTlb();
|
||||
}
|
||||
|
||||
uint32 PagingGetPhysical (uint32 virt, PageDirectory* pd)
|
||||
{
|
||||
// Calculate pde and pte
|
||||
uint32 pde = virt >> 22;
|
||||
uint32 pte = (virt >> 12) & 0x3ff;
|
||||
|
||||
// Not mapped
|
||||
if (!pd->Tables[pde] || !pd->Tables[pde]->Pages[pte]) return NULL;
|
||||
|
||||
return (pd->Tables[pde]->Pages[pte] & PageFrame);
|
||||
if (KernelDirectory->Tables[i] == src->Tables[i])
|
||||
{
|
||||
// It is in the kernel, link it
|
||||
dir->Tables[i] = src->Tables[i];
|
||||
dir->TablesPhysical[i] = src->TablesPhysical[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy the table
|
||||
uint32 ph;
|
||||
dir->Tables[i] = PagingCloneTable (src->Tables[i], &ph);
|
||||
dir->TablesPhysical[i] = ph | 0x7;
|
||||
}
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
@ -6,89 +6,103 @@
|
||||
*/
|
||||
#include <memory-add.h>
|
||||
|
||||
uint32* BlockMap;
|
||||
uint32 TotalBlocks;
|
||||
uint32* FrameMap;
|
||||
uint32 TotalFrames;
|
||||
uint32 TotalMemory;
|
||||
uint32 UsedBlocks;
|
||||
uint32 UsedFrames;
|
||||
|
||||
inline void ConvertIndexToBlock (uint32 index, uint32* address, uint32* offset)
|
||||
inline void ConvertIndexToFrame (uint32 index, uint32* address, uint32* offset)
|
||||
{
|
||||
*address = (index >> 5);
|
||||
*offset = index & 0x1f;
|
||||
}
|
||||
|
||||
inline uint32 ConvertBlockToIndex (uint32 address, uint32 offset)
|
||||
inline uint32 ConvertFrameToIndex (uint32 address, uint32 offset)
|
||||
{
|
||||
return (address<<5) | offset;
|
||||
}
|
||||
|
||||
void MemPhSetBlock (uint32 Block, uint8 value)
|
||||
void MemPhSetFrame (uint32 frame, uint8 value)
|
||||
{
|
||||
uint32 addr, off;
|
||||
ConvertIndexToBlock(Block, &addr, &off);
|
||||
ConvertIndexToFrame(frame, &addr, &off);
|
||||
|
||||
if (value) {
|
||||
if ((BlockMap[addr] & (1<<off)) == 0) UsedBlocks++;
|
||||
BlockMap[addr] |= 1<<off;
|
||||
if ((FrameMap[addr] & (1<<off)) == 0) UsedFrames++;
|
||||
FrameMap[addr] |= 1<<off;
|
||||
}
|
||||
|
||||
else {
|
||||
if (BlockMap[addr] & (1<<off)) UsedBlocks--;
|
||||
BlockMap[addr] &= ~(1<<off);
|
||||
if (FrameMap[addr] & (1<<off)) UsedFrames--;
|
||||
FrameMap[addr] &= ~(1<<off);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 MemPhGetBlock (uint32 Block)
|
||||
uint32 MemPhGetFrame (uint32 frame)
|
||||
{
|
||||
uint32 addr, off;
|
||||
ConvertIndexToBlock(Block, &addr, &off);
|
||||
ConvertIndexToFrame(frame, &addr, &off);
|
||||
|
||||
return BlockMap[addr] & (1<<off);
|
||||
return FrameMap[addr] & (1<<off);
|
||||
}
|
||||
|
||||
uint32 MemPhAllocateBlock()
|
||||
uint32 MemPhFindFreeFrame()
|
||||
{
|
||||
uint32 addr, pos;
|
||||
|
||||
for (addr = 0; addr < TotalBlocks >> 5; addr++)
|
||||
if (BlockMap[addr] != 0xffffffff)
|
||||
for (addr = 0; addr < TotalFrames >> 5; addr++)
|
||||
if (FrameMap[addr] != 0xffffffff)
|
||||
{
|
||||
for (pos = 0; (BlockMap[addr] & (1<<pos)) != 0; pos++) ;
|
||||
for (pos = 0; (FrameMap[addr] & (1<<pos)) != 0; pos++) ;
|
||||
|
||||
uint32 index = ConvertBlockToIndex(addr, pos);
|
||||
MemPhSetBlock(index, 1);
|
||||
|
||||
// Return address
|
||||
return (index<<12);
|
||||
return ConvertFrameToIndex(addr, pos);
|
||||
}
|
||||
|
||||
return 0xffffffff;
|
||||
}
|
||||
|
||||
void MemPhFreeBlock(uint32 addr)
|
||||
void MemPhAllocFrame(Page* page, uint8 isKernel, uint8 isWriteable)
|
||||
{
|
||||
uint32 Block = addr >> 12;
|
||||
if (!Block) return;
|
||||
if ((*page & PageFrame) != 0) return;
|
||||
|
||||
MemPhSetBlock(Block, 0);
|
||||
uint32 free = MemPhFindFreeFrame();
|
||||
if (free == 0xffffffff) {
|
||||
Panic("Mem", "%#Failed allocation free=0x%x page=0x%x\n", ColorRed, free, *page);
|
||||
return;
|
||||
}
|
||||
|
||||
MemPhSetFrame(free, 1);
|
||||
*page |= PagePresent;
|
||||
*page |= (isKernel) ? 0 : PageUser;
|
||||
*page |= (isWriteable) ? PageWriteable : 0;
|
||||
*page |= (free<<12) & PageFrame;
|
||||
}
|
||||
|
||||
void MemPhFreeFrame(Page* page)
|
||||
{
|
||||
uint32 frame = *page & PageFrame;
|
||||
if (!frame) return;
|
||||
|
||||
MemPhSetFrame(frame, 0);
|
||||
*page &= ~PageFrame;
|
||||
}
|
||||
|
||||
void MemPhInitialize(uint32 SystemMemoryKb)
|
||||
{
|
||||
TotalBlocks = SystemMemoryKb >> 2;
|
||||
TotalFrames = SystemMemoryKb >> 2;
|
||||
TotalMemory = SystemMemoryKb;
|
||||
|
||||
BlockMap = (uint32*) kmalloc(sizeof(uint32) * (1 + (TotalBlocks>>5)));
|
||||
memset(BlockMap, 0, sizeof(uint32) * (1 + (TotalBlocks>>5)));
|
||||
FrameMap = (uint32*) kmalloc(sizeof(uint32) * (1 + (TotalFrames>>5)));
|
||||
memset(FrameMap, 0, sizeof(uint32) * (1 + (TotalFrames>>5)));
|
||||
Log("Mem", "%#Started physical memory manager ok!, found %ukb\n", ColorLightGreen, SystemMemoryKb);
|
||||
}
|
||||
|
||||
void MemPhReserveBlocks (uint32 address, uint32 length)
|
||||
void MemPhReserveFrames (uint32 address, uint32 length)
|
||||
{
|
||||
address >>= 12;
|
||||
length = (length>>12) + ((length & 0xfff) > 0);
|
||||
uint32 end = address + length;
|
||||
|
||||
for (; address < end ; address++)
|
||||
MemPhSetBlock(address, 1);
|
||||
MemPhSetFrame(address, 1);
|
||||
}
|
||||
|
@ -1,7 +1,49 @@
|
||||
; tasking.asm
|
||||
;
|
||||
; tasking-asm.asm
|
||||
;
|
||||
; Created on: Sep 6, 2011
|
||||
; Author: Tiberiu
|
||||
;
|
||||
|
||||
bits 32
|
||||
|
||||
global TaskReadEip
|
||||
TaskReadEip:
|
||||
global PagingCopyPagePhysical
|
||||
PagingCopyPagePhysical:
|
||||
push ebx
|
||||
pushf
|
||||
cli
|
||||
|
||||
mov ebx, [esp+12]
|
||||
mov ecx, [esp+16]
|
||||
|
||||
; Disable paging
|
||||
mov edx, cr0
|
||||
and edx, 0x7fffffff
|
||||
mov cr0, edx
|
||||
|
||||
; copy
|
||||
mov edx, 1024
|
||||
|
||||
.loop:
|
||||
mov eax, [ebx]
|
||||
mov [ecx], eax
|
||||
add ebx, 4
|
||||
add ecx, 4
|
||||
dec edx
|
||||
jnz .loop
|
||||
|
||||
; reenable paging
|
||||
mov edx, cr0
|
||||
or edx, 0x80000000
|
||||
mov cr0, edx
|
||||
|
||||
; return
|
||||
popf
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
|
||||
global TaskingReadEip
|
||||
TaskingReadEip:
|
||||
pop eax
|
||||
jmp eax
|
||||
|
@ -1,107 +1,141 @@
|
||||
/*
|
||||
* tasking-multi.c
|
||||
*
|
||||
* Created on: Sep 8, 2011
|
||||
* Created on: Sep 7, 2011
|
||||
* Author: Tiberiu
|
||||
*/
|
||||
|
||||
#include <tasking.h>
|
||||
#include <memory-add.h>
|
||||
#include <debugio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Task* TaskList;
|
||||
Task* CurrentTask;
|
||||
uint32 NextPid = 1;
|
||||
volatile Task *CurrentTask;
|
||||
volatile Task *TaskQueue;
|
||||
volatile uint32 NextPid = 1;
|
||||
|
||||
void TaskSwitch (_RegsStack32* regs)
|
||||
void TaskingInitialize()
|
||||
{
|
||||
MagicBreakpoint();
|
||||
// Stop interrupts
|
||||
asm volatile ("cli");
|
||||
|
||||
if (!TaskList) return;
|
||||
// Relocate stack
|
||||
TaskingMoveStack(0xE0000000, 0x4000);
|
||||
|
||||
uint32 eip = TaskReadEip();
|
||||
if (eip == 0xABCDEF) return;
|
||||
// Set up first task (kernel)
|
||||
CurrentTask = TaskQueue = (Task*) kmalloc(sizeof(Task));
|
||||
CurrentTask->Pid = NextPid ++;
|
||||
CurrentTask->Esp = CurrentTask->Ebp = CurrentTask->Eip = 0;
|
||||
CurrentTask->Pd = CurrentDirectory;
|
||||
CurrentTask->Next = NULL;
|
||||
|
||||
// Save context
|
||||
asm volatile ("mov %%esp, %0" : "=r"(CurrentTask->Esp));
|
||||
asm volatile ("mov %%ebp, %0" : "=r"(CurrentTask->Ebp));
|
||||
CurrentTask->Eip = eip;
|
||||
// Reenable interrupts
|
||||
asm volatile ("sti");
|
||||
|
||||
// Next task
|
||||
CurrentTask = (!CurrentTask->Next) ? TaskList : CurrentTask->Next ;
|
||||
|
||||
// Switch context
|
||||
PagingSwitchDirectory(CurrentTask->Pd);
|
||||
|
||||
// Prepare for jump
|
||||
asm volatile (""
|
||||
"mov %0, %%ebp; "
|
||||
"mov %1, %%esp; "
|
||||
"mov %2, %%ecx; "
|
||||
"mov $0xABCDEF, %%eax; "
|
||||
"jmp *%%ecx; "
|
||||
: : "r"(CurrentTask->Ebp), "r"(CurrentTask->Esp), "r"(CurrentTask->Eip)
|
||||
: "eax", "ecx");
|
||||
Log("Tasking", "Initialized, currenttask: pid=%u esp=%x ebp=%x eip=%x Pd=%x Next=%x\n", CurrentTask->Pid,
|
||||
CurrentTask->Esp, CurrentTask->Ebp, CurrentTask->Eip, CurrentTask->Pd, CurrentTask->Next);
|
||||
}
|
||||
|
||||
// Fallback for new tasks
|
||||
void TaskEnd ()
|
||||
int32 Fork()
|
||||
{
|
||||
// Find parent of current task
|
||||
if (CurrentTask->Pid == TaskList->Pid) TaskList = TaskList->Next;
|
||||
asm volatile ("cli");
|
||||
|
||||
else {
|
||||
Task* t = TaskList;
|
||||
while (t->Next && t->Next->Pid != CurrentTask->Pid) t = t->Next;
|
||||
Task* Parent = (Task*) CurrentTask;
|
||||
PageDirectory* Dir = PagingCloneDirectory(CurrentDirectory);
|
||||
|
||||
t->Next = CurrentTask->Next;
|
||||
// Create a new process
|
||||
Task* n = (Task*)kmalloc(sizeof(Task));
|
||||
n->Pid = NextPid++;
|
||||
n->Esp = n->Ebp = 0;
|
||||
n->Eip = 0;
|
||||
n->Pd = Dir;
|
||||
n->Next = 0;
|
||||
|
||||
// Add it at the end of the queue
|
||||
Task* temp = (Task*) TaskQueue;
|
||||
while (temp->Next) temp = temp->Next; // Find end of queue
|
||||
temp->Next = n; // Add it
|
||||
|
||||
// Read eip
|
||||
uint32 eip = TaskingReadEip();
|
||||
|
||||
// We could be the parent
|
||||
if (CurrentTask == Parent)
|
||||
{
|
||||
uint32 esp, ebp;
|
||||
asm volatile ("mov %%esp, %0" : "=r"(esp));
|
||||
asm volatile ("mov %%ebp, %0" : "=r"(ebp));
|
||||
n->Esp = esp;
|
||||
n->Ebp = ebp;
|
||||
n->Eip = eip;
|
||||
|
||||
asm volatile ("sti");
|
||||
return n->Pid;
|
||||
}
|
||||
|
||||
// Free allocated space
|
||||
kfree((void*)CurrentTask->StackLowerBase);
|
||||
kfree(CurrentTask);
|
||||
|
||||
// Wait for next task
|
||||
for (;;) ;
|
||||
// Or the child
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void TaskCreate (void (*func)())
|
||||
void TaskingScheduler()
|
||||
{
|
||||
// Create a new task
|
||||
Task* t = kmalloc(sizeof(Task));
|
||||
|
||||
// Set up data
|
||||
t->StackLowerBase = (uint32) kmalloc(0x1000); // Allocate some space for new stack
|
||||
t->StackUpperBase = t->StackLowerBase + 0x1000;
|
||||
t->Next = NULL;
|
||||
t->Pd = KernelDirectory;
|
||||
t->Pid = NextPid++;
|
||||
|
||||
// Set up stack
|
||||
/*memset(&t->Regs, 0, sizeof(_RegsStack32));
|
||||
t->Regs.ebp = t->StackUpperBase;
|
||||
t->Regs.esp = (t->StackUpperBase - 0x4 - sizeof(_RegsStack32));
|
||||
t->Regs.useresp = t->StackUpperBase - 0x4;
|
||||
t->Regs.eip = (uint32) func;
|
||||
*(uint32 *) (t->Regs.esp) = (uint32) TaskEnd; // Fallback function
|
||||
t->Initialized = 0;
|
||||
|
||||
// Read eflags
|
||||
asm volatile ("pushf; pop %0" : "=r"(t->Regs.eflags));*/
|
||||
|
||||
// Add the task to the list
|
||||
Task* last = TaskList;
|
||||
while (last && last->Next) last = last->Next;
|
||||
if (last) last->Next = t;
|
||||
// For now, just switch tasks
|
||||
TaskingSwitch();
|
||||
}
|
||||
|
||||
void TaskInitialize()
|
||||
void Func()
|
||||
{
|
||||
Task* t = kmalloc(sizeof(Task));
|
||||
|
||||
t->Pid = NextPid++;
|
||||
t->Pd = KernelDirectory;
|
||||
t->Next = NULL;
|
||||
|
||||
TaskList = CurrentTask = t;
|
||||
}
|
||||
|
||||
void TaskingSwitch()
|
||||
{
|
||||
// Make sure tasking is initialized, or there are at least 2 processes running
|
||||
if (!CurrentTask) return;
|
||||
|
||||
// Save esp & epb
|
||||
uint32 esp, ebp, eip;
|
||||
asm volatile("mov %%esp, %0" : "=r"(esp));
|
||||
asm volatile("mov %%ebp, %0" : "=r"(ebp));
|
||||
eip = TaskingReadEip();
|
||||
|
||||
// Have we just switched tasks?
|
||||
if (eip == 0xABCDE) return;
|
||||
|
||||
// No? Switch
|
||||
// Save stack address and current instruction pointer
|
||||
CurrentTask->Eip = eip;
|
||||
CurrentTask->Esp = esp;
|
||||
CurrentTask->Ebp = ebp;
|
||||
|
||||
//Log("Tasking", "Saved eip=%x esp=%x ebp=%x\n", eip, esp, ebp);
|
||||
|
||||
CurrentTask = CurrentTask ->Next; // Switch task
|
||||
if (!CurrentTask) CurrentTask = TaskQueue; // End of queue? Start over
|
||||
|
||||
// Read registers
|
||||
eip = CurrentTask->Eip;
|
||||
esp = CurrentTask->Esp;
|
||||
ebp = CurrentTask->Ebp;
|
||||
|
||||
//Log("Tasking", "Loaded eip=%x esp=%x ebp=%x", eip, esp, ebp);
|
||||
|
||||
CurrentDirectory = CurrentTask->Pd;
|
||||
MagicBreakpoint();
|
||||
|
||||
// Put data in registers
|
||||
asm volatile (" "
|
||||
"cli;"
|
||||
"mov %0, %%ecx;"
|
||||
"mov %1, %%esp;"
|
||||
"mov %2, %%ebp;"
|
||||
"mov %3, %%cr3;"
|
||||
"mov $0xABCDE, %%eax;"
|
||||
"sti;"
|
||||
"jmp *%%ecx"
|
||||
: : "r"(eip), "r"(esp), "r"(ebp), "r"(CurrentDirectory->PhysicalAddr));
|
||||
}
|
||||
|
||||
int32 GetPid()
|
||||
{
|
||||
return CurrentTask->Pid;
|
||||
}
|
||||
|
51
Kernel/tasking/tasking-stack.c
Normal file
51
Kernel/tasking/tasking-stack.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* tasking-stack.c
|
||||
*
|
||||
* Created on: Sep 7, 2011
|
||||
* Author: Tiberiu
|
||||
*/
|
||||
|
||||
#include <memory-add.h>
|
||||
uint32 InitialStack;
|
||||
|
||||
void TaskingSetInitialStack(uint32 addr)
|
||||
{
|
||||
InitialStack = addr;
|
||||
}
|
||||
|
||||
void TaskingMoveStack (uint32 newstart, uint32 size)
|
||||
{
|
||||
|
||||
uint32 i;
|
||||
for (i = newstart; i >= newstart-size; i-= 0x1000)
|
||||
MemPhAllocFrame(PagingGetPage(i, 1, CurrentDirectory), 0, 1);
|
||||
|
||||
// Flush TLB by rewriting cr3
|
||||
uint32 t;
|
||||
asm volatile ("mov %%cr3, %0" : "=r" (t));
|
||||
asm volatile ("mov %0, %%cr3" : : "r" (t));
|
||||
|
||||
// Read old esp, ebp regs
|
||||
uint32 oldStackPointer, oldBasePointer;
|
||||
asm volatile ("mov %%esp, %0" : "=r"(oldStackPointer));
|
||||
asm volatile ("mov %%ebp, %0" : "=r"(oldBasePointer));
|
||||
|
||||
uint32 offset = newstart - InitialStack;
|
||||
uint32 newStackPointer = oldStackPointer + offset;
|
||||
uint32 newBasePointer = oldBasePointer + offset;
|
||||
|
||||
// Copy stack content
|
||||
memcpy((void*)newStackPointer, (void*)oldStackPointer, InitialStack-oldStackPointer);
|
||||
|
||||
// (Attempt to) change EBP addresses in new stack
|
||||
for (i = newstart; i > newstart - size; i-=4)
|
||||
{
|
||||
uint32 *temp = (uint32*)i;
|
||||
if (oldStackPointer < *temp && *temp < InitialStack)
|
||||
*temp += offset;
|
||||
}
|
||||
|
||||
// Set stack pointers to new stack
|
||||
asm volatile ("mov %0, %%esp" : : "r" (newStackPointer));
|
||||
asm volatile ("mov %0, %%ebp" : : "r" (newBasePointer));
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
CREATE "filename" ; creates a new ramdisk with the filename
|
||||
MKDIR "name" ; creates a new directory (in current dir)
|
||||
CD "\path" ; sets current directory, where \ is root
|
||||
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
|
||||
|
@ -1,133 +0,0 @@
|
||||
#
|
||||
# Generated Makefile - do not edit!
|
||||
#
|
||||
# Edit the Makefile in the project folder instead (../Makefile). Each target
|
||||
# has a pre- and a post- target defined where you can add customization code.
|
||||
#
|
||||
# This makefile implements macros and targets common to all configurations.
|
||||
#
|
||||
# NOCDDL
|
||||
|
||||
|
||||
# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
|
||||
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
|
||||
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
|
||||
# and .clean-reqprojects-conf unless SUB has the value 'no'
|
||||
SUB_no=NO
|
||||
SUBPROJECTS=${SUB_${SUB}}
|
||||
BUILD_SUBPROJECTS_=.build-subprojects
|
||||
BUILD_SUBPROJECTS_NO=
|
||||
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
|
||||
CLEAN_SUBPROJECTS_=.clean-subprojects
|
||||
CLEAN_SUBPROJECTS_NO=
|
||||
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
|
||||
|
||||
|
||||
# Project Name
|
||||
PROJECTNAME=RamdiskWriter
|
||||
|
||||
# Active Configuration
|
||||
DEFAULTCONF=Debug
|
||||
CONF=${DEFAULTCONF}
|
||||
|
||||
# All Configurations
|
||||
ALLCONFS=Debug Release
|
||||
|
||||
|
||||
# build
|
||||
.build-impl: .build-pre .validate-impl .depcheck-impl
|
||||
@#echo "=> Running $@... Configuration=$(CONF)"
|
||||
"${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf
|
||||
|
||||
|
||||
# clean
|
||||
.clean-impl: .clean-pre .validate-impl .depcheck-impl
|
||||
@#echo "=> Running $@... Configuration=$(CONF)"
|
||||
"${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf
|
||||
|
||||
|
||||
# clobber
|
||||
.clobber-impl: .clobber-pre .depcheck-impl
|
||||
@#echo "=> Running $@..."
|
||||
for CONF in ${ALLCONFS}; \
|
||||
do \
|
||||
"${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
|
||||
done
|
||||
|
||||
# all
|
||||
.all-impl: .all-pre .depcheck-impl
|
||||
@#echo "=> Running $@..."
|
||||
for CONF in ${ALLCONFS}; \
|
||||
do \
|
||||
"${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \
|
||||
done
|
||||
|
||||
# build tests
|
||||
.build-tests-impl: .build-impl .build-tests-pre
|
||||
@#echo "=> Running $@... Configuration=$(CONF)"
|
||||
"${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf
|
||||
|
||||
# run tests
|
||||
.test-impl: .build-tests-impl .test-pre
|
||||
@#echo "=> Running $@... Configuration=$(CONF)"
|
||||
"${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf
|
||||
|
||||
# dependency checking support
|
||||
.depcheck-impl:
|
||||
@echo "# This code depends on make tool being used" >.dep.inc
|
||||
@if [ -n "${MAKE_VERSION}" ]; then \
|
||||
echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
|
||||
echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
|
||||
echo "include \$${DEPFILES}" >>.dep.inc; \
|
||||
echo "endif" >>.dep.inc; \
|
||||
else \
|
||||
echo ".KEEP_STATE:" >>.dep.inc; \
|
||||
echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
|
||||
fi
|
||||
|
||||
# configuration validation
|
||||
.validate-impl:
|
||||
@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
|
||||
then \
|
||||
echo ""; \
|
||||
echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
|
||||
echo "See 'make help' for details."; \
|
||||
echo "Current directory: " `pwd`; \
|
||||
echo ""; \
|
||||
fi
|
||||
@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
|
||||
then \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
# help
|
||||
.help-impl: .help-pre
|
||||
@echo "This makefile supports the following configurations:"
|
||||
@echo " ${ALLCONFS}"
|
||||
@echo ""
|
||||
@echo "and the following targets:"
|
||||
@echo " build (default target)"
|
||||
@echo " clean"
|
||||
@echo " clobber"
|
||||
@echo " all"
|
||||
@echo " help"
|
||||
@echo ""
|
||||
@echo "Makefile Usage:"
|
||||
@echo " make [CONF=<CONFIGURATION>] [SUB=no] build"
|
||||
@echo " make [CONF=<CONFIGURATION>] [SUB=no] clean"
|
||||
@echo " make [SUB=no] clobber"
|
||||
@echo " make [SUB=no] all"
|
||||
@echo " make help"
|
||||
@echo ""
|
||||
@echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
|
||||
@echo " also build subprojects."
|
||||
@echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
|
||||
@echo " also clean subprojects."
|
||||
@echo "Target 'clobber' will remove all built files from all configurations and,"
|
||||
@echo " unless 'SUB=no', also from subprojects."
|
||||
@echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
|
||||
@echo " also build subprojects."
|
||||
@echo "Target 'help' prints this message."
|
||||
@echo ""
|
||||
|
@ -1,7 +0,0 @@
|
||||
Exception: STATUS_ACCESS_VIOLATION at eip=6102048B
|
||||
eax=00925C98 ebx=61243754 ecx=75907BBE edx=002F51F8 esi=00000000 edi=0022FA10
|
||||
ebp=61020C00 esp=0022C7E0 program=C:\cygwin\bin\bash.exe, pid 2900, thread main
|
||||
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
|
||||
Stack trace:
|
||||
Frame Function Args
|
||||
End of stack trace
|
@ -30,13 +30,13 @@
|
||||
00000000000i[ ] SB16 support: yes
|
||||
00000000000i[ ] USB support: yes
|
||||
00000000000i[ ] VGA extension support: vbe cirrus
|
||||
00000000000i[MEM0 ] allocated memory at 03C60020. after alignment, vector=03C61000
|
||||
00000000000i[MEM0 ] allocated memory at 04310020. after alignment, vector=04311000
|
||||
00000000000i[MEM0 ] 32.00MB
|
||||
00000000000i[MEM0 ] mem block size = 0x00100000, blocks=32
|
||||
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('C:\Program Files\Bochs-2.4.6\BIOS-bochs-latest')
|
||||
00000000000i[MEM0 ] rom at 0xc0000/40448 ('C:\Program Files\Bochs-2.4.6\VGABIOS-lgpl-latest')
|
||||
00000000000i[CMOS ] Using local time for initial clock
|
||||
00000000000i[CMOS ] Setting initial clock to: Tue Sep 20 12:05:43 2011 (time0=1316509543)
|
||||
00000000000i[CMOS ] Setting initial clock to: Wed Sep 07 15:36:29 2011 (time0=1315398989)
|
||||
00000000000i[DMA ] channel 4 used by cascade
|
||||
00000000000i[DMA ] channel 2 used by Floppy Drive
|
||||
00000000000i[FDD ] fd0: 'a:' ro=0, h=2,t=80,spt=18
|
||||
@ -160,40 +160,65 @@
|
||||
00023137418i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
|
||||
00023142199i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
|
||||
00023146850i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
|
||||
00044035593i[CPU0 ] [44035593] Stopped on MAGIC BREAKPOINT
|
||||
00044142237i[CPU0 ] [44142237] Stopped on MAGIC BREAKPOINT
|
||||
00044779187i[KBD ] setting typematic info
|
||||
00044779205i[KBD ] setting delay to 500 mS (unused)
|
||||
00044779205i[KBD ] setting repeat rate to 10.9 cps (unused)
|
||||
00044779248i[KBD ] Switched to scancode set 2
|
||||
00044779311i[KBD ] keyboard: scan convert turned off
|
||||
00044838196i[CPU0 ] [44838196] Stopped on MAGIC BREAKPOINT
|
||||
00044838228i[ ] dbg: Quit
|
||||
00044838228i[CPU0 ] CPU is in protected mode (active)
|
||||
00044838228i[CPU0 ] CS.d_b = 32 bit
|
||||
00044838228i[CPU0 ] SS.d_b = 32 bit
|
||||
00044838228i[CPU0 ] EFER = 0x00000000
|
||||
00044838228i[CPU0 ] | RAX=0000000000108f18 RBX=0000000000000064
|
||||
00044838228i[CPU0 ] | RCX=0000000000111720 RDX=0000000000000014
|
||||
00044838228i[CPU0 ] | RSP=0000000000111720 RBP=0000000000000014
|
||||
00044838228i[CPU0 ] | RSI=0000000000111806 RDI=0000000000000002
|
||||
00044838228i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
|
||||
00044838228i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
|
||||
00044838228i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
|
||||
00044838228i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
|
||||
00044838228i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf
|
||||
00044838228i[CPU0 ] | SEG selector base limit G D
|
||||
00044838228i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
|
||||
00044838228i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044838228i[CPU0 ] | MSR_FS_BASE:0000000000000000
|
||||
00044838228i[CPU0 ] | MSR_GS_BASE:0000000000000000
|
||||
00044838228i[CPU0 ] | RIP=0000000000108f60 (0000000000108f60)
|
||||
00044838228i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000000000000
|
||||
00044838228i[CPU0 ] | CR3=0x0011b000 CR4=0x00000000
|
||||
00044838228i[CMOS ] Last time is 1316509554 (Tue Sep 20 12:05:54 2011)
|
||||
00044838228i[CTRL ] quit_sim called with exit code 0
|
||||
00044037091i[CPU0 ] [44037091] Stopped on MAGIC BREAKPOINT
|
||||
00044377981i[CPU0 ] [44377981] Stopped on MAGIC BREAKPOINT
|
||||
00044972707e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
|
||||
00044972707e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
|
||||
00044972707e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
|
||||
00044972707i[CPU0 ] CPU is in protected mode (active)
|
||||
00044972707i[CPU0 ] CS.d_b = 32 bit
|
||||
00044972707i[CPU0 ] SS.d_b = 32 bit
|
||||
00044972707i[CPU0 ] EFER = 0x00000000
|
||||
00044972707i[CPU0 ] | RAX=00000000c008000c RBX=00000000001195ee
|
||||
00044972707i[CPU0 ] | RCX=000000000000006d RDX=000000000011f000
|
||||
00044972707i[CPU0 ] | RSP=00000000dfffff98 RBP=0000000000067ec4
|
||||
00044972707i[CPU0 ] | RSI=000000000002bd20 RDI=0000000000000000
|
||||
00044972707i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
|
||||
00044972707i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
|
||||
00044972707i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
|
||||
00044972707i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
|
||||
00044972707i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf af pf cf
|
||||
00044972707i[CPU0 ] | SEG selector base limit G D
|
||||
00044972707i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
|
||||
00044972707i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
|
||||
00044972707i[CPU0 ] | MSR_FS_BASE:0000000000000000
|
||||
00044972707i[CPU0 ] | MSR_GS_BASE:0000000000000000
|
||||
00044972707i[CPU0 ] | RIP=00000000001091e2 (00000000001091e2)
|
||||
00044972707i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000000000000
|
||||
00044972707i[CPU0 ] | CR3=0x00120000 CR4=0x00000000
|
||||
00044972707e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
|
||||
00044972707i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
|
||||
00044972707i[CPU0 ] cpu hardware reset
|
||||
00044972707i[APIC0] allocate APIC id=0 (MMIO enabled) to 0x00000000fee00000
|
||||
00044972707i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
|
||||
00044972707i[CPU0 ] CPUID[0x00000001]: 00000f23 00000800 00002000 07cbfbff
|
||||
00044972707i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x00000007]: 00000000 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000001 2a100800
|
||||
00044972707i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
|
||||
00044972707i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
|
||||
00044972707i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
|
||||
00044972707i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
|
||||
00044972707i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
|
||||
00044972707i[ ] reset of 'unmapped' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'biosdev' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'speaker' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'extfpuirq' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'gameport' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'iodebug' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'pci_ide' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'acpi' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'ioapic' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'keyboard' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'harddrv' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'serial' plugin device by virtual method
|
||||
00044972707i[ ] reset of 'parallel' plugin device by virtual method
|
||||
|
10672
bochs/dump.txt
10672
bochs/dump.txt
File diff suppressed because it is too large
Load Diff
BIN
build/clock.o
BIN
build/clock.o
Binary file not shown.
BIN
build/console.o
BIN
build/console.o
Binary file not shown.
BIN
build/crash.o
Normal file
BIN
build/crash.o
Normal file
Binary file not shown.
BIN
build/hal.o
BIN
build/hal.o
Binary file not shown.
BIN
build/initrd.o
BIN
build/initrd.o
Binary file not shown.
BIN
build/keyboard.o
Normal file
BIN
build/keyboard.o
Normal file
Binary file not shown.
BIN
build/logger.o
BIN
build/logger.o
Binary file not shown.
BIN
build/mem-heap.o
BIN
build/mem-heap.o
Binary file not shown.
Binary file not shown.
BIN
build/mem-phys.o
BIN
build/mem-phys.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/tasking-stack.o
Normal file
BIN
build/tasking-stack.o
Normal file
Binary file not shown.
11
change.log
11
change.log
@ -1,16 +1,7 @@
|
||||
[????] BUILD 0.1.1.50 DATE 9/20/2011 AT 12:43 PM
|
||||
[????] BUILD 0.1.1.??? DATE 9/0?/2011 AT ?:?? ??
|
||||
====================================================
|
||||
Mainly changed: Tasking
|
||||
+ Implemented multitasking
|
||||
+ Switching works
|
||||
? TODO: Fix other not working tasking routines
|
||||
|
||||
[GOOD] BUILD 0.1.0.629 DATE 9/08/2011 AT 5:20 PM
|
||||
====================================================
|
||||
Mainly changed: Memory manager
|
||||
+ Rewritten virtual memory manager (easier to understand now :D)
|
||||
+ Updated physical memory manager
|
||||
+ Other minor bug fixes
|
||||
|
||||
[GOOD] BUILD 0.1.0.601 DATE 9/06/2011 AT 5:20 PM
|
||||
====================================================
|
||||
|
166
exp/video.cpp
166
exp/video.cpp
@ -1,166 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <dos.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned uint16;
|
||||
typedef unsigned long uint32;
|
||||
|
||||
struct vbeInfo {
|
||||
char Signature[4];
|
||||
uint16 Version;
|
||||
uint32 OemString;
|
||||
uint8 Capabilities[4];
|
||||
uint32 VideoModes;
|
||||
uint16 TotalMem;
|
||||
};
|
||||
|
||||
struct modeInfo {
|
||||
uint16 attributes;
|
||||
uint8 winA,winB;
|
||||
uint16 granularity;
|
||||
uint16 winsize;
|
||||
uint16 segmentA, segmentB;
|
||||
uint32 realFctPtr;
|
||||
uint16 pitch; // uint8s per scanline
|
||||
|
||||
uint16 Xres, Yres;
|
||||
uint8 Wchar, Ychar, planes, bpp, banks;
|
||||
uint8 memory_model, bank_size, image_pages;
|
||||
uint8 reserved0;
|
||||
|
||||
uint8 red_mask, red_position;
|
||||
uint8 green_mask, green_position;
|
||||
uint8 blue_mask, blue_position;
|
||||
uint8 rsv_mask, rsv_position;
|
||||
uint8 directcolor_attributes;
|
||||
|
||||
uint32 physbase; // your LFB address ;)
|
||||
uint32 reserved1;
|
||||
uint16 reserved2;
|
||||
};
|
||||
|
||||
uint16 GetInfo (vbeInfo far* info)
|
||||
{
|
||||
REGS regs;
|
||||
SREGS segregs;
|
||||
|
||||
regs.x.ax = 0x4f00;
|
||||
regs.x.di = FP_OFF(info);
|
||||
segregs.es = FP_SEG(info);
|
||||
int86x(0x10, ®s, ®s, &segregs);
|
||||
|
||||
return regs.x.ax;
|
||||
}
|
||||
|
||||
uint16 GetModeInfo (modeInfo far* info, uint16 mode)
|
||||
{
|
||||
REGS regs;
|
||||
SREGS segregs;
|
||||
|
||||
regs.x.ax = 0x4f01;
|
||||
regs.x.cx = mode;
|
||||
regs.x.di = FP_OFF(info);
|
||||
segregs.es = FP_SEG(info);
|
||||
int86x(0x10, ®s, ®s, &segregs);
|
||||
|
||||
return regs.x.ax;
|
||||
}
|
||||
|
||||
void SetMode (uint16 mode)
|
||||
{
|
||||
REGS regs;
|
||||
|
||||
regs.x.ax = 0x4F02;
|
||||
regs.x.bx = mode;
|
||||
int86(0x10, ®s, ®s);
|
||||
}
|
||||
|
||||
uint16 bank_current = 0xffff;
|
||||
void SwitchBank (uint16 bank)
|
||||
{
|
||||
if (bank == bank_current) return;
|
||||
|
||||
REGS regs;
|
||||
regs.x.ax = 0x4F05;
|
||||
regs.x.bx = 0;
|
||||
regs.x.dx = bank;
|
||||
int86(0x10, ®s, ®s);
|
||||
|
||||
bank_current = bank;
|
||||
}
|
||||
|
||||
modeInfo* CurrentMode;
|
||||
|
||||
void PutPixel (int x, int y, uint16 color)
|
||||
{
|
||||
unsigned address = (y * CurrentMode->Xres) + x;
|
||||
unsigned bank_size = CurrentMode->granularity * 1024;
|
||||
unsigned bank_number = address / bank_size;
|
||||
unsigned bank_offset = address % bank_size;
|
||||
|
||||
SwitchBank (bank_number);
|
||||
|
||||
uint16 far* ptr = (uint16 far*) (bank_offset + 0xA0000l);
|
||||
*ptr = color;
|
||||
}
|
||||
|
||||
void SetBestMode (uint16 X, uint16 Y, uint8 bpp)
|
||||
{
|
||||
vbeInfo* info = (vbeInfo*) malloc (sizeof(vbeInfo) * 2);
|
||||
modeInfo* modeinf = (modeInfo*) malloc (sizeof(modeInfo) * 4);
|
||||
|
||||
strncpy(info->Signature, "VBE2", 4);
|
||||
|
||||
if (GetInfo(info) != 0x4F) {
|
||||
printf("Error\n"); return;
|
||||
}
|
||||
|
||||
uint16 far* modes = (uint16 far*) info->VideoModes;
|
||||
uint16 best = 0x13;
|
||||
uint16 bestpixdiff = (320 * 200) - (X * Y);
|
||||
uint16 bestdppdiff = 8 >= bpp ? 8 - bpp : (bpp - 8) * 2;
|
||||
|
||||
for (int i = 0; modes[i] != 0xFFFF; i++)
|
||||
{
|
||||
if (GetModeInfo(modeinf, modes[i]) != 0x4F) continue;
|
||||
if ((modeinf->attributes & 0x90) != 0x90) continue;
|
||||
if (modeinf->memory_model != 4 && modeinf->memory_model != 6) continue;
|
||||
|
||||
if (X == modeinf->Xres && Y == modeinf->Yres && bpp == modeinf->bpp) {
|
||||
best = modes[i]; break;
|
||||
}
|
||||
|
||||
uint16 pixdiff = (modeinf->Xres * modeinf->Yres) - (X*Y);
|
||||
uint16 dppdiff = (modeinf->bpp >= bpp) ? (modeinf->bpp - bpp) : (bpp - modeinf->bpp);
|
||||
if ( bestpixdiff > pixdiff || (bestpixdiff == pixdiff && bestdppdiff > dppdiff) )
|
||||
{
|
||||
best = modes[i];
|
||||
bestpixdiff = pixdiff;
|
||||
bestdppdiff = dppdiff;
|
||||
}
|
||||
}
|
||||
|
||||
CurrentMode = modeinf;
|
||||
GetModeInfo(CurrentMode, best);
|
||||
printf("Best mode found: %ux%u %ubpp\n", CurrentMode->Xres, CurrentMode->Yres, CurrentMode->bpp);
|
||||
|
||||
// Set mode
|
||||
SetMode (best);
|
||||
|
||||
free (info);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
SetBestMode(800, 600, 15);
|
||||
|
||||
for (int i = 0; i < 700; i++)
|
||||
for (int j = 0; j < 500; j++)
|
||||
PutPixel (i, j, 0x7FFF - i - j);
|
||||
|
||||
free (CurrentMode);
|
||||
return 0;
|
||||
}
|
@ -13,6 +13,5 @@ Kernel/hal/cpu/isrs-asm.asm
|
||||
HAL :: Interrupt Requests assembly module
|
||||
Kernel/hal/cpu/irq-asm.asm
|
||||
|
||||
Tasking :: Assembly module
|
||||
Tasking :: Tasking assembly module
|
||||
Kernel/tasking/tasking-asm.asm
|
||||
|
||||
|
@ -133,6 +133,9 @@ Kernel/memory/mem-phys.c
|
||||
Memory Manager :: Paging
|
||||
Kernel/memory/mem-paging.c
|
||||
|
||||
Tasking :: Stack move
|
||||
Kernel/tasking/tasking-stack.c
|
||||
|
||||
Tasking :: Multitasking
|
||||
Kernel/tasking/tasking-multi.c
|
||||
|
||||
|
BIN
kernel.bin
BIN
kernel.bin
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
@echo off
|
||||
|
||||
E:
|
||||
chdir E:\Software\OsDev
|
||||
C:
|
||||
chdir C:\Dev\lux
|
||||
set CYGWIN=nodosfilewarning
|
||||
|
||||
bash /cygdrive/e/Software/OsDev/lux/build.sh
|
||||
C:\cygwin\bin\bash /cygdrive/c/Dev/lux/build.sh
|
||||
|
@ -1,6 +1,6 @@
|
||||
@echo off
|
||||
|
||||
E:
|
||||
chdir E:\Software\OsDev\lux
|
||||
C:
|
||||
chdir C:\Dev\lux
|
||||
|
||||
bash /cygdrive/e/Software/OsDev/lux/scripts/pack.sh
|
||||
C:\cygwin\bin\bash /cygdrive/c/Dev/lux/scripts/pack.sh
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd /cygdrive/e/Software/OsDev
|
||||
cd /cygdrive/c/Dev
|
||||
|
||||
# Get version number
|
||||
read version < ./lux/Kernel/include/version.h
|
||||
|
@ -1 +1 @@
|
||||
50
|
||||
48
|
||||
|
Loading…
Reference in New Issue
Block a user