搜索
bottom↓
回复: 3

请问cortex-m3的权威指南这句话是否出错?

[复制链接]

出0入0汤圆

发表于 2012-11-25 14:31:04 | 显示全部楼层 |阅读模式
该书2009年7月出版的,P342页

咱对汇编不熟悉,所以一开始就暂且相信了“从(xSP-0x24)处读取入栈PC”。但后来发觉怎么都对头,一看汇编LDREQ R0,[R0,#24],这应该是xSP+0x18的意思吧。第一不应该是减号,第二不应该是16进制的24。请熟悉的大侠帮我看看,是不是有问题?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2012-11-26 08:40:38 | 显示全部楼层
应该是减回去 #20,因为栈生长方向的问题,所以是加

出0入0汤圆

发表于 2012-11-26 08:41:42 | 显示全部楼层

02
* HardFaultHandler_C:
03
* This is called from the HardFault_HandlerAsm with a pointer the Fault stack
04
* as the parameter. We can then read the values from the stack and place them
05
* into local variables for ease of reading.
06
* We then read the various Fault Status and Address Registers to help decode
07
* cause of the fault.
08
* The function ends with a BKPT instruction to force control back into the debugger
09
*/
10
void HardFault_HandlerC(unsigned long *hardfault_args){
11
  volatile unsigned long stacked_r0 ;
12
  volatile unsigned long stacked_r1 ;
13
  volatile unsigned long stacked_r2 ;
14
  volatile unsigned long stacked_r3 ;
15
  volatile unsigned long stacked_r12 ;
16
  volatile unsigned long stacked_lr ;
17
  volatile unsigned long stacked_pc ;
18
  volatile unsigned long stacked_psr ;
19
  volatile unsigned long _CFSR ;
20
  volatile unsigned long _HFSR ;
21
  volatile unsigned long _DFSR ;
22
  volatile unsigned long _AFSR ;
23
  volatile unsigned long _BFAR ;
24
  volatile unsigned long _MMAR ;
25

26
  stacked_r0 = ((unsigned long)hardfault_args[0]) ;
27
  stacked_r1 = ((unsigned long)hardfault_args[1]) ;
28
  stacked_r2 = ((unsigned long)hardfault_args[2]) ;
29
  stacked_r3 = ((unsigned long)hardfault_args[3]) ;
30
  stacked_r12 = ((unsigned long)hardfault_args[4]) ;
31
  stacked_lr = ((unsigned long)hardfault_args[5]) ;
32
  stacked_pc = ((unsigned long)hardfault_args[6]) ;
33
  stacked_psr = ((unsigned long)hardfault_args[7]) ;
34

35
  // Configurable Fault Status Register
36
  // Consists of MMSR, BFSR and UFSR
37
  _CFSR = (*((volatile unsigned long *)(0xE000ED28))) ;
38

39
  // Hard Fault Status Register
40
  _HFSR = (*((volatile unsigned long *)(0xE000ED2C))) ;
41

42
  // Debug Fault Status Register
43
  _DFSR = (*((volatile unsigned long *)(0xE000ED30))) ;
44

45
  // Auxiliary Fault Status Register
46
  _AFSR = (*((volatile unsigned long *)(0xE000ED3C))) ;
47

48
  // Read the Fault Address Registers. These may not contain valid values.
49
  // Check BFARVALID/MMARVALID to see if they are valid values
50
  // MemManage Fault Address Register
51
  _MMAR = (*((volatile unsigned long *)(0xE000ED34))) ;
52
  // Bus Fault Address Register
53
  _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;
54

55
  __asm("BKPT #0\n") ; // Break into the debugger
56
}
57

58
__attribute__((naked))
59
PE_ISR(Cpu_ivINT_Hard_Fault)
60
{
61
  __asm volatile (
62
    " movs r0,#4       \n"
63
    " movs r1, lr      \n"
64
    " tst r0, r1       \n"
65
    " beq _MSP         \n"
66
    " mrs r0, psp      \n"
67
    " b _HALT          \n"
68
  "_MSP:               \n"
69
    " mrs r0, msp      \n"
70
  "_HALT:              \n"
71
    " ldr r1,[r0,#20]  \n"
72
    " b HardFault_HandlerC \n"
73
    " bkpt #0          \n"
74
  );
75
}

出0入0汤圆

 楼主| 发表于 2012-11-26 09:19:09 | 显示全部楼层
是啊,而且数值也不对,应该是0x18
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-21 01:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表