123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- /*
- * Test if our calling convention gymnastics actually work
- */
- #include <efi.h>
- #include <efilib.h>
- #if 0
- extern void dump_stack(void);
- asm( ".globl dump_stack\n"
- "dump_stack:\n"
- " movq %rsp, %rdi\n"
- " jmp *dump_stack_helper@GOTPCREL(%rip)\n"
- ".size dump_stack, .-dump_stack");
- void dump_stack_helper(uint64_t rsp_val)
- {
- uint64_t *rsp = (uint64_t *)rsp_val;
- int x;
- Print(L"%%rsp: 0x%08x%08x stack:\r\n",
- (rsp_val & 0xffffffff00000000) >>32,
- rsp_val & 0xffffffff);
- for (x = 0; x < 8; x++) {
- Print(L"%08x: ", ((uint64_t)rsp) & 0xffffffff);
- Print(L"%016x ", *rsp++);
- Print(L"%016x ", *rsp++);
- Print(L"%016x ", *rsp++);
- Print(L"%016x\r\n", *rsp++);
- }
- }
- #endif
- EFI_STATUS EFI_FUNCTION test_failure_callback(void)
- {
- return EFI_UNSUPPORTED;
- }
- EFI_STATUS test_failure(void)
- {
- return uefi_call_wrapper(test_failure_callback, 0);
- }
- EFI_STATUS EFI_FUNCTION test_call0_callback(void)
- {
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call0(void)
- {
- return uefi_call_wrapper(test_call0_callback, 0);
- }
- EFI_STATUS EFI_FUNCTION test_call1_callback(UINT32 a)
- {
- if (a != 0x12345678) {
- return EFI_LOAD_ERROR;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call1(void)
- {
- return uefi_call_wrapper(test_call1_callback, 1,0x12345678);
- }
- EFI_STATUS EFI_FUNCTION test_call2_callback(UINT32 a, UINT32 b)
- {
- if (a != 0x12345678) {
- return EFI_LOAD_ERROR;
- }
- if (b != 0x23456789) {
- return EFI_INVALID_PARAMETER;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call2(void)
- {
- return uefi_call_wrapper(test_call2_callback, 2,
- 0x12345678, 0x23456789);
- }
- EFI_STATUS EFI_FUNCTION test_call3_callback(UINT32 a, UINT32 b,
- UINT32 c)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call3(void)
- {
- return uefi_call_wrapper(test_call3_callback, 3,
- 0x12345678, 0x23456789, 0x3456789a);
- }
- EFI_STATUS EFI_FUNCTION test_call4_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call4(void)
- {
- return uefi_call_wrapper(test_call4_callback, 4,
- 0x12345678, 0x23456789, 0x3456789a, 0x456789ab);
- }
- EFI_STATUS EFI_FUNCTION test_call5_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call5(void)
- {
- return uefi_call_wrapper(test_call5_callback, 5,
- 0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc);
- }
- EFI_STATUS EFI_FUNCTION test_call6_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e, UINT32 f)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- if (f != 0x6789abcd)
- return EFI_NOT_READY;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call6(void)
- {
- return uefi_call_wrapper(test_call6_callback, 6,
- 0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc,
- 0x6789abcd);
- }
- EFI_STATUS EFI_FUNCTION test_call7_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- if (f != 0x6789abcd)
- return EFI_NOT_READY;
- if (g != 0x789abcde)
- return EFI_DEVICE_ERROR;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call7(void)
- {
- return uefi_call_wrapper(test_call7_callback, 7,
- 0x12345678, 0x23456789, 0x3456789a, 0x456789ab,
- 0x56789abc, 0x6789abcd, 0x789abcde);
- }
- EFI_STATUS EFI_FUNCTION test_call8_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- if (f != 0x6789abcd)
- return EFI_NOT_READY;
- if (g != 0x789abcde)
- return EFI_DEVICE_ERROR;
- if (h != 0x89abcdef)
- return EFI_WRITE_PROTECTED;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call8(void)
- {
- return uefi_call_wrapper(test_call8_callback, 8,
- 0x12345678,
- 0x23456789,
- 0x3456789a,
- 0x456789ab,
- 0x56789abc,
- 0x6789abcd,
- 0x789abcde,
- 0x89abcdef);
- }
- EFI_STATUS EFI_FUNCTION test_call9_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- if (f != 0x6789abcd)
- return EFI_NOT_READY;
- if (g != 0x789abcde)
- return EFI_DEVICE_ERROR;
- if (h != 0x89abcdef)
- return EFI_WRITE_PROTECTED;
- if (i != 0x9abcdef0)
- return EFI_OUT_OF_RESOURCES;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call9(void)
- {
- return uefi_call_wrapper(test_call9_callback, 9,
- 0x12345678,
- 0x23456789,
- 0x3456789a,
- 0x456789ab,
- 0x56789abc,
- 0x6789abcd,
- 0x789abcde,
- 0x89abcdef,
- 0x9abcdef0);
- }
- extern EFI_STATUS test_call10(void);
- EFI_STATUS EFI_FUNCTION test_call10_callback(UINT32 a, UINT32 b,
- UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i,
- UINT32 j)
- {
- if (a != 0x12345678)
- return EFI_LOAD_ERROR;
- if (b != 0x23456789)
- return EFI_INVALID_PARAMETER;
- if (c != 0x3456789a)
- return EFI_UNSUPPORTED;
- if (d != 0x456789ab)
- return EFI_BAD_BUFFER_SIZE;
- if (e != 0x56789abc)
- return EFI_BUFFER_TOO_SMALL;
- if (f != 0x6789abcd)
- return EFI_NOT_READY;
- if (g != 0x789abcde)
- return EFI_DEVICE_ERROR;
- if (h != 0x89abcdef)
- return EFI_WRITE_PROTECTED;
- if (i != 0x9abcdef0)
- return EFI_OUT_OF_RESOURCES;
- if (j != 0xabcdef01)
- return EFI_VOLUME_CORRUPTED;
- return EFI_SUCCESS;
- }
- EFI_STATUS test_call10(void)
- {
- return uefi_call_wrapper(test_call10_callback, 10,
- 0x12345678,
- 0x23456789,
- 0x3456789a,
- 0x456789ab,
- 0x56789abc,
- 0x6789abcd,
- 0x789abcde,
- 0x89abcdef,
- 0x9abcdef0,
- 0xabcdef01);
- }
- EFI_STATUS
- efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab)
- {
- EFI_STATUS rc = EFI_SUCCESS;
- InitializeLib(image, systab);
- PoolAllocationType = 2; /* klooj */
- #ifdef __x86_64__
- __asm__ volatile("out %0,%1" : : "a" ((uint8_t)0x14), "dN" (0x80));
- #endif
- Print(L"Hello\r\n");
- rc = test_failure();
- if (EFI_ERROR(rc)) {
- Print(L"Returning Failure works\n");
- } else {
- Print(L"Returning failure doesn't work.\r\n");
- Print(L"%%rax was 0x%016x, should have been 0x%016x\n",
- rc, EFI_UNSUPPORTED);
- return EFI_INVALID_PARAMETER;
- }
- rc = test_call0();
- if (!EFI_ERROR(rc)) {
- Print(L"0 args works just fine here.\r\n");
- } else {
- Print(L"0 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call1();
- if (!EFI_ERROR(rc)) {
- Print(L"1 arg works just fine here.\r\n");
- } else {
- Print(L"1 arg failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call2();
- if (!EFI_ERROR(rc)) {
- Print(L"2 args works just fine here.\r\n");
- } else {
- Print(L"2 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call3();
- if (!EFI_ERROR(rc)) {
- Print(L"3 args works just fine here.\r\n");
- } else {
- Print(L"3 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call4();
- if (!EFI_ERROR(rc)) {
- Print(L"4 args works just fine here.\r\n");
- } else {
- Print(L"4 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call5();
- if (!EFI_ERROR(rc)) {
- Print(L"5 args works just fine here.\r\n");
- } else {
- Print(L"5 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call6();
- if (!EFI_ERROR(rc)) {
- Print(L"6 args works just fine here.\r\n");
- } else {
- Print(L"6 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call7();
- if (!EFI_ERROR(rc)) {
- Print(L"7 args works just fine here.\r\n");
- } else {
- Print(L"7 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call8();
- if (!EFI_ERROR(rc)) {
- Print(L"8 args works just fine here.\r\n");
- } else {
- Print(L"8 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call9();
- if (!EFI_ERROR(rc)) {
- Print(L"9 args works just fine here.\r\n");
- } else {
- Print(L"9 args failed: 0x%016x\n", rc);
- return rc;
- }
- rc = test_call10();
- if (!EFI_ERROR(rc)) {
- Print(L"10 args works just fine here.\r\n");
- } else {
- Print(L"10 args failed: 0x%016x\n", rc);
- return rc;
- }
- return rc;
- }
|