Tried to implement kernel in rust

This commit is contained in:
Aaro Koivukangas
2026-03-22 03:32:27 +02:00
parent a1d256917e
commit a6d305a2c0
7 changed files with 147 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
[unstable]
json-target-spec = true
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]
[build]
target = "target.json"
[target.'cfg(target_os = "none")']
runner = "bootimage runner"
+1
View File
@@ -0,0 +1 @@
target/*
+16
View File
@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bootloader"
version = "0.9.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13f6a8a495d2f93fe3d6eb3a224f9aa749a63cfd746ed03eb5ddcbd00ade7d8f"
[[package]]
name = "deros-kernel"
version = "0.1.0"
dependencies = [
"bootloader",
]
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "deros-kernel"
version = "0.1.0"
edition = "2024"
[dependencies]
bootloader = "0.9"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
[[bin]]
name = "deros-kernel"
test = false
bench = false
+52
View File
@@ -0,0 +1,52 @@
/* The bootloader will look at this image and start execution at the symbol
designated as the entry point. */
ENTRY(_start)
/* Tell where the various sections of the object files will be put in the final
kernel image. */
SECTIONS
{
/* It used to be universally recommended to use 1M as a start offset,
as it was effectively guaranteed to be available under BIOS systems.
However, UEFI has made things more complicated, and experimental data
strongly suggests that 2M is a safer place to load. In 2016, a new
feature was introduced to the multiboot2 spec to inform bootloaders
that a kernel can be loaded anywhere within a range of addresses and
will be able to relocate itself to run from such a loader-selected
address, in order to give the loader freedom in selecting a span of
memory which is verified to be available by the firmware, in order to
work around this issue. This does not use that feature, so 2M was
chosen as a safer option than the traditional 1M. */
. = 2M;
/* First put the multiboot header, as it is required to be put very early
in the image or the bootloader won't recognize the file format.
Next we'll put the .text section. */
.text ALIGN(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
/* Read-only data. */
.rodata ALIGN(4K) : ALIGN(4K)
{
*(.rodata)
}
/* Read-write data (initialized) */
.data ALIGN(4K) : ALIGN(4K)
{
*(.data)
}
/* Read-write data (uninitialized) and stack */
.bss ALIGN(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
/* The compiler may produce other sections, by default it will put them in
a segment with the same name. Simply add stuff here as needed. */
}
+21
View File
@@ -0,0 +1,21 @@
#![no_std]
#![no_main]
static HELLO: &[u8] = b"Hello World!";
#[unsafe(no_mangle)]
fn _start() -> ! {
let vga_buffer = 0xb8000 as *mut u8;
for (i, &byte) in HELLO.iter().enumerate() {
unsafe {
*vga_buffer.offset(i as isize * 2) = byte;
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
}
}
loop {}
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
+28
View File
@@ -0,0 +1,28 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": 64,
"target-c-int-width": 32,
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"dynamic-linking": false,
"relocation-model": "pic",
"code-model": "kernel",
"exe-suffix": ".elf",
"has-rpath": false,
"no-default-libraries": true,
"position-independent-executables": false,
"pre-link-args": {
"ld.lld": [
"--script=./linker.ld"
]
},
"rustc-abi": "x86-softfloat"
}