Booting a basic OS

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
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Booting a basic OS

Post by gsingh2011 »

I'm using the exact code from http://wiki.osdev.org/Bare_Bones. I made the floppy.img file and now I'm trying to boot it. I tried Bochs, but when I ran it, the boot screen kept repeating over and over. Then I tried QEMU for windows, and I couldn't figure out how to boot it from there. Then I tried Virtual Box, and that gave me an unhandled win32 exception and asked me to debug.

What's wrong?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Booting a basic OS

Post by neon »

Hello,

In your bochs configuation file, add the following line:

Code: Select all

log:         os.log
Run it again using Bochs and it should output a log file, os.log. Post the last few lines of that log (registers, any errors or PANICs here.)

I personally suspect either GRUB is not installed correctly or the floppy disk image is not being correctly copied over. I cannot troubleshoot further however until I see the log.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: Booting a basic OS

Post by gsingh2011 »

Sorry, I really didn't know which information you needed, so I just uploaded the whole file so you can see what you need.

os.log

Thanks for the help.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Booting a basic OS

Post by neon »

Here is the important info from the log:

Code: Select all

00008023335i[BIOS ] Booting from 0000:7c00
00008334848i[FDD  ] partial read() on floppy image returns 374/512
00008357581i[FDD  ] read() on floppy image returns 0

...

00025568511i[FDD  ] read() on floppy image returns 0
00025591244i[FDD  ] read() on floppy image returns 0
00025625159i[FDD  ] read() on floppy image returns 0
00025651077e[CPU0 ] check_cs(0x0008): attempt to jump to long mode without enabling EFER.LMA !
00025651077e[CPU0 ] check_cs(0x0008): conforming code seg descriptor dpl > cpl, dpl=3, cpl=0
00025651077i[CPU0 ] CPU is in protected mode (active)
00025651077i[CPU0 ] CS.d_b = 16 bit
00025651077i[CPU0 ] SS.d_b = 16 bit
00025651077i[CPU0 ] EFER   = 0x00000000
00025651077i[CPU0 ] | RAX=0000000060000011  RBX=0000000000000001
00025651077i[CPU0 ] | RCX=0000000000000501  RDX=0000000000000000
00025651077i[CPU0 ] | RSP=0000000000001fec  RBP=0000000000001ff0
00025651077i[CPU0 ] | RSI=00000000ffff8116  RDI=00000000000881f0
00025651077i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00025651077i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00025651077i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00025651077i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00025651077i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00025651077i[CPU0 ] | SEG selector     base    limit G D
00025651077i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00025651077i[CPU0 ] |  CS:0000( 0004| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  ES:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00025651077i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00025651077i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00025651077i[CPU0 ] | RIP=0000000000008789 (0000000000008789)
00025651077i[CPU0 ] | CR0=0x60000011 CR1=0x0 CR2=0x0000000000000000
00025651077i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00025651077i[CPU0 ] >> jmp far 0008:00008791 : 66EA918700000800
00025651077e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: Booting a basic OS

Post by gsingh2011 »

Yea... I have no clue what that means. It's my first time doing this...
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Booting a basic OS

Post by neon »

gsingh2011 wrote:Yea... I have no clue what that means. It's my first time doing this...
How much experience do you have with assembly language? If you know it (at least the basics) most of the log should be fairly easy to understand.

However I do not have much experience with GRUB so cannot assist you in setting it up. Perhaps another member here can help you with that.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Re: Booting a basic OS

Post by gsingh2011 »

I do not have a very good understanding at assembly, although I attempted learning once. Thank you for all your help so far neon! Can anyone else identify the problem?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Booting a basic OS

Post by neon »

I suspect that it is failing inside of GRUB. I know it is booting into the boot loader (based upon that eip is not inside of the bios and above 0x7c00). Perhaps GRUB is not configured correctly? Or the floppy image is not built correctly?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
AndrewAPrice
Member
Member
Posts: 2306
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Booting a basic OS

Post by AndrewAPrice »

Code: Select all

00025651077i[CPU0 ] >> jmp far 0008:00008791 : 66EA918700000800
Is the hint (it's a disassembly of the instruction that caused the fault that caused the double fault that caused the triple fault). You're trying to far jump to a bad segment. Check your linker script to make sure your program starts at 1MB.
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Booting a basic OS

Post by Combuster »

Also
00025625159i[FDD ] read() on floppy image returns 0
Bochs is complaining to you about your floppy image being broken (it should be exactly 1.44Mb in size!)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Booting a basic OS

Post by Love4Boobies »

gsingh2011 wrote:Then I tried QEMU for windows, and I couldn't figure out how to boot it from there.
Look for bios.bin. It should either be in the sub-directory pc-bios, or in the main directory, depending on where you got the package from (as I'm assuming you haven't compiled it yourself). Then, try the following command:

Code: Select all

qemu -fda floppy.img -boot a -L pc-bios
Replace pc-bios with the path to bios.bin. If it's in the current directory, write "-L ." instead.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply