一步一步写嵌入式操作系统----启动

 启动顺序:程序运行栈初始化→机器处理外设初始化

文件调用顺序:leeos.lds(链接脚本决定从_start开始执行)→start.s(_start)→init.s(__vector_reset,plat_boot)→boot.c

abnormal.s

.global __vector_undefined
.global __vector_swi
.global __vector_prefetch_abort
.global __vector_data_abort
.global __vector_reserved
.global __vector_irq
.global __vector_fiq

.text
.code 32

__vector_undefined:
	nop
__vector_swi:
	nop
__vector_prefetch_abort:	
	nop
__vector_data_abort:
	nop
__vector_reserved:
	nop
__vector_irq:
	nop
__vector_fiq:
	nop

init.s

# date:17.4.10
# author: linyang <942510346@qq.com>

.equ DISABLE_IRQ,	0x80
.equ DISABLE_FIQ,	0x40
.equ SYS_MOD,		0x1f
.equ IRQ_MOD,		0x12
.equ FIQ_MOD,		0x11
.equ SVC_MOD,		0x13
.equ ABT_MOD,		0x17
.equ UND_MOD,		0x1b

.equ MEM_SIZE, 		0x800000
.equ TEXT_BASE,		0x30000000
.equ _SVC_STACK,	(TEXT_BASE+MEM_SIZE-4)
.equ _IRQ_STACK,	(_SVC_STACK-0x400)
.equ _FIQ_STACK,	(_IRQ_STACK-0x400)
.equ _ABT_STACK,	(_FIQ_STACK-0x400)
.equ _UND_STACK,	(_ABT_STACK-0x400)
.equ _SYS_STACK,	(_UND_STACK-0x400)

.text
.code 32
.global __vector_reset

.extern plat_boot
.extern __bss_start__
.extern __bss_end__

__vector_reset:
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|SVC_MOD)
	ldr sp,=_SVC_STACK
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|IRQ_MOD)
	ldr sp,=_IRQ_STACK
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|FIQ_MOD)
	ldr sp,=_FIQ_STACK
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|ABT_MOD)
	ldr sp,=_ABT_STACK
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|UND_MOD)
	ldr sp,=_UND_STACK
	msr cpsr_c,#(DISABLE_IRQ|DISABLE_FIQ|SYS_MOD)
	ldr sp,=_SYS_STACK

_clear_bss:
	ldr r1,_bss_start_
	ldr r3,_bss_end_
	mov r2,#0x0
1:
	cmp r1,r3
	beq _main
	str r2,[r1],#0x4
	b 1b

_main:
	b plat_boot


_bss_start_:	.word  __bss_start__
_bss_end_:		.word  __bss_end__

.end

 leeos.lds

OUTPUT_ARCH(arm)
ENTRY(_start)

SECTIONS
{
	. = 0x00000000;
	.text :
	{
		*(.startup)
		*(.text)
	}
	. = ALIGN(32);
	.data :
	{
		*(.data)
	}
	. = ALIGN(32);
	__bss_start__ = .;
	.bss :
	{
		*(.bss)
	}
	__bss_end__ = .;
}

 boot.c

typedef void (*init_func)(void);

#define UFCON0	((volatile unsigned int *)(0x50000020))

void helloworld(void)
{
	const char *p = "3.1_helloworld\n";
	while(*p) {
		*UFCON0 = *p++;
	};
}

static init_func init[] = {
	helloworld,
	0,
};

void plat_boot(void)
{
	int i;
	for(i = 0; init[i]; i++) {
		init[i]();
	}
	while(1);
}

 start.s

.section .startup
.code 32
.align 0

.global _start
.extern __vector_reset
.extern __vector_undefined
.extern __vector_swi
.extern __vector_prefetch_abort
.extern __vector_data_abort
.extern __vector_reserved
.extern __vector_irq
.extern __vector_fiq

_start:
	ldr pc,_vector_reset
	ldr pc,_vector_undefined
	ldr pc,_vector_swi
	ldr pc,_vector_prefetch_abort
	ldr pc,_vector_data_abort
	ldr pc,_vector_reserved
	ldr pc,_vector_irq
	ldr pc,_vector_fiq

	.align 4

_vector_reset:			.word  __vector_reset
_vector_undefined:		.word  __vector_undefined
_vector_swi:			.word  __vector_swi
_vector_prefetch_abort:	.word  __vector_prefetch_abort
_vector_data_abort:		.word  __vector_data_abort
_vector_reserved:		.word  __vector_reserved
_vector_irq:			.word  __vector_irq
_vector_fiq:			.word  __vector_fiq

Makefile

CC=arm-elf-gcc
LD=arm-elf-ld
OBJCOPY=arm-elf-objcopy

CFLAGS= -O2 -g
ASFLAGS= -O2 -g
LDFLAGS=-Tleeos.lds -Ttext 30000000 

OBJS=init.o start.o boot.o abnormal.o

.c.o:
	$(CC) $(CFLAGS) -c $<
.s.o:
	$(CC) $(ASFLAGS) -c $<

leeos.elf:$(OBJS)
	$(CC) -static -nostartfiles -nostdlib $(LDFLAGS) $? -o $@ -lgcc
	$(OBJCOPY) -O binary $@ leeos.bin

clean:
	rm *.o leeos.elf leeos.bin -f

skyeye.conf

cpu:  arm920t
mach: s3c2410x
  
#physical memory
mem_bank: map=M, type=RW, addr=0x30000000, size=0x00800000, file=./leeos.bin,boot=yes
mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000

 

一步嵌入式操作系统 linux平台实现代码 step 0 准备开发环境 1 安装交叉编译工具 sudo apt-get install gcc-arm-none-eabi sudo apt-get install gcc-arm-linux-gnueabihf sudo apt-get install g++-arm-linux-gnueabihf 2 手边编译skyeye 用apt命令安装的skyeye模拟器版本(1.2.5)有bug,需要手动编译更高版本的skyeye 下载并解压skyeye 1.2.6_rc1的代码, ~/Downloads/skyeye-1.2.6_rc1 根据执行skyeye-1.2.6_rc1/INSTALL的说明 1 执行 ./configure 2 执行 make 后 编译错误1: In file included from /usr/include/fcntl.h:289:0, from nandflash/nandflash_smallblock.c:19: In function ‘open’, inlined from ‘nandflash_sb_setup’ at nandflash/nandflash_smallblock.c:519:24: /usr/include/x86_64-linux-gnu/bits/fcntl2.h:50:4: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments __open_missing_mode (); 解决方法: 修改skyeye-1.2.6_rc1/device/nandflash/nandflash_smallblock.c 519行 if ((nf->fdump= open(dev->dump, FILE_FLAG)) < 0) 改为: if ((nf->fdump= open(dev->dump, FILE_FLAG, 0777)) < 0) 编译错误2: gcc -g -O2 -o skyeye skyeye.o ./utils/libutils.a ./arch/arm/libarm.a ./device/libdev.a ./arch/mips/libmips.a ./arch/ppc/libppc.a ./arch/bfin/libbfin.a ./arch/mips/libmips.a ./arch/coldfire/libcoldfire.a -lc ./utils/libutils.a -lbfd -lm -lc ./arch/mips/libmips.a(decoder.o):在函数‘decode’中: /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1079:对‘sign_extend_UInt32’未定义的引用 /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1105:对‘sign_extend_UInt32’未定义的引用 /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1049:对‘sign_extend_UInt32’未定义的引用 /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1027:对‘sign_extend_UInt32’未定义的引用 /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1013:对‘sign_extend_UInt32’未定义的引用 ./arch/mips/libmips.a(decoder.o):/home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:1001: 跟着更多未定义的参考到 sign_extend_UInt32 ./arch/mips/libmips.a(decoder.o):在函数‘decode’中: /home/kolya/Downloads/skyeye-1.2.6_rc1/arch/mips/common/decoder.c:240:对‘divide_UI
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值