Multi-boot/PE problems from hell....

OS Design, Theory, and Programming

Moderator: Moderators

Multi-boot/PE problems from hell....

Postby atc » Tue Feb 02, 2010 6:23 am

I hope I'm not asking you kind folks too many questions, and I hope it's not (for some reason) inappropriate to repost something from another forums. :D But for some reason I'm having serious problems, which I thoroughly describe in my post below. Apparently, I have much bigger fish to fry than working on DLL loading, lol. I'm hoping I can possibly get some help/ideas about this here. Well, here's the post:

Perhaps I celebrated too soon about my PE kernel and being "multiboot compliant". :lol:

I thought everything was ok, and as far as I could originally tell it was. Grub booted the kernel with ease, and my kernel obviously had control of the system. So, I played around a bit and got it to clear the screen, change colors, print a couple chars to the screen, etc, and figured it was time to move on to some real implementations of the groundwork. Wrong. I soon discovered my basic I/O implementation was giving horrible results. If, let's say, I tried to print char* teststring = "Hello from the kernel!"; I would get some random junk like:

sdf9087=!@^y654%$P .... (there was a LOT more, covering several lines, lol)

So I wonder what the heck is wrong. I check and recheck the implementations, and can find no problems with the code. I even copy and paste them into a Win32 console application to try out, and it worked fine; as if I was using a regular standard library. THEN I become aware that only local variables actually exist at runtime. If I have a global variable and try to print it via VGA, Virtual PC again prints random junk. Mind you, at the local level inside a function printing a single character at a time works perfectly somehow. On Sun's Virtual Box, nothing is printed at all if I try to print a global char*/string. It's like they disappear into an unknown (void *). :)

Then I got to thinking that maybe the way I've implemented the multi-boot code was bad, and causing data/resources to get chopped off during loading. So, I went to the only two online tutorials for this that I know exist:

http://ksrenevasan.blogspot.com/
http://forum.osdev.org/viewtopic.php?f=1&t=21260

Following those and all their settings to the letter, I'm still plagued with the same problem. Random junk is written to the video buffer when you try to print a string, and global variables (anything outside the functions) doesn't exist at all -- and may result in more random junk. For ksrenevasan's PE/multi-boot tutorial, I discovered that changing:

Code: Select all
...
                dd(0x0010200F)               ; load_end_addr
                dd(0x0010200F)               ; bss_end_addr
...

to:
                dd(0x001020FF)               ; load_end_addr
                dd(0x001020FF)               ; bss_end_addr


...Eliminates the issue with being totally unable to print an uncorrupted string. However, the same problem is still there in respect to only local variables working.

I'm using Grub 0.97 and the stage2_eltorito loader, if it is of any significance. I'm going to be trying to solve this, and thoroughly (re-)reading all of the information available for both the PE format and multi-boot specifications. But I'm hoping someone at least knows what could be the issue with this or slap a bit of sense into me. :) My guess is that there is just something obviously wrong with how my kernel gets loaded, and it's likely within that multiboot header somehow (it suggests to me that data/resources are getting chopped?). Alternatively, the way I've rigged VS to output the kernel could be flawed, but I really doubt this. The weird thing is the tutorial writers who I copied for validation suggest it works fine, and I doubt they would have posted it if it didn't. And yes, I've more than tripled check during my tests to be sure I set everything up like them (to validate whether or not their code would work). I'm just a bit baffled at this point. :lol:

Sorry for long question, but I wanted to be as clear as possible about my problem. Also, I kindly request that any suggestions to switch toolsets/formats/etc be withheld. The project is 100% 'academic' at this time, and the whole point (and requirement) is to use PE format and work in VS. :D

...

If anyone can point me in the right direction for solving this, it may save loads of time for me. If not, I still appreciate your time! :wink:
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm

Re: Multi-boot/PE problems from hell....

Postby Andyhhp » Tue Feb 02, 2010 4:03 pm

What are you using to compile/link your program. You are almost certainly not formatting the .data or .r(o)data section at compile/link time, rather than getting corruption at runtime.

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Multi-boot/PE problems from hell....

Postby atc » Tue Feb 02, 2010 5:22 pm

Yup. I just realized further increasing the aforementioned numbers gets rid of the local vs global variable problem! :shock: Even though it technically "works", that's a nasty thing to rely upon. I need to figure out the correct way to do it overall.
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm

Re: Multi-boot/PE problems from hell....

Postby Andyhhp » Tue Feb 02, 2010 5:26 pm

Once again, what compiler / linker are you using?

That is the most importent point.

It sounds like you might not be making a "flat" file but I cant suggest anything untill I know what compiler/linker you are using.

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Multi-boot/PE problems from hell....

Postby atc » Tue Feb 02, 2010 6:00 pm

Oh, sorry. Visual Studio Pro 2008. Should be exactly the same as VC++ Express compiler & linker afaik.
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm

Re: Multi-boot/PE problems from hell....

Postby Andyhhp » Tue Feb 02, 2010 6:05 pm

Look in your .vsproj file.

Under <Tool Name="VCLinkerTool" you should have:

BaseAddress="0x100000" //or whichever base address you choose
RandomizeBaseAddress="0"
FixedBaseAddress="1"

Thats the first thing to check.

~Andrew
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Multi-boot/PE problems from hell....

Postby atc » Tue Feb 02, 2010 6:26 pm

Straight from the VCProj file:


BaseAddress="0x100000"
RandomizedBaseAddress="0"
FixedBaseAddress="1"


It DOES boot and run without incident. But I'm quite convinced that something is wrong with the header itself and maybe the configuration (causing clipping/corruption of data resources on loading or even build-time). It doesn't even work if I follow those tutorials I linked to the letter. :lol: So something is obviously wrong there. And like I said, making those two parameters in the header larger actually solved the problem when using the method from the blog tutorial. But that's a poor thing to rely upon; a random guess/ugly "hack".

Really, I suppose that I need to get into some deeper information about the specification and get more intimate with the PE format. Then figure out how to properly make the header and build the kernel to deploy it. Another question I have now is whether or not "forcing" this PE to be multi-boot compliant is going to have any consequences/negative impacts I should be aware of. If there will be, maybe I could skirt around the issue by making a setup program in another multi-boot compliant format which then loads the kernel and executes it. Just not sure what I'll have to do to accomplish that or if it's truly necessary.

Sorry, mind is racing around wildly a bit. :) But you seem to have far more experience with this, so I'll sit back and listen to what you say before I run off on some wild assumptions or break anything. :D
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm

Re: Multi-boot/PE problems from hell....

Postby Andyhhp » Tue Feb 02, 2010 6:48 pm

can you post the code you used to make it multiboot complient?
Image
Andyhhp
Moderator
 
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1

Re: Multi-boot/PE problems from hell....

Postby atc » Tue Feb 02, 2010 7:46 pm

I certainly can, but it will be a big space hog. First, I tried some ideas of my own, which failed. Then I tried the *exact* code and settings from these two tutorials I linked earlier:

http://ksrenevasan.blogspot.com/
http://forum.osdev.org/viewtopic.php?f=1&t=21260

I think you'll get a better idea from those links, since they list all the code and describe the settings to the T. But if you want me to post my own, exact copies for some reason, just let me know. I'm positive each test on their code was copied perfectly to the letter, including the settings. I also had my brother look at it and he agreed it's an exact copy. :) Only difference is my messy comments and comment-outs of my own code. So hopefully those tutorial links will suffice. :lol:
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm

Re: Multi-boot/PE problems from hell....

Postby atc » Thu Feb 04, 2010 3:10 pm

Yiiippeeee! :D I got it! This was pretty darn tough, not because it involves complicated programming and implementations but because there are so many points of failure, lol. One tiny error in your compiler/linker options, one bit off, one incorrect field, etc and you are destined for either a nasty message from Grub about how inferior you mortal human are or triple-fault pwn4ge. So one must READ for many hours about the multiboot and PE specification, dump their binaries and test, test, test. It can drive you insane, no doubt. :lol:

I'll be around if anyone has questions about how to do it or needs information. Thanks for all of your generous help thus far, even though you guys were a bit late on this one, heheh! :)

Regards,
atc
 
Posts: 23
Joined: Sun Jan 24, 2010 2:20 pm


Return to Advanced OS Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron