hello world asdasd

This commit is contained in:
MeexReay 2025-01-28 00:00:11 +03:00
parent 0a34a214c1
commit 7845d5da70
6 changed files with 128 additions and 0 deletions

37
Makefile Normal file
View File

@ -0,0 +1,37 @@
.PHONY: clean run run-iso target_dir
target/main.iso: target/kernel.elf target_dir
cp 'src/grub.cfg' target/iso/boot/grub
cp '$<' target/iso/boot
grub-mkrescue -o '$@' target/iso
target/boot.o: src/boot.s target_dir
nasm -f elf32 '$<' -o '$@'
target/kernel.elf: src/linker.ld target/boot.o target/kernel.o
i686-elf-ld -m elf_i386 -nostdlib -o '$@' -T $^
target/kernel.o: kernel/ target_dir
cd kernel && cargo build --release
cp kernel/target/x86-unknown-bare_metal/release/deps/kernel-*.o target/kernel.o
target_dir:
mkdir -p target
mkdir -p target/iso
mkdir -p target/iso/lib
mkdir -p target/iso/boot
mkdir -p target/iso/boot/grub
build: target/main.iso
clean:
rm -rf target
rm -rf kernel/target
rm -rf kernel/Cargo.lock
mkdir target
run-elf: target/kernel.elf
qemu-system-i386 -kernel '$<'
run: target/main.iso
qemu-system-i386 -cdrom '$<'

15
kernel/.cargo/config.toml Normal file
View File

@ -0,0 +1,15 @@
[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]
[build]
target = "x86-unknown-bare_metal.json"
[target.x86-unknown-bare_metal]
rustflags = [
"-C", "opt-level=s", # Эквивалент GCC -Os
"-C", "debuginfo=0", # Убирает отладочную информацию
"-C", "relocation-model=static", # Для freestanding
"--emit=obj" # Генерация объектного файла
]

8
shell.nix Normal file
View File

@ -0,0 +1,8 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs =
with pkgs; [
pkgsCross.i686-embedded.buildPackages.gcc
];
}

40
src/boot.s Normal file
View File

@ -0,0 +1,40 @@
global loader
global stack_ptr
extern main
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
FLAGS equ MODULEALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
section .mbheader
align 4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
section .text
STACKSIZE equ 0x4000
loader:
mov esp, stack+STACKSIZE
push eax
push ebx
call main
cli
hang:
hlt
jmp hang
section .bss
align 4
stack:
resb STACKSIZE
stack_ptr:

5
src/grub.cfg Normal file
View File

@ -0,0 +1,5 @@
set timeout=0
set default="0"
menuentry "main" {
multiboot /boot/kernel.elf
}

23
src/linker.ld Normal file
View File

@ -0,0 +1,23 @@
ENTRY (loader)
SECTIONS
{
. = 0x00100000;
.mbheader : {
*(.mbheader)
}
.text : {
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}