feat: debogage de printf et modification de dump_regs

This commit is contained in:
Nicolas Hordé 2018-08-30 01:07:28 +02:00
parent ca1f1c18a8
commit 0c8419c91b
9 changed files with 152 additions and 95 deletions

View File

@ -25,9 +25,11 @@ typedef unsigned long long UQWORD;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long int u64;
typedef char s8;
typedef short s16;
typedef int s32;
typedef long int s64;
typedef int bool;
extern char ctype[];

View File

@ -12,12 +12,12 @@ void gotoscr(u16 x,u16 y);
void useplane(u8 plan);
u8 getfont();
void setfont(u8 num);
void waitvretrace (void);
void waithretrace (void);
void enablecursor (void);
void disablecursor (void);
void enablescroll (void);
void disablescroll (void);
void waitvretrace ();
void waithretrace ();
void enablecursor ();
void disablecursor ();
void enablescroll ();
void disablescroll ();
void (*writepxl)(u16 x, u16 y, u32 c);
void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib);
void (*fill)(u8 attrib);
@ -39,3 +39,5 @@ void outreg(u16 port,u8 *src,u16 num);
void outregsame(u16 port,u8 *src,u16 num);
void inreg(u16 port,u8 *src,u16 num);
void inregsame(u16 port,u8 *src,u16 num);
u8 nextvmode();
u8 getvmode();

View File

@ -16,6 +16,6 @@ void putchar(u8 thechar);
u32 print(u8* string);
u32 printf (const u8 *string, ...);
void changevc(u8 vc);
u8* itoa(u32 num, u8* str, u8 base, u8 achar);
u8* sitoa(int num, u8* str);
u8* itoa(u32 num, u8* str, u8 base, u32 dim, u8 achar);
u8* sitoa(int num, u8* str, u32 dim);

View File

@ -141,56 +141,59 @@ void dump_regs()
u16 fs = 0;
u16 gs = 0;
u16 ss = 0;
u32 flags = 0;
asm("movl %%eax, %[a1] ;" "movl %%ebx, %[b1] ;" "movl %%ecx, %[c1] ;" "movl %%edx, %[d1] ;" "movl %%esi, %[e1] ;" "movl %%edi, %[f1] ;" "movl %%esp, %[g1] ;" "movl %%ebp, %[h1] ;" "movw %%cs, %[i1] ;" "movw %%ds, %[j1] ;" "movw %%es, %[k1] ;" "movw %%fs, %[l1] ;" "movw %%gs, %[m1] ;" "movw %%ss, %[n1] ;":
u32 cr0 = 0;
u32 cr1 = 0;
u32 cr2 = 0;
u32 cr3 = 0;
u32 cr4 = 0;
u32 eflags = 0;
asm("movl %%eax, %[a1] ;" "movl %%ebx, %[b1] ;" "movl %%ecx, %[c1] ;" "movl %%edx, %[d1] ;" "movl %%esi, %[e1] ;" "movl %%edi, %[f1] ;" "movl %%esp, %[g1] ;" "movl %%ebp, %[h1] ;" "movw %%cs, %[i1] ;" "movw %%ds, %[j1] ;" "movw %%es, %[k1] ;" "movw %%fs, %[l1] ;" "movw %%gs, %[m1] ;" "movw %%ss, %[n1] ;" "mov %%cr0, %%eax ;" "mov %%eax, %[o1] ;" "mov %%cr2, %%eax ;" "mov %%eax, %[p1] ;" "mov %%cr3, %%eax ;" "mov %%eax, %[q1] ;" "mov %%cr4, %%eax ;" "mov %%eax,%[r1] ;":
[a1] "=m"(eax),[b1] "=m"(ebx),[c1] "=m"(ecx),[d1] "=m"(edx),[e1] "=m"(esi),
[f1] "=m"(edi),[g1] "=m"(ebp),[h1] "=m"(esp),[i1] "=m"(cs),[j1] "=m"(ds),
[k1] "=m"(es),[l1] "=m"(fs),[m1] "=m"(gs),[n1] "=m"(ss));
[k1] "=m"(es),[l1] "=m"(fs),[m1] "=m"(gs),[n1] "=m"(ss), [o1] "=m"(cr0),[p1] "=m"(cr2),[q1] "=m"(cr3), [r1] "=m"(cr4));
printf("eax=%x ebx=%x ecx=%x eax=%x\r\n", eax, ebx,
ecx, edx);
printf("esi=%x edi=%x\r\n", esi, edi);
printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n",
cs, ds, es, fs, gs);
printf("ss=%x esp=%x ebp=%x\r\n", ss, esp, ebp);
printf("EAX=%X EBX=%X ECX=%x EDX=%X\r\n",eax,ebx,ecx,edx);
printf("ESI=%X EDI=%X ESP=%X EBP=%X\r\n",esi,edi,esp,ebp);
printf(" CS=%hX DS=%hX ES=%hX FS=%hX GS=%hX SS=%hX\r\n",cs,ds,es,fs,gs,ss);
printf("CR0=%X CR1=N/A CR2=%X CR3=%X CR4=%X\r\n",cr0,cr2,cr3,cr4);
asm("pushf ;" "pop %[f1] ;":
[f1] "=m"(flags));
[f1] "=m"(eflags));
printf("FLAGS");
printf("EFLAGS=%X",eflags);
if (flags & (1 << 0)) // Carry
if (eflags & (1 << 0)) // Carry
printf(" (C1");
else
printf(" (C0");
if (flags & (1 << 2)) // Parity
if (eflags & (1 << 2)) // Parity
printf(" P1");
else
printf(" P0");
if (flags & (1 << 4)) // Adjust
if (eflags & (1 << 4)) // Adjust
printf(" A1");
else
printf(" A0");
if (flags & (1 << 6)) // Zero
if (eflags & (1 << 6)) // Zero
printf(" Z1");
else
printf(" Z0");
if (flags & (1 << 7)) // Sign
if (eflags & (1 << 7)) // Sign
printf(" S1");
else
printf(" S0");
if (flags & (1 << 11)) // Overflow
if (eflags & (1 << 11)) // Overflow
printf(" O1)\n");
else
printf(" O0)\n");
printf("STACK\r\n");
for (u8 i = 0; i < 25; i++)
printf("+%d\t\t%x\r\n", i, viewstack(i * 4));
printf("+%d\t\t%X\r\n", i, viewstack(i * 4));
}

View File

@ -3,7 +3,7 @@
#include "asm.h"
#include "memory.h"
#include "keyboard.h"
#include "vga.h"
#include "video.h"
static u8 bufferscan[256] = { 0 };
@ -208,29 +208,37 @@ unsigned convert(u32 keypressed)
kbdstatus |= STATUS_CTRL;
return 0;
}
if (key == SCAN_CTRL) {
else if (key == SCAN_CTRL) {
kbdstatus |= STATUS_CTRL;
return 0;
}
if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
else if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
kbdstatus |= STATUS_SHIFT;
return 0;
}
if ((key >= SCAN_F1) && (key <= SCAN_F8)) {
else if ((key >= SCAN_F1) && (key <= SCAN_F8)) {
changevc(key - SCAN_F1);
}
else if (key == SCAN_F9) {
dump_regs();
}
else if (key == SCAN_F10) {
nextvmode();
}
/* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
if (key == SCAN_SCROLLLOCK) {
else if (key == SCAN_SCROLLLOCK) {
kbdstatus ^= STATUS_SCRL;
goto LEDS;
}
if (key == SCAN_NUMLOCK) {
else if (key == SCAN_NUMLOCK) {
kbdstatus ^= STATUS_NUM;
goto LEDS;
}
if (key == SCAN_CAPSLOCK) {
else if (key == SCAN_CAPSLOCK) {
kbdstatus ^= STATUS_CAPS;
LEDS:
outkbd(0x60, 0xED); /* "mise a jour des LEDS */

View File

@ -12,7 +12,7 @@ u8 log2(u32 n) {
logValue++;
n >>= 1;
}
return logValue;
return logValue+1;
}
/******************************************************************************/

View File

@ -150,7 +150,7 @@ void unsplit()
/* Attend la retrace verticale */
void waitvretrace(void)
void waitvretrace()
{
while ((inb(state) & 8) == 0) ;
}
@ -159,7 +159,7 @@ void waitvretrace(void)
/* Attend la retrace horizontale */
void waithretrace(void)
void waithretrace()
{
while ((inb(state) & 1) == 0) ;
}
@ -168,7 +168,7 @@ void waithretrace(void)
/* Active l'affichage du curseur de texte */
void enablecursor(void)
void enablecursor()
{
u8 curs;
/* active le curseur hardware */
@ -181,7 +181,7 @@ void enablecursor(void)
/* Desactive l'affichage du curseur de texte */
void disablecursor(void)
void disablecursor()
{
u8 curs;
/* Desactive le curseur hardware */
@ -194,7 +194,7 @@ void disablecursor(void)
/* Active le scrolling en cas de débordement d'écran */
void enablescroll(void)
void enablescroll()
{
scrolling = true;
}
@ -203,7 +203,7 @@ void enablescroll(void)
/* Desactive le scrolling en cas de débordement d'écran */
void disablescroll(void)
void disablescroll()
{
scrolling = false;
}
@ -471,6 +471,28 @@ void writepxl_8bitsunchain(u16 x, u16 y, u32 c)
*off = c;
}
/*******************************************************************************/
/* Met le mode video suivant */
u8 nextvmode()
{
u8 mode=getvmode();
mode++;
if (mode>=0x80) {
if (mode>maxgraphmode)
mode=0x0;
}
else {
if (mode>maxtextmode)
mode=0x80;
}
setvmode(mode);
return mode;
}
/*******************************************************************************/
/* Change le mode video courant */
@ -591,7 +613,7 @@ u32 setvmode(u8 mode)
/* Récupère le mode vidéo en cours */
u8 getvmode(void)
u8 getvmode()
{
return vmode;
}

View File

@ -309,13 +309,13 @@ u32 print(u8 * string)
u32 printf(const u8 *string, ...)
{
va_list args;
u8 achar,temp;
u32 sizes[]={0xFF,0xFFFF,0xFFFFFFFF};
u8 asize,charadd;
u8 strbase2 = "b\000";
u8 strbase8 = "o\000";
u8 strbase16 = "h\000";
u8 strbase2[] = "b\000";
u8 strbase8[] = "o\000";
u8 strbase16[] = "h\000";
u8 hexadecimal[]="*0x\000";
u8 achar,temp;
u8 asize,charadd;
u8 buffer[buffersize];
u8 *str = string;
u8 *strtemp;
@ -331,39 +331,45 @@ u32 printf(const u8 *string, ...)
putchar(achar);
counter++;
asize=2;
charadd=0;
charadd=0xFF;
}
else if (achar == '%' || flag)
{
++i;
if (!flag) ++i;
achar = *(str + i);
switch(achar)
{
case '0':
charadd='0';
flag=true;
break;
case ' ':
charadd=' ';
flag=true;
break;
case 'h':
asize--;
flag=true;
break;
case 'l':
asize++;
flag=true;
break;
case 'u':
num = (u32)va_arg(args, int);
num&=sizes[asize];
itoa(num, buffer, 10, charadd);
counter += print(buffer);
if (charadd==0xFF)
charadd='0';
itoa(num, &buffer, 10, sizes[asize], charadd);
counter += print(&buffer);
flag=false;
break;
break;
case 'o':
num = (u32)va_arg(args, int);
num&=sizes[asize];
itoa(num, buffer, 8, charadd);
counter += print(buffer)+1;
print(strbase8);
if (charadd==0xFF)
charadd='0';
itoa(num, &buffer, 8, sizes[asize], charadd);
counter += print(&buffer)+1;
print(&strbase8);
flag=false;
break;
case 'c':
@ -375,9 +381,10 @@ u32 printf(const u8 *string, ...)
case 'd':
case 'i':
num = (int)va_arg(args, int);
num&=sizes[asize];
sitoa(num, buffer);
counter += print(buffer);
if (charadd==0xFF)
charadd=' ';
sitoa(num, &buffer, sizes[asize]);
counter += print(&buffer);
flag=false;
break;
case 's':
@ -387,29 +394,32 @@ u32 printf(const u8 *string, ...)
break;
case 'p':
num = (u32)va_arg(args, int);
num&=sizes[asize];
print(hexadecimal);
itoa(num, buffer, 16, '0');
counter += print(buffer)+2;
if (charadd==0xFF)
charadd='0';
print(&hexadecimal);
itoa(num, buffer, 16, sizes[asize], '0');
counter += print(&buffer)+2;
flag=false;
break;
case 'x':
case 'X':
num = (u32)va_arg(args, int);
num&=sizes[asize];
itoa(num, buffer, 16, charadd);
counter += print(buffer)+1;
if (charadd==0xFF)
charadd='0';
itoa(num, &buffer, 16, sizes[asize], charadd);
if (achar=='X')
strtoupper(buffer);
print(strbase16);
strtoupper(&buffer);
counter += print(&buffer)+1;
print(&strbase16);
flag=false;
break;
case 'b':
num = (u32)va_arg(args, int);
num&=sizes[asize];
itoa(num, buffer, 2, charadd);
counter += print(buffer)+1;
print(strbase2);
if (charadd==0xFF)
charadd='0';
itoa(num, &buffer, 2, sizes[asize], charadd);
counter += print(&buffer)+1;
print(&strbase2);
flag=false;
break;
default:
@ -425,39 +435,42 @@ u32 printf(const u8 *string, ...)
/* converti un entier non signé en chaine de caractère */
u8* itoa(u32 num, u8* str, u8 base, u8 achar)
u8* itoa(u32 orignum, u8* str, u8 base, u32 dim, u8 achar)
{
u32 pointer = 0, i=0, size=0;
if (num == 0)
u32 sizes[]={0xFF,0xFFFF,0xFFFFFFFF};
u8 *pointer = str, i, size=0;
u32 num=orignum;
num&=dim;
if (num == 0 && (achar==0))
{
str[pointer++] = '0';
str[pointer] = '\0';
*(pointer++) = '0';
*pointer = '\000';
return str;
}
switch (base)
{
case 2:
size=log2(num);
size=log2(dim);
break;
case 8:
size=log2(num)/4;
size=log2(dim)/2;
break;
case 10:
size=log10(num);
size=log10(dim);
break;
case 16:
size=log2(num)/2;
size=log2(dim)/4;
break;
}
for(i=0;i<size;size++)
for(i=0;i<size;i++)
{
u32 result = num % (u32)base;
str[pointer++] = (result > 9)? (result-10) + 'a' : result + '0';
*(pointer++) = (result > 9)? (result-10) + 'a' : result + '0';
num = num / (u32)base;
if ((num==0) && (achar==0))
break;
}
str[pointer] = '\0';
*pointer = '\000';
strinvert(str);
return str;
}
@ -466,14 +479,15 @@ u8* itoa(u32 num, u8* str, u8 base, u8 achar)
/* converti un entier en chaine de caractère */
u8* sitoa(int num, u8* str)
u8* sitoa(int num, u8* str, u32 dim)
{
u32 i = 0;
u8 *pointer = str;
bool isNegative = false;
num&=dim;
if (num == 0)
{
str[i++] = '0';
str[i] = '\0';
*pointer++ = '0';
*pointer = '\000';
return str;
}
if (num < 0)
@ -484,12 +498,12 @@ u8* sitoa(int num, u8* str)
while (num != 0)
{
u32 result = num % 10;
str[i++] = (result > 9)? (result-10) + 'a' : result + '0';
*(pointer++) = (result > 9)? (result-10) + 'a' : result + '0';
num = num/ 10;
}
if (isNegative)
str[i++] = '-';
str[i] = '\0';
*(pointer++) = '-';
*pointer = '\000';
strinvert(str);
return str;
}

View File

@ -76,17 +76,23 @@ int main(void)
static u8 cmd_clear[]="CLEAR\000";
static u8 cmd_detectcpu[]="DETECTCPU\000";
static u8 cmd_test2d[]="TEST2D\000";
static u8 cmd_regs[]="REGS\000";
while (true) {
print("\r\n# ");
getstring(&field);
print("\r\n");
if (strgetnbitems(&field,' ')<1) continue;
strgetitem(&field, &item, ' ', 0);
strtoupper(&item);
if (strcmp(&item,&cmd_reboot)==0) reboot();
if (strcmp(&item,&cmd_mode)==0) setvmode(0x84);
if (strcmp(&item,&cmd_clear)==0) fill(0x00);
if (strcmp(&item,&cmd_detectcpu)==0) detectcpu();
if (strcmp(&item,&cmd_test2d)==0) test2d();
else if (strcmp(&item,&cmd_mode)==0) setvmode(0x84);
else if (strcmp(&item,&cmd_clear)==0) fill(0x00);
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
printf("Commande inconnue !\r\n\000");
}
}