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

Bochs fails to boot with cpu model = pentium or pentium_mmx #63

Closed
egranata opened this issue Sep 28, 2018 · 5 comments
Closed

Bochs fails to boot with cpu model = pentium or pentium_mmx #63

egranata opened this issue Sep 28, 2018 · 5 comments
Labels
bug Something isn't working kernel panic A kind of bug that shows us as the kernel panicking

Comments

@egranata
Copy link
Owner

If one sets the Bochs CPU model (http://bochs.sourceforge.net/doc/docbook/user/cpu-models.html) to either pentium or pentium_mmx the boot fails at:

(0).[463479252] [0x000000146ef3] 0010:0000000000146ef3 (unk. ctxt): mov cr4, ecx              ; 0f22e1

At a glance, this is in loader.s:

    mov ecx, cr4
    or ecx,  0x00000080                          ; Allow global page mappings (must be done with PG=1)
    mov cr4, ecx

Do we need to do this so early at boot? Can we use CPUID to detect whether this is supported? Can we try and do it later on, and panic?

@egranata egranata added bug Something isn't working kernel panic A kind of bug that shows us as the kernel panicking labels Sep 28, 2018
@egranata
Copy link
Owner Author

Fixing the PGE issue is not especially hard (CPUID.0x1 EDX bit 13 contains the support information) and it is definitely possible to map the kernel without the "G" bit enabled (at a performance cost); but the compiler is generating unsupported instructions:

[0] kernel/src/boot/earlyboot.cpp:39 invalid instruction [eip = 0xC0101AFA]
[0] kernel/src/boot/earlyboot.cpp:39 invalid instruction [eip = 0xC012072A]

In both cases, the culprit is a CMOVE:

kernel`PhysicalPageManager::alloc:
kernel[0xc0101ad0] <+0>:   push   ebp
kernel[0xc0101ad1] <+1>:   mov    eax, 0x100000
kernel[0xc0101ad6] <+6>:   mov    ebp, esp
kernel[0xc0101ad8] <+8>:   push   edi
kernel[0xc0101ad9] <+9>:   push   esi
kernel[0xc0101ada] <+10>:  xor    esi, esi
kernel[0xc0101adc] <+12>:  push   ebx
kernel[0xc0101add] <+13>:  sub    esp, 0x4
kernel[0xc0101ae0] <+16>:  mov    ebx, dword ptr [ebp + 0x8]
kernel[0xc0101ae3] <+19>:  mov    ecx, dword ptr [ebx + 0x200000]
kernel[0xc0101ae9] <+25>:  jmp    0xc0101af4                ; <+36>
kernel[0xc0101aeb] <+27>:  nop
kernel[0xc0101aec] <+28>:  lea    esi, [esi]
kernel[0xc0101af0] <+32>:  inc    ecx
kernel[0xc0101af1] <+33>:  dec    eax
kernel[0xc0101af2] <+34>:  je     0xc0101b40                ; <+112>
kernel[0xc0101af4] <+36>:  cmp    ecx, 0x100000
kernel[0xc0101afa] <+42>:  cmove  ecx, esi

and

kernel`panichandler:
kernel[0xc0120700] <+0>:   push   ebp
kernel[0xc0120701] <+1>:   mov    ebp, esp
kernel[0xc0120703] <+3>:   push   edi
kernel[0xc0120704] <+4>:   push   esi
kernel[0xc0120705] <+5>:   push   ebx
kernel[0xc0120706] <+6>:   sub    esp, 0x4c
kernel[0xc0120709] <+9>:   call   0xc012568d                ; disableirq
kernel[0xc012070e] <+14>:  mov    edx, dword ptr [-0x3fc8c910]
kernel[0xc0120714] <+20>:  mov    eax, 0xc0133b8e
kernel[0xc0120719] <+25>:  mov    ecx, 0xc0133b9a
kernel[0xc012071e] <+30>:  mov    dword ptr [esp], 0x0
kernel[0xc0120725] <+37>:  lea    ebx, [ebp - 0x1b]
kernel[0xc0120728] <+40>:  test   edx, edx
kernel[0xc012072a] <+42>:  cmove  edx, eax

(which funnily enough means that the PANIC itself recursively causes a PANIC)

https://stackoverflow.com/questions/30150274/purpose-of-cmove-instruction-in-x86-assembly

@egranata
Copy link
Owner Author

In theory it should be possible to set -march=i586 and disable the generation of CMOVE (as the instruction was part of the Pentium Pro first, aka i686), but for some reason as of yet unclear, init still has such code in its malloc implementation:

init`_malloc_r:
init[0x4022e0] <+0>:    pushl  %ebp
init[0x4022e1] <+1>:    pushl  %edi
init[0x4022e2] <+2>:    pushl  %esi
init[0x4022e3] <+3>:    pushl  %ebx
init[0x4022e4] <+4>:    subl   $0x1c, %esp
init[0x4022e7] <+7>:    movl   0x34(%esp), %eax
init[0x4022eb] <+11>:   leal   0xb(%eax), %esi
init[0x4022ee] <+14>:   cmpl   $0x16, %esi
init[0x4022f1] <+17>:   ja     0x402370                  ; <+144>
init[0x4022f3] <+19>:   cmpl   $0x10, %eax
init[0x4022f6] <+22>:   ja     0x4025f0                  ; <+784>
init[0x4022fc] <+28>:   subl   $0xc, %esp
init[0x4022ff] <+31>:   movl   $0x10, %esi
init[0x402304] <+36>:   pushl  0x3c(%esp)
init[0x402308] <+40>:   calll  0x402c60                  ; __malloc_lock
init[0x40230d] <+45>:   addl   $0x10, %esp
init[0x402310] <+48>:   movl   $0x18, %eax
init[0x402315] <+53>:   movl   $0x2, %ecx
init[0x40231a] <+58>:   movl   0x4134a4(%eax), %ebx
init[0x402320] <+64>:   leal   0x413498(%eax), %edx
init[0x402326] <+70>:   addl   $0x4134a0, %eax           ; imm = 0x4134A0
init[0x40232b] <+75>:   cmpl   %edx, %ebx
init[0x40232d] <+77>:   je     0x4027a0                  ; <+1216>
init[0x402333] <+83>:   movl   0x4(%ebx), %eax
init[0x402336] <+86>:   andl   $-0x4, %eax
init[0x402339] <+89>:   movl   0xc(%ebx), %edx
init[0x40233c] <+92>:   movl   0x8(%ebx), %ecx
init[0x40233f] <+95>:   movl   %edx, 0xc(%ecx)
init[0x402342] <+98>:   movl   %ecx, 0x8(%edx)
init[0x402345] <+101>:  orl    $0x1, 0x4(%ebx,%eax)
init[0x40234a] <+106>:  subl   $0xc, %esp
init[0x40234d] <+109>:  pushl  0x3c(%esp)
init[0x402351] <+113>:  calll  0x402c70                  ; __malloc_unlock
init[0x402356] <+118>:  leal   0x8(%ebx), %eax
init[0x402359] <+121>:  addl   $0x10, %esp
init[0x40235c] <+124>:  addl   $0x1c, %esp
init[0x40235f] <+127>:  popl   %ebx
init[0x402360] <+128>:  popl   %esi
init[0x402361] <+129>:  popl   %edi
init[0x402362] <+130>:  popl   %ebp
init[0x402363] <+131>:  retl
init[0x402364] <+132>:  leal   (%esi), %esi
init[0x40236a] <+138>:  leal   (%edi), %edi
init[0x402370] <+144>:  andl   $-0x8, %esi
init[0x402373] <+147>:  js     0x4025f0                  ; <+784>
init[0x402379] <+153>:  cmpl   %esi, %eax
init[0x40237b] <+155>:  ja     0x4025f0                  ; <+784>
init[0x402381] <+161>:  subl   $0xc, %esp
init[0x402384] <+164>:  pushl  0x3c(%esp)
init[0x402388] <+168>:  calll  0x402c60                  ; __malloc_lock
init[0x40238d] <+173>:  addl   $0x10, %esp
init[0x402390] <+176>:  cmpl   $0x1f7, %esi              ; imm = 0x1F7
init[0x402396] <+182>:  jbe    0x4027d0                  ; <+1264>
init[0x40239c] <+188>:  movl   %esi, %eax
init[0x40239e] <+190>:  shrl   $0x9, %eax
init[0x4023a1] <+193>:  testl  %eax, %eax
init[0x4023a3] <+195>:  je     0x4023d0                  ; <+240>
init[0x4023a5] <+197>:  cmpl   $0x4, %eax
init[0x4023a8] <+200>:  jbe    0x4025c0                  ; <+736>
init[0x4023ae] <+206>:  cmpl   $0x14, %eax
init[0x4023b1] <+209>:  ja     0x402900                  ; <+1568>
init[0x4023b7] <+215>:  leal   0x5c(%eax), %ebp
init[0x4023ba] <+218>:  leal   0x5b(%eax), %edi
init[0x4023bd] <+221>:  leal   (,%ebp,8), %eax
init[0x4023c4] <+228>:  jmp    0x4023df                  ; <+255>
init[0x4023c6] <+230>:  leal   (%esi), %esi
init[0x4023c9] <+233>:  leal   (%edi), %edi
init[0x4023d0] <+240>:  movl   $0x200, %eax              ; imm = 0x200
init[0x4023d5] <+245>:  movl   $0x40, %ebp
init[0x4023da] <+250>:  movl   $0x3f, %edi
init[0x4023df] <+255>:  movl   0x4134a4(%eax), %ebx
init[0x4023e5] <+261>:  leal   0x413498(%eax), %ecx
init[0x4023eb] <+267>:  cmpl   %ebx, %ecx
init[0x4023ed] <+269>:  jne    0x40240f                  ; <+303>
init[0x4023ef] <+271>:  jmp    0x402420                  ; <+320>
init[0x4023f1] <+273>:  jmp    0x402400                  ; <+288>
init[0x4023f3] <+275>:  nop
init[0x4023f4] <+276>:  nop
init[0x4023f5] <+277>:  nop
init[0x4023f6] <+278>:  nop
init[0x4023f7] <+279>:  nop
init[0x4023f8] <+280>:  nop
init[0x4023f9] <+281>:  nop
init[0x4023fa] <+282>:  nop
init[0x4023fb] <+283>:  nop
init[0x4023fc] <+284>:  nop
init[0x4023fd] <+285>:  nop
init[0x4023fe] <+286>:  nop
init[0x4023ff] <+287>:  nop
init[0x402400] <+288>:  testl  %edx, %edx
init[0x402402] <+290>:  jns    0x402339                  ; <+89>
init[0x402408] <+296>:  movl   0xc(%ebx), %ebx
init[0x40240b] <+299>:  cmpl   %ebx, %ecx
init[0x40240d] <+301>:  je     0x402420                  ; <+320>
init[0x40240f] <+303>:  movl   0x4(%ebx), %eax
init[0x402412] <+306>:  andl   $-0x4, %eax
init[0x402415] <+309>:  movl   %eax, %edx
init[0x402417] <+311>:  subl   %esi, %edx
init[0x402419] <+313>:  cmpl   $0xf, %edx
init[0x40241c] <+316>:  jle    0x402400                  ; <+288>
init[0x40241e] <+318>:  movl   %edi, %ebp
init[0x402420] <+320>:  movl   0x4134b0, %ebx
init[0x402426] <+326>:  movl   0x4134a4, %eax
init[0x40242b] <+331>:  cmpl   $0x4134a8, %ebx           ; imm = 0x4134A8
init[0x402431] <+337>:  je     0x4024aa                  ; <+458>
init[0x402433] <+339>:  movl   0x4(%ebx), %eax
init[0x402436] <+342>:  andl   $-0x4, %eax
init[0x402439] <+345>:  movl   %eax, %edx
init[0x40243b] <+347>:  subl   %esi, %edx
init[0x40243d] <+349>:  cmpl   $0xf, %edx
init[0x402440] <+352>:  jg     0x4027c0                  ; <+1248>
init[0x402446] <+358>:  testl  %edx, %edx
init[0x402448] <+360>:  movl   $0x4134a8, 0x4134b4       ; imm = 0x4134A8
init[0x402452] <+370>:  movl   $0x4134a8, 0x4134b0       ; imm = 0x4134A8
init[0x40245c] <+380>:  jns    0x4025e0                  ; <+768>
init[0x402462] <+386>:  cmpl   $0x1ff, %eax              ; imm = 0x1FF
init[0x402467] <+391>:  ja     0x402890                  ; <+1456>
init[0x40246d] <+397>:  shrl   $0x3, %eax
init[0x402470] <+400>:  movl   %eax, %ecx
init[0x402472] <+402>:  movl   %eax, %edx
init[0x402474] <+404>:  movl   $0x1, %eax
init[0x402479] <+409>:  sarl   $0x2, %ecx
init[0x40247c] <+412>:  addl   $0x1, %edx
init[0x40247f] <+415>:  shll   %cl, %eax
init[0x402481] <+417>:  orl    0x4134a4, %eax
init[0x402487] <+423>:  movl   0x4134a0(,%edx,8), %ecx
init[0x40248e] <+430>:  leal   0x413498(,%edx,8), %edi
init[0x402495] <+437>:  movl   %ecx, 0x8(%ebx)
init[0x402498] <+440>:  movl   %edi, 0xc(%ebx)
init[0x40249b] <+443>:  movl   %eax, 0x4134a4
init[0x4024a0] <+448>:  movl   %ebx, 0x4134a0(,%edx,8)
init[0x4024a7] <+455>:  movl   %ebx, 0xc(%ecx)
init[0x4024aa] <+458>:  movl   %ebp, %ecx
init[0x4024ac] <+460>:  movl   $0x1, %edx
init[0x4024b1] <+465>:  sarl   $0x2, %ecx
init[0x4024b4] <+468>:  movl   %edx, %edi
init[0x4024b6] <+470>:  shll   %cl, %edi
init[0x4024b8] <+472>:  cmpl   %eax, %edi
init[0x4024ba] <+474>:  ja     0x402580                  ; <+672>
init[0x4024c0] <+480>:  testl  %eax, %edi
init[0x4024c2] <+482>:  jne    0x4024e9                  ; <+521>
init[0x4024c4] <+484>:  movl   %ebp, %edx
init[0x4024c6] <+486>:  addl   %edi, %edi
init[0x4024c8] <+488>:  andl   $-0x4, %edx
init[0x4024cb] <+491>:  testl  %eax, %edi
init[0x4024cd] <+493>:  leal   0x4(%edx), %ebp
init[0x4024d0] <+496>:  jne    0x4024e9                  ; <+521>
init[0x4024d2] <+498>:  leal   (%esi), %esi
init[0x4024d9] <+505>:  leal   (%edi), %edi
init[0x4024e0] <+512>:  addl   %edi, %edi
init[0x4024e2] <+514>:  addl   $0x4, %ebp
init[0x4024e5] <+517>:  testl  %eax, %edi
init[0x4024e7] <+519>:  je     0x4024e0                  ; <+512>
init[0x4024e9] <+521>:  movl   %edi, 0x4(%esp)
init[0x4024ed] <+525>:  leal   0x4134a0(,%ebp,8), %eax
init[0x4024f4] <+532>:  movl   %ebp, %edi
init[0x4024f6] <+534>:  movl   %eax, 0x8(%esp)
init[0x4024fa] <+538>:  movl   %eax, %ecx
init[0x4024fc] <+540>:  movl   0xc(%ecx), %ebx
init[0x4024ff] <+543>:  cmpl   %ebx, %ecx
init[0x402501] <+545>:  jne    0x402523                  ; <+579>
init[0x402503] <+547>:  jmp    0x4027f0                  ; <+1296>
init[0x402508] <+552>:  nop
init[0x402509] <+553>:  leal   (%esi), %esi
init[0x402510] <+560>:  testl  %edx, %edx
init[0x402512] <+562>:  jns    0x402870                  ; <+1424>
init[0x402518] <+568>:  movl   0xc(%ebx), %ebx
init[0x40251b] <+571>:  cmpl   %ebx, %ecx
init[0x40251d] <+573>:  je     0x4027f0                  ; <+1296>
init[0x402523] <+579>:  movl   0x4(%ebx), %eax
init[0x402526] <+582>:  andl   $-0x4, %eax
init[0x402529] <+585>:  movl   %eax, %edx
init[0x40252b] <+587>:  subl   %esi, %edx
init[0x40252d] <+589>:  cmpl   $0xf, %edx
init[0x402530] <+592>:  jle    0x402510                  ; <+560>
init[0x402532] <+594>:  leal   (%ebx,%esi), %ecx
init[0x402535] <+597>:  orl    $0x1, %esi
init[0x402538] <+600>:  movl   0x8(%ebx), %edi
init[0x40253b] <+603>:  movl   %esi, 0x4(%ebx)
init[0x40253e] <+606>:  movl   0xc(%ebx), %esi
init[0x402541] <+609>:  movl   %esi, 0xc(%edi)
init[0x402544] <+612>:  movl   %edi, 0x8(%esi)
init[0x402547] <+615>:  movl   %edx, %esi
init[0x402549] <+617>:  movl   %ecx, 0x4134b4
init[0x40254f] <+623>:  movl   %ecx, 0x4134b0
init[0x402555] <+629>:  orl    $0x1, %esi
init[0x402558] <+632>:  movl   $0x4134a8, 0xc(%ecx)      ; imm = 0x4134A8
init[0x40255f] <+639>:  movl   $0x4134a8, 0x8(%ecx)      ; imm = 0x4134A8
init[0x402566] <+646>:  movl   %esi, 0x4(%ecx)
init[0x402569] <+649>:  movl   %edx, (%ebx,%eax)
init[0x40256c] <+652>:  jmp    0x40234a                  ; <+106>
init[0x402571] <+657>:  jmp    0x402580                  ; <+672>
init[0x402573] <+659>:  nop
init[0x402574] <+660>:  nop
init[0x402575] <+661>:  nop
init[0x402576] <+662>:  nop
init[0x402577] <+663>:  nop
init[0x402578] <+664>:  nop
init[0x402579] <+665>:  nop
init[0x40257a] <+666>:  nop
init[0x40257b] <+667>:  nop
init[0x40257c] <+668>:  nop
init[0x40257d] <+669>:  nop
init[0x40257e] <+670>:  nop
init[0x40257f] <+671>:  nop
init[0x402580] <+672>:  movl   0x4134a8, %ebx
init[0x402586] <+678>:  movl   0x4(%ebx), %ecx
init[0x402589] <+681>:  andl   $-0x4, %ecx
init[0x40258c] <+684>:  movl   %ecx, %eax
init[0x40258e] <+686>:  subl   %esi, %eax
init[0x402590] <+688>:  cmpl   $0xf, %eax
init[0x402593] <+691>:  jle    0x402610                  ; <+816>
init[0x402595] <+693>:  cmpl   %esi, %ecx
init[0x402597] <+695>:  jb     0x402610                  ; <+816>
init[0x402599] <+697>:  movl   %esi, %edx
init[0x40259b] <+699>:  orl    $0x1, %eax
init[0x40259e] <+702>:  addl   %ebx, %esi
init[0x4025a0] <+704>:  orl    $0x1, %edx
init[0x4025a3] <+707>:  movl   %edx, 0x4(%ebx)
init[0x4025a6] <+710>:  movl   %esi, 0x4134a8
init[0x4025ac] <+716>:  movl   %eax, 0x4(%esi)
init[0x4025af] <+719>:  jmp    0x40234a                  ; <+106>
init[0x4025b4] <+724>:  leal   (%esi), %esi
init[0x4025ba] <+730>:  leal   (%edi), %edi
init[0x4025c0] <+736>:  movl   %esi, %eax
init[0x4025c2] <+738>:  shrl   $0x6, %eax
init[0x4025c5] <+741>:  leal   0x39(%eax), %ebp
init[0x4025c8] <+744>:  leal   0x38(%eax), %edi
init[0x4025cb] <+747>:  leal   (,%ebp,8), %eax
init[0x4025d2] <+754>:  jmp    0x4023df                  ; <+255>
init[0x4025d7] <+759>:  movl   %esi, %esi
init[0x4025d9] <+761>:  leal   (%edi), %edi
init[0x4025e0] <+768>:  orl    $0x1, 0x4(%ebx,%eax)
init[0x4025e5] <+773>:  jmp    0x40234a                  ; <+106>
init[0x4025ea] <+778>:  leal   (%esi), %esi
init[0x4025f0] <+784>:  movl   0x30(%esp), %eax
init[0x4025f4] <+788>:  movl   $0xc, (%eax)
init[0x4025fa] <+794>:  addl   $0x1c, %esp
init[0x4025fd] <+797>:  xorl   %eax, %eax
init[0x4025ff] <+799>:  popl   %ebx
init[0x402600] <+800>:  popl   %esi
init[0x402601] <+801>:  popl   %edi
init[0x402602] <+802>:  popl   %ebp
init[0x402603] <+803>:  retl
init[0x402604] <+804>:  leal   (%esi), %esi
init[0x40260a] <+810>:  leal   (%edi), %edi
init[0x402610] <+816>:  movl   0x414050, %eax
init[0x402615] <+821>:  movl   %ecx, 0x4(%esp)
init[0x402619] <+825>:  addl   %esi, %eax
init[0x40261b] <+827>:  leal   0x100f(%eax), %edi
init[0x402621] <+833>:  addl   $0x10, %eax
init[0x402624] <+836>:  andl   $0xfffff000, %edi         ; imm = 0xFFFFF000
init[0x40262a] <+842>:  cmpl   $-0x1, 0x413480
init[0x402631] <+849>:  cmovnel %edi, %eax

I have not yet investigated this - but one possible theory is that since my cross-compiler is built for i686, its own libgcc contains the CMOV.

So, the tl;dr of this is that in order to boot on a Pentium, we'd need an entire toolchain + kernel + userspace built for i586 instead of i686. This is probably not worth the cost, since the Pentium Pro was first introduced in 1995

@egranata
Copy link
Owner Author

On a side note, during the teardown of init due to the "invalid opcode" error, we get a page fault:

[2235] kernel/src/mm/pagefault.cpp:124 page fault, vaddr = 0x8, physical counterpart <nullptr>
[2240] kernel/src/process/dumperror.cpp:26 irq: 14 error code: 0
[2275] kernel/src/process/dumperror.cpp:44 register cr0: 0xE0010031
[2280] kernel/src/process/dumperror.cpp:45 register cr2: 0x8
[2285] kernel/src/process/dumperror.cpp:46 register cr3: 0x80B000
[2290] kernel/src/process/dumperror.cpp:47 register cr4: 0x14
[2325] kernel/src/process/dumperror.cpp:49 register eax: 0x4
[2330] kernel/src/process/dumperror.cpp:50 register ebx: 0xC8EFD733
[2335] kernel/src/process/dumperror.cpp:51 register ecx: 0x20
[2340] kernel/src/process/dumperror.cpp:52 register edx: 0xA
[2375] kernel/src/process/dumperror.cpp:54 register ebp: 0xC8EFD6FB
[2380] kernel/src/process/dumperror.cpp:55 register esi: 0x0
[2385] kernel/src/process/dumperror.cpp:56 register edi: 0xC016D820
[2390] kernel/src/process/dumperror.cpp:57 register esp: 0xC8EFD6C3
[2425] kernel/src/process/dumperror.cpp:61 flags = 0x10296, x87 status = 0x0
[2430] kernel/src/process/dumperror.cpp:62 segments: cs: 0x8, ds: 0x10, es: 0x10, fs: 0x10, gs: 0x10, ss: 0x10
[2555] kernel/src/process/dumperror.cpp:72 eip = 0xC0105160
[2700] kernel/src/process/dumperror.cpp:84     0xC010BFEB
[2735] kernel/src/process/dumperror.cpp:84     0xC011A64B
[2765] kernel/src/process/dumperror.cpp:84     0xC0107762
[2800] kernel/src/process/dumperror.cpp:84     0xC01216A7


(lldb) dis -a 0xC0105160
kernel`Backtrace::backtrace:
kernel[0xc0105110] <+0>:   pushl  %ebp
kernel[0xc0105111] <+1>:   movl   %esp, %ebp
kernel[0xc0105113] <+3>:   pushl  %edi
kernel[0xc0105114] <+4>:   pushl  %esi
kernel[0xc0105115] <+5>:   pushl  %ebx
kernel[0xc0105116] <+6>:   subl   $0xc, %esp
kernel[0xc0105119] <+9>:   calll  0xc0116af0                ; VirtualPageManager::get()
kernel[0xc010511e] <+14>:  movl   %eax, %edi
kernel[0xc0105120] <+16>:  movl   0x8(%ebp), %eax
kernel[0xc0105123] <+19>:  movl   0x20(%eax), %eax
kernel[0xc0105126] <+22>:  testl  %eax, %eax
kernel[0xc0105128] <+24>:  je     0xc0105170                ; <+96>
kernel[0xc010512a] <+26>:  movl   0x10(%ebp), %ecx
kernel[0xc010512d] <+29>:  testl  %ecx, %ecx
kernel[0xc010512f] <+31>:  je     0xc0105170                ; <+96>
kernel[0xc0105131] <+33>:  xorl   %esi, %esi
kernel[0xc0105133] <+35>:  jmp    0xc010515d                ; <+77>
kernel[0xc0105135] <+37>:  leal   (%esi), %esi
kernel[0xc0105139] <+41>:  leal   (%edi), %edi
kernel[0xc0105140] <+48>:  pushl  %eax
kernel[0xc0105141] <+49>:  pushl  $0x0
kernel[0xc0105143] <+51>:  pushl  %ebx
kernel[0xc0105144] <+52>:  pushl  %edi
kernel[0xc0105145] <+53>:  calll  0xc0116070                ; VirtualPageManager::mapped(unsigned long, VirtualPageManager::map_options_t*)
kernel[0xc010514a] <+58>:  addl   $0x10, %esp
kernel[0xc010514d] <+61>:  testb  %al, %al
kernel[0xc010514f] <+63>:  je     0xc0105170                ; <+96>
kernel[0xc0105151] <+65>:  incl   %esi
kernel[0xc0105152] <+66>:  movl   %ebx, %eax
kernel[0xc0105154] <+68>:  testl  %ebx, %ebx
kernel[0xc0105156] <+70>:  je     0xc0105170                ; <+96>
kernel[0xc0105158] <+72>:  cmpl   %esi, 0x10(%ebp)
kernel[0xc010515b] <+75>:  jbe    0xc0105170                ; <+96>
kernel[0xc010515d] <+77>:  subl   $0xc, %esp
kernel[0xc0105160] <+80>:  movl   0x4(%eax), %edx <<< THIS RIGHT HERE - eax: 0x4, PF at 0x8
kernel[0xc0105163] <+83>:  movl   (%eax), %ebx
kernel[0xc0105165] <+85>:  pushl  %edx
kernel[0xc0105166] <+86>:  calll  *0xc(%ebp)
kernel[0xc0105169] <+89>:  addl   $0x10, %esp
kernel[0xc010516c] <+92>:  testb  %al, %al
kernel[0xc010516e] <+94>:  jne    0xc0105140                ; <+48>
kernel[0xc0105170] <+96>:  leal   -0xc(%ebp), %esp
kernel[0xc0105173] <+99>:  popl   %ebx
kernel[0xc0105174] <+100>: popl   %esi
kernel[0xc0105175] <+101>: popl   %edi
kernel[0xc0105176] <+102>: popl   %ebp
kernel[0xc0105177] <+103>: retl

@egranata
Copy link
Owner Author

If I had to guess, the sequence

kernel[0xc0105160] <+80>:  movl   0x4(%eax), %edx
kernel[0xc0105163] <+83>:  movl   (%eax), %ebx

corresponds to:

auto eip = frame[1];
auto fp = frame[0];

which makes me think that we want/need to validate "frame" as a "valid and mapped address" before trying to read from it

egranata added a commit that referenced this issue Sep 30, 2018
In trying to get #63 to work, I ran into two issues:

- the earlyboot "invalid opcode" handler was using a mismatched format string;
- the backtrace API must check that the frame pointer is valid before trying to dereference it
@egranata
Copy link
Owner Author

This issue would require reworking the toolchain to support the i586 as its target instead of i686 - it is probably not worth pursuing. Closing for now, and will open a new file if there's a reason why Pentium support is critical

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kernel panic A kind of bug that shows us as the kernel panicking
Projects
None yet
Development

No branches or pull requests

1 participant