• 平台介绍
qemu-system-arm -M virt,secure=on -cpu cortex-a7 -m 32M
  • 中断产生过程
arch_timer -PPI中断-> gic Distributor  -> gic CPU interface --IRQ中断--> CPU

各模块的参考手册

  • Generic Timer
ARMv7 ref : P1481CNTP_TVAL // PL1 Physical TimerCNTP_CTL
  • PPI 中断
cortex-a7 trm P179Private Peripheral Interrupts // PPI2
  • GIC 版本
cortex-a7 trm P177The integrated GIC is compliant with the version 2.0 of the ARM Generic Interrupt Controller (GIC) Architecture Specification.
  • GIC 基址
ARMv7 ref : P1481c15 寄存器
cortex-a7 trm P79CBAR : // 基址(是个40bit的数据)需要重新拼接一下// 但如果 PERIPHBASE[39:32] 为 0的话 ,拼接后的结果(即GIC基址)和 CBAR 的值一样
CBAR 为 0x8000000
所以 基址 为 0x8000000查看设备树,设备树上写的为 reg = <0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00 0x10000>;
即 基地址 为 0x8000000这两个不知道以哪个为准,反正都是相同的.
  • GIC各模块偏移地址
cortex-a7 trm P178我们只需要关注0x1000 - 0x1FFF Distributor0x2000 - 0x3FFF CPU interface但是实际情况为     基址 + 0x1000  这块内存并不存在查看设备树,设备树上写的为 reg = <0x00 0x8000000 0x00 0x10000 0x00 0x8010000 0x00 0x10000>;
即 基地址 为 0x8000000 0x8010000 ,根据我从CBAR读出的值可以判定 如下Distributor     的偏移地址 为 0x00000CPU interface    的偏移地址 为 0x10000
  • GIC Distributor 寄存器描述
gic ref P75 // 描述的不完全Distributor register map
cortex-a7 trm P181 // 以这个为准Distributor register summary
  • GIC CPU interface 寄存器描述
gic ref P76  // 描述的不完全CPU interface register map
cortex-a7 trm P188 // 以这个为准CPU Interface register summary

代码

$ cat arch/arm32/driver/timer.c
/*************************************************************************> File Name: timer.c> Author: SuWeishuai> Mail: suwsl@foxmail.com> Created Time: Wed 27 Apr 2022 04:10:31 PM CST************************************************************************/#include "platform.h"
#include "reg_ops.h"
#include "pt_regs.h"#define TIMER_USE_TVALint timer_init(void){#ifdef TIMER_USE_TVALsreg_wr(CNTP_TVAL,TIMER_PERIOD);
#elsesreg64_wr(CNTP_CVAL,sreg64_rd(CNTPCT)+TIMER_PERIOD);
#endifsreg_wr(CNTP_CTL, (1 << 0) | (0 << 1));return 0;
}void timer_handler(unsigned long cause,struct pt_regs *pt_regs){#ifdef TIMER_USE_TVALsreg_wr(CNTP_TVAL,TIMER_PERIOD);
#elsesreg64_wr(CNTP_CVAL,sreg64_rd(CNTPCT)+TIMER_PERIOD);
#endifreturn ;
}
$ cat arch/arm32/driver/gic_v2.c
/*************************************************************************> File Name: gic_v2.c> Author: SuWeishuai> Mail: suwsl@foxmail.com> Created Time: Thu 28 Apr 2022 04:18:56 PM CST************************************************************************/#include "platform.h"
#include "reg_ops.h"
#include "gic_v2.h"gic_v2_dist_t * gic_dist  = 0;
gic_v2_cpu_t  * gic_cpu   = 0;int gic_v2_init(void){int i = 0;unsigned cbar = 0;cbar =  sreg_rd(CBAR);gic_dist = (gic_v2_dist_t *)cbar;gic_cpu  = (gic_v2_cpu_t  *)(cbar+0x10000);#if 0// The GICD_IPRIORITYRs provide an 8-bit priority field for each interrupt supported by the GIC.for(i = 0 ; i < 32; i++){gic_dist->D_IPRIORITYR[i] = 0x5 << 3;}
#endif// Provides an interrupt priority filter.gic_cpu->C_PMR = 0XF8;#if 0// The value of this field controls how the 8-bit interrupt priority field is split into a group priority field// 0X2// Group priority field : Subpriority field// [7:3]                : [2:0]// ggggg                : sssgic_cpu->C_BPR = 0X2;
#endif// The GICD_ISENABLERs provide a Set-enable bit for each interrupt supported by the GIC.// Writing 1 to a Set-enable bit enables forwarding of the corresponding interrupt from the// Distributor to the CPU interfaces.gic_dist->D_ISENABLER[0] = (1 << 29);// Enables the forwarding of pending interrupts from the Distributor to the CPU interfaces.gic_dist->D_CTLR = 0X1;// Enables the signaling of interrupts by the CPU interface to the connected processorgic_cpu->C_CTLR = 0X1;return 0;
}

名词解释

  • 几个名词
system counter
processor counter
generic timer counter
其中 system counter 和 generic timer counter 一致 , 以后只说  system counter
其中 processor counter 是 processor 运行的 计数
system counter 的频率 是 1MHZ-50MHZ , 可设置
processor counter 的频率更高,可以达到 2GHZ,即处理器的运行频率
  • system counter 是什么
和power domain类似,clock domain也是不同的,system counter和 processor 工作在不同的clock下,软件修改了CPU的频率也不会影响system counter的工作节奏,从而也不会改变timer的行为。Notes:System counter提供一个计数,分发到各个timer中。Timer定时器基于System counter计数值,超时后触发一个信号到GIC,超时函数进行处理。考虑到功耗,各CPU专属的Timer、电路可以被单独关闭;而System counter保持运行。processor   按 时钟 动作
generic  timer       按 时钟 动作cpu 和 timer的 clock domain  和 power domain 都不一样有没有一个 寄存器可以显示 processor 的 count 数
为什么 system counter 是 timer 的计数,而不是 processor 的 计数
  • generic timer 的 寄存器
armv7v8中的 CNTFRQ 是 clock 的频率
armv7v8中的 CNTPCT 是 clock 的当前计数值,也叫system counter
  • CNTFRQ
The CNTFRQ register indicates the clock frequency of the system counter.Programming CNTFRQ does not affect the system clock frequency.
However, on system initialization, CNTFRQ must be correctly
programmed with the system clock frequency, to make this value
available to software. Typically, the system drives the system counter at a fixed frequency and the CNTFRQ register must be programmed
to this value during the system boot process. 写入 CNTFRQ  不影响 system clock  frequency , 那会影响什么呢?
既然不影响  system clock  frequency , 写入 这个寄存器的目的是什么呢?

riscv 中的 mtimer


我感觉 riscv中的mtimer 可以等价于 generic timer ,都是 必备的,而不是外部的IPriscv 中的 mcycle/mcycleh 寄存器,在 armv7v8中有没有对应的寄存器
有 , 叫 cycle counter , 也叫 processor countermtimer/generic timer 的频率 必然远远低于 mcycle/cycle counter 的计数频率processor counter在不同的微架构上访问方式不同arm11MP :  // https://developer.arm.com/documentation/ddi0360/f/control-coprocessor-cp15/register-descriptions/c15--cycle-counter-register--ccnt-MRC p15, 0, <Rd>, c15, c12, 1 ; Read Cycle Counter RegisterMCR p15, 0, <Rd>, c15, c12, 1 ; Write Cycle Counter Registercortex-M : // https://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3DWT_CYCCNTCPU_CYCLEScortex-A : // https://developer.arm.com/documentation/ddi0601/2022-03/?lang=enPMCCNTR_EL0// https://aijishu.com/a/1060000000212593// https://ilinuxkernel.com/?p=1755

ARMv7 GICv2 GenericTimer 实战演练相关推荐

  1. 工控安全:攻防演示案例分享

    列举一些可以在工控安全项目中用的攻防演示案例,持续更新...... 前言 在某核电的安全项目中,感谢公司leader信任让我负责项目的总体方案设计.攻防案例设计.安全防护等方案,经过前期大量的搜索.复 ...

  2. ARMv8通用定时器简介

    前言 基于网上资料对相关概念做整理汇总,部分内容引用自文后文章. 详细内容参考手册 " ARMv8-A Architecture reference manual-DDI0487A_g_ar ...

  3. ASP.NET WebApi技术从入门到实战演练

    一.课程介绍 曾经有一位不知名的讲师说过这么一句名言: 一门RPC技术不会,那么千万万门RPC技术将都不会!在今天移动互联网的时代,作为攻城师的我们,谁不想着只写一套API就可以让我们的Web, An ...

  4. xcode armv6 armv7 armv7s arm64

    眼下ios的指令集有下面几种: armv6 iPhone iPhone2 iPhone3G 第一代和第二代iPod Touch armv7 iPhone4 iPhone4S armv7s iPhone ...

  5. 嵌入式网络那些事LwIP协议深度剖析与实战演练pdf

    下载地址:网盘下载 <嵌入式网络那些事:LwIP协议深度剖析与实战演练>面向网络TCP/IP协议初学者以及大量嵌入式网络开发人员,从当下流行的嵌入式网络协议栈LwIP的源代码入手,详细讲解 ...

  6. No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv7s)

    问题: No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv ...

  7. [转] Jenkins实战演练之Windows系统节点管理

    [前提] 通过<Jenkins实战演练之Windows服务器快速搭建>(http://my.oschina.net/iware/blog /191818)和<Jenkins实战演练之 ...

  8. [architecture]-ARMV7架构下SecureMonitor双系统切换时保存和恢复哪些寄存

    ★★★ 个人博客导读首页-点击此处 ★★★ . 文章目录 1.armv7的通用寄存器简介 2.寄存器的保存和恢复 3.参考代码: 1.armv7的通用寄存器简介 ARMV7处理器有40个32位寄存器, ...

  9. [architecture]-ARMV7架构下Linux Kernel的Userspace进程切换时保存和恢复哪些寄存器

    ★★★ 个人博客导读首页-点击此处 ★★★ . 文章目录 1.armv7的通用寄存器简介 2.寄存器的保存和恢复 3.Linux Kernel参考代码 1.armv7的通用寄存器简介 ARMV7处理器 ...

最新文章

  1. BZOJ 1040 骑士
  2. hadoop块的存储方式
  3. helloworld 1 2結合版 (有意思)
  4. pku 1573 Robot Motion 第一周训练——模拟
  5. MXone影视自适应模板
  6. 机器学习算法(4)——SVM(以及拉格朗日对偶问题)
  7. Qemu-6.1.0多热补丁管理
  8. 速卖通关键词挖掘工具_2020网站关键词挖掘工具有哪些
  9. Springboot毕设项目会议预约系统设计与实现3if68(java+VUE+Mybatis+Maven+Mysql)
  10. Linux系统安全强化指南
  11. 大工《电机与拖动实验》实验报告离线作业
  12. matlab画图semilogy
  13. android+自定义跑马灯,android自定义View实现跑马灯效果
  14. 重装系统后小喇叭显示未安装音频输出设备
  15. IE11上登陆oracle OEM时报:“证书错误,导航已阻止”且无继续浏览此网站(不推荐)的错误...
  16. Fortran中分配数组大小
  17. springboot publish event 事件机制demo
  18. C语言量化管理系统,任务量化管理系统
  19. Redis数据库(入门)
  20. 算法提高 排队打水问题 无聊刷个水题

热门文章

  1. 易语言永久修改窗口标题
  2. mysql -u root mysql_输入命令mysql -u root -p 报错
  3. excel 从身份证号中提取性别,年龄
  4. 深圳高新技术企业补贴政策
  5. 一个新的项目:狼人杀
  6. java swing 毛玻璃_实时、动态的毛玻璃(aero)效果,javaSwing 实现的,用的是高斯模糊算法...
  7. 谈谈我对京东的认识(2):商业价值和前景分析
  8. left out join举例
  9. 《Spring事务传播行为详解》经典例子 看完这篇,别的不用看了
  10. 02.windows转mac日记——操作习惯