public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* x86 setup code rewrite in C - revised
@ 2007-07-11 19:18 H. Peter Anvin
       [not found] ` <7aca4ce0a222438c94300a2ea535270a21db8812.1184181208.git.hpa@zytor.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 51+ messages in thread
From: H. Peter Anvin @ 2007-07-11 19:18 UTC (permalink / raw)
  To: torvalds, andi, linux-kernel

This patch set replaces the x86 setup code, which is currently all in
assembly, with a version written in C, using the ".code16gcc" feature
of binutils (which has been present since at least 2001.)

The new code is vastly easier to read, and, I hope, debug.  It should
be noted that I found a fair number of minor bugs while going through
this code, and have attempted to correct them.

In the process of doing so, it introduces several cleanups, in
particular:

- Obsoletes the hd_info field in the boot_params structure; they are
  only ever used for ST-506 (pre-IDE) drives and are pretty much
  guaranteed to be wrong on current BIOSes;
- Unifies the CPU feature bits between i386 and x86-64.  In the
  future, it should be possible to use arch/i386/boot/cpucheck.c to do
  the post-invocation CPU check currently done in
  arch/x86_64/kernel/trampoline.S, although this patch set doesn't
  introduce that change.
- boot_params is now a proper structure.

This patchset incorporates all feedback received by 2007-07-11 12:00 PDT.

 arch/i386/boot/bootsect.S                     |   98 -
 arch/i386/boot/edd.S                          |  231 --
 arch/i386/boot/setup.S                        | 1075 -------------
 arch/i386/boot/video.S                        | 2043 --------------------------
 arch/i386/kernel/verify_cpu.S                 |   94 -
 arch/x86_64/boot/bootsect.S                   |   98 -
 arch/x86_64/boot/install.sh                   |    2 
 arch/x86_64/boot/mtools.conf.in               |   17 
 arch/x86_64/boot/setup.S                      |  826 ----------
 arch/x86_64/boot/tools/build.c                |  185 --
 b/Documentation/i386/zero-page.txt            |    1 
 b/MAINTAINERS                                 |    4 
 b/arch/i386/Kconfig.cpu                       |    6 
 b/arch/i386/boot/Makefile                     |   48 
 b/arch/i386/boot/a20.c                        |  161 ++
 b/arch/i386/boot/apm.c                        |   97 +
 b/arch/i386/boot/bitops.h                     |   45 
 b/arch/i386/boot/boot.h                       |  296 +++
 b/arch/i386/boot/cmdline.c                    |   97 +
 b/arch/i386/boot/code16gcc.h                  |   15 
 b/arch/i386/boot/compressed/Makefile          |    7 
 b/arch/i386/boot/compressed/head.S            |    6 
 b/arch/i386/boot/copy.S                       |  101 +
 b/arch/i386/boot/cpu.c                        |   69 
 b/arch/i386/boot/cpucheck.c                   |  267 +++
 b/arch/i386/boot/edd.c                        |  196 ++
 b/arch/i386/boot/header.S                     |  283 +++
 b/arch/i386/boot/main.c                       |  161 ++
 b/arch/i386/boot/mca.c                        |   43 
 b/arch/i386/boot/memory.c                     |   99 +
 b/arch/i386/boot/pm.c                         |  170 ++
 b/arch/i386/boot/pmjump.S                     |   54 
 b/arch/i386/boot/printf.c                     |  307 +++
 b/arch/i386/boot/setup.ld                     |   54 
 b/arch/i386/boot/string.c                     |   52 
 b/arch/i386/boot/tools/build.c                |  160 --
 b/arch/i386/boot/tty.c                        |  112 +
 b/arch/i386/boot/version.c                    |   23 
 b/arch/i386/boot/vesa.h                       |   79 +
 b/arch/i386/boot/video-bios.c                 |  125 +
 b/arch/i386/boot/video-vesa.c                 |  284 +++
 b/arch/i386/boot/video-vga.c                  |  260 +++
 b/arch/i386/boot/video.c                      |  456 +++++
 b/arch/i386/boot/video.h                      |  145 +
 b/arch/i386/boot/voyager.c                    |   46 
 b/arch/i386/kernel/cpu/Makefile               |    2 
 b/arch/i386/kernel/cpu/addon_cpuid_features.c |   50 
 b/arch/i386/kernel/cpu/common.c               |    2 
 b/arch/i386/kernel/cpu/proc.c                 |   21 
 b/arch/i386/kernel/e820.c                     |    2 
 b/arch/i386/kernel/setup.c                    |   12 
 b/arch/x86_64/Kconfig                         |    4 
 b/arch/x86_64/boot/Makefile                   |  136 -
 b/arch/x86_64/boot/compressed/Makefile        |    9 
 b/arch/x86_64/boot/compressed/head.S          |    6 
 b/arch/x86_64/kernel/Makefile                 |    2 
 b/arch/x86_64/kernel/setup.c                  |   21 
 b/arch/x86_64/kernel/verify_cpu.S             |   22 
 b/drivers/ide/legacy/hd.c                     |   73 
 b/include/asm-i386/boot.h                     |    6 
 b/include/asm-i386/bootparam.h                |   85 +
 b/include/asm-i386/cpufeature.h               |   26 
 b/include/asm-i386/e820.h                     |   14 
 b/include/asm-i386/processor.h                |    1 
 b/include/asm-i386/required-features.h        |   39 
 b/include/asm-i386/setup.h                    |   10 
 b/include/asm-x86_64/alternative.h            |   68 
 b/include/asm-x86_64/boot.h                   |   16 
 b/include/asm-x86_64/bootparam.h              |    1 
 b/include/asm-x86_64/cpufeature.h             |  115 -
 b/include/asm-x86_64/e820.h                   |    4 
 b/include/asm-x86_64/processor.h              |    3 
 b/include/asm-x86_64/required-features.h      |   46 
 b/include/asm-x86_64/segment.h                |    8 
 b/include/linux/edd.h                         |    4 
 b/include/linux/screen_info.h                 |    9 
 76 files changed, 4606 insertions(+), 5209 deletions(-)

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: x86 setup code rewrite in C - revised
@ 2007-07-12 13:18 Etienne Lorrain
  0 siblings, 0 replies; 51+ messages in thread
From: Etienne Lorrain @ 2007-07-12 13:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa

> This patch set replaces the x86 setup code, which is currently all in
> assembly, with a version written in C, using the ".code16gcc" feature
> of binutils (which has been present since at least 2001.)

 ".code16gcc" is useable since a bit earlier than that, in fact since:
http://sourceware.org/ml/binutils/2000-04/msg00021.html
 has been fixed, I am using it every other day.

> The new code is vastly easier to read, and, I hope, debug.

 Yes it is, and there is a lot of work in those 33 patch; in very few of
them I would have liked to read something like "inspired by ..." in one of
the C comments (no need to add any E-mail, I already receive enough spam).

 Etienne.

http://gujin.org


	

	
		
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses 
http://fr.answers.yahoo.com

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: x86 setup code rewrite in C - revised
@ 2007-07-13 14:25 Etienne Lorrain
  2007-07-13 16:35 ` Chuck Ebbert
  0 siblings, 1 reply; 51+ messages in thread
From: Etienne Lorrain @ 2007-07-13 14:25 UTC (permalink / raw)
  To: linux-kernel

On Thu, 12 Jul 2007, Linus Torvalds wrote:
> On Thu, 12 Jul 2007, Andrew Morton wrote:
> > 
> > This code has been in -mm since 11 May, as git-newsetup.patch.  It has
> > caused (for what it is) astonishingly few problems.  Maybe a couple of
> > build glitches and one runtime failure, all quickly fixed.
> > 
> > I'd say it's ready.
> 
> Ok. That makes it easy. I'll just merge it.
> 
> 		Linus

 Have fun, this code:
 - do not open the fast A20 gate before checking if the slow A20 gate is open or closed.
 - uses in asm("") inputs which may or may not be set by the compiler in the stack,
   after modifying the stack pointer in the asm block: at least has_eflag()
 - The VGA recalc has the same bug as the assembly version where a VGA write protected
   register is written (Overflow register) without setting the enable bit (see VGA docs).
 - Does not save and restore %ds when printing a char on the screen (%ds is destroyed
   only when the content of the screen scroll - only for some video cards)
 - Has a "dn" for outl() which sliped in instead of "dN"
 and probably few other problems - just seen those by reading the patches (the asm("")
 are inlined in the C code - I find it more difficult to check).

 Also, I do not know if "m" is right in here:
static inline u8 rdfs8(addr_t addr)
{
	u8 v;
	asm("movb %%fs:%1,%0" : "=r" (v) : "m" (*(u8 *)addr));
	return v;
}

  I may repeat me, but to find these kind of problems, it is very nice to have an ELF
 file to do a readelf/objdump -D -m i8086 (even after final link).

  Etienne.
http://gujin.org

I like that message in this context...
   http://marc.info/?l=linux-kernel&m=117077712515509&w=4


      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: x86 setup code rewrite in C - revised
@ 2007-07-13 14:42 Etienne Lorrain
  0 siblings, 0 replies; 51+ messages in thread
From: Etienne Lorrain @ 2007-07-13 14:42 UTC (permalink / raw)
  To: linux-kernel

Andi wrote:
> The only thing questionable is that .code16gcc is arguably quite
> an abuse of gcc. I even checked with some gcc developers 
> and they weren't too happy about it. e.g. it's not regression
> tested at all so we would be basically on our own with it.

 On the other hand GCC just produces an assembly text file, it is
not the GCC developper problem what the user does with this text file.
Usually it goes to the assembler with standard options - .code16gcc
is a "special" option - and bugs (if there is) should be forwarded to binutils.
 GCC tries to go around CPU bugs, and those bug may be different in
protected or real mode - but I still do not have one example of such
a bug.
 GCC also has a base library support (multiplication & divisions of
64 bits...), and when you use .code16gcc you know you cannot touch it
(it is assembled with .code32); so that management may be what they
are refering to.

 Etienne.


      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: RE : Re: RE : Re: x86 setup code rewrite in C - revised
@ 2007-07-16  9:15 H. Peter Anvin
  2007-07-16 10:21 ` Etienne Lorrain
  0 siblings, 1 reply; 51+ messages in thread
From: H. Peter Anvin @ 2007-07-16  9:15 UTC (permalink / raw)
  To: Etienne Lorrain; +Cc: Chuck Ebbert, linux-kernel

Etienne Lorrain wrote:

> BUGS:	some implementations (including the original IBM PC) have a bug which
> 	  destroys BP
> 	the Trident TVGA8900CL (BIOS dated 1992/9/8) clears DS to 0000h when
> 	  scrolling in an SVGA mode (800x600 or higher)

"When scrolling in an SVGA mode", sounds to me like a bug when using
BIOS for text output in graphics mode.  We don't do that.

>>>>>>  Also, I do not know if "m" is right in here:
>>>>>> static inline u8 rdfs8(addr_t addr)
>>>>>> {
>>>>>> 	u8 v;
>>>>>> 	asm("movb %%fs:%1,%0" : "=r" (v) : "m" (*(u8 *)addr));
>>>>>> 	return v;
>>>>>> }
>>>> The "m" is correct right there.
>>>  strange, "g" would mean anything can go there - and this assembly instruction
>>> should accept every access modes.
>> Not with an %fs: prefix.  It would also allow the compiler to do a move
>> into a register "on its own", which would be disastrous, since it would
>> lack the prefix.  So "m" is correct.
> 
>   "mov %fs:(%ebx,%eax,4),%ecx" works for me.

That's an example on what "m" can generate.

"g" could produce stuff like:

	mov %fs:$1234,%ecx
	mov %fs:%eax,%ecx

	-hpa

^ permalink raw reply	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2007-07-16 17:35 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-11 19:18 x86 setup code rewrite in C - revised H. Peter Anvin
     [not found] ` <7aca4ce0a222438c94300a2ea535270a21db8812.1184181208.git.hpa@zytor.com>
2007-07-11 19:18   ` [x86 setup 01/33] x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code H. Peter Anvin
     [not found]   ` <e2ef08d659e025247a9de7e16784d695161c317e.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 02/33] hd.c: remove BIOS/CMOS queries H. Peter Anvin
     [not found]   ` <c20a5e19075b8eb5a5dd5f350c2012a71f072d56.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 03/33] include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h> H. Peter Anvin
     [not found]   ` <c74269f00504931e6a653be3b4f0684ca8753561.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 04/33] Unify the CPU features vectors between i386 and x86-64 H. Peter Anvin
     [not found]   ` <6ca6bf20ba1c8bef47e0042657fd9dccad3404b8.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 05/33] Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY H. Peter Anvin
     [not found]   ` <068e40b5e554720f1c3f1a966f5ea3d16cb8bbc5.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 06/33] Clean up struct screen_info (<linux/screen_info.h>) H. Peter Anvin
     [not found]   ` <b7ce2cdc4470b799c0ca96459898a24d1d04e8f5.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 07/33] Use a new CPU feature word to cover all Intel features that are spread around H. Peter Anvin
     [not found]   ` <e21d26f6728a59ddc9f19efdc111c5ed069cd1c0.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 08/33] Define zero-page offset 0x1e4 as a scratch field, and use it H. Peter Anvin
     [not found]   ` <e6a39812b9f6930a943ec96de73f270cb07cc2c2.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent H. Peter Anvin
     [not found]   ` <ee5aac7aaaa45d7bab8fe9bc2e5ac4fb8b9c3e44.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 10/33] Make struct boot_params a real structure, and remove obsolete fields H. Peter Anvin
     [not found]   ` <e75ca1b52aabe4d87c9db5d29eaff7fe5505bde4.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 11/33] x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386 H. Peter Anvin
     [not found]   ` <9c629383add61d72f69fde427153cb6b57f22188.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 12/33] x86-64: add symbolic constants for the boot segment selectors H. Peter Anvin
     [not found]   ` <ab1907cf095c021d5e721b9df84d7c4e6de82e66.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 13/33] Header file to produce 16-bit code with gcc H. Peter Anvin
     [not found]   ` <949c4631547d635d11605ddab03a18aa6e74483d.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 14/33] Top header file for new x86 setup code H. Peter Anvin
     [not found]   ` <03eade29601f9ca92ea95e241aaa7bfbcaaf0c6c.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 15/33] Simple bitops for the " H. Peter Anvin
     [not found]   ` <8697ab9d1471721ca1c40a2224191d276c78ea0e.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 16/33] String-handling functions " H. Peter Anvin
     [not found]   ` <fe891becb7c2f4551a36056287a16696d77a8afa.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 17/33] A20 handling code H. Peter Anvin
     [not found]   ` <d1d88acb7f06459e4d906701132bfeffebfb04a3.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 18/33] APM probing code H. Peter Anvin
     [not found]   ` <f0db7b1f909cdf2dd895c5c44273dd46ffb5addc.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 19/33] Command-line parsing code for the new x86 setup code H. Peter Anvin
     [not found]   ` <f38ae9eb84193af6271ed2294992f589fabc8b3d.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 20/33] Console-writing " H. Peter Anvin
     [not found]   ` <6ffab1ac3c68a7cdc06ae6c54c5d564b47d49e17.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 21/33] Version string " H. Peter Anvin
     [not found]   ` <39a01d42c01c5034adea3b442c6698983bd4d921.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 22/33] CPU features verification " H. Peter Anvin
     [not found]   ` <099b1190b55993dc1ee0ac7bf4faa3bf55ce5223.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 23/33] EDD probing code " H. Peter Anvin
     [not found]   ` <16466ebe45a5054920bf2e67083663eccf8da662.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 24/33] MCA support for " H. Peter Anvin
     [not found]   ` <67bea0be0e4af894483cd7d8e725631d24e9c263.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 25/33] Memory probing support for the " H. Peter Anvin
     [not found]   ` <76894ec63ab814078b628b5697e1b86d6421b187.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 26/33] Voyager " H. Peter Anvin
     [not found]   ` <509992ad2f618e07db2c72a96f8f5d708bfc6991.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 27/33] Video mode probing " H. Peter Anvin
2007-07-16 10:59     ` Martin Mares
     [not found]   ` <43b8a8153855d9af17029fcfcadebd8d4b14b7c4.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 28/33] Code for actual protected-mode entry H. Peter Anvin
     [not found]   ` <1a615a45477fc9b51fcb45279215881cc92dd794.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 29/33] Assembly header and main routine for new x86 setup code H. Peter Anvin
     [not found]   ` <5024dde46d1d0a742fcdcfcbff6a1112cb6c4729.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 30/33] Linker script for the " H. Peter Anvin
     [not found]   ` <70ac788a6377732e01a3f870f1bb2fe216f5b995.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 31/33] Use the new x86 setup code for i386 H. Peter Anvin
2007-07-13  9:27       ` Tilman Schmidt
     [not found]   ` <1208e1483b0e4e17d27fb07f9cdbb6945f9b1fb0.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 32/33] Use the new x86 setup code for x86-64; unify with i386 H. Peter Anvin
     [not found]   ` <5823c605b63bb9712f05fa73ab07d66a4f6e0f92.1184181208.git.hpa@zytor.com>
2007-07-11 19:18     ` [x86 setup 33/33] Remove old i386 setup code H. Peter Anvin
2007-07-11 20:08 ` x86 setup code rewrite in C - revised Jeff Garzik
2007-07-11 20:29   ` H. Peter Anvin
2007-07-12 17:24 ` Linus Torvalds
2007-07-12 17:30   ` Andrew Morton
2007-07-12 17:49     ` Linus Torvalds
2007-07-12 19:38   ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2007-07-12 13:18 Etienne Lorrain
2007-07-13 14:25 Etienne Lorrain
2007-07-13 16:35 ` Chuck Ebbert
2007-07-13 16:51   ` H. Peter Anvin
2007-07-13 22:23   ` H. Peter Anvin
2007-07-16 13:31     ` Etienne Lorrain
2007-07-16 17:35       ` H. Peter Anvin
2007-07-13 14:42 Etienne Lorrain
2007-07-16  9:15 RE : Re: RE : " H. Peter Anvin
2007-07-16 10:21 ` Etienne Lorrain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox