MichaelPetch wrote:
Can you show us the complete code for this boot sector? I took your code, commented out the `LEA` instruction (since you didn't have the error message in your file), and then padded the disk to 510 bytes and wrote 0xaa55 for the disk signature. When I booted it as a floppy image in VirtualBox it printed `2` on the screen.
Sure thing. Here is the rest:
Code:
BIOSSEG EQU 07C0H ; where the PC-BIOS reads the boot-sector.
BOOTSEG EQU 0AE0H ; the segment where the boot-sector is relocated.
LOADSEG EQU 0050H ; where the real-mode DOS system is read.
USE16
ORG 7C00H
JMP SHORT BEGLDR
NOP
BPBBEG:
DB "PEDOS1.0"
BYPRSC: DW 512
SCPRCL: DB 1
RVSCCN: DW 1
FATCNT: DB 2
RDECNT: DW 224
DW 2880
DB 0F0H
SCPRTR: DW 9
SCPRFT: DW 18
TRPRCY: DW 2
DD 0
DD 0
DW 0
DB 41
DD 0
DB " "
DB "FAT12 "
BPBEND:
;
; POSTBIOS: Ensure that all segment registers
; are set to known values.
;
; Copy boot-sector to higher memory.
;
BEGLDR:
MOV AX, BOOTSEG
MOV ES, AX
CLI ; clear maskable interrupts
MOV SS, AX
MOV SP, 1024
STI ; restore interrupts
PUSH WORD BIOSSEG
POP DS
XOR SI, SI ; DS:SI should be 07C0:0
XOR DI, DI ; ES:DI should be 0AE0:0
MOV CX, 256
CLD
REP MOVSW
; DS:SI = 07C0:0 ... 07C0:1FF
; ES:DI = 0AE0:0 ... 0AE0:1FF
SAVSRS:
PUSH ES ; We no longer need ES, so
POP DS ; DS now becomes 0AE0.
RSTCPU:
PUSH BOOTSEG
PUSH WORD DSKERR
RETF ; 0000:AE00+<FNDFLE>
;
; DISKERROR: Display and error message, and
; and await a system reset.
;
DSKERR:
LEA SI, [ERRMSG]
PRNSTR:
LODSB
OR AL, 0
JZ SHORT DSKHLT
MOV AH, 14
MOV BL, 0
JMP SHORT PRNSTR
DSKHLT:
XOR AX, AX ; ! 'Restart' the PC-BIOS. !
INT 22 ; 16H
INT 25 ; 19H
;
; FINDFILE: Search for the files 'IO.SYS'
; and 'RMDOS.SYS'.
;
; Read the Root Directory into memory:
;
FNDFLE:
MOV BX, 7
MOV AH, 14
MOV AL, '2'
INT 16
JMP SHORT $
MOV AX, 19
LEA BX, [DSKBUF] ; BX=7E00
MOV CX, 1
XOR DX, DX
ADC DX, 0
FNDSYS:
JNE DSKERR
FDNDOS:
JNE DSKERR
;
; READFILE: Partially read the file
; 'IO.SYS' into memory.
;
; Read the FAT into memory:
;
REDFLE:
NXTCLU:
CLUODD:
REDNXT:
JMP NXTCLU
; Transfer CPU execution to io.sys
;
RUNDOS:
PUSH CS
PUSH WORD LOADSEG
RETF
;
; REDSEC: Read the specified sectors into memory
; at logical address ES:BX.
;
; IN:
;
; DX:AX = head, track, sector value
; CX = sector count
;
REDSEC:
PUSHA
DIV WORD [SCPRTR]
MOV CX, DX
INC CX
XOR DX, DX
DIV WORD [TRPRCY]
MOV CH, AL
SHL AH, 6
OR CL, AH
MOV DH, DL
MOV DL, 0
MOV AX, 201H
INT 19 ; 13H
JNC SHORT NXTSEC
JMP DSKERR
NXTSEC:
POPA
DEC CX
JZ SHORT SR1RET
ADD BX, WORD [BYPRSC]
ADD AX, 1
ADC DX, 0
JMP SHORT REDSEC
SR1RET:
RET
; error message
ERRMSG: DB "Non-System disk or disk error... Replace and try again when ready."
DB 0
DOSFLE: DB "RMDOS SYS" ; The real-mode kernel component to PE-DOS.
SYSFLE: DB "IO SYS" ; I/O system.
TIMES 510 - ($ - $$) DB 0
DW 0AA55H ; End of Boot Sector.
DSKBUF:
;
; The FAT and Root-Dir is read exactly
; after the boot-sector.
;