<div dir="ltr"><br><div style>Source code:rtems 4.11</div><div style>gcc version  :arm-rtemseabi4.11-</div><div style>Arch           : arm1176jzf-s, s3c6410</div><div style><br></div><div style>When I am testing fileio testcase on s3c6410 board, I always encounter such problems:</div>
<div style><br></div><div style>shell</div><div style><div><div>1.</div><div><div>[/] # abc</div><div><b>scriptFile 50183118, length 1          //(0)</b><br></div><div><br></div><div><br></div><div>Unrecognized instruction</div>
<div>data_abort at address 0x501225D8, instruction: 0xE18430B0,   spsr = 0x40000113</div><div>active thread thread 0x0A010003</div><div>Previous sp=0x50183000 lr=0x501225D0 and actual cpsr=60000197</div><div> 0x00000020 0x501842D0 0x00000003 0x50122898 0x501770D8 0x00000020</div>
<div> 0x5017CDD8 0x1A010004 0x00000000 0x501839B0 0x50183078 0x00000000</div><div> 0x00000001 0x00000001 0x501835DC 0x5011346C 0x501835DC 0x00000000</div><div> 0x00000000 0x0017B260 0x5017CDD8 0x50111C4C 0x00000059 0x00000000</div>
<div> 0x5017B260 0x50183618 0x501831B8 0x50145334 0x00000000 0x501449B0</div><div> 0x5017B260 0x5017B228 0x00000059 0x00000000 0x501839AF 0x00000001</div><div> 0x00000104 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000</div>
<div> 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000</div></div></div><div><br></div><div style>But if I input "/abc", all is ok.</div><div style><br></div><div style><br></div><div style><br>
</div><div style><div style>I am confusing why use "strh", but not "strb" instruction. Because if r4+r0 is not aligned, fault occurs.</div><div style><br></div><div style>The source code of findOnPATH is </div>
<div style><br></div></div><div style><div>static int findOnPATH(</div><div>  const char *userScriptName,  <b>//register r0</b></div><div>  char       *scriptFile,              <b> //register r1</b></div><div>  size_t      scriptFileLength      <b>//register r2</b></div>
<div>)</div><div>{</div><div>  int sc;</div><div>.............................</div><div><div>    /* XXX should use strncat but what is the limit? */</div><div><div>    getcwd( scriptFile, PATH_MAX ); <b>(1)</b></div><div>
<span style="white-space:pre">    </span>printk("scriptFile %s, length %d\n", scriptFile, strlen(scriptFile));</div><div>    strncat( scriptFile, "/", PATH_MAX );<b>(2)</b></div><div>    strncat(                                          <b> (3)</b></div>
<div>      scriptFile,</div><div>      ( (userScriptName[0] == '.' && userScriptName[1] == '/') ?</div><div>         &userScriptName[2] : userScriptName),</div><div>      PATH_MAX</div><div>    );</div>
</div></div><div><br></div><div><br></div><div>.............................</div><div>}</div><div><br></div><div><div>The correspondence between  assemble  and  c code is   (a)---(1) , (b)----(2), (c)----(3)</div></div><div>
I locate the address <b>0x501225D8</b>. The dissassemble code is following:<br></div><div>gcc optimize the code for (2).<br></div><div><br></div><div><div>5012258c <findOnPATH.isra.0>:</div><div>5012258c:<span class="" style="white-space:pre"> </span>e92d4038 <span class="" style="white-space:pre"> </span>push<span class="" style="white-space:pre">      </span>{r3, r4, r5, lr}</div>
<div>50122590:<span class="" style="white-space:pre">   </span>e5d03000 <span class="" style="white-space:pre"> </span>ldrb<span class="" style="white-space:pre">      </span>r3, [r0]</div><div>50122594:<span class="" style="white-space:pre">  </span>e1a05000 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r5, r0</div>
<div>50122598:<span class="" style="white-space:pre">   </span>e353002f <span class="" style="white-space:pre"> </span>cmp<span class="" style="white-space:pre">       </span>r3, #47<span class="" style="white-space:pre">   </span>; 0x2f</div>
<div>5012259c:<span class="" style="white-space:pre">   </span>e1a04001 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r4, r1   <b> //store scriptFile --> r4</b></div><div>
501225a0:<span class="" style="white-space:pre">      </span>0a00001b <span class="" style="white-space:pre"> </span>beq<span class="" style="white-space:pre">       </span>50122614 <findOnPATH.isra.0+0x88></div><div>501225a4:<span class="" style="white-space:pre">   </span>e3a010ff <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r1, #255<span class="" style="white-space:pre">  </span>; 0xff</div>
<div>501225a8:<span class="" style="white-space:pre">   </span>e1a00004 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r0, r4</div><div>501225ac:<span class="" style="white-space:pre">    </span>eb009dd6 <span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>50149d0c <getcwd> <b>(a)</b></div>
<div>501225b0:<span class="" style="white-space:pre">   </span>e1a00004 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r0, r4 <b> //restore scriptFile-->r0</b></div><div>
501225b4:<span class="" style="white-space:pre">      </span>eb00b27a <span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>5014efa4 <strlen></div><div>501225b8:<span class="" style="white-space:pre">   </span>e1a01004 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r1, r4</div>
<div>501225bc:<span class="" style="white-space:pre">   </span>e1a02000 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r2, r0</div><div>501225c0:<span class="" style="white-space:pre">    </span>e59f0070 <span class="" style="white-space:pre"> </span>ldr<span class="" style="white-space:pre">       </span>r0, [pc, #112]<span class="" style="white-space:pre">    </span>; 50122638 <findOnPATH.isra.0+0xac></div>
<div>501225c4:<span class="" style="white-space:pre">   </span>ebffb4a6 <span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>5010f864 <printk></div><div>501225c8:<span class="" style="white-space:pre">   </span>e1a00004 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r0, r4 <b> //restore scriptFile-->r0</b></div>
<div>501225cc:<span class="" style="white-space:pre">   </span>eb00b274 <span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>5014efa4 <strlen>  <b>//strlen(scriptFile) here lenght is 1 because (1)</b></div>
<div><b>assign "/" to scriptFile, so strlen assigns 1 to r0.</b></div><div>501225d0:<span class="" style="white-space:pre">   </span>e59f3064 <span class="" style="white-space:pre"> </span>ldr<span class="" style="white-space:pre">       </span>r3, [pc, #100]<span class="" style="white-space:pre">    </span>; 5012263c <findOnPATH.isra.0+0xb0></div>
<div>501225d4:<span class="" style="white-space:pre">   </span>e1d330b0 <span class="" style="white-space:pre"> </span>ldrh<span class="" style="white-space:pre">      </span>r3, [r3] <b>//It loads '2f00' from address (d)  to r3, in string format is "/"</b></div>
<div>501225d8:<span class="" style="white-space:pre">   </span>e18430b0 <b><span class="" style="white-space:pre">        </span>strh<span class="" style="white-space:pre">      </span>r3, [r4, r0] // (b)  r4 is 0x50183118, r0 is 1.</b></div>
<div>501225dc:<span class="" style="white-space:pre">   </span>e5d53000 <span class="" style="white-space:pre"> </span>ldrb<span class="" style="white-space:pre">      </span>r3, [r5]</div><div>501225e0:<span class="" style="white-space:pre">  </span>e353002e <span class="" style="white-space:pre"> </span>cmp<span class="" style="white-space:pre">       </span>r3, #46<span class="" style="white-space:pre">   </span>; 0x2e</div>
<div>501225e4:<span class="" style="white-space:pre">   </span>0a00000f <span class="" style="white-space:pre"> </span>beq<span class="" style="white-space:pre">       </span>50122628 <findOnPATH.isra.0+0x9c></div><div>501225e8:<span class="" style="white-space:pre">   </span>e1a00004 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r0, r4</div>
<div>501225ec:<span class="" style="white-space:pre">   </span>e1a01005 <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r1, r5</div><div>501225f0:<span class="" style="white-space:pre">    </span>e3a020ff <span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre">       </span>r2, #255<span class="" style="white-space:pre">  </span>; 0xff</div>
<div>501225f4:<span class="" style="white-space:pre">   </span>eb00b282 <span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre">        </span>5014f004 <strncat> <b>(c)</b></div></div><div>...............</div>
<div><div>5012263c:<span class="" style="white-space:pre">        </span>5016fe5c <span class="" style="white-space:pre"> </span>andspl<span class="" style="white-space:pre">    </span>pc, r6, ip, asr lr<span class="" style="white-space:pre">        </span>; <UNPREDICTABLE></div>
</div><div>...............</div><div><div>5016fe5c:<span class="" style="white-space:pre">      </span><b>0000002f </b><span class="" style="white-space:pre">      </span>andeq<span class="" style="white-space:pre">     </span>r0, r0, pc, lsr #32<b> (d) </b></div>
</div><div><br></div><div style><br></div><div style><div>why (b) incurs fault? r4 is an 4 byte aligned address listed in (0), while r0 is 1. Thus strh access an unaligned address, and incurs fault. Why using strh when not know the length of "scriptFile".</div>
<div style>I am not sure whether this analysis is correct, but I have no other reasonable explanation.</div><div style><br></div><div style>Thanks in advance for you advice.</div><div style><br></div><div style>Regards,</div>
<div style>Peng.</div></div></div></div></div>