ARMのCPU判定
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
* ARMのCPU判定 [#a5ab70ea]
Intel x86では、CPUID命令でCPUの種類を得ることができるが、...
ARMではシステム制御コプロセッサの[[Main ID Register(MIDR)...
おまけで、[[System Control Register(SCTLR):https://develo...
#highlight(c){{
#include <linux/init.h>
#include <linux/module.h>
unsigned int get_MIDR_reg(void)
{
unsigned int reg;
__asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0" : "=r" ...
return reg;
}
unsigned int get_SCTLR_reg(void)
{
unsigned int reg;
__asm__ __volatile__("mrc p15, 0, %0, c1, c0, 0" : "=r" ...
return reg;
}
static int armcpuinfo_init(void)
{
pr_info("%s\n", __FUNCTION__);
pr_info("MIDR = %x\n", get_MIDR_reg());
pr_info("SCTLR = %x\n", get_SCTLR_reg());
return 0;
}
static void armcpuinfo_exit(void)
{
pr_info("%s\n", __FUNCTION__);
}
MODULE_LICENSE("GPL v2");
module_init(armcpuinfo_init);
module_exit(armcpuinfo_exit);
}}
#ref(armcpuinfo.tgz)
** ビルド [#g24006d9]
pi@raspberrypi:~/armcpuinfo $ make
make -C /lib/modules/5.4.83-v7+/build M=/home/pi/armcpui...
make[1]: Entering directory '/home/pi/linux'
CC [M] /home/pi/armcpuinfo/armcpuinfo.o
Building modules, stage 2.
MODPOST 1 modules
CC [M] /home/pi/armcpuinfo/armcpuinfo.mod.o
LD [M] /home/pi/armcpuinfo/armcpuinfo.ko
make[1]: Leaving directory '/home/pi/linux'
** 実行結果 [#sf4c92ad]
pi@raspberrypi:~/armcpuinfo $ sudo insmod armcpuinfo.ko
pi@raspberrypi:~/armcpuinfo $ sudo rmmod armcpuinfo
pi@raspberrypi:~ $ dmesg | tail
[ 4245.068818] armcpuinfo: loading out-of-tree module ta...
[ 4245.069367] armcpuinfo_init
[ 4245.069379] MIDR = 410fd034
[ 4245.069388] SCTLR = 10c5383d
[ 4255.571746] armcpuinfo_exit
** AArch64 [#u2829445]
手元のラズパイは32bitだが、64bitのAArch64では、アクセス方...
それぞれ、アクセスするレジスタが、[[Main ID Register, EL1...
[[System Control Register, EL1(SCTLR_EL1):https://develop...
#highlight(c){{
#include <linux/init.h>
#include <linux/module.h>
unsigned long get_MIDR_EL1_reg(void)
{
unsigned long reg;
__asm__ __volatile__("mrs %0, MIDR_EL1" : "=r" (reg));
return reg;
}
unsigned long get_SCTLR_EL1_reg(void)
{
unsigned long reg;
__asm__ __volatile__("mrs %0, SCTLR_EL1" : "=r" (reg));
return reg;
}
static int armcpuinfo_init(void)
{
void __iomem *virt_addr;
pr_info("%s\n", __FUNCTION__);
pr_info("MIDR_EL1 = %lx\n", get_MIDR_EL1_reg());
pr_info("SCTLR_EL1 = %lx\n", get_SCTLR_EL1_reg());
return 0;
}
static void armcpuinfo_exit(void)
{
pr_info("%s\n", __FUNCTION__);
}
MODULE_LICENSE("GPL v2");
module_init(armcpuinfo_init);
module_exit(armcpuinfo_exit);
}}
#highlight(end)
※Raspberry PiはRaspberry Pi財団の登録商標です。
#htmlinsert(rpi3b+.html);
終了行:
* ARMのCPU判定 [#a5ab70ea]
Intel x86では、CPUID命令でCPUの種類を得ることができるが、...
ARMではシステム制御コプロセッサの[[Main ID Register(MIDR)...
おまけで、[[System Control Register(SCTLR):https://develo...
#highlight(c){{
#include <linux/init.h>
#include <linux/module.h>
unsigned int get_MIDR_reg(void)
{
unsigned int reg;
__asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0" : "=r" ...
return reg;
}
unsigned int get_SCTLR_reg(void)
{
unsigned int reg;
__asm__ __volatile__("mrc p15, 0, %0, c1, c0, 0" : "=r" ...
return reg;
}
static int armcpuinfo_init(void)
{
pr_info("%s\n", __FUNCTION__);
pr_info("MIDR = %x\n", get_MIDR_reg());
pr_info("SCTLR = %x\n", get_SCTLR_reg());
return 0;
}
static void armcpuinfo_exit(void)
{
pr_info("%s\n", __FUNCTION__);
}
MODULE_LICENSE("GPL v2");
module_init(armcpuinfo_init);
module_exit(armcpuinfo_exit);
}}
#ref(armcpuinfo.tgz)
** ビルド [#g24006d9]
pi@raspberrypi:~/armcpuinfo $ make
make -C /lib/modules/5.4.83-v7+/build M=/home/pi/armcpui...
make[1]: Entering directory '/home/pi/linux'
CC [M] /home/pi/armcpuinfo/armcpuinfo.o
Building modules, stage 2.
MODPOST 1 modules
CC [M] /home/pi/armcpuinfo/armcpuinfo.mod.o
LD [M] /home/pi/armcpuinfo/armcpuinfo.ko
make[1]: Leaving directory '/home/pi/linux'
** 実行結果 [#sf4c92ad]
pi@raspberrypi:~/armcpuinfo $ sudo insmod armcpuinfo.ko
pi@raspberrypi:~/armcpuinfo $ sudo rmmod armcpuinfo
pi@raspberrypi:~ $ dmesg | tail
[ 4245.068818] armcpuinfo: loading out-of-tree module ta...
[ 4245.069367] armcpuinfo_init
[ 4245.069379] MIDR = 410fd034
[ 4245.069388] SCTLR = 10c5383d
[ 4255.571746] armcpuinfo_exit
** AArch64 [#u2829445]
手元のラズパイは32bitだが、64bitのAArch64では、アクセス方...
それぞれ、アクセスするレジスタが、[[Main ID Register, EL1...
[[System Control Register, EL1(SCTLR_EL1):https://develop...
#highlight(c){{
#include <linux/init.h>
#include <linux/module.h>
unsigned long get_MIDR_EL1_reg(void)
{
unsigned long reg;
__asm__ __volatile__("mrs %0, MIDR_EL1" : "=r" (reg));
return reg;
}
unsigned long get_SCTLR_EL1_reg(void)
{
unsigned long reg;
__asm__ __volatile__("mrs %0, SCTLR_EL1" : "=r" (reg));
return reg;
}
static int armcpuinfo_init(void)
{
void __iomem *virt_addr;
pr_info("%s\n", __FUNCTION__);
pr_info("MIDR_EL1 = %lx\n", get_MIDR_EL1_reg());
pr_info("SCTLR_EL1 = %lx\n", get_SCTLR_EL1_reg());
return 0;
}
static void armcpuinfo_exit(void)
{
pr_info("%s\n", __FUNCTION__);
}
MODULE_LICENSE("GPL v2");
module_init(armcpuinfo_init);
module_exit(armcpuinfo_exit);
}}
#highlight(end)
※Raspberry PiはRaspberry Pi財団の登録商標です。
#htmlinsert(rpi3b+.html);
ページ名: