DragonOS/kernel/head.S

226 lines
5.3 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.

//
// Created by longjin.
// 2022/01/20
#include "common/asm.h"
.section .text
.global _start
_start:
//
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %ss
mov $0x7e00, %esp
// === GDTR ====
lgdt GDT_POINTER(%rip) //rip, PICposition independent code
// === IDTR ====
lidt IDT_POINTER(%rip)
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %ss
mov %ax, %gs
movq $0x7e00, %rsp
// ==== CR3
movq $0x101000, %rax //
movq %rax, %cr3
movq switch_seg(%rip), %rax
// ljmplcallGASlretcs
// Amazing
pushq $0x08 //
pushq %rax
lretq
// 64
switch_seg:
.quad entry64
entry64:
movq $0x10, %rax
movq %rax, %ds
movq %rax, %es
movq %rax, %gs
movq %rax, %ss
movq $0xffff800000007e00, %rsp //rsp
setup_IDT:
leaq m_ignore_int(%rip), %rdx // ignore_int8B
movq $(0x08 << 16), %rax // IDT0x100000TI=0,RPL=0
movw %dx, %ax
movq $ (0x8e00 << 32), %rcx // Type=1110 P=1 DPL=00 0=0
addq %rcx, %rax
// ignore_int, rax8B rdx8B
movl %edx, %ecx
shrl $16, %ecx // 16
shlq $48, %rcx
addq %rcx, %rax // 31:16
shrq $32, %rdx // 3232
leaq IDT_Table(%rip), %rdi // rdi
mov $256, %rcx //
repeat_set_idt:
// ====== 256 ===
movq %rax, (%rdi) // 8B
movq %rdx, 8(%rdi) // 8B
addq $0x10, %rdi // IDT
dec %rcx
jne repeat_set_idt
SetUp_TSS64:
// == 64 ===
//rdx8B rax8B
leaq TSS64_Table(%rip), %rdx
xorq %rax, %rax
xorq %rcx, %rcx
// TSS47401000 1001
movq $0x89, %rax
shlq $40, %rax
// 设置段基地址31:24
movl %edx, %ecx
shrl $24, %ecx
shlq $56, %rcx
addq %rcx, %rax
xorq %rcx, %rcx
// 设置段基地址23:00
movl %edx, %ecx
andl $0xffffff, %ecx // ecx8
shlq $16, %rcx
addq %rcx, %rax
addq $103, %rax //
leaq GDT_Table(%rip), %rdi
movq %rax, 64(%rdi) // BGDT8
shrq $32, %rdx
movq %rdx, 72(%rdi) // 8BGDT9
// (main.c使load_TR)
// mov $0x40, %ax // 64
// ltr %ax
//
movq go_to_kernel(%rip), %rax
pushq $0x08
pushq %rax
lretq
go_to_kernel:
.quad Start_Kernel
// ==== / ignore int
m_ignore_int:
// cignore_int
movq go_to_ignore_int(%rip), %rax
pushq $0x08
pushq %rax
lretq
lretq
go_to_ignore_int:
.quad ignore_int
ENTRY(_stack_start)
.quad initial_proc_union + 32768
//
.align 8 //8byte
.org 0x1000 //0x1000
__PML4E:
.quad 0x102007 // 访 31~12
.fill 255,8,0
.quad 0x102007
.fill 255,8,0
.org 0x2000
__PDPTE:
.quad 0x103003 // 访
.fill 511,8,0
.org 0x3000
__PDE:
.quad 0x000083 // 访
.quad 0x200083
.quad 0x400083
.quad 0x600083
.quad 0x800083
.quad 0xe0000083 /*0x a00000*/
.quad 0xe0200083
.quad 0xe0400083
.quad 0xe0600083 /*0x1000000*/
.quad 0xe0800083
.quad 0xe0a00083
.quad 0xe0c00083
.quad 0xe0e00083
.fill 499,8,0
// GDT
.section .data
.global GDT_Table // 使GDT访
GDT_Table:
.quad 0x0000000000000000 // 0 00
.quad 0x0020980000000000 // 1 64 08
.quad 0x0000920000000000 // 2 64 10
.quad 0x0020f80000000000 // 3 64 18
.quad 0x0000f20000000000 // 4 64 20
.quad 0x00cf9a000000ffff // 5 32 28
.quad 0x00cf92000000ffff // 6 32 30
.fill 10, 8, 0 // 8~9 TSS() 80
GDT_END:
GDT_POINTER:
GDT_LIMIT: .word GDT_END - GDT_Table - 1 // GDT
GDT_BASE: .quad GDT_Table
// IDT
.global IDT_Table
IDT_Table:
.fill 512, 8, 0 // 512*8IDT
IDT_END:
IDT_POINTER:
IDT_LIMIT: .word IDT_END - IDT_Table - 1
IDT_BASE: .quad IDT_Table
// 64TSS
.global TSS64_Table
TSS64_Table:
.fill 13, 8, 0
TSS64_END:
TSS64_POINTER:
TSS64_LIMIT: .word TSS64_END - TSS64_Table - 1
TSS64_BASE: .quad TSS64_Table