Skip to content

Commit 7d720f8

Browse files
author
Ian Seyler
committed
Re-org
1 parent 4362bec commit 7d720f8

File tree

9 files changed

+70
-47
lines changed

9 files changed

+70
-47
lines changed

src/init.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
%include "init/nvs.asm"
1212
%include "init/net.asm"
1313
%include "init/hid.asm"
14+
%include "init/sys.asm"
1415

1516

1617
; =============================================================================

src/init/64.asm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ make_interrupt_gate_stubs:
108108
; Initialize the linear frame buffer output
109109
call lfb_init
110110

111+
; Output block to screen (1/8)
112+
mov ebx, 0
113+
call os_debug_block
114+
111115
; Initialize the APIC
112116
call os_apic_init
113117

@@ -117,6 +121,10 @@ make_interrupt_gate_stubs:
117121
; Initialize the HPET
118122
call os_hpet_init
119123

124+
; Output block to screen (2/8)
125+
mov ebx, 2
126+
call os_debug_block
127+
120128
; Initialize all AP's to run our reset code. Skip the BSP
121129
call b_smp_get_id
122130
mov ebx, eax
@@ -138,8 +146,8 @@ no_more_aps:
138146
; Configure the serial port
139147
call serial_init
140148

141-
; Output block to screen (1/8)
142-
mov ebx, 0
149+
; Output block to screen (3/8)
150+
mov ebx, 4
143151
call os_debug_block
144152

145153
ret

src/init/bus.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ init_bus_usb_xhci_start:
148148

149149
init_bus_usb_not_found:
150150

151-
; Output block to screen (3/8)
152-
mov ebx, 4
151+
; Output block to screen (4/8)
152+
mov ebx, 6
153153
call os_debug_block
154154

155155
ret

src/init/hid.asm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ init_hid:
1919
cli
2020

2121
init_hid_done:
22-
; Output block to screen (6-8/8)
23-
mov ebx, 10
24-
call os_debug_block
22+
; Output block to screen (7/8)
2523
mov ebx, 12
2624
call os_debug_block
27-
mov ebx, 14
28-
call os_debug_block
2925
ret
3026
; -----------------------------------------------------------------------------
3127

src/init/net.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ init_net_probe_found_finish:
9191
init_net_probe_not_found:
9292

9393
init_net_end:
94-
; Output block to screen (5/8)
95-
mov ebx, 8
94+
; Output block to screen (7/8)
95+
mov ebx, 10
9696
call os_debug_block
9797

9898
ret

src/init/nvs.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ init_nvs_ata:
6565
jmp init_nvs_done
6666

6767
init_nvs_done:
68-
; Output block to screen (4/8)
69-
mov ebx, 6
68+
; Output block to screen (5/8)
69+
mov ebx, 8
7070
call os_debug_block
7171

7272
ret

src/init/sys.asm

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; =============================================================================
2+
; BareMetal -- a 64-bit OS written in Assembly for x86-64 systems
3+
; Copyright (C) 2008-2025 Return Infinity -- see LICENSE.TXT
4+
;
5+
; Initialize system to start payload
6+
; =============================================================================
7+
8+
9+
; -----------------------------------------------------------------------------
10+
init_sys:
11+
; Copy the payload after the kernel to the proper address
12+
mov esi, 0x100000 + KERNELSIZE ; Payload starts right after the kernel
13+
mov edi, 0x1E0000
14+
mov ecx, 2048
15+
rep movsq ; Copy 16384 bytes
16+
17+
; Set the payload to run
18+
bsp_run_payload:
19+
mov rsi, [os_LocalAPICAddress] ; We can't use b_smp_get_id as no configured stack yet
20+
xor eax, eax ; Clear Task Priority (bits 7:4) and Task Priority Sub-Class (bits 3:0)
21+
mov dword [rsi+0x80], eax ; APIC Task Priority Register (TPR)
22+
mov eax, dword [rsi+0x20] ; APIC ID in upper 8 bits
23+
shr eax, 24 ; Shift to the right and AL now holds the CPU's APIC ID
24+
mov [os_BSP], al ; Keep a record of the BSP APIC ID
25+
mov ebx, eax ; Save the APIC ID
26+
mov rdi, os_SMP ; Clear the entry in the work table
27+
shl rax, 3 ; Quick multiply by 8 to get to proper record
28+
add rdi, rax
29+
xor eax, eax
30+
or al, 1 ; Set bit 0 for "present"
31+
stosq ; Clear the code address
32+
mov rcx, rbx ; Copy the APIC ID for b_smp_set
33+
mov rax, 0x1E0000 ; Payload was copied here
34+
call b_smp_set
35+
36+
init_sys_done:
37+
; Output block to screen (8/8)
38+
mov ebx, 14
39+
call os_debug_block
40+
ret
41+
; -----------------------------------------------------------------------------
42+
43+
44+
; =============================================================================
45+
; EOF

src/kernel.asm

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,11 @@ start:
3939
call init_nvs ; Initialize non-volatile storage
4040
call init_net ; Initialize network
4141
call init_hid ; Initialize human interface devices
42-
43-
; Copy the payload after the kernel to the proper address
44-
mov rsi, 0x100000 + KERNELSIZE ; Payload starts right after the kernel
45-
cmp qword [rsi], 0 ; Is there a payload after the kernel?
42+
cmp qword [0x100000 + KERNELSIZE], 0 ; Is there a payload after the kernel?
4643
je ap_clear ; If not, skip to ap_clear
47-
mov rdi, 0x1E0000
48-
mov rcx, 2048
49-
rep movsq ; Copy 16384 bytes
50-
51-
; Set the payload to run
52-
bsp_run_payload:
53-
mov rsi, [os_LocalAPICAddress] ; We can't use b_smp_get_id as no configured stack yet
54-
xor eax, eax ; Clear Task Priority (bits 7:4) and Task Priority Sub-Class (bits 3:0)
55-
mov dword [rsi+0x80], eax ; APIC Task Priority Register (TPR)
56-
mov eax, dword [rsi+0x20] ; APIC ID in upper 8 bits
57-
shr eax, 24 ; Shift to the right and AL now holds the CPU's APIC ID
58-
mov [os_BSP], al ; Keep a record of the BSP APIC ID
59-
mov ebx, eax ; Save the APIC ID
60-
mov rdi, os_SMP ; Clear the entry in the work table
61-
shl rax, 3 ; Quick multiply by 8 to get to proper record
62-
add rdi, rax
63-
xor eax, eax
64-
or al, 1 ; Set bit 0 for "present"
65-
stosq ; Clear the code address
66-
mov rcx, rbx ; Copy the APIC ID for b_smp_set
67-
mov rax, 0x1E0000 ; Payload was copied here
68-
call b_smp_set
44+
call init_sys
6945
jmp bsp ; Skip past some of the ap_clear code we have already executed
7046

71-
; Fall through to ap_clear as align fills the space with No-Ops
72-
; At this point the BSP is just like one of the AP's
73-
7447
align 16
7548
ap_clear: ; All cores start here on first start-up and after an exception
7649
cli ; Disable interrupts on this core

src/syscalls/debug.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,21 @@ os_debug_block:
171171
xor edx, edx
172172
xor eax, eax
173173
xor ebx, ebx
174-
mov ax, [0x00005F00 + 0x12] ; Screen Y
174+
mov ax, [os_screen_y] ; Screen Y
175175
add ax, 16 ; Lower row
176176
shr ax, 1 ; Quick divide by 2
177-
mov bx, [0x00005F00 + 0x10] ; Screen X
177+
mov bx, [os_screen_x] ; Screen X
178178
shl ebx, 2 ; Quick multiply by 4
179179
mul ebx ; Multiply EDX:EAX by EBX
180-
mov rdi, [0x00005F00] ; Frame buffer base
180+
mov rdi, [os_screen_lfb] ; Frame buffer base
181181
add rdi, rax ; Offset is ((screeny - 8) / 2 + screenx * 4)
182182
pop rax
183183
pop rbx
184184
xor edx, edx
185-
mov dx, [0x00005F00 + 0x14] ; PixelsPerScanLine
185+
mov dx, [os_screen_ppsl] ; PixelsPerScanLine
186186
shl edx, 2 ; Quick multiply by 4 for line offset
187187
xor ecx, ecx
188-
mov cx, [0x00005F00 + 0x10] ; Screen X
188+
mov cx, [os_screen_x] ; Screen X
189189
shr cx, 4 ; Quick divide by 16 (box width plus blank width)
190190
sub cx, 8 ; CX = total amount of 8-pixel wide blocks
191191
add ebx, ecx

0 commit comments

Comments
 (0)