1
Lowlevel-Coding / Re: VESA / VBE Informationen abrufen
« am: 24. March 2017, 00:29 »
So...... Nach viel googlen und viel experimentieren habe ich es endlich geschafft. Oben genannter Code mit der Funktion int32() funktioniert. Hier der Code um die Informationen abzurufen:
Code: [Auswählen]
typedef struct MODE_INFO
{
unsigned short ModeAttributes __attribute__ ((packed));
unsigned char WinAAttributes __attribute__ ((packed));
unsigned char WinBAttributes __attribute__ ((packed));
unsigned short WinGranularity __attribute__ ((packed));
unsigned short WinSize __attribute__ ((packed));
unsigned short WinASegment __attribute__ ((packed));
unsigned short WinBSegment __attribute__ ((packed));
unsigned long WinFuncPtr __attribute__ ((packed));
unsigned short BytesPerScanLine __attribute__ ((packed));
unsigned short XResolution __attribute__ ((packed));
unsigned short YResolution __attribute__ ((packed));
unsigned char XCharSize __attribute__ ((packed));
unsigned char YCharSize __attribute__ ((packed));
unsigned char NumberOfPlanes __attribute__ ((packed));
unsigned char BitsPerPixel __attribute__ ((packed));
unsigned char NumberOfBanks __attribute__ ((packed));
unsigned char MemoryModel __attribute__ ((packed));
unsigned char BankSize __attribute__ ((packed));
unsigned char NumberOfImagePages __attribute__ ((packed));
unsigned char Reserved_page __attribute__ ((packed));
unsigned char RedMaskSize __attribute__ ((packed));
unsigned char RedMaskPos __attribute__ ((packed));
unsigned char GreenMaskSize __attribute__ ((packed));
unsigned char GreenMaskPos __attribute__ ((packed));
unsigned char BlueMaskSize __attribute__ ((packed));
unsigned char BlueMaskPos __attribute__ ((packed));
unsigned char ReservedMaskSize __attribute__ ((packed));
unsigned char ReservedMaskPos __attribute__ ((packed));
unsigned char DirectColorModeInfo __attribute__ ((packed));
unsigned long PhysBasePtr __attribute__ ((packed));
unsigned long OffScreenMemOffset __attribute__ ((packed));
unsigned short OffScreenMemSize __attribute__ ((packed));
unsigned char Reserved[206] __attribute__ ((packed));
} MODE_INFO;
typedef struct VESA_INFO
{
unsigned char VESASignature[4] __attribute__ ((packed));
unsigned short VESAVersion __attribute__ ((packed));
unsigned long OEMStringPtr __attribute__ ((packed));
unsigned char Capabilities[4] __attribute__ ((packed));
unsigned long VideoModePtr __attribute__ ((packed));
unsigned short TotalMemory __attribute__ ((packed));
unsigned short OemSoftwareRev __attribute__ ((packed));
unsigned long OemVendorNamePtr __attribute__ ((packed));
unsigned long OemProductNamePtr __attribute__ ((packed));
unsigned long OemProductRevPtr __attribute__ ((packed));
unsigned char Reserved[222] __attribute__ ((packed));
unsigned char OemData[256] __attribute__ ((packed));
} VESA_INFO;
uint8_t* vga; //Framebuffer-Adresse
extern void int32(unsigned char intnum, regs16_t *regs);
void get_vesa_modes(void) {
struct VESA_INFO *vesa=(VESA_INFO *)pmm_alloc();
struct MODE_INFO *info=(MODE_INFO *)pmm_alloc();
memcpy(vesa->VESASignature,"VBE2",4);
regs16_t regs;
regs.ax=0x4f00;
regs.di=vesa;
regs.es=0;
int32(0x10,®s);
if(regs.ax!=0x004f) {
kprintf("VBE Error\n");
return false;
}
uint16_t *modes = ((vesa->VideoModePtr & 0xFFFF0000) >> 12) + (vesa->VideoModePtr & 0xFFFF);
while(*modes!=0xffff) {
regs.ax=0x4f01;
regs.cx=*modes;
regs.es=0;
regs.di=info;
int32(0x10,®s);
if(regs.ax !=0x004f) {
kprintf(" Error\n");
continue;
}
// Hier überprüfen ob die Auflösung ect. passt - ist ja ausreichend dokumentiert:
// http://www.lowlevel.eu/wiki/VBE
// http://wiki.osdev.org/User:Omarrx024/VESA_Tutorial
// http://wiki.osdev.org/Vesa
*modes++;
}
}
struct MODE_INFO *get_vesa_mode_info(uint16_t mode) {
struct MODE_INFO *info=(MODE_INFO *)pmm_alloc();
regs16_t regs;
regs.ax=0x4f01;
regs.cx=mode;
regs.es=0;
regs.di=info;
int32(0x10,®s);
if(regs.ax !=0x004f) {
kprintf(" Error\n");
return -1;
} else {
kprintf("Mode: %x\n",mode);
}
kprintf(" --> %dx%dx%d Addr: %x\n",info->XResolution,info->YResolution,info->BitsPerPixel,(char*)info->PhysBasePtr);
return info;
}
void set_vesa_mode(uint16_t mode) {
struct MODE_INFO *info=get_vesa_mode_info(mode);
vga=(uint8_t*) (uintptr_t)info->PhysBasePtr;
regs16_t regs;
regs.ax = 0x4f02;
regs.bx = mode;
int32(0x10,®s);
// Hier wird der gesamte Bildschirm weiß gefärbt
for(int y=0;y<info->YResolution;y++) {
for(int x=0;x<info->XResolution;x++) {
PutPixel(x,y,0xffffff,info->BytesPerScanLine);
}
}
}
void PutPixel(int x, int y, unsigned int color, unsigned short bps) { //Funktioniert nur bei 32 Bit Farbtiefe
*(uint32_t *)(vga + y * bps + x * 4) = color;
}