Skip to content

Commit 35e8454

Browse files
minuxbradfitz
authored andcommitted
runtime: check and fail early with a message if MMX is not available on 386
Fixes #12970. Change-Id: Id0026e8274e071d65d47df63d65a93110abbec5d Reviewed-on: https://go-review.googlesource.com/15998 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4a29150 commit 35e8454

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/runtime/asm_386.s

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
2626
MOVL SP, (g_stack+stack_hi)(BP)
2727

2828
// find out information about the processor we're on
29+
#ifdef GOOS_nacl // NaCl doesn't like PUSHFL/POPFL
30+
JMP has_cpuid
31+
#else
32+
// first see if CPUID instruction is supported.
33+
PUSHFL
34+
PUSHFL
35+
XORL $(1<<21), 0(SP) // flip ID bit
36+
POPFL
37+
PUSHFL
38+
POPL AX
39+
XORL 0(SP), AX
40+
POPFL // restore EFLAGS
41+
TESTL $(1<<21), AX
42+
JNE has_cpuid
43+
#endif
44+
45+
bad_proc: // show that the program requires MMX.
46+
MOVL $2, 0(SP)
47+
MOVL $bad_proc_msg<>(SB), 4(SP)
48+
MOVL $0x3d, 8(SP)
49+
CALL runtime·write(SB)
50+
MOVL $1, 0(SP)
51+
CALL runtime·exit(SB)
52+
INT $3
53+
54+
has_cpuid:
2955
MOVL $0, AX
3056
CPUID
3157
CMPL AX, $0
@@ -48,6 +74,11 @@ notintel:
4874
MOVL CX, AX // Move to global variable clobbers CX when generating PIC
4975
MOVL AX, runtime·cpuid_ecx(SB)
5076
MOVL DX, runtime·cpuid_edx(SB)
77+
78+
// Check for MMX support
79+
TESTL $(1<<23), DX // MMX
80+
JZ bad_proc
81+
5182
nocpuinfo:
5283

5384
// if there is an _cgo_init, call it to let it
@@ -129,6 +160,17 @@ ok:
129160
INT $3
130161
RET
131162

163+
DATA bad_proc_msg<>+0x00(SB)/8, $"This pro"
164+
DATA bad_proc_msg<>+0x08(SB)/8, $"gram can"
165+
DATA bad_proc_msg<>+0x10(SB)/8, $" only be"
166+
DATA bad_proc_msg<>+0x18(SB)/8, $" run on "
167+
DATA bad_proc_msg<>+0x20(SB)/8, $"processe"
168+
DATA bad_proc_msg<>+0x28(SB)/8, $"rs with "
169+
DATA bad_proc_msg<>+0x30(SB)/8, $"MMX supp"
170+
DATA bad_proc_msg<>+0x38(SB)/4, $"ort."
171+
DATA bad_proc_msg<>+0x3c(SB)/1, $0xa
172+
GLOBL bad_proc_msg<>(SB), RODATA, $0x3d
173+
132174
DATA runtime·mainPC+0(SB)/4,$runtime·main(SB)
133175
GLOBL runtime·mainPC(SB),RODATA,$4
134176

0 commit comments

Comments
 (0)