Page 1 of 2
Will this work?
Posted: Sun Jun 20, 2010 7:36 am
by Benjamin1996
Hello fellow computer nerds!
Since I got my new Mac, I decided to reset the development of my OS.
But, as the Mac doesn't have a floppy disk drive (obviously
), I decided to do it on a CD/DVD instead
.
So I would like to know if my code will work if I transfer it to a CD and boot from the CD drive.
This is my bootstrap:
http://pastebin.com/QXrga4nB (I'm sorry that pastebin.com messed up the format)
This is the assemble.bat file in my "boot" folder:
Code: Select all
@echo off
nasm -f bin -o bootloader.bin bootloader.asm
copy "C:\Users\Benjamin\Desktop\Cyborg OS X\boot\bootloader.bin" "C:\Users\Benjamin\Desktop\Cyborg OS X\output\bootloader.bin"
del bootloader.bin
pause
And this is the compile.bat in my "core" folder:
Code: Select all
@echo off
"C:\Program Files\bin\gcc.exe" -ffreestanding -c main.c -o main.o
ld -i -e _kernelEntry -Ttext 0x1000 -o kernel.o main.o
objcopy -O binary kernel.o kernel.bin
makeboot cyborgosx.img "C:\Users\Benjamin\Desktop\Cyborg OS X\output\bootloader.bin" kernel.bin
copy "C:\Users\Benjamin\Desktop\Cyborg OS X\core\*.o" "C:\Users\Benjamin\Desktop\Cyborg OS X\output\*.o"
copy "C:\Users\Benjamin\Desktop\Cyborg OS X\core\*.bin" "C:\Users\Benjamin\Desktop\Cyborg OS X\output\*.bin"
copy "C:\Users\Benjamin\Desktop\Cyborg OS X\core\*.img" "C:\Users\Benjamin\Desktop\Cyborg OS X\output\*.img"
del *.o
del *.bin
del *.img
pause
Oh and by the way, I take the "cyborgosx.img" file and turns it into a *.iso file using MagicISO.
So, will this *.iso work, on a CD/DVD booted directly from the CD drive? - And by work I mean, will it enter the kernel.
(Which is just an entry point, that jumps into an infinite loop so far)
Re: Will this work?
Posted: Sun Jun 20, 2010 1:23 pm
by icecoder
I think it shouldn't work, because (according to this:
http://en.wikipedia.org/wiki/CD-ROM#CD_sector_contents ) the sector size is different, so you should first learn the structure of the filesystem your cd will be using, and then rewrite your code.. I never dealt with CDs, that's just what I thought while reading wikipedia.
Re: Will this work?
Posted: Sun Jun 20, 2010 1:31 pm
by Benjamin1996
icecoder wrote:I think it shouldn't work, because (according to this:
http://en.wikipedia.org/wiki/CD-ROM#CD_sector_contents ) the sector size is different, so you should first learn the structure of the filesystem your cd will be using, and then rewrite your code.. I never dealt with CDs, that's just what I thought while reading wikipedia.
Well, couldn't I just reformat the disk with the FAT12 file system
?
Re: Will this work?
Posted: Sun Jun 20, 2010 5:46 pm
by bewing
'Fraid not. The BIOS expects CDs/DVDs to have an ISO9660 filesystem on them to boot. Nothing else will work.
Anyway, it would be wisest for you to do your development in an emulator, rather than creating 3000 drink coasters that you only use once, if that. The emulator can continue to emulate your current boot method.
Re: Will this work?
Posted: Sun Jun 20, 2010 11:07 pm
by robos
It will work if you make an ISO that uses floppy emulation.
If you don't want to use floppy emulation you'll need to parse the ISO file system and load the second stage yourself indeed
You don't need to burn 3000 disks. This is what CD-RW / DVD-RW was invented for
It's what I've been using to test CD boot.
Mac's have very little ways of booting. Apparently they don't support USB or PXE boot, so the only real option is CD/DVD (or put a second harddisk in and keep updating that, the Mac will see it as "Windows")
On a side note I've found that on Mac's (at least on the firmware last year) you can't use int 16h with ah = 0 when no key has been pressed yet. It will hang and never return. You have to do int 16h with ah = 1 to check if a key is available first and looping if there's not any. A 'hlt' might be good to throw in for laptops (my macbook pro would get very loud with the fans if I did not).
Re: Will this work?
Posted: Sun Jun 20, 2010 11:39 pm
by quok
robos wrote:It will work if you make an ISO that uses floppy emulation.
If you don't want to use floppy emulation you'll need to parse the ISO file system and load the second stage yourself indeed
The problem with floppy and hard disk emulation is these days they are buggy. You're less likely to find BIOS bugs when using the no emulation mode supported by the El-Torito spec. The El-Torito spec allows you to load more than a single sector as well, and you can load it to some place other than 0x7C00. That being said, doing so will also increase your chances of running in to BIOS bugs. Parsing the ISO file system is pretty easy. 2048 bytes is more than enough room to parse the filesystem and load a second stage.
robos wrote:Mac's have very little ways of booting. Apparently they don't support USB or PXE boot, so the only real option is CD/DVD (or put a second harddisk in and keep updating that, the Mac will see it as "Windows")
On a side note I've found that on Mac's (at least on the firmware last year) you can't use int 16h with ah = 0 when no key has been pressed yet. It will hang and never return. You have to do int 16h with ah = 1 to check if a key is available first and looping if there's not any. A 'hlt' might be good to throw in for laptops (my macbook pro would get very loud with the fans if I did not).
Your Mac-fu is weak, young padawan. You can indeed boot from a USB disk on a Mac. You just have to know how to do it. Google can help you there. Since Macs are Macs (and use EFI for firmware), it's not as straight forward as it would be on a regular PC.
You are indeed correct about the Int 16h bugs on Apple hardware though. I ran in to it myself, and it turns out OpenBSD's bootloader has the same bug documented as well.
Re: Will this work?
Posted: Mon Jun 21, 2010 12:02 am
by robos
Personally I'm not going for emulation either, I just wanted to let the op know it's a possibility, at least to try out. I'd be surprised if it doesn't work since some stuff at least uses it (like Haiku anyboot, 2.88 MB floppy image emulation).
I haven't investigated the Mac USB stick boot much, but an earlier Google search gave me some results that weren't very encouraging. If you have any links handy please post them.
I guess firewire (harddisk) boot is an option on Mac too. Somehow I forgot about that even though I use it a lot myself
Re: Will this work?
Posted: Mon Jun 21, 2010 6:17 am
by Benjamin1996
Thanks a lot for all of the replies
.
So, according to your comments I guess my code will not work, if I boot this from a psychical CD, unless I make some changes to it?
If so, could someone please help me find some information on how to do it on a Mac?
But if I get a CD-RW, couldn't I just reformat the disk and keep transferring the data, insert a such CD in the drive, and then boot directly from the CD drive?
Re: Will this work?
Posted: Mon Jun 21, 2010 7:34 am
by Combuster
Easiest thing is to have genisoimage/mkisofs as part of your build script. You can feed it all the files you need and the bootsector you want. The output is even usable by all sane emulators.
Then for testing on real hardware you can just erase the CD-RW, then burn the image. But it will be a very slow testcycle (Floppies are like 10 times faster than a CD between build and test, and for USB/HD it becomes negligible compared to the time you'll lose on rebooting the machine - assuming your test box isn't your dev box)
Re: Will this work?
Posted: Mon Jun 21, 2010 9:42 am
by Benjamin1996
Combuster wrote:Easiest thing is to have genisoimage/mkisofs as part of your build script. You can feed it all the files you need and the bootsector you want. The output is even usable by all sane emulators.
Then for testing on real hardware you can just erase the CD-RW, then burn the image. But it will be a very slow testcycle (Floppies are like 10 times faster than a CD between build and test, and for USB/HD it becomes negligible compared to the time you'll lose on rebooting the machine - assuming your test box isn't your dev box)
So your actually saying that I can just download this program, build my files, and add them as input to this program, and an *.iso will come out, that I can just run in any emulator, or burn it directly onto this RW-CD, and boot from it, and it'll work?
Re: Will this work?
Posted: Mon Jun 21, 2010 9:46 am
by Combuster
Benjamin1996 wrote:So your actually saying that I can just download this program, build my files, and add them as input to this program, and an *.iso will come out, that I can just run in any emulator, or burn it directly onto this RW-CD, and boot from it, and it'll work?
It works as long as you don't screw up your code
Re: Will this work?
Posted: Mon Jun 21, 2010 10:02 am
by Benjamin1996
Combuster wrote:Benjamin1996 wrote:So your actually saying that I can just download this program, build my files, and add them as input to this program, and an *.iso will come out, that I can just run in any emulator, or burn it directly onto this RW-CD, and boot from it, and it'll work?
It works as long as you don't screw up your code
Well thats kinda self-explanatory, but thanks anyway!
But, is my code good to go?
Also, could you please show me the usage of this program? - And can it be downloaded on a PC? (Just asking for convenience)
Re: Will this work?
Posted: Mon Jun 21, 2010 11:02 am
by Combuster
Benjamin1996 wrote:But, is my code good to go?
Also, could you please show me the usage of this program? - And can it be downloaded on a PC? (Just asking for convenience
no,
yes,
yes.
And then I haven't even searched the wiki, which makes things even easier.
Re: Will this work?
Posted: Mon Jun 21, 2010 11:35 am
by Benjamin1996
Combuster wrote:Benjamin1996 wrote:But, is my code good to go?
Also, could you please show me the usage of this program? - And can it be downloaded on a PC? (Just asking for convenience
no,
yes,
yes.
And then I haven't even searched the wiki, which makes things even easier.
Thanks.. but thats a really big PDF.. do I need to read all of it, or just some chapters? (In that case: which ones?
)
Re: Will this work?
Posted: Mon Jun 21, 2010 1:40 pm
by Benjamin1996
Alright then.. I know this might be a lot to ask for.. BUT. The way I got it the El Torito thing is an extension to the ISO 9660 CD-ROM specification (<- correct me if I'm wrong). And what I pretty much need to do is (assuming that my computer has got this extension) to configure my code to be using this specification to allow the BIOS to find my bootimage.
So my (unfair) request is an example showing how to interpret this in terms of code, please
.
EDIT: Or maybe I'll be able to use floppy emulation for my *.iso file? (Like suggested above). Will I be able to use the Nero program to convert my *.img file produced by my compiler script to a floppy emulated *.iso file, if I choose this solution?