blob: bb1f7f698bdf521d4fd2fb829cabba52f00298f1 [file] [log] [blame]
Richard Henderson0885f122023-09-16 15:01:47 -07001/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * Host specific cpu identification for LoongArch.
4 */
5
6#include "qemu/osdep.h"
7#include "host/cpuinfo.h"
8
9#ifdef CONFIG_GETAUXVAL
10# include <sys/auxv.h>
11#else
12# include "elf.h"
13#endif
14#include <asm/hwcap.h>
15
16unsigned cpuinfo;
17
18/* Called both as constructor and (possibly) via other constructors. */
19unsigned __attribute__((constructor)) cpuinfo_init(void)
20{
21 unsigned info = cpuinfo;
22 unsigned long hwcap;
23
24 if (info) {
25 return info;
26 }
27
28 hwcap = qemu_getauxval(AT_HWCAP);
29
30 info = CPUINFO_ALWAYS;
31 info |= (hwcap & HWCAP_LOONGARCH_LSX ? CPUINFO_LSX : 0);
Richard Henderson9d779182024-05-27 17:18:20 +000032 info |= (hwcap & HWCAP_LOONGARCH_LASX ? CPUINFO_LASX : 0);
Richard Henderson0885f122023-09-16 15:01:47 -070033
34 cpuinfo = info;
35 return info;
36}