Skip to content

Commit

Permalink
Merge branch 'master' into pr/2802
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaProductions committed Jul 10, 2024
2 parents 19a34f0 + 1648d48 commit 06eac0d
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 104 deletions.
12 changes: 8 additions & 4 deletions Docs/articles/Installation/DevKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

* 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/).

* [Visual Studio 2022 Community](https://visualstudio.microsoft.com/vs/)
* [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".

Expand All @@ -29,15 +31,15 @@
* QEMU or any other virtual machine. See [Running](https://cosmosos.github.io/articles/Installation/Running.html) for more information.

### Installation
Git cline the current source code of Cosmos.
Git clone the current source code of Cosmos.
Run `make` to build Cosmos. Cosmos will clone all the required repos, build itself, and install it and its nuget packages to the system automatically.

## MacOS (Apple Silicon/Intel)
It is currently difficult to build Cosmos on Apple Silicon Devices. So, we are going to build DevKit on Docker (Virtual Environment Service).

### Prerequisites

* Docker (`brew cask install docker`)
* Docker (`brew install --cask docker`)
* QEMU or any other virtual machine. See [Running](https://cosmosos.github.io/articles/Installation/Running.html) for more information.


Expand All @@ -55,7 +57,7 @@ This will take a while. If there is no error, you successfully installed Cosmos

If you are using custom Cosmos repos, you will need to clone them all manually, as the installer script will only pull from https://github.com/CosmosOS/

A tree diagram of the source should look like the following:
A tree diagram of the source should look like the following:

<img src="https://raw.githubusercontent.com/CosmosOS/Cosmos/master/Docs/images/Dir.png" width="200">

Expand All @@ -73,7 +75,9 @@ Although Cosmos typically uninstalls previous kits before installing a new one;
If you have more than 1 version of Visual Studio *(such as both 2022 and 2019)*, this bug can occur. Try running `dotnet Project Templates` to get them back.

### 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. 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/`.

*Last updated on 24 March 2024.*
*Last updated on 20 April 2024.*

2 changes: 1 addition & 1 deletion Docs/articles/Kernel/VFS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is essential for using the VFS.
We start with creating a global CosmosVFS, this line should appear outside of any function, and before the BeforeRun() function.

```C#
Sys.FileSystem.CosmosVFS fs = new Cosmos.FileSystem.CosmosVFS();
Sys.FileSystem.CosmosVFS fs = new Cosmos.System.FileSystem.CosmosVFS();
```

Next, we register our VFS at the VFS manager, this will initiate the VFS and make it usable, add this to your kernel's BeforeRun() function:
Expand Down
77 changes: 49 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,52 @@ COMMON_DIR = $(THISDIR)/../Common
GIT = git
DOTNET = dotnet

BUILDMODE=Release
GITFLAGS = clone --depth=1
DOTNETFLAGS = -v:q -nologo
DOTNETFLAGS = -nologo -v:q -c:$(BUILDMODE)
GREEN = \033[0;32m
YELLOW = \033[1;33m
DEFAULT = \033[0m

.PHONY: all
all: $(IL2CPU_DIR) $(XSHARP_DIR) $(COMMON_DIR)
@printf "${YELLOW}Cosmos${DEFAULT} DevKit Installer\n"
@# Elapsed time is stored in a temporary file, deleted post-install.
@date +%s > _time_$@.txt
@$(MAKE) build
@$(MAKE) publish
@sudo $(MAKE) install
@$(MAKE) nuget-install
@echo "============================================"
@echo "| Cosmos has been installed successfully! |"
@echo "============================================"
@$(MAKE) template-install
@printf "To create a Cosmos kernel, run \'dotnet new cosmosCSKernel -n \{name\}\'"
@printf "Build log file saved to ${GREEN}$(THISDIR)/build${date}.log${DEFAULT}\n"
@printf "============================================\n"
@printf "| ${YELLOW}Cosmos${DEFAULT} has been installed successfully! |\n"
@printf "============================================\n"
@printf "Took ${YELLOW}$$(($$(date +%s)-$$(cat _time_$@.txt)))s${DEFAULT} to build\n"
@rm _time_$@.txt

$(IL2CPU_DIR):
@echo "Cloning Cosmos/IL2CPU"
@$(GIT) $(GITFLAGS) --branch=$(IL2CPU_BRANCH) $(IL2CPU_URL) $(THISDIR)/../IL2CPU
@printf "Cloning ${GREEN}Cosmos/IL2CPU${DEFAULT}\n"
@$(GIT) $(GITFLAGS) --branch=$(IL2CPU_BRANCH) $(IL2CPU_URL) $(IL2CPU_DIR)

$(XSHARP_DIR):
@echo "Cloning Cosmos/XSharp"
@$(GIT) $(GITFLAGS) --branch=$(XSHARP_BRANCH) $(XSHARP_URL) $(THISDIR)/../XSharp
@printf "Cloning ${GREEN}Cosmos/XSharp${DEFAULT}\n"
@$(GIT) $(GITFLAGS) --branch=$(XSHARP_BRANCH) $(XSHARP_URL) $(XSHARP_DIR)

$(COMMON_DIR):
@echo "Cloning Cosmos/Common"
@$(GIT) $(GITFLAGS) --branch=$(COMMON_BRANCH) $(COMMON_URL) $(THISDIR)/../Common
@printf "Cloning ${GREEN}Cosmos/Common${DEFAULT}\n"
@$(GIT) $(GITFLAGS) --branch=$(COMMON_BRANCH) $(COMMON_URL) $(COMMON_DIR)


.PHONY: build
build:
@echo "Building IL2CPU"
@printf "Building ${GREEN}IL2CPU${DEFAULT}\n"
@$(DOTNET) clean $(IL2CPU_DIR)
@$(DOTNET) build $(IL2CPU_DIR) $(DOTNETFLAGS)
@$(DOTNET) pack $(IL2CPU_DIR) $(DOTNETFLAGS)

@echo "Building Cosmos"
@printf "Building ${GREEN}Cosmos${DEFAULT}\n"

@$(DOTNET) clean $(THISDIR)/source/Cosmos.Common
@$(DOTNET) clean $(THISDIR)/source/Cosmos.Debug.Kernel
Expand All @@ -74,7 +87,7 @@ build:
@$(DOTNET) pack $(THISDIR)/source/Cosmos.Build.Tasks $(DOTNETFLAGS)
@$(DOTNET) pack $(THISDIR)/source/Cosmos.Plugs $(DOTNETFLAGS)

@echo "Building X#"
@printf "Building ${GREEN}X#${DEFAULT}\n"
@$(DOTNET) clean $(XSHARP_DIR)/source/XSharp/XSharp
@$(DOTNET) clean $(XSHARP_DIR)/source/Spruce

Expand All @@ -84,23 +97,23 @@ build:

.PHONY: publish
publish:
@echo "Publishing IL2CPU"
@printf "Publishing ${GREEN}IL2CPU${DEFAULT}\n"
$(DOTNET) publish $(IL2CPU_DIR)/source/IL2CPU -r linux-x64 --self-contained $(DOTNETFLAGS)

@echo "Publishing Cosmos"
@printf "Publishing ${GREEN}Cosmos${DEFAULT}\n"
@$(DOTNET) publish $(THISDIR)/source/Cosmos.Core_Plugs $(DOTNETFLAGS)
@$(DOTNET) publish $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm $(DOTNETFLAGS)
@$(DOTNET) publish $(THISDIR)/source/Cosmos.HAL2 $(DOTNETFLAGS)
@$(DOTNET) publish $(THISDIR)/source/Cosmos.System2_Plugs $(DOTNETFLAGS)
@$(DOTNET) publish $(THISDIR)/source/Cosmos.Plugs $(DOTNETFLAGS)

@echo "Publishing X#"
@printf "Publishing ${GREEN}X#${DEFAULT}\n"
@$(DOTNET) publish $(XSHARP_DIR)/source/XSharp/XSharp $(DOTNETFLAGS)
@$(DOTNET) publish $(XSHARP_DIR)/source/Spruce $(DOTNETFLAGS)

.PHONY: install
install:
@echo "Installing to" $(DESTDIR)
@printf "Installing to ${YELLOW}$(DESTDIR)${DEFAULT}\n"
@mkdir -p $(DESTDIR)/Cosmos
@mkdir -p $(DESTDIR)/XSharp/DebugStub
@mkdir -p $(DESTDIR)/Build/ISO
Expand All @@ -109,31 +122,39 @@ install:
@mkdir -p $(DESTDIR)/Build/VMware/Workstation
@mkdir -p $(DESTDIR)/Packages
@mkdir -p $(DESTDIR)/Kernel
@cp -r $(IL2CPU_DIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(THISDIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(XSHARP_DIR)/artifacts/Release/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(IL2CPU_DIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(THISDIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(XSHARP_DIR)/artifacts/$(BUILDMODE)/nupkg/*.nupkg $(DESTDIR)/Packages/
@cp -r $(IL2CPU_DIR)/source/Cosmos.Core.DebugStub/*.xs $(DESTDIR)/XSharp/DebugStub/

@cp -r $(THISDIR)/Artwork/XSharp/XSharp.ico $(DESTDIR)/XSharp/
@cp -r $(THISDIR)/Artwork/Cosmos.ico $(DESTDIR)/

@cp -r $(IL2CPU_DIR)/source/IL2CPU/bin/Release/*/linux-x64/publish/* $(DESTDIR)/Build/IL2CPU/
@cp -r $(THISDIR)/source/Cosmos.Core_Plugs/bin/Release/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.System2_Plugs/bin/Release/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.HAL2/bin/Release/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm/bin/Debug/netstandard2.0/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(IL2CPU_DIR)/source/IL2CPU/bin/$(BUILDMODE)/*/linux-x64/publish/* $(DESTDIR)/Build/IL2CPU/
@cp -r $(THISDIR)/source/Cosmos.Core_Plugs/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.System2_Plugs/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.HAL2/bin/$(BUILDMODE)/*/publish/*.dll $(DESTDIR)/Kernel/
@cp -r $(THISDIR)/source/Cosmos.Debug.Kernel.Plugs.Asm/bin/$(BUILDMODE)/netstandard2.0/publish/*.dll $(DESTDIR)/Kernel/

@cp -r $(THISDIR)/Build/HyperV/*.vhdx $(DESTDIR)/Build/HyperV/
@cp -r $(THISDIR)/Build/VMWare/Workstation/* $(DESTDIR)/Build/VMware/Workstation/
@cp -r $(THISDIR)/Build/syslinux/* $(DESTDIR)/Build/ISO/
@echo $(DESTDIR) > /etc/CosmosUserKit.cfg
@printf $(DESTDIR) > /etc/CosmosUserKit.cfg

.PHONY: nuget-install
nuget-install:
@echo "Installing Nuget packages"
@printf "Installing ${GREEN}Nuget packages${DEFAULT}\n"

@rm -r -f ~/.nuget/packages/cosmos.*/
@rm -r -f ~/.nuget/packages/il2cpu.*/

@$(DOTNET) nuget remove source "Cosmos Local Package Feed" || true
@$(DOTNET) nuget add source $(DESTDIR)/Packages/ -n "Cosmos Local Package Feed"
@$(DOTNET) nuget add source $(DESTDIR)/Packages/ -n "Cosmos Local Package Feed"

.PHONY: template-install
template-install:
@printf "Installing ${GREEN}C# Template packages${DEFAULT}\n"
@-dotnet new uninstall $(THISDIR)/source/templates/csharp/
@printf "If the template was not installed, you can ignore this\n"
@dotnet new -i $(THISDIR)/source/templates/csharp/
#TODO: Uninstall
2 changes: 1 addition & 1 deletion source/Cosmos.HAL2/BlockDevice/BlockDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class BlockDevice : Device
/// </summary>
/// <param name="aBlockCount">Number of blocks to alloc.</param>
/// <returns>byte array.</returns>
public byte[] NewBlockArray(uint aBlockCount)
public byte[] NewBlockArray(ulong aBlockCount)
{
return new byte[aBlockCount * mBlockSize];
}
Expand Down
12 changes: 6 additions & 6 deletions source/Cosmos.HAL2/BlockDevice/EBR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class EBR
public class PartInfo
{
public readonly byte SystemID;
public readonly uint StartSector;
public readonly uint SectorCount;
public readonly ulong StartSector;
public readonly ulong SectorCount;

public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount)
public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount)
{
SystemID = aSystemID;
StartSector = aStartSector;
Expand All @@ -30,7 +30,7 @@ public EBR(byte[] aEBR)
ParsePartition(aEBR, 462);
}

protected void ParsePartition(byte[] aEBR, uint aLoc)
protected void ParsePartition(byte[] aEBR, int aLoc) //This should be int. ToUInt64(byte[] value, int)!!
{
byte xSystemID = aEBR[aLoc + 4];
// SystemID = 0 means no partition
Expand All @@ -41,8 +41,8 @@ protected void ParsePartition(byte[] aEBR, uint aLoc)
}
else if (xSystemID != 0)
{
uint xStartSector = BitConverter.ToUInt32(aEBR, (int)aLoc + 8);
uint xSectorCount = BitConverter.ToUInt32(aEBR, (int)aLoc + 12);
ulong xStartSector = BitConverter.ToUInt32(aEBR, aLoc + 8);
ulong xSectorCount = BitConverter.ToUInt32(aEBR, aLoc + 12);

var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount);
Partitions.Add(xPartInfo);
Expand Down
12 changes: 6 additions & 6 deletions source/Cosmos.HAL2/BlockDevice/GPT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ public GPT(BlockDevice aBlockDevice)

// Start of parition entries
ulong partEntryStart = BitConverter.ToUInt64(GPTHeader, 72);
uint numParitions = BitConverter.ToUInt32(GPTHeader, 80);
uint partSize = BitConverter.ToUInt32(GPTHeader, 84);
ulong numParitions = BitConverter.ToUInt32(GPTHeader, 80);
ulong partSize = BitConverter.ToUInt32(GPTHeader, 84);

uint paritionsPerSector = 512 / partSize;
ulong paritionsPerSector = 512 / partSize;

for (ulong i = 0; i < numParitions/paritionsPerSector; i++)
for (ulong i = 0; i < numParitions / paritionsPerSector; i++)
{

byte[] partData = new byte[512];
aBlockDevice.ReadBlock(partEntryStart + i, 1, ref partData);

for (uint j = 0; j < paritionsPerSector; j++)
{
ParseParition(partData, j * partSize);
ParseParition(partData, j * (long)partSize);
}
}
}

private void ParseParition(byte[] partData, uint off)
private void ParseParition(byte[] partData, long off)
{
byte[] guidArray = new byte[16];

Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.HAL2/BlockDevice/IDE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ internal static void ScanAndInitPartitions(BlockDevice device)
}
}
}
}
}
18 changes: 9 additions & 9 deletions source/Cosmos.HAL2/BlockDevice/MBR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class MBR
public class PartInfo
{
public readonly byte SystemID;
public readonly uint StartSector;
public readonly uint SectorCount;
public readonly ulong StartSector;
public readonly ulong SectorCount;

public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount)
public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount)
{
SystemID = aSystemID;
StartSector = aStartSector;
Expand All @@ -41,7 +41,7 @@ public MBR(BlockDevice device)
ParsePartition(aMBR, 494);
}

protected void ParsePartition(byte[] aMBR, uint aLoc)
protected void ParsePartition(byte[] aMBR, ulong aLoc)
{
byte xSystemID = aMBR[aLoc + 4];
// SystemID = 0 means no partition
Expand All @@ -56,8 +56,8 @@ protected void ParsePartition(byte[] aMBR, uint aLoc)
}
else if (xSystemID != 0)
{
uint xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8);
uint xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12);
ulong xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8);
ulong xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12);

var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount);
Partitions.Add(xPartInfo);
Expand Down Expand Up @@ -128,11 +128,11 @@ public void WritePartitionInformation(Partition partition, byte PartitionNo)
partition.Host.ReadBlock(0, 1, ref mb.memory);
//TO DO: Implement the CHS starting / ending sector adresses and partition type
mb.Write8((uint)(446 + (PartitionNo * 16) + 4), 0x0B);
mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint) partition.StartingSector);
mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint) partition.BlockCount);
mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint)partition.StartingSector);
mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint)partition.BlockCount);
partition.Host.WriteBlock(0, 1, ref mb.memory);
ParsePartition(mb.memory, 446 + (uint)(PartitionNo * 16));

}
}
}
Loading

0 comments on commit 06eac0d

Please sign in to comment.