/** @brief Switch memory context */ void km_arch_ctx_switch(struct km * pre_ctx, struct km * next_ctx) { unsigned long cr3_physical; /* Get physical base of cr3 */ cr3_physical = HAL_GET_BASIC_PHYADDRESS(next_ctx->translation_table); //TODO: not use this macro /* Write to cr3 to switch */ write_cr3(cr3_physical); #if 0 /*load the LDT, if the LDT is different*/ if(unlikely(pre_ctx->ldt!=new_ctx->ldt)) { //printk("\nnew_ctx->ldt :%h,%d.",new_ctx->ldt,new_ctx->ldt_entries); set_ldt(new_ctx->ldt,new_ctx->ldt_entries); } #endif }
/** @brief Map driver framework to kernel */ void ke_startup_driver_process(void *physical_data, size_t size) { unsigned long entry_address; unsigned long base; Elf32_Ehdr *hdr = (Elf32_Ehdr*)physical_data; if (hdr->e_ident[EI_CLASS] == ELFCLASS32) { entry_address = hdr->e_entry; } else if (hdr->e_ident[EI_CLASS] == ELFCLASS64) { Elf64_Ehdr *hdr64 = (Elf64_Ehdr*)physical_data; entry_address = hdr64->e_entry; } else { printk("不识别的驱动文件格式.\n"); goto end; } /* 64kb offset is not base */ base = entry_address & (~0xffff); // TODO: size of the map should contain bss, and notify system that bss should not be allocated for normal use */ /* Map physical to base */ if (km_map_physical(HAL_GET_BASIC_PHYADDRESS(physical_data), size + 0x60000/*BSS?*/, base | KM_MAP_PHYSICAL_FLAG_WITH_VIRTUAL | KM_MAP_PHYSICAL_FLAG_NORMAL_CACHE) == NULL) goto err; ((void(*)())entry_address)(&ddk); end: return; err: printk("驱动包影射到内核空间失败,可能是地址冲突,要影射的地址范围为%d@%x.\n", size, base); }
unsigned long hal_get_basic_phyaddr(void *vaddr) { return HAL_GET_BASIC_PHYADDRESS(vaddr); }