DragonOS/kernel/smp/apu_boot.S

155 lines
2.9 KiB
ArmAsm
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "../common/asm.h"
.balign 0x1000 // 4k
.text
.code16
ENTRY(_apu_boot_start)
_apu_boot_base = .
cli
wbinvd //
mov %cs, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %ss
mov %ax, %fs
mov %ax, %gs
//
movl $(_apu_boot_tmp_stack_end - _apu_boot_base), %esp
// ap
mov %cs, %ax
movzx %ax, %esi
shll $4, %esi
// set gdt and 32bit/64bit code addr
leal (_apu_code32 - _apu_boot_base)(%esi), %eax
movl %eax, (_apu_code32_vector - _apu_boot_base)
leal (_apu_code64 - _apu_boot_base)(%esi), %eax
movl %eax, (_apu_code64_vector - _apu_boot_base)
leal (_apu_tmp_gdt - _apu_boot_base)(%esi), %eax
movl %eax, (_apu_tmp_gdt + 2 - _apu_boot_base)
//
lidtl _apu_tmp_idt - _apu_boot_base
lgdtl _apu_tmp_gdt - _apu_boot_base
// cr0使
smsw %ax
bts $0, %ax
lmsw %ax
//
ljmpl *(_apu_code32_vector - _apu_boot_base)
.code32
.balign 4
_apu_code32:
#
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %ss
mov %ax, %fs
mov %ax, %gs
//
leal (_apu_boot_tmp_stack_end - _apu_boot_base)(%esi), %eax
movl %eax, %esp
// open PAE
movl %cr4, %eax
bts $5, %eax
movl %eax, %cr4
//
movl $pml4, %eax // bsp32
movl %eax, %cr3
mov $0xC0000080, %ecx
rdmsr
or $(1<<8), %eax
wrmsr
// enable PE and paging
mov %cr0, %eax
or $(1<<31), %eax
mov %eax, %cr0
// 64
ljmp *(_apu_code64_vector - _apu_boot_base)(%esi)
.code64
.balign 4
_apu_code64:
movq $0x20, %rax
movq %rax, %ds
movq %rax, %es
movq %rax, %ss
movq %rax, %fs
movq %rax, %gs
//now enable SSE and the like
movq %cr0, %rax
and $0xFFFB, %ax //clear coprocessor emulation CR0.EM
or $0x2, %ax //set coprocessor monitoring CR0.MP
movq %rax, %cr0
movq %cr4, %rax
or $(3 << 9), %ax //set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time
movq %rax, %cr4
// 1MB
movq $_start64, %rax
jmpq *%rax
hlt
.balign 4
_apu_tmp_idt:
.word 0
.word 0,0
.balign 4
_apu_tmp_gdt:
.short _apu_tmp_gdt_end - _apu_tmp_gdt -1
.long _apu_tmp_gdt - _apu_boot_base
.short 0
.quad 0x00cf9a000000ffff
.quad 0x00cf92000000ffff
.quad 0x0020980000000000
.quad 0x0000920000000000
_apu_tmp_gdt_end:
.balign 4
_apu_code32_vector:
.long _apu_code32 - _apu_boot_base
.word 0x08,0
.balign 4
_apu_code64_vector:
.long _apu_code64 - _apu_boot_base
.word 0x18,0
.balign 4
_apu_boot_tmp_stack_start:
.org 0x400
_apu_boot_tmp_stack_end:
ENTRY(_apu_boot_end)