概要
中古ノート買ってみた。
最小kernelコンパイルしてqemuで動かしてみた。
今回は、nasmを使ってみた。
手順
wsl1のubuntuにnasmをインストールする
# apt install nasm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
efibootmgr libefiboot1 libefivar1
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
nasm
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 359 kB of archives.
After this operation, 2831 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 nasm amd64 2.13.02-0.1 [359 kB]
Fetched 359 kB in 4s (100 kB/s)
Selecting previously unselected package nasm.
(Reading database ... 36780 files and directories currently installed.)
Preparing to unpack .../nasm_2.13.02-0.1_amd64.deb ...
Unpacking nasm (2.13.02-0.1) ...
Setting up nasm (2.13.02-0.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
kernelをコンパイルする。
makefile
all: test5.elf
test5.elf: kernel5.o
ld -m elf_i386 -e_start -Ttext=0x100000 -otest5.elf kernel5.o
kernel5.o: kernel5.asm
nasm -f elf32 -o kernel5.o kernel5.asm
kernel5.asm
[BITS 32]
[SECTION .text]
global _start
global multiboot_header
_start:
mov ebx, 0xb8000 ; VGAテキストバッファの先頭
mov ecx, 12 ; 表示する文字数
mov esi, msg ; メッセージのアドレス
.loop:
mov al, [esi] ; 文字を取得
mov ah, 2 ; 属性(緑色)
mov [ebx], ax ; 画面に表示
add ebx, 2 ; 次の文字位置へ
inc esi ; 次の文字へ
dec ecx ; カウンタ減少
jne .loop ; 繰り返し
jmp $ ; 無限ループ
[SECTION .data]
align 4
multiboot_header:
dd 0x1badb002 ; magic number
dd 0x0 ; flags
dd -0x1badb002 ; checksum
msg:
db "Hello world!", 0 ; メッセージ(null終端)
floppyイメージにkernel5.elfを入れる。
qemuを起動する。
grubでkernelをbootする。
kernel (fd0)/boot/test5.elf
boot
以上。


