printf

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
frank

printf

Post 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?
crazybuddha

Re:printf

Post 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.
frank

Re:printf

Post 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
frank

Re:printf

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