trying to start from scratch
Posted: Wed Jan 05, 2011 10:41 pm
Hi all, I spent much time reading, playing with code snippets, and building on other codes from tutorials.I have wrote small 32 bit kernel in nasm, pretty useless still but I am proud.
After taking a break to do some work in java on a friends project, I come back, and want to write my own stage 1 bootloader.
So I used bios interrupts to try and load files. Now I have compared to some code I pulled from a tutorial months ago, and mine is VERY bare comparatively, but I do not see any part of their code which looks necessary to actually loading sector to memory and executing.
Please note before answering: I am not looking for code to fix my problem, I would like to make it myself, but I need some direction as to what I am doing wrong(because when I look at reference manual from Intel or Art of Assembler, I see my code looks right to me)
Anyway here is the code I have wrote, i dd both files to raw floppy image.
boot1.s
and stage2 stub:
After taking a break to do some work in java on a friends project, I come back, and want to write my own stage 1 bootloader.
So I used bios interrupts to try and load files. Now I have compared to some code I pulled from a tutorial months ago, and mine is VERY bare comparatively, but I do not see any part of their code which looks necessary to actually loading sector to memory and executing.
Please note before answering: I am not looking for code to fix my problem, I would like to make it myself, but I need some direction as to what I am doing wrong(because when I look at reference manual from Intel or Art of Assembler, I see my code looks right to me)
Anyway here is the code I have wrote, i dd both files to raw floppy image.
boot1.s
Code: Select all
BITS 16
ORG 0x7C00
start: jmp load
Puts16:
mov ah, 0x0E
.loop:
lodsb
cmp al, 0
jz .done
int 10h
jmp .loop
.done:
ret
ResetFloppy:
mov si, rstfloppy
call Puts16
xor ah, ah
mov dl, ah
int 13h
jc ResetFloppy
ret
ReadSectors: ; read sectors to ax:0 (es:bx)
call ResetFloppy
mov es, ax
xor bx, bx
mov ah, 02h
mov al, 1 ; sectors to load: adjust for stage2 size
mov ch, 1 ; track #(should make function to translate linear address to chs)
mov cl, 2 ; sector number(sector to begin reading at)
xor dh, dh ; head 0 (first side of the floppy
mov dl, dh ; drive 0 = floppy
int 13h ; call bios disk service interupt
jc ReadSectors ; epic fail, do that **** again
ret
load:
xor ax, ax
mov ds, ax ; do i need this line?
mov es, ax ; or this one?
mov si, bootmsg
call Puts16
mov ax, 0x0200
call ReadSectors
jmp 0x0200:0x0 ;far jump to execute loaded sector!
bootmsg db 'Stage 1 boot initiated...', 13, 10, 0
rstfloppy db 'Resetting floppy drive.', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA
Code: Select all
BITS 16
ORG 0x0200
start: jmp stg2
Puts16:
mov ah, 0x0E
.loop:
lodsb
cmp al, 0
jz .done
int 10h
jmp .loop
.done:
ret
stg2:
mov si, msg
call Puts16
cli
jmp $
msg db 'now in stage 2!', 13, 10, 0