1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Functions to provide access to special i386 instructions.
|
|
|
|
* XXX - bezillions more are defined in locore.s but are not declared anywhere.
|
1993-10-16 14:40:57 +00:00
|
|
|
*
|
1993-12-21 21:27:04 +00:00
|
|
|
* $Id: cpufunc.h,v 1.6 1993/12/19 00:50:14 wollman Exp $
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1993-11-07 17:43:17 +00:00
|
|
|
#ifndef _MACHINE_CPUFUNC_H_
|
|
|
|
#define _MACHINE_CPUFUNC_H_ 1
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline int bdb(void)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
extern int bdb_exists;
|
|
|
|
|
|
|
|
if (!bdb_exists)
|
|
|
|
return (0);
|
|
|
|
__asm("int $3");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline void
|
1993-06-12 14:58:17 +00:00
|
|
|
disable_intr(void)
|
|
|
|
{
|
|
|
|
__asm __volatile("cli");
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline void
|
1993-06-12 14:58:17 +00:00
|
|
|
enable_intr(void)
|
|
|
|
{
|
|
|
|
__asm __volatile("sti");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This roundabout method of returning a u_char helps stop gcc-1.40 from
|
|
|
|
* generating unnecessary movzbl's.
|
|
|
|
*/
|
|
|
|
#define inb(port) ((u_char) u_int_inb(port))
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline u_int
|
1993-06-12 14:58:17 +00:00
|
|
|
u_int_inb(u_int port)
|
|
|
|
{
|
|
|
|
u_char data;
|
|
|
|
/*
|
|
|
|
* We use %%dx and not %1 here because i/o is done at %dx and not at
|
|
|
|
* %edx, while gcc-2.2.2 generates inferior code (movw instead of movl)
|
|
|
|
* if we tell it to load (u_short) port.
|
|
|
|
*/
|
|
|
|
__asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline void
|
1993-06-12 14:58:17 +00:00
|
|
|
outb(u_int port, u_char data)
|
|
|
|
{
|
|
|
|
register u_char al asm("ax");
|
|
|
|
|
|
|
|
al = data; /* help gcc-1.40's register allocator */
|
|
|
|
__asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
|
|
|
int
|
1993-07-27 10:52:31 +00:00
|
|
|
imin(a, b)
|
|
|
|
int a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a < b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
|
|
|
int
|
1993-07-27 10:52:31 +00:00
|
|
|
imax(a, b)
|
|
|
|
int a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a > b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
unsigned int
|
|
|
|
min(a, b)
|
|
|
|
unsigned int a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a < b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
unsigned int
|
|
|
|
max(a, b)
|
|
|
|
unsigned int a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a > b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
long
|
|
|
|
lmin(a, b)
|
|
|
|
long a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a < b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
long
|
|
|
|
lmax(a, b)
|
|
|
|
long a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a > b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
unsigned long
|
|
|
|
ulmin(a, b)
|
|
|
|
unsigned long a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a < b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
unsigned long
|
|
|
|
ulmax(a, b)
|
|
|
|
unsigned long a, b;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a > b ? a : b);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
|
|
|
int
|
1993-07-27 10:52:31 +00:00
|
|
|
ffs(mask)
|
|
|
|
register long mask;
|
|
|
|
{
|
|
|
|
register int bit;
|
|
|
|
|
|
|
|
if (!mask)
|
|
|
|
return(0);
|
|
|
|
for (bit = 1;; ++bit) {
|
|
|
|
if (mask&0x01)
|
|
|
|
return(bit);
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
|
|
|
int
|
1993-07-27 10:52:31 +00:00
|
|
|
bcmp(v1, v2, len)
|
|
|
|
void *v1, *v2;
|
|
|
|
register unsigned len;
|
|
|
|
{
|
|
|
|
register u_char *s1 = v1, *s2 = v2;
|
|
|
|
|
|
|
|
while (len--)
|
|
|
|
if (*s1++ != *s2++)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static inline
|
1993-07-27 10:52:31 +00:00
|
|
|
size_t
|
|
|
|
strlen(s1)
|
1993-11-25 01:38:01 +00:00
|
|
|
register const char *s1;
|
1993-07-27 10:52:31 +00:00
|
|
|
{
|
|
|
|
register size_t len;
|
|
|
|
|
|
|
|
for (len = 0; *s1++ != '\0'; len++)
|
|
|
|
;
|
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
1993-12-19 00:55:01 +00:00
|
|
|
struct quehead {
|
|
|
|
struct quehead *qh_link;
|
|
|
|
struct quehead *qh_rlink;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
insque(void *a, void *b)
|
|
|
|
{
|
|
|
|
register struct quehead *element = a, *head = b;
|
|
|
|
element->qh_link = head->qh_link;
|
|
|
|
head->qh_link = (struct quehead *)element;
|
|
|
|
element->qh_rlink = (struct quehead *)head;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink
|
|
|
|
= (struct quehead *)element;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
remque(void *a)
|
|
|
|
{
|
|
|
|
register struct quehead *element = a;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
|
|
|
|
((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
|
|
|
|
element->qh_rlink = 0;
|
|
|
|
}
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#else /* not __GNUC__ */
|
1993-12-19 00:55:01 +00:00
|
|
|
extern void insque __P((void *, void *));
|
|
|
|
extern void remque __P((void *));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
int bdb __P((void));
|
|
|
|
void disable_intr __P((void));
|
|
|
|
void enable_intr __P((void));
|
|
|
|
u_char inb __P((u_int port));
|
|
|
|
void outb __P((u_int port, u_int data)); /* XXX - incompat */
|
|
|
|
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
|
|
|
|
void load_cr0 __P((u_int cr0));
|
1993-12-19 00:55:01 +00:00
|
|
|
u_int rcr0 __P((void));
|
|
|
|
void load_cr3(u_long);
|
|
|
|
u_long rcr3(void);
|
|
|
|
u_long rcr2(void);
|
|
|
|
|
|
|
|
void setidt __P((int, void (*)(), int, int));
|
|
|
|
extern u_long kvtop(void *);
|
|
|
|
extern void tlbflush(void);
|
|
|
|
extern void outw(int /*u_short*/, int /*u_short*/); /* XXX inline!*/
|
1993-12-21 21:27:04 +00:00
|
|
|
extern void outsb(int /*u_short*/, void *, size_t);
|
|
|
|
extern void outsw(int /*u_short*/, void *, size_t);
|
|
|
|
extern void insw(int /*u_short*/, void *, size_t);
|
|
|
|
extern void fillw(int /*u_short*/, void *, size_t);
|
1993-07-27 10:52:31 +00:00
|
|
|
|
1993-11-07 17:43:17 +00:00
|
|
|
#endif /* _MACHINE_CPUFUNC_H_ */
|