src/kernel/task/threads.c
/**
 * @note this function will create a empty user process.
 *       must load exe file before add it to scheduler.
 * @return
 */
@note this function will create a empty user process.
must load exe file before add it to scheduler.
@return
@note this function will create a empty user process . must load exe file before add it to scheduler . @return
thread_t * create_empty_process_for_exe_load(){
    vmm_t * vmm_pool = object_new(OBJECT_VMM,CONFIG_USER_ADDR_START,(CONFIG_USER_ADDR_END-CONFIG_USER_ADDR_START)/PAGE_SIZE);
    if(vmm_pool == NULL){
        return NULL;
    }
    object_clear_ref(vmm_pool);
    vmm_copy_kern_space(vmm_pool);
    trap_frame_t trap_frame={0};
    trap_frame.sepc = CONFIG_USER_DEFAULT_ENTRY;
    trap_frame.sscratch = CONFIG_USER_ADDR_END;
    if(valloc(vmm_pool,trap_frame.sscratch-2*PAGE_SIZE,2,VMM_PTE_R|VMM_PTE_W)==NULL){
        return NULL;
    }
    platform_driver_mmio_vmap(vmm_pool);
    plic_mmio_map(vmm_pool);
    vmm_pool->brk_start = 0;
    vmm_pool->brk_end = 0;
    thread_t * self = create_user_thread(trap_frame, vmm_pool, tid_gen(), pid_gen(), NULL);
    if(self==NULL){
        return NULL;
    }
    return self;
}
thread_t * create_empty_process_for_exe_load ( ) { vmm_t * vmm_pool = object_new ( OBJECT_VMM , CONFIG_USER_ADDR_START , ( CONFIG_USER_ADDR_END - CONFIG_USER_ADDR_START ) / PAGE_SIZE ) ; if ( vmm_pool == NULL ) { return NULL ; } object_clear_ref ( vmm_pool ) ; vmm_copy_kern_space ( vmm_pool ) ; trap_frame_t trap_frame = { 0 } ; trap_frame . sepc = CONFIG_USER_DEFAULT_ENTRY ; trap_frame . sscratch = CONFIG_USER_ADDR_END ; if ( valloc ( vmm_pool , trap_frame . sscratch - 2 * PAGE_SIZE , 2 , VMM_PTE_R | VMM_PTE_W ) == NULL ) { return NULL ; } platform_driver_mmio_vmap ( vmm_pool ) ; plic_mmio_map ( vmm_pool ) ; vmm_pool -> brk_start = 0 ; vmm_pool -> brk_end = 0 ; thread_t * self = create_user_thread ( trap_frame , vmm_pool , tid_gen ( ) , pid_gen ( ) , NULL ) ; if ( self == NULL ) { return NULL ; } return self ; }
@note this function will create a empty user process.
@note this function will create a empty user process .
//clear ref_cnt to 0 , and this obj will ref in user thread create... //copy kern vmm pagetable // the sepc is the start point of control flow in user mode. // if exe loader have different start point , it have to change. // alloc user stack.