forked from metaverse/kernel-dev
Compare commits
3 Commits
25116eaee4
...
925ff4777d
Author | SHA1 | Date |
---|---|---|
pointer-to-bios | 925ff4777d | |
pointer-to-bios | 622f017b6a | |
pointer-to-bios | f64ff62b75 |
|
@ -28,7 +28,7 @@ typedef struct __gate_descriptor_t
|
|||
*
|
||||
* `ssp`代表一个tss描述符在任务段中的的索引。
|
||||
*/
|
||||
#define INTERRUPT_DESCRIPTOR_FLAG_IST(ssp) (ssp)
|
||||
#define INTERRUPT_DESCRIPTOR_FLAG_IST 1
|
||||
|
||||
// 在第15位上有一个表示代码段是否存在的标志位,代码段总是存在,故直接设置为1
|
||||
#define INTERRUPT_DESCRIPTOR_FLAG_TYPE_INTERRUPT (0x8e << 8)
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
*/
|
||||
extern void prepare_stack();
|
||||
|
||||
extern u32 TSS[26];
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,6 +4,18 @@
|
|||
#include <types.h>
|
||||
#include <libk/bits.h>
|
||||
|
||||
/**
|
||||
* @details x86_64
|
||||
*
|
||||
* 物理地址空间:
|
||||
*
|
||||
* * 0 \~ 2MB:不使用,不映射
|
||||
* * 2MB \~ 4MB:中断栈。
|
||||
* * 4MB \~ 16MB:内核栈。
|
||||
* * 16MB \~ ?:内核镜像。
|
||||
* * ? \~ 128MB:内核大分配器。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name MEMM_PAGE_SIZE
|
||||
* @addindex 平台定制宏
|
||||
|
|
|
@ -116,7 +116,7 @@ typedef void (*memm_free_t)(void *allocator, void *mem);
|
|||
typedef struct __allocator_t
|
||||
{
|
||||
#ifndef MEMM_ALLOCATOR_MAGIC
|
||||
#define MEMM_ALLOCATOR_MAGIC 0x271fe441
|
||||
#define MEMM_ALLOCATOR_MAGIC ((u32)0x271fe441)
|
||||
#endif
|
||||
// 分配器有效性由此检验,不为`MEMM_ALLOCATOR_MAGIC_NUM`说明获得了一个错误的分配器地址。
|
||||
// 此值在编译时通过各种方式确定,若
|
||||
|
|
|
@ -7,7 +7,7 @@ CC = gcc
|
|||
CCFLAGS = -m64 -mcmodel=large -I ../../include \
|
||||
-fno-stack-protector -fno-exceptions \
|
||||
-fno-builtin -nostdinc -nostdlib \
|
||||
-DMEMM_ALLOCATOR_MAGIC=\"${ALLOCATOR_MAGIC}\"
|
||||
-DMEMM_ALLOCATOR_MAGIC="(u32)(0x${ALLOCATOR_MAGIC})"
|
||||
ifdef release
|
||||
CCFLAGS := ${CCFLAGS} -O2
|
||||
endif
|
||||
|
|
|
@ -26,9 +26,6 @@ init64:
|
|||
lea rax, [systemcall_procedure]
|
||||
wrmsr
|
||||
|
||||
; 加载中断相关寄存器
|
||||
; 需要加载寄存器IA32_INTERRUPT_SSP_TABLE
|
||||
|
||||
jmp kmain
|
||||
|
||||
section .multiboot2 align=8
|
||||
|
|
|
@ -47,7 +47,7 @@ init32:
|
|||
; 设置gdt_ptr
|
||||
mov eax, 0x10402a ; gdt_ptr + 2
|
||||
mov dword [eax], 0x104000 ; gdt
|
||||
; 加载GDTR和段寄存器
|
||||
; 加载GDTR、段寄存器和TR寄存器
|
||||
db 0x66
|
||||
lgdt [0x104028] ; gdt_ptr
|
||||
mov ax, 0x10
|
||||
|
@ -56,6 +56,8 @@ init32:
|
|||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov ax, 0x30
|
||||
ltr ax
|
||||
|
||||
; 打开PAE
|
||||
mov eax, cr4
|
||||
|
@ -103,6 +105,9 @@ gdt:
|
|||
dq 0x0000920000000000 ; 内核态数据段
|
||||
dq 0x0020f80000000000 ; 用户态代码段
|
||||
dq 0x0000f20000000000 ; 用户态数据段
|
||||
dq 0
|
||||
dq 0x0000891060000000 ; TSS段(低64位)
|
||||
dq 0 ; TSS段(高64位)
|
||||
gdt_end:
|
||||
|
||||
gdt_ptr: ; 0x104028
|
||||
|
@ -120,3 +125,14 @@ idt_ptr: ; 0x104038
|
|||
global idt
|
||||
idt:
|
||||
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)
|
||||
|
|
|
@ -139,7 +139,7 @@ impl KernelLogger {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
true
|
||||
};
|
||||
while !all_end(&indeces, &logs) {
|
||||
let mut min_ind = None;
|
||||
|
|
|
@ -206,6 +206,19 @@ impl ToString for Message {
|
|||
/// .build();
|
||||
/// ```
|
||||
///
|
||||
/// 定义了`message!`宏,简化构造消息的代码:
|
||||
///
|
||||
/// ```rust
|
||||
/// use crate::kernel::tty::tty::BuilderFunctions::*;
|
||||
///
|
||||
/// message!(
|
||||
/// Msg("Hello, "),
|
||||
/// Msg("Metaverse"),
|
||||
/// FgColor(Color::GREEN),
|
||||
/// Msg("!\n"),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// 对于特殊情况可以使用非链式调用:
|
||||
/// ```rust
|
||||
/// let mut msg = MessageBuilder::new();
|
||||
|
|
|
@ -13,10 +13,14 @@ SECTIONS {
|
|||
{
|
||||
*(.multiboot2)
|
||||
}
|
||||
.cpumeta :
|
||||
.cpumeta ALIGN(4096) :
|
||||
{
|
||||
*(.cpumeta)
|
||||
}
|
||||
.cpumeta.tss ALIGN(4096) :
|
||||
{
|
||||
*(.cpumeta.tss)
|
||||
}
|
||||
. = 16M;
|
||||
.text :
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue