-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel_entry.asm
More file actions
117 lines (95 loc) · 2.88 KB
/
kernel_entry.asm
File metadata and controls
117 lines (95 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
; ============================================================================
; KERNEL ENTRY POINT (32-bit Protected Mode)
; ============================================================================
; This is the first code executed when the bootloader jumps to the kernel.
; It sets up the environment and calls the C kernel main function.
; ============================================================================
[bits 32]
[extern kernel_main]
[global _start]
section .text
_start:
; We're now in 32-bit protected mode!
; Stack is already set up by bootloader at 0x90000
; Clear the screen first
call clear_screen
; Print welcome message
mov esi, msg_kernel_entry
call print_string_pm
; Call C kernel main
call kernel_main
; If kernel_main returns, halt
.halt:
cli
hlt
jmp .halt
; ============================================================================
; Clear Screen (32-bit protected mode)
; ============================================================================
clear_screen:
push eax
push ecx
push edi
mov edi, 0xB8000 ; VGA text buffer
mov ecx, 80 * 25 ; 80 columns * 25 rows
mov ax, 0x0720 ; Space character with light gray on black
rep stosw
; Reset cursor position
mov dword [cursor_pos], 0
pop edi
pop ecx
pop eax
ret
; ============================================================================
; Print String (32-bit protected mode, direct VGA)
; Input: ESI = null-terminated string
; ============================================================================
print_string_pm:
push eax
push ebx
push esi
.loop:
lodsb ; Load character from ESI
test al, al
jz .done
cmp al, 0x0D ; Carriage return?
je .cr
cmp al, 0x0A ; Line feed?
je .lf
; Calculate VGA buffer position
mov ebx, [cursor_pos]
mov byte [0xB8000 + ebx*2], al
mov byte [0xB8000 + ebx*2 + 1], 0x0A ; Light green on black
inc dword [cursor_pos]
jmp .loop
.cr:
; Move to start of line
mov eax, [cursor_pos]
xor edx, edx
mov ebx, 80
div ebx ; EAX = row, EDX = column
mul ebx ; EAX = start of current row
mov [cursor_pos], eax
jmp .loop
.lf:
; Move to next line
mov eax, [cursor_pos]
xor edx, edx
mov ebx, 80
div ebx ; EAX = row
inc eax ; Next row
mul ebx
mov [cursor_pos], eax
jmp .loop
.done:
pop esi
pop ebx
pop eax
ret
; ============================================================================
; Data
; ============================================================================
section .data
cursor_pos: dd 0
msg_kernel_entry: db 'Nyx Kernel Entry Point', 0x0D, 0x0A, 0
section .bss