下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Interrupts and Traps in Oberon-ARMNiklaus Wirth22.2.20081. Interrupts, and the ARM-ArchitectureAn interrupt is by definition a break in the sequential stream of instruction execution caused by an external signal. It is useful to consider an interrupt as causing the execution of a procedure. The prog
2、rammers problem is that this procedure may be inserted anywhere in the normal program flow. An interrupt should be considered as a procedure call, which may occur at any time, anywhere, asynchronously. It is the programmers duty to ensure that such procedures, called interrupt handlers, cooperate ha
3、rmoniously with the remaining program.In the ARM-processor, there are 6 sources of interrupt signals. They are: Fast Interrupt (FIQ), Interrupt (IRQ), Software Interrupt (SWI), Undefined Instruction, and Abort. The first two are caused by external signals, the third by the SWI instruction, and the l
4、ast by internal conditions. When an interrupt signal is sensed, the ARM processor picks the next instruction from a fixed location, which is called the interrupt vector. Every interrupt source has its own associated interrupt location. The locations are therefore called a vector.The processor is sai
5、d to be in a mode. This mode is represented by the Processor Status Register (8 bits). The mode is set whenever an interrupt happens. The PSR also contains two bits which, when set to 1, disable interrupts from the external sources.In detail, the following actions are taken when an interrupt conditi
6、on is sensed:1. The address of the current instruction + 8 is saved in register R14 (LNK), just as in the case of a Branch and Link instruction, and the PSR is saved in the SPSR register: PC - LNK, PSR - SPSR.2. The interrupt locations address is assigned to the PC, and the mode associated with the
7、interrupt source is assigned to the PSR: intadr - PC, intmode - PSR.3. In case of an external interrupt, the corresponding disable bit in the PSR is set in order to prevent a recursive interrupt.The following table specifies the vector locations and the offsets required in the return instruction for
8、 the various interrupt sources.Interruptvect. locationoffsetFIQ28-4IRQ24-4Abort data16-8Abort instr.12-4SWI8 0Und. Instr.4 0The ARMs structure is in fact somewhat more complex. It features for each mode its own link and saved mode registers (LNK, SPSR). The processor automatically uses the pair belo
9、nging to the current mode. For the following, however, we may ignore this, as if there were only one pair for all modes.2. Interrupts in Oberon-ARMIn Oberon, interrupts are handled by procedures. Because their end must not consist of a simple branch and link instruction (BL), which restores the PC,
10、but by one that also restores the PSR, an interrupt procedure must be specially marked. This is done by an offset specification enclosed in brackets in place of a regular parameter list.In addition, the procedure must be “installed” in the corresponding vector location. This is done by placing a bra
11、nch instruction (BR) in that location using the SYSTEM.PUT operator. The address field of the jump must contain the offset of the interrupt procedure from the interrupt location.The following example shows a handler of the IRQ signal, which is assumed to be driven by a timer. It causes an LED to bli
12、nk once per second. LED and TIM are the addresses of a light emitting diode and of the timer respectively. Count and sense are variables used by the particular handler.MODULE TestIRQ; SVstk = 800h;VAR count, sense: INTEGER;PROCEDURE Handle 4;BEGIN INC(count); SYSTEM.PUT(TIM, 0); (*reset int req*)IF
13、count = 500 THEN SYSTEM.PUT(LED, sense); count := 0; sense := 1 - sense ENDEND Handle;BEGIN count := 0; sense := 1; (*system initialization; install handler*)SYSTEM.PUT(IRQvec, (SYSTEM.ADR(Handle) - IRQvec - 8) DIV 4 + 0EA000000H);SYSTEM.LDPSR(0, 0D2H); SYSTEM.SP := SVstk; (*set IRQ-stack pointer SP
14、*)SYSTEM.LDPSR(0, 53H); (*enable IRQ interrupt and assume supervisor mode*)REPEAT UNTIL FALSE (*main program, idle*)END TestIRQ.The compiled code for the handler is shown below. 1 E92D5FFFSTM SPsave registers R0-R11, FP, LNK 2 E1A0C00DMOV FP R0 SPFP := SP 3 E51FB018LDR R11 PC -24INC(count) 4 E28BB00
15、1ADD R11 R11 1 5 E50FB020STR R11 PC -32 . 20 E1A0D00CMOV SP R0 FPSP := FP 21 E8BD5FFFLDM SPrestore registers R0-R11, FP, LNK 22 E25EF004SUB PC LNK 4restore PSR, PC := LNKIn the case of the fast interrupt FIQ, the processor switches registers. It uses a fresh set of registers R8 R14. This makes it un
16、necessary to save those registers to memory and to restore them on exit. In order to make use of this property in Oberon, an interrupt handler may be marked by an asterisk like a leaf procedure. Local variables are then allocated in R11, R10, R9, R8. As in leaf procedures, only variables of types IN
17、TEGER and SET are admitted.In order to make this interrupt as fast as possible, no registers are saved at all. Hence, no FP is valid, and therefore no local variables in memory must be declared. These restrictions are not checked by the compiler!3. Traps in Oberon-ARMTraps are handled by the process
18、or through the same mechanism as interrupts, although their meaning is quite different. Whereas interrupts (caused by external signals, here IRQ and FIQ) call for an action, typically a short action) and a subsequent return to the interrupted program, traps (caused by internal signals reporting a fa
19、ilure) require a transfer to a specific program point, possibly after execution of a recovery routine. Therefore, whereas genuine interrupts correspond to a procedure call, traps correspond to a jump, a GOTO statement, an exception.How is a jump without return achieved in Oberon? There exists no exp
20、licit language construct for this purpose. Evidently, one must resort to the means of accessing system registers through use of PUT and GET operators.The following example shows how this is done for the case of the Software Interrupt (SWI). Typically, there is exactly one trap handler in a system. T
21、he example must therefore be considered as the core of a system with a single, fixed return point from traps. In this example, the handler sends out the low byte of the instruction that caused the trap. We recognize that the handler is essentially like the interrupt handler of the preceding section.
22、 However, it terminates by a jump to the resumption point in the body of the system.This is achieved by assigning the resumption address to the PC register and the desired mode to the PSR. The latter is done by the LDPSR intrinsic procedure. Note that this procedure cannot be executed in user mode.
23、It is feasible here, because a software trap puts the processor into supervisor mode.Three global variables called FPsv, SPsv, PCsv serve to hold the values which the three registers FP, SP, and PC must have at the resumption point. The three values are assigned to the respective registers at the en
24、d of the trap handler.MODULE System;IMPORT SYSTEM, IO;CONST trapvec = 8; mode = 0D0H; StkOrg = 300000H;VAR FPsv, SPsv, PCsv, n: INTEGER;PROCEDURE Trap 0;VAR adr, instr: INTEGER;BEGIN adr := SYSTEM.LNK; (*adr of trap instruction + 4*)SYSTEM.GET(adr-4, instr); IO.SendStr(trap); IO.SendInt(instr MOD 10
25、0H); IO.End;SYSTEM.LDPSR(0, mode);SYSTEM.FP := FPsv; SYSTEM.SP := SPsv; SYSTEM.PC := PCsv (*transfer*)END Trap;PROCEDURE Q(n: INTEGER);BEGIN ASSERT(n 10, 34); IO.SendStr( ok); IO.EndEND Q;BEGIN (*system initialization; install trap vector*)SYSTEM.PUT(trapvec, (SYSTEM.ADR(Trap) - trapvec - 8) DIV 4 + 0EA000000H);SYSTEM.LDPSR(0, mode); SYSTEM.SP := StkOrg; SYSTEM.FP := StkOrg; FPsv := SYSTEM.FP; SPsv := SYSTEM.SP;PCsv := SYSTEM.PC + 0; (*return point*)REPEAT IO.RecInt(n); Q(n) UNTIL FALSE (*main program*)END System.The compiled code corresponding to the trap handler is shown below. 1 E92D5FF
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年电子健康档案共享协议
- 培训课件:小红书焦虑情绪内容洞察数据分析报告
- 2025年夜间宠物经济行业报告
- 2026年机场集团工程建设指挥部招聘备考题库完整答案详解
- 高中个性化学习支持服务中AI应用的成本效益评估与实施效果分析教学研究课题报告
- 沧州医学高等专科学校2026年度高层次人才选聘的备考题库及答案详解参考
- 2026年院感管理环境微生物监测内容及计划
- 2025年秋人教版(简谱)初中音乐七年级上册期末测试卷(三套含答案)
- 2026年四川省产业技术研究转化有限公司人才招聘备考题库及参考答案详解1套
- 安徽省淮南市2025年部分高中引进紧缺专业人才备考题库(二)及答案详解(考点梳理)
- 四川省2025年高职单招职业技能综合测试(中职类)汽车类试卷(含答案解析)
- 广西柳州市2023-2024学年八年级上学期期末质量监测地理试卷
- 《铁道概论》题库及参考答案
- 新版物业交割单
- 网络教育毕业论文写作指导-公共关系学习通课后章节答案期末考试题库2023年
- GB/T 24002.1-2023环境管理体系针对环境主题领域应用GB/T 24001管理环境因素和应对环境状况的指南第1部分:通则
- GB/T 36767-2018醇胺类脱硫脱碳剂净化性能评价方法
- GB/T 16938-2008紧固件螺栓、螺钉、螺柱和螺母通用技术条件
- C语言课程设计-商品信息管理系统
- 中西方建筑对比课件
- 2022年医务科年度工作总结范文
评论
0/150
提交评论