Skip to content

Commit 750bf87

Browse files
author
Ian Seyler
committed
Optimizations to kernel size
- Add kernel build flag for NO_VGA. By default this is enabled - Re-org if statements for calls of os_debug_string - Use 32-bit register sets in interrupt.asm where possible. This saves 5 bytes per `mov`
1 parent c0dcf0f commit 750bf87

File tree

9 files changed

+40
-38
lines changed

9 files changed

+40
-38
lines changed

build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
BUILDFLAGS=""
3+
BUILDFLAGS="-dNO_VGA"
44

55
# Internal
66
# -dNO_VIRTIO Remove VirtIO drivers (NVS, NET)
@@ -14,7 +14,8 @@ BUILDFLAGS=""
1414
# -dNO_I8259X Remove i8259x 10-Gigabit driver
1515
# HID
1616
# -dNO_XHCI Remove xHCI USB driver (hid)
17-
# -dNO_LFB Remove LFB text driver
17+
# -dNO_LFB Remove LFB graphical text output driver
18+
# -dNO_VGA Remove VGA text output driver
1819

1920
mkdir -p bin
2021
cd src

src/drivers.asm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
; Video
5656
%ifndef NO_LFB
5757
%include "drivers/lfb/lfb.asm"
58-
%else
58+
%endif
59+
%ifndef NO_VGA
5960
%include "drivers/vga.asm"
6061
%endif
6162

src/init/64.asm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,25 @@ make_interrupt_gate_stubs:
115115
; Configure the serial port (if present)
116116
call serial_init
117117

118+
init_64_lfb:
118119
; Initialize text output
119120
%ifndef NO_LFB
121+
; Check if LFB was enabled by Pure64
122+
mov rax, [os_screen_lfb]
123+
cmp rax, 0
124+
je init_64_vga
120125
call lfb_init ; Initialize LFB for text output
121-
%else
126+
%endif
127+
init_64_vga:
128+
%ifndef NO_VGA
122129
call vga_init
123-
; Output progress via serial
130+
%endif
131+
132+
; Output progress via debug
124133
mov rsi, msg_baremetal
125134
call os_debug_string
126135
mov rsi, msg_64
127136
call os_debug_string
128-
%endif
129137

130138
; Initialize the APIC
131139
call os_apic_init
@@ -164,11 +172,11 @@ no_more_aps:
164172
; Output block to screen (2/8)
165173
mov ebx, 2
166174
call os_debug_block
167-
%else
175+
%endif
176+
168177
; Output progress via serial
169178
mov rsi, msg_ok
170179
call os_debug_string
171-
%endif
172180

173181
ret
174182
; -----------------------------------------------------------------------------

src/init/bus.asm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
; -----------------------------------------------------------------------------
3030
init_bus:
3131

32-
%ifdef NO_LFB
3332
; Output progress via serial
3433
mov rsi, msg_bus
3534
call os_debug_string
36-
%endif
3735

3836
mov rdi, bus_table ; Address of Bus Table in memory
3937
xor edx, edx ; Register 0 for Device ID/Vendor ID
@@ -165,11 +163,11 @@ init_bus_usb_not_found:
165163
; Output block to screen (4/8)
166164
mov ebx, 6
167165
call os_debug_block
168-
%else
166+
%endif
167+
169168
; Output progress via serial
170169
mov rsi, msg_ok
171170
call os_debug_string
172-
%endif
173171

174172
ret
175173
; -----------------------------------------------------------------------------

src/init/net.asm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
; init_net -- Configure the first network device it finds
1111
init_net:
1212

13-
%ifdef NO_LFB
1413
; Output progress via serial
1514
mov rsi, msg_net
1615
call os_debug_string
17-
%endif
1816

1917
mov ax, [NIC_DeviceVendor_ID] ; Check for NIC driver definitions
2018
cmp ax, 0x0000
@@ -123,11 +121,11 @@ init_net_end:
123121
; Output block to screen (6/8)
124122
mov ebx, 10
125123
call os_debug_block
126-
%else
124+
%endif
125+
127126
; Output progress via serial
128127
mov rsi, msg_ok
129128
call os_debug_string
130-
%endif
131129

132130
ret
133131
; -----------------------------------------------------------------------------

src/init/nvs.asm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
; init_nvs -- Configure the first non-volatile storage device it finds
1111
init_nvs:
1212

13-
%ifdef NO_LFB
1413
; Output progress via serial
1514
mov rsi, msg_nvs
1615
call os_debug_string
17-
%endif
1816

1917
%ifndef NO_NVME
2018
; Check Bus Table for NVMe
@@ -93,11 +91,11 @@ init_nvs_done:
9391
; Output block to screen (5/8)
9492
mov ebx, 8
9593
call os_debug_block
96-
%else
94+
%endif
95+
9796
; Output progress via serial
9897
mov rsi, msg_ok
9998
call os_debug_string
100-
%endif
10199

102100
ret
103101
; -----------------------------------------------------------------------------

src/init/sys.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ init_sys_done:
2525
; Output block to screen (8/8)
2626
mov ebx, 14
2727
call os_debug_block
28-
%else
28+
%endif
29+
2930
; Output progress via serial
3031
mov rsi, msg_ready
3132
call os_debug_string
32-
%endif
3333

3434
ret
3535
; -----------------------------------------------------------------------------

src/interrupt.asm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
; Default exception handler
1111
align 8
1212
exception_gate:
13-
mov rsi, int_string00
13+
mov esi, int_string00
1414
call b_output
15-
mov rsi, exc_string
15+
mov esi, exc_string
1616
call b_output
1717
jmp $ ; Hang
1818
; -----------------------------------------------------------------------------
@@ -175,7 +175,7 @@ ap_wakeup:
175175
align 8
176176
ap_reset:
177177
; Don't use 'os_apic_write' as we can't guarantee the state of the stack
178-
mov rax, ap_clear ; Set RAX to the address of ap_clear
178+
mov eax, ap_clear ; Set RAX to the address of ap_clear
179179
mov [rsp], rax ; Overwrite the return address on the CPU's stack
180180
mov rdi, [os_LocalAPICAddress] ; Acknowledge the IPI
181181
add rdi, 0xB0
@@ -378,24 +378,24 @@ exception_gate_main:
378378
push rcx ; Char counter for b_output
379379
push rax ; Save RAX since b_smp_get_id clobbers it
380380
call os_debug_newline
381-
mov rsi, int_string00
382-
mov rcx, 6
381+
mov esi, int_string00
382+
mov ecx, 6
383383
call b_output
384384
call b_smp_get_id ; Get the local CPU ID and print it
385385
call os_debug_dump_ax
386-
mov rsi, int_string01
387-
mov rcx, 15
386+
mov esi, int_string01
387+
mov ecx, 15
388388
call b_output
389-
mov rsi, exc_string00
389+
mov esi, exc_string00
390390
pop rax
391-
and rax, 0x00000000000000FF ; Clear out everything in RAX except for AL
391+
and eax, 0x00000000000000FF ; Clear out everything in RAX except for AL
392392
push rax
393393
mov bl, 6 ; Length of each message
394394
mul bl ; AX = AL x BL
395395
add rsi, rax ; Use the value in RAX as an offset to get to the right message
396396
pop rax
397397
mov bl, 0x0F
398-
mov rcx, 6
398+
mov ecx, 6
399399
call b_output
400400
pop rcx
401401
pop rsi
@@ -420,14 +420,14 @@ exception_gate_main:
420420
push rcx
421421
push rbx
422422
push rax
423-
mov rsi, reg_string00 ; Load address of first register string
423+
mov esi, reg_string00 ; Load address of first register string
424424
mov ecx, 4 ; Number of characters per reg_string
425425
mov edx, 16 ; Counter of registers to left to output
426426
xor ebx, ebx ; Counter of registers output per line
427427
call os_debug_newline
428428
exception_gate_main_nextreg:
429429
call b_output
430-
add rsi, 4
430+
add esi, 4
431431
pop rax
432432
call os_debug_dump_rax
433433
add ebx, 1
@@ -445,7 +445,7 @@ exception_gate_main_nextreg_continue:
445445
mov rax, [rsp+8] ; RIP of caller
446446
call os_debug_dump_rax
447447
call os_debug_space
448-
add rsi, 4
448+
add esi, 4
449449
call b_output
450450
mov rax, cr2
451451
call os_debug_dump_rax

src/syscalls/debug.asm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ os_debug_space:
155155
; -----------------------------------------------------------------------------
156156

157157

158-
%ifdef NO_LFB
159158
; -----------------------------------------------------------------------------
160159
; os_debug_string - Dump a string to output
161160
; IN: RSI = String Address (null terminated)
@@ -172,14 +171,13 @@ os_debug_string:
172171
not rcx
173172
dec rcx
174173

175-
call b_output
174+
call b_output_serial
176175

177176
pop rax
178177
pop rcx
179178
pop rdi
180179
ret
181180
; -----------------------------------------------------------------------------
182-
%endif
183181

184182

185183
%ifndef NO_LFB

0 commit comments

Comments
 (0)