cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

test_logic.c (1686B)


      1#include <stdio.h>
      2
      3int main(void)
      4{
      5    int a, b, c;
      6    int result;
      7
      8    b = 0x9743;
      9    c = 0x2;
     10    result = 0x25d0c;
     11    __asm
     12    ("l.sll    %0, %1, %2\n\t"
     13     : "=r"(a)
     14     : "r"(b), "r"(c)
     15    );
     16    if (a != result) {
     17        printf("sll error\n");
     18        return -1;
     19    }
     20
     21    b = 0x9743;
     22    result = 0x25d0c;
     23    __asm
     24    ("l.slli   %0, %1, 0x2\n\t"
     25     : "=r"(a)
     26     : "r"(b)
     27    );
     28    if (a != result) {
     29        printf("slli error\n");
     30        return -1;
     31    }
     32
     33    b = 0x7654;
     34    c = 0x03;
     35    result = 0xeca;
     36    __asm
     37    ("l.srl    %0, %1, %2\n\t"
     38     : "=r"(a)
     39     : "r"(b), "r"(c)
     40    );
     41
     42    b = 0x7654;
     43    result = 0xeca;
     44    __asm
     45    ("l.srli   %0, %1, 0x3\n\t"
     46     : "=r"(a)
     47     : "r"(b)
     48    );
     49    if (a != result) {
     50        printf("srli error\n");
     51        return -1;
     52    }
     53
     54    b = 0x80000001;
     55    c = 0x4;
     56    result = 0x18000000;
     57    __asm
     58    ("l.ror    %0, %1, %2\n\t"
     59     : "=r"(a)
     60     : "r"(b), "r"(c)
     61    );
     62    if (a != result) {
     63        printf("ror error\n");
     64        return -1;
     65    }
     66
     67    b = 0x80000001;
     68    result = 0x18000000;
     69    __asm
     70    ("l.rori   %0, %1, 0x4\n\t"
     71     : "=r"(a)
     72     : "r"(b)
     73    );
     74    if (a != result) {
     75        printf("rori error\n");
     76        return -1;
     77    }
     78
     79    b = 0x80000001;
     80    c = 0x03;
     81    result = 0xf0000000;
     82    __asm
     83    ("l.sra    %0, %1, %2\n\t"
     84     : "=r"(a)
     85     : "r"(b), "r"(c)
     86    );
     87    if (a != result) {
     88        printf("sra error\n");
     89        return -1;
     90    }
     91
     92    b = 0x80000001;
     93    result = 0xf0000000;
     94    __asm
     95    ("l.srai   %0, %1, 0x3\n\t"
     96     : "=r"(a)
     97     : "r"(b)
     98    );
     99    if (a != result) {
    100        printf("srai error\n");
    101        return -1;
    102    }
    103
    104    return 0;
    105}