Page 1 of 1
Problems booting from Bochs.
Posted: Fri Oct 08, 2010 1:54 pm
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:
Start of krnldr.asm:
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.
Re: Problems booting from Bochs.
Posted: Fri Oct 08, 2010 2:33 pm
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?
Re: Problems booting from Bochs.
Posted: Fri Oct 08, 2010 2:36 pm
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..
Re: Problems booting from Bochs.
Posted: Sat Oct 09, 2010 1:43 am
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...
Re: Problems booting from Bochs.
Posted: Sat Oct 09, 2010 3:08 am
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...
Re: Problems booting from Bochs.
Posted: Sat Oct 09, 2010 8:44 am
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.
Re: Problems booting from Bochs.
Posted: Wed Oct 13, 2010 11:08 pm
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.
Re: Problems booting from Bochs.
Posted: Wed Oct 13, 2010 11:51 pm
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?
Re: Problems booting from Bochs.
Posted: Fri Oct 15, 2010 10:06 am
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
Re: Problems booting from Bochs.
Posted: Fri Oct 15, 2010 10:44 am
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.
Re: Problems booting from Bochs.
Posted: Fri Oct 15, 2010 11:07 am
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!
Re: Problems booting from Bochs.
Posted: Sat Oct 16, 2010 1:44 am
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.
Re: Problems booting from Bochs.
Posted: Sun Oct 17, 2010 1:03 pm
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.