欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    嵌入式处理器架构与程式设计课件.ppt

    • 资源ID:91506893       资源大小:237KB        全文页数:72页
    • 资源格式: PPT        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    嵌入式处理器架构与程式设计课件.ppt

    嵌入式處理器架構與程式設計王建民中央研究院 資訊所2008年 7月ContentsnIntroductionnComputer ArchitecturenARM ArchitecturenDevelopment Tools:GNU Development ToolsnARM Instruction SetnARM Assembly LanguagenARM Assembly Programming:GNU ARM ToolChainnInterrupts and Monitor2Lecture 10Interrupts and MonitorOutlinenException Handling and Software InterruptsnELF:Executable and Linking FormatnARM Monitor and Program Loading4Normal Program Flow vs.ExceptionnNormally,programs execute sequentially(with a few branches to make life interesting)nNormally,programs execute in user mode nExceptions and interrupts break the sequential flow of a program,jumping to architecturallydefined memory locations nIn ARM,SoftWare Interrupt(SWI)is the“system call”exception5ARM ExceptionsnTypes of ARM exceptions lReset:when CPU reset pin is asserted lundefined instruction:when CPU tries to execute an undefined opcode lsoftware interrupt:when CPU executes the SWI instruction lprefetch abort:when CPU tries to execute an instruction prefetched from an illegal addressldata abort:when data transfer instruction tries to read or write at an illegal address lIRQ:when CPUs external interrupt request pin is asserted lFIQ:when CPUs external fast interrupt request pin is asserted 6The Programmers ModelnProcessor Modes(of interest)lUser:the“normal”program execution mode.lIRQ:used for generalpurpose interrupt handling.lSupervisor:a protected mode for the operating system.nThe Register SetlRegisters R0R15+CPSRlR13:Stack Pointer(by convention)lR14:Link Register(hardwired)lR15:Program Counter where bits 0:1 are ignored(hardwired)7TerminologynThe terms exception and interrupt are often confused nException usually refers to an internal CPU eventlfloating point overflow lMMU fault(e.g.,page fault)ltrap(SWI)nInterrupt usually refers to an external I/O eventlI/O device request lreset nIn the ARM architecture manuals,the two terms are mixed together8What do SWIs do?nSWIs(often called software traps)allow a user program to“call”the OS that is,SWIs are how system calls are implemented.nWhen SWIs execute,the processor changes modes(from User to Supervisor mode on the ARM)and disables interrupts.9SWI ExamplenTypes of SWIs in ARM Angel(axd or armsd)lSWI_WriteC(SWI 0)Write a byte to the debug channel lSWI_Write0(SWI 2)Write the nullterminated string to debug channel lSWI_ReadC(SWI 4)Read a byte from the debug channel lSWI_Exit(SWI 0 x11)Halt emulation this is how a program exits lSWI_EnterOS(SWI 0 x16)Put the processor in supervisor mode lSWI_Clock(SWI 0 x61)Return the number of centiseconds lSWI_Time(SWI 0 x63)Return the number of secs since Jan.1,197010What happens on an SWI?1nThe ARM architecture defines a Vector Table indexed by exception type nOne SWI,CPU does the following:PC 0 x08 nAlso,sets LR_svc,SPSR_svc,CPSR(supervisor mode,no IRQ)ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)SWI Handler111What happens on an SWI?2nNot enough space in the table(only one instruction per entry)to hold all of the code for the SWI handler function nThis one instruction must transfer control to appropriate SWI Handler nSeveral options are presented in the next slideADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)SWI Handler212“Vectoring”Exceptions to HandlersnOption of choice:Load PC from jump table(shown below)nAnother option:Direct branch(limited range)ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER ProgramLDR pc,pc,0 x100 LDR pc,pc,0 x100 LDR pc,pc,0 x100 LDR pc,pc,0 x100LDR pc,pc,0 x100 LDR pc,pc,0 x100 LDR pc,pc,0 x100 LDR pc,pc,0 x100Vector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1cSWI Handler(S_Handler)2&A_Handler&U_Handler&S_Handler&P_Handler.“Jump”Table0 x1080 x10c0 x1100 x114.Why 0 x110?13What happens on SWI completion?nVectoring to the S_Handler starts executing the SWI handler nWhen the handler is done,it returns to the program at the instruction following the SWI nMOVS restores the original CPSR as well as changing pcADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)3MOVS pc,lrSWI Handler(S_Handler)14How to determine the SWI number?nAll SWIs go to 0 x08ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)SWI Handler must serve as clearinghouse for differentSWIsMOVS pc,lrSWI Handler(S_Handler)15SWI Instruction FormatnExample:SWI 0 x1824bit“comment”field(ignored by processor)1 1 1 1cond02324273128SWI number16Executing SWI InstructionOn SWI,the processor(1)copies CPSR to SPSR_SVC(2)set the CPSR mode bits to supervisor mode(3)sets the CPSR IRQ to disable(4)stores the value(PC+4)into LR_SVC(5)forces PC to 0 x08 ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)LDR r0,lr,#4BIC r0,r0,#0 xff000000R0 holds SWI numberMOVS pc,lrSWI Handler(S_Handler)24bit“comment”field(ignored by processor)1 1 1 1cond17Jump to“Service Routine”ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)LDR r0,lr,#4BIC r0,r0,#0 xff000000switch(r0)case 0 x00:service_SWI1();case 0 x01:service_SWI2();case 0 x02:service_SWI3();MOVS pc,lrSWI Handler(S_Handler)24bit“comment”field(ignored by processor)1 1 1 1condOn SWI,the processor(1)copies CPSR to SPSR_SVC(2)set the CPSR mode bits to supervisor mode(3)sets the CPSR IRQ to disable(4)stores the value(PC+4)into LR_SVC(5)forces PC to 0 x08 18Problem with The Current HandlerOn SWI,the processor(1)copies CPSR to SPSR_SVC(2)set the CPSR mode bits to supervisor mode(3)sets the CPSR IRQ to disable(4)stores the value(PC+4)into LR_SVC(5)forces PC to 0 x08 ADD r0,r0,r1 SWI 0 x10 SUB r2,r2,r0USER Programto R_Handlerto U_Handlerto S_Handlerto P_Handlerto D_Handler.to I_Handlerto F_HandlerVector Table(spring board)starting at 0 x00 in memory0 x000 x040 x080 x0c0 x100 x140 x180 x1c(Reset(Undef instr.)(SWI)(Prefetch abort)(Data abort)(Reserved)(IRQ)(FIQ)LDR r0,lr,#4BIC r0,r0,#0 xff000000switch(r0)case 0 x00:service_SWI1();case 0 x01:service_SWI2();case 0 x02:service_SWI3();MOVS pc,lrSWI Handler(S_Handler)What was in R0?User program may have been using this register.Therefore,cannot just use it must first save it 19Full SWI HandlerS_Handler:SUB sp,sp,#4 leave room on stack for SPSR STMFD sp!,r0r12,lr store users gp registersMRS r2,spsr get SPSR into gp registersSTR r2,sp,#14*4 store SPSR above gp registersMOV r1,sp pointer to parameters on stack LDR r0,lr,#4 extract the SWI number BIC r0,r0,#0 xff000000 get SWI#by bitmaskingBL C_SWI_handler go to handler(see next slide)LDR r2,sp,#14*4 restore SPSR(NOT“sp!”)MSR spsr_csxf,r2 csxf flagsLDMFD sp!,r0r12,lr unstack users registers ADD sp,sp,#4 remove space used to store SPSR MOVS pc,lr return from handlergp=general-purposeSPSR is stored above gp registers since the registers may contain system call parameters(sp in r1)20C_SWI_Handlervoid C_SWI_handler(unsigned number,unsigned*regs)switch(number)case 0:/*SWI number 0 code*/break;case 1:/*SWI number 1 code*/break;.case 0 x100:puts(“SWI 0 x100 trigged!n”);break;.case XXX:/*SWI number XXX code*/break;default:/*end switch*/*end C_SWI_handler()*/spsr_svclr_svcr4r3r12r11r10r9r8r7r6r5r2r1r0Previous sp_svcsp_svcregs12regs0(also*regs)21Loading the Vector Table/*For 18349,the Vector Table will use the LDR PC,PC,*offset springboard approach*/unsigned Install_Handler(unsigned int routine,unsigned int*vector)unsigned int pcload_instr,old_handler,*soft_vector;pcload_instr=*vector;/*read the Vector Table instr(LDR.)*/pcload_instr&=0 xfff;/*compute offset of jump table entry */pcload_instr+=0 x8+(unsigned)vector;/*=offset adjusted by PC and prefetch */soft_vector=(unsigned*)pcload_instr;/*address to load pc from*/old_handler=*soft_vector;/*remember the old handler */*soft_vector=routine;/*set up new handler in jump table */return(old_handler);/*return old handler address */*end Install_Handler()*/Called as Install_Handler(unsigned)S_Handler,swivec);where,unsigned*swivec=(unsigned*)0 x08;22 .text .align 2 .global triggertrigger:STMFD sp!,lr SWI#0 x100 LDMFD sp!,pcextern void S_Handler();extern void trigger();int main()unsigned*swivec=(unsigned*)0 x08;unsigned backup;backup=Install_Handler(unsigned)S_Handler,swivec);trigger();Install_Handler(backup,swivec);Example:SWI Application23Exercise#3nWrite a service routine that receives a file name from a trigger and display the first lines of the file on the screen.lVoid service101(char*filename);nWrite a trigger that pass a file name as an argument to the above service routine through SWI#0 x101.lvoid trigger101(char*filename);nWrite a main program to perform a demonstration.24OutlinenException Handling and Software InterruptsnELF:Executable and Linking FormatnARM Monitor and Program Loading25Introduction to ELFnExecutable and Linking FormatnDeveloped by Unix System Lab.nDefault binary format on Linux,Solaris 2.x,etcnSome of the capabilities of ELF are dynamic linking,dynamic loading,imposing runtime control on a program,and an improved method for creating shared libraries.nThe ELF representation of control data in an object file is platform independent.26Three Types of ELF FilesnRelocatable fileldescribes how it should be linked with other object files to create an executable file or shared library.nExecutable filelsupplies information necessary for the operating system to create a process image suitable for executing the code and accessing the data contained within the file.nShared object filelcontains information needed in both static and dynamic linking.27ELF File FormatnTwo views for each of the three file types.lLinking view and execution viewnThese views support both the linking and execution of a program.lLinking view is partitioned by sections.lExecution view is partitioned by segments.nThe ELF access library,libelf,provides tools to extract and manipulate ELF object files.28ELF File Format(cont.)nLinking View Execution ViewELF headerProgram header table(optional)Section 1Section nSection header tableELF headerProgram header tableSegment 1Segment nSection header table(optional)29Example:readelfnWe can use“readelf”to output ELF informationnExampleluse“e”option to read all header from the executable file of“hello.c”$cat hello.c/*hello.c,a simple example program*/#define GREETING Hello,World!nint main()puts(GREETING);$armelfgcc o hello.elf hello.c$armelfreadelf e hello.elf30Example:ELF HeaderELF Header:Magic:7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 Class:ELF32 Data:2s complement,little endian Version:1(current)OS/ABI:ARM ABI Version:0 Type:EXEC(Executable file)Machine:ARM Version:0 x1 Entry point address:0 x8100 Start of program headers:52(bytes into file)Start of section headers:168152(bytes into file)Flags:0 x202,has entry point,GNU EABI,software FP Size of this header:52(bytes)Size of program headers:32(bytes)Number of program headers:1 Size of section headers:40(bytes)Number of section headers:25 Section header string table index:2231Example:Section HeaderSection Headers:Nr Name Type Addr Off Size ES Flg Lk Inf Al 0 NULL 00000000 000000 000000 00 0 0 0 1.init PROGBITS 00008000 008000 000020 00 AX 0 0 4 2.text PROGBITS 00008020 008020 0030e8 00 AX 0 0 4 3.fini PROGBITS 0000b108 00b108 00001c 00 AX 0 0 4 4.rodata PROGBITS 0000b124 00b124 000020 00 A 0 0 4 5.data PROGBITS 0000b244 00b244 00092c 00 WA 0 0 4 6.eh_frame PROGBITS 0000bb70 00bb70 000004 00 A 0 0 4 7.ctors PROGBITS 0000bb74 00bb74 000008 00 WA 0 0 4 8.dtors PROGBITS 0000bb7c 00bb7c 000008 00 WA 0 0 4 9.jcr PROGBITS 0000bb84 00bb84 000004 00 WA 0 0 4 10.bss NOBITS 0000bb88 00bb88 00010c 00 WA 0 0 4 ment PROGBITS 00000000 00bb88 000288 00 0 0 1 12.debug_aranges PROGBITS 00000000 00be10 000420 00 0 0 8 13.debug_pubnames PROGBITS 00000000 00c230 000726 00 0 0 1 14.debug_info PROGBITS 00000000 00c956 011f48 00 0 0 1 15.debug_abbrev PROGBITS 00000000 01e89e 0031f4 00 0 0 1 16.debug_line PROGBITS 00000000 021a92 002a14 00 0 0 1 17.debug_frame PROGBITS 00000000 0244a8 000a14 00 0 0 4 18.debug_str PROGBITS 00000000 024ebc 001406 01 MS 0 0 1 19.debug_loc PROGBITS 00000000 0262c2 002be0 00 0 0 1 20.stack PROGBITS 00080000 028ea2 000000 00 W 0 0 1 21.debug_ranges PROGBITS 00000000 028ea2 000150 00 0 0 1 22.shstrtab STRTAB 00000000 028ff2 0000e3 00 0 0 1 23.symtab SYMTAB 00000000 0294c0 001590 10 24 ef 4 24.strtab STRTAB 00000000 02aa50 0007f9 00 0 0 1Key to Flags:W(write),A(alloc),X(execute),M(merge),S(strings)I(info),L(link order),G(group),x(unknown)O(extra OS processing required)o(OS specific),p(processor specific)32Example:Program HeaderProgram Headers:Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0 x008000 0 x00008000 0 x00008000 0 x03b88 0 x03c94 RWE 0 x8000 Section to Segment mapping:Segment Sections.00 .init.text.fini.rodata.data.eh_frame.ctors.dtors.jcr.bss 33Data RepresentationnSupport various processors with 8bit bytes and 32bit architectures.nIntended to be extensible to larger or smaller architecture.NameSizeAlignment PurposeElf32_Addr44Unsigned program addressElf32_Half22Unsigned medium integerElf32_Off44Unsigned file offsetElf32_Sword44Signed large integerElf32_Word44Unsigned large integerunsigned char 11Unsigned small integer34ELF Header1nIt is always the first section of the file.nDescribes the type of the object file.nIts target architecture,and the version of ELF it is using.nThe location of the Program Header table,Section Header table,and String table along with associated number and size of entries for each table are also given.nContains the location of the first executable instruction.35ELF Header2#define EI_NIDENT 16typedef struct unsigned chare_identEI_NIDENT;/file ID,interpretation Elf32_Halfe_type;/object file type Elf32_Halfe_machine;/target architecture Elf32_Worde_version;/ELF version El

    注意事项

    本文(嵌入式处理器架构与程式设计课件.ppt)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开