aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/boot/boot.stage2.asm100
-rw-r--r--src/boot/boot.stage2.print.asm37
-rw-r--r--src/common.asm22
-rw-r--r--src/common/common.asm27
-rw-r--r--src/common/common.protmode.clear.asm13
-rw-r--r--src/common/common.protmode.print.asm35
-rw-r--r--src/kernel/kernel.asm34
-rw-r--r--src/kernel/kernel.print.asm21
8 files changed, 143 insertions, 146 deletions
diff --git a/src/boot/boot.stage2.asm b/src/boot/boot.stage2.asm
index 968bedc..13d844b 100644
--- a/src/boot/boot.stage2.asm
+++ b/src/boot/boot.stage2.asm
@@ -1,75 +1,75 @@
- ;; boot.stage2.asm
+;; boot.stage2.asm
- [bits 16]
- [org 0x7e00]
-
- %include "common.asm"
+[bits 16]
+[org 0x7e00]
+
+%include "common.asm"
- jmp 0x0000:_s2_entry
+ jmp 0x0000:_s2_entry
_s2_entry:
- cli
- xor ax, ax
- mov ds, ax
+ cli
+ xor ax, ax
+ mov ds, ax
- mov si, DAP_kernel
- mov ah, 0x42
- int 0x13
- jc _kernel_load_err
- jmp _kernel_loaded
+ mov si, DAP_kernel
+ mov ah, 0x42
+ int 0x13
+ jc _kernel_load_err
+ jmp _kernel_loaded
_kernel_load_err:
- mov si, boot_kernel_err
- call _print_string
+ mov si, boot_kernel_err
+ call _print_string
- jmp $
+ jmp $
_kernel_loaded:
- mov si, boot_s2_msg
- call _print_string
+ mov si, boot_s2_msg
+ call _print_string
- call _enable_a20 ; Enable A20 line
- lgdt [GDT32_ptr] ; Load GDT
+ call _enable_a20 ; Enable A20 line
+ lgdt [GDT32_ptr] ; Load GDT
- ;; Setup Protected Mode
- mov eax, cr0
- or eax, 1
- mov cr0, eax
+;; Setup Protected Mode
+ mov eax, cr0
+ or eax, 1
+ mov cr0, eax
- jmp CODE_SEG32:_protected_mode
+ jmp CODE_SEG32:_protected_mode
- [bits 32]
+[bits 32]
_protected_mode:
- mov ax, DATA_SEG32
- mov ds, ax
- mov ss, ax
- mov esp, 0x90000
- and esp, 0xFFFFFFF0 ; Align to 16-byte boundary
+ mov ax, DATA_SEG32
+ mov ds, ax
+ mov ss, ax
+ mov esp, 0x90000
+ and esp, 0xFFFFFFF0 ; Align to 16-byte boundary
- mov esi, boot_protmode_msg
- call _print_string_pm_vga
+ mov esi, boot_protmode_msg
+ call _print_string_pm_vga
- call 0x10000
-
+ call 0x10000
+
boot_s2_msg:
- db "Entering Stage 2", 13, 10, 0
+ db "Entering Stage 2", 13, 10, 0
boot_protmode_msg:
- db "Enabling Protected Mode", 13, 10, 0
+ db "Enabling Protected Mode", 13, 10, 0
boot_kernel_err:
- db "Error loading kernel from disk", 13, 10, 0
+ db "Error loading kernel from disk", 13, 10, 0
- align 16
+align 16
DAP_kernel:
- db 0x10
- db 0
- dw 1 ; Number of sectors
- dw 0x0000
- dw 0x1000 ; Offset
- dq 66 ; Starting sector
+ db 0x10
+ db 0
+ dw 1 ; Number of sectors
+ dw 0x0000
+ dw 0x1000 ; Offset
+ dq 66 ; Starting sector
- %include "boot.stage1.print.asm"
- %include "boot.stage2.a20.asm"
- %include "boot.stage2.gdt32.asm"
- %include "boot.stage2.print.asm"
+%include "boot.stage1.print.asm"
+%include "boot.stage2.a20.asm"
+%include "boot.stage2.gdt32.asm"
+%include "common.protmode.print.asm"
diff --git a/src/boot/boot.stage2.print.asm b/src/boot/boot.stage2.print.asm
deleted file mode 100644
index 4527b87..0000000
--- a/src/boot/boot.stage2.print.asm
+++ /dev/null
@@ -1,37 +0,0 @@
- ;; boot.stage2.print.asm
-
- %define VGA_BUFFER 0xb8000
- %define WB_COLOR 0xf
-
-
-_print_string_pm_vga:
- pusha
- mov edi, VGA_BUFFER
- mov ah, WB_COLOR
- xor ecx, ecx
- xor edx, edx
-
- .print_loop:
- lodsb
- test al, al
- jz .done
-
- push eax
- mov eax, edx
- imul eax, eax, 160
- lea edi, [VGA_BUFFER + eax]
- lea edi, [edi + ecx * 2]
- pop eax
-
- ;; Advance cursor
- inc cl
- cmp cl, 80
- jb .print_loop
- xor cl, cl
- inc dl
-
- jmp .print_loop
-
- .done:
- popa
- ret
diff --git a/src/common.asm b/src/common.asm
deleted file mode 100644
index 26f7aa5..0000000
--- a/src/common.asm
+++ /dev/null
@@ -1,22 +0,0 @@
- ;; common.asm
- %ifndef COMMON_ASM
- %define COMMON_ASM
-
- ;; Real mode constants
- %define READ_SECTORS_NUM 16
- %define BOOT_LOAD_ADDR 0x7c00
- %define STAGE2_ADDR 0x7e00
- %define SECTOR_SIZE 512
- %define STACK_ADDR 0x9c00
-
- ;; Mostly kernel and protected mode constants
- %define VGA_COLOR_BLACK 0
- %define VGA_COLOR_GREEN 2
- %define VGA_COLOR_RED 4
- %define VGA_WHITE_ON_BLACK 0x0f20
- %define VGA_BUFFER 0xb8000
- %define VGA_SCREEN_X 80
- %define VGA_SCREEN_Y 25
- %define VGA_SCREEN (VGA_SCREEN_X*VGA_SCREEN_Y)
-
- %endif
diff --git a/src/common/common.asm b/src/common/common.asm
new file mode 100644
index 0000000..a98ef67
--- /dev/null
+++ b/src/common/common.asm
@@ -0,0 +1,27 @@
+;; common.asm
+%ifndef COMMON_ASM
+%define COMMON_ASM
+
+;; Real mode constants
+%define READ_SECTORS_NUM 16
+%define BOOT_LOAD_ADDR 0x7c00
+%define STAGE2_ADDR 0x7e00
+%define SECTOR_SIZE 512
+%define STACK_ADDR 0x9c00
+
+;; Mostly kernel and protected mode constants
+%define VGA_COLOR_BLACK 0
+%define VGA_COLOR_GREEN 2
+%define VGA_COLOR_RED 4
+%define VGA_WHITE_ON_BLACK 0x0f20
+%define VGA_BUFFER 0xb8000
+%define VGA_SCREEN_X 80
+%define VGA_SCREEN_Y 25
+%define VGA_SCREEN (VGA_SCREEN_X*VGA_SCREEN_Y)
+
+;; Forth-specific constants
+%define FS_DATA_STACK 0x80000
+%define FS_RET_STACK 0x90000
+%define FS_DICT_BASE 0xa0000
+
+%endif
diff --git a/src/common/common.protmode.clear.asm b/src/common/common.protmode.clear.asm
new file mode 100644
index 0000000..47cb980
--- /dev/null
+++ b/src/common/common.protmode.clear.asm
@@ -0,0 +1,13 @@
+;; common.protmode.print.asm
+
+%include "common.asm"
+
+_clear_screen:
+ mov edi, VGA_BUFFER
+ mov ecx, VGA_SCREEN
+ mov ax, VGA_WHITE_ON_BLACK
+.clear:
+ mov [edi], eax
+ add edi, 2
+ loop .clear
+ ret
diff --git a/src/common/common.protmode.print.asm b/src/common/common.protmode.print.asm
new file mode 100644
index 0000000..5995e69
--- /dev/null
+++ b/src/common/common.protmode.print.asm
@@ -0,0 +1,35 @@
+;; common.protmode.print.asm
+
+%include "common.asm"
+
+_print_string_pm_vga:
+ pusha
+ mov edi, VGA_BUFFER
+ mov ah, WB_COLOR
+ xor ecx, ecx
+ xor edx, edx
+
+.print_loop:
+ lodsb
+ test al, al
+ jz .done
+
+ push eax
+ mov eax, edx
+ imul eax, eax, 160
+ lea edi, [VGA_BUFFER + eax]
+ lea edi, [edi + ecx * 2]
+ pop eax
+
+;; Advance cursor
+ inc cl
+ cmp cl, 80
+ jb .print_loop
+ xor cl, cl
+ inc dl
+
+ jmp .print_loop
+
+.done:
+ popa
+ ret
diff --git a/src/kernel/kernel.asm b/src/kernel/kernel.asm
index 1b02249..022a93d 100644
--- a/src/kernel/kernel.asm
+++ b/src/kernel/kernel.asm
@@ -1,20 +1,22 @@
- ;; kernel.asm
- [bits 32]
- [org 0x10000]
+;; kernel.asm
+[bits 32]
+[org 0x10000]
+
+%include "common.asm"
+%include "common.protmode.print.asm"
+%include "common.protmode.clear.asm"
- %include "common.asm"
_kernel_entry:
- call _clear_screen
+ cli ; No interrupts yet
+ mov ebp, RET_STACK
+ mov esp, DATA_STACK
- .halt: hlt
- jmp .halt
+ call _clear_screen
+ call _show_welcome_msg
+
+.halt: hlt
+ jmp .halt
-_clear_screen:
- mov edi, VGA_BUFFER
- mov ecx, VGA_SCREEN
- mov ax, VGA_WHITE_ON_BLACK
- .clear:
- mov [edi], eax
- add edi, 2
- loop .clear
- ret
+welcome_msg:
+ db "Welcome...", 13, 10, 0
+
diff --git a/src/kernel/kernel.print.asm b/src/kernel/kernel.print.asm
deleted file mode 100644
index d7a6a7d..0000000
--- a/src/kernel/kernel.print.asm
+++ /dev/null
@@ -1,21 +0,0 @@
- ;; kernel.print.asm
-%define VGA_BUFFER 0xB8000
-_terminal_getidx:
- push ax
- shl dh, 1
- mov al, VGA_WIDTH
- mul dl
- mov dl, al
- shl dl, 1
- add dl, dh
- mov dh, 0
- pop ax
- ret
-
-_terminal_set_color:
- shl dl, 4
- or dl, dh
- mov [terminal_color], dl
- ret
-
-