Compare commits
14 Commits
c706615a4d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8c4847b12 | ||
|
|
7e4cedcdc0 | ||
|
|
80a5815731 | ||
|
|
3ef8cbbf8c | ||
|
|
95c8480aac | ||
|
|
d504aa2a6d | ||
|
|
288dd537c0 | ||
|
|
4d80e10dbd | ||
|
|
faaadcf475 | ||
|
|
c01cbbc458 | ||
|
|
01c36c6178 | ||
|
|
2851629a8a | ||
|
|
eaece6994a | ||
|
|
4206ae592b |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
*.o
|
||||
*.iso
|
||||
*.bin
|
||||
gamarjoba_munde/gamarjoba
|
||||
baremetal_gamarjoba/baremetal_gamarjoba
|
||||
keyboard/keyboard_kernel
|
||||
target/
|
||||
48
Makefile
48
Makefile
@@ -1,48 +0,0 @@
|
||||
|
||||
|
||||
gamarjoba: gamarjoba.asm
|
||||
nasm -f elf64 -o gamarjoba.o gamarjoba.asm
|
||||
ld -o gamarjoba gamarjoba.o
|
||||
|
||||
run_gamarjoba: gamarjoba
|
||||
./gamarjoba
|
||||
|
||||
baremetal_gamarjoba: baremetal_gamarjoba.asm include.c
|
||||
gcc -m32 -ffreestanding -o include.o -c include.c
|
||||
nasm -f elf32 baremetal_gamarjoba.asm
|
||||
ld -m elf_i386 -nostdlib -T linker.ld baremetal_gamarjoba.o include.o -o baremetal_gamarjoba
|
||||
|
||||
run_baremetal_gamarjoba: baremetal_gamarjoba
|
||||
qemu-system-i386 -kernel baremetal_gamarjoba
|
||||
|
||||
keyboard: keyboard.asm c_keyboard.c keyboard.rs
|
||||
gcc -m32 -ffreestanding -o c_keyboard.o -c c_keyboard.c
|
||||
rustc --emit obj -o rust_keyboard.o --target i686-unknown-linux-gnu keyboard.rs
|
||||
nasm -f elf32 keyboard.asm
|
||||
ld -m elf_i386 -nostdlib -T linker.ld keyboard.o c_keyboard.o rust_keyboard.o -o keyboard
|
||||
|
||||
run_keyboard: keyboard
|
||||
qemu-system-i386 -kernel keyboard
|
||||
|
||||
run_terminal_keyboard: keyboard
|
||||
qemu-system-i386 -display curses -kernel keyboard
|
||||
|
||||
|
||||
lightshow: lightshow.asm lightshow.rs
|
||||
rustc --emit obj -o lightshow_rust.o --target i686-unknown-linux-gnu -g lightshow.rs
|
||||
nasm -f elf32 -g lightshow.asm
|
||||
ld -m elf_i386 -nostdlib -T linker.ld lightshow.o lightshow_rust.o -o lightshow
|
||||
|
||||
run_lightshow: lightshow
|
||||
qemu-system-i386 -kernel lightshow
|
||||
|
||||
debug_lightshow: lightshow
|
||||
qemu-system-i386 -kernel lightshow -gdb tcp::9999 -S
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f gamarjoba
|
||||
rm -f baremetal_gamarjoba
|
||||
rm -f keyboard
|
||||
rm -f lightshow
|
||||
12
README
12
README
@@ -1,12 +0,0 @@
|
||||
Sandbox for playing with low-level programming stuff
|
||||
|
||||
|
||||
The following projects are inspirational:
|
||||
|
||||
https://github.com/programble/bare-metal-tetris
|
||||
http://0xax.blogspot.com/2014/09/say-hello-to-x64-assembly-part-3.html
|
||||
|
||||
|
||||
x86 instruction set reference:
|
||||
http://x86.renejeschke.de/
|
||||
http://www.cs.virginia.edu/~evans/cs216/guides/x86.html#registers
|
||||
22
README.md
Normal file
22
README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Bare metal programming sandbox
|
||||
|
||||
This repo is a sandbox for experimenting with bare metal code and other
|
||||
low-level programming concerns.
|
||||
|
||||
This repo contains the following executables:
|
||||
|
||||
* `gamarjoba_munde` - x86-64 linux binary that prints the text "Gamarjoba, Munde"
|
||||
* `baremetal_gamarjoba` - bare-metal x86 program run with QEMU
|
||||
* `keyboard` - reads keycode information from keyboard. Also uses both Rust and C includes.
|
||||
* `lightshow` - NOTE: Broken - an attempt at a substantial #[no_core] rust object file, currently crashes rustc
|
||||
* `rust_kernel` - me following the 2015 version of the Phil Opp rust bare metal tutorial. Kept around for posterity
|
||||
|
||||
# Useful links
|
||||
|
||||
The following projects are inspirational:
|
||||
* https://github.com/programble/bare-metal-tetris
|
||||
* http://0xax.blogspot.com/2014/09/say-hello-to-x64-assembly-part-3.html
|
||||
|
||||
## x86 instruction set reference:
|
||||
* http://x86.renejeschke.de/
|
||||
* http://www.cs.virginia.edu/~evans/cs216/guides/x86.html#registers
|
||||
@@ -1,5 +1,5 @@
|
||||
%include "multiboot_header.asm"
|
||||
%include "x86_vram.asm"
|
||||
%include "../common/multiboot_header.asm"
|
||||
%include "../common/x86_vram.asm"
|
||||
|
||||
%define stack_size 0x1000
|
||||
|
||||
@@ -13,8 +13,11 @@ print_word db 'Hahaha',0
|
||||
|
||||
section .text
|
||||
|
||||
; Defined in include.c
|
||||
extern get_vram_offset
|
||||
extern c_entry
|
||||
|
||||
; Defined in common/x86_vram_functions.asm
|
||||
global write_to_coord
|
||||
|
||||
global boot
|
||||
@@ -52,4 +55,4 @@ halt:
|
||||
hlt
|
||||
jmp halt
|
||||
|
||||
%include "x86_vram_functions.asm"
|
||||
%include "../common/x86_vram_functions.asm"
|
||||
@@ -1,3 +1,5 @@
|
||||
%ifndef X86_VRAM_ASM
|
||||
%define X86_VRAM_ASM
|
||||
|
||||
; x86 video stuff
|
||||
; each character cell is a 16 bit word
|
||||
@@ -31,3 +33,4 @@
|
||||
%define BG.GRAY 7 << 12
|
||||
%define BG.BRIGHT 8 << 12
|
||||
|
||||
%endif
|
||||
56
justfile
Normal file
56
justfile
Normal file
@@ -0,0 +1,56 @@
|
||||
default:
|
||||
just --list
|
||||
|
||||
execute_rust_os:
|
||||
#!/usr/bin/env bash
|
||||
cd os-in-rust
|
||||
cargo bootimage
|
||||
qemu-system-x86_64 -drive format=raw,file=target/x86_64_target/debug/bootimage-os-in-rust.bin
|
||||
|
||||
run_gamarjoba: build_gamarjoba
|
||||
./gamarjoba_munde/gamarjoba
|
||||
|
||||
build_gamarjoba:
|
||||
nasm -f elf64 -o gamarjoba_munde/gamarjoba.o gamarjoba_munde/gamarjoba.asm
|
||||
ld -o gamarjoba_munde/gamarjoba gamarjoba_munde/gamarjoba.o
|
||||
|
||||
build_baremetal_gamarjoba:
|
||||
#!/usr/bin/env bash
|
||||
cd baremetal_gamarjoba
|
||||
gcc -m32 -ffreestanding -o include.o -c include.c
|
||||
nasm -f elf32 -i ../common baremetal_gamarjoba.asm
|
||||
ld -m elf_i386 -nostdlib -T ../common/linker.ld baremetal_gamarjoba.o include.o -o baremetal_gamarjoba
|
||||
|
||||
|
||||
run_baremetal_gamarjoba: build_baremetal_gamarjoba
|
||||
#!/usr/bin/env bash
|
||||
cd baremetal_gamarjoba
|
||||
qemu-system-i386 -kernel baremetal_gamarjoba
|
||||
|
||||
|
||||
build_keyboard:
|
||||
#!/usr/bin/env bash
|
||||
cd keyboard
|
||||
gcc -m32 -ffreestanding -o c_keyboard.o -c c_keyboard.c
|
||||
rustc --emit obj -o rust_keyboard.o --target i686-unknown-linux-gnu keyboard.rs
|
||||
nasm -f elf32 -i ../common keyboard.asm
|
||||
ld -m elf_i386 -nostdlib -T ../common/linker.ld keyboard.o c_keyboard.o rust_keyboard.o -o keyboard_kernel
|
||||
|
||||
run_keyboard: build_keyboard
|
||||
qemu-system-i386 -kernel keyboard/keyboard_kernel
|
||||
|
||||
run_terminal_keyboard: build_keyboard
|
||||
qemu-system-i386 -display curses -kernel keyboard/keyboard_kernel
|
||||
|
||||
build_lightshow:
|
||||
#!/usr/bin/env bash
|
||||
cd lightshow
|
||||
rustc --emit obj -o lightshow_rust.o --target i686-unknown-linux-gnu -g lightshow.rs
|
||||
nasm -f elf32 -i ../common -g lightshow.asm
|
||||
ld -m elf_i386 -nostdlib -T ../common/linker.ld lightshow.o lightshow_rust.o -o lightshow
|
||||
|
||||
run_lightshow: build_lightshow
|
||||
qemu-system-i386 -kernel lightshow
|
||||
|
||||
debug_lightshow: build_lightshow
|
||||
qemu-system-i386 -kernel lightshow -gdb tcp::9999 -S
|
||||
@@ -1,5 +1,5 @@
|
||||
%include "multiboot_header.asm"
|
||||
%include "x86_vram.asm"
|
||||
%include "../common/multiboot_header.asm"
|
||||
%include "../common/x86_vram.asm"
|
||||
|
||||
extern c_entry
|
||||
extern print_int
|
||||
@@ -56,4 +56,4 @@ scan:
|
||||
xor al, al
|
||||
ret
|
||||
|
||||
%include "x86_vram_functions.asm"
|
||||
%include "../common/x86_vram_functions.asm"
|
||||
@@ -1,4 +1,4 @@
|
||||
%include "x86_vram.asm"
|
||||
%include "../common/x86_vram.asm"
|
||||
|
||||
extern rust_entry
|
||||
|
||||
@@ -12,8 +12,8 @@ section .data
|
||||
section .text
|
||||
global boot
|
||||
|
||||
%include "multiboot_header.asm"
|
||||
%include "x86_vram_functions.asm"
|
||||
%include "../common/multiboot_header.asm"
|
||||
%include "../common/x86_vram_functions.asm"
|
||||
|
||||
boot:
|
||||
mov esp, stack + 0x100
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#![feature(lang_items, start, no_core)]
|
||||
#![feature(lang_items, no_core)]
|
||||
#![no_core]
|
||||
#![no_main]
|
||||
|
||||
@@ -10,10 +10,18 @@ extern fn eh_personality() {}
|
||||
fn panic_fmt() -> ! { loop {} }
|
||||
|
||||
#[lang = "panic"]
|
||||
pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! { panic_fmt() }
|
||||
pub fn panic(_expr_file_line: &(&'static str, &'static str, u32)) -> ! { panic_fmt() }
|
||||
|
||||
#[lang = "panic_location"]
|
||||
struct Location<'a> {
|
||||
_file: &'a str,
|
||||
_line: u32,
|
||||
_col: u32,
|
||||
}
|
||||
|
||||
|
||||
#[lang = "sized"]
|
||||
trait Sized {}
|
||||
pub trait Sized {}
|
||||
|
||||
#[lang = "copy"]
|
||||
trait Copy {}
|
||||
@@ -21,7 +29,7 @@ trait Copy {}
|
||||
#[lang = "add"]
|
||||
pub trait Add<RHS=Self> {
|
||||
type Output;
|
||||
fn add(self, rhs: RHS) -> Self::Output;
|
||||
fn add(self, _rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
/* this can be bogus, apparently? */
|
||||
@@ -33,12 +41,12 @@ impl Add for usize {
|
||||
#[lang = "mul"]
|
||||
pub trait Mul<RHS = Self> {
|
||||
type Output;
|
||||
fn mul(self, rhs: RHS) -> Self::Output;
|
||||
fn mul(self, _rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Mul for usize {
|
||||
type Output = usize;
|
||||
fn mul(self, rhs: usize) -> usize { 1 }
|
||||
fn mul(self, _rhs: usize) -> usize { 1 }
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +62,7 @@ pub extern fn rust_entry() {
|
||||
}
|
||||
|
||||
const X86_COLS: usize = 80;
|
||||
#[allow(dead_code)]
|
||||
const X86_ROWS: usize = 25;
|
||||
const VRAM_OFFSET: usize = 0xb8000;
|
||||
|
||||
6
os-in-rust/.cargo/config.toml
Normal file
6
os-in-rust/.cargo/config.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[unstable]
|
||||
build-std = ["core", "compiler_builtins"]
|
||||
build-std-features = ["compiler-builtins-mem"]
|
||||
|
||||
[build]
|
||||
target = "x86_64_target.json"
|
||||
16
os-in-rust/Cargo.lock
generated
Normal file
16
os-in-rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bootloader"
|
||||
version = "0.9.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2"
|
||||
|
||||
[[package]]
|
||||
name = "os-in-rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bootloader",
|
||||
]
|
||||
10
os-in-rust/Cargo.toml
Normal file
10
os-in-rust/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "os-in-rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
#bootloader = "0.10.12"
|
||||
bootloader = "0.9.8"
|
||||
30
os-in-rust/src/main.rs
Normal file
30
os-in-rust/src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
static GAMARJOBA: &[u8] = b"Gamarjoba, MVNDE!";
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
let vga_buffer = 0xb8000 as *mut u8;
|
||||
|
||||
for (i, &byte) in GAMARJOBA.iter().enumerate() {
|
||||
let i = i as isize;
|
||||
unsafe {
|
||||
*vga_buffer.offset(i * 2) = byte;
|
||||
*vga_buffer.offset(i * 2 + 1) = 0xd;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
18
os-in-rust/x86_64_target.json
Normal file
18
os-in-rust/x86_64_target.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"llvm-target": "x86_64-unknown-none",
|
||||
"data-layout": "e-m:e-i64:64-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"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
global start
|
||||
|
||||
section .text
|
||||
bits 32
|
||||
start:
|
||||
mov dword [0xb800], 0x2f4b2f4f
|
||||
hlt
|
||||
7
thousand-line-os/Cargo.lock
generated
Normal file
7
thousand-line-os/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "thousand-line-os"
|
||||
version = "0.1.0"
|
||||
6
thousand-line-os/Cargo.toml
Normal file
6
thousand-line-os/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "thousand-line-os"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
3
thousand-line-os/README.md
Normal file
3
thousand-line-os/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Thousand Line OS
|
||||
|
||||
Aspirational. Following https://operating-system-in-1000-lines.vercel.app/en/
|
||||
11
thousand-line-os/justfile
Normal file
11
thousand-line-os/justfile
Normal file
@@ -0,0 +1,11 @@
|
||||
_default:
|
||||
@just --list
|
||||
|
||||
|
||||
|
||||
run:
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
QEMU=qemu-system-riscv32
|
||||
# Start QEMU
|
||||
$QEMU -machine virt -bios default -nographic -serial mon:stdio --no-reboot
|
||||
28
thousand-line-os/kernel.ld
Normal file
28
thousand-line-os/kernel.ld
Normal file
@@ -0,0 +1,28 @@
|
||||
ENTRY(boot)
|
||||
|
||||
SECTIONS {
|
||||
. = 0x80200000;
|
||||
|
||||
.text :{
|
||||
KEEP(*(.text.boot));
|
||||
*(.text .text.*);
|
||||
}
|
||||
|
||||
.rodata : ALIGN(4) {
|
||||
*(.rodata .rodata.*);
|
||||
}
|
||||
|
||||
.data : ALIGN(4) {
|
||||
*(.data .data.*);
|
||||
}
|
||||
|
||||
.bss : ALIGN(4) {
|
||||
__bss = .;
|
||||
*(.bss .bss.* .sbss .sbss.*);
|
||||
__bss_end = .;
|
||||
}
|
||||
|
||||
. = ALIGN(4);
|
||||
. += 128 * 1024; /* 128KB */
|
||||
__stack_top = .;
|
||||
}
|
||||
14
thousand-line-os/src/lib.rs
Normal file
14
thousand-line-os/src/lib.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
init()
|
||||
}
|
||||
|
||||
fn init() -> ! {
|
||||
loop {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user