Page 1 of 2
printString function not printing strings!
Posted: Mon Jun 28, 2010 2:51 am
by Benjamin1996
Hi guys!
I have a problem that's seriously starting to get on my nerves. For some reason I can't get my printString(char* message) function working. And by working I mean it doesn't print out anything, what so ever. First I tried with my own printString(char* message) function, but I then thought that I had just done something wrong. Then I instead decided to c+p a function from a tutorial, yet, no reactions from VMWare player. My first consideration was that the memory map might look different on my MacBook than on a PC. But I scratched that idea as I can easily clear the screen by writing to 0xb8000.
Here's some links to pastebin.com where I have uploaded the code:
main.c:
http://pastebin.com/gi7CvS8Y
video.c:
http://pastebin.com/8X2MjiAH
video.h:
http://pastebin.com/9BVBHBys
And finally here's compile.bat:
Code: Select all
@echo off
"C:\Mingw\bin\gcc.exe" -ffreestanding -c main.c -o main.o
"C:\Mingw\bin\gcc.exe" -c video.c -o video.o
"C:\Mingw\bin\gcc.exe" -c hal.c -o hal.o
ld -e _kernelEntry -Map memorymap.map -Ttext 0x1000 -o kernel.o main.o video.o hal.o
objcopy -O binary kernel.o kernel.bin
makeboot cyborgosx.img "C:\Users\Benjamin\Desktop\CyborgOSX\output\bootloader.bin" kernel.bin
copy "C:\Users\Benjamin\Desktop\CyborgOSX\core\*.img" "C:\Users\Benjamin\Desktop\CyborgOSX\core\src\*.img"
del *.img
"C:\Users\Benjamin\Downloads\cdrtools-latest\mkisofs.exe" -o cyborgosx.iso -A CyborgOSX -b cyborgosx.img src
copy "C:\Users\Benjamin\Desktop\CyborgOSX\core\*.o" "C:\Users\Benjamin\Desktop\CyborgOSX\output\*.o"
copy "C:\Users\Benjamin\Desktop\CyborgOSX\core\*.bin" "C:\Users\Benjamin\Desktop\CyborgOSX\output\*.bin"
copy "C:\Users\Benjamin\Desktop\CyborgOSX\core\*.iso" "C:\Users\Benjamin\Desktop\CyborgOSX\output\*.iso"
del *.o
del *.bin
del *.iso
pause
And in VMWare player, the screen is cleared with cyan background, magenta text, and the cursor is reset to 0,0. But no string is displayed, what so ever.
I would really like some help!
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 6:10 am
by Solar
Check if your kernel binary actually contains the string you are trying to print. If it doesn't, you need a linker script that links .rodata into the kernel binary.
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 7:37 am
by Benjamin1996
Solar wrote:Check if your kernel binary actually contains the string you are trying to print. If it doesn't, you need a linker script that links .rodata into the kernel binary.
Both kernel.bin and cyborgosx.iso contains the "Welcome to CyborgOSX!" string..
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 10:39 am
by Velko
Is offset calculated correctly? Try to print without adding offset to videoMemory.
If this works, there's probably something wrong with your in() function.
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 11:03 am
by Benjamin1996
Velko wrote:Is offset calculated correctly? Try to print without adding offset to videoMemory.
If this works, there's probably something wrong with your in() function.
Nope. I commented out "videoMemory += offset * 2;", yet, nothing happens
.
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 2:51 pm
by neon
char* videoMemory = (char*)0xb8000;
This should be unsigned.
If you verified the string is in the binary; verify that the address passed to the routine actually points to the correct offset in the binary. Also, make sure a valid stack is set up.
Re: printString function not printing strings!
Posted: Mon Jun 28, 2010 3:05 pm
by Benjamin1996
neon wrote:char* videoMemory = (char*)0xb8000;
This should be unsigned.
If you verified the string is in the binary; verify that the address passed to the routine actually points to the correct offset in the binary. Also, make sure a valid stack is set up.
How, exactly, would I find out if the addresses match, and if the stack is valid?
Re: printString function not printing strings!
Posted: Tue Jun 29, 2010 4:06 am
by jal
Benjamin1996 wrote:How, exactly, would I find out if the addresses match, and if the stack is valid?
On a different note, do you have a working printChar function or the like? If so, try making a printString function that uses printChar. Also, try a sequence of printChar-s to see whether that works. If it does, it is likely a linking problem.
JAL
Re: printString function not printing strings!
Posted: Tue Jun 29, 2010 7:49 am
by Benjamin1996
jal wrote:Benjamin1996 wrote:How, exactly, would I find out if the addresses match, and if the stack is valid?
On a different note, do you have a working printChar function or the like? If so, try making a printString function that uses printChar. Also, try a sequence of printChar-s to see whether that works. If it does, it is likely a linking problem.
JAL
I think it's a linking problem then, because adding
Code: Select all
*videoMemory = 'A';
videoMemory++;
*videoMemory = 0x0035;
videoMemory++;
to the "kernelEntry()" function in main.c, does print out an A in the upper left-most corner of the screen
.
Re: printString function not printing strings!
Posted: Tue Jun 29, 2010 1:11 pm
by jal
Benjamin1996 wrote:I think it's a linking problem then, because adding
Code: Select all
*videoMemory = 'A';
videoMemory++;
*videoMemory = 0x0035;
videoMemory++;
to the "kernelEntry()" function in main.c, does print out an A in the upper left-most corner of the screen :).
It could of course still be a bug in the printString routine. Try something like this:
Code: Select all
char someString[] = "Hello world";
for (int i = 0; someString[i] != 0; i++)
{
videoMemory[i*2] = someString[i];
videoMemory[i*2+1] = 0x35; // or whatever you like
}
If this doesn't work, it is definitely a linking problem.
JAL
Re: printString function not printing strings!
Posted: Tue Jun 29, 2010 2:08 pm
by Benjamin1996
jal wrote:Benjamin1996 wrote:I think it's a linking problem then, because adding
Code: Select all
*videoMemory = 'A';
videoMemory++;
*videoMemory = 0x0035;
videoMemory++;
to the "kernelEntry()" function in main.c, does print out an A in the upper left-most corner of the screen
.
It could of course still be a bug in the printString routine. Try something like this:
Code: Select all
char someString[] = "Hello world";
for (int i = 0; someString[i] != 0; i++)
{
videoMemory[i*2] = someString[i];
videoMemory[i*2+1] = 0x35; // or whatever you like
}
If this doesn't work, it is definitely a linking problem.
JAL
I tried to replace my while loop with your for loop, but still no effect, so it's probably a linking problem.. so far, so good
.
Re: printString function not printing strings!
Posted: Wed Jun 30, 2010 12:25 am
by jal
Benjamin1996 wrote:I tried to replace my while loop with your for loop, but still no effect, so it's probably a linking problem.. so far, so good :).
Indeed. Linking problems should not be too hard to solve (although I have unfortunately no experience with mingw or Windows development).
JAL
Re: printString function not printing strings!
Posted: Wed Jun 30, 2010 5:13 am
by Benjamin1996
Hmm.. I just tried to add the following directly into my kernelEntry function, but still nothing is displayed:
Code: Select all
unsigned char* videoMemory = (unsigned char*)0xb8000;
char welcome[] = {"Welcome to CyborgOSX!"};
int i = 0;
while(welcome[i] != 0){
*videoMemory = welcome[i++];
videoMemory++;
*videoMemory = 0x0009;
videoMemory++;
}
I don't know if this is of any help, but at least you know now
.
Re: printString function not printing strings!
Posted: Wed Jun 30, 2010 6:03 am
by Solar
jal wrote:Linking problems should not be too hard to solve (although I have unfortunately no experience with mingw or Windows development).
*cough*crosscompiler*cough*...
Re: printString function not printing strings!
Posted: Wed Jun 30, 2010 7:10 am
by Benjamin1996
I just remembered something about having to add the -i option to ld.exe in the line where I link all the kernel files into kernel.o. However, doing this causes the OS to triple fault trying to jump to 0x0008:0x01000. This might not be helpful at all, if so, sorry about that. - It was just something that came to my mind (also, I've got no clue what the -i option does, what so ever).