printString function not printing strings!

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.
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

printString function not printing strings!

Post 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! :)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: printString function not printing strings!

Post 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.
Every good solution is obvious once you've found it.
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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..
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: printString function not printing strings!

Post 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.
If something looks overcomplicated, most likely it is.
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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 :(.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: printString function not printing strings!

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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?
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: printString function not printing strings!

Post 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
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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 :).
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: printString function not printing strings!

Post 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
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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 :).
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: printString function not printing strings!

Post 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
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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 :).
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: printString function not printing strings!

Post 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*...
Every good solution is obvious once you've found it.
Benjamin1996
Member
Member
Posts: 78
Joined: Sat Apr 10, 2010 7:00 am
Location: Denmark

Re: printString function not printing strings!

Post 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).
Post Reply