I am writing a kernel, the base is working fine, but when i went to add I/O ports, with this header:
#ifndef __PORT_H
#define __PORT_H
class Port {
protected: Port(uint16_t _portNum);
~Port();
uint16_t portNum;
};
class Port8Bit: public Port {
public:
using Port::Port;
Port8Bit(uint16_t _portNum);
~Port8Bit();
virtual uint8_t read();
virtual void write(uint8_t data);
protected:
static inline uint8_t read8(uint16_t _port) {
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a" (result) : "Nd" (_port))
return result
}
static inline void write8(uint16_t _port, uint8_t _data) {
__asm__ volatile("outb %0, %1" : : "a" (_data), "Nd" (_port))
}
};
#endif
And this .cpp file:
#include "port.h"
Port::Port(uint16_t _portNum) {
portNum = _portNum;
}
Port::~Port() {}
Port8Bit::Port8Bit(uint16_t _portNum) : Port(_portNum) {}
Port8Bit::~Port8Bit() {}
void Port8Bit::write(uint8_t data) {
write8(portNum, data);
}
uint8_t Port8Bit::read() {
return read8(portNum);
}
I get the following error:
ld: lib/io/port.o:(.data.rel.ro._ZTI8Port8Bit[_ZTI8Port8Bit]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
ld: lib/io/port.o:(.data.rel.ro._ZTI4Port[_ZTI4Port]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
make: *** [Makefile:42: link] Error 1
I am using gcc as a compiler
What I have tried:
I tried removing the
using Port::Port
and got this error:
ld: lib/io/port.o:(.data.rel.ro._ZTI8Port8Bit[_ZTI8Port8Bit]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
ld: lib/io/port.o:(.data.rel.ro._ZTI4Port[_ZTI4Port]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
make: *** [Makefile:42: link] Error 1
If i (in port.cpp) comment everything out under
Port::~Port() {}
it compiles fine.
But when i then add
Port8Bit::Port8Bit(uint16_t _portNum) : Port(_portNum) {}
it gives me the following error:
ld: lib/io/port.o: in function `Port8Bit::Port8Bit(unsigned short)':
port.cpp:(.text+0x5f): undefined reference to `vtable for Port8Bit'
make: *** [Makefile:42: link] Error 1
If I do like this (port.cpp):
#include "port.h"
Port::Port(uint16_t _portNum) {
portNum = _portNum;
}
Port::~Port() {}
void Port8Bit::write(uint8_t data) {
write8(portNum, data);
}
It compiles, but when i add the read function:
#include "port.h"
Port::Port(uint16_t _portNum) {
portNum = _portNum;
}
Port::~Port() {}
void Port8Bit::write(uint8_t data) {
write8(portNum, data);
}
uint8_t Port8Bit::read() {
return read8(portNum);
}
It once again fails and gives me this code:
ld: lib/io/port.o:(.data.rel.ro._ZTI8Port8Bit[_ZTI8Port8Bit]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
ld: lib/io/port.o:(.data.rel.ro._ZTI4Port[_ZTI4Port]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
make: *** [Makefile:42: link] Error 1
I really hope somebody can help me with this, it's incredibly confusing and I have no idea what the compiler is doing at all, why will only it work implementing the write, not the read? Even if i comment out
return read8(portNum);
so it's literally just an empty function it still gives the same error.