Skip to content
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
5 changes: 5 additions & 0 deletions How_to_write_a_bootloader/Part_3/bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ all:
dd if=./bin/kernel.bin >> ./bin/os.bin
dd if=/dev/zero bs=512 count=8 >> ./bin/os.bin

qemu:
# Use 32 bit qemu when using debugger on this 32 bit OS
qemu-system-x86_64 -hda ./bin/os.bin
#qemu-system-i386 -hda ./bin/os.bin

clean:
rm -f ./bin/boot.bin
rm -f ./bin/kernel.bin
Expand Down
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/bin/boot.bin
Binary file not shown.
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/bin/kernel.bin
100644 → 100755
Binary file not shown.
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/bin/os.bin
Binary file not shown.
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/build/completeKernel.o
Binary file not shown.
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/build/kernel.asm.o
Binary file not shown.
Binary file modified How_to_write_a_bootloader/Part_3/bootloader/build/kernel.o
Binary file not shown.
16 changes: 15 additions & 1 deletion How_to_write_a_bootloader/Part_3/bootloader/src/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ start:
mov ss, ax ; Set stack segment (SS) to 0x00
mov sp, 0x7c00; Set stack pointer (SP) to 0x7c00, top of the bootloader segment
sti ; Enable interrupts, allowing them to occur again

; set video mode, al 03h is a text mode, this also clears the screen
mov AH, 00h
mov AL, 03h
int 0x10


;Load kernel
mov bx, KERNEL_LOAD_SEG
mov bx, KERNEL_LOAD_SEG ; Load segment
mov es, bx
mov bx, 0x0000 ; Load offset (SEG*16 + OFFSET)
mov dh, 0x00
mov dl, 0x80
mov cl, 0x02
Expand Down Expand Up @@ -89,6 +96,13 @@ PModeMain:
or al, 2
out 0x92, al

; Copy kernel from 0x10000 to 0x100000, where we jump to, as protected mode can access past 1MB now
mov esi, 0x10000 ; Source
mov edi, KERNEL_START_ADDR ; Destination
mov ecx, 4096 ; num sectors * 512 bytes
cld
rep movsb

jmp CODE_OFFSET:KERNEL_START_ADDR


Expand Down
4 changes: 2 additions & 2 deletions How_to_write_a_bootloader/Part_3/bootloader/src/kernel.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ extern kernel_main

_start:
call kernel_main
jmp$
jmp $

times 512-($ - $$) db 0
times 510-($ - $$) db 0
6 changes: 5 additions & 1 deletion How_to_write_a_bootloader/Part_3/bootloader/src/kernel.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "kernel.h"

#define VIDEO_MEMORY 0xb8000

void kernel_main(){

unsigned char *video = (unsigned char *)VIDEO_MEMORY;
video[0] = 'H';
video[2] = 'i';
}
4 changes: 2 additions & 2 deletions How_to_write_a_bootloader/Part_3/bootloader/src/kernel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef KENREL_H
#define KENREL_H
#ifndef KERNEL_H
#define KERNEL_H

void kernel_main();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ OUTPUT_FORMAT(binary)
SECTIONS
{
. = 0x0100000;
.text : ALIGN(4096)
.text : ALIGN(16)
{
*(.text)
}

.rodata : ALIGN(4096)
.rodata : ALIGN(16)
{
*(.rodata)
}

.data : ALIGN(4096)
.data : ALIGN(16)
{
*(.data)
}

.bss : ALIGN(4096)
.bss : ALIGN(16)
{
*(COMMON)
*(.bss)
Expand Down