Skip to content

Commit a96fcbb

Browse files
committed
Fix/improve error messages
1 parent 104f5b4 commit a96fcbb

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

src/stage_2.s

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
.code16
44

55
second_stage_start_str: .asciz "Booting (second stage)..."
6-
loading_kernel_block_str: .asciz "loading kernel block..."
7-
kernel_load_failed_str: .asciz "Failed to load kernel"
6+
kernel_load_failed_str: .asciz "Failed to load kernel from disk"
87

98
kernel_load_failed:
10-
jmp kernel_load_failed
9+
lea si, [kernel_load_failed_str]
10+
call println
11+
kernel_load_failed_spin:
12+
jmp kernel_load_failed_spin
1113

1214
stage_2:
15+
lea si, [second_stage_start_str]
16+
call println
17+
1318
set_target_operating_mode:
1419
# Some BIOSs assume the processor will only operate in Legacy Mode. We change the Target
1520
# Operating Mode to "Long Mode Target Only", so the firmware expects each CPU to enter Long Mode

src/stage_3.s

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
.intel_syntax noprefix
33
.code32
44

5-
no_long_mode_str: .asciz "No long mode support"
6-
75
stage_3:
86
mov bx, 0x10
97
mov ds, bx # set data segment
108
mov es, bx # set extra segment
119
mov ss, bx # set stack segment
1210

11+
# print "3rd stage" to the top right
12+
mov eax, 0x0f720f33 # "3r"
13+
mov [0xb808c], eax
14+
mov eax, 0x0f200f64 # "d "
15+
mov [0xb808c + 4], eax
16+
mov eax, 0x0f740f73 # "st"
17+
mov [0xb808c + 8], eax
18+
mov eax, 0x0f670f61 # "ag"
19+
mov [0xb808c + 12], eax
20+
mov eax, 0x0f200f65 # "e "
21+
mov [0xb808c + 16], eax
22+
1323
check_cpu:
1424
call check_cpuid
1525
call check_long_mode
@@ -143,8 +153,18 @@ check_cpuid:
143153
je no_cpuid
144154
ret
145155
no_cpuid:
146-
lea si, no_cpuid_str
147-
jmp no_cpuid
156+
# print "no cpuid" to the top right
157+
mov eax, 0x4f6f4f6e # "no"
158+
mov [0xb8130], eax
159+
mov eax, 0x4f634f20 # " c"
160+
mov [0xb8130 + 4], eax
161+
mov eax, 0x4f754f70 # "pu"
162+
mov [0xb8130 + 8], eax
163+
mov eax, 0x4f644f69 # "id"
164+
mov [0xb8130 + 12], eax
165+
no_cpuid_spin:
166+
hlt
167+
jmp no_cpuid_spin
148168

149169
check_long_mode:
150170
# test if extended processor info in available
@@ -160,8 +180,22 @@ check_long_mode:
160180
jz no_long_mode # If it's not set, there is no long mode
161181
ret
162182
no_long_mode:
163-
lea si, no_long_mode_str
164-
jmp no_long_mode
183+
# print "no long mode" to the top right
184+
mov eax, 0x4f6f4f6e # "no"
185+
mov [0xb8128], eax
186+
mov eax, 0x4f6c4f20 # " l"
187+
mov [0xb8128 + 4], eax
188+
mov eax, 0x4f6e4f6f # "on"
189+
mov [0xb8128 + 8], eax
190+
mov eax, 0x4f204f67 # "g "
191+
mov [0xb8128 + 12], eax
192+
mov eax, 0x4f6f4f6d # "mo"
193+
mov [0xb8128 + 16], eax
194+
mov eax, 0x4f654f64 # "de"
195+
mov [0xb8128 + 20], eax
196+
no_long_mode_spin:
197+
hlt
198+
jmp no_long_mode_spin
165199

166200

167201
.align 4

0 commit comments

Comments
 (0)