prefetch abort

prefetch abort 是一类比较难解决的问题,因为很难定位出错的位置。

更奇怪的是:程序单独运行就会出错,使用VS2008按 F5 运行就不会出错。更不用想单步调试了,也不会出错啦!

 

类似于 Data Abort 的错误,prefetch abort 可能的原因有:

1)操作过程中有Bug,内容被修改;

2)内存重新映射以后,出错的地址处的内容没有初始化;arm,linux,winbond,nuvoton,w90p710,w90n745, 开源,嵌入式,操作系统,嵌入式开发,嵌入式联盟,linux,ecos,uclinux,t- kernel,freeos,rtems,ucos,skyeye,  y1 p) [1 d0 F, ]/ T2 K- W
- 我们只做简洁、实用、专业的嵌入式开发技术论坛。0 m2 `# m& a- d2 H3 P8 n
3)PC指针无效;

 

在网上查找到有这样一篇文章:

Windows CE: Prefetch Aborts, why they are difficult to locate

转载其内容:

Prefetch aborts can be difficult to locate and fix.  To understand why, we first need to understand what a prefetch abort is.  A prefetch abort occurs when the CPU runs out of instructions in its pipeline.  But that can also mean that a zero instruction is in the pipeline.

Possible causes of prefetch aborts:

  1. The CPU really can't get instructions to run.  This could indicate a hardware problem.
  2. An uninitialized function pointer.  I have seen this used as a way to indicate a problem, although I can think of better ways to indicate problems.  This can also be a bug in the code.



    Causes the following debug output:

    Prefetch Abort: Thread=8339d4a8 Proc=81327730 'SDMenu.exe'
    AKY=00000021 PC=00000000(???+0x00000000) RA=00011a58(SDMenu.exe+0x00001a58) BVA=
    00000000 FSR=000004f0

    Notice that the Program Counter (PC) is zero, which should never happen.  But the good news is that the Return Address (RA) is telling us where the code last was.  So this abort message does give us something to go on to find the problem.
  3. Stack overrun, or corrupted stack.

    Writting code to demonstrate this is a challenge becuase the compiler's job is to optimize out code that doesn't do anything.  So the following two functions will cause the prefetch abort.  The reason for the two functions is to trick the compiler into createing the necessary assembly code.

    This set of functions will cause a prefetch abort by corrupting the stack:.


    When it runs, the following abort occurs.  Notice the PC is zero again. Notice that the RETAILMSG at the end of CausePrefetchStackAbort() is displayed, just before the return address is popped off the stack.

    returning CausePrefetchStackAbort( 500 )
    Prefetch Abort: Thread=8339d550 Proc=81327730 ''
    AKY=00000021 PC=00000000(???+0x00000000) RA=00000000(???+0x00000000) BVA=0000000
    0 FSR=000004f0

So the problem with prefetch aborts is that the abort message doesn't always give much to go on to track back to the cause.  When it does, we can use that to find the problem in the code.  I will cover that in a post on Data Aborts soon.

 

### Keil 工程项目中配置和使用 .S 汇编文件作为启动文件 #### 配置和使用.S 文件作为启动文件的方法 在Keil工程项目中,.S汇编文件通常用于初始化硬件并设置堆栈指针、向量表以及其他必要的系统参数。对于STM32系列微控制器而言,`startup_stm32f10x_md.s`是一个典型的启动文件[^1]。 为了使该类型的启动文件能够被正确识别和利用,在创建新的工程或者导入现有源码时需要注意以下几点: - **添加启动文件至工程** 将`.s`扩展名的启动脚本加入到项目的Source Group里去。这一步骤可以通过双击Project窗口下的Target名称来打开Options对话框完成;接着切换到“Target”标签页下找到“Manage”按钮旁边的下拉菜单选择“Add Existing Files to Group '...'”,浏览定位到所需的启动文件路径后点击OK确认加载。 - **指定正确的设备型号** 在同一个选项卡内的Device字段处输入目标MCU的确切型号(例如STM32F103RCT6),这样可以确保链接器能获取到相应的内存布局信息以及预定义符号等资源。 - **调整Linker Script** 对于大多数情况下,默认提供的散列文件(`*.icf`)已经足够满足需求。但如果遇到特殊情况,则可能需要手动编辑这些文件以适应特定的应用场景。通过修改scatter-loading description file(.icf),可自定义ROM/RAM区域大小及其起始位置等内容。 - **启用复位处理程序** 启动代码内部包含了多个入口点,其中最重要的是Reset_Handler()函数——它负责执行最基础级别的CPU状态恢复工作。因此要保证此部分逻辑无误,并且按照实际应用场景合理安排后续操作流程。 ```assembly Reset_Handler PROC IMPORT __main LDR R0, =__main BX R0 ENDP ``` 上述示例展示了如何重定向reset handler指向C库入口(__main)。 #### S3C2440 的特殊考虑事项 针对ARM9架构处理器如S3C2440来说,除了遵循上面提到的一般原则之外还需要额外关注中断机制的设计。具体做法是在`s3c2440.s`里面增加相应IRQ/FIQ中断向量项,并将其关联到用户自定义的服务子程序上[^2]。 ```assembly AREA RESET, CODE, READONLY ENTRY ; ...其他指令... _start: B reset_handler ; 复位异常 LDR PC, [PC, #8*1] ; undefined instruction abort LDR PC, [PC, #8*2] ; software interrupt (SWI) LDR PC, [PC, #8*3] ; prefetch abort LDR PC, [PC, #8*4] ; data abort NOP ; reserved LDR PC, [PC, #8*6] ; IRQ LDR PC, [PC, #8*7] ; FIQ ; 定义各异常模式下的跳转地址 DCD reset_handler ; 复位 DCD undef_instruction ; Undefined Instruction Handler DCD swi_handler ; Software Interrupt Handler DCD pre_abort ; Prefetch Abort Handler DCD data_abort ; Data Abort Handler DCD 0 ; Reserved DCD irq_handler ; IRQ Handler DCD fiq_handler ; FIQ Handler ALIGN END ``` 这段代码片段说明了怎样构建一个完整的异常向量表结构,同时预留出了将来可能会用到的各种异常响应接口。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

91program

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值