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
Printing and rebooting
RE:Printing and rebooting
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.
Gnome.
this is my linking
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
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
RE:Printing and rebooting
I think your problem is that you must terminate your character string correctly.
like this:
print("Hello and welcome\0");
Hope this helps!!
like this:
print("Hello and welcome\0");
Hope this helps!!
RE:Printing and rebooting
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.");
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.");