initial commit

This commit is contained in:
2025-04-24 17:20:18 +02:00
commit b14387c40a
5 changed files with 161 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
[{*.s,Makefile}]
indent_style = tab
indent_size = 8
+18
View File
@@ -0,0 +1,18 @@
Copyright © 2025 Niklas Elsbrock
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+43
View File
@@ -0,0 +1,43 @@
src_dir := src
build_dir := build
asm := nasm
qemu := qemu-system-i386
qemu_flags := -drive file=$(build_dir)/rainbowboot.img,format=raw
qemu_flags_gdb := -s -S
dosbox := dosbox
.PHONY: all run run-gdb run-dosbox attach clean
all: $(build_dir)/rainbowboot.img
run: $(build_dir)/rainbowboot.img
$(qemu) $(qemu_flags)
run-gdb: $(build_dir)/rainbowboot.img
$(qemu) $(qemu_flags_gdb) $(qemu_flags)
run-dosbox: $(build_dir)/rainbowboot.img
$(dosbox) -c "BOOT $(build_dir)/rainbowboot.img"
attach: $(build_dir)/rainbowboot.elf
gdb $(build_dir)/rainbowboot.elf \
-ex "target remote localhost:1234" \
-ex "set architecture i8086"
clean:
rm -rf $(build_dir)
$(build_dir)/rainbowboot.img: $(build_dir)/rainbowboot.elf | $(build_dir)
objcopy -O binary $(build_dir)/rainbowboot.elf $(build_dir)/rainbowboot.img
$(build_dir)/rainbowboot.elf: $(build_dir)/rainbowboot.o | $(build_dir)
ld -Ttext=0x7c00 -melf_i386 $(build_dir)/rainbowboot.o -o $(build_dir)/rainbowboot.elf
$(build_dir)/rainbowboot.o: $(src_dir)/rainbowboot.s | $(build_dir)
$(asm) -f elf32 -g3 -F dwarf $(src_dir)/rainbowboot.s -o $(build_dir)/rainbowboot.o
$(build_dir):
mkdir -p $(build_dir)
+41
View File
@@ -0,0 +1,41 @@
# rainbowboot
This is a x86 boot sector demo that prints a rolling rainbow pattern to screen.
Licensed under
## How to use
Make sure you have NASM (and QEMU, GDB and DOSBox if applicable) installed.
### Building the disk image
```sh
make
```
### Running on QEMU
```sh
make run
```
### Running on DOSBox
```sh
make run-dosbox
```
### Debugging using QEMU and GDB
Starting QEMU in debug mode:
```sh
make run-gdb
```
Attaching to the virtual machine:
```sh
make attach
```
+49
View File
@@ -0,0 +1,49 @@
%define CHAR '#' ; printed ASCII character
%define DELAY 40000 ; time delay between lines in microseconds
%define CCOUNT 7 ; amount of colors
;; colors (see https://en.wikipedia.org/wiki/BIOS_color_attributes):
%define COLORS 0x04, 0x0C, 0x0E, 0x0A, 0x0B, 0x09, 0x05
%define DELAY_L (DELAY & 0xFFFF)
%define DELAY_H (DELAY >> 16)
bits 16
section .text
global _start
_start:
cli ; disable hardware interrupts
xor bh, bh ; set page number to 0
mov ax, 0x0003 ; set video mode
int 0x10 ; --- interrupt
mov ah, 0x01 ; hide cursor
mov ch, 0x3F ; --- ...
int 0x10 ; --- interrupt
mov ah, 0x02 ; move cursor to bottom
mov dh, 24 ; --- row 24
xor dl, dl ; --- column 0
int 0x10 ; --- interrupt
xor si, si ; set color index to 0
.loop mov ah, 0x09 ; print 80 colored characters
mov cx, 80 ; --- set count to 80
mov al, CHAR ; --- set character
mov bl, [colors+si] ; --- set attribute (color)
int 0x10 ; --- interrupt
mov ah, 0x86 ; sleep
mov cx, DELAY_H ; --- set microseconds (cx:dx)
mov dx, DELAY_L ; --- ...
int 0x15 ; --- interrupt
mov ah, 0x0E ; print line feed
mov al, 0x0A ; --- set character to line feed
int 0x10 ; --- interrupt
inc si ; increment color index
cmp si, CCOUNT ; --- if color index is inside bounds
jl .loop ; --- -> repeat loop
xor si, si ; --- else, set color index to 0
jmp .loop ; repeat loop
colors: db COLORS
times 510 - ($ - $$) db 0
dw 0xAA55