feat: ajout de fonction v/s/printf et ajout de fonction de deboguage (desassemblage)
This commit is contained in:
parent
946355b687
commit
bb21e15dc4
|
@ -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; \
|
||||||
|
}
|
||||||
|
|
|
@ -20,3 +20,4 @@ int info();
|
||||||
int err();
|
int err();
|
||||||
int view();
|
int view();
|
||||||
int test(void);
|
int test(void);
|
||||||
|
int disasm(u8* commandline);
|
||||||
|
|
|
@ -21,9 +21,14 @@ void putchar(u8 thechar);
|
||||||
void clearscreen(void);
|
void clearscreen(void);
|
||||||
u32 print(u8* string);
|
u32 print(u8* string);
|
||||||
u32 printf (const 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);
|
void changevc(u8 vc);
|
||||||
u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar);
|
u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar);
|
||||||
u8* sitoa(u64 num, u8 * str, u64 dim);
|
u8* sitoa(u64 num, u8 * str, u64 dim);
|
||||||
u8* rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf);
|
u8* rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf);
|
||||||
u8* rtoasingle(float 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);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
97
lib/shell.c
97
lib/shell.c
|
@ -12,6 +12,7 @@
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "multiboot2.h"
|
#include "multiboot2.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
static command commands[] = {
|
static command commands[] = {
|
||||||
{"reboot" , "", &rebootnow},
|
{"reboot" , "", &rebootnow},
|
||||||
|
@ -26,6 +27,7 @@ static command commands[] = {
|
||||||
{"err" , "", &err},
|
{"err" , "", &err},
|
||||||
{"test" , "", &test},
|
{"test" , "", &test},
|
||||||
{"view" , "", &view},
|
{"view" , "", &view},
|
||||||
|
{"disasm" , "", &disasm}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
@ -64,6 +66,30 @@ int test(void)
|
||||||
print("Fonction de test !\r\n");
|
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 */
|
/* Génère des exceptions */
|
||||||
|
|
||||||
|
@ -72,24 +98,73 @@ int view(u8* commandline)
|
||||||
u8 arg[] = " \000";
|
u8 arg[] = " \000";
|
||||||
u32 address;
|
u32 address;
|
||||||
u8 size;
|
u8 size;
|
||||||
u8* pointer;
|
u8* pointerb;
|
||||||
|
u16* pointerw;
|
||||||
|
u32* pointerd;
|
||||||
|
u8 format;
|
||||||
|
u8 nbligne;
|
||||||
if (strgetnbitems(commandline, ' ') < 3)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
strgetitem(commandline, &arg, ' ', 1);
|
strgetitem(commandline, &arg, ' ', 1);
|
||||||
address=strtoint(&arg);
|
address=strtoint(&arg);
|
||||||
strgetitem(commandline, &arg, ' ', 2);
|
strgetitem(commandline, &arg, ' ', 2);
|
||||||
size=strtoint(&arg);
|
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);
|
printf("Adresse %Y - % hhu",address,size);
|
||||||
pointer=address;
|
for(u32 i=0;i<size;i++)
|
||||||
for(u32 i=0;i<size;i++) {
|
switch (format) {
|
||||||
if (i%16==0)
|
case 'c':
|
||||||
printf("\r\n:%Y - ",pointer);
|
if (i%nbligne==0)
|
||||||
else
|
printf("\r\n:%Y - ",pointerb);
|
||||||
printf("%hhY ",*(pointer++));
|
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 */
|
/* Génère des exceptions */
|
||||||
|
@ -100,7 +175,7 @@ int err(u8* commandline)
|
||||||
u32 argint;
|
u32 argint;
|
||||||
if (strgetnbitems(commandline, ' ') < 2)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
strgetitem(commandline, &arg, ' ', 1);
|
strgetitem(commandline, &arg, ' ', 1);
|
||||||
|
@ -214,7 +289,7 @@ int mode(u8* commandline)
|
||||||
u32 argint;
|
u32 argint;
|
||||||
if (strgetnbitems(commandline, ' ') < 2)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
strgetitem(commandline, &arg, ' ', 1);
|
strgetitem(commandline, &arg, ' ', 1);
|
||||||
|
|
10
lib/vga.c
10
lib/vga.c
|
@ -306,13 +306,9 @@ void scroll_unchain(u8 lines, u8 attrib)
|
||||||
void scroll_chain(u8 lines, u8 attrib)
|
void scroll_chain(u8 lines, u8 attrib)
|
||||||
{
|
{
|
||||||
if (scrolling) {
|
if (scrolling) {
|
||||||
memcpy((u8 *) basemem + activepage * pagesize +
|
memcpy((u8 *) basemem + activepage * pagesize + linesize * 8 * lines,
|
||||||
linesize * 8 * lines,
|
(u8 *) basemem + activepage * pagesize, pagesize - linesize * 8 * lines, 1);
|
||||||
(u8 *) basemem + activepage * pagesize,
|
memset((u8 *) (basemem + activepage * pagesize + pagesize - linesize * 8 * lines), attrib & 0x0F, linesize * 8 * lines, 1);
|
||||||
pagesize - linesize * 8 * lines, 1);
|
|
||||||
memset((u8 *) (basemem + activepage * pagesize + pagesize -
|
|
||||||
linesize * 8 * lines), attrib & 0x0F,
|
|
||||||
linesize * 8 * lines, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
lib/video.c
47
lib/video.c
|
@ -326,6 +326,8 @@ u32 storestr(u8* src, u8** dest, u32 len) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define maxbuffersize 1024
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
/* affiche une chaine de caractère formaté a l'ecran */
|
/* affiche une chaine de caractère formaté a l'ecran */
|
||||||
|
|
||||||
|
@ -333,7 +335,7 @@ u32 printf(const u8 * string, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, string);
|
va_start(args, string);
|
||||||
format(string, args, &printstr, NULL);
|
vprintf(string, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,18 +346,49 @@ u32 sprintf(u8 *variable, const u8 *string, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, string);
|
va_start(args, string);
|
||||||
|
vsprintf(variable, string, args);
|
||||||
format(string, args, &storestr, variable);
|
|
||||||
va_end(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 */
|
/* affiche une chaine de caractère formaté a l'ecran */
|
||||||
|
|
||||||
#define maxsize 1024
|
u32 format(const u8 * string, va_list args, u32 maxsize, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest)
|
||||||
|
|
||||||
u32 format(const u8 * string, va_list args, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest)
|
|
||||||
{
|
{
|
||||||
u64 sizes[] = { 0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
|
u64 sizes[] = { 0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
|
||||||
u8 units[][4] = { "o\000\000", "kio", "mio", "gio", "tio", "pio" };
|
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 hexadecimal[] = "*0x\000";
|
||||||
u8 achar, temp;
|
u8 achar, temp;
|
||||||
u8 asize, charadd, unit, precisioni, precisionf;
|
u8 asize, charadd, unit, precisioni, precisionf;
|
||||||
u8 buffer[maxsize];
|
u8 buffer[maxbuffersize];
|
||||||
u8* bufferend;
|
u8* bufferend;
|
||||||
u32 buffersize;
|
u32 buffersize;
|
||||||
u8 *str = string;
|
u8 *str = string;
|
||||||
|
|
Loading…
Reference in New Issue