2

Author Topic: Chameleon and Bochs  (Read 6943 times)

0 Members and 1 Guest are viewing this topic.

Firestryke31

  • Entrant
  • Posts: 7
Chameleon and Bochs
« on: August 26, 2009, 07:00:07 PM »
I'm writing my own hobby OS, and would like to use Chameleon 2 as the bootloader because it supports FAT32 natively. I do my OS development under Windows, so FAT32 is the most viable option for me.

What I've done is create a 512MB disk image for use in the Bochs emulator. Due to the way my disk image utility works, this image is not partitioned. I had to install Chameleon manually due to the fact that Leopard wouldn't mount the disk image. What I did was copy the relevant parts of the boot1f32 file (the first 3 bytes as well as everything from "BOOT     " to the BIOS 0x55 0xAA signature) to the formatted disk image's boot sector. I then mounted the image under Windows and copied the "Extras" folder and "boot" file to the mounted image. Finally, I unmounted the image and tried to boot it with Bochs. I got "boot1f32: init boot1f32: error." Looking at the Bochs log I see that boot1f32 is trying to access some sector outside of the disk, but of course the ever-useful error message doesn't tell me what sector it is.

Did I do something wrong in the installation procedure? Does Chameleon expect a partitioned disk?

Sorry for the wall o' text, and thanks for a great bootloader.

Kabyl

  • VoodooLabs
  • Posts: 158
Re: Chameleon and Bochs
« Reply #1 on: August 26, 2009, 08:07:15 PM »
You need to create a FAT32 partition, I'm not sure if it needs to be an EFI System partition, but it's probably what boot0 look for, so if that is the case, just use any mbr which loads a flagged partition, and install boot1f32 on that partition.

Firestryke31

  • Entrant
  • Posts: 7
Re: Chameleon and Bochs
« Reply #2 on: August 27, 2009, 12:37:49 AM »
I have no boot0, because the BIOS doesn't actually need it (all the BIOS on any computer cares about is whether the last 2 bytes of the first sector are 0x55 0xAA to show that the disk is bootable, which boot1f32 has). My question is whether boot1f32 expects there to be a GPT-style or MBR-style partition table at the first sector and gets confused when it finds itself instead. I'm guessing this is what's happening, but due to the way my disk image mounting tool works I can't partition the image like I'm thinking I need to.

/wishes there were free win32 software to do this...

Kabyl

  • VoodooLabs
  • Posts: 158
Re: Chameleon and Bochs
« Reply #3 on: August 27, 2009, 11:37:32 AM »
If you don't have a filesystem, how exactly do you expect it to read files like /boot and your /kernel ?


Firestryke31

  • Entrant
  • Posts: 7
Re: Chameleon and Bochs
« Reply #4 on: August 27, 2009, 05:44:59 PM »
I do have a file system. It's FAT32, like I said in my first post. A hard drive does not need to be partitioned to work properly, or even to boot. It's expected nowadays, but still not needed.

My disk image is not partitioned, the whole image is FAT32. On a real disk, even a hard drive with only one file system that takes up the "whole" disk still has an MBR (plus some) with a single partition that spans the rest of the disk.

I'm just going to write a utility that will let me manipulate partitioned disk images so that I can actually use this. Whee.

Kabyl

  • VoodooLabs
  • Posts: 158
Re: Chameleon and Bochs
« Reply #5 on: August 27, 2009, 06:54:29 PM »
OK, I get it now, maybe zef :P has an answer.

zef

  • Administrator
  • Posts: 265
Re: Chameleon and Bochs
« Reply #6 on: August 28, 2009, 10:24:37 PM »
boot1h/boot1f32 expects two arguments from a stage0 like booter (like boot0):

BIOS drive unit passed in DL register, and an MBR style partition entry pointer passed in DS:SI where only the partition's starting LBA offset will be used.

Btw i traced both boot0 and boot1h under bochs in the beginning :)
ASUS P8Z68-V PRO/GEN3 | i5-2500k | 16GB RAM | GTX560 | Keyboard | Mouse | Devilsound DAC

Firestryke31

  • Entrant
  • Posts: 7
Re: Chameleon and Bochs
« Reply #7 on: August 29, 2009, 03:18:50 AM »
The only problem with that that I can see is not all MBR binaries pass the partition table entry pointer in DS:SI. I know the FAT systems have the Hidden Sectors field in the BPB which is basically the LBA of the partition start, but IDK about other file systems. In all of the bootloaders I've written, the boot1f32 equivalent used that BPB field instead of the DS:SI pointer so that the same bootsector would work on both a partitioned disk and an unpartitioned image, so I guess I took that for granted.

I always gave up on writing my own bootloader because it was always so boring. That's why I am switching to Chameleon: It's already here and does what I want in a fantastic manner. All that's missing is the ability to remember the last OS booted.

Firestryke31

  • Entrant
  • Posts: 7
Re: Chameleon and Bochs
« Reply #8 on: August 31, 2009, 07:46:22 PM »
Sorry for the double post...

I downloaded the Chameleon 2 source and re-assembled the boot1f32 without the ds:si check (where it uses the Hidden Sector Count, or as it's called in the source gPartLBA) and after a touch of massaging the disk image it will now load and run /boot. Sort of. The problem is that for some reason it's now triple faulting. Here's the relevant part of the Bochs log:

Code: [Select]
00070343899e[CPU0 ] write_virtual_checks(): write beyond limit, r/w
00070343899e[CPU0 ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00070343899e[CPU0 ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00070343899i[CPU0 ] CPU is in protected mode (active)
00070343899i[CPU0 ] CS.d_b = 32 bit
00070343899i[CPU0 ] SS.d_b = 32 bit
00070343899i[CPU0 ] EFER   = 0x00000000
00070343899i[CPU0 ] | RAX=0000000000000000  RBX=0000000004200000
00070343899i[CPU0 ] | RCX=000000000000011c  RDX=0000000000000470
00070343899i[CPU0 ] | RSP=000000000008ed48  RBP=000000000008ed4c
00070343899i[CPU0 ] | RSI=00000000ffffffff  RDI=00000000ffffffff
00070343899i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00070343899i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00070343899i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00070343899i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00070343899i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00070343899i[CPU0 ] | SEG selector     base    limit G D
00070343899i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00070343899i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 0 1
00070343899i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00070343899i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00070343899i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00070343899i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00070343899i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00070343899i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00070343899i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00070343899i[CPU0 ] | RIP=0000000000038fbd (0000000000038fbd)
00070343899i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
00070343899i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00070343899i[CPU0 ] 0x0000000000038fbd>> rep stosd dword ptr es:[edi], eax : F3AB
00070343899e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting

Does /boot also expect a partitioned setup? I would guess so just from my quick glance through the source, but I didn't really look too hard.

madwolf

  • Entrant
  • Posts: 5
Re: Chameleon and Bochs
« Reply #9 on: September 11, 2009, 03:28:03 PM »
Maybe that's a stupid question but if you're writing your own OS what do you need an advanced stage2 bootloader for? Chameleon is a bit too much for the task... wouldn't it be easier to write your own bootloader (maybe based ona chameleon source)? It wouldn't be too complicated... as basically what you need is to load your kernel into memory and start executing it, am I right? and how about ext2fs? probably there is much more source code available than for managing fat32...

Firestryke31

  • Entrant
  • Posts: 7
Re: Chameleon and Bochs
« Reply #10 on: September 11, 2009, 06:37:07 PM »
I'm using FAT32 because I'm using Windows for my OS development. Windows can't write to ext2fs by default, so I decided to go with a well documented file system (MS has the specs available for download on their site for free). I wanted to use Chameleon because I want to write an OS, not a bootloader. Chameleon already does everything I want, is free, and I'm sure I could figure out how to get it to run my OS instead of OS X. Every bootloader I've written has gotten stuck at one point in development or another, because the bootloader needs to do more than load and run the kernel, it also needs to set up the execution environment (even those fancy quad-core 64-bit processors start out using only a single core in 16-bit mode) and I get stuck on how exactly I should go about doing that. By using an existing bootloader I can focus on what I want to do: writing an OS.