[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZzWpY_zR43Zq5WJh@black.fi.intel.com>
Date: Thu, 14 Nov 2024 09:40:19 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: "Woodhouse, David" <dwmw@...zon.co.uk>,
"peterz@...radead.org" <peterz@...radead.org>,
"kexec@...ts.infradead.org" <kexec@...ts.infradead.org>,
"jpoimboe@...nel.org" <jpoimboe@...nel.org>,
"horms@...nel.org" <horms@...nel.org>,
"x86@...nel.org" <x86@...nel.org>, "bp@...en8.de" <bp@...en8.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"kai.huang@...el.com" <kai.huang@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
"nik.borisov@...e.com" <nik.borisov@...e.com>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>
Subject: Re: [RFC PATCH 6/7] x86/kexec: Debugging support: Dump registers on
exception
On Tue, Nov 05, 2024 at 01:58:40PM -0800, H. Peter Anvin wrote:
> On 11/5/24 13:37, H. Peter Anvin wrote:
> > What is the point of writing this code in assembly in the first place? A
> > much more logical thing to do is to just push the registers you haven't
> > pushed already onto the stack and call a C function to do the actual
> > dumping? It isn't like it is in any shape, way or form performance
> > critical.
>
> arch/x86/boot/compressed/misc.c has some code that you can crib, both for
> writing to a text screen (not that useful anymore with EFI framebuffers) and
> serial port. If you factor it a little bit then you can probably even share
> the code directly.
>
> (__putstr perhaps should have a __putchar() factored out of it?)
>
> Then you can just do the obvious (have your assembly stub point %rdi to the
> base of the register dump; set the frame order to whatever you'd like,
> except rip/err/exc, or reverse the order if you prefer by changing the
> loop):
>
> static inline __noreturn void die(void)
> {
> while (1)
> asm volatile("hlt");
> }
>
> void dump_register_frame(const unsigned long frame[])
> {
> static const char regnames[][5] = {
> "rax:", "rcx:", "rdx:", "rbx:",
> "rsp:", "rbp:", "rsi:", "rdi:",
> "r8: ", "r9: ", "r10:", "r11:",
> "r12:", "r13:", "r14:", "r15:",
> "cr2:", "Exc:", "Err:", "rip:"
> };
>
> for (size_t i = 0; i < ARRAY_SIZE(regnames); i++) {
> __putstr(regnames[i]);
> __puthex(frame[i]);
> __putstr("\n");
> }
>
> /* Only return from int3 */
> if (frame[17] != 3)
> die();
> }
+ a mil here!
Please, use existing early_serial_console infra. Also we have
debug_putaddr() / debug_puthex() / debug_putstr() which are
probably ones you want to use.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists