OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:12 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: I am having trouble with booting a simple kernel in qemu.
PostPosted: Fri Nov 11, 2022 10:41 pm 
Offline

Joined: Fri Nov 11, 2022 10:28 pm
Posts: 10
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!


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 6:57 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
How many sectors is your kernel?


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 10:55 pm 
Offline

Joined: Fri Nov 11, 2022 10:28 pm
Posts: 10
Octocontrabass wrote:

There is the boot sector (1) and the kernel sector (2)


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 11:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
I'm pretty sure your kernel is bigger than one sector.

How big is one sector? How big is your kernel?


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 11:24 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
As OP committed their binaries in git, it looks like their kernel is 8.32KiB, or 17 sectors.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 11:30 pm 
Offline

Joined: Fri Nov 11, 2022 10:28 pm
Posts: 10
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


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 11:31 pm 
Offline

Joined: Fri Nov 11, 2022 10:28 pm
Posts: 10
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.


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Sun Nov 13, 2022 11:54 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: I am having trouble with booting a simple kernel in qemu
PostPosted: Mon Nov 14, 2022 12:25 am 
Offline

Joined: Fri Nov 11, 2022 10:28 pm
Posts: 10
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 71 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group