/* vim: set filetype=c:
 *
 * misc.h86  -  Various interface function for target library
 *
 * 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: misc.h86,v 1.9 2007/01/06 18:30:54 gkminix Exp $
 */


#ifndef I386_MISC_H86
#define I386_MISC_H86



/*
 **************************************************************************
 *
 * This file can not be included into assembler source
 */
#ifndef _ASSEMBLY_

#include <common.h86>



/*
 **************************************************************************
 *
 * Handle segment registers
 */

/* Get DS register */
__nb_inline__ __u16 getds(void)
{
  register __u16 ret;

  __asm__ __volatile__ (
	"mov %%ds,%0"
	: "=&r" (ret)
	: /* no input */ );
  return(ret);
}


/* Get ES register */
__nb_inline__ __u16 getes(void)
{
  register __u16 ret;

  __asm__ __volatile__ (
	"mov %%es,%0"
	: "=&r" (ret)
	: /* no input */ );
  return(ret);
}


/* Set ES register */
__nb_inline__ void setes(__u16 seg)
{
  __asm__ __volatile__(
	"mov %0,%%es"
	: /* no output */
	: "r" (seg));
}




/*
 **************************************************************************
 *
 * Random number generator
 */
extern unsigned long random(unsigned long mask);



/*
 **************************************************************************
 *
 * BOOTP routines in the runtime library. These routines should not be
 * used by the bootrom, which implements it's own BOOTP handling.
 */
#if !defined(_BOOTROM_) && defined(NEED_BOOTP)

/* External data structures */
extern __u16 bootplen asm ("bootplen");		/* Length of BOOTP record */
extern struct bootp bootpbuf asm ("bootpbuf");	/* Space to hold BOOTP record */


/* Routine to get a certain BOOTP tag */
__nb_inline__ __u8 *bootp_tag(unsigned short tagnum, unsigned short *len)
{
  __u16 ret;
  __u16 blen;
  __u16 d0;

  __asm__ __volatile__(
	"call btptag"
	: "=&D" (ret), "=&c" (blen), "=&a" (d0)
	: "2" ((__u16)tagnum));
  *len = blen;
  return((__u8 *)((unsigned long)ret));
}

#endif

#endif /* _ASSEMBLY_ */

#endif

