generated from mdpatelcsecon/charlotte-os-limine-rust-barebones
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6df5569
Showing
18 changed files
with
777 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Security check | ||
on: | ||
schedule: | ||
- cron: "0 6 * * 5,2" | ||
|
||
jobs: | ||
security-audit: | ||
uses: charlotte-os/devops/.github/workflows/security_audit.yml@main | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Test code | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
unit-test: | ||
uses: charlotte-os/devops/.github/workflows/unit_tests.yml@main | ||
secrets: inherit | ||
with: | ||
toolchain: nightly | ||
style-check: | ||
uses: charlotte-os/devops/.github/workflows/style_check.yml@main | ||
secrets: inherit | ||
with: | ||
toolchain: nightly | ||
benchmark: | ||
needs: [unit-test, style-check] | ||
uses: charlotte-os/devops/.github/workflows/benchmark.yml@main | ||
secrets: inherit | ||
with: | ||
toolchain: nightly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.iso | ||
ovmf-aarch64 | ||
ovmf-riscv64 | ||
ovmf-x86_64 | ||
kernel/target/** | ||
log.txt | ||
limine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "limine"] | ||
path = limine | ||
url = https://github.com/limine-bootloader/limine.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
#x86_64 | ||
|
||
default: run-x86_64-debug | ||
|
||
install-requirements: | ||
chmod +x ./tools/install-requirements.sh | ||
./tools/install-requirements.sh | ||
|
||
limine: | ||
@if [ ! -d "limine" ]; then \ | ||
git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1;\ | ||
fi | ||
make -C limine | ||
|
||
ovmf-x86_64: | ||
mkdir -p ovmf-x86_64 | ||
cd ovmf-x86_64 && curl -o OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd | ||
|
||
build-x86_64-debug: limine | ||
cd kernel && cargo build --target x86_64-unknown-none | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/x86_64-unknown-none/debug/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-x86_64-debug.iso | ||
rm -rf iso_root | ||
|
||
run-x86_64-debug: ovmf-x86_64 build-x86_64-debug | ||
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 2G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-debug.iso -boot d -serial stdio | ||
|
||
run-x86_64-debug-multicore: ovmf-x86_64 build-x86_64-debug | ||
qemu-system-x86_64 -enable-kvm -M q35 -smp 8 -cpu host -m 2G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-debug.iso -boot d -serial stdio | ||
|
||
run-x86_64-debug-numa: ovmf-x86_64 build-x86_64-debug | ||
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 8G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-debug.iso -boot d -serial stdio -smp 4 -object memory-backend-ram,size=4G,id=m0 -object memory-backend-ram,size=4G,id=m1 -numa node,memdev=m0,cpus=0-1,nodeid=0 -numa node,memdev=m1,cpus=2-3,nodeid=1 | ||
|
||
run-x86_64-extdb: ovmf-x86_64 build-x86_64-debug | ||
qemu-system-x86_64 -enable-kvm -s -S -M q35 -m 2G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-debug.iso -boot d -serial stdio | ||
|
||
run-x86_64-log: ovmf-x86_64 build-x86_64-debug | ||
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 12G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-debug.iso -boot d -serial file:log_x86_64.txt | ||
|
||
build-x86_64-release: limine | ||
cd kernel && cargo build --target x86_64-unknown-none --release | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/x86_64-unknown-none/release/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-x86_64-release.iso | ||
rm -rf iso_root | ||
|
||
run-x86_64-release: ovmf-x86_64 build-x86_64-release | ||
qemu-system-x86_64 -enable-kvm -M q35 -cpu host -m 12G -bios ovmf-x86_64/OVMF.fd -cdrom kernel-x86_64-release.iso -boot d | ||
|
||
check-x86_64: | ||
cd kernel && cargo check --target x86_64-unknown-none | ||
|
||
# aarch64 | ||
|
||
ovmf-aarch64: | ||
mkdir -p ovmf-aarch64 | ||
cd ovmf-aarch64 && curl -o OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASEAARCH64_QEMU_EFI.fd | ||
build-aarch64-debug: limine | ||
cd kernel && cargo build --target aarch64-unknown-none | ||
kernel-aarch64-debug.iso: build-aarch64-debug | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/aarch64-unknown-none/debug/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTAA64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-aarch64-debug.iso | ||
rm -rf iso_root | ||
run-aarch64-debug: ovmf-aarch64 kernel-aarch64-debug.iso | ||
qemu-system-aarch64 -M virt -cpu cortex-a72 -device ramfb -device qemu-xhci -device usb-kbd -m 2G -bios ovmf-aarch64/OVMF.fd -cdrom kernel-aarch64-debug.iso -boot d | ||
run-aarch64-log: ovmf-aarch64 kernel-aarch64-debug.iso | ||
qemu-system-aarch64 -M virt -cpu cortex-a72 -device ramfb -device qemu-xhci -device usb-kbd -m 2G -bios ovmf-aarch64/OVMF.fd -cdrom kernel-aarch64-debug.iso -boot d \ | ||
-serial file:log_aarch64.txt | ||
|
||
|
||
build-aarch64-release: limine | ||
cd kernel && cargo build --target aarch64-unknown-none --release | ||
kernel-aarch64-release.iso: build-aarch64-release | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/aarch64-unknown-none/release/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTAA64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-aarch64-release.iso | ||
rm -rf iso_root | ||
run-aarch64-release: ovmf-aarch64 kernel-aarch64-release.iso | ||
qemu-system-aarch64 -M virt -cpu cortex-a72 -device ramfb -device qemu-xhci -device usb-kbd -m 2G -bios ovmf-aarch64/OVMF.fd -cdrom kernel-aarch64-release.iso -boot d | ||
|
||
# riscv64 | ||
|
||
ovmf-riscv64: | ||
mkdir -p ovmf-riscv64 | ||
cd ovmf-riscv64 && curl -o OVMF.fd https://retrage.github.io/edk2-nightly/bin/RELEASERISCV64_VIRT_CODE.fd && dd if=/dev/zero of=OVMF.fd bs=1 count=0 seek=33554432 | ||
build-riscv64-debug: | ||
cd kernel && cargo build --target riscv64gc-unknown-none-elf | ||
kernel-riscv64-debug.iso: build-riscv64-debug | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/riscv64gc-unknown-none-elf/debug/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTRISCV64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-riscv64-debug.iso | ||
rm -rf iso_root | ||
run-riscv64-debug: ovmf-riscv64 kernel-riscv64-debug.iso | ||
qemu-system-riscv64 -M virt -cpu rv64 \ | ||
-device ramfb -device qemu-xhci -device usb-kbd -m 2G -drive if=pflash,unit=0,format=raw,file=ovmf-riscv64/OVMF.fd \ | ||
-device virtio-scsi-pci,id=scsi -device scsi-cd,drive=cd0 -drive id=cd0,format=raw,file=kernel-riscv64-debug.iso | ||
run-riscv64-debug-log: ovmf-riscv64 kernel-riscv64-debug.iso | ||
qemu-system-riscv64 -M virt -cpu rv64 \ | ||
-device ramfb -device qemu-xhci -device usb-kbd -m 2G -drive if=pflash,unit=0,format=raw,file=ovmf-riscv64/OVMF.fd \ | ||
-device virtio-scsi-pci,id=scsi -device scsi-cd,drive=cd0 -drive id=cd0,format=raw,file=kernel-riscv64-debug.iso \ | ||
-serial file:log_riscv64.txt | ||
|
||
build-riscv64-release: | ||
cd kernel && cargo build --target riscv64gc-unknown-none-elf | ||
kernel-riscv64-release.iso: build-riscv64-release | ||
rm -rf iso_root | ||
mkdir -p iso_root | ||
cp -v kernel/target/riscv64gc-unknown-none-elf/release/kernel \ | ||
limine.conf limine/limine-uefi-cd.bin iso_root/ | ||
mkdir -p iso_root/EFI/BOOT | ||
cp -v limine/BOOTRISCV64.EFI iso_root/EFI/BOOT/ | ||
xorriso -as mkisofs \ | ||
-no-emul-boot -boot-load-size 4 -boot-info-table \ | ||
--efi-boot limine-uefi-cd.bin \ | ||
-efi-boot-part --efi-boot-image --protective-msdos-label \ | ||
iso_root -o kernel-riscv64-release.iso | ||
rm -rf iso_root | ||
run-riscv64-release: ovmf-riscv64 kernel-riscv64-release.iso | ||
qemu-system-riscv64 -M virt -cpu rv64 \ | ||
-device ramfb -device qemu-xhci -device usb-kbd -m 2G -drive if=pflash,unit=0,format=raw,file=ovmf-riscv64/OVMF.fd \ | ||
-device virtio-scsi-pci,id=scsi -device scsi-cd,drive=cd0 -drive id=cd0,format=raw,file=kernel-riscv64-release.iso | ||
|
||
# clean commands | ||
|
||
clean: | ||
cd kernel && cargo clean | ||
rm -rf ovmf-aarch64 | ||
rm -rf ovmf-riscv64 | ||
rm -rf ovmf-x86_64 | ||
rm -f kernel-aarch64-debug.iso | ||
rm -f kernel-riscv64-debug.iso | ||
rm -f kernel-x86_64-debug.iso | ||
rm -f kernel-aarch64-release.iso | ||
rm -f kernel-riscv64-release.iso | ||
rm -f kernel-x86_64-release.iso | ||
rm -f log_aarch64.txt | ||
rm -f log_riscv64.txt | ||
rm -f log_x86_64.txt | ||
|
||
distclean: clean | ||
rm -rf limine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# CharlotteOS Limine Rust Barebones | ||
|
||
This repository serves as a template for developing a Limine Boot Protocol compliant operating system kernel in the Rust Programming Langauge. | ||
|
||
The following need to be installed in order to use it: | ||
|
||
- Rustup | ||
- A Rust toolchain | ||
- xorriso | ||
- curl | ||
- make | ||
- qemu-system | ||
|
||
With all of those dependencies installed all of the make commands should just work. If not then open an issue. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "kernel" | ||
version = "0.0.0" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[[bin]] | ||
name = "kernel" | ||
test = false | ||
bench = false | ||
|
||
[build-dependencies] | ||
|
||
[dependencies] | ||
limine = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::env; | ||
|
||
fn main() { | ||
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); | ||
|
||
match arch.as_str() { | ||
"x86_64" => { | ||
// Tell cargo to pass the linker script to the linker... | ||
println!("cargo:rustc-link-arg=-Tlinker/x86_64.ld"); | ||
// ...and to re-run if it changes. | ||
println!("cargo:rerun-if-changed=linker/x86_64.ld"); | ||
} | ||
"aarch64" => { | ||
// Tell cargo to pass the linker script to the linker... | ||
println!("cargo:rustc-link-arg=-Tlinker/aarch64.ld"); | ||
// ...and to re-run if it changes. | ||
println!("cargo:rerun-if-changed=linker/aarch64.ld"); | ||
} | ||
"riscv64" => { | ||
// Tell cargo to pass the linker script to the linker... | ||
println!("cargo:rustc-link-arg=-Tlinker/riscv64.ld"); | ||
// ...and to re-run if it changes. | ||
println!("cargo:rerun-if-changed=linker/riscv64.ld"); | ||
} | ||
_ => panic!("Invalid ISA"), | ||
} | ||
|
||
println!("cargo:rerun-if-changed=asm"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Tell the linker that we want an aarch64 ELF64 output file */ | ||
OUTPUT_FORMAT(elf64-littleaarch64) | ||
OUTPUT_ARCH(aarch64) | ||
|
||
/* We want the symbol main to be our entry point */ | ||
ENTRY(main) | ||
|
||
/* Define the program headers we want so the bootloader gives us the right */ | ||
/* MMU permissions */ | ||
PHDRS | ||
{ | ||
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ | ||
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ | ||
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ | ||
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic PHDR for relocations */ | ||
} | ||
|
||
SECTIONS | ||
{ | ||
/* We wanna be placed in the topmost 2GiB of the address space, for optimisations */ | ||
/* and because that is what the Limine spec mandates. */ | ||
/* Any address in this region will do, but often 0xffffffff80000000 is chosen as */ | ||
/* that is the beginning of the region. */ | ||
. = 0xffffffff80000000; | ||
|
||
.text : { | ||
*(.text .text.*) | ||
} :text | ||
|
||
/* Move to the next memory page for .rodata */ | ||
. += CONSTANT(MAXPAGESIZE); | ||
|
||
.rodata : { | ||
*(.rodata .rodata.*) | ||
} :rodata | ||
|
||
/* Move to the next memory page for .data */ | ||
. += CONSTANT(MAXPAGESIZE); | ||
|
||
.data : { | ||
*(.data .data.*) | ||
} :data | ||
|
||
/* Dynamic section for relocations, both in its own PHDR and inside data PHDR */ | ||
.dynamic : { | ||
*(.dynamic) | ||
} :data :dynamic | ||
|
||
/* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ | ||
/* unnecessary zeros will be written to the binary. */ | ||
/* If you need, for example, .init_array and .fini_array, those should be placed */ | ||
/* above this. */ | ||
.bss : { | ||
*(.bss .bss.*) | ||
*(COMMON) | ||
} :data | ||
|
||
/* Discard .note.* and .eh_frame since they may cause issues on some hosts. */ | ||
/DISCARD/ : { | ||
*(.eh_frame) | ||
*(.note .note.*) | ||
} | ||
} |
Oops, something went wrong.