2014年(21)
分类: LINUX
2014-09-02 19:34:50
stage2_end=stage2_start+stage2_size |
.text .globl _trampoline _trampoline: bl main /* if main ever returns we just call it again */ b _trampoline |
typedef struct memory_area_struct { u32 start; /* the base address of the memory region */ u32 size; /* the byte number of the memory region */ int used; } memory_area_t; |
memory_area_t memory_map[NUM_MEM_AREAS] = { [0 ... (NUM_MEM_AREAS - 1)] = { .start = 0, .size = 0, .used = 0 }, }; |
/* 数组初始化 */ for(i = 0; i < NUM_MEM_AREAS; i++) memory_map.used = 0; /* first write a 0 to all memory locations */ for(addr = MEM_START; addr < MEM_END; addr += PAGE_SIZE) * (u32 *)addr = 0; for(i = 0, addr = MEM_START; addr < MEM_END; addr += PAGE_SIZE) { /* * 检测从基地址 MEM_START+i*PAGE_SIZE 开始,大小为 * PAGE_SIZE 的地址空间是否是有效的RAM地址空间。 */ 调用3.1.2节中的算法test_mempage(); if ( current memory page isnot a valid ram page) { /* no RAM here */ if(memory_map.used ) i++; continue; } /* * 当前页已经是一个被映射到 RAM 的有效地址范围 * 但是还要看看当前页是否只是 4GB 地址空间中某个地址页的别名? */ if(* (u32 *)addr != 0) { /* alias? */ /* 这个内存页是 4GB 地址空间中某个地址页的别名 */ if ( memory_map.used ) i++; continue; } /* * 当前页已经是一个被映射到 RAM 的有效地址范围 * 而且它也不是 4GB 地址空间中某个地址页的别名。 */ if (memory_map.used == 0) { memory_map.start = addr; memory_map.size = PAGE_SIZE; memory_map.used = 1; } else { memory_map.size += PAGE_SIZE; } } /* end of for (…) */ |
while(count) { *dest++ = *src++; /* they are all aligned with word boundary */ count -= 4; /* byte number */ }; |
/* The list ends with an ATAG_NONE node. */ #define ATAG_NONE 0x00000000 struct tag_header { u32 size; /* 注意,这里size是字数为单位的 */ u32 tag; }; …… struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem; struct tag_videotext videotext; struct tag_ramdisk ramdisk; struct tag_initrd initrd; struct tag_serialnr serialnr; struct tag_revision revision; struct tag_videolfb videolfb; struct tag_cmdline cmdline; /* * Acorn specific */ struct tag_acorn acorn; /* * DC21285 specific */ struct tag_memclk memclk; } u; }; |
params = (struct tag *)BOOT_PARAMS; params->hdr.tag = ATAG_CORE; params->hdr.size = tag_size(tag_core); params->u.core.flags = 0; params->u.core.pagesize = 0; params->u.core.rootdev = 0; params = tag_next(params); |
for(i = 0; i < NUM_MEM_AREAS; i++) { if(memory_map.used) { params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size(tag_mem32); params->u.mem.start = memory_map.start; params->u.mem.size = memory_map.size; params = tag_next(params); } } |
char *p; /* eat leading white space */ for(p = commandline; *p == ' '; p++) ; /* skip non-existent command lines so the kernel will still * use its default command line. */ if(*p == '\0') return; params->hdr.tag = ATAG_CMDLINE; params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2; strcpy(params->u.cmdline.cmdline, p); params = tag_next(params); |
params->hdr.tag = ATAG_INITRD2; params->hdr.size = tag_size(tag_initrd); params->u.initrd.start = RAMDISK_RAM_BASE; params->u.initrd.size = INITRD_LEN; params = tag_next(params); |
params->hdr.tag = ATAG_RAMDISK; params->hdr.size = tag_size(tag_ramdisk); params->u.ramdisk.start = 0; params->u.ramdisk.size = RAMDISK_SIZE; /* 请注意,单位是KB */ params->u.ramdisk.flags = 1; /* automatically load ramdisk */ params = tag_next(params); |
static void setup_end_tag(void) { params->hdr.tag = ATAG_NONE; params->hdr.size = 0; } |
void (*theKernel)(int zero, int arch, u32 params_addr) = (void (*)(int, int, u32))KERNEL_RAM_BASE; …… theKernel(0, ARCH_NUMBER, (u32) kernel_params_start); |