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
control is not returning to assembly when tried return(0) in main of test case
Tools, Software and IDEs blog
Forums
Videos & Files
Help
Jump...
Cancel
New
Replies
3 replies
Subscribers
126 subscribers
Views
2435 views
Users
0 members are here
Related
control is not returning to assembly when tried return(0) in main of test case
Offline
Lokesh Kumar
over 7 years ago
Note: This was originally posted on 27th August 2012 at http://forums.arm.com
Hi,
Here is my code. As you can see below from C test case main has return and main was called by assembly code by using BL main.
But when I run this test control never comes back to assembly, since main is not retuning control to assembly as it should have done since BL instruction is used.
I do see that main function is getting completed as it's printing it's messages.
Do I need to do something different?
[color=#1F497D]Assembly code is as below :-[/color]
//ARM initialization code
//Call C main function
BL main
MOV r0, #0
MOV r1, #1
LDR r2, =0xffffffff
LDR r10, =0xcab00010
LDR r0, [r10]
STR r0, [r10] ; 0's
STR r2, [r10] ; f's
STR r0, [r10] ; 0's
DMB
Loop
WFI
B Loop
B pass
[color=#1F497D] [/color]
[color=#1F497D][/color]Main function of C code is as below :-
[color=#1F497D] [/color]int main(int argc, char *argv[]) {
loc_puts("INFO: ARM Booted Successfully!\n");
loc_puts("READ to boot space!\n"); return (0);
}
Offline
Scott Douglass
over 7 years ago
Note: This was originally posted on 5th September 2012 at
http://forums.arm.com
The stack pointer (and indirectly the stack size) is usually set by the "startup code". For bare-metal (no OS) cases this can be code supplied by the development environment. The startup code and is also responsible for things like iniitializing global variables, initializing the C library and calling main. You seem to be writing your own startup code and using the ARM compiler (Keil, DS-5 or RVDS). Have you seen this
http://infocenter.ar...h/CHDJGDAD.html
(or the equivalent for your version of the tools)? __main is the ARM library's startup code and is what make use of the ARM_LIB_STACK and ARM_LIB_HEAP areas.
The addresses of RAM suitable for use as stack and heap will depend on exactly what target you are using and will be different from one chip/platform to another.
Cancel
Up
0
Down
Reply
Cancel
Offline
Scott Douglass
over 7 years ago
Note: This was originally posted on 29th August 2012 at
http://forums.arm.com
I suspect a stack problem. Very likely 'main' uses the stack to save/restore the return address. Possibly the saved return address is being overwritten by 'loc_puts' or possibly the stack pointer (sp/r13) is not pointing to valid memory.
Cancel
Up
0
Down
Reply
Cancel
Offline
Lokesh Kumar
over 7 years ago
Note: This was originally posted on 4th September 2012 at
http://forums.arm.com
Scott,
Thanks for answering.
How to set stack size so that main function doesn't overwrite return address?
Is there any way to avoid it?
I see in assembly we do give option like below
; Heap starts at 1MB in RAM and grows upwards
ARM_LIB_HEAP 0x20100000 EMPTY 0x100000-0x8000
{
}
;; Stack starts at the end of the 2MB of RAM
;; And grows downwards for 32KB
ARM_LIB_STACK 0x20200000 EMPTY -0x8000
{
}
Is this the correct or I need to modify them?
Please guide me, as I am knew to arm flow.
Thanks
Cancel
Up
0
Down
Reply
Cancel
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
Dual-core debugging in DS
0
5677
views
2
replies
Latest
2 months ago
by
Ivan Savvateev
Answered
DS52020.0 connection to Musca-A/B boards not working
+1
Arm Development Studio
Musca-A
7455
views
4
replies
Latest
2 months ago
by
Daniel Oliveira
Answered
Positioning a function in a Position Independent Executable for ARMV8
+1
8024
views
3
replies
Latest
3 months ago
by
Stephen Theobald
Answered
Link a pure binary file to image with scatter file
0
8003
views
3
replies
Latest
3 months ago
by
Ronan Synnott
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)
13104
views
23
replies
Latest
3 months ago
by
Boon Khai
<
>
View all questions in Arm Development Studio forum