ARM彙編寫的流水燈,完全裸機(對於彙編學習,板子啓動初始化認識幫助很大)

我是用的是6410的板子(128MBDDR,256MBnand)。

裏面有我的一些註釋,希望大家一起學習交流學習。

編譯通過的話,燒寫到要從nand的0地址開始,這與6410板子的啓動有關係,具體自己看一些書籍查詢。

/*Makefile*/

CC	:= arm-linux-gcc
AS	:= arm-linux-as
LD	:= arm-linux-ld
OBJCOPY := arm-linux-objcopy


BIN	:= arm.bin
ELF	:= arm

OBJS	:= start.o main.o


all:$(ELF)
	$(OBJCOPY) $< -O binary /tftpboot/$(BIN)

#-Ttext指定程序的人口地址是在nand地址的0 
$(ELF):$(OBJS)
	$(LD) $^ -o $@ -Ttext 0  

%.o:%.c
	$(CC) $< -c -o $@
%.o:%.s
	$(AS) $< -o $@

.PHONY:clean
clean:
	rm -rf $(OBJS) $(ELF)

          /*start_led.s*/
        .align	2
	.global	_start,start,loop,delay1
	.text
_start:
	mov	r0,#0x70000000        @外圍寄存器的基地址
	orr	r0,#0x13              @外圍寄存器的大小size=0x13 = 256M
	mcr	p15,0,r0,c15,c2,4     @告訴處理器訪問外圍存儲器的大小(MMU)
    
	ldr r0,=0x7e004000        @門狗定時器控制寄存器,關閉。
	ldr	r1,[r0]
	bic r1,#(1 << 5)
	str	r1,[r0]
    
	@mov sp,#0x2000			  @初始化棧指針,(6410板子內置DROM = 8K)
	
        ldr r0,=0x7f008820        @GPMCON
	ldr r2,[r0]               @read the value
        ldr r1,=(~0xffff)         @r1 = ~0xffff
	and r2,r1                 @clear the 16bits(4 leds)
        ldr r1,=0x1111	          @enable the GPMCON(16bits) as output
	orr r2,r1
	str r2,[r0]               @write in the GPMCON

        ldr r0,=0x7f008824        @GPMDAT
	ldr r2,[r0]               @read the GPMDAT old  value
        mov r1,#0xf
	orr r2,r1                 @off the leds
	str r2,[r0]               @write new value in the GPMDAT

start:                        @after led on 4 leds,init r5 to the first led
        mov r5,#0				  @r5 is about which leds is on
loop:
        cmp r5,#4
	beq start

	mov r1,#1
        ldr r0,=0x7f008824        @the r5 led on
        ldr r2,[r0]            
        bic r2,r1,lsl r5         
	str r2,[r0]
	mov r3,#0
	bl delay1
    
	ldr r2,[r0]               @the r5 led off,then the led right move 
        orr r2,r1,lsl r5          
	str r2,[r0]
	add r5,#1;
        b loop

delay1:
	nop;
	add r3,#1
	ldr r4,=0xffff
	cmp r3,r4
	moveq pc,lr
        b delay1


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章