fix: ajout affichage des Float & Double dans printf, correction makefile et autre...

This commit is contained in:
Nicolas Hordé 2018-10-04 21:49:06 +02:00
parent b72b0c2f11
commit 9b421fd7cc
7 changed files with 182 additions and 32 deletions

View File

@ -11,3 +11,4 @@ u8 log2(u32 n);
u8 log10(u32 n);
unsigned long long __udivdi3 (unsigned long long num, unsigned long long den);
unsigned long long __umoddi3 (unsigned long long n, unsigned long long d);
u32 pow(u32 a, u8 n);

View File

@ -20,4 +20,5 @@ u32 printf (const u8 *string, ...);
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 precision);
u8* rtoasingle(float num, u8 * str, u8 precision);

View File

@ -176,7 +176,7 @@ void exception0()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("divide error",&dump);
cpuerror("#DE Divide error",&dump);
}
void exception1()
@ -188,12 +188,19 @@ void exception1()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("debug exception",&dump);
cpuerror("#DB Debug exception",&dump);
}
void exception2()
{
cpuerror("non-maskable hardware interrupt",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("NMI Non-maskable hardware interrupt",&dump);
}
void exception3()
@ -205,17 +212,31 @@ void exception3()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("INT3 instruction",&dump);
cpuerror("#BP INT3 instruction",&dump);
}
void exception4()
{
cpuerror("INTO instruction detected overflow",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#OF INTO instruction detected overflow",&dump);
}
void exception5()
{
cpuerror("BOUND instruction detected overrange",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#BR BOUND instruction detected overrange",&dump);
}
void exception6()
@ -227,27 +248,55 @@ void exception6()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("Invalid instruction opcode",&dump);
cpuerror("#UD Invalid instruction opcode",&dump);
}
void exception7()
{
cpuerror("no coprocessor",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#NM No coprocessor",&dump);
}
void exception8()
{
cpuerror("double fault",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#DF Double fault",&dump);
}
void exception9()
{
cpuerror("coprocessor segment overrun",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("Coprocessor segment overrun",&dump);
}
void exception10()
{
cpuerror("invalid task state segment (TSS)",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x28+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#TS Invalid task state segment (TSS)",&dump);
}
void exception11()
@ -259,12 +308,19 @@ void exception11()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("segment not present",&dump);
cpuerror("#NP Segment not present",&dump);
}
void exception12()
{
cpuerror("stack fault",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#SS Stack fault",&dump);
}
void exception13()
@ -276,7 +332,7 @@ void exception13()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("general protection fault (GPF)",&dump);
cpuerror("#GP General protection fault (GPF)",&dump);
}
void exception14()
@ -288,10 +344,10 @@ void exception14()
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
u8 *errorstring="page fault";
u8 *errorstring="#PF Page fault";
switch (current->error_code) {
case 0:
errorstring="page fault - Supervisory process tried to read a non-present page entry";
errorstring="Page fault - Supervisory process tried to read a non-present page entry";
break;
case 1:
errorstring="Page fault - Supervisory process tried to read a page and caused a protection fault";
@ -320,22 +376,50 @@ void exception14()
void exception15()
{
cpuerror("(reserved)",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("(reserved)",&dump);
}
void exception16()
{
cpuerror("coprocessor error",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#MF Coprocessor error",&dump);
}
void exception17()
{
cpuerror("alignment check",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#AC Alignment check",&dump);
}
void exception18()
{
cpuerror("machine check",NULL);
cli();
save_stack dump;
exception_stack_noerror *current = getESP()+0x30+sizeof(save_stack);
dump_cpu(&dump);
dump.eip=current->eip;
dump.cs=current->cs;
dump.esp=(current+1);
cpuerror("#MC Machine check",&dump);
}
/******************************************************************************/

View File

@ -46,6 +46,20 @@ unsigned long long __umoddi3 (unsigned long long n, unsigned long long d)
return n - d * __udivdi3 (n, d);
}
/******************************************************************************/
/* Fonction qui retourne la puissance n de a */
u32 pow(u32 a, u8 n) {
u32 r = 1;
while (n > 0) {
if (n & 1)
r *= a;
a *= a;
n >>= 1;
}
return r;
}
/******************************************************************************/
/* Fonction qui retourne le logarithme 2 */

View File

@ -372,6 +372,22 @@ u32 printf(const u8 * string, ...)
asize=3;
flag = true;
break;
case 'f':
if (asize==0) {
num = (u64) va_arg(args, u8);
break;
}
else if (asize==1) {
num = (u64) va_arg(args, u16);
break;
}
else if (asize==2)
rtoasingle((float)va_arg(args, double), &buffer, 5);
else
rtoadouble((double)va_arg(args, double), &buffer, 5);
counter += print(&buffer);
flag = false;
break;
case 'u':
if (asize==0)
num = (u64) va_arg(args, u8);
@ -507,6 +523,38 @@ u32 printf(const u8 * string, ...)
return counter;
}
/*******************************************************************************/
/* converti un réel signé en chaine de caractère */
u8 *rtoadouble(double num, u8 * str, u8 precision) {
u8 *pointer=str;
u32 integerpart = (int)num;
double fracpart = num - (double)integerpart;
pointer = sitoa(integerpart, str, 0xFFFFFFFF);
if (precision != 0)
{
*pointer = '.';
fracpart = fracpart * pow(10, precision);
sitoa((u32)fracpart, pointer+1, 0xFFFFFFFF);
}
}
/*******************************************************************************/
/* converti un réel signé en chaine de caractère */
u8 *rtoasingle(float num, u8 * str, u8 precision) {
u8 *pointer=str;
u32 integerpart = (int)num;
float fracpart = num - (float)integerpart;
pointer = sitoa(integerpart, str, 0xFFFFFFFF);
if (precision != 0)
{
*pointer = '.';
fracpart = fracpart * pow(10, precision);
sitoa((u32)fracpart, pointer+1, 0xFFFFFFFF);
}
return pointer;
}
/*******************************************************************************/
/* converti un entier non signé en chaine de caractère */
@ -518,7 +566,7 @@ u8 *itoa(u64 orignum, u8 * str, u8 base, u64 dim, u8 achar)
if (num == 0 && (achar == 0)) {
*(pointer++) = '0';
*pointer = '\000';
return str;
return pointer;
}
switch (base) {
case 2:
@ -548,7 +596,7 @@ u8 *itoa(u64 orignum, u8 * str, u8 base, u64 dim, u8 achar)
}
*pointer = '\000';
strinvert(str);
return str;
return pointer;
}
/*******************************************************************************/
@ -560,9 +608,9 @@ u8 *sitoa(u64 num, u8 * str, u64 dim)
bool isNegative = false;
num &= dim;
if (num == 0) {
*pointer++ = '0';
*(pointer++) = '0';
*pointer = '\000';
return str;
return pointer;
}
if ((((dim+1)>>1)&num)>0) {
isNegative = true;
@ -578,6 +626,6 @@ u8 *sitoa(u64 num, u8 * str, u64 dim)
*(pointer++) = '-';
*pointer = '\000';
strinvert(str);
return str;
return pointer;
}
/*******************************************************************************/

View File

@ -61,16 +61,16 @@ redebug: littleclean debug-system
debug64: debug-system64
debug-boot: all harddisk qemu-debug
debug-boot: bits32 harddisk qemu-debug
(sleep 2;cgdb -x ./debug/boot.txt)
debug-loader: all harddisk qemu-debug
debug-loader: bits32 harddisk qemu-debug
(sleep 2;cgdb -x ./debug/loader.txt)
debug-system: all harddisk qemu-debug
debug-system: bits32 harddisk qemu-debug
(sleep 2;cgdb -x ./debug/system.txt)
debug-system64: all uefi qemu-debug64
debug-system64: bits64 uefi qemu-debug64
(sleep 2;cgdb -x ./debug/system.txt)
qemu-debug:

View File

@ -103,11 +103,13 @@ int main(u32 magic, u32 addr)
warning();
else
ok();
print(" -Installation des appels systemes utilisateur");
printf(" -Installation des appels systemes utilisateur");
initsyscall();
ok();
float test=3.14f;
double test2=3.14;
printf(" -Test float & double %f %lf %f %f %f %f",test,test2,0.1212412544f,0.1f,15545487.0f,0.0001f);
retry:
shell();
}