MBR confusion - I'm too dumb to break a computers MBR

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
2dum2code
Posts: 8
Joined: Fri Jan 11, 2008 5:50 pm

MBR confusion - I'm too dumb to break a computers MBR

Post by 2dum2code »

Hello. I am an old demo hacker from the Amiga world. Since the 90's I've been focusing on web programming and whatever turns an easy dollar. Recently, I've become interested in the boot process on PC's. Several things are new to me:

- IA32 assembly
- GNU (AT & T) assembly syntax
- The PC BIOS
- The PC boot process
- and many more(tm)

Okay so here's my problem. I have installed bochs with the default DLX boot image, which appears to be a flat file. I have written boot-code using GNU as under the cygwin environment. I am successfully producing a 512 byte program. My intention here isn't to boot the disk, so I don't care that I'm wiping out the partition table.

I use dd to apply my bootblock to the hd image. I use hexdump to visually inspect the first sector, and it's my version.. I simply call ROM BASIC.. which should probably result in an error on most moderns PC's.

I start bochs. And yknow what it does? It loads linux!

LILO.. which no longer exists in the MBR, springs into action and loads linux.

Can someone make me feel a little less dumb about this? Maybe point me at some documentation? How does the boot process get past my useless MBR (which ends with "start: jmp start") and load LILO?

(thinks to self.. maybe the bochs bios attempts to boot the first active partition if ROM BASIC is called..)
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

This sounds like it has to be a problem with your bochs config file (bochsrc.txt).
It doesn't sound like it's trying to access your disk image at all.
Please make sure in the config file that the simulated primary master drive points at your disk image file, and that (a little lower down in the config file) that is says "boot: disk".

Other than that, I am quite certain that the bochs "bios" checks the 0xAA 0x55 signature bytes at the end of the MBR, before it will even try jumping to it. So make sure that you have those in there, or it will still never boot your disk image.

Something like:
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14

ata0-master: type=disk, mode=flat, path="c:c.img", cylinders=20, heads=16, spt=63
2dum2code
Posts: 8
Joined: Fri Jan 11, 2008 5:50 pm

Post by 2dum2code »

Well.. I'm getting the idea that I'm *not* being an idiot here.. but there is some complication that I am not aware of in my work environment which is allowing bochs to see the *backup* VLX image I currently have in my recycle bin.

To test that theory, I recycled the VLX image that I believe the system is using. I now have *no* VLX images anywhere on my system that I am aware of (other than in the recycling bin). Despite this, the bochs system boots fine! This may not be a problem with my code or procedure at all, but maybe related to some vista complication.

I am now in a position to investigate further on my own.

Thanks very much for your tips!.. I don't feel like an idiot anymore :)
2dum2code
Posts: 8
Joined: Fri Jan 11, 2008 5:50 pm

Post by 2dum2code »

This is a little off topic, but will very much help is someone has an answer. Under Windows Vista, is there an easy way for me to monitor what files bochs is opening? That would allow me to see why bochs is able to boot into a full OS despite there being no disk image on my harddrive that corresponds with the location in the config file.

Thanks a million.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Bochs creates a log file, usually called bochsout.txt, where it specifies every filename used during bootup. You can let bochs run a billion opcodes or so, then quit, then look in the log file for lines that contain "[HD ]" (without the quotes -- 3 spaces after HD). That won't answer your Vista question, but it will concretely specify every file bochs *thinks* it is opening. (I do not use Vista, so I cannot answer the Vista question.)
2dum2code
Posts: 8
Joined: Fri Jan 11, 2008 5:50 pm

Post by 2dum2code »

Well, it seems that vista does some screwy file name remapping if you use data in the "Program Files" directory. If I run bochs normally, it "sees" the freshly installed hd image. If I right click, and choose "run as administrator", it "sees" the version that cygwin "sees" when I run it as administrator.

Utterly confusing.

Thanks for the help :D

- Rich
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

2dum2code wrote:This is a little off topic, but will very much help is someone has an answer. Under Windows Vista, is there an easy way for me to monitor what files bochs is opening?
I use Process Explorer for stuff like that.
2dum2code wrote: Well, it seems that vista does some screwy file name remapping if you use data in the "Program Files" directory. If I run bochs normally, it "sees" the freshly installed hd image. If I right click, and choose "run as administrator", it "sees" the version that cygwin "sees" when I run it as administrator.
Yeah Vista does some weird directory mirroring to make sure that user programs don't write directly to the program files directory. User level writes will go to a "Program Files" directory inside of the users profile.
Post Reply