Re: [PATCH] x86/boot: This program cannot be run in DOS mode.$

From: Ingo Molnar
Date: Thu Apr 18 2019 - 07:27:28 EST



* Pavel Machek <pavel@xxxxxx> wrote:

> On Mon 2019-04-08 20:08:09, Pali Rohár wrote:
> > On Monday 08 April 2019 20:04:22 Pavel Machek wrote:
> > > On Mon 2019-04-01 12:24:34, Pali Rohár wrote:
> > > > Every EFI binary is in PE format. And we know that PE format needs to have
> > > > MZ MS-DOS header as there is written offset to PE header.
> > > >
> > > > Therefore generated bzImage binary with CONFIG_EFI_STUB option is MS-DOS
> > > > executable binary.
> > > >
> > > > We already know the "requirement" that Windows PE executable started in
> > > > MS-DOS must print legendary and famous message to computer screen:
> > > > "This program cannot be run in DOS mode."
> > > >
> > > > But trying to run that bzImage of Linux kernel with MZ header just cause
> > > > freezing whole MS-DOS instead of writing "the correct message" to user.
> > > > This is not the compliant behavior of PE executables!
> > > >
> > > > This patch fixes this problem. When Linux kernel compiled with
> > > > CONFIG_EFI_STUB is started in MS-DOS then it prints message:
> > > >
> > > > This program cannot be run in DOS mode.
> > > > To load Linux kernel from DOS mode use LOADLIN.EXE.
> > > >
> > > > So it also helps MS-DOS users how to "correctly" start this bzImage binary
> > > > by mentioning LOADLIN.EXE. Note that MS-DOS strings are not null-terminated
> > > > but rather dollar-terminated.
> > > >
> > > > To have error message unified bugger_off_msg for BIOS boot block code was
> > > > changed to:
> > > >
> > > > This program cannot be run in BIOS mode.
> > > >
> > > > So if you copy generated bzImage directly to boot sector and try to boot it
> > > > by BIOS you get this new updated message.
> > > >
> > > > Due to fixed offset of setup header (0x1f1), PE header was moved after
> > > > entrytext section. bstext and bsdata sections where is full MZ header and
> > > > MS-DOS code is now bigger.
> > >
> > > Hehe, I guess the patch may have been dropped due to april's fools?
> >
> > Yea, it was mean as first April patch :-) I tested it with MS-DOS 7.0
> > and DOSBox and it worked.
> >
> > > You may want to retransmit?
> >
> > Do you really think it can be useful? :-)
>
> Dunno. It is quite simple, and quite a nice hack ;-).

Agreed, looks simple enough, no objections from me! :)

Ingo