Can you fire an NMI on real hardware?

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
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Can you fire an NMI on real hardware?

Post by iansjack »

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.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: Can you fire an NMI on real hardware?

Post by mallard »

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
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Can you fire an NMI on real hardware?

Post by Antti »

iansjack wrote:Expansion cards exist for this purpose
Thanks for the information. It could be fun to try it.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Can you fire an NMI on real hardware?

Post by iansjack »

I don't know, but I very much doubt it.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: Can you fire an NMI on real hardware?

Post by thomtl »

You can't just solder a pin in the CPU, especially not in a laptop.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Can you fire an NMI on real hardware?

Post by Schol-R-LEA »

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.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: Can you fire an NMI on real hardware?

Post by mallard »

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
feryno
Member
Member
Posts: 73
Joined: Thu Feb 09, 2012 6:53 am
Location: Czechoslovakia
Contact:

Re: Can you fire an NMI on real hardware?

Post by feryno »

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)
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: Can you fire an NMI on real hardware?

Post by Octocontrabass »

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.
feryno
Member
Member
Posts: 73
Joined: Thu Feb 09, 2012 6:53 am
Location: Czechoslovakia
Contact:

Re: Can you fire an NMI on real hardware?

Post by feryno »

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