⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 os arm os arm os arm os arm os arm os arm os arm os arm os arm os arm os arm os arm os arm os arm
💻 C
字号:
/* *	ApOS (Another Project software for s3c2410) *	 *	This program is free software; you can redistribute it and/or modify *	it under the terms of the GNU General Public License version 2 as *	published by the Free Software Foundation. *			 *						Copyright caiyuqing * */#include <string.h>#include <stdarg.h>#include "../include/s3c2410/lcd.h"#include "../include/s3c2410/timer.h"#include "../include/s3c2410/nand_flash.h"#include "../include/s3c2410/clock.h"#include "../include/s3c2410/cpu.h"#include "../include/s3c2410/dma.h"#include "../include/s3c2410/s3c2410.h"#include "../include/kernel/sched.h"#include "../include/kernel/gui.h"#include "../include/kernel/irq.h"#include "../include/kernel/task.h"#include "../include/s3c2410/io.h"#include "../include/kernel/sys.h"#define KERNEL_BASE	0x30095000//得到user模式下的cpsr的值#define USER ({ \int reg; \	reg=read_cpsr();\	reg&=~(0x1f);\	reg|=UserMode;\reg; })extern struct lcd_control_obj 		lcd_control_obj;extern struct io_control_obj 		io_control_obj;extern struct irq_ctrl_object 		irq_ctrl_object;extern struct timer_ctrl_object 	timer_ctrl_object;extern struct touchsrc_ctrl_object 	touchsrc_ctrl_object;extern struct dma_ctrl_object 		dma_ctrl_object;extern struct sdi_control_obj 		sdi_control_obj;extern struct iis_control_obj 		iis_control_obj;extern struct elf_loader_obj 		elf_loader_obj;extern struct memory_ctrl_object 	memory_ctrl_object;extern struct usb_host_ctrl_object 	usb_host_ctrl_object;union task_union init_task; extern struct task_struct* task[NR_TASKS];extern struct task_struct* current; //inline system_call0(int,fork);#define fork() ({ \	unsigned int res;\	unsigned int fun_id=NR_fork;\	asm volatile(\		"ldr r0,%1 \n\t"\		"swi \n\t"\		"str r0,%0 \n\t"\		:"=m"(res)\		:"m"(fun_id)\		:"r0","memory"\	);\	res;\})void device_object_init(){	//lcd_control_obj_init(struct lcd_control_obj* ) define in ../device/lcd.c	lcd_control_obj_init(&lcd_control_obj);	//io_control_obj_init(struct io_control_obj* ) define in ../device/io.c	io_control_obj_init(&io_control_obj);	//irq_ctrl_obj_init(struct irq_ctrl_object* ) define in ../device/io.c	irq_ctrl_obj_init(&irq_ctrl_object);	//timer_ctrl_obj_init(struct timer_ctrl_object* ) define in ../device/timer.c	timer_ctrl_obj_init(&timer_ctrl_object);	//touchscreen_ctrl_obj_init(struct touchsrc_ctrl_object* ) define in ../device/touchscreen.c	touchscreen_ctrl_obj_init(&touchsrc_ctrl_object);	//dma_ctrl_obj_init(struct dma_ctrl_object* ) define in ../device/dma.c	dma_ctrl_obj_init(&dma_ctrl_object);	//sdi_ctrl_obj_init(struct sdi_control_obj* ) define in ../device/sdi.c	sdi_ctrl_obj_init(&sdi_control_obj);	//iis_ctrl_obj_init(struct iis_control_obj* ) define in ../device/iis.c	iis_ctrl_obj_init(&iis_control_obj);	//memory_ctrl_obj_init(struct memory_ctrl_object* ) define in ../device/memory.c	memory_ctrl_obj_init(&memory_ctrl_object);	usb_host_obj_init(&usb_host_ctrl_object);	}void dump_info(){	set_con_font_color(RGB(0,255,255));	printk("Welcome to ApOS's world :}\n\Please login in www.antoher-prj.com to get more information\n\Copyright to AnotherProject.\n\n"); 	 	set_con_font_color(RGB(255,255,255));  	printk("Hardware information:\n\n");	printk("System clock: %dMHz\n\n\n",get_system_clock());}/* *	加载任务0并切换到用户模式,task0的使用的是内核的代码区,但它有属 *	于自己堆栈,这样就不会引起permision fault. */#define move_to_user() ({\	unsigned int *regs=&(init_task.task.cpu_registers);\	unsigned int cpu_mode=USER;\	asm volatile(\		"ldr r0,%0 \n\t"\		"ldmib r0!,{r1-r13}\n\t"\		"ldr r0,%1 \n\t"\		"msr cpsr,r0 \n\t"\		:\		:"m"(regs),"m"(cpu_mode)\	);\})void printf(char *fmt,...){	int i;	char printbuf[1024];		va_list args;	va_start(args,fmt);	i=vsprintf(printbuf,fmt,args);	va_end(args);	/*	 *	write函数是运行在System特权级下的,这和普通的	 *	系统调用是不同的,系统调用是运行在SVC特权级下	 *	的	 */	write(1,printbuf,i);}int main(void){	//初始化所有设备控制对象	device_object_init();	/* 	set_system_clock(unsignd int) define in ../device/clock.c	 *	 *	system clock advance in APOS:	 *					vMPLLCON_202MHz	 *					vMPLLCON_170MHz	 *					vMPLLCON_90MHz	 *					vMPLLCON_50MHz	 */	set_system_clock(vMPLLCON_202MHz);	io_config();			lcd_on();	console_init();	dump_info();	touchsrc_con_init();	irq_enable();	ram_init();	//sdi_init();	if(mount_fat32()==-1)		printk("file system mount fail.\n\n\n");	else			printk("FAT32 mount.\n");	sched_init();	set_sched_freq(50);	//时钟滴答为50赫兹	enable_watchdog();	//find_cluster("programe\\hello\\haha\\hello\\ding\\programe\\hello\\haha\\hello\\ding\\");	move_to_user();//从这里开始的代码将运行在User模式	start_task0();	while(1);}void start_task0(){	if(fork()==0)	{		printf("Hello! I am task1.\n");		while(1);	}	if(fork()==0)	{		printf("Hello! I am task2.\n");		while(1);	}	if(fork()==0)	{		printf("Hello! I am task3.\n");		while(1);	}		if(fork()==0)	{		printf("Hello! I am task4.\n");		while(1);	}	printf("Hello! I am task0.\n");	while(1);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -