;
; bootsect.asm
; Copyright(C) 2004, Tian XiangYuan
;
.MODEL TINY,C
.386p
option expr32
option casemap:none
SYSSEG EQU 1000h
SYSOFF EQU 0100h
.CODE
ORG 7C00h
_start:
jmp begin
nop
DB 'BOOTSECT',0 ;magic
pack_size DB 16
DB 0 ;reserved
DW 60 ;sectors
DW SYSOFF ;buf_addr_off
DW SYSSEG ;buf_addr_seg
DD 2 ;sector_from
DD 0 ;sector_from_high
begin:
cli
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0FFFFh
sti
mov cx,msg_load_len ;length
lea bp,msg_load ;es:bp
call display_msg
; read disk for my OS
lea si,pack_size
mov dl,80h
mov ax,4200h
int 13h ;使用LBA方式读硬盘
jc error
; test magic of my os
lea si,magic_test ;ds:si
mov ax,SYSSEG
mov es,ax
mov di,SYSOFF
add di,3 ;es:di
mov cx,magic_test_len
cld
test_again:
cmpsb
jnz error
loop test_again
push SYSSEG
push SYSOFF
retf ;转入操作系统执行
error:
mov ax,cs
mov es,ax
lea bp,msg_error ;es:bp
mov cx,msg_error_len
call display_msg
failure:
hlt
jmp failure
;cx : length of message
;es:bp : address of message
;void display_msg();
display_msg PROC NEAR C
;scrollup a line
push cx
push bp
mov ax,0601h
mov bh,07h
mov cx,0000h ;y/x
mov dx,184Fh ;y2/x2, 24/79
int 10h
pop bp
pop cx
;display message
mov ax,1301h
mov bx,000Ah
;mov cx,msg_error_len
mov dl,0 ;x
mov dh,24 ;y
;lea bp,msg_error ;es:bp
int 10h
ret
display_msg endp
.DATA
msg_load DB 'Loading......',0
msg_load_len DW $ - msg_load
msg_error DB 'NO BOOTER,please reboot!',0
msg_error_len DW $ - msg_error
magic_test DB 'TianXiangYuan',0
magic_test_len DW $ - magic_test
end _start |