Skip to content

Commit

Permalink
Merge branch 'master' into feature/auto_gc
Browse files Browse the repository at this point in the history
  • Loading branch information
quajak authored Oct 13, 2023
2 parents fcc8c63 + 36833d0 commit 6abcaf3
Show file tree
Hide file tree
Showing 107 changed files with 1,830 additions and 459 deletions.
13 changes: 13 additions & 0 deletions Build.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DapperExtensions.StrongName
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IL2CPU.Debug.Symbols.Net48", "..\IL2CPU\source\IL2CPU.Debug.Symbols.Net48\IL2CPU.Debug.Symbols.Net48.csproj", "{440CE2D4-024F-45D3-A95C-9077CC0A51E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Plugs", "source\Cosmos.Plugs\Cosmos.Plugs.csproj", "{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -428,6 +430,16 @@ Global
{440CE2D4-024F-45D3-A95C-9077CC0A51E3}.Release-CI|Any CPU.Build.0 = Release|Any CPU
{440CE2D4-024F-45D3-A95C-9077CC0A51E3}.TEST|Any CPU.ActiveCfg = TEST|Any CPU
{440CE2D4-024F-45D3-A95C-9077CC0A51E3}.TEST|Any CPU.Build.0 = TEST|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Debug-CI|Any CPU.ActiveCfg = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Debug-CI|Any CPU.Build.0 = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Release|Any CPU.Build.0 = Release|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Release-CI|Any CPU.ActiveCfg = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.Release-CI|Any CPU.Build.0 = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.TEST|Any CPU.ActiveCfg = Debug|Any CPU
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21}.TEST|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -470,6 +482,7 @@ Global
{9413B5A0-1120-43AD-8784-8A3726C1898C} = {FF5BAFDE-AE9D-438D-935A-86B33EE0A758}
{28F18214-DFF8-4A30-BA24-4F32C20CA910} = {FF5BAFDE-AE9D-438D-935A-86B33EE0A758}
{440CE2D4-024F-45D3-A95C-9077CC0A51E3} = {FF5BAFDE-AE9D-438D-935A-86B33EE0A758}
{509FB0F8-6D0F-424F-9C6B-9E5818B06B21} = {4D3F3613-E112-4013-AB81-B8CCED78A555}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E5429BF0-2CEE-45B0-BC73-2188A409E1D3}
Expand Down
File renamed without changes.
File renamed without changes.
Binary file removed Build/Tools/cygwin/cygiconv-2.dll
Binary file not shown.
Binary file removed Build/Tools/cygwin/cygintl-3.dll
Binary file not shown.
Binary file modified Build/Tools/cygwin/cygwin1.dll
Binary file not shown.
Binary file modified Build/Tools/cygwin/ld.exe
Binary file not shown.
7 changes: 7 additions & 0 deletions Build/Tools/cygwin/objdump.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ECHO OFF

REM %1 == ToolPath
REM %2 == ElfFile
REM %3 == MapFile

"%~1\objdump.exe" --wide --syms "%~2" > "%~3"
Binary file modified Build/Tools/cygwin/objdump.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions Build/Tools/cygwin/objdump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# %1 == ToolPath
# %2 == ElfFile
# %3 == MapFile
objdump --wide --syms "$2" > "$3"
Binary file added Build/VMWare/Workstation/FilesystemTest.vmdk
Binary file not shown.
12 changes: 12 additions & 0 deletions Docs/articles/Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Devkit changelog

## c5c087c697d106348adbcff86d5d43331500e648 (update then merged in)

### Features

* X# is now packaged as a nuget package
* Plugs are now packaged as a nuget package rather then been hard coded in build scripts

### Breaking changes

Plugs are now included via a nuget package, to update cosmos past this commit you need to add the `Cosmos.Plugs` package to your kernel project. Don't forget to tick the `Include prerelease` checkbox and to set the package origin to `All`!
8 changes: 4 additions & 4 deletions Docs/articles/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ console window, you will see the following:

![](images/SNAG-0003.png)

This is your operating system running in VMWare Player! Cosmos can of course
also be booted in VMWare Workstation, Hyper-V, Virtual PC, Bochs, or on real
hardware. But by default Cosmos uses VMWare Player because it is both free,
This is your operating system running in VMware Player! Cosmos can of course
also be booted in VMware Workstation, Hyper-V, Virtual PC, Bochs, or on real
hardware. But by default Cosmos uses VMware Player because it is both free,
and reliable. Cosmos can even debug in Visual Studio, even when running on
another machine.

Expand Down Expand Up @@ -70,7 +70,7 @@ over (F10) is not supported yet.

The debugger uses the serial port to communicate. Because of this, debugging
only works wtih virtualization environments that support serial ports such as
VMWare. QEMU supports serial ports as well, but its serial port implementation
VMware. QEMU supports serial ports as well, but its serial port implementation
is seriously broken on Windows and makes debugging impossible using QEMU. To
debug on real hardware, you must use a physical serial cable. In the future
Cosmos will also support debugging over Ethernet.
Expand Down
28 changes: 8 additions & 20 deletions Docs/articles/Installation/DevKit.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
# Dev Kit Installation

### Prerequisites for Windows

* (Free) source code of Development Kit from [Cosmos on GitHub](https://github.com/CosmosOS/Cosmos)
* You must clone the repository using Git. For a detailed walkthrough, [see here](https://help.github.com/articles/fork-a-repo/).
* When following the tutorial, replace *OctoCat* with *CosmosOS* and *Spoon-Knife* with *Cosmos*.
* (Free) [Visual Studio 2022 Community](https://visualstudio.microsoft.com/vs/)
* (Free) [InnoSetup QuickStart Kit](http://www.jrsoftware.org/isdl.php#qsp)
* (Free) [InnoSetup](http://www.jrsoftware.org/isdl.php#qsp)
* This is required to build the setup kit which is used to build and install the Visual Studio integration libaries for Cosmos.
* During install it will ask you about optional components to install. Be sure you check "Install Inno Setup Preprocessor".
* Visual Studio SDK: [download here](https://www.microsoft.com/en-us/download/details.aspx?id=40758).

### Prerequisites for Linux

* .NET 6 SDK: [Download .NET SDK](https://learn.microsoft.com/en-us/dotnet/core/install/linux)
* Make
* .NET SDK (6+): [Download .NET SDK](https://learn.microsoft.com/en-us/dotnet/core/install/linux)
* Make (`apt install make`)
* Yasm (`apt install yasm`)
* Xorriso (`apt install xorriso`)
* QEMU or any other virtual machine
* QEMU or any other virtual machine. See [Running](https://cosmosos.github.io/articles/Installation/Running.html) for more information.

### Installation on Windows

* Look in the downloaded sources and run **install-VS2022.bat** with admin privileges (UAC will ask for permission), needed for install in system directories.
* When the installation is complete, Visual Studio will automatically open and you may begin programming with your new, modified copy of Cosmos.

## Arguments for the 'install-VS2022.bat' file
The `install-VS2022.bat` accepts the following parameters :

- `-USERKIT` Run installer for the User Kit only. By default installer build and install Dev Kit.
- `-RESETHIVE` Reset Visual Studio Experimental Hive after installation.
- `-NOTASK` When specified installer would be run directly instead of running as the task in the Task Scheduler
- `-NOCLEAN` Don't clean solution before run installer.
- `-NOVSLAUNCH` Don't launch VS after installation.
- `-IGNOREVS` Ignore running VS during installation.
- `-VSEXPHIVE` or `/VSEXPHIVE` Use Visual Studio Experimental Hive for installation.

### Installation on Linux
Run `make all` to build Cosmos. Run `sudo make install`. Make sure to run `make nuget-install` under your user account, and not as sudo.
Run `make` to build Cosmos. Cosmos will clone all the required repos, build itself, and install it and it's nuget packages to the system automatically.

### dotnet Project Templates
If you are using linux or prefer not using Visual Studio for your projects, you can install the dotnet project template using `dotnet new --install .\source\templates\csharp\` assuming you are currently in the Cosmos base directory.
If you are using linux or prefer not using Visual Studio for your projects, you can install the dotnet project template using `dotnet new --install ./source/templates/csharp/` assuming you are currently in the Cosmos base directory.
After installing the template use `dotnet new cosmosCSKernel -n {name}` to create a new Cosmos Kernel project.
The dotnet template can be removed at a later time using `dotnet new --uninstall .\source\templates\csharp\`.
The dotnet template can be removed at a later time using `dotnet new --uninstall ./source/templates/csharp/`.
2 changes: 1 addition & 1 deletion Docs/articles/Installation/Running.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ VMWare Workstation can be downloaded for free trial [here](https://www.vmware.co

Not officially supported at this time, but can be done. Just use the ISO option above with debugging turned off.

QEMU can be downloaded [here](https://qemu.weilnetz.de/w64/)
QEMU can be downloaded [here](https://www.qemu.org/download/)

## Bochs

Expand Down
12 changes: 12 additions & 0 deletions Docs/articles/Internals/object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Object

## Memory Layout

Each object is allocated with a header of three uints. The first uint is the type of the object, the second uint is the instance type of object (normal, boxed, array etc) and the third is the size in memory.

## Garbage Collector Information

The garbage collector itself also alloctes its own header of 1 uint (2 ushort). The first ushort is the allocated size of the object (this includes the size of both headers) while the second tracks the GC information.
The GC information is made up of a 1bit flag (the lowest bit) used to track if the GC has hit the object during the sweep phase already and the upper 7 bits count how many static references there are to the object.

Combined in memory we have the format | ushort: memory size | ushort: gc info | uint: object type | uint: instance type | uint: object size | variable: object data |
2 changes: 2 additions & 0 deletions Docs/articles/Kernel/Audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var audioManager = new AudioManager()
audioManager.Enable();
```

The sampleAudioBytes are the bytes of a ttf audio file. You can read it from [VFS](https://cosmosos.github.io/articles/Kernel/VFS.html) or using [ManifestResourceStream](https://cosmosos.github.io/articles/Kernel/ManifestResouceStream.html)

## Audio Streams
An `AudioStream` is an object that can provide sample data to audio buffers. By design, the base `AudioStream` class does not have any length or position properties, as audio streams may be infinite - for example, an output stream from a microphone, or an audio mixer. All seekable streams inherit from the class `SeekableAudioStream`, which provides functionality for accessing the position/length properties and allows methods to determine whether they accept infinite and finite streams, or only finite streams.

Expand Down
30 changes: 20 additions & 10 deletions Docs/articles/Kernel/CGS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

The Cosmos Graphic Subsystem (CGS from now on) is based on the abstraction of Canvas that is an empty space in which the user of CGS can draw its content. CGS is not a widget toolkit as Winforms or Gnome / GTK but is thought to be more lower level and it will be the basic in which widget toolkits will be implemented. CGS hides the graphics driver (so far VGA, VBE and SVGA II) used and it is thought to be the universal way to draw on the screen in Cosmos.
The Cosmos Graphic Subsystem (CGS from now on) is based on the abstraction of Canvas that is an empty space in which the user of CGS can draw its content. CGS is not a widget toolkit as Winforms or Gnome / GTK but is thought to be more lower level and it will be the basic in which widget toolkits will be implemented. CGS hides the graphics driver (so far VGA, VBE and SVGAII) used and it is thought to be the universal way to draw on the screen in Cosmos.

# FullScreenCanvas
The `FullScreenCanvas` provides two methods to get a canvas instance for the screen. It automatically chooses the best available driver to use.
Expand All @@ -10,6 +10,7 @@ The `FullScreenCanvas` provides two methods to get a canvas instance for the scr
`public static Canvas GetFullScreenCanvas()`: gets the instance of Canvas representing the complete screen in the best driver available on your platform

# Canvas

## List of Properties of the Canvas class

`Mode`: get / set the mode of the video card to mode. It throws if the selected mode is not supported by the video card
Expand All @@ -20,11 +21,11 @@ The `FullScreenCanvas` provides two methods to get a canvas instance for the scr

`Clear(Color color)` clear the entire Canvas using the specified color as background

`void DrawPoint(Pen pen, int x, int y)` draws a point at the coordinates specified by x and y with the specified pen
`void DrawPoint(Color color, int x, int y)` draws a point at the coordinates specified by x and y with the specified pen

`void DrawLine(Pen pen, int x_start, int y_start, int x_end, int y_end)` draws a line at the coordinates specified by x_start, y_start and x_end, y_end with the specified pen
`void DrawLine(Color color, int x_start, int y_start, int x_end, int y_end)` draws a line at the coordinates specified by x_start, y_start and x_end, y_end with the specified pen

`void DrawRectangle(Pen pen, int x_start, int y_start,int width, int height)` draws a rectangle specified by a coordinate pair, a width, and a height with the specified pen
`void DrawRectangle(Color color, int x_start, int y_start,int width, int height)` draws a rectangle specified by a coordinate pair, a width, and a height with the specified pen

`void DrawImage(Image image, int x, int y)` draws an image at the x and y specified

Expand All @@ -34,7 +35,7 @@ The `FullScreenCanvas` provides two methods to get a canvas instance for the scr


Really simple right?
# A working example
# A working example (devkit only!)
```CSharp
using System;
using Sys = Cosmos.System;
Expand Down Expand Up @@ -69,17 +70,21 @@ namespace GraphicTest
// If all works correctly you should not really see this :-)
Console.WriteLine("Cosmos booted successfully. Let's go in Graphical Mode");

// You don't have to specify the Mode, but here we do to show that you can.
/*
You don't have to specify the Mode, but here we do to show that you can.
To not specify the Mode and pick the best one, use:
canvas = FullScreenCanvas.GetFullScreenCanvas();
*/
canvas = FullScreenCanvas.GetFullScreenCanvas(new Mode(640, 480, ColorDepth.ColorDepth32));

// This will clear the canvas with the specified color.
canvas.Clear(Color.Blue);
}

protected override void Run()
{
try
{
Pen pen = new Pen();

// A red Point
canvas.DrawPoint(Color.Red, 69, 69);

Expand Down Expand Up @@ -108,7 +113,7 @@ namespace GraphicTest
}
catch (Exception e)
{
mDebugger.Send("Exception occurred: " + e.Message);
Debugger.Send("Exception occurred: " + e.Message);
Sys.Power.Shutdown();
}
}
Expand All @@ -117,9 +122,14 @@ namespace GraphicTest
```
# Limitations of the current implementation

1. Only 32 bit color depth is actually supported, the API provides methods to set a resolution with 24, 16, 8 and 4 bit but the low level Bochs driver has not yet implemented them.
1. Only 32 bit color depth is actually supported, the API provides methods to set a resolution with 24, 16, 8 and 4 bit but the low level Bochs driver has not yet implemented them.
If you use SVGAIICanvas, you can use 24 bit Color depth and if you use VGACanvas there are 3 modes: 320x200x8, 640x480x4 and 720x480x4.

2. In addition, some other nice things could be implemented:
- Plugging System.Drawing functions for easier manipulation of colors

3. CGS interacts badly with the uncaught exceptions and Kernel.Stop method: the screen will freeze without displaying any error message whatsoever. You must use the Sys.Power.Shutdown() function to properly shut down your computer.

# Old examples

In the web there are a lot of tutorials explaining how to use graphics in Cosmos, but most of them are outdated. Just remember that the new Mouse class is Sys.MouseManager and Pen has been replaced with Color.
3 changes: 3 additions & 0 deletions Docs/articles/Kernel/Levels.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Levels

**Warning** This article is for a older version of Cosmos and it doesn't work for current version.

The security model of Cosmos will evolve and mature as
Cosmos does, however the base model is presented here.

Expand Down
4 changes: 2 additions & 2 deletions Docs/articles/Kernel/ManifestResouceStream.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Manifest Resource Streams allow you to include data from the files as byte array
![image](https://user-images.githubusercontent.com/8559822/132468001-256b92d1-0b29-4db3-9ef5-3383bfdef023.png)
2. In the code reference the file using the following format (a static byte array with the attribute):
```
[ManifestResourceStream(ResourceName = {project_name}.{path}.{to}.{filename_with_extension})]
[ManifestResourceStream(ResourceName = "{project_name}.{path}.{to}.{filename_with_extension}")]
static byte[] file;
```
The field _must_ be static but the name of the field can be changed. You will also need to add `using IL2CPU.API.Attribs;` to the code.
The field _must_ be static but the name of the field (file) can be changed. You will also need to add `using IL2CPU.API.Attribs;` to the code.
For example, if the project is called Kernel and the file is `Data\Text.txt`, then `ResourceName = "Kernel.Data.Text.txt"`.

3. To access the data simply read from the byte array defined.
2 changes: 1 addition & 1 deletion Docs/articles/Kernel/Network.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ using(var xClient = new DnsClient())
## Get local IP address
```csharp
Console.WriteLine(NetworkConfiguration.CurrentAddress.ToString());
```
```
3 changes: 2 additions & 1 deletion Docs/articles/Kernel/OnBoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
If you need to disable drivers because you are developing your own, or in some cases just don't need them, you may do so by adding the OnBoot method to your kernel. For now, you can disable 3 drivers and disable a part of a driver, an example would be

```csharp
protected override void OnBoot() {
protected override void OnBoot()
{
Sys.Global.Init(GetTextScreen(),true,true,true,false);
}
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/articles/Kernel/Startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ On startup, the first thing that happens is that the BIOS of your computer loads
## Sys.Kernel.Start()

### What does it do?
`Kernel.Start()` does quite a bit of stuff. First, it checks if `System.String.Empty` was not... Uhh, thrown away by the compiler. Then it initializes the hardware bootstrap, then calls `OnBoot()`.
`Kernel.Start()` does quite a bit of stuff. First, it checks if `System.String.Empty` is null. If it is null, then it will just throw an exception. If it isn't, it just continues. After that check, `Kernel.Start()` initializes the hardware bootstrap, then calls `OnBoot()`.
> We have an article explaining what `OnBoot()` is.
Then, `Kernel.Start()` calls your `BeforeRun()` method, after it finishes, `Kernel.Start()` enables the hardware interrupts. Then it simply does a `while (!mStopped)` loop with your `Run()` method. After that, it calls an optional method called `AfterRun()`. By default, `AfterRun()` is just empty, so don't worry about nulls or something like that. Then it finishes. All of that is also try/catched too with the `A kernel exception has occurred` message.
Expand Down
Loading

0 comments on commit 6abcaf3

Please sign in to comment.