This commit is contained in:
Matthijs ter Woord 2016-06-10 11:12:59 -04:00
commit 6df53c4295
9 changed files with 293 additions and 71 deletions

View file

@ -1 +1,104 @@
On initialization of the kernel, a GlobalInformationTable is setup. This contains the address of the first DataLookupEntry
# Layout
```
F..F
Stack
Currently only one stack as we don't have threads yet. Stack resides at top of RAM and grows down.
In future each process will have its own stack in DATA. And Stack master section will be eliminated.
....
Data
-Heap
Global heap for all processes since compiler enforces references.
Text
All sections are fixed in size and are stacked.
-Syslinux Boot Code
-Cosmos Boot Code
-Kernel
-Apps (Monolithic currently, will move to DATA later)
-Legacy GDT
-IDT
-Page Tables
0..0
```
```
MM API
-Allocate new item
-Add/remove ref
-Lock/unlock an item
-Force a compact
Implicit
-Get pointer
Internal
-Compact
-Relocate items
Properties
-Ref count
-Lock status
-Size
Handles
-Use indirect pointers via a lookup table. Handle is ptr to table. Global table to save space.
-No way to compact tables?
-use linked list of tables to allow some compaction?
-Allocate tables to processes so they will go away 100% when process goes way since its not fully shrinkable.
-Keep in data space in future?
-Small tables increase compaction opportunities
-Points to actual data
-Properties are before pointer
-In atomic ops (IL emit groups) - pointer can be grabbed and stored
```
# OLD BELOW THIS POINT
On initialization of the kernel, a GlobalInformationTable is setup. This contains the address of the first DataLookupEntry
# The Memory Manager
The manager will init itself if there are no blocks. The manager is modeled after a double LinkedList and is not a List.
# Memory Layout
The layout does not have a preset list or table but rather every item has meta data linking the next and previous item. This allows for a robust system.
The data layout is as follows:
````
Block|Block|Block etc.
Block =
Meta Data|Data
Meta data =
4 bytes (preveus block address start)|4 bytes (next block address start)|4 bytes (curent[this] block size)| 4 bytes (curent[this] block flag)
```
BlockFlags :
```
Allocated = 0,
Free = 1,
```
the final layout looks like this:
```
4 bytes|4 bytes|4 bytes|4 bytes | (size of Block) bytes | 4 bytes|4 bytes|4 bytes | 4 bytes | (size of Block) bytes | etc
```
Note:
this means the smallest size an Block can occupy is 17 bytes, 16 bytes for the header and 1 for the smallest data type a byte.
# Usage
### Allocation
Allocating a block happens by finding the first free block and split it (if necessary).
## Deallocation
Freeing a block is easy set its flag (in the metadata) to free.

View file

@ -1,42 +0,0 @@
# The Memory Manager
The manager will init itself if there are no blocks. The manager is modeled after a double LinkedList and is not a List.
# Memory Layout
The layout does not have a preset list or table but rather every item has meta data linking the next and previous item. This allows for a robust system.
The data layout is as follows:
````
Block|Block|Block etc.
Block =
Meta Data|Data
Meta data =
4 bytes (preveus block address start)|4 bytes (next block address start)|4 bytes (curent[this] block size)| 4 bytes (curent[this] block flag)
```
BlockFlags :
```
Allocated = 0,
Free = 1,
```
the final layout looks like this:
```
4 bytes|4 bytes|4 bytes|4 bytes | (size of Block) bytes | 4 bytes|4 bytes|4 bytes | 4 bytes | (size of Block) bytes | etc
```
Note:
this means the smallest size an Block can occupy is 17 bytes, 16 bytes for the header and 1 for the smallest data type a byte.
# Usage
### Allocation
Allocating a block happens by finding the first free block and split it (if necessary).
## Deallocation
Freeing a block is easy set its flag (in the metadata) to free.

View file

@ -8,39 +8,39 @@ namespace DebugCompiler
[TestFixture]
public class RunKernels
{
[Test]
public void Test([ValueSource(typeof(MySource), nameof(MySource.ProvideData))] Type kernelToRun)
{
var xEngine = new Engine();
// Sets the time before an error is registered. For example if set to 60 then if a kernel runs for more than 60 seconds then
// that kernel will be marked as a failiure and terminated
xEngine.AllowedSecondsInKernel = 1800;
//[Test]
//public void Test([ValueSource(typeof(MySource), nameof(MySource.ProvideData))] Type kernelToRun)
//{
// var xEngine = new Engine();
// // Sets the time before an error is registered. For example if set to 60 then if a kernel runs for more than 60 seconds then
// // that kernel will be marked as a failiure and terminated
// xEngine.AllowedSecondsInKernel = 1800;
// If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are run.
xEngine.RunTargets.Add(RunTargetEnum.Bochs);
// // If you want to test only specific platforms, add them to the list, like next line. By default, all platforms are run.
// xEngine.RunTargets.Add(RunTargetEnum.Bochs);
// If you're working on the compiler (or other lower parts), you can choose to run the compiler in process
// one thing to keep in mind though, is that this only works with 1 kernel at a time!
xEngine.RunIL2CPUInProcess = false;
xEngine.TraceAssembliesLevel = TraceAssemblies.User;
xEngine.EnableStackCorruptionChecks = true;
xEngine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
// // If you're working on the compiler (or other lower parts), you can choose to run the compiler in process
// // one thing to keep in mind though, is that this only works with 1 kernel at a time!
// xEngine.RunIL2CPUInProcess = false;
// xEngine.TraceAssembliesLevel = TraceAssemblies.User;
// xEngine.EnableStackCorruptionChecks = true;
// xEngine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions;
// Select kernels to be tested by adding them to the engine
xEngine.AddKernel(kernelToRun.Assembly.Location);
// // Select kernels to be tested by adding them to the engine
// xEngine.AddKernel(kernelToRun.Assembly.Location);
xEngine.OutputHandler = new TestOutputHandler();
// xEngine.OutputHandler = new TestOutputHandler();
Assert.IsTrue(xEngine.Execute());
// Assert.IsTrue(xEngine.Execute());
}
//}
private class TestOutputHandler: OutputHandlerFullTextBase
{
protected override void Log(string message)
{
TestContext.WriteLine(String.Concat(DateTime.Now.ToString("hh:mm:ss.ffffff "), new String(' ', mLogLevel * 2), message));
}
}
//private class TestOutputHandler: OutputHandlerFullTextBase
//{
// protected override void Log(string message)
// {
// TestContext.WriteLine(String.Concat(DateTime.Now.ToString("hh:mm:ss.ffffff "), new String(' ', mLogLevel * 2), message));
// }
//}
}
}

View file

@ -8,6 +8,9 @@ build_script:
rem %APPVEYOR_BUILD_FOLDER%
nuget restore "source\Cosmos.sln"
msbuild "source\Builder.sln" /maxcpucount /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Platform=x86 /p:Configuration=Debug /p:DeployExtension=false
@ -50,4 +53,6 @@ notifications:
on_build_failure: true
on_build_status_changed: true
matrix:
fast_finish: true
fast_finish: true
artifacts:
- path: source\TestResults\TestResult.xml

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cosmos.Core.Memory.Test {
static public class CRAM {
}
}

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cosmos.Core.Memory.Test</RootNamespace>
<AssemblyName>Cosmos.Core.Memory.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="CRAM.cs" />
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cosmos.Core.Memory.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cosmos.Core.Memory.Test")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("901ea2c4-5e9c-44e8-b6d2-3b23dee6d61b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,11 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Cosmos.Core.Memory.Test {
[TestClass]
public class UnitTest1 {
[TestMethod]
public void TestMethod1() {
}
}
}

View file

@ -249,6 +249,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Compiler.Tests.Metho
EndProject
Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "Cosmos.Compiler.Tests.MethodTestsBoot", "..\Tests\Cosmos.Compiler.Tests.MethodTests\Cosmos.Compiler.Tests.MethodTestsBoot.Cosmos", "{0FEE977D-AE52-4381-B513-71C5C1982ED4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Core.Memory.Test", "Cosmos.Core.Memory.Test\Cosmos.Core.Memory.Test.csproj", "{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1105,6 +1107,18 @@ Global
{0FEE977D-AE52-4381-B513-71C5C1982ED4}.Release|x64.Build.0 = Debug|x86
{0FEE977D-AE52-4381-B513-71C5C1982ED4}.Release|x86.ActiveCfg = Debug|x86
{0FEE977D-AE52-4381-B513-71C5C1982ED4}.Release|x86.Build.0 = Debug|x86
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|x64.ActiveCfg = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|x64.Build.0 = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|x86.ActiveCfg = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Debug|x86.Build.0 = Debug|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|Any CPU.Build.0 = Release|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|x64.ActiveCfg = Release|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|x64.Build.0 = Release|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|x86.ActiveCfg = Release|Any CPU
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1204,5 +1218,6 @@ Global
{C1D525C4-B072-4F2F-94BF-4862E6727C4B} = {9637A680-F8E9-4925-A4E4-00045205EC04}
{FE8B9F39-7C96-4866-9A18-386735895CEE} = {F104F6BC-EF8E-4408-A786-D570D7565231}
{0FEE977D-AE52-4381-B513-71C5C1982ED4} = {F104F6BC-EF8E-4408-A786-D570D7565231}
{901EA2C4-5E9C-44E8-B6D2-3B23DEE6D61B} = {9637A680-F8E9-4925-A4E4-00045205EC04}
EndGlobalSection
EndGlobal