Academic Operating System

We are developing an operating system for my personal research and practical education. For the academic purpose, this motivation is similar to MINIX, but we do not focus on theories. Our main objective is to provide knowledges on hardware-related programming. This is one of the most difficult and complex parts when we start the development of operating system from scratch.

The source code is available at the public github repository.

Checkpoint 0: Display boot message

We first develop a simple program that displays a welcome message using BIOS embedded functions. The BIOS loads the first sector, first 512 bytes (a.k.a. master boot record) of the image (aos.img), which stores the initial program loader (src/boot/arch/x86_64/diskboot.s), to 0x7c00. Then, it jumps to the address 0x7c00 and executes the program if the magic number at the last two bytes is valid (0x55aa). The initial program loader displays a welcome message through BIOS call using int 10h.

The program loaded from the first 512 bytes to 0x7c00 is called initial program loader (IPL) as well as master boot record (MBR).

BIOS: Basic Input/Output System

BIOS stands for Basic Input/Output System. BIOS provides various I/O functions to software. BIOS functions (a.k.a. BIOS calls) are implemented as interrupt handlers, and consequently, they are called through the INT instruction that invokes an interrupt. Basically, interrupt number and AH register collectively specify the function: Interrupt number specifiesthe group of functions, and AH register (sometimes AX register) generally specifies the function.

Since the BIOS calls are called through slow INT instruction with some overheads, they are not preferred to achieve fast boot. Instead, Unified Extensible Firmware Interface (UEFI) that implements I/O functions in host memory to be called through the CALL instruction. The details of UEFI will be written in this site in the future.

The following is the assembly code to display a welcome message.

The following line specifies that its following lines of code are compiled for 16-bit real mode.

28
	.code16

The following line exports the symble named “start” so that the linker sets it to the entry point.

29
	.globl start		/* Entry point */

Displays support various video mode such as 80x25 16-bit color text mode. Line 44–46 change the video mode to 80x25 16-bit color text mode. Since this mode is probably default in most of systems, this may take no effect, but we do this to ensure the video mode set to 80x25 16-bit color text mode in order to display messages.

	movb	VGA_TEXT_COLOR_80x25,%al
	movb	$0x00,%ah
	int	$0x10

The following is the Makefile to compile the assembly code.

The linker options, -N, -e start, -Ttext=0x7c00, and --oformat binary mean “do not page-align the data segment,” “specify start as the entry point,” “set the entry point address to 0x7c00,” and “output the program as binary (not ELF etc.),” respectively.

The following is the Makefile to create the image.