• 0

[C] LD Error. Need Help


Question

Okay, I can't get my OS to compile when I try to use ld.exe from the Dev-Cpp tools.

Instructions to comile are at the bottom. Want to see if it works for anyone else. LD gives me the error:

ks.o: file not reconized: File format not reconized.

kernel_start.asm:

[BITS 32]

[global start]
[extern _k_main]

start:
  call _k_main

  cli ; stop interrupts
  hlt; halt the CPU

kernel.c:

#define WHITE_TXT 0x07

void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);


k_main()
{
	k_clear_screen();
	k_printf("Test. Can you read this???", 0);
};

void k_clear_screen()
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	while(i < (80*25*2))
	{
  vidmem[i]=' ';
  i++;
  vidmem[i]=WHITE_TXT;
  i++;
	};
};

unsigned int k_printf(char *message, unsigned int line)
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;

	i=(line*80*2);

	while(*message!=0)
	{
  if(*message=='\n')
  {
 	 line++;
 	 i=(line*80*2);
 	 *message++;
  } else {
 	 vidmem[i]=*message;
 	 *message++;
 	 i++;
 	 vidmem[i]=WHITE_TXT;
 	 i++;
  };
	};

	return(1);
};

link.ld:

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
  .text  0x100000 : {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }
  .data  : {
    data = .; _data = .; __data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss  :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .; _end = .; __end = .;
}

Build Instructions:

1. nasm -f aout kernel_start.asm -o ks.o

2. gcc -c kernel.c -o kernel.o

3. ld -T link.ld -o kernel.bin ks.o kernel.o

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I don't think the Dev-Cpp tools recognise the a.out format. Try using COFF or use the DJGPP tools (that's what I used with windows).

Off topic: What boot loader are you gonna use to bring up your kernel. If GRUB, you might want to look at the multiboot header. In any case, you should setup protected mode before you do anything. Just a simple GDT with a couple of entries and disabled interrupts will do.

EDIT: You should do a cli before calling _k_main.

Edited by MrA
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.