diff options
| author | Clément Sibille <claymeuns@protonmail.com> | 2021-10-04 13:30:31 +0200 | 
|---|---|---|
| committer | Clément Sibille <claymeuns@protonmail.com> | 2021-10-04 13:30:31 +0200 | 
| commit | 25a24b8b167a7cb28c622039ea30e4afd166cd83 (patch) | |
| tree | 811a6a0e46234ac6fc7078030b0221db8d85f5b6 | |
| parent | 84ac89b379da880468d2bb1396eb4773b48b6a92 (diff) | |
Make kernel print hello world using the VGA text buffer
| -rw-r--r-- | Cargo.toml | 17 | ||||
| -rw-r--r-- | Makefile | 21 | ||||
| -rw-r--r-- | boot/boot.S | 36 | ||||
| -rw-r--r-- | boot/linker.ld | 28 | ||||
| -rw-r--r-- | i686-lisibleos.json | 14 | ||||
| -rw-r--r-- | kernel/.cargo/config.toml | 5 | ||||
| -rw-r--r-- | kernel/Cargo.toml | 12 | ||||
| -rw-r--r-- | kernel/src/lib.rs | 23 | ||||
| -rw-r--r-- | rust-toolchain.toml | 4 | ||||
| -rw-r--r-- | src/lib.rs | 7 | 
10 files changed, 154 insertions, 13 deletions
@@ -1,8 +1,13 @@ -[package] -name = "lisibleos" -version = "0.1.0" -edition = "2018" +[workspace] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +members = [ +  "kernel", +] -[dependencies] +[profile.dev] +panic = "abort" +lto = true + +[profile.release] +panic = "abort" +lto = true
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cb64d5e --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +all: target/kernel.o + +run: target/kernel.o +	qemu-system-i386 -kernel $< -machine type=pc-i440fx-3.1 + +target/boot.o: boot/boot.S +	mkdir -p target +	nasm -felf32 $< -o $@ + +target/kernel.o: target/boot.o target/i686-lisibleos/release/libkernel.a +	mkdir -p target +	ld -m elf_i386 -n -T boot/linker.ld -o $@ $^ + +target/i686-lisibleos/release/libkernel.a: +	mkdir -p target +	xargo build -p kernel --target i686-lisibleos --release + +clean: +	xargo clean --target i686-lisibleos +	rm target/kernel.o target/boot.o target/i686-lisibleos/debug/libkernel.a +	rm target/kernel.o target/boot.o target/i686-lisibleos/release/libkernel.a diff --git a/boot/boot.S b/boot/boot.S new file mode 100644 index 0000000..6164029 --- /dev/null +++ b/boot/boot.S @@ -0,0 +1,36 @@ +MULTIBOOT_ALIGN EQU 1<<0                                      ; Align loaded modules on page boundaries +MULTIBOOT_MEMINFO EQU 1<<1                                    ; Provide memory map +MULTIBOOT_FLAGS EQU MULTIBOOT_ALIGN | MULTIBOOT_MEMINFO       ; Multiboot flags +MULTIBOOT_MAGIC EQU 0x1BADB002                                ; Multiboot 1 magic number +MULTIBOOT_CHECKSUM EQU -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) ; Checksum + +SECTION .multiboot +ALIGN 4 +DD MULTIBOOT_MAGIC +DD MULTIBOOT_FLAGS +DD MULTIBOOT_CHECKSUM + +SECTION .bss +ALIGN 16 +stack_bottom: +RESB 16384 ; 16 KiB stack +stack_top: + + +SECTION .text +GLOBAL _start:function (_start.end - _start) +_start: +    MOV esp, stack_top +    EXTERN kmain +    CALL kmain +    CLI +.hang: HLT +    JMP .hang +.end: + + + + + + + diff --git a/boot/linker.ld b/boot/linker.ld new file mode 100644 index 0000000..a725f4e --- /dev/null +++ b/boot/linker.ld @@ -0,0 +1,28 @@ +ENTRY(_start) + +SECTIONS +{ +    . = 1M; + +    .text BLOCK(4K) : ALIGN(4K) +    { +		*(.multiboot) +		*(.text) +    } + +    .rodata BLOCK(4K) : ALIGN(4K) +    { +        *(.rodata) +    } + +    .data BLOCK(4K) : ALIGN(4K) +    { +        *(.data) +    } + +    .bss BLOCK(4K) : ALIGN(4K) +    { +        *(COMMON) +        *(.bss) +    } +}
\ No newline at end of file diff --git a/i686-lisibleos.json b/i686-lisibleos.json new file mode 100644 index 0000000..4ff9198 --- /dev/null +++ b/i686-lisibleos.json @@ -0,0 +1,14 @@ +{ +  "llvm-target": "i686-unknown-none", +  "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128", +  "linker-flavor": "ld.lld", +  "linker": "rust-lld", +  "panic-strategy": "abort", +  "target-endian": "little", +  "target-pointer-width": "32", +  "target-c-int-width": "32", +  "arch": "x86", +  "os": "none", +  "disable-redzone": true, +  "features": "-mmx,-sse,+soft-float" +}
\ No newline at end of file diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml new file mode 100644 index 0000000..a26e254 --- /dev/null +++ b/kernel/.cargo/config.toml @@ -0,0 +1,5 @@ + +[unstable] +build-std = ["core", "compiler_builtins"] +[build] +target = "i686-lisibleos.json" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml new file mode 100644 index 0000000..1ca49e6 --- /dev/null +++ b/kernel/Cargo.toml @@ -0,0 +1,12 @@ + + +[package] +name = "kernel" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["staticlib"] + diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs new file mode 100644 index 0000000..285ecff --- /dev/null +++ b/kernel/src/lib.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[no_mangle] +pub extern "C" fn kmain() -> ! { +    let vga_buffer = 0xb8000 as *mut u8; + +    for (i, &byte) in b"LisibleOS Hello world".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: &PanicInfo) -> ! { +    loop {} +}
\ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..b368c8b --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +components = [ "rustfmt", "rustc-dev" ] +channel = "nightly" +profile = "minimal"
\ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 31e1bb2..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { -    #[test] -    fn it_works() { -        assert_eq!(2 + 2, 4); -    } -}  | 
