x86 setup code rewrite in C
Subsystems (2)
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 code has been tested in -mm since early in the 2.6.22 cycle.
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 | 46 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 | 290 +++ b/arch/i386/boot/cmdline.c | 97 + b/arch/i386/boot/code16gcc.h | 9 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 | 331 ++++ b/arch/i386/boot/setup.ld | 54 b/arch/i386/boot/string.c | 34 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 | 6 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, 4601 insertions(+), 5208 deletions(-)
PATCH 1/33 x86 setup: MAINTAINERS: formally take responsibility for the i386 boot code
From: H. Peter Anvin <[email protected]>
Change MAINTAINERS to formally take responsibility for the i386 boot code.
--- MAINTAINERS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
MAINTAINERS +2 -2
@@ -1750,8 +1750,8 @@ T: http://www.harbaum.org/till/i2c_tiny_usb S: Maintained i386 BOOT CODE -P: Riley H. Williams -M: [email protected] +P: H. Peter Anvin +M: [email protected] L: [email protected] S: Maintained
Signature · 1 line
1.5.2.2
PATCH 2/33 hd.c: remove BIOS/CMOS queries
From: H. Peter Anvin <[email protected]>
An ST-506 disk these days is pretty much someone trying to pull ancient data using an auxilliary controller. Pulling data from the BIOS or CMOS is just plain wrong, since it's likely to be the primary OS disk... and would be user-entered data anyway. Instead, require the user enters it on the command line.
--- drivers/ide/legacy/hd.c | 73 ++++++++--------------------------------------- 1 files changed, 12 insertions(+), 61 deletions(-)
drivers/ide/legacy/hd.c +12 -61
@@ -718,74 +718,25 @@ static int __init hd_init(void) device_timer.function = hd_times_out;blk_queue_hardsect_size (hd_queue,512 ); -#ifdef __i386__if (!NR_HD ) { -extern struct drive_info drive_info; -unsigned char *BIOS = (unsigned char *) &drive_info; -unsigned long flags; -int cmos_disks; - -for (drive=0 ; drive<2 ; drive++) { - hd_info[drive].cyl = *(unsigned short *)BIOS ; - hd_info[drive].head = *(2 +BIOS ); - hd_info[drive].wpcom = *(unsigned short *) (5 +BIOS ); - hd_info[drive].ctl = *(8 +BIOS ); - hd_info[drive].lzone = *(unsigned short *) (12 +BIOS ); - hd_info[drive].sect = *(14 +BIOS ); -#ifdef does_not_work_for_everybody_with_scsi_but_helps_ibm_vp -if (hd_info[drive].cyl &&NR_HD == drive) -NR_HD ++; -#endif -BIOS +=16 ; - } - -/* -We query CMOS about hard disks : it could be that -we have a SCSI/ESDI/etc controller that is BIOS -compatible with ST-506, and thus showing up in our -BIOS table, but not register compatible, and therefore -not present in CMOS. - -Furthermore, we will assume that our ST-506 drives -<if any> are the primary drives in the system, and -the ones reflected as drive 1 or 2. - -The first drive is stored in the high nibble of CMOS -byte 0x12, the second in the low nibble. This will be -either a 4 bit drive type or 0xf indicating use byte 0x19 -for an 8 bit type, drive 1, 0x1a for drive 2 in CMOS. - -Needless to say, a non-zero value means we have -an AT controller hard disk for that drive. - -Currently the rtc_lock is a bit academic since this -driver is non-modular, but someday... ? Paul G. -*/ - -spin_lock_irqsave (&rtc_lock, flags); - cmos_disks =CMOS_READ (0x12 ); -spin_unlock_irqrestore (&rtc_lock, flags); - -if (cmos_disks &0xf0 ) { -if (cmos_disks &0x0f ) -NR_HD =2 ; -else -NR_HD =1 ; - } - } -#endif /* __i386__ */ -#ifdef __arm__ -if (!NR_HD ) { -/* We don't know anything about the drive. This means +/* +* We don't know anything about the drive. This means * that you *MUST* specify the drive parameters to the * kernel yourself. +* +* If we were on an i386, we used to read this info from +* the BIOS or CMOS. This doesn't work all that well, +* since this assumes that this is a primary or secondary +* drive, and if we're using this legacy driver, it's +* probably an auxilliary controller added to recover +* legacy data off an ST-506 drive. Either way, it's +* definitely safest to have the user explicitly specify +* the information. */ printk ("hd: no drives specified - use hd=cyl,head,sectors" " on kernel command line\n" ); - } -#endif -if (!NR_HD ) goto out; + }for (drive=0 ; drive <NR_HD ; drive++) {struct gendisk *disk =alloc_disk (64 );
Signature · 1 line
1.5.2.2
PATCH 3/33 include/asm-i386/boot.h: This is <asm/boot.h>, not <linux/boot.h>
From: H. Peter Anvin <[email protected]>
include/asm-i386/boot.h incorrectly has the multiple include guards as _LINUX_BOOT_H instead of _ASM_BOOT_H. Fix.
--- include/asm-i386/boot.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
include/asm-i386/boot.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _LINUX_BOOT_H -#define _LINUX_BOOT_H +#ifndef _ASM_BOOT_H +#define _ASM_BOOT_H/* Don't touch these, unless you really know what you're doing. */ #define DEF_INITSEG 0x9000
@@ -17,4 +17,4 @@ + (CONFIG_PHYSICAL_ALIGN - 1)) \ & ~(CONFIG_PHYSICAL_ALIGN - 1)) -#endif /* _LINUX_BOOT_H */ +#endif /* _ASM_BOOT_H */
Signature · 1 line
1.5.2.2
PATCH 4/33 Unify the CPU features vectors between i386 and x86-64
From: H. Peter Anvin <[email protected]>
Unify the handling of the CPU features vectors between i386 and x86-64. This also adopts the collapsing of features which are required at compile-time into constant tests from x86-64 to i386.
--- arch/i386/kernel/cpu/proc.c | 15 +++-- arch/i386/kernel/verify_cpu.S | 12 ++-- arch/x86_64/kernel/setup.c | 13 ++-- arch/x86_64/kernel/verify_cpu.S | 22 +----- include/asm-i386/cpufeature.h | 17 +++-- include/asm-i386/required-features.h | 38 ++++++++--- include/asm-x86_64/alternative.h | 68 ++++++++++--------- include/asm-x86_64/cpufeature.h | 115 +++---------------------------- include/asm-x86_64/processor.h | 2 - include/asm-x86_64/required-features.h | 45 ++++++++++++ 10 files changed, 159 insertions(+), 188 deletions(-) create mode 100644 include/asm-x86_64/required-features.h
arch/i386/kernel/cpu/proc.c +9 -6
@@ -29,7 +29,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"syscall" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,"mp" ,"nx" ,NULL ,"mmxext" ,NULL , -NULL ,"fxsr_opt" ,"pdpe1gb" ,"rdtscp" ,NULL ,"lm" ,"3dnowext" ,"3dnow" , +NULL ,"fxsr_opt" ,"pdpe1gb" ,"rdtscp" ,NULL ,"lm" , +"3dnowext" ,"3dnow" ,/* Transmeta-defined */ "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
@@ -40,8 +41,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)/* Other (Linux-defined) */ "cxmmx" ,"k6_mtrr" ,"cyrix_arr" ,"centaur_mcr" ,NULL ,NULL ,NULL ,NULL , -"constant_tsc" ,"up" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +"constant_tsc" ,"up" ,NULL ,"arch_perfmon" , +"pebs" ,"bts" ,NULL ,"sync_rdtsc" , +"rep_good" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , /* Intel-defined (#2) */
@@ -57,9 +59,10 @@ static int show_cpuinfo(struct seq_file *m, void *v)NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,/* AMD-defined (#2) */ -"lahf_lm" ,"cmp_legacy" ,"svm" ,"extapic" ,"cr8legacy" ,"abm" , -"sse4a" ,"misalignsse" , -"3dnowprefetch" ,"osvw" ,"ibs" ,NULL ,NULL ,NULL ,NULL ,NULL , +"lahf_lm" ,"cmp_legacy" ,"svm" ,"extapic" ,"cr8_legacy" , +"altmovcr8" ,"abm" ,"sse4a" , +"misalignsse" ,"3dnowprefetch" , +"osvw" ,"ibs" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, };
arch/i386/kernel/verify_cpu.S +6 -6
@@ -20,7 +20,7 @@ verify_cpu: testl $(1<<18),%eax jz bad #endif -#if REQUIRED_MASK1 != 0 +#if REQUIRED_MASK0 != 0 pushfl # standard way to check for cpuid popl %eax movl %eax,%ebx
@@ -39,14 +39,14 @@ verify_cpu: pushfl popl %eax cmpl %eax,%ebx - jz bad # REQUIRED_MASK1 != 0 requires CPUID + jz bad # REQUIRED_MASK0 != 0 requires CPUID movl $0x0,%eax # See if cpuid 1 is implemented cpuid cmpl $0x1,%eax jb bad # no cpuid 1 -#if REQUIRED_MASK1 & NEED_CMPXCHG64 +#if REQUIRED_MASK0 & NEED_CMPXCHG64 /* Some VIA C3s need magic MSRs to enable CX64. Do this here */ cmpl $0x746e6543,%ebx # Cent jne 1f
@@ -79,10 +79,10 @@ verify_cpu: #error add proper model checking here #endif - andl $REQUIRED_MASK1,%edx - xorl $REQUIRED_MASK1,%edx + andl $REQUIRED_MASK0,%edx + xorl $REQUIRED_MASK0,%edx jnz bad -#endif /* REQUIRED_MASK1 */ +#endif /* REQUIRED_MASK0 */ popfl xor %eax,%eax
arch/x86_64/kernel/setup.c +7 -6
@@ -931,7 +931,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)"fpu" ,"vme" ,"de" ,"pse" ,"tsc" ,"msr" ,"pae" ,"mce" ,"cx8" ,"apic" ,NULL ,"sep" ,"mtrr" ,"pge" ,"mca" ,"cmov" ,"pat" ,"pse36" ,"pn" ,"clflush" ,NULL ,"dts" ,"acpi" ,"mmx" , -"fxsr" ,"sse" ,"sse2" ,"ss" ,"ht" ,"tm" ,"ia64" ,NULL , +"fxsr" ,"sse" ,"sse2" ,"ss" ,"ht" ,"tm" ,"ia64" ,"pbe" ,/* AMD-defined */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -947,10 +947,11 @@ static int show_cpuinfo(struct seq_file *m, void *v)NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,/* Other (Linux-defined) */ -"cxmmx" ,NULL ,"cyrix_arr" ,"centaur_mcr" ,NULL , -"constant_tsc" ,NULL ,NULL , -"up" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +"cxmmx" ,"k6_mtrr" ,"cyrix_arr" ,"centaur_mcr" , +NULL ,NULL ,NULL ,NULL , +"constant_tsc" ,"up" ,NULL ,"arch_perfmon" , +"pebs" ,"bts" ,NULL ,"sync_rdtsc" , +"rep_good" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , /* Intel-defined (#2) */
@@ -961,7 +962,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)/* VIA/Cyrix/Centaur-defined */ NULL ,NULL ,"rng" ,"rng_en" ,NULL ,NULL ,"ace" ,"ace_en" , -NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +"ace2" ,"ace2_en" ,"phe" ,"phe_en" ,"pmm" ,"pmm_en" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
arch/x86_64/kernel/verify_cpu.S +4 -18
@@ -37,20 +37,6 @@ verify_cpu: pushl $0 # Kill any dangerous flags popfl - /* minimum CPUID flags for x86-64 as defined by AMD */ -#define M(x) (1<<(x)) -#define M2(a,b) M(a)|M(b) -#define M4(a,b,c,d) M(a)|M(b)|M(c)|M(d) - -#define SSE_MASK \ - (M2(X86_FEATURE_XMM,X86_FEATURE_XMM2)) -#define REQUIRED_MASK1 \ - (M4(X86_FEATURE_FPU,X86_FEATURE_PSE,X86_FEATURE_TSC,X86_FEATURE_MSR)|\ - M4(X86_FEATURE_PAE,X86_FEATURE_CX8,X86_FEATURE_PGE,X86_FEATURE_CMOV)|\ - M(X86_FEATURE_FXSR)) -#define REQUIRED_MASK2 \ - (M(X86_FEATURE_LM - 32)) - pushfl # standard way to check for cpuid popl %eax movl %eax,%ebx
@@ -79,8 +65,8 @@ verify_cpu: verify_cpu_noamd: movl $0x1,%eax # Does the cpu have what it takes cpuid - andl $REQUIRED_MASK1,%edx - xorl $REQUIRED_MASK1,%edx + andl $REQUIRED_MASK0,%edx + xorl $REQUIRED_MASK0,%edx jnz verify_cpu_no_longmode movl $0x80000000,%eax # See if extended cpuid is implemented
@@ -90,8 +76,8 @@ verify_cpu_noamd: movl $0x80000001,%eax # Does the cpu have what it takes cpuid - andl $REQUIRED_MASK2,%edx - xorl $REQUIRED_MASK2,%edx + andl $REQUIRED_MASK1,%edx + xorl $REQUIRED_MASK1,%edx jnz verify_cpu_no_longmode verify_cpu_sse_test:
include/asm-i386/cpufeature.h +12 -5
@@ -81,6 +81,7 @@#define X86_FEATURE_BTS (3*32+13)/* Branch Trace Store */ #define X86_FEATURE_LAPIC_TIMER_BROKEN (3*32+ 14)/* lapic timer broken in C1 */ #define X86_FEATURE_SYNC_RDTSC (3*32+15)/* RDTSC synchronizes the CPU */ +#define X86_FEATURE_REP_GOOD (3*32+16)/* rep microcode works well on this CPU */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
@@ -108,11 +109,17 @@#define X86_FEATURE_LAHF_LM (6*32+ 0)/* LAHF/SAHF in long mode */ #define X86_FEATURE_CMP_LEGACY (6*32+ 1)/* If yes HyperThreading not valid */ -#define cpu_has (c, bit) \ - ((__builtin_constant_p(bit) && (bit) < 32 && \ - (1UL << (bit)) & REQUIRED_MASK1) ? \ - 1 : \ - test_bit(bit, (c)->x86_capability)) +#define cpu_has (c, bit) \ + (__builtin_constant_p(bit) && \ + ( (((bit)>>5)==0 && (1UL<<((bit)&31) & REQUIRED_MASK0)) || \ + (((bit)>>5)==1 && (1UL<<((bit)&31) & REQUIRED_MASK1)) || \ + (((bit)>>5)==2 && (1UL<<((bit)&31) & REQUIRED_MASK2)) || \ + (((bit)>>5)==3 && (1UL<<((bit)&31) & REQUIRED_MASK3)) || \ + (((bit)>>5)==4 && (1UL<<((bit)&31) & REQUIRED_MASK4)) || \ + (((bit)>>5)==5 && (1UL<<((bit)&31) & REQUIRED_MASK5)) || \ + (((bit)>>5)==6 && (1UL<<((bit)&31) & REQUIRED_MASK6)) ) \ + ? 1 : \ + test_bit(bit, (c)->x86_capability))#define boot_cpu_has (bit) cpu_has(&boot_cpu_data, bit)#define cpu_has_fpu boot_cpu_has(X86_FEATURE_FPU)
include/asm-i386/required-features.h +29 -9
@@ -3,32 +3,52 @@/* Define minimum CPUID feature set for kernel These bits are checked really early to actually display a visible error message before the -kernel dies. Only add word 0 bits here +kernel dies. Make sure to assign features to the proper mask! Some requirements that are not in CPUID yet are also in the -CONFIG_X86_MINIMUM_CPU mode which is checked too. +CONFIG_X86_MINIMUM_CPU_FAMILY which is checked too. The real information is in arch/i386/Kconfig.cpu, this just converts the CONFIGs into a bitmask */ +#ifndef CONFIG_MATH_EMULATION +# define NEED_FPU (1<<(X86_FEATURE_FPU & 31)) +#else +# define NEED_FPU 0 +#endif +#ifdef CONFIG_X86_PAE -#define NEED_PAE (1<<X86_FEATURE_PAE) +# define NEED_PAE (1<<(X86_FEATURE_PAE & 31))#else -#define NEED_PAE 0 +# define NEED_PAE 0#endif #ifdef CONFIG_X86_CMOV -#define NEED_CMOV (1<<X86_FEATURE_CMOV) +# define NEED_CMOV (1<<(X86_FEATURE_CMOV & 31))#else -#define NEED_CMOV 0 +# define NEED_CMOV 0#endif #ifdef CONFIG_X86_CMPXCHG64 -#define NEED_CMPXCHG64 (1<<X86_FEATURE_CX8) +# define NEED_CX8 (1<<(X86_FEATURE_CX8 & 31)) +#else +# define NEED_CX8 0 +#endif + +#define REQUIRED_MASK0 (NEED_FPU|NEED_PAE|NEED_CMOV|NEED_CX8) + +#ifdef CONFIG_X86_USE_3DNOW +# define NEED_3DNOW (1<<(X86_FEATURE_3DNOW & 31))#else -#define NEED_CMPXCHG64 0 +# define NEED_3DNOW 0#endif -#define REQUIRED_MASK1 (NEED_PAE|NEED_CMOV|NEED_CMPXCHG64) +#define REQUIRED_MASK1 (NEED_3DNOW) + +#define REQUIRED_MASK2 0 +#define REQUIRED_MASK3 0 +#define REQUIRED_MASK4 0 +#define REQUIRED_MASK5 0 +#define REQUIRED_MASK6 0#endif
include/asm-x86_64/alternative.h +35 -33
80 lines not on this page · raw message
include/asm-x86_64/cpufeature.h +12 -103
127 lines not on this page · raw message
include/asm-x86_64/processor.h +0 -2
@@ -368,8 +368,6 @@ static inline void sync_core(void) asmvolatile ("cpuid" :"=a" (tmp) :"0" (1 ) :"ebx" ,"ecx" ,"edx" ,"memory" ); } -#define cpu_has_fpu 1 -#define ARCH_HAS_PREFETCH static inline void prefetch (void *x) {
include/asm-x86_64/required-features.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 5/33 Change CONFIG_X86_MINIMUM_CPU_MODEL to CONFIG_X86_MINIMUM_CPU_FAMILY
From: H. Peter Anvin <[email protected]>
CONFIG_X86_MINIMUM_CPU_MODEL, so change it to CONFIG_X86_MINIMUM_CPU_FAMILY. Also, the default minimum should be 3, not 0.
--- arch/i386/Kconfig.cpu | 6 +++--- arch/i386/kernel/verify_cpu.S | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/i386/Kconfig.cpu +3 -3
@@ -344,8 +344,8 @@ config X86_CMOV depends on (MK7 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7) default y -config X86_MINIMUM_CPU_MODEL +config X86_MINIMUM_CPU_FAMILY int - default "4" if X86_XADD || X86_CMPXCHG || X86_BSWAP - default "0" + default "4" if X86_XADD || X86_CMPXCHG || X86_BSWAP || X86_WP_WORKS_OK + default "3"
arch/i386/kernel/verify_cpu.S +2 -2
@@ -9,7 +9,7 @@ verify_cpu: pushl $0 # Kill any dangerous flags popfl -#if CONFIG_X86_MINIMUM_CPU_MODEL >= 4 +#if CONFIG_X86_MINIMUM_CPU_FAMILY >= 4 pushfl pop %eax orl $(1<<18),%eax # try setting AC
@@ -75,7 +75,7 @@ verify_cpu: movl $0x1,%eax # Does the cpu have what it takes cpuid -#if CONFIG_X86_MINIMUM_CPU_MODEL > 4 +#if CONFIG_X86_MINIMUM_CPU_FAMILY > 4 #error add proper model checking here #endif
Signature · 1 line
1.5.2.2
PATCH 6/33 Clean up struct screen_info (<linux/screen_info.h>)
From: H. Peter Anvin <[email protected]>
struct screen_info has unaligned members, it needs to be packed. In the process, fix the naming of some of the members, which don't belong in this structure but are part of it anyway.
--- include/linux/screen_info.h | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
include/linux/screen_info.h +4 -5
@@ -10,7 +10,7 @@struct screen_info {u8 orig_x;/* 0x00 */ u8 orig_y;/* 0x01 */ -u16 dontuse1;/* 0x02 -- EXT_MEM_K sits here */ +u16 ext_mem_k;/* 0x02 */ u16 orig_video_page;/* 0x04 */ u8 orig_video_mode;/* 0x06 */ u8 orig_video_cols;/* 0x07 */
@@ -27,7 +27,7 @@ struct screen_info {u16 lfb_depth;/* 0x16 */ u32 lfb_base;/* 0x18 */ u32 lfb_size;/* 0x1c */ -u16 dontuse2, dontuse3;/* 0x20 -- CL_MAGIC and CL_OFFSET here */ +u16 cl_magic, cl_offset;/* 0x20 */ u16 lfb_linelength;/* 0x24 */ u8 red_size;/* 0x26 */ u8 red_pos;/* 0x27 */
@@ -42,9 +42,8 @@ struct screen_info {u16 pages;/* 0x32 */ u16 vesa_attributes;/* 0x34 */ u32 capabilities;/* 0x36 */ -/* 0x3a -- 0x3b reserved for future expansion */ -/* 0x3c -- 0x3f micro stack for relocatable kernels */ -}; +u8 _reserved[6 ];/* 0x3a */ +} __attribute__((packed));extern struct screen_info screen_info;
Signature · 1 line
1.5.2.2
PATCH 7/33 Use a new CPU feature word to cover all Intel features that are spread around
From: Venki Pallipadi <[email protected]>
in different CPUID leafs like 0x5, 0x6 and 0xA. Make this feature detection code common across i386 and x86_64.
Display Intel Dynamic Acceleration feature in /proc/cpuinfo. This feature will be enabled automatically by current acpi-cpufreq driver.
Refer to Intel Software Developer's Manual for more details about the feature.
Thanks to hpa (H Peter Anvin) for the making the actual code detecting the scattered features data-driven.
--- arch/i386/kernel/cpu/Makefile | 2 +- arch/i386/kernel/cpu/addon_cpuid_features.c | 50 +++++++++++++++++++++++++++ arch/i386/kernel/cpu/common.c | 2 + arch/i386/kernel/cpu/proc.c | 6 +++ arch/x86_64/kernel/Makefile | 2 + arch/x86_64/kernel/setup.c | 8 ++++ include/asm-i386/cpufeature.h | 11 +++++- include/asm-i386/processor.h | 1 + include/asm-i386/required-features.h | 1 + include/asm-x86_64/processor.h | 1 + include/asm-x86_64/required-features.h | 1 + 11 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 arch/i386/kernel/cpu/addon_cpuid_features.c
arch/i386/kernel/cpu/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-y += amd.o obj-y += cyrix.o obj-y += centaur.o obj-y += transmeta.o -obj-y += intel.o intel_cacheinfo.o +obj-y += intel.o intel_cacheinfo.o addon_cpuid_features.o obj-y += rise.o obj-y += nexgen.o obj-y += umc.o
arch/i386/kernel/cpu/addon_cpuid_features.c new file +50 -0
50 lines not on this page · raw message
arch/i386/kernel/cpu/common.c +2 -0
@@ -353,6 +353,8 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 * c)if ( xlvl >=0x80000004 )get_model_name (c);/* Default name */ } + +init_scattered_cpuid_features (c); }early_intel_workaround (c);
arch/i386/kernel/cpu/proc.c +6 -0
@@ -65,6 +65,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)"osvw" ,"ibs" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , + +/* Auxiliary (Linux-defined) */ +"ida" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, };static const char *const x86_power_flags[] = { "ts", /* temperature sensor */
arch/x86_64/kernel/Makefile +2 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_PCI) += early-quirks.o obj-y += topology.o obj-y += intel_cacheinfo.o +obj-y += addon_cpuid_features.o obj-y += pcspeaker.o CFLAGS_vsyscall.o := $(PROFILING) -g0
@@ -55,6 +56,7 @@ cpuid-$(subst m,y,$(CONFIG_X86_CPUID)) += ../../i386/kernel/cpuid.o topology-y += ../../i386/kernel/topology.o microcode-$(subst m,y,$(CONFIG_MICROCODE)) += ../../i386/kernel/microcode.o intel_cacheinfo-y += ../../i386/kernel/cpu/intel_cacheinfo.o +addon_cpuid_features-y += ../../i386/kernel/cpu/addon_cpuid_features.o quirks-y += ../../i386/kernel/quirks.o i8237-y += ../../i386/kernel/i8237.o msr-$(subst m,y,$(CONFIG_X86_MSR)) += ../../i386/kernel/msr.o
arch/x86_64/kernel/setup.c +8 -0
@@ -846,6 +846,8 @@ void __cpuinit identify_cpu(struct cpuinfo_x86 *c) c->x86_capability[2 ] =cpuid_edx (0x80860001 ); } +init_scattered_cpuid_features (c); + c->apicid =phys_pkg_id (0 );/*
@@ -973,6 +975,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)"osvw" ,"ibs" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , + +/* Auxiliary (Linux-defined) */ +"ida" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, };static char *x86_power_flags[] = { "ts", /* temperature sensor */
include/asm-i386/cpufeature.h +9 -2
@@ -12,7 +12,7 @@#endif #include <asm/required-features.h> -#define NCAPINTS 7/* N 32-bit words worth of info */ +#define NCAPINTS 8/* N 32-bit words worth of info */ /* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */ #define X86_FEATURE_FPU (0*32+ 0)/* Onboard FPU */
@@ -109,6 +109,12 @@#define X86_FEATURE_LAHF_LM (6*32+ 0)/* LAHF/SAHF in long mode */ #define X86_FEATURE_CMP_LEGACY (6*32+ 1)/* If yes HyperThreading not valid */ +/* +* Auxiliary flags: Linux defined - For features scattered in various +* CPUID levels like 0x6, 0xA etc +*/ +#define X86_FEATURE_IDA (7*32+ 0)/* Intel Dynamic Acceleration */ +#define cpu_has (c, bit) \ (__builtin_constant_p(bit) && \ ( (((bit)>>5)==0 && (1UL<<((bit)&31) & REQUIRED_MASK0)) || \
@@ -117,7 +123,8 @@ (((bit)>>5)==3 && (1UL<<((bit)&31) & REQUIRED_MASK3)) || \ (((bit)>>5)==4 && (1UL<<((bit)&31) & REQUIRED_MASK4)) || \ (((bit)>>5)==5 && (1UL<<((bit)&31) & REQUIRED_MASK5)) || \ - (((bit)>>5)==6 && (1UL<<((bit)&31) & REQUIRED_MASK6)) ) \ + (((bit)>>5)==6 && (1UL<<((bit)&31) & REQUIRED_MASK6)) || \ + (((bit)>>5)==7 && (1UL<<((bit)&31) & REQUIRED_MASK7)) ) \ ? 1 : \ test_bit(bit, (c)->x86_capability))#define boot_cpu_has (bit) cpu_has(&boot_cpu_data, bit)
include/asm-i386/processor.h +1 -0
@@ -119,6 +119,7 @@ void __init cpu_detect(struct cpuinfo_x86 *c);extern void identify_boot_cpu (void );extern void identify_secondary_cpu (struct cpuinfo_x86 *);extern void print_cpu_info (struct cpuinfo_x86 *); +extern void init_scattered_cpuid_features (struct cpuinfo_x86 *c);extern unsigned int init_intel_cacheinfo (struct cpuinfo_x86 *c);extern unsigned short num_cache_leaves;
include/asm-i386/required-features.h +1 -0
@@ -50,5 +50,6 @@#define REQUIRED_MASK4 0#define REQUIRED_MASK5 0#define REQUIRED_MASK6 0 +#define REQUIRED_MASK7 0#endif
include/asm-x86_64/processor.h +1 -0
@@ -100,6 +100,7 @@ extern char ignore_irq13;extern void identify_cpu (struct cpuinfo_x86 *);extern void print_cpu_info (struct cpuinfo_x86 *); +extern void init_scattered_cpuid_features (struct cpuinfo_x86 *c);extern unsigned int init_intel_cacheinfo (struct cpuinfo_x86 *c);extern unsigned short num_cache_leaves;
include/asm-x86_64/required-features.h +1 -0
@@ -41,5 +41,6 @@#define REQUIRED_MASK4 0#define REQUIRED_MASK5 0#define REQUIRED_MASK6 0 +#define REQUIRED_MASK7 0#endif
Signature · 1 line
1.5.2.2
PATCH 8/33 Define zero-page offset 0x1e4 as a scratch field, and use it
From: H. Peter Anvin <[email protected]>
The relocatable kernel code needs a scratch field for the decompressor to determine its own location. It was using a location inside struct screen_info; reserve a free location and document it as scratch instead.
--- Documentation/i386/zero-page.txt | 1 + arch/i386/boot/compressed/head.S | 6 +++--- arch/x86_64/boot/compressed/head.S | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-)
Documentation/i386/zero-page.txt +1 -0
@@ -37,6 +37,7 @@ Offset Type Description 0x1d0 unsigned long EFI memory descriptor map pointer 0x1d4 unsigned long EFI memory descriptor map size 0x1e0 unsigned long ALT_MEM_K, alternative mem check, in Kb +0x1e4 unsigned long Scratch field for the kernel setup code 0x1e8 char number of entries in E820MAP (below) 0x1e9 unsigned char number of entries in EDDBUF (below) 0x1ea unsigned char number of entries in EDD_MBR_SIG_BUFFER (below)
arch/i386/boot/compressed/head.S +3 -3
@@ -45,10 +45,10 @@ startup_32: * at and where we were actually loaded at. This can only be done * with a short local call on x86. Nothing else will tell us what * address we are running at. The reserved chunk of the real-mode - * data at 0x34-0x3f are used as the stack for this calculation. - * Only 4 bytes are needed. + * data at 0x1e4 (defined as a scratch field) are used as the stack + * for this calculation. Only 4 bytes are needed. */ - leal 0x40(%esi), %esp + leal (0x1e4+4)(%esi), %esp call 1f 1: popl %ebp subl $1b, %ebp
arch/x86_64/boot/compressed/head.S +3 -3
@@ -46,10 +46,10 @@ startup_32: * at and where we were actually loaded at. This can only be done * with a short local call on x86. Nothing else will tell us what * address we are running at. The reserved chunk of the real-mode - * data at 0x34-0x3f are used as the stack for this calculation. - * Only 4 bytes are needed. + * data at 0x1e4 (defined as a scratch field) are used as the stack + * for this calculation. Only 4 bytes are needed. */ - leal 0x40(%esi), %esp + leal (0x1e4+4)(%esi), %esp call 1f 1: popl %ebp subl $1b, %ebp
Signature · 1 line
1.5.2.2
PATCH 9/33 Make definitions for struct e820entry and struct e820map consistent
From: H. Peter Anvin <[email protected]>
Make definitions for struct e820entry and struct e820map consistent between i386 and x86-64.
--- arch/i386/kernel/e820.c | 2 +- include/asm-i386/e820.h | 14 ++++++++------ include/asm-x86_64/e820.h | 6 ++++-- 3 files changed, 13 insertions(+), 9 deletions(-)
arch/i386/kernel/e820.c +1 -1
@@ -734,7 +734,7 @@ void __init print_memory_map(char *who)case E820_NVS :printk ("(ACPI NVS)\n" );break ; -default :printk ("type %lu\n" , e820.map[i].type); +default :printk ("type %u\n" , e820.map[i].type);break ; } }
include/asm-i386/e820.h +8 -6
@@ -25,13 +25,15 @@#ifndef __ASSEMBLY__ +struct e820entry { +u64 addr;/* start of memory segment */ +u64 size;/* size of memory segment */ +u32 type;/* type of memory segment */ +} __attribute__((packed)); +struct e820map { -int nr_map; -struct e820entry { -unsigned long long addr;/* start of memory segment */ -unsigned long long size;/* size of memory segment */ -unsigned long type;/* type of memory segment */ - } map[E820MAX ]; +u32 nr_map; +struct e820entry map[E820MAX ]; };extern struct e820map e820;
include/asm-x86_64/e820.h +4 -2
@@ -11,7 +11,9 @@#ifndef __E820_HEADER#define __E820_HEADER -#include <linux/mmzone.h> +#ifndef _SETUP +# include <linux/mmzone.h> +#endif #define E820MAP 0x2d0/* our map */ #define E820MAX 128/* number of entries in E820MAP */
@@ -30,7 +32,7 @@ struct e820entry { } __attribute__((packed));struct e820map { -int nr_map; +u32 nr_map;struct e820entry map[E820MAX ]; };
Signature · 1 line
1.5.2.2
PATCH 10/33 Make struct boot_params a real structure, and remove obsolete fields
From: H. Peter Anvin <[email protected]>
Make struct boot_params a real structure, and remove the handling of some obsolete fields, in particular hd*_info, which was only used by the ST-506 driver, and likely to be wrong for that driver on any modern BIOS.
--- arch/i386/kernel/setup.c | 12 +----- include/asm-i386/bootparam.h | 85 ++++++++++++++++++++++++++++++++++++++++ include/asm-i386/setup.h | 10 +++-- include/asm-x86_64/boot.h | 16 +------- include/asm-x86_64/bootparam.h | 1 + 5 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 include/asm-i386/bootparam.h create mode 100644 include/asm-x86_64/bootparam.h
arch/i386/kernel/setup.c +1 -11
@@ -102,19 +102,10 @@ static unsigned int highmem_pages = -1;/* * Setup options */ -struct drive_info_struct {char dummy[32 ]; } drive_info; -#if defined(CONFIG_BLK_DEV_IDE ) || defined(CONFIG_BLK_DEV_HD ) || \ - defined(CONFIG_BLK_DEV_IDE_MODULE ) || defined(CONFIG_BLK_DEV_HD_MODULE ) -EXPORT_SYMBOL (drive_info); -#endif struct screen_info screen_info;EXPORT_SYMBOL (screen_info);struct apm_info apm_info;EXPORT_SYMBOL (apm_info); -struct sys_desc_table_struct { -unsigned short length; -unsigned char table[0 ]; -};struct edid_info edid_info;EXPORT_SYMBOL_GPL (edid_info);struct ist_info ist_info;
@@ -134,7 +125,7 @@ unsigned long saved_videomode;static char __initdata command_line[COMMAND_LINE_SIZE ]; -unsigned char __initdata boot_params[PARAM_SIZE ]; +struct boot_params __initdata boot_params;#if defined(CONFIG_EDD ) || defined(CONFIG_EDD_MODULE )struct edd edd;
@@ -528,7 +519,6 @@ void __init setup_arch(char **cmdline_p)#endif ROOT_DEV =old_decode_dev (ORIG_ROOT_DEV ); - drive_info =DRIVE_INFO ; screen_info =SCREEN_INFO ; edid_info =EDID_INFO ; apm_info.bios =APM_BIOS_INFO ;
include/asm-i386/bootparam.h new file +85 -0
85 lines not on this page · raw message
include/asm-i386/setup.h +6 -4
@@ -26,12 +26,15 @@#define NEW_CL_POINTER 0x228/* Relative to real mode data */ #ifndef __ASSEMBLY__ + +#include <asm/bootparam.h> +/* * This is set up by the setup-routine at boot-time */ -extern unsigned char boot_params[PARAM_SIZE ]; +extern struct boot_params boot_params; -#define PARAM (boot_params) +#define PARAM ((char *)&boot_params)#define SCREEN_INFO (*(struct screen_info *) (PARAM+0))#define EXT_MEM_K (*(unsigned short *) (PARAM+2))#define ALT_MEM_K (*(unsigned long *) (PARAM+0x1e0))
@@ -39,8 +42,7 @@ extern unsigned char boot_params[PARAM_SIZE];#define E820_MAP ((struct e820entry *) (PARAM+E820MAP))#define APM_BIOS_INFO (*(struct apm_bios_info *) (PARAM+0x40))#define IST_INFO (*(struct ist_info *) (PARAM+0x60)) -#define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80)) -#define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0)) +#define SYS_DESC_TABLE (*(struct sys_desc_table *)(PARAM+0xa0))#define EFI_SYSTAB ((efi_system_table_t *) *((unsigned long *)(PARAM+0x1c4)))#define EFI_MEMDESC_SIZE (*((unsigned long *) (PARAM+0x1c8)))#define EFI_MEMDESC_VERSION (*((unsigned long *) (PARAM+0x1cc)))
include/asm-x86_64/boot.h +1 -15
@@ -1,15 +1 @@ -#ifndef _LINUX_BOOT_H -#define _LINUX_BOOT_H - -/* Don't touch these, unless you really know what you're doing. */ -#define DEF_INITSEG 0x9000 -#define DEF_SYSSEG 0x1000 -#define DEF_SETUPSEG 0x9020 -#define DEF_SYSSIZE 0x7F00 - -/* Internal svga startup constants */ -#define NORMAL_VGA 0xffff/* 80x25 mode */ -#define EXTENDED_VGA 0xfffe/* 80x50 mode */ -#define ASK_VGA 0xfffd/* ask for it at bootup */ - -#endif +#include <asm-i386/boot.h>
include/asm-x86_64/bootparam.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-i386/bootparam.h>
Signature · 1 line
1.5.2.2
PATCH 11/33 x86-64: add CONFIG_PHYSICAL_ALIGN for consistency with i386
From: H. Peter Anvin <[email protected]>
Add CONFIG_PHYSICAL_ALIGN (currently as a hardcoded constant) to provide consistency with i386. This value is manifest in the bzImage header.
--- arch/x86_64/Kconfig | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86_64/Kconfig +4 -0
@@ -427,6 +427,10 @@ config NR_CPUS This is purely to save memory - each supported CPU requires memory in the static kernel configuration. +config PHYSICAL_ALIGN + hex + default "0x200000" + config HOTPLUG_CPU bool "Support for suspend on SMP and hot-pluggable CPUs (EXPERIMENTAL)" depends on SMP && HOTPLUG && EXPERIMENTAL
Signature · 1 line
1.5.2.2
PATCH 12/33 x86-64: add symbolic constants for the boot segment selectors
From: H. Peter Anvin <[email protected]>
Add symbolic constants for the segment selectors/GDT slots used by the setup code, for consistency with i386.
--- include/asm-x86_64/segment.h | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
include/asm-x86_64/segment.h +8 -0
@@ -3,6 +3,14 @@#include <asm/cache.h> +/* Simple and small GDT entries for booting only */ + +#define GDT_ENTRY_BOOT_CS 2 +#define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8) + +#define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1) +#define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8) +#define __KERNEL_CS 0x10#define __KERNEL_DS 0x18
Signature · 1 line
1.5.2.2
PATCH 13/33 Header file to produce 16-bit code with gcc
From: H. Peter Anvin <[email protected]>
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate 16-bit (real-mode) code. This header file provides the assembly prefix.
--- arch/i386/boot/code16gcc.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/code16gcc.h
arch/i386/boot/code16gcc.h new file +9 -0
@@ -0,0 +1,9 @@ +/* +* code16gcc.h +* +* This file is -include'd when compiling 16-bit C code. +*/ + +#ifndef __ASSEMBLY__ +asm(".code16gcc" ); +#endif
Signature · 1 line
1.5.2.2
PATCH 14/33 Top header file for new x86 setup code
From: H. Peter Anvin <[email protected]>
Top header file for the new x86 setup code.
--- arch/i386/boot/boot.h | 290 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 290 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/boot.h
arch/i386/boot/boot.h new file +290 -0
@@ -0,0 +1,290 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/boot.h +* +* Header file for the real-mode kernel code +*/ + +#ifndef BOOT_BOOT_H +#define BOOT_BOOT_H + +#ifndef __ASSEMBLY__ + +#include <stdarg.h> +#include <linux/types.h> +#include <linux/edd.h> +#include <asm/boot.h> +#include <asm/bootparam.h> + +/* Useful macros */ +#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2*!!(condition)])) + +extern struct setup_header hdr; +extern struct boot_params boot_params; + +/* Basic port I/O */ +static inline void outb (u8 v,u16 port) +{ + asmvolatile ("outb %0,%1" : :"a" (v),"dN" (port)); +} +static inline u8 inb (u16 port) +{ +u8 v; + asmvolatile ("inb %1,%0" :"=a" (v) :"dN" (port)); +return v; +} + +static inline void outw (u16 v,u16 port) +{ + asmvolatile ("outw %0,%1" : :"a" (v),"dN" (port)); +} +static inline u16 inw (u16 port) +{ +u16 v; + asmvolatile ("inw %1,%0" :"=a" (v) :"dN" (port)); +return v; +} + +static inline void outl (u32 v,u16 port) +{ + asmvolatile ("outl %0,%1" : :"a" (v),"dn" (port)); +} +static inline u32 inl (u32 port) +{ +u32 v; + asmvolatile ("inl %1,%0" :"=a" (v) :"dN" (port)); +return v; +} + +static inline void io_delay (void ) +{ +const u16 DELAY_PORT =0x80 ; + asmvolatile ("outb %%al,%0" : :"dN" (DELAY_PORT )); +} + +/* These functions are used to reference data in other segments. */ + +static inline u16 ds (void ) +{ +u16 seg; + asm("movw %%ds,%0" :"=rm" (seg)); +return seg; +} + +static inline void set_fs (u16 seg) +{ + asmvolatile ("movw %0,%%fs" : :"rm" (seg)); +} +static inline u16 fs (void ) +{ +u16 seg; + asm("movw %%fs,%0" :"=rm" (seg)); +return seg; +} + +static inline void set_gs (u16 seg) +{ + asmvolatile ("movw %0,%%gs" : :"rm" (seg)); +} +static inline u16 gs (void ) +{ +u16 seg; + asm("movw %%gs,%0" :"=rm" (seg)); +return seg; +} + +typedef unsigned int addr_t ; + +static inline u8 rdfs8 (addr_t addr) +{ +u8 v; + asm("movb %%fs:%1,%0" :"=r" (v) :"m" (*(u8 *)addr)); +return v; +} +static inline u16 rdfs16 (addr_t addr) +{ +u16 v; + asm("movw %%fs:%1,%0" :"=r" (v) :"m" (*(u16 *)addr)); +return v; +} +static inline u32 rdfs32 (addr_t addr) +{ +u32 v; + asm("movl %%fs:%1,%0" :"=r" (v) :"m" (*(u32 *)addr)); +return v; +} + +static inline void wrfs8 (u8 v,addr_t addr) +{ + asmvolatile ("movb %1,%%fs:%0" :"+m" (*(u8 *)addr) :"r" (v)); +} +static inline void wrfs16 (u16 v,addr_t addr) +{ + asmvolatile ("movw %1,%%fs:%0" :"+m" (*(u16 *)addr) :"r" (v)); +} +static inline void wrfs32 (u32 v,addr_t addr) +{ + asmvolatile ("movl %1,%%fs:%0" :"+m" (*(u32 *)addr) :"r" (v)); +} + +static inline u8 rdgs8 (addr_t addr) +{ +u8 v; + asm("movb %%gs:%1,%0" :"=r" (v) :"m" (*(u8 *)addr)); +return v; +} +static inline u16 rdgs16 (addr_t addr) +{ +u16 v; + asm("movw %%gs:%1,%0" :"=r" (v) :"m" (*(u16 *)addr)); +return v; +} +static inline u32 rdgs32 (addr_t addr) +{ +u32 v; + asm("movl %%gs:%1,%0" :"=r" (v) :"m" (*(u32 *)addr)); +return v; +} + +static inline void wrgs8 (u8 v,addr_t addr) +{ + asmvolatile ("movb %1,%%gs:%0" :"+m" (*(u8 *)addr) :"r" (v)); +} +static inline void wrgs16 (u16 v,addr_t addr) +{ + asmvolatile ("movw %1,%%gs:%0" :"+m" (*(u16 *)addr) :"r" (v)); +} +static inline void wrgs32 (u32 v,addr_t addr) +{ + asmvolatile ("movl %1,%%gs:%0" :"+m" (*(u32 *)addr) :"r" (v)); +} + +/* Note: these only return true/false, not a signed return value! */ +static inline int memcmp (const void *s1,const void *s2,size_t len) +{ +u8 diff; + asm("repe; cmpsb; setnz %0" + :"=qm" (diff),"+D" (s1),"+S" (s2),"+c" (len)); +return diff; +} + +static inline int memcmp_fs (const void *s1,addr_t s2,size_t len) +{ +u8 diff; + asm("fs; repe; cmpsb; setnz %0" + :"=qm" (diff),"+D" (s1),"+S" (s2),"+c" (len)); +return diff; +} +static inline int memcmp_gs (const void *s1,addr_t s2,size_t len) +{ +u8 diff; + asm("gs; repe; cmpsb; setnz %0" + :"=qm" (diff),"+D" (s1),"+S" (s2),"+c" (len)); +return diff; +} + +/* Heap -- available for dynamic lists. */ +#define STACK_SIZE 512/* Minimum number of bytes for stack */ + +extern char _end[]; +extern char *HEAP ; +extern char *heap_end; +#define RESET_HEAP () ((void *)( HEAP = _end )) +static inline char *__get_heap (size_t s,size_t a,size_t n) +{ +char *tmp; + +HEAP = (char *)(((size_t )HEAP +(a-1 )) & ~(a-1 )); + tmp =HEAP ; +HEAP += s*n; +return tmp; +} +#define GET_HEAP (type, n) \ + ((type *)__get_heap(sizeof(type),__alignof__(type),(n))) + +static inline int heap_free (void ) +{ +return heap_end-HEAP ; +} + +/* copy.S */ + +void copy_to_fs (addr_t dst,void *src,size_t len); +void *copy_from_fs (void *dst,addr_t src,size_t len); +void copy_to_gs (addr_t dst,void *src,size_t len); +void *copy_from_gs (void *dst,addr_t src,size_t len); +void *memcpy (void *dst,void *src,size_t len); +void *memset (void *dst,int c,size_t len); + +#define memcpy (d,s,l) __builtin_memcpy(d,s,l) +#define memset (d,c,l) __builtin_memset(d,c,l) + +/* a20.c */ +int enable_a20 (void ); + +/* apm.c */ +int query_apm_bios (void ); + +/* cmdline.c */ +int cmdline_find_option (const char *option,char *buffer,int bufsize); + +/* cpu.c, cpucheck.c */ +int check_cpu (int *cpu_level_ptr,int *req_level_ptr,u32 **err_flags_ptr); +int validate_cpu (void ); + +/* edd.c */ +void query_edd (void ); + +/* header.S */ +void __attribute__((noreturn))die (void ); + +/* mca.c */ +int query_mca (void ); + +/* memory.c */ +int detect_memory (void ); + +/* pm.c */ +void __attribute__((noreturn))go_to_protected_mode (void ); + +/* pmjump.S */ +void __attribute__((noreturn)) +protected_mode_jump (u32 entrypoint,u32 bootparams); + +/* printf.c */ +unsigned int atou (const char *s); +int sprintf (char *buf,const char *fmt, ...); +int vsprintf (char *buf,const char *fmt,va_list args); +int printf (const char *fmt, ...); + +/* string.c */ +int strcmp (const char *str1,const char *str2); + +/* tty.c */ +void puts (const char *); +void putchar (int ); +int getchar (void ); +void kbd_flush (void ); +int getchar_timeout (void ); + +/* video.c */ +void set_video (void ); + +/* video-vesa.c */ +void vesa_store_edid (void ); + +/* voyager.c */ +int query_voyager (void ); + +#endif /* __ASSEMBLY__ */ + +#endif /* BOOT_BOOT_H */
Signature · 1 line
1.5.2.2
PATCH 15/33 Simple bitops for the new x86 setup code.
From: H. Peter Anvin <[email protected]>
A simple collection of bitops for the new x86 setup code.
--- arch/i386/boot/bitops.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/bitops.h
arch/i386/boot/bitops.h new file +45 -0
@@ -0,0 +1,45 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/bitops.h +* +* Very simple bitops for the boot code. +*/ + +#ifndef BOOT_BITOPS_H +#define BOOT_BITOPS_H +#define _LINUX_BITOPS_H/* Inhibit inclusion of <linux/bitops.h> */ + +static inline int constant_test_bit (int nr,const void *addr) +{ +const u32 *p = (const u32 *)addr; +return ((1UL << (nr &31 )) & (p[nr >>5 ])) !=0 ; +} +static inline int variable_test_bit (int nr,const void *addr) +{ +u8 v; +const u32 *p = (const u32 *)addr; + + asm("btl %2,%1; setc %0" :"=qm" (v) :"m" (*p),"Ir" (nr)); +return v; +} + +#define test_bit (nr,addr) \ +(__builtin_constant_p(nr) ? \ + constant_test_bit((nr),(addr)) : \ + variable_test_bit((nr),(addr))) + +static inline void set_bit (int nr,void *addr) +{ + asm("btsl %1,%0" :"+m" (*(u32 *)addr) :"Ir" (nr)); +} + +#endif /* BOOT_BITOPS_H */
Signature · 1 line
1.5.2.2
PATCH 16/33 String-handling functions for the new x86 setup code.
From: H. Peter Anvin <[email protected]>
strcmp(), memcpy(), memset(), as well as routines to copy to and from other segments (as pointed to by fs and gs).
--- arch/i386/boot/copy.S | 101 +++++++++++++++++++++++++++++++++++++++++++++++ arch/i386/boot/string.c | 34 ++++++++++++++++ 2 files changed, 135 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/copy.S create mode 100644 arch/i386/boot/string.c
arch/i386/boot/copy.S new file +101 -0
@@ -0,0 +1,101 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright (C) 1991, 1992 Linus Torvalds + * Copyright 2007 rPath, Inc. - All Rights Reserved + * + * This file is part of the Linux kernel, and is made available under + * the terms of the GNU General Public License version 2. + * + * ----------------------------------------------------------------------- */ + +/* + * arch/i386/boot/copy.S + * + * Memory copy routines + */ + + .code16gcc + .text + + .globl memcpy + .type memcpy, @function +memcpy: + pushw %si + pushw %di + movw %ax, %di + movw %dx, %si + pushw %cx + shrw $2, %cx + rep; movsl + popw %cx + andw $3, %cx + rep; movsb + popw %di + popw %si + ret + .size memcpy, .-memcpy + + .globl memset + .type memset, @function +memset: + pushw %di + movw %ax, %di + movzbl %dl, %eax + imull $0x01010101,%eax + pushw %cx + shrw $2, %cx + rep; stosl + popw %cx + andw $3, %cx + rep; stosb + popw %di + ret + .size memset, .-memset + + .globl copy_from_fs + .type copy_from_fs, @function +copy_from_fs: + pushw %ds + pushw %fs + popw %ds + call memcpy + popw %ds + ret + .size copy_from_fs, .-copy_from_fs + + .globl copy_to_fs + .type copy_to_fs, @function +copy_to_fs: + pushw %es + pushw %fs + popw %es + call memcpy + popw %es + ret + .size copy_to_fs, .-copy_to_fs + +#if 0 /* Not currently used, but can be enabled as needed */ + + .globl copy_from_gs + .type copy_from_gs, @function +copy_from_gs: + pushw %ds + pushw %gs + popw %ds + call memcpy + popw %ds + ret + .size copy_from_gs, .-copy_from_gs + .globl copy_to_gs + + .type copy_to_gs, @function +copy_to_gs: + pushw %es + pushw %gs + popw %es + call memcpy + popw %es + ret + .size copy_to_gs, .-copy_to_gs + +#endif
arch/i386/boot/string.c new file +34 -0
@@ -0,0 +1,34 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/string.c +* +* Very basic string functions +*/ + +#include "boot.h" +#include <linux/edd.h> + +int strcmp (const char *str1,const char *str2) +{ +const unsigned char *s1 = (const unsigned char *)str1; +const unsigned char *s2 = (const unsigned char *)str2; +int delta =0 ; + +while (*s1 || *s2) { + delta = *s2 - *s1; +if (delta) +return delta; + s1++; + s2++; + } +return 0 ; +}
Signature · 1 line
1.5.2.2
PATCH 17/33 A20 handling code
From: H. Peter Anvin <[email protected]>
A20 handling code for the new x86 setup code. This implements the same algorithms as the assembly version.
--- arch/i386/boot/a20.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 161 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/a20.c
arch/i386/boot/a20.c new file +161 -0
@@ -0,0 +1,161 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/a20.c +* +* Enable A20 gate (return -1 on failure) +*/ + +#include "boot.h" + +#define MAX_8042_LOOPS 100000 + +static int empty_8042 (void ) +{ +u8 status; +int loops =MAX_8042_LOOPS ; + +while (loops--) { +io_delay (); + + status =inb (0x64 ); +if (status &1 ) { +/* Read and discard input data */ +io_delay (); + (void )inb (0x60 ); + }else if (!(status &2 )) { +/* Buffers empty, finished! */ +return 0 ; + } + } + +return -1 ; +} + +/* Returns nonzero if the A20 line is enabled. The memory address +used as a test is the int $0x80 vector, which should be safe. */ + +#define A20_TEST_ADDR (4*0x80) +#define A20_TEST_SHORT 32 +#define A20_TEST_LONG 2097152/* 2^21 */ + +static int a20_test (int loops) +{ +int ok =0 ; +int saved, ctr; + +set_fs (0x0000 ); +set_gs (0xffff ); + + saved = ctr =rdfs32 (A20_TEST_ADDR ); + +while (loops--) { +wrfs32 (++ctr,A20_TEST_ADDR ); +io_delay ();/* Serialize and make delay constant */ + ok =rdgs32 (A20_TEST_ADDR +0x10 ) ^ ctr; +if (ok) +break ; + } + +wrfs32 (saved,A20_TEST_ADDR ); +return ok; +} + +/* Quick test to see if A20 is already enabled */ +static int a20_test_short (void ) +{ +return a20_test (A20_TEST_SHORT ); +} + +/* Longer test that actually waits for A20 to come on line; this +is useful when dealing with the KBC or other slow external circuitry. */ +static int a20_test_long (void ) +{ +return a20_test (A20_TEST_LONG ); +} + +static void enable_a20_bios (void ) +{ + asmvolatile ("pushfl; int $0x15; popfl" + : :"a" ((u16 )0x2401 )); +} + +static void enable_a20_kbc (void ) +{ +empty_8042 (); + +outb (0xd1 ,0x64 );/* Command write */ +empty_8042 (); + +outb (0xdf ,0x60 );/* A20 on */ +empty_8042 (); +} + +static void enable_a20_fast (void ) +{ +u8 port_a; + + port_a =inb (0x92 );/* Configuration port A */ + port_a |=0x02 ;/* Enable A20 */ + port_a &= ~0x01 ;/* Do not reset machine */ +outb (port_a,0x92 ); +} + +/* +* Actual routine to enable A20; return 0 on ok, -1 on failure +*/ + +#define A20_ENABLE_LOOPS 255/* Number of times to try */ + +int enable_a20 (void ) +{ +int loops =A20_ENABLE_LOOPS ; + +#if defined(CONFIG_X86_ELAN ) +/* Elan croaks if we try to touch the KBC */ +enable_a20_fast (); +while (!a20_test_long ()) + ; +return 0 ; +#elif defined(CONFIG_X86_VOYAGER ) +/* On Voyager, a20_test() is unsafe? */ +enable_a20_kbc (); +return 0 ; +#else +while (loops--) { +/* First, check to see if A20 is already enabled +(legacy free, etc.) */ +if (a20_test_short ()) +return 0 ; + +/* Next, try the BIOS (INT 0x15, AX=0x2401) */ +enable_a20_bios (); +if (a20_test_short ()) +return 0 ; + +/* Try enabling A20 through the keyboard controller */ +empty_8042 (); +if (a20_test_short ()) +return 0 ;/* BIOS worked, but with delayed reaction */ + +enable_a20_kbc (); +if (a20_test_long ()) +return 0 ; + +/* Finally, try enabling the "fast A20 gate" */ +enable_a20_fast (); +if (a20_test_long ()) +return 0 ; + } + +return -1 ; +#endif +}
Signature · 1 line
1.5.2.2
PATCH 18/33 APM probing code
From: H. Peter Anvin <[email protected]>
APM probing code for the new x86 setup code. This implements the same functionality as the assembly version.
--- arch/i386/boot/apm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/apm.c
arch/i386/boot/apm.c new file +97 -0
@@ -0,0 +1,97 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* Original APM BIOS checking by Stephen Rothwell, May 1994 +* ([email protected]) +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/apm.c +* +* Get APM BIOS information +*/ + +#include "boot.h" + +#if defined(CONFIG_APM ) || defined(CONFIG_APM_MODULE ) + +int query_apm_bios (void ) +{ +u16 ax, bx, cx, dx, di; +u32 ebx, esi; +u8 err; + +/* APM BIOS installation check */ + ax =0x5300 ; + bx = cx =0 ; + asmvolatile ("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0" + :"=d" (err),"+a" (ax),"+b" (bx),"+c" (cx) + : :"esi" ,"edi" ); + +if (err) +return -1 ;/* No APM BIOS */ + +if (bx !=0x504d )/* "PM" signature */ +return -1 ; + +if (cx &0x02 )/* 32 bits supported? */ +return -1 ; + +/* Disconnect first, just in case */ + ax =0x5304 ; + asmvolatile ("pushl %%ebp ; int $0x15 ; popl %%ebp" + :"+a" (ax) + : :"ebx" ,"ecx" ,"edx" ,"esi" ,"edi" ); + +/* Paranoia */ + ebx = esi =0 ; + cx = dx = di =0 ; + +/* 32-bit connect */ + asmvolatile ("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %6" + :"=a" (ax),"+b" (ebx),"+c" (cx),"+d" (dx), +"+S" (esi),"+D" (di),"=m" (err) + :"a" (0x5303 )); + + boot_params.apm_bios_info.cseg = ax; + boot_params.apm_bios_info.offset = ebx; + boot_params.apm_bios_info.cseg_16 = cx; + boot_params.apm_bios_info.dseg = dx; + boot_params.apm_bios_info.cseg_len = (u16 )esi; + boot_params.apm_bios_info.cseg_16_len = esi >>16 ; + boot_params.apm_bios_info.dseg_len = di; + +if (err) +return -1 ; + +/* Redo the installation check as the 32-bit connect; +some BIOSes return different flags this way... */ + + ax =0x5300 ; + bx = cx =0 ; + asmvolatile ("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0" + :"=d" (err),"+a" (ax),"+b" (bx),"+c" (cx) + : :"esi" ,"edi" ); + +if (err || bx !=0x504d ) { +/* Failure with 32-bit connect, try to disconect and ignore */ + ax =0x5304 ; + bx =0 ; + asmvolatile ("pushl %%ebp ; int $0x15 ; popl %%ebp" + :"+a" (ax),"+b" (bx) + : :"ecx" ,"edx" ,"esi" ,"edi" ); +return -1 ; + } + + boot_params.apm_bios_info.version = ax; + boot_params.apm_bios_info.flags = cx; +return 0 ; +} + +#endif
Signature · 1 line
1.5.2.2
PATCH 19/33 Command-line parsing code for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Simple command-line parser which allows us to access the kernel command line from the setup code.
--- arch/i386/boot/cmdline.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/cmdline.c
arch/i386/boot/cmdline.c new file +97 -0
@@ -0,0 +1,97 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/cmdline.c +* +* Simple command-line parser for early boot. +*/ + +#include "boot.h" + +static inline int myisspace (u8 c) +{ +return c <=' ' ;/* Close enough approximation */ +} + +/* +* Find a non-boolean option, that is, "option=argument". In accordance +* with standard Linux practice, if this option is repeated, this returns +* the last instance on the command line. +* +* Returns the length of the argument (regardless of if it was +* truncated to fit in the buffer), or -1 on not found. +*/ +int cmdline_find_option (const char *option,char *buffer,int bufsize) +{ +u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr; +addr_t cptr; +char c; +int len =-1 ; +const char *opptr =NULL ; +char *bufptr = buffer; +enum { + st_wordstart,/* Start of word/after whitespace */ + st_wordcmp,/* Comparing this word */ + st_wordskip,/* Miscompare, skip */ + st_bufcpy/* Copying this to buffer */ + } state = st_wordstart; + +if (!cmdline_ptr || cmdline_ptr >=0x100000 ) +return -1 ;/* No command line, or inaccessible */ + + cptr = cmdline_ptr &0xf ; +set_fs (cmdline_ptr >>4 ); + +while (cptr <0x10000 && (c =rdfs8 (cptr++))) { +switch (state) { +case st_wordstart: +if (myisspace (c)) +break ; + +/* else */ + state = st_wordcmp; + opptr = option; +/* fall through */ + +case st_wordcmp: +if (c =='=' && !*opptr) { + len =0 ; + bufptr = buffer; + state = st_bufcpy; + }else if (myisspace (c)) { + state = st_wordstart; + }else if (c != *opptr++) { + state = st_wordskip; + } +break ; + +case st_wordskip: +if (myisspace (c)) + state = st_wordstart; +break ; + +case st_bufcpy: +if (myisspace (c)) { + state = st_wordstart; + }else { +if (len < bufsize-1 ) + *bufptr++ = c; + len++; + } +break ; + } + } + +if (bufsize) + *bufptr ='\0' ; + +return len; +}
Signature · 1 line
1.5.2.2
PATCH 20/33 Console-writing code for the new x86 setup code
From: H. Peter Anvin <[email protected]>
This implements writing text to the console, including printf().
--- arch/i386/boot/printf.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++ arch/i386/boot/tty.c | 112 ++++++++++++++++ 2 files changed, 443 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/printf.c create mode 100644 arch/i386/boot/tty.c
arch/i386/boot/printf.c new file +331 -0
@@ -0,0 +1,331 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/printf.c +* +* Oh, it's a waste of space, but oh-so-yummy for debugging. This +* version of printf() does not include 64-bit support. "Live with +* it." +* +*/ + +#include "boot.h" + +static inline int isdigit (int ch) +{ +return (ch >='0' ) && (ch <='9' ); +} + +static int skip_atoi (const char **s) +{ +int i =0 ; + +while (isdigit (**s)) + i = i *10 + *((*s)++) -'0' ; +return i; +} + +unsigned int atou (const char *s) +{ +unsigned int i =0 ; +while (isdigit (*s)) + i = i *10 + (*s++ -'0' ); +return i; +} + +static int strnlen (const char *s,int maxlen) +{ +const char *es = s; +while (*es && maxlen) { + es++; + maxlen--; + } + +return (es - s); +} + +#define ZEROPAD 1/* pad with zero */ +#define SIGN 2/* unsigned/signed long */ +#define PLUS 4/* show plus */ +#define SPACE 8/* space if plus */ +#define LEFT 16/* left justified */ +#define SPECIAL 32/* 0x */ +#define LARGE 64/* use 'ABCDEF' instead of 'abcdef' */ + +#define do_div (n,base) ({ \ +int __res; \ +__res = ((unsigned long) n) % (unsigned) base; \ +n = ((unsigned long) n) / (unsigned) base; \ +__res; }) + +static char *number (char *str,long num,int base,int size,int precision, +int type) +{ +char c, sign, tmp[66 ]; +const char *digits ="0123456789abcdefghijklmnopqrstuvwxyz" ; +int i; + +if (type &LARGE ) + digits ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; +if (type &LEFT ) + type &= ~ZEROPAD ; +if (base <2 || base >36 ) +return 0 ; + c = (type &ZEROPAD ) ?'0' :' ' ; + sign =0 ; +if (type &SIGN ) { +if (num <0 ) { + sign ='-' ; + num = -num; + size--; + }else if (type &PLUS ) { + sign ='+' ; + size--; + }else if (type &SPACE ) { + sign =' ' ; + size--; + } + } +if (type &SPECIAL ) { +if (base ==16 ) + size -=2 ; +else if (base ==8 ) + size--; + } + i =0 ; +if (num ==0 ) + tmp[i++] ='0' ; +else +while (num !=0 ) + tmp[i++] = digits[do_div (num, base)]; +if (i > precision) + precision = i; + size -= precision; +if (!(type & (ZEROPAD +LEFT ))) +while (size-- >0 ) + *str++ =' ' ; +if (sign) + *str++ = sign; +if (type &SPECIAL ) { +if (base ==8 ) + *str++ ='0' ; +else if (base ==16 ) { + *str++ ='0' ; + *str++ = digits[33 ]; + } + } +if (!(type &LEFT )) +while (size-- >0 ) + *str++ = c; +while (i < precision--) + *str++ ='0' ; +while (i-- >0 ) + *str++ = tmp[i]; +while (size-- >0 ) + *str++ =' ' ; +return str; +} + +int vsprintf (char *buf,const char *fmt,va_list args) +{ +int len; +unsigned long num; +int i, base; +char *str; +const char *s; + +int flags;/* flags to number() */ + +int field_width;/* width of output field */ +int precision;/* min. # of digits for integers; max +number of chars for from string */ +int qualifier;/* 'h', 'l', or 'L' for integer fields */ + +for (str = buf; *fmt; ++fmt) { +if (*fmt !='%' ) { + *str++ = *fmt; +continue ; + } + +/* process flags */ + flags =0 ; + repeat: + ++fmt;/* this also skips first '%' */ +switch (*fmt) { +case '-' : + flags |=LEFT ; + goto repeat; +case '+' : + flags |=PLUS ; + goto repeat; +case ' ' : + flags |=SPACE ; + goto repeat; +case '#' : + flags |=SPECIAL ; + goto repeat; +case '0' : + flags |=ZEROPAD ; + goto repeat; + } + +/* get field width */ + field_width =-1 ; +if (isdigit (*fmt)) + field_width =skip_atoi (&fmt); +else if (*fmt =='*' ) { + ++fmt; +/* it's the next argument */ + field_width =va_arg (args, int); +if (field_width <0 ) { + field_width = -field_width; + flags |=LEFT ; + } + } + +/* get the precision */ + precision =-1 ; +if (*fmt =='.' ) { + ++fmt; +if (isdigit (*fmt)) + precision =skip_atoi (&fmt); +else if (*fmt =='*' ) { + ++fmt; +/* it's the next argument */ + precision =va_arg (args, int); + } +if (precision <0 ) + precision =0 ; + } + +/* get the conversion qualifier */ + qualifier =-1 ; +if (*fmt =='h' || *fmt =='l' || *fmt =='L' ) { + qualifier = *fmt; + ++fmt; + } + +/* default base */ + base =10 ; + +switch (*fmt) { +case 'c' : +if (!(flags &LEFT )) +while (--field_width >0 ) + *str++ =' ' ; + *str++ = (unsigned char )va_arg (args, int); +while (--field_width >0 ) + *str++ =' ' ; +continue ; + +case 's' : + s = va_arg(args, char *); + len =strnlen (s, precision); + +if (!(flags &LEFT )) +while (len < field_width--) + *str++ =' ' ; +for (i =0 ; i < len; ++i) + *str++ = *s++; +while (len < field_width--) + *str++ =' ' ; +continue ; + +case 'p' : +if (field_width ==-1 ) { + field_width =2 *sizeof (void *); + flags |=ZEROPAD ; + } + str =number (str, + (unsigned long)va_arg(args, void *), 16, + field_width, precision, flags); +continue ; + +case 'n' : +if (qualifier =='l' ) { + long *ip = va_arg(args, long *); + *ip = (str - buf); + }else { + int *ip = va_arg(args, int *); + *ip = (str - buf); + } +continue ; + +case '%' : + *str++ ='%' ; +continue ; + +/* integer number formats - set up the flags and "break" */ +case 'o' : + base =8 ; +break ; + +case 'X' : + flags |=LARGE ; +case 'x' : + base =16 ; +break ; + +case 'd' : +case 'i' : + flags |=SIGN ; +case 'u' : +break ; + +default : + *str++ ='%' ; +if (*fmt) + *str++ = *fmt; +else + --fmt; +continue ; + } +if (qualifier =='l' ) + num = va_arg(args, unsigned long); +else if (qualifier =='h' ) { + num = (unsigned short )va_arg (args, int); +if (flags &SIGN ) + num = (short )num; + }else if (flags &SIGN ) + num =va_arg (args, int); +else + num = va_arg(args, unsigned int); + str =number (str, num, base, field_width, precision, flags); + } + *str ='\0' ; +return str - buf; +} + +int sprintf (char *buf,const char *fmt, ...) +{ +va_list args; +int i; + +va_start (args, fmt); + i =vsprintf (buf, fmt, args); +va_end (args); +return i; +} + +int printf (const char *fmt, ...) +{ +char printf_buf[1024 ]; +va_list args; +int printed; + +va_start (args, fmt); + printed =vsprintf (printf_buf, fmt, args); +va_end (args); + +puts (printf_buf); + +return printed; +}
arch/i386/boot/tty.c new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 21/33 Version string for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Module which only includes the kernel version string.
--- arch/i386/boot/version.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/version.c
arch/i386/boot/version.c new file +23 -0
@@ -0,0 +1,23 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/version.c +* +* Kernel version string +*/ + +#include "boot.h" +#include <linux/utsrelease.h> +#include <linux/compile.h> + +const char kernel_version[] = +UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") " +UTS_VERSION ;
Signature · 1 line
1.5.2.2
PATCH 22/33 CPU features verification for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Verify that the CPU has enough features to run the kernel. This may entail enabling features on some CPUs.
By doing this in the setup code we can be guaranteed to still be able to write to the console through the BIOS.
--- arch/i386/boot/cpu.c | 69 ++++++++++++ arch/i386/boot/cpucheck.c | 267 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 336 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/cpu.c create mode 100644 arch/i386/boot/cpucheck.c
arch/i386/boot/cpu.c new file +69 -0
@@ -0,0 +1,69 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/cpucheck.c +* +* Check for obligatory CPU features and abort if the features are not +* present. +*/ + +#include "boot.h" +#include "bitops.h" +#include <asm/cpufeature.h> + +static char *cpu_name (int level) +{ +static char buf[6 ]; + +if (level ==64 ) { +return "x86-64" ; + }else { +sprintf (buf,"i%d86" , level); +return buf; + } +} + +int validate_cpu (void ) +{ +u32 *err_flags; +int cpu_level, req_level; + +check_cpu (&cpu_level, &req_level, &err_flags); + +if (cpu_level < req_level) { +printf ("This kernel requires an %s CPU, " , +cpu_name (req_level)); +printf ("but only detected an %s CPU.\n" , +cpu_name (cpu_level)); +return -1 ; + } + +if (err_flags) { +int i, j; +puts ("This kernel requires the following features " +"not present on the CPU:\n" ); + +for (i =0 ; i <NCAPINTS ; i++) { +u32 e = err_flags[i]; + +for (j =0 ; j <32 ; j++) { +if (e &1 ) +printf ("%d:%d " , i, j); + + e >>=1 ; + } + } +putchar ('\n' ); +return -1 ; + }else { +return 0 ; + } +}
arch/i386/boot/cpucheck.c new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 23/33 EDD probing code for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Probe EDD and MBR signatures, in order to make it easier to map physical hard drives to BIOS drives.
--- arch/i386/boot/edd.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 196 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/edd.c
arch/i386/boot/edd.c new file +196 -0
@@ -0,0 +1,196 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/edd.c +* +* Get EDD BIOS disk information +*/ + +#include "boot.h" +#include <linux/edd.h> + +#if defined(CONFIG_EDD ) || defined(CONFIG_EDD_MODULE ) + +struct edd_dapa { +u8 pkt_size; +u8 rsvd; +u16 sector_cnt; +u16 buf_off, buf_seg; +u64 lba; +u64 buf_lin_addr; +}; + +/* +* Read the MBR (first sector) from a specific device. +*/ +static int read_mbr (u8 devno,void *buf) +{ +struct edd_dapa dapa; +u16 ax, bx, cx, dx, si; + +memset (&dapa,0 ,sizeof dapa); + dapa.pkt_size =sizeof (dapa); + dapa.sector_cnt =1 ; + dapa.buf_off = (size_t )buf; + dapa.buf_seg =ds (); +/* dapa.lba = 0; */ + + ax =0x4200 ;/* Extended Read */ + si = (size_t )&dapa; + dx = devno; + asm("pushfl; stc; int $0x13; setc %%al; popfl" + :"+a" (ax),"+S" (si),"+d" (dx) + :"m" (dapa) + :"ebx" ,"ecx" ,"edi" ,"memory" ); + +if (!(u8 )ax) +return 0 ;/* OK */ + + ax =0x0201 ;/* Legacy Read, one sector */ + cx =0x0001 ;/* Sector 0-0-1 */ + dx = devno; + bx = (size_t )buf; + asm("pushfl; stc; int $0x13; setc %%al; popfl" + :"+a" (ax),"+c" (cx),"+d" (dx),"+b" (bx) + : :"esi" ,"edi" ,"memory" ); + +return -(u8 )ax;/* 0 or -1 */ +} + +static u32 read_mbr_sig (u8 devno,struct edd_info *ei) +{ +int sector_size; +char *mbrbuf_ptr, *mbrbuf_end; +u32 mbrsig; +u32 buf_base, mbr_base; +extern char _end[]; +static char mbr_buf[1024 ]; + + sector_size = ei->params.bytes_per_sector; +if (!sector_size) + sector_size =512 ;/* Best available guess */ + + buf_base = (ds () <<4 ) + (u32)&_end; + mbr_base = (buf_base+sector_size-1 ) & ~(sector_size-1 ); + mbrbuf_ptr = mbr_buf + (mbr_base-buf_base); + mbrbuf_end = mbrbuf_ptr + sector_size; + +if (!(boot_params.hdr.loadflags &CAN_USE_HEAP )) +return 0 ; +if (mbrbuf_end > (char *)(size_t )boot_params.hdr.heap_end_ptr) +return 0 ; + +if (read_mbr (devno, mbrbuf_ptr)) +return 0 ; + + mbrsig = *(u32 *)&mbrbuf_ptr[EDD_MBR_SIG_OFFSET ]; +return mbrsig; +} + +static int get_edd_info (u8 devno,struct edd_info *ei) +{ +u16 ax, bx, cx, dx, di; + +memset (ei,0 ,sizeof *ei); + +/* Check Extensions Present */ + + ax =0x4100 ; + bx =EDDMAGIC1 ; + dx = devno; + asm("pushfl; stc; int $0x13; setc %%al; popfl" + :"+a" (ax),"+b" (bx),"=c" (cx),"+d" (dx) + : :"esi" ,"edi" ); + +if ((u8 )ax) +return -1 ;/* No extended information */ + +if (bx !=EDDMAGIC2 ) +return -1 ; + + ei->device = devno; + ei->version = ax >>8 ;/* EDD version number */ + ei->interface_support = cx;/* EDD functionality subsets */ + +/* Extended Get Device Parameters */ + + ei->params.length =sizeof (ei->params); + ax =0x4800 ; + dx = devno; + asm("pushfl; int $0x13; popfl" + :"+a" (ax),"+d" (dx) + :"S" (&ei->params) + :"ebx" ,"ecx" ,"edi" ); + +/* Get legacy CHS parameters */ + +/* Ralf Brown recommends setting ES:DI to 0:0 */ + ax =0x0800 ; + dx = devno; + di =0 ; + asm("pushw %%es; " +"movw %%di,%%es; " +"pushfl; stc; int $0x13; setc %%al; popfl; " +"popw %%es" + :"+a" (ax),"=b" (bx),"=c" (cx),"+d" (dx),"+D" (di) + : :"esi" ); + +if ((u8 )ax ==0 ) { + ei->legacy_max_cylinder = (cx >>8 ) + ((cx &0xc0 ) <<2 ); + ei->legacy_max_head = dx >>8 ; + ei->legacy_sectors_per_track = cx &0x3f ; + } + +return 0 ; +} + +void query_edd (void ) +{ +char eddarg[8 ]; +int do_mbr =1 ; +int do_edd =1 ; +int devno; +struct edd_info ei, *edp; + +if (cmdline_find_option ("edd" , eddarg,sizeof eddarg) >0 ) { +if (!strcmp (eddarg,"skipmbr" ) || !strcmp (eddarg,"skip" )) + do_mbr =0 ; +else if (!strcmp (eddarg,"off" )) + do_edd =0 ; + } + + edp = (struct edd_info *)boot_params.eddbuf; + +if (!do_edd) +return ; + +for (devno =0x80 ; devno <0x80 +EDD_MBR_SIG_MAX ; devno++) { +/* +* Scan the BIOS-supported hard disks and query EDD +* information... +*/ +get_edd_info (devno, &ei); + +if (boot_params.eddbuf_entries <EDDMAXNR ) { +memcpy (edp, &ei,sizeof ei); + edp++; + boot_params.eddbuf_entries++; + } + +if (do_mbr) { +u32 mbr_sig; + mbr_sig =read_mbr_sig (devno, &ei); + boot_params.edd_mbr_sig_buffer[devno-0x80 ] = mbr_sig; + } + } +} + +#endif
Signature · 1 line
1.5.2.2
PATCH 24/33 MCA support for new x86 setup code
From: H. Peter Anvin <[email protected]>
MCA probing support for the new x86 setup code. This implements the same functionality as the assembly version.
--- arch/i386/boot/mca.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/mca.c
arch/i386/boot/mca.c new file +43 -0
@@ -0,0 +1,43 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/mca.c +* +* Get the MCA system description table +*/ + +#include "boot.h" + +int query_mca (void ) +{ +u8 err; +u16 es, bx, len; + + asm("pushw %%es ; " +"int $0x15 ; " +"setc %0 ; " +"movw %%es, %1 ; " +"popw %%es" + :"=acdSDm" (err),"=acdSDm" (es),"=b" (bx) + :"a" (0xc000 )); + +if (err) +return -1 ;/* No MCA present */ + +set_fs (es); + len =rdfs16 (bx); + +if (len >sizeof (boot_params.sys_desc_table)) + len =sizeof (boot_params.sys_desc_table); + +copy_from_fs (&boot_params.sys_desc_table, bx, len); +return 0 ; +}
Signature · 1 line
1.5.2.2
PATCH 25/33 Memory probing support for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Probe memory (INT 15h: E820, E801, 88).
--- arch/i386/boot/memory.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/memory.c
arch/i386/boot/memory.c new file +99 -0
@@ -0,0 +1,99 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/memory.c +* +* Memory detection code +*/ + +#include "boot.h" + +#define SMAP 0x534d4150/* ASCII "SMAP" */ + +static int detect_memory_e820 (void ) +{ +u32 next =0 ; +u32 size, id; +u8 err; +struct e820entry *desc = boot_params.e820_map; + +do { + size =sizeof (struct e820entry ); + id =SMAP ; + asm("int $0x15; setc %0" + :"=am" (err),"+b" (next),"+d" (id),"+c" (size), +"=m" (*desc) + :"D" (desc),"a" (0xe820 )); + +if (err || id !=SMAP ) +break ; + + boot_params.e820_entries++; + desc++; + }while (next && boot_params.e820_entries <E820MAX ); + +return boot_params.e820_entries; +} + +static int detect_memory_e801 (void ) +{ +u16 ax, bx, cx, dx; +u8 err; + + bx = cx = dx =0 ; + ax =0xe801 ; + asm("stc; int $0x15; setc %0" + :"=m" (err),"+a" (ax),"+b" (bx),"+c" (cx),"+d" (dx)); + +if (err) +return -1 ; + +/* Do we really need to do this? */ +if (cx || dx) { + ax = cx; + bx = dx; + } + +if (ax >15 *1024 ) +return -1 ;/* Bogus! */ + +/* This ignores memory above 16MB if we have a memory hole +there. If someone actually finds a machine with a memory +hole at 16MB and no support for 0E820h they should probably +generate a fake e820 map. */ + boot_params.alt_mem_k = (ax ==15 *1024 ) ? (dx <<6 )+ax : ax; + +return 0 ; +} + +static int detect_memory_88 (void ) +{ +u16 ax; +u8 err; + + ax =0x8800 ; + asm("stc; int $0x15; setc %0" :"=bcdm" (err),"+a" (ax)); + + boot_params.screen_info.ext_mem_k = ax; + +return -err; +} + +int detect_memory (void ) +{ +if (detect_memory_e820 () >0 ) +return 0 ; + +if (!detect_memory_e801 ()) +return 0 ; + +return detect_memory_88 (); +}
Signature · 1 line
1.5.2.2
PATCH 26/33 Voyager support for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Voyager support for the new x86 setup code. This implements the same functionality as the assembly version.
--- arch/i386/boot/voyager.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/voyager.c
arch/i386/boot/voyager.c new file +46 -0
@@ -0,0 +1,46 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/voyager.c +* +* Get the Voyager config information +*/ + +#include "boot.h" + +#ifdef CONFIG_X86_VOYAGER + +int query_voyager (void ) +{ +u8 err; +u16 es, di; +/* Abuse the apm_bios_info area for this */ +u8 *data_ptr = (u8 *)&boot_params.apm_bios_info; + + data_ptr[0 ] =0xff ;/* Flag on config not found(?) */ + + asm("pushw %%es ; " +"int $0x15 ; " +"setc %0 ; " +"movw %%es, %1 ; " +"popw %%es" + :"=qm" (err),"=rm" (es),"=D" (di) + :"a" (0xffc0 )); + +if (err) +return -1 ;/* Not Voyager */ + +set_fs (es); +copy_from_fs (data_ptr, di,7 );/* Table is 7 bytes apparently */ +return 0 ; +} + +#endif /* CONFIG_X86_VOYAGER */
Signature · 1 line
1.5.2.2
PATCH 27/33 Video mode probing support for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Video mode probing for the new x86 setup code. This code breaks down different drivers into modules. This code deliberately drops support for a lot of the vendor-specific mode probing present in the assembly version, since a lot of those probes have been found to be stale in current versions of those chips -- frequently, support for those modes have been dropped from recent video BIOSes due to space constraints, but the video BIOS signatures are still the same.
However, additional drivers should be extremely straightforward to plug in, if desirable.
--- arch/i386/boot/vesa.h | 79 ++++++++ arch/i386/boot/video-bios.c | 125 ++++++++++++ arch/i386/boot/video-vesa.c | 284 +++++++++++++++++++++++++++ arch/i386/boot/video-vga.c | 260 ++++++++++++++++++++++++ arch/i386/boot/video.c | 456 +++++++++++++++++++++++++++++++++++++++++++ arch/i386/boot/video.h | 145 ++++++++++++++ 6 files changed, 1349 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/vesa.h create mode 100644 arch/i386/boot/video-bios.c create mode 100644 arch/i386/boot/video-vesa.c create mode 100644 arch/i386/boot/video-vga.c create mode 100644 arch/i386/boot/video.c create mode 100644 arch/i386/boot/video.h
arch/i386/boot/vesa.h new file +79 -0
@@ -0,0 +1,79 @@ +/* ----------------------------------------------------------------------- * +* +* Copyright 1999-2007 H. Peter Anvin - All Rights Reserved +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, Inc., 53 Temple Place Ste 330, +* Boston MA 02111-1307, USA; either version 2 of the License, or +* (at your option) any later version; incorporated herein by reference. +* +* ----------------------------------------------------------------------- */ + +#ifndef BOOT_VESA_H +#define BOOT_VESA_H + +typedef struct { +u16 off, seg; +}far_ptr ; + +/* VESA General Information table */ +struct vesa_general_info { +u32 signature;/* 0 Magic number = "VESA" */ +u16 version;/* 4 */ +far_ptr vendor_string;/* 6 */ +u32 capabilities;/* 10 */ +far_ptr video_mode_ptr;/* 14 */ +u16 total_memory;/* 18 */ + +u16 oem_software_rev;/* 20 */ +far_ptr oem_vendor_name_ptr;/* 22 */ +far_ptr oem_product_name_ptr;/* 26 */ +far_ptr oem_product_rev_ptr;/* 30 */ + +u8 reserved[222 ];/* 34 */ +u8 oem_data[256 ];/* 256 */ +} __attribute__ ((packed)); + +#define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24)) +#define VBE2_MAGIC ('V' + ('B' << 8) + ('E' << 16) + ('2' << 24)) + +struct vesa_mode_info { +u16 mode_attr;/* 0 */ +u8 win_attr[2 ];/* 2 */ +u16 win_grain;/* 4 */ +u16 win_size;/* 6 */ +u16 win_seg[2 ];/* 8 */ +far_ptr win_scheme;/* 12 */ +u16 logical_scan;/* 16 */ + +u16 h_res;/* 18 */ +u16 v_res;/* 20 */ +u8 char_width;/* 22 */ +u8 char_height;/* 23 */ +u8 memory_planes;/* 24 */ +u8 bpp;/* 25 */ +u8 banks;/* 26 */ +u8 memory_layout;/* 27 */ +u8 bank_size;/* 28 */ +u8 image_planes;/* 29 */ +u8 page_function;/* 30 */ + +u8 rmask;/* 31 */ +u8 rpos;/* 32 */ +u8 gmask;/* 33 */ +u8 gpos;/* 34 */ +u8 bmask;/* 35 */ +u8 bpos;/* 36 */ +u8 resv_mask;/* 37 */ +u8 resv_pos;/* 38 */ +u8 dcm_info;/* 39 */ + +u32 lfb_ptr;/* 40 Linear frame buffer address */ +u32 offscreen_ptr;/* 44 Offscreen memory address */ +u16 offscreen_size;/* 48 */ + +u8 reserved[206 ];/* 50 */ +} __attribute__ ((packed)); + +#endif /* LIB_SYS_VESA_H */
arch/i386/boot/video-bios.c new file +125 -0
125 lines not on this page · raw message
arch/i386/boot/video-vesa.c new file +284 -0
284 lines not on this page · raw message
arch/i386/boot/video-vga.c new file +260 -0
260 lines not on this page · raw message
arch/i386/boot/video.c new file +456 -0
456 lines not on this page · raw message
arch/i386/boot/video.h new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 28/33 Code for actual protected-mode entry
From: H. Peter Anvin <[email protected]>
This is the code which actually does the switch to protected mode, including all preparation. It is also responsible for invoking the boot loader hooks, if present.
--- arch/i386/boot/pm.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++ arch/i386/boot/pmjump.S | 54 +++++++++++++++ 2 files changed, 224 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/pm.c create mode 100644 arch/i386/boot/pmjump.S
arch/i386/boot/pm.c new file +170 -0
@@ -0,0 +1,170 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +* +* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/pm.c +* +* Prepare the machine for transition to protected mode. +*/ + +#include "boot.h" +#include <asm/segment.h> + +/* +* Invoke the realmode switch hook if present; otherwise +* disable all interrupts. +*/ +static void realmode_switch_hook (void ) +{ +if (boot_params.hdr.realmode_swtch) { + asmvolatile ("lcallw *%0" + : :"m" (boot_params.hdr.realmode_swtch) + :"eax" ,"ebx" ,"ecx" ,"edx" ); + }else { + asmvolatile ("cli" ); +outb (0x80 ,0x70 );/* Disable NMI */ +io_delay (); + } +} + +/* +* A zImage kernel is loaded at 0x10000 but wants to run at 0x1000. +* A bzImage kernel is loaded and runs at 0x100000. +*/ +static void move_kernel_around (void ) +{ +/* Note: rely on the compile-time option here rather than +the LOADED_HIGH flag. The Qemu kernel loader unconditionally +sets the loadflags to zero. */ +#ifndef __BIG_KERNEL__ +u16 dst_seg, src_seg; +u32 syssize; + + dst_seg =0x1000 >>4 ; + src_seg =0x10000 >>4 ; + syssize = boot_params.hdr.syssize;/* Size in 16-byte paragraps */ + +while (syssize) { +int paras = (syssize >=0x1000 ) ?0x1000 : syssize; +int dwords = paras <<2 ; + + asmvolatile ("pushw %%es ; " +"pushw %%ds ; " +"movw %1,%%es ; " +"movw %2,%%ds ; " +"xorw %%di,%%di ; " +"xorw %%si,%%si ; " +"rep;movsl ; " +"popw %%ds ; " +"popw %%es" + :"+c" (dwords) + :"rm" (dst_seg),"rm" (src_seg) + :"esi" ,"edi" ); + + syssize -= paras; + dst_seg += paras; + src_seg += paras; + } +#endif +} + +/* +* Disable all interrupts at the legacy PIC. +*/ +static void mask_all_interrupts (void ) +{ +outb (0xff ,0xa1 );/* Mask all interrupts on the seconday PIC */ +io_delay (); +outb (0xfb ,0x21 );/* Mask all but cascade on the primary PIC */ +io_delay (); +} + +/* +* Reset IGNNE# if asserted in the FPU. +*/ +static void reset_coprocessor (void ) +{ +outb (0 ,0xf0 ); +io_delay (); +outb (0 ,0xf1 ); +io_delay (); +} + +/* +* Set up the GDT +*/ +#define GDT_ENTRY (flags,base,limit) \ + (((u64)(base & 0xff000000) << 32) | \ + ((u64)flags << 40) | \ + ((u64)(limit & 0x00ff0000) << 32) | \ + ((u64)(base & 0x00ffff00) << 16) | \ + ((u64)(limit & 0x0000ffff))) + +struct gdt_ptr { +u16 len; +u32 ptr; +} __attribute__((packed)); + +static void setup_gdt (void ) +{ + /* There are machines which are known to not boot with the GDT + being 8-byte unaligned. Intel recommends 16 byte alignment. */ + static const u64 boot_gdt[] __attribute__((aligned(16))) = { +/* CS: code, read/execute, 4 GB, base 0 */ + [GDT_ENTRY_BOOT_CS ] =GDT_ENTRY (0xc09b ,0 ,0xfffff ), +/* DS: data, read/write, 4 GB, base 0 */ + [GDT_ENTRY_BOOT_DS ] =GDT_ENTRY (0xc093 ,0 ,0xfffff ), + }; +struct gdt_ptr gdt; + + gdt.len =sizeof (boot_gdt)-1 ; + gdt.ptr = (u32 )&boot_gdt + (ds () <<4 ); + + asmvolatile ("lgdtl %0" : :"m" (gdt)); +} + +/* +* Set up the IDT +*/ +static void setup_idt (void ) +{ +static const struct gdt_ptr null_idt = {0 ,0 }; + asmvolatile ("lidtl %0" : :"m" (null_idt)); +} + +/* +* Actual invocation sequence +*/ +void go_to_protected_mode (void ) +{ +/* Hook before leaving real mode, also disables interrupts */ +realmode_switch_hook (); + +/* Move the kernel/setup to their final resting places */ +move_kernel_around (); + +/* Enable the A20 gate */ +if (enable_a20 ()) { +puts ("A20 gate not responding, unable to boot...\n" ); +die (); + } + +/* Reset coprocessor (IGNNE#) */ +reset_coprocessor (); + +/* Mask all interrupts in the PIC */ +mask_all_interrupts (); + +/* Actual transition to protected mode... */ +setup_idt (); +setup_gdt (); +protected_mode_jump (boot_params.hdr.code32_start, + (u32 )&boot_params + (ds () <<4 )); +}
arch/i386/boot/pmjump.S new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 29/33 Assembly header and main routine for new x86 setup code
From: H. Peter Anvin <[email protected]>
The assembly header and initialization code, and the main() routine. main.c also contains some miscellaneous very short routines.
--- arch/i386/boot/header.S | 283 +++++++++++++++++++++++++++++++++++++++++++++++ arch/i386/boot/main.c | 161 +++++++++++++++++++++++++++ 2 files changed, 444 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/header.S create mode 100644 arch/i386/boot/main.c
arch/i386/boot/header.S new file +283 -0
@@ -0,0 +1,283 @@ +/* + * header.S + * + * Copyright (C) 1991, 1992 Linus Torvalds + * + * Based on bootsect.S and setup.S + * modified by more people than can be counted + * + * Rewritten as a common file by H. Peter Anvin (Apr 2007) + * + * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment + * addresses must be multiplied by 16 to obtain their respective linear + * addresses. To avoid confusion, linear addresses are written using leading + * hex while segment addresses are written as segment:offset. + * + */ + +#include <asm/segment.h> +#include <linux/utsrelease.h> +#include <asm/boot.h> +#include <asm/e820.h> +#include <asm/page.h> +#include <asm/setup.h> +#include "boot.h" + +SETUPSECTS = 4 /* default nr of setup-sectors */ +BOOTSEG = 0x07C0 /* original address of boot-sector */ +SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */ +SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */ + /* to be loaded */ +ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */ +SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */ + +#ifndef SVGA_MODE +#define SVGA_MODE ASK_VGA +#endif + +#ifndef RAMDISK +#define RAMDISK 0 +#endif + +#ifndef ROOT_RDONLY +#define ROOT_RDONLY 1 +#endif + + .code16 + .section ".bstext", "ax" + + .global bootsect_start +bootsect_start: + + # Normalize the start address + ljmp $BOOTSEG, $start2 + +start2: + movw %cs, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %ss + xorw %sp, %sp + sti + cld + + movw $bugger_off_msg, %si + +msg_loop: + lodsb + andb %al, %al + jz bs_die + movb $0xe, %ah + movw $7, %bx + int $0x10 + jmp msg_loop + +bs_die: + # Allow the user to press a key, then reboot + xorw %ax, %ax + int $0x16 + int $0x19 + + # int 0x19 should never return. In case it does anyway, + # invoke the BIOS reset code... + ljmp $0xf000,$0xfff0 + + .section ".bsdata", "a" +bugger_off_msg: + .ascii "Direct booting from floppy is no longer supported.\r\n" + .ascii "Please use a boot loader program instead.\r\n" + .ascii "\n" + .ascii "Remove disk and press any key to reboot . . .\r\n" + .byte 0 + + + # Kernel attributes; used by setup. This is part 1 of the + # header, from the old boot sector. + + .section ".header", "a" + .globl hdr +hdr: +setup_sects: .byte SETUPSECTS +root_flags: .word ROOT_RDONLY +syssize: .long SYSSIZE +ram_size: .word RAMDISK +vid_mode: .word SVGA_MODE +root_dev: .word ROOT_DEV +boot_flag: .word 0xAA55 + + # offset 512, entry point + + .globl _start +_start: + # Explicitly enter this as bytes, or the assembler + # tries to generate a 3-byte jump here, which causes + # everything else to push off to the wrong offset. + .byte 0xeb # short (2-byte) jump + .byte start_of_setup-1f +1: + + # Part 2 of the header, from the old setup.S + + .ascii "HdrS" # header signature + .word 0x0206 # header version number (>= 0x0105) + # or else old loadlin-1.5 will fail) + .globl realmode_swtch +realmode_swtch: .word 0, 0 # default_switch, SETUPSEG +start_sys_seg: .word SYSSEG + .word kernel_version-512 # pointing to kernel version string + # above section of header is compatible + # with loadlin-1.5 (header v1.5). Don't + # change it. + +type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin, + # Bootlin, SYSLX, bootsect...) + # See Documentation/i386/boot.txt for + # assigned ids + +# flags, unused bits must be zero (RFU) bit within loadflags +loadflags: +LOADED_HIGH = 1 # If set, the kernel is loaded high +CAN_USE_HEAP = 0x80 # If set, the loader also has set + # heap_end_ptr to tell how much + # space behind setup.S can be used for + # heap purposes. + # Only the loader knows what is free +#ifndef __BIG_KERNEL__ + .byte 0 +#else + .byte LOADED_HIGH +#endif + +setup_move_size: .word 0x8000 # size to move, when setup is not + # loaded at 0x90000. We will move setup + # to 0x90000 then just before jumping + # into the kernel. However, only the + # loader knows how much data behind + # us also needs to be loaded. + +code32_start: # here loaders can put a different + # start address for 32-bit code. +#ifndef __BIG_KERNEL__ + .long 0x1000 # 0x1000 = default for zImage +#else + .long 0x100000 # 0x100000 = default for big kernel +#endif + +ramdisk_image: .long 0 # address of loaded ramdisk image + # Here the loader puts the 32-bit + # address where it loaded the image. + # This only will be read by the kernel. + +ramdisk_size: .long 0 # its size in bytes + +bootsect_kludge: + .long 0 # obsolete + +heap_end_ptr: .word _end+1024 # (Header version 0x0201 or later) + # space from here (exclusive) down to + # end of setup code can be used by setup + # for local heap purposes. + +pad1: .word 0 +cmd_line_ptr: .long 0 # (Header version 0x0202 or later) + # If nonzero, a 32-bit pointer + # to the kernel command line. + # The command line should be + # located between the start of + # setup and the end of low + # memory (0xa0000), or it may + # get overwritten before it + # gets read. If this field is + # used, there is no longer + # anything magical about the + # 0x90000 segment; the setup + # can be located anywhere in + # low memory 0x10000 or higher. + +ramdisk_max: .long (-__PAGE_OFFSET-(512 << 20)-1) & 0x7fffffff + # (Header version 0x0203 or later) + # The highest safe address for + # the contents of an initrd + +kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment + #required for protected mode + #kernel +#ifdef CONFIG_RELOCATABLE +relocatable_kernel: .byte 1 +#else +relocatable_kernel: .byte 0 +#endif +pad2: .byte 0 +pad3: .word 0 + +cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line, + #added with boot protocol + #version 2.06 + +# End of setup header ##################################################### + + .section ".inittext", "ax" +start_of_setup: +#ifdef SAFE_RESET_DISK_CONTROLLER +# Reset the disk controller. + movw $0x0000, %ax # Reset disk controller + movb $0x80, %dl # All disks + int $0x13 +#endif + +# We will have entired with %cs = %ds+0x20, normalize %cs so +# it is on par with the other segments. + pushw %ds + pushw $setup2 + lretw + +setup2: +# Force %es = %ds + movw %ds, %ax + movw %ax, %es + cld + +# Stack paranoia: align the stack and make sure it is good +# for both 16- and 32-bit references. In particular, if we +# were meant to have been using the full 16-bit segment, the +# caller might have set %sp to zero, which breaks %esp-based +# references. + andw $~3, %sp # dword align (might as well...) + jnz 1f + movw $0xfffc, %sp # Make sure we're not zero +1: movzwl %sp, %esp # Clear upper half of %esp + sti + +# Check signature at end of setup + cmpl $0x5a5aaa55, setup_sig + jne setup_bad + +# Zero the bss + movw $__bss_start, %di + movw $_end+3, %cx + xorl %eax, %eax + subw %di, %cx + shrw $2, %cx + rep; stosl + +# Jump to C code (should not return) + calll main + +# Setup corrupt somehow... +setup_bad: + movl $setup_corrupt, %eax + calll puts + # Fall through... + + .globl die + .type die, @function +die: + hlt + jmp die + + .size die, .-due + + .section ".initdata", "a" +setup_corrupt: + .byte 7 + .string "No setup signature found..."
arch/i386/boot/main.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 30/33 Linker script for the new x86 setup code
From: H. Peter Anvin <[email protected]>
Linker script to define the layout of the new x86 setup code. Includes assert for size overflow and a misaligned setup header.
--- arch/i386/boot/setup.ld | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/setup.ld
arch/i386/boot/setup.ld new file +54 -0
@@ -0,0 +1,54 @@ +/* + * setup.ld + * + * Linker script for the i386 setup code + */ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) + +SECTIONS +{ + . = 0; + .bstext : { *(.bstext) } + .bsdata : { *(.bsdata) } + + . = 497; + .header : { *(.header) } + .inittext : { *(.inittext) } + .initdata : { *(.initdata) } + .text : { *(.text*) } + + . = ALIGN(16); + .rodata : { *(.rodata*) } + + .videocards : { + video_cards = .; + *(.videocards) + video_cards_end = .; + } + + . = ALIGN(16); + .data : { *(.data*) } + + .signature : { + setup_sig = .; + LONG(0x5a5aaa55) + } + + + . = ALIGN(16); + .bss : + { + __bss_start = .; + *(.bss) + __bss_end = .; + } + . = ALIGN(16); + _end = .; + + /DISCARD/ : { *(.note*) } + + . = ASSERT(_end <= 0x8000, "Setup too big!"); + . = ASSERT(hdr == 0x1f1, "The setup header has the wrong offset!"); +}
Signature · 1 line
1.5.2.2
PATCH 31/33 Use the new x86 setup code for i386
From: H. Peter Anvin <[email protected]>
This patch hooks the new x86 setup code into the Makefile machinery. It also adapts boot/tools/build.c to a two-file (as opposed to three-file) universe, and simplifies it substantially.
--- arch/i386/boot/Makefile | 46 +++++++++-- arch/i386/boot/compressed/Makefile | 7 ++- arch/i386/boot/tools/build.c | 160 ++++++++++++++++-------------------- 3 files changed, 116 insertions(+), 97 deletions(-)
arch/i386/boot/Makefile +39 -7
@@ -25,27 +25,54 @@ SVGA_MODE := -DSVGA_MODE=NORMAL_VGA #RAMDISK := -DRAMDISK=512 -targets := vmlinux.bin bootsect bootsect.o \ - setup setup.o zImage bzImage +targets := vmlinux.bin setup.bin setup.elf zImage bzImage subdir- := compressed +setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o +setup-y += header.o main.o mca.o memory.o pm.o pmjump.o +setup-y += printf.o string.o tty.o video.o version.o voyager.o + +# The link order of the video-*.o modules can matter. In particular, +# video-vga.o *must* be listed first, followed by video-vesa.o. +# Hardware-specific drivers should follow in the order they should be +# probed, and video-bios.o should typically be last. +setup-y += video-vga.o +setup-y += video-vesa.o +setup-y += video-bios.o + hostprogs-y := tools/build HOSTCFLAGS_build.o := $(LINUXINCLUDE) # --------------------------------------------------------------------------- +# How to compile the 16-bit code. Note we always compile for -march=i386, +# that way we can complain to the user if the CPU is insufficient. +cflags-i386 := +cflags-x86_64 := -m32 +CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \ + $(cflags-$(ARCH)) \ + -Wall -Wstrict-prototypes \ + -march=i386 -mregparm=3 \ + -include $(srctree)/$(src)/code16gcc.h \ + -fno-strict-aliasing -fomit-frame-pointer \ + $(call cc-option, -ffreestanding) \ + $(call cc-option, -fno-stack-protector) \ + $(call cc-option, -mpreferred-stack-boundary=2) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + $(obj)/zImage: IMAGE_OFFSET := 0x1000 $(obj)/zImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK) $(obj)/bzImage: IMAGE_OFFSET := 0x100000 +$(obj)/bzImage: EXTRA_CFLAGS := -D__BIG_KERNEL__ $(obj)/bzImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__ $(obj)/bzImage: BUILDFLAGS := -b quiet_cmd_image = BUILD $@ -cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/bootsect $(obj)/setup \ +cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/setup.bin \ $(obj)/vmlinux.bin $(ROOT_DEV) > $@ -$(obj)/zImage $(obj)/bzImage: $(obj)/bootsect $(obj)/setup \ +$(obj)/zImage $(obj)/bzImage: $(obj)/setup.bin \ $(obj)/vmlinux.bin $(obj)/tools/build FORCE $(call if_changed,image) @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
@@ -53,12 +80,17 @@ $(obj)/zImage $(obj)/bzImage: $(obj)/bootsect $(obj)/setup \ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE $(call if_changed,objcopy) -LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary -LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext +SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) -$(obj)/setup $(obj)/bootsect: %: %.o FORCE +LDFLAGS_setup.elf := -T +$(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE $(call if_changed,ld) +OBJCOPYFLAGS_setup.bin := -O binary + +$(obj)/setup.bin: $(obj)/setup.elf FORCE + $(call if_changed,objcopy) + $(obj)/compressed/vmlinux: FORCE $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
arch/i386/boot/compressed/Makefile +6 -1
@@ -9,9 +9,14 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o \ EXTRA_AFLAGS := -traditional LDFLAGS_vmlinux := -T -CFLAGS_misc.o += -fPIC hostprogs-y := relocs +CFLAGS := -m32 -D__KERNEL__ $(LINUX_INCLUDE) -O2 \ + -fno-strict-aliasing -fPIC \ + $(call cc-option,-ffreestanding) \ + $(call cc-option,-fno-stack-protector) +LDFLAGS := -m elf_i386 + $(obj)/vmlinux: $(src)/vmlinux.lds $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE $(call if_changed,ld) @:
arch/i386/boot/tools/build.c +71 -89
234 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 32/33 Use the new x86 setup code for x86-64; unify with i386
From: H. Peter Anvin <[email protected]>
This unifies arch/*/boot (except arch/*/boot/compressed) between i386 and x86-64, and uses the new x86 setup code for x86-64 as well.
--- arch/x86_64/boot/Makefile | 136 +------ arch/x86_64/boot/bootsect.S | 98 ---- arch/x86_64/boot/compressed/Makefile | 9 +- 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 -------- 7 files changed, 10 insertions(+), 1263 deletions(-) delete mode 100644 arch/x86_64/boot/bootsect.S delete mode 100644 arch/x86_64/boot/install.sh delete mode 100644 arch/x86_64/boot/mtools.conf.in delete mode 100644 arch/x86_64/boot/setup.S delete mode 100644 arch/x86_64/boot/tools/build.c
arch/x86_64/boot/Makefile +5 -131
@@ -1,135 +1,9 @@ # # arch/x86_64/boot/Makefile # -# This file is subject to the terms and conditions of the GNU General Public -# License. See the file "COPYING" in the main directory of this archive -# for more details. -# -# Copyright (C) 1994 by Linus Torvalds -# - -# ROOT_DEV specifies the default root-device when making the image. -# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case -# the default of FLOPPY is used by 'build'. - -ROOT_DEV := CURRENT - -# If you want to preset the SVGA mode, uncomment the next line and -# set SVGA_MODE to whatever number you want. -# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. -# The number is the same as you would ordinarily press at bootup. - -SVGA_MODE := -DSVGA_MODE=NORMAL_VGA - -# If you want the RAM disk device, define this to be the size in blocks. - -#RAMDISK := -DRAMDISK=512 - -targets := vmlinux.bin bootsect bootsect.o \ - setup setup.o bzImage mtools.conf - -EXTRA_CFLAGS := -m32 - -hostprogs-y := tools/build -HOST_EXTRACFLAGS += $(LINUXINCLUDE) -subdir- := compressed/ #Let make clean descend in compressed/ -# --------------------------------------------------------------------------- - -$(obj)/bzImage: IMAGE_OFFSET := 0x100000 -$(obj)/bzImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__ -$(obj)/bzImage: BUILDFLAGS := -b - -quiet_cmd_image = BUILD $@ -cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/bootsect $(obj)/setup \ - $(obj)/vmlinux.bin $(ROOT_DEV) > $@ - -$(obj)/bzImage: $(obj)/bootsect $(obj)/setup \ - $(obj)/vmlinux.bin $(obj)/tools/build FORCE - $(call if_changed,image) - @echo 'Kernel: $@ is ready' ' (#'`cat .version`')' - -$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE - $(call if_changed,objcopy) - -LDFLAGS_bootsect := -Ttext 0x0 -s --oformat binary -LDFLAGS_setup := -Ttext 0x0 -s --oformat binary -e begtext - -$(obj)/setup $(obj)/bootsect: %: %.o FORCE - $(call if_changed,ld) - -$(obj)/compressed/vmlinux: FORCE - $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@ - -# Set this if you want to pass append arguments to the zdisk/fdimage/isoimage kernel -FDARGS = -# Set this if you want an initrd included with the zdisk/fdimage/isoimage kernel -FDINITRD = - -image_cmdline = default linux $(FDARGS) $(if $(FDINITRD),initrd=initrd.img,) - -$(obj)/mtools.conf: $(src)/mtools.conf.in - sed -e 's|@OBJ@|$(obj)|g' < $< > $@ - -# This requires write access to /dev/fd0 -zdisk: $(BOOTIMAGE) $(obj)/mtools.conf - MTOOLSRC=$(obj)/mtools.conf mformat a: ; sync - syslinux /dev/fd0 ; sync - echo '$(image_cmdline)' | \ - MTOOLSRC=$(obj)/mtools.conf mcopy - a:syslinux.cfg - if [ -f '$(FDINITRD)' ] ; then \ - MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' a:initrd.img ; \ - fi - MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) a:linux ; sync - -# These require being root or having syslinux 2.02 or higher installed -fdimage fdimage144: $(BOOTIMAGE) $(obj)/mtools.conf - dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=1440 - MTOOLSRC=$(obj)/mtools.conf mformat v: ; sync - syslinux $(obj)/fdimage ; sync - echo '$(image_cmdline)' | \ - MTOOLSRC=$(obj)/mtools.conf mcopy - v:syslinux.cfg - if [ -f '$(FDINITRD)' ] ; then \ - MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' v:initrd.img ; \ - fi - MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) v:linux ; sync - -fdimage288: $(BOOTIMAGE) $(obj)/mtools.conf - dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=2880 - MTOOLSRC=$(obj)/mtools.conf mformat w: ; sync - syslinux $(obj)/fdimage ; sync - echo '$(image_cmdline)' | \ - MTOOLSRC=$(obj)/mtools.conf mcopy - w:syslinux.cfg - if [ -f '$(FDINITRD)' ] ; then \ - MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' w:initrd.img ; \ - fi - MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) w:linux ; sync - -isoimage: $(BOOTIMAGE) - -rm -rf $(obj)/isoimage - mkdir $(obj)/isoimage - for i in lib lib64 share end ; do \ - if [ -f /usr/$$i/syslinux/isolinux.bin ] ; then \ - cp /usr/$$i/syslinux/isolinux.bin $(obj)/isoimage ; \ - break ; \ - fi ; \ - if [ $$i = end ] ; then exit 1 ; fi ; \ - done - cp $(BOOTIMAGE) $(obj)/isoimage/linux - echo '$(image_cmdline)' > $(obj)/isoimage/isolinux.cfg - if [ -f '$(FDINITRD)' ] ; then \ - cp '$(FDINITRD)' $(obj)/isoimage/initrd.img ; \ - fi - mkisofs -J -r -o $(obj)/image.iso -b isolinux.bin -c boot.cat \ - -no-emul-boot -boot-load-size 4 -boot-info-table \ - $(obj)/isoimage - rm -rf $(obj)/isoimage - -zlilo: $(BOOTIMAGE) - if [ -f $(INSTALL_PATH)/vmlinuz ]; then mv $(INSTALL_PATH)/vmlinuz $(INSTALL_PATH)/vmlinuz.old; fi - if [ -f $(INSTALL_PATH)/System.map ]; then mv $(INSTALL_PATH)/System.map $(INSTALL_PATH)/System.old; fi - cat $(BOOTIMAGE) > $(INSTALL_PATH)/vmlinuz - cp System.map $(INSTALL_PATH)/ - if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi +# The actual boot code is shared with i386 including the Makefile. +# So tell kbuild that we fetch the code from i386 and include the +# Makefile from i386 too. -install: - sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)" +src := arch/i386/boot +include $(src)/Makefile
arch/x86_64/boot/bootsect.S deleted +0 -98
98 lines not on this page · raw message
arch/x86_64/boot/compressed/Makefile +5 -4
@@ -7,11 +7,12 @@ # targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o -EXTRA_AFLAGS := -traditional -# cannot use EXTRA_CFLAGS because base CFLAGS contains -mkernel which conflicts with -# -m32 -CFLAGS := -m64 -D__KERNEL__ -Iinclude -O2 -fno-strict-aliasing -fPIC -mcmodel=small -fno-builtin +CFLAGS := -m64 -D__KERNEL__ $(LINUXINCLUDE) -O2 \ + -fno-strict-aliasing -fPIC -mcmodel=small \ + $(call cc-option, -ffreestanding) \ + $(call cc-option, -fno-stack-protector) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ LDFLAGS := -m elf_x86_64 LDFLAGS_vmlinux := -T
arch/x86_64/boot/install.sh deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/sh -. $srctree/arch/i386/boot/install.sh
arch/x86_64/boot/mtools.conf.in deleted +0 -17
@@ -1,17 +0,0 @@ -# -# mtools configuration file for "make (b)zdisk" -# - -# Actual floppy drive -drive a: - file="/dev/fd0" - -# 1.44 MB floppy disk image -drive v: - file="@OBJ@/fdimage" cylinders=80 heads=2 sectors=18 filter - -# 2.88 MB floppy disk image (mostly for virtual uses) -drive w: - file="@OBJ@/fdimage" cylinders=80 heads=2 sectors=36 filter - -
arch/x86_64/boot/setup.S deleted +0 -826
826 lines not on this page · raw message
arch/x86_64/boot/tools/build.c deleted +0 -185
185 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 33/33 Remove old i386 setup code
From: H. Peter Anvin <[email protected]>
This removes the old i386 setup code. This is done as a separate patch to avoid breaking git bisect as some of the i386 code was also used by the old x86-64 code.
--- 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 -- include/linux/edd.h | 4 - 6 files changed, 0 insertions(+), 3545 deletions(-) delete mode 100644 arch/i386/boot/bootsect.S delete mode 100644 arch/i386/boot/edd.S delete mode 100644 arch/i386/boot/setup.S delete mode 100644 arch/i386/boot/video.S delete mode 100644 arch/i386/kernel/verify_cpu.S
arch/i386/boot/bootsect.S deleted +0 -98
@@ -1,98 +0,0 @@ -/* - * bootsect.S Copyright (C) 1991, 1992 Linus Torvalds - * - * modified by Drew Eckhardt - * modified by Bruce Evans (bde) - * modified by Chris Noe (May 1999) (as86 -> gas) - * gutted by H. Peter Anvin (Jan 2003) - * - * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment - * addresses must be multiplied by 16 to obtain their respective linear - * addresses. To avoid confusion, linear addresses are written using leading - * hex while segment addresses are written as segment:offset. - * - */ - -#include <asm/boot.h> - -SETUPSECTS = 4 /* default nr of setup-sectors */ -BOOTSEG = 0x07C0 /* original address of boot-sector */ -INITSEG = DEF_INITSEG /* we move boot here - out of the way */ -SETUPSEG = DEF_SETUPSEG /* setup starts here */ -SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */ -SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */ - /* to be loaded */ -ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */ -SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */ - -#ifndef SVGA_MODE -#define SVGA_MODE ASK_VGA -#endif - -#ifndef RAMDISK -#define RAMDISK 0 -#endif - -#ifndef ROOT_RDONLY -#define ROOT_RDONLY 1 -#endif - -.code16 -.text - -.global _start -_start: - - # Normalize the start address - jmpl $BOOTSEG, $start2 - -start2: - movw %cs, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %ss - movw $0x7c00, %sp - sti - cld - - movw $bugger_off_msg, %si - -msg_loop: - lodsb - andb %al, %al - jz die - movb $0xe, %ah - movw $7, %bx - int $0x10 - jmp msg_loop - -die: - # Allow the user to press a key, then reboot - xorw %ax, %ax - int $0x16 - int $0x19 - - # int 0x19 should never return. In case it does anyway, - # invoke the BIOS reset code... - ljmp $0xf000,$0xfff0 - - -bugger_off_msg: - .ascii "Direct booting from floppy is no longer supported.\r\n" - .ascii "Please use a boot loader program instead.\r\n" - .ascii "\n" - .ascii "Remove disk and press any key to reboot . . .\r\n" - .byte 0 - - - # Kernel attributes; used by setup - - .org 497 -setup_sects: .byte SETUPSECTS -root_flags: .word ROOT_RDONLY -syssize: .word SYSSIZE -swap_dev: .word SWAP_DEV -ram_size: .word RAMDISK -vid_mode: .word SVGA_MODE -root_dev: .word ROOT_DEV -boot_flag: .word 0xAA55
arch/i386/boot/edd.S deleted +0 -231
231 lines not on this page · raw message
arch/i386/boot/setup.S deleted +0 -1075
1,075 lines not on this page · raw message
arch/i386/boot/video.S deleted +0 -2043
1,596 lines not on this page · raw message
arch/i386/kernel/verify_cpu.S deleted +0 -94
94 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.2.2
Part of the diff is not shown here. View the raw message.
Re: [x86 setup 31/33] Use the new x86 setup code for i386
In reply to H. Peter AnvinMinor nitpick:
arch/i386/boot/tools/build.c line 8
Quoted 13 lines
arch/i386/boot/tools/build.c +1
-0@@ -1,13 +1,12 @@/* * Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1997 Martin Mares +* Copyright (C) 2007 H. Peter Anvin */ /* * This file builds a disk-image from three different files:
~~~~~
twoQuoted 6 lines
arch/i386/boot/tools/build.c +0
-2* -* - bootsect: compatibility mbr which prints an error message if -* someone tries to boot the kernel directly. * - setup: 8086 machine code, sets up system parm * - system: 80386 code for actual system *
Signature · 4 lines
Tilman Schmidt E-Mail: [email protected] Bonn, Germany Diese Nachricht besteht zu 100% aus wiederverwerteten Bits. Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
Re: [x86 setup 22/33] CPU features verification for the new x86 setup code
In reply to H. Peter AnvinHi Peter,
Only two sub-minor nits:
Quoted 24 lines · On Mon, 9 Jul 2007 19:52:01 -0700 "H. Peter Anvin" <[email protected]> wrote:
From: H. Peter Anvin <[email protected]>
Verify that the CPU has enough features to run the kernel. This may entail enabling features on some CPUs.
By doing this in the setup code we can be guaranteed to still be able to write to the console through the BIOS.
Signed-off-by H. Peter Anvin <[email protected]>--- arch/i386/boot/cpu.c | 69 ++++++++++++ arch/i386/boot/cpucheck.c | 267 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 336 insertions(+), 0 deletions(-) create mode 100644 arch/i386/boot/cpu.c create mode 100644 arch/i386/boot/cpucheck.carch/i386/boot/cpu.c new file +2
-0@@ -0,0 +1,69 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +*
arch/i386/boot/cpu.c line 12
Quoted 10 lines
arch/i386/boot/cpu.c new file +10
-0+* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/cpucheck.c
^^^^^
cpu.c ?Quoted 65 lines
arch/i386/boot/cpu.c new file +57
-0+* +* Check for obligatory CPU features and abort if the features are not +* present. +*/ + +#include "boot.h" +#include "bitops.h" +#include <asm/cpufeature.h> + +static char *cpu_name (int level) +{ +static char buf[6 ]; + +if (level ==64 ) { +return "x86-64" ; + }else { +sprintf (buf,"i%d86" , level); +return buf; + } +} + +int validate_cpu (void ) +{ +u32 *err_flags; +int cpu_level, req_level; + +check_cpu (&cpu_level, &req_level, &err_flags); + +if (cpu_level < req_level) { +printf ("This kernel requires an %s CPU, " , +cpu_name (req_level)); +printf ("but only detected an %s CPU.\n" , +cpu_name (cpu_level)); +return -1 ; + } + +if (err_flags) { +int i, j; +puts ("This kernel requires the following features " +"not present on the CPU:\n" ); + +for (i =0 ; i <NCAPINTS ; i++) { +u32 e = err_flags[i]; + +for (j =0 ; j <32 ; j++) { +if (e &1 ) +printf ("%d:%d " , i, j); + + e >>=1 ; + } + } +putchar ('\n' ); +return -1 ; + }else { +return 0 ; + } +}arch/i386/boot/cpucheck.c new file +2
-0@@ -0,0 +1,267 @@ +/* -*- linux-c -*- ------------------------------------------------------- * +*
arch/i386/boot/cpucheck.c line 12
Quoted 10 lines
arch/i386/boot/cpucheck.c new file +10
-0+* Copyright (C) 1991, 1992 Linus Torvalds +* Copyright 2007 rPath, Inc. - All Rights Reserved +* +* This file is part of the Linux kernel, and is made available under +* the terms of the GNU General Public License version 2. +* +* ----------------------------------------------------------------------- */ + +/* +* arch/i386/boot/cpu.c
^^^^^
cpucheck.c ?arch/i386/boot/cpucheck.c line 20
Quoted 8 lines
arch/i386/boot/cpucheck.c new file +8
-0+* +* Check for obligatory CPU features and abort if the features are not +* present. This code should be compilable as 16-, 32- or 64-bit +* code, so be very careful with types and inline assembly. +* +* This code should not contain any messages; that requires an +* additional wrapper. +*
Sébastien.
Re: [x86 setup 20/33] Console-writing code for the new x86 setup code
In reply to H. Peter Anvinarch/i386/boot/printf.c line 25
Quoted 5 lines · H. Peter Anvin
arch/i386/boot/printf.c new file +5
-0+ +static inline int isdigit (int ch) +{ +return (ch >='0' ) && (ch <='9' ); +}
I'd say static inline unsigned int isdigit(unsigned char), since ASCII does not realistically exceed 255.
Quoted 1 line
+static int
strnlen(const char *s, int maxlen)
unsigned int, and unsigned int, too?
The glibc strnlen type also uses unsigned types.
Jan
Re: [x86 setup 20/33] Console-writing code for the new x86 setup code
Quoted 9 lines · Jan Engelhardt
arch/i386/boot/printf.c line 25
Quoted 5 lines · H. Peter Anvin
arch/i386/boot/printf.c new file +5
-0+ +static inline int isdigit (int ch) +{ +return (ch >='0' ) && (ch <='9' ); +}I'd say static inline unsigned int isdigit(unsigned char), since ASCII does not realistically exceed 255.
If you're trying to be standard, you're doing the wrong thing (the standard is int, since -1 is a permitted value.)
It doesn't matter anyway, and your version would probably generate slightly worse code.
Quoted 4 lines
Quoted 1 line
+static int
strnlen(const char *s, int maxlen)unsigned int, and unsigned int, too?
The glibc strnlen type also uses unsigned types.
If anything it should be size_t. Fixing, and moved to string.c, where it belongs.
-hpa
Re: [x86 setup 17/33] A20 handling code
In reply to H. Peter Anvinarch/i386/boot/a20.c line 33
Quoted 5 lines · H. Peter Anvin
arch/i386/boot/a20.c new file +5
-0+ status =inb (0x64 ); +if (status &1 ) { +/* Read and discard input data */ +io_delay (); + (void )inb (0x60 );
Is the (void) cast needed for some obscure reason? Let's hope inb _is_ declared as volatile. (Minus the volatile flames.
arch/i386/boot/a20.c line 48
Quoted 13 lines
arch/i386/boot/a20.c new file +13
-0+ }else if (!(status &2 )) { +/* Buffers empty, finished! */ +return 0 ; + } + } + +return -1 ; +} + + +#define A20_TEST_ADDR (4*0x80) +#define A20_TEST_SHORT 32 +#define A20_TEST_LONG 2097152/* 2^21 */
Maybe...?
#define A20_TEST_LONG (1 << 21)
arch/i386/boot/a20.c line 83
Quoted 12 lines
arch/i386/boot/a20.c new file +12
-0+/* Quick test to see if A20 is already enabled */ +static int a20_test_short (void ) +{ +return a20_test (A20_TEST_SHORT ); +} + +/* Longer test that actually waits for A20 to come on line; this +is useful when dealing with the KBC or other slow external circuitry. */ +static int a20_test_long (void ) +{ +return a20_test (A20_TEST_LONG ); +}
To me looks like some of these (or other functions) could return bool.
Jan
Re: [x86 setup 17/33] A20 handling code
Quoted 11 lines · Jan Engelhardt
arch/i386/boot/a20.c line 33
Quoted 5 lines · H. Peter Anvin
arch/i386/boot/a20.c new file +5
-0+ status =inb (0x64 ); +if (status &1 ) { +/* Read and discard input data */ +io_delay (); + (void )inb (0x60 );Is the (void) cast needed for some obscure reason? Let's hope inb _is_ declared as volatile. (Minus the volatile flames.
The (void) cast is there as a stylistic device, it tells the human reader "yes, I really meant to read this value and throw it away."
-hpa
Re: [x86 setup 17/33] A20 handling code
In reply to Jan EngelhardtQuoted 7 lines · Jan Engelhardt
arch/i386/boot/a20.c line 48
Quoted 4 lines
arch/i386/boot/a20.c new file +4
-0+ +#define A20_TEST_ADDR (4*0x80) +#define A20_TEST_SHORT 32 +#define A20_TEST_LONG 2097152/* 2^21 */ Maybe...?
#defineA20_TEST_LONG(1 << 21)
That makes it look like it's a magic value or bitmask, it's not. The value 2^21 is largely arbitrary, it's just what happened to be in the previous code.
Quoted 6 lines
Quoted 6 lines
arch/i386/boot/a20.c new file +6
-0+/* Quick test to see if A20 is already enabled */ +static int a20_test_short (void ) +{ +return a20_test (A20_TEST_SHORT ); +} +
Quoted 8 lines
arch/i386/boot/a20.c line 83
Quoted 6 lines
arch/i386/boot/a20.c new file +6
-0+/* Longer test that actually waits for A20 to come on line; this +is useful when dealing with the KBC or other slow external circuitry. */ +static int a20_test_long (void ) +{ +return a20_test (A20_TEST_LONG ); +}To me looks like some of these (or other functions) could return bool.
Does it matter? It will generate worse code.
-hpa
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
In reply to H. Peter AnvinQuoted 3 lines · H. Peter Anvin
strcmp(),memcpy(),memset(), as well as routines to copy to and from other segments (as pointed to by fs and gs).
I wonder, strcmp() is the only one not done in assembler. Is there a particular reason? (Or the other way around, why is memcpy/memset not C.) The opcode is rep[n]z cmps[bl];
Would perhaps using __builtin_memset
and whatever GCC provides also work in 16-bit mode (would save implementing it again).
arch/i386/boot/string.c line 18
Quoted 8 lines
arch/i386/boot/string.c new file +8
-0+/* +* arch/i386/boot/string.c +* +* Very basic string functions +*/ + +#include "boot.h" +#include <linux/edd.h>
What's edd good for here?
Quoted 5 lines
arch/i386/boot/string.c new file +5
-0+int strcmp (const char *str1,const char *str2) +{ +const unsigned char *s1 = (const unsigned char *)str1; +const unsigned char *s2 = (const unsigned char *)str2; +int delta =0 ;
arch/i386/boot/string.c line 34
Quoted 10 lines
arch/i386/boot/string.c new file +10
-0+ +while (*s1 || *s2) { + delta = *s2 - *s1; +if (delta) +return delta; + s1++; + s2++; + } +return 0 ; +}
Jan
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Quoted 7 lines · Jan Engelhardt
Quoted 2 lines · H. Peter Anvin
strcmp(),memcpy(),memset(), as well as routines to copy to and from other segments (as pointed to by fs and gs).I wonder,
strcmp()is the only one not done in assembler. Is there a particular reason? (Or the other way around, why is memcpy/memset not C.) The opcode is rep[n]z cmps[bl];
BZZT, wrong. repz cmpsb is memcmp(), not strcmp(). The reason is simply that memset and memcpy are in assembly is that they are simple wrappers around string instructions, plus the need to provide the other-segment copy functions -- it was cleaner to do them as an assembly file.
This is not the case for strcmp(), nor for any other string functions that may want to be used in the future.
Quoted 3 lines
Would perhaps using
__builtin_memset
and whatever GCC provides also work in 16-bit mode (would save implementing it again).
Nope. The builtins not only vary between gcc versions, but they also have a nasty tendency to generate calls to library functions, sometimes libgcc functions. Hence -ffreestanding.
Quoted 10 lines
arch/i386/boot/string.c line 18
Quoted 8 lines
arch/i386/boot/string.c new file +8
-0+/* +* arch/i386/boot/string.c +* +* Very basic string functions +*/ + +#include "boot.h" +#include <linux/edd.h> What's edd good for here?
It's a copy-and-paste accident; already fixed in the tree.
-hpa
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Quoted 3 lines
Nope. The builtins not only vary between gcc versions, but they also have a nasty tendency to generate calls to library functions, sometimes libgcc functions. Hence -ffreestanding.
-ffreestanding will still generate calls to libgcc functions. -ffreestanding doesn't disable _all_ of the C library, either.
Segher
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Review
Quoted 7 lines · Segher Boessenkool
Quoted 3 lines
Nope. The builtins not only vary between gcc versions, but they also have a nasty tendency to generate calls to library functions, sometimes libgcc functions. Hence -ffreestanding.
(quoted diff) +0
-2-ffreestanding will still generate calls to libgcc functions. -ffreestanding doesn't disable _all_ of the C library, either.
No, it doesn't, but it does inhibit builtin functions, and so provides a bit more ABI stability.
-hpa
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Quoted 9 lines
Review
Quoted 6 lines
Quoted 3 lines
Nope. The builtins not only vary between gcc versions, but they also have a nasty tendency to generate calls to library functions, sometimes libgcc functions. Hence -ffreestanding.
(quoted diff) +0
-2-ffreestanding will still generate calls to libgcc functions. -ffreestanding doesn't disable _all_ of the C library, either.No, it doesn't, but it does inhibit builtin functions, and so provides a bit more ABI stability.
Yes, Linux should definitely be compiled with -ffreestanding, it isn't a hosted application after all ;-)
Segher
Re: [x86 setup 16/33] String-handling functions for the new x86 setup code.
Quoted 2 lines
Yes, Linux should definitely be compiled with -ffreestanding, it isn't a hosted application after all ;-)
We tried it some time ago and it caused problems so it was dropped again
-Andi
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to H. Peter AnvinQuoted 2 lines
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate 16-bit (real-mode) code. This header file provides the assembly prefix.
This only works correctly with newer GCCs if you pass the -fno-toplevel-reorder option (and it only works on older GCC versions by accident). This option however disables certain optimisations; but perhaps that doesn't matter all that much here.
Segher
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 8 lines · On Tuesday 10 July 2007 16:16:29 Segher Boessenkool wrote:
Quoted 4 lines
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate
16-bit (real-mode) code. This header file provides the assembly prefix.This only works correctly with newer GCCs if you pass the -fno-toplevel-reorder option (and it only works on older GCC versions by accident).
And on older ones (gcc-3.3-hammer / 3.4 / 4.0 ) -fno-unit-at-a-time
Still it seems quite fragile to me agreed.
-Andi
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 5 lines · Andi Kleen
Quoted 4 lines · On Tuesday 10 July 2007 16:16:29 Segher Boessenkool wrote:
Quoted 4 lines
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate
16-bit (real-mode) code. This header file provides the assembly prefix.
Quoted 7 lines
Quoted 3 lines
This only works correctly with newer GCCs if you pass the -fno-toplevel-reorder option (and it only works on older GCC versions by accident).
And on older ones (gcc-3.3-hammer / 3.4 / 4.0 ) -fno-unit-at-a-time
Still it seems quite fragile to me agreed.
The alternative, of course, is to compile to an .s file and insert .code16gcc into the .s file. This makes the Makefile uglier, but would be more resilient against oddball gcc changes.
I'm a bit surprised about the claim w.r.t. -fno-unit-at-a-time (although I guess that is the default and one would thus typically not see this.)
Got any pointers why that would cause a global asm() to be scrambled
around?
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 6 lines · H. Peter Anvin
I'm a bit surprised about the claim w.r.t. -fno-unit-at-a-time (although I guess that is the default and one would thus typically not see this.)
Got any pointers why that would cause a globalasm()to be scrambled
around?
Never mind. It's quite right there in the gcc doc, and -fno-unit-at-a-time is documented as the fix.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to H. Peter AnvinQuoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate
16-bit (real-mode) code. This header file provides the assembly prefix.This only works correctly with newer GCCs if you pass the -fno-toplevel-reorder option (and it only works on older GCC versions by accident).
Quoted 7 lines
Quoted 3 lines
And on older ones (gcc-3.3-hammer / 3.4 / 4.0 ) -fno-unit-at-a-time
Still it seems quite fragile to me agreed.
The alternative, of course, is to compile to an .s file and insert .code16gcc into the .s file. This makes the
Makefileuglier, but would be more resilient against oddball gcc changes.
This would be even more fragile. The exact format of GCC's assembler code output isn't defined at all, so in principle this is a hopeless task. In practice just putting the .code16gcc directive on the first line would likely work though, GCC never generates a .code32 AFAIK, but it isn't guaranteed that this will work (or will keep working).
Quoted 2 lines
I'm a bit surprised about the claim w.r.t. -fno-unit-at-a-time (although I guess that is the default and one would thus typically not see this.)
-fno-unit-at-a-time is the default on three year old compilers, yes. Newer compilers have unit-at-a-time enabled by default.
Quoted 2 lines
Got any pointers why that would cause a global
asm()to be scrambled
around?
An asm() outside of a function is a top-level thing, just like functions and file-scope variable definitions, and with unit-at-a-time compilation all such blocks can be reordered (or even omitted, or inlined, or whatever). Note that even before unit-at-a-time was introduced there was no guarantee of emitting everything in the order it appears in the source file.
Segher
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 7 lines · Segher Boessenkool
Quoted 3 lines
I'm a bit surprised about the claim w.r.t. -fno-unit-at-a-time (although I guess that is the default and one would thus typically not see this.)
-fno-unit-at-a-time is the default on three year old compilers, yes. Newer compilers have unit-at-a-time enabled by default.
As I said, never mind. "Unit at a time" does something totally different from what I somehow had gotten into my head it did.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 11 lines · Segher Boessenkool
Quoted 4 lines
The alternative, of course, is to compile to an .s file and insert .code16gcc into the .s file. This makes the
Makefileuglier, but would
be more resilient against oddball gcc changes.This would be even more fragile. The exact format of GCC's assembler code output isn't defined at all, so in principle this is a hopeless task. In practice just putting the .code16gcc directive on the first line would likely work though, GCC never generates a .code32 AFAIK, but it isn't guaranteed that this will work (or will keep working).
Unfortunately, .code16gcc is still experimental (at least binutils' website says that). What is worse, it says that it is possible that 16bit code produced on GCC won't work on pre-80386 processors (before switching to protected mode you have to think about cpu as a pre-80386).
I don't think that -m16 flag will be introduced quickly. In fact, only OS developers _sometimes_ use 16 bit code...
I did a fast test and now I know that assembler instructions are almost ignored by GCC and passed to gas. The situation is the same with .code16gcc, what mean that gas has to translate 32bit code from GCC to 16 bit code. The result binary was correct 16 bit program (at least its code looked good), but it is IMHO too many translations from C to 32bit assembler and then to 16bit assembler, that can cause unpredictable errors.
Additionally, I prefer to write architecture depend procedures in assembler (but is only *my* opinion, and you probably disagree). Assembler is faster, you have bigger control over the code, and portability of C is in this circumstances not necessary.
Pawel
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 7 lines · Pawel Dziepak
Unfortunately, .code16gcc is still experimental (at least binutils' website says that). What is worse, it says that it is possible that 16bit code produced on GCC won't work on pre-80386 processors (before switching to protected mode you have to think about cpu as a pre-80386).
.code16gcc has been in production use in real projects since at least 2001.
16-bit code produced by gcc is indeed, guaranteed to not work on pre-386 x86s, but so is the code we had there before. Saying "before switching to protected mode you have to think about [the] cpu as a pre-80386" is blatantly false; 32-bit registers and addressing are readily available in real mode using size override prefixes (which is what ".code16gcc" takes care of.)
Quoted 10 lines
I don't think that -m16 flag will be introduced quickly. In fact, only OS developers _sometimes_ use 16 bit code...
I did a fast test and now I know that assembler instructions are almost ignored by GCC and passed to gas. The situation is the same with .code16gcc, what mean that gas has to translate 32bit code from GCC to 16 bit code. The result binary was correct 16 bit program (at least its code looked good), but it is IMHO too many translations from C to 32bit assembler and then to 16bit assembler, that can cause unpredictable errors.
You're saying "I don't understand it, and it scares me." The differences compared to standard .code16 are pretty minute, mostly in the matter of a couple of different default sizes (e.g. "call" defaults to "calll" not "callw".)
Quoted 4 lines
Additionally, I prefer to write architecture depend procedures in assembler (but is only *my* opinion, and you probably disagree). Assembler is faster, you have bigger control over the code, and portability of C is in this circumstances not necessary.
... and the code is an utter, unmaintainable mess.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to Pawel DziepakQuoted 13 lines · Pawel Dziepak
Quoted 11 lines · Segher Boessenkool
Quoted 4 lines
The alternative, of course, is to compile to an .s file and insert .code16gcc into the .s file. This makes the
Makefileuglier, but would
be more resilient against oddball gcc changes.This would be even more fragile. The exact format of GCC's assembler code output isn't defined at all, so in principle this is a hopeless task. In practice just putting the .code16gcc directive on the first line would likely work though, GCC never generates a .code32 AFAIK, but it isn't guaranteed that this will work (or will keep working).
Quoted 5 lines
Unfortunately, .code16gcc is still experimental (at least binutils' website says that). What is worse, it says that it is possible that 16bit code produced on GCC won't work on pre-80386 processors (before switching to protected mode you have to think about cpu as a pre-80386).
What .code16gcc does is produce 32-bit instructions that are meant to be run from a 16-bit code segment (real mode or 16-bit protected) by using address and data size override prefixes. This means that pre-386 processors cannot run the code because they cannot understand 32-bit instructions.
--
Brian Gerst
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to Andi KleenQuoted 10 lines
Quoted 8 lines
Quoted 4 lines
gcc for i386 can be used with the assembly prefix ".code16gcc" to generate
16-bit (real-mode) code. This header file provides the assembly prefix.This only works correctly with newer GCCs if you pass the -fno-toplevel-reorder option (and it only works on older GCC versions by accident).
And on older ones (gcc-3.3-hammer / 3.4 / 4.0 ) -fno-unit-at-a-time
...which inhibits even more optimisations. Still not too important, but the code size difference probably is noticeable.
Quoted 1 line
Still it seems quite fragile to me agreed.
Well at least with -fno-toplevel-reorder it is guaranteed to work (not the same thing as "is working", heh, but fairly close).
It seems to me GCC should grow an option to insert .code16gcc by itself (-m16 perhaps?) Or GAS could get a flag to include a file as a prelude before the main thing. Neither will help Linux right now of course.
Segher
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 10 lines · Segher Boessenkool
Well at least with -fno-toplevel-reorder it is guaranteed to work (not the same thing as "is working", heh, but fairly close).
It seems to me GCC should grow an option to insert .code16gcc by itself (-m16 perhaps?) Or GAS could get a flag to include a file as a prelude before the main thing. Neither will help Linux right now of course.
-m16 is the right thing, and it also provides a proper hook for eventually having a real 16-bit backend (there are at least two projects for doing that.)
For now, I have:
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
$(cflags-$(ARCH)) \
-Wall -Wstrict-prototypes \
-march=i386 -mregparm=3 \
-include $(srctree)/$(src)/code16gcc.h \
-fno-strict-aliasing -fomit-frame-pointer \
$(call cc-option, -ffreestanding) \
$(call cc-option, -fno-unit-at-a-time) \
$(call cc-option, -fno-toplevel-reorder) \
$(call cc-option, -fno-stack-protector) \
$(call cc-option, -mpreferred-stack-boundary=2)... since that will require less violence to eventually hack in the proper -m16 option if/when it becomes available.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 4 lines
Quoted 2 lines
It seems to me GCC should grow an option to insert .code16gcc by itself (-m16 perhaps?)
-m16 is the right thing,
Probably not actually, -m16 might have 16-bit "int" etc. -mabi=16 is closer to what other architectures do here.
Quoted 3 lines
and it also provides a proper hook for
eventually having a real 16-bit backend (there are at least two projects for doing that.)
Those would use -m16, yes.
Quoted 14 lines
For now, I have:
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \ $(cflags-$(ARCH)) \ -Wall -Wstrict-prototypes \ -march=i386 -mregparm=3 \ -include $(srctree)/$(src)/code16gcc.h \ -fno-strict-aliasing -fomit-frame-pointer \ $(call cc-option, -ffreestanding) \ $(call cc-option, -fno-unit-at-a-time) \ $(call cc-option, -fno-toplevel-reorder) \ $(call cc-option, -fno-stack-protector) \ $(call cc-option, -mpreferred-stack-boundary=2)
Quoted 2 lines
... since that will require less violence to eventually hack in the proper -m16 option if/when it becomes available.
Looks good, except you don't want -fno-unit-at-a-time if -fno-toplevel-reorder works. And of course it would be good to get rid of -fno-strict-aliasing, but let's not go there today ;-P
Segher
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 15 lines · Segher Boessenkool
Quoted 15 lines
For now, I have:
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \ $(cflags-$(ARCH)) \ -Wall -Wstrict-prototypes \ -march=i386 -mregparm=3 \ -include $(srctree)/$(src)/code16gcc.h \ -fno-strict-aliasing -fomit-frame-pointer \ $(call cc-option, -ffreestanding) \ $(call cc-option, -fno-unit-at-a-time) \ $(call cc-option, -fno-toplevel-reorder) \ $(call cc-option, -fno-stack-protector) \ $(call cc-option, -mpreferred-stack-boundary=2)
Quoted 8 lines
Quoted 2 lines
... since that will require less violence to eventually hack in the proper -m16 option if/when it becomes available.
Looks good, except you don't want -fno-unit-at-a-time if -fno-toplevel-reorder works. And of course it would be good to get rid of -fno-strict-aliasing, but let's not go there today ;-P
OK, how does this look:
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
$(cflags-$(ARCH)) \
-Wall -Wstrict-prototypes \
-march=i386 -mregparm=3 \
-include $(srctree)/$(src)/code16gcc.h \
-fno-strict-aliasing -fomit-frame-pointer \
$(call cc-option, -ffreestanding) \
$(call cc-option, -fno-toplevel-reorder,\
$(call cc-option, -fno-unit-at-a-time)) \
$(call cc-option, -fno-stack-protector) \
$(call cc-option, -mpreferred-stack-boundary=2)I think dropping -fno-strict-aliasing for this code is probably bad... it's pretty low-level stuff which does a lot of bitlevel manipulation.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 7 lines
Quoted 4 lines
Looks good, except you don't want -fno-unit-at-a-time if -fno-toplevel-reorder works. And of course it would be good to get rid of -fno-strict-aliasing, but let's not go there today ;-P
OK, how does this look:
Quoted 11 lines
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
$(cflags-$(ARCH)) \
-Wall -Wstrict-prototypes \
-march=i386 -mregparm=3 \
-include $(srctree)/$(src)/code16gcc.h \
-fno-strict-aliasing -fomit-frame-pointer \
$(call cc-option, -ffreestanding) \
$(call cc-option, -fno-toplevel-reorder,\
$(call cc-option, -fno-unit-at-a-time)) \
$(call cc-option, -fno-stack-protector) \
$(call cc-option, -mpreferred-stack-boundary=2)That looks fine.
Quoted 2 lines
I think dropping -fno-strict-aliasing for this code is probably bad... it's pretty low-level stuff which does a lot of bitlevel manipulation.
"Which breaks C aliasing rules all over the place". Well, probably not all that often, actually. But, as I said -- let's not go there now, keep the flag in there, removing it will take a lot of work.
Segher
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to H. Peter AnvinQuoted 11 lines · H. Peter Anvin
Quoted 9 lines · Segher Boessenkool
Well at least with -fno-toplevel-reorder it is guaranteed to work (not the same thing as "is working", heh, but fairly close).
It seems to me GCC should grow an option to insert .code16gcc by itself (-m16 perhaps?) Or GAS could get a flag to include a file as a prelude before the main thing. Neither will help Linux right now of course.
Quoted 5 lines
-m16 is the right thing, and it also provides a proper hook for eventually having a real 16-bit backend (there are at least two projects for doing that.)
For now, I have:
Can't you use the global CFLAGS and append your specific ones?
Quoted 1 line
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
-g ???
Quoted 3 lines
$(cflags-$(ARCH)) \
-Wall -Wstrict-prototypes \
-march=i386 -mregparm=3 \Why -march=i386 ?
Quoted 3 lines
-include $(srctree)/$(src)/code16gcc.h \
-fno-strict-aliasing -fomit-frame-pointer \
$(call cc-option, -ffreestanding) \No need to test, -ffreestanding is supported by all gcc versions we support.
Quoted 9 lines
$(call cc-option, -fno-unit-at-a-time) \ $(call cc-option, -fno-toplevel-reorder) \ $(call cc-option, -fno-stack-protector) \ $(call cc-option, -mpreferred-stack-boundary=2)... since that will require less violence to eventually hack in the proper -m16 option if/when it becomes available.
-hpa
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: [x86 setup 13/33] Header file to produce 16-bit code with gcc
Quoted 5 lines · Adrian Bunk
Quoted 2 lines
For now, I have:
Can't you use the global CFLAGS and append your specific ones?
No. A lot of the x86-64 flags don't work with -m32.
Quoted 3 lines
Quoted 1 line
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
-g ???
Leaves debugging information in setup.elf. It is handy sometimes.
Quoted 5 lines
Quoted 3 lines
$(cflags-$(ARCH)) \ -Wall -Wstrict-prototypes \ -march=i386 -mregparm=3 \Why -march=i386 ?
So we can at least spit out an error message.
-hpa
Re: [x86 setup 13/33] Header file to produce 16-bit code with gcc
In reply to Adrian BunkQuoted 20 lines · Adrian Bunk
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Segher Boessenkool
Well at least with -fno-toplevel-reorder it is guaranteed to work (not the same thing as "is working", heh, but fairly close).
It seems to me GCC should grow an option to insert .code16gcc by itself (-m16 perhaps?) Or GAS could get a flag to include a file as a prelude before the main thing. Neither will help Linux right now of course.
Quoted 5 lines
-m16 is the right thing, and it also provides a proper hook for eventually having a real 16-bit backend (there are at least two projects for doing that.)
For now, I have:
Can't you use the global CFLAGS and append your specific ones?
Quoted 1 line
CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
Quoted 7 lines
-g ???
Quoted 3 lines
$(cflags-$(ARCH)) \ -Wall -Wstrict-prototypes \ -march=i386 -mregparm=3 \Why -march=i386 ?
To prevent gcc from using instructions (particularly cmovxx) that not all processors will understand.
--
Brian Gerst
A message that is not in the archive (sent off-list or not yet received): 2034f71d414def30de582fb59573295cadbdabb4.1184032748.git.hpa@zytor.com
A message that is not in the archive (sent off-list or not yet received): 361d0a8b7b7ea9d41d0c25664b3e2b30fd99e329.1184032749.git.hpa@zytor.com
Re: [x86 setup 09/33] Make definitions for struct e820entry and struct e820map consistent
include/asm-x86_64/e820.h line 16
Quoted 12 lines
include/asm-x86_64/e820.h +3
-1@@ -11,7 +11,9 @@#ifndef __E820_HEADER#define __E820_HEADER -#include <linux/mmzone.h> +#ifndef _SETUP +# include <linux/mmzone.h> +#endif
If the ifdef is valid then the include can be completely removed.
-Andi
Quoted 92 lines · H. Peter Anvin
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_infofield in theboot_paramsstructure; 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 usearch/i386/boot/cpucheck.cto do the post-invocation CPU check currently done inarch/x86_64/kernel/trampoline.S, although this patch set doesn't introduce that change.
-boot_paramsis now a proper structure.This code has been tested in -mm since early in the 2.6.22 cycle.
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 | 46 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 | 290 +++ b/arch/i386/boot/cmdline.c | 97 + b/arch/i386/boot/code16gcc.h | 9 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 | 331 ++++ b/arch/i386/boot/setup.ld | 54 b/arch/i386/boot/string.c | 34 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
Quoted 8 lines
b/include/asm-x86_64/cpufeature.h | 115 - b/include/asm-x86_64/e820.h | 6 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, 4601 insertions(+), 5208 deletions(-)
is possible to put 16bit c in seperate directory. or rename them with _16.c?
YH
Quoted 3 lines · Yinghai Lu
is possible to put 16bit c in seperate directory. or rename them with _16.c?
They *ARE* in a separate directory, specifically arch/i386/boot. All the *.c files in there are 16 bits; the 32-bit code is in arch/i386/boot/compressed or arch/i386/kernel.
-hpa
Quoted 21 lines · H. Peter Anvin
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_infofield in theboot_paramsstructure; 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 usearch/i386/boot/cpucheck.cto do the post-invocation CPU check currently done inarch/x86_64/kernel/trampoline.S, although this patch set doesn't introduce that change.
-boot_paramsis now a proper structure.
Quoted 1 line
This code has been tested in -mm since early in the 2.6.22 cycle.
ACK
I don't claim to be an expert in this area, but I definitely support this going in, and I really did read every patch. :)
The only minor problem I found was a misspelling "paragrap" (perhaps plural) in one of the patches.
Jeff
Jeremy Fitzhardinge
Acked-byQuoted 21 lines · H. Peter Anvin
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_infofield in theboot_paramsstructure; 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 usearch/i386/boot/cpucheck.cto do the post-invocation CPU check currently done inarch/x86_64/kernel/trampoline.S, although this patch set doesn't introduce that change.
-boot_paramsis now a proper structure.
Quoted 2 lines
This code has been tested in -mm since early in the 2.6.22 cycle.
This stuff is good. I haven't read through this series in detail, but I have been working on the code in -mm and its a clear improvement.
J