got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

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
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

Hi,

I got my S3 ViRGE GX/2 working. According to VGADOC4B, I need to read the port 0x9AE8 to check status , but system hangs. Does in/out operation lead to exception?
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: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by Combuster »

Ask the intel manuals :wink:
"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
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by Brendan »

Hi,
blackoil wrote:I got my S3 ViRGE GX/2 working. According to VGADOC4B, I need to read the port 0x9AE8 to check status , but system hangs. Does in/out operation lead to exception?
IN/OUT can directly cause an exception if CPL > IOPL (e.g. you're in user-mode), unless the I/O permission bitmap in the TSS allows it. If you're running at CPL=0 (in "kernel-mode") it can't happen.

IN/OUT can indirectly cause an exception, depending on the hardware you're messing with. For example, accidentally asking a PCI "bus mastering" card to transfer data to RAM might cause an exception (e.g. overwrite your kernel).

I/O port accesses could also (potentially) cause any sort of interrupt (SMI, NMI, IRQ 123, etc) but this isn't likely unless you're messing with the device's MSI (Message Signaled Interrupts) registers in PCI configuration space.

IMHO the most likely explanation (if CPL <= IOPL) is that the I/O port access doesn't cause the exception and something else does - a timer IRQ that happens to occur at about the same time, some inline assembly that doesn't tell the compiler that it modifies a register, some kernel code that messes up EFLAGS (sets IOPL to something unintended), etc.

If anything does cause an exception, then your exception handlers should tell you about it. If you're messing with a video device driver then this might be difficult to do - you may need to login via. serial to see anything if the video card is in an unusable state. In this case, if you don't want to use the serial port then (as a temporary hack) you might be able to use the PC speaker or turn the floppy motor on when an exception occurs (so at least you know an exception did occur). Another idea might be to setup dual monitors, so you can use one video card while you develop the device driver for the other video card.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

That code runs in ring 0. I just got freezed, even the caplock led doesn't work after that.
I already made the hardware graphical cursor working, with inverted screen color.
I will continue to do more tests to figure out what's wrong.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

I think I figure out what's wrong. I tried to inportw(0x9AE8) in bootloader, it works fine. After switch videomode with VESA 2, the code make system crash, it should be the register read triggers some DMA operations that overwrite my kernel.

So without detailed hardware specification, don't know which register should be initialized,
it's difficult to go on.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by Brendan »

Hi,
blackoil wrote:So without detailed hardware specification, don't know which register should be initialized,
it's difficult to go on.
A few ideas...

Do the VBE functions leave the "enhanced command registers" enabled? I'd assume that for compatibility purposes the VBE functions would leave the enhanced command registers disabled, so your I/O port read during boot would be ignored.

Does your driver enable access to the enhanced command registers? If it does, then your I/O port read wouldn't be ignored (and could behave entirely differently to the same I/O port read done during boot). If you don't enable access to the enhanced command registers, then you probably should if you're going to use them.... ;)

What would happen if the video card sent a "FIFO queue empty" IRQ (or any other IRQ) to your OS? Do you have an IRQ handler (just in case), or is the IDT entry "not present"?

If your video IRQ handler is present, what does it do? There's lots of ways to get PCI IRQ handling wrong...

What do your exception handlers actually do? Do they display information, or do a "cli; hlt", or...? Do you know that an exception definitely does occur, or does everything hang with no way to tell even what happened?

Note: It may be possible to trigger a blit from display memory to host memory using a write to I/O port 0x9AE8, but it should be impossible to start any kind of DMA transfer using a read from to I/O port 0x9AE8.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

Hi Brendan

I forgot to set 0x3D4 index 40h to enable enhanced registers in bootloader. I will try it later.
Ny IDT ends with secondary ATA handler, and incomplete, only 48 entries, maybe it send me a video interrupt that causes corruption.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

I tried in bootloader, but still crash, once read port 0x9ae8

Code: Select all

				mov dx,0x3d4
				mov al,0x38
				out dx,al
				mov dx,0x3d5
				mov al,0x48     ;0x48 to unlock
				out dx,al

				mov dx,0x3d4
				mov al,0x39
				out dx,al
				mov dx,0x3d5
				mov al,0xa5     ;0xa5 to unlock
				out dx,al

				mov dx,0x3d4
				mov al,0x40
				out dx,al
				mov dx,0x3d5
				in al,dx
				or al,1          ;set bit0 to enable 
				out dx,al

				mov dx,0x9ae8
				in al,dx
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: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by Combuster »

I noticed before (with a mach64 chip) that VGADOC can have the ports wrong when dealing with PCI devices. I.e., VGADOC gives you a sparse register file while the PCI version has a flat register file. To check for that, you'll have to do PCI enumeration to see what ranges the card actually uses.

Secondly, the S3 doc does not mention the S3 Virge at all, are you sure its one of the chips mentioned and not a more recent chip with a different core?
"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 ]
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: got crash, when access port 0x9AE8 (S3 HW 2D ACCEL)

Post by blackoil »

Hi, combuster,

I never play with PCI yet, it takes time to code.
I do notice my virge gx is not listed in VGADOC4B. I think its 2d acceleration may be share the same design, so I try it. But It goes into a weird state, without any exception/interrupt.

I can set the hw gfx cursor with port 0x46-0x49.

Code: Select all

			OutPortB(0x3D4,0x47);		OutPortB(0x3D5,MouseX);
			OutPortB(0x3D4,0x46);		OutPortB(0x3D5,MouseX>>8);
			OutPortB(0x3D4,0x49);		OutPortB(0x3D5,MouseY);
			OutPortB(0x3D4,0x48);		OutPortB(0x3D5,MouseY>>8);
Post Reply