feat: ajout de fonction v/s/printf et ajout de fonction de deboguage (desassemblage)

This commit is contained in:
Nicolas Hordé 2018-10-08 21:50:40 +02:00
parent 946355b687
commit bb21e15dc4
7 changed files with 2735 additions and 26 deletions

37
include/debug.h Normal file
View File

@ -0,0 +1,37 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "types.h"
#define opBufSz 32
#define decodeSIB() \
base = r32[*b&0x07]; \
indx = r32[(*b&0x38)>>3]; \
scale = ((*b&0xc0)>>6)*2; \
if(scale && !indx){ \
print("Invalid SIB byte."); \
return; \
}
#define setG() \
reg = (*b&0x38)>>3; \
if(!Gsz){ \
} else if(Gsz == 1){ \
G = r8[reg]; \
} else if(Gsz == 2){ \
G = r16[reg]; \
} else if(Gsz == 3){ \
G = r32[reg]; \
} else if(Gsz == 4){ \
if(reg < 8){ \
G = rseg[reg]; \
} else{ \
print("Invalid Mod R/M byte."); \
return; \
} \
} else{ \
print("Invalid Mod R/M byte."); \
return; \
}

View File

@ -20,3 +20,4 @@ int info();
int err();
int view();
int test(void);
int disasm(u8* commandline);

View File

@ -21,9 +21,14 @@ void putchar(u8 thechar);
void clearscreen(void);
u32 print(u8* string);
u32 printf (const u8 *string, ...);
u32 sprintf(u8 *variable, const u8 *string, ...);
u32 snprintf(u8 *variable, u32 maxsize, const u8 *string, ...);
u32 vprintf(const u8 * string, va_list args);
u32 vsprintf(u8 *variable, const u8 *string, va_list args);
u32 vsnprintf(u8 *variable, u32 maxsize, const u8 *string, va_list args);
void changevc(u8 vc);
u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar);
u8* sitoa(u64 num, u8 * str, u64 dim);
u8* rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf);
u8* rtoasingle(float num, u8 * str, u8 precisioni , u8 precisionf);
u32 format(const u8 * string, va_list args, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest);
u32 format(const u8 * string, va_list args, u32 maxsize, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest);

2562
lib/debug.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@
#include "shell.h"
#include "multiboot2.h"
#include "math.h"
#include "debug.h"
static command commands[] = {
{"reboot" , "", &rebootnow},
@ -26,6 +27,7 @@ static command commands[] = {
{"err" , "", &err},
{"test" , "", &test},
{"view" , "", &view},
{"disasm" , "", &disasm}
};
/*******************************************************************************/
@ -64,6 +66,30 @@ int test(void)
print("Fonction de test !\r\n");
}
/*******************************************************************************/
/* Desassemble une zone de mémoire donnée */
int disasm(u8* commandline)
{
u8 arg[] = " \000";
u8* size;
u8* pointer;
if (strgetnbitems(commandline, ' ') < 3)
{
print("Syntaxe de la commande DISASM\r\ndisasm \33[32madresse taille\r\n\r\n \33[32madresse\33[0m\33[0m\33[25D\33[10C - Adresse a visualiser\r\n \33[32mtaille\33[0m\33[25D\33[10C - nombre d'octets a desassembler <256\r\n");
return;
}
strgetitem(commandline, &arg, ' ', 1);
size=pointer=strtoint(&arg);
strgetitem(commandline, &arg, ' ', 2);
size+=strtoint(&arg);
while(pointer<size)
{
pointer+=decode(pointer);
}
}
/*******************************************************************************/
/* Génère des exceptions */
@ -72,24 +98,73 @@ int view(u8* commandline)
u8 arg[] = " \000";
u32 address;
u8 size;
u8* pointer;
u8* pointerb;
u16* pointerw;
u32* pointerd;
u8 format;
u8 nbligne;
if (strgetnbitems(commandline, ' ') < 3)
{
print("Syntaxe de la commande VIEW\r\nview \33[32madresse taille\r\n\r\n \33[32madresse\33[0m - Adresse a visualiser\r\n \33[32mtaille\33[0m - nombre d'octets a visualiser <256\r\n");
print("Syntaxe de la commande VIEW\r\nview \33[32madresse taille [size] [nbligne]\r\n\r\n \33[32madresse\33[0m\33[0m\33[25D\33[10C - Adresse a visualiser\r\n \33[32mtaille\33[0m\33[25D\33[10C - nombre d'octets a visualiser <256\r\n \33[32mformat\33[0m\33[25D\33[10C - c (ascii) b (octet) w (mot) d (double mot)\r\n \33[32mnbligne\33[0m\33[25D\33[10C - nombre d'octets a visualiser par ligne\r\n");
return;
}
strgetitem(commandline, &arg, ' ', 1);
address=strtoint(&arg);
strgetitem(commandline, &arg, ' ', 2);
size=strtoint(&arg);
if (strgetnbitems(commandline, ' ') < 4)
format='b';
else {
strgetitem(commandline, &arg, ' ', 3);
format=arg[0];
}
switch (format) {
case 'c':
pointerb=address;
nbligne=12;
break;
case 'b':
pointerb=address;
nbligne=22;
break;
case 'w':
pointerw=address;
nbligne=13;
break;
case 'd':
pointerd=address;
nbligne=7;
break;
}
if (strgetnbitems(commandline, ' ') == 5)
{
strgetitem(commandline, &arg, ' ', 4);
nbligne=strtoint(&arg);
}
printf("Adresse %Y - % hhu",address,size);
pointer=address;
for(u32 i=0;i<size;i++) {
if (i%16==0)
printf("\r\n:%Y - ",pointer);
else
printf("%hhY ",*(pointer++));
}
for(u32 i=0;i<size;i++)
switch (format) {
case 'c':
if (i%nbligne==0)
printf("\r\n:%Y - ",pointerb);
printf("%hhY \33[40C%c\33[41D",*(pointerb),*(pointerb++));
break;
case 'b':
if (i%nbligne==0)
printf("\r\n:%Y - ",pointerb);
printf("%hhY ",*(pointerb++));
break;
case 'w':
if (i%nbligne==0)
printf("\r\n:%Y - ",pointerw);
printf("%hY ",*(pointerw++));
break;
case 'd':
if (i%nbligne==0)
printf("\r\n:%Y - ",pointerd);
printf("%Y ",*(pointerd++));
break;
}
}
/*******************************************************************************/
/* Génère des exceptions */
@ -100,7 +175,7 @@ int err(u8* commandline)
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");
print("Syntaxe de la commande ERR\r\nerr \33[32mexception\r\n\r\n exception\33[0m\33[25D\33[10C - code de l'exception\r\n");
return;
}
strgetitem(commandline, &arg, ' ', 1);
@ -214,7 +289,7 @@ int mode(u8* commandline)
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");
print("Syntaxe de la commande MODE\r\nmode \33[32mmodevideo\r\n\r\n modevideo\33[0m\33[25D\33[10C - mode video a initialiser (>0x80 = graphique)\r\n");
return;
}
strgetitem(commandline, &arg, ' ', 1);

View File

@ -306,13 +306,9 @@ void scroll_unchain(u8 lines, u8 attrib)
void scroll_chain(u8 lines, u8 attrib)
{
if (scrolling) {
memcpy((u8 *) basemem + activepage * pagesize +
linesize * 8 * lines,
(u8 *) basemem + activepage * pagesize,
pagesize - linesize * 8 * lines, 1);
memset((u8 *) (basemem + activepage * pagesize + pagesize -
linesize * 8 * lines), attrib & 0x0F,
linesize * 8 * lines, 1);
memcpy((u8 *) basemem + activepage * pagesize + linesize * 8 * lines,
(u8 *) basemem + activepage * pagesize, pagesize - linesize * 8 * lines, 1);
memset((u8 *) (basemem + activepage * pagesize + pagesize - linesize * 8 * lines), attrib & 0x0F, linesize * 8 * lines, 1);
}
}

View File

@ -326,6 +326,8 @@ u32 storestr(u8* src, u8** dest, u32 len) {
return len;
}
#define maxbuffersize 1024
/*******************************************************************************/
/* affiche une chaine de caractère formaté a l'ecran */
@ -333,7 +335,7 @@ u32 printf(const u8 * string, ...)
{
va_list args;
va_start(args, string);
format(string, args, &printstr, NULL);
vprintf(string, args);
va_end(args);
}
@ -344,18 +346,49 @@ u32 sprintf(u8 *variable, const u8 *string, ...)
{
va_list args;
va_start(args, string);
format(string, args, &storestr, variable);
vsprintf(variable, string, args);
va_end(args);
}
/*******************************************************************************/
/* met une chaine de caractère formaté dans une variable de taille fixée */
u32 snprintf(u8 *variable, u32 maxsize, const u8 *string, ...)
{
va_list args;
va_start(args, string);
vsnprintf(variable, maxsize, string, args);
va_end(args);
}
/*******************************************************************************/
/* affiche une chaine de caractère formaté a l'ecran depuis vararg */
u32 vprintf(const u8 * string, va_list args)
{
format(string, args, maxbuffersize, &printstr, NULL);
}
/*******************************************************************************/
/* met une chaine de caractère formaté dans une variable depuis vararg */
u32 vsprintf(u8 *variable, const u8 *string, va_list args)
{
format(string, args, maxbuffersize, &storestr, variable);
}
/*******************************************************************************/
/* met une chaine de caractère formaté dans une variable de taille fixée depuis vararg */
u32 vsnprintf(u8 *variable, u32 maxsize, const u8 *string, va_list args)
{
format(string, args, maxsize, &storestr, variable);
}
/*******************************************************************************/
/* affiche une chaine de caractère formaté a l'ecran */
#define maxsize 1024
u32 format(const u8 * string, va_list args, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest)
u32 format(const u8 * string, va_list args, u32 maxsize, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest)
{
u64 sizes[] = { 0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
u8 units[][4] = { "o\000\000", "kio", "mio", "gio", "tio", "pio" };
@ -365,7 +398,7 @@ u32 format(const u8 * string, va_list args, u32 (*fonction)(u8* src, u8** dest,
u8 hexadecimal[] = "*0x\000";
u8 achar, temp;
u8 asize, charadd, unit, precisioni, precisionf;
u8 buffer[maxsize];
u8 buffer[maxbuffersize];
u8* bufferend;
u32 buffersize;
u8 *str = string;