diff options
| author | czjstmax <jstmaxlol@disroot.org> | 2026-02-22 02:33:30 +0100 |
|---|---|---|
| committer | czjstmax <jstmaxlol@disroot.org> | 2026-02-22 02:33:30 +0100 |
| commit | fea8e314e6291bd55fd96b1bec478d500b548489 (patch) | |
| tree | 3df2fa6b06924ede0d31f06c1452b14bc7654006 | |
initial commit
i cant get the stage2 to load kernel, or the kernel to print.
it's 2 am so gn for now.
Signed-off-by: czjstmax <jstmaxlol@disroot.org>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | Makefile | 17 | ||||
| -rw-r--r-- | README.md | 14 | ||||
| -rw-r--r-- | build/boot.bin | bin | 0 -> 512 bytes | |||
| -rw-r--r-- | build/boot_s2.o | bin | 0 -> 528 bytes | |||
| -rw-r--r-- | build/mkernel.o | bin | 0 -> 1536 bytes | |||
| -rw-r--r-- | build/mullos.img | bin | 0 -> 820 bytes | |||
| -rwxr-xr-x | build/s2.bin | bin | 0 -> 308 bytes | |||
| -rwxr-xr-x | build/s2.elf | bin | 0 -> 5300 bytes | |||
| -rw-r--r-- | src/boot.asm | 134 | ||||
| -rw-r--r-- | src/boot_s2.asm | 23 | ||||
| -rw-r--r-- | src/krn/api/std.h | 18 | ||||
| -rw-r--r-- | src/krn/mkern.c | 13 | ||||
| -rw-r--r-- | src/linker.ld | 8 | ||||
| -rw-r--r-- | src/linker_kernel.ld | 7 |
16 files changed, 256 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..258cd57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +todo @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 czjstmax <jstmaxlol at disroot dot org> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9e63e3f --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +all: + # assemble bootloader + nasm -f bin src/boot.asm -o build/boot.bin + nasm -f elf32 src/boot_s2.asm -o build/boot_s2.o + # compile kernel + gcc -m32 -ffreestanding -nostdlib -c src/krn/mkern.c -o build/mkernel.o + # link + ld -m elf_i386 -T src/linker.ld -nostdlib -o build/s2.elf build/boot_s2.o build/mkernel.o + objcopy -O binary build/s2.elf build/s2.bin + # make .img + cat build/boot.bin build/s2.bin > build/mullos.img + # qemu test + qemu-system-x86_64 -drive format=raw,file=build/mullos.img + +clean: + rm -vf build/* + diff --git a/README.md b/README.md new file mode 100644 index 0000000..71257aa --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +### müllos + +minimal x86_64 'operating system' experiment von czjstmax. \ +the name is based off the german word for trash. haha. + +--- + +the objectives for müllos are to have: +- a C compiler work on it +- an integrated minimal userland shell. + +#### müllkernel +the simple and very stoopid kernel for za müllos. + diff --git a/build/boot.bin b/build/boot.bin Binary files differnew file mode 100644 index 0000000..30c4d1f --- /dev/null +++ b/build/boot.bin diff --git a/build/boot_s2.o b/build/boot_s2.o Binary files differnew file mode 100644 index 0000000..b1aee93 --- /dev/null +++ b/build/boot_s2.o diff --git a/build/mkernel.o b/build/mkernel.o Binary files differnew file mode 100644 index 0000000..709e657 --- /dev/null +++ b/build/mkernel.o diff --git a/build/mullos.img b/build/mullos.img Binary files differnew file mode 100644 index 0000000..9e707e1 --- /dev/null +++ b/build/mullos.img diff --git a/build/s2.bin b/build/s2.bin Binary files differnew file mode 100755 index 0000000..020ebf3 --- /dev/null +++ b/build/s2.bin diff --git a/build/s2.elf b/build/s2.elf Binary files differnew file mode 100755 index 0000000..3bd6f0d --- /dev/null +++ b/build/s2.elf diff --git a/src/boot.asm b/src/boot.asm new file mode 100644 index 0000000..011c00f --- /dev/null +++ b/src/boot.asm @@ -0,0 +1,134 @@ +; boot.asm - stage 1 + +[bits 16] +[org 0x7C00] + +start: + xor ax, ax + mov ds, ax + mov es, ax + mov ss, ax + + ; clear screen by big scrollup + mov ah, 0x06 ; scrollup function + mov al, 0 ; al contains the n of lines to scroll (0 is clearall) + mov bh, 0x07 ; 'attribute byte' 0x07 is white on black + mov cx, 0x0000 ; upper-left corner + mov dx, 0x184F ; bottom-right corner + + int 0x10 ; call + ; set cursor position back to default + mov ah, 0x02 ; set cur pos function + ; position parameters: + mov bh, 0x00 ; page number (0) + mov dh, 0x00 ; row + mov dl, 0x00 ; col + + int 0x10 ; call + + mov si, msg1 ; print msg1 + call print_string + + mov ah, 0x02 ; set cur pos function + ; position parameters: + mov bh, 0x00 ; page number (0) + mov dh, 0x01 ; row + mov dl, 0x00 ; col + + int 0x10 ; call + + mov si, msg2 ; print msg2 + call print_string + + mov ah, 0x02 ; set cur pos function + ; position parameters: + mov bh, 0x00 ; page number (0) + mov dh, 0x02 ; row + mov dl, 0x00 ; col + + int 0x10 ; call + + mov si, msg3 + call print_string + + mov ah, 0x02 ; set cur pos function + ; position parameters: + mov bh, 0x00 ; page number (0) + mov dh, 0x03 ; row + mov dl, 0x00 ; col + + int 0x10 ; call + +load_stage2: + mov ax, 0x0000 + mov es, ax + mov bx, 0x1000 + ; load stage2 from disk - first sector at 0x1000 + mov bx, 0x1000 ; load address + mov dh, 0 + mov ch, 0 + mov cl, 2 ; sector 2 + mov al, 20 ; sectors to read + mov ah, 0x02 + + int 0x13 + jc halt + + ; GDT for protected mode +gdt_start: + dq 0 + dq 0x00CF9A000000FFFF ; code + dq 0x00CF92000000FFFF ; data + gdt_end: + +gdt_descriptor: + dw gdt_end - gdt_start -1 + dd gdt_start + + ; enable protected mode cleanly and transfer to 32-bit stub + cli + lgdt [gdt_descriptor] + + mov eax, cr0 + or eax, 1 + mov cr0, eax + + ; far jump reloads CS with selector 0x08 and enters protected mode + jmp 0x08:pm_entry + + ; 32-bit entry point + [bits 32] +pm_entry: + ; reload data segment registers with data selector (0x10) + mov ax, 0x10 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + + mov esp, 0x90000 ; setup stack + + mov eax, 0x1000 ; jump to linear address 0x1000 (which wloud be where s2.bin was loaded) + jmp eax + +halt: + hlt + jmp halt + +print_string: + lodsb + cmp al, 0 + je .done + mov ah, 0x0E + int 0x10 + jmp print_string +.done: + ret + +msg1 db `mull_bootloader hath bespoken unto thee:\n`, 0 +msg2 db `\"behold, \'O user! mull_kernel doth now commence its solemn journey!\"\n`, 0 +msg3 db `trying to kernel kernel :3`, 0 + +times 510-($-$$) db 0 +dw 0xAA55 diff --git a/src/boot_s2.asm b/src/boot_s2.asm new file mode 100644 index 0000000..b974827 --- /dev/null +++ b/src/boot_s2.asm @@ -0,0 +1,23 @@ +; boot_stage2.asm - stage2 +[bits 32] + +global _start +extern kmain + +section .text + +_start: + ; reload segments + mov ax, 0x10 + mov ds, ax + mov es, ax + mov ss, ax + mov fs, ax + mov gs, ax + mov esp, 0x90000 ; stack + + mov dword [0xB8000], 0x07410741 + call kmain + + hlt + diff --git a/src/krn/api/std.h b/src/krn/api/std.h new file mode 100644 index 0000000..d22835f --- /dev/null +++ b/src/krn/api/std.h @@ -0,0 +1,18 @@ +#define MÜLL_STD_H + +/* + * Minimal 'standard library' for I/O basics + */ + +// includes +#include <stdint.h> + +volatile uint16_t* VGA = (volatile uint16_t*)0xB8000; +uint16_t cursor = 0; + +void RealPrint(const char* str) { + while(*str) { + VGA[cursor++] = (uint8_t)(*str) | 0x0700; // white on black + str++; + } +} diff --git a/src/krn/mkern.c b/src/krn/mkern.c new file mode 100644 index 0000000..3bdc188 --- /dev/null +++ b/src/krn/mkern.c @@ -0,0 +1,13 @@ +#define MÜLL_KERN + +/* + * müll_kernel + */ + +#include "api/std.h" + +void kmain(void) __attribute__((noreturn)); +void kmain(void) { + RealPrint("the kernel says hii!"); + while (1); +} diff --git a/src/linker.ld b/src/linker.ld new file mode 100644 index 0000000..b6a4871 --- /dev/null +++ b/src/linker.ld @@ -0,0 +1,8 @@ +ENTRY(_start) + +SECTIONS { + . = 0x1000; + .text : { *(.text) } + .data : { *(.data) } + .bss : { *(.bss) } +} diff --git a/src/linker_kernel.ld b/src/linker_kernel.ld new file mode 100644 index 0000000..1153734 --- /dev/null +++ b/src/linker_kernel.ld @@ -0,0 +1,7 @@ +ENTRY(kmain) +SECTIONS { + . = 0x2000; /* load kernel at 0x2000 */ + .text : { *(.text) } + .data : { *(.data) } + .bss : { *(.bss) } +} |