📄 mkservice.c.svn-base
字号:
#include "lib.h"#include "elf.h"#include "mkservice.h"#include <arch.h>static struct mk_service *services = (struct mk_service *)SERVICE_START;extern int elf_load (char *elf, struct mk_service_entry* entry);extern void start_kernel(rt_uint32 kernel_entry, rt_uint32 service_entry);/* * load microkernel service: kernel and services * * It reads each service file and copy it to the physical memory area. */static int load_service(void){ char *ptr, index; struct service_description* sd; struct service_entry* entry; ptr = (char*)ENTRY_START; sd = (struct service_description*)ENTRY_START; if (sd[0] != MK_MAGIC0 || sd[1] != MK_MAGIC1 || sd[2] != MK_MAGIC2 || sd[3] != MK_MAGIC3 ) { printf("invalid service description\n"); return -1; } entry = (struct service_entry*)(sd + 1); for (index = 0; index < sd->count; index ++) { /* binary, copy to physical address */ if (entry[i].type == SERVICE_TYPE_BINARY) { memcopy(phaddr, ptr + entry[i].offset, entry[i].size); } /* loading elf */ else if (entry[i].type == SERVICE_TYPE_ELF_LOADING) { if (elf_load(ptr + entry[i].offset, &entry[i])) { printf("loading elf failed\n"); return -1; } } } return 0;}/* boot loader entry point */void loader_main(void){ rt_uint32 kernel_entry; /* init arch */ rt_arch_init(); printf("RT-Thread Service Loader V0.0.1\n"); /* clean services description page */ memset((char*)services, 0, sizeof(struct mk_service)); /* set services description page's magic */ services->magic[0] = MK_MAGIC0; services->magic[1] = MK_MAGIC1; services->magic[2] = MK_MAGIC2; services->magic[3] = MK_MAGIC3; /* init physical memory */ service_memory_init(services); if (load_service() == 0) { kernel_entry = (unsigned int)phys_to_virt(services->kernel.entry); printf("kernel_entry=%x\n", kernel_entry); start_kernel(kernel_entry, (rt_uint32)services); } printf("loading services failed\n"); while(1) ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -