[SOLVED] Bochs and HPET: How to detect ?

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
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

[SOLVED] Bochs and HPET: How to detect ?

Post by wichtounet »

Hi,

I've had an HPET driver working correctly for quite some time on Qemu. Before, it was not detecting any HPET in Bochs, but now Bochs added an ACPI Table for HPET and my OS detect that there is support for HPET. However, I'm having issues from Bochs telling me that I read (or write) to invalid HPET Register.

Here is what I'm doing to Detect HPET support for my OS:
  1. Check if the Table is here
  2. Check if possible to handle legacy replacement mode
  3. Check if the main counter is 64 bits
  4. Check if timer #0 is 64-bits
With Bochs, the three first tests pass without issue, but it crashes with:
Unsupported HPET read at address 0x0000fed00100
Is there any way to do a better detection so that step 4. does not fail ?
Is my HPET detection wrong ?

I was thinking to detect the number of timers, but Bochs tell me there are two counters...

Thanks
Last edited by wichtounet on Thu Mar 29, 2018 3:27 am, edited 1 time in total.
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
linuxyne
Member
Member
Posts: 211
Joined: Sat Jul 02, 2016 7:02 am

Re: Bochs and HPET: How to detect ?

Post by linuxyne »

The function hpet_read raises that error if the read size is not 4 or 8 bytes.

You may want to disassemble your binary to determine if any optimizations have caused it to contain such attempts at reading the hpet registers.
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

Re: Bochs and HPET: How to detect ?

Post by wichtounet »

linuxyne wrote:The function hpet_read raises that error if the read size is not 4 or 8 bytes.

You may want to disassemble your binary to determine if any optimizations have caused it to contain such attempts at reading the hpet registers.
Oh my god, you were right, I was missing a volatile!

Thanks a lot. It works now. It seems incredibly slow compared to qemu though.

I also tried patching the hpet_read function to handle small reads and it also works.
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Bochs and HPET: How to detect ?

Post by BrightLight »

wichtounet wrote:I also tried patching the hpet_read function to handle small reads and it also works.
That's against the spec though. The HPET spec only allows DWORD reads/writes at DWORD-aligned boundaries, and QWORD read/writes at QWORD-aligned boundaries.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
wichtounet
Member
Member
Posts: 90
Joined: Fri Nov 01, 2013 4:05 pm
Location: Fribourg, Switzerland
Contact:

Re: Bochs and HPET: How to detect ?

Post by wichtounet »

omarrx024 wrote:
wichtounet wrote:I also tried patching the hpet_read function to handle small reads and it also works.
That's against the spec though. The HPET spec only allows DWORD reads/writes at DWORD-aligned boundaries, and QWORD read/writes at QWORD-aligned boundaries.
Thanks, I didn't know that :)
Thor Operating System: C++ 64 bits OS: https://github.com/wichtounet/thor-os
Good osdeving!
Post Reply