ARM汇编程序:
.data
#define GPA0_BASE 0xe0200000
#define UART0_BASE 0xe2900000
#define ULCON 0x0
#define UCON 0x4
#define UFCON 0x8
#define UTRSTAT 0x10
#define UBRDIV 0x28
#define UDIVSLOT 0x2c
#define URXH 0x24
#define UTXH 0x20
.text
.global _start
_start:
bic sp,sp,#7
mrs r0,cpsr
bic r0,#0xc0
msr cpsr,r0
bl uart_init
0:
b 0b
uart_init:
stmfd sp!,{lr}
ldr r0,=GPA0_BASE
ldr r1,[r0]
bic r1,r1,#0xff
orr r1,r1,#0x22 @uart_0_rxd and uart_0_txd
str r1,[r0]
ldr r0,=UART0_BASE
ldr r1,=0x3 @word length is 8-bit
str r1,[r0,#ULCON]
ldr r1,=0x5 @transmit mode and receive mode is interrupt request or polling mode
str r1,[r0,#UCON]
ldr r1,=0x1 @fifo enable
str r1,[r0,#UFCON]
ldr r1,=35 @(66.5MHz/(115200x16)-1) = 35.07
str r1,[r0,#UBRDIV]
ldr r1,=0x80 @(16x0.07) = 1
str r1,[r0,#UDIVSLOT]
ldmfd sp!,{pc}
uart_getc:
stmfd sp!,{lr}
ldr r0,=UART0_BASE
1:
ldr r1,[r0,#UTRSTAT]
and r1,r1,#0x1<<0
cmp r1,#0
beq 1b
ldrb r1,[r0,#URXH]
mov r0,r1
ldmfd sp!,{pc}
uart_putc:
stmfd sp!,{lr}
mov r1,r0
ldr r0,=UART0_BASE
strb r1,[r0,#UTXH]
ldmfd sp!,{pc}
func:
str lr,sp!
push {fp} @str fp,sp!
add fp,sp,#0
srmfd sp!,{r0,r3}
ldmfd sp!,{r0,r3}
add sp,fp,#0
pop {fp}
ldr pc,sp!
.end
ENTRY(_start);
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm");
OUTPUT_ARCH(arm);
SECTIONS
{
. = 0x20000000;
. = ALIGN(4);
.text : {
start.o(.text)
*(.text);
}
. = ALIGN(4);
.rodata : {
*(.rodata);
}
. = ALIGN(4);
.data : {
*(.data);
}
. = ALIGN(4);
.bss : {
*(.bss);
}
}