Page 1 of 1

Extending Bochs / Qemu

Posted: Fri Dec 21, 2007 5:49 am
by jal
While having problems with getting GRUB to pass me decent VESA info (see some other threads I recently started), I thought of a different approach: what if I developed a simple graphics device to compile with Bochs (or Qemu for that matter) and use that instead of VESA? I have no intentions of running on real hardware for at least the coming year, so a fake gfx card would suite my purposes. Has anyone ever tried that before? Could Bochs plug-ins be used? If so, how (I could find very little info on them while googling)?


JAL

Posted: Fri Dec 21, 2007 11:23 am
by ucosty
Have you tried using the Bochs Cirrus driver?

Re: Extending Bochs / Qemu

Posted: Fri Dec 21, 2007 1:36 pm
by os64dev
jal wrote:While having problems with getting GRUB to pass me decent VESA info (see some other threads I recently started), I thought of a different approach: what if I developed a simple graphics device to compile with Bochs (or Qemu for that matter) and use that instead of VESA? I have no intentions of running on real hardware for at least the coming year, so a fake gfx card would suite my purposes. Has anyone ever tried that before? Could Bochs plug-ins be used? If so, how (I could find very little info on them while googling)?
What good would that do you most likely have to rewrite a lot of stuff again because of a non existing video. Keeping to VESA will ensure working on real computer afterwards. I'll read the other threads now to see if i can help (doubt it ;-))

Posted: Mon Dec 24, 2007 3:27 am
by jal
ucosty wrote:Have you tried using the Bochs Cirrus driver?
I don't want to. Then I'd have to program a Cirrus. Pretty pointless, as Cirrus is dead and not present in a real machine and like I said, I don't want to bother with progamming real video hardware anyway. I want to be able to do a simple out to set the width, one to set the height and one to set bit depth, for example.


JAL

Re: Extending Bochs / Qemu

Posted: Mon Dec 24, 2007 3:31 am
by jal
os64dev wrote:What good would that do you most likely have to rewrite a lot of stuff again because of a non existing video.
My video driver could, as long as I'm not leaving Bochs (and that'll be for quite some time), be as simple as

Code: Select all

outb (myVideoPortBase, 0);
outw (myVideoPortBase+2, Width);
outw (myVideoPortBase+4, Height);
outb (myVideoPortBase+6, ColorDepth);
outb (myVideoPortBase, 1);
to set a video mode. Without me having to resort to a) programming real video card hardware or b) switching to real mode to call VBE.


JAL

Posted: Wed Dec 26, 2007 1:50 pm
by ucosty
Try this code out for size

Code: Select all

class VesaDriver
{
	public:
		void SetVideoMode(unsigned short width, unsigned short height, unsigned short depth);
		void ExitVideoMode();
		
	private:
		void WriteCommand(unsigned short index, unsigned short value);
		
		enum VBE_IOPORTS {
			VBE_DISPI_IOPORT_INDEX = 0x01CE, VBE_DISPI_IOPORT_DATA = 0x01CF
		};

		enum VBE_COMMANDS {
			VBE_DISPI_INDEX_ID, VBE_DISPI_INDEX_XRES, VBE_DISPI_INDEX_YRES,
			VBE_DISPI_INDEX_BPP, VBE_DISPI_INDEX_ENABLE, VBE_DISPI_INDEX_BANK,
			VBE_DISPI_INDEX_VIRT_WIDTH, VBE_DISPI_INDEX_VIRT_HEIGHT,
			VBE_DISPI_INDEX_X_OFFSET, VBE_DISPI_INDEX_Y_OFFSET
		};
		
		enum VBE_FLAGS {
			VBE_DISPI_DISABLED, VBE_DISPI_ENABLED, VBE_DISPI_GETCAPS,
			VBE_DISPI_8BIT_DAC = 0x20, VBE_DISPI_LFB_ENABLED = 0x40, VBE_DISPI_NOCLEARMEM = 0x80
		};
};


void VesaDriver::SetVideoMode(unsigned short width, unsigned short height, unsigned short depth)
{
	this->WriteCommand(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);
	this->WriteCommand(VBE_DISPI_INDEX_XRES, width);
	this->WriteCommand(VBE_DISPI_INDEX_YRES, height);
	this->WriteCommand(VBE_DISPI_INDEX_BPP, depth);
	this->WriteCommand(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED );
}

void VesaDriver::ExitVideoMode()
{
	this->WriteCommand(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);
	
}

void VesaDriver::WriteCommand(unsigned short index, unsigned short value)
{
	core::IOPorts::WriteWord(VBE_DISPI_IOPORT_INDEX, index);
	core::IOPorts::WriteWord(VBE_DISPI_IOPORT_DATA, value);
}


Posted: Thu Dec 27, 2007 9:47 am
by jal
ucosty wrote:Try this code out for size
Well, that's something like I imagined, yes. But I didn't think this was possible, I never heard of VBE having a definition for videoports etc. What specification is this based upon? Or is this just Bochs?

EDIT: I did some Googling, and it seems some Bochs VGA BIOS extension? Can't find much documentation about it though.

JAL

Posted: Thu Dec 27, 2007 11:06 pm
by ucosty
jal wrote:
ucosty wrote:Try this code out for size
Well, that's something like I imagined, yes. But I didn't think this was possible, I never heard of VBE having a definition for videoports etc. What specification is this based upon? Or is this just Bochs?

EDIT: I did some Googling, and it seems some Bochs VGA BIOS extension? Can't find much documentation about it though.

JAL
TBH I have no idea what it is based on. I found it while randomly trolling around and found it works nicely in Bochs and QEMU, which is good enough for me at this stage.

Posted: Fri Dec 28, 2007 1:29 am
by jal
ucosty wrote:TBH I have no idea what it is based on. I found it while randomly trolling around and found it works nicely in Bochs and QEMU, which is good enough for me at this stage.
Well, it is exactly what I wanted, so thanks very much! This should be in the Wiki really.


JAL

Posted: Fri Dec 28, 2007 2:27 am
by Combuster
AFAIK it is limited to bochs and qemu. The reason that it works on both is that they share a VGA BIOS, and hence the same video interface.

Posted: Fri Dec 28, 2007 4:58 am
by jal
Combuster wrote:AFAIK it is limited to bochs and qemu. The reason that it works on both is that they share a VGA BIOS, and hence the same video interface.
That's what I found, yes, and it serves my purposes for now perfectly. However, it must be something more than just the BIOS, as we're talking direct outs to hardware ports. But I guess the Bochs VGA BIOS creators thought along the same line as I did, i.e. why emulate a piece of hardware when you can do it the easy way...


JAL