cpuid.c 815 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/cpuid.h>
  6. void aws_run_cpuid(uint32_t eax, uint32_t ecx, uint32_t *abcd) {
  7. uint32_t ebx = 0;
  8. uint32_t edx = 0;
  9. #if defined(__i386__) && defined(__PIC__)
  10. /* in case of PIC under 32-bit EBX cannot be clobbered */
  11. __asm__ __volatile__("movl %%ebx, %%edi \n\t "
  12. "cpuid \n\t "
  13. "xchgl %%ebx, %%edi"
  14. : "=D"(ebx),
  15. #else
  16. __asm__ __volatile__("cpuid"
  17. : "+b"(ebx),
  18. #endif
  19. "+a"(eax),
  20. "+c"(ecx),
  21. "=d"(edx));
  22. abcd[0] = eax;
  23. abcd[1] = ebx;
  24. abcd[2] = ecx;
  25. abcd[3] = edx;
  26. }