Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/interrupt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ spurious: ; handler for spurious interrupts

; -----------------------------------------------------------------------------
; CPU Exception Gates
align 16
exception_gate_00:
mov al, 0x00
jmp exception_gate_main
Expand Down
81 changes: 48 additions & 33 deletions src/pure64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
BITS 64
ORG 0x00008000
DEFAULT ABS
%ifdef NOVIDEO
PURE64SIZE equ 4096 ; Pad Pure64 to this length
%else
PURE64SIZE equ 6144 ; Pad Pure64 to this length
%endif

start:
jmp bootmode ; This command will be overwritten with 'NOP's before the AP's are started
Expand Down Expand Up @@ -268,10 +272,11 @@ start64:

; Configure serial port @ 0x03F8 as 115200 8N1
call init_serial


%ifdef DEBUG
mov rsi, msg_pure64 ; Output "[ Pure64 ]"
call debug_msg

; Output boot method
mov rsi, msg_boot
call debug_msg
Expand All @@ -284,6 +289,7 @@ boot_uefi:
mov rsi, msg_uefi
call debug_msg
msg_boot_done:
%endif

; Clear out the first 20KiB of memory. This will store the 64-bit IDT, GDT, PML4, PDP Low, and PDP High
mov ecx, 5120
Expand Down Expand Up @@ -385,7 +391,7 @@ skip1GB:
lgdt [GDTR64]

; Point cr3 at PML4
mov rax, 0x00002008 ; Write-thru enabled (Bit 3)
mov eax, 0x00002008 ; Write-thru enabled (Bit 3)
mov cr3, rax

xor eax, eax ; aka r0
Expand Down Expand Up @@ -429,9 +435,9 @@ clearcs64:
; Build the IDT
xor edi, edi ; create the 64-bit IDT (at linear address 0x0000000000000000)

mov rcx, 32
mov ecx, 32
make_exception_gates: ; make gates for exception handlers
mov rax, exception_gate
mov eax, exception_gate
push rax ; save the exception gate to the stack for later use
stosw ; store the low word (15:0) of the address
mov ax, SYS64_CODE_SEL
Expand All @@ -443,14 +449,14 @@ make_exception_gates: ; make gates for exception handlers
stosw ; store the high word (31:16) of the address
shr rax, 16
stosd ; store the extra high dword (63:32) of the address.
xor rax, rax
xor eax, eax
stosd ; reserved
dec rcx
dec ecx
jnz make_exception_gates

mov rcx, 256-32
mov ecx, 256-32
make_interrupt_gates: ; make gates for the other interrupts
mov rax, interrupt_gate
mov eax, interrupt_gate
push rax ; save the interrupt gate to the stack for later use
stosw ; store the low word (15:0) of the address
mov ax, SYS64_CODE_SEL
Expand All @@ -464,33 +470,22 @@ make_interrupt_gates: ; make gates for the other interrupts
stosd ; store the extra high dword (63:32) of the address.
xor eax, eax
stosd ; reserved
dec rcx
dec ecx
jnz make_interrupt_gates

; Set up the exception gates for all of the CPU exceptions
; The following code depends on exception gates being below 16MB
mov word [0x00*16], exception_gate_00 ; #DE
mov word [0x01*16], exception_gate_01 ; #DB
mov word [0x02*16], exception_gate_02
mov word [0x03*16], exception_gate_03 ; #BP
mov word [0x04*16], exception_gate_04 ; #OF
mov word [0x05*16], exception_gate_05 ; #BR
mov word [0x06*16], exception_gate_06 ; #UD
mov word [0x07*16], exception_gate_07 ; #NM
mov word [0x08*16], exception_gate_08 ; #DF
mov word [0x09*16], exception_gate_09 ; #MF
mov word [0x0A*16], exception_gate_10 ; #TS
mov word [0x0B*16], exception_gate_11 ; #NP
mov word [0x0C*16], exception_gate_12 ; #SS
mov word [0x0D*16], exception_gate_13 ; #GP
mov word [0x0E*16], exception_gate_14 ; #PF
mov word [0x0F*16], exception_gate_15
mov word [0x10*16], exception_gate_16 ; #MF
mov word [0x11*16], exception_gate_17 ; #AC
mov word [0x12*16], exception_gate_18 ; #MC
mov word [0x13*16], exception_gate_19 ; #XM
mov word [0x14*16], exception_gate_20 ; #VE
mov word [0x15*16], exception_gate_21 ; #CP
; The following code depends on:
; - Exception gates being below 16MB
; - Each exception_gate_XX being exactly 4 bytes apart
mov eax, exception_gate_00 ; Address of first handler
xor edi, edi ; Clear EDI as IDT starts at 0x0000
mov cl, 22 ; 22 exception gates (0x00-0x15)
set_exception_gate:
mov [rdi], ax ; Patch low word of handler address in IDT entry
add edi, 16 ; Advance to next IDT entry (16 bytes each)
add eax, 4 ; Advance to next gate handler (4 bytes each)
dec cl
jnz set_exception_gate

lidt [IDTR64] ; load IDT register

Expand Down Expand Up @@ -745,48 +740,64 @@ pde_end:
call debug_block
%endif

%ifdef DEBUG
mov rsi, msg_acpi
call debug_msg
%endif
call init_acpi ; Find and process the ACPI tables
%ifdef DEBUG
mov rsi, msg_ok
call debug_msg
%endif

%ifndef NOVIDEO
; Visual Debug (4/8)
mov ebx, 6
call debug_block
%endif

%ifdef DEBUG
mov rsi, msg_bsp
call debug_msg
%endif
call init_cpu ; Configure the BSP CPU
%ifdef DEBUG
mov rsi, msg_ok
call debug_msg
%endif

%ifndef NOVIDEO
; Visual Debug (5/8)
mov ebx, 8
call debug_block
%endif

%ifdef DEBUG
; Configure system timer
mov rsi, msg_timer
call debug_msg
%endif
call init_timer ; Configure the timer
%ifdef DEBUG
mov rsi, msg_ok
call debug_msg
%endif

%ifndef NOVIDEO
; Visual Debug (6/8)
mov ebx, 10
call debug_block
%endif

%ifdef DEBUG
mov rsi, msg_smp
call debug_msg
%endif
call init_smp ; Init of SMP, deactivate interrupts
%ifdef DEBUG
mov rsi, msg_ok
call debug_msg
%endif

; Reset the stack to the proper location (was set to 0x8000 previously)
mov rsi, [p_LocalAPICAddress] ; We would call p_smp_get_id here but the stack is not ...
Expand Down Expand Up @@ -945,8 +956,10 @@ lfb_wc_end:
call debug_block
%endif

%ifdef DEBUG
mov rsi, msg_kernel
call debug_msg
%endif

%ifdef FLOPPY
cmp byte [p_BootDisk], 'F' ; Check if sys is booted from floppy?
Expand Down Expand Up @@ -1073,6 +1086,7 @@ debug_progressbar:
%endif


%ifdef DEBUG
; -----------------------------------------------------------------------------
; debug_msg_char - Send a single char via the serial port
; IN: AL = Byte to send
Expand Down Expand Up @@ -1171,6 +1185,7 @@ debug_dump_al_l:
pop rax ; Restore RAX
ret
; -----------------------------------------------------------------------------
%endif


EOF:
Expand Down
2 changes: 2 additions & 0 deletions src/sysvar.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
; =============================================================================


%ifdef DEBUG
; Messages
msg_pure64: db 13, 10, 13, 10, '[ Pure64 ]', 0
msg_ok: db 'ok', 0
Expand All @@ -20,6 +21,7 @@ msg_bsp: db 13, 10, 'bsp ', 0
msg_timer: db 13, 10, 'timer ', 0
msg_smp: db 13, 10, 'smp ', 0
msg_kernel: db 13, 10, 'kernel start', 13, 10, 0
%endif

;CONFIG
cfg_smpinit: db 1 ; By default SMP is enabled. Set to 0 to disable.
Expand Down
Loading