Skip to content

Commit e05f19f

Browse files
committed
Tidy
1 parent a8e13b2 commit e05f19f

4 files changed

Lines changed: 36 additions & 37 deletions

File tree

src/init/smp.asm

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ smp_send_SIPI_done:
117117

118118
noMP:
119119

120-
; Calculate base speed of CPU
121-
cpuid
122-
xor edx, edx
123-
xor eax, eax
124-
rdtsc
125-
push rax
126-
mov rax, 1024 ; 1024 microseconds (1ms)
127-
call timer_delay
128-
rdtsc
129-
pop rdx
130-
sub rax, rdx
131-
xor edx, edx
132-
mov rcx, 1024
133-
div rcx
134-
mov [p_cpu_speed], ax
120+
; ; Calculate base speed of CPU
121+
; cpuid
122+
; xor edx, edx
123+
; xor eax, eax
124+
; rdtsc
125+
; push rax
126+
; mov rax, 1024 ; 1024 microseconds (1ms)
127+
; call timer_delay
128+
; rdtsc
129+
; pop rdx
130+
; sub rax, rdx
131+
; xor edx, edx
132+
; mov rcx, 1024
133+
; div rcx
134+
; mov [p_cpu_speed], ax
135135

136136
ret
137137

src/init/timer.asm

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ init_timer_hpet:
6666
mov rbx, rax ; Move Counter Clock Period to RBX
6767
xor rdx, rdx
6868
mov rax, 1000000000000000 ; femotoseconds per second
69-
div rbx ; RDX:RAX / RBX
69+
div rbx ; RDX:RAX / RBX = frequency in Hz
7070
mov [p_HPET_Frequency], eax ; Save the HPET frequency
7171

72+
; Precompute cycles per microsecond (freq_Hz / 1,000,000)
73+
xor rdx, rdx
74+
mov ecx, 1000000
75+
div rcx
76+
mov [p_HPET_CyclesPerUs], rax
77+
7278
; Disable interrupts on all timers
7379
xor ebx, ebx
7480
mov bl, [p_HPET_Timers]
@@ -140,24 +146,18 @@ hpet_delay:
140146
push rax
141147

142148
mov rbx, rax ; Save delay to RBX
143-
xor edx, edx
144-
xor ecx, ecx
145-
call hpet_read ; Get HPET General Capabilities and ID Register
146-
shr rax, 32
147-
mov rcx, rax ; RCX = RAX >> 32 (timer period in femtoseconds)
148-
mov rax, 1000000000
149-
div rcx ; Divide 1000000000 (RDX:RAX) / RCX (converting from period in femtoseconds to frequency in MHz)
150-
mul rbx ; RAX *= RBX, should get number of HPET cycles to wait, save result in RBX
149+
mov rax, [p_HPET_CyclesPerUs] ; Use precomputed cycles per microsecond
150+
mul rbx ; RAX = cycles to wait
151151
mov rbx, rax
152152
mov ecx, HPET_MAIN_COUNTER
153153
call hpet_read ; Get HPET counter in RAX
154-
add rbx, rax ; RBX += RAX Until when to wait
154+
add rbx, rax ; RBX = target counter value
155155
hpet_delay_loop: ; Stay in this loop until the HPET timer reaches the expected value
156+
pause
156157
mov ecx, HPET_MAIN_COUNTER
157158
call hpet_read ; Get HPET counter in RAX
158-
cmp rax, rbx ; If RAX >= RBX then jump to end, otherwise jump to loop
159-
jae hpet_delay_end
160-
jmp hpet_delay_loop
159+
cmp rax, rbx
160+
jb hpet_delay_loop
161161
hpet_delay_end:
162162

163163
pop rax
@@ -291,6 +291,7 @@ kvm_delay:
291291
call kvm_get_usec
292292
add rbx, rax ; Add elapsed time
293293
kvm_delay_wait:
294+
pause
294295
call kvm_get_usec
295296
cmp rax, rbx
296297
jb kvm_delay_wait

src/pure64.asm

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ pdpte_low_32:
149149
pop eax
150150
add eax, 0x00001000 ; 4KiB later (512 records x 8 bytes)
151151
dec ecx
152-
cmp ecx, 0
153-
jne pdpte_low_32
152+
jnz pdpte_low_32
154153

155154
; Create the temporary low Page-Directory Entries (PDE).
156155
; A single PDE can map 2MiB of RAM
@@ -693,8 +692,7 @@ create_pdpe_high:
693692
stosq
694693
add rax, 0x00001000 ; 4K later (512 records x 8 bytes)
695694
dec ecx
696-
cmp ecx, 0
697-
jne create_pdpe_high
695+
jnz create_pdpe_high
698696

699697
; Create the High Page-Directory Entries (PDE).
700698
; A single PDE can map 2MiB of RAM
@@ -714,15 +712,14 @@ pde_next_range:
714712
sub rcx, 2 ; Subtract 2 MiB from the length
715713
skipfirst4mb:
716714
shr ecx, 1 ; Quick divide by 2 for 2 MB pages
715+
cmp ecx, 0
716+
je pde_next_range
717717
add rax, 0x00000083 ; Bits 0 (P), 1 (R/W), and 7 (PS) set
718718
pde_high: ; Create a 2MiB page
719719
stosq
720720
add rax, 0x00200000 ; Increment by 2MiB
721-
cmp ecx, 0
722-
je pde_next_range
723721
dec ecx
724-
cmp ecx, 0
725-
jne pde_high
722+
jnz pde_high
726723
jmp pde_next_range
727724
pde_end:
728725

src/sysvar.asm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ msg_kernel: db 13, 10, 'kernel start', 13, 10, 0
2424
%endif
2525

2626
;CONFIG
27-
cfg_smpinit: db 1 ; By default SMP is enabled. Set to 0 to disable.
27+
cfg_smpinit: db 0 ; By default SMP is enabled. Set to 0 to disable.
2828

2929
; Memory locations
3030
InfoMap: equ 0x0000000000005000
@@ -38,6 +38,7 @@ VBEModeInfoBlock: equ 0x0000000000005F00 ; 256 bytes
3838

3939
; DQ - Starting at offset 0, increments by 0x8
4040
p_ACPITableAddress: equ SystemVariables + 0x00
41+
p_HPET_CyclesPerUs: equ SystemVariables + 0x08 ; Precomputed HPET cycles per microsecond
4142
p_LocalAPICAddress: equ SystemVariables + 0x10
4243
p_HPET_Address: equ SystemVariables + 0x28
4344
sys_timer: equ SystemVariables + 0x30

0 commit comments

Comments
 (0)