1. 程式人生 > 其它 ><30 DAYS TO MAKE YOUR OWN OS> on Ubuntu(1)

<30 DAYS TO MAKE YOUR OWN OS> on Ubuntu(1)

技術標籤:環境搭建linuxOSASKOS

Day 1:

1.install qemu

sudo apt-get install qemu

2.run

qemu-system-x86_64 -m 32 -fda projects/01_day/helloos0/helloos.img

在這裡插入圖片描述
3.build

nasm helloos.nas -o helloos.img

helloos.nas:41: error: attempt to reserve non-constant quantity of BSS space
modiy:

; RESB	0x1fe-$
RESB	0x1fe-($-$$)

NASM supports two special tokens in expressions, allowing calculations to involve the current assembly position: the $ and KaTeX parse error: Can't use function '$' in math mode at position 10: tokens. $̲ evaluates to t… evaluates to the beginning of the current section; so you can tell how far into the section you are by using ( − -

$).
https://nasm.us/doc/nasmdoc3.html#section-3.5

Again:

 qemu-system-x86_64 helloos.img

It will be shown as above!

Day2:

projects/02_day/helloos3:
build

nasm helloos.nas -o helloos.img

Modify:

; RESB	0x7dfe-$
RESB	0x7dfe-($-$$)

no bootable device!?
Modify again:

; RESB	0x7dfe-($-$$)
RESB	0x1fe-($-$$)

build again:

nasm helloos.nas -o helloos.img

No error, run :

qemu-system-x86_64 helloos.img

It will be shown as above!

projects/02_day/helloos5

makefile:

ipl.bin : ipl.nas Makefile
	nasm ipl.nas -o ipl.bin
img : ipl.bin
	mformat -f 1440 -C -B ipl.bin -i helloos.img ::

run

make img

It will be shown as above!

Day3

projects/03_day/harib00a

Run:

nasm ipl.nas -o ipl.img
qemu-system-x86_64 -fda ipl.img

在這裡插入圖片描述

projects/03_day/harib00g

makefile:

IPL_NAME=ipl10
IMG_NAME=os
SYS_NAME=haribote

default: $(IPL_NAME) $(SYS_NAME)
	mformat -f 1440 -C -B $(IPL_NAME).bin -i $(IMG_NAME).img ::
	mcopy $(SYS_NAME).sys -i $(IMG_NAME).img ::

$(IPL_NAME):
	nasm $(IPL_NAME).nas -o $(IPL_NAME).bin

$(SYS_NAME):
	nasm $(SYS_NAME).nas -o $(SYS_NAME).sys

It will be shown a black screen!

projects/03_day/harib00i

makefile:

IPL_NAME=ipl10
IMG_NAME=os
SYS_NAME=haribote
ASM_HEAD=asmhead
BOOT_PACK=bootpack
OS_LINKERSCRIPT=os.ld

default: $(IPL_NAME) $(SYS_NAME)
	mformat -f 1440 -C -B $(IPL_NAME).bin -i $(IMG_NAME).img ::
	mcopy $(SYS_NAME).sys -i $(IMG_NAME).img ::

$(IPL_NAME):
	nasm $(IPL_NAME).nas -o $(IPL_NAME).bin

$(ASM_HEAD):
	nasm $(ASM_HEAD).nas -o $(ASM_HEAD).bin

$(SYS_NAME): $(ASM_HEAD)
	gcc -m32 -fno-pie -nostdlib -T $(OS_LINKERSCRIPT) $(BOOT_PACK).c -o $(BOOT_PACK).bin
	cat $(ASM_HEAD).bin $(BOOT_PACK).bin > $(SYS_NAME).sys

os.ld file:

OUTPUT_FORMAT("binary");

SECTIONS
{
    .head 0x0 : {
        LONG(64 * 1024)  /*  0 : stack+.data+heap の大きさ(4KBの倍數) */
        LONG(0x69726148)      /*  4 : シグネチャ "Hari" */
        LONG(0)               /*  8 : mmarea の大きさ(4KBの倍數) */
        LONG(0x310000)        /* 12 : スタック初期値&.data転送先 */
        LONG(SIZEOF(.data))   /* 16 : .dataサイズ */
        LONG(LOADADDR(.data)) /* 20 : .dataの初期値列のファイル位置 */
        LONG(0xE9000000)      /* 24 : 0xE9000000 */
        LONG(HariMain - 0x20) /* 28 : エントリアドレス - 0x20 */
        LONG(0)               /* 32 : heap領域(malloc領域)開始アドレス */
    }

    .text : { *(.text) }

    .data 0x310000 : AT ( ADDR(.text) + SIZEOF(.text) ) {
        *(.data)
        *(.rodata*)
        *(.bss)
    }

    /DISCARD/ : { *(.eh_frame) }

}

ref:https://vanya.jp.net/os/haribote.html
After run, it will be shown a black screen!

projects/03_day/harib00j

IPL_NAME=ipl10
IMG_NAME=os
SYS_NAME=haribote
ASM_HEAD=asmhead
BOOT_PACK=bootpack
OS_LINKERSCRIPT=os.ld
NASK_FUNC=naskfunc

default: $(IPL_NAME) $(SYS_NAME)
	mformat -f 1440 -C -B $(IPL_NAME).bin -i $(IMG_NAME).img ::
	mcopy $(SYS_NAME).sys -i $(IMG_NAME).img ::

$(IPL_NAME):
	nasm $(IPL_NAME).nas -o $(IPL_NAME).bin

$(ASM_HEAD):
	nasm $(ASM_HEAD).nas -o $(ASM_HEAD).bin

$(NASK_FUNC):
	nasm -f elf $(NASK_FUNC).nas -o $(NASK_FUNC).o

$(SYS_NAME): $(ASM_HEAD) $(NASK_FUNC)
	gcc -m32 -fno-pie -nostdlib -T $(OS_LINKERSCRIPT) $(BOOT_PACK).c $(NASK_FUNC).o -o $(BOOT_PACK).bin
	cat $(ASM_HEAD).bin $(BOOT_PACK).bin > $(SYS_NAME).sys

clean:
	rm *.bin *.sys *.img *.o

After run, it will be shown a black screen!