This is a script I made for testing a simple operating system.
It assembles the source and creates a boot image, then It automates the configuration of a Virtual Box machine.
#!/bin/bash
OS_NAME="hello"
MEMORY_SIZE=8
build_main () {
# remove old files
rm -f $OS_NAME.bin
rm -f $OS_NAME.flp
rm -f $OS_NAME.iso
# assemble OS
nasm -f bin -o $OS_NAME.bin $OS_NAME.asm
if [[ ! -f $OS_NAME.bin ]]
then
exit
fi
dd if=/dev/zero of=$OS_NAME.flp bs=512 count=2880
dd conv=notrunc if=$OS_NAME.bin of=$OS_NAME.flp
# make CD image
mkisofs -o $OS_NAME.iso -b $OS_NAME.flp .
VBoxManage unregistervm "$OS_NAME" --delete
rm -f $OS_NAME.vdi
VBoxManage createvm --name "$OS_NAME" --register
# settings
VBoxManage modifyvm "$OS_NAME" --memory $MEMORY_SIZE --acpi on --$OS_NAME1 dvd
VBoxManage modifyvm "$OS_NAME" --ostype other
VBoxManage modifyvm "$OS_NAME" --cpuexecutioncap 90
VBoxManage modifyvm "$OS_NAME" --firmware bios
VBoxManage createvdi -filename "$OS_NAME.vdi" --size 8
VBoxManage storagectl "$OS_NAME" --name "IDE Controller" --add ide
VBoxManage storageattach "$OS_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ./$OS_NAME.vdi
VBoxManage storageattach "$OS_NAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium ./$OS_NAME.iso
# start the machine
open -a VirtualBox
VBoxManage startvm "$OS_NAME"
}
build_main
Here is a simple operating system to use for testing, hello.asm
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we are loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
text_string db 'hello world', 0
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature