As it's my first post - I should introduce myself. My name is Vladimir, currently in Year 12 at college in the UK. All of my assembler knowledge is 3 days old (and no older) and I am tinkering away at an attempt to run a "Hello, world" example in C++ using my own boot loader and from the hard drive.
I want to keep things simple - the kernel is located at the first sector on the hard drive (LBA mode) and I am guessing that the bootloader can use the int 0x13 to read a couple of sectors from the first "device" and in that way load the kernel. Ok, I'm talking a kernel that prints "hello" from asm in real mode but it will be a start.
However, here is my asm bootloader (512 bytes):
Code: Select all
; Set the "standard" boot loader location to our current one
[ORG 0x7c00]
jmp start ;Jump to start, sets CS, the code segment pointer
start:
xor ax, ax ;Sets AX to 0 (why can't we load 0 into ax?)
mov ds, ax ;Initialises DS with AX
jmp run ;Starts running properly
run:
;Clear the screen
mov ax, 3 ;Moves 3 into AX, sets text mode to 3
int 0x10 ;Calls the interrupt
mov si, msg ;Loads start message into SI
call print ;Print the message
;Set up stack
cli ;Clear interrupts
mov ax, 0x9000 ;Stack is at 9000h (9000:0000)
mov ss, ax ;Init
mov sp, 0 ;Clear stack pointer
sti ;Enable interrupts again
call loadkrnl ;Calls the kernel loader
loadkrnl:
mov ah, 0x2 ;Read sectors into memory (arg for int 13h)
mov al, 0x1 ; number of sectors to read - 1
mov ch, 0x0 ; cylinder number
mov cl, 0x1 ; sector number
mov dh, 0x0 ; head number
mov dl, 0x0 ; driver number
mov bx, 0x7000 ; offset to ES -- linear 0x7000
int 0x13 ;Call the disk interrupt
mov si, gsf
call print
hang:
jmp hang
print:
;Load the string
lodsb ;Loads a string (a byte at address DS:(E)SI into AL)
or al,al ;Performs a bitwise OR on the contents of AL and stores them in AL
jz done ;Jumps to done: (jump if zero, i.e. if AL is 0)
;Prepare for the interrupt sending
mov ah, 0x0E ;Set the correct flag
int 0x10 ;Call the interrupt
jmp print ;Jump back
done:
retn ;Return to caller
msg db 'Starting Boot process...', 13, 10, 0
gsf db 'Got so far...', 13, 10, 0
times 510-($-$$) db 0 ;fill with zeroes the first 512 bytes of boot sector
db 0x55 ;End with a (deprecate?) signature that this is a boot loader
db 0xAA ;ibid.
When I run this with "qemu boot2.bin -hda disk.img" (where disk.img is a file which represents the file system but has only the kernel binary at the start of it) - it doesn't get to finish with ("Got so far") but when the -hda flag is removed it reads(?) successfully...
Is it possible to print the contents of the memory once the segments are loaded?
Many thanks,
Vladimir