here goes the code
Stage1:
Code: Select all
[bits 16]
[org 0x07C00]
; ----------------------------------------------------------------
; code section STARTS
; ----------------------------------------------------------------
start:
cli
mov ax, 0x0000
mov ds, ax
mov ss, ax
mov ax, 0x7c00
mov sp, ax
mov si, rstring
call printstring
call newline
mov si, stagestring
call printstring
call newline
mov ax, 0
mov bx, 0
mov cx, 0
mov dx, 0
mov bx, 0x1000
mov es, bx
mov bx, 0x0000
reset:
mov ax, 0
mov dl, 0
int 0x13
jc reset
readsector:
; mov ah, 0x02 ; service
; mov al, 0x03 ; number of sectors to read
; mov ch, 0x00 ; cylinder number
; mov cl, 0x01 ; sector number
; mov dh, 0x00 ; head number
; mov dl, 0x00 ; drive number
mov ax, 0x0201
mov cx, 1
xor dx, dx
int 0x13
jc readsector
mov ax, 0x1000
mov ds, ax
JMP 0x1000:0000
; ---------------------------------------------------------------
; code section ENDS
; ---------------------------------------------------------------
; ----------------------------------------------------------------
; core functions STARTS
; ----------------------------------------------------------------
printstring:
next_printstring:
lodsb
or al, al
jz exit_printstring
call printchar
jmp next_printstring
exit_printstring:
ret
printchar:
mov ah, 0x0e
mov bh, 0x0
mov bl, 0x07
int 0x10
ret
newline:
mov al, 0xa ; 10 - new line
call printchar
mov al, 0xd ; 13 - line feed
call printchar
ret
; --------------------------------------------------------------------
; core functions ENDS
; --------------------------------------------------------------------
; ------------------------------------------------------------------
; data section STARTS
; ------------------------------------------------------------------
rstring db 'rloader version 0.5. ', 0
stagestring db 'stage1 . ', 0
;-------------------------------------------------------------------
; data section ENDS
;-------------------------------------------------------------------
TIMES 510 - ($ - $$) db 0
DW 0xAA55
Stage2:
Code: Select all
[bits 16]
[org 0]
mov si, stage2
call printstring
JMP $
printstring:
next_printstring:
lodsb
or al, al
jz exit_printstring
call printchar
jmp next_printstring
exit_printstring:
ret
printchar:
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
int 0x10
ret
stage2 db "stage 2 loader ! .", 13, 10, 0
TIMES 512 - ($ - $$) db 0
;DW 0x5577