<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26977/arm-7-assembly-and-c-coding-mix-up</link><description> 
Hi 

 
I am new TO ARM7 And KEIL uVISION4 IDE. 

 
I am using AT91FR40162S ATMEL COntroller. 

 
When i created a project using KEIL IDE and selected AT91FR40162S
ATMEL COntroller from the device list. Automatically startup.s file
is added to the project</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/126417?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 07:42:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fcd1bab1-40aa-455e-868b-abb1a23e90dd</guid><dc:creator>Marcus Harnisch</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;gt; So how to change the mode from USR to SUPERVISOR.&lt;/p&gt;

&lt;p&gt;
Have a look at the SVC instruction.&lt;/p&gt;

&lt;p&gt;
--&lt;br /&gt;
Marcus&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/116052?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 05:58:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3206fafc-b334-47bb-be32-d8451f258e61</guid><dc:creator>anup kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanx a lot Marcus and John also for responding so quickly&lt;/p&gt;

&lt;p&gt;
TO Marcus -&lt;/p&gt;

&lt;p&gt;
From ur help also i got a clear idea. it works fine if my code is
running in privileged mode.&lt;/p&gt;

&lt;p&gt;
My question is If my code is not running in non privileged mode,
How to change to privileged mode?&lt;/p&gt;

&lt;p&gt;
If my code is running in USR mode i can not alter CPSR bits so can
not change MODE from USR to SUPERVISOR.&lt;/p&gt;

&lt;p&gt;
So how to change the mode from USR to SUPERVISOR.&lt;/p&gt;

&lt;p&gt;
Thanx In Advance&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/116051?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 05:53:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:38a7e2e2-b006-4e25-9092-d4ce521e25a8</guid><dc:creator>anup kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanx a lot Marcus&lt;/p&gt;

&lt;p&gt;
From ur help also i got a clear idea. it works fine if i am in
privileged mode.&lt;/p&gt;

&lt;p&gt;
My question is If I am in not privileged mode, How to change to
privileged mode.&lt;/p&gt;

&lt;p&gt;
If i am in USR mode i can not alter CPSR bits so can not change
SUPERVISOR mode from USR mode .&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/84717?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 05:49:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cbf6ea11-fcb7-4c6e-ae59-ebd2ff2655fe</guid><dc:creator>anup kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanx a Lot Martin&lt;/p&gt;

&lt;p&gt;
I got the idea from ur code. But i need to be in supervisor mode
to alter the CPSR register.&lt;/p&gt;

&lt;p&gt;
When i entered to the main function i was in USR mode so was not
able to alter the CPSR register.&lt;/p&gt;

&lt;p&gt;
I want to know if i am in USR mode in my application main.c then
if i want to change the CPSR register i need to change the MODE to
SUPERVISOR mode.&lt;/p&gt;

&lt;p&gt;
So To alter CPSR bits How to change from USR mode to SUPERVISOR
mode.&lt;/p&gt;

&lt;p&gt;
Thanx a lot in advance&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/104289?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 00:48:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3786d026-ed7c-4d4c-a945-c846474ae629</guid><dc:creator>Marcus Harnisch</dc:creator><description>&lt;p&gt;&lt;p&gt;
I agree with the statement about inline assembler, but in which
way is embedded assembler restricted?&lt;/p&gt;

&lt;p&gt;
But to answer the original question:&lt;br /&gt;
&amp;gt; I want to enable and disable the interrupts in my main.c file.
So How will i be able&lt;br /&gt;
&amp;gt; to access the CPSR register in my c coding.&lt;/p&gt;

&lt;p&gt;
Two ways (both require running in privileged mode, of course):&lt;/p&gt;

&lt;p&gt;
1. Use compiler intrinsics __disable_irq()/__disable_fiq() and
__enable_irq()/__enable_fiq()&lt;br /&gt;
2. Use named register variables (see manual)&lt;/p&gt;

&lt;p&gt;
Hope this helps&lt;br /&gt;
--&lt;br /&gt;
Marcus&lt;br /&gt;
&lt;a href="http://www.doulos.com/arm/"&gt;http://www.doulos.com/arm/&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/78701?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2010 00:36:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ababe334-ebc1-4712-ab88-22ae990f44ff</guid><dc:creator>Martin Unger</dc:creator><description>&lt;p&gt;&lt;p&gt;
The use of inline and embedded assembler is somewhat restricted
concerning the use of special registers like CPSR and SP. I recommend
the use of plain assembler. Example for file intendis.s:&lt;/p&gt;

&lt;pre&gt;
  EXPORT DisableInterrupts
  EXPORT EnableInterrupts

        AREA    ||.text||, CODE, READONLY, ALIGN=3
        ARM
  PRESERVE8

DisableInterrupts PROC
      STMDB SP!, {R0}           ; Push R0
      MRS   R0, CPSR            ; Get CPSR.
      ORR   R0, R0, #0xC0       ; Disable IRQ, FIQ.
      MSR   CPSR_cxsf, R0       ; Write back modified value.
      LDMIA SP!, {R0}           ; Pop R0
      BX    LR                  ; return
      ENDP

EnableInterrupts PROC
      STMDB SP!, {R0-R1}        ; Push R0,R1
      MRS   R0, CPSR            ; Get CPSR.
      AND   R1, R0, #0x0000001f ; R1 = R0 &amp;amp; 0x1f (mode bits)
      CMP   R1, #0x00000012     ; Test for IRQ mode
      BICNE   R0, R0, #0x80     ; Enable IRQ, but not in IRQ-Mode (no nesting)
      MSR   CPSR_cxsf, R0       ; Write back modified value.
      LDMIA SP!, {R0-R1}        ; Pop R0,R1
      BX    LR                  ; return
      ENDP


      END                       ; End of file

&lt;/pre&gt;

&lt;p&gt;
Of cause you need a header file intendis.h then:&lt;/p&gt;

&lt;pre&gt;
#ifndef INTENDIS_H
#define INTENDIS_H

// this pair of functions has the following characteristics:
// - disables all ints
// - enables only IRQ, but not during interrupt service
void DisableInterrupts(void);
void EnableInterrupts(void);

#endif /* INTENDIS_H */
&lt;/pre&gt;

&lt;p&gt;
Hope that helps.&lt;/p&gt;

&lt;p&gt;
Martin&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ARM 7 Assembly and C coding mix up</title><link>https://community.arm.com/thread/58728?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2010 18:46:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:034ed0fe-3eb2-4b8a-b673-8b47ac5bb1ff</guid><dc:creator>John Linq</dc:creator><description>&lt;p&gt;&lt;p&gt;
Maybe:&lt;br /&gt;
Using the Inline and Embedded Assemblers&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/armcc/armcc_cihffbgf.htm"&gt;http://www.keil.com/support/man/docs/armcc/armcc_cihffbgf.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>