⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot record.asm

📁 挺小的
💻 ASM
📖 第 1 页 / 共 2 页
字号:
jmp nextchar                    ; 继续显示下一下字符
return:
ret
; ****************************************************************************************************
Message:
db "set.asm begin!"    ; 定义显示消息
db 13 , 10 , 0      ; 13 表示回车,10 表示换到下一行,0 表示字符串结束


初步注释后的ChaOSv2.0的引导程序(与原程序有一些变动):
;*************************************************************************
;              这是引导程序主要的作用是加载set.asm到内存中(至于加载到哪儿去了我还没有具体分析)
;                 to load a file from a DOS FAT12 floppy as the OS
;*************************************************************************
[BITS 16]
[ORG 0x0000]
jmp     START
    
    OEM_ID                db "QiMingOS";这儿可以改成你想要的字符,可能只能是8个字符!
    BytesPerSector        dw 0x0200
    SectorsPerCluster     db 0x01
    ReservedSectors       dw 0x0001
    TotalFATs             db 0x02
    MaxRootEntries        dw 0x00E0
    TotalSectorsSmall     dw 0x0B40
    MediaDescriptor       db 0xF0
    SectorsPerFAT         dw 0x0009
    SectorsPerTrack       dw 0x0012
    NumHeads              dw 0x0002
    HiddenSectors         dd 0x00000000
    TotalSectorsLarge     dd 0x00000000
    DriveNumber           db 0x00
    Flags                 db 0x00
    Signature             db 0x29
    VolumeID              dd 0xFFFFFFFF
    VolumeLabel           db "QUASI  BOOT"
    SystemID              db "FAT12   "
    
    START:
    ; code located at 0000:7C00, adjust segment registers
         cli
         mov     ax, 0x07C0
         mov     ds, ax
         mov     es, ax
         mov     fs, ax
         mov     gs, ax
    ; create stack
         mov     ax, 0x0000
         mov     ss, ax
         mov     sp, 0xFFFF
         sti
    ; post message
         mov     si, msgLoading
         call    DisplayMessage
    LOAD_ROOT:
    ; compute size of root directory and store in 慶x?
         xor     cx, cx
         xor     dx, dx
         mov     ax, 0x0020                          ; 32 byte directory entry
         mul     WORD [MaxRootEntries]               ; total size of directory
         div     WORD [BytesPerSector]               ; sectors used by directory
         xchg    ax, cx
    ; compute location of root directory and store in 慳x?
         mov     al, BYTE [TotalFATs]                ; number of FATs
         mul     WORD [SectorsPerFAT]                ; sectors used by FATs
         add     ax, WORD [ReservedSectors]          ; adjust for bootsector
         mov     WORD [datasector], ax               ; base of root directory
         add     WORD [datasector], cx
    ; read root directory into memory (7C00:0200)
         mov     bx, 0x0200                          ; copy root dir above bootcode
         call    ReadSectors
    ; browse root directory for binary image
         mov     cx, WORD [MaxRootEntries]           ; load loop counter
         mov     di, 0x0200                          ; locate first root entry
    .LOOP:
         push    cx
         mov     cx, 0x000B                          ; eleven character name
         mov     si, ImageName                       ; image name to find
         push    di
    rep  cmpsb                                       ; test for entry match
         pop     di
         je      LOAD_FAT
         pop     cx
         add     di, 0x0020                          ; queue next directory entry
         loop    .LOOP
         jmp     FAILURE
    LOAD_FAT:
    ; save starting cluster of boot image
         mov     si, msgCRLF
         call    DisplayMessage
         mov     dx, WORD [di + 0x001A]
         mov     WORD [cluster], dx                  ; file抯 first cluster
    ; compute size of FAT and store in 慶x?
         xor     ax, ax
         mov     al, BYTE [TotalFATs]                ; number of FATs
         mul     WORD [SectorsPerFAT]                ; sectors used by FATs
         mov     cx, ax
    ; compute location of FAT and store in 慳x?
         mov     ax, WORD [ReservedSectors]          ; adjust for bootsector
    ; read FAT into memory (7C00:0200)
         mov     bx, 0x0200                          ; copy FAT above bootcode
         call    ReadSectors
    ; read image file into memory (0100:0000)
         mov     si, msgCRLF
         call    DisplayMessage
         mov     ax, 0x0100                          ; destination of image CS
         mov     es, ax
         mov     bx, 0x0000                          ; destination for image IP
         push    bx
    LOAD_IMAGE:
         mov     ax, WORD [cluster]                  ; cluster to read
         pop     bx                                  ; buffer to read into
         call    ClusterLBA                          ; convert cluster to LBA
         xor     cx, cx
         mov     cl, BYTE [SectorsPerCluster]        ; sectors to read
         call    ReadSectors
         push    bx
    ; compute next cluster
         mov     ax, WORD [cluster]                  ; identify current cluster
         mov     cx, ax                              ; copy current cluster
         mov     dx, ax                              ; copy current cluster
         shr     dx, 0x0001                          ;
    ;divide by two
         add     cx, dx                              ; sum for (3/2)
         mov     bx, 0x0200                          ; location of FAT in memory
         add     bx, cx                              ; index into FAT
         mov     dx, WORD [bx]                       ; read two bytes from FAT
         test    ax, 0x0001
         jnz     .ODD_CLUSTER
    .EVEN_CLUSTER:
         and     dx, 0000111111111111b               ; take low twelve bits
        jmp     .DONE
    .ODD_CLUSTER:
         shr     dx, 0x0004                          ; take high twelve bits
    .DONE:
         mov     WORD [cluster], dx                  ; store new cluster
         cmp     dx, 0x0FF0                          ; test for end of file
         jb      LOAD_IMAGE
    DONE:
         mov     si, msgCRLF
         call    DisplayMessage
         push    WORD 0x0100
         push    WORD 0x0000
         retf
    FAILURE:
         mov     si, msgFailure
         call    DisplayMessage
         mov     ah, 0x00
         int     0x16                                ; await keypress
         int     0x19                                ; warm boot computer
    
    ;*************************************************************************
    ; PROCEDURE DisplayMessage
    ; display ASCIIZ string at ds:si via BIOS
    ;*************************************************************************
    DisplayMessage:
         lodsb                                       ; load next character
         or      al, al                              ; test for NUL character
         jz      .DONE
         mov     ah, 0x0E                            ; BIOS teletype
         mov     bh, 0x00                            ; display page 0
         mov     bl, 0x07                            ; text attribute
         int     0x10                                ; invoke BIOS
         jmp     DisplayMessage
    .DONE:
         ret
    
    ;*************************************************************************
    ; PROCEDURE ReadSectors
    ; reads 慶x?sectors from disk starting at 慳x?into
    ;memory location 慹s:bx?
    ;*************************************************************************
    ReadSectors:
    .MAIN
         mov     di, 0x0005                          ; five retries for error
    .SECTORLOOP
         push    ax
         push    bx
         push    cx
         call    LBACHS
         mov     ah, 0x02                            ; BIOS read sector
         mov     al, 0x01                            ; read one sector
         mov     ch, BYTE [absoluteTrack]            ; track
         mov     cl, BYTE [absoluteSector]           ; sector
         mov     dh, BYTE [absoluteHead]             ; head
         mov     dl, BYTE [DriveNumber]              ; drive
         int     0x13                                ; invoke BIOS
         jnc     .SUCCESS                            ; test for read error
         xor     ax, ax                              ; BIOS reset disk
         int     0x13                                ; invoke BIOS
         dec     di                                  ; decrement error counter
         pop     cx
         pop     bx
         pop     ax
         jnz     .SECTORLOOP                         ; attempt to read again
         int     0x18
    .SUCCESS
         mov     si, msgProgress
         call    Di

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -