Sign in to follow this  

Using bochs

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I'm learning something about writing an OS from here, and I having some problems. I've got up to and including printing to the screen compiled. First of all, I'm using linux (Fedora Core 3). I can get an initial kernel.bin file compiled, but the problem is, I don't know how to properly format the floppy disk to get it to run. Second of all, I don't know how to make bochs run it. I've been looking at the bochs site for some time, but I'm nowhere closer.
00000000000i[     ] lt_dlhandle is 0x8cb1488
00000000000i[PLGIN] loaded plugin libbx_x.la
00000000000i[     ] installing x module as the Bochs GUI
00000000000i[     ] Bochs x86 Emulator 2.2.pre4
00000000000i[     ]   Build from CVS snapshot on May 15th, 2005
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   fpu support: yes
00000000000i[     ]   paging support: yes, tlb enabled: yes
00000000000i[     ]   mmx support: yes
00000000000i[     ]   sse support: 1
00000000000i[     ]   v8086 mode support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: no
00000000000i[     ]   SEP support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Host Asm support: yes
00000000000i[     ]   Fast function calls: yes
00000000000e[     ] No romimage to load. Is your bochsrc file loaded/valid ?
00000000000i[MEM0 ] allocated memory at 0xf4d8e008. after alignment, vector=0xf4d8f000
00000000000i[MEM0 ] 32.00MB
00000000000p[MEM0 ] >>PANIC<< ROM: System BIOS image undefined
00000000000i[SYS  ] Last time is 0
00000000000i[     ] restoring default signal behavior
========================================================================
Bochs is exiting with the following message:
[MEM0 ] ROM: System BIOS image undefined
========================================================================
00000000000i[CTRL ] quit_sim called with exit code 1

This is what I get when I try to run it. The disk is in, and I've copied the 'kernel.bin' file onto the disk, and it is the only thing on the disk. I haven't changed any of the options, and I assume that it is trying to run from the disk, because in the 'Disk options', the only boot drive defined is #1 and that is labelled as "floppy". Does anyone know anything that will help?

Share this post


Link to post
Share on other sites
Bochs needs the path to the system BIOS ROM and VGA BIOS ROM. In the Bochs folder, look out for files like BIOS-bochs-latest and VGABIOS-lgpl-latest or similar.

In your bochs configuration set these paths.

This will result in two lines like this:

romimage: file=C:\Programme\Bochs-2.1.1\BIOS-bochs-latest, address=0xf0000
vgaromimage: C:\Programme\Bochs-2.1.1\VGABIOS-elpin-2.40


You should write your configuration file to disk, i.e. into file bochsrc, and then start bochs via:
> bochs -f bochsrc -q

Share this post


Link to post
Share on other sites
Ok - firstly to get it to run your kernel.bin image, you can't simply copy it to a floppy disc (or image).

You are going to have to install some sort of bootloader - then do anything else the bootloader needs to run your kernel bin.

In the case of syslinux, this is pretty easy, just run the syslinux (syslinux.exe on windows) installer program, giving it the name of the floppy image or raw device to use. This should be an already formatted, fat16 filesystem floppy image in one of the normal sizes.

To create a formatted fat16 floppy image, first create a blank file of the appropriate size, for example:


dd if=/dev/zero of=myfloppy.img bs=1k count=1440


Then make a fat filesystem on it

/sbin/mkfs.msdos myfloppy.img


Then you can syslinux it


syslinux myfloppy.img # this assumes the syslinux installer is in your path


You can *then* copy your kernel.bin on to the floppy as a normal file (either by loop-mounting it or using mtools)

When you boot the image, syslinux will probably try to load a kernel image called "linux". This will fail. So hold down shift and at the syslinux: prompt, type kernel.bin - it will then load that.

You can also create a syslinux.cfg file to tell it to load kernel.bin by default.

Mark

Share this post


Link to post
Share on other sites
Okay, I've followed the instructions from the above post.

I've created a blank file, to use as a disk image. I've formatted it as a disk with a FAT filesys as per above, and I've run syslinux on the image.

What I'm not getting is the connection between the disk image and:

Quote:

You can *then* copy your kernel.bin on to the floppy as a normal file (either by loop-mounting it or using mtools)


So, do I copy the image onto the floppy, using dd, thereby making an actual disk that can be booted from with bochs?

Or am I supposed to boot from the disk image and then load the kernel from the physical disk?

Could someone walk me through these steps?

Share this post


Link to post
Share on other sites
Either loop-mount it, or use mtools

If you loop-mount it, you will be able to see the contents of the floppy image as a normal directory (in this case /mnt/myfloppy)

to loop mount it, do something like


mkdir -p /mnt/myfloppy # create directory for mount-point
mount myfloppy.img /mnt/myfloppy -t msdos -o loop


Remember to unmount it again before you try to boot off the floppy in the emulator - having a process writing to the file while it's mounted could end in tears.

Mark

Share this post


Link to post
Share on other sites
Okay, but in that case, after I copy the files onto it, do I have to use 'dd' to copy it all back onto the physical disk to boot off it? Or in bochs, is there an option to use a disk image?

Share this post


Link to post
Share on other sites
- Start bochs
- Select edit options
- Select Disk options
- Select first floppy (floppy disk 0)
- Enter the filename of the disk image, i.e. the file that contains GRUB + kernel.bin and which was formatted as FAT disk (myfloppy.img)
- Select the typ of disk (1.44M) and select inserted
- Go to the main menu, and select "save options..."
- Save the options into a file called bochsrc

Bochs will use the disk image (containing GRUB and your kernel image) as virtual disk drive.

Share this post


Link to post
Share on other sites
Fantastic!!!

I've done all of that and it runs without immediately, but my only problem is that it was supposed to clear the screen and print out the general "Hello World" message, but it doesn't actually do anything. Also, on the console, I'm getting many "00000180000e[CLVGA] character height = 1, skipping text update" messages.

Here's the whole console text for bochs.

00000000000i[ ] lt_dlhandle is 0x8b6b4c8
00000000000i[PLGIN] loaded plugin libbx_x.la
00000000000i[ ] installing x module as the Bochs GUI
00000000000i[ ] Bochs x86 Emulator 2.2.pre4
00000000000i[ ] Build from CVS snapshot on May 15th, 2005
00000000000i[ ] System configuration
00000000000i[ ] processors: 1
00000000000i[ ] A20 line support: yes
00000000000i[ ] APIC support: yes
00000000000i[ ] CPU configuration
00000000000i[ ] level: 6
00000000000i[ ] fpu support: yes
00000000000i[ ] paging support: yes, tlb enabled: yes
00000000000i[ ] mmx support: yes
00000000000i[ ] sse support: 1
00000000000i[ ] v8086 mode support: yes
00000000000i[ ] 3dnow! support: no
00000000000i[ ] PAE support: yes
00000000000i[ ] PGE support: yes
00000000000i[ ] PSE support: yes
00000000000i[ ] x86-64 support: no
00000000000i[ ] SEP support: no
00000000000i[ ] Optimization configuration
00000000000i[ ] Guest2HostTLB support: yes
00000000000i[ ] RepeatSpeedups support: yes
00000000000i[ ] Icache support: yes
00000000000i[ ] Host Asm support: yes
00000000000i[ ] Fast function calls: yes
00000000000i[MEM0 ] allocated memory at 0xf4d8e008. after alignment, vector=0xf4d8f000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] rom at 0xf0000/65536 ('/usr/share/bochs/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/32768 ('/usr/share/bochs/VGABIOS-lgpl-latest')
00000000000i[APIC?] local apic in initializing
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[ ] lt_dlhandle is 0x8b77df0
00000000000i[PLGIN] loaded plugin libbx_unmapped.la
00000000000i[ ] lt_dlhandle is 0x8b782f0
00000000000i[PLGIN] loaded plugin libbx_biosdev.la
00000000000i[ ] lt_dlhandle is 0x8b788e0
00000000000i[PLGIN] loaded plugin libbx_cmos.la
00000000000i[ ] lt_dlhandle is 0x8b78e38
00000000000i[PLGIN] loaded plugin libbx_dma.la
00000000000i[ ] lt_dlhandle is 0x8b79480
00000000000i[PLGIN] loaded plugin libbx_pic.la
00000000000i[ ] lt_dlhandle is 0x8b79a00
00000000000i[PLGIN] loaded plugin libbx_vga.la
00000000000i[ ] lt_dlhandle is 0x8b79ec0
00000000000i[PLGIN] loaded plugin libbx_floppy.la
00000000000i[ ] lt_dlhandle is 0x8b7a6b0
00000000000i[PLGIN] loaded plugin libbx_harddrv.la
00000000000i[ ] lt_dlhandle is 0x8b80230
00000000000i[PLGIN] loaded plugin libbx_keyboard.la
00000000000i[ ] lt_dlhandle is 0x8b80398
00000000000i[PLGIN] loaded plugin libbx_serial.la
00000000000i[ ] lt_dlhandle is 0x8b813a8
00000000000i[PLGIN] loaded plugin libbx_parallel.la
00000000000i[ ] lt_dlhandle is 0x8b80908
00000000000i[PLGIN] loaded plugin libbx_extfpuirq.la
00000000000i[ ] lt_dlhandle is 0x8b81e48
00000000000i[PLGIN] loaded plugin libbx_gameport.la
00000000000i[ ] lt_dlhandle is 0x8b822b8
00000000000i[PLGIN] loaded plugin libbx_speaker.la
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Thu May 19 18:33:44 2005 (time0=1116491624)
00000000000i[DMA ] channel 4 used by cascade
00000000000i[DMA ] channel 2 used by Floppy Drive
00000000000i[FDD ] fd0: 'myfloppy.img' ro=0, h=2,t=80,spt=18
00000000000i[XGUI ] test_alloc_colors: 16 colors available out of 16 colors tried
00000000000i[XGUI ] font 8 wide x 16 high, display depth = 24
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=30000
00000000000i[CLVGA] CL-GD5430 ISA initialized
00000000000i[PLGIN] init_mem of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'serial' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'parallel' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'gameport' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'speaker' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD ] Using boot sequence floppy, none, none
00000000000i[HD ] Floppy boot signature check is enabled
00000000000i[PLGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD ] will paste characters every 1000 keyboard ticks
00000000000i[PLGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4
00000000000i[PLGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
00000000000i[PLGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[SPEAK] Open /dev/console successfully
00000000000i[PLGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLGIN] reset of 'speaker' plugin device by virtual method
00000000000i[XGUI ] [x] Mouse off
00000004163i[BIOS ] rombios.c,v 1.138 2005/05/07 15:55:26 vruppert Exp $
00000015000e[CLVGA] character height = 1, skipping text update
00000030000e[CLVGA] character height = 1, skipping text update
00000045000e[CLVGA] character height = 1, skipping text update
00000060000e[CLVGA] character height = 1, skipping text update
00000075000e[CLVGA] character height = 1, skipping text update
00000090000e[CLVGA] character height = 1, skipping text update
00000105000e[CLVGA] character height = 1, skipping text update
00000120000e[CLVGA] character height = 1, skipping text update
00000135000e[CLVGA] character height = 1, skipping text update
00000150000e[CLVGA] character height = 1, skipping text update
00000165000e[CLVGA] character height = 1, skipping text update
00000180000e[CLVGA] character height = 1, skipping text update
00000195000e[CLVGA] character height = 1, skipping text update
00000210000e[CLVGA] character height = 1, skipping text update
00000225000e[CLVGA] character height = 1, skipping text update
00000240000e[CLVGA] character height = 1, skipping text update
00000255000e[CLVGA] character height = 1, skipping text update
00000270000e[CLVGA] character height = 1, skipping text update
00000285000e[CLVGA] character height = 1, skipping text update
00000300000e[CLVGA] character height = 1, skipping text update
00000315000e[CLVGA] character height = 1, skipping text update
00000330000e[CLVGA] character height = 1, skipping text update
00000330070i[KBD ] reset-disable command received
00000345000e[CLVGA] character height = 1, skipping text update
00000360000e[CLVGA] character height = 1, skipping text update
00000390000e[CLVGA] character height = 1, skipping text update
00000405000e[CLVGA] character height = 1, skipping text update
00000420000e[CLVGA] character height = 1, skipping text update
00000435000e[CLVGA] character height = 1, skipping text update
00000450000e[CLVGA] character height = 1, skipping text update
00000451783i[VBIOS] VGABios $Id: vgabios.c,v 1.59 2004/07/18 20:22:43 vruppert Exp $
00000451853i[CLVGA] VBE known Display Interface b0c0
00000451885i[CLVGA] VBE known Display Interface b0c3
00000454810i[VBIOS] VBE Bios $Id: vbe.c,v 1.45 2004/07/22 18:37:29 vruppert Exp $
00000465000e[CLVGA] character height = 1, skipping text update
00000510000i[XGUI ] charmap update. Font Height is 16
00000525000i[XGUI ] charmap update. Font Height is 16
00000724412e[HD ] device set to 0 which does not exist
00000724705e[HD ] device set to 1 which does not exist
00999204500p[XGUI ] >>PANIC<< POWER button turned off.
00999204500i[SYS ] Last time is 1116493622
00999204500i[XGUI ] Exit.
00999204500i[CPU0 ] real mode
00999204500i[CPU0 ] CS.d_b = 16 bit
00999204500i[CPU0 ] SS.d_b = 16 bit
00999204500i[CPU0 ] | EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000000
00999204500i[CPU0 ] | ESP=00004000 EBP=00000000 ESI=000007ee EDI=00000000
00999204500i[CPU0 ] | IOPL=0 NV UP DI PL ZR NA PE NC
00999204500i[CPU0 ] | SEG selector base limit G D
00999204500i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00999204500i[CPU0 ] | CS:0000( 0001| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | DS:0000( 0003| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | SS:0000( 0003| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | ES:0000( 0003| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | FS:0000( 0003| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | GS:0000( 0003| 0| 0) 00000000 0000ffff 0 0
00999204500i[CPU0 ] | EIP=00007c31 (00007c31)
00999204500i[CPU0 ] | CR0=0x00000010 CR1=0 CR2=0x00000000
00999204500i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00999204500i[ ] restoring default signal behavior
========================================================================
Bochs is exiting with the following message:
[XGUI ] POWER button turned off.
========================================================================
00999204500i[CTRL ] quit_sim called with exit code 1



Here's the syslinux.cfg file:

DEFAULT kernel.bin




I know its a lot to look through, but the output doens't suggest anything wrong, apart from the "skipping text update", which I don't really know what it means.

Is it possibly the syslinux.cfg file which is wrong?

Share this post


Link to post
Share on other sites
Don't bother posting the console output from bochs again - it's bochs internal debug output and wholly uninteresting.

What did you see on the screen? This is much more interesting.

Presumably, syslinux came up, loaded kernel.bin, then nothing happened?

You might want to post the floppy image on a web site somewhere so we can take a look at it.

Mark

Share this post


Link to post
Share on other sites
I've had a go at running this through the debugger in qemu.

As far as I can tell, it's working fine. Your kernel.bin loads at 0:7c00, then starts running. It doesn't do very much, then it hits 0x7c31 which is a jump instruction to the same location.

Is that not what it's supposed to do?

Mark

Share this post


Link to post
Share on other sites
Well, since in main(), there is a call to 'puts("Hello World");' then it should print out "Hello World", because in the assembly file, there is a call to 'main'.

Here is the code that I have. It should be working, because, just to get something up and running, I basically copied it all from a tutorial I'm working from: Bran's Kernel Development Tutorial. The code is everything up to and including "Printing to the screen."

Share this post


Link to post
Share on other sites
I think it's trying to run 32-bit code in 16-bit mode.

Syslinux does NOT put normally put the CPU into pmode, or set up anything very much for you. This is because it's designed to boot Linux, and Linux contains that setup code itself. Syslinux just loads the image into (DOS) memory and jump to the (DOS) start address 0:7c00 - but that's all.

The CPU is in the wrong mode.

I have however found a solution!

see This page for a description of Syslinux "c32" COMBOOT32 format.

In this format, the kernel is loaded at 0x101000 with a flat memory model. This is what you want, except your link file is telling it to start at 0x100000.

I changed the filename of your kernel to kernel.c32, changed the linker offset to 0x101000 and it worked!

Hello, World :)

Mark

Share this post


Link to post
Share on other sites
Mark, I don't want to scare you, but you have just become my new best friend!!

Thanks very much Mark, you've just jump started me again. :D

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hi,

i followed your instructions to make the image, but when i start bochs i just get

Quote:
Booting from Floppy...

SYSLINUX 1.75 2002-06-14 Copyright (C) 1994-2002 H. Peter Anvin
.


but my kernel does not start

i used the same tutorial as Endar, though i expanded on it a little

Share this post


Link to post
Share on other sites
:D I expanded on it as well, the first time.

Then it crashed, and I decided to take it step by step. First you should get something working, then impove it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
it does work, just not with bochs. if i boot it normally with the computer it works fine, but it doesn't start with bochs

Share this post


Link to post
Share on other sites

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this