Skip to content

Instantly share code, notes, and snippets.

@orumin
Created December 22, 2017 21:19
entry.s
uefi_entry_start:
.if longmode
mov uefi_entry_physoff(%rip),%rax
call uefi_entry_rip_plus_rax
mov uefi_entry_cr3(%rip),%rax
mov %rax,%cr3
mov uefi_entry_physoff(%rip),%rax
add $head-0x100000,%rax
neg %rax
add %rdi,%rax
add %rax,entry_pml4-DIFFPHYS(%rdi)
add %rax,entry_pdp+0-DIFFPHYS(%rdi)
add %rax,entry_pdp+8-DIFFPHYS(%rdi)
mov %rdi,%rax
mov $0x83,%al
xor %ebx,%ebx
1:
mov %rax,entry_pd-DIFFPHYS(%rdi,%rbx,8)
add $0x200000,%rax
add $1,%ebx
cmp $512,%ebx
jb 1b
lea entry_pml4-DIFFPHYS(%rdi),%rax
mov %rax,%cr3
mov %edi,vmm_start_phys
sgdtq calluefi_uefi_gdtr
sidtq calluefi_uefi_idtr
sldt calluefi_uefi_ldtr
mov %es,calluefi_uefi_sregs+0
mov %cs,calluefi_uefi_sregs+2
mov %ss,calluefi_uefi_sregs+4
mov %ds,calluefi_uefi_sregs+6
mov %fs,calluefi_uefi_sregs+8
mov %gs,calluefi_uefi_sregs+10
mov uefi_entry_cr3(%rip),%rax
mov %rax,calluefi_uefi_cr3
mov $bss,%edi # Clear BSS
mov $end+3,%ecx #
sub %edi,%ecx #
shr $2,%ecx #
xor %eax,%eax #
cld #
rep stosl #
mov %cr4,%rcx
or $(CR4_PAE_BIT|CR4_PGE_BIT),%rcx
and $~CR4_MCE_BIT,%rcx
mov %cr3,%rax
mov %rcx,entry_cr4 # Save CR4
mov %rax,vmm_base_cr3 # Save CR3
mov %rcx,%cr4
lgdtq entry_gdtr # Load GDTR
ljmpl *1f
1:
.long callmain64
.long ENTRY_SEL_CODE64
.else
ret
.endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment