From b5f2e09fdb253a4811ce80a7762c5246f44c845b Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 30 Oct 2024 17:08:57 -0700 Subject: [PATCH 1/3] Add test for 80386+ to cputest.S --- elks/arch/i86/boot/cputype.S | 58 ++++++++++++++++++++--------------- elks/arch/i86/kernel/system.c | 2 +- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/elks/arch/i86/boot/cputype.S b/elks/arch/i86/boot/cputype.S index 863692b98..4c8dffc70 100644 --- a/elks/arch/i86/boot/cputype.S +++ b/elks/arch/i86/boot/cputype.S @@ -1,4 +1,4 @@ -// obsolote and inaccurate, but required for arch_cpu > 5 +// obsolete and inaccurate, but required for arch_cpu = 6 and 7 (286, 386+) // XT vs AT BIOS system capabilities (sys_caps) auto-detection by kernel // #define CONFIG_CPU_8086 /* required for this file only */ @@ -10,10 +10,10 @@ ! */ getcpu: - mov $SETUPSEG,%ax /* Codesegment setup.S */ + mov $SETUPSEG,%ax // setup.S code segment mov %ax,%ds #ifndef CONFIG_ROMCODE - pushf + pushf // check for 8088/8086/V20/V30/80188/80186 xor %ax,%ax push %ax popf @@ -23,7 +23,7 @@ getcpu: and $0xf000,%ax cmp $0xf000,%ax je is8086 - mov $0x7000,%ax + mov $0x7000,%ax // check for 80286 pushf push %ax popf @@ -32,13 +32,28 @@ getcpu: popf and $0x7000,%ax je is80286 -// -// Default & unknown CPU -// - mov $0xff,%cl + pushf // check for 32-bit CPU (80386+) + pushf + pop %bx // old FLAGS -> BX + mov %bx,%ax + xor $0x70,%ah // try changing b14 (NT) or b13:b12 (IOPL) + push %ax + popf + pushf + pop %ax // new FLAGS -> AX + popf + xor %ah,%bh + xor %ax,%ax + and $0x70,%bh // 32-bit CPU if we changed NT or IOPL + je not_32bit + mov $7,%cl // 80386+ + lea p80386,%si + jmp cpu_store + +not_32bit: // Unknown CPU + mov $255,%cl lea px86,%si jmp cpu_store - nop #endif #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) @@ -178,26 +193,19 @@ queue_end: // The processor name must not be longer than 15 characters! // #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) -p8088: .ascii "Intel 8088" - .byte 0 -p8086: .ascii "Intel 8086" - .byte 0 -pv20: .ascii "NEC V20" - .byte 0 -pv30: .ascii "NEC V30" - .byte 0 -p80188: .ascii "Intel 80188" - .byte 0 -p80186: .ascii "Intel 80186" - .byte 0 +p8088: .ascii "Intel 8088\0" +p8086: .ascii "Intel 8086\0" +pv20: .ascii "NEC V20\0" +pv30: .ascii "NEC V30\0" +p80188: .ascii "Intel 80188\0" +p80186: .ascii "Intel 80186\0" #endif #if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_80286) -p80286: .ascii "Intel 80286" - .byte 0 +p80286: .ascii "Intel 80286\0" +p80386: .ascii "Intel 80386+\0" #endif #if !defined(CONFIG_ROMCODE) -px86: .ascii "Unknown x86" - .byte 0 +px86: .ascii "Unknown x86\0" #endif // // Here is the CPU id stored diff --git a/elks/arch/i86/kernel/system.c b/elks/arch/i86/kernel/system.c index 901d750a2..d732b31fe 100644 --- a/elks/arch/i86/kernel/system.c +++ b/elks/arch/i86/kernel/system.c @@ -71,7 +71,7 @@ unsigned int INITPROC setup_arch(void) byte_t arch_cpu = SETUP_CPU_TYPE; if (arch_cpu > 5) /* IBM PC/AT capabilities */ sys_caps = CAP_ALL; - debug("arch %d sys_caps %02x\n", arch_cpu, sys_caps); + printk("arch %d sys_caps %02x\n", arch_cpu, sys_caps); #endif return endbss; /* used as start address in near heap init */ From 38788882b604cdd1d2933ca2d6264cdb65336e35 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 30 Oct 2024 17:31:03 -0700 Subject: [PATCH 2/3] Remove incorrect CONFIG_ROMCODE and CONFIG_CPU_ defines --- elks/arch/i86/boot/cputype.S | 32 ++++++++------------------------ elks/arch/i86/boot/setup.S | 8 ++++---- elks/arch/i86/kernel/system.c | 2 +- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/elks/arch/i86/boot/cputype.S b/elks/arch/i86/boot/cputype.S index 4c8dffc70..d34ec3e61 100644 --- a/elks/arch/i86/boot/cputype.S +++ b/elks/arch/i86/boot/cputype.S @@ -1,7 +1,6 @@ // obsolete and inaccurate, but required for arch_cpu = 6 and 7 (286, 386+) // XT vs AT BIOS system capabilities (sys_caps) auto-detection by kernel // -#define CONFIG_CPU_8086 /* required for this file only */ /* ! Probe for the CPU @@ -12,7 +11,6 @@ getcpu: mov $SETUPSEG,%ax // setup.S code segment mov %ax,%ds -#ifndef CONFIG_ROMCODE pushf // check for 8088/8086/V20/V30/80188/80186 xor %ax,%ax push %ax @@ -50,13 +48,11 @@ getcpu: lea p80386,%si jmp cpu_store -not_32bit: // Unknown CPU +not_32bit: // Unknown CPU mov $255,%cl lea px86,%si jmp cpu_store -#endif -#if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) is8086: mov $0xff,%al mov $0x21,%cl // 80188/86 uses only the five lower @@ -96,18 +92,14 @@ isv30: isv20: mov $2,%cl lea pv20,%si jmp cpu_store -#endif -#if !defined (CONFIG_ROMCODE) || defined(CONFIG_CPU_80286) + is80286:mov $6,%cl lea p80286,%si // jmp cpu_store -#endif cpu_store: - // - // Store the processor name and type - // - push %cx +#if UNUSED + push %cx // Store processor name mov $INITSEG,%ax mov %ax,%es mov $0x30,%di @@ -124,12 +116,13 @@ con_cp1: rep movsb pop %cx - mov $INITSEG,%ax +#endif + mov $INITSEG,%ax // Store processor type mov %ax,%ds mov %cl,0x20 + cli // FIXME reset to cli; shouldn't have sti's above ret -#if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) /* ! ! Determine the length of the prefetch queue. 8088/188/v20 has @@ -189,24 +182,19 @@ queue_end: or %dx,%dx ret + // // The processor name must not be longer than 15 characters! // -#if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086) p8088: .ascii "Intel 8088\0" p8086: .ascii "Intel 8086\0" pv20: .ascii "NEC V20\0" pv30: .ascii "NEC V30\0" p80188: .ascii "Intel 80188\0" p80186: .ascii "Intel 80186\0" -#endif -#if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_80286) p80286: .ascii "Intel 80286\0" p80386: .ascii "Intel 80386+\0" -#endif -#if !defined(CONFIG_ROMCODE) px86: .ascii "Unknown x86\0" -#endif // // Here is the CPU id stored // @@ -214,7 +202,3 @@ v_id: .byte 0,0,0,0 v_id2: .byte 0,0,0,0 v_id3: .byte 0,0,0,0 .byte 0 - -#endif /* !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_8086)*/ - -#undef CONFIG_CPU_8086 diff --git a/elks/arch/i86/boot/setup.S b/elks/arch/i86/boot/setup.S index c7db93a12..0d63e2123 100644 --- a/elks/arch/i86/boot/setup.S +++ b/elks/arch/i86/boot/setup.S @@ -52,10 +52,10 @@ ! 5 = 80186 ! 6 = 80286 ! 7 = 80386 -! 8 = 80486 -! 9 = Pentium -! 10 = Pentium PRO -! 255 = VM86 mode +! 8 = 80486 UNUSED +! 9 = Pentium UNUSED +! 10 = Pentium PRO UNUSED +! 255 = Unknown ! ... ! 0x2a: mem_kbytes word size of base memory in kbytes ! 0x30: proc_name byte[16] processor name string UNUSED diff --git a/elks/arch/i86/kernel/system.c b/elks/arch/i86/kernel/system.c index d732b31fe..db35aa737 100644 --- a/elks/arch/i86/kernel/system.c +++ b/elks/arch/i86/kernel/system.c @@ -69,7 +69,7 @@ unsigned int INITPROC setup_arch(void) sys_caps = SYS_CAPS; /* custom system capabilities */ #else byte_t arch_cpu = SETUP_CPU_TYPE; - if (arch_cpu > 5) /* IBM PC/AT capabilities */ + if (arch_cpu > 5) /* 80286+ IBM PC/AT capabilities or Unknown CPU */ sys_caps = CAP_ALL; printk("arch %d sys_caps %02x\n", arch_cpu, sys_caps); #endif From 9d10ba609cda3279b97b50bd0063a98f98db4f81 Mon Sep 17 00:00:00 2001 From: Greg Haerr Date: Wed, 30 Oct 2024 17:38:49 -0700 Subject: [PATCH 3/3] Remove processor name string saving --- elks/arch/i86/boot/cputype.S | 25 +++++++++++++------------ elks/arch/i86/boot/setup.S | 2 +- elks/arch/i86/kernel/system.c | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/elks/arch/i86/boot/cputype.S b/elks/arch/i86/boot/cputype.S index d34ec3e61..fbeda7b2a 100644 --- a/elks/arch/i86/boot/cputype.S +++ b/elks/arch/i86/boot/cputype.S @@ -1,6 +1,6 @@ // obsolete and inaccurate, but required for arch_cpu = 6 and 7 (286, 386+) // XT vs AT BIOS system capabilities (sys_caps) auto-detection by kernel -// +// Note: enables, then disables interrupts when called /* ! Probe for the CPU @@ -9,7 +9,7 @@ ! */ getcpu: - mov $SETUPSEG,%ax // setup.S code segment + mov $SETUPSEG,%ax // setup code segment mov %ax,%ds pushf // check for 8088/8086/V20/V30/80188/80186 xor %ax,%ax @@ -45,12 +45,12 @@ getcpu: and $0x70,%bh // 32-bit CPU if we changed NT or IOPL je not_32bit mov $7,%cl // 80386+ - lea p80386,%si + #lea p80386,%si jmp cpu_store not_32bit: // Unknown CPU mov $255,%cl - lea px86,%si + #lea px86,%si jmp cpu_store is8086: @@ -63,38 +63,37 @@ is8086: mov $0xffff,%cx nop rep -// seg es lodsb or %cx,%cx jz isv30 call queue jz is8088 mov $1,%cl - lea p8086,%si + #lea p8086,%si jmp cpu_store is8088: xor %cl,%cl - lea p8088,%si + #lea p8088,%si jmp cpu_store is80186:call queue jz is80188 mov $5,%cl - lea p80186,%si + #lea p80186,%si jmp cpu_store is80188:mov $4,%cl - lea p80188,%si + #lea p80188,%si jmp cpu_store isv30: call queue jz isv20 mov $3,%cl - lea pv30,%si + #lea pv30,%si jmp cpu_store isv20: mov $2,%cl - lea pv20,%si + #lea pv20,%si jmp cpu_store is80286:mov $6,%cl - lea p80286,%si + #lea p80286,%si // jmp cpu_store cpu_store: @@ -183,6 +182,7 @@ queue_end: or %dx,%dx ret +#if UNUSED // // The processor name must not be longer than 15 characters! // @@ -202,3 +202,4 @@ v_id: .byte 0,0,0,0 v_id2: .byte 0,0,0,0 v_id3: .byte 0,0,0,0 .byte 0 +#endif diff --git a/elks/arch/i86/boot/setup.S b/elks/arch/i86/boot/setup.S index 0d63e2123..93004ec04 100644 --- a/elks/arch/i86/boot/setup.S +++ b/elks/arch/i86/boot/setup.S @@ -43,7 +43,7 @@ ! 10: mono/color, video memory size, 2 bytes ! 14: screen_lines, 1 byte ! 15: VGA present, 1 byte -! 0x20: cpu_type byte Processor type UNUSED +! 0x20: cpu_type byte Processor type ! 0 = 8088 ! 1 = 8086 ! 2 = NEC V20 diff --git a/elks/arch/i86/kernel/system.c b/elks/arch/i86/kernel/system.c index db35aa737..7278b683b 100644 --- a/elks/arch/i86/kernel/system.c +++ b/elks/arch/i86/kernel/system.c @@ -71,7 +71,7 @@ unsigned int INITPROC setup_arch(void) byte_t arch_cpu = SETUP_CPU_TYPE; if (arch_cpu > 5) /* 80286+ IBM PC/AT capabilities or Unknown CPU */ sys_caps = CAP_ALL; - printk("arch %d sys_caps %02x\n", arch_cpu, sys_caps); + debug("arch %d sys_caps %02x\n", arch_cpu, sys_caps); #endif return endbss; /* used as start address in near heap init */