fix: ajout de fonctionnalité sur printf (64bits) et corrections

This commit is contained in:
Nicolas Hordé 2018-09-28 00:03:45 +02:00
parent 4a4886886e
commit 60bf48343f
4 changed files with 66 additions and 18 deletions

View File

@ -17,5 +17,5 @@ u32 print(u8* string);
u32 printf (const u8 *string, ...);
void changevc(u8 vc);
u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar);
u8* sitoa(int num, u8* str, u32 dim);
u8* sitoa(u64 num, u8 * str, u64 dim);

View File

@ -13,12 +13,12 @@ u32 addr=infobloc;
struct multiboot_tag *tag;
unsigned size = *(unsigned *) addr;
if (addr & 7) print("Non aligne...");
printf(" Taille :%X\r\n", (u32)size);
printf(" Taille :% 4u\r\n", (u32)size);
for (tag = (struct multiboot_tag *) (addr + 8);
tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *) ((u8 *) tag + ((tag->size + 7) & ~7)))
{
printf ("Tag 0x%x, Taille 0x%x\r\n", tag->type, tag->size);
printf ("--- Tag % 4u, Taille % 4u\r\n", tag->type, tag->size);
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_CMDLINE:
@ -30,15 +30,15 @@ for (tag = (struct multiboot_tag *) (addr + 8);
((struct multiboot_tag_string *) tag)->string);
break;
case MULTIBOOT_TAG_TYPE_MODULE:
printf ("Module %x-%x. Command line %s\r\n",
printf ("Module %X-%X. Command line %s\r\n",
((struct multiboot_tag_module *) tag)->mod_start,
((struct multiboot_tag_module *) tag)->mod_end,
((struct multiboot_tag_module *) tag)->cmdline);
break;
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
printf ("Memoire basse : %uKB, memoire haute = %uKB\r\n",
((struct multiboot_tag_basic_meminfo *) tag)->mem_lower,
((struct multiboot_tag_basic_meminfo *) tag)->mem_upper);
printf ("Memoire basse : %H, memoire haute = %lH\r\n",
((struct multiboot_tag_basic_meminfo *) tag)->mem_lower<<10,
((u64)((struct multiboot_tag_basic_meminfo *) tag)->mem_upper)<<10);
break;
case MULTIBOOT_TAG_TYPE_BOOTDEV:
printf ("Peripherique de demarrage : %x,%u,%u\r\n\r\n",

View File

@ -308,14 +308,15 @@ u32 print(u8 * string)
u32 printf(const u8 * string, ...)
{
va_list args;
va_list args,argstemp;
u64 sizes[] = { 0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF };
u8 units[][4] = { "o\000\000", "kio", "mio", "gio", "tio", "pio" };
u8 strbase2[] = "0xb\000";
u8 strbase8[] = "0xo\000";
u8 strbase16[] = "0x\000";
u8 hexadecimal[] = "*0x\000";
u8 achar, temp;
u8 asize, charadd;
u8 asize, charadd, unit;
u8 buffer[buffersize];
u8 *str = string;
u8 *strtemp;
@ -353,6 +354,27 @@ u32 printf(const u8 * string, ...)
if (asize>3) asize=3;
flag = true;
break;
case '1':
case '2':
case '3':
asize=0;
flag = true;
break;
case '4':
case '5':
case '6':
case '7':
asize=1;
flag = true;
break;
case '8':
asize=2;
flag = true;
break;
case '9':
asize=3;
flag = true;
break;
case 'u':
if (asize==0)
num = (u64) va_arg(args, u8);
@ -390,6 +412,28 @@ u32 printf(const u8 * string, ...)
counter++;
flag = false;
break;
case 'H':
if (asize==0)
num = (u64) va_arg(args, u8);
else if (asize==1)
num = (u64) va_arg(args, u16);
else if (asize==2)
num = (u64) va_arg(args, u32);
else
num = (u64) va_arg(args, u64);
if (charadd == 0xFF)
charadd = ' ';
unit=0;
while(num>1024*10)
{
num=num>>10;
unit++;
}
sitoa(num, &buffer, sizes[asize]);
counter += print(&buffer);
print(units[unit]);
flag = false;
break;
case 'd':
case 'i':
if (asize==0)
@ -493,12 +537,16 @@ u8 *itoa(u64 orignum, u8 * str, u8 base, u64 dim, u8 achar)
break;
}
for (i = 0; i < size; i++) {
if (num == 0) {
if (achar == 0) break;
*(pointer++) = achar;
}
else
{
u64 result = num % (u32) base;
*(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;
}
}
*pointer = '\000';
strinvert(str);
@ -509,7 +557,7 @@ u8 *itoa(u64 orignum, u8 * str, u8 base, u64 dim, u8 achar)
/* converti un entier en chaine de caractère */
u8 *sitoa(int num, u8 * str, u32 dim)
u8 *sitoa(u64 num, u8 * str, u64 dim)
{
u8 *pointer = str;
bool isNegative = false;
@ -519,12 +567,12 @@ u8 *sitoa(int num, u8 * str, u32 dim)
*pointer = '\000';
return str;
}
if (num < 0) {
if ((((dim+1)>>1)&num)>0) {
isNegative = true;
num = -num;
num = (~num&dim)+1;
}
while (num != 0) {
u32 result = num % 10;
u64 result = num % 10;
*(pointer++) =
(result > 9) ? (result - 10) + 'a' : result + '0';
num = num / 10;

View File

@ -78,7 +78,7 @@ qemu-debug64:
(killall qemu-system-x86_64;qemu-system-x86_64 -m 1G -drive format=raw,file=./final/harddiskuefi.img.final --bios /usr/share/qemu/OVMF.fd -s -S &)
qemu:
(killall qemu-system-i386;qemu-system-i386 -m 5G -drive format=raw,file=./final/harddisk.img.final --enable-kvm -cpu host -s &)
(killall qemu-system-i386;qemu-system-i386 -m 1G -drive format=raw,file=./final/harddisk.img.final --enable-kvm -cpu host -s &)
qemu64:
(killall qemu-system-x86_64;qemu-system-x86_64 -m 1G -drive format=raw,file=./final/harddiskuefi.img.final --bios /usr/share/qemu/OVMF.fd --enable-kvm -cpu host -s &)