I made my GDT in C++ which defines both the kernel and user segments, problem is with my asm (probably with my table). VirtualBox crashes after the:
Code: Select all
mov ss, ax
gdt.h
Code: Select all
#pragma once
#include "stdint.h"
struct GDTDescriptor {
uint16_t Size;
uint32_t Offset;
} __attribute__((packed));
struct GDTEntry {
uint16_t Limit0;
uint16_t Base0;
uint8_t Base1;
uint8_t AccessByte;
uint8_t Limit1_Flags;
uint8_t Base2;
} __attribute__((packed));
struct GDT {
GDTEntry Null;
GDTEntry KernelCode;
GDTEntry KernelData;
GDTEntry UserNull;
GDTEntry UserCode;
GDTEntry UserData;
} __attribute__((packed))
__attribute((aligned(0x1000)));
extern GDT DefaultGDT;
extern "C" void LoadGDT(GDTDescriptor* gdtDescriptor);
Code: Select all
#include "gdt.h"
GDT DefaultGDT = {
{0, 0, 0, 0x00, 0x00, 0},
{0, 0, 0, 0x9a, 0xa0, 0},
{0, 0, 0, 0x92, 0xa0, 0},
{0, 0, 0, 0x00, 0x00, 0},
{0, 0, 0, 0x9a, 0xa0, 0},
{0, 0, 0, 0x92, 0xa0, 0}
};
Code: Select all
global LoadGDT
LoadGDT:
lgdt [edi]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
retf
Code: Select all
GDTDescriptor gdtDescriptor;
gdtDescriptor.Size = sizeof(GDT) - 1;
gdtDescriptor.Offset = (uint32_t)&DefaultGDT;
LoadGDT(&gdtDescriptor);
(I am running in protected mode after booting from GRUB).