Arm Community
Site
Search
User
Site
Search
User
Groups
Arm Research
DesignStart
Education Hub
Graphics and Gaming
High Performance Computing
Innovation
Multimedia
Open Source Software and Platforms
Physical
Processors
Security
System
Software Tools
TrustZone for Armv8-M
中文社区
Blog
Announcements
Artificial Intelligence
Automotive
Healthcare
HPC
Infrastructure
Innovation
Internet of Things
Machine Learning
Mobile
Smart Homes
Wearables
Forums
All developer forums
IP Product forums
Tool & Software forums
Support
Open a support case
Documentation
Downloads
Training
Arm Approved program
Arm Design Reviews
Community Help
More
Cancel
Developer Community
Tools and Software
Software Tools
Jump...
Cancel
Software Tools
Arm Development Studio forum
Unaligned access problems
Tools, Software and IDEs blog
Forums
Videos & Files
Help
Jump...
Cancel
New
Replies
3 replies
Subscribers
126 subscribers
Views
2736 views
Users
0 members are here
Related
Unaligned access problems
Offline
Felix Varghese
over 7 years ago
Note: This was originally posted on 1st June 2009 at http://forums.arm.com
We had written some code for an ARM Cortex M3 platform. But now, we have to port it to an ARM7TDMI based controller in very little time. The problem is the former supports unaligned access, but the latter doesnt. Now, we have lots of code of the form:
unsigned int a;
char b[100];
a = *( ( unsigned int *) &b[5] );
As you can see, we were using typecasts to copy 4-byte entities and also 2 byte entities in many places. We are using IAR compiler. The code works fine when run on Cortex M3 but when ARM7TDMI encounters this kind of instructions, it goes into abort. Is there any way we can cause the compiler to generate appropriate instructions so that aborts do not occur, other than replacing all of this kind of instructions with byte-wise memcopys ?
Parents
Offline
Peter Harris
over 7 years ago
Note: This was originally posted on 1st June 2009 at
http://forums.arm.com
A C compiler will always generally assume that integers are aligned - so there is normally no "quick" solution to this problem. Casting an integer to an unaligned memory address is not strictly valid C, so you are really in to implementation defined behavior of the compiler.
With the RealView tools you can make a pointer point to a packed object - which will generate either unaligned accesses or byte accesses depending on the CPU you have chosen and the presence of the --[no-]unaligned flag:
__packed int *pMyInt;
There might be an equivalent for the IAR tools - but it varies from tool to tool ...
Cancel
Up
0
Down
Reply
Cancel
Reply
Offline
Peter Harris
over 7 years ago
Note: This was originally posted on 1st June 2009 at
http://forums.arm.com
A C compiler will always generally assume that integers are aligned - so there is normally no "quick" solution to this problem. Casting an integer to an unaligned memory address is not strictly valid C, so you are really in to implementation defined behavior of the compiler.
With the RealView tools you can make a pointer point to a packed object - which will generate either unaligned accesses or byte accesses depending on the CPU you have chosen and the presence of the --[no-]unaligned flag:
__packed int *pMyInt;
There might be an equivalent for the IAR tools - but it varies from tool to tool ...
Cancel
Up
0
Down
Reply
Cancel
Children
No data
More questions in this forum
By title
By date
By reply count
By view count
By most asked
By votes
By quality
Descending
Ascending
All recent questions
Unread questions
Questions you've participated in
Questions you've asked
Unanswered questions
Answered questions
Questions with suggested answers
Questions with no replies
Answered
Failed to read contents of Internal RAM L1-I_DATA in ARM DS
0
Arm Development Studio
Cache
Debug and Trace Services Layer (DTSL)
13457
views
23
replies
Latest
4 months ago
by
Boon Khai
Answered
DS-5 connect fail when cortex-r5 is in lock-step mode
+1
11225
views
10
replies
Latest
5 months ago
by
Stuart Hirons
Answered
On Cortex-M4F microcontrollers: is fixed point math faster or floating point?
+1
10773
views
10
replies
Latest
5 months ago
by
Ronan Synnott
Answered
Debugging kernel: OS support not working for Linux 5.4
+1
Kernel Developers
External Hardware Debug
Debugger
9648
views
5
replies
Latest
5 months ago
by
sgoldschmidt
Answered
DS-5 bare metal wait error after run "debug"
+1
DS-5 Development Studio
Debugging
Arm Compiler 5
Memory
32539
views
14
replies
Latest
5 months ago
by
prasadghole
<
>
View all questions in Arm Development Studio forum