Compare commits

...

3 Commits

Author SHA1 Message Date
pointer-to-bios 320ceaa56d 增加raw allocator使用建议。
改变低地址映射策略
2024-03-01 01:47:06 +08:00
pointer-to-bios 6f14cd6322 移除不需要的有关地址替换的注释 2024-02-29 11:36:56 +08:00
pointer-to-bios 2f0f12f893 解决idt加载失败的问题 2024-02-27 22:18:14 +08:00
6 changed files with 40 additions and 41 deletions

View File

@ -1,6 +1,6 @@
SOURCE := $(shell pwd)/src/scripts
.PHONY: all clear run debug config
.PHONY: all clear run debug config disass
all: config
@make -C src all --no-print-directory
@ -25,3 +25,6 @@ config:
touch metaverse_kernel; \
"${SOURCE}/depcheck"; \
fi
disass:
objdump -D src/metaverse.elf > kerndisass.txt

View File

@ -9,7 +9,8 @@
*
*
*
* * 0 \~ 2MB使
* * 0 \~ 1MB
* * 1MB \~ 2MB
* * 2MB \~ 4MB
* * 4MB \~ 16MB
* * 16MB \~ ?

View File

@ -16,14 +16,6 @@ typedef struct __raw_allocator_cell
} raw_allocator_cell;
#define raw_allocator_next_cell(cell) (raw_allocator_cell *)((void *)((cell)->content) + (cell)->capacity)
// 原始分配器
//
// 包括至少一个cell分配时像cell的分裂一样将空白的一段分成两段
// 释放时只把length归零并不将cell合并。
// length=0的cell称为空cell
//
// 统计从上次细胞合并以来free的调用次数当调用次数很多或可用空间不足时
// 触发细胞合并。
/**
* @name raw_allocator_t
*
@ -33,6 +25,8 @@ typedef struct __raw_allocator_cell
*
* free的调用次数`RAW_ALLOCATOR_FREE_MAX`
*
* 使allocate和free的情况下使用使allocate时效率低下并难以得到内存安全保证
*
* @internal free_count
*
* free方法的调用次数`RAW_ALLOCATOR_FREE_MAX`

View File

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

View File

@ -1,9 +1,6 @@
section .entry
extern init64
; 寄存器ebx是multiboot2 information不可以使用
;
; 由于这个代码是32位环境的代码而链接器链接时会把它当作64位代码链接
; 所以这里所有的使用了常数的位置都要通过指令写入
init32:
cli
@ -37,19 +34,9 @@ init32:
add edi, 4
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寄存器
db 0x66
lgdt [0x104028] ; gdt_ptr
lgdt [0x104000] ; gdt_ptr
mov ax, 0x10
mov ds, ax
mov ss, ax
@ -86,7 +73,6 @@ init32:
section .cpumeta align=4096
global PML4
; 分页
; 链接器会把这些数据替换掉所以要在代码中重新设置
PML4:
dq 0x003 + PDPT0
resq 511
@ -98,7 +84,20 @@ PDPT0:
PD0:
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:
dq 0
dq 0x0020980000000000 ; 内核态代码段
@ -106,27 +105,16 @@ gdt:
dq 0x0020f80000000000 ; 用户态代码段
dq 0x0000f20000000000 ; 用户态数据段
dq 0
dq 0x0000891060000000 ; TSS段低64位
dq 0x0000891070000000 ; TSS段低64位
dq 0 ; TSS段高64位
gdt_end:
gdt_ptr: ; 0x104028
dw gdt_end - gdt - 1
dq gdt
resb 6
idt_ptr: ; 0x104038
dw 0x7ff
dq idt
resb 14
section .cpumeta.idt align=4096
global idt
idt:
resq 512 ; 16 bytes per descriptor (512 q-bytes)
section .cpumeta.tss alogn=4096
section .cpumeta.tss align=4096
global TSS
TSS:
dd 0

View File

@ -17,6 +17,18 @@ SECTIONS {
{
*(.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)