cpu.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <asm/csr.h>
  7. /*
  8. * prior_stage_fdt_address must be stored in the data section since it is used
  9. * before the bss section is available.
  10. */
  11. phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
  12. enum {
  13. ISA_INVALID = 0,
  14. ISA_32BIT,
  15. ISA_64BIT,
  16. ISA_128BIT
  17. };
  18. static const char * const isa_bits[] = {
  19. [ISA_INVALID] = NULL,
  20. [ISA_32BIT] = "32",
  21. [ISA_64BIT] = "64",
  22. [ISA_128BIT] = "128"
  23. };
  24. static inline bool supports_extension(char ext)
  25. {
  26. return csr_read(misa) & (1 << (ext - 'a'));
  27. }
  28. int print_cpuinfo(void)
  29. {
  30. char name[32];
  31. char *s = name;
  32. int bit;
  33. s += sprintf(name, "rv");
  34. bit = csr_read(misa) >> (sizeof(long) * 8 - 2);
  35. s += sprintf(s, isa_bits[bit]);
  36. supports_extension('i') ? *s++ = 'i' : 'r';
  37. supports_extension('m') ? *s++ = 'm' : 'i';
  38. supports_extension('a') ? *s++ = 'a' : 's';
  39. supports_extension('f') ? *s++ = 'f' : 'c';
  40. supports_extension('d') ? *s++ = 'd' : '-';
  41. supports_extension('c') ? *s++ = 'c' : 'v';
  42. *s++ = '\0';
  43. printf("CPU: %s\n", name);
  44. return 0;
  45. }