diff --git a/asm/Makefile b/asm/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ce6142a3fe43fb3407c00dc7d4e2c76796b12804 --- /dev/null +++ b/asm/Makefile @@ -0,0 +1,6 @@ +build: + nasm -f bin boot.asm -o boot.img + +run: build + qemu-system-x86_64 boot.img + diff --git a/asm/x16.asm b/asm/boot.asm similarity index 70% rename from asm/x16.asm rename to asm/boot.asm index 4321a91decaae57b964c8b5e4fd772536a166f20..b7d842ef63084127a5140a8225dfcbcc6785dc44 100644 --- a/asm/x16.asm +++ b/asm/boot.asm @@ -1,7 +1,7 @@ [bits 16] [org 0x7c00] -jmp _enter_prot_mode +jmp _init_prot_mode gdt_begin: @@ -36,7 +36,7 @@ gdt_desc: CODE_SEG_OFFSET equ gdt_entry_1 - gdt_begin DATA_SEG_OFFSET equ gdt_entry_2 - gdt_begin -_enter_prot_mode: +_init_prot_mode: cli lgdt [gdt_desc] mov eax, cr0 @@ -46,6 +46,7 @@ _enter_prot_mode: jmp CODE_SEG_OFFSET:_prot_begin [bits 32] +%include "./str.32.inc" _prot_begin: mov ax, DATA_SEG_OFFSET mov ds, ax @@ -56,8 +57,20 @@ _prot_begin: mov ebp, 0x90000 ; 600KB free space here, until 0x7c00 + 0x200 byte (MBR sector 0) mov esp, ebp + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32BIT PROTECTED MODE BEGIN ;;;;;;;;;;;;;;;;;;;;;;;;;; +_dead_loop: + mov ebx, _motd_32 + call println_vga + mov ebx, _motd_32p + call println_vga + jmp _dead_loop + +_motd_32: + db '----- CPU is in INTEL x86 protected mode now -----', 0x0 +_motd_32p: + db '+++++ CPU is in INTEL x86 protected mode now +++++', 0x0 - +%include "./mbr_end.inc" diff --git a/asm/mbr_end.inc b/asm/mbr_end.inc new file mode 100644 index 0000000000000000000000000000000000000000..97b1717f770ff495e7a3c23516d54e4927595113 --- /dev/null +++ b/asm/mbr_end.inc @@ -0,0 +1,2 @@ +times 510-($-$$) db 0 +dw 0xaa55 diff --git a/asm/str.16.inc b/asm/str.16.inc new file mode 100644 index 0000000000000000000000000000000000000000..ce51edf8f85e4d02c475b378e4d1fc862cd9d6ac --- /dev/null +++ b/asm/str.16.inc @@ -0,0 +1,17 @@ + +println_bios: + ; Arg0: addr in register bx + ; while true: + ; if [bx] != NULL: + ; print [bx]; ++bx + mov ah, 0x0e +_loop_begin: + mov al, [bx] + cmp al, 0x0 + je _loop_exit + int 0x10 + inc bx + jmp _loop_begin +_loop_exit: + ret + diff --git a/asm/str.32.inc b/asm/str.32.inc new file mode 100644 index 0000000000000000000000000000000000000000..5f8c933092621e396f5605f570f4034ad283523a --- /dev/null +++ b/asm/str.32.inc @@ -0,0 +1,20 @@ + +VGA_BEGIN_ADDR equ 0xb8000 +println_vga: + ; Arg0: addr in register ebx + pusha + mov edx, VGA_BEGIN_ADDR + mov ah, 0x0f +_loop_begin_1: + mov al, [ebx] + cmp al, 0x0 + je _loop_exit_1 + mov [edx], ax + inc ebx + add edx, 2 + jmp _loop_begin_1 +_loop_exit_1: + popa + ret + + diff --git a/asm/test.asm b/asm/test.asm index 4e8d2f4c782e6760ed69368f928e677dc2a7663b..086200f632b93b80b03e54e7a297c3fe82c5f235 100644 --- a/asm/test.asm +++ b/asm/test.asm @@ -3,8 +3,9 @@ ; [org 0x7c00] -mov bx, str -call println_bios +mov ebx, str +call println_vga +jmp $ println_bios: ; Arg0: addr in register bx @@ -22,13 +23,29 @@ _loop_begin: _loop_exit: ret +; [bits 32] +VGA_BEGIN_ADDR equ 0xb8000 println_vga: - ; Arg0: addr in register eax + ; Arg0: addr in register ebx + pusha + mov edx, VGA_BEGIN_ADDR + mov ah, 0x0f +_loop_begin_1: + mov al, [ebx] + cmp al, 0x0 + je _loop_exit_1 + mov [edx], ax + inc ebx + add edx, 2 + jmp _loop_begin_1 +_loop_exit_1: + popa + ret + str: db 'This is Recolic!', 0x0 -jmp $ times 510-($-$$) db 0 dw 0xaa55 diff --git a/boot.backup.c b/boot.backup.c deleted file mode 100644 index 5b0b903b85a01b66c27afcf1a1a01b22898eb130..0000000000000000000000000000000000000000 --- a/boot.backup.c +++ /dev/null @@ -1,39 +0,0 @@ - -asm ("jmp 0x14"); - -//void print_char(char to_print) { -// asm inline ( -// "mov $0x0e, %%ah\n\t" -// "mov %0, %%al\n\t" -// "int $0x10" -// : -// : "Ir" (to_print) -// : "ax" -// ); -//} -// -//void println(char *s) { -// while(*s != 0) { -// print_char(*s); -// } -//} - - - -void main() { -_start_p: - asm ( - "mov $0x0e, %ah\n\t" - "mov $0x55, %al\n\t" - "int $0x10" - ); - //print_char('X'); - //println("Hello world!"); - //println("Recolic Booting OS HERE..."); -} - -asm ( -"jmp 0x-2\n\t" -); - -