2018-09-28 20:35:51 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
|
|
|
/* */
|
2018-09-17 18:17:11 +02:00
|
|
|
#include "vga.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "interrupts.h"
|
|
|
|
#include "asm.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "2d.h"
|
|
|
|
#include "gdt.h"
|
|
|
|
#include "shell.h"
|
2018-09-27 21:01:02 +02:00
|
|
|
#include "multiboot2.h"
|
2018-09-17 18:17:11 +02:00
|
|
|
|
|
|
|
static command commands[] = {
|
2018-10-02 13:49:10 +02:00
|
|
|
{"REBOOT" , "", &rebootnow},
|
|
|
|
{"CLEAR" , "", &clear},
|
|
|
|
{"MODE" , "", &mode},
|
|
|
|
{"DETECTCPU" , "", &detectcpu},
|
|
|
|
{"TEST2D" , "", &test2d},
|
2018-10-02 17:16:23 +02:00
|
|
|
{"REGS" , "", ®s},
|
2018-10-02 13:49:10 +02:00
|
|
|
{"GDT" , "", &readgdt},
|
|
|
|
{"IDT" , "", &readidt},
|
|
|
|
{"INFO" , "", &info},
|
2018-10-03 22:50:54 +02:00
|
|
|
{"PGFAULTW" , "", &pgfaultw},
|
|
|
|
{"PGFAULTR" , "", &pgfaultr},
|
2018-10-04 14:55:41 +02:00
|
|
|
{"DIVZERR" , "", &divzerr},
|
|
|
|
{"INVALIDOP","", &invalidop},
|
|
|
|
{"INT3" , "", &int3},
|
|
|
|
{"GENERALFAULT" , "", &generalfault},
|
2018-10-04 16:29:54 +02:00
|
|
|
{"SEGFAULT","", &segfault},
|
|
|
|
{"BREAKPOINT","", &breakpoint},
|
|
|
|
{"TESTING","", &testing}
|
2018-09-17 18:17:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Shell, traite les commandes */
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
void shell()
|
|
|
|
{
|
|
|
|
static u8 field[] =
|
|
|
|
" \000";
|
|
|
|
static u8 item[] = " \000";
|
|
|
|
int i;
|
|
|
|
bool found;
|
|
|
|
while (true) {
|
|
|
|
print("\r\n# ");
|
|
|
|
getstring(&field);
|
|
|
|
print("\r\n");
|
|
|
|
if (strgetnbitems(&field, ' ') < 1)
|
|
|
|
continue;
|
|
|
|
strgetitem(&field, &item, ' ', 0);
|
|
|
|
strtoupper(&item);
|
|
|
|
found = false;
|
|
|
|
for (i = 0; i < sizeof(commands); i++) {
|
|
|
|
if (strcmp(&item, &commands[i].name) == 0) {
|
|
|
|
(*commands[i].function) ();
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
printf("Commande inconnue !\r\n\000");
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 16:29:54 +02:00
|
|
|
void testing(void)
|
|
|
|
{
|
|
|
|
print("Fonction de test !\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère un breakpoint */
|
|
|
|
int breakpoint()
|
|
|
|
{
|
|
|
|
print("Creation d'un breakpoint !\r\n");
|
|
|
|
asm("movl %[address],%%dr0 \n \
|
|
|
|
movl $0x00000003, %%eax\n \
|
|
|
|
movl %%eax, %%dr7"::[address] "a" (&testing):);
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:55:41 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une interruption 3 */
|
|
|
|
int int3()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur interruption 3 !\r\n");
|
|
|
|
asm("int $0x3");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une erreur general fault */
|
|
|
|
int generalfault()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur general fault !\r\n");
|
|
|
|
asm("mov $0x666, %ax; ltr %ax");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une erreur double fault */
|
|
|
|
int segfault()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur double fault !\r\n");
|
|
|
|
setidt(&segfault, SEL_KERNEL_CODE, INTGATE, 104);
|
|
|
|
asm("int $0x68");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une erreur d'opcode invalide */
|
|
|
|
int invalidop()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur d'opcode invalide !\r\n");
|
|
|
|
asm("mov %cr7, %eax");
|
|
|
|
}
|
|
|
|
|
2018-10-03 22:50:54 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une erreur de division par 0 */
|
|
|
|
int divzerr()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur de division par 0 !\r\n");
|
|
|
|
asm("movl $0x0,%ecx; divl %ecx");
|
|
|
|
}
|
|
|
|
|
2018-09-17 18:17:11 +02:00
|
|
|
/*******************************************************************************/
|
2018-10-02 13:49:10 +02:00
|
|
|
/* Génère une erreur de page à l'adresse 0xE0000000 */
|
2018-10-03 22:50:54 +02:00
|
|
|
int pgfaultw()
|
|
|
|
{
|
|
|
|
print("Creation d'une erreur de page !\r\n");
|
|
|
|
asm("movl $0x66666666,(0xE0000000)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Génère une erreur de page à l'adresse 0xD0000000 */
|
|
|
|
int pgfaultr()
|
2018-10-02 13:49:10 +02:00
|
|
|
{
|
2018-10-02 17:16:23 +02:00
|
|
|
print("Creation d'une erreur de page !\r\n");
|
2018-10-03 22:50:54 +02:00
|
|
|
asm("movl (0xD0000000),%eax");
|
2018-10-02 13:49:10 +02:00
|
|
|
}
|
2018-09-17 18:17:11 +02:00
|
|
|
|
2018-10-02 13:49:10 +02:00
|
|
|
/*******************************************************************************/
|
2018-09-27 21:01:02 +02:00
|
|
|
/* Information sur le démarrage */
|
|
|
|
int info()
|
|
|
|
{
|
|
|
|
getbootinfo();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2018-09-17 18:17:11 +02:00
|
|
|
/* Affiche les registres */
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
int regs()
|
|
|
|
{
|
2018-10-03 22:50:54 +02:00
|
|
|
save_stack dump;
|
|
|
|
dump_cpu(&dump);
|
|
|
|
show_cpu(&dump);
|
2018-09-27 17:47:27 +02:00
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Change le mode */
|
2018-09-27 17:47:27 +02:00
|
|
|
int mode()
|
|
|
|
{
|
|
|
|
setvmode(0x84);
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Efface l'écran */
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
int clear()
|
|
|
|
{
|
|
|
|
fill(0x00);
|
|
|
|
gotoscr(0, 0);
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Redemarre */
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
int rebootnow()
|
|
|
|
{
|
|
|
|
print("<Appuyer sur une touche pour redemarrer>");
|
|
|
|
waitascii();
|
|
|
|
reboot();
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Test les fonctionnalité 2D graphiques */
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
int test2d()
|
|
|
|
{
|
|
|
|
setvmode(0x89);
|
|
|
|
fill(0x00);
|
|
|
|
struct vertex2d a, b, c;
|
|
|
|
randomize();
|
|
|
|
for (int i = 0; i < 3200; i++) {
|
|
|
|
a.x = random(0, 800);
|
|
|
|
a.y = random(0, 600);
|
|
|
|
b.x = random(0, 800);
|
|
|
|
b.y = random(0, 600);
|
|
|
|
c.x = random(0, 800);
|
|
|
|
c.y = random(0, 600);
|
|
|
|
trianglefilled(&a, &b, &c, random(0, 16));
|
|
|
|
triangle(&a, &b, &c, 2);
|
|
|
|
}
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
2018-09-27 17:47:27 +02:00
|
|
|
|
2018-09-17 18:17:11 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* Lit l'IDT et l'affiche */
|
|
|
|
|
|
|
|
int readidt()
|
|
|
|
{
|
2018-09-27 17:47:27 +02:00
|
|
|
u32 index, i = 0;
|
|
|
|
idtdes *desc;
|
|
|
|
struct idtr idtreg;
|
|
|
|
sidt(&idtreg);
|
2018-10-04 14:55:41 +02:00
|
|
|
printf("Information sur l'IDT\r\nAdresse:%X Limite:%hX\r\n", idtreg.base,
|
2018-09-27 17:47:27 +02:00
|
|
|
(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);
|
2018-10-04 14:55:41 +02:00
|
|
|
u32 type = desc[index].type & 0x0F00;
|
2018-10-07 12:57:38 +02:00
|
|
|
u8 *typestr1, *typestr2;
|
2018-10-04 14:55:41 +02:00
|
|
|
if (i>=32 & i<=39)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr1="IRQ master";
|
2018-10-04 14:55:41 +02:00
|
|
|
else if (i>=96 & i<=103)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr1="IRQ slave ";
|
2018-10-04 14:55:41 +02:00
|
|
|
else if (i<19)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr1="EXCEPTION ";
|
2018-10-04 14:55:41 +02:00
|
|
|
else
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr1="INTERRUPT ";
|
2018-09-27 17:47:27 +02:00
|
|
|
if (type == INTGATE)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr2="INTGATE";
|
2018-09-27 17:47:27 +02:00
|
|
|
else if (type == TRAPGATE)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr2="TRAPGATE";
|
2018-09-27 17:47:27 +02:00
|
|
|
else if (type == TASKGATE)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr2="TASKGATE";
|
2018-09-27 17:47:27 +02:00
|
|
|
else if (type == CALLGATE)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr2="CALLGATE";
|
2018-09-27 17:47:27 +02:00
|
|
|
else if (type == LDTDES)
|
2018-10-07 12:57:38 +02:00
|
|
|
typestr2="LDTDES";
|
2018-09-27 17:47:27 +02:00
|
|
|
else
|
|
|
|
print("inconnu");
|
2018-10-07 12:57:38 +02:00
|
|
|
printf("%s % hu %hY:%Y - %s\r\n", typestr1, i++, select, offset, typestr2);
|
|
|
|
|
2018-09-27 17:47:27 +02:00
|
|
|
if (i % 32 == 0) {
|
|
|
|
print("\r\n<Appuyez sur une touche>\r\n");
|
|
|
|
waitascii();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
2018-09-27 17:47:27 +02:00
|
|
|
|
2018-09-17 18:17:11 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* Lit les descripteurs GDT et les affiche */
|
|
|
|
|
|
|
|
int readgdt()
|
|
|
|
{
|
2018-09-27 17:47:27 +02:00
|
|
|
u32 index;
|
|
|
|
struct gdtr gdtreg;
|
|
|
|
sgdt(&gdtreg);
|
2018-10-04 14:55:41 +02:00
|
|
|
printf("Information sur la GDT\r\nAdresse:%X Limite:%hX\r\n", gdtreg.base, gdtreg.limite);
|
|
|
|
for (index = 0; index < gdtreg.limite ; index+=sizeof(gdtdes)) {
|
|
|
|
if (!isdesvalid(index))
|
|
|
|
printf("\033[31m");
|
|
|
|
printf("SEL =%hY %Y %Y DPL=%d %cS%d [%c%c%c] %h ub\033[0m\r\n",index,getdesbase(index),getdeslimit(index),getdesdpl(index),getdestype(index),getdessize(index),getdesbit3(index),getdesbit2(index),getdesbit1(index),getdesalign(index));
|
2018-09-27 17:47:27 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Detecte et affiche les information sur le CPU */
|
|
|
|
|
|
|
|
int detectcpu()
|
|
|
|
{
|
2018-09-27 17:47:27 +02:00
|
|
|
cpuinfo cpu;
|
|
|
|
u8 noproc[] = "\033[31mInconnu\033[0m\000";
|
|
|
|
strcpy(&noproc, &cpu.detectedname);
|
2018-09-17 18:17:11 +02:00
|
|
|
getcpuinfos(&cpu);
|
2018-09-27 17:47:27 +02:00
|
|
|
printf
|
|
|
|
("\r\nDetection du processeur\r\033[1m Revision \t:%d\r Modele \t:%d\r Famille \t:%d\r Nom cpuid\t:%s\rJeux d'instruction\t:%s\033[0m\r\n\000",
|
|
|
|
cpu.stepping, cpu.models, cpu.family, &cpu.detectedname,
|
|
|
|
&cpu.techs);
|
|
|
|
return 0;
|
2018-09-17 18:17:11 +02:00
|
|
|
}
|
2018-09-28 20:35:51 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|