Last active
May 25, 2024 07:11
-
-
Save alirezaarzehgar/f111f57dc1246eb241514c5948a85a01 to your computer and use it in GitHub Desktop.
Hello World OS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| nasm -f elf32 kernel.asm -o kasm.o | |
| gcc -m32 -c kernel.c -o kc.o | |
| ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o | |
| mkdir -p root/boot/grub | |
| cp kernel root/boot | |
| echo "multiboot /boot/kernel;boot" > root/boot/grub/grub.cfg | |
| grub-mkrescue -o os.iso root | |
| rm -rf root *.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| section .text | |
| align 4 | |
| dd 0x1BADB002 | |
| dd 0x00 | |
| dd - (0x1BADB002 + 0x00) | |
| global start | |
| extern kernel_main | |
| start: | |
| cli | |
| mov esp, stack_space | |
| call kernel_main | |
| hlt | |
| section .bss | |
| resb 8192 | |
| stack_space: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define VIDEO_MEMORY (char *)0xb8000 | |
| char *vid = VIDEO_MEMORY; | |
| void print_str(const char *const str, unsigned int len) | |
| { | |
| for (unsigned int i = 0; i < len; i++) | |
| { | |
| *(vid++) = str[i]; | |
| *(vid++) = 0x07; | |
| } | |
| } | |
| void clear_screen() | |
| { | |
| const char *str = " "; | |
| for (int i = 0; i < 80 * 25; i++) | |
| print_str(str, 10); | |
| vid = VIDEO_MEMORY; | |
| } | |
| void kernel_main(void) | |
| { | |
| clear_screen(); | |
| print_str("Ha bemola ke!", 13); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OUTPUT_FORMAT(elf32-i386) | |
| ENTRY(start) | |
| SECTIONS | |
| { | |
| . = 0x100000; | |
| .text : { *(.text) } | |
| .data : { *(.data) } | |
| .bss : { *(.bss) } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install dependencies on debian:
Run project:
Note:
You may have following error:
You should install
nasm,mtools.You may build your os without error, but after booting iso using qemu, qemu say no bootable device. You should install
grub-pc-bin.Boot iso using qemu:
Resource: https://wiki.osdev.org/Bare_Bones