提交 009cc184 创建 作者: 赵鹏翀's avatar 赵鹏翀

init template

上级
/*.img
/bochs/bios.bin-1.7.5
/bochs/bochs.exe
/bochs/bochsdbg.exe
/bochs/VGABIOS-lgpl-latest
/Debug
/Release
bochsout.txt
*.bak
\ No newline at end of file
memory: guest=32, host=32
romimage: file=Bochs/bios.bin-1.7.5 # http://www.seabios.org/SeaBIOS
vgaromimage: file=Bochs/VGABIOS-lgpl-latest
clock: sync=realtime, time0=local
pci: enabled=1, chipset=i440fx, slot1=pcivga
private_colormap: enabled=0
ata0-master: type=disk, path=".\harddisk.img", mode=flat, cylinders=32, heads=2, spt=63
boot: disk
floppy_bootsig_check: disabled=0
log: bochsout.txt
panic: action=ask
error: action=report
info: action=report
debug: action=ignore
debugger_log: -
parport1: enabled=1, file="parport.out"
speaker: enabled=1, mode=sound
e1000: enabled=1, mac=52:54:00:12:34:56, ethmod=slirp, script=slirp.conf
usb_uhci: enabled=1, port1=disk:USBstick.img
<?xml version="1.0" encoding="gb2312"?>
<ASMProject Version="1.00" Name="PC016" ProjectType="pcproject" ProjectTemplateID="3652ff0f-6c27-4789-953c-043737005851" TemplatePath="PC016\Project" IncrementalUpload="-1" ProjectID="45b33c53-386f-4899-88f1-2741d8ae5f2c" IsSubmitWork="0">
<Configurations>
<Configuration Name="Debug" ConfigurationType="2" DebuggerFlavor="2">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool"/>
<Tool Name="JWASMAssemblerTool" ObjectFile="$(IntDir)\$(InputName).bin" ObjectFormate="0" ListFile="$(InputName).lst" GenerateDebugInformation="-1" VersionDebugInfo="-1" AdditionalOptions="/W0"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="JWlinkLinkerTool" AdditionalOptions="disable 1014"/>
<Tool Name="PostBuildEventTool" CommandLine="echo U̾ļ...&#xA;mkimage.exe &quot;$(IntDir)\boot.bin&quot; &quot;$(IntDir)\loader.bin&quot; &quot;USBstick.img&quot;&#xA;"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="Bochs">
<File RelativePath=".\Bochs\bios.bin-1.7.5" NoUpload="-1">
</File>
<File RelativePath=".\Bochs\bochs.exe" NoUpload="-1">
</File>
<File RelativePath=".\Bochs\bochsdbg.exe" NoUpload="-1">
</File>
<File RelativePath=".\Bochs\bochsrc.bxrc" NoUpload="-1">
</File>
<File RelativePath=".\Bochs\VGABIOS-lgpl-latest" NoUpload="-1">
</File>
</Filter>
<File RelativePath=".\bochsout.txt" NoUpload="-1">
</File>
<File RelativePath=".\boot.asm">
</File>
<File RelativePath=".\loader.asm">
</File>
<File RelativePath=".\harddisk.img">
</File>
<File RelativePath=".\USBstick.img">
</File>
</Files>
</ASMProject>
添加文件
LOADER_BASE equ 1000h
codeseg segment
org 7c00h ;告诉编译器程序加载到7c00处
start:
mov ax, 0 ;读取0面0道2扇区的内容到0:1000(即loader的内容)
mov es, ax
mov bx, LOADER_BASE
mov al, 4 ;读取的扇区数(拟定loader占用4个扇区)
mov ch, 0 ;磁道
mov cl, 2 ;扇区号(读第二个扇区)
mov dl, 80h ;硬盘从80h开始
mov dh, 0 ;0面
mov ah, 2 ;读扇区操作
int 13h
mov bx, 0b800h ;清屏
mov es, bx
mov bx, 0
mov cx, 25*80
clear:
mov word ptr es:[bx], 20h ;空格
mov word ptr es:[bx+1], 7h ;字符属性
add bx, 2
loop clear
mov ax, LOADER_BASE ;程序跳转到0:1000h处执行loader.bin
jmp ax
db 446- ($-start) dup (0) ;前446字节的内容不满时,用0填充
;硬盘分区表(共64字节,每16字节为一项,每项表示一个分区,共4项)
;每项中第一个字节表示引导指示符,80h表示活动分区,00h表示无效分区
db 80h
;第二、三、四个字节在这里没有用到。
db 00h, 00h, 00h
;第五个字节定义分区类型。01h表示未定义的分区类型。
db 01h
;第六、七、八个字节在这里没有用到。
db 00h, 00h, 00h
;第九到第十二字节表示逻辑起始扇区号(相对于逻辑0扇区的扇区数)。一个扇区大小为 512 字节。
dd 00010000h ;第一个分区前有 32MB 空白区域
;第十三到第十六字节表示该分区所占用的扇区数(总扇区数)
dd 00010000h ;第一个分区共 32MB 大小
;其余三项全部为0,表示没有其他分区。
db 16 dup (0)
db 16 dup (0)
db 16 dup (0)
dw 0aa55h ;可引导标志,2字节。这样446+64+2=512字节,恰好等于引导扇区的字节数。
codeseg ends
end
.386p
codeseg segment use16
org 1000h ;告诉编译器程序加载到1000处
jmp start ;程序的功能是用PIO方式读取硬盘0号扇区的内容,并将其显示在屏幕上
buffer db 512 dup (0) ;准备一个数据缓冲区
count dw 0 ;用于统计字数
ide_command_base_addr equ 01f0h ;IDE设备命令模块寄存器基地址
;***************************寄存器地址****************************************
; Port Read/Write Misc
; -------- ---------- ------------------------------------
; 1f0 r/w data register, the bytes are written/read here
; 1f1 r error register (look these values up yourself)
; 1f2 r/w sector count, how many sectors to read/write
; 1f3 r/w sector number, the actual sector wanted
; 1f4 r/w cylinder low, cylinders is 0-1024
; 1f5 r/w cylinder high, this makes up the rest of the 1024
; 1f6 r/w drive/head
; bit 7 = 1
; bit 6 = 0
; bit 5 = 1
; bit 4 = 0 drive 0 select
; = 1 drive 1 select
; bit 3-0 head select bits
; 1f7 r status register
; bit 7 = 1 controller is executing a command
; bit 6 = 1 drive is ready
; bit 5 = 1 write fault
; bit 4 = 1 seek complete
; bit 3 = 1 sector buffer requires servicing
; bit 2 = 1 disk data read corrected
; bit 1 = 1 index - set to 1 each revolution
; bit 0 = 1 previous command ended in an error
; 1f7 w command register
; commands:
; 50h format track
; 20h read sectors with retry
; 21h read sectors without retry
; 22h read long with retry
; 23h read long without retry
; 30h write sectors with retry
; 31h write sectors without retry
; 32h write long with retry
; 33h write long without retry
;
; Most of these should work on even non-IDE hard disks.
;*****************************************************************************
start:
mov ax, cs ;全部置0
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 7c00h
;磁头和驱动器
;读的扇区数
;读取的扇区号
;柱面的低8位
;柱面的高8位
;写命令字,读扇区,可重试
;查询IDE设备状态,忙时则等待
;读取IDE设备数据端口信息并送至数据缓冲区buffer
;***************************打印缓冲区内容*********************************
ShowBuffer:
lea si,offset buffer ;显示buffer内容,即将规定扇区的内容输出到屏幕上
cld
mov bp,24 ;共24行
NextLine:
mov cx,22 ;每行显示16字节的内容
NextCh:
lodsb
push ax
shr al, 4 ;逻辑右移,显示ah中数据
mov bx, 0
mov ah, 0eh
call ToASCII
int 10h
pop ax ;显示al中的数据
mov ah, 0eh
call ToASCII
int 10h
mov al, ' ' ;输出空格
int 10h
mov dx, count ;当输出了512字节后,跳转到死循环
add dx, 1
mov count, dx
cmp dx, 512
je over
loop NextCh ;循环
mov al, 0dh ;换行
int 10h
mov al, 0ah ;回车
int 10h
dec bp ;行数的循环
jnz NextLine
over:
pop dx
jmp over ;程序在这里死循环
ToASCII: ;将字符转换成ASCII码
and al,0fh
cmp al,10
jae Over10
add al,'0'
ret
Over10:
add al,'A'-10
ret
codeseg ends
end
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论