增加中断向量表及TSS段

This commit is contained in:
pointer-to-bios 2024-02-26 22:02:58 +08:00
parent 622f017b6a
commit 925ff4777d
5 changed files with 33 additions and 14 deletions

View File

@ -7,7 +7,7 @@
/** /**
* @name gate_descriptor_t * @name gate_descriptor_t
* @addindex x86_64 * @addindex x86_64
* *
* *
*/ */
typedef struct __gate_descriptor_t typedef struct __gate_descriptor_t
@ -23,12 +23,12 @@ typedef struct __gate_descriptor_t
/** /**
* @name INTERRUPT_DESCRIPTOR_FLAG_IST * @name INTERRUPT_DESCRIPTOR_FLAG_IST
* @addindex x86_64 * @addindex x86_64
* *
* `gate_descriptor_t``flags` * `gate_descriptor_t``flags`
* *
* `ssp`tss描述符在任务段中的的索引 * `ssp`tss描述符在任务段中的的索引
*/ */
#define INTERRUPT_DESCRIPTOR_FLAG_IST(ssp) (ssp) #define INTERRUPT_DESCRIPTOR_FLAG_IST 1
// 在第15位上有一个表示代码段是否存在的标志位代码段总是存在故直接设置为1 // 在第15位上有一个表示代码段是否存在的标志位代码段总是存在故直接设置为1
#define INTERRUPT_DESCRIPTOR_FLAG_TYPE_INTERRUPT (0x8e << 8) #define INTERRUPT_DESCRIPTOR_FLAG_TYPE_INTERRUPT (0x8e << 8)
@ -36,7 +36,7 @@ typedef struct __gate_descriptor_t
/** /**
* @name idt * @name idt
* *
* *
*/ */
extern gate_descriptor_t idt[256]; extern gate_descriptor_t idt[256];

View File

@ -12,4 +12,6 @@
*/ */
extern void prepare_stack(); extern void prepare_stack();
extern u32 TSS[26];
#endif #endif

View File

@ -26,9 +26,6 @@ init64:
lea rax, [systemcall_procedure] lea rax, [systemcall_procedure]
wrmsr wrmsr
; 加载中断相关寄存器
; 需要加载寄存器IA32_INTERRUPT_SSP_TABLE
jmp kmain jmp kmain
section .multiboot2 align=8 section .multiboot2 align=8

View File

@ -47,7 +47,7 @@ init32:
; 设置gdt_ptr ; 设置gdt_ptr
mov eax, 0x10402a ; gdt_ptr + 2 mov eax, 0x10402a ; gdt_ptr + 2
mov dword [eax], 0x104000 ; gdt mov dword [eax], 0x104000 ; gdt
; 加载GDTR和段寄存器 ; 加载GDTR、段寄存器和TR寄存器
db 0x66 db 0x66
lgdt [0x104028] ; gdt_ptr lgdt [0x104028] ; gdt_ptr
mov ax, 0x10 mov ax, 0x10
@ -56,6 +56,8 @@ init32:
mov es, ax mov es, ax
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
mov ax, 0x30
ltr ax
; 打开PAE ; 打开PAE
mov eax, cr4 mov eax, cr4
@ -99,10 +101,13 @@ PD0:
; 分段 ; 分段
gdt: gdt:
dq 0 dq 0
dq 0x0020980000000000 ; 内核态代码段 dq 0x0020980000000000 ; 内核态代码段
dq 0x0000920000000000 ; 内核态数据段 dq 0x0000920000000000 ; 内核态数据段
dq 0x0020f80000000000 ; 用户态代码段 dq 0x0020f80000000000 ; 用户态代码段
dq 0x0000f20000000000 ; 用户态数据段 dq 0x0000f20000000000 ; 用户态数据段
dq 0
dq 0x0000891060000000 ; TSS段低64位
dq 0 ; TSS段高64位
gdt_end: gdt_end:
gdt_ptr: ; 0x104028 gdt_ptr: ; 0x104028
@ -120,3 +125,14 @@ idt_ptr: ; 0x104038
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
global TSS
TSS:
dd 0
dq 0x1000000 ; rsp0内核栈
dq 0 ; rsp1
dq 0 ; rsp2
dq 0
dq 0x400000 ; ist1中断栈
resb 104 - ($ - TSS)

View File

@ -13,10 +13,14 @@ SECTIONS {
{ {
*(.multiboot2) *(.multiboot2)
} }
.cpumeta : .cpumeta ALIGN(4096) :
{ {
*(.cpumeta) *(.cpumeta)
} }
.cpumeta.tss ALIGN(4096) :
{
*(.cpumeta.tss)
}
. = 16M; . = 16M;
.text : .text :
{ {