Printing and rebooting

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
Who

Printing and rebooting

Post by Who »

I got a problem. Tried some source from one of the tutorials; writing a kernel in C. Well I did, and I wrote the print(..) function.. the problem is that if I make a program like:
const char *var;
int main() {
    print(var);
}
const char *var = "welcome to my OS";
it works great.. but if I get rid of the variables and just write something like:
int main() {
print("Hello and welcome");
}
it doesnt work, in fact the computer´s rebooting when running this..how come? Im using DJGPP
Gnome

RE:Printing and rebooting

Post by Gnome »

I'm almost certain this is a problem with how you're linking your kernel. I had a similar problem once when I had a messed up linker script. Are you using a linker script? This could be caused by not correctly putting all sections in the output.

Gnome.
Who

this is my linking

Post by Who »

ld -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
ld -i -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
makeboot a.img bootsect.bin kernel.bin

no script.. using DJGPP and nasm
nisse

RE:Printing and rebooting

Post by nisse »

I think your problem is that you must terminate your character string correctly.

like this:

print("Hello and welcome\0");

Hope this helps!!
GT

RE:Printing and rebooting

Post by GT »

Note, that just added a *second* null character, as the compiler already adds one to the end of any string constant.  The only way to NOT get a null at the end of a C string is to declare a variable with insufficent space for it, i.e.

char *x = "This string is null terminated."
char y[] = "So is this one."
char z[20] = "But this one isn't!!"

printf("Of course, this one is.");
Post Reply