Permalink
Browse files

Various changes and fixes

- Reverted change to GC and initial memory
- Updated TinySim so that memory mapping matches docs
- Updated TinySim and Multiboot stage so that the stack address matches
docs
  • Loading branch information...
1 parent 9733b84 commit ba0c422548882a9ef46173bb620e0bd624c74d2c @charsleysa charsleysa committed Dec 22, 2015
@@ -38,11 +38,11 @@
0x01500000 - 0x015FFFFF = Virtual Page Allocator
0x01600000 - 0x016FFFFF = Virtual Page Allocator
0x01700000 - 0x017FFFFF = Virtual Page Allocator
-0x01800000 - 0x018FFFFF = Initial GC
-0x01900000 - 0x019FFFFF = Initial GC
-0x01A00000 - 0x01AFFFFF = Initial GC
-0x01B00000 - 0x01BFFFFF = Initial GC
-0x01C00000 - 0x01CFFFFF = Initial GC
-0x01D00000 - 0x01DFFFFF = Initial GC
-0x01E00000 - 0x01EFFFFF = Initial GC
-0x01F00000 - 0x01FFFFFF = Initial GC
+0x01800000 - 0x018FFFFF = Unused
+0x01900000 - 0x019FFFFF = Unused
+0x01A00000 - 0x01AFFFFF = Unused
+0x01B00000 - 0x01BFFFFF = Unused
+0x01C00000 - 0x01CFFFFF = Unused
+0x01D00000 - 0x01DFFFFF = Unused
+0x01E00000 - 0x01EFFFFF = Unused
+0x01F00000 - 0x01FFFFFF = Unused
@@ -9,8 +9,8 @@ namespace Mosa.Kernel.x86
/// </summary>
public static class KernelMemory
{
- static private uint heap = Address.GCInitialMemory;
- static private uint allocated = 1024 * 1024 * 8; // 8MB
+ static private uint heap = 0;
+ static private uint allocated = 0;
static private uint used = 0;
[Method("Mosa.Platform.Internal.x86.GC.AllocateMemory")]
@@ -6,6 +6,8 @@ namespace Mosa.Platform.Internal.x86
{
public unsafe static class GC
{
+ private static bool isSetup = false;
+
// This method will be plugged by "Mosa.Kernel.x86.KernelMemory.AllocateMemory"
private static uint AllocateMemory(uint size)
{
@@ -14,11 +16,16 @@ private static uint AllocateMemory(uint size)
public static void* AllocateObject(uint size)
{
+ Debug.Assert(isSetup, "GC not setup yet!");
+
+ // TODO: GC
return (void*)AllocateMemory(size);
}
public static void Setup()
{
+ // TODO: GC
+ isSetup = true;
}
}
}
@@ -54,6 +54,11 @@ public sealed class Multiboot0695Stage : BaseCompilerStage
/// </summary>
private const uint HEADER_MB_FLAG_NON_ELF_BINARY = 0x00010000U;
+ /// <summary>
+ /// This address is the top of the initial kernel stack.
+ /// </summary>
+ private const uint STACK_ADDRESS = 0x003FFFFC;
+
#endregion Constants
#region Data members
@@ -107,18 +112,22 @@ protected override void Run()
var eax = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
var ebx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
var ebp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBP);
+ var esp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);
var multibootEax = Operand.CreateUnmanagedSymbolPointer(TypeSystem, MultibootEAX);
var multibootEbx = Operand.CreateUnmanagedSymbolPointer(TypeSystem, MultibootEBX);
+ var zero = Operand.CreateConstant(TypeSystem.BuiltIn.I4, 0);
+ var stackTop = Operand.CreateConstant(TypeSystem.BuiltIn.I4, STACK_ADDRESS);
var basicBlocks = new BasicBlocks();
var block = basicBlocks.CreateBlock();
basicBlocks.AddHeadBlock(block);
var ctx = new Context(block);
- // set sentinel on the stack to indicate the start of the stack
- var zero = Operand.CreateConstant(TypeSystem.BuiltIn.I4, 0);
+ // Setup the stack and place the sentinel on the stack to indicate the start of the stack
+ ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, esp, 0), stackTop);
ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ebp, 0), zero);
+ // Place the multiboot address into a static field
ctx.AppendInstruction(X86.Mov, ecx, multibootEax);
ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ecx, 0), eax);
ctx.AppendInstruction(X86.Mov, ecx, multibootEbx);
@@ -5,7 +5,7 @@ namespace Mosa.TinyCPUSimulator.x86.Emulate
public class MosaImage : BaseSimDevice
{
public static readonly uint BaseAddress = 0x00400000;
- public static readonly uint ImageSize = 0x00400000;
+ public static readonly uint ImageSize = 1024 * 1024 * 8; // 8MB
public MosaImage(SimCPU simCPU)
: base(simCPU)
@@ -4,13 +4,12 @@ namespace Mosa.TinyCPUSimulator.x86.Emulate
{
public class MosaKernel : BaseSimDevice
{
- public static readonly uint GdtTable = 0x1401000;
- public static readonly uint IdtTable = 0x1411000;
+ public static readonly uint SmallTables = 1024 * 1024 * 2; // Includes GDT, IDT, Page Directory, etc
+ public static readonly uint KernelStack = 1024 * 1024 * 3;
public static readonly uint PageTable = 1024 * 1024 * 16;
- public static readonly uint PageDirectory = 1024 * 1024 * 20;
- public static readonly uint PageFrameTable = 1024 * 1024 * 28;
- public static readonly uint FreeMemory = 1024 * 1024 * 32; // start at 32Mb
- public static readonly uint VirtualPageBitMap = 1024 * 1024 * 21; // 0x1500000
+ public static readonly uint PageFrameTable = 1024 * 1024 * 12;
+ public static readonly uint FreeMemory = 1024 * 1024 * 32; // start at 32MB
+ public static readonly uint VirtualPageBitMap = 1024 * 1024 * 20; // 0x01400000
public MosaKernel(SimCPU simCPU)
: base(simCPU)
@@ -21,13 +20,12 @@ public override void Initialize()
{
var x86 = simCPU as CPUx86;
- simCPU.AddMemory(PageDirectory, 1024 * 4, 1); // Page Directory (4K)
- simCPU.AddMemory(PageTable, 1024 * 1024 * 4, 1); // Page Table (4Mb)
- simCPU.AddMemory(FreeMemory, 1024 * 1024 * 64, 1); // Free Memory (64Mb)
- simCPU.AddMemory(IdtTable, 256 * 256, 1); // IDT Table
- simCPU.AddMemory(GdtTable, 8 * 256, 1); // GDT Table
- simCPU.AddMemory(PageFrameTable, 1024 * 1024 * 4, 1); // Page Table (4Mb)
- simCPU.AddMemory(VirtualPageBitMap, 1024 * 1024 * 4, 1); // Virtual Page BitMap (4Mb)
+ simCPU.AddMemory(SmallTables, 1024 * 1024 * 1, 1); // Small Tables (1MB)
+ simCPU.AddMemory(KernelStack, 1024 * 1024 * 1, 1); // Kernel Stack (1MB)
+ simCPU.AddMemory(PageTable, 1024 * 1024 * 4, 1); // Page Table (4MB)
+ simCPU.AddMemory(FreeMemory, 1024 * 1024 * 64, 1); // Free Memory (64MB)
+ simCPU.AddMemory(PageFrameTable, 1024 * 1024 * 4, 1); // Page Table (4MB)
+ simCPU.AddMemory(VirtualPageBitMap, 1024 * 1024 * 4, 1); // Virtual Page BitMap (4MB)
}
public override BaseSimDevice Clone(SimCPU simCPU)
@@ -32,7 +32,7 @@ public override void Reset()
var x86 = simCPU as CPUx86;
// Start of stack
- x86.ESP.Value = 0x00080000;
+ x86.ESP.Value = 0x003FFFFC;
x86.EBP.Value = x86.ESP.Value;
// Start EIP
@@ -12,7 +12,7 @@ public partial class MemoryView : SimulatorDockContent
{
private uint multibootStructure = Multiboot.MultibootStructure;
private uint physicalPageFreeList = MosaKernel.PageTable;
- private uint cr3 = MosaKernel.PageDirectory;
+ private uint cr3 = MosaKernel.SmallTables;
/// <summary>
/// Initializes a new instance of the <see cref="MemoryView"/> class.

0 comments on commit ba0c422

Please sign in to comment.