Page 1 of 1

unable to pass arguments to putch()

Posted: Tue Oct 07, 2008 10:38 pm
by combate
I have encountered a problem after having managed to load the kernel from the bootloader.

Now I am trying to write on the screen, however when i call the function puts() does not pass the string.

I have no idea of why does not work, someone can have a look and help me find the problem

this is my kmain.c

Code: Select all

void kmain(void)
{
	iniciarVideo();

	puts("hello");

	for (;;);
}
this is my video.c

Code: Select all

void puts(char *str)
{
     int i;
   
     if(!str)
	     return;

    for (i = 0; i < strlen(str) ; i++)
          putch(str[i]);
     
}
the function above does not work, however when I try with the function below, print fine

Code: Select all

void puts(char *str)
{
     int i;
     char bla[] = "HELLO WORLD";

     for (i = 0; i < strlen(bla) ; i++)
          putch(bla[i]);       
} 
I can send the entire code if needed, thanks

Posted: Tue Oct 07, 2008 11:35 pm
by Mike
What compiler are you using? I have seen this problem more prominent in GCC and DJGPP so I want to make sure.

Posted: Wed Oct 08, 2008 12:40 am
by combate
im using gcc version 4.3.2, and yes its with djgpp.
is there a way to fix it?

Posted: Wed Oct 08, 2008 12:52 am
by Mike
Do you use a linker script? If so, can you please post it?

This error is most common when the read only data section (.rodata) is not defined in the linker script.

Posted: Wed Oct 08, 2008 1:24 am
by combate
im not using any linker script, im using this to link.

Code: Select all

ld --oformat binary -Ttext 0x10000
maybe thats the problem, its really necessary to use a linker script?

Posted: Wed Oct 08, 2008 1:52 am
by Mike
im not using any linker script, im using this to link.

Code: Select all

ld --oformat binary -Ttext 0x10000
maybe thats the problem, its really necessary to use a linker script?
Yes, that may be the problem.

If you want, try this script from my old system (A little modified). You can add C style comments:

Code: Select all

SECTIONS 
{
    .data : 
    { 
        data = .; _data = .; __data = .; 
        *(.data*) 
    } 

    .rodata :
    {
	    rodata = .; _rodata = .; __rodata = .;
       *(.rodata*)
    }

    .bss : 
    { 
        bss = .; _bss = .; __bss = .; 
        *(.bss*) 
    } 

    end = .; _end = .; __end = .; 
}
Add -map MapFile.ld when executing LD to specify the linker script to use. For example:

ld --oformat binary -Ttext 0x10000 -map mapFile.ld

Please post any errors if any.

Posted: Wed Oct 08, 2008 6:00 pm
by combate
it doesn't work either. i tried with

Code: Select all

ld --oformat binary -Ttext 0x10000 -T mapFile.ld 
since the -map, doesn't work. any other ideas?

this is my kinit.asm

Code: Select all

[BITS 32]

GLOBAL start
start:
	extern _kmain
	call _kmain
	cli
	hlt

Posted: Wed Oct 08, 2008 11:52 pm
by Mike
Can you please describe how it does not work?

Posted: Thu Oct 09, 2008 12:31 am
by combate
when i try with -map this is the error that appear.

Code: Select all

ld --oformat binary -Ttext 0x10000 -map linker.ld -o KERNEL.SYS kinit.o kmain.o
video.o klib\opmem.o klib\string.o klib\ports.o
e:\djgpp\bin/ld.exe: unrecognised emulation mode: ap
Supported emulations: i386go32
make.exe: *** [KERNEL] Error 1
it only link if i use the -T linker.ld instead of -map linker.ld.


im using the bootloader from the OS Development Series from your tutorials.

when i jump to kernel from stage2.asm i don't setup any kind of stack,as shown in kinit.asm.
can that be the problem?