summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-15 21:24:36 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-15 21:24:36 +0200
commitf8dd9dd71ab603af23e008f1147f652b429c9296 (patch)
tree316bbf3585b9baeb55ca2b870e7be4724ce4936c
parent48f0fe5954a445ba890b6a3633bbbf46cddd07c9 (diff)
downloadabaos-f8dd9dd71ab603af23e008f1147f652b429c9296.tar.gz
abaos-f8dd9dd71ab603af23e008f1147f652b429c9296.tar.bz2
increased size of stage 2 bootloader by 1024 bytes
-rw-r--r--README6
-rw-r--r--src/Makefile10
-rw-r--r--src/README2
-rw-r--r--src/boot/boot.asm11
-rw-r--r--src/boot/stage1_functions.asm7
-rw-r--r--src/boot/stage2_check_magic.asm10
-rw-r--r--src/boot/stage2_real_functions.asm10
-rw-r--r--src/kernel/kernel.c5
8 files changed, 36 insertions, 25 deletions
diff --git a/README b/README
index 38574df..c6263fe 100644
--- a/README
+++ b/README
@@ -14,7 +14,7 @@ ndisasm -b16 -o7c00h -a image.bin | less
objdump -M intel -d kernel.o | less
gcc -m32 -ffreestanding -c -o kernel.o kernel.c
-ld -o kernel.bin -Ttext 0x8400 kernel.o -m elf_i386 --oformat binary
+ld -o kernel.bin -Ttext 0x8800 kernel.o -m elf_i386 --oformat binary
objdump -M intel -d kernel.bin | less
# oformat: objdump -i lists tons of formats
@@ -38,10 +38,10 @@ Next at t=14040244
(0) [0x000000007c00] 0000:7c00 (unk. ctxt): mov ax, 0x0000 ; b80000
C entry:
-break 0x8400
+break 0x8800
disassemble kernel in 32-bit mode
-ndisasm -b32 -o8400h -a kernel.bin | less
+ndisasm -b32 -o8800h -a kernel.bin | less
With qemu remote (see http://wiki.osdev.org/Kernel_Debugging):
diff --git a/src/Makefile b/src/Makefile
index d32d3c1..6689169 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,12 +10,12 @@ MAGIC := $(shell printf '%x' `date +%s`)
all: image.bin kernel.sym
# truncate to correct number of sectors, we have
-# 512 (boot, stage 1) + N * 512 (N currenty is 3, stage 2) = 3072 for boot.bin
-# + M * 512 (M is currently 7) = 3144 for kernel.bin
+# 512 (boot, stage 1) + N * 512 (N currenty is 5, stage 2) = 3072 for boot.bin
+# + M * 512 (M is currently 39) = 19968 for kernel.bin
# + 1 * 512 = 512 for magic.bin
# (M + N + 1 is the number of sectors to be read in stage 2, as stage 1
-# loads only the first sector, and stage 1 loads 3 sectors of stage 2,
-# adapt NOF_LOAD_SECTORS to 44)
+# loads only the first sector, and stage 1 loads 5 sectors of stage 2,
+# adapt NOF_LOAD_SECTORS to 42)
# then we make sure the image has the size of a 1.44 MB floppy
# (emulators like qemu do some guess work for CHS resolution based
# on the size of the image)
@@ -35,7 +35,7 @@ kernel.sym: kernel.elf
$(OBJCOPY) --only-keep-debug kernel.elf kernel.sym
kernel.elf: kernel/kernel.o kernel/kernel_asm.o kernel/console.o kernel/vgatext.o kernel/serial.o hardware/port.o hardware/port_asm.o hardware/interrupts.o hardware/interrupts_asm.o hardware/pci.o drivers/driver.o drivers/hdi/ps2/keyboard.o drivers/hdi/ps2/mouse.o drivers/video/vga.o libc/string.o libc/stdlib.o libc/stdio.o libc/setjmp.o
- $(LD) -o kernel.elf -N -n -Ttext 0x8400 --oformat elf32-i386 \
+ $(LD) -o kernel.elf -N -n -Ttext 0x8800 --oformat elf32-i386 \
kernel/kernel.o kernel/kernel_asm.o \
kernel/console.o kernel/vgatext.o kernel/serial.o \
hardware/port.o hardware/port_asm.o \
diff --git a/src/README b/src/README
index c1f1577..905399b 100644
--- a/src/README
+++ b/src/README
@@ -5,7 +5,7 @@ Simple bootloader, loading in two phases and loading the kernel itself
* boot.bin - boot sector (stage 1 and 2, total 2k), offset 0x7c00
* boot.asm - the main boot sector code using:
-* kernel.bin - linked kernel with fix start offset 0x8400
+* kernel.bin - linked kernel with fix start offset 0x8800
* boot_gdt.asm - the early GDT, flat memory model, no protection
* stage1_functions.asm - real mode functions of the bootloader
* stage2_functions.asm - protected mode primitive VGA routines
diff --git a/src/boot/boot.asm b/src/boot/boot.asm
index c3cb57e..75ad05e 100644
--- a/src/boot/boot.asm
+++ b/src/boot/boot.asm
@@ -106,7 +106,7 @@ stage2:
call print_string
-; load kernel to 0x8400 (directly after stage 2
+; load kernel to 0x8800 (directly after stage 2
; of the boot loader)
mov dl, [BOOT_DRIVE]
call read_from_disk
@@ -220,8 +220,11 @@ MESSAGE_HALTED:
%include "boot/stage2_check_magic.asm"
; make sure we have full sectors, stage 1 is 512 bytes, so we
-; have to will up 3 sectors
-times 2048-($-$$) db 0
+; have to will up 5 sectors (gives 6 in total for stage 1 and 2)
+times 3070-($-$$) db 0
-; position is 0x8400 now for the C entry
+; magic number of stage 2
+dw 0xAABB
+
+; position is 0x8800 now for the C entry
kernel_main:
diff --git a/src/boot/stage1_functions.asm b/src/boot/stage1_functions.asm
index bdb2aac..f1d229b 100644
--- a/src/boot/stage1_functions.asm
+++ b/src/boot/stage1_functions.asm
@@ -1,3 +1,6 @@
+; NOF_SECTORS_STAGE2
+NOF_SECTORS_STAGE2 equ 5
+
; IN dx: hex value to print
print_hex:
push bx
@@ -88,7 +91,7 @@ current_row:
read_stage2_from_disk:
mov ah, 0x02 ; read sectors from drive
- mov al, 3 ; read 3 sectors of stage 2
+ mov al, NOF_SECTORS_STAGE2 ; read sectors of stage 2
mov ch, 0 ; select first cylinder
mov dh, 0 ; first head
mov cl, 2 ; second sector after boot sector
@@ -101,7 +104,7 @@ read_stage2_from_disk:
jc .read_error
- cmp al, 3 ; 3 sectors read?
+ cmp al, NOF_SECTORS_STAGE2 ; correct number of sectors read?
jne .short_read ; if not, short read
ret
diff --git a/src/boot/stage2_check_magic.asm b/src/boot/stage2_check_magic.asm
index 1deaf05..7339a89 100644
--- a/src/boot/stage2_check_magic.asm
+++ b/src/boot/stage2_check_magic.asm
@@ -8,7 +8,7 @@ check_magic:
push edi
mov eax, NOF_LOAD_SECTORS ; number of 512-byte sectors
shl eax, 9 ; 512 bytes per sector
- mov edx, 0x8400 ; offset of kernel
+ mov edx, 0x8800 ; offset of kernel
add edx, eax
sub edx, MAGICLEN ; subtract the length of the magic string
mov esi, edx ; now use edx as first string address to compare to
@@ -20,12 +20,16 @@ check_magic:
.ok:
mov si, MAGIC_OK_MSG
call pm_print_string
+ mov edx, esi
+ call pm_print_hex
call pm_print_newline
xor eax, eax
jmp .end
.mismatch:
mov si, MAGIC_NOT_OK_MSG
call pm_print_string
+ mov edx, esi
+ call pm_print_hex
call pm_print_newline
xor eax, eax
mov eax, 1
@@ -42,7 +46,7 @@ db "ABAOS", %[MAGIC], 0
MAGICLEN equ $ - COMPARE_MAGIC
MAGIC_NOT_OK_MSG:
-db "Magic signature found", 0
+db "Magic signature found at ", 0
MAGIC_OK_MSG:
-db "Magic signature not found!", 0
+db "Magic signature not found at ", 0
diff --git a/src/boot/stage2_real_functions.asm b/src/boot/stage2_real_functions.asm
index 87642c2..84713d5 100644
--- a/src/boot/stage2_real_functions.asm
+++ b/src/boot/stage2_real_functions.asm
@@ -1,8 +1,8 @@
; number of sectors to be read for the kernel itself
; (note: the first sector gets loaded by the BIOS, the
-; next 3 sectors are read by the simple stage 1 loader,
-; so subtract 3 here!)
-NOF_LOAD_SECTORS equ 44
+; next 5 sectors are read by the simple stage 1 loader,
+; so subtract 5 here!)
+NOF_LOAD_SECTORS equ 42
; data sections used for reading the kernel from disk
SECTORS_PER_CYLINDER:
@@ -13,7 +13,7 @@ NOF_HEADS:
SECTORS_TO_LOAD:
db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total
CURRENT_SECTOR:
- db 5 ; first sector after stage 2
+ db 7 ; first sector after stage 2
CURRENT_CYLINDER:
db 0
CURRENT_HEAD:
@@ -90,7 +90,7 @@ read_from_disk:
mov bx, 0 ; where to store the data
mov es, bx
- mov bx, 0x8400 ; 2'048 bytes after first sector
+ mov bx, 0x8800 ; 3072 bytes after first sector
.read_next_sector:
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index d74e031..9557745 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -31,7 +31,7 @@ static bool terminate = false;
// also elimiate all the object allocated on the stack in kernel_main
static driver_manager_t *global_driver_manager;
-// must be first entry in kernel.bin (0x8400) as stage 2 of
+// must be first entry in kernel.bin (0x8800) as stage 2 of
// the boot loader expects the entry point to be here!
void kernel_main( void )
{
@@ -51,7 +51,8 @@ void kernel_main( void )
// initialize the early console of the kernel
stdio_set_console( &console );
puts( "Started early kernel console" );
- printf( "Kernel code and data is at 0x%X, kernel stack at 0x%X\n", 0x8400, 0x90000 );
+ // TODO: get those values somehow from the boot loader
+ printf( "Kernel code and data is at 0x%X, kernel stack at 0x%X\n", 0x8800, 0x90000 );
// exit point in case of kernel panic, do this as soon as
// possible, as soon we have an early console we can croak on