🆕 设置了IDT,装载了TSS到GDT中。实现了第一个简易的中断处理函数ignore_int

This commit is contained in:
fslongjin 2022-01-24 20:56:59 +08:00
parent 278c35111f
commit cfd0f76059
3 changed files with 85 additions and 16 deletions

View File

@ -1,17 +1,3 @@
/***************************************************
*
*
* MINE
*
* 使
*
*
*
*
* EMail: 345538255@qq.com
*
*
***************************************************/
#ifndef __FONT_H__
#define __FONT_H__

View File

@ -53,6 +53,70 @@ entry64:
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
//
mov $0x40, %ax // 64
ltr %ax
//
movq go_to_kernel(%rip), %rax
pushq $0x08
@ -62,8 +126,18 @@ entry64:
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
go_to_ignore_int:
.quad ignore_int
//
.align 8 //8byte
.org 0x1000 //0x1000

View File

@ -47,7 +47,6 @@ void test_printk()
printk("2022-01-01\tDavid\t99\n");
printk("2022-01-01\tJohn\t95\n");
//测试输出八进制
printk("\nTest base 8 : %d --> %o\n", 255, 255);
@ -62,9 +61,19 @@ void Start_Kernel(void)
init_printk(1440, 900, FR_address, 1440 * 900 * 4, 8, 16);
show_welcome();
test_printk();
//test_printk();
int t = 1 / 0; // 测试异常处理模块ignore_int能否正常工作
while (1)
;
}
void ignore_int()
{
printk("[");
printk_color(YELLOW, BLACK, "WARN");
printk("] Unknown interrupt or fault at RIP.\n");
while (1)
;
}