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

Bug: BIOS boot looping #1258

Open
randomtwdude opened this issue Aug 14, 2024 · 0 comments
Open

Bug: BIOS boot looping #1258

randomtwdude opened this issue Aug 14, 2024 · 0 comments
Labels
medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable)

Comments

@randomtwdude
Copy link

Contact Details

No response

What happened?

Giving a printf("hello world") APE (cosmocc -o hello hello.c) to qemu-system-x86_64 causes boot loops. Upon closer inspection, the bootloader (pc in ape.S) seems to be loading from the start of the file instead of where the code actually is (0x10000 into the file), causing it to try to execute the ELF header at 0x4e0 and fail.

Using a debugger to set the al, cl, dh, si, eflags registers and make it start loading from 0x10000 makes it go further along, failing after transition to long mode in __get_virtual.

   0x000000000040107e <+109>:	mov    $0x1000,%ecx
   0x0000000000401083 <+114>:	xor    %eax,%eax
   0x0000000000401085 <+116>:	rep stos %al,%es:(%rdi)  // dies here

bochs log at this failure:

00026266026e[CPU0  ] interrupt(long mode): vector must be within IDT table limits, IDT.limit = 0x0
00026266026e[CPU0  ] interrupt(long mode): vector must be within IDT table limits, IDT.limit = 0x0
00026266026i[CPU0  ] CPU is in long mode (active)
00026266026i[CPU0  ] CS.mode = 64 bit
00026266026i[CPU0  ] SS.mode = 64 bit
00026266026i[CPU0  ] EFER   = 0x00000d01
00026266026i[CPU0  ] | RAX=0000000000000000  RBX=ffff80000007c018
00026266026i[CPU0  ] | RCX=0000000000001000  RDX=00000000fffc0000
00026266026i[CPU0  ] | RSP=000000000007fe90  RBP=000000000007fed0
00026266026i[CPU0  ] | RSI=00000000fffc0000  RDI=ffff8000fffc0000
00026266026i[CPU0  ] |  R8=0000000000000002   R9=0000000000000002
00026266026i[CPU0  ] | R10=0000000000000518  R11=0000000000000002
00026266026i[CPU0  ] | R12=ffff8000fffc0000  R13=000000000000001e
00026266026i[CPU0  ] | R14=0000000000000001  R15=ffff800000000000
00026266026i[CPU0  ] | IOPL=0 ID vip vif ac vm RF nt of df if tf sf ZF af PF cf
00026266026i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00026266026i[CPU0  ] |  CS:0028( 0005| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  DS:0030( 0006| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  SS:0030( 0006| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  ES:0030( 0006| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  FS:0030( 0006| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  GS:0030( 0006| 0|  0) 00000000 ffffffff 1 0
00026266026i[CPU0  ] |  MSR_FS_BASE:0000000000000000
00026266026i[CPU0  ] |  MSR_GS_BASE:0000000000000000
00026266026i[CPU0  ] | RIP=ffff800000101085 (ffff800000101085)
00026266026i[CPU0  ] | CR0=0xe0000013 CR2=0xffff8000fffc0000
00026266026i[CPU0  ] | CR3=0x000000000007e000 CR4=0x000002a0
00026266026e[CPU0  ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting

Version

cosmocc (GCC) 14.1.0

What operating system are you seeing the problem on?

BIOS

Relevant log output

No response

@randomtwdude randomtwdude added the medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable) label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium severity Used to report medium severity bugs (e.g. Malfunctioning Features but still useable)
Projects
None yet
Development

No branches or pull requests

1 participant