Annoying ld linking problem
Posted: Wed Mar 14, 2012 1:47 pm
So, I have successfully compiled an object file out of my c++ source
k_defines.h
kernel.ld
build script (batch)
But I just get an error on the linker:
If anyone could help, it would be appreciated.
Code: Select all
#include "k_defines.h"
inline void outportb(unsigned int port, unsigned char value);
unsigned int panic(char *message);
void k_main();
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
void update_cursor(int row, int col);
void k_main()
{
k_clear_screen();
k_printf("Starting P-DOS...",0);
update_cursor(1,0);
k_printf("Nopony else is in here. Looks like I'm forever aLUNA. (How punny of me *induberdebly*)",3);
update_cursor(5,0);
};
unsigned int k_printf(char *message, unsigned int line)
{
char *vram = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message==0x2f)
{
*message++;
if(*message==0x63)
{
line++;
i=(line*80*2);
*message++;
if(*message==0)
{
return(1);
};
};
};
vram[i]=*message;
*message++;
i++;
vram[i]=0x07;
i++;
};
return(1);
};
void k_clear_screen()
{
char *vram = (char *) 0xb8000;
unsigned int i=0;
while(i<(80*2*25))
{
vram[i]=' ';
i++;
vram[i]=WHITE_TXT;
i++;
};
};
inline void outportb(unsigned int port, unsigned char value)
{
asm volatile ("outb %%al, %%dx"::"d" (port), "a" (value));
};
void update_cursor(int row, int col)
{
USHORT position=(row*80)+col;
outportb(0x3d4, 0x0f);
outportb(0x3d5, (UCHAR)(position&0xff));
outportb(0x3d4, 0x0e);
outportb(0x3d5, (UCHAR)((position<<8)&0xff));
};
unsigned int panic(char *message)
{
char *vram = (char *) 0xb8000;
unsigned int i=0;
unsigned int line=0;
i=(line*80*2);
while(*message!=0)
{
if(*message==0x2f)
{
*message++;
if(*message==0x63)
{
line++;
i=(line*80*2);
*message++;
if(*message==0)
{
return(1);
};
};
};
vram[i]=*message;
*message++;
i++;
vram[i]=0x9; //use blue text
i++;
};
return(1);
};
Code: Select all
#define WHITE_TXT 0x7
#define BLUE_TXT 0x09
#define UCHAR unsigned char
#define USHORT unsigned short
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(k_main)
SECTIONS
{
.text 0x005000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Code: Select all
echo off
gcc-3 -c pony.cpp -o pony.o
ld -T kernel.ld -o PONY.SYS pony.o
copy PONY.SYS A:\PONY.SYS
pause
Code: Select all
ld: cannot perform PE operation on a non PE file 'PONY.SYS'