Re: printf() problem with ported NewLib
Posted: Tue Apr 30, 2013 8:35 am
This is for running an application. The kernel is written in Assembly which is why I'm struggling with the C / NewLib apps.
I'm pretty sure its a sbrk() issue... I think BSS is getting zero'd now.
crt0.c
test.c
app.ld
Compile:
The app runs with some of the output missing still. Is that valid for clearing BSS? Can the -fno-zero-initialized-in-bss flag be used instead?
I'm pretty sure its a sbrk() issue... I think BSS is getting zero'd now.
crt0.c
Code: Select all
extern int main(int argc, char **argv, char **environ);
extern char __bss_start, _end; // BSS should be the last think before _end
// XXX: environment
char *__env[1] = { 0 };
char **environ = __env;
_start()
{
char *i;
write(1, "trololo\n", 8);
// zero BSS
for(i = &__bss_start; i < &_end; i++)
{
*i = 0;
}
// XXX: get argc and argv
main(0,0, __env);
return 0;
}
Code: Select all
#include <stdio.h>
char tempstring[32];
int main()
{
printf("NewLib Test Application\n=======================\n");
printf("%s %d\n", "Output:", 1234);
printf("Enter some text: ");
fgets(tempstring, 32, stdin); // Get up to 32 chars from the keyboard
printf("You entered: '%s'", tempstring);
}
Code: Select all
OUTPUT_FORMAT("binary")
OUTPUT_ARCH("i386:x86-64")
ENTRY(main)
SECTIONS
{
. = 0x0000000000200000;
.text : { *(.text) }
.data : { *(.data .rodata) QUAD(ADDR(.bss)+SIZEOF(.bss)) }
__bss_start = .;
.bss : { *(.bss) }
end = .; _end = .; __end = .;
}
Code: Select all
gcc -I newlib-2.0.0/newlib/libc/include/ -c crt0.c -o crt0.o
gcc -I newlib-2.0.0/newlib/libc/include/ -c test.c -o test.o
ld -T app.ld -o test.app crt0.o test.o libc.a