Cant add global function

Programming, for all ages and all languages.
Post Reply
dmcbeing
Posts: 4
Joined: Tue Mar 31, 2009 5:13 am

Cant add global function

Post by dmcbeing »

Hello every one !
I am creating my kernel in c++.
I have made an ostream implementation for printing variables.
Now i am creating and IDTEntry class to help me with the creation of the IDT.
Header:

Code: Select all

	class IDTEntry
	{
		friend cstream& operator<<(cstream& cs,const IDTEntry& var);
		public:
			IDTEntry(void (*isr)(void),PrivilegeType privilege = Kernel,bool present = true);
		private:
			unsigned short offset_high;
			unsigned short seg_selector;
			unsigned char unused;
			unsigned char atributes;
			unsigned short offset_low;
			
	}__attribute__((__packed__));
	cstream& operator<<(cstream& cs,const IDTEntry& var);
Implementation:

Code: Select all

	#include "IDTEntry.h"

	IDTEntry::IDTEntry(void (*isr)(void),PrivilegeType privilege,bool present)
	{
		offset_low = ((unsigned int)isr)&0xFFFF;
		offset_high = (((unsigned int)isr)>>16)&0xFFFF;
		atributes = present<<7 + (privilege&3)<<5 + Int32;
		seg_selector = 0x8;	//Deafault CS
	}
	cstream& operator<<(cstream& cs,const IDTEntry& var)
	{
		cs << (void*)var.seg_selector << cstream::endl;
		return cs;
	}
the problem is that if i run the kernel like that and print a string i have declared:

Code: Select all

char str[] = "Hello C++!";
prints garbage

whereas if i run the cstream& operator<<(cstream& cs,const IDTEntry& var) i get a gpf.

I guess it has somethink to do with the linker,perhaps i need a linker script?
Can anyone point me in the right direction?
Thanks in advance.
dmcbeing
Posts: 4
Joined: Tue Mar 31, 2009 5:13 am

Re: Cant add global function

Post by dmcbeing »

i think i solved it by using a linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x0010000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + SIZEOF(.text))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + SIZEOF(.text) + SIZEOF(.data))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
the final image went up to ~10k.
Can anyone sugest any improvements for the linker script ?

edit:
i took the original from the wiki faq "string not working" , however i got overlapping sections so i made some modifications.
Now it doesent gpf anymore but i cant use strings :S
Post Reply