Page 1 of 1

Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 2:18 am
by alphomega
Ok, I've read and read but I still can't solve this problem.

I read Bare Bones article, and have used the code as it is, unchanged, in bochs and qemu, with and without GRUB (using the qemu bootloader), on two different computers, but the 'A' Does not print.

Everything appears to be fine except I get wierd results when trying to put characters on the screen. I messed around a bit and put some loops in to put 65 into RAM at every second byte starting at 0xB8000. I get some interesting results. Nothing is displayed until I set my loop to go 309 bytes over 0xB8000. Then suddenly I get about 150 'A's printed sequentially, almost completing two lines. When I set the loop to go to 620, the printed amount of 'A's doubles. Changing the second byte to change colour yields unpredictable responses but usually just gives me a Orange on Blue 'A' for the values I put in.

I have read all the questions in the article and conformed to appropriate suggestions. I have also looked at the troubleshooting section of http://wiki.osdev.org/Printing_to_Screen, to no avail.

I simply do not know what to look at next. I feel it's highly unlikely it's a hardware problem because I've tried it on a 64bit and 32bit computer (Desktop and laptop respectively). As far as code goes it is copied directly from the article, unchanged in anyway.

The troubleshooting section of the printing to screen article mentions having to set the screen up for 80x25 video mode while in real mode, so I figured GRUB or the qemu bootloader would do this for me.

Any advice would be really appreciated.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 4:09 am
by Artlav
So, if you manually write 0x44 0x07 0x69 0x07 to first dword at 0xB8000, nothing will appear, or something wrong will appear?

Neither is it quite clear which code have you used, i assume C bare bones tutorial.

How do you determine that "Everything appears to be fine"?

Do you mean "I messed around a bit and put some loops in to put 65 into RAM at every second byte starting at 0xB8000." exactly as you wrote it? Because if you do, you didn't read the tutorial with enough attention.

Have you tried debugging it, in Bochs or something similar?

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 4:10 am
by montrom
Here is how you should approach this. I don't know all the details, but I suspect that the wiki code was never meant to be copied and pasted, but instead should be used as a reference for building your own code. Next, you should know how to debug your kernel effectively, you do not, because you didn't write it and you have made the mistake to rush right into compiling your first Fischer Price OS, and that is a road which inevitably always leads to failure. Thus, I warn you to slow down and to take the time to understand what it is you are truly doing and why. OK? Good luck.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 6:14 am
by alphomega
Artlav wrote:So, if you manually write 0x44 0x07 0x69 0x07 to first dword at 0xB8000, nothing will appear, or something wrong will appear?

Neither is it quite clear which code have you used, i assume C bare bones tutorial.

How do you determine that "Everything appears to be fine"?

Do you mean "I messed around a bit and put some loops in to put 65 into RAM at every second byte starting at 0xB8000." exactly as you wrote it? Because if you do, you didn't read the tutorial with enough attention.

Have you tried debugging it, in Bochs or something similar?
Just then I did exactly that, and nothing was printed:

Code: Select all

   unsigned char *videoram = (unsigned char *) 0xb8000;
   videoram[0] = 0x44;
   videoram[1] = 0x07;
   videoram[2] = 0x69;
   videoram[3] = 0x07;
Yes, it's the C bare bones tutorial.

It was vague, but by "everything appears fine" i mean, the bootloader gets found, and run and then the bootloader calls the kernel. And I can get stuff printed, it just doesn't do it the way I expect it to.

As far as the loop goes, it put decimal 65 into memory at 0xB8000, then 65 at 0xB8002, and 0xB8004 and so forth. I also did a bunch of variations on this loop including putting 65 into each byte and so forth.

I havn't tried debugging it in bochs/qemu. I will read up on that.

To montrom: Yes, I'm taking a step back and learning everything I can about x86 assembly right now. And I'll also try learn how to debug.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 1:59 pm
by montrom
Hi, I'm not just talking about learning how to program better in your language of choice. I meant that you should also step back and understand the hardware that you are supporting and the concepts that you are learning. It wont be easy to debug a program having thousands of lines of code (eventually) while having little to no understanding of how any of it works, because you didn't write 90% of it. And, do please learn how to debug. Debugging is about taking the logical steps to pinpoint an issue(s). Setting breakpoints and stepping through each line thereafter isn't the only form of debugging. You should be able to make fairly accurate assumptions about what might be causing your issue(s). Which of course, brings me back to my original point: You wont be very effective if you don't understand.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 5:14 pm
by falstart
Your problem is likely in the linker.ld. If you copy and paste it, it won't work; this is because it's producing an ELF file. I suggest that you should add OUTPUT_FORMAT("binary") near the top of the file.

Good luck with your kernel. In my opinion, you should start with a bootloader, not a full kernel. It's a great learning experience because it requires that you understand topics that you'll use again, for example memory management and assembly.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 5:59 pm
by alphomega
montrom wrote:Hi, I'm not just talking about learning how to program better in your language of choice. I meant that you should also step back and understand the hardware that you are supporting and the concepts that you are learning. It wont be easy to debug a program having thousands of lines of code (eventually) while having little to no understanding of how any of it works, because you didn't write 90% of it. And, do please learn how to debug. Debugging is about taking the logical steps to pinpoint an issue(s). Setting breakpoints and stepping through each line thereafter isn't the only form of debugging. You should be able to make fairly accurate assumptions about what might be causing your issue(s). Which of course, brings me back to my original point: You wont be very effective if you don't understand.
Yeah, I can appreciate what you're saying.
montrom wrote:Hi, I'm not just talking about learning how to program better in your language of choice. I meant that you should also step back and understand the hardware that you are supporting and the concepts that you are learning. It wont be easy to debug a program having thousands of lines of code (eventually) while having little to no understanding of how any of it works, because you didn't write 90% of it. And, do please learn how to debug. Debugging is about taking the logical steps to pinpoint an issue(s). Setting breakpoints and stepping through each line thereafter isn't the only form of debugging. You should be able to make fairly accurate assumptions about what might be causing your issue(s). Which of course, brings me back to my original point: You wont be very effective if you don't understand.
I thought GRUB would be fine loading an ELF kernel?

I did what you suggested, but now qemu says I get an error while loading an ELF kernel, so perhaps there is something there.

Yeah I've gone back to writing a bootloader, starting with just messing around with BIOS interrupts and learning real mode stuff.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon May 31, 2010 7:05 pm
by falstart
Sorry about that, for some reason between the time I read your first post and the time I clicked the "post reply" button I disregarded that you were using GRUB. GRUB should load ELF so you might have copied or linked it improperly, seeing as the the wiki is fairly credible. You just seemed to be having a similar problem to mine and that was how I fixed it. You might want to use objdump and readelf for debugging.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon Jul 05, 2010 6:35 am
by crazy2k
I'm having the same problem. bochs tells me I have what I want at 0xb800:

Code: Select all

<bochs:2> x 0xb800
[bochs]:
0x0000b800 <bogus+       0>:	0x41f241f2
That should print two A's, if I'm not mistaken. However, I see nothing.

It's strange. I've used bochs before without GRUB in the middle, and I was able to print stuff to the screen. Any ideas?

Thanks,

Re: Bare Bones Article - Problem with printing characters

Posted: Mon Jul 05, 2010 7:03 am
by Gigasoft
@crazy2k: That's the wrong address, it should be 0xb8000, and you have also reversed the high and low bytes. The low byte should be the character code and the high byte, the attribute.

Re: Bare Bones Article - Problem with printing characters

Posted: Mon Jul 05, 2010 7:11 am
by crazy2k
Gigasoft wrote:@crazy2k: That's the wrong address, it should be 0xb8000, and you have also reversed the high and low bytes. The low byte should be the character code and the high byte, the attribute.
Oh. Thanks :)

Now it works. I guess one shouldn't stay up this late programming.

Thanks again,