Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

another strike in the war on void*

  • Loading branch information...
commit 7a05d20f8e442d38a92740d4745273452bcbcfca 1 parent dbdcc71
@wolfwood wolfwood authored
View
3  kernel/arch/x86_64/architecture/cpu.d
@@ -677,8 +677,7 @@ private:
// Will create and install a new kernel stack
// Note: You have to preserve the current stack
ErrorVal installStack() {
- ubyte* stackSpace = cast(ubyte*)PageAllocator.allocPage();
- stackSpace = cast(ubyte*)VirtualMemory.mapStack(stackSpace);
+ ubyte* stackSpace = VirtualMemory.mapStack(PageAllocator.allocPage());
ubyte* currentStack = cast(ubyte*)(&_stack-4096);
stackSpace[0..4096] = currentStack[0..4096];
View
2  kernel/arch/x86_64/architecture/main.d
@@ -37,7 +37,7 @@ public:
ErrorVal initialize() {
// Reading from the linker script
// 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.virtualStart = cast(ubyte*)LinkerScript.kernelVMA;
View
2  kernel/arch/x86_64/architecture/syscall.d
@@ -68,7 +68,7 @@ static:
Cpu.writeMSR(SFMASK_MSR, 0);
// stash a syscall stack in GS.Base
- void* stackPtr = PageAllocator.allocPage();
+ PhysicalAddress stackPtr = PageAllocator.allocPage();
ulong syscallStack = cast(ulong)VirtualMemory.mapStack(stackPtr) + 4096;
asm{
View
16 kernel/arch/x86_64/architecture/vm.d
@@ -116,7 +116,7 @@ public:
return Paging.PAGESIZE;
}
- synchronized void* mapStack(void* physAddr) {
+ synchronized ubyte* mapStack(PhysicalAddress physAddr) {
if(stackSegment is null){
stackSegment = findFreeSegment().ptr;
createSegment(stackSegment, oneGB, AccessMode.Writable|AccessMode.AllocOnAccess);
@@ -124,16 +124,16 @@ public:
stackSegment += Paging.PAGESIZE;
- if(Paging.mapRegion(stackSegment, physAddr, Paging.PAGESIZE) == ErrorVal.Fail){
- return null;
- }else{
- return stackSegment;
- }
+ return Paging.mapRegion(stackSegment, physAddr, Paging.PAGESIZE).ptr;
}
// --- OLD --- //
- synchronized ErrorVal mapRegion(void* gib, void* physAddr, ulong regionLength) {
- return Paging.mapRegion(gib, physAddr, regionLength);
+ synchronized ErrorVal mapRegion(ubyte* gib, PhysicalAddress physAddr, ulong regionLength) {
+ if(Paging.mapRegion(gib, physAddr, regionLength) !is null){
+ return ErrorVal.Fail;
+ }
+
+ return ErrorVal.Success;
}
private:
View
6 kernel/arch/x86_64/core/gdt.d
@@ -33,9 +33,11 @@ static:
}
ErrorVal install() {
+ PhysicalAddress gdtPage = PageAllocator.allocPage();
+
// Create a new GDT structure
- GlobalDescriptorTable* gdt = cast(GlobalDescriptorTable*)PageAllocator.allocPage();
- gdt = cast(GlobalDescriptorTable*)Paging.mapRegion(cast(ubyte*)gdt, VirtualMemory.pagesize);
+ GlobalDescriptorTable* gdt = cast(GlobalDescriptorTable*)gdtPage;
+ gdt = cast(GlobalDescriptorTable*)Paging.mapRegion(gdtPage, VirtualMemory.pagesize);
*gdt = GlobalDescriptorTable.init;
tables[Cpu.identifier] = gdt;
initializeTable(Cpu.identifier);
View
9 kernel/arch/x86_64/core/info.d
@@ -9,6 +9,9 @@
module kernel.arch.x86_64.core.info;
+import user.types;
+
+
struct Info {
static:
public:
@@ -68,8 +71,8 @@ public:
// Whether or not this IO APIC is enabled
bool enabled;
- // Virtual address of the IO APIC register
- void* address;
+ // address of the IO APIC register
+ PhysicalAddress address;
}
IOAPICInfo[16] IOAPICs;
@@ -88,7 +91,7 @@ public:
}
// The address of the apic registers
- void* localAPICAddress;
+ PhysicalAddress localAPICAddress;
LAPICInfo[256] LAPICs;
uint numLAPICs;
View
7 kernel/arch/x86_64/core/ioapic.d
@@ -25,6 +25,9 @@ import kernel.core.error;
import kernel.core.log;
import kernel.core.kprintf;
+import user.types;
+
+
struct IOAPIC
{
static:
@@ -112,7 +115,7 @@ private:
// -- Setup -- //
- void initUnit(ubyte ioAPICID, void* ioAPICAddress, bool hasIMCR) {
+ void initUnit(ubyte ioAPICID, PhysicalAddress ioAPICAddress, bool hasIMCR) {
// disable the IMCR
if (hasIMCR) {
@@ -124,7 +127,7 @@ private:
// map IOAPIC region
//kprintfln!("IOAPIC Addr {x}")(ioAPICAddress);
- void* IOAPICVirtAddr = Paging.mapRegion(ioAPICAddress, 4096);
+ ubyte* IOAPICVirtAddr = Paging.mapRegion(ioAPICAddress, 4096).ptr;
//kprintfln!("IOAPIC Addr {x}")(IOAPICVirtAddr);
// set the addresses for the data register and window
View
7 kernel/arch/x86_64/core/lapic.d
@@ -21,6 +21,9 @@ import kernel.core.log;
import kernel.system.info;
+import user.types;
+
+
struct LocalAPIC {
static:
public:
@@ -117,7 +120,7 @@ private:
uint[256] logicalIDToAPICId = 0;
uint[256] APICIdToLogicalID = 0;
- void initLocalApic(void* localAPICAddr) {
+ void initLocalApic(PhysicalAddress localAPICAddr) {
ubyte* apicRange;
ulong MSRValue = Cpu.readMSR(0x1B);
@@ -134,7 +137,7 @@ private:
// Map in the first megabyte of space
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);
View
9 kernel/arch/x86_64/core/paging.d
@@ -434,15 +434,6 @@ public:
// --- 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
// It returns the virtual address to this region. Use sparingly
ubyte[] mapRegion(PhysicalAddress physAddr, ulong regionLength) {
View
6 kernel/arch/x86_64/core/tss.d
@@ -46,8 +46,10 @@ static:
// To reset the TSS, you will need to reset the Segment Type to
// AvailableTSS.
ErrorVal install() {
- TaskStateSegment* tss = cast(TaskStateSegment*)PageAllocator.allocPage();
- tss = cast(TaskStateSegment*)Paging.mapRegion(cast(ubyte*)tss, VirtualMemory.pagesize);
+ PhysicalAddress tssPage = PageAllocator.allocPage();
+
+ TaskStateSegment* tss = cast(TaskStateSegment*)tssPage;
+ tss = cast(TaskStateSegment*)Paging.mapRegion(tssPage, VirtualMemory.pagesize);
*tss = TaskStateSegment.init;
segments[Cpu.identifier] = tss;
GDT.tables[Cpu.identifier].setSystemSegment((tssBase >> 3), 0x67, (cast(ulong)tss), SystemSegmentType.AvailableTSS, 0, true, false, false);
View
11 kernel/arch/x86_64/specs/acpitables.d
@@ -20,6 +20,7 @@ import kernel.arch.x86_64.core.paging;
import kernel.system.info;
import user.util : Bitfield;
+import user.types;
struct Tables {
static:
@@ -56,7 +57,7 @@ public:
// (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) {
// 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
if (validateXSDT() == ErrorVal.Fail) {
@@ -66,7 +67,7 @@ public:
}
else {
// 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
if (validateRSDT() == ErrorVal.Fail) {
@@ -227,7 +228,7 @@ private:
uint* curByte = cast(uint*)(ptrRSDT + 1);
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' &&
curTable.signature[1] == 'P' &&
@@ -513,7 +514,7 @@ private:
endByte--;
// Set LocalAPIC Address
- Info.localAPICAddress = cast(void*)ptrMADT.localAPICAddr;
+ Info.localAPICAddress = cast(PhysicalAddress)ptrMADT.localAPICAddr;
// For the overrides, read from the table
@@ -548,7 +549,7 @@ private:
Info.IOAPICs[Info.numIOAPICs].enabled = true;
// 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
Info.numIOAPICs++;
View
5 kernel/arch/x86_64/specs/mp.d
@@ -20,6 +20,7 @@ import kernel.core.kprintf;
// Bitfield!()
import user.util;
+import user.types;
// The Info struct holds all of the information we will enumerating
import kernel.arch.x86_64.core.info;
@@ -87,7 +88,7 @@ public:
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
// kernel region.
@@ -139,7 +140,7 @@ public:
Info.IOAPICs[Info.numIOAPICs].ID = ioapic.ioAPICID;
Info.IOAPICs[Info.numIOAPICs].ver = ioapic.ioAPICVersion;
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
Info.numIOAPICs++;
View
2  kernel/dev/console.d
@@ -61,7 +61,7 @@ public:
videoMemoryLocation = vid.ptr + videoMetaData.videoBufferOffset;
videoInfo = videoMetaData;
- VirtualMemory.mapRegion(cast(ubyte*)(videoMemoryLocation), cast(ubyte*)videoMemoryPhysLocation, vramSize);
+ VirtualMemory.mapRegion(videoMemoryLocation, videoMemoryPhysLocation, vramSize);
uint temp = LINES * COLUMNS;
temp++;
View
2  kernel/system/definitions.d
@@ -45,7 +45,7 @@ enum RegionType: ubyte {
// This structure keeps track of special memory regions.
struct Region {
// The location and length of the region
- ubyte* start;
+ PhysicalAddress start;
ulong length;
// The virtual location of the region
View
2  kernel/system/multiboot.d
@@ -197,7 +197,7 @@ ErrorVal verifyBootInformation(int id, void *data) {
else {
// This is a reserved region
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.numRegions++;
}
Please sign in to comment.
Something went wrong with that request. Please try again.