fix: gestion de ligne de commande pour le shell, centralisation des erreurs dans une fonction ERR
This commit is contained in:
parent
02948e1f0f
commit
5315bb549f
|
@ -5,7 +5,7 @@ typedef struct command
|
||||||
{
|
{
|
||||||
u8 name[64];
|
u8 name[64];
|
||||||
u8 params[64];
|
u8 params[64];
|
||||||
int (*function)(void)
|
int (*function)()
|
||||||
} command __attribute__ ((packed));
|
} command __attribute__ ((packed));
|
||||||
|
|
||||||
int rebootnow();
|
int rebootnow();
|
||||||
|
@ -17,12 +17,5 @@ int mode();
|
||||||
int clear();
|
int clear();
|
||||||
int regs();
|
int regs();
|
||||||
int info();
|
int info();
|
||||||
int pgfaultr();
|
int err();
|
||||||
int pgfaultw();
|
int test(void);
|
||||||
int divzerr();
|
|
||||||
int invalidop();
|
|
||||||
int segfault();
|
|
||||||
int int3();
|
|
||||||
int generalfault();
|
|
||||||
int breakpoint();
|
|
||||||
void testing(void);
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ u8 getcpuinfos(cpuinfo * proc)
|
||||||
boolean = &proc->mmx;
|
boolean = &proc->mmx;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < sizeof(msg); i++)
|
||||||
if (*(boolean++) == 1) {
|
if (*(boolean++) == 1) {
|
||||||
strcat(msg[i], &proc->techs);
|
strcat(msg[i], &proc->techs);
|
||||||
strcat(space, &proc->techs);
|
strcat(space, &proc->techs);
|
||||||
|
|
|
@ -372,6 +372,7 @@ void exception14()
|
||||||
errorstring="User process tried to write a page and caused a protection fault";
|
errorstring="User process tried to write a page and caused a protection fault";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// printf("%X",current->error_code);
|
||||||
sprintf(&completeerrorstring,"#PF Page fault - %s at adress %X",errorstring,dump.cr2);
|
sprintf(&completeerrorstring,"#PF Page fault - %s at adress %X",errorstring,dump.cr2);
|
||||||
cpuerror(&completeerrorstring,&dump);
|
cpuerror(&completeerrorstring,&dump);
|
||||||
}
|
}
|
||||||
|
|
203
lib/shell.c
203
lib/shell.c
|
@ -11,26 +11,20 @@
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "multiboot2.h"
|
#include "multiboot2.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
static command commands[] = {
|
static command commands[] = {
|
||||||
{"REBOOT" , "", &rebootnow},
|
{"reboot" , "", &rebootnow},
|
||||||
{"CLEAR" , "", &clear},
|
{"clear" , "", &clear},
|
||||||
{"MODE" , "", &mode},
|
{"mode" , "", &mode},
|
||||||
{"DETECTCPU" , "", &detectcpu},
|
{"detectcpu" , "", &detectcpu},
|
||||||
{"TEST2D" , "", &test2d},
|
{"test2d" , "", &test2d},
|
||||||
{"REGS" , "", ®s},
|
{"regs" , "", ®s},
|
||||||
{"GDT" , "", &readgdt},
|
{"gdt" , "", &readgdt},
|
||||||
{"IDT" , "", &readidt},
|
{"idt" , "", &readidt},
|
||||||
{"INFO" , "", &info},
|
{"info" , "", &info},
|
||||||
{"PGFAULTW" , "", &pgfaultw},
|
{"err" , "", &err},
|
||||||
{"PGFAULTR" , "", &pgfaultr},
|
{"test" , "", &test},
|
||||||
{"DIVZERR" , "", &divzerr},
|
|
||||||
{"INVALIDOP","", &invalidop},
|
|
||||||
{"INT3" , "", &int3},
|
|
||||||
{"GENERALFAULT" , "", &generalfault},
|
|
||||||
{"SEGFAULT","", &segfault},
|
|
||||||
{"BREAKPOINT","", &breakpoint},
|
|
||||||
{"TESTING","", &testing}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
@ -50,11 +44,11 @@ void shell()
|
||||||
if (strgetnbitems(&field, ' ') < 1)
|
if (strgetnbitems(&field, ' ') < 1)
|
||||||
continue;
|
continue;
|
||||||
strgetitem(&field, &item, ' ', 0);
|
strgetitem(&field, &item, ' ', 0);
|
||||||
strtoupper(&item);
|
strtolower(&item);
|
||||||
found = false;
|
found = false;
|
||||||
for (i = 0; i < sizeof(commands); i++) {
|
for (i = 0; i < sizeof(commands); i++) {
|
||||||
if (strcmp(&item, &commands[i].name) == 0) {
|
if (strcmp(&item, &commands[i].name) == 0) {
|
||||||
(*commands[i].function) ();
|
(*commands[i].function) (&field);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -64,77 +58,105 @@ void shell()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testing(void)
|
int test(void)
|
||||||
{
|
{
|
||||||
print("Fonction de test !\r\n");
|
print("Fonction de test !\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
/* Génère un breakpoint */
|
/* Génère des exceptions */
|
||||||
int breakpoint()
|
|
||||||
|
int err(u8* commandline)
|
||||||
{
|
{
|
||||||
print("Creation d'un breakpoint !\r\n");
|
u8 arg[] = " \000";
|
||||||
asm("movl %[address],%%dr0 \n \
|
u32 argint;
|
||||||
|
if (strgetnbitems(commandline, ' ') < 2)
|
||||||
|
{
|
||||||
|
print("Syntaxe de la commande ERR\r\nerr \33[32mexception\r\n\r\n exception\33[0m - code de l'exception\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strgetitem(commandline, &arg, ' ', 1);
|
||||||
|
argint=strtoint(&arg);
|
||||||
|
switch (argint)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
print("Creation d'une erreur de division par 0 !\r\n");
|
||||||
|
asm("movl $0x0,%ecx; divl %ecx");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
print("Creation d'un breakpoint !\r\n");
|
||||||
|
asm("movl %[address],%%dr0 \n \
|
||||||
movl $0x00000003, %%eax\n \
|
movl $0x00000003, %%eax\n \
|
||||||
movl %%eax, %%dr7"::[address] "a" (&testing):);
|
movl %%eax, %%dr7"::[address] "a" (&test):);
|
||||||
}
|
break;
|
||||||
|
case 2:
|
||||||
/*******************************************************************************/
|
print("NON GERE!\r\n");
|
||||||
/* Génère une interruption 3 */
|
break;
|
||||||
int int3()
|
case 3:
|
||||||
{
|
print("Creation d'une erreur interruption 3 !\r\n");
|
||||||
print("Creation d'une erreur interruption 3 !\r\n");
|
asm("int $0x3");
|
||||||
asm("int $0x3");
|
break;
|
||||||
}
|
case 4:
|
||||||
|
print("NON GERE!\r\n");
|
||||||
/*******************************************************************************/
|
break;
|
||||||
/* Génère une erreur general fault */
|
case 5:
|
||||||
int generalfault()
|
print("NON GERE!\r\n");
|
||||||
{
|
break;
|
||||||
print("Creation d'une erreur general fault !\r\n");
|
case 6:
|
||||||
asm("mov $0x666, %ax; ltr %ax");
|
print("Creation d'une erreur d'opcode invalide !\r\n");
|
||||||
}
|
asm("mov %cr7, %eax");
|
||||||
|
break;
|
||||||
/*******************************************************************************/
|
case 7:
|
||||||
/* Génère une erreur double fault */
|
print("NON GERE!\r\n");
|
||||||
int segfault()
|
break;
|
||||||
{
|
case 8:
|
||||||
print("Creation d'une erreur double fault !\r\n");
|
print("NON GERE!\r\n");
|
||||||
setidt(&segfault, SEL_KERNEL_CODE, INTGATE, 104);
|
break;
|
||||||
asm("int $0x68");
|
case 9:
|
||||||
}
|
print("NON GERE!\r\n");
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
/*******************************************************************************/
|
print("NON GERE!\r\n");
|
||||||
/* Génère une erreur d'opcode invalide */
|
break;
|
||||||
int invalidop()
|
case 11:
|
||||||
{
|
print("Creation d'une erreur segment non present !\r\n");
|
||||||
print("Creation d'une erreur d'opcode invalide !\r\n");
|
setidt(&err, SEL_KERNEL_CODE, INTGATE, 104);
|
||||||
asm("mov %cr7, %eax");
|
asm("int $0x68");
|
||||||
}
|
break;
|
||||||
|
case 12:
|
||||||
/*******************************************************************************/
|
print("NON GERE!\r\n");
|
||||||
/* Génère une erreur de division par 0 */
|
break;
|
||||||
int divzerr()
|
case 13:
|
||||||
{
|
print("Creation d'une erreur general fault !\r\n");
|
||||||
print("Creation d'une erreur de division par 0 !\r\n");
|
asm("mov $0x666, %ax; ltr %ax");
|
||||||
asm("movl $0x0,%ecx; divl %ecx");
|
break;
|
||||||
}
|
case 14:
|
||||||
|
if (random(0, 100)>50) {
|
||||||
/*******************************************************************************/
|
print("Creation d'une erreur de page en ecriture !\r\n");
|
||||||
/* Génère une erreur de page à l'adresse 0xE0000000 */
|
asm("movl $0x66666666,(0xE0000000)");
|
||||||
int pgfaultw()
|
}
|
||||||
{
|
else {
|
||||||
print("Creation d'une erreur de page !\r\n");
|
print("Creation d'une erreur de page en lecture !\r\n");
|
||||||
asm("movl $0x66666666,(0xE0000000)");
|
asm("movl (0xD0000000),%eax");
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
/*******************************************************************************/
|
case 15:
|
||||||
/* Génère une erreur de page à l'adresse 0xD0000000 */
|
print("NON GERE!\r\n");
|
||||||
int pgfaultr()
|
break;
|
||||||
{
|
case 16:
|
||||||
print("Creation d'une erreur de page !\r\n");
|
print("NON GERE!\r\n");
|
||||||
asm("movl (0xD0000000),%eax");
|
break;
|
||||||
|
case 17:
|
||||||
|
print("NON GERE!\r\n");
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
|
print("NON GERE!\r\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print("Exception qui n'existe pas !!!\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
@ -158,9 +180,18 @@ int regs()
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
/* Change le mode */
|
/* Change le mode */
|
||||||
int mode()
|
int mode(u8* commandline)
|
||||||
{
|
{
|
||||||
setvmode(0x84);
|
u8 arg[] = " \000";
|
||||||
|
u32 argint;
|
||||||
|
if (strgetnbitems(commandline, ' ') < 2)
|
||||||
|
{
|
||||||
|
print("Syntaxe de la commande MODE\r\nmode \33[32mmodevideo\r\n\r\n modevideo\33[0m - mode video a initialiser (>0x80 = graphique)\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strgetitem(commandline, &arg, ' ', 1);
|
||||||
|
argint=strtoint(&arg);
|
||||||
|
setvmode(argint);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue