print all cluster numbers ok
This commit is contained in:
parent
308d1caf1e
commit
a0dacc4b9e
136
loader.asm
136
loader.asm
@ -28,15 +28,15 @@ DispStr:
|
|||||||
pop bp
|
pop bp
|
||||||
ret
|
ret
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
; @param ax: the int to print
|
; @param bp + 4: the word to print as uint_16t
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
; print a word as decimal to current cursor
|
; print a word as decimal to current cursor
|
||||||
|
|
||||||
DispInt:
|
DispInt:
|
||||||
push bp
|
push bp
|
||||||
mov bp, sp
|
mov bp, sp
|
||||||
pusha
|
pusha
|
||||||
mov di, 0
|
mov di, 0
|
||||||
|
mov ax, [bp + 4]
|
||||||
.loop1:
|
.loop1:
|
||||||
mov dx, 0
|
mov dx, 0
|
||||||
mov bx, 10
|
mov bx, 10
|
||||||
@ -61,8 +61,9 @@ DispInt:
|
|||||||
pop bp
|
pop bp
|
||||||
ret
|
ret
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
; give you a new line
|
; no param
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
|
; give you a new line
|
||||||
DispNewline:
|
DispNewline:
|
||||||
push bp
|
push bp
|
||||||
mov bp, sp
|
mov bp, sp
|
||||||
@ -81,6 +82,27 @@ DispNewline:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
|
; @param bp + 4: low byte holds the ascii to print
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
|
; putchar to current cursor pos
|
||||||
|
DispPutchar:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
pusha
|
||||||
|
; get cursor pos
|
||||||
|
mov ax, 0300h
|
||||||
|
mov bh, 0
|
||||||
|
int 10h
|
||||||
|
; putchar
|
||||||
|
mov ax, [bp + 4]
|
||||||
|
mov ah, 0Eh ; no need to set al, ax holds the param
|
||||||
|
mov bl, 0Fh
|
||||||
|
int 10H
|
||||||
|
|
||||||
|
popa
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
;----------------------------------------------------------------------------
|
||||||
; 函数名: StringCmp
|
; 函数名: StringCmp
|
||||||
;----------------------------------------------------------------------------
|
;----------------------------------------------------------------------------
|
||||||
; 作用:
|
; 作用:
|
||||||
@ -143,11 +165,11 @@ ReadSector:
|
|||||||
pop bp
|
pop bp
|
||||||
ret
|
ret
|
||||||
.ReadFail:
|
.ReadFail:
|
||||||
|
|
||||||
jmp $ ; 如果cf位置1,就意味着读入错误,这个时候建议直接开摆
|
jmp $ ; 如果cf位置1,就意味着读入错误,这个时候建议直接开摆
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; 函数名: GetNextCluster
|
; 函数名: GetNextCluster
|
||||||
|
; data => BaseOfSectorBuf : 0
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; 作用:
|
; 作用:
|
||||||
; ax存放的是当前的簇(cluster)号,根据当前的簇号在fat表里查找,找到下一个簇的簇号,并将返回值存放在ax
|
; ax存放的是当前的簇(cluster)号,根据当前的簇号在fat表里查找,找到下一个簇的簇号,并将返回值存放在ax
|
||||||
@ -176,9 +198,9 @@ GetNextCluster:
|
|||||||
mov ax, [es:bx]
|
mov ax, [es:bx]
|
||||||
pop bx ; 取回奇数标识信息
|
pop bx ; 取回奇数标识信息
|
||||||
cmp bx, 0 ; 如果是第奇数个FAT项还得右移四位
|
cmp bx, 0 ; 如果是第奇数个FAT项还得右移四位
|
||||||
jz EvenCluster ; 可能是微软(FAT是微软创建的)第一个亲儿子的原因,有它的历史局限性
|
jz .EvenCluster ; 可能是微软(FAT是微软创建的)第一个亲儿子的原因,有它的历史局限性
|
||||||
shr ax, 4 ; 当时的磁盘很脆弱,经常容易写坏,所以需要两张FAT表备份,而且人们能够制作的存储设备的容量很小
|
shr ax, 4 ; 当时的磁盘很脆弱,经常容易写坏,所以需要两张FAT表备份,而且人们能够制作的存储设备的容量很小
|
||||||
EvenCluster:
|
.EvenCluster:
|
||||||
and ax, 0FFFh ; 读完需要与一下,因为高位是未定义的,防止ax值有误
|
and ax, 0FFFh ; 读完需要与一下,因为高位是未定义的,防止ax值有误
|
||||||
mov word [bp - 2], ax ; 这里用了一个技巧,这样在popa的时候ax也顺便更新了
|
mov word [bp - 2], ax ; 这里用了一个技巧,这样在popa的时候ax也顺便更新了
|
||||||
|
|
||||||
@ -191,7 +213,7 @@ EvenCluster:
|
|||||||
; @retval ax: first cluster no
|
; @retval ax: first cluster no
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; Find File by name, return first cluster no.
|
; Find File by name, return first cluster no.
|
||||||
|
; data => BaseOfSectorBuf:OffsetOfSectorBuf
|
||||||
FuncFindFile:
|
FuncFindFile:
|
||||||
push bp
|
push bp
|
||||||
mov bp, sp
|
mov bp, sp
|
||||||
@ -247,58 +269,86 @@ FuncFindFile:
|
|||||||
pop bp
|
pop bp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;------------------------------------------------------------------------------
|
||||||
|
; @param bp + 4: first cluster number
|
||||||
|
;------------------------------------------------------------------------------
|
||||||
|
; Find File by name, return first cluster no.
|
||||||
|
; data => BaseOfSectorBuf:OffsetOfSectorBuf
|
||||||
|
FuncPrintClusterNumbers:
|
||||||
|
push bp
|
||||||
|
mov bp, sp
|
||||||
|
pusha
|
||||||
|
mov ax, [bp + 4]
|
||||||
|
.loop:
|
||||||
|
mov ax, dx
|
||||||
|
push ax
|
||||||
|
call DispInt ; ax now holds the current cluster number
|
||||||
|
add sp, 2
|
||||||
|
push ' '
|
||||||
|
call DispPutchar
|
||||||
|
add sp, 2
|
||||||
|
|
||||||
|
call GetNextCluster ; 根据数据区簇号获取文件下一个簇的簇号
|
||||||
|
mov dx, ax ; dx <- 下一个簇的簇号
|
||||||
|
cmp dx, 0FFFh ; 判断是否读完了(根据文档理论上dx只要在0xFF8~0xFFF都行,但是这里直接偷懒只判断0xFFF)
|
||||||
|
jnz .loop
|
||||||
|
|
||||||
|
popa
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
|
||||||
MAIN:
|
MAIN:
|
||||||
mov ax, cs ; cs <- 0
|
mov ax, cs ; cs <- 0
|
||||||
mov ds, ax ; ds <- 0
|
mov ds, ax ; ds <- 0
|
||||||
mov ss, ax ; ss <- 0
|
mov ss, ax ; ss <- 0
|
||||||
mov ax, BaseOfSectorBuf
|
mov ax, BaseOfSectorBuf
|
||||||
mov es, ax ; es <- BaseOfSectorBuf
|
mov es, ax ; es <- BaseOfSectorBuf
|
||||||
|
; Display "This is {name}'s boot"
|
||||||
call DispNewline
|
call DispNewline
|
||||||
mov ax, cs
|
|
||||||
push ax
|
|
||||||
mov ax, StudentString
|
|
||||||
push ax
|
|
||||||
mov ax, _endStudentString - StudentString
|
|
||||||
push ax
|
|
||||||
call DispStr
|
|
||||||
add sp, 6 ; pop for 3 times
|
|
||||||
|
|
||||||
mov ax, LoaderFileName
|
push cs
|
||||||
push ax
|
push StudentString
|
||||||
|
push _endStudentString - StudentString
|
||||||
|
call DispStr
|
||||||
|
add sp, 6 ; pop for 3 times
|
||||||
|
|
||||||
|
; Read loader.bin's cluster number
|
||||||
|
push LoaderFileName
|
||||||
call FuncFindFile
|
call FuncFindFile
|
||||||
mov dx, ax ; temporarily save read result to dx
|
add sp, 2
|
||||||
pop ax
|
|
||||||
|
|
||||||
|
mov dx, ax ; temporarily save read result to dx
|
||||||
|
; Print first cluster number
|
||||||
call DispNewline
|
call DispNewline
|
||||||
mov ax, cs
|
|
||||||
push ax
|
push cs
|
||||||
mov ax, clusternoString
|
push clusternoString
|
||||||
push ax
|
push _endclusternoString - clusternoString
|
||||||
mov ax, _endclusternoString - clusternoString
|
|
||||||
push ax
|
|
||||||
call DispStr
|
call DispStr
|
||||||
add sp, 6 ; pop for 3 times
|
add sp, 6 ; pop for 3 times
|
||||||
mov ax, dx ; dx holds the read result
|
|
||||||
call DispInt
|
|
||||||
|
|
||||||
mov ax, AA1FileName
|
push dx ; dx holds the read result
|
||||||
push ax
|
call FuncPrintClusterNumbers
|
||||||
|
add sp, 2
|
||||||
|
|
||||||
|
; Read aA1.txt's cluster number
|
||||||
|
push AA1FileName
|
||||||
call FuncFindFile
|
call FuncFindFile
|
||||||
mov dx, ax ; temporarily save read result to dx
|
add sp, 2
|
||||||
pop ax
|
|
||||||
|
|
||||||
|
mov dx, ax ; temporarily save read result to dx
|
||||||
|
; Print first cluster number
|
||||||
call DispNewline
|
call DispNewline
|
||||||
mov ax, cs
|
|
||||||
push ax
|
push cs
|
||||||
mov ax, clusternoString
|
push clusternoString
|
||||||
push ax
|
push _endclusternoString - clusternoString
|
||||||
mov ax, _endclusternoString - clusternoString
|
|
||||||
push ax
|
|
||||||
call DispStr
|
call DispStr
|
||||||
add sp, 6 ; pop for 3 times
|
add sp, 6
|
||||||
mov ax, dx ; dx holds the read result
|
|
||||||
call DispInt
|
push dx ; dx holds the read result
|
||||||
|
call FuncPrintClusterNumbers
|
||||||
|
add sp, 2
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
;==============================================================================
|
;==============================================================================
|
||||||
@ -307,7 +357,7 @@ MAIN:
|
|||||||
BaseOfStack equ 07c00h ; Boot状态下堆栈基地址(栈底, 从这个位置向低地址生长)
|
BaseOfStack equ 07c00h ; Boot状态下堆栈基地址(栈底, 从这个位置向低地址生长)
|
||||||
; according to osdev, memory from 0x0000:0x7e00 to 0x7000:0xFFFF is free to use
|
; according to osdev, memory from 0x0000:0x7e00 to 0x7000:0xFFFF is free to use
|
||||||
BaseOfSectorBuf equ 07000h ; diff from where we are here
|
BaseOfSectorBuf equ 07000h ; diff from where we are here
|
||||||
OffsetOfSectorBuf equ 0000h ; diff from where we are here
|
OffsetOfSectorBuf equ 0400h ; the first 400h(=1024d) bytes left for fat1 read buf
|
||||||
RootDirSectors equ 14 ; 19~32
|
RootDirSectors equ 14 ; 19~32
|
||||||
SectorNoOfRootDirectory equ 19 ; Root Sector starts from 19
|
SectorNoOfRootDirectory equ 19 ; Root Sector starts from 19
|
||||||
SectorNoOfFAT1 equ 1
|
SectorNoOfFAT1 equ 1
|
||||||
@ -335,7 +385,7 @@ LeftRootDirSectors dw RootDirSectors ; 还未搜索的根目录
|
|||||||
RootDirSectorNow dw SectorNoOfRootDirectory ; 目前正在搜索的根目录扇区
|
RootDirSectorNow dw SectorNoOfRootDirectory ; 目前正在搜索的根目录扇区
|
||||||
BufferPacket times 010h db 0 ; ReadSector函数会用到的,用于向int 13h中断的一个缓冲区
|
BufferPacket times 010h db 0 ; ReadSector函数会用到的,用于向int 13h中断的一个缓冲区
|
||||||
|
|
||||||
LoaderFileName db "LOADE BIN", 0 ; 8:3, fill with whitespace
|
LoaderFileName db "LOADER BIN", 0 ; 8:3, fill with whitespace
|
||||||
AA1FileName db "AA1 TXT", 0 ; the 0 at end is for StrCmp
|
AA1FileName db "AA1 TXT", 0 ; the 0 at end is for StrCmp
|
||||||
StudentString db "This is LiMaoliang's boot" ; size = 25
|
StudentString db "This is LiMaoliang's boot" ; size = 25
|
||||||
_endStudentString
|
_endStudentString
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user