compile programs in standalone mode

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

compile programs in standalone mode

alemus
Hi,

int main()
{
  int i;
  short int *screen = (short int *) 0xB8000;
  char msg[]="Hello World";

  for(i=0; msg[i] != '\0'; *(screen++) = 0x1F00 | msg[i], ++i);
  for(;;);
  return 0;
}

 When i compiled i got a very big main.bin file more then 960MByte, so i
tried to change the char vector with only a char and it works fine. I
think the problem was the buffer overflow protector system that take the
.nodata segment in other address, or something like that... (readelf -S
main)

So how can i use the char vector in my programs and build them in standalone
mode?

int main()
{
  int i;
  short int *screen = (short int *) 0xB8000;
  char msg = 'H';

  *screen = 0x1F00 | msg;
  for(;;);
  return 0;
}

gcc -c main.c -o main.o -fno-stack-protector -ffreestand
ld main.o -e main -Ttext 0x1000 -o main
objcopy -R .comment -R .note -S -O binary main main.bin

Regards

-Alex-