finish exec4.14-15

This commit is contained in:
KAAAsS 2021-05-18 18:42:57 +08:00
parent 7660d524f4
commit 0512b0d497
Signed by: KAAAsS
GPG Key ID: D56625F3E671882F
4 changed files with 28 additions and 15 deletions

View File

@ -13,4 +13,4 @@ define add-symbol-file-auto
end end
add-symbol-file-auto ./build/kernel.img add-symbol-file-auto ./build/kernel.img
add-symbol-file-auto ./user/build/ramdisk/yield_multi_aff.bin add-symbol-file-auto ./user/build/ramdisk/spawn_info.bin

View File

@ -144,8 +144,8 @@ struct thread *rr_sched_choose_thread(void)
return NULL; return NULL;
} }
kdebug("[RR] Cpu #%d Select thread %lx, sp = %lx\n", // kdebug("[RR] Cpu #%d Select thread %lx, sp = %lx\n",
smp_get_cpu_id(), result->thread_ctx, result->thread_ctx->ec.reg[SP_EL0]); // smp_get_cpu_id(), result->thread_ctx, result->thread_ctx->ec.reg[SP_EL0]);
return result; return result;
} }
@ -179,7 +179,7 @@ int rr_sched(void)
// 若非空闲线程,放入队列 // 若非空闲线程,放入队列
if (current_thread->thread_ctx->type != TYPE_IDLE) { if (current_thread->thread_ctx->type != TYPE_IDLE) {
rr_sched_enqueue(current_thread); rr_sched_enqueue(current_thread);
kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx); // kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx);
} }
} }

View File

@ -259,8 +259,8 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* process. * process.
* You do not need to modify code in this scope * You do not need to modify code in this scope
*/ */
pmo_requests[0].size = LAB4_SPAWN_BLANK; pmo_requests[0].size = MAIN_THREAD_STACK_SIZE;
pmo_requests[0].type = LAB4_SPAWN_BLANK; pmo_requests[0].type = PMO_DATA;
ret = usys_create_pmos((void *)pmo_requests, 1); ret = usys_create_pmos((void *)pmo_requests, 1);
if (ret != 0) { if (ret != 0) {
@ -284,7 +284,7 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* Transfer the capbilities (nr_caps) of current process to the * Transfer the capbilities (nr_caps) of current process to the
* capbilities of child process * capbilities of child process
*/ */
// 将需要转移的 Caps 进行转移
if (nr_caps > 0) { if (nr_caps > 0) {
/* usys_transfer_caps is used during process creation */ /* usys_transfer_caps is used during process creation */
ret = usys_transfer_caps(new_process_cap, caps, nr_caps, ret = usys_transfer_caps(new_process_cap, caps, nr_caps,
@ -302,7 +302,8 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* Use the given pmo_mao_reqs to map the vmspace in the child * Use the given pmo_mao_reqs to map the vmspace in the child
* process * process
*/ */
if (nr_pmo_map_reqs) { // 将参数中需要映射子进程的 PMOs 进行映射,即可实现共享内存
if (nr_pmo_map_reqs > 0) {
ret = ret =
usys_map_pmos(new_process_cap, (void *)pmo_map_reqs, usys_map_pmos(new_process_cap, (void *)pmo_map_reqs,
nr_pmo_map_reqs); nr_pmo_map_reqs);
@ -329,13 +330,13 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* thread's stack? * thread's stack?
* *
* For stack_offset, when the main thread gets * For stack_offset, when the main thread gets
* to execute the first time, what's the virtual adress the sp * to execute the first time, what's the virtual address the sp
* register points to? * register points to?
* stack_offset is the offset from main thread's stack base to * stack_offset is the offset from main thread's stack base to
* that address. * that address.
*/ */
stack_top = LAB4_SPAWN_BLANK; stack_top = MAIN_THREAD_STACK_BASE + MAIN_THREAD_STACK_SIZE;
stack_offset = LAB4_SPAWN_BLANK; stack_offset = MAIN_THREAD_STACK_SIZE - PAGE_SIZE;
/* Construct the parameters on the top page of the stack */ /* Construct the parameters on the top page of the stack */
construct_init_env(init_env, stack_top, &user_elf->elf_meta, construct_init_env(init_env, stack_top, &user_elf->elf_meta,
@ -364,9 +365,9 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* map the the main thread stack's pmo in the new process. * map the the main thread stack's pmo in the new process.
* Both VM_READ and VM_WRITE permission should be set. * Both VM_READ and VM_WRITE permission should be set.
*/ */
pmo_map_requests[0].pmo_cap = LAB4_SPAWN_BLANK; pmo_map_requests[0].pmo_cap = main_stack_cap;
pmo_map_requests[0].addr = LAB4_SPAWN_BLANK; pmo_map_requests[0].addr = MAIN_THREAD_STACK_BASE;
pmo_map_requests[0].perm = LAB4_SPAWN_BLANK; pmo_map_requests[0].perm = VM_READ | VM_WRITE;
ret = ret =
usys_map_pmos(new_process_cap, (void *)pmo_map_requests, 1); usys_map_pmos(new_process_cap, (void *)pmo_map_requests, 1);
@ -384,7 +385,7 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
* create main thread in the new process. * create main thread in the new process.
* Please fill the stack_va! * Please fill the stack_va!
*/ */
stack_va = LAB4_SPAWN_BLANK; stack_va = MAIN_THREAD_STACK_BASE + stack_offset;
main_thread_cap = main_thread_cap =
usys_create_thread(new_process_cap, stack_va, pc, usys_create_thread(new_process_cap, stack_va, pc,
(u64) NULL, MAIN_THREAD_PRIO, aff); (u64) NULL, MAIN_THREAD_PRIO, aff);
@ -397,6 +398,12 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf,
{ {
/* Step C: Output the child process & thread capabilities */ /* Step C: Output the child process & thread capabilities */
if (child_process_cap != NULL) {
}
if (child_main_thread_cap != NULL) {
}
} }
return 0; return 0;

View File

@ -211,3 +211,9 @@ sys_yield 要注意必须手动调用切换上下文,不然不会有效果。
*** 练习8 *** 练习8
否则将无法再次在该核上进行调度。 否则将无法再次在该核上进行调度。
*** 练习15
Step A、B 的代码完全没有删干净,而且 A、B 描述都是反的。所以写完练习 14 就可以直接通过 spawn info 了。
我还以为乱码是我又映射错了,结果是代码真的是这么设计的,好吧。