Problems booting from Bochs.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Problems booting from Bochs.

Post by Benjamin1996 »

I have a problem booting from a psychical floppy disk using Bochs emulator: It reports there's no bootable device!
Which sounds strange to me because it works on real hardware..
The problem occurred after I linked my second stage bootloader together with my first stage bootloader.. (they're both in 16-bit Assembly).
I use NASM to output two ELF executables: boot.o & krnldr.o my first and second stage bootloaders, respectively.
I then link boot.o and krnldr.o using a linkerscript & ld from whom I also produce a memory map of the final product, bootloader.o.
Finally I make bootloader.o binary, using objcopy.
This is my build script:

Code: Select all

@echo off
nasm -f elf -o ./bin/boot/boot.o ./src/boot/boot.asm
nasm -f elf -o ./bin/boot/krnldr.o ./src/boot/krnldr.asm
"C:/Mingw/bin/ld.exe" -T link.ld -Map ./bin/debug/boot/bootloader.map -o ./bin/boot/bootloader.o ./bin/boot/boot.o ./bin/boot/krnldr.o
"C:/Mingw/bin/objcopy.exe" -O binary ./bin/boot/bootloader.o ./bin/boot/bootloader.bin
"C:\Users\Benjamin\Downloads\rawwritewin-0.7\rawwritewin.exe" --write --copies 1 --drive 0 ./bin/boot/bootloader.bin
echo Script done!
pause
This is my linkerscript:

Code: Select all

SECTIONS
{
   . = 0x7c00;
   .boot :
   {
      *(.boot)
   }
   
   . = 0x0500;
   .text :
   {
      *(.text .text.*)
   }
   
   .data :
   {
      *(.data .data.*)
   }
   
   .bss :
   {
      *(.bss .bss.*)
      *(COMMON)
   }
}
Start of boot.asm:

Code: Select all

[bits 16]
[section .boot]
boot:
Start of krnldr.asm:

Code: Select all

[bits 16]
[section .text]
main:
The memory dump also seems flawless to me:

Code: Select all

.boot           0x00007c00      0x200
 *(.boot)
 .boot          0x00007c00      0x200 ./bin/boot/boot.o
                0x00000500                . = 0x500

.text           0x00000500      0x200
 *(.text .text.*)
 .text          0x00000500       0x18 ./bin/boot/krnldr.o

.data
 *(.data .data.*)

.bss
 *(.bss .bss.*)
 *(COMMON)
LOAD ./bin/boot/boot.o
LOAD ./bin/boot/krnldr.o
OUTPUT(./bin/boot/bootloader.o pei-i386)
And as I mentioned above, the second stage bootloader IS executed on real hardware!

Best regards,
Benjamin.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

If your code boots properly on real hardware, but bochs does not recognize a boot device, there might be a problem with your bochs / boot device setup. Have you successfully booted other disks or disk images with bochs before? Are you sure that you correctly specified the boot device in your bochsrc file?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

XenOS wrote:If your code boots properly on real hardware, but bochs does not recognize a boot device, there might be a problem with your bochs / boot device setup. Have you successfully booted other disks or disk images with bochs before? Are you sure that you correctly specified the boot device in your bochsrc file?
Yep... it worked fine when I only had a single file, and I assembled it with 'nasm -f bin boot.asm -o boot.bin', and I haven't touched bochsrc.txt since..
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

This really looks a bit strange. Is there any additional information in bochs' log file? Usually bochs outputs a lot of information there if something fails. If you want even more information, you might try to enable debug output in your bochsrc file - this really gives you a lot of output, so the log file may become quite huge...
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

Well by looking through oslog.txt (no debug info), the only information that seems the least bit helpful is the CPU register dump after the '00014087699p[BIOS ] >>PANIC<< No bootable device.' line:

Code: Select all

00014087699i[CPU0 ] | SEG selector     base    limit G D
00014087699i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00014087699i[CPU0 ] |  CS:f000( 0004| 0|  0) 000f0000 0000ffff 0 0
00014087699i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00014087699i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00014087699i[CPU0 ] |  ES:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00014087699i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00014087699i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
Is CS meant not to be 0x7C00 even after it recognized my disk as 'unbootable'?
This is my Bochs configuration file:

Code: Select all

floppya: 1_44=A:, status=inserted
log:         oslog.log
panic:      action=ask
debug:     action=ignore
error:       action=report 
info:        action=report
I've also tested to see if it could boot if I specified 'bootloader.bin' instead of the A: drive in the configuration file, but nope, no luck...
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

The value of CS is correct, because the error message comes from the BIOS, so there is no jump to the boot sector at 07c0:0000.

You could try floppy_bootsig_check: disabled=1 to check whether your boot disk has a wrong boot signature after linking with the second stage, and debug: action=report to check what happens immediately before the panic.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

Oh! I've been so stupid! I didn't notice until now, but when I boot from real hardware, it seems that the first stage bootloader is skipped, because all it does is print the 'W', I told the second stage to print, to check the execution of it.
And it also prints the 'W' (nothing else!) in Bochs when I disable the boot-signature check!
And it seems to be doing a bunch of 8-bit writes to 0x03d4 and 0x03d5, before the panic, here's a chunk of the dump:
00014083797d[CPU0 ] interrupt(): vector = 10, TYPE = 4, EXT = 0
00014084416d[CLVGA] 8-bit write to 03d4 = 0e
00014084437d[CLVGA] 8-bit write to 03d5 = 06
00014084453d[CLVGA] 8-bit write to 03d4 = 0f
00014084472d[CLVGA] 8-bit write to 03d5 = 06
00014084582d[CPU0 ] interrupt(): vector = 10, TYPE = 4, EXT = 0
00014085201d[CLVGA] 8-bit write to 03d4 = 0e
00014085222d[CLVGA] 8-bit write to 03d5 = 06
00014085238d[CLVGA] 8-bit write to 03d4 = 0f
00014085257d[CLVGA] 8-bit write to 03d5 = 07
00014085367d[CPU0 ] interrupt(): vector = 10, TYPE = 4, EXT = 0
00014085986d[CLVGA] 8-bit write to 03d4 = 0e
00014086007d[CLVGA] 8-bit write to 03d5 = 06
00014086023d[CLVGA] 8-bit write to 03d4 = 0f
00014086042d[CLVGA] 8-bit write to 03d5 = 08
00014086152d[CPU0 ] interrupt(): vector = 10, TYPE = 4, EXT = 0
00014086771d[CLVGA] 8-bit write to 03d4 = 0e
00014086792d[CLVGA] 8-bit write to 03d5 = 06
00014086808d[CLVGA] 8-bit write to 03d4 = 0f
00014086827d[CLVGA] 8-bit write to 03d5 = 09
00014086937d[CPU0 ] interrupt(): vector = 10, TYPE = 4, EXT = 0
00014087556d[CLVGA] 8-bit write to 03d4 = 0e
00014087577d[CLVGA] 8-bit write to 03d5 = 06
00014087593d[CLVGA] 8-bit write to 03d4 = 0f
00014087612d[CLVGA] 8-bit write to 03d5 = 0a
00014087699p[BIOS ] >>PANIC<< No bootable device.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

These writes to 0x3d4 and 0x3d5 simply move the cursor on the screen, so that probably means that the BIOS is printing something on the screen. But this is not directly related to booting from the floppy.

Have you checked that the boot sector is correctly written to your bootloader.bin file? I'm not sure whether objcopy actually does what you expect. Have you tried linking directly to a flat binary using OUTPUT_FORMAT("binary") in your linker script?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

Hmm.. when I add 'OUTPUT_FORMAT("binary")' as the final line in link.ld, and remove the use of objcopy from my batch file, so it is as follows, I get this error: "C:/Mingw/bin/ld.exe: cannot perform PE operations on non PE output file './bin/boot/bootloader.bin'."
make.bat:

Code: Select all

@echo off
nasm -f elf -o ./bin/boot/boot.o ./src/boot/boot.asm
nasm -f elf -o ./bin/boot/krnldr.o ./src/boot/krnldr.asm
"C:/Mingw/bin/ld.exe" -T link.ld -Map ./bin/debug/boot/bootloader.map -o ./bin/boot/bootloader.bin ./bin/boot/boot.o ./bin/boot/krnldr.o
"C:\Users\Benjamin\Downloads\rawwritewin-0.7\rawwritewin.exe" --write --copies 1 --drive 0 ./bin/boot/bootloader.bin
echo Script done!
pause
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

This looks like a toolchain problem to me - are you using the ld that comes with MinGW? This is certainly not the best way to link ELF files created by NASM to get a binary kernel... The recommended (and, in my experience, best) way to do that is to use a cross compiler.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

Thanks a lot for the link, to the article about cross-compilers, very useful. I originally planned on developing my OS on Ubuntu 10.10, but it doesn't support floppy disk drives I think. When I put a disk in the drive, and try to open the drive, I get a prompt: 'No media in the drive'. Do you know the cause, because if you do I would be more than happy to get it fixed, so I don't have to use Windows, - it is driving me insane! :)
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Problems booting from Bochs.

Post by xenos »

I haven't used physical floppies for a while, but I would be very surprised if they were not supported by Ubuntu 10.10. Currently I'm using Ubuntu 9.10 on my laptop and 10.04 on some desktop computer, and I never stumbled across any unsupported media type.

Have you tried mounting a freshly formatted floppy with Ubuntu? Since Bochs says that your boot floppies do not have a valid boot signature, the boot sector data might be corrupted and Ubuntu refuses to mount it.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: Problems booting from Bochs.

Post by Benjamin1996 »

XenOS wrote:I haven't used physical floppies for a while, but I would be very surprised if they were not supported by Ubuntu 10.10. Currently I'm using Ubuntu 9.10 on my laptop and 10.04 on some desktop computer, and I never stumbled across any unsupported media type.

Have you tried mounting a freshly formatted floppy with Ubuntu? Since Bochs says that your boot floppies do not have a valid boot signature, the boot sector data might be corrupted and Ubuntu refuses to mount it.
Nope. I did a full format on Windows, booted back into Ubuntu, just to get the same message: No media in the drive.
I'll report back if I manage to fix.
EDIT: I fixed it by installing Ubuntu 7.10.
Post Reply