Minimized multiboot works!
This commit is contained in:
5
Makefile
5
Makefile
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
IN_EXT ?= .S
|
IN_EXT ?= .S
|
||||||
LD ?= ld
|
LD ?= ld
|
||||||
|
LINKER_SCRIPT ?= linker.ld
|
||||||
# Use gcc so that the preprocessor will run first.
|
# Use gcc so that the preprocessor will run first.
|
||||||
MYAS ?= gcc
|
MYAS ?= gcc
|
||||||
OBJ_EXT ?= .o
|
OBJ_EXT ?= .o
|
||||||
@@ -16,8 +17,8 @@ OUTS := $(patsubst %$(IN_EXT),%$(OUT_EXT),$(INS))
|
|||||||
|
|
||||||
all: $(OUTS)
|
all: $(OUTS)
|
||||||
|
|
||||||
%$(OUT_EXT): %$(OBJ_EXT) a.ld
|
%$(OUT_EXT): %$(OBJ_EXT) $(LINKER_SCRIPT)
|
||||||
$(LD) --oformat binary -o '$@' '$<' -T a.ld #-Ttext 0x7C00
|
$(LD) --oformat binary -o '$@' '$<' -T '$(LINKER_SCRIPT)' #-Ttext 0x7C00
|
||||||
|
|
||||||
%$(OBJ_EXT): %$(IN_EXT)
|
%$(OBJ_EXT): %$(IN_EXT)
|
||||||
$(MYAS) -c -o '$@' '$<'
|
$(MYAS) -c -o '$@' '$<'
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ Hello world examples of programs without an OS. A.K.A. bare bones.
|
|||||||
1. [bios_one_char](bios_one_char.S)
|
1. [bios_one_char](bios_one_char.S)
|
||||||
1. [bios_hello_world](bios_hello_world.S)
|
1. [bios_hello_world](bios_hello_world.S)
|
||||||
1. [shutdown_apm](shutdown_apm.S)
|
1. [shutdown_apm](shutdown_apm.S)
|
||||||
|
1. [multiboot/](multiboot/)
|
||||||
1. TODO not working
|
1. TODO not working
|
||||||
1. [multiboot-c/](multiboot-c/)
|
|
||||||
1. [UEFI](uefi/)
|
1. [UEFI](uefi/)
|
||||||
1. [hajji](hajji)
|
1. [hajji](hajji)
|
||||||
1. [nasm](nasm/)
|
1. [nasm](nasm/)
|
||||||
@@ -21,13 +21,17 @@ Hello world examples of programs without an OS. A.K.A. bare bones.
|
|||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
sudo apt-get install build-essential gnu-efi qemu
|
sudo apt-get install build-essential gnu-efi qemu
|
||||||
|
|
||||||
|
# Run the default program on QEMU.
|
||||||
make run
|
make run
|
||||||
|
|
||||||
|
# Run a given program.
|
||||||
make run RUN=min
|
make run RUN=min
|
||||||
make run RUN=bios_one_char
|
make run RUN=bios_one_char
|
||||||
|
|
||||||
Tested on Ubuntu 14.04.
|
Tested on Ubuntu 14.04.
|
||||||
|
|
||||||
Run on real hardware: insert as USB, determine its device (`/dev/sdX`) with:
|
Run on real hardware: for insert as USB, determine its device (`/dev/sdX`) with:
|
||||||
|
|
||||||
sudo lsblk
|
sudo lsblk
|
||||||
sudo fdisk -l
|
sudo fdisk -l
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# Multiboot
|
# Multiboot
|
||||||
|
|
||||||
|
1. [hello-world](hello-world/)
|
||||||
|
1. TODO not working
|
||||||
|
1. [osdev](osdev/)
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
<https://en.wikipedia.org/wiki/Multiboot_Specification>
|
<https://en.wikipedia.org/wiki/Multiboot_Specification>
|
||||||
|
|
||||||
Standard created by GRUB for booting OSes.
|
Standard created by GRUB for booting OSes.
|
||||||
16
multiboot/hello-world/Makefile
Normal file
16
multiboot/hello-world/Makefile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
main.elf: entry.o main.o
|
||||||
|
ld -m elf_i386 -nostdlib -T linker.ld -o '$@' $^
|
||||||
|
|
||||||
|
entry.o: entry.asm
|
||||||
|
nasm -f elf '$<' -o '$@'
|
||||||
|
|
||||||
|
main.o: main.c
|
||||||
|
gcc -c -m32 -std=c99 -ffreestanding -fno-builtin -Os -Wall -Wextra -o '$@' '$<'
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.elf *.o
|
||||||
|
|
||||||
|
run: main.elf
|
||||||
|
qemu-system-i386 -kernel '$<'
|
||||||
|
|
||||||
|
.PHONY: clean run
|
||||||
7
multiboot/hello-world/README.md
Normal file
7
multiboot/hello-world/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Hello World
|
||||||
|
|
||||||
|
Multiboot hello world.
|
||||||
|
|
||||||
|
Uses VGA output because we cannot use BIOS calls from protected mode: <http://stackoverflow.com/questions/5794991/why-cant-i-call-bios-interrupts-from-protected-mode>
|
||||||
|
|
||||||
|
Originally minimized from <https://github.com/programble/bare-metal-tetris>
|
||||||
40
multiboot/hello-world/entry.asm
Normal file
40
multiboot/hello-world/entry.asm
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
global loader
|
||||||
|
global stack_ptr
|
||||||
|
|
||||||
|
extern main
|
||||||
|
|
||||||
|
MODULEALIGN equ 1<<0
|
||||||
|
MEMINFO equ 1<<1
|
||||||
|
FLAGS equ MODULEALIGN | MEMINFO
|
||||||
|
MAGIC equ 0x1BADB002
|
||||||
|
CHECKSUM equ -(MAGIC + FLAGS)
|
||||||
|
|
||||||
|
section .mbheader
|
||||||
|
align 4
|
||||||
|
MultiBootHeader:
|
||||||
|
dd MAGIC
|
||||||
|
dd FLAGS
|
||||||
|
dd CHECKSUM
|
||||||
|
|
||||||
|
section .text
|
||||||
|
|
||||||
|
STACKSIZE equ 0x4000
|
||||||
|
|
||||||
|
loader:
|
||||||
|
mov esp, stack+STACKSIZE
|
||||||
|
push eax
|
||||||
|
push ebx
|
||||||
|
|
||||||
|
call main
|
||||||
|
|
||||||
|
cli
|
||||||
|
|
||||||
|
hang:
|
||||||
|
hlt
|
||||||
|
jmp hang
|
||||||
|
|
||||||
|
section .bss
|
||||||
|
align 4
|
||||||
|
stack:
|
||||||
|
resb STACKSIZE
|
||||||
|
stack_ptr:
|
||||||
23
multiboot/hello-world/linker.ld
Normal file
23
multiboot/hello-world/linker.ld
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
ENTRY (loader)
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
. = 0x00100000;
|
||||||
|
.mbheader : {
|
||||||
|
*(.mbheader)
|
||||||
|
}
|
||||||
|
.text : {
|
||||||
|
*(.text)
|
||||||
|
}
|
||||||
|
.rodata ALIGN (0x1000) : {
|
||||||
|
*(.rodata)
|
||||||
|
}
|
||||||
|
.data ALIGN (0x1000) : {
|
||||||
|
*(.data)
|
||||||
|
}
|
||||||
|
.bss : {
|
||||||
|
sbss = .;
|
||||||
|
*(COMMON)
|
||||||
|
*(.bss)
|
||||||
|
ebss = .;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
multiboot/hello-world/main.c
Normal file
36
multiboot/hello-world/main.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
enum color {
|
||||||
|
BLACK = 0,
|
||||||
|
BRIGHT = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
enum size {
|
||||||
|
COLS = 80,
|
||||||
|
ROWS = 25
|
||||||
|
};
|
||||||
|
|
||||||
|
uint16_t *const video = (uint16_t*) 0xB8000;
|
||||||
|
|
||||||
|
void putc(uint8_t x, uint8_t y, enum color fg, enum color bg, char c) {
|
||||||
|
video[y * COLS + x] = (bg << 12) | (fg << 8) | c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void puts(uint8_t x, uint8_t y, enum color fg, enum color bg, const char *s) {
|
||||||
|
for (; *s; s++, x++)
|
||||||
|
putc(x, y, fg, bg, *s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear(enum color bg) {
|
||||||
|
uint8_t x, y;
|
||||||
|
for (y = 0; y < ROWS; y++)
|
||||||
|
for (x = 0; x < COLS; x++)
|
||||||
|
putc(x, y, bg, bg, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int __attribute__((noreturn)) main() {
|
||||||
|
clear(BLACK);
|
||||||
|
puts(0, 0, BRIGHT, BLACK, "hello world");
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
BIN
multiboot/hello-world/main.elf
Executable file
BIN
multiboot/hello-world/main.elf
Executable file
Binary file not shown.
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
Originally from: <http://wiki.osdev.org/Bare_Bones>, should be a reasonable way to start a serious OS.
|
Originally from: <http://wiki.osdev.org/Bare_Bones>, should be a reasonable way to start a serious OS.
|
||||||
|
|
||||||
## TODO get working
|
|
||||||
|
|
||||||
sudo aptitude install -y build-essential gcc-multilib qemu xorriso
|
sudo aptitude install -y build-essential gcc-multilib qemu xorriso
|
||||||
make run
|
make run
|
||||||
|
|
||||||
Reference in New Issue
Block a user