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 char u8;
typedef unsigned short u16; typedef unsigned short u16;
typedef unsigned int u32; typedef unsigned int u32;
typedef unsigned long int u64;
typedef char s8; typedef char s8;
typedef short s16; typedef short s16;
typedef int s32; typedef int s32;
typedef long int s64;
typedef int bool; typedef int bool;
extern char ctype[]; extern char ctype[];

View File

@ -12,12 +12,12 @@ void gotoscr(u16 x,u16 y);
void useplane(u8 plan); void useplane(u8 plan);
u8 getfont(); u8 getfont();
void setfont(u8 num); void setfont(u8 num);
void waitvretrace (void); void waitvretrace ();
void waithretrace (void); void waithretrace ();
void enablecursor (void); void enablecursor ();
void disablecursor (void); void disablecursor ();
void enablescroll (void); void enablescroll ();
void disablescroll (void); void disablescroll ();
void (*writepxl)(u16 x, u16 y, u32 c); void (*writepxl)(u16 x, u16 y, u32 c);
void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib); void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib);
void (*fill)(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 outregsame(u16 port,u8 *src,u16 num);
void inreg(u16 port,u8 *src,u16 num); void inreg(u16 port,u8 *src,u16 num);
void inregsame(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 print(u8* string);
u32 printf (const u8 *string, ...); u32 printf (const u8 *string, ...);
void changevc(u8 vc); void changevc(u8 vc);
u8* itoa(u32 num, u8* str, u8 base, u8 achar); u8* itoa(u32 num, u8* str, u8 base, u32 dim, u8 achar);
u8* sitoa(int num, u8* str); u8* sitoa(int num, u8* str, u32 dim);

View File

@ -141,56 +141,59 @@ void dump_regs()
u16 fs = 0; u16 fs = 0;
u16 gs = 0; u16 gs = 0;
u16 ss = 0; u16 ss = 0;
u32 flags = 0; u32 cr0 = 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 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), [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), [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, printf("EAX=%X EBX=%X ECX=%x EDX=%X\r\n",eax,ebx,ecx,edx);
ecx, edx); printf("ESI=%X EDI=%X ESP=%X EBP=%X\r\n",esi,edi,esp,ebp);
printf("esi=%x edi=%x\r\n", esi, edi); printf(" CS=%hX DS=%hX ES=%hX FS=%hX GS=%hX SS=%hX\r\n",cs,ds,es,fs,gs,ss);
printf("cs=%x ds=%x es=%x fs=%x gs=%x\r\n", printf("CR0=%X CR1=N/A CR2=%X CR3=%X CR4=%X\r\n",cr0,cr2,cr3,cr4);
cs, ds, es, fs, gs);
printf("ss=%x esp=%x ebp=%x\r\n", ss, esp, ebp);
asm("pushf ;" "pop %[f1] ;": 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"); printf(" (C1");
else else
printf(" (C0"); printf(" (C0");
if (flags & (1 << 2)) // Parity if (eflags & (1 << 2)) // Parity
printf(" P1"); printf(" P1");
else else
printf(" P0"); printf(" P0");
if (flags & (1 << 4)) // Adjust if (eflags & (1 << 4)) // Adjust
printf(" A1"); printf(" A1");
else else
printf(" A0"); printf(" A0");
if (flags & (1 << 6)) // Zero if (eflags & (1 << 6)) // Zero
printf(" Z1"); printf(" Z1");
else else
printf(" Z0"); printf(" Z0");
if (flags & (1 << 7)) // Sign if (eflags & (1 << 7)) // Sign
printf(" S1"); printf(" S1");
else else
printf(" S0"); printf(" S0");
if (flags & (1 << 11)) // Overflow if (eflags & (1 << 11)) // Overflow
printf(" O1)\n"); printf(" O1)\n");
else else
printf(" O0)\n"); printf(" O0)\n");
printf("STACK\r\n"); printf("STACK\r\n");
for (u8 i = 0; i < 25; i++) 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 "asm.h"
#include "memory.h" #include "memory.h"
#include "keyboard.h" #include "keyboard.h"
#include "vga.h"
#include "video.h" #include "video.h"
static u8 bufferscan[256] = { 0 }; static u8 bufferscan[256] = { 0 };
@ -208,29 +208,37 @@ unsigned convert(u32 keypressed)
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if (key == SCAN_CTRL) { else if (key == SCAN_CTRL) {
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) { else if (key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
kbdstatus |= STATUS_SHIFT; kbdstatus |= STATUS_SHIFT;
return 0; return 0;
} }
if ((key >= SCAN_F1) && (key <= SCAN_F8)) { else if ((key >= SCAN_F1) && (key <= SCAN_F8)) {
changevc(key - SCAN_F1); 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 */ /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
if (key == SCAN_SCROLLLOCK) { else if (key == SCAN_SCROLLLOCK) {
kbdstatus ^= STATUS_SCRL; kbdstatus ^= STATUS_SCRL;
goto LEDS; goto LEDS;
} }
if (key == SCAN_NUMLOCK) { else if (key == SCAN_NUMLOCK) {
kbdstatus ^= STATUS_NUM; kbdstatus ^= STATUS_NUM;
goto LEDS; goto LEDS;
} }
if (key == SCAN_CAPSLOCK) { else if (key == SCAN_CAPSLOCK) {
kbdstatus ^= STATUS_CAPS; kbdstatus ^= STATUS_CAPS;
LEDS: LEDS:
outkbd(0x60, 0xED); /* "mise a jour des LEDS */ outkbd(0x60, 0xED); /* "mise a jour des LEDS */

View File

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

View File

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

View File

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

View File

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