1321 |
} |
} |
1322 |
#endif |
#endif |
1323 |
|
|
1324 |
extern char func_lret32; |
#if defined(__x86_64__) |
1325 |
extern char func_iret32; |
asm(".globl func_lret\n" |
1326 |
|
"func_lret:\n" |
1327 |
|
"movl $0x87654641, %eax\n" |
1328 |
|
"lretq\n"); |
1329 |
|
#else |
1330 |
|
asm(".globl func_lret\n" |
1331 |
|
"func_lret:\n" |
1332 |
|
"movl $0x87654321, %eax\n" |
1333 |
|
"lret\n" |
1334 |
|
|
1335 |
|
".globl func_iret\n" |
1336 |
|
"func_iret:\n" |
1337 |
|
"movl $0xabcd4321, %eax\n" |
1338 |
|
"iret\n"); |
1339 |
|
#endif |
1340 |
|
|
1341 |
|
extern char func_lret; |
1342 |
|
extern char func_iret; |
1343 |
|
|
1344 |
void test_misc(void) |
void test_misc(void) |
1345 |
{ |
{ |
1351 |
asm ("xlat" : "=a" (res) : "b" (table), "0" (res)); |
asm ("xlat" : "=a" (res) : "b" (table), "0" (res)); |
1352 |
printf("xlat: EAX=" FMTLX "\n", res); |
printf("xlat: EAX=" FMTLX "\n", res); |
1353 |
|
|
1354 |
#if !defined(__x86_64__) |
#if defined(__x86_64__) |
1355 |
|
{ |
1356 |
|
static struct __attribute__((packed)) { |
1357 |
|
uint32_t offset; |
1358 |
|
uint16_t seg; |
1359 |
|
} desc; |
1360 |
|
long cs_sel; |
1361 |
|
|
1362 |
|
asm volatile ("mov %%cs, %0" : "=r" (cs_sel)); |
1363 |
|
|
1364 |
|
asm volatile ("push %1\n" |
1365 |
|
"call func_lret\n" |
1366 |
|
: "=a" (res) |
1367 |
|
: "r" (cs_sel) : "memory", "cc"); |
1368 |
|
printf("func_lret=" FMTLX "\n", res); |
1369 |
|
|
1370 |
|
/* NOTE: we assume that &func_lret < 4GB */ |
1371 |
|
desc.offset = (long)&func_lret; |
1372 |
|
desc.seg = cs_sel; |
1373 |
|
|
1374 |
|
asm volatile ("xor %%rax, %%rax\n" |
1375 |
|
"rex64 lcall %1\n" |
1376 |
|
: "=a" (res) |
1377 |
|
: "m" (desc) |
1378 |
|
: "memory", "cc"); |
1379 |
|
printf("func_lret2=" FMTLX "\n", res); |
1380 |
|
|
1381 |
|
asm volatile ("push %2\n" |
1382 |
|
"mov $ 1f, %%rax\n" |
1383 |
|
"push %%rax\n" |
1384 |
|
"ljmp %1\n" |
1385 |
|
"1:\n" |
1386 |
|
: "=a" (res) |
1387 |
|
: "m" (desc), "b" (cs_sel) |
1388 |
|
: "memory", "cc"); |
1389 |
|
printf("func_lret3=" FMTLX "\n", res); |
1390 |
|
} |
1391 |
|
#else |
1392 |
asm volatile ("push %%cs ; call %1" |
asm volatile ("push %%cs ; call %1" |
1393 |
: "=a" (res) |
: "=a" (res) |
1394 |
: "m" (func_lret32): "memory", "cc"); |
: "m" (func_lret): "memory", "cc"); |
1395 |
printf("func_lret32=" FMTLX "\n", res); |
printf("func_lret=" FMTLX "\n", res); |
1396 |
|
|
1397 |
asm volatile ("pushf ; push %%cs ; call %1" |
asm volatile ("pushf ; push %%cs ; call %1" |
1398 |
: "=a" (res) |
: "=a" (res) |
1399 |
: "m" (func_iret32): "memory", "cc"); |
: "m" (func_iret): "memory", "cc"); |
1400 |
printf("func_iret32=" FMTLX "\n", res); |
printf("func_iret=" FMTLX "\n", res); |
1401 |
#endif |
#endif |
1402 |
|
|
1403 |
#if defined(__x86_64__) |
#if defined(__x86_64__) |