summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorThomas Bushnell <thomas@gnu.org>1997-02-25 21:28:37 +0000
committerThomas Bushnell <thomas@gnu.org>1997-02-25 21:28:37 +0000
commitf07a4c844da9f0ecae5bbee1ab94be56505f26f7 (patch)
tree12b07c7e578fc1a5f53dbfde2632408491ff2a70 /util
Initial source
Diffstat (limited to 'util')
-rw-r--r--util/Makerules32
-rw-r--r--util/about_to_die.c34
-rw-r--r--util/config.h23
-rw-r--r--util/cpu.c27
-rw-r--r--util/cpu.h41
-rw-r--r--util/cpu_init.c40
-rw-r--r--util/cpu_subs.h23
-rw-r--r--util/cpus.h27
-rw-r--r--util/debug.h81
-rw-r--r--util/die.c54
-rw-r--r--util/panic.c48
-rw-r--r--util/phys_mem.h34
-rw-r--r--util/putchar.c28
-rw-r--r--util/puts.c37
-rw-r--r--util/ref_count.h68
15 files changed, 597 insertions, 0 deletions
diff --git a/util/Makerules b/util/Makerules
new file mode 100644
index 0000000..0d6a231
--- /dev/null
+++ b/util/Makerules
@@ -0,0 +1,32 @@
+#
+# Copyright (c) 1994 The University of Utah and
+# the Computer Systems Laboratory (CSL). All rights reserved.
+#
+# Permission to use, copy, modify and distribute this software and its
+# documentation is hereby granted, provided that both the copyright
+# notice and this permission notice appear in all copies of the
+# software, derivative works or modified versions, and any portions
+# thereof, and that both notices appear in supporting documentation.
+#
+# THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+# IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
+# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+#
+# CSS requests users of this software to return to css-dist@cs.utah.edu any
+# improvements that they make and grant CSS redistribution rights.
+#
+# Author: Bryan Ford, University of Utah CSS
+#
+ifndef _kernel_util_makerules_
+_kernel_util_makerules = yes
+
+
+# Old defines that I hope to phase out
+DEFINES += -DMACH_KERNEL
+
+
+# Include the makefile containing the generic rules.
+include $(GSRCDIR)/Makerules
+
+
+endif
diff --git a/util/about_to_die.c b/util/about_to_die.c
new file mode 100644
index 0000000..9b039cc
--- /dev/null
+++ b/util/about_to_die.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+/* Call this to declare intention to die,
+ before doing final printfs and such.
+ The default implementation does nothing,
+ but typical actions might be to restore the video mode
+ to a standard setting, or stop other processors.
+ Note that this might very well be called several times
+ before die() is finally called. */
+void about_to_die(int exit_code)
+{
+}
+
diff --git a/util/config.h b/util/config.h
new file mode 100644
index 0000000..23b2bf6
--- /dev/null
+++ b/util/config.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+/* This file is just an empty default config.h file. */
diff --git a/util/cpu.c b/util/cpu.c
new file mode 100644
index 0000000..0e45ac4
--- /dev/null
+++ b/util/cpu.c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include "cpu.h"
+
+struct cpu cpu[NCPUS];
+
diff --git a/util/cpu.h b/util/cpu.h
new file mode 100644
index 0000000..357f6d7
--- /dev/null
+++ b/util/cpu.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _UTIL_CPU_H_
+#define _UTIL_CPU_H_
+
+#include "cpus.h"
+
+
+/* There's one of these data structures per processor. */
+struct cpu
+{
+#define cpu_sub(name) struct cpu_##name name;
+#include "cpu_subs.h"
+#undef cpu_sub
+int dummy;
+};
+
+extern struct cpu cpu[NCPUS];
+
+
+#endif _UTIL_CPU_H_
diff --git a/util/cpu_init.c b/util/cpu_init.c
new file mode 100644
index 0000000..c59824b
--- /dev/null
+++ b/util/cpu_init.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include "cpu.h"
+
+void cpu_init(struct cpu *cpu)
+{
+#define cpu_sub(name) cpu_##name##_init(cpu);
+#include "cpu_subs.h"
+#undef cpu_sub
+}
+
+void cpus_init()
+{
+ int n;
+
+ for (n = 0; n < NCPUS; n++)
+ cpu_init(&cpu[n]);
+}
+
diff --git a/util/cpu_subs.h b/util/cpu_subs.h
new file mode 100644
index 0000000..850ef38
--- /dev/null
+++ b/util/cpu_subs.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+/* This file is just a terminator for the set of cpu_subs.h headers. */
diff --git a/util/cpus.h b/util/cpus.h
new file mode 100644
index 0000000..355ecdb
--- /dev/null
+++ b/util/cpus.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+/* Default cpus.h sets things up for a uniprocessor. */
+#define NCPUS 1
+#undef MULTIPROCESSOR
+
diff --git a/util/debug.h b/util/debug.h
new file mode 100644
index 0000000..d61502b
--- /dev/null
+++ b/util/debug.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1995-1993 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+/*
+ * File: debug.h
+ * Author: Bryan Ford
+ *
+ * This file contains definitions for kernel debugging,
+ * which are compiled in on the DEBUG symbol.
+ *
+ */
+#ifndef _MACH_UTIL_DEBUG_H_
+#define _MACH_UTIL_DEBUG_H_
+
+#include <mach/macro_help.h>
+
+
+#ifdef DEBUG
+
+extern void panic(const char *fmt, ...);
+
+#define here() printf("@ %s:%d\n", __FILE__, __LINE__)
+#define message(args) ({ printf("@ %s:%d: ", __FILE__, __LINE__); printf args; printf("\n"); })
+
+#define otsan() panic("%s:%d: off the straight and narrow!", __FILE__, __LINE__)
+
+#define assert(v) \
+ MACRO_BEGIN \
+ if (!(v)) \
+ panic("%s:%d: failed assertion `"#v"'\n", \
+ __FILE__, __LINE__); \
+ MACRO_END
+
+#define do_debug(stmt) stmt
+
+#define debugmsg(args) \
+ ({ printf("%s:%d: ", __FILE__, __LINE__); printf args; printf("\n"); })
+
+#define struct_id_decl unsigned struct_id;
+#define struct_id_init(p,id) ((p)->struct_id = (id))
+#define struct_id_denit(p) ((p)->struct_id = 0)
+#define struct_id_verify(p,id) \
+ ({ if ((p)->struct_id != (id)) \
+ panic("%s:%d: "#p" (%08x) struct_id should be "#id" (%08x), is %08x\n", \
+ __FILE__, __LINE__, (p), (id), (p->struct_id)); \
+ })
+
+#else !DEBUG
+
+#define otsan()
+#define assert(v)
+#define do_debug(stmt)
+#define debugmsg(args)
+
+#define struct_id_decl
+#define struct_id_init(p,id)
+#define struct_id_denit(p)
+#define struct_id_verify(p,id)
+
+#endif !DEBUG
+
+#endif _MACH_UTIL_DEBUG_H_
diff --git a/util/die.c b/util/die.c
new file mode 100644
index 0000000..c2eeeaf
--- /dev/null
+++ b/util/die.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <stdarg.h>
+
+/* Note: These routines are deprecated and should not be used anymore.
+ Use panic() instead. */
+void die(const char *fmt, ...)
+{
+ int exit_code = fmt != 0;
+
+ about_to_die(exit_code);
+
+ if (fmt)
+ {
+ va_list vl;
+
+ va_start(vl, fmt);
+ vprintf(fmt, vl);
+ va_end(vl);
+
+ putchar('\n');
+
+ exit(exit_code);
+ }
+ else
+ exit(exit_code);
+}
+
+void die_no_mem(void)
+{
+ die("Not enough memory.");
+}
+
diff --git a/util/panic.c b/util/panic.c
new file mode 100644
index 0000000..2df8839
--- /dev/null
+++ b/util/panic.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+void panic(const char *fmt, ...)
+{
+ int exit_code = fmt != 0;
+
+ about_to_die(exit_code);
+
+ if (fmt)
+ {
+ va_list vl;
+
+ va_start(vl, fmt);
+ vprintf(fmt, vl);
+ va_end(vl);
+
+ putchar('\n');
+
+ exit(exit_code);
+ }
+ else
+ exit(exit_code);
+}
+
diff --git a/util/phys_mem.h b/util/phys_mem.h
new file mode 100644
index 0000000..2e18a6b
--- /dev/null
+++ b/util/phys_mem.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _UTIL_PHYS_MEM_H_
+#define _UTIL_PHYS_MEM_H_
+
+#include <mach/machine/vm_types.h>
+
+
+/* This always holds the physical address
+ of the top of known physical memory. */
+extern vm_offset_t phys_mem_max;
+
+
+#endif _UTIL_PHYS_MEM_H_
diff --git a/util/putchar.c b/util/putchar.c
new file mode 100644
index 0000000..18f0f06
--- /dev/null
+++ b/util/putchar.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+int putchar(int c)
+{
+ cnputc(c);
+}
+
diff --git a/util/puts.c b/util/puts.c
new file mode 100644
index 0000000..c0eec03
--- /dev/null
+++ b/util/puts.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+/* Simple puts() implementation that just uses putchar().
+ Note that our libc's printf() is implemented
+ in terms of only puts() and putchar(), so that's all we need. */
+int puts(const char *s)
+{
+ while (*s)
+ {
+ putchar(*s);
+ s++;
+ }
+ putchar('\n');
+ return 0;
+}
+
diff --git a/util/ref_count.h b/util/ref_count.h
new file mode 100644
index 0000000..b6d3404
--- /dev/null
+++ b/util/ref_count.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 1995-1993 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+/*
+ * File: refcount.h
+ *
+ * This defines the system-independent atomic reference count data type.
+ * (This file will often be overridden
+ * by better machine-dependent implementations.)
+ *
+ */
+
+#ifndef _KERN_REF_COUNT_H_
+#define _KERN_REF_COUNT_H_
+
+#include <mach/macro_help.h>
+
+#include "simple_lock.h"
+
+
+struct ref_count {
+ decl_simple_lock_data(,lock) /* lock for reference count */
+ int count; /* number of references */
+};
+
+#define ref_count_init(refcount, refs) \
+ MACRO_BEGIN \
+ simple_lock_init(&(refcount)->lock); \
+ ((refcount)->count = (refs)); \
+ MACRO_END
+
+#define ref_count_take(refcount) \
+ MACRO_BEGIN \
+ simple_lock(&(refcount)->lock); \
+ (refcount)->count++; \
+ simple_unlock(&(refcount)->lock); \
+ MACRO_END
+
+#define ref_count_drop(refcount, func) \
+ MACRO_BEGIN \
+ int new_value; \
+ simple_lock(&(refcount)->lock); \
+ new_value = --(refcount)->count; \
+ simple_unlock(&(refcount)->lock); \
+ if (new_value == 0) { func; } \
+ MACRO_END
+
+
+#endif _KERN_REF_COUNT_H_