如何解决使用“ masm bootloader.asm”生产bootloader.bin文件,错误“必须在段块中”
我想使用masm从bootloader.asm到bootloader.bin编译引导扇区代码。但这会引发错误“ 必须在分段块中”。如果不能,我们不能在引导加载程序代码中使用分段,那么错误“必须在分段块中”的解决方案是什么。
我正在使用以下命令来编译引导加载程序代码:
MASM myboot.asm
我的引导扇区代码如下:
JMP START
nop
bsOEM_NAME DB 'MSDOS5.0' ; 8 bytes
bsBYTES_PER_SECTOR DW ?
bsSECTORS_PER_CLUSTER DB ?
bsRESERVED_SECTORS DW ?
bsFAT_copIES DB ?
bsROOT_DIR_ENTRIES DW ?
bsTOTAL_disK_SECTORS DW ?
bsMEDIA_DESCRIPTOR DB ?
bsSECTORS_PER_FAT DW ?
bsSECTORS_PER_TRACK DW ?
bsSIDES DW ?
bsHIDDEN_SECTORS_HIGH DW ?
bsHIDDEN_SECTORS_LOW DW ?
bsTOTAL_NUM_SECTORS DD ?
bsPHYS_DRIVE_NUMBER_1 DB ?
bsPHYS_DRIVE_NUMBER_2 DB ?
bsBOOT_RECORD_SIG DB 29h
bsVOL_SERIAL_NUM DD 1F61A800h
bsVOLUME_LABEL DB 'NO NAME ' ; 11 bytes
bsFILE_SYstem_ID DB 'FAT16 ' ; 8 bytes
;disk Parameter Block
; The DPB is located in the ROM BIOS at the address pointed to
;by 0078h.
; The 11 bytes starting from START are overwritten at copY_DPB
;with the
; DPB (7C3E-7C48). This is what the area looks like *after*
;the copy
; at copY_DPB:
;
START CLI ; disable interrupts
XOR AX,AX ; AX=0000
MOV SS,AX ; SS=0000
MOV SP,7C00 ; SP grows in decrements
PUSH SS
POP ES ; ES=0000
MOV BX,0078 ; The address of the ROM
; BIOS disk table is 78h.
; (INT 18h). ROM routine
; copies this address during
; cold boot initialization.
LDS SI,[BX] ; SI points to ROMBIOS table
; The source for the copy
PUSH DS
PUSH SI
PUSH SS
PUSH BX
MOV DI,START ; Address of destination
MOV CX,000B ; Size of area to copy
; (disk parameters)
CLD ; Set direction flag to inc
REPZ ; Move 11 bytes from the
; disk parameter area to
; overlap with the start
; of the code at 7D3E
; (save space?)
MOVSB
PUSH ES
POP DS ; DS=0000
MOV BYTE PTR [DI-02],0F
; At this point,DI points
; to 7C49,one byte after
; the last thing copied.
; Destination operand is
; dpbHEAD_SETTLE_TIME.
MOV CX,bsSECTORS_PER_TRACK
MOV [DI-07],CL ; Destination operand is
; dpbSECTORS_PER_TRACK.
MOV [BX+02],AX ; Destination operand is
; dpbMOTOR_OFF_DELAY.
MOV WORD PTR [BX],START
STI ; The code at 7C6B installs
; the new Int 1E into the
; interrupt table at
; 0000:0078. At 7C68,AX is
; 0. START is the offset
; for the new INT 1E.
INT 13 ; Reset drives (AX=0000)
JB ERROR_IN_BOOT_1
XOR AX,AX
CMP bsTOTAL_disK_SECTORS,AX
JZ LOOP_1
MOV CX,bsTOTAL_disK_SECTORS
MOV bsTOTAL_NUM_SECTORS,CX
LOOP_1 MOV AL,bsFAT_copIES
MUL WORD PTR bsSECTORS_PER_FAT
ADD AX,bsHIDDEN_SECTORS_HIGH
ADC DX,bsHIDDEN_SECTORS_LOW
ADD AX,bsRESERVED_SECTORS
ADC DX,+00
MOV [7C50],AX
MOV [7C52],DX
MOV [7C49],AX
MOV [7C4B],DX
MOV AX,0020
MUL WORD PTR bsROOT_DIR_ENTRIES
MOV BX,bsBYTES_PER_SECTOR
ADD AX,BX
DEC AX
DIV BX
ADD [7C49],AX
ADC WORD PTR [7C4B],+00
MOV BX,0500 ; Buffer for root directory
MOV DX,[7C4B]
MOV AX,[7C49]
CALL CALculaTE
JB ERROR_IN_BOOT_1
MOV AL,01
CALL READ_SECTOR
JB ERROR_IN_BOOT_1 ;Error? Print message
; and reboot.
MOV DI,BX
MOV SI,OFFSET FILE_IO_SYS
REPZ
CMPSB
JNZ ERROR_IN_BOOT_1 ;First file in root
; dir is not IO.SYS?
; Print error.
LEA DI,[BX+20]
MOV CX,000B ; 11 characters in DOS
; filename.
REPZ
CMPSB ; Is second file in root
; MSDOS.SYS?
JZ LOOP_2 ; Yes? Then continue on.
ERROR_IN_BOOT_1 MOV SI,OFFSET NON_SYstem_disK
CALL WRITE_STRING
XOR AX,AX
INT 16
POP SI
POP DS
POP [SI]
POP [SI+02]
INT 19
ERROR_IN_BOOT_2 POP AX
POP AX
POP AX
JMP ERROR_IN_BOOT_1
LOOP_2 MOV AX,[BX+1A]
DEC AX
DEC AX
MOV BL,SECTORS_PER_CLUSTER
XOR BH,BH
MUL BX
ADD AX,[7C49]
ADC DX,[7C4B]
MOV BX,0700 ; DOS loading buffer
MOV CX,0003
LOOP_3 PUSH AX
PUSH DX
PUSH CX
CALL CALculaTE
JB ERROR_IN_BOOT_2
MOV AL,01
CALL READ_SECTOR
POP CX
POP DX
POP AX
JB ERROR_IN_BOOT_1
ADD AX,0001
ADC DX,+00
ADD BX,BYTES_PER_SEC
LOOP LOOP_3
MOV CH,MEDIA_DESCRIPTOR
MOV DL,PHYS_DRIVE_NUMBER_1
MOV BX,[7C49]
MOV AX,[7C4B]
JMP 0070:0000 ; Transfer to ROM BIOS
WRITE_STRING LODSB
OR AL,AL
JZ RETURN_FROM_2
MOV AH,0E
MOV BX,0007
INT 10
JMP WRITE_STRING
CALculaTE CMP DX,SECTORS_PER_TRACK
JNB RETURN_FROM_1
DIV WORD PTR SECTORS_PER_TRACK
INC DL
MOV [7C4F],DL
XOR DX,DX
DIV WORD PTR SIDES
MOV PHYS_DRIVE_NUMBER_2,DL
MOV [7C4D],AX
CLC
RET
RETURN_FROM_1 STC
RETURN_FROM_2 RET
READ_SECTOR MOV AH,02 ; 02h is ReadSector .
MOV DX,[7C4D] ; DH is head/side number.
; DL is drive number.
; (Bit 7 of DL set for HD)
MOV CL,06 ; CL is sector number.
SHL DH,CL ; Multiply DH (number of
; heads) by 6.
OR DH,[7C4F]
MOV CX,DX
XCHG CH,CL
MOV DL,bsPHYS_DRIVE_NUMBER_1
MOV DH,bsPHYS_DRIVE_NUMBER_2
INT 13 ; ReadSector
RET
NON_SYstem_disK DB 13,10
DB 'Non-System disk or disk error'
DB 13,10
DB 'Replace and press any key when ready'
DB 13,10,0
FILE_IO_SYS DB 'IO SYS'
FILE_MSDOS_SYS DB 'MSDOS SYS'
DB 0,55,AA
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。