My GDT and paging tables are both statically allocated variables/stucts/arrays and therefore have to be in kernel address space (so below &_end).
My Project is online on GitHub:
https://github.com/DevNoteHQ/MOSThe kernel source code is in /system/kernel/src/
GS register is set in cpu/cpu.cpp (the GS register contains a pointer to struct CPU::CPU BSP which contains the address of the GDT).
GDT is configured in init/gdt.cpp
Paging is first configured in init/boot.asm and then redone in mm/vmm/init.cpp (i should maybe change that).
Note that i am using 1GB pages for mapping the kernel.
init/boot.asm starts System::Init() in init/init.cpp which starts all the other things.
Also note that i am standard including some header files. These files can be found in /include/ (libMOS.a is not in working right now and therefore not used).
Thank you for your help!
EDIT4:
So in a long mode kernel to debug with VMware Player, you have to connect as 32-bit debugger (port 8832), set a breakpoint at your trampoline code (where you are in long mode but still use 32-bit addresses), continue, disconnect and connect as 64-bit debugger (port 8864).
Can someone maybe tell me why nasm doesn't create debug symbols? I used:
Code:
NASFLAGS = -f elf64 -F dwarf -g
$(OBJDIR)/%_asm.o : $(SRCDIR)/%.asm
$(mk) $(@D)
$(ASM) $(NASFLAGS) $< -o $@
And -gdwarf for gcc.
EDIT5:
I fixed the issue. I'm not sure what the cause was, but after redoing my string class the issue was gone. It's possible that the string methods tried to free memory that didn't exist and that if(addr == NULL) return; didn't work in my free()-function.
Could someone more experienced in C++ take a quick look at my string class?
string.hpp:
Code:
class string
{
private:
char* cstr;
public:
string();
string(const char* str);
string(const string& str);
~string();
operator char*();
operator const char*();
string& operator+=(const string& rhs);
string& operator=(const string& rhs);
friend string operator+(const string& lhs, const string& rhs);
friend string operator+(const string& lhs, char rhs);
friend string operator+(const string& lhs, const char* rhs);
friend string operator+(char lhs, const string& rhs);
friend string operator+(const char* lhs, const string& rhs);
};
string.cpp:
Code:
string::string()
{
cstr = 0;
}
string::string(const char *str)
{
cstr = new char[strlen(str) + 1];
strcpy(cstr, str);
}
string::string(const string& q)
{
cstr = new char[strlen(q.cstr) + 1];
strcpy(cstr, q.cstr);
}
string::~string()
{
if (cstr)
delete[] cstr;
}
string::operator char*()
{
return cstr;
}
string::operator const char* ()
{
return cstr;
}
string& string::operator= (const string& rhs)
{
if (this == &rhs) return *this;
if (cstr)
delete[] cstr;
cstr = new char[strlen(rhs.cstr) + 1];
strcpy(cstr, rhs.cstr);
return *this;
}
string& string::operator+= (const string& rhs)
{
uint32_t size = strlen(cstr) + strlen(rhs.cstr) + 1;
char *tmp = new char[size];
strcpy(tmp, cstr);
strcat(tmp, rhs.cstr);
delete[] cstr;
cstr = tmp;
return *this;
}
string operator+ (const string& lhs, const string& rhs)
{
return string(lhs) += rhs;
}
string operator+ (const string& lhs, char rhs)
{
return string(lhs) += string(rhs);
}
string operator+ (const string& lhs, const char* rhs)
{
return string(lhs) += string(rhs);
}
string operator+ (char lhs, const string& rhs)
{
return string(lhs) += rhs;
}
string operator+ (const char* lhs, const string& rhs)
{
return string(lhs) += rhs;
}