I am having trouble with booting a simple kernel in qemu.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
lochyj
Posts: 10
Joined: Fri Nov 11, 2022 10:28 pm

I am having trouble with booting a simple kernel in qemu.

Post by lochyj »

The problem is that qemu goes into a boot loop and only loads my boot-loader before it fails and restarts instantly.

I think the problem is with the length of my kernel or the location of my kernel main function in memory. I am completely stumped on this.

The source code: https://github.com/lochyj/OS

I am running Arch in WSL on windows 10 to compile and run it.

i have a previous version that works untill i include certain header files in the kernel.c file. But i tried removing the files from the kernel.c file on the current version and it doesnt work.

The kernel is an adapted version of https://dev.to/frosnerd/series/9585

Running the image file: qemu-system-i386 -fda ./out/image/image.img

There is extra info in the github repo

I am relatively a beginner at OS dev and i am just trying it out for fun and as a project to put on my github.

Thanks in advance!

If you need any extra info just ask!
lochyj
Posts: 10
Joined: Fri Nov 11, 2022 10:28 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by lochyj »

There is the boot sector (1) and the kernel sector (2)
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by Octocontrabass »

I'm pretty sure your kernel is bigger than one sector.

How big is one sector? How big is your kernel?
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: I am having trouble with booting a simple kernel in qemu

Post by klange »

As OP committed their binaries in git, it looks like their kernel is 8.32KiB, or 17 sectors.
lochyj
Posts: 10
Joined: Fri Nov 11, 2022 10:28 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by lochyj »

Ah, sorry.
Although i don't think this is the problem as i load all sectors after sector 1 as the kernel and into memory.

In disk_load at https://github.com/lochyj/OS/blob/main/boot/disk.asm
lochyj
Posts: 10
Joined: Fri Nov 11, 2022 10:28 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by lochyj »

Here is the cpu dump ( i think that is what its called ) from QEMU when i run the kernel and the bootloader

check_exception old: 0xffffffff new 0xd
1: v=0d e=0032 i=0 cpl=0 IP=0008:0000efdb pc=0000efdb SP=0010:0008fff4 env->regs[R_EAX]=00000010
EAX=00000010 EBX=00007d63 ECX=00000000 EDX=00000200
ESI=00000000 EDI=00000000 EBP=00090000 ESP=0008fff4
EIP=0000efdb EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00007ce6 00000017
IDT= 00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000010 CCD=00000010 CCO=ADDB
EFER=0000000000000000
check_exception old: 0xd new 0xd
2: v=08 e=0000 i=0 cpl=0 IP=0008:0000efdb pc=0000efdb SP=0010:0008fff4 env->regs[R_EAX]=00000010
EAX=00000010 EBX=00007d63 ECX=00000000 EDX=00000200
ESI=00000000 EDI=00000000 EBP=00090000 ESP=0008fff4
EIP=0000efdb EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 00007ce6 00000017
IDT= 00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000010 CCD=00000010 CCO=ADDB
EFER=0000000000000000
check_exception old: 0x8 new 0xd


I also think i need to use a debugger for the kernel and i have no idea about how to run QEMU with GDB, so any help with that is also appreciated.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by Octocontrabass »

lochyj wrote:i load all sectors after sector 1
No you don't. You load two sectors after sector 1. Two sectors is 1024 bytes. Since your kernel is bigger than that, you aren't loading the entire kernel.
lochyj wrote:I also think i need to use a debugger for the kernel and i have no idea about how to run QEMU with GDB, so any help with that is also appreciated.
The official instructions are a good start. If GDB refuses to connect to QEMU, try starting GDB with no file loaded, connect to QEMU, and then load your kernel file. This works for me running QEMU in Windows and GDB in WSL.
lochyj
Posts: 10
Joined: Fri Nov 11, 2022 10:28 pm

Re: I am having trouble with booting a simple kernel in qemu

Post by lochyj »

Ok thank you, i will work on loading more than 2 sectors and ill try to setup GDB.
Thanks for the help.

EDIT: It now boots properly, i am now working on fixing the things i broke trying to fix this
Post Reply