agra-uni-bremen / riscv-vp

RISC-V Virtual Prototype
MIT License
139 stars 49 forks source link

printf for 64 Bit types #15

Closed tk-ka closed 2 years ago

tk-ka commented 3 years ago

printf() does not work correctly for 64 Bit integers. This might be related to #14 .

Test-code:

unsigned long int x = 0x123456789ABCDEF0;  
printf("64-Bit variable as decimal: %d \t %ld \t %lld \n", x, x, x);
printf("64-Bit variable as unsigned: %u \t %lu \t %llu \n", x, x, x);

Expected output:

64-Bit variable as decimal: -1698898192      1311768467463790320     1311768467463790320  
64-Bit variable as unsigned: 2596069104      1311768467463790320     1311768467463790320 

Observed output (code just added to main.c of printf test-software):

64-Bit Variable as decimal: -1698898192      -1698898192     6891036400 
64-Bit Variable as unsigned: 2596069104      2596069104  6891036400
CA92697 commented 3 years ago

That's a very interesting observation, that triggered an idea! I agree, it's indeed related to #14 so I will post it there. Just note that #14 is observed on my 32-bit architecture. Yours appears to be 64-bit since your 'long' is already 64 bits.

Cirromulus commented 2 years ago

see #14

So this is due to our very simple implementation of the Syscall emulation, that does not copy or re-align data structures for use with the host syscall interface. With an alignment of 64 bit, it works on most systems.