code:7C00 code segment byte public 'CODE' use16
code:7C00 assume cs:code
code:7C00 org 7C00h
code:7C00 assume es:nothing, ss:nothing, ds:code, fs:nothing, gs:nothing
code:7C00 start proc far
code:7C00 xor ax, ax
code:7C02 mov ss, ax
code:7C04 mov sp, 7C00h
code:7C07 sti
code:7C08 push ax
code:7C09 pop es
code:7C0A push ax ; es=ds=ss=0x0000
code:7C0B pop ds ; initial segment and stack
code:7C0C cld
code:7C0D push ax
code:7C0E mov si, 7C00h
code:7C11 mov di, 600h
code:7C14 mov cx, 200h
code:7C17 rep movsb ; move this MBR code to 600h
code:7C19 mov di, 61Eh
code:7C1C push di
code:7C1D retf ; jmp 0000:61Eh
code:7C1E xor bx, bx ; ip=61Eh
code:7C20 xor dx, dx
code:7C22 mov si,
7BEh ; partition state
// 7BEh 这个数是怎么来的,是什么意思
code:7C25 mov cl, 4 ; Search DPT,and it has 4 itemes,
code:7C27 check_next_partition:
code:7C27 test byte ptr [si], 80h ; 0x80->Active 0x00->not active
code:7C2A jz short search_active_partition ; next item, size of one item is 10h
code:7C2A
code:7C2C mov dx, si ; save item base address
code:7C2E inc bx ; the sum of the active item
code:7C2F search_active_partition:
code:7C2F add si, 10h ; next item, size of one item is 10h
code:7C32 loop check_next_partition ; 0x80->Active 0x00->not active
code:7C34 cmp bx, 1
code:7C37 jz short found_partition_active
code:7C39 mov si, 0C4h ; sz_Invalid_DPT Si=lpString (Offset)
code:7C3C mov cx, 17h ; length
code:7C3F jmp short Display_Error_Informatin ; add base ip
code:7C41 nop
code:7C42 found_partition_active:
code:7C42 push dx
code:7C43 mov ah, 41h
code:7C45 mov dl, 80h
code:7C47 mov bx, 55AAh
code:7C4A int 13h ; Detect sport extend int 13h call
code:7C4C pop dx
code:7C4D cmp bx, 0AA55h
code:7C51 jnz short CHSReadMBRFormDisk
code:7C53 test cl, 1
code:7C56 jz short CHSReadMBRFormDisk
code:7C58 LBAReadMBRFormDisk:
code:7C58 mov ax, 4200h
code:7C5B mov si, 7ADh
code:7C5E mov cl, 10h
code:7C60 init_disk_addr_pkt:
code:7C60 mov byte ptr [si], 0
code:7C63 inc si
code:7C64 loop init_disk_addr_pkt
code:7C66 mov si, 7ADh
code:7C69 mov di, dx ; dx point to active item base address
code:7C6B mov byte ptr [si], 10h ; packet_size=16 (DB must)
code:7C6E mov byte ptr [si+2], 1 ; sector_count 01h (DW)
code:7C72 mov word ptr [si+4], 7C00h ; buffer_addr (DD)
code:7C77 mov bx, [di+8] ; line address of sectors (DD RAV)
code:7C7A mov [si+8], bx ; sector_base (QD)
code:7C7D mov bx, [di+0Ah] ; line address of sectors + 2 (DD RAV)
code:7C80 mov [si+0Ah], bx ; sector_base + 2 (QD)
code:7C83 jmp short ReadDisk
code:7C85 nop
code:7C86 CHSReadMBRFormDisk:
code:7C86 mov ax, 201h
code:7C89 mov bx, 7C00h ; offset buffer_addr (DW)
code:7C8C mov si, dx ; dx point to active item base address
code:7C8E mov cx, [si+2] ; CH = track, CL = sector
code:7C91 mov dh, [si+1] ; DH = head
code:7C94 ReadDisk:
code:7C94 mov dl, 80h
code:7C96 int 13h AH = status, AL = number of sectors read
code:7C98 mov si, 7DFEh
code:7C9B cmp word ptr [si], 0AA55h ; chech is invalid MBR
code:7C9F jz short Load_OS_MBR
code:7CA1 mov si, 0DBh
code:7CA4 mov cx, 18h
code:7CA7 jmp short Display_Error_Informatin ; add base ip
code:7CA9 nop
code:7CAA Load_OS_MBR:
code:7CAA xor ax, ax
code:7CAC push ax
code:7CAD mov ax, 7C00h
code:7CB0 push ax
code:7CB1 retf ; jmp load os MBR
code:7CB2 Display_Error_Informatin:
code:7CB2 add si, 600h ; add base ip
code:7CB6 Display:
code:7CB6 lodsb ; AL = character
code:7CB7 mov bx, 7 ; BH = display page BL = foreground color
code:7CBA mov ah, 0Eh
code:7CBC int 10h ; VIDEO - WRITE CHARACTER AND ADVANCE CURSOR
code:7CBE loop Display
code:7CC0 db 0B1h
code:7CC1 db 0Fh
code:7CC2 db 0E2h ; ?
code:7CC3 db 0FCh ; ?
code:7CC4 sz_Invalid_DPT db 'Invalid partition tableMissing operating system',0
code:7CF4 sz_MBR_Information db 'Master Boot Record Wrote by DiskMan Ver1.30',0
code:7D20 db 98h dup(0) ; not use space
code:7DB8 s_Zmzm db 'ZmZm',0 ; not use data, can set any data if you like
code:7DBD db 0
code:7DBE First_Item_DPT db 80h ; statue
code:7DBF db 1 ; 开始头
code:7DC0 dw 1 ; 开始扇区
code:7DC2 db 7 ; 分区类型指示
code:7DC3 db 0FEh ; 结束头
code:7DC4 dw 0CCFFh ; 结束扇
code:7DC6 dd 3Fh ; 扇区在前的分区 1
code:7DCA dd 0EE834Eh
code:7DCE Second_Item_DPT db 0 ; statue
code:7DCF db 0
code:7DD0 dw 0CDC1h
code:7DD2 db 0Fh
code:7DD3 db 0FEh ; ?
code:7DD4 dw 0FFFFh
code:7DD6 dd 0EE838Dh
code:7DDA dd 3BB47F9h
code:7DDE T_Item_DPT db 10h dup(0)
code:7DEE F_Item_DPT db 10h dup(0)
code:7DFE MBR_Flag db 55h ; U
code:7DFF db 0AAh ; ?
code:7DFF code ends
code:7DFF end start
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课