From 1036cac955bed5bf91814b626d672482a4202b01 Mon Sep 17 00:00:00 2001
From: Recolic Keghart <root@recolic.net>
Date: Mon, 8 Jun 2020 21:57:10 +0800
Subject: [PATCH] reorder dir

---
 Makefile                        | 22 +++++++++---------
 boot.c                          | 41 ---------------------------------
 {asm => bootloader}/Makefile    |  0
 {asm => bootloader}/boot.asm    | 15 ++++++------
 {asm => bootloader}/mbr_end.inc |  0
 {asm => bootloader}/str.16.inc  |  0
 {asm => bootloader}/str.32.inc  |  0
 {asm => bootloader}/test.asm    |  0
 kernel/Makefile                 |  8 +++++++
 kernel/kernel.c                 |  6 +++++
 10 files changed, 32 insertions(+), 60 deletions(-)
 delete mode 100644 boot.c
 rename {asm => bootloader}/Makefile (100%)
 rename {asm => bootloader}/boot.asm (85%)
 rename {asm => bootloader}/mbr_end.inc (100%)
 rename {asm => bootloader}/str.16.inc (100%)
 rename {asm => bootloader}/str.32.inc (100%)
 rename {asm => bootloader}/test.asm (100%)
 create mode 100644 kernel/Makefile
 create mode 100644 kernel/kernel.c

diff --git a/Makefile b/Makefile
index 2924d3f..303a82f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,16 @@
 
-build:
-	cc -c boot.c -o boot.o -m32
-	ld -o boot.img -Ttext 0x0 --oformat binary boot.o -m elf_i386
-	# objcopy -O binary boot.o boot.img
-	# [[ $$(stat boot.img --printf='%s') -lt 510 ]]
-	truncate --size=510 boot.img
-	printf '\x55\xAA' >> boot.img
+bootloader:
+	$(MAKE) -C bootloader
 
-run: build
-	qemu-system-x86_64 boot.img
+kernel:
+	$(MAKE) -C kernel
 
+build: bootloader kernel
+
+assemble: build
+	cat bootloader/boot.img kernel/kernel.img > disk.img
+
+run: assemble
+	qemu-system-x86_64 disk.img
 
-clean:
-	rm *.o
 
diff --git a/boot.c b/boot.c
deleted file mode 100644
index 1ee6cdf..0000000
--- a/boot.c
+++ /dev/null
@@ -1,41 +0,0 @@
-
-void main();
-void __entry() {
-    main();
-}
-
-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() {
-    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"
-    );
-}
-
-
diff --git a/asm/Makefile b/bootloader/Makefile
similarity index 100%
rename from asm/Makefile
rename to bootloader/Makefile
diff --git a/asm/boot.asm b/bootloader/boot.asm
similarity index 85%
rename from asm/boot.asm
rename to bootloader/boot.asm
index b7d842e..43313ea 100644
--- a/asm/boot.asm
+++ b/bootloader/boot.asm
@@ -58,18 +58,17 @@ _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
+
+    KERN_ADDR equ 0x1000
+
+    jmp $
 
 _motd_32:
-    db '----- CPU is in INTEL x86 protected mode now -----', 0x0
-_motd_32p:
-    db '+++++ CPU is in INTEL x86 protected mode now +++++', 0x0
+    db '[ENTER X86 MODE SUCC] [LOADING KERN..]', 0x0
+_motd_endk:
+    db '[ENTER X86 MODE SUCC] [LOADING KERN..] [KERN EXITED]', 0x0
     
 %include "./mbr_end.inc"    
 
diff --git a/asm/mbr_end.inc b/bootloader/mbr_end.inc
similarity index 100%
rename from asm/mbr_end.inc
rename to bootloader/mbr_end.inc
diff --git a/asm/str.16.inc b/bootloader/str.16.inc
similarity index 100%
rename from asm/str.16.inc
rename to bootloader/str.16.inc
diff --git a/asm/str.32.inc b/bootloader/str.32.inc
similarity index 100%
rename from asm/str.32.inc
rename to bootloader/str.32.inc
diff --git a/asm/test.asm b/bootloader/test.asm
similarity index 100%
rename from asm/test.asm
rename to bootloader/test.asm
diff --git a/kernel/Makefile b/kernel/Makefile
new file mode 100644
index 0000000..b712a80
--- /dev/null
+++ b/kernel/Makefile
@@ -0,0 +1,8 @@
+
+kernel:
+	gcc -ffreestanding -c kernel.c -o kernel.o # -m32
+	ld -o kernel.img -Ttext 0x1000 --oformat binary kernel.o # -m elf_i386
+
+clean:
+	rm *.o *.img
+
diff --git a/kernel/kernel.c b/kernel/kernel.c
new file mode 100644
index 0000000..e0b0410
--- /dev/null
+++ b/kernel/kernel.c
@@ -0,0 +1,6 @@
+
+void main() {
+    char *vga_begin = (char *)0xb8000;
+    *vga_begin = 'X';
+}
+
-- 
GitLab