Skip to content

Commit

Permalink
Merge pull request #2089 from ghaerr/cputest
Browse files Browse the repository at this point in the history
[setup] Add 80386+ CPU testing to cputest.S
  • Loading branch information
ghaerr authored Oct 31, 2024
2 parents 5809d15 + 9d10ba6 commit 2d59813
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 64 deletions.
109 changes: 51 additions & 58 deletions elks/arch/i86/boot/cputype.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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 */
// Note: enables, then disables interrupts when called

/*
! Probe for the CPU
Expand All @@ -10,10 +9,9 @@
!
*/
getcpu:
mov $SETUPSEG,%ax /* Codesegment setup.S */
mov $SETUPSEG,%ax // setup code segment
mov %ax,%ds
#ifndef CONFIG_ROMCODE
pushf
pushf // check for 8088/8086/V20/V30/80188/80186
xor %ax,%ax
push %ax
popf
Expand All @@ -23,7 +21,7 @@ getcpu:
and $0xf000,%ax
cmp $0xf000,%ax
je is8086
mov $0x7000,%ax
mov $0x7000,%ax // check for 80286
pushf
push %ax
popf
Expand All @@ -32,16 +30,29 @@ getcpu:
popf
and $0x7000,%ax
je is80286
//
// Default & unknown CPU
//
mov $0xff,%cl
lea px86,%si
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)
is8086:
mov $0xff,%al
mov $0x21,%cl // 80188/86 uses only the five lower
Expand All @@ -52,47 +63,42 @@ 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
#endif
#if !defined (CONFIG_ROMCODE) || defined(CONFIG_CPU_80286)

is80286:mov $6,%cl
lea p80286,%si
#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
Expand All @@ -109,12 +115,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
Expand Down Expand Up @@ -174,39 +181,25 @@ queue_end:

or %dx,%dx
ret

#if UNUSED
//
// 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
#endif
#if !defined(CONFIG_ROMCODE) || defined(CONFIG_CPU_80286)
p80286: .ascii "Intel 80286"
.byte 0
#endif
#if !defined(CONFIG_ROMCODE)
px86: .ascii "Unknown x86"
.byte 0
#endif
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"
p80286: .ascii "Intel 80286\0"
p80386: .ascii "Intel 80386+\0"
px86: .ascii "Unknown x86\0"
//
// Here is the CPU id stored
//
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
#endif
10 changes: 5 additions & 5 deletions elks/arch/i86/boot/setup.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elks/arch/i86/kernel/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
debug("arch %d sys_caps %02x\n", arch_cpu, sys_caps);
#endif
Expand Down

0 comments on commit 2d59813

Please sign in to comment.