Extending Bochs / 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Extending Bochs / Qemu

Post 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
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

Have you tried using the Bochs Cirrus driver?
The cake is a lie | rackbits.com
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Re: Extending Bochs / Qemu

Post 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 ;-))
Author of COBOS
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Extending Bochs / Qemu

Post 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
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post 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);
}

The cake is a lie | rackbits.com
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post 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.
The cake is a lie | rackbits.com
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
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:

Post 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.
"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 ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
Post Reply