/*
 * cpu.S86  -  Check if we are running on a 386+ processor
 *
 * Copyright (C) 2003-2007 Gero Kuhlmann   <gero@gkminix.han.de>
 *
 *  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; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: cpu.S86,v 1.7 2007/01/06 18:30:51 gkminix Exp $
 *
 *====================================================================
 */


#include <common.i86>

.file __FILE__
.line __LINE__



/*
 *====================================================================
 *
 * Start the text segment and define all public entry points. For
 * the sake of compatibility, this module should NOT use a BSS
 * segment!
 */

	.text

	.global	chkcpu			# define global symbols



/*
 *====================================================================
 *
 * Check that we are running on a 386+ processor
 * NOTE: This routine is not allowed to use the BSS segment!!
 * Input:  None
 * Output: SI  -  Pointer to error message, 0 if no error
 * Changed registers: AX, SI, EBP
 */
chkcpu:	push	cx
	mov	cl,33
	mov	ax,0xFFFF		# the 8088 and 8086 will actually
	shl	ax,cl			# shift over by 33 bits
	jz	1f

	push	sp
	pop	ax
	cmp	ax,sp			# 286 or better?
	jne	1f

	pushf				# save original flags
	pushf
	pop	ax
	or	ax,0x7000		# set IOPL field in status word
	push	ax
	popf
	pushf
	pop	ax
	popf				# restore original flags
	test	ax,0x7000		# a 386+ lets us set the IOPL field
	jz	1f

	xor	si,si			# return without error
	xor	ebp,ebp			# this is necessary for GCC!!!
	jmp	9f

1:	mov	si,offset cpuerr	# return pointer to error message
9:	pop	cx
	ret




/*
 *====================================================================
 *
 * Read-only data definitions
 */
	_rodata

/* Error messages */
cpuerr:	.asciz	"Not running on a 386+ processor"




/*
 *====================================================================
 */
	.end

