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