Crashes when booting as CD image

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
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Crashes when booting as CD image

Post by neon »

Hey everyone!

I have a quick question... I am having a problem in my (kind of new) 2nd stage boot loader.

The problem relates to the BIOS INT 0x13 function 0x02 (READ SECTOR(S) INTO MEMORY).

If I boot it from a floppy image, it runs fine in both Bochs and Virtual PC (No errors nor crashes, runs my kernel fine too). However, if I create a CD image of it (with floppy emulation) and boot from it, it fails at my ReadSectors() int 13 bios interrupt call (It never seems to return from it).

All of my other ReadSectors() int 0x13 calls work (they load below the 1MB mark). This ReadSectors() int 0x13 call that is crashing was set up to load the file to 1MB and is the only one that fails. Can me loading at 1MB be the problem? If so, why would it work when booting form floppy but not CD?

Virtual PC just hangs and Bochs gives me this when booting from the CD image:

Code: Select all

00001280102p[CPU  ] >>PANIC<< prefetch: RIP > CS.limit
00001280102i[SYS  ] Last time is 1217637822
00001280102i[CPU  ] real mode
00001280102i[CPU  ] CS.d_b = 16 bit
00001280102i[CPU  ] SS.d_b = 16 bit
00001280102i[CPU  ] | EAX=04e40e2e  EBX=00000010  ECX=00300102  EDX=00000000
00001280102i[CPU  ] | ESP=0000ffcb  EBP=00000010  ESI=00000749  EDI=00000005
00001280102i[CPU  ] | IOPL=0 OV UP DI NG NZ AC PO NC
00001280102i[CPU  ] | SEG selector     base    limit G D
00001280102i[CPU  ] | SEG sltr(index|ti|rpl)     base    limit G D
00001280102i[CPU  ] |  DS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00001280102i[CPU  ] |  ES:ffff( 0000| 0|  0) 000ffff0 0000ffff 0 0
00001280102i[CPU  ] |  FS:07c0( 0000| 0|  0) 00007c00 0000ffff 0 0
00001280102i[CPU  ] |  GS:07c0( 0000| 0|  0) 00007c00 0000ffff 0 0
00001280102i[CPU  ] |  SS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00001280102i[CPU  ] |  CS:0eba( 0000| 0|  0) 0000eba0 0000ffff 0 0
00001280102i[CPU  ] | EIP=00010460 (00010460)
00001280102i[CPU  ] | CR0=0x60000010 CR1=0x00000000 CR2=0x00000000
00001280102i[CPU  ] | CR3=0x00000000 CR4=0x00000000
Please keep in mind that my code works fine with Bochs and VirtualPC when booting from a floppy image. This only seems to happen with CD images.

I will be more then happy to post any code if requested--I just don't quite know what I should post here.

ES:BX was set by me (0xffff:0x0010) = 0x100000 (1 MB). This is the buffer for the Bios interrupt handler to copy the sectors to.

Thanks for any suggestions :)
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: Crashes when booting as CD image

Post by Masterkiller »

neon wrote:The problem relates to the BIOS INT 0x13 function 0x02 (READ SECTOR(S) INTO MEMORY).
CD-ROM that does not emulate floppy or harddisk has different BIOS number than 0x80 and 0x00 between 0x81 and 0xFF. To load sectors from CD-ROM that does not emulate use AH=42h/INT 13h function (extended read). No installation check is required. If this BIOS extension is missing CD-ROM won't boot.
neon wrote:ES:BX was set by me (0xffff:0x0010) = 0x100000 (1 MB). This is the buffer for the Bios interrupt handler to copy the sectors to.
You cannot access to memory locations above 1MB this way. You must enable A20, switch to pmode, load the segments with new descriptors (the hidden part of them must contain memory descriptor allowing writing, reading and executing above one megabyte - best choise is all physical memory) and switch back to real mode. Without this way (also called switching to unreal mode) memory wraps and you actually access to 0x00000 instead 0x100000.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Crashes when booting as CD image

Post by AJ »

Masterkiller wrote: You cannot access to memory locations above 1MB this way. You must enable A20, switch to pmode, load the segments with new descriptors...
You can - up to 0x10FFEF if you enable gate A20, but it's not so advisable, because as soon as your kernel reaches FFEF bytes long you will get memory wrapping and all sorts of related problems. At this point, you have to use either PMode switches, Unreal Mode as you suggest or native PMode drivers.

Cheers,
Adam
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Crashes when booting as CD image

Post by bewing »

Loading above 1M is quite likely to be the problem. Even though the CD is using floppy emulation -- that does not mean that it is using the same driver code in the BIOS. Clearly the floppy driver code is better written than the CD driver code. You are stress-testing the BIOS with an edge case, here. And stress-testing BIOSes is usually a bad idea. They are not well written in general, and some of them will fail to perform properly under stress. And then you will have a bootloader that fails randomly on particular BIOSes -- which is the very last thing that you want a bootloader to do.

So, I'd suggest recoding that section to load into a buffer in normal low memory, and then rep movsd the data yourself into the high memory area. By just making this one change, you can find out if it was the problem in the first place, too (and I expect it is).
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Crashes when booting as CD image

Post by neon »

Masterkiller wrote:CD-ROM that does not emulate floppy or harddisk has different BIOS number than 0x80 and 0x00 between 0x81 and 0xFF. To load sectors from CD-ROM that does not emulate use AH=42h/INT 13h function (extended read). No installation check is required. If this BIOS extension is missing CD-ROM won't boot.
Thanks for that, except I'm not really planning on supporting CD-ROM booting without emulation yet... Although I just might look more into it.
bewing wrote:So, I'd suggest recoding that section to load into a buffer in normal low memory, and then rep movsd the data yourself into the high memory area. By just making this one change, you can find out if it was the problem in the first place, too (and I expect it is).
That's what I suspected I would have to do. I'll give it a try and let you know what happens :)

Thanks for all the suggestions so far! :D
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Crashes when booting as CD image

Post by neon »

That fixed it :D

Thanks again!
Post Reply