Page 1 of 2

Some Really annoying G++ Hair-tear problem I'm having

Posted: Sun Aug 17, 2008 2:13 pm
by Tezzanator
I hope this is the right place, I'm new here so please forgive me if it isn't :)

Anyway I came here to ask a question

My OS And Tools of choice
Windows XP Pro SP2
G++
ld-elf
bochs

None of this code is deadlly serious, It's just to make sure my environment is working right!

I have my main.cpp:

Code: Select all

#include "VGA.h"
 
extern "C" void __cxa_pure_virtual()
{
    // print error message
}
 
extern "C" void kmain(void* mbd, unsigned int magic);
 
void kmain( void* mbd, unsigned int magic )
{
	VGA v;
	v.clrscr();
 
}

and my VGA.h

Code: Select all

#ifndef VGA_H
#define VGA_H
 
class VGA
{
private:
	char *videoMemory;
public:
	VGA();
	~VGA();
	void clrscr();
};
 
#endif

and my VGA.cpp

Code: Select all

#include "VGA.h"
 
VGA::VGA()
{
	videoMemory = (char*) 0xb8000;
}
 
VGA::~VGA()
{
}
 
void VGA::clrscr()
{
    int i;
    for(i=0;i < (80*25*2);i+=2)
    {
        videoMemory[i]=' ';
        videoMemory[i+1]=0x07;
    }
}


Now If I compile with:

Code: Select all

"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\kernel.o" -c -nostdlib -nostartfiles -nodefaultlibs  "Source\Kernel\main.cpp" "Source\Kernel\VGA.cpp"

G++ Throws:
Source\Kernel\main.cpp:15: sorry, unimplemented: inter-module optimisations not implemented yet In file included from Source\Kernel\VGA.cpp:1:
Source\Kernel\VGA.h:5: error: redefinition of `class VGA'
Source\Kernel\VGA.h:5: error: previous definition of `class VGA'

my external linking (With LD-elf) throws:
Output\object\kernel.o(.text+0x13):main.cpp: undefined reference to `__ZN3VGAC1Ev'
Output\object\kernel.o(.text+0x1e):main.cpp: undefined reference to `__ZN3VGA6clrscrEv'
Output\object\kernel.o(.text+0x29):main.cpp: undefined reference to `__ZN3VGAD1Ev'

Yet If I add "#include "VGA.cpp"" to main.CPP, like so:

Code: Select all

#include "VGA.cpp"
#include "VGA.h"
 
extern "C" void __cxa_pure_virtual()
{
    // print error message
}
 
extern "C" void kmain(void* mbd, unsigned int magic);
 
void kmain( void* mbd, unsigned int magic )
{
	VGA v;
	v.clrscr();
 
}

And compile with:

Code: Select all

"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\kernel.o" -c -nostdlib -nostartfiles -nodefaultlibs  "Source\Kernel\main.cpp"

It will compile correctly and will even boot in bochs (And will do what I expected, Clear the screen)!
But Including CPP files isn't exactly right is it?

Any Ideas on how to resolve this would be MUCH appreciated! - Maybe I am overlooking something I need to do to get this working (Maybe I'm doing my G++ command TOTALLY wrong)

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Sun Aug 17, 2008 3:30 pm
by samoz
Well, as a rule of thumb, if your compiler gives you errors, any thing the linker says will be erroneous, since it is using flawed code from the compiler.

I'm not positive, but I'm pretty sure your problem is arriving from including the header file twice.

Place this around all the code in your header file:

Code: Select all

#ifndef CODED
#define CODED

//your code here

#endif
Because as is, your header file defines the class the first time it is included and again in the 2nd file.

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Sun Aug 17, 2008 3:55 pm
by Tezzanator
Unfortunately, I've already done that

Code: Select all

#ifndef VGA_H
#define VGA_H

class VGA
{
private:
   char *videoMemory;
public:
   VGA();
   ~VGA();
   void clrscr();
};

#endif
However it still throws these strange errors I can;t wrap my head around :?

Which is why this is so baffeling to me :?

I appreciate your help however, I've asked so many people, Even the C++ Channel on freenode, but no-one seems to have an idea what's going on, :-({|=

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Sun Aug 17, 2008 4:53 pm
by froggey
The -o switch doesn't work with the -c switch when compiling multiple files.

You have to either build the two file seperately or compile without using the -o switch.

Code: Select all

"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\main.o" -c -nostdlib -nostartfiles -nodefaultlibs "Source\Kernel\main.cpp"
"Build Tools\MinGW\bin\g++" -fno-exceptions -fno-rtti -o "Output\object\VGA.o" -c -nostdlib -nostartfiles -nodefaultlibs "Source\Kernel\VGA.cpp"

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Sun Aug 17, 2008 5:04 pm
by Tezzanator
Oh wow.
I can't thank you enough. =D> [-o<

Boy do I feel like an idiot #-o :oops:

Many, Many, Many, many, many, many thanks!!

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Mon Aug 18, 2008 5:30 am
by ineo
froggey wrote:The -o switch doesn't work with the -c switch when compiling multiple files.
Hence the "inter-module optimisations not implemented yet" error message.
Impressive froggey =D>

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Mon Aug 18, 2008 7:31 pm
by Tezzanator
Well, I don't wont to seem like a pest :lol:

Why do these tools never agree with me? - I blame it on too much contact with visual studio's "Do everything for you and hide the details" approach :P

However I ran into an equally as baffeling problem.
If i compile my code with just a bare class (No code AT ALL, Just the constructor and destructor)

Code: Select all

#include "VGA.h"

VGA::VGA()
{
	// Initialize the memory map of the VGA memory.
	//videoMemory = (char*) 0xb8000;
}

VGA::~VGA()
{
}

/*
void VGA::clrscr()
{
    int i;
    for(i=0;i < (80*25*2);i+=2)
    {
        videoMemory[i]=' ';
        videoMemory[i+1]=0x07;
    }
}*/
then instantiate the class

Code: Select all

VGA v;

bochs will triple fault and reboot.
The constructor contains no code at all, I commented it all out.

Yet this only happens when my class is linked in from an external .o file. However the linker throws no errors. this has my head boiling :| .

My linker script (Which I suspect is the problem?)

Code: Select all

OUTPUT_FORMAT("elf32-i386") 

INPUT("Output\object\VGA.o")
INPUT("Output\object\Kernel.o")
INPUT("Output\object\loader.o")

ENTRY (_loader)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
		start_ctors = .;
		*(.ctor*)
		end_ctors = .;
		start_dtors = .;
		*(.dtor*)
		end_dtors = .;
		*(.data)
	}


    .bss : {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }
}
I was hoping someone else encountered the same thing could save me from hours of trial and error and pain [-o<

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 3:51 am
by Combuster
could you start by posting the bochs log and disassembly of your kernel?

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 5:51 am
by Tezzanator
Combuster wrote:could you start by posting the bochs log and disassembly of your kernel?
Certainly, I abstained from doing such as I wasn't sure exactly what you guys would find useful, And Walls of text aren't fun :D

Here's the Bochs log

Code: Select all

00000000000i[     ] installing win32 module as the Bochs GUI
00000000000i[     ] Bochs x86 Emulator 2.3.7
00000000000i[     ]   Build from CVS snapshot, on June 3, 2008
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   CLFLUSH support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   SEP support: yes
00000000000i[     ]   MWAIT support: no
00000000000i[     ]   XSAVE support: no
00000000000i[     ]   AES support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 01D00020. after alignment, vector=01D01000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('C:\Program Files\Bochs-2.3.7/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('C:\Program Files\Bochs-2.3.7/VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: 0xfec00000 - 0xfec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Tue Aug 19 13:09:01 2008 (time0=1219147741)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'output\floppy.img' ro=0, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 0x000a0000 - 0x000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1024 x 768
00000000000i[WGUI ] Number of Mouse Buttons = 5
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: 0xe0000000 - 0xe07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_mem of 'gameport' plugin device by virtual method
00000000000i[     ] init_mem of 'speaker' plugin device by virtual method
00000000000i[     ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[     ] init_mem of 'acpi' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, none, none
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000003302i[BIOS ] $Revision: 1.209 $ $Date: 2008/06/02 20:08:10 $
00000080000e[CLVGA] character height = 1, skipping text update
00000317069i[KBD  ] reset-disable command received
00000436653i[VBIOS] VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $
00000436724i[CLVGA] VBE known Display Interface b0c0
00000436756i[CLVGA] VBE known Display Interface b0c4
00000439681i[VBIOS] VBE Bios $Id: vbe.c,v 1.60 2008/03/02 07:47:21 vruppert Exp $
00000480000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00000762682i[BIOS ] Starting rombios32
00000763509i[BIOS ] ram_size=0x02000000
00000784058i[BIOS ] Found 1 cpu(s)
00000800359i[BIOS ] bios_table_addr: 0x000fb778 end=0x000fcc00
00000800426i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001259233i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001718720i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001718767i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001718814i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001718861i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001718877i[P2I  ] write: ELCR2 = 0x0a
00001719814i[BIOS ] PIIX3 init: elcr=00 0a
00001740069i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00001743306i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00001746039i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00001746500i[PIDE ] new BM-DMA address: 0xc000
00001747383i[BIOS ] region 4: 0x0000c000
00001749959i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00001750459i[ACPI ] new irq line = 11
00001750496i[ACPI ] new PM base address: 0xb000
00001750558i[ACPI ] new SM base address: 0xb100
00001751026i[CPU0 ] Enter to System Management Mode
00001751036i[CPU0 ] RSM: Resuming from System Management Mode
00001751070i[PCI  ] setting SMRAM control register to 0x4a
00001751352i[PCI  ] setting SMRAM control register to 0x0a
00001774633i[BIOS ] MP table addr=0x000fb850 MPC table addr=0x000fb780 size=0xd0
00001776836i[BIOS ] SMBIOS table addr=0x000fb860
00001779880i[BIOS ] ACPI tables: RSDP addr=0x000fb970 ACPI DATA addr=0x01ff0000 size=0x9d8
00001799413i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001800425i[BIOS ] bios_table_cur_addr: 0x000fb994
00008023335i[BIOS ] Booting from 0000:7c00
00012720441i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00012725222i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00012729879i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
00047628777i[FDD  ] partial read() on floppy image returns 324/512
00047651510i[FDD  ] read() on floppy image returns 0
00047674243i[FDD  ] read() on floppy image returns 0
00047696976i[FDD  ] read() on floppy image returns 0
00047719709i[FDD  ] read() on floppy image returns 0
00047742442i[FDD  ] read() on floppy image returns 0
00047765175i[FDD  ] read() on floppy image returns 0
00047787908i[FDD  ] read() on floppy image returns 0
00047810641i[FDD  ] read() on floppy image returns 0
00047833374i[FDD  ] read() on floppy image returns 0
00047856107i[FDD  ] read() on floppy image returns 0
00047878840i[FDD  ] read() on floppy image returns 0
00047901573i[FDD  ] read() on floppy image returns 0
00047924306i[FDD  ] read() on floppy image returns 0
00047947039i[FDD  ] read() on floppy image returns 0
00047969772i[FDD  ] read() on floppy image returns 0
00067845655i[CPU0 ] CPU is in protected mode (active)
00067845655i[CPU0 ] CS.d_b = 32 bit
00067845655i[CPU0 ] SS.d_b = 32 bit
00067845655i[CPU0 ] EFER   = 0x00000000
00067845655i[CPU0 ] | RAX=0000000000104fd8  RBX=0000000000101000
00067845655i[CPU0 ] | RCX=000000000001c300  RDX=000000000002be00
00067845655i[CPU0 ] | RSP=0000000000104fc4  RBP=0000000000104ff0
00067845655i[CPU0 ] | RSI=000000000002be78  RDI=0000000000000080
00067845655i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00067845655i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00067845655i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00067845655i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00067845655i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf AF pf cf
00067845655i[CPU0 ] | SEG selector     base    limit G D
00067845655i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00067845655i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00067845655i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00067845655i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00067845655i[CPU0 ] | RIP=0000000000100034 (0000000000100034)
00067845655i[CPU0 ] | CR0=0x60000011 CR1=0x0 CR2=0x0000000000000000
00067845655i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00067845655i[CPU0 ] >> (invalid)  : FFFF
00067845655e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting

00067845655i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00067845655i[CPU0 ] cpu software reset
00067845655i[APIC0] local apic in CPU 0 initializing
00067848958i[BIOS ] $Revision: 1.209 $ $Date: 2008/06/02 20:08:10 $
00068162550i[KBD  ] reset-disable command received
VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $
00068282205i[CLVGA] VBE known Display Interface b0c0
00068282237i[CLVGA] VBE known Display Interface b0c4
00068285162i[VBIOS] VBE Bios $Id: vbe.c,v 1.60 2008/03/02 07:47:21 vruppert Exp $
00068608163i[BIOS ] Starting rombios32
00068608990i[BIOS ] ram_size=0x02000000
00068629539i[BIOS ] Found 1 cpu(s)
00068645840i[BIOS ] bios_table_addr: 0x000fb778 end=0x000fcc00
00068645907i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00069104714i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00069565295i[BIOS ] PIIX3 init: elcr=00 0a
00069585550i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00069588787i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00069591520i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00069592864i[BIOS ] region 4: 0x0000c000
00069595440i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00069619407i[BIOS ] MP table addr=0x000fb850 MPC table addr=0x000fb780 size=0xd0
00069621610i[BIOS ] SMBIOS table addr=0x000fb860
00069624654i[BIOS ] ACPI tables: RSDP addr=0x000fb970 ACPI DATA addr=0x01ff0000 size=0x9d8
00069644187i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00069645199i[BIOS ] bios_table_cur_addr: 0x000fb994
00076188998i[BIOS ] Booting from 0000:7c00
00080886014i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00080890795i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00080895452i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
And disassembly:
Hope This Suffices :)

Code: Select all

output\kernel.bin:     file format elf32-i386
output\kernel.bin
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0010005c

Program Header:
    LOAD off    0x00001000 vaddr 0x00100000 paddr 0x00100000 align 2**12
         filesz 0x0000009d memsz 0x0000009d flags r-x
    LOAD off    0x00002000 vaddr 0x00101000 paddr 0x00101000 align 2**12
         filesz 0x00000000 memsz 0x00004000 flags rw-

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000009d  00100000  00100000  00001000  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00101000  00101000  00002000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00004000  00101000  00101000  00002000  2**2
                  ALLOC
  3 .comment      0000001f  00105000  00105000  00002000  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00100000 l    d  .text	00000000 
00101000 l    d  .data	00000000 
00101000 l    d  .bss	00000000 
00105000 l    d  .comment	00000000 
00000000 l    d  *ABS*	00000000 
00000000 l    d  *ABS*	00000000 
00000000 l    d  *ABS*	00000000 
00000000 l    df *ABS*	00000000 Source\Loader\loader.s
00000001 l       *ABS*	00000000 MODULEALIGN
00000002 l       *ABS*	00000000 MEMINFO
00000003 l       *ABS*	00000000 FLAGS
1badb002 l       *ABS*	00000000 MAGIC
e4524ffb l       *ABS*	00000000 CHECKSUM
00100050 l       .text	00000000 MultiBootHeader
00004000 l       *ABS*	00000000 STACKSIZE
00100063 l       .text	00000000 static_ctors_loop
0010006d l       .text	00000000 static_ctors_loop.body
00100075 l       .text	00000000 static_ctors_loop.test
00100082 l       .text	00000000 static_dtors_loop
0010008c l       .text	00000000 static_dtors_loop.body
00100094 l       .text	00000000 static_dtors_loop.test
00101000 l       .bss	00000000 stack
0010005c g       .text	00000000 _loader
00101000 g     O .bss	00000000 _sbss
00100012 g       .text	00000000 __ZN3VGAD1Ev
00101000 g     O .data	00000000 start_ctors
00100000 g       .text	00000000 __ZN3VGAC2Ev
00101000 g     O .data	00000000 start_dtors
00105000 g     O .bss	00000000 _ebss
00101000 g     O .data	00000000 end_ctors
00100006 g       .text	00000000 __ZN3VGAC1Ev
00101000 g     O .data	00000000 end_dtors
00100020 g       .text	00000000 ___cxa_pure_virtual
0010000c g       .text	00000000 __ZN3VGAD2Ev
00100026 g       .text	00000000 _kmain


Contents of section .text:
 100000 5589e55d c3905589 e55dc390 5589e55d  U..]..U..]..U..]
 100010 c3905589 e55dc390 90909090 90909090  ..U..]..........
 100020 5589e55d c3905589 e583ec28 8d45e889  U..]..U....(.E..
 100030 0424e8e6 ffffff8d 45e88904 24e8f2ff  .$......E...$...
 100040 ffffc9c3 90909090 90909090 90909090  ................
 100050 02b0ad1b 03000000 fb4f52e4 bc005010  .........OR...P.
 100060 005053bb 00101000 e9080000 00ff1381  .PS.............
 100070 c3040000 0081fb00 10100072 f0e8a4ff  ...........r....
 100080 ffffbb00 101000e9 08000000 ff1381c3  ................
 100090 04000000 81fb0010 100072f0 f4        ..........r..   
Contents of section .data:
Contents of section .comment:
 105000 00546865 204e6574 77696465 20417373  .The Netwide @$$
 105010 656d626c 65722032 2e30332e 303100    embler 2.03.01. 
Disassembly of section .text:

00100000 <__ZN3VGAC2Ev>:
  100000:	55             	pushl  %ebp
  100001:	89 e5          	movl   %esp,%ebp
  100003:	5d             	popl   %ebp
  100004:	c3             	ret    
  100005:	90             	nop    

00100006 <__ZN3VGAC1Ev>:
  100006:	55             	pushl  %ebp
  100007:	89 e5          	movl   %esp,%ebp
  100009:	5d             	popl   %ebp
  10000a:	c3             	ret    
  10000b:	90             	nop    

0010000c <__ZN3VGAD2Ev>:
  10000c:	55             	pushl  %ebp
  10000d:	89 e5          	movl   %esp,%ebp
  10000f:	5d             	popl   %ebp
  100010:	c3             	ret    
  100011:	90             	nop    

00100012 <__ZN3VGAD1Ev>:
  100012:	55             	pushl  %ebp
  100013:	89 e5          	movl   %esp,%ebp
  100015:	5d             	popl   %ebp
  100016:	c3             	ret    
  100017:	90             	nop    
  100018:	90             	nop    
  100019:	90             	nop    
  10001a:	90             	nop    
  10001b:	90             	nop    
  10001c:	90             	nop    
  10001d:	90             	nop    
  10001e:	90             	nop    
  10001f:	90             	nop    

00100020 <___cxa_pure_virtual>:
  100020:	55             	pushl  %ebp
  100021:	89 e5          	movl   %esp,%ebp
  100023:	5d             	popl   %ebp
  100024:	c3             	ret    
  100025:	90             	nop    

00100026 <_kmain>:
  100026:	55             	pushl  %ebp
  100027:	89 e5          	movl   %esp,%ebp
  100029:	83 ec 28       	subl   $0x28,%esp
  10002c:	8d 45 e8       	leal   0xffffffe8(%ebp),%eax
  10002f:	89 04 24       	movl   %eax,(%esp,1)
  100032:	e8 e6 ff ff ff 	call   10001d <__ZN3VGAD1Ev+0xb>
  100037:	8d 45 e8       	leal   0xffffffe8(%ebp),%eax
  10003a:	89 04 24       	movl   %eax,(%esp,1)
  10003d:	e8 f2 ff ff ff 	call   100034 <_kmain+0xe>
  100042:	c9             	leave  
  100043:	c3             	ret    
  100044:	90             	nop    
  100045:	90             	nop    
  100046:	90             	nop    
  100047:	90             	nop    
  100048:	90             	nop    
  100049:	90             	nop    
  10004a:	90             	nop    
  10004b:	90             	nop    
  10004c:	90             	nop    
  10004d:	90             	nop    
  10004e:	90             	nop    
  10004f:	90             	nop    

00100050 <MultiBootHeader>:
  100050:	02 b0 ad 1b 03 	addb   0x31bad(%eax),%dh
  100055:	00 
  100056:	00 00          	addb   %al,(%eax)
  100058:	fb             	sti    
  100059:	4f             	decl   %edi
  10005a:	52             	pushl  %edx
  10005b:	e4 bc          	inb    $0xbc,%al

0010005c <_loader>:
  10005c:	bc 00 50 10 00 	movl   $0x105000,%esp
  100061:	50             	pushl  %eax
  100062:	53             	pushl  %ebx

00100063 <static_ctors_loop>:
  100063:	bb 00 10 10 00 	movl   $0x101000,%ebx
  100068:	e9 08 00 00 00 	jmp    100075 <static_ctors_loop.test>

0010006d <static_ctors_loop.body>:
  10006d:	ff 13          	call   *(%ebx)
  10006f:	81 c3 04 00 00 	addl   $0x4,%ebx
  100074:	00 

00100075 <static_ctors_loop.test>:
  100075:	81 fb 00 10 10 	cmpl   $0x101000,%ebx
  10007a:	00 
  10007b:	72 f0          	jb     10006d <static_ctors_loop.body>
  10007d:	e8 a4 ff ff ff 	call   100026 <_kmain>

00100082 <static_dtors_loop>:
  100082:	bb 00 10 10 00 	movl   $0x101000,%ebx
  100087:	e9 08 00 00 00 	jmp    100094 <static_dtors_loop.test>

0010008c <static_dtors_loop.body>:
  10008c:	ff 13          	call   *(%ebx)
  10008e:	81 c3 04 00 00 	addl   $0x4,%ebx
  100093:	00 

00100094 <static_dtors_loop.test>:
  100094:	81 fb 00 10 10 	cmpl   $0x101000,%ebx
  100099:	00 
  10009a:	72 f0          	jb     10008c <static_dtors_loop.body>
  10009c:	f4             	hlt    
Disassembly of section .data:
I've tried allsorts but it seems to refuse.
Come to think of it, It may of been a good Idea of me to dissaseemble the working version (The one with the include .cpp) and look at the differences.

Again, Sorry for being a pest, Im usually very good with sorting things like this - But this just has me stuck before I even started :|

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 6:32 am
by kmcguire
Use the BOCHS debug version. It is likely a executable in the BOCHS install directory that looks like, bochsdbg.exe.

Then insert a:

asm("hlt");
asm("nop");

Right, before the instantiation of the class or right before a call to a function that does the instantiation. Then run the simulation and wait until you are sure it has reached that point and stopped. Press ctrl+c and step through the instructions using the command step in the debugger until you find the instruction that faults.

That is a really great way to find problems because it _will_ narrow it down to a single instruction (processor operation). The only bad side to that is you could end up typing step quite a lot. So you have to be smart and insert the halt instruction in strategic places to find bad bugs in really loopy places (lots of code loops).

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 9:07 am
by JamesM
Hi,

Oh dear, something's gone drastically wrong there!

Code: Select all

00100026 <_kmain>:
  100026:   55                pushl  %ebp
  100027:   89 e5             movl   %esp,%ebp
  100029:   83 ec 28          subl   $0x28,%esp
  10002c:   8d 45 e8          leal   0xffffffe8(%ebp),%eax
  10002f:   89 04 24          movl   %eax,(%esp,1)
  100032:   e8 e6 ff ff ff    call   10001d <__ZN3VGAD1Ev+0xb>
  100037:   8d 45 e8          leal   0xffffffe8(%ebp),%eax
  10003a:   89 04 24          movl   %eax,(%esp,1)
  10003d:   e8 f2 ff ff ff    call   100034 <_kmain+0xe>
  100042:   c9                leave 
  100043:   c3                ret    
Note the two calls. 0x10001d and 0x100034. Look in your disassembly at those addresses. The first is in the NOP sled at the end of the VGA descructor, the second isn't even on a valid instruction boundary! (between 0x100032 and 0x100037).

We need to see the entire file that contains kmain, and the entire file that contains the VGA class, because it's not getting linked anywhere near correctly.

Cheers!

James

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 9:34 am
by Tezzanator
kmcguire wrote:Use the BOCHS debug version. It is likely a executable in the BOCHS install directory that looks like, bochsdbg.exe.

Then insert a:

asm("hlt");
asm("nop");

Right, before the instantiation of the class or right before a call to a function that does the instantiation. Then run the simulation and wait until you are sure it has reached that point and stopped. Press ctrl+c and step through the instructions using the command step in the debugger until you find the instruction that faults.

That is a really great way to find problems because it _will_ narrow it down to a single instruction (processor operation). The only bad side to that is you could end up typing step quite a lot. So you have to be smart and insert the halt instruction in strategic places to find bad bugs in really loopy places (lots of code loops).
I'll keep this in mind, seems like it will save me hours of pain :)
JamesM wrote: We need to see the entire file that contains kmain, and the entire file that contains the VGA class, because it's not getting linked anywhere near correctly.

Cheers!

James
Aha, Thanks.
My assumption wasn't too far off then :3

I'm not exactly sure what you mean by "Entire file that contains *" Are you wanting the source file, object file?
For simplicity sake I've put the Linker script, object files, Build batch, Compiled "kernel", floppy image and source files into a zip file :)
http://tezzanator.net/downloads/OS.zip

I really appreciate your help!! - You seem to have a good idea of what is causing this! :)

Looking over the dissssembly now, Wow that is quite a drastic... problem.

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Tue Aug 19, 2008 9:38 am
by Tezzanator
-snip-
Oh god, my bad, I thought this forum had an auto-merge system.... Very sorry.

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Wed Aug 20, 2008 2:51 am
by JamesM
Hi,

Fixed it.

Code: Select all

0010001e <_kmain>:
  10001e:       55                      push   %ebp
  10001f:       89 e5                   mov    %esp,%ebp
  100021:       83 ec 18                sub    $0x18,%esp
  100024:       f4                      hlt
  100025:       90                      nop
  100026:       83 ec 0c                sub    $0xc,%esp
  100029:       8d 45 ff                lea    -0x1(%ebp),%eax
  10002c:       50                      push   %eax
  10002d:       e8 d4 ff ff ff          call   100006 <_ZN3VGAC1Ev>
  100032:       83 c4 10                add    $0x10,%esp
  100035:       83 ec 0c                sub    $0xc,%esp
  100038:       8d 45 ff                lea    -0x1(%ebp),%eax
  10003b:       50                      push   %eax
  10003c:       e8 d1 ff ff ff          call   100012 <_ZN3VGAD1Ev>
  100041:       83 c4 10                add    $0x10,%esp
  100044:       c9                      leave
  100045:       c3                      ret
Your problem is that you're linking COFF object files and ELF object files into an ELF executable! The G++ you're using is outputting COFF object files, the nasm you're using is outputting ELF object files, and you're linking them to an ELF target.

The solution is to build a crosscompiler with native ELF output. This will fix your problem. There is an excellent page in the wiki written by Solar: GCC Cross-Compiler.

I got your code to work because I am working under linux, so have a native ELF32 G++.

Cheers!

James

Re: Some Really annoying G++ Hair-tear problem I'm having

Posted: Wed Aug 20, 2008 5:19 am
by Tezzanator
Thanks alot James 8) - I have ubuntu 32-bit installed (Dual boot) on my main PC, so later on I'll give it a shot on there.

I can't thank this forum enough [-o<