Page 1 of 1

printf

Posted: Thu Aug 15, 2002 8:44 am
by frank
the basic functions work now (putc,gotoxy)
but printf does not work...

Code: Select all


 printf("fffff");        <- that's how I call the printf function

Code: Select all

void printf(char * string)
{
 unsigned short *vidmem = (short*) 0xb8000;
  int i=0;
  if (string[0]=='f'){
   vidmem[i] = 0x1F66; 
  } 
}

it does print an f without the if statement, but does not with it.
So the first character is not f....
where did those characters go?

Re:printf

Posted: Thu Aug 15, 2002 9:58 am
by crazybuddha
You are probably expecting that the string is passed on the stack. It isn't.

We need to know more about your linking to give a more complete answer.

Re:printf

Posted: Thu Aug 15, 2002 11:40 am
by frank
> You are probably expecting that the string is passed on the stack. It isn't.
I understand, so how is it passed?


This is the compile line:

Code: Select all

gcc -O4 -c kern.c
ld -o kern -Ttext 0x0 -e 0x0 kern.o
objcopy -R .note -R .comment -S -O binary kern kern.bin
(I jump to the main in the kernel using asm("jmp main"); on 0x0 of the kernel)

this is how I've set up the stack:

Code: Select all

mov ax,0x10
mov ss,ax
mov esp,0xFFFF

Re:printf

Posted: Fri Aug 16, 2002 9:48 am
by frank
Got it working now ;D

the Ttext was wrong, since i've loaded it into 0x1000 it can't be 0x0 ;)

Code: Select all

gcc -O4 -c kern.c
ld -o kern -Ttext 0x1000 -e 0x0 kern.o
objcopy -R .note -R .comment -S -O binary kern kern.bin