Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CR3より先にContext::cr3に値を設定しておくべき? #6

Open
uchan-nos opened this issue Feb 21, 2021 · 3 comments
Open
Labels
bug Something isn't working

Comments

@uchan-nos
Copy link
Owner

mikanos/kernel/terminal.cpp

Lines 135 to 136 in 88b352c

SetCR3(cr3);
current_task.Context().cr3 = cr3;

SetCR3 の直後にタスクスイッチしてしまうと、戻ってきたときに current_task.Context().cr3 = 0 となっていて、
先ほど生成した PML4 ではなく、デフォルトの PML4 が CR3 に設定されてしまうのではないか?

@uchan-nos uchan-nos added the bug Something isn't working label Feb 21, 2021
@alpha-netzilla
Copy link
Contributor

mikanos/kernel/terminal.cpp

Lines 142 to 143 in 88b352c

current_task.Context().cr3 = 0;
ResetCR3();

同様の問題は上のコードでは発生しないでしょうか?

  1. current_task.Context().cr3 = 0
  2. ResetCR3()
  3. タスクスイッチ
  4. タスクスイッチ戻り

@uchan-nos
Copy link
Owner Author

@alpha-netzilla
問題無いと思います。
タスクスイッチ(SwitchContext)の中で、そのとき CR3 に設定されていた値が Context 構造体の cr3 フィールドに保存されるからです。

mikanos/kernel/asmfunc.asm

Lines 132 to 133 in d4048a3

mov rax, cr3
mov [rsi + 0x00], rax ; CR3

同様に、私が書いた 2 行の処理も問題無い気がします。

ご意見ください。

@alpha-netzilla
Copy link
Contributor

alpha-netzilla commented May 20, 2021

@uchan-nos
ご指摘ありがとうございます。SwitchContext のコードを読み、私も問題ないと判断しました。
"その時の CR3 レジスタの値が"、"Context 構造体の cr3 フィールドに"、ここがポイントですね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants