<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -48,13 +48,12 @@ void AkariMemorySubsystem::SetPaging(bool mode) {
 	POSIX::memset(_frames, 0, INDEX_BIT(_frameCount) + 1);
 
 	_kernelDirectory = PageDirectory::Allocate();
-	_heap = new Heap(KHEAP_START, KHEAP_START + KHEAP_INITIAL_SIZE, 0xCFFFF000, false, true);
 
 	for (u32 i = KHEAP_START; i &lt; KHEAP_START + KHEAP_INITIAL_SIZE; i += 0x1000)
 		_kernelDirectory-&gt;GetPage(i, true);
 	
 	u32 base = 0;
-	while (base &lt; _placementAddress) {
+	while (base &lt; (_placementAddress + sizeof(Heap))) {
 		_kernelDirectory-&gt;GetPage(base, true)-&gt;AllocFrame(base, false, false);
 		base += 0x1000;
 	}
@@ -67,11 +66,13 @@ void AkariMemorySubsystem::SetPaging(bool mode) {
 		_kernelDirectory-&gt;GetPage(i, true)-&gt;AllocAnyFrame(false, false);
 
 	Akari-&gt;Descriptor-&gt;_idt-&gt;InstallHandler(14, this-&gt;PageFault);
+
+	SwitchPageDirectory(_kernelDirectory);
+	_heap = new Heap(KHEAP_START, KHEAP_START + KHEAP_INITIAL_SIZE, 0xCFFFF000, false, true);
+	_placementAddress = 0;
 	
 	_activeDirectory = _kernelDirectory-&gt;Clone();
 	SwitchPageDirectory(_activeDirectory);
-
-	_placementAddress = 0;
 }
 
 void *AkariMemorySubsystem::Alloc(u32 n, u32 *phys) {
@@ -217,7 +218,12 @@ _start(start), _end(end), _max(max), _supervisor(supervisor), _readonly(readonly
 	if (start &amp; 0xFFFF)
 		start = (start &amp; 0xFFFFF000) + 0x1000;
 
+	ASSERT(_index._size == 0);
 	_index.insert(Entry(start, end - start, true));
+	ASSERT(_index._size == 1);
+	ASSERT(_index[0].start == start);
+	ASSERT(_index[0].size == end - start);
+	ASSERT(_index[0].isHole);
 }
 
 void *AkariMemorySubsystem::Heap::Alloc(u32 n) {
@@ -290,16 +296,19 @@ bool AkariMemorySubsystem::Heap::IndexSort(const Entry &amp;a, const Entry &amp;b) {
 
 s32 AkariMemorySubsystem::Heap::SmallestHole(u32 n) const {
 	u32 it = 0;
+	ASSERT(_index._size &gt; 0);
+
 	while (it &lt; _index._size) {
 		const Entry &amp;entry = _index[it];
 		if (!entry.isHole) {
 			++it; continue;
 		}
-		if (entry.size &gt;= n)
+		if (entry.size &gt;= n) {
 			return it;
+		}
 		++it;
 	}
-	AkariPanic(&quot;no smallest hole!&quot;);
+	AkariPanic(&quot;no smallest hole in SmallestHole!&quot;);
 	return -1;
 }
 
@@ -323,7 +332,7 @@ s32 AkariMemorySubsystem::Heap::SmallestAlignedHole(u32 n) const {
 
 		++it;
 	}
-	AkariPanic(&quot;no smallest hole!&quot;);
+	AkariPanic(&quot;no smallest hole in SmallestAlignedHole!&quot;);
 	return -1;
 }
 </diff>
      <filename>AkariMemorySubsystem.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,7 @@ CSRCS := $(wildcard *.c)
 CXXSRCS := $(wildcard *.cpp)
 OBJS := $(patsubst %.s,obj/%.s.o,$(ASMSRCS)) $(patsubst %.c,obj/%.c.o,$(CSRCS)) $(patsubst %.cpp,obj/%.cpp.o,$(CXXSRCS))
 
-all: $(TARGET)-copy
+all: clean $(TARGET)-copy
 
 $(TARGET)-copy: $(TARGET)
 	$(MTOOLS_BIN)/mcopy -D o $(TARGET) $(COPYDEST)</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 #include &lt;POSIX.hpp&gt;
+#include &lt;Akari.hpp&gt;
 
 namespace POSIX {
 	void *memset(void *mem, u8 c, u32 n) {</diff>
      <filename>POSIX.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,7 @@ class OrderedArray {
 			ASSERT(maxSize);
 			ASSERT(lessThan);
 
-			POSIX::memset(array, 0, maxSize * sizeof(T));
+			POSIX::memset(_array, 0, maxSize * sizeof(T));
 		}
 
 		const T &amp;operator[](u32 index) const {</diff>
      <filename>inc/OrderedArray.hpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a8e348e48ac9a08540d9e2f2c9cfbc43219c4357</id>
    </parent>
  </parents>
  <author>
    <name>Arlen Cuss</name>
    <email>celtic@sairyx.org</email>
  </author>
  <url>http://github.com/celtic/akari/commit/ae05e5c41dabe9cd972f1676e4d7d940d8dc283d</url>
  <id>ae05e5c41dabe9cd972f1676e4d7d940d8dc283d</id>
  <committed-date>2009-03-22T06:22:57-07:00</committed-date>
  <authored-date>2009-03-22T06:22:57-07:00</authored-date>
  <message>make sure we initialise the heap in the right spot, when paging is ENABLED, so we don't try initialising the OrderedArray at 0xC000,0000 when that really means nothing
add a bunch of asserts
actually include space in the placement for the Heap object
don't forget to disable placement up front by setting it to 0 as soon as the Heap's constructed, since otherwise our attempt to clone the pagedir tries to use the placement address, but we're already paging so it sets a fault off
clean before every make, our dependencies aren't done right</message>
  <tree>b681a324ff0259d9423bb5b363a3bc6366f49517</tree>
  <committer>
    <name>Arlen Cuss</name>
    <email>celtic@sairyx.org</email>
  </committer>
</commit>
