Skip to content

Commit

Permalink
Refined GibAllocator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Jan 18, 2010
1 parent 4495c6c commit ef4f99c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 54 deletions.
10 changes: 5 additions & 5 deletions kernel/core/kmain.d
Expand Up @@ -104,14 +104,14 @@ extern(C) void kmain(int bootLoaderID, void *data) {
Log.print("PageAllocator: initialize()");
Log.result(PageAllocator.initialize());

// 3b. RamFS Initialization
// Log.print("RamFS: initialize()");
// Log.result(RamFS.initialize());

// 3c. Console Initialization
// 3b. Console Initialization
Log.print("Console: initialize()");
Log.result(Console.initialize());

// 3c. RamFS Initialization
Log.print("RamFS: initialize()");
Log.result(RamFS.initialize());

// 4. Timer Initialization
// LATER

Expand Down
2 changes: 1 addition & 1 deletion kernel/dev/console.d
Expand Up @@ -41,7 +41,7 @@ public:
info.width = COLUMNS;
info.height = LINES;

Gib video = GibAllocator.alloc((1024*128)+3, 0);
Gib video = GibAllocator.alloc(Access.Kernel | Access.Read | Access.Write);
// Gib video = RamFS.open("/dev/video", Access.Create | Access.Read | Access.Write);
MetaData* videoMetaData = cast(MetaData*)video.ptr;
*videoMetaData = info;
Expand Down
74 changes: 41 additions & 33 deletions kernel/filesystem/ramfs.d
Expand Up @@ -12,53 +12,61 @@ import kernel.environ.scheduler;

import architecture.vm;

import kernel.mem.giballocator;
import kernel.mem.gib;

import user.ramfs;

enum Access : uint {
Create = 1,
Read = 2,
Write = 4,
Append = 8
}
class RamFS {
static:
ErrorVal initialize() {
// Make root
rootDir = GibAllocator.alloc(Access.Kernel | Access.Read | Access.Write);

int strcmp(char[] s1, char[] s2) {
if (s1.length != s2.length) {
return s1.length - s2.length;
return ErrorVal.Fail;
}

foreach(uint i, ch; s1) {
if (s2[i] != ch) {
return s2[i] - ch;
}
}
void mkdir(Gib curDir) {
// Check curDir permissions
// ...

return 0;
}
// Create new directory Gib
Gib newDir = GibAllocator.alloc(Access.Kernel | Access.Read | Access.Write);

// form this new directory
// ...

// link curDir to this new directory
// ...

// close kernel Gib
// ...

bool streq(char[] s1, uint len, char[] s2) {
if (len != s2.length) {
return false;
}

foreach(uint i, ch; s2) {
if (s1[i] != ch) {
return false;
}
ErrorVal destroy() {
return ErrorVal.Fail;
}

return true;
}
ErrorVal create() {
// Create a new Gib
// ...

return ErrorVal.Fail;
}

ErrorVal open() {
return ErrorVal.Fail;
}

bool streq(char[] s1, char[] s2) {
if (s1.length != s2.length) {
return false;
ErrorVal close() {
return ErrorVal.Fail;
}

foreach(uint i, ch; s1) {
if (s2[i] != ch) {
return false;
}
ErrorVal link() {
return ErrorVal.Fail;
}

return true;
private:
Gib rootDir;
}
2 changes: 1 addition & 1 deletion kernel/mem/bitmap.d
Expand Up @@ -32,7 +32,7 @@ ErrorVal initialize() {
totalPages = System.memory.length / VirtualMemory.getPageSize();

// Get a gib for the page allocator
bitmapGib = GibAllocator.alloc((1024*128) + 1, 0);
bitmapGib = GibAllocator.alloc(Access.Kernel | Access.Read | Access.Write);

// Calculate how much we need for the bitmap.
// 8 bits per byte, 8 bytes for ulong.
Expand Down
22 changes: 20 additions & 2 deletions kernel/mem/giballocator.d
Expand Up @@ -15,16 +15,28 @@ import kernel.core.error;
import kernel.core.kprintf;
import kernel.core.log;

enum Access : uint {
Read = 1,
Write = 2,
Kernel = 128,
}

struct GibAllocator {
static:
public:

Gib alloc(uint gibIndex, uint flags) {
Gib alloc(uint flags) {
Gib ret;
uint gibIndex = 0;
if (flags & Access.Kernel != 0) {
// kernel gib
gibIndex = nextFreeKernelGib;
nextFreeKernelGib++;
}
ubyte* gibAddr = VirtualMemory.allocGib(gibIndex, flags);
ret._start = gibAddr;
ret._curpos = gibAddr;
kprintfln!("Gib address: {}")(gibAddr);
kprintfln!("Gib (kernel) address: {} at {}")(gibAddr, gibIndex);
return ret;
}

Expand All @@ -39,5 +51,11 @@ public:

private:
const auto KERNEL_START = 1024UL * 128UL;
const auto MAX_GIBS = 256UL * 1024UL;
const auto GIB_SIZE = 1024UL * 1024UL * 1024UL;

// Must take into account the first gib is always the kernel executable
uint nextFreeKernelGib = KERNEL_START + 1;
ulong[(MAX_GIBS+64)/64] gibBitmap;

}
2 changes: 1 addition & 1 deletion kernel/mem/heap.d
Expand Up @@ -32,7 +32,7 @@ public:

// Needs to be called by the architecture
ErrorVal initialize() {
_gib = GibAllocator.alloc((1024*128)+2, 0);
_gib = GibAllocator.alloc(Access.Kernel | Access.Read | Access.Write);
return ErrorVal.Success;
}

Expand Down
11 changes: 0 additions & 11 deletions user/ramfs.d
@@ -1,17 +1,6 @@

module user.ramfs;

alias void* Gib;










// BLEH

alias void* PagePtr;
Expand Down

0 comments on commit ef4f99c

Please sign in to comment.