1

I'm currently working on a basic OS for a university assignment. I am working in x86 assembly language. I seem to have an issue with switching to the second stage of my boot-loader, resulting in the error above when I try to run the application in Bochs. From my testing, I think that the error is a result of the application not reading the program from memory properly, either due to a mistake in the first stage of my boot loader or something being wrong in the makefile. I will include both of these below:

First Stage of bootloader:

BITS 16

ORG 7C00h
jmp     Real_Mode_Start 

%include "functions_16.asm"

Read_Failed:
  mov       si, boot_error
  call Console_WriteLine_16
  ret

Real_Mode_Start:
  cli                                   
  xor   ax, ax                       
  mov   ss, ax
  mov   sp, 4000h

  mov   ds, ax                      

  mov   si, boot_message            
  call  Console_WriteLine_16

  mov   al, 5                       
  mov       bx, 9000h                   
  mov       ch, 0                       
  mov       dh, 0                       
  mov       dl, 0 
  mov       cl, 2                       
  int       13h
  cmp       al, 5                       
  jne       Read_Failed

  jmp   9000h

  hlt                                   


; Data
boot_message:   db  'MacOS Remastered' , 0
boot_error:     db  'Boot Failed' , 0

times 510 - ($ - $$) db 0

dw 0AA55h

Makefile:

.DEFAULT_GOAL:=all
Imgname=MacRemastered
.SUFFIXES: .iso .img .bin .asm

%.bin: %.asm
nasm -w+all -f bin -o $@ $<

boot.bin: boot.asm functions_16.asm 
boot2.bin: boot.asm functions_16.asm

$(Imgname).iso: boot.bin boot2.bin
cp floppy_image/$(Imgname).img $(Imgname).img
dd status=noxfer conv=notrunc if=boot.bin of=$(Imgname).img
dd status=noxfer conv=notrunc seek=1 if=boot2.bin of=$(Imgname).img
rm -rf cdiso
mkdir cdiso
cp $(Imgname).img cdiso/$(Imgname).img
mkisofs -o $(Imgname).iso -b $(Imgname).img cdiso/  

all: $(Imgname).iso

clean:
rm -f boot.bin
rm -f boot2.bin
rm -f $(Imgname).img
rm -f $(Imgname).iso
rm -rf cdiso

Any help would be appreciated.

3
  • Would you mind giving us a hint as to which line it is reporting the error on? The bootsector that you have posted looks fine. It could very well be in the subsequent code you're loading. Commented Oct 4, 2016 at 23:34
  • Awesome, setting ah to 2 fixed it. I haven't even touched the mov dl, 0 part yet but will have a look at that next. Commented Oct 5, 2016 at 11:16
  • I can't give you +rep for some reason Commented Oct 5, 2016 at 11:16

1 Answer 1

1

You should review the docs for Int 13h/ah=2h. Ralf Brown's Interrupt guide is the bible of DOS and BIOS interrupts. The guide says this:

DISK - READ SECTOR(S) INTO MEMORY

AH = 02h
AL = number of sectors to read (must be nonzero)
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
DL = drive number (bit 7 set for hard disk)
ES:BX -> data buffer

Return:

CF set on error
if AH = 11h (corrected ECC error), AL = burst length
CF clear if successful
AH = status (see #00234)
AL = number of sectors transferred (only valid if CF set for some BIOSes)

Most issues are related to your disk read:

  • You should set ES to 0 as the buffer is an address specified by ES:BX.
  • Don't set DL to zero. The BIOS will set DL to the boot drive before transferring to your code.
  • You didn't set AH to 2 which tells Int 13h that you want to do a disk read.
  • Rather than cmp al, 5 jne Read_Failed to test for disk error you can check the Carry Flag(CF). Replace both those lines with a simple jc Read_Failed right after Int 13h

I also recommend using the BOCHS debugger for 16-bit real mode debugging. When the BOCHS debugger starts set a breakpoint at 0x7c00 with the command b 0x7c00 then use the command c to continue. That should start the BOCHS startup and should break at the beginning of the boot sector. Basic commands:

  • help for a list of commands
  • n (next)
  • s (step)
  • c will continue until next break point.
  • b address breaks on an address. ie: b 0x7c00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.