1.gboot.lds
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS {
. = 0x30008000; //起始地址
. = ALIGN(4);//4字节对齐
.text : //代码段
{
start.o (.text)//以.o开始执行
*(.text)
}
. = ALIGN(4);
.data : //数据段
{
*(.data)
}
. = ALIGN(4);
bss_start = .;//定义变量
.bss : //未初始化段
{
*(.bss)
}
bss_end = .;
}
2.start.S
.text
.global _start//定义全局变量
_start: //代码开始执行
//以下是异常向量表代码
b reset//复位
ldr pc, _undifined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq
//定义相应的变量 进行跳转
_undifined_instruction: .word undifined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abort: .word prefetch_abort
_data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word reset
//跳转之后所实现的功能
undifined_instruction:
nop
software_interrupt:
nop
prefetch_abort:
nop
data_abort:
nop
not_used:
nop
irq:
nop
fiq:
nop
//复位
reset:
bl set_svc
bl disable_watchdog
bl disable_interrupt
bl disable_mmu
//设置svc模式
set_svc:
mrs r0, cpsr
bic r0, r0,#0x1f
orr r0, r0,#0xd3
msr cpsr, r0
mov pc, lr
//关闭看门狗
#define pWTCON 0x53000000
disable_watchdog:
ldr r0, =pWTCON
mov r1, #0x0
str r1, [r0]
mov pc, lr
//关闭中断
disable_interrupt:
mvn r1, #0x0
ldr r0, =0x4a000008
str r1, [r0]
mov pc, lr
//关闭mmu
disable_mmu:
mcr p15,0,r0,c7,c7,0
mrc p15,0,r0,c1,c0,0
bic r0, r0, #0x00000007
mcr p15,0,r0,c1,c0,0
mov pc, lr
//makefile文件
3.Makefile
all: start.o
arm-linux-ld -Tgboot.lds -o gboot.elf $^
arm-linux-objcopy -O binary gboot.elf gboot.bin
%.o : %.S
arm-linux-gcc -g -c $^
%.o : %.c
arm-linux-gcc -g -c $^
.PHONY: clean
clean:
rm *.o *.elf *.bin