Current status of the code

This commit is contained in:
Eric-Paul Ickhorn 2023-05-26 21:24:50 +02:00
parent ad75b3ab3f
commit 61a8ca90e8
9 changed files with 192 additions and 23 deletions

View File

@ -1,3 +1,3 @@
# nightloader
A slightly bloated bootloader.
A slightly bloated bootloader.

View File

@ -1,12 +1,58 @@
#!/bin/env bash
#!/bin/bash
cd bootsector
./build.sh
cd ../
echo "|==== Building the NightLoader with Build-Script v0.1 ====|"
echo " "
cd stage_2
./build.sh
cd ../
cat bootsector/stage_1.bin > nightloader.bin
# cat stage_2/stage_2.bin >> nightloader.bin
# Legacy Bootloader for old BIOS-platforms
echo "STARTING TO BUILD LEGACY-BIOS LOADER!"
# Build the stage-1 bootloader; the first disk-sector.
cd code/legacy-bios/bootsector
bash build.sh $1 $2
mv bootsector.bin ../../../
cd ..
# Build the stage 2 - starter; it is just there to jump
# to the *executable file* which the UEFI-codepath also uses.
cd starter
bash build.sh $1 $2
mv starter.bin ../../../
cd ../../../
mv bootsector.bin build/objects/
mv starter.bin build/objects/
echo "FINISHED BUILDING LEGACY-BIOS LOADER"
echo " "
echo " "
echo " "
echo "Creating disk image for a basic NightLoader-installation"
# Create the partition's image-file by allocating 256MB and
# creating a FAT32 - partition which then resides there.
truncate -s 256M partition.bin
mkfs.fat -F32 -nNIGHT partition.bin
# Mount the partition-image to a specific directory (needs
# root-permissions), copy over the freshly built binaries to
# the path they belobng to and unmount the partition.
mount partition.bin partition/
mkdir -p partition/nightloader/
cp starter.bin partition/
umount partition.bin
mv partition.bin build/objects/
# Create a disk image by including the first disk sector.
cat build/objects/bootsector.bin > nightloader.bin
cat build/objects/partition.bin >> nightloader.bin
echo " "
echo " "
echo "Finished building the NightLoader!"
echo " "

View File

@ -1,3 +1,2 @@
#!/bin/env bash
nasm -fbin start.asm -o stage_1.bin
nasm -fbin start.asm -o bootsector.bin

View File

@ -1,4 +1,65 @@
; TODO: Read FAT32 filesystem and load raw binary frompath nightloader/stage_2.bin
; TODO: Read FAT32 filesystem and load raw binary from path nightloader/stage_2.bin
FAT32_HEADER_ROOT_DIRECTORY_FAT_INDEX equ 0x2c
find_stage_2:
; Set extra-segment to the address where the Stage 2 - partition is located.
mov bx, 0x2000
mov es, bx
mov ds, bx
; PART 1: FIND THE STAGE 2 - FILE'S OFFSET IN THE PARTITION
; Read cluster size (in bytes) into dx
mov bx, 0x000b
mov ax, [bx]
add bx, 2
mov di, [bx]
mul di
mov dx, ax
; Read the root directory's first cluster's index into si:di (si: upper, di: lower)
mov bx, FAT32_HEADER_ROOT_DIRECTORY_FAT_INDEX
mov di, [bx]
add bx, 2
mov si, [bx]
push si
push di
; Put address of root directory into ds:bx
; Part 1: Get the overflow
; mov bx,
; Loop through the root directory's entries
.root_directory_loop: ; Loops through all the root directory's clusters
mov di, [bx]
add bx, 2
mov si, [bx]
; Test for the root directory's "Last Cluster" - marker.
mov ax, [bx]
; cmp
jmp .root_directory_loop
; Arguments:
; bx:
; Return Values:
; ax: The index of the FAT-entry in which the searched file was found.
find_file_in_directory:

View File

@ -0,0 +1,54 @@
create_gdt:
mov bx, STAGE_1_GDT_MEMORY_ADDRESS
mov ds, bx
mov bx, 8
mov di, 8
.set_loop:
mov ax, bx
and ax, 0b111
mov [bx], byte 0xff
cmp ax, 0
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 1
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 2
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 3
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 4
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 5
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 6
je .set_loop_condition
mov [bx], byte 0xff
cmp ax, 7
je .set_loop_condition
.set_loop_condition:
cmp bx, 48
jb .set_loop
ret

View File

@ -2,7 +2,8 @@
STAGE_1_CODE_MEMORY_ADDRESS equ 0x7c00
STAGE_1_STACK_MEMORY_ADDRESS equ 0x07e0
STAGE_1_STACK_MEMORY_ADDRESS equ 0x7e00 ; grows downwards
STAGE_1_GDT_MEMORY_ADDRESS equ 0x7e00
NIGHTLOADER_PARTITION_TYPE equ 0x9d
@ -23,9 +24,9 @@ stage_0:
mov bx, STAGE_1_STACK_MEMORY_ADDRESS
mov ss, bx
mov bx, 0x0800
mov bp, 256
mov sp, 256
mov bx, 0x2000
mov bp, 512
mov sp, 512
mov bx, 0x0000
mov ds, bx
@ -71,6 +72,8 @@ stage_0:
.load_partition:
call create_gdt ; TODO: Doesn't belong here!
mov si, cx ; address of the partition table entry of the nightloader-partition
; TODO: Make this more flexible; that's urgent.
@ -80,23 +83,25 @@ stage_0:
mov cl, 2 ; sector (starts at 1, max.: 63)
mov dx, di ; storage device id
mov dh, 0 ; head
mov bx, 0x0800
mov bx, 0x2000
mov es, bx ; read destination segment
mov bx, 0x0000 ; read destination address
int 0x13
mov si, 0x8000
mov bx, 0x2000
mov ds, bx
mov si, 0x0000
mov cx, 8
mov dh, 12
mov dl, 36
call print_string
; jmp .wait
jmp 0x0800:0x0000
jmp 0x2000:0x0000
.no_boot_partition:
mov si, errors.no_boot_partition
@ -105,6 +110,8 @@ stage_0:
mov dh, 12
call print_string
.wait:
cli
hlt
@ -119,5 +126,6 @@ errors:
db "0123456789abcdef"
%include "utility.asm"
%include "gdt.asm"
%include "fat32.asm"
%include "partition_table.asm"

View File

@ -1,4 +1,5 @@
; cx: len_buffer
; si: buffer
; dl: start_x NOTE: Will contain the end of the text on-screen

View File

@ -1,3 +1,3 @@
#!/bin/env bash
#!/bin/bash

View File

@ -1,3 +1,3 @@
#!/bin/env bash
#!/bin/bash
qemu-system-x86_64 nightloader.bin