Skip to content

Commit

Permalink
another strike in the war on void*
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfwood committed Aug 13, 2011
1 parent dbdcc71 commit 7a05d20
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 42 deletions.
3 changes: 1 addition & 2 deletions kernel/arch/x86_64/architecture/cpu.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -677,8 +677,7 @@ private:
// Will create and install a new kernel stack // Will create and install a new kernel stack
// Note: You have to preserve the current stack // Note: You have to preserve the current stack
ErrorVal installStack() { ErrorVal installStack() {
ubyte* stackSpace = cast(ubyte*)PageAllocator.allocPage(); ubyte* stackSpace = VirtualMemory.mapStack(PageAllocator.allocPage());
stackSpace = cast(ubyte*)VirtualMemory.mapStack(stackSpace);
ubyte* currentStack = cast(ubyte*)(&_stack-4096); ubyte* currentStack = cast(ubyte*)(&_stack-4096);


stackSpace[0..4096] = currentStack[0..4096]; stackSpace[0..4096] = currentStack[0..4096];
Expand Down
2 changes: 1 addition & 1 deletion kernel/arch/x86_64/architecture/main.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public:
ErrorVal initialize() { ErrorVal initialize() {
// Reading from the linker script // Reading from the linker script
// We want the length of the kernel module // We want the length of the kernel module
System.kernel.start = cast(ubyte*)0x0; System.kernel.start = null;
System.kernel.length = LinkerScript.ekernel - LinkerScript.kernelVMA; System.kernel.length = LinkerScript.ekernel - LinkerScript.kernelVMA;
System.kernel.virtualStart = cast(ubyte*)LinkerScript.kernelVMA; System.kernel.virtualStart = cast(ubyte*)LinkerScript.kernelVMA;


Expand Down
2 changes: 1 addition & 1 deletion kernel/arch/x86_64/architecture/syscall.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static:
Cpu.writeMSR(SFMASK_MSR, 0); Cpu.writeMSR(SFMASK_MSR, 0);


// stash a syscall stack in GS.Base // stash a syscall stack in GS.Base
void* stackPtr = PageAllocator.allocPage(); PhysicalAddress stackPtr = PageAllocator.allocPage();
ulong syscallStack = cast(ulong)VirtualMemory.mapStack(stackPtr) + 4096; ulong syscallStack = cast(ulong)VirtualMemory.mapStack(stackPtr) + 4096;


asm{ asm{
Expand Down
16 changes: 8 additions & 8 deletions kernel/arch/x86_64/architecture/vm.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,24 +116,24 @@ public:
return Paging.PAGESIZE; return Paging.PAGESIZE;
} }


synchronized void* mapStack(void* physAddr) { synchronized ubyte* mapStack(PhysicalAddress physAddr) {
if(stackSegment is null){ if(stackSegment is null){
stackSegment = findFreeSegment().ptr; stackSegment = findFreeSegment().ptr;
createSegment(stackSegment, oneGB, AccessMode.Writable|AccessMode.AllocOnAccess); createSegment(stackSegment, oneGB, AccessMode.Writable|AccessMode.AllocOnAccess);
} }


stackSegment += Paging.PAGESIZE; stackSegment += Paging.PAGESIZE;


if(Paging.mapRegion(stackSegment, physAddr, Paging.PAGESIZE) == ErrorVal.Fail){ return Paging.mapRegion(stackSegment, physAddr, Paging.PAGESIZE).ptr;
return null;
}else{
return stackSegment;
}
} }


// --- OLD --- // // --- OLD --- //
synchronized ErrorVal mapRegion(void* gib, void* physAddr, ulong regionLength) { synchronized ErrorVal mapRegion(ubyte* gib, PhysicalAddress physAddr, ulong regionLength) {
return Paging.mapRegion(gib, physAddr, regionLength); if(Paging.mapRegion(gib, physAddr, regionLength) !is null){
return ErrorVal.Fail;
}

return ErrorVal.Success;
} }


private: private:
Expand Down
6 changes: 4 additions & 2 deletions kernel/arch/x86_64/core/gdt.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ static:
} }


ErrorVal install() { ErrorVal install() {
PhysicalAddress gdtPage = PageAllocator.allocPage();

// Create a new GDT structure // Create a new GDT structure
GlobalDescriptorTable* gdt = cast(GlobalDescriptorTable*)PageAllocator.allocPage(); GlobalDescriptorTable* gdt = cast(GlobalDescriptorTable*)gdtPage;
gdt = cast(GlobalDescriptorTable*)Paging.mapRegion(cast(ubyte*)gdt, VirtualMemory.pagesize); gdt = cast(GlobalDescriptorTable*)Paging.mapRegion(gdtPage, VirtualMemory.pagesize);
*gdt = GlobalDescriptorTable.init; *gdt = GlobalDescriptorTable.init;
tables[Cpu.identifier] = gdt; tables[Cpu.identifier] = gdt;
initializeTable(Cpu.identifier); initializeTable(Cpu.identifier);
Expand Down
9 changes: 6 additions & 3 deletions kernel/arch/x86_64/core/info.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


module kernel.arch.x86_64.core.info; module kernel.arch.x86_64.core.info;


import user.types;


struct Info { struct Info {
static: static:
public: public:
Expand Down Expand Up @@ -68,8 +71,8 @@ public:
// Whether or not this IO APIC is enabled // Whether or not this IO APIC is enabled
bool enabled; bool enabled;


// Virtual address of the IO APIC register // address of the IO APIC register
void* address; PhysicalAddress address;
} }


IOAPICInfo[16] IOAPICs; IOAPICInfo[16] IOAPICs;
Expand All @@ -88,7 +91,7 @@ public:
} }


// The address of the apic registers // The address of the apic registers
void* localAPICAddress; PhysicalAddress localAPICAddress;


LAPICInfo[256] LAPICs; LAPICInfo[256] LAPICs;
uint numLAPICs; uint numLAPICs;
Expand Down
7 changes: 5 additions & 2 deletions kernel/arch/x86_64/core/ioapic.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import kernel.core.error;
import kernel.core.log; import kernel.core.log;
import kernel.core.kprintf; import kernel.core.kprintf;


import user.types;


struct IOAPIC struct IOAPIC
{ {
static: static:
Expand Down Expand Up @@ -112,7 +115,7 @@ private:


// -- Setup -- // // -- Setup -- //


void initUnit(ubyte ioAPICID, void* ioAPICAddress, bool hasIMCR) { void initUnit(ubyte ioAPICID, PhysicalAddress ioAPICAddress, bool hasIMCR) {


// disable the IMCR // disable the IMCR
if (hasIMCR) { if (hasIMCR) {
Expand All @@ -124,7 +127,7 @@ private:


// map IOAPIC region // map IOAPIC region
//kprintfln!("IOAPIC Addr {x}")(ioAPICAddress); //kprintfln!("IOAPIC Addr {x}")(ioAPICAddress);
void* IOAPICVirtAddr = Paging.mapRegion(ioAPICAddress, 4096); ubyte* IOAPICVirtAddr = Paging.mapRegion(ioAPICAddress, 4096).ptr;
//kprintfln!("IOAPIC Addr {x}")(IOAPICVirtAddr); //kprintfln!("IOAPIC Addr {x}")(IOAPICVirtAddr);


// set the addresses for the data register and window // set the addresses for the data register and window
Expand Down
7 changes: 5 additions & 2 deletions kernel/arch/x86_64/core/lapic.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import kernel.core.log;


import kernel.system.info; import kernel.system.info;


import user.types;


struct LocalAPIC { struct LocalAPIC {
static: static:
public: public:
Expand Down Expand Up @@ -117,7 +120,7 @@ private:
uint[256] logicalIDToAPICId = 0; uint[256] logicalIDToAPICId = 0;
uint[256] APICIdToLogicalID = 0; uint[256] APICIdToLogicalID = 0;


void initLocalApic(void* localAPICAddr) { void initLocalApic(PhysicalAddress localAPICAddr) {
ubyte* apicRange; ubyte* apicRange;


ulong MSRValue = Cpu.readMSR(0x1B); ulong MSRValue = Cpu.readMSR(0x1B);
Expand All @@ -134,7 +137,7 @@ private:


// Map in the first megabyte of space // Map in the first megabyte of space
ubyte* bootRange; ubyte* bootRange;
bootRange = cast(ubyte*)Paging.mapRegion(cast(void*)0x0, trampolineLength); bootRange = cast(ubyte*)Paging.mapRegion(null, trampolineLength);


//kprintfln!("bootRange: {} trampolineLength: {} trampolineCode: {x} trampoline: {x} Kernel: {x}")(bootRange, trampolineLength, trampolineCode, LinkerScript.trampoline, System.kernel.start); //kprintfln!("bootRange: {} trampolineLength: {} trampolineCode: {x} trampoline: {x} Kernel: {x}")(bootRange, trampolineLength, trampolineCode, LinkerScript.trampoline, System.kernel.start);


Expand Down
9 changes: 0 additions & 9 deletions kernel/arch/x86_64/core/paging.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -434,15 +434,6 @@ public:


// --- Making Specific Physical Addresses Available --- // --- Making Specific Physical Addresses Available ---


void* mapRegion(void* physAddr, ulong regionLength) {
return cast(void*)mapRegion(cast(PhysicalAddress)physAddr, regionLength).ptr;
}

ErrorVal mapRegion(void* gib, void* physAddr, ulong regionLength) {
mapRegion(cast(ubyte*)gib, cast(PhysicalAddress)physAddr, regionLength);
return ErrorVal.Success;
}

// Using heapAddress, this will add a region to the kernel space // Using heapAddress, this will add a region to the kernel space
// It returns the virtual address to this region. Use sparingly // It returns the virtual address to this region. Use sparingly
ubyte[] mapRegion(PhysicalAddress physAddr, ulong regionLength) { ubyte[] mapRegion(PhysicalAddress physAddr, ulong regionLength) {
Expand Down
6 changes: 4 additions & 2 deletions kernel/arch/x86_64/core/tss.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ static:
// To reset the TSS, you will need to reset the Segment Type to // To reset the TSS, you will need to reset the Segment Type to
// AvailableTSS. // AvailableTSS.
ErrorVal install() { ErrorVal install() {
TaskStateSegment* tss = cast(TaskStateSegment*)PageAllocator.allocPage(); PhysicalAddress tssPage = PageAllocator.allocPage();
tss = cast(TaskStateSegment*)Paging.mapRegion(cast(ubyte*)tss, VirtualMemory.pagesize);
TaskStateSegment* tss = cast(TaskStateSegment*)tssPage;
tss = cast(TaskStateSegment*)Paging.mapRegion(tssPage, VirtualMemory.pagesize);
*tss = TaskStateSegment.init; *tss = TaskStateSegment.init;
segments[Cpu.identifier] = tss; segments[Cpu.identifier] = tss;
GDT.tables[Cpu.identifier].setSystemSegment((tssBase >> 3), 0x67, (cast(ulong)tss), SystemSegmentType.AvailableTSS, 0, true, false, false); GDT.tables[Cpu.identifier].setSystemSegment((tssBase >> 3), 0x67, (cast(ulong)tss), SystemSegmentType.AvailableTSS, 0, true, false, false);
Expand Down
11 changes: 6 additions & 5 deletions kernel/arch/x86_64/specs/acpitables.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kernel.arch.x86_64.core.paging;
import kernel.system.info; import kernel.system.info;


import user.util : Bitfield; import user.util : Bitfield;
import user.types;


struct Tables { struct Tables {
static: static:
Expand Down Expand Up @@ -56,7 +57,7 @@ public:
// (lets assume the XSDT is there, it will be there if this is not a legacy RSDP... revision=1) // (lets assume the XSDT is there, it will be there if this is not a legacy RSDP... revision=1)
if (ptrRSDP.revision >= 1 && ptrRSDP.ptrXSDT != 0) { if (ptrRSDP.revision >= 1 && ptrRSDP.ptrXSDT != 0) {
// Map in XSDT into kernel virtual memory space // Map in XSDT into kernel virtual memory space
ptrXSDT = cast(XSDT*)Paging.mapRegion(cast(void*)ptrRSDP.ptrRSDT, RSDT.sizeof); ptrXSDT = cast(XSDT*)Paging.mapRegion(cast(PhysicalAddress)ptrRSDP.ptrRSDT, RSDT.sizeof);


// validate the XSDT // validate the XSDT
if (validateXSDT() == ErrorVal.Fail) { if (validateXSDT() == ErrorVal.Fail) {
Expand All @@ -66,7 +67,7 @@ public:
} }
else { else {
// Map in RSDT into kernel virtual memory space // Map in RSDT into kernel virtual memory space
ptrRSDT = cast(RSDT*)Paging.mapRegion(cast(void*)ptrRSDP.ptrRSDT, RSDT.sizeof); ptrRSDT = cast(RSDT*)Paging.mapRegion(cast(PhysicalAddress)ptrRSDP.ptrRSDT, RSDT.sizeof);


// validate the RSDT // validate the RSDT
if (validateRSDT() == ErrorVal.Fail) { if (validateRSDT() == ErrorVal.Fail) {
Expand Down Expand Up @@ -227,7 +228,7 @@ private:
uint* curByte = cast(uint*)(ptrRSDT + 1); uint* curByte = cast(uint*)(ptrRSDT + 1);


for (; curByte < endByte; curByte++) { for (; curByte < endByte; curByte++) {
DescriptorHeader* curTable = cast(DescriptorHeader*)Paging.mapRegion(cast(void*)(*curByte), MADT.sizeof); DescriptorHeader* curTable = cast(DescriptorHeader*)Paging.mapRegion(cast(PhysicalAddress)(*curByte), MADT.sizeof);


if (curTable.signature[0] == 'A' && if (curTable.signature[0] == 'A' &&
curTable.signature[1] == 'P' && curTable.signature[1] == 'P' &&
Expand Down Expand Up @@ -513,7 +514,7 @@ private:
endByte--; endByte--;


// Set LocalAPIC Address // Set LocalAPIC Address
Info.localAPICAddress = cast(void*)ptrMADT.localAPICAddr; Info.localAPICAddress = cast(PhysicalAddress)ptrMADT.localAPICAddr;


// For the overrides, read from the table // For the overrides, read from the table


Expand Down Expand Up @@ -548,7 +549,7 @@ private:
Info.IOAPICs[Info.numIOAPICs].enabled = true; Info.IOAPICs[Info.numIOAPICs].enabled = true;


// Get the IOAPIC address // Get the IOAPIC address
Info.IOAPICs[Info.numIOAPICs].address = cast(void*)ioapicInfo.IOAPICAddr; Info.IOAPICs[Info.numIOAPICs].address = cast(PhysicalAddress)ioapicInfo.IOAPICAddr;


// increment the count // increment the count
Info.numIOAPICs++; Info.numIOAPICs++;
Expand Down
5 changes: 3 additions & 2 deletions kernel/arch/x86_64/specs/mp.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kernel.core.kprintf;


// Bitfield!() // Bitfield!()
import user.util; import user.util;
import user.types;


// The Info struct holds all of the information we will enumerating // The Info struct holds all of the information we will enumerating
import kernel.arch.x86_64.core.info; import kernel.arch.x86_64.core.info;
Expand Down Expand Up @@ -87,7 +88,7 @@ public:
return ErrorVal.Fail; return ErrorVal.Fail;
} }


Info.localAPICAddress = cast(void*)mpConfig.addressOfLocalAPIC; Info.localAPICAddress = cast(PhysicalAddress)mpConfig.addressOfLocalAPIC;


// We need to map in the APIC register space info a separate // We need to map in the APIC register space info a separate
// kernel region. // kernel region.
Expand Down Expand Up @@ -139,7 +140,7 @@ public:
Info.IOAPICs[Info.numIOAPICs].ID = ioapic.ioAPICID; Info.IOAPICs[Info.numIOAPICs].ID = ioapic.ioAPICID;
Info.IOAPICs[Info.numIOAPICs].ver = ioapic.ioAPICVersion; Info.IOAPICs[Info.numIOAPICs].ver = ioapic.ioAPICVersion;
Info.IOAPICs[Info.numIOAPICs].enabled = cast(bool)ioapic.ioAPICEnabled; Info.IOAPICs[Info.numIOAPICs].enabled = cast(bool)ioapic.ioAPICEnabled;
Info.IOAPICs[Info.numIOAPICs].address = cast(void*)ioapic.ioAPICAddress; Info.IOAPICs[Info.numIOAPICs].address = cast(PhysicalAddress)ioapic.ioAPICAddress;


// increment the count // increment the count
Info.numIOAPICs++; Info.numIOAPICs++;
Expand Down
2 changes: 1 addition & 1 deletion kernel/dev/console.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public:
videoMemoryLocation = vid.ptr + videoMetaData.videoBufferOffset; videoMemoryLocation = vid.ptr + videoMetaData.videoBufferOffset;
videoInfo = videoMetaData; videoInfo = videoMetaData;


VirtualMemory.mapRegion(cast(ubyte*)(videoMemoryLocation), cast(ubyte*)videoMemoryPhysLocation, vramSize); VirtualMemory.mapRegion(videoMemoryLocation, videoMemoryPhysLocation, vramSize);


uint temp = LINES * COLUMNS; uint temp = LINES * COLUMNS;
temp++; temp++;
Expand Down
2 changes: 1 addition & 1 deletion kernel/system/definitions.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum RegionType: ubyte {
// This structure keeps track of special memory regions. // This structure keeps track of special memory regions.
struct Region { struct Region {
// The location and length of the region // The location and length of the region
ubyte* start; PhysicalAddress start;
ulong length; ulong length;


// The virtual location of the region // The virtual location of the region
Expand Down
2 changes: 1 addition & 1 deletion kernel/system/multiboot.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ ErrorVal verifyBootInformation(int id, void *data) {
else { else {
// This is a reserved region // This is a reserved region
if (System.numRegions < System.regionInfo.length) { if (System.numRegions < System.regionInfo.length) {
System.regionInfo[System.numRegions].start = cast(ubyte*)baseAddr; System.regionInfo[System.numRegions].start = cast(PhysicalAddress)baseAddr;
System.regionInfo[System.numRegions].length = length; System.regionInfo[System.numRegions].length = length;
System.numRegions++; System.numRegions++;
} }
Expand Down

0 comments on commit 7a05d20

Please sign in to comment.