| 1 |
/* |
| 2 |
* Test if our calling convention gymnastics actually work |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <efi.h> |
| 6 |
#include <efilib.h> |
| 7 |
|
| 8 |
#if 0 |
| 9 |
extern void dump_stack(void); |
| 10 |
asm( ".globl dump_stack\n" |
| 11 |
"dump_stack:\n" |
| 12 |
" movq %rsp, %rdi\n" |
| 13 |
" jmp *dump_stack_helper@GOTPCREL(%rip)\n" |
| 14 |
".size dump_stack, .-dump_stack"); |
| 15 |
|
| 16 |
void dump_stack_helper(uint64_t rsp_val) |
| 17 |
{ |
| 18 |
uint64_t *rsp = (uint64_t *)rsp_val; |
| 19 |
int x; |
| 20 |
|
| 21 |
Print(L"%%rsp: 0x%08x%08x stack:\r\n", |
| 22 |
(rsp_val & 0xffffffff00000000) >>32, |
| 23 |
rsp_val & 0xffffffff); |
| 24 |
for (x = 0; x < 8; x++) { |
| 25 |
Print(L"%08x: ", ((uint64_t)rsp) & 0xffffffff); |
| 26 |
Print(L"%016x ", *rsp++); |
| 27 |
Print(L"%016x ", *rsp++); |
| 28 |
Print(L"%016x ", *rsp++); |
| 29 |
Print(L"%016x\r\n", *rsp++); |
| 30 |
} |
| 31 |
} |
| 32 |
#endif |
| 33 |
|
| 34 |
EFI_STATUS EFI_FUNCTION test_failure_callback(void) |
| 35 |
{ |
| 36 |
return EFI_UNSUPPORTED; |
| 37 |
} |
| 38 |
|
| 39 |
EFI_STATUS test_failure(void) |
| 40 |
{ |
| 41 |
return uefi_call_wrapper(test_failure_callback, 0); |
| 42 |
} |
| 43 |
|
| 44 |
EFI_STATUS EFI_FUNCTION test_call0_callback(void) |
| 45 |
{ |
| 46 |
return EFI_SUCCESS; |
| 47 |
} |
| 48 |
|
| 49 |
EFI_STATUS test_call0(void) |
| 50 |
{ |
| 51 |
return uefi_call_wrapper(test_call0_callback, 0); |
| 52 |
} |
| 53 |
|
| 54 |
EFI_STATUS EFI_FUNCTION test_call1_callback(UINT32 a) |
| 55 |
{ |
| 56 |
if (a != 0x12345678) { |
| 57 |
return EFI_LOAD_ERROR; |
| 58 |
} |
| 59 |
return EFI_SUCCESS; |
| 60 |
} |
| 61 |
|
| 62 |
EFI_STATUS test_call1(void) |
| 63 |
{ |
| 64 |
return uefi_call_wrapper(test_call1_callback, 1,0x12345678); |
| 65 |
} |
| 66 |
|
| 67 |
EFI_STATUS EFI_FUNCTION test_call2_callback(UINT32 a, UINT32 b) |
| 68 |
{ |
| 69 |
if (a != 0x12345678) { |
| 70 |
return EFI_LOAD_ERROR; |
| 71 |
} |
| 72 |
if (b != 0x23456789) { |
| 73 |
return EFI_INVALID_PARAMETER; |
| 74 |
} |
| 75 |
return EFI_SUCCESS; |
| 76 |
} |
| 77 |
|
| 78 |
EFI_STATUS test_call2(void) |
| 79 |
{ |
| 80 |
return uefi_call_wrapper(test_call2_callback, 2, |
| 81 |
0x12345678, 0x23456789); |
| 82 |
} |
| 83 |
|
| 84 |
EFI_STATUS EFI_FUNCTION test_call3_callback(UINT32 a, UINT32 b, |
| 85 |
UINT32 c) |
| 86 |
{ |
| 87 |
if (a != 0x12345678) |
| 88 |
return EFI_LOAD_ERROR; |
| 89 |
if (b != 0x23456789) |
| 90 |
return EFI_INVALID_PARAMETER; |
| 91 |
if (c != 0x3456789a) |
| 92 |
return EFI_UNSUPPORTED; |
| 93 |
return EFI_SUCCESS; |
| 94 |
} |
| 95 |
|
| 96 |
EFI_STATUS test_call3(void) |
| 97 |
{ |
| 98 |
return uefi_call_wrapper(test_call3_callback, 3, |
| 99 |
0x12345678, 0x23456789, 0x3456789a); |
| 100 |
} |
| 101 |
|
| 102 |
EFI_STATUS EFI_FUNCTION test_call4_callback(UINT32 a, UINT32 b, |
| 103 |
UINT32 c, UINT32 d) |
| 104 |
{ |
| 105 |
if (a != 0x12345678) |
| 106 |
return EFI_LOAD_ERROR; |
| 107 |
if (b != 0x23456789) |
| 108 |
return EFI_INVALID_PARAMETER; |
| 109 |
if (c != 0x3456789a) |
| 110 |
return EFI_UNSUPPORTED; |
| 111 |
if (d != 0x456789ab) |
| 112 |
return EFI_BAD_BUFFER_SIZE; |
| 113 |
|
| 114 |
return EFI_SUCCESS; |
| 115 |
} |
| 116 |
|
| 117 |
EFI_STATUS test_call4(void) |
| 118 |
{ |
| 119 |
return uefi_call_wrapper(test_call4_callback, 4, |
| 120 |
0x12345678, 0x23456789, 0x3456789a, 0x456789ab); |
| 121 |
} |
| 122 |
|
| 123 |
EFI_STATUS EFI_FUNCTION test_call5_callback(UINT32 a, UINT32 b, |
| 124 |
UINT32 c, UINT32 d, UINT32 e) |
| 125 |
{ |
| 126 |
if (a != 0x12345678) |
| 127 |
return EFI_LOAD_ERROR; |
| 128 |
if (b != 0x23456789) |
| 129 |
return EFI_INVALID_PARAMETER; |
| 130 |
if (c != 0x3456789a) |
| 131 |
return EFI_UNSUPPORTED; |
| 132 |
if (d != 0x456789ab) |
| 133 |
return EFI_BAD_BUFFER_SIZE; |
| 134 |
if (e != 0x56789abc) |
| 135 |
return EFI_BUFFER_TOO_SMALL; |
| 136 |
|
| 137 |
return EFI_SUCCESS; |
| 138 |
} |
| 139 |
|
| 140 |
EFI_STATUS test_call5(void) |
| 141 |
{ |
| 142 |
return uefi_call_wrapper(test_call5_callback, 5, |
| 143 |
0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc); |
| 144 |
} |
| 145 |
|
| 146 |
EFI_STATUS EFI_FUNCTION test_call6_callback(UINT32 a, UINT32 b, |
| 147 |
UINT32 c, UINT32 d, UINT32 e, UINT32 f) |
| 148 |
{ |
| 149 |
if (a != 0x12345678) |
| 150 |
return EFI_LOAD_ERROR; |
| 151 |
if (b != 0x23456789) |
| 152 |
return EFI_INVALID_PARAMETER; |
| 153 |
if (c != 0x3456789a) |
| 154 |
return EFI_UNSUPPORTED; |
| 155 |
if (d != 0x456789ab) |
| 156 |
return EFI_BAD_BUFFER_SIZE; |
| 157 |
if (e != 0x56789abc) |
| 158 |
return EFI_BUFFER_TOO_SMALL; |
| 159 |
if (f != 0x6789abcd) |
| 160 |
return EFI_NOT_READY; |
| 161 |
|
| 162 |
return EFI_SUCCESS; |
| 163 |
} |
| 164 |
|
| 165 |
EFI_STATUS test_call6(void) |
| 166 |
{ |
| 167 |
return uefi_call_wrapper(test_call6_callback, 6, |
| 168 |
0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc, |
| 169 |
0x6789abcd); |
| 170 |
} |
| 171 |
|
| 172 |
EFI_STATUS EFI_FUNCTION test_call7_callback(UINT32 a, UINT32 b, |
| 173 |
UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g) |
| 174 |
{ |
| 175 |
if (a != 0x12345678) |
| 176 |
return EFI_LOAD_ERROR; |
| 177 |
if (b != 0x23456789) |
| 178 |
return EFI_INVALID_PARAMETER; |
| 179 |
if (c != 0x3456789a) |
| 180 |
return EFI_UNSUPPORTED; |
| 181 |
if (d != 0x456789ab) |
| 182 |
return EFI_BAD_BUFFER_SIZE; |
| 183 |
if (e != 0x56789abc) |
| 184 |
return EFI_BUFFER_TOO_SMALL; |
| 185 |
if (f != 0x6789abcd) |
| 186 |
return EFI_NOT_READY; |
| 187 |
if (g != 0x789abcde) |
| 188 |
return EFI_DEVICE_ERROR; |
| 189 |
|
| 190 |
return EFI_SUCCESS; |
| 191 |
} |
| 192 |
|
| 193 |
EFI_STATUS test_call7(void) |
| 194 |
{ |
| 195 |
return uefi_call_wrapper(test_call7_callback, 7, |
| 196 |
0x12345678, 0x23456789, 0x3456789a, 0x456789ab, |
| 197 |
0x56789abc, 0x6789abcd, 0x789abcde); |
| 198 |
} |
| 199 |
|
| 200 |
EFI_STATUS EFI_FUNCTION test_call8_callback(UINT32 a, UINT32 b, |
| 201 |
UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h) |
| 202 |
{ |
| 203 |
if (a != 0x12345678) |
| 204 |
return EFI_LOAD_ERROR; |
| 205 |
if (b != 0x23456789) |
| 206 |
return EFI_INVALID_PARAMETER; |
| 207 |
if (c != 0x3456789a) |
| 208 |
return EFI_UNSUPPORTED; |
| 209 |
if (d != 0x456789ab) |
| 210 |
return EFI_BAD_BUFFER_SIZE; |
| 211 |
if (e != 0x56789abc) |
| 212 |
return EFI_BUFFER_TOO_SMALL; |
| 213 |
if (f != 0x6789abcd) |
| 214 |
return EFI_NOT_READY; |
| 215 |
if (g != 0x789abcde) |
| 216 |
return EFI_DEVICE_ERROR; |
| 217 |
if (h != 0x89abcdef) |
| 218 |
return EFI_WRITE_PROTECTED; |
| 219 |
|
| 220 |
return EFI_SUCCESS; |
| 221 |
} |
| 222 |
|
| 223 |
EFI_STATUS test_call8(void) |
| 224 |
{ |
| 225 |
return uefi_call_wrapper(test_call8_callback, 8, |
| 226 |
0x12345678, |
| 227 |
0x23456789, |
| 228 |
0x3456789a, |
| 229 |
0x456789ab, |
| 230 |
0x56789abc, |
| 231 |
0x6789abcd, |
| 232 |
0x789abcde, |
| 233 |
0x89abcdef); |
| 234 |
} |
| 235 |
|
| 236 |
EFI_STATUS EFI_FUNCTION test_call9_callback(UINT32 a, UINT32 b, |
| 237 |
UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i) |
| 238 |
{ |
| 239 |
if (a != 0x12345678) |
| 240 |
return EFI_LOAD_ERROR; |
| 241 |
if (b != 0x23456789) |
| 242 |
return EFI_INVALID_PARAMETER; |
| 243 |
if (c != 0x3456789a) |
| 244 |
return EFI_UNSUPPORTED; |
| 245 |
if (d != 0x456789ab) |
| 246 |
return EFI_BAD_BUFFER_SIZE; |
| 247 |
if (e != 0x56789abc) |
| 248 |
return EFI_BUFFER_TOO_SMALL; |
| 249 |
if (f != 0x6789abcd) |
| 250 |
return EFI_NOT_READY; |
| 251 |
if (g != 0x789abcde) |
| 252 |
return EFI_DEVICE_ERROR; |
| 253 |
if (h != 0x89abcdef) |
| 254 |
return EFI_WRITE_PROTECTED; |
| 255 |
if (i != 0x9abcdef0) |
| 256 |
return EFI_OUT_OF_RESOURCES; |
| 257 |
|
| 258 |
return EFI_SUCCESS; |
| 259 |
} |
| 260 |
|
| 261 |
EFI_STATUS test_call9(void) |
| 262 |
{ |
| 263 |
return uefi_call_wrapper(test_call9_callback, 9, |
| 264 |
0x12345678, |
| 265 |
0x23456789, |
| 266 |
0x3456789a, |
| 267 |
0x456789ab, |
| 268 |
0x56789abc, |
| 269 |
0x6789abcd, |
| 270 |
0x789abcde, |
| 271 |
0x89abcdef, |
| 272 |
0x9abcdef0); |
| 273 |
} |
| 274 |
|
| 275 |
extern EFI_STATUS test_call10(void); |
| 276 |
EFI_STATUS EFI_FUNCTION test_call10_callback(UINT32 a, UINT32 b, |
| 277 |
UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i, |
| 278 |
UINT32 j) |
| 279 |
{ |
| 280 |
if (a != 0x12345678) |
| 281 |
return EFI_LOAD_ERROR; |
| 282 |
if (b != 0x23456789) |
| 283 |
return EFI_INVALID_PARAMETER; |
| 284 |
if (c != 0x3456789a) |
| 285 |
return EFI_UNSUPPORTED; |
| 286 |
if (d != 0x456789ab) |
| 287 |
return EFI_BAD_BUFFER_SIZE; |
| 288 |
if (e != 0x56789abc) |
| 289 |
return EFI_BUFFER_TOO_SMALL; |
| 290 |
if (f != 0x6789abcd) |
| 291 |
return EFI_NOT_READY; |
| 292 |
if (g != 0x789abcde) |
| 293 |
return EFI_DEVICE_ERROR; |
| 294 |
if (h != 0x89abcdef) |
| 295 |
return EFI_WRITE_PROTECTED; |
| 296 |
if (i != 0x9abcdef0) |
| 297 |
return EFI_OUT_OF_RESOURCES; |
| 298 |
if (j != 0xabcdef01) |
| 299 |
return EFI_VOLUME_CORRUPTED; |
| 300 |
|
| 301 |
return EFI_SUCCESS; |
| 302 |
} |
| 303 |
|
| 304 |
EFI_STATUS test_call10(void) |
| 305 |
{ |
| 306 |
return uefi_call_wrapper(test_call10_callback, 10, |
| 307 |
0x12345678, |
| 308 |
0x23456789, |
| 309 |
0x3456789a, |
| 310 |
0x456789ab, |
| 311 |
0x56789abc, |
| 312 |
0x6789abcd, |
| 313 |
0x789abcde, |
| 314 |
0x89abcdef, |
| 315 |
0x9abcdef0, |
| 316 |
0xabcdef01); |
| 317 |
} |
| 318 |
|
| 319 |
EFI_STATUS |
| 320 |
efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab) |
| 321 |
{ |
| 322 |
EFI_STATUS rc = EFI_SUCCESS; |
| 323 |
|
| 324 |
InitializeLib(image, systab); |
| 325 |
PoolAllocationType = 2; /* klooj */ |
| 326 |
|
| 327 |
#ifdef __x86_64__ |
| 328 |
__asm__ volatile("out %0,%1" : : "a" ((uint8_t)0x14), "dN" (0x80)); |
| 329 |
#endif |
| 330 |
|
| 331 |
Print(L"Hello\r\n"); |
| 332 |
rc = test_failure(); |
| 333 |
if (EFI_ERROR(rc)) { |
| 334 |
Print(L"Returning Failure works\n"); |
| 335 |
} else { |
| 336 |
Print(L"Returning failure doesn't work.\r\n"); |
| 337 |
Print(L"%%rax was 0x%016x, should have been 0x%016x\n", |
| 338 |
rc, EFI_UNSUPPORTED); |
| 339 |
return EFI_INVALID_PARAMETER; |
| 340 |
} |
| 341 |
|
| 342 |
rc = test_call0(); |
| 343 |
if (!EFI_ERROR(rc)) { |
| 344 |
Print(L"0 args works just fine here.\r\n"); |
| 345 |
} else { |
| 346 |
Print(L"0 args failed: 0x%016x\n", rc); |
| 347 |
return rc; |
| 348 |
} |
| 349 |
|
| 350 |
rc = test_call1(); |
| 351 |
if (!EFI_ERROR(rc)) { |
| 352 |
Print(L"1 arg works just fine here.\r\n"); |
| 353 |
} else { |
| 354 |
Print(L"1 arg failed: 0x%016x\n", rc); |
| 355 |
return rc; |
| 356 |
} |
| 357 |
|
| 358 |
rc = test_call2(); |
| 359 |
if (!EFI_ERROR(rc)) { |
| 360 |
Print(L"2 args works just fine here.\r\n"); |
| 361 |
} else { |
| 362 |
Print(L"2 args failed: 0x%016x\n", rc); |
| 363 |
return rc; |
| 364 |
} |
| 365 |
|
| 366 |
rc = test_call3(); |
| 367 |
if (!EFI_ERROR(rc)) { |
| 368 |
Print(L"3 args works just fine here.\r\n"); |
| 369 |
} else { |
| 370 |
Print(L"3 args failed: 0x%016x\n", rc); |
| 371 |
return rc; |
| 372 |
} |
| 373 |
|
| 374 |
rc = test_call4(); |
| 375 |
if (!EFI_ERROR(rc)) { |
| 376 |
Print(L"4 args works just fine here.\r\n"); |
| 377 |
} else { |
| 378 |
Print(L"4 args failed: 0x%016x\n", rc); |
| 379 |
return rc; |
| 380 |
} |
| 381 |
|
| 382 |
rc = test_call5(); |
| 383 |
if (!EFI_ERROR(rc)) { |
| 384 |
Print(L"5 args works just fine here.\r\n"); |
| 385 |
} else { |
| 386 |
Print(L"5 args failed: 0x%016x\n", rc); |
| 387 |
return rc; |
| 388 |
} |
| 389 |
|
| 390 |
rc = test_call6(); |
| 391 |
if (!EFI_ERROR(rc)) { |
| 392 |
Print(L"6 args works just fine here.\r\n"); |
| 393 |
} else { |
| 394 |
Print(L"6 args failed: 0x%016x\n", rc); |
| 395 |
return rc; |
| 396 |
} |
| 397 |
|
| 398 |
rc = test_call7(); |
| 399 |
if (!EFI_ERROR(rc)) { |
| 400 |
Print(L"7 args works just fine here.\r\n"); |
| 401 |
} else { |
| 402 |
Print(L"7 args failed: 0x%016x\n", rc); |
| 403 |
return rc; |
| 404 |
} |
| 405 |
|
| 406 |
rc = test_call8(); |
| 407 |
if (!EFI_ERROR(rc)) { |
| 408 |
Print(L"8 args works just fine here.\r\n"); |
| 409 |
} else { |
| 410 |
Print(L"8 args failed: 0x%016x\n", rc); |
| 411 |
return rc; |
| 412 |
} |
| 413 |
|
| 414 |
rc = test_call9(); |
| 415 |
if (!EFI_ERROR(rc)) { |
| 416 |
Print(L"9 args works just fine here.\r\n"); |
| 417 |
} else { |
| 418 |
Print(L"9 args failed: 0x%016x\n", rc); |
| 419 |
return rc; |
| 420 |
} |
| 421 |
|
| 422 |
rc = test_call10(); |
| 423 |
if (!EFI_ERROR(rc)) { |
| 424 |
Print(L"10 args works just fine here.\r\n"); |
| 425 |
} else { |
| 426 |
Print(L"10 args failed: 0x%016x\n", rc); |
| 427 |
return rc; |
| 428 |
} |
| 429 |
|
| 430 |
return rc; |
| 431 |
} |