# # Code to detect an easter-egg with early AMD64 processors # # assemble/link with "as -o hammer.o hammer.s ; ld -o hammer hammer.o" # # by Vince Weaver 2004 # Easter egg pointed out by Adam Sulmicki # # Problems with the code (due to assembler updates that enforce # stack alignment) pointed out by # poly-p man April 2009 # I also improved the code a bit, and made it fully 64-bit clean # # This easter egg is mentioned as "mystery level" at # http://www.sandpile.org/ia32/cpuid.htm # # It works on a 15/4/10 original AMD Opteron I have access to # but not on any newer machines # # In theory it should print a different message on K6 machines, I haven't # tested that (my K6-2+ is currently turned off, alas) # # SPOILER: for those curious, the message printed is listed at the # end of this file # Sycscalls .equ SYSCALL_EXIT, 60 .equ SYSCALL_WRITE, 1 .equ STDOUT,1 .globl _start _start: mov $0x8fffffff,%eax # Load magic value into ax cpuid # call cpuid cmp $0,%eax # Check to see if we got anything je unsupported mov %eax,string # store the result mov %ebx,string+4 # to memory mov %ecx,string+8 mov %edx,string+12 movb $'\n',string+16 # Tack a linefeed onto the end. mov $string, %rsi jmp write_stdout unsupported: mov $sorry, %rsi # print unsupported message write_stdout: push $SYSCALL_WRITE # put 4 in eax (write syscall) pop %rax # in 3 bytes of code push $1 pop %rdi # put 1 in rdi (stdout) push $17 pop %rdx # length of string syscall # run the syscall #================================ # Exit #================================ exit: xor %rdi,%rdi push $SYSCALL_EXIT pop %rax # put exit syscall number (1) in eax syscall # and exit #============================================================================ # section .bss #============================================================================ .bss .lcomm string, 18 .data sorry: .asciz "Unsupported chip\n" # SPOILER: # IT'S HAMMER TIME