OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Oct 26, 2020 7:29 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: no-emul-boot in mkisofs
PostPosted: Fri Jan 16, 2009 7:12 am 
Offline

Joined: Fri Dec 26, 2008 8:16 am
Posts: 13
Welcome
I am writting bootloader,I have file(my bootloader) that weights 1kB. I want put this file on CD, so that this CD will be booted from my file. To do it I use mkisofs.There are two possibilites.My file's name is 'boot'
a) Extend my file ( 'boot') from 1kB to 1.44 mgb(put zeros at the end) and then
mkisofs -o bootablecd.iso -b boot directory
There is 'boot' in directory
b) I don't have to extend 'boot'
mkisofs -no-emul-boot -o bootablecd.iso -b boot directory

In theory both of these methods should run. But when I use second method, something does not work.
It means I run bootablecd.iso in bochs, and I get message that ' 0mb medium detected' but then nothing happens.
When I put bootablecd.iso on physical CD, and run it on my notebook I see black screen and nothing happens.
BUT when I run this physical bootable CD on my PC or on my dad's notebook, it works fine.

It is quite strange for me.
Does someone know what is happening?


Top
 Profile  
 
 Post subject: Re: no-emul-boot in mkisofs
PostPosted: Fri Jan 16, 2009 10:06 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
For the sake of discussion, can you define "works fine?" I take it the bootloader is supposed to output to screen or something. :) If you don't mind, posting the code would also be a great help.

Either method should work, but there's plenty of BIOS bugs around when it comes to booting El Torito CDs. I find it odd that the second method doesn't work in Bochs (at least, it's odd without seeing your code or otherwise having a better idea of how it is "broke"). Perhaps it's not too surprising that it doesn't work on your notebook if your notebook is older. Would you mind clarifying the specs on both notebooks you've tested the machine on? BIOS versions as well may help quite a bit.

Off the top of my head, here's several reasons for your boot code to not work. I'm listing the BIOS bugs I know of first because they're most likely the culprit:

* Several BIOSes have bugs when using int 13 function 41h (EDD extensions check) on CD/DVD/etc drives.
* Several BIOSes have bugs when the El Torito "boot sector" image is not a multiple of 2048 bytes.
* Several BIOSes will not correctly load the El Torito image to anything other than 0x7C00, although the spec allows you to specify the load address.
* Using int 13 function 48h (get drive parameters) reports garbage on several BIOSes when combined with CD booting.
* Same thing with int 13 function 4B01h.
* You're attemping to read more than 7F sectors at once with int 13 function 42h. That's a violation of the EDD 3.0 spec, but some BIOSes DO support reading more sectors at once.
* You're using the wrong drive number with int 13 functions.

You may also try your hand at writing an El Torito boot sector (keeping it to no more than 2048 bytes, and padded out to that if necessary) that scans the ISO9660 filesystem to locate stage 2 and load that. I've tried both methods and either one works fine on any machine I've tried it on.

Perhaps after you post some code, or a more detailed explanation, I can help you out some more.

Edit: Oops, you don't read sectors with int 13 func 41h. Fixed that. :)


Last edited by quok on Fri Jan 16, 2009 11:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: no-emul-boot in mkisofs
PostPosted: Fri Jan 16, 2009 11:22 am 
Offline

Joined: Fri Dec 26, 2008 8:16 am
Posts: 13
Thanks for your response. I appreciate that.
Let's begin:
'works fine' means that works like I want. My program works like that: I put CD with my program then I put new CD, for example UBuntu liveCD, then I press enter and then my program is responsible to execute this Ubuntu Live CD.
To do it I use function 42h of int 13h.
My notebook is Hp nx 7400 EY508ES (on this hardware program doesn't work).It was bought 2,5 years ago
My dad's notebook is some IBM. It was bought about 1 year ago.
PC is 6 years old.
I attach source code of loader.
It reads 17 sector of CD(boot record of el torito cd), read pointer to Booting Catalog, then I read first sector of Booting Catalog to memory. It will read offset of bootable image, at the end it reads bootable image to 7c00, and finally jmp to 7c00.
When I put this program on physical CD using method 1, it doesn't read 8800(begin of 17 sector) but it reads something diffrent something like F200. It is also quite amazing for me.

EDIT:
I see a little problem here. At first my bootloader was written to execute it from floppy.
It consists of two parts
a) boot.s it is bootable part (55aa in bytes 510-511) it is read by BIOS and then BIOS writes it to 7C00, this program reads second sector(loader.s) of floppy and then jmp to right address
b) loader.s it is program that boots CD

I compile these files and concat them. Finally I have one file ('boot')

When I create bootable, 'boot' is bootable image. When I made bootable CD using first method it knows that sectors are 512 b.
When I use no-emulation method there is some problem with size of sectors.
Is it possible ?


Attachments:
loader.s [2.64 KiB]
Downloaded 130 times
Top
 Profile  
 
 Post subject: Re: no-emul-boot in mkisofs
PostPosted: Fri Jan 16, 2009 1:16 pm 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
Well, I see a bunch of problems.

The first appears to be that you're assuming what the drive number is. Take for instance:
Code:
ExtRead:
   mov dl,159         ;CD
   push ecx
   mov ah,0x41        ;check extensions
   mov bx,0x55aa
   int 0x13
   jc ExtRead

   mov ax,msg_support
   call Print

   mov si,DAP
   mov ah,0x42   ;read
   int 0x13   

   ;jc ExtRead

   mov ax,msg_read_ok
   call Print
   pop ecx
ret



The BIOS tells you what the drive number is, or you can attempt to find it by probing, but it could potentially be different on every machine, especially if you're using a no-emulation El Torito boot image. Also, checking for the EDD extensions on a EL-Torito image is one of those possibly buggy things. The El Torito spec says that EDD support in the BIOS is optional, but in practice I've never come across a BIOS that didn't implement EDD if it also implemented El-Torito, and a quick search didn't come up with anything either. It's safe to assume that if you want to boot using a no-emulation El Torito image, EDD support is there.

You're also not handling errors correctly. If the drive number you pass to int 13 (via DL) is incorrect or the extensions aren't supported or there is any other error, int 13 returns with carry set, and puts an error code in AH. Your code, upon seeing the carry flag set, repeats the exact same test indefinitely. You also should test the return values to make sure they are valid. After performing a read, you're not actually testing anything and assuming it worked! There's also no need to test for EDD extensions repeatedly.

You're making a lot of potentially unsafe assumptions as far as the El Torito spec is concerned, as well. You don't verify the sector you read (sector 17) actually does contain the boot record, for instance.

There's a bunch of other problems I see, but that should get you pointed in the right direction.

As far as what you're seeing with sector sizes, when you use floppy emulation, the BIOS will translate sector sizes for you. You'll effectively be accessing a floppy drive using 512 byte sectors. The same goes for hard disk emulation. However, under "no emulation" your sector size will be 2048 bytes. The BIOS knows this and will read the correct sector for you, you don't have to tell it the sector size. If anywhere in your code you compute the sector to read by using the sector size, make sure you are using the correct sector size. :)


Top
 Profile  
 
 Post subject: Re: no-emul-boot in mkisofs
PostPosted: Fri Jan 16, 2009 1:34 pm 
Offline

Joined: Fri Dec 26, 2008 8:16 am
Posts: 13
I know that there are plenty of things in this program I have to correct, but actually I want it to work on my notebook.
This code is in testing phase that's why I check EDD extensions every time.

About size of sectors, 'boot' looks like that:

.....................}
.....................} 512 bytes
..............55aa}
----------------------
.....................}
.......loader.....} 512 bytes
.....................}

It is all in the same file

First 512 bytes
Code:

  mov ah,2
  mov al, 1   ;       number of sector u want to read (po 512 B)
  mov ch, 0   ;number of cylinder
  mov cl, 2   ;        number of sector  (first is bootsector of floppy)
  mov dh, 0   ;number of head

  mov bx, 9000h   
  mov es, bx
  xor bx, bx
  int 0x13
  jmp 0x9000:0x0000

When this was executed from floppy or floppy emulation it reads second sector of floppy(next 512 bytes).When it is on no-emulation CD
it reads 2048 bytes of next sector. Should I convert 'boot' to something like that? :

.....................}
.....................}
..............55aa}2048 bytes
.....................}
.....................}
----------------------
.....................}
.....................} 2048 bytes
......loader......}
.....................}
.....................}
In few words problem is that my bootloader does not jump from first to second part.
Thanks for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group