解决idt加载失败的问题

This commit is contained in:
pointer-to-bios 2024-02-27 22:18:14 +08:00
parent 925ff4777d
commit 2f0f12f893
3 changed files with 32 additions and 27 deletions

View File

@ -6,12 +6,13 @@ init64:
endbr64 endbr64
cli cli
; 加载段寄存器
mov rax, 0x1000000 mov rax, 0x1000000
mov rbp, rax mov rbp, rax
mov rsp, rax mov rsp, rax
mov rdi, rbx mov rdi, rbx
lidt [0x104010]
; 加载系统调用相关寄存器 ; 加载系统调用相关寄存器
; IA32_STAR = 0x0018_0008_0000_0000 ; IA32_STAR = 0x0018_0008_0000_0000
mov rcx, 0xc0000081 mov rcx, 0xc0000081

View File

@ -37,19 +37,9 @@ init32:
add edi, 4 add edi, 4
loop init32_loop0 loop init32_loop0
; 设置idt_ptr
mov eax, 0x10403a ; idt_ptr + 2
mov dword [eax], 0x104050
; 加载IDTR寄存器
db 0x66
lidt [0x104038]
; 设置gdt_ptr
mov eax, 0x10402a ; gdt_ptr + 2
mov dword [eax], 0x104000 ; gdt
; 加载GDTR、段寄存器和TR寄存器 ; 加载GDTR、段寄存器和TR寄存器
db 0x66 db 0x66
lgdt [0x104028] ; gdt_ptr lgdt [0x104000] ; gdt_ptr
mov ax, 0x10 mov ax, 0x10
mov ds, ax mov ds, ax
mov ss, ax mov ss, ax
@ -98,7 +88,20 @@ PDPT0:
PD0: PD0:
resq 512 resq 512
; 分段 section .cpumeta.tblptrs
gdt_ptr: ; 0x104000
dw gdt_end - gdt - 1
dq gdt
dd 0
dw 0
idt_ptr: ; 0x104010
dw 0x7ff
dq idt
section .cpumeta.gdt align=4096
gdt: gdt:
dq 0 dq 0
dq 0x0020980000000000 ; 内核态代码段 dq 0x0020980000000000 ; 内核态代码段
@ -106,27 +109,16 @@ gdt:
dq 0x0020f80000000000 ; 用户态代码段 dq 0x0020f80000000000 ; 用户态代码段
dq 0x0000f20000000000 ; 用户态数据段 dq 0x0000f20000000000 ; 用户态数据段
dq 0 dq 0
dq 0x0000891060000000 ; TSS段低64位 dq 0x0000891070000000 ; TSS段低64位
dq 0 ; TSS段高64位 dq 0 ; TSS段高64位
gdt_end: gdt_end:
gdt_ptr: ; 0x104028 section .cpumeta.idt align=4096
dw gdt_end - gdt - 1
dq gdt
resb 6
idt_ptr: ; 0x104038
dw 0x7ff
dq idt
resb 14
global idt global idt
idt: idt:
resq 512 ; 16 bytes per descriptor (512 q-bytes) resq 512 ; 16 bytes per descriptor (512 q-bytes)
section .cpumeta.tss alogn=4096 section .cpumeta.tss align=4096
global TSS global TSS
TSS: TSS:
dd 0 dd 0

View File

@ -17,6 +17,18 @@ SECTIONS {
{ {
*(.cpumeta) *(.cpumeta)
} }
.cpumeta.tblptrs ALIGN(4096) :
{
*(cpumeta.tblptrs)
}
.cpumeta.gdt ALIGN(4096) :
{
*(.cpumeta.gdt)
}
.cpumeta.idt ALIGN(4096) :
{
*(.cpumeta.idt)
}
.cpumeta.tss ALIGN(4096) : .cpumeta.tss ALIGN(4096) :
{ {
*(.cpumeta.tss) *(.cpumeta.tss)