Guest User

STARTUP.S

a guest
Apr 22nd, 2010
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*****************************************************************************/
  2. /* STARTUP.S: Startup file for Blinky Example                                */
  3. /*****************************************************************************/
  4. /* Version: CodeSourcery Sourcery G++ Lite (with CS3)                        */
  5. /*****************************************************************************/
  6.  
  7.  
  8. /*
  9. //*** <<< Use Configuration Wizard in Context Menu >>> ***
  10. */
  11.  
  12.  
  13. /*
  14.  *  The STARTUP.S code is executed after CPU Reset. This file may be
  15.  *  translated with the following SET symbols. In uVision these SET
  16.  *  symbols are entered under Options - ASM - Define.
  17.  *
  18.  *  REMAP: when set the startup code initializes the register MEMMAP
  19.  *  which overwrites the settings of the CPU configuration pins. The
  20.  *  startup and interrupt vectors are remapped from:
  21.  *     0x00000000  default setting (not remapped)
  22.  *     0x40000000  when RAM_MODE is used
  23.  *
  24.  *  RAM_MODE: when set the device is configured for code execution
  25.  *  from on-chip RAM starting at address 0x40000000.
  26.  */
  27.  
  28.  
  29. # Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
  30.  
  31.         .equ    Mode_USR,       0x10
  32.         .equ    Mode_FIQ,       0x11
  33.         .equ    Mode_IRQ,       0x12
  34.         .equ    Mode_SVC,       0x13
  35.         .equ    Mode_ABT,       0x17
  36.         .equ    Mode_UND,       0x1B
  37.         .equ    Mode_SYS,       0x1F
  38.  
  39.         .equ    I_Bit,          0x80    /* when I bit is set, IRQ is disabled */
  40.         .equ    F_Bit,          0x40    /* when F bit is set, FIQ is disabled */
  41.  
  42.  
  43. /*
  44. // <h> Stack Configuration (Stack Sizes in Bytes)
  45. //   <o0> Undefined Mode      <0x0-0xFFFFFFFF:8>
  46. //   <o1> Abort Mode          <0x0-0xFFFFFFFF:8>
  47. //   <o2> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
  48. //   <o3> Interrupt Mode      <0x0-0xFFFFFFFF:8>
  49. //   <o4> Supervisor Mode     <0x0-0xFFFFFFFF:8>
  50. //   <o5> User/System Mode    <0x0-0xFFFFFFFF:8>
  51. // </h>
  52. */
  53.  
  54.         .equ    UND_Stack_Size, 0x00000000
  55.         .equ    ABT_Stack_Size, 0x00000000
  56.         .equ    FIQ_Stack_Size, 0x00000000
  57.         .equ    IRQ_Stack_Size, 0x00000200
  58.         .equ    SVC_Stack_Size, 0x00000008
  59.         .equ    USR_Stack_Size, 0x00000400
  60.  
  61.         .section ".stack", "w"
  62.         .align  3
  63.         .globl  __cs3_stack_mem
  64.         .globl  __cs3_stack_size
  65. __cs3_stack_mem:
  66.         .if     USR_Stack_Size
  67.         .space  USR_Stack_Size
  68.         .endif
  69.         .if     SVC_Stack_Size
  70.         .space  SVC_Stack_Size
  71.         .endif
  72.         .if     IRQ_Stack_Size
  73.         .space  IRQ_Stack_Size
  74.         .endif
  75.         .if     FIQ_Stack_Size
  76.         .space  FIQ_Stack_Size
  77.         .endif
  78.         .if     ABT_Stack_Size
  79.         .space  ABT_Stack_Size
  80.         .endif
  81.         .if     UND_Stack_Size
  82.         .space  UND_Stack_Size
  83.         .endif
  84.         .size   __cs3_stack_mem,  . - __cs3_stack_mem
  85.         .set    __cs3_stack_size, . - __cs3_stack_mem
  86.  
  87.  
  88. /*
  89. // <h> Heap Configuration
  90. //   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  91. // </h>
  92. */
  93.  
  94.         .equ    Heap_Size,      0x00000000
  95.  
  96.         .section ".heap", "w"
  97.         .align  3
  98.         .globl  __cs3_heap_start
  99.         .globl  __cs3_heap_end
  100. __cs3_heap_start:
  101.         .if     Heap_Size
  102.         .space  Heap_Size
  103.         .endif
  104. __cs3_heap_end:
  105.  
  106.  
  107. # VPBDIV definitions
  108.         .equ    VPBDIV,         0xE01FC100  /* VPBDIV Address */
  109.  
  110. /*
  111. // <e> VPBDIV Setup
  112. // <i> Peripheral Bus Clock Rate
  113. //   <o1.0..1>   VPBDIV: VPB Clock
  114. //               <0=> VPB Clock = CPU Clock / 4
  115. //               <1=> VPB Clock = CPU Clock
  116. //               <2=> VPB Clock = CPU Clock / 2
  117. //   <o1.4..5>   XCLKDIV: XCLK Pin
  118. //               <0=> XCLK Pin = CPU Clock / 4
  119. //               <1=> XCLK Pin = CPU Clock
  120. //               <2=> XCLK Pin = CPU Clock / 2
  121. // </e>
  122. */
  123.         .equ    VPBDIV_SETUP,   0
  124.         .equ    VPBDIV_Val,     0x00000000
  125.  
  126.  
  127. # Phase Locked Loop (PLL) definitions
  128.         .equ    PLL_BASE,       0xE01FC080  /* PLL Base Address */
  129.         .equ    PLLCON_OFS,     0x00        /* PLL Control Offset*/
  130.         .equ    PLLCFG_OFS,     0x04        /* PLL Configuration Offset */
  131.         .equ    PLLSTAT_OFS,    0x08        /* PLL Status Offset */
  132.         .equ    PLLFEED_OFS,    0x0C        /* PLL Feed Offset */
  133.         .equ    PLLCON_PLLE,    (1<<0)      /* PLL Enable */
  134.         .equ    PLLCON_PLLC,    (1<<1)      /* PLL Connect */
  135.         .equ    PLLCFG_MSEL,    (0x1F<<0)   /* PLL Multiplier */
  136.         .equ    PLLCFG_PSEL,    (0x03<<5)   /* PLL Divider */
  137.         .equ    PLLSTAT_PLOCK,  (1<<10)     /* PLL Lock Status */
  138.  
  139. /*
  140. // <e> PLL Setup
  141. //   <o1.0..4>   MSEL: PLL Multiplier Selection
  142. //               <1-32><#-1>
  143. //               <i> M Value
  144. //   <o1.5..6>   PSEL: PLL Divider Selection
  145. //               <0=> 1   <1=> 2   <2=> 4   <3=> 8
  146. //               <i> P Value
  147. // </e>
  148. */
  149.         .equ    PLL_SETUP,      1
  150.         .equ    PLLCFG_Val,     0x00000024
  151.  
  152.  
  153. # Memory Accelerator Module (MAM) definitions
  154.         .equ    MAM_BASE,       0xE01FC000  /* MAM Base Address */
  155.         .equ    MAMCR_OFS,      0x00        /* MAM Control Offset*/
  156.         .equ    MAMTIM_OFS,     0x04        /* MAM Timing Offset */
  157.  
  158. /*
  159. // <e> MAM Setup
  160. //   <o1.0..1>   MAM Control
  161. //               <0=> Disabled
  162. //               <1=> Partially Enabled
  163. //               <2=> Fully Enabled
  164. //               <i> Mode
  165. //   <o2.0..2>   MAM Timing
  166. //               <0=> Reserved  <1=> 1   <2=> 2   <3=> 3
  167. //               <4=> 4         <5=> 5   <6=> 6   <7=> 7
  168. //               <i> Fetch Cycles
  169. // </e>
  170. */
  171.         .equ    MAM_SETUP,      1
  172.         .equ    MAMCR_Val,      0x00000002
  173.         .equ    MAMTIM_Val,     0x00000004
  174.  
  175.  
  176. # Exception Vectors
  177.  
  178.         .arm
  179.  
  180.         .section ".cs3.interrupt_vector"
  181.         .globl  __cs3_interrupt_vector_arm
  182.         .type   __cs3_interrupt_vector_arm, %object
  183. __cs3_interrupt_vector_arm:
  184.  
  185.                 LDR     PC, Reset_Addr        
  186.                 LDR     PC, Undef_Addr
  187.                 LDR     PC, SWI_Addr
  188.                 LDR     PC, PAbt_Addr
  189.                 LDR     PC, DAbt_Addr
  190.                 NOP                            /* Reserved Vector */
  191. #               LDR     PC, IRQ_Addr
  192.                 LDR     PC, [PC, #-0x0FF0]     /* Vector from VicVectAddr */
  193.                 LDR     PC, FIQ_Addr
  194.  
  195. Reset_Addr:     .word   __cs3_reset_arm
  196. Undef_Addr:     .word   Undef_Handler
  197. SWI_Addr:       .word   SWI_Handler
  198. PAbt_Addr:      .word   PAbt_Handler
  199. DAbt_Addr:      .word   DAbt_Handler
  200.                 .word   0                      /* Reserved Address */
  201. IRQ_Addr:       .word   IRQ_Handler
  202. FIQ_Addr:       .word   FIQ_Handler
  203.  
  204.         .size   __cs3_interrupt_vector_arm, . - __cs3_interrupt_vector_arm
  205.  
  206.  
  207. # Exception Handlers
  208.  
  209.         .section ".text"
  210.  
  211.         .weak   Undef_Handler
  212.         .type   Undef_Handler, %function
  213. Undef_Handler:  B       Undef_Handler
  214.         .size   Undef_Handler, . - Undef_Handler
  215.  
  216.         .weak   SWI_Handler
  217.         .type   SWI_Handler, %function
  218. SWI_Handler:    B       SWI_Handler
  219.         .size   SWI_Handler, . - SWI_Handler
  220.  
  221.         .weak   PAbt_Handler
  222.         .type   PAbt_Handler, %function
  223. PAbt_Handler:   B       PAbt_Handler
  224.         .size   PAbt_Handler, . - PAbt_Handler
  225.  
  226.         .weak   DAbt_Handler
  227.         .type   DAbt_Handler, %function
  228. DAbt_Handler:   B       DAbt_Handler
  229.         .size   DAbt_Handler, . - DAbt_Handler
  230.  
  231.         .weak   IRQ_Handler
  232.         .type   IRQ_Handler, %function
  233. IRQ_Handler:    B       IRQ_Handler
  234.         .size   IRQ_Handler, . - IRQ_Handler
  235.  
  236.         .weak   FIQ_Handler
  237.         .type   FIQ_Handler, %function
  238. FIQ_Handler:    B       FIQ_Handler
  239.         .size   FIQ_Handler, . - FIQ_Handler
  240.  
  241.  
  242. # Reset Handler
  243.  
  244.         .section .cs3.reset,"x",%progbits
  245.         .globl  __cs3_reset_arm
  246.         .type   __cs3_reset_arm, %function
  247. __cs3_reset_arm:
  248.         .fnstart
  249.  
  250.  
  251. # Setup VPBDIV
  252.         .if VPBDIV_SETUP
  253.                 LDR     R0, =VPBDIV
  254.                 LDR     R1, =VPBDIV_Val
  255.                 STR     R1, [R0]
  256.         .endif
  257.  
  258.  
  259. # Setup PLL
  260.         .if PLL_SETUP
  261.                 LDR     R0, =PLL_BASE
  262.                 MOV     R1, #0xAA
  263.                 MOV     R2, #0x55
  264.  
  265. #  Configure and Enable PLL
  266.                 MOV     R3, #PLLCFG_Val
  267.                 STR     R3, [R0, #PLLCFG_OFS]
  268.                 MOV     R3, #PLLCON_PLLE
  269.                 STR     R3, [R0, #PLLCON_OFS]
  270.                 STR     R1, [R0, #PLLFEED_OFS]
  271.                 STR     R2, [R0, #PLLFEED_OFS]
  272.  
  273. #  Wait until PLL Locked
  274. PLL_Loop:       LDR     R3, [R0, #PLLSTAT_OFS]
  275.                 ANDS    R3, R3, #PLLSTAT_PLOCK
  276.                 BEQ     PLL_Loop
  277.  
  278. #  Switch to PLL Clock
  279.                 MOV     R3, #(PLLCON_PLLE | PLLCON_PLLC)
  280.                 STR     R3, [R0, #PLLCON_OFS]
  281.                 STR     R1, [R0, #PLLFEED_OFS]
  282.                 STR     R2, [R0, #PLLFEED_OFS]
  283.         .endif
  284.  
  285.  
  286. # Setup MAM
  287.         .if MAM_SETUP
  288.                 LDR     R0, =MAM_BASE
  289.                 MOV     R1, #MAMTIM_Val
  290.                 STR     R1, [R0, #MAMTIM_OFS]
  291.                 MOV     R1, #MAMCR_Val
  292.                 STR     R1, [R0, #MAMCR_OFS]
  293.         .endif
  294.  
  295.  
  296. # Memory Mapping (when Interrupt Vectors are in RAM)
  297.         .equ    MEMMAP, 0xE01FC040             /* MAM Base Address */
  298.  
  299.         .ifdef REMAP
  300.                 LDR     R0, =MEMMAP
  301.         .ifdef RAM_MODE
  302.                 IF      :DEF:RAM_MODE
  303.                 MOV     R1, #2
  304.         .else
  305.                 MOV     R1, #1
  306.         .endif
  307.                 STR     R1, [R0]
  308.         .endif
  309.  
  310.  
  311. # Initialise Interrupt System
  312. #  ...
  313.  
  314.  
  315. # Setup Stack for each mode
  316.  
  317.                 LDR     R0, =__cs3_stack
  318.  
  319. #  Enter Undefined Instruction Mode and set its Stack Pointer
  320.                 MSR     CPSR_c, #Mode_UND|I_Bit|F_Bit
  321.                 MOV     SP, R0
  322.                 SUB     R0, R0, #UND_Stack_Size
  323.  
  324. #  Enter Abort Mode and set its Stack Pointer
  325.                 MSR     CPSR_c, #Mode_ABT|I_Bit|F_Bit
  326.                 MOV     SP, R0
  327.                 SUB     R0, R0, #ABT_Stack_Size
  328.  
  329. #  Enter FIQ Mode and set its Stack Pointer
  330.                 MSR     CPSR_c, #Mode_FIQ|I_Bit|F_Bit
  331.                 MOV     SP, R0
  332.                 SUB     R0, R0, #FIQ_Stack_Size
  333.  
  334. #  Enter IRQ Mode and set its Stack Pointer
  335.                 MSR     CPSR_c, #Mode_IRQ|I_Bit|F_Bit
  336.                 MOV     SP, R0
  337.                 SUB     R0, R0, #IRQ_Stack_Size
  338.  
  339. #  Enter Supervisor Mode and set its Stack Pointer
  340.                 MSR     CPSR_c, #Mode_SVC|I_Bit|F_Bit
  341.                 MOV     SP, R0
  342.                 SUB     R0, R0, #SVC_Stack_Size
  343.  
  344. #  Enter User Mode and set its Stack Pointer
  345.                 MSR     CPSR_c, #Mode_USR
  346.                 MOV     SP, R0
  347.  
  348. #  Setup a default Stack Limit (when compiled with "-mapcs-stack-check")
  349.                 SUB     SL, SP, #USR_Stack_Size
  350.  
  351.  
  352. # Enter the C code
  353.  
  354.         .globl  _start
  355. _start:
  356.                 LDR     R0,=__cs3_start_c
  357.                 BX      R0
  358.  
  359.  
  360.         .fnend
  361.         .size   __cs3_reset_arm, . - __cs3_reset_arm
  362.  
  363.  
  364.         .end
Advertisement
Add Comment
Please, Sign In to add comment