void test_misc(void)

{

    char table[256];

    long res, i;



    for(i=0;i<256;i++) table[i] = 256 - i;

    res = 0x12345678;

    asm ("xlat" : "=a" (res) : "b" (table), "0" (res));

    printf("xlat: EAX=" FMTLX "\n", res);



#if defined(__x86_64__)

#if 0

    {

        /* XXX: see if Intel Core2 and AMD64 behavior really

           differ. Here we implemented the Intel way which is not

           compatible yet with QEMU. */

        static struct __attribute__((packed)) {

            uint64_t offset;

            uint16_t seg;

        } desc;

        long cs_sel;



        asm volatile ("mov %%cs, %0" : "=r" (cs_sel));



        asm volatile ("push %1\n"

                      "call func_lret\n"

                      : "=a" (res)

                      : "r" (cs_sel) : "memory", "cc");

        printf("func_lret=" FMTLX "\n", res);



        desc.offset = (long)&func_lret;

        desc.seg = cs_sel;



        asm volatile ("xor %%rax, %%rax\n"

                      "rex64 lcall *(%%rcx)\n"

                      : "=a" (res)

                      : "c" (&desc)

                      : "memory", "cc");

        printf("func_lret2=" FMTLX "\n", res);



        asm volatile ("push %2\n"

                      "mov $ 1f, %%rax\n"

                      "push %%rax\n"

                      "rex64 ljmp *(%%rcx)\n"

                      "1:\n"

                      : "=a" (res)

                      : "c" (&desc), "b" (cs_sel)

                      : "memory", "cc");

        printf("func_lret3=" FMTLX "\n", res);

    }

#endif

#else

    asm volatile ("push %%cs ; call %1"

                  : "=a" (res)

                  : "m" (func_lret): "memory", "cc");

    printf("func_lret=" FMTLX "\n", res);



    asm volatile ("pushf ; push %%cs ; call %1"

                  : "=a" (res)

                  : "m" (func_iret): "memory", "cc");

    printf("func_iret=" FMTLX "\n", res);

#endif



#if defined(__x86_64__)

    /* specific popl test */

    asm volatile ("push $12345432 ; push $0x9abcdef ; pop (%%rsp) ; pop %0"

                  : "=g" (res));

    printf("popl esp=" FMTLX "\n", res);

#else

    /* specific popl test */

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0"

                  : "=g" (res));

    printf("popl esp=" FMTLX "\n", res);



    /* specific popw test */

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0"

                  : "=g" (res));

    printf("popw esp=" FMTLX "\n", res);

#endif

}

void test_misc(void)

{

    char table[256];

    long res, i;



    for(i=0;i<256;i++) table[i] = 256 - i;

    res = 0x12345678;

    asm ("xlat" : "=a" (res) : "b" (table), "0" (res));

    printf("xlat: EAX=" FMTLX "\n", res);



#if defined(__x86_64__)

#if 0

    {

        





        static struct __attribute__((packed)) {

            uint64_t offset;

            uint16_t seg;

        } desc;

        long cs_sel;



        asm volatile ("mov %%cs, %0" : "=r" (cs_sel));



        asm volatile ("push %1\n"

                      "call func_lret\n"

                      : "=a" (res)

                      : "r" (cs_sel) : "memory", "cc");

        printf("func_lret=" FMTLX "\n", res);



        desc.offset = (long)&func_lret;

        desc.seg = cs_sel;



        asm volatile ("xor %%rax, %%rax\n"

                      "rex64 lcall *(%%rcx)\n"

                      : "=a" (res)

                      : "c" (&desc)

                      : "memory", "cc");

        printf("func_lret2=" FMTLX "\n", res);



        asm volatile ("push %2\n"

                      "mov $ 1f, %%rax\n"

                      "push %%rax\n"

                      "rex64 ljmp *(%%rcx)\n"

                      "1:\n"

                      : "=a" (res)

                      : "c" (&desc), "b" (cs_sel)

                      : "memory", "cc");

        printf("func_lret3=" FMTLX "\n", res);

    }

#endif

#else

    asm volatile ("push %%cs ; call %1"

                  : "=a" (res)

                  : "m" (func_lret): "memory", "cc");

    printf("func_lret=" FMTLX "\n", res);



    asm volatile ("pushf ; push %%cs ; call %1"

                  : "=a" (res)

                  : "m" (func_iret): "memory", "cc");

    printf("func_iret=" FMTLX "\n", res);

#endif



#if defined(__x86_64__)

    

    asm volatile ("push $12345432 ; push $0x9abcdef ; pop (%%rsp) ; pop %0"

                  : "=g" (res));

    printf("popl esp=" FMTLX "\n", res);

#else

    

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0"

                  : "=g" (res));

    printf("popl esp=" FMTLX "\n", res);



    

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0"

                  : "=g" (res));

    printf("popw esp=" FMTLX "\n", res);

#endif

}

void FUNC_0(void)

{

    char VAR_0[256];

    long VAR_1, VAR_2;



    for(VAR_2=0;VAR_2<256;VAR_2++) VAR_0[VAR_2] = 256 - VAR_2;

    VAR_1 = 0x12345678;

    asm ("xlat" : "=a" (VAR_1) : "b" (VAR_0), "0" (VAR_1));

    printf("xlat: EAX=" FMTLX "\n", VAR_1);



#if defined(__x86_64__)

#if 0

    {

        





        static struct __attribute__((packed)) {

            uint64_t offset;

            uint16_t seg;

        } desc;

        long cs_sel;



        asm volatile ("mov %%cs, %0" : "=r" (cs_sel));



        asm volatile ("push %1\n"

                      "call func_lret\n"

                      : "=a" (VAR_1)

                      : "r" (cs_sel) : "memory", "cc");

        printf("func_lret=" FMTLX "\n", VAR_1);



        desc.offset = (long)&func_lret;

        desc.seg = cs_sel;



        asm volatile ("xor %%rax, %%rax\n"

                      "rex64 lcall *(%%rcx)\n"

                      : "=a" (VAR_1)

                      : "c" (&desc)

                      : "memory", "cc");

        printf("func_lret2=" FMTLX "\n", VAR_1);



        asm volatile ("push %2\n"

                      "mov $ 1f, %%rax\n"

                      "push %%rax\n"

                      "rex64 ljmp *(%%rcx)\n"

                      "1:\n"

                      : "=a" (VAR_1)

                      : "c" (&desc), "b" (cs_sel)

                      : "memory", "cc");

        printf("func_lret3=" FMTLX "\n", VAR_1);

    }

#endif

#else

    asm volatile ("push %%cs ; call %1"

                  : "=a" (VAR_1)

                  : "m" (func_lret): "memory", "cc");

    printf("func_lret=" FMTLX "\n", VAR_1);



    asm volatile ("pushf ; push %%cs ; call %1"

                  : "=a" (VAR_1)

                  : "m" (func_iret): "memory", "cc");

    printf("func_iret=" FMTLX "\n", VAR_1);

#endif



#if defined(__x86_64__)

    

    asm volatile ("push $12345432 ; push $0x9abcdef ; pop (%%rsp) ; pop %0"

                  : "=g" (VAR_1));

    printf("popl esp=" FMTLX "\n", VAR_1);

#else

    

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0"

                  : "=g" (VAR_1));

    printf("popl esp=" FMTLX "\n", VAR_1);



    

    asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0"

                  : "=g" (VAR_1));

    printf("popw esp=" FMTLX "\n", VAR_1);

#endif

}

void FUNC_0(void)
{ char VAR_0[256]; long VAR_1, VAR_2; for(VAR_2=0;VAR_2<256;VAR_2++) VAR_0[VAR_2] = 256 - VAR_2; VAR_1 = 0x12345678; asm ("xlat" : "=a" (VAR_1) : "b" (VAR_0), "0" (VAR_1)); printf("xlat: EAX=" FMTLX "\n", VAR_1); #if defined(__x86_64__)
#if 0
{ static struct __attribute__((packed)) { uint64_t offset; uint16_t seg; } desc; long cs_sel; asm volatile ("mov %%cs, %0" : "=r" (cs_sel)); asm volatile ("push %1\n"
"call func_lret\n"
: "=a" (VAR_1)
: "r" (cs_sel) : "memory", "cc"); printf("func_lret=" FMTLX "\n", VAR_1); desc.offset = (long)&func_lret; desc.seg = cs_sel; asm volatile ("xor %%rax, %%rax\n"
"rex64 lcall *(%%rcx)\n"
: "=a" (VAR_1)
: "c" (&desc)
: "memory", "cc"); printf("func_lret2=" FMTLX "\n", VAR_1); asm volatile ("push %2\n"
"mov $ 1f, %%rax\n"
"push %%rax\n"
"rex64 ljmp *(%%rcx)\n"
"1:\n"
: "=a" (VAR_1)
: "c" (&desc), "b" (cs_sel)
: "memory", "cc"); printf("func_lret3=" FMTLX "\n", VAR_1); } #endif
#else
asm volatile ("push %%cs ; call %1" : "=a" (VAR_1)
: "m" (func_lret): "memory", "cc"); printf("func_lret=" FMTLX "\n", VAR_1); asm volatile ("pushf ; push %%cs ; call %1" : "=a" (VAR_1)
: "m" (func_iret): "memory", "cc"); printf("func_iret=" FMTLX "\n", VAR_1); #endif
#if defined(__x86_64__)
asm volatile ("push $12345432 ; push $0x9abcdef ; pop (%%rsp) ; pop %0" : "=g" (VAR_1)); printf("popl esp=" FMTLX "\n", VAR_1); #else
asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0" : "=g" (VAR_1)); printf("popl esp=" FMTLX "\n", VAR_1); asm volatile ("pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0" : "=g" (VAR_1)); printf("popw esp=" FMTLX "\n", VAR_1); #endif
}