littlekernel / lk

LK embedded kernel
MIT License
3.14k stars 615 forks source link

lk can't run on AMD Dell Ryzen7 #202

Open eastmoutain opened 6 years ago

eastmoutain commented 6 years ago

hi I managed flashing LK kernel and creating a bootable USB device driver, it can boot on any Intel computer, but failed on AMD Dell Ryzen7.

Here is experiment procedures:

  1. run ./script/do-qemux86 -6 this will generate lk.elf
  2. create an ISO image a) create a directory tree looks like bellow. note '^' stands for space key isofile |---boot |^^^|---grub |^^^|^^^|--- b) copy your lk.elf(find it in your lk build directory) into isofile/boot directory, and create a grub.cfg file under grub diretory. c) fill grub.cfg with the following lines set timeout=0 set default=0 menuentry "little kernel" { multiboot /boot/lk.elf boot } d) then your isofile directory tree looks like: isofile |---boot |^^^|---grub |^^^|^^^|---grub.cfg |^^^|---lk.elf run grub-mkrescue -o lk.iso isofile, then lk.iso will be created.
  3. create a bootable USB device driver run sudo dd if=isofile.iso of=/dev/sdb. Assume your USB device appears as "/dev/sdb" under "/dev" directory.
  4. boot computer Inert the bootable USB device into computer's USB slot, and boot the computer in legacy mode(configured in BIOS) from USB device.

On any recently Intel processor Computer, it works fine, but failed to boot up on AMD processor Computer.

I added the following debug info in "arch/x86/64/start.S" to print "OK" and then halt the processor movl $0x2f4b2f4f, 0xb8000 hlt

It should print "OK" on screen if I insert the snippet at the point before enabling Paging, but won't print after paging is enabled.

It's reasonable that after paging is enabled, CPU should fed with virtual address, so I add kernel offset 0XFFFFFFFF80000000 to 0xb8000 in order to print message on screen. mov $0XFFFFFFFF8000b8000, %rax movl $0x2f4b2f4f, (%rax) hlt

It looks perfect and should work now, however it still can't print the massage.

So am not sure what's going on with LK or AMD processor, I have no idea about that!!!

travisg commented 6 years ago

Ah I'm pretty sure I know what the problem is. I fixed it over in the magenta fork. AMD machines are more picky about unused bits in the page tables and I believe the initial 64bit page table that start.S sets up has some extra unused bits. I'll see about rolling a fix back.

On Tue, Aug 29, 2017 at 12:28 AM, east moutain notifications@github.com wrote:

hi I managed flashing LK kernel and creating a bootable USB device driver, it can boot on any Intel computer, but failed on AMD Dell Ryzen7.

Here is experiment procedures:

  1. run ./script/do-qemux86 -6 this will generate lk.elf
  2. create an ISO image a) create a directory tree looks like bellow. note '^' stands for space key isofile |---boot |^^^|---grub |^^^|^^^|--- b) copy your lk.elf(find it in your lk build directory) into isofile/boot directory, and create a grub.cfg file under grub diretory. c) fill grub.cfg with the following lines set timeout=0 set default=0 menuentry "little kernel" { multiboot /boot/lk.elf boot } d) then your isofile directory tree looks like: isofile |---boot |^^^|---grub |^^^|^^^|---grub.cfg |^^^|---lk.elf run grub-mkrescue -o lk.iso isofile, then lk.iso will be created.
  3. create a bootable USB device driver run sudo dd if=isofile.iso of=/dev/sdb. Assume your USB device appears as "/dev/sdb" under "/dev" directory.
  4. boot computer Inert the bootable USB device into computer's USB slot, and boot the computer in legacy mode(configured in BIOS) from USB device.

On any recently Intel processor Computer, it works fine, but failed to boot up on AMD processor Computer.

I added the following debug info in "arch/x86/64/start.S" to print "OK" and then halt the processor movl $0x2f4b2f4f, 0xb8000 hlt

It should print "OK" on screen if I insert the snippet at the point before enabling Paging, but won't print after paging is enabled.

It's reasonable that after paging is enabled, CPU should fed with virtual address, so I add kernel offset 0XFFFFFFFF80000000 to 0xb8000 in order to print message on screen. mov $0XFFFFFFFF8000b8000, %rax movl $0x2f4b2f4f, (%rax) hlt

It looks perfect and should work now, however it still can't print the massage.

So am not sure what's going on with LK or AMD processor, I have no idea about that!!!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/littlekernel/lk/issues/202, or mute the thread https://github.com/notifications/unsubscribe-auth/AAF9rAeCAindI1CG_h7LSJmNLAAM47dEks5sc72ZgaJpZM4PFfAk .

eastmoutain commented 6 years ago

thank you very much, i fixed the issue after comparing start.S file with magenta.