打印

Keil for Arm里进入main()函数前的一段初始化汇编代码在哪儿?

[复制链接]
6048|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Wxy8030|  楼主 | 2008-9-2 11:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
                IMPORT  __main
                LDR     R0, =__main
                BX      R0

在这上面这一段指令之后,进入C的main之前有一段代码,原型在哪儿,有兄弟研究过么?

相关下载

相关帖子

沙发
biao.l| | 2008-9-2 16:21 | 只看该作者

很明显的没有了

使用特权

评论回复
板凳
avocationA| | 2008-9-3 07:55 | 只看该作者

1

                PRESERVE8
                

; Area Definition and Entry Point
;  Startup Code must be linked first at Address at which it expects to run.

                AREA    RESET, CODE, READONLY
                ARM


; Exception Vectors
;  Mapped to Address 0.
;  Absolute addressing mode must be used.
;  Dummy Handlers are implemented as infinite loops which can be modified.

Vectors         LDR     PC, Reset_Addr         
                LDR     PC, Undef_Addr
                LDR     PC, SWI_Addr
                LDR     PC, PAbt_Addr
                LDR     PC, DAbt_Addr
                NOP                            ; Reserved Vector 
                LDR     PC, IRQ_Addr
                LDR     PC, FIQ_Addr


                IF      IntVT_SETUP <> 0

;Interrupt Vector Table Address                
HandleEINT0          EQU    IntVTAddress           
HandleEINT1          EQU    IntVTAddress +4
HandleEINT2          EQU    IntVTAddress +4*2
HandleEINT3          EQU    IntVTAddress +4*3
HandleEINT4_7      EQU    IntVTAddress +4*4
HandleEINT8_23    EQU    IntVTAddress +4*5
HandleCAM          EQU    IntVTAddress +4*6
HandleBATFLT      EQU    IntVTAddress +4*7
HandleTICK          EQU    IntVTAddress +4*8
HandleWDT          EQU    IntVTAddress +4*9
HandleTIMER0       EQU    IntVTAddress +4*10
HandleTIMER1       EQU    IntVTAddress +4*11
HandleTIMER2       EQU    IntVTAddress +4*12
HandleTIMER3       EQU    IntVTAddress +4*13
HandleTIMER4       EQU    IntVTAddress +4*14
HandleUART2        EQU    IntVTAddress +4*15
HandleLCD           EQU    IntVTAddress +4*16
HandleDMA0          EQU    IntVTAddress +4*17
HandleDMA1          EQU    IntVTAddress +4*18
HandleDMA2          EQU    IntVTAddress +4*19
HandleDMA3          EQU    IntVTAddress +4*20
HandleMMC          EQU    IntVTAddress +4*21
HandleSPI0          EQU    IntVTAddress +4*22
HandleUART1          EQU    IntVTAddress +4*23
HandleNFCON          EQU    IntVTAddress +4*24
HandleUSBD          EQU    IntVTAddress +4*25
HandleUSBH          EQU    IntVTAddress +4*26
HandleIIC          EQU    IntVTAddress +4*27
HandleUART0       EQU    IntVTAddress +4*28
HandleSPI1           EQU    IntVTAddress +4*39
HandleRTC           EQU    IntVTAddress +4*30
HandleADC           EQU    IntVTAddress +4*31

IRQ_Entry
                sub    sp,sp,#4       ;reserved for PC
                stmfd    sp!,{r8-r9}
                
                ldr    r9,=INTOFFSET
                ldr    r9,[r9]
                ldr    r8,=HandleEINT0
                add    r8,r8,r9,lsl #2
                ldr    r8,[r8]
                str    r8,[sp,#8]
                ldmfd    sp!,{r8-r9,pc}                
                
                ENDIF

Reset_Addr      DCD     Reset_Handler
Undef_Addr      DCD     Undef_Handler
SWI_Addr        DCD     SWI_Handler
PAbt_Addr       DCD     PAbt_Handler
DAbt_Addr       DCD     DAbt_Handler
                DCD     0                      ; Reserved Address 
IRQ_Addr        DCD     IRQ_Handler
FIQ_Addr        DCD     FIQ_Handler

Undef_Handler   B       Undef_Handler
SWI_Handler     B       SWI_Handler
PAbt_Handler    B       PAbt_Handler
DAbt_Handler    B       DAbt_Handler
                
                IF      IntVT_SETUP <> 1
IRQ_Handler     B       IRQ_Handler
                ENDIF
                
                IF      IntVT_SETUP <> 0
IRQ_Handler     B       IRQ_Entry
                ENDIF
                
FIQ_Handler     B       FIQ_Handler



; Memory Controller Configuration
                IF      MC_SETUP <> 0
MC_CFG
                DCD     BWSCON_Val
                DCD     BANKCON0_Val
                DCD     BANKCON1_Val
                DCD     BANKCON2_Val
                DCD     BANKCON3_Val
                DCD     BANKCON4_Val
                DCD     BANKCON5_Val
                DCD     BANKCON6_Val
                DCD     BANKCON7_Val
                DCD     REFRESH_Val
                DCD     BANKSIZE_Val
                DCD     MRSRB6_Val
                DCD     MRSRB7_Val
                ENDIF


; Clock Management Configuration
                IF      CLOCK_SETUP <> 0
CLK_CFG
                DCD     LOCKTIME_Val     
                DCD     CLKDIVN_Val 
                DCD     UPLLCON_Val 
                DCD     MPLLCON_Val 
                DCD     CLKSLOW_Val 
                DCD     CLKCON_Val 
                DCD     CAMDIVN_Val 
                ENDIF 

            

; I/O Configuration
               
                IF      PIO_SETUP <> 0
PIOA_CFG     
                DCD     PCONA_Val
PIOB_CFG        DCD     PCONB_Val
                DCD     PUPB_Val
PIOC_CFG        DCD     PCONC_Val
                DCD     PUPC_Val
PIOD_CFG        DCD     PCOND_Val
                DCD     PUPD_Val
PIOE_CFG        DCD     PCONE_Val
                DCD     PUPE_Val
PIOF_CFG        DCD     PCONF_Val
                DCD     PUPF_Val
PIOG_CFG        DCD     PCONG_Val
                DCD     PUPG_Val
PIOH_CFG        DCD     PCONH_Val
                DCD     PUPH_Val
PIOJ_CFG        DCD     PCONJ_Val
                DCD     PUPJ_Val
                ENDIF

; Reset Handler

                EXPORT  Reset_Handler
Reset_Handler   

                IF      WT_SETUP <> 0
                LDR     R0, =WT_BASE
                LDR     R1, =WTCON_Val
                LDR     R2, =WTDAT_Val
                STR     R2, [R0, #WTCNT_OFS]
                STR     R2, [R0, #WTDAT_OFS]
                STR     R1, [R0, #WTCON_OFS]
                ENDIF
                
                
                IF      CLOCK_SETUP <> 0         
                LDR     R0, =CLK_BASE            
                ADR     R8, CLK_CFG
                LDMIA   R8, {R1-R7}            
                STR     R1, [R0, #LOCKTIME_OFS]
                STR     R2, [R0, #CLKDIVN_OFS]  
                STR     R3, [R0, #UPLLCON_OFS] 
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                STR     R4, [R0, #MPLLCON_OFS]  
                STR     R5, [R0, #CLKSLOW_OFS]
                STR     R6, [R0, #CLKCON_OFS]
                STR     R7, [R0, #CAMDIVN_OFS]
                ENDIF                          

                                     
                IF      MC_SETUP <> 0
                ADR     R13, MC_CFG
                LDMIA   R13, {R0-R12}
                LDR     R13, =MC_BASE
                STMIA   R13, {R0-R12}
                ENDIF                            
                                
              
                IF      PIO_SETUP <> 0
                LDR     R13, =PIO_BASE

                IF      PIOA_SETUP <> 0
                ADR     R0, PIOA_CFG
                STR     R0, [R13, #PCONA_OFS]
                ENDIF

                IF      PIOB_SETUP <> 0
                ADR     R0, PIOB_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONB_OFS]
                STR     R1, [R13, #PUPB_OFS]
                ENDIF

                IF      PIOC_SETUP <> 0
                ADR     R0, PIOC_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONC_OFS]
                STR     R1, [R13, #PUPC_OFS]
                ENDIF

                IF      PIOD_SETUP <> 0
                ADR     R0, PIOD_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCOND_OFS]
                STR     R1, [R13, #PUPD_OFS]
                ENDIF

                IF      PIOE_SETUP <> 0
                ADR     R0, PIOE_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONE_OFS]
                STR     R1, [R13, #PUPE_OFS]
                ENDIF

                IF      PIOF_SETUP <> 0
                ADR     R0, PIOF_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONF_OFS]
                STR     R1, [R13, #PUPF_OFS]
                ENDIF

                IF      PIOG_SETUP <> 0
                ADR     R0, PIOG_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONG_OFS]
                STR     R1, [R13, #PUPG_OFS]
                ENDIF
  
                IF      PIOH_SETUP <> 0
                ADR     R0, PIOH_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONH_OFS]
                STR     R1, [R13, #PUPH_OFS]
                ENDIF
               
                IF      PIOJ_SETUP <> 0
                ADR     R0, PIOJ_CFG
                LDR     R1, [R0,#4]
                STR     R0, [R13, #PCONJ_OFS]
                STR     R1, [R13, #PUPJ_OFS]
                ENDIF 

                ENDIF
                
                
; Setup Stack for each mode

                LDR     R0, =Stack_Top

;  Enter Undefined Instruction Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #UND_Stack_Size

;  Enter Abort Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #ABT_Stack_Size

;  Enter FIQ Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #FIQ_Stack_Size

;  Enter IRQ Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #IRQ_Stack_Size

;  Enter Supervisor Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
                MOV     SP, R0
                SUB     R0, R0, #SVC_Stack_Size
;                IMPORT MMU_EnableICache
;                bl     MMU_EnableICache


;  Enter User Mode and set its Stack Pointer
                MSR     CPSR_c, #Mode_USR
                MOV     SP, R0
                SUB     SL, SP, #USR_Stack_Size


; Enter the C code
                                            ;
                IMPORT  __main
                LDR     R0, =__main
                BX      R0


; User Initial Stack & Heap
                AREA    |.text|, CODE, READONLY

               ; IMPORT  __use_two_region_memory

                EXPORT  __user_initial_stackheap
__user_initial_stackheap

                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + USR_Stack_Size)
                LDR     R2, = (Heap_Mem +      Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR



                END

使用特权

评论回复
地板
Wxy8030|  楼主 | 2008-9-3 08:40 | 只看该作者

怎么会没有呢,要看编译后的汇编文件才能看到——

Startup.s就不用贴出来啦,我虽然不一定能全部自己写出来,但相信还是将就能看懂的;

编译后模拟运行时,在跳出这个Startup.s后,进入你自己的C函数之前还有一段汇编代码,最起码清零ZI段是在那里执行的,我现在想知道的是,那段程序的源代码在哪儿?

使用特权

评论回复
5
mcujobjun| | 2008-9-3 15:01 | 只看该作者

C库

函数__main的代码只能通过仿真,反汇编看到,没有它的原代码
Reset_Handler 函数直接跳转到 C 库执行,代码如下:

   Reset_Handler
    ; Branch to C Library entry point
   assign  B __main

使用特权

评论回复
6
宛城君| | 2008-9-3 16:31 | 只看该作者

启动过程如下

程序首先进入 Image Entry Point
然后就进入到初始化就是我们的启动代码
 reset handler
initialize stack pointers
configure MMU/MPU
setup cache/enable TCM
在接着就是进入到C库的
__main
//copy code and data
//zero uninitialized data
__rt_entry
__user_initial_stackheap( )
set up stack & heap
$Sub$$main( )
enable caches & interrupts
依次执行 最后到main()中

使用特权

评论回复
7
avocationA| | 2008-9-3 19:49 | 只看该作者

知道楼主意思了!去KEIL FOR ARM的官方网

去KEIL FOR ARM的官方网  里面有视频讲解的

使用特权

评论回复
8
小野狼| | 2008-9-4 10:08 | 只看该作者

网址如下

使用特权

评论回复
9
avocationA| | 2008-9-4 10:39 | 只看该作者

以假换真好象还要贴钱吧?

使用特权

评论回复
10
vincer| | 2008-9-8 16:06 | 只看该作者

look look

                IMPORT  __main
                LDR     R0, =__main
                BX      R0 
调试时,在 -- LDR     R0, =__main --设个断点;
run停在断点时,在反汇编里单步调式就能看到你想的
...
 __scatterload__rt2
...
__rt_entry
...

使用特权

评论回复
11
milk_wong| | 2008-9-9 19:16 | 只看该作者

_

answear is in 6f

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

144

主题

2092

帖子

2

粉丝