这是引导程序的主要功能
/* bootmain - the entry of bootloader */
void
bootmain(void) {
// read the 1st page off disk
readseg((uintptr_t)ELFHDR,SECTSIZE * 8,0);
// is this a valid ELF?
if (ELFHDR->e_magic != ELF_MAGIC) {
goto bad;
}
struct proghdr *ph,*eph;
// load each program segment (ignores ph flags)
ph = (struct proghdr *)((uintptr_t)ELFHDR + ELFHDR->e_phoff);
eph = ph + ELFHDR->e_phnum;
for (; ph < eph; ph ++) {
readseg(ph->p_va & 0xFFFFFF,ph->p_memsz,ph->p_offset);
}
// call the entry point from the ELF header
// note: does not return
((void (*)(void))(ELFHDR->e_entry & 0xFFFFFF))();
bad:
outw(0x8A00,0x8A00);
outw(0x8A00,0x8E00);
/* do nothing */
while (1);
}
我对最后一个指令的含义感到好奇,它们是'outw(0x8A00,0x8A00); outw(0x8A00,0x8E00);' 如您所知,内核函数将永远不会返回。 函数outw定义如下,它只在使用指定端口进行I / O。
static inline void
outw(uint16_t port,uint16_t data) {
asm volatile ("outw %0,%1" :: "a" (data),"d" (port));
}
此外,我想知道为什么从ELF读取的每个虚拟地址都应为Logic And,例如0xFFFFFF。 ph-> p_va和0xFFFFFF。如果没有逻辑与运算怎么办?