unable to pass arguments to putch()

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm
unable to pass arguments to putch()

Post by combate » Tue Oct 07, 2008 10:38 pm

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
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Tue Oct 07, 2008 11:35 pm

What compiler are you using? I have seen this problem more prominent in GCC and DJGPP so I want to make sure.

combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm

Post by combate » Wed Oct 08, 2008 12:40 am

im using gcc version 4.3.2, and yes its with djgpp.
is there a way to fix it?
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Wed Oct 08, 2008 12:52 am

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.

combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm

Post by combate » Wed Oct 08, 2008 1:24 am

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?
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Wed Oct 08, 2008 1:52 am

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.

combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm

Post by combate » Wed Oct 08, 2008 6:00 pm

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
combate

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Post by Mike » Wed Oct 08, 2008 11:52 pm

Can you please describe how it does not work?

combate
Posts:7
Joined:Tue Oct 07, 2008 9:59 pm

Post by combate » Thu Oct 09, 2008 12:31 am

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?
combate

Post Reply