Skip to content
New issue

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

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

Already on GitHub? # to your account

day03a以降、カーネルの起動まで進まない #74

Closed
mj-hd opened this issue Oct 1, 2022 · 2 comments
Closed

day03a以降、カーネルの起動まで進まない #74

mj-hd opened this issue Oct 1, 2022 · 2 comments

Comments

@mj-hd
Copy link

mj-hd commented Oct 1, 2022

day03a以降、カーネルへ処理を移していると思いますが、この章から先が全て動いておらず、何かご助言いただけないでしょうか。

ソースコード: uchan-nos/mikanos, branch: osbook_day03a

edk2: https://github.com/tianocore/edk2/tree/4ac02962017c77bf38b462f970c884c2dc7931cf (gcc12で動くようこのパッチを当てています)

clang: 14.0.6

カーネルビルドコマンド:

$ clang++ -O2 -Wall -g --target=x86_64-elf -ffreestanding -mno-red-zone -fno-exceptions -fno-rtti -std=c++17 -c main.cpp`
$ ld.lld --entry KernelMain -z norelro --image-base 0x100000 --static -o kernel.elf main.o

QEMU起動コマンド:
$ ./devenv/run_qemu.sh edk2/Build/MikanLoaderX64/DEBUG_CLANG38/X64/Loader.efi kernel/kernel.elf

QEMU起動後の様子:
image

レジスタの値を確認してみると、以下のようになっています(RIPはkernelまで到達できていなそうでした):

(qemu) info registers
RAX=000000003fb7b3e0 RBX=000000003fb79f3b RCX=000000003fb7b3e0 RDX=000000003fea03f8
RSI=0000000000000000 RDI=0000000000101180 RBP=000000003fea87e0 RSP=000000003fea83c0
R8 =0000000000000001 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=000000003f308198 R13=0000000000000210 R14=000000003fb68234 R15=0000000000000006
RIP=000000003fb73016 RFL=00000046 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0030 0000000000000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0038 0000000000000000 ffffffff 00af9a00 DPL=0 CS64 [-R-]
SS =0030 0000000000000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0030 0000000000000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0030 0000000000000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0030 0000000000000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     000000003fbee698 00000047
IDT=     000000003f306018 00000fff
CR0=80010033 CR2=0000000000000000 CR3=000000003fc01000 CR4=00000668
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000500
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=0000000000000000 0000000000000000 XMM01=0000000000000000 0000000000000000
XMM02=0000000000000000 0000000000000000 XMM03=0000000000000000 0000000000000000
XMM04=0000000000000000 0000000000000000 XMM05=0000000000000000 0000000000000000
XMM06=0000000000000000 0000000000000000 XMM07=0000000000000000 0000000000000000
XMM08=0000000000000000 0000000000000000 XMM09=0000000000000000 0000000000000000
XMM10=0000000000000000 0000000000000000 XMM11=0000000000000000 0000000000000000
XMM12=0000000000000000 0000000000000000 XMM13=0000000000000000 0000000000000000
XMM14=0000000000000000 0000000000000000 XMM15=0000000000000000 0000000000000000
(qemu) x /2i 0x000000003fb73016
0x3fb73016:  48 83 7c 24 40 00        cmpq     $0, 0x40(%rsp)
0x3fb7301c:  74 f8                    je       0x3fb73016

試しに、以下のようにPrint文を仕込んでみると、先ほどとは変わってエラーメッセージが出力されるようになります:

diff --git a/MikanLoaderPkg/Main.c b/MikanLoaderPkg/Main.c
index f7f50be..226af7c 100644
--- a/MikanLoaderPkg/Main.c
+++ b/MikanLoaderPkg/Main.c
@@ -153,13 +153,16 @@ EFI_STATUS EFIAPI UefiMain(

   // #@@range_begin(exit_bs)
   EFI_STATUS status;
+  Print(L"Run First ExitBootServices\n");
   status = gBS->ExitBootServices(image_handle, memmap.map_key);
   if (EFI_ERROR(status)) {
+    Print(L"EFI_ERROR(%d) Run GetMemoryMap\n", status);
     status = GetMemoryMap(&memmap);
     if (EFI_ERROR(status)) {
       Print(L"failed to get memory map: %r\n", status);
       while (1);
     }
+    Print(L"Run Second ExitBootServices\n");
     status = gBS->ExitBootServices(image_handle, memmap.map_key);
     if (EFI_ERROR(status)) {
       Print(L"Could not exit boot service: %r\n", status);

QEMU起動後の様子:
image

@mj-hd
Copy link
Author

mj-hd commented Oct 1, 2022

すみません、https://github.com/uchan-nos/os-from-zero のレポジトリにIssue立てるのが正しかったようです。
こちらCloseします。

@mj-hd mj-hd closed this as completed Oct 1, 2022
@mj-hd
Copy link
Author

mj-hd commented Oct 1, 2022

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant