接上文,实现boot的开机引导

bootsect.s只是做了修改:

SYSSIZE = 0x3000
.globl begtext, begdata, begbss, endtext, enddata, endbss
.text
begtext:
.data
begdata:
.bss
begbss:
.text

SETUPLEN =4    !nr of setup-sectors
BOOTSEG  =0x07c0   !original address of boot-sector
INITSEG  =0x9000   ! wemove boot here - out of the way
SETUPSEG =0x9020   ! setupstarts here
SYSSEG   =0x1000   !system loaded at 0x10000 (65536).
ENDSEG   = SYSSEG +SYSSIZE  ! where to stoploading

ROOT_DEV = 0x306

entry _start
_start:
!-------------------------
 mov ax,#BOOTSEG
 mov ds,ax
 mov ax,#INITSEG
 mov es,ax
 mov cx,#256
 sub si,si
 sub di,di
 rep
 movw
 jmpi go,INITSEG
!---------------------------
go: mov ax,cs
 mov ds,ax
 mov es,ax
! put stack at 0x9ff00.
 mov ss,ax
 mov sp,#0xFF00  !arbitrary value >>512

! load the setup-sectors directly after the bootblock.
! Note that 'es' is already set up.
!-----------------------------
load_setup:
 mov dx,#0x0000  !drive 0, head 0
 mov cx,#0x0002  !sector 2, track 0
 mov bx,#0x0200  !address = 512, in INITSEG
 mov ax,#0x0200+SETUPLEN !service 2, nr of sectors
 int 0x13   !read it
 jnc ok_load_setup  !ok - continue
 mov dx,#0x0000
 mov ax,#0x0000  !reset the diskette
 int 0x13
 j load_setup
!---------------------------
ok_load_setup:

! Print some inane message

 mov ah,#0x03  !read cursor pos
 xor bh,bh
 int 0x10

 mov cx,#29
 mov bx,#0x0007  !page 0, attribute 7 (normal)
 mov bp,#msg1
 mov ax,#0x1301  !write string, move cursor
 int 0x10


 jmpi 0,SETUPSEG

msg1:
 .byte 13,10
 .ascii "Kerberos is Loading ..."
 .byte 13,10,13,10

.org 508
root_dev:
 .word ROOT_DEV
boot_flag:
 .word 0xAA55

.text
endtext:
.data
enddata:
.bss
endbss:
setup.s也只是修改了一下:

INITSEG  = 0x9000 ! we moveboot here - out of the way
SYSSEG   =0x1000 ! system loaded at 0x10000 (65536).
SETUPSEG = 0x9020 ! this is the currentsegment

.globl begtext, begdata, begbss, endtext, enddata, endbss
.text
begtext:
.data
begdata:
.bss
begbss:
.text

entry start
start:
! -------打印字符串----------------
 mov ax,cs;
 mov ds,ax;
 mov es,ax;
!--------代码段与数据段、附加段在一个位置--------
 mov ah,#0x03  !read cursor pos
 xor bh,bh
 int 0x10
 
 mov cx,#22
 mov bx,#0x0007  !page 0, attribute 7 (normal)
 mov bp,#msg1
 mov ax,#0x1301  !write string, move cursor
 int 0x10

!--------打印光标位置---------------

 mov ax,#INITSEG !this is done in bootsect already, but...
 mov ds,ax
 mov ah,#0x03 !read cursor pos
 xor bh,bh
 int 0x10  !save it in known place, con_init fetches
 mov [0],dx  !it from 0x90000.

 mov cx,#13
 mov bx,#0x0007  !page 0, attribute 7 (normal)
 mov bp,#cursor1
 mov ax,#0x1301  !write string, move cursor
 int 0x10
  
!----------调用函数用数字打印------------
 push [0]
 call print_hex
 call print_nl
 pop [0];
 
!----------打印内存信息-------------------------- 
! Get memory size (extended mem, kB)
 mov ah,#0x03  !read cursor pos
 xor bh,bh
 int 0x10
 
 mov cx,#14
 mov bx,#0x0007  !page 0, attribute 7 (normal)
 mov bp,#memory
 mov ax,#0x1301  !write string, move cursor
 int 0x10
 
 mov ah,#0x88
 int 0x15
 mov [2],ax
 
 push [2]
 call print_hex
 mov ax,#0xe4b  !K
 int 0x10
 mov al,#0x42  !B
 int 0x10
 call print_nl
 pop [0];
!----------------------------
msg1:
 .ascii "Ahh! I'm in SETUP..."
 .byte 13,10
cursor1:
 .byte 13,10
 .ascii "Cursor Pos:"
memory:
 .byte 13,10
 .ascii "Memory Size:"
!--------将16进制输出到屏幕上的函数----------------
print_hex:
 mov bp,sp;
 add bp,#2;
 mov dx,(bp)  !将(bp)所指的值放入dx中,如果bp是指向栈顶的话
 mov cx,#4  ! 4个十六进制数字
print_digit:
 rol dx,#4   !循环以使低4比特用上 !!取dx的高4比特移到低4比特处。  
  mov ax,#0xe0f ! ah = 请求的功能值,al =半字节(4个比特)掩码。  
  and al,dl  ! 取dl的低4比特值。
  add al,#0x30 !给al数字加上十六进制0x30   
  cmp al,#0x3a
  jl outp   !是一个不大于十的数字   
  add al,#0x07  !是a~f,要多加7
outp:
 int 0x10   
 loop print_digit   
 ret
 
!打印回车换行
print_nl:
 mov ax,#0xe0d ! CR
 int 0x10
 mov al,#0xa  !LF   
 int 0x10
 ret

.text
endtext:
.data
enddata:
.bss
endbss

以上代码仅供参看,水平有限,研究成果,不提倡摘抄,可以研究,不供投机用,谢谢合作!

posted @ 2008-09-27 00:22  dc0453  阅读(228)  评论(0)    收藏  举报