Skip to content
Têng Ûi edited this page Nov 14, 2024 · 68 revisions

筆記

BIOS -> Legacy BIOS, UEFI BIOS BootLoader -> Grub(單階段啟動), Uboot(兩階段啟動,嵌入式專用)

BIOS將Boot Loader(原本MBR內)載入到記憶體(RAM)後,並將控制權給 Boot Loader Boot Loader 準備把 Kernel image 從硬碟讀到記憶體中,接者跳轉到Kernel的入口點執行,開始啟動作業系統

OVMF(Open Virtual Machine Firmware),提供QEMU拿來做為虛擬機的UEFI BIOS

NASM

ORG: Binary File Program Origin

$ evaluates to the assembly position at the beginning of the line containing the expression. $$ evaluates to the beginning of the current section; so you can tell how far into the section you are by using ($-$$).

$ means "address of here". $$ means "address of start of current section". So $-$$ means "current size of section".

MBR

https://en.wikipedia.org/wiki/Master_boot_record#PTE

INT 13H

https://en.wikipedia.org/wiki/INT_13H

INT 15H

https://en.wikipedia.org/wiki/E820\ https://wiki.osdev.org/Detecting_Memory_(x86)

Set Video Mode

http://vitaly_filatov.tripod.com/ng/asm/asm_023.1.html

segment addressing

segment:offset = logical address (16-bit) in real mode
segment * 16 + offset = physical address (20-bit) in real mode

CS:IP (CS is Code Segment, IP is Instruction Pointer) points to the address where the processor will fetch the next byte of code.
SS:SP (SS is Stack Segment, SP is Stack Pointer) points to the address of the top of the stack
DS:SI (DS is Data Segment, SI is Source Index) is often used to point to string data that is about to be copied to ES:DI.
ES:DI (ES is Extra Segment, DI is Destination Index) is typically used to point to the destination for a string copy

GDT

https://wiki.osdev.org/GDT
http://www.brokenthorn.com/Resources/OSDev8.html
進入保護模式(一):加載GDTR

protected mode addressing

segment descriptor:offset

paging

https://www.cnblogs.com/lanrenxinxin/p/4735027.html
https://zhuanlan.zhihu.com/p/152119007 \

// intel 的手冊 裡面有 paging 的介紹
https://www.intel.com/content/www/us/en/content-details/782158/intel-64-and-ia-32-architectures-software-developer-s-manual-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html?wapkw=intel%2064%20and%20ia-32%20architectures%20software%20developer%27s%20manual&docid=782161

PIC(Programmable Interrupt Controller)

https://stenlyho.blogspot.com/2008/08/pic.html
https://wiki.osdev.org/8259_PIC

PIT

https://wiki.osdev.org/Programmable_Interval_Timer

CPL vs. DPL vs. RPL

https://www.csie.ntu.edu.tw/~wcchen/asm98/asm/proj/b85506061/chap3/privilege.html
https://stackoverflow.com/a/36631763/5321961

The RPL is intended to represent the privilege level of the procedure that originates a selector.
An internal processor register records the current privilege level (CPL).
Normally the CPL is equal to the DPL of the segment that the processor is currently executing.

Flags register

https://en.wikipedia.org/wiki/FLAGS_register

TSS

https://wiki.osdev.org/Task_State_Segment

文件

鳥哥 - 第十九章、開機流程、模組管理與 Loader
*Writing a Bootloader Part 1
osdev
nasm tutorial

參考影片

nanobyte

tutorials

64bit-os-tutorial
A bare metal hello world in C for Risc-V using QEMU to test

todo

使用 UEFI
使用 Grub
Grub2 and UEFI
eBPF aya
refactor some asm codes to C codes (e.g. gdt, tss, pic, pit...)
APCI
add create/update/delete method to FAT16
add sub folders support to FAT16
FAT 32
EXT 2/3
syscall: fork/open/close/exec/read/wait_pid
add move cursor in text mode network driver
mouse driver
audio driver
usb driver
add Symmetric Multi-Processing (SMP)
add Bad Apple demo
add scrolling
add cursor moving
add more commands
modify examples/process into fork and exec and observing the context switch