File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 21
21
#include <exception/gate.h>
22
22
#include <filesystem/devfs/devfs.h>
23
23
#include <filesystem/fat32/fat32.h>
24
- #include <filesystem/rootfs/rootfs.h>
25
24
#include <filesystem/procfs/procfs.h>
25
+ #include <filesystem/rootfs/rootfs.h>
26
26
#include <ktest/ktest.h>
27
27
#include <mm/slab.h>
28
28
#include <sched/sched.h>
@@ -123,6 +123,18 @@ void __switch_to(struct process_control_block *prev, struct process_control_bloc
123
123
}
124
124
#pragma GCC pop_options
125
125
126
+ /**
127
+ * @brief 切换进程的fs、gs寄存器
128
+ * 注意,fs、gs的值在return的时候才会生效,因此本函数不能简化为一个单独的宏
129
+ * @param fs 目标fs值
130
+ * @param gs 目标gs值
131
+ */
132
+ void process_switch_fsgs (uint64_t fs , uint64_t gs )
133
+ {
134
+ asm volatile ("movq %0, %%fs \n\t" ::"a" (fs ));
135
+ asm volatile ("movq %0, %%gs \n\t" ::"a" (gs ));
136
+ }
137
+
126
138
/**
127
139
* @brief 打开要执行的程序文件
128
140
*
@@ -504,6 +516,7 @@ ul initial_kernel_thread(ul arg)
504
516
current_pcb -> thread -> fs = USER_DS | 0x3 ;
505
517
barrier ();
506
518
current_pcb -> thread -> gs = USER_DS | 0x3 ;
519
+ process_switch_fsgs (current_pcb -> thread -> fs , current_pcb -> thread -> gs );
507
520
508
521
// 主动放弃内核线程身份
509
522
current_pcb -> flags &= (~PF_KTHREAD );
You can’t perform that action at this time.
0 commit comments