Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Docker image to be used with the book #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM rustlang/rust:nightly
# add intermezzOS deps
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
nasm \
xorriso \
qemu \
build-essential \
grub-pc-bin && apt-get clean \
&& cargo install xargo \
&& rustup component add rust-src
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Usage

To build a new image - `docker-compose build`

To test against the intermezzOS chapter 3 - `docker-compose run test`
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# docker-compose.yml
test:
build: .
command: make
volumes:
- ./test:/src
working_dir: /src
28 changes: 28 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
default: run

.PHONY: default build run clean

build/multiboot_header.o: multiboot_header.asm
mkdir -p build
nasm -f elf64 multiboot_header.asm -o build/multiboot_header.o

build/boot.o: boot.asm
mkdir -p build
nasm -f elf64 boot.asm -o build/boot.o

build/kernel.bin: build/multiboot_header.o build/boot.o linker.ld
ld -n -o build/kernel.bin -T linker.ld build/multiboot_header.o build/boot.o

build/os.iso: build/kernel.bin grub.cfg
mkdir -p build/isofiles/boot/grub
cp grub.cfg build/isofiles/boot/grub
cp build/kernel.bin build/isofiles/boot/
grub-mkrescue -o build/os.iso build/isofiles

run: build/os.iso
qemu-system-x86_64 -curses -net none -cdrom build/os.iso

build: build/os.iso

clean:
rm -rf build
19 changes: 19 additions & 0 deletions test/boot.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
global start

section .text
bits 32
start:
mov word [0xb8000], 0x0248 ; H
mov word [0xb8002], 0x0265 ; e
mov word [0xb8004], 0x026c ; l
mov word [0xb8006], 0x026c ; l
mov word [0xb8008], 0x026f ; o
mov word [0xb800a], 0x022c ; ,
mov word [0xb800c], 0x0220 ;
mov word [0xb800e], 0x0277 ; w
mov word [0xb8010], 0x026f ; o
mov word [0xb8012], 0x0272 ; r
mov word [0xb8014], 0x026c ; l
mov word [0xb8016], 0x0264 ; d
mov word [0xb8018], 0x0221 ; !
hlt
7 changes: 7 additions & 0 deletions test/grub.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set timeout=0
set default=0

menuentry "intermezzOS" {
multiboot2 /boot/kernel.bin
boot
}
16 changes: 16 additions & 0 deletions test/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ENTRY(start)

SECTIONS {
. = 1M;

.boot :
{
/* ensure that the multiboot header is at the beginning */
*(.multiboot_header)
}

.text :
{
*(.text)
}
}
14 changes: 14 additions & 0 deletions test/multiboot_header.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
section .multiboot_header
header_start:
dd 0xe85250d6 ; magic number
dd 0 ; protected mode code
dd header_end - header_start ; header length

; checksum
dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))

; required end tag
dw 0 ; type
dw 0 ; flags
dd 8 ; size
header_end: