OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 1:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Tue Oct 23, 2018 1:33 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
It depends upon your computer. Many servers have an NMI button, but I'm not sure if any consumer desktops do. If you were clever enough you could probably wire a switch to cause an NMI - again, it probably depends upon your hardware. Expansion cards exist for this purpose - http://connecttech.com/product/pci-dump-switch-card/ . I should imagine they are fairly expensive as demand for them will be small.


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Tue Oct 23, 2018 2:12 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
Most server-class systems have NMI functionality available via a pin on the motherboard. It's pin 23 on the 24-pin front-panel connector that's "standard" on boards based on Intel server chipsets.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Tue Oct 23, 2018 2:56 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
iansjack wrote:
Expansion cards exist for this purpose


Thanks for the information. It could be fun to try it.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Tue Oct 23, 2018 6:26 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
I don't know, but I very much doubt it.


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Wed Oct 24, 2018 3:04 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 66
You can't just solder a pin in the CPU, especially not in a laptop.


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Wed Oct 24, 2018 8:57 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
mariuszp wrote:
Any idea if it's possible on HP Probook laptop? It's the only hardware I have available at the moment.


How (in)feasible would it be to find other hardware to test with, and what limitations do you have on space to set something up? I would normally recommend seeing if you could find an inexpensive used desktop PC off of Ebay or Craigslist or something similar, or at some computer hardware recycler if there are any where you are, but I have no idea if this would even be possible for you.

Or, if you don't mind putting a bit more research and elbow grease into it, you could build one from new or used components. This would probably be a bit more expensive, even with used parts, but in the US at least, a picked build with used parts could potentially be under US$100 if you already have a suitable monitor (I gather you don't, though), or around US$500 for new hardware including an inexpensive monitor (for something like this, a tool such as the PC Parts Picker website is quite helpful).

However, I don't know where you are (your profile doesn't list a location, and you may well have a reason not to put one - I don't know what your circumstances are), so all I can give advice about is how things are in the US. I also don't know your living situation - if a desktop is out of the question, this advice probably won't help much - or what, if any, money you could spend on something like that.

If you have some money and the ability to order parts, but lack space, a NUC may be an option. They range from moderately pricey to quite pricey indeed (anywhere from around US$300 to close to US$900), and are a bit underpowered compared to a desktop or even most laptops, but they are for the most part full PCs.

Another possibility an x86-based SBC such as a LattePanda or an UDOO x86, which have comparable computing power to a NUC but cost a bit less. However, those are still fairly expensive compared to most other SBCs (the LattePanda's official e-store lists the boards (without a Windows 10 key) ranging from US$90 for an older 2GiB model, to US$360 for the Alpha 864 model, while the UDOO website lists the existing x86 models as US$175 and US$267, and the upcoming Ryzen model as US$230). Also, while they have the same CPU instruction set, their hardware is significantly different from a stock PC in other ways. Further, you'd need to buy a raft of additional components such as a case, an AC adapter and video cables, the heat sink and fan in some cases, an inexpensive keyboard, etc., though you should be able to use an HDMI-ready TV for the video - or else run it headless, using the laptop to connect via an SSH client.

But getting to the NMI pin should be a breeze with an SBC. What's more, both the LattePandas and the UDOOs have built-in headers for connecting a JTAG breakout unit, which may prove more useful than the NMI break approach. While JTAG adapters are primarily meant for debugging hardware, it is my understanding that the more powerful ones can be used for pausing the CPU and dumping or inspecting the system memory, making them useful for debugging system software. Can anyone else add anything about this?

And for completeness ' sake: a non-x86 SBC might be less expensive, but at that point, you are dealing with an entirely different CPU type - usually an ARM of some variety, though MIPS and even RISC-V boards do exist (though the one full-fledged RISC-V SBC on the market now, the HiFive Unleashed, is US$1000, which I am guessing isn't going to be in you budget any more than it is in my own; much less expensive ones are available, such as the HiFive One and the LoFive, but they use much less powerful microcontroller CPUs). You alsdo would still need all the accessories as with the previous two. Obviously, the original question wouldn't apply to these (as the debugging method for those usually involves a JTAG breakout module), but if you decide to try something other than a PC, those are an option.

Come to think of it, it is possible that your laptop has a JTAG header hidden somewhere on the motherboard, but I have no idea if it does or not - probably not, but maybe. Which model of ProBook do you have?

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Thu Oct 25, 2018 2:38 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
The other option would be to cause an NMI to trigger from software... That at least allows you to test your NMI handler, even if you can't use it for debugging. Most recent-ish Intel chipsets (including some laptop chipsets) have an integrated watchdog timer which is capable of triggering an NMI.

The procedure would be simply to configure the watchdog to produce an NMI (and not to reset the CPU afterwards), enable it and once the timeout expires an NMI will be produced. The process for doing so is documented in Intel's "Intelligent Platform Management Interface Specification" (here).

Of course, once you've worked out how to program the watchdog, you can then use it for it's intended purpose and have your NMI handler fire when the OS hangs...

_________________
Image


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Fri Oct 26, 2018 11:22 am 
Offline
Member
Member

Joined: Thu Feb 09, 2012 6:53 am
Posts: 67
Location: Czechoslovakia
I used to send NMIs to different CPUs in SMP by writing into APIC ICR.
Executing int 2 (binary CD 02) is not true NMI as it lacks hardware features of NMI (on true NMI subsequent NMI's are blocked).
While NMIs blocked the CPU cannot receive second NMI (preventing entering NMI handler twice while the first one is not yet finished).
To unblock blocked NMI execute IRETQ (64 bit OS) / IRET (32 bit OS). The last instruction of NMI handler is usually IRETQ/IRET.
Using NMI for debugging is very good idea as this powerfull interrupt is capable of waking up cpu from some bad almost dead states (e.g. when cpu executes HLT with disabled interrupts when the timer interrupt cannot wake up the CPU and IIRC NMI is able to wake up CPU from shutdown state after triplefault) - only NMI until executing IRETQ and wait-for-sipi states block delivering NMI.

_________________
hypervisor-based solutions developer (Intel, AMD)


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Sat Oct 27, 2018 12:38 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
mariuszp wrote:
the whole issue is that random processes freeze in kernel space but it still responds to interrupts.

You don't really need NMI if it's still responding to other interrupt sources. Just have one of your other interrupt handlers perform the crash dump on some specific event. For example, you can configure Windows to crash on a key combination.


Top
 Profile  
 
 Post subject: Re: Can you fire an NMI on real hardware?
PostPosted: Sun Oct 28, 2018 7:14 am 
Offline
Member
Member

Joined: Thu Feb 09, 2012 6:53 am
Posts: 67
Location: Czechoslovakia
mariuszp wrote:
I can't send it using APIC when my whole OS crashed.

Then use watchdog timer NMI as suggested by others, you have to set it in APIC. If your OS is x64 you can use IST feature of TSS so NMI handler is executed at its own good stack even if kernel stack is damaged.

_________________
hypervisor-based solutions developer (Intel, AMD)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group