feat: gestion GDT + affichage GDT+IDT

This commit is contained in:
Nicolas Hordé 2018-08-31 02:48:03 +02:00
parent 0c8419c91b
commit aace138efe
7 changed files with 145 additions and 9 deletions

View File

@ -24,7 +24,13 @@
#define irqendslave() asm("movb $0x20,%al; \
outb %al,$0xA0;")
#define lidt(dtr) asm ("lidtl %0"::"m" (*dtr))
#define lidt(idtr) asm ("lidtl %0"::"m" (*idtr))
#define lgdt(gdtr) asm ("lgdtl %0"::"m" (*gdtr))
#define sidt(idtr) asm ("sidtl %0"::"m" (*idtr))
#define sgdt(gdtr) asm ("sgdtl %0"::"m" (*gdtr))
/******************************************************************************/

View File

@ -1,6 +1,6 @@
#include <type.h>
#include <types.h>
struct gdtdesc {
typedef struct gdtdes {
u16 lim0_15;
u16 base0_15;
u8 base16_23;
@ -8,7 +8,7 @@ struct gdtdesc {
u8 lim16_19 : 4;
u8 flags : 4;
u8 base24_31;
} __attribute__ ((packed));
} gdtdes __attribute__ ((packed));
struct gdtr {
u16 limite;

View File

@ -41,7 +41,7 @@ typedef struct idtdes {
} idtdes __attribute__ ((packed));
struct dtr {
struct idtr {
u16 limite;
u32 base;
} __attribute__ ((packed));

31
lib/gdt.c Executable file
View File

@ -0,0 +1,31 @@
#include "gdt.h"
#include "asm.h"
#include "types.h"
/*******************************************************************************/
/* Initialise la GDT */
void initgdt()
{
}
/*******************************************************************************/
/* Créé un descripteur GDT */
void makegdtdes(u32 base, u32 limite, u8 acces, u8 flags, gdtdes *desc)
{
desc->lim0_15 = (limite & 0xffff);
desc->base0_15 = (base & 0xffff);
desc->base16_23 = (base & 0xff0000) >> 16;
desc->acces = acces;
desc->lim16_19 = (limite & 0xf0000) >> 16;
desc->flags = (flags & 0xf);
desc->base24_31 = (base & 0xff000000) >> 24;
return;
}

View File

@ -5,7 +5,7 @@
#include "video.h"
/* registre idt */
static struct dtr idtreg;
static struct idtr idtreg;
/* table de IDT */
static idtdes idt[256];
@ -535,7 +535,7 @@ void initidt(void)
putidt((u32) irq13, 0x20, INTGATE, 101);
putidt((u32) irq14, 0x20, INTGATE, 102);
putidt((u32) irq15, 0x20, INTGATE, 103);
for (i = 104; i < 255; i++) {
for (i = 104; i <= 255; i++) {
putidt((u32) interruption, 0x20, TRAPGATE, i);
}
/* initialise le registre idt */
@ -545,7 +545,6 @@ void initidt(void)
memcpy(&idt, (u8 *) idtreg.base, idtreg.limite, 1);
/* chargement du registre IDTR */
lidt(&idtreg);
}
/******************************************************************************/

View File

@ -1,6 +1,6 @@
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include
LINK=ld -m elf_i386 -r -o
OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o
OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o gdt.o
all: makeall

View File

@ -9,6 +9,7 @@
#include "string.h"
#include "2d.h"
#include "ansi.c"
#include "gdt.h"
static u8 warnmsg[] =
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
@ -77,6 +78,8 @@ int main(void)
static u8 cmd_detectcpu[]="DETECTCPU\000";
static u8 cmd_test2d[]="TEST2D\000";
static u8 cmd_regs[]="REGS\000";
static u8 cmd_gdt[]="GDT\000";
static u8 cmd_idt[]="IDT\000";
while (true) {
print("\r\n# ");
getstring(&field);
@ -91,11 +94,17 @@ int main(void)
else if (strcmp(&item,&cmd_detectcpu)==0) detectcpu();
else if (strcmp(&item,&cmd_test2d)==0) test2d();
else if (strcmp(&item,&cmd_regs)==0) dump_regs();
else if (strcmp(&item,&cmd_gdt)==0) readgdt();
else if (strcmp(&item,&cmd_idt)==0) readidt();
else
printf("Commande inconnue !\r\n\000");
}
}
/*******************************************************************************/
/* Test les fonctionnalité 2D graphiques */
void test2d() {
setvmode(0x89);
fill(0x00);
@ -113,6 +122,97 @@ void test2d() {
triangle(&a,&b,&c,2);
}
}
/*******************************************************************************/
/* Lit l'IDT et l'affiche */
void readidt()
{
u32 index,i=0;
idtdes* desc;
struct idtr idtreg;
sidt(&idtreg);
printf("Information sur l'IDT\r\nAdresse:%X Limite:%hX",idtreg.base,(u32)idtreg.limite);
desc=idtreg.base;
for(index=0;index<idtreg.limite/sizeof(idtdes);index++)
{
u32 select=desc[index].select;
u32 offset=desc[index].offset0_15+(desc[index].offset16_31 << 16);
u32 type=desc[index].type;
printf("\r\nInterruption % d Selecteur %hX: offset:%X type:",i++,select,offset,type);
if (type==INTGATE) print("INTGATE");
else if (type==TRAPGATE) print("TRAPGATE");
else if (type==TASKGATE) print("TASKGATE");
else if (type==CALLGATE) print("CALLGATE");
else if (type==LDTDES) print("LDTDES");
else print("inconnu");
if (i%32==0) waitascii();
}
}
/*******************************************************************************/
/* Lit les descripteurs GDT et les affiche */
void readgdt()
{
u32 index;
gdtdes* desc;
struct gdtr gdtreg;
sgdt(&gdtreg);
printf("Information sur la LGDT\r\nAdresse:%X Limite:%hX",gdtreg.base,(u32)gdtreg.limite);
desc=gdtreg.base;
for(index=0;index<=gdtreg.limite/sizeof(gdtdes);index++)
{
u32 acces=desc[index].acces;
if (acces >> 7 == 1) {
u32 flags=desc[index].flags;
u32 limit=desc[index].lim0_15+(desc[index].lim16_19 << 16);
u32 base=desc[index].base0_15+(desc[index].base16_23 << 16)+(desc[index].base24_31 << 24) ;
printf("\r\nSelecteur %hX: base:%X limit:%X access:%hX flags:%hX\r\n -> ",index*sizeof(gdtdes),base,limit,acces,flags);
if ((acces >> 4) & 1 == 1)
print("Systeme ");
else {
if (acces & 1 == 1)
print("Acces ");
}
if ((acces >> 3) & 1 == 1) {
print("Code.");
if ((acces >> 1) & 1 == 1)
print("Readable ");
if ((acces >> 2) & 1 == 1)
print("Conforming ");
else
print("Normal ");
}
else {
print("Data.");
if ((acces >> 3) & 1 == 1)
print("Down ");
else
print("up ");
if ((acces >> 1) & 1 == 1)
print("writeable ");
}
if (flags & 1 == 1)
print("Dispo");
if ((flags >> 2) & 1 == 1)
print("32 bits ");
else
print("16 bits ");
if ((flags >> 3) & 1 == 1)
print("4k ");
else
print("1b ");
u8 dpl=(acces>>5) & 0b11;
printf("DPL:%d",dpl);
}
}
}
/*******************************************************************************/
/* Detecte et affiche les information sur le CPU */
void detectcpu()
{