clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

2
.clang-format Normal file
View File

@@ -0,0 +1,2 @@
IncludeBlocks: Preserve
SortIncludes: Never

View File

@@ -43,9 +43,7 @@
* is less than either x or y (the choice to compare with x or y is * is less than either x or y (the choice to compare with x or y is
* arbitrary). * arbitrary).
*/ */
long long long long __adddi3(long long a, long long b) {
__adddi3(long long a, long long b)
{
union uu aa, bb, sum; union uu aa, bb, sum;
aa.ll = a; aa.ll = a;

View File

@@ -40,9 +40,7 @@
/* /*
* Return a & b, in long long. * Return a & b, in long long.
*/ */
long long long long __anddi3(long long a, long long b) {
__anddi3(long long a, long long b)
{
union uu aa, bb; union uu aa, bb;
aa.ll = a; aa.ll = a;

View File

@@ -41,9 +41,7 @@
* Shift a (signed) long long value left (arithmetic shift left). * Shift a (signed) long long value left (arithmetic shift left).
* This is the same as logical shift left! * This is the same as logical shift left!
*/ */
long long long long __ashldi3(long long a, unsigned int shift) {
__ashldi3(long long a, unsigned int shift)
{
union uu aa; union uu aa;
if (shift == 0) if (shift == 0)
@@ -53,8 +51,7 @@ __ashldi3(long long a, unsigned int shift)
aa.ui[H] = aa.ui[L] << (shift - INT_BITS); aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
aa.ui[L] = 0; aa.ui[L] = 0;
} else { } else {
aa.ui[H] = (aa.ui[H] << shift) | aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
(aa.ui[L] >> (INT_BITS - shift));
aa.ui[L] <<= shift; aa.ui[L] <<= shift;
} }
return (aa.ll); return (aa.ll);

View File

@@ -40,9 +40,7 @@
/* /*
* Shift a (signed) long long value right (arithmetic shift right). * Shift a (signed) long long value right (arithmetic shift right).
*/ */
long long long long __ashrdi3(long long a, unsigned int shift) {
__ashrdi3(long long a, unsigned int shift)
{
union uu aa; union uu aa;
if (shift == 0) if (shift == 0)
@@ -64,8 +62,7 @@ __ashrdi3(long long a, unsigned int shift)
aa.ui[L] = aa.si[H] >> (shift - INT_BITS); aa.ui[L] = aa.si[H] >> (shift - INT_BITS);
aa.ui[H] = s; aa.ui[H] = s;
} else { } else {
aa.ui[L] = (aa.ui[L] >> shift) | aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
(aa.ui[H] << (INT_BITS - shift));
/* LINTED inherits machine dependency */ /* LINTED inherits machine dependency */
aa.si[H] >>= shift; aa.si[H] >>= shift;
} }

View File

@@ -42,13 +42,14 @@
* Both a and b are considered signed---which means only the high word is * Both a and b are considered signed---which means only the high word is
* signed. * signed.
*/ */
int int __cmpdi2(long long a, long long b) {
__cmpdi2(long long a, long long b)
{
union uu aa, bb; union uu aa, bb;
aa.ll = a; aa.ll = a;
bb.ll = b; bb.ll = b;
return (aa.si[H] < bb.si[H] ? 0 : aa.si[H] > bb.si[H] ? 2 : return (aa.si[H] < bb.si[H] ? 0
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1); : aa.si[H] > bb.si[H] ? 2
: aa.ui[L] < bb.ui[L] ? 0
: aa.ui[L] > bb.ui[L] ? 2
: 1);
} }

View File

@@ -41,9 +41,7 @@
* Divide two signed long longs. * Divide two signed long longs.
* ??? if -1/2 should produce -1 on this machine, this code is wrong * ??? if -1/2 should produce -1 on this machine, this code is wrong
*/ */
long long long long __divdi3(long long a, long long b) {
__divdi3(long long a, long long b)
{
unsigned long long ua, ub, uq; unsigned long long ua, ub, uq;
int neg = 0; int neg = 0;

View File

@@ -40,9 +40,7 @@
/* /*
* Return a | b, in long long. * Return a | b, in long long.
*/ */
long long long long __iordi3(long long a, long long b) {
__iordi3(long long a, long long b)
{
union uu aa, bb; union uu aa, bb;
aa.ll = a; aa.ll = a;

View File

@@ -87,7 +87,6 @@ union uu {
#define L 1 #define L 1
#endif #endif
/* /*
* Total number of bits in a long long and in the pieces that make it up. * Total number of bits in a long long and in the pieces that make it up.
* These are used for shifting, and also below for halfword extraction * These are used for shifting, and also below for halfword extraction

View File

@@ -41,9 +41,7 @@
* Shift an (unsigned) long long value left (logical shift left). * Shift an (unsigned) long long value left (logical shift left).
* This is the same as arithmetic shift left! * This is the same as arithmetic shift left!
*/ */
long long long long __lshldi3(long long a, unsigned int shift) {
__lshldi3(long long a, unsigned int shift)
{
union uu aa; union uu aa;
if (shift == 0) if (shift == 0)
@@ -53,8 +51,7 @@ __lshldi3(long long a, unsigned int shift)
aa.ui[H] = aa.ui[L] << (shift - INT_BITS); aa.ui[H] = aa.ui[L] << (shift - INT_BITS);
aa.ui[L] = 0; aa.ui[L] = 0;
} else { } else {
aa.ui[H] = (aa.ui[H] << shift) | aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
(aa.ui[L] >> (INT_BITS - shift));
aa.ui[L] <<= shift; aa.ui[L] <<= shift;
} }
return (aa.ll); return (aa.ll);

View File

@@ -40,9 +40,7 @@
/* /*
* Shift an (unsigned) long long value right (logical shift right). * Shift an (unsigned) long long value right (logical shift right).
*/ */
long long long long __lshrdi3(long long a, unsigned int shift) {
__lshrdi3(long long a, unsigned int shift)
{
union uu aa; union uu aa;
if (shift == 0) if (shift == 0)
@@ -52,8 +50,7 @@ __lshrdi3(long long a, unsigned int shift)
aa.ui[L] = aa.ui[H] >> (shift - INT_BITS); aa.ui[L] = aa.ui[H] >> (shift - INT_BITS);
aa.ui[H] = 0; aa.ui[H] = 0;
} else { } else {
aa.ui[L] = (aa.ui[L] >> shift) | aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
(aa.ui[H] << (INT_BITS - shift));
aa.ui[H] >>= shift; aa.ui[H] >>= shift;
} }
return (aa.ll); return (aa.ll);

View File

@@ -42,9 +42,7 @@
* *
* XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent. * XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent.
*/ */
long long long long __moddi3(long long a, long long b) {
__moddi3(long long a, long long b)
{
unsigned long long ua, ub, ur; unsigned long long ua, ub, ur;
int neg = 0; int neg = 0;

View File

@@ -96,9 +96,7 @@
*/ */
static long long __lmulq(unsigned int, unsigned int); static long long __lmulq(unsigned int, unsigned int);
long long long long __muldi3(long long a, long long b) {
__muldi3(long long a, long long b)
{
union uu u, v, low, prod; union uu u, v, low, prod;
unsigned int high, mid, udiff, vdiff; unsigned int high, mid, udiff, vdiff;
int negall, negmid; int negall, negmid;
@@ -152,8 +150,7 @@ __muldi3(long long a, long long b)
/* /*
* Assemble the final product. * Assemble the final product.
*/ */
prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] + prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] + low.ui[H];
low.ui[H];
prod.ui[L] = low.ui[L]; prod.ui[L] = low.ui[L];
} }
return (negall ? -prod.ll : prod.ll); return (negall ? -prod.ll : prod.ll);
@@ -180,9 +177,7 @@ __muldi3(long long a, long long b)
* *
* splits into high and low ints as HHALF(l) and LHUP(l) respectively. * splits into high and low ints as HHALF(l) and LHUP(l) respectively.
*/ */
static long long static long long __lmulq(unsigned int u, unsigned int v) {
__lmulq(unsigned int u, unsigned int v)
{
unsigned int u1, u0, v1, v0, udiff, vdiff, high, mid, low; unsigned int u1, u0, v1, v0, udiff, vdiff, high, mid, low;
unsigned int prodh, prodl, was; unsigned int prodh, prodl, was;
union uu prod; union uu prod;

View File

@@ -40,9 +40,7 @@
/* /*
* Return -a (or, equivalently, 0 - a), in long long. See subdi3.c. * Return -a (or, equivalently, 0 - a), in long long. See subdi3.c.
*/ */
long long long long __negdi2(long long a) {
__negdi2(long long a)
{
union uu aa, res; union uu aa, res;
aa.ll = a; aa.ll = a;

View File

@@ -41,9 +41,7 @@
* Return ~a. For some reason gcc calls this `one's complement' rather * Return ~a. For some reason gcc calls this `one's complement' rather
* than `not'. * than `not'.
*/ */
long long long long __one_cmpldi2(long long a) {
__one_cmpldi2(long long a)
{
union uu aa; union uu aa;
aa.ll = a; aa.ll = a;

View File

@@ -64,10 +64,8 @@ static void shl(digit *p, int len, int sh);
* length dividend and divisor are 4 `digits' in this base (they are * length dividend and divisor are 4 `digits' in this base (they are
* shorter if they have leading zeros). * shorter if they have leading zeros).
*/ */
unsigned long long unsigned long long __qdivrem(unsigned long long ull, unsigned long long vll,
__qdivrem(unsigned long long ull, unsigned long long vll, unsigned long long *arq) {
unsigned long long *arq)
{
union uu tmp; union uu tmp;
digit *u, *v, *q; digit *u, *v, *q;
digit v1, v2; digit v1, v2;
@@ -248,8 +246,7 @@ __qdivrem(unsigned long long ull, unsigned long long vll,
if (d) { if (d) {
for (i = m + n; i > m; --i) for (i = m + n; i > m; --i)
u[i] = (digit)(((unsigned int)u[i] >> d) | u[i] = (digit)(((unsigned int)u[i] >> d) |
LHALF((unsigned int)u[i - 1] << LHALF((unsigned int)u[i - 1] << (HALF_BITS - d)));
(HALF_BITS - d)));
u[i] = 0; u[i] = 0;
} }
tmp.ui[H] = COMBINE(uspace[1], uspace[2]); tmp.ui[H] = COMBINE(uspace[1], uspace[2]);
@@ -267,9 +264,7 @@ __qdivrem(unsigned long long ull, unsigned long long vll,
* `fall out' the left (there never will be any such anyway). * `fall out' the left (there never will be any such anyway).
* We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS. * We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS.
*/ */
static void static void shl(digit *p, int len, int sh) {
shl(digit *p, int len, int sh)
{
int i; int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)

View File

@@ -42,9 +42,7 @@
* carry from a single unsigned int difference x-y occurs if and only * carry from a single unsigned int difference x-y occurs if and only
* if (x-y) > x. * if (x-y) > x.
*/ */
long long long long __subdi3(long long a, long long b) {
__subdi3(long long a, long long b)
{
union uu aa, bb, diff; union uu aa, bb, diff;
aa.ll = a; aa.ll = a;

View File

@@ -41,13 +41,14 @@
* Return 0, 1, or 2 as a <, =, > b respectively. * Return 0, 1, or 2 as a <, =, > b respectively.
* Neither a nor b are considered signed. * Neither a nor b are considered signed.
*/ */
int int __ucmpdi2(unsigned long long a, unsigned long long b) {
__ucmpdi2(unsigned long long a, unsigned long long b)
{
union uu aa, bb; union uu aa, bb;
aa.ull = a; aa.ull = a;
bb.ull = b; bb.ull = b;
return (aa.ui[H] < bb.ui[H] ? 0 : aa.ui[H] > bb.ui[H] ? 2 : return (aa.ui[H] < bb.ui[H] ? 0
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1); : aa.ui[H] > bb.ui[H] ? 2
: aa.ui[L] < bb.ui[L] ? 0
: aa.ui[L] > bb.ui[L] ? 2
: 1);
} }

View File

@@ -40,9 +40,7 @@
/* /*
* Divide two unsigned long longs. * Divide two unsigned long longs.
*/ */
unsigned long long unsigned long long __udivdi3(unsigned long long a, unsigned long long b) {
__udivdi3(unsigned long long a, unsigned long long b)
{
return __qdivrem(a, b, NULL); return __qdivrem(a, b, NULL);
} }

View File

@@ -40,9 +40,7 @@
/* /*
* Return remainder after dividing two unsigned long longs. * Return remainder after dividing two unsigned long longs.
*/ */
unsigned long long unsigned long long __umoddi3(unsigned long long a, unsigned long long b) {
__umoddi3(unsigned long long a, unsigned long long b)
{
unsigned long long r; unsigned long long r;
(void)__qdivrem(a, b, &r); (void)__qdivrem(a, b, &r);

View File

@@ -40,9 +40,7 @@
/* /*
* Return a ^ b, in long long. * Return a ^ b, in long long.
*/ */
long long long long __xordi3(long long a, long long b) {
__xordi3(long long a, long long b)
{
union uu aa, bb; union uu aa, bb;
aa.ll = a; aa.ll = a;

View File

@@ -52,7 +52,6 @@
#include <stdarg.h> #include <stdarg.h>
/* /*
* Do we want to support "long long" types with %lld? * Do we want to support "long long" types with %lld?
* *
@@ -72,7 +71,6 @@
#define INTTYPE long #define INTTYPE long
#endif #endif
/* /*
* Space for a long long in base 8, plus a NUL, plus one * Space for a long long in base 8, plus a NUL, plus one
* character extra for slop. * character extra for slop.
@@ -141,10 +139,7 @@ typedef struct {
* We count the total length we send out so we can return it from __vprintf, * We count the total length we send out so we can return it from __vprintf,
* since that's what most printf-like functions want to return. * since that's what most printf-like functions want to return.
*/ */
static static void __pf_print(PF *pf, const char *txt, size_t len) {
void
__pf_print(PF *pf, const char *txt, size_t len)
{
pf->sendfunc(pf->clientdata, txt, len); pf->sendfunc(pf->clientdata, txt, len);
pf->charcount += len; pf->charcount += len;
} }
@@ -152,10 +147,7 @@ __pf_print(PF *pf, const char *txt, size_t len)
/* /*
* Reset the state for the next %-field. * Reset the state for the next %-field.
*/ */
static static void __pf_endfield(PF *pf) {
void
__pf_endfield(PF *pf)
{
pf->in_pct = 0; pf->in_pct = 0;
pf->size = INTSZ; pf->size = INTSZ;
pf->num = 0; pf->num = 0;
@@ -177,10 +169,7 @@ __pf_endfield(PF *pf)
* 0-9 field width * 0-9 field width
* leading 0 pad with zeros instead of spaces * leading 0 pad with zeros instead of spaces
*/ */
static static void __pf_modifier(PF *pf, int ch) {
void
__pf_modifier(PF *pf, int ch)
{
switch (ch) { switch (ch) {
case '#': case '#':
pf->altformat = 1; pf->altformat = 1;
@@ -193,8 +182,7 @@ __pf_modifier(PF *pf, int ch)
#ifdef USE_LONGLONG #ifdef USE_LONGLONG
pf->size = LLONGSZ; pf->size = LLONGSZ;
#endif #endif
} } else {
else {
pf->size = LONGSZ; pf->size = LONGSZ;
} }
break; break;
@@ -208,8 +196,7 @@ __pf_modifier(PF *pf, int ch)
* field size. * field size.
*/ */
pf->spacing = pf->spacing * 10; pf->spacing = pf->spacing * 10;
} } else {
else {
/* /*
* Leading zero; set the padding character to 0. * Leading zero; set the padding character to 0.
*/ */
@@ -237,10 +224,7 @@ __pf_modifier(PF *pf, int ch)
* in pf->num, according to the size recorded in pf->size and using * in pf->num, according to the size recorded in pf->size and using
* the numeric type specified by ch. * the numeric type specified by ch.
*/ */
static static void __pf_getnum(PF *pf, int ch) {
void
__pf_getnum(PF *pf, int ch)
{
if (ch == 'p') { if (ch == 'p') {
/* /*
* Pointer. * Pointer.
@@ -249,8 +233,7 @@ __pf_getnum(PF *pf, int ch)
* integer the same size as a pointer. * integer the same size as a pointer.
*/ */
pf->num = (uintptr_t)va_arg(pf->ap, void *); pf->num = (uintptr_t)va_arg(pf->ap, void *);
} } else if (ch == 'd') {
else if (ch=='d') {
/* signed integer */ /* signed integer */
INTTYPE signednum = 0; INTTYPE signednum = 0;
switch (pf->size) { switch (pf->size) {
@@ -280,12 +263,10 @@ __pf_getnum(PF *pf, int ch)
if (signednum < 0) { if (signednum < 0) {
pf->sign = -1; pf->sign = -1;
pf->num = -signednum; pf->num = -signednum;
} } else {
else {
pf->num = signednum; pf->num = signednum;
} }
} } else {
else {
/* unsigned integer */ /* unsigned integer */
switch (pf->size) { switch (pf->size) {
case INTSZ: case INTSZ:
@@ -320,10 +301,7 @@ __pf_getnum(PF *pf, int ch)
* If the "alternate format" was requested, or always for pointers, * If the "alternate format" was requested, or always for pointers,
* note to print the C prefix for the type. * note to print the C prefix for the type.
*/ */
static static void __pf_setbase(PF *pf, int ch) {
void
__pf_setbase(PF *pf, int ch)
{
switch (ch) { switch (ch) {
case 'd': case 'd':
case 'u': case 'u':
@@ -345,10 +323,7 @@ __pf_setbase(PF *pf, int ch)
/* /*
* Function to print "spc" instances of the fill character. * Function to print "spc" instances of the fill character.
*/ */
static static void __pf_fill(PF *pf, int spc) {
void
__pf_fill(PF *pf, int spc)
{
char f = pf->fillchar; char f = pf->fillchar;
int i; int i;
for (i = 0; i < spc; i++) { for (i = 0; i < spc; i++) {
@@ -362,12 +337,8 @@ __pf_fill(PF *pf, int spc)
* and the other is the sign) get printed *after* space padding but * and the other is the sign) get printed *after* space padding but
* *before* zero padding, if padding is on the left. * *before* zero padding, if padding is on the left.
*/ */
static static void __pf_printstuff(PF *pf, const char *prefix, const char *prefix2,
void const char *stuff) {
__pf_printstuff(PF *pf,
const char *prefix, const char *prefix2,
const char *stuff)
{
/* Total length to print. */ /* Total length to print. */
int len = strlen(prefix) + strlen(prefix2) + strlen(stuff); int len = strlen(prefix) + strlen(prefix2) + strlen(stuff);
@@ -375,8 +346,7 @@ __pf_printstuff(PF *pf,
int spc = pf->spacing; int spc = pf->spacing;
if (spc > len) { if (spc > len) {
spc -= len; spc -= len;
} } else {
else {
spc = 0; spc = 0;
} }
@@ -410,10 +380,7 @@ __pf_printstuff(PF *pf,
* NUMBER_BUF_SIZE is set so that the longest number string we can * NUMBER_BUF_SIZE is set so that the longest number string we can
* generate (a long long printed in octal) will fit. See above. * generate (a long long printed in octal) will fit. See above.
*/ */
static static void __pf_printnum(PF *pf) {
void
__pf_printnum(PF *pf)
{
/* Digits to print with. */ /* Digits to print with. */
const char *const digits = "0123456789abcdef"; const char *const digits = "0123456789abcdef";
@@ -471,11 +438,9 @@ __pf_printnum(PF *pf)
*/ */
if (pf->baseprefix && pf->base == 16) { if (pf->baseprefix && pf->base == 16) {
bprefix = "0x"; bprefix = "0x";
} } else if (pf->baseprefix && pf->base == 8) {
else if (pf->baseprefix && pf->base==8) {
bprefix = "0"; bprefix = "0";
} } else {
else {
bprefix = ""; bprefix = "";
} }
@@ -493,10 +458,7 @@ __pf_printnum(PF *pf)
/* /*
* Process a single character out of the format string. * Process a single character out of the format string.
*/ */
static static void __pf_send(PF *pf, int ch) {
void
__pf_send(PF *pf, int ch)
{
/* Cannot get NULs here. */ /* Cannot get NULs here. */
assert(ch != 0); assert(ch != 0);
@@ -507,21 +469,18 @@ __pf_send(PF *pf, int ch)
*/ */
char c = ch; char c = ch;
__pf_print(pf, &c, 1); __pf_print(pf, &c, 1);
} } else if (pf->in_pct == 0) {
else if (pf->in_pct==0) {
/* /*
* Not in a format, but got a %. Start a format. * Not in a format, but got a %. Start a format.
*/ */
pf->in_pct = 1; pf->in_pct = 1;
} } else if (strchr("#-lz0123456789", ch)) {
else if (strchr("#-lz0123456789", ch)) {
/* /*
* These are the modifier characters we recognize. * These are the modifier characters we recognize.
* (These are the characters between the % and the type.) * (These are the characters between the % and the type.)
*/ */
__pf_modifier(pf, ch); __pf_modifier(pf, ch);
} } else if (strchr("doupx", ch)) {
else if (strchr("doupx", ch)) {
/* /*
* Integer types. * Integer types.
* Fetch the number, set the base, print it, then * Fetch the number, set the base, print it, then
@@ -531,8 +490,7 @@ __pf_send(PF *pf, int ch)
__pf_setbase(pf, ch); __pf_setbase(pf, ch);
__pf_printnum(pf); __pf_printnum(pf);
__pf_endfield(pf); __pf_endfield(pf);
} } else if (ch == 's') {
else if (ch=='s') {
/* /*
* Print a string. * Print a string.
*/ */
@@ -542,8 +500,7 @@ __pf_send(PF *pf, int ch)
} }
__pf_printstuff(pf, "", "", str); __pf_printstuff(pf, "", "", str);
__pf_endfield(pf); __pf_endfield(pf);
} } else {
else {
/* /*
* %%, %c, or illegal character. * %%, %c, or illegal character.
* Illegal characters are printed like %%. * Illegal characters are printed like %%.
@@ -552,8 +509,7 @@ __pf_send(PF *pf, int ch)
char x[2]; char x[2];
if (ch == 'c') { if (ch == 'c') {
x[0] = va_arg(pf->ap, int); x[0] = va_arg(pf->ap, int);
} } else {
else {
x[0] = ch; x[0] = ch;
} }
x[1] = 0; x[1] = 0;
@@ -567,10 +523,8 @@ __pf_send(PF *pf, int ch)
* Create and initialize a printf state object, * Create and initialize a printf state object,
* then send it each character from the format string. * then send it each character from the format string.
*/ */
int int __vprintf(void (*func)(void *clientdata, const char *str, size_t len),
__vprintf(void (*func)(void *clientdata, const char *str, size_t len), void *clientdata, const char *format, va_list ap) {
void *clientdata, const char *format, va_list ap)
{
PF pf; PF pf;
int i; int i;

View File

@@ -47,7 +47,6 @@
* Standard C string/IO function: printf into a character buffer. * Standard C string/IO function: printf into a character buffer.
*/ */
/* /*
* Context structure for snprintf: buffer to print into, maximum * Context structure for snprintf: buffer to print into, maximum
* length, and index of the next character to write. * length, and index of the next character to write.
@@ -70,10 +69,7 @@ typedef struct {
* null-terminated. * null-terminated.
*/ */
static static void __snprintf_send(void *mydata, const char *data, size_t len) {
void
__snprintf_send(void *mydata, const char *data, size_t len)
{
SNP *snp = mydata; SNP *snp = mydata;
unsigned i; unsigned i;
@@ -95,9 +91,7 @@ __snprintf_send(void *mydata, const char *data, size_t len)
/* /*
* The va_list version of snprintf. * The va_list version of snprintf.
*/ */
int int vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
{
int chars; int chars;
SNP snp; SNP snp;
@@ -111,8 +105,7 @@ vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
snp.buf = buf; snp.buf = buf;
if (len == 0) { if (len == 0) {
snp.buflen = 0; snp.buflen = 0;
} } else {
else {
snp.buflen = len - 1; snp.buflen = len - 1;
} }
snp.bufpos = 0; snp.bufpos = 0;
@@ -144,9 +137,7 @@ vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
/* /*
* snprintf - hand off to vsnprintf. * snprintf - hand off to vsnprintf.
*/ */
int int snprintf(char *buf, size_t len, const char *fmt, ...) {
snprintf(char *buf, size_t len, const char *fmt, ...)
{
int chars; int chars;
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@@ -154,4 +145,3 @@ snprintf(char *buf, size_t len, const char *fmt, ...)
va_end(ap); va_end(ap);
return chars; return chars;
} }

View File

@@ -46,9 +46,7 @@
* really report syntax errors or overflow in any useful way. * really report syntax errors or overflow in any useful way.
*/ */
int int atoi(const char *s) {
atoi(const char *s)
{
static const char digits[] = "0123456789"; /* legal digits in order */ static const char digits[] = "0123456789"; /* legal digits in order */
unsigned val = 0; /* value we're accumulating */ unsigned val = 0; /* value we're accumulating */
int neg = 0; /* set to true if we see a minus sign */ int neg = 0; /* set to true if we see a minus sign */
@@ -62,8 +60,7 @@ atoi(const char *s)
if (*s == '-') { if (*s == '-') {
neg = 1; neg = 1;
s++; s++;
} } else if (*s == '+') {
else if (*s=='+') {
s++; s++;
} }

View File

@@ -45,9 +45,7 @@
* memory. * memory.
*/ */
void void bzero(void *vblock, size_t len) {
bzero(void *vblock, size_t len)
{
char *block = vblock; char *block = vblock;
size_t i; size_t i;
@@ -61,14 +59,12 @@ bzero(void *vblock, size_t len)
* divides and moduli out. Fortunately, it is. * divides and moduli out. Fortunately, it is.
*/ */
if ((uintptr_t)block % sizeof(long) == 0 && if ((uintptr_t)block % sizeof(long) == 0 && len % sizeof(long) == 0) {
len % sizeof(long) == 0) {
long *lb = (long *)block; long *lb = (long *)block;
for (i = 0; i < len / sizeof(long); i++) { for (i = 0; i < len / sizeof(long); i++) {
lb[i] = 0; lb[i] = 0;
} }
} } else {
else {
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
block[i] = 0; block[i] = 0;
} }

View File

@@ -44,9 +44,7 @@
* C standard function - copy a block of memory. * C standard function - copy a block of memory.
*/ */
void * void *memcpy(void *dst, const void *src, size_t len) {
memcpy(void *dst, const void *src, size_t len)
{
size_t i; size_t i;
/* /*
@@ -63,8 +61,7 @@ memcpy(void *dst, const void *src, size_t len)
*/ */
if ((uintptr_t)dst % sizeof(long) == 0 && if ((uintptr_t)dst % sizeof(long) == 0 &&
(uintptr_t)src % sizeof(long) == 0 && (uintptr_t)src % sizeof(long) == 0 && len % sizeof(long) == 0) {
len % sizeof(long) == 0) {
long *d = dst; long *d = dst;
const long *s = src; const long *s = src;
@@ -72,8 +69,7 @@ memcpy(void *dst, const void *src, size_t len)
for (i = 0; i < len / sizeof(long); i++) { for (i = 0; i < len / sizeof(long); i++) {
d[i] = s[i]; d[i] = s[i];
} }
} } else {
else {
char *d = dst; char *d = dst;
const char *s = src; const char *s = src;

View File

@@ -45,9 +45,7 @@
* regions correctly. * regions correctly.
*/ */
void * void *memmove(void *dst, const void *src, size_t len) {
memmove(void *dst, const void *src, size_t len)
{
size_t i; size_t i;
/* /*
@@ -89,8 +87,7 @@ memmove(void *dst, const void *src, size_t len)
*/ */
if ((uintptr_t)dst % sizeof(long) == 0 && if ((uintptr_t)dst % sizeof(long) == 0 &&
(uintptr_t)src % sizeof(long) == 0 && (uintptr_t)src % sizeof(long) == 0 && len % sizeof(long) == 0) {
len % sizeof(long) == 0) {
long *d = dst; long *d = dst;
const long *s = src; const long *s = src;
@@ -103,8 +100,7 @@ memmove(void *dst, const void *src, size_t len)
for (i = len / sizeof(long); i > 0; i--) { for (i = len / sizeof(long); i > 0; i--) {
d[i - 1] = s[i - 1]; d[i - 1] = s[i - 1];
} }
} } else {
else {
char *d = dst; char *d = dst;
const char *s = src; const char *s = src;

View File

@@ -38,9 +38,7 @@
* C standard function - initialize a block of memory * C standard function - initialize a block of memory
*/ */
void * void *memset(void *ptr, int ch, size_t len) {
memset(void *ptr, int ch, size_t len)
{
char *p = ptr; char *p = ptr;
size_t i; size_t i;

View File

@@ -43,9 +43,7 @@
* Standard C string function: append one string to another. * Standard C string function: append one string to another.
*/ */
char * char *strcat(char *dest, const char *src) {
strcat(char *dest, const char *src)
{
size_t offset; size_t offset;
offset = strlen(dest); offset = strlen(dest);

View File

@@ -43,9 +43,7 @@
* C standard string function: find leftmost instance of a character * C standard string function: find leftmost instance of a character
* in a string. * in a string.
*/ */
char * char *strchr(const char *s, int ch_arg) {
strchr(const char *s, int ch_arg)
{
/* avoid sign-extension problems */ /* avoid sign-extension problems */
const char ch = ch_arg; const char ch = ch_arg;

View File

@@ -44,9 +44,7 @@
* sort order. * sort order.
*/ */
int int strcmp(const char *a, const char *b) {
strcmp(const char *a, const char *b)
{
size_t i; size_t i;
/* /*
@@ -82,8 +80,7 @@ strcmp(const char *a, const char *b)
*/ */
if ((unsigned char)a[i] > (unsigned char)b[i]) { if ((unsigned char)a[i] > (unsigned char)b[i]) {
return 1; return 1;
} } else if (a[i] == b[i]) {
else if (a[i] == b[i]) {
return 0; return 0;
} }
return -1; return -1;

View File

@@ -42,9 +42,7 @@
/* /*
* Standard C string function: copy one string to another. * Standard C string function: copy one string to another.
*/ */
char * char *strcpy(char *dest, const char *src) {
strcpy(char *dest, const char *src)
{
size_t i; size_t i;
/* /*

View File

@@ -43,9 +43,7 @@
* C standard string function: get length of a string * C standard string function: get length of a string
*/ */
size_t size_t strlen(const char *str) {
strlen(const char *str)
{
size_t ret = 0; size_t ret = 0;
while (str[ret]) { while (str[ret]) {

View File

@@ -43,9 +43,7 @@
* C standard string function: find rightmost instance of a character * C standard string function: find rightmost instance of a character
* in a string. * in a string.
*/ */
char * char *strrchr(const char *s, int ch_arg) {
strrchr(const char *s, int ch_arg)
{
/* avoid sign-extension problems */ /* avoid sign-extension problems */
const char ch = ch_arg; const char ch = ch_arg;

View File

@@ -46,9 +46,7 @@
* The "context" argument should point to a "char *" that is preserved * The "context" argument should point to a "char *" that is preserved
* between calls to strtok_r that wish to operate on same string. * between calls to strtok_r that wish to operate on same string.
*/ */
char * char *strtok_r(char *string, const char *seps, char **context) {
strtok_r(char *string, const char *seps, char **context)
{
char *head; /* start of word */ char *head; /* start of word */
char *tail; /* end of word */ char *tail; /* end of word */
@@ -84,8 +82,7 @@ strtok_r(char *string, const char *seps, char **context)
/* Save head for next time in context */ /* Save head for next time in context */
if (*tail == 0) { if (*tail == 0) {
*context = NULL; *context = NULL;
} } else {
else {
*tail = 0; *tail = 0;
tail++; tail++;
*context = tail; *context = tail;

View File

@@ -30,7 +30,6 @@
#ifndef _MIPS_CURRENT_H_ #ifndef _MIPS_CURRENT_H_
#define _MIPS_CURRENT_H_ #define _MIPS_CURRENT_H_
/* /*
* Macro for current thread, or current cpu. * Macro for current thread, or current cpu.
* *

View File

@@ -34,7 +34,6 @@
* MIPS machine-dependent definitions for the ELF binary format. * MIPS machine-dependent definitions for the ELF binary format.
*/ */
/* The ELF executable type. */ /* The ELF executable type. */
#define EM_MACHINE EM_MIPS #define EM_MACHINE EM_MIPS
@@ -54,5 +53,4 @@
#define R_MIPS_GPREL32 12 /* s32 offset from GP register */ #define R_MIPS_GPREL32 12 /* s32 offset from GP register */
/* %hi/%lo are defined so %hi(sym) << 16 + %lo(sym) = sym */ /* %hi/%lo are defined so %hi(sym) << 16 + %lo(sym) = sym */
#endif /* _MIPS_ELF_H_ */ #endif /* _MIPS_ELF_H_ */

View File

@@ -36,7 +36,6 @@
#ifndef _KERN_MIPS_REGDEFS_H_ #ifndef _KERN_MIPS_REGDEFS_H_
#define _KERN_MIPS_REGDEFS_H_ #define _KERN_MIPS_REGDEFS_H_
#define z0 $0 /* always zero register */ #define z0 $0 /* always zero register */
#define AT $1 /* assembler temp register */ #define AT $1 /* assembler temp register */
#define v0 $2 /* value 0 */ #define v0 $2 /* value 0 */
@@ -70,5 +69,4 @@
#define s8 $30 /* saved (callee-save) 8 = frame pointer */ #define s8 $30 /* saved (callee-save) 8 = frame pointer */
#define ra $31 /* return address */ #define ra $31 /* return address */
#endif /* _KERN_MIPS_REGDEFS_H_ */ #endif /* _KERN_MIPS_REGDEFS_H_ */

View File

@@ -43,5 +43,4 @@
/* A jmp_buf is an array of __JB_REGS registers */ /* A jmp_buf is an array of __JB_REGS registers */
typedef uint32_t jmp_buf[__JB_REGS]; typedef uint32_t jmp_buf[__JB_REGS];
#endif /* _MIPS_SETJMP_H_ */ #endif /* _MIPS_SETJMP_H_ */

View File

@@ -27,7 +27,6 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#ifndef _KERN_MIPS_SIGNAL_H_ #ifndef _KERN_MIPS_SIGNAL_H_
#define _KERN_MIPS_SIGNAL_H_ #define _KERN_MIPS_SIGNAL_H_

View File

@@ -38,7 +38,6 @@
* See kern/types.h for an explanation of the underscores. * See kern/types.h for an explanation of the underscores.
*/ */
/* Sized integer types, with convenient short names */ /* Sized integer types, with convenient short names */
typedef char __i8; /* 8-bit signed integer */ typedef char __i8; /* 8-bit signed integer */
typedef short __i16; /* 16-bit signed integer */ typedef short __i16; /* 16-bit signed integer */
@@ -74,5 +73,4 @@ typedef long __ptrdiff_t; /* Difference of two pointers */
/* Number of bits per byte. */ /* Number of bits per byte. */
#define __CHAR_BIT 8 #define __CHAR_BIT 8
#endif /* _KERN_MIPS_TYPES_H_ */ #endif /* _KERN_MIPS_TYPES_H_ */

View File

@@ -41,11 +41,8 @@
*/ */
MEMBAR_INLINE MEMBAR_INLINE
void void membar_any_any(void) {
membar_any_any(void) __asm volatile(".set push;" /* save assembler mode */
{
__asm volatile(
".set push;" /* save assembler mode */
".set mips32;" /* allow MIPS32 instructions */ ".set mips32;" /* allow MIPS32 instructions */
"sync;" /* do it */ "sync;" /* do it */
".set pop" /* restore assembler mode */ ".set pop" /* restore assembler mode */
@@ -59,5 +56,4 @@ MEMBAR_INLINE void membar_store_store(void) { membar_any_any(); }
MEMBAR_INLINE void membar_store_any(void) { membar_any_any(); } MEMBAR_INLINE void membar_store_any(void) { membar_any_any(); }
MEMBAR_INLINE void membar_any_store(void) { membar_any_any(); } MEMBAR_INLINE void membar_any_store(void) { membar_any_any(); }
#endif /* _MIPS_MEMBAR_H_ */ #endif /* _MIPS_MEMBAR_H_ */

View File

@@ -30,7 +30,6 @@
#ifndef _MIPS_SPECIALREG_H_ #ifndef _MIPS_SPECIALREG_H_
#define _MIPS_SPECIALREG_H_ #define _MIPS_SPECIALREG_H_
/* /*
* Coprocessor 0 (system processor) register numbers * Coprocessor 0 (system processor) register numbers
*/ */
@@ -113,5 +112,4 @@
#define EXADDR_UTLB 0x80000000 #define EXADDR_UTLB 0x80000000
#define EXADDR_GENERAL 0x80000080 #define EXADDR_GENERAL 0x80000080
#endif /* _MIPS_SPECIALREG_H_ */ #endif /* _MIPS_SPECIALREG_H_ */

View File

@@ -32,7 +32,6 @@
#include <cdefs.h> #include <cdefs.h>
/* Type of value needed to actually spin on */ /* Type of value needed to actually spin on */
typedef unsigned spinlock_data_t; typedef unsigned spinlock_data_t;
@@ -55,9 +54,7 @@ spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd);
* memory. * memory.
*/ */
SPINLOCK_INLINE SPINLOCK_INLINE
void void spinlock_data_set(volatile spinlock_data_t *sd, unsigned val) {
spinlock_data_set(volatile spinlock_data_t *sd, unsigned val)
{
*sd = val; *sd = val;
} }
@@ -66,11 +63,7 @@ spinlock_data_set(volatile spinlock_data_t *sd, unsigned val)
* instruction, and instructions are atomic with respect to memory. * instruction, and instructions are atomic with respect to memory.
*/ */
SPINLOCK_INLINE SPINLOCK_INLINE
spinlock_data_t spinlock_data_t spinlock_data_get(volatile spinlock_data_t *sd) { return *sd; }
spinlock_data_get(volatile spinlock_data_t *sd)
{
return *sd;
}
/* /*
* Test-and-set a spinlock_data_t. Use the LL/SC instructions to * Test-and-set a spinlock_data_t. Use the LL/SC instructions to
@@ -86,9 +79,7 @@ spinlock_data_get(volatile spinlock_data_t *sd)
* to atomically update one machine word. * to atomically update one machine word.
*/ */
SPINLOCK_INLINE SPINLOCK_INLINE
spinlock_data_t spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd) {
spinlock_data_testandset(volatile spinlock_data_t *sd)
{
spinlock_data_t x; spinlock_data_t x;
spinlock_data_t y; spinlock_data_t y;
@@ -104,19 +95,18 @@ spinlock_data_testandset(volatile spinlock_data_t *sd)
*/ */
y = 1; y = 1;
__asm volatile( __asm volatile(".set push;" /* save assembler mode */
".set push;" /* save assembler mode */
".set mips32;" /* allow MIPS32 instructions */ ".set mips32;" /* allow MIPS32 instructions */
".set volatile;" /* avoid unwanted optimization */ ".set volatile;" /* avoid unwanted optimization */
"ll %0, 0(%2);" /* x = *sd */ "ll %0, 0(%2);" /* x = *sd */
"sc %1, 0(%2);" /* *sd = y; y = success? */ "sc %1, 0(%2);" /* *sd = y; y = success? */
".set pop" /* restore assembler mode */ ".set pop" /* restore assembler mode */
: "=&r" (x), "+r" (y) : "r" (sd)); : "=&r"(x), "+r"(y)
: "r"(sd));
if (y == 0) { if (y == 0) {
return 1; return 1;
} }
return x; return x;
} }
#endif /* _MIPS_SPINLOCK_H_ */ #endif /* _MIPS_SPINLOCK_H_ */

View File

@@ -30,7 +30,6 @@
#ifndef _MIPS_THREAD_H_ #ifndef _MIPS_THREAD_H_
#define _MIPS_THREAD_H_ #define _MIPS_THREAD_H_
/* /*
* Machine-dependent thread bits. * Machine-dependent thread bits.
*/ */
@@ -44,5 +43,4 @@ struct thread_machdep {
jmp_buf tm_copyjmp; /* longjmp area used by copyin/out */ jmp_buf tm_copyjmp; /* longjmp area used by copyin/out */
}; };
#endif /* _MIPS_THREAD_H_ */ #endif /* _MIPS_THREAD_H_ */

View File

@@ -101,5 +101,4 @@ int tlb_probe(uint32_t entryhi, uint32_t entrylo);
#define NUM_TLB 64 #define NUM_TLB 64
#endif /* _MIPS_TLB_H_ */ #endif /* _MIPS_TLB_H_ */

View File

@@ -104,5 +104,4 @@ __DEAD void mips_usermode(struct trapframe *tf);
extern vaddr_t cpustacks[]; extern vaddr_t cpustacks[];
extern vaddr_t cputhreads[]; extern vaddr_t cputhreads[];
#endif /* _MIPS_TRAPFRAME_H_ */ #endif /* _MIPS_TRAPFRAME_H_ */

View File

@@ -30,7 +30,6 @@
#ifndef _MIPS_VM_H_ #ifndef _MIPS_VM_H_
#define _MIPS_VM_H_ #define _MIPS_VM_H_
/* /*
* Machine-dependent VM system definitions. * Machine-dependent VM system definitions.
*/ */
@@ -125,5 +124,4 @@ struct tlbshootdown {
#define TLBSHOOTDOWN_MAX 16 #define TLBSHOOTDOWN_MAX 16
#endif /* _MIPS_VM_H_ */ #endif /* _MIPS_VM_H_ */

View File

@@ -40,39 +40,26 @@
#include <mainbus.h> #include <mainbus.h>
#include <syscall.h> #include <syscall.h>
/* in exception-*.S */ /* in exception-*.S */
extern __DEAD void asm_usermode(struct trapframe *tf); extern __DEAD void asm_usermode(struct trapframe *tf);
/* called only from assembler, so not declared in a header */ /* called only from assembler, so not declared in a header */
void mips_trap(struct trapframe *tf); void mips_trap(struct trapframe *tf);
/* Names for trap codes */ /* Names for trap codes */
#define NTRAPCODES 13 #define NTRAPCODES 13
static const char *const trapcodenames[NTRAPCODES] = { static const char *const trapcodenames[NTRAPCODES] = {
"Interrupt", "Interrupt", "TLB modify trap", "TLB miss on load",
"TLB modify trap", "TLB miss on store", "Address error on load", "Address error on store",
"TLB miss on load", "Bus error on code", "Bus error on data", "System call",
"TLB miss on store", "Break instruction", "Illegal instruction", "Coprocessor unusable",
"Address error on load",
"Address error on store",
"Bus error on code",
"Bus error on data",
"System call",
"Break instruction",
"Illegal instruction",
"Coprocessor unusable",
"Arithmetic overflow", "Arithmetic overflow",
}; };
/* /*
* Function called when user-level code hits a fatal fault. * Function called when user-level code hits a fatal fault.
*/ */
static static void kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr) {
void
kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr)
{
int sig = 0; int sig = 0;
KASSERT(code < NTRAPCODES); KASSERT(code < NTRAPCODES);
@@ -112,8 +99,8 @@ kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr)
* You will probably want to change this. * You will probably want to change this.
*/ */
kprintf("Fatal user mode trap %u sig %d (%s, epc 0x%x, vaddr 0x%x)\n", kprintf("Fatal user mode trap %u sig %d (%s, epc 0x%x, vaddr 0x%x)\n", code,
code, sig, trapcodenames[code], epc, vaddr); sig, trapcodenames[code], epc, vaddr);
panic("I don't know how to handle this\n"); panic("I don't know how to handle this\n");
} }
@@ -122,9 +109,7 @@ kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr)
* This is called by the assembly-language exception handler once * This is called by the assembly-language exception handler once
* the trapframe has been set up. * the trapframe has been set up.
*/ */
void void mips_trap(struct trapframe *tf) {
mips_trap(struct trapframe *tf)
{
uint32_t code; uint32_t code;
/*bool isutlb; -- not used */ /*bool isutlb; -- not used */
bool iskern; bool iskern;
@@ -145,8 +130,7 @@ mips_trap(struct trapframe *tf)
/* Make sure we haven't run off our stack */ /* Make sure we haven't run off our stack */
if (curthread != NULL && curthread->t_stack != NULL) { if (curthread != NULL && curthread->t_stack != NULL) {
KASSERT((vaddr_t)tf > (vaddr_t)curthread->t_stack); KASSERT((vaddr_t)tf > (vaddr_t)curthread->t_stack);
KASSERT((vaddr_t)tf < (vaddr_t)(curthread->t_stack KASSERT((vaddr_t)tf < (vaddr_t)(curthread->t_stack + STACK_SIZE));
+ STACK_SIZE));
} }
/* Interrupt? Call the interrupt handler and return. */ /* Interrupt? Call the interrupt handler and return. */
@@ -180,8 +164,7 @@ mips_trap(struct trapframe *tf)
curthread->t_curspl = IPL_HIGH; curthread->t_curspl = IPL_HIGH;
curthread->t_iplhigh_count++; curthread->t_iplhigh_count++;
doadjust = true; doadjust = true;
} } else {
else {
doadjust = false; doadjust = false;
} }
@@ -218,8 +201,8 @@ mips_trap(struct trapframe *tf)
KASSERT(curthread->t_curspl == 0); KASSERT(curthread->t_curspl == 0);
KASSERT(curthread->t_iplhigh_count == 0); KASSERT(curthread->t_iplhigh_count == 0);
DEBUG(DB_SYSCALL, "syscall: #%d, args %x %x %x %x\n", DEBUG(DB_SYSCALL, "syscall: #%d, args %x %x %x %x\n", tf->tf_v0, tf->tf_a0,
tf->tf_v0, tf->tf_a0, tf->tf_a1, tf->tf_a2, tf->tf_a3); tf->tf_a1, tf->tf_a2, tf->tf_a3);
syscall(tf); syscall(tf);
goto done; goto done;
@@ -297,8 +280,7 @@ mips_trap(struct trapframe *tf)
* from the exception handler. * from the exception handler.
*/ */
if (curthread != NULL && if (curthread != NULL && curthread->t_machdep.tm_badfaultfunc != NULL) {
curthread->t_machdep.tm_badfaultfunc != NULL) {
tf->tf_epc = (vaddr_t)curthread->t_machdep.tm_badfaultfunc; tf->tf_epc = (vaddr_t)curthread->t_machdep.tm_badfaultfunc;
goto done; goto done;
} }
@@ -309,8 +291,7 @@ mips_trap(struct trapframe *tf)
kprintf("panic: Fatal exception %u (%s) in kernel mode\n", code, kprintf("panic: Fatal exception %u (%s) in kernel mode\n", code,
trapcodenames[code]); trapcodenames[code]);
kprintf("panic: EPC 0x%x, exception vaddr 0x%x\n", kprintf("panic: EPC 0x%x, exception vaddr 0x%x\n", tf->tf_epc, tf->tf_vaddr);
tf->tf_epc, tf->tf_vaddr);
panic("I can't handle this... I think I'll just die now...\n"); panic("I can't handle this... I think I'll just die now...\n");
@@ -364,9 +345,7 @@ mips_trap(struct trapframe *tf)
* - enter_new_process, for use by exec and equivalent. * - enter_new_process, for use by exec and equivalent.
* - enter_forked_process, in syscall.c, for use by fork. * - enter_forked_process, in syscall.c, for use by fork.
*/ */
void void mips_usermode(struct trapframe *tf) {
mips_usermode(struct trapframe *tf)
{
/* /*
* Interrupts should be off within the kernel while entering * Interrupts should be off within the kernel while entering
@@ -419,10 +398,8 @@ mips_usermode(struct trapframe *tf)
* *
* Works by creating an ersatz trapframe. * Works by creating an ersatz trapframe.
*/ */
void void enter_new_process(int argc, userptr_t argv, userptr_t env, vaddr_t stack,
enter_new_process(int argc, userptr_t argv, userptr_t env, vaddr_t entry) {
vaddr_t stack, vaddr_t entry)
{
struct trapframe tf; struct trapframe tf;
bzero(&tf, sizeof(tf)); bzero(&tf, sizeof(tf));

View File

@@ -36,7 +36,6 @@
#include <current.h> #include <current.h>
#include <syscall.h> #include <syscall.h>
/* /*
* System call dispatcher. * System call dispatcher.
* *
@@ -75,9 +74,7 @@
* stack, starting at sp+16 to skip over the slots for the * stack, starting at sp+16 to skip over the slots for the
* registerized values, with copyin(). * registerized values, with copyin().
*/ */
void void syscall(struct trapframe *tf) {
syscall(struct trapframe *tf)
{
int callno; int callno;
int32_t retval; int32_t retval;
int err; int err;
@@ -105,8 +102,7 @@ syscall(struct trapframe *tf)
break; break;
case SYS___time: case SYS___time:
err = sys___time((userptr_t)tf->tf_a0, err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1);
(userptr_t)tf->tf_a1);
break; break;
/* Add stuff here */ /* Add stuff here */
@@ -117,7 +113,6 @@ syscall(struct trapframe *tf)
break; break;
} }
if (err) { if (err) {
/* /*
* Return the error code. This gets converted at * Return the error code. This gets converted at
@@ -126,8 +121,7 @@ syscall(struct trapframe *tf)
*/ */
tf->tf_v0 = err; tf->tf_v0 = err;
tf->tf_a3 = 1; /* signal an error */ tf->tf_a3 = 1; /* signal an error */
} } else {
else {
/* Success. */ /* Success. */
tf->tf_v0 = retval; tf->tf_v0 = retval;
tf->tf_a3 = 0; /* signal no error */ tf->tf_a3 = 0; /* signal no error */
@@ -154,8 +148,4 @@ syscall(struct trapframe *tf)
* *
* Thus, you can trash it and do things another way if you prefer. * Thus, you can trash it and do things another way if you prefer.
*/ */
void void enter_forked_process(struct trapframe *tf) { (void)tf; }
enter_forked_process(struct trapframe *tf)
{
(void)tf;
}

View File

@@ -72,17 +72,14 @@ vaddr_t cputhreads[MAXCPUS];
* associated with a new cpu. Note that we're not running on the new * associated with a new cpu. Note that we're not running on the new
* cpu when this is called. * cpu when this is called.
*/ */
void void cpu_machdep_init(struct cpu *c) {
cpu_machdep_init(struct cpu *c)
{
vaddr_t stackpointer; vaddr_t stackpointer;
KASSERT(c->c_number < MAXCPUS); KASSERT(c->c_number < MAXCPUS);
if (c->c_curthread->t_stack == NULL) { if (c->c_curthread->t_stack == NULL) {
/* boot cpu; don't need to do anything here */ /* boot cpu; don't need to do anything here */
} } else {
else {
/* /*
* Stick the stack in cpustacks[], and thread pointer * Stick the stack in cpustacks[], and thread pointer
* in cputhreads[]. * in cputhreads[].
@@ -110,20 +107,14 @@ cpu_machdep_init(struct cpu *c)
#define SYS161_PRID_ORIG 0x000003ff #define SYS161_PRID_ORIG 0x000003ff
#define SYS161_PRID_2X 0x000000a1 #define SYS161_PRID_2X 0x000000a1
static inline static inline uint32_t cpu_getprid(void) {
uint32_t
cpu_getprid(void)
{
uint32_t prid; uint32_t prid;
__asm volatile("mfc0 %0,$15" : "=r"(prid)); __asm volatile("mfc0 %0,$15" : "=r"(prid));
return prid; return prid;
} }
static inline static inline uint32_t cpu_getfeatures(void) {
uint32_t
cpu_getfeatures(void)
{
uint32_t features; uint32_t features;
__asm volatile(".set push;" /* save assembler mode */ __asm volatile(".set push;" /* save assembler mode */
@@ -134,10 +125,7 @@ cpu_getfeatures(void)
return features; return features;
} }
static inline static inline uint32_t cpu_getifeatures(void) {
uint32_t
cpu_getifeatures(void)
{
uint32_t features; uint32_t features;
__asm volatile(".set push;" /* save assembler mode */ __asm volatile(".set push;" /* save assembler mode */
@@ -148,9 +136,7 @@ cpu_getifeatures(void)
return features; return features;
} }
void void cpu_identify(char *buf, size_t max) {
cpu_identify(char *buf, size_t max)
{
uint32_t prid; uint32_t prid;
uint32_t features; uint32_t features;
@@ -161,17 +147,16 @@ cpu_identify(char *buf, size_t max)
break; break;
case SYS161_PRID_2X: case SYS161_PRID_2X:
features = cpu_getfeatures(); features = cpu_getfeatures();
snprintf(buf, max, "MIPS/161 (System/161 2.x) features 0x%x", snprintf(buf, max, "MIPS/161 (System/161 2.x) features 0x%x", features);
features);
features = cpu_getifeatures(); features = cpu_getifeatures();
if (features != 0) { if (features != 0) {
kprintf("WARNING: unknown CPU incompatible features " kprintf("WARNING: unknown CPU incompatible features "
"0x%x\n", features); "0x%x\n",
features);
} }
break; break;
default: default:
snprintf(buf, max, "32-bit MIPS (unknown type, CPU ID 0x%x)", snprintf(buf, max, "32-bit MIPS (unknown type, CPU ID 0x%x)", prid);
prid);
break; break;
} }
} }
@@ -206,9 +191,7 @@ cpu_identify(char *buf, size_t max)
/* /*
* Interrupts on. * Interrupts on.
*/ */
void void cpu_irqon(void) {
cpu_irqon(void)
{
uint32_t x; uint32_t x;
GET_STATUS(x); GET_STATUS(x);
@@ -219,9 +202,7 @@ cpu_irqon(void)
/* /*
* Interrupts off. * Interrupts off.
*/ */
void void cpu_irqoff(void) {
cpu_irqoff(void)
{
uint32_t x; uint32_t x;
GET_STATUS(x); GET_STATUS(x);
@@ -232,10 +213,7 @@ cpu_irqoff(void)
/* /*
* Used below. * Used below.
*/ */
static static void cpu_irqonoff(void) {
void
cpu_irqonoff(void)
{
uint32_t x, xon, xoff; uint32_t x, xon, xoff;
GET_STATUS(x); GET_STATUS(x);
@@ -261,11 +239,7 @@ cpu_irqonoff(void)
* appropriate the mips32 WAIT instruction. * appropriate the mips32 WAIT instruction.
*/ */
static static inline void wait(void) {
inline
void
wait(void)
{
/* /*
* The WAIT instruction goes into powersave mode until an * The WAIT instruction goes into powersave mode until an
* interrupt is trying to occur. * interrupt is trying to occur.
@@ -277,8 +251,7 @@ wait(void)
* System/161 simulator is partly guesswork. This code may not * System/161 simulator is partly guesswork. This code may not
* work on a real mips. * work on a real mips.
*/ */
__asm volatile( __asm volatile(".set push;" /* save assembler mode */
".set push;" /* save assembler mode */
".set mips32;" /* allow MIPS32 instructions */ ".set mips32;" /* allow MIPS32 instructions */
".set volatile;" /* avoid unwanted optimization */ ".set volatile;" /* avoid unwanted optimization */
"wait;" /* suspend until interrupted */ "wait;" /* suspend until interrupted */
@@ -289,9 +262,7 @@ wait(void)
/* /*
* Idle the processor until something happens. * Idle the processor until something happens.
*/ */
void void cpu_idle(void) {
cpu_idle(void)
{
wait(); wait();
cpu_irqonoff(); cpu_irqonoff();
} }
@@ -299,9 +270,7 @@ cpu_idle(void)
/* /*
* Halt the CPU permanently. * Halt the CPU permanently.
*/ */
void void cpu_halt(void) {
cpu_halt(void)
{
cpu_irqoff(); cpu_irqoff();
while (1) { while (1) {
wait(); wait();

View File

@@ -37,7 +37,6 @@
/* in threadstart.S */ /* in threadstart.S */
extern void mips_threadstart(/* arguments are in unusual registers */); extern void mips_threadstart(/* arguments are in unusual registers */);
/* /*
* Function to initialize the switchframe of a new thread, which is * Function to initialize the switchframe of a new thread, which is
* *not* the one that is currently running. * *not* the one that is currently running.
@@ -51,11 +50,9 @@ extern void mips_threadstart(/* arguments are in unusual registers */);
* store the arguments in the s* registers, and use a bit of asm * store the arguments in the s* registers, and use a bit of asm
* (mips_threadstart) to move them and then jump to thread_startup. * (mips_threadstart) to move them and then jump to thread_startup.
*/ */
void void switchframe_init(struct thread *thread,
switchframe_init(struct thread *thread,
void (*entrypoint)(void *data1, unsigned long data2), void (*entrypoint)(void *data1, unsigned long data2),
void *data1, unsigned long data2) void *data1, unsigned long data2) {
{
vaddr_t stacktop; vaddr_t stacktop;
struct switchframe *sf; struct switchframe *sf;

View File

@@ -36,14 +36,10 @@
#include <thread.h> #include <thread.h>
#include <threadprivate.h> #include <threadprivate.h>
void void thread_machdep_init(struct thread_machdep *tm) {
thread_machdep_init(struct thread_machdep *tm)
{
tm->tm_badfaultfunc = NULL; tm->tm_badfaultfunc = NULL;
} }
void void thread_machdep_cleanup(struct thread_machdep *tm) {
thread_machdep_cleanup(struct thread_machdep *tm)
{
KASSERT(tm->tm_badfaultfunc == NULL); KASSERT(tm->tm_badfaultfunc == NULL);
} }

View File

@@ -64,11 +64,7 @@
*/ */
static struct spinlock stealmem_lock = SPINLOCK_INITIALIZER; static struct spinlock stealmem_lock = SPINLOCK_INITIALIZER;
void void vm_bootstrap(void) { /* Do nothing. */ }
vm_bootstrap(void)
{
/* Do nothing. */
}
/* /*
* Check if we're in a context that can sleep. While most of the * Check if we're in a context that can sleep. While most of the
@@ -77,10 +73,7 @@ vm_bootstrap(void)
* avoid the situation where syscall-layer code that works ok with * avoid the situation where syscall-layer code that works ok with
* dumbvm starts blowing up during the VM assignment. * dumbvm starts blowing up during the VM assignment.
*/ */
static static void dumbvm_can_sleep(void) {
void
dumbvm_can_sleep(void)
{
if (CURCPU_EXISTS()) { if (CURCPU_EXISTS()) {
/* must not hold spinlocks */ /* must not hold spinlocks */
KASSERT(curcpu->c_spinlocks == 0); KASSERT(curcpu->c_spinlocks == 0);
@@ -90,10 +83,7 @@ dumbvm_can_sleep(void)
} }
} }
static static paddr_t getppages(unsigned long npages) {
paddr_t
getppages(unsigned long npages)
{
paddr_t addr; paddr_t addr;
spinlock_acquire(&stealmem_lock); spinlock_acquire(&stealmem_lock);
@@ -105,9 +95,7 @@ getppages(unsigned long npages)
} }
/* Allocate/free some kernel-space virtual pages */ /* Allocate/free some kernel-space virtual pages */
vaddr_t vaddr_t alloc_kpages(unsigned npages) {
alloc_kpages(unsigned npages)
{
paddr_t pa; paddr_t pa;
dumbvm_can_sleep(); dumbvm_can_sleep();
@@ -118,24 +106,18 @@ alloc_kpages(unsigned npages)
return PADDR_TO_KVADDR(pa); return PADDR_TO_KVADDR(pa);
} }
void void free_kpages(vaddr_t addr) {
free_kpages(vaddr_t addr)
{
/* nothing - leak the memory. */ /* nothing - leak the memory. */
(void)addr; (void)addr;
} }
void void vm_tlbshootdown(const struct tlbshootdown *ts) {
vm_tlbshootdown(const struct tlbshootdown *ts)
{
(void)ts; (void)ts;
panic("dumbvm tried to do tlb shootdown?!\n"); panic("dumbvm tried to do tlb shootdown?!\n");
} }
int int vm_fault(int faulttype, vaddr_t faultaddress) {
vm_fault(int faulttype, vaddr_t faultaddress)
{
vaddr_t vbase1, vtop1, vbase2, vtop2, stackbase, stacktop; vaddr_t vbase1, vtop1, vbase2, vtop2, stackbase, stacktop;
paddr_t paddr; paddr_t paddr;
int i; int i;
@@ -199,14 +181,11 @@ vm_fault(int faulttype, vaddr_t faultaddress)
if (faultaddress >= vbase1 && faultaddress < vtop1) { if (faultaddress >= vbase1 && faultaddress < vtop1) {
paddr = (faultaddress - vbase1) + as->as_pbase1; paddr = (faultaddress - vbase1) + as->as_pbase1;
} } else if (faultaddress >= vbase2 && faultaddress < vtop2) {
else if (faultaddress >= vbase2 && faultaddress < vtop2) {
paddr = (faultaddress - vbase2) + as->as_pbase2; paddr = (faultaddress - vbase2) + as->as_pbase2;
} } else if (faultaddress >= stackbase && faultaddress < stacktop) {
else if (faultaddress >= stackbase && faultaddress < stacktop) {
paddr = (faultaddress - stackbase) + as->as_stackpbase; paddr = (faultaddress - stackbase) + as->as_stackpbase;
} } else {
else {
return EFAULT; return EFAULT;
} }
@@ -234,9 +213,7 @@ vm_fault(int faulttype, vaddr_t faultaddress)
return EFAULT; return EFAULT;
} }
struct addrspace * struct addrspace *as_create(void) {
as_create(void)
{
struct addrspace *as = kmalloc(sizeof(struct addrspace)); struct addrspace *as = kmalloc(sizeof(struct addrspace));
if (as == NULL) { if (as == NULL) {
return NULL; return NULL;
@@ -253,16 +230,12 @@ as_create(void)
return as; return as;
} }
void void as_destroy(struct addrspace *as) {
as_destroy(struct addrspace *as)
{
dumbvm_can_sleep(); dumbvm_can_sleep();
kfree(as); kfree(as);
} }
void void as_activate(void) {
as_activate(void)
{
int i, spl; int i, spl;
struct addrspace *as; struct addrspace *as;
@@ -281,16 +254,10 @@ as_activate(void)
splx(spl); splx(spl);
} }
void void as_deactivate(void) { /* nothing */ }
as_deactivate(void)
{
/* nothing */
}
int int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz, int readable, int writeable, int executable) {
int readable, int writeable, int executable)
{
size_t npages; size_t npages;
dumbvm_can_sleep(); dumbvm_can_sleep();
@@ -328,16 +295,11 @@ as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
return ENOSYS; return ENOSYS;
} }
static static void as_zero_region(paddr_t paddr, unsigned npages) {
void
as_zero_region(paddr_t paddr, unsigned npages)
{
bzero((void *)PADDR_TO_KVADDR(paddr), npages * PAGE_SIZE); bzero((void *)PADDR_TO_KVADDR(paddr), npages * PAGE_SIZE);
} }
int int as_prepare_load(struct addrspace *as) {
as_prepare_load(struct addrspace *as)
{
KASSERT(as->as_pbase1 == 0); KASSERT(as->as_pbase1 == 0);
KASSERT(as->as_pbase2 == 0); KASSERT(as->as_pbase2 == 0);
KASSERT(as->as_stackpbase == 0); KASSERT(as->as_stackpbase == 0);
@@ -366,26 +328,20 @@ as_prepare_load(struct addrspace *as)
return 0; return 0;
} }
int int as_complete_load(struct addrspace *as) {
as_complete_load(struct addrspace *as)
{
dumbvm_can_sleep(); dumbvm_can_sleep();
(void)as; (void)as;
return 0; return 0;
} }
int int as_define_stack(struct addrspace *as, vaddr_t *stackptr) {
as_define_stack(struct addrspace *as, vaddr_t *stackptr)
{
KASSERT(as->as_stackpbase != 0); KASSERT(as->as_stackpbase != 0);
*stackptr = USERSTACK; *stackptr = USERSTACK;
return 0; return 0;
} }
int int as_copy(struct addrspace *old, struct addrspace **ret) {
as_copy(struct addrspace *old, struct addrspace **ret)
{
struct addrspace *new; struct addrspace *new;
dumbvm_can_sleep(); dumbvm_can_sleep();

View File

@@ -32,7 +32,6 @@
#include <vm.h> #include <vm.h>
#include <mainbus.h> #include <mainbus.h>
vaddr_t firstfree; /* first free virtual address; set by start.S */ vaddr_t firstfree; /* first free virtual address; set by start.S */
static paddr_t firstpaddr; /* address of first free physical page */ static paddr_t firstpaddr; /* address of first free physical page */
@@ -42,9 +41,7 @@ static paddr_t lastpaddr; /* one past end of last free physical page */
* Called very early in system boot to figure out how much physical * Called very early in system boot to figure out how much physical
* RAM is available. * RAM is available.
*/ */
void void ram_bootstrap(void) {
ram_bootstrap(void)
{
size_t ramsize; size_t ramsize;
/* Get size of RAM. */ /* Get size of RAM. */
@@ -69,8 +66,7 @@ ram_bootstrap(void)
*/ */
firstpaddr = firstfree - MIPS_KSEG0; firstpaddr = firstfree - MIPS_KSEG0;
kprintf("%uk physical memory available\n", kprintf("%uk physical memory available\n", (lastpaddr - firstpaddr) / 1024);
(lastpaddr-firstpaddr)/1024);
} }
/* /*
@@ -91,9 +87,7 @@ ram_bootstrap(void)
* This function should not be called once the VM system is initialized, * This function should not be called once the VM system is initialized,
* so it is not synchronized. * so it is not synchronized.
*/ */
paddr_t paddr_t ram_stealmem(unsigned long npages) {
ram_stealmem(unsigned long npages)
{
size_t size; size_t size;
paddr_t paddr; paddr_t paddr;
@@ -124,11 +118,7 @@ ram_stealmem(unsigned long npages)
* initialize the VM system, after which the VM system should take * initialize the VM system, after which the VM system should take
* charge of knowing what memory exists. * charge of knowing what memory exists.
*/ */
paddr_t paddr_t ram_getsize(void) { return lastpaddr; }
ram_getsize(void)
{
return lastpaddr;
}
/* /*
* This function is intended to be called by the VM system when it * This function is intended to be called by the VM system when it
@@ -142,9 +132,7 @@ ram_getsize(void)
* This function should not be called once the VM system is initialized, * This function should not be called once the VM system is initialized,
* so it is not synchronized. * so it is not synchronized.
*/ */
paddr_t paddr_t ram_getfirstfree(void) {
ram_getfirstfree(void)
{
paddr_t ret; paddr_t ret;
ret = firstpaddr; ret = firstpaddr;

View File

@@ -60,16 +60,12 @@
* matches the c0_compare register, the timer interrupt line is * matches the c0_compare register, the timer interrupt line is
* asserted. Writing to c0_compare again clears the interrupt. * asserted. Writing to c0_compare again clears the interrupt.
*/ */
static static void mips_timer_set(uint32_t count) {
void
mips_timer_set(uint32_t count)
{
/* /*
* $11 == c0_compare; we can't use the symbolic name inside * $11 == c0_compare; we can't use the symbolic name inside
* the asm string. * the asm string.
*/ */
__asm volatile( __asm volatile(".set push;" /* save assembler mode */
".set push;" /* save assembler mode */
".set mips32;" /* allow MIPS32 registers */ ".set mips32;" /* allow MIPS32 registers */
"mtc0 %0, $11;" /* do it */ "mtc0 %0, $11;" /* do it */
".set pop" /* restore assembler mode */ ".set pop" /* restore assembler mode */
@@ -83,9 +79,7 @@ mips_timer_set(uint32_t count)
*/ */
static struct lamebus_softc *lamebus; static struct lamebus_softc *lamebus;
void void mainbus_bootstrap(void) {
mainbus_bootstrap(void)
{
/* Interrupts should be off (and have been off since startup) */ /* Interrupts should be off (and have been off since startup) */
KASSERT(curthread->t_curspl > 0); KASSERT(curthread->t_curspl > 0);
@@ -122,20 +116,14 @@ mainbus_bootstrap(void)
/* /*
* Start all secondary CPUs. * Start all secondary CPUs.
*/ */
void void mainbus_start_cpus(void) { lamebus_start_cpus(lamebus); }
mainbus_start_cpus(void)
{
lamebus_start_cpus(lamebus);
}
/* /*
* Function to generate the memory address (in the uncached segment) * Function to generate the memory address (in the uncached segment)
* for the specified offset into the specified slot's region of the * for the specified offset into the specified slot's region of the
* LAMEbus. * LAMEbus.
*/ */
void * void *lamebus_map_area(struct lamebus_softc *bus, int slot, uint32_t offset) {
lamebus_map_area(struct lamebus_softc *bus, int slot, uint32_t offset)
{
uint32_t address; uint32_t address;
(void)bus; // not needed (void)bus; // not needed
@@ -149,9 +137,8 @@ lamebus_map_area(struct lamebus_softc *bus, int slot, uint32_t offset)
/* /*
* Read a 32-bit register from a LAMEbus device. * Read a 32-bit register from a LAMEbus device.
*/ */
uint32_t uint32_t lamebus_read_register(struct lamebus_softc *bus, int slot,
lamebus_read_register(struct lamebus_softc *bus, int slot, uint32_t offset) uint32_t offset) {
{
uint32_t *ptr; uint32_t *ptr;
ptr = lamebus_map_area(bus, slot, offset); ptr = lamebus_map_area(bus, slot, offset);
@@ -168,10 +155,8 @@ lamebus_read_register(struct lamebus_softc *bus, int slot, uint32_t offset)
/* /*
* Write a 32-bit register of a LAMEbus device. * Write a 32-bit register of a LAMEbus device.
*/ */
void void lamebus_write_register(struct lamebus_softc *bus, int slot,
lamebus_write_register(struct lamebus_softc *bus, int slot, uint32_t offset, uint32_t val) {
uint32_t offset, uint32_t val)
{
uint32_t *ptr; uint32_t *ptr;
ptr = lamebus_map_area(bus, slot, offset); ptr = lamebus_map_area(bus, slot, offset);
@@ -184,13 +169,10 @@ lamebus_write_register(struct lamebus_softc *bus, int slot,
membar_store_store(); membar_store_store();
} }
/* /*
* Power off the system. * Power off the system.
*/ */
void void mainbus_poweroff(void) {
mainbus_poweroff(void)
{
/* /*
* *
* Note that lamebus_write_register() doesn't actually access * Note that lamebus_write_register() doesn't actually access
@@ -203,9 +185,7 @@ mainbus_poweroff(void)
/* /*
* Reboot the system. * Reboot the system.
*/ */
void void mainbus_reboot(void) {
mainbus_reboot(void)
{
/* /*
* The MIPS doesn't appear to have any on-chip reset. * The MIPS doesn't appear to have any on-chip reset.
* LAMEbus doesn't have a reset control, so we just * LAMEbus doesn't have a reset control, so we just
@@ -222,11 +202,7 @@ mainbus_reboot(void)
* On some systems, this would return to the boot monitor. But we don't * On some systems, this would return to the boot monitor. But we don't
* have one. * have one.
*/ */
void void mainbus_halt(void) { cpu_halt(); }
mainbus_halt(void)
{
cpu_halt();
}
/* /*
* Called to reset the system from panic(). * Called to reset the system from panic().
@@ -235,19 +211,13 @@ mainbus_halt(void)
* as to panic recursively if we do much of anything. So just power off. * as to panic recursively if we do much of anything. So just power off.
* (We'd reboot, but System/161 doesn't do that.) * (We'd reboot, but System/161 doesn't do that.)
*/ */
void void mainbus_panic(void) { mainbus_poweroff(); }
mainbus_panic(void)
{
mainbus_poweroff();
}
/* /*
* Function to get the size of installed physical RAM from the LAMEbus * Function to get the size of installed physical RAM from the LAMEbus
* controller. * controller.
*/ */
uint32_t uint32_t mainbus_ramsize(void) {
mainbus_ramsize(void)
{
uint32_t ramsize; uint32_t ramsize;
ramsize = lamebus_ramsize(); ramsize = lamebus_ramsize();
@@ -270,20 +240,14 @@ mainbus_ramsize(void)
/* /*
* Send IPI. * Send IPI.
*/ */
void void mainbus_send_ipi(struct cpu *target) {
mainbus_send_ipi(struct cpu *target)
{
lamebus_assert_ipi(lamebus, target); lamebus_assert_ipi(lamebus, target);
} }
/* /*
* Trigger the debugger. * Trigger the debugger.
*/ */
void void mainbus_debugger(void) { ltrace_stop(0); }
mainbus_debugger(void)
{
ltrace_stop(0);
}
/* /*
* Interrupt dispatcher. * Interrupt dispatcher.
@@ -294,9 +258,7 @@ mainbus_debugger(void)
#define LAMEBUS_IPI_BIT 0x00000800 /* inter-processor interrupt */ #define LAMEBUS_IPI_BIT 0x00000800 /* inter-processor interrupt */
#define MIPS_TIMER_BIT 0x00008000 /* on-chip timer */ #define MIPS_TIMER_BIT 0x00008000 /* on-chip timer */
void void mainbus_interrupt(struct trapframe *tf) {
mainbus_interrupt(struct trapframe *tf)
{
uint32_t cause; uint32_t cause;
bool seen = false; bool seen = false;
@@ -330,15 +292,13 @@ mainbus_interrupt(struct trapframe *tf)
* reading the cause register. This was * reading the cause register. This was
* actually seen... once. * actually seen... once.
*/ */
} } else {
else {
/* /*
* But if we get an interrupt on an interrupt * But if we get an interrupt on an interrupt
* line that's not supposed to be wired up, * line that's not supposed to be wired up,
* complain. * complain.
*/ */
panic("Unknown interrupt; cause register is %08x\n", panic("Unknown interrupt; cause register is %08x\n", cause);
cause);
} }
} }
} }

View File

@@ -46,8 +46,7 @@
#define bus_read_register(bus, slot, offset) \ #define bus_read_register(bus, slot, offset) \
lamebus_read_register(bus, slot, offset) lamebus_read_register(bus, slot, offset)
#define bus_map_area(bus, slot, offset) \ #define bus_map_area(bus, slot, offset) lamebus_map_area(bus, slot, offset)
lamebus_map_area(bus, slot, offset)
/* /*
* Machine-dependent LAMEbus definitions * Machine-dependent LAMEbus definitions
@@ -56,5 +55,4 @@
/* Base address of the LAMEbus mapping area */ /* Base address of the LAMEbus mapping area */
#define LB_BASEADDR (MIPS_KSEG1 + 0x1fe00000) #define LB_BASEADDR (MIPS_KSEG1 + 0x1fe00000)
#endif /* _SYS161_BUS_H_ */ #endif /* _SYS161_BUS_H_ */

View File

@@ -46,9 +46,7 @@
static struct beep_softc *the_beep = NULL; static struct beep_softc *the_beep = NULL;
int int config_beep(struct beep_softc *bs, int unit) {
config_beep(struct beep_softc *bs, int unit)
{
/* We use only the first beep device. */ /* We use only the first beep device. */
if (unit != 0) { if (unit != 0) {
return ENODEV; return ENODEV;
@@ -59,13 +57,10 @@ config_beep(struct beep_softc *bs, int unit)
return 0; return 0;
} }
void void beep(void) {
beep(void)
{
if (the_beep != NULL) { if (the_beep != NULL) {
the_beep->bs_beep(the_beep->bs_devdata); the_beep->bs_beep(the_beep->bs_devdata);
} } else {
else {
kprintf("beep: Warning: no beep device\n"); kprintf("beep: Warning: no beep device\n");
} }
} }

View File

@@ -83,10 +83,7 @@ static struct lock *con_userlock_write = NULL;
static char delayed_outbuf[DELAYBUFSIZE]; static char delayed_outbuf[DELAYBUFSIZE];
static size_t delayed_outbuf_pos = 0; static size_t delayed_outbuf_pos = 0;
static static void putch_delayed(int ch) {
void
putch_delayed(int ch)
{
/* /*
* No synchronization needed: called only during system startup * No synchronization needed: called only during system startup
* by main thread. * by main thread.
@@ -96,10 +93,7 @@ putch_delayed(int ch)
delayed_outbuf[delayed_outbuf_pos++] = ch; delayed_outbuf[delayed_outbuf_pos++] = ch;
} }
static static void flush_delay_buf(void) {
void
flush_delay_buf(void)
{
size_t i; size_t i;
for (i = 0; i < delayed_outbuf_pos; i++) { for (i = 0; i < delayed_outbuf_pos; i++) {
putch(delayed_outbuf[i]); putch(delayed_outbuf[i]);
@@ -113,10 +107,7 @@ flush_delay_buf(void)
* Print a character, using polling instead of interrupts to wait for * Print a character, using polling instead of interrupts to wait for
* I/O completion. * I/O completion.
*/ */
static static void putch_polled(struct con_softc *cs, int ch) {
void
putch_polled(struct con_softc *cs, int ch)
{
cs->cs_sendpolled(cs->cs_devdata, ch); cs->cs_sendpolled(cs->cs_devdata, ch);
} }
@@ -125,10 +116,7 @@ putch_polled(struct con_softc *cs, int ch)
/* /*
* Print a character, using interrupts to wait for I/O completion. * Print a character, using interrupts to wait for I/O completion.
*/ */
static static void putch_intr(struct con_softc *cs, int ch) {
void
putch_intr(struct con_softc *cs, int ch)
{
P(cs->cs_wsem); P(cs->cs_wsem);
cs->cs_send(cs->cs_devdata, ch); cs->cs_send(cs->cs_devdata, ch);
} }
@@ -136,16 +124,12 @@ putch_intr(struct con_softc *cs, int ch)
/* /*
* Read a character, using interrupts to wait for I/O completion. * Read a character, using interrupts to wait for I/O completion.
*/ */
static static int getch_intr(struct con_softc *cs) {
int
getch_intr(struct con_softc *cs)
{
unsigned char ret; unsigned char ret;
P(cs->cs_rsem); P(cs->cs_rsem);
ret = cs->cs_gotchars[cs->cs_gotchars_tail]; ret = cs->cs_gotchars[cs->cs_gotchars_tail];
cs->cs_gotchars_tail = cs->cs_gotchars_tail = (cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
(cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
return ret; return ret;
} }
@@ -158,9 +142,7 @@ getch_intr(struct con_softc *cs)
* too) would be with a second semaphore used with a nonblocking P, * too) would be with a second semaphore used with a nonblocking P,
* but we don't have that in OS/161. * but we don't have that in OS/161.
*/ */
void void con_input(void *vcs, int ch) {
con_input(void *vcs, int ch)
{
struct con_softc *cs = vcs; struct con_softc *cs = vcs;
unsigned nexthead; unsigned nexthead;
@@ -179,9 +161,7 @@ con_input(void *vcs, int ch)
/* /*
* Called from underlying device when a write-done interrupt occurs. * Called from underlying device when a write-done interrupt occurs.
*/ */
void void con_start(void *vcs) {
con_start(void *vcs)
{
struct con_softc *cs = vcs; struct con_softc *cs = vcs;
V(cs->cs_wsem); V(cs->cs_wsem);
@@ -197,27 +177,20 @@ con_start(void *vcs)
* not, and does not. * not, and does not.
*/ */
void void putch(int ch) {
putch(int ch)
{
struct con_softc *cs = the_console; struct con_softc *cs = the_console;
if (cs == NULL) { if (cs == NULL) {
putch_delayed(ch); putch_delayed(ch);
} } else if (curthread->t_in_interrupt || curthread->t_curspl > 0 ||
else if (curthread->t_in_interrupt ||
curthread->t_curspl > 0 ||
curcpu->c_spinlocks > 0) { curcpu->c_spinlocks > 0) {
putch_polled(cs, ch); putch_polled(cs, ch);
} } else {
else {
putch_intr(cs, ch); putch_intr(cs, ch);
} }
} }
int int getch(void) {
getch(void)
{
struct con_softc *cs = the_console; struct con_softc *cs = the_console;
KASSERT(cs != NULL); KASSERT(cs != NULL);
KASSERT(!curthread->t_in_interrupt && curthread->t_iplhigh_count == 0); KASSERT(!curthread->t_in_interrupt && curthread->t_iplhigh_count == 0);
@@ -231,19 +204,13 @@ getch(void)
* VFS interface functions * VFS interface functions
*/ */
static static int con_eachopen(struct device *dev, int openflags) {
int
con_eachopen(struct device *dev, int openflags)
{
(void)dev; (void)dev;
(void)openflags; (void)openflags;
return 0; return 0;
} }
static static int con_io(struct device *dev, struct uio *uio) {
int
con_io(struct device *dev, struct uio *uio)
{
int result; int result;
char ch; char ch;
struct lock *lk; struct lock *lk;
@@ -252,8 +219,7 @@ con_io(struct device *dev, struct uio *uio)
if (uio->uio_rw == UIO_READ) { if (uio->uio_rw == UIO_READ) {
lk = con_userlock_read; lk = con_userlock_read;
} } else {
else {
lk = con_userlock_write; lk = con_userlock_write;
} }
@@ -274,8 +240,7 @@ con_io(struct device *dev, struct uio *uio)
if (ch == '\n') { if (ch == '\n') {
break; break;
} }
} } else {
else {
result = uiomove(&ch, 1, uio); result = uiomove(&ch, 1, uio);
if (result) { if (result) {
lock_release(lk); lock_release(lk);
@@ -291,10 +256,7 @@ con_io(struct device *dev, struct uio *uio)
return 0; return 0;
} }
static static int con_ioctl(struct device *dev, int op, userptr_t data) {
int
con_ioctl(struct device *dev, int op, userptr_t data)
{
/* No ioctls. */ /* No ioctls. */
(void)dev; (void)dev;
(void)op; (void)op;
@@ -308,10 +270,7 @@ static const struct device_ops console_devops = {
.devop_ioctl = con_ioctl, .devop_ioctl = con_ioctl,
}; };
static static int attach_console_to_vfs(struct con_softc *cs) {
int
attach_console_to_vfs(struct con_softc *cs)
{
struct device *dev; struct device *dev;
int result; int result;
@@ -340,9 +299,7 @@ attach_console_to_vfs(struct con_softc *cs)
* Config routine called by autoconf.c after we are attached to something. * Config routine called by autoconf.c after we are attached to something.
*/ */
int int config_con(struct con_softc *cs, int unit) {
config_con(struct con_softc *cs, int unit)
{
struct semaphore *rsem, *wsem; struct semaphore *rsem, *wsem;
struct lock *rlk, *wlk; struct lock *rlk, *wlk;

View File

@@ -53,10 +53,7 @@ static struct random_softc *the_random = NULL;
* VFS device functions. * VFS device functions.
* open: allow reading only. * open: allow reading only.
*/ */
static static int randeachopen(struct device *dev, int openflags) {
int
randeachopen(struct device *dev, int openflags)
{
(void)dev; (void)dev;
if (openflags != O_RDONLY) { if (openflags != O_RDONLY) {
@@ -69,10 +66,7 @@ randeachopen(struct device *dev, int openflags)
/* /*
* VFS I/O function. Hand off to implementation. * VFS I/O function. Hand off to implementation.
*/ */
static static int randio(struct device *dev, struct uio *uio) {
int
randio(struct device *dev, struct uio *uio)
{
struct random_softc *rs = dev->d_data; struct random_softc *rs = dev->d_data;
if (uio->uio_rw != UIO_READ) { if (uio->uio_rw != UIO_READ) {
@@ -85,10 +79,7 @@ randio(struct device *dev, struct uio *uio)
/* /*
* VFS ioctl function. * VFS ioctl function.
*/ */
static static int randioctl(struct device *dev, int op, userptr_t data) {
int
randioctl(struct device *dev, int op, userptr_t data)
{
/* /*
* We don't support any ioctls. * We don't support any ioctls.
*/ */
@@ -107,9 +98,7 @@ static const struct device_ops random_devops = {
/* /*
* Config function. * Config function.
*/ */
int int config_random(struct random_softc *rs, int unit) {
config_random(struct random_softc *rs, int unit)
{
int result; int result;
/* We use only the first random device. */ /* We use only the first random device. */
@@ -134,23 +123,18 @@ config_random(struct random_softc *rs, int unit)
return 0; return 0;
} }
/* /*
* Random number functions exported to the rest of the kernel. * Random number functions exported to the rest of the kernel.
*/ */
uint32_t uint32_t random(void) {
random(void)
{
if (the_random == NULL) { if (the_random == NULL) {
panic("No random device\n"); panic("No random device\n");
} }
return the_random->rs_random(the_random->rs_devdata); return the_random->rs_random(the_random->rs_devdata);
} }
uint32_t uint32_t randmax(void) {
randmax(void)
{
if (the_random == NULL) { if (the_random == NULL) {
panic("No random device\n"); panic("No random device\n");
} }

View File

@@ -49,9 +49,7 @@
static struct rtclock_softc *the_clock = NULL; static struct rtclock_softc *the_clock = NULL;
int int config_rtclock(struct rtclock_softc *rtc, int unit) {
config_rtclock(struct rtclock_softc *rtc, int unit)
{
/* We use only the first clock device. */ /* We use only the first clock device. */
if (unit != 0) { if (unit != 0) {
return ENODEV; return ENODEV;
@@ -62,9 +60,7 @@ config_rtclock(struct rtclock_softc *rtc, int unit)
return 0; return 0;
} }
void void gettime(struct timespec *ts) {
gettime(struct timespec *ts)
{
KASSERT(the_clock != NULL); KASSERT(the_clock != NULL);
the_clock->rtc_gettime(the_clock->rtc_devdata, ts); the_clock->rtc_gettime(the_clock->rtc_devdata, ts);
} }

View File

@@ -38,9 +38,7 @@
#include <lamebus/ltimer.h> #include <lamebus/ltimer.h>
#include "autoconf.h" #include "autoconf.h"
struct beep_softc * struct beep_softc *attach_beep_to_ltimer(int beepno, struct ltimer_softc *ls) {
attach_beep_to_ltimer(int beepno, struct ltimer_softc *ls)
{
struct beep_softc *bs = kmalloc(sizeof(struct beep_softc)); struct beep_softc *bs = kmalloc(sizeof(struct beep_softc));
if (bs == NULL) { if (bs == NULL) {
return NULL; return NULL;

View File

@@ -38,9 +38,7 @@
#include <lamebus/lscreen.h> #include <lamebus/lscreen.h>
#include "autoconf.h" #include "autoconf.h"
struct con_softc * struct con_softc *attach_con_to_lscreen(int consno, struct lscreen_softc *ls) {
attach_con_to_lscreen(int consno, struct lscreen_softc *ls)
{
struct con_softc *cs = kmalloc(sizeof(struct con_softc)); struct con_softc *cs = kmalloc(sizeof(struct con_softc));
if (cs == NULL) { if (cs == NULL) {
return NULL; return NULL;
@@ -56,4 +54,3 @@ attach_con_to_lscreen(int consno, struct lscreen_softc *ls)
return cs; return cs;
} }

View File

@@ -38,9 +38,7 @@
#include <lamebus/lser.h> #include <lamebus/lser.h>
#include "autoconf.h" #include "autoconf.h"
struct con_softc * struct con_softc *attach_con_to_lser(int consno, struct lser_softc *ls) {
attach_con_to_lser(int consno, struct lser_softc *ls)
{
struct con_softc *cs = kmalloc(sizeof(struct con_softc)); struct con_softc *cs = kmalloc(sizeof(struct con_softc));
if (cs == NULL) { if (cs == NULL) {
return NULL; return NULL;
@@ -58,4 +56,3 @@ attach_con_to_lser(int consno, struct lser_softc *ls)
return cs; return cs;
} }

View File

@@ -99,31 +99,21 @@
/* /*
* Shortcut for reading a register * Shortcut for reading a register
*/ */
static static inline uint32_t emu_rreg(struct emu_softc *sc, uint32_t reg) {
inline
uint32_t
emu_rreg(struct emu_softc *sc, uint32_t reg)
{
return bus_read_register(sc->e_busdata, sc->e_buspos, reg); return bus_read_register(sc->e_busdata, sc->e_buspos, reg);
} }
/* /*
* Shortcut for writing a register * Shortcut for writing a register
*/ */
static static inline void emu_wreg(struct emu_softc *sc, uint32_t reg, uint32_t val) {
inline
void
emu_wreg(struct emu_softc *sc, uint32_t reg, uint32_t val)
{
bus_write_register(sc->e_busdata, sc->e_buspos, reg, val); bus_write_register(sc->e_busdata, sc->e_buspos, reg, val);
} }
/* /*
* Called by the underlying bus code when an interrupt happens * Called by the underlying bus code when an interrupt happens
*/ */
void void emu_irq(void *dev) {
emu_irq(void *dev)
{
struct emu_softc *sc = dev; struct emu_softc *sc = dev;
sc->e_result = emu_rreg(sc, REG_RESULT); sc->e_result = emu_rreg(sc, REG_RESULT);
@@ -136,25 +126,32 @@ emu_irq(void *dev)
* Convert the error codes reported by the "hardware" to errnos. * Convert the error codes reported by the "hardware" to errnos.
* Or, on cases that indicate a programming error in emu.c, panic. * Or, on cases that indicate a programming error in emu.c, panic.
*/ */
static static uint32_t translate_err(struct emu_softc *sc, uint32_t code) {
uint32_t
translate_err(struct emu_softc *sc, uint32_t code)
{
switch (code) { switch (code) {
case EMU_RES_SUCCESS: return 0; case EMU_RES_SUCCESS:
return 0;
case EMU_RES_BADHANDLE: case EMU_RES_BADHANDLE:
case EMU_RES_BADOP: case EMU_RES_BADOP:
case EMU_RES_BADSIZE: case EMU_RES_BADSIZE:
panic("emu%d: got fatal result code %d\n", sc->e_unit, code); panic("emu%d: got fatal result code %d\n", sc->e_unit, code);
case EMU_RES_BADPATH: return ENOENT; case EMU_RES_BADPATH:
case EMU_RES_EXISTS: return EEXIST; return ENOENT;
case EMU_RES_ISDIR: return EISDIR; case EMU_RES_EXISTS:
case EMU_RES_MEDIA: return EIO; return EEXIST;
case EMU_RES_NOHANDLES: return ENFILE; case EMU_RES_ISDIR:
case EMU_RES_NOSPACE: return ENOSPC; return EISDIR;
case EMU_RES_NOTDIR: return ENOTDIR; case EMU_RES_MEDIA:
case EMU_RES_UNKNOWN: return EIO; return EIO;
case EMU_RES_UNSUPP: return ENOSYS; case EMU_RES_NOHANDLES:
return ENFILE;
case EMU_RES_NOSPACE:
return ENOSPC;
case EMU_RES_NOTDIR:
return ENOTDIR;
case EMU_RES_UNKNOWN:
return EIO;
case EMU_RES_UNSUPP:
return ENOSYS;
} }
kprintf("emu%d: Unknown result code %d\n", sc->e_unit, code); kprintf("emu%d: Unknown result code %d\n", sc->e_unit, code);
return EAGAIN; return EAGAIN;
@@ -163,10 +160,7 @@ translate_err(struct emu_softc *sc, uint32_t code)
/* /*
* Wait for an operation to complete, and return an errno for the result. * Wait for an operation to complete, and return an errno for the result.
*/ */
static static int emu_waitdone(struct emu_softc *sc) {
int
emu_waitdone(struct emu_softc *sc)
{
P(sc->e_sem); P(sc->e_sem);
return translate_err(sc, sc->e_result); return translate_err(sc, sc->e_result);
} }
@@ -177,12 +171,9 @@ emu_waitdone(struct emu_softc *sc)
* order to look at them, so by the time VOP_EACHOPEN is called the * order to look at them, so by the time VOP_EACHOPEN is called the
* files are already open. * files are already open.
*/ */
static static int emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
int bool create, bool excl, mode_t mode, uint32_t *newhandle,
emu_open(struct emu_softc *sc, uint32_t handle, const char *name, int *newisdir) {
bool create, bool excl, mode_t mode,
uint32_t *newhandle, int *newisdir)
{
uint32_t op; uint32_t op;
int result; int result;
@@ -192,11 +183,9 @@ emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
if (create && excl) { if (create && excl) {
op = EMU_OP_EXCLCREATE; op = EMU_OP_EXCLCREATE;
} } else if (create) {
else if (create) {
op = EMU_OP_CREATE; op = EMU_OP_CREATE;
} } else {
else {
op = EMU_OP_OPEN; op = EMU_OP_OPEN;
} }
@@ -226,10 +215,7 @@ emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
* This is not necessarily called at VOP_LASTCLOSE time; it's called * This is not necessarily called at VOP_LASTCLOSE time; it's called
* at VOP_RECLAIM time. * at VOP_RECLAIM time.
*/ */
static static int emu_close(struct emu_softc *sc, uint32_t handle) {
int
emu_close(struct emu_softc *sc, uint32_t handle)
{
int result; int result;
bool mine; bool mine;
int retries = 0; int retries = 0;
@@ -247,8 +233,7 @@ emu_close(struct emu_softc *sc, uint32_t handle)
result = emu_waitdone(sc); result = emu_waitdone(sc);
if (result == EIO && retries < 10) { if (result == EIO && retries < 10) {
kprintf("emu%d: I/O error on close, retrying\n", kprintf("emu%d: I/O error on close, retrying\n", sc->e_unit);
sc->e_unit);
retries++; retries++;
continue; continue;
} }
@@ -264,11 +249,8 @@ emu_close(struct emu_softc *sc, uint32_t handle)
/* /*
* Common code for read and readdir. * Common code for read and readdir.
*/ */
static static int emu_doread(struct emu_softc *sc, uint32_t handle, uint32_t len,
int uint32_t op, struct uio *uio) {
emu_doread(struct emu_softc *sc, uint32_t handle, uint32_t len,
uint32_t op, struct uio *uio)
{
int result; int result;
KASSERT(uio->uio_rw == UIO_READ); KASSERT(uio->uio_rw == UIO_READ);
@@ -302,33 +284,24 @@ emu_doread(struct emu_softc *sc, uint32_t handle, uint32_t len,
/* /*
* Read from a hardware-level file handle. * Read from a hardware-level file handle.
*/ */
static static int emu_read(struct emu_softc *sc, uint32_t handle, uint32_t len,
int struct uio *uio) {
emu_read(struct emu_softc *sc, uint32_t handle, uint32_t len,
struct uio *uio)
{
return emu_doread(sc, handle, len, EMU_OP_READ, uio); return emu_doread(sc, handle, len, EMU_OP_READ, uio);
} }
/* /*
* Read a directory entry from a hardware-level file handle. * Read a directory entry from a hardware-level file handle.
*/ */
static static int emu_readdir(struct emu_softc *sc, uint32_t handle, uint32_t len,
int struct uio *uio) {
emu_readdir(struct emu_softc *sc, uint32_t handle, uint32_t len,
struct uio *uio)
{
return emu_doread(sc, handle, len, EMU_OP_READDIR, uio); return emu_doread(sc, handle, len, EMU_OP_READDIR, uio);
} }
/* /*
* Write to a hardware-level file handle. * Write to a hardware-level file handle.
*/ */
static static int emu_write(struct emu_softc *sc, uint32_t handle, uint32_t len,
int struct uio *uio) {
emu_write(struct emu_softc *sc, uint32_t handle, uint32_t len,
struct uio *uio)
{
int result; int result;
KASSERT(uio->uio_rw == UIO_WRITE); KASSERT(uio->uio_rw == UIO_WRITE);
@@ -360,10 +333,7 @@ emu_write(struct emu_softc *sc, uint32_t handle, uint32_t len,
/* /*
* Get the file size associated with a hardware-level file handle. * Get the file size associated with a hardware-level file handle.
*/ */
static static int emu_getsize(struct emu_softc *sc, uint32_t handle, off_t *retval) {
int
emu_getsize(struct emu_softc *sc, uint32_t handle, off_t *retval)
{
int result; int result;
lock_acquire(sc->e_lock); lock_acquire(sc->e_lock);
@@ -382,10 +352,7 @@ emu_getsize(struct emu_softc *sc, uint32_t handle, off_t *retval)
/* /*
* Truncate a hardware-level file handle. * Truncate a hardware-level file handle.
*/ */
static static int emu_trunc(struct emu_softc *sc, uint32_t handle, off_t len) {
int
emu_trunc(struct emu_softc *sc, uint32_t handle, off_t len)
{
int result; int result;
KASSERT(len >= 0); KASSERT(len >= 0);
@@ -417,10 +384,7 @@ static int emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
/* /*
* VOP_EACHOPEN on files * VOP_EACHOPEN on files
*/ */
static static int emufs_eachopen(struct vnode *v, int openflags) {
int
emufs_eachopen(struct vnode *v, int openflags)
{
/* /*
* At this level we do not need to handle O_CREAT, O_EXCL, * At this level we do not need to handle O_CREAT, O_EXCL,
* O_TRUNC, or O_APPEND. * O_TRUNC, or O_APPEND.
@@ -438,10 +402,7 @@ emufs_eachopen(struct vnode *v, int openflags)
/* /*
* VOP_EACHOPEN on directories * VOP_EACHOPEN on directories
*/ */
static static int emufs_eachopendir(struct vnode *v, int openflags) {
int
emufs_eachopendir(struct vnode *v, int openflags)
{
switch (openflags & O_ACCMODE) { switch (openflags & O_ACCMODE) {
case O_RDONLY: case O_RDONLY:
break; break;
@@ -463,10 +424,7 @@ emufs_eachopendir(struct vnode *v, int openflags)
* *
* Reclaim should make an effort to returning errors other than EBUSY. * Reclaim should make an effort to returning errors other than EBUSY.
*/ */
static static int emufs_reclaim(struct vnode *v) {
int
emufs_reclaim(struct vnode *v)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
struct emufs_fs *ef = v->vn_fs->fs_data; struct emufs_fs *ef = v->vn_fs->fs_data;
unsigned ix, i, num; unsigned ix, i, num;
@@ -519,8 +477,8 @@ emufs_reclaim(struct vnode *v)
} }
} }
if (ix == num) { if (ix == num) {
panic("emu%d: reclaim vnode %u not in vnode pool\n", panic("emu%d: reclaim vnode %u not in vnode pool\n", ef->ef_emu->e_unit,
ef->ef_emu->e_unit, ev->ev_handle); ev->ev_handle);
} }
vnodearray_remove(ef->ef_vnodes, ix); vnodearray_remove(ef->ef_vnodes, ix);
@@ -536,10 +494,7 @@ emufs_reclaim(struct vnode *v)
/* /*
* VOP_READ * VOP_READ
*/ */
static static int emufs_read(struct vnode *v, struct uio *uio) {
int
emufs_read(struct vnode *v, struct uio *uio)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
uint32_t amt; uint32_t amt;
size_t oldresid; size_t oldresid;
@@ -572,10 +527,7 @@ emufs_read(struct vnode *v, struct uio *uio)
/* /*
* VOP_READDIR * VOP_READDIR
*/ */
static static int emufs_getdirentry(struct vnode *v, struct uio *uio) {
int
emufs_getdirentry(struct vnode *v, struct uio *uio)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
uint32_t amt; uint32_t amt;
@@ -592,10 +544,7 @@ emufs_getdirentry(struct vnode *v, struct uio *uio)
/* /*
* VOP_WRITE * VOP_WRITE
*/ */
static static int emufs_write(struct vnode *v, struct uio *uio) {
int
emufs_write(struct vnode *v, struct uio *uio)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
uint32_t amt; uint32_t amt;
size_t oldresid; size_t oldresid;
@@ -628,10 +577,7 @@ emufs_write(struct vnode *v, struct uio *uio)
/* /*
* VOP_IOCTL * VOP_IOCTL
*/ */
static static int emufs_ioctl(struct vnode *v, int op, userptr_t data) {
int
emufs_ioctl(struct vnode *v, int op, userptr_t data)
{
/* /*
* No ioctls. * No ioctls.
*/ */
@@ -646,10 +592,7 @@ emufs_ioctl(struct vnode *v, int op, userptr_t data)
/* /*
* VOP_STAT * VOP_STAT
*/ */
static static int emufs_stat(struct vnode *v, struct stat *statbuf) {
int
emufs_stat(struct vnode *v, struct stat *statbuf)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
int result; int result;
@@ -674,10 +617,7 @@ emufs_stat(struct vnode *v, struct stat *statbuf)
/* /*
* VOP_GETTYPE for files * VOP_GETTYPE for files
*/ */
static static int emufs_file_gettype(struct vnode *v, uint32_t *result) {
int
emufs_file_gettype(struct vnode *v, uint32_t *result)
{
(void)v; (void)v;
*result = S_IFREG; *result = S_IFREG;
return 0; return 0;
@@ -686,10 +626,7 @@ emufs_file_gettype(struct vnode *v, uint32_t *result)
/* /*
* VOP_GETTYPE for directories * VOP_GETTYPE for directories
*/ */
static static int emufs_dir_gettype(struct vnode *v, uint32_t *result) {
int
emufs_dir_gettype(struct vnode *v, uint32_t *result)
{
(void)v; (void)v;
*result = S_IFDIR; *result = S_IFDIR;
return 0; return 0;
@@ -698,10 +635,7 @@ emufs_dir_gettype(struct vnode *v, uint32_t *result)
/* /*
* VOP_ISSEEKABLE * VOP_ISSEEKABLE
*/ */
static static bool emufs_isseekable(struct vnode *v) {
bool
emufs_isseekable(struct vnode *v)
{
(void)v; (void)v;
return true; return true;
} }
@@ -709,10 +643,7 @@ emufs_isseekable(struct vnode *v)
/* /*
* VOP_FSYNC * VOP_FSYNC
*/ */
static static int emufs_fsync(struct vnode *v) {
int
emufs_fsync(struct vnode *v)
{
(void)v; (void)v;
return 0; return 0;
} }
@@ -720,10 +651,7 @@ emufs_fsync(struct vnode *v)
/* /*
* VOP_TRUNCATE * VOP_TRUNCATE
*/ */
static static int emufs_truncate(struct vnode *v, off_t len) {
int
emufs_truncate(struct vnode *v, off_t len)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
return emu_trunc(ev->ev_emu, ev->ev_handle, len); return emu_trunc(ev->ev_emu, ev->ev_handle, len);
} }
@@ -731,11 +659,8 @@ emufs_truncate(struct vnode *v, off_t len)
/* /*
* VOP_CREAT * VOP_CREAT
*/ */
static static int emufs_creat(struct vnode *dir, const char *name, bool excl,
int mode_t mode, struct vnode **ret) {
emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
struct vnode **ret)
{
struct emufs_vnode *ev = dir->vn_data; struct emufs_vnode *ev = dir->vn_data;
struct emufs_fs *ef = dir->vn_fs->fs_data; struct emufs_fs *ef = dir->vn_fs->fs_data;
struct emufs_vnode *newguy; struct emufs_vnode *newguy;
@@ -743,8 +668,8 @@ emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
int result; int result;
int isdir; int isdir;
result = emu_open(ev->ev_emu, ev->ev_handle, name, true, excl, mode, result = emu_open(ev->ev_emu, ev->ev_handle, name, true, excl, mode, &handle,
&handle, &isdir); &isdir);
if (result) { if (result) {
return result; return result;
} }
@@ -762,10 +687,7 @@ emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
/* /*
* VOP_LOOKUP * VOP_LOOKUP
*/ */
static static int emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret) {
int
emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret)
{
struct emufs_vnode *ev = dir->vn_data; struct emufs_vnode *ev = dir->vn_data;
struct emufs_fs *ef = dir->vn_fs->fs_data; struct emufs_fs *ef = dir->vn_fs->fs_data;
struct emufs_vnode *newguy; struct emufs_vnode *newguy;
@@ -792,11 +714,8 @@ emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret)
/* /*
* VOP_LOOKPARENT * VOP_LOOKPARENT
*/ */
static static int emufs_lookparent(struct vnode *dir, char *pathname,
int struct vnode **ret, char *buf, size_t len) {
emufs_lookparent(struct vnode *dir, char *pathname, struct vnode **ret,
char *buf, size_t len)
{
char *s; char *s;
s = strrchr(pathname, '/'); s = strrchr(pathname, '/');
@@ -824,10 +743,7 @@ emufs_lookparent(struct vnode *dir, char *pathname, struct vnode **ret,
/* /*
* VOP_NAMEFILE * VOP_NAMEFILE
*/ */
static static int emufs_namefile(struct vnode *v, struct uio *uio) {
int
emufs_namefile(struct vnode *v, struct uio *uio)
{
struct emufs_vnode *ev = v->vn_data; struct emufs_vnode *ev = v->vn_data;
struct emufs_fs *ef = v->vn_fs->fs_data; struct emufs_fs *ef = v->vn_fs->fs_data;
@@ -846,10 +762,7 @@ emufs_namefile(struct vnode *v, struct uio *uio)
/* /*
* VOP_MMAP * VOP_MMAP
*/ */
static static int emufs_mmap(struct vnode *v) {
int
emufs_mmap(struct vnode *v)
{
(void)v; (void)v;
return ENOSYS; return ENOSYS;
} }
@@ -860,59 +773,42 @@ emufs_mmap(struct vnode *v)
* Bits not implemented at all on emufs * Bits not implemented at all on emufs
*/ */
static static int emufs_symlink(struct vnode *v, const char *contents,
int const char *name) {
emufs_symlink(struct vnode *v, const char *contents, const char *name)
{
(void)v; (void)v;
(void)contents; (void)contents;
(void)name; (void)name;
return ENOSYS; return ENOSYS;
} }
static static int emufs_mkdir(struct vnode *v, const char *name, mode_t mode) {
int
emufs_mkdir(struct vnode *v, const char *name, mode_t mode)
{
(void)v; (void)v;
(void)name; (void)name;
(void)mode; (void)mode;
return ENOSYS; return ENOSYS;
} }
static static int emufs_link(struct vnode *v, const char *name, struct vnode *target) {
int
emufs_link(struct vnode *v, const char *name, struct vnode *target)
{
(void)v; (void)v;
(void)name; (void)name;
(void)target; (void)target;
return ENOSYS; return ENOSYS;
} }
static static int emufs_remove(struct vnode *v, const char *name) {
int
emufs_remove(struct vnode *v, const char *name)
{
(void)v; (void)v;
(void)name; (void)name;
return ENOSYS; return ENOSYS;
} }
static static int emufs_rmdir(struct vnode *v, const char *name) {
int
emufs_rmdir(struct vnode *v, const char *name)
{
(void)v; (void)v;
(void)name; (void)name;
return ENOSYS; return ENOSYS;
} }
static static int emufs_rename(struct vnode *v1, const char *n1, struct vnode *v2,
int const char *n2) {
emufs_rename(struct vnode *v1, const char *n1,
struct vnode *v2, const char *n2)
{
(void)v1; (void)v1;
(void)n1; (void)n1;
(void)v2; (void)v2;
@@ -935,55 +831,37 @@ emufs_rename(struct vnode *v1, const char *n1,
* problem but is otherwise not very appealing. * problem but is otherwise not very appealing.
*/ */
static static int emufs_void_op_isdir(struct vnode *v) {
int
emufs_void_op_isdir(struct vnode *v)
{
(void)v; (void)v;
return EISDIR; return EISDIR;
} }
static static int emufs_uio_op_isdir(struct vnode *v, struct uio *uio) {
int
emufs_uio_op_isdir(struct vnode *v, struct uio *uio)
{
(void)v; (void)v;
(void)uio; (void)uio;
return EISDIR; return EISDIR;
} }
static static int emufs_uio_op_notdir(struct vnode *v, struct uio *uio) {
int
emufs_uio_op_notdir(struct vnode *v, struct uio *uio)
{
(void)v; (void)v;
(void)uio; (void)uio;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_name_op_notdir(struct vnode *v, const char *name) {
int
emufs_name_op_notdir(struct vnode *v, const char *name)
{
(void)v; (void)v;
(void)name; (void)name;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_readlink_notlink(struct vnode *v, struct uio *uio) {
int
emufs_readlink_notlink(struct vnode *v, struct uio *uio)
{
(void)v; (void)v;
(void)uio; (void)uio;
return EINVAL; return EINVAL;
} }
static static int emufs_creat_notdir(struct vnode *v, const char *name, bool excl,
int mode_t mode, struct vnode **retval) {
emufs_creat_notdir(struct vnode *v, const char *name, bool excl, mode_t mode,
struct vnode **retval)
{
(void)v; (void)v;
(void)name; (void)name;
(void)excl; (void)excl;
@@ -992,41 +870,31 @@ emufs_creat_notdir(struct vnode *v, const char *name, bool excl, mode_t mode,
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_symlink_notdir(struct vnode *v, const char *contents,
int const char *name) {
emufs_symlink_notdir(struct vnode *v, const char *contents, const char *name)
{
(void)v; (void)v;
(void)contents; (void)contents;
(void)name; (void)name;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_mkdir_notdir(struct vnode *v, const char *name, mode_t mode) {
int
emufs_mkdir_notdir(struct vnode *v, const char *name, mode_t mode)
{
(void)v; (void)v;
(void)name; (void)name;
(void)mode; (void)mode;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_link_notdir(struct vnode *v, const char *name,
int struct vnode *target) {
emufs_link_notdir(struct vnode *v, const char *name, struct vnode *target)
{
(void)v; (void)v;
(void)name; (void)name;
(void)target; (void)target;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_rename_notdir(struct vnode *v1, const char *n1,
int struct vnode *v2, const char *n2) {
emufs_rename_notdir(struct vnode *v1, const char *n1,
struct vnode *v2, const char *n2)
{
(void)v1; (void)v1;
(void)n1; (void)n1;
(void)v2; (void)v2;
@@ -1034,21 +902,17 @@ emufs_rename_notdir(struct vnode *v1, const char *n1,
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_lookup_notdir(struct vnode *v, char *pathname,
int struct vnode **result) {
emufs_lookup_notdir(struct vnode *v, char *pathname, struct vnode **result)
{
(void)v; (void)v;
(void)pathname; (void)pathname;
(void)result; (void)result;
return ENOTDIR; return ENOTDIR;
} }
static static int emufs_lookparent_notdir(struct vnode *v, char *pathname,
int struct vnode **result, char *buf,
emufs_lookparent_notdir(struct vnode *v, char *pathname, struct vnode **result, size_t len) {
char *buf, size_t len)
{
(void)v; (void)v;
(void)pathname; (void)pathname;
(void)result; (void)result;
@@ -1057,11 +921,7 @@ emufs_lookparent_notdir(struct vnode *v, char *pathname, struct vnode **result,
return ENOTDIR; return ENOTDIR;
} }
static int emufs_truncate_isdir(struct vnode *v, off_t len) {
static
int
emufs_truncate_isdir(struct vnode *v, off_t len)
{
(void)v; (void)v;
(void)len; (void)len;
return ENOTDIR; return ENOTDIR;
@@ -1140,11 +1000,8 @@ static const struct vnode_ops emufs_dirops = {
/* /*
* Function to load a vnode into memory. * Function to load a vnode into memory.
*/ */
static static int emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
int struct emufs_vnode **ret) {
emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
struct emufs_vnode **ret)
{
struct vnode *v; struct vnode *v;
struct emufs_vnode *ev; struct emufs_vnode *ev;
unsigned i, num; unsigned i, num;
@@ -1217,10 +1074,7 @@ emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
/* /*
* FSOP_SYNC * FSOP_SYNC
*/ */
static static int emufs_sync(struct fs *fs) {
int
emufs_sync(struct fs *fs)
{
(void)fs; (void)fs;
return 0; return 0;
} }
@@ -1228,10 +1082,7 @@ emufs_sync(struct fs *fs)
/* /*
* FSOP_GETVOLNAME * FSOP_GETVOLNAME
*/ */
static static const char *emufs_getvolname(struct fs *fs) {
const char *
emufs_getvolname(struct fs *fs)
{
/* We don't have a volume name beyond the device name */ /* We don't have a volume name beyond the device name */
(void)fs; (void)fs;
return NULL; return NULL;
@@ -1240,10 +1091,7 @@ emufs_getvolname(struct fs *fs)
/* /*
* FSOP_GETROOT * FSOP_GETROOT
*/ */
static static int emufs_getroot(struct fs *fs, struct vnode **ret) {
int
emufs_getroot(struct fs *fs, struct vnode **ret)
{
struct emufs_fs *ef; struct emufs_fs *ef;
KASSERT(fs != NULL); KASSERT(fs != NULL);
@@ -1261,10 +1109,7 @@ emufs_getroot(struct fs *fs, struct vnode **ret)
/* /*
* FSOP_UNMOUNT * FSOP_UNMOUNT
*/ */
static static int emufs_unmount(struct fs *fs) {
int
emufs_unmount(struct fs *fs)
{
/* Always prohibit unmount, as we're not really "mounted" */ /* Always prohibit unmount, as we're not really "mounted" */
(void)fs; (void)fs;
return EBUSY; return EBUSY;
@@ -1287,10 +1132,7 @@ static const struct fs_ops emufs_fsops = {
* *
* Basically, we just add ourselves to the name list in the VFS layer. * Basically, we just add ourselves to the name list in the VFS layer.
*/ */
static static int emufs_addtovfs(struct emu_softc *sc, const char *devname) {
int
emufs_addtovfs(struct emu_softc *sc, const char *devname)
{
struct emufs_fs *ef; struct emufs_fs *ef;
int result; int result;
@@ -1334,9 +1176,7 @@ emufs_addtovfs(struct emu_softc *sc, const char *devname)
* *
* Initialize our data, then add ourselves to the VFS layer. * Initialize our data, then add ourselves to the VFS layer.
*/ */
int int config_emu(struct emu_softc *sc, int emuno) {
config_emu(struct emu_softc *sc, int emuno)
{
char name[32]; char name[32];
sc->e_lock = lock_create("emufs-lock"); sc->e_lock = lock_create("emufs-lock");

View File

@@ -30,7 +30,6 @@
#ifndef _LAMEBUS_EMU_H_ #ifndef _LAMEBUS_EMU_H_
#define _LAMEBUS_EMU_H_ #define _LAMEBUS_EMU_H_
#define EMU_MAXIO 16384 #define EMU_MAXIO 16384
#define EMU_ROOTHANDLE 0 #define EMU_ROOTHANDLE 0
@@ -58,5 +57,4 @@ struct emu_softc {
/* Functions called by lower-level drivers */ /* Functions called by lower-level drivers */
void emu_irq(/*struct emu_softc*/ void *); void emu_irq(/*struct emu_softc*/ void *);
#endif /* _LAMEBUS_EMU_H_ */ #endif /* _LAMEBUS_EMU_H_ */

View File

@@ -40,12 +40,10 @@
/* Lowest revision we support */ /* Lowest revision we support */
#define LOW_VERSION 1 #define LOW_VERSION 1
struct emu_softc * struct emu_softc *attach_emu_to_lamebus(int emuno, struct lamebus_softc *sc) {
attach_emu_to_lamebus(int emuno, struct lamebus_softc *sc)
{
struct emu_softc *es; struct emu_softc *es;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_EMUFS, int slot =
LOW_VERSION, NULL); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_EMUFS, LOW_VERSION, NULL);
if (slot < 0) { if (slot < 0) {
return NULL; return NULL;
} }

View File

@@ -58,15 +58,11 @@
#define CTLCPU_CIPI 0x004 #define CTLCPU_CIPI 0x004
#define CTLCPU_CRAM 0x300 #define CTLCPU_CRAM 0x300
/* /*
* Read a config register for the given slot. * Read a config register for the given slot.
*/ */
static static inline uint32_t read_cfg_register(struct lamebus_softc *lb, int slot,
inline uint32_t offset) {
uint32_t
read_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset)
{
/* Note that lb might be NULL on some platforms in some contexts. */ /* Note that lb might be NULL on some platforms in some contexts. */
offset += LB_CONFIG_SIZE * slot; offset += LB_CONFIG_SIZE * slot;
return lamebus_read_register(lb, LB_CONTROLLER_SLOT, offset); return lamebus_read_register(lb, LB_CONTROLLER_SLOT, offset);
@@ -75,12 +71,8 @@ read_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset)
/* /*
* Write a config register for a given slot. * Write a config register for a given slot.
*/ */
static static inline void write_cfg_register(struct lamebus_softc *lb, int slot,
inline uint32_t offset, uint32_t val) {
void
write_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset,
uint32_t val)
{
offset += LB_CONFIG_SIZE * slot; offset += LB_CONFIG_SIZE * slot;
lamebus_write_register(lb, LB_CONTROLLER_SLOT, offset, val); lamebus_write_register(lb, LB_CONTROLLER_SLOT, offset, val);
} }
@@ -88,11 +80,8 @@ write_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset,
/* /*
* Read one of the bus controller's registers. * Read one of the bus controller's registers.
*/ */
static static inline uint32_t read_ctl_register(struct lamebus_softc *lb,
inline uint32_t offset) {
uint32_t
read_ctl_register(struct lamebus_softc *lb, uint32_t offset)
{
/* Note that lb might be NULL on some platforms in some contexts. */ /* Note that lb might be NULL on some platforms in some contexts. */
return read_cfg_register(lb, LB_CONTROLLER_SLOT, offset); return read_cfg_register(lb, LB_CONTROLLER_SLOT, offset);
} }
@@ -100,23 +89,17 @@ read_ctl_register(struct lamebus_softc *lb, uint32_t offset)
/* /*
* Write one of the bus controller's registers. * Write one of the bus controller's registers.
*/ */
static static inline void write_ctl_register(struct lamebus_softc *lb, uint32_t offset,
inline uint32_t val) {
void
write_ctl_register(struct lamebus_softc *lb, uint32_t offset, uint32_t val)
{
write_cfg_register(lb, LB_CONTROLLER_SLOT, offset, val); write_cfg_register(lb, LB_CONTROLLER_SLOT, offset, val);
} }
/* /*
* Write one of the bus controller's CPU control registers. * Write one of the bus controller's CPU control registers.
*/ */
static static inline void write_ctlcpu_register(struct lamebus_softc *lb,
inline unsigned hw_cpunum, uint32_t offset,
void uint32_t val) {
write_ctlcpu_register(struct lamebus_softc *lb, unsigned hw_cpunum,
uint32_t offset, uint32_t val)
{
offset += LB_CTLCPU_OFFSET + hw_cpunum * LB_CTLCPU_SIZE; offset += LB_CTLCPU_OFFSET + hw_cpunum * LB_CTLCPU_SIZE;
lamebus_write_register(lb, LB_CONTROLLER_SLOT, offset, val); lamebus_write_register(lb, LB_CONTROLLER_SLOT, offset, val);
} }
@@ -124,20 +107,15 @@ write_ctlcpu_register(struct lamebus_softc *lb, unsigned hw_cpunum,
/* /*
* Find and create secondary CPUs. * Find and create secondary CPUs.
*/ */
void void lamebus_find_cpus(struct lamebus_softc *lamebus) {
lamebus_find_cpus(struct lamebus_softc *lamebus)
{
uint32_t mainboard_vid, mainboard_did; uint32_t mainboard_vid, mainboard_did;
uint32_t cpumask, self, bit, val; uint32_t cpumask, self, bit, val;
unsigned i, numcpus, bootcpu; unsigned i, numcpus, bootcpu;
unsigned hwnum[32]; unsigned hwnum[32];
mainboard_vid = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, mainboard_vid = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, CFGREG_VID);
CFGREG_VID); mainboard_did = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, CFGREG_DID);
mainboard_did = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, if (mainboard_vid == LB_VENDOR_CS161 && mainboard_did == LBCS161_UPBUSCTL) {
CFGREG_DID);
if (mainboard_vid == LB_VENDOR_CS161 &&
mainboard_did == LBCS161_UPBUSCTL) {
/* Old uniprocessor mainboard; no cpu registers. */ /* Old uniprocessor mainboard; no cpu registers. */
lamebus->ls_uniprocessor = 1; lamebus->ls_uniprocessor = 1;
return; return;
@@ -175,8 +153,7 @@ lamebus_find_cpus(struct lamebus_softc *lamebus)
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
if (i != bootcpu) { if (i != bootcpu) {
val = 0; val = 0;
} } else {
else {
val = 0xffffffff; val = 0xffffffff;
} }
write_ctlcpu_register(lamebus, hwnum[i], CTLCPU_CIRQE, val); write_ctlcpu_register(lamebus, hwnum[i], CTLCPU_CIRQE, val);
@@ -193,9 +170,7 @@ lamebus_find_cpus(struct lamebus_softc *lamebus)
* LAMEbus; if in some environment there are other CPUs about as well * LAMEbus; if in some environment there are other CPUs about as well
* this logic will have to be made more complex. * this logic will have to be made more complex.
*/ */
void void lamebus_start_cpus(struct lamebus_softc *lamebus) {
lamebus_start_cpus(struct lamebus_softc *lamebus)
{
uint32_t cpumask, self, bit; uint32_t cpumask, self, bit;
uint32_t ctlcpuoffset; uint32_t ctlcpuoffset;
uint32_t *cram; uint32_t *cram;
@@ -218,8 +193,7 @@ lamebus_start_cpus(struct lamebus_softc *lamebus)
continue; continue;
} }
ctlcpuoffset = LB_CTLCPU_OFFSET + i * LB_CTLCPU_SIZE; ctlcpuoffset = LB_CTLCPU_OFFSET + i * LB_CTLCPU_SIZE;
cram = lamebus_map_area(lamebus, cram = lamebus_map_area(lamebus, LB_CONTROLLER_SLOT,
LB_CONTROLLER_SLOT,
ctlcpuoffset + CTLCPU_CRAM); ctlcpuoffset + CTLCPU_CRAM);
cram[0] = (uint32_t)cpu_start_secondary; cram[0] = (uint32_t)cpu_start_secondary;
cram[1] = cpunum++; cram[1] = cpunum++;
@@ -247,11 +221,8 @@ lamebus_start_cpus(struct lamebus_softc *lamebus)
* more specific checks. * more specific checks.
*/ */
int int lamebus_probe(struct lamebus_softc *sc, uint32_t vendorid,
lamebus_probe(struct lamebus_softc *sc, uint32_t deviceid, uint32_t lowver, uint32_t *version_ret) {
uint32_t vendorid, uint32_t deviceid,
uint32_t lowver, uint32_t *version_ret)
{
int slot; int slot;
uint32_t val; uint32_t val;
@@ -306,9 +277,7 @@ lamebus_probe(struct lamebus_softc *sc,
* This prevents the probe routine from returning the same device over * This prevents the probe routine from returning the same device over
* and over again. * and over again.
*/ */
void void lamebus_mark(struct lamebus_softc *sc, int slot) {
lamebus_mark(struct lamebus_softc *sc, int slot)
{
uint32_t mask = ((uint32_t)1) << slot; uint32_t mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
@@ -326,9 +295,7 @@ lamebus_mark(struct lamebus_softc *sc, int slot)
/* /*
* Mark that a slot is no longer in use. * Mark that a slot is no longer in use.
*/ */
void void lamebus_unmark(struct lamebus_softc *sc, int slot) {
lamebus_unmark(struct lamebus_softc *sc, int slot)
{
uint32_t mask = ((uint32_t)1) << slot; uint32_t mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
@@ -347,19 +314,15 @@ lamebus_unmark(struct lamebus_softc *sc, int slot)
* Register a function (and a device context pointer) to be called * Register a function (and a device context pointer) to be called
* when a particular slot signals an interrupt. * when a particular slot signals an interrupt.
*/ */
void void lamebus_attach_interrupt(struct lamebus_softc *sc, int slot, void *devdata,
lamebus_attach_interrupt(struct lamebus_softc *sc, int slot, void (*irqfunc)(void *devdata)) {
void *devdata,
void (*irqfunc)(void *devdata))
{
uint32_t mask = ((uint32_t)1) << slot; uint32_t mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
spinlock_acquire(&sc->ls_lock); spinlock_acquire(&sc->ls_lock);
if ((sc->ls_slotsinuse & mask) == 0) { if ((sc->ls_slotsinuse & mask) == 0) {
panic("lamebus_attach_interrupt: slot %d not marked in use\n", panic("lamebus_attach_interrupt: slot %d not marked in use\n", slot);
slot);
} }
KASSERT(sc->ls_devdata[slot] == NULL); KASSERT(sc->ls_devdata[slot] == NULL);
@@ -375,17 +338,14 @@ lamebus_attach_interrupt(struct lamebus_softc *sc, int slot,
* Unregister a function that was being called when a particular slot * Unregister a function that was being called when a particular slot
* signaled an interrupt. * signaled an interrupt.
*/ */
void void lamebus_detach_interrupt(struct lamebus_softc *sc, int slot) {
lamebus_detach_interrupt(struct lamebus_softc *sc, int slot)
{
uint32_t mask = ((uint32_t)1) << slot; uint32_t mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
spinlock_acquire(&sc->ls_lock); spinlock_acquire(&sc->ls_lock);
if ((sc->ls_slotsinuse & mask) == 0) { if ((sc->ls_slotsinuse & mask) == 0) {
panic("lamebus_detach_interrupt: slot %d not marked in use\n", panic("lamebus_detach_interrupt: slot %d not marked in use\n", slot);
slot);
} }
KASSERT(sc->ls_irqfuncs[slot] != NULL); KASSERT(sc->ls_irqfuncs[slot] != NULL);
@@ -399,9 +359,7 @@ lamebus_detach_interrupt(struct lamebus_softc *sc, int slot)
/* /*
* Mask/unmask an interrupt using the global IRQE register. * Mask/unmask an interrupt using the global IRQE register.
*/ */
void void lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot) {
lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot)
{
uint32_t bits, mask = ((uint32_t)1) << slot; uint32_t bits, mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
@@ -412,9 +370,7 @@ lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot)
spinlock_release(&lamebus->ls_lock); spinlock_release(&lamebus->ls_lock);
} }
void void lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot) {
lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot)
{
uint32_t bits, mask = ((uint32_t)1) << slot; uint32_t bits, mask = ((uint32_t)1) << slot;
KASSERT(slot >= 0 && slot < LB_NSLOTS); KASSERT(slot >= 0 && slot < LB_NSLOTS);
@@ -425,13 +381,10 @@ lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot)
spinlock_release(&lamebus->ls_lock); spinlock_release(&lamebus->ls_lock);
} }
/* /*
* LAMEbus interrupt handling function. (Machine-independent!) * LAMEbus interrupt handling function. (Machine-independent!)
*/ */
void void lamebus_interrupt(struct lamebus_softc *lamebus) {
lamebus_interrupt(struct lamebus_softc *lamebus)
{
/* /*
* Note that despite the fact that "spl" stands for "set * Note that despite the fact that "spl" stands for "set
* priority level", we don't actually support interrupt * priority level", we don't actually support interrupt
@@ -469,8 +422,7 @@ lamebus_interrupt(struct lamebus_softc *lamebus)
/* /*
* Huh? None of them? Must be a glitch. * Huh? None of them? Must be a glitch.
*/ */
kprintf("lamebus: stray interrupt on cpu %u\n", kprintf("lamebus: stray interrupt on cpu %u\n", curcpu->c_number);
curcpu->c_number);
duds++; duds++;
duds_this_time++; duds_this_time++;
@@ -543,7 +495,6 @@ lamebus_interrupt(struct lamebus_softc *lamebus)
irqs = read_ctl_register(lamebus, CTLREG_IRQS); irqs = read_ctl_register(lamebus, CTLREG_IRQS);
} }
/* /*
* If we get interrupts for a slot with no driver or no * If we get interrupts for a slot with no driver or no
* interrupt handler, it's fairly serious. Because LAMEbus * interrupt handler, it's fairly serious. Because LAMEbus
@@ -578,9 +529,7 @@ lamebus_interrupt(struct lamebus_softc *lamebus)
/* /*
* Have the bus controller power the system off. * Have the bus controller power the system off.
*/ */
void void lamebus_poweroff(struct lamebus_softc *lamebus) {
lamebus_poweroff(struct lamebus_softc *lamebus)
{
/* /*
* Write 0 to the power register to shut the system off. * Write 0 to the power register to shut the system off.
*/ */
@@ -595,9 +544,7 @@ lamebus_poweroff(struct lamebus_softc *lamebus)
/* /*
* Ask the bus controller how much memory we have. * Ask the bus controller how much memory we have.
*/ */
uint32_t uint32_t lamebus_ramsize(void) {
lamebus_ramsize(void)
{
/* /*
* Note that this has to work before bus initialization. * Note that this has to work before bus initialization.
* On machines where lamebus_read_register doesn't work * On machines where lamebus_read_register doesn't work
@@ -611,33 +558,25 @@ lamebus_ramsize(void)
/* /*
* Turn on or off the interprocessor interrupt line for a given CPU. * Turn on or off the interprocessor interrupt line for a given CPU.
*/ */
void void lamebus_assert_ipi(struct lamebus_softc *lamebus, struct cpu *target) {
lamebus_assert_ipi(struct lamebus_softc *lamebus, struct cpu *target)
{
if (lamebus->ls_uniprocessor) { if (lamebus->ls_uniprocessor) {
return; return;
} }
write_ctlcpu_register(lamebus, target->c_hardware_number, write_ctlcpu_register(lamebus, target->c_hardware_number, CTLCPU_CIPI, 1);
CTLCPU_CIPI, 1);
} }
void void lamebus_clear_ipi(struct lamebus_softc *lamebus, struct cpu *target) {
lamebus_clear_ipi(struct lamebus_softc *lamebus, struct cpu *target)
{
if (lamebus->ls_uniprocessor) { if (lamebus->ls_uniprocessor) {
return; return;
} }
write_ctlcpu_register(lamebus, target->c_hardware_number, write_ctlcpu_register(lamebus, target->c_hardware_number, CTLCPU_CIPI, 0);
CTLCPU_CIPI, 0);
} }
/* /*
* Initial setup. * Initial setup.
* Should be called from mainbus_bootstrap(). * Should be called from mainbus_bootstrap().
*/ */
struct lamebus_softc * struct lamebus_softc *lamebus_init(void) {
lamebus_init(void)
{
struct lamebus_softc *lamebus; struct lamebus_softc *lamebus;
int i; int i;

View File

@@ -39,7 +39,6 @@
* Machine-independent definitions. * Machine-independent definitions.
*/ */
/* Vendors */ /* Vendors */
#define LB_VENDOR_CS161 1 #define LB_VENDOR_CS161 1
@@ -113,8 +112,7 @@ void lamebus_start_cpus(struct lamebus_softc *lamebus);
* *
* Returns a slot number (0-31) or -1 if no such device is found. * Returns a slot number (0-31) or -1 if no such device is found.
*/ */
int lamebus_probe(struct lamebus_softc *, int lamebus_probe(struct lamebus_softc *, uint32_t vendorid, uint32_t deviceid,
uint32_t vendorid, uint32_t deviceid,
uint32_t lowver, uint32_t *version_ret); uint32_t lowver, uint32_t *version_ret);
/* /*
@@ -128,8 +126,7 @@ void lamebus_unmark(struct lamebus_softc *, int slot);
/* /*
* Attach to an interrupt. * Attach to an interrupt.
*/ */
void lamebus_attach_interrupt(struct lamebus_softc *, int slot, void lamebus_attach_interrupt(struct lamebus_softc *, int slot, void *devdata,
void *devdata,
void (*irqfunc)(void *devdata)); void (*irqfunc)(void *devdata));
/* /*
* Detach from interrupt. * Detach from interrupt.
@@ -169,14 +166,12 @@ void lamebus_clear_ipi(struct lamebus_softc *, struct cpu *targetcpu);
*/ */
uint32_t lamebus_read_register(struct lamebus_softc *, int slot, uint32_t lamebus_read_register(struct lamebus_softc *, int slot,
uint32_t offset); uint32_t offset);
void lamebus_write_register(struct lamebus_softc *, int slot, void lamebus_write_register(struct lamebus_softc *, int slot, uint32_t offset,
uint32_t offset, uint32_t val); uint32_t val);
/* /*
* Map a buffer that starts at offset OFFSET within slot SLOT. * Map a buffer that starts at offset OFFSET within slot SLOT.
*/ */
void *lamebus_map_area(struct lamebus_softc *, int slot, void *lamebus_map_area(struct lamebus_softc *, int slot, uint32_t offset);
uint32_t offset);
#endif /* _LAMEBUS_H_ */ #endif /* _LAMEBUS_H_ */

View File

@@ -63,33 +63,28 @@
/* /*
* Shortcut for reading a register. * Shortcut for reading a register.
*/ */
static static inline uint32_t lhd_rdreg(struct lhd_softc *lh, uint32_t reg) {
inline
uint32_t lhd_rdreg(struct lhd_softc *lh, uint32_t reg)
{
return bus_read_register(lh->lh_busdata, lh->lh_buspos, reg); return bus_read_register(lh->lh_busdata, lh->lh_buspos, reg);
} }
/* /*
* Shortcut for writing a register. * Shortcut for writing a register.
*/ */
static static inline void lhd_wreg(struct lhd_softc *lh, uint32_t reg, uint32_t val) {
inline
void lhd_wreg(struct lhd_softc *lh, uint32_t reg, uint32_t val)
{
bus_write_register(lh->lh_busdata, lh->lh_buspos, reg, val); bus_write_register(lh->lh_busdata, lh->lh_buspos, reg, val);
} }
/* /*
* Convert a result code from the hardware to an errno value. * Convert a result code from the hardware to an errno value.
*/ */
static static int lhd_code_to_errno(struct lhd_softc *lh, int code) {
int lhd_code_to_errno(struct lhd_softc *lh, int code)
{
switch (code & LHD_STATEMASK) { switch (code & LHD_STATEMASK) {
case LHD_OK: return 0; case LHD_OK:
case LHD_INVSECT: return EINVAL; return 0;
case LHD_MEDIA: return EIO; case LHD_INVSECT:
return EINVAL;
case LHD_MEDIA:
return EIO;
} }
kprintf("lhd%d: Unknown result code %d\n", lh->lh_unit, code); kprintf("lhd%d: Unknown result code %d\n", lh->lh_unit, code);
return EAGAIN; return EAGAIN;
@@ -99,10 +94,7 @@ int lhd_code_to_errno(struct lhd_softc *lh, int code)
* Record that an I/O has completed: save the result and poke the * Record that an I/O has completed: save the result and poke the
* completion semaphore. * completion semaphore.
*/ */
static static void lhd_iodone(struct lhd_softc *lh, int err) {
void
lhd_iodone(struct lhd_softc *lh, int err)
{
lh->lh_result = err; lh->lh_result = err;
V(lh->lh_done); V(lh->lh_done);
} }
@@ -112,9 +104,7 @@ lhd_iodone(struct lhd_softc *lh, int err)
* Read the status register; if an operation finished, clear the status * Read the status register; if an operation finished, clear the status
* register and report completion. * register and report completion.
*/ */
void void lhd_irq(void *vlh) {
lhd_irq(void *vlh)
{
struct lhd_softc *lh = vlh; struct lhd_softc *lh = vlh;
uint32_t val; uint32_t val;
@@ -136,10 +126,7 @@ lhd_irq(void *vlh)
/* /*
* Function called when we are open()'d. * Function called when we are open()'d.
*/ */
static static int lhd_eachopen(struct device *d, int openflags) {
int
lhd_eachopen(struct device *d, int openflags)
{
/* /*
* Don't need to do anything. * Don't need to do anything.
*/ */
@@ -152,10 +139,7 @@ lhd_eachopen(struct device *d, int openflags)
/* /*
* Function for handling ioctls. * Function for handling ioctls.
*/ */
static static int lhd_ioctl(struct device *d, int op, userptr_t data) {
int
lhd_ioctl(struct device *d, int op, userptr_t data)
{
/* /*
* We don't support any ioctls. * We don't support any ioctls.
*/ */
@@ -182,10 +166,7 @@ lhd_reset(struct lhd_softc *lh)
/* /*
* I/O function (for both reads and writes) * I/O function (for both reads and writes)
*/ */
static static int lhd_io(struct device *d, struct uio *uio) {
int
lhd_io(struct device *d, struct uio *uio)
{
struct lhd_softc *lh = d->d_data; struct lhd_softc *lh = d->d_data;
uint32_t sector = uio->uio_offset / LHD_SECTSIZE; uint32_t sector = uio->uio_offset / LHD_SECTSIZE;
@@ -273,9 +254,7 @@ static const struct device_ops lhd_devops = {
/* /*
* Setup routine called by autoconf.c when an lhd is found. * Setup routine called by autoconf.c when an lhd is found.
*/ */
int int config_lhd(struct lhd_softc *lh, int lhdno) {
config_lhd(struct lhd_softc *lh, int lhdno)
{
char name[32]; char name[32];
/* Figure out what our name is. */ /* Figure out what our name is. */
@@ -298,8 +277,8 @@ config_lhd(struct lhd_softc *lh, int lhdno)
/* Set up the VFS device structure. */ /* Set up the VFS device structure. */
lh->lh_dev.d_ops = &lhd_devops; lh->lh_dev.d_ops = &lhd_devops;
lh->lh_dev.d_blocks = bus_read_register(lh->lh_busdata, lh->lh_buspos, lh->lh_dev.d_blocks =
LHD_REG_NSECT); bus_read_register(lh->lh_busdata, lh->lh_buspos, LHD_REG_NSECT);
lh->lh_dev.d_blocksize = LHD_SECTSIZE; lh->lh_dev.d_blocksize = LHD_SECTSIZE;
lh->lh_dev.d_data = lh; lh->lh_dev.d_data = lh;

View File

@@ -39,12 +39,10 @@
/* Lowest revision we support */ /* Lowest revision we support */
#define LOW_VERSION 2 #define LOW_VERSION 2
struct lhd_softc * struct lhd_softc *attach_lhd_to_lamebus(int lhdno, struct lamebus_softc *sc) {
attach_lhd_to_lamebus(int lhdno, struct lamebus_softc *sc)
{
struct lhd_softc *lh; struct lhd_softc *lh;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_DISK, int slot =
LOW_VERSION, NULL); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_DISK, LOW_VERSION, NULL);
if (slot < 0) { if (slot < 0) {
/* None found */ /* None found */
return NULL; return NULL;

View File

@@ -33,14 +33,10 @@
/*#include <lamebus/lnet.h>*/ /* not yet */ /*#include <lamebus/lnet.h>*/ /* not yet */
#include "autoconf.h" #include "autoconf.h"
int int config_lnet(struct lnet_softc *sc, int lnetno) {
config_lnet(struct lnet_softc *sc, int lnetno)
{
(void)sc; (void)sc;
kprintf("lnet%d: No network support in system\n", lnetno); kprintf("lnet%d: No network support in system\n", lnetno);
return ENODEV; return ENODEV;
} }

View File

@@ -37,11 +37,10 @@
/* Highest revision we support */ /* Highest revision we support */
#define HIGH_VERSION 1 #define HIGH_VERSION 1
struct lnet_softc * struct lnet_softc *attach_lnet_to_lamebus(int lnetno,
attach_lnet_to_lamebus(int lnetno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{ int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_NET, LOW_VERSION,
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_NET, HIGH_VERSION);
LOW_VERSION, HIGH_VERSION);
if (slot < 0) { if (slot < 0) {
return NULL; return NULL;
} }

View File

@@ -43,38 +43,29 @@
/* Constants */ /* Constants */
#define LR_RANDMAX 0xffffffff #define LR_RANDMAX 0xffffffff
int int config_lrandom(struct lrandom_softc *lr, int lrandomno) {
config_lrandom(struct lrandom_softc *lr, int lrandomno)
{
(void)lrandomno; (void)lrandomno;
(void)lr; (void)lr;
return 0; return 0;
} }
uint32_t uint32_t lrandom_random(void *devdata) {
lrandom_random(void *devdata)
{
struct lrandom_softc *lr = devdata; struct lrandom_softc *lr = devdata;
return bus_read_register(lr->lr_bus, lr->lr_buspos, LR_REG_RAND); return bus_read_register(lr->lr_bus, lr->lr_buspos, LR_REG_RAND);
} }
uint32_t uint32_t lrandom_randmax(void *devdata) {
lrandom_randmax(void *devdata)
{
(void)devdata; (void)devdata;
return LR_RANDMAX; return LR_RANDMAX;
} }
int int lrandom_read(void *devdata, struct uio *uio) {
lrandom_read(void *devdata, struct uio *uio)
{
struct lrandom_softc *lr = devdata; struct lrandom_softc *lr = devdata;
uint32_t val; uint32_t val;
int result; int result;
while (uio->uio_resid > 0) { while (uio->uio_resid > 0) {
val = bus_read_register(lr->lr_bus, lr->lr_buspos, val = bus_read_register(lr->lr_bus, lr->lr_buspos, LR_REG_RAND);
LR_REG_RAND);
result = uiomove(&val, sizeof(val), uio); result = uiomove(&val, sizeof(val), uio);
if (result) { if (result) {
return result; return result;

View File

@@ -36,12 +36,11 @@
/* Lowest revision we support */ /* Lowest revision we support */
#define LOW_VERSION 1 #define LOW_VERSION 1
struct lrandom_softc * struct lrandom_softc *attach_lrandom_to_lamebus(int lrandomno,
attach_lrandom_to_lamebus(int lrandomno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{
struct lrandom_softc *lr; struct lrandom_softc *lr;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_RANDOM, int slot =
LOW_VERSION, NULL); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_RANDOM, LOW_VERSION, NULL);
if (slot < 0) { if (slot < 0) {
return NULL; return NULL;
} }

View File

@@ -54,21 +54,13 @@
#define LSCR_SCREEN 32768 #define LSCR_SCREEN 32768
/* Convert a 32-bit X/Y pair to X and Y coordinates. */ /* Convert a 32-bit X/Y pair to X and Y coordinates. */
static static inline void splitxy(uint32_t xy, unsigned *x, unsigned *y) {
inline
void
splitxy(uint32_t xy, unsigned *x, unsigned *y)
{
*x = xy >> 16; *x = xy >> 16;
*y = xy & 0xffff; *y = xy & 0xffff;
} }
/* Convert X and Y coordinates to a single 32-bit value. */ /* Convert X and Y coordinates to a single 32-bit value. */
static static inline uint32_t mergexy(unsigned x, unsigned y) {
inline
uint32_t
mergexy(unsigned x, unsigned y)
{
uint32_t val = x; uint32_t val = x;
return (val << 16) | y; return (val << 16) | y;
@@ -79,9 +71,7 @@ mergexy(unsigned x, unsigned y)
/* /*
* Interrupt handler. * Interrupt handler.
*/ */
void void lscreen_irq(void *vsc) {
lscreen_irq(void *vsc)
{
struct lscreen_softc *sc = vsc; struct lscreen_softc *sc = vsc;
uint32_t ch, x; uint32_t ch, x;
@@ -89,17 +79,15 @@ lscreen_irq(void *vsc)
x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ); x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ);
if (x & LSCR_IRQ_ACTIVE) { if (x & LSCR_IRQ_ACTIVE) {
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_CHAR);
LSCR_REG_CHAR); bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ,
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_IRQ_ENABLE);
LSCR_REG_RIRQ, LSCR_IRQ_ENABLE);
spinlock_release(&sc->ls_lock); spinlock_release(&sc->ls_lock);
if (sc->ls_input) { if (sc->ls_input) {
sc->ls_input(sc->ls_devdata, ch); sc->ls_input(sc->ls_devdata, ch);
} }
} } else {
else {
spinlock_release(&sc->ls_lock); spinlock_release(&sc->ls_lock);
} }
} }
@@ -109,10 +97,7 @@ lscreen_irq(void *vsc)
/* /*
* Handle a newline on the screen. * Handle a newline on the screen.
*/ */
static static void lscreen_newline(struct lscreen_softc *sc) {
void
lscreen_newline(struct lscreen_softc *sc)
{
if (sc->ls_cy >= sc->ls_height - 1) { if (sc->ls_cy >= sc->ls_height - 1) {
/* /*
* Scroll * Scroll
@@ -120,10 +105,8 @@ lscreen_newline(struct lscreen_softc *sc)
memmove(sc->ls_screen, sc->ls_screen + sc->ls_width, memmove(sc->ls_screen, sc->ls_screen + sc->ls_width,
sc->ls_width * (sc->ls_height - 1)); sc->ls_width * (sc->ls_height - 1));
bzero(sc->ls_screen + sc->ls_width * (sc->ls_height-1), bzero(sc->ls_screen + sc->ls_width * (sc->ls_height - 1), sc->ls_width);
sc->ls_width); } else {
}
else {
sc->ls_cy++; sc->ls_cy++;
} }
sc->ls_cx = 0; sc->ls_cx = 0;
@@ -132,10 +115,7 @@ lscreen_newline(struct lscreen_softc *sc)
/* /*
* Handle a printable character being written to the screen. * Handle a printable character being written to the screen.
*/ */
static static void lscreen_char(struct lscreen_softc *sc, int ch) {
void
lscreen_char(struct lscreen_softc *sc, int ch)
{
if (sc->ls_cx >= sc->ls_width) { if (sc->ls_cx >= sc->ls_width) {
lscreen_newline(sc); lscreen_newline(sc);
} }
@@ -148,17 +128,19 @@ lscreen_char(struct lscreen_softc *sc, int ch)
* Send a character to the screen. * Send a character to the screen.
* This should probably know about backspace and tab. * This should probably know about backspace and tab.
*/ */
void void lscreen_write(void *vsc, int ch) {
lscreen_write(void *vsc, int ch)
{
struct lscreen_softc *sc = vsc; struct lscreen_softc *sc = vsc;
int ccx, ccy; int ccx, ccy;
spinlock_acquire(&sc->ls_lock); spinlock_acquire(&sc->ls_lock);
switch (ch) { switch (ch) {
case '\n': lscreen_newline(sc); break; case '\n':
default: lscreen_char(sc, ch); break; lscreen_newline(sc);
break;
default:
lscreen_char(sc, ch);
break;
} }
/* /*
@@ -173,8 +155,8 @@ lscreen_write(void *vsc, int ch)
} }
/* Set the cursor position */ /* Set the cursor position */
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_POSN,
LSCR_REG_POSN, mergexy(ccx, ccy)); mergexy(ccx, ccy));
spinlock_release(&sc->ls_lock); spinlock_release(&sc->ls_lock);
} }
@@ -184,9 +166,7 @@ lscreen_write(void *vsc, int ch)
/* /*
* Setup routine called by autoconf.c when an lscreen is found. * Setup routine called by autoconf.c when an lscreen is found.
*/ */
int int config_lscreen(struct lscreen_softc *sc, int lscreenno) {
config_lscreen(struct lscreen_softc *sc, int lscreenno)
{
uint32_t val; uint32_t val;
(void)lscreenno; (void)lscreenno;
@@ -197,29 +177,25 @@ config_lscreen(struct lscreen_softc *sc, int lscreenno)
* Enable interrupting. * Enable interrupting.
*/ */
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ,
LSCR_REG_RIRQ, LSCR_IRQ_ENABLE); LSCR_IRQ_ENABLE);
/* /*
* Get screen size. * Get screen size.
*/ */
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_SIZE);
LSCR_REG_SIZE);
splitxy(val, &sc->ls_width, &sc->ls_height); splitxy(val, &sc->ls_width, &sc->ls_height);
/* /*
* Get cursor position. * Get cursor position.
*/ */
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_POSN);
LSCR_REG_POSN);
splitxy(val, &sc->ls_cx, &sc->ls_cy); splitxy(val, &sc->ls_cx, &sc->ls_cy);
/* /*
* Get a pointer to the memory-mapped screen area. * Get a pointer to the memory-mapped screen area.
*/ */
sc->ls_screen = bus_map_area(sc->ls_busdata, sc->ls_buspos, sc->ls_screen = bus_map_area(sc->ls_busdata, sc->ls_buspos, LSCR_SCREEN);
LSCR_SCREEN);
return 0; return 0;
} }

View File

@@ -41,12 +41,11 @@
/* Highest revision we support */ /* Highest revision we support */
#define HIGH_VERSION 1 #define HIGH_VERSION 1
struct lscreen_softc * struct lscreen_softc *attach_lscreen_to_lamebus(int lscreenno,
attach_lscreen_to_lamebus(int lscreenno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{
struct lscreen_softc *ls; struct lscreen_softc *ls;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SCREEN, int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SCREEN, LOW_VERSION,
LOW_VERSION, HIGH_VERSION); HIGH_VERSION);
if (slot < 0) { if (slot < 0) {
/* Not found */ /* Not found */
return NULL; return NULL;

View File

@@ -44,9 +44,7 @@
#define LSER_IRQ_ACTIVE 2 #define LSER_IRQ_ACTIVE 2
#define LSER_IRQ_FORCE 4 #define LSER_IRQ_FORCE 4
void void lser_irq(void *vsc) {
lser_irq(void *vsc)
{
struct lser_softc *sc = vsc; struct lser_softc *sc = vsc;
uint32_t x; uint32_t x;
bool clear_to_write = false; bool clear_to_write = false;
@@ -60,18 +58,15 @@ lser_irq(void *vsc)
x = LSER_IRQ_ENABLE; x = LSER_IRQ_ENABLE;
sc->ls_wbusy = 0; sc->ls_wbusy = 0;
clear_to_write = true; clear_to_write = true;
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ, x);
LSER_REG_WIRQ, x);
} }
x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ); x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ);
if (x & LSER_IRQ_ACTIVE) { if (x & LSER_IRQ_ACTIVE) {
x = LSER_IRQ_ENABLE; x = LSER_IRQ_ENABLE;
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_CHAR);
LSER_REG_CHAR);
got_a_read = true; got_a_read = true;
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ, x);
LSER_REG_RIRQ, x);
} }
spinlock_release(&sc->ls_lock); spinlock_release(&sc->ls_lock);
@@ -84,9 +79,7 @@ lser_irq(void *vsc)
} }
} }
void void lser_write(void *vls, int ch) {
lser_write(void *vls, int ch)
{
struct lser_softc *ls = vls; struct lser_softc *ls = vls;
spinlock_acquire(&ls->ls_lock); spinlock_acquire(&ls->ls_lock);
@@ -112,24 +105,17 @@ lser_write(void *vls, int ch)
spinlock_release(&ls->ls_lock); spinlock_release(&ls->ls_lock);
} }
static static void lser_poll_until_write(struct lser_softc *sc) {
void
lser_poll_until_write(struct lser_softc *sc)
{
uint32_t val; uint32_t val;
KASSERT(spinlock_do_i_hold(&sc->ls_lock)); KASSERT(spinlock_do_i_hold(&sc->ls_lock));
do { do {
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ);
LSER_REG_WIRQ); } while ((val & LSER_IRQ_ACTIVE) == 0);
}
while ((val & LSER_IRQ_ACTIVE) == 0);
} }
void void lser_writepolled(void *vsc, int ch) {
lser_writepolled(void *vsc, int ch)
{
struct lser_softc *sc = vsc; struct lser_softc *sc = vsc;
bool irqpending; bool irqpending;
@@ -139,15 +125,12 @@ lser_writepolled(void *vsc, int ch)
irqpending = true; irqpending = true;
lser_poll_until_write(sc); lser_poll_until_write(sc);
/* Clear the ready condition, but leave the IRQ asserted */ /* Clear the ready condition, but leave the IRQ asserted */
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
LSER_REG_WIRQ,
LSER_IRQ_FORCE | LSER_IRQ_ENABLE); LSER_IRQ_FORCE | LSER_IRQ_ENABLE);
} } else {
else {
irqpending = false; irqpending = false;
/* Clear the interrupt enable bit */ /* Clear the interrupt enable bit */
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ, 0);
LSER_REG_WIRQ, 0);
} }
/* Send the character. */ /* Send the character. */
@@ -164,16 +147,14 @@ lser_writepolled(void *vsc, int ch)
* interrupt handler and they'll be cleared. * interrupt handler and they'll be cleared.
*/ */
if (!irqpending) { if (!irqpending) {
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
LSER_REG_WIRQ, LSER_IRQ_ENABLE); LSER_IRQ_ENABLE);
} }
spinlock_release(&sc->ls_lock); spinlock_release(&sc->ls_lock);
} }
int int config_lser(struct lser_softc *sc, int lserno) {
config_lser(struct lser_softc *sc, int lserno)
{
(void)lserno; (void)lserno;
/* /*
@@ -183,10 +164,10 @@ config_lser(struct lser_softc *sc, int lserno)
spinlock_init(&sc->ls_lock); spinlock_init(&sc->ls_lock);
sc->ls_wbusy = false; sc->ls_wbusy = false;
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ,
LSER_REG_RIRQ, LSER_IRQ_ENABLE); LSER_IRQ_ENABLE);
bus_write_register(sc->ls_busdata, sc->ls_buspos, bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
LSER_REG_WIRQ, LSER_IRQ_ENABLE); LSER_IRQ_ENABLE);
return 0; return 0;
} }

View File

@@ -36,12 +36,11 @@
/* Lowest revision we support */ /* Lowest revision we support */
#define LOW_VERSION 1 #define LOW_VERSION 1
struct lser_softc * struct lser_softc *attach_lser_to_lamebus(int lserno,
attach_lser_to_lamebus(int lserno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{
struct lser_softc *ls; struct lser_softc *ls;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SERIAL, int slot =
LOW_VERSION, NULL); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SERIAL, LOW_VERSION, NULL);
if (slot < 0) { if (slot < 0) {
return NULL; return NULL;
} }

View File

@@ -54,9 +54,7 @@ static bool havetimerclock;
/* /*
* Setup routine called by autoconf stuff when an ltimer is found. * Setup routine called by autoconf stuff when an ltimer is found.
*/ */
int int config_ltimer(struct ltimer_softc *lt, int ltimerno) {
config_ltimer(struct ltimer_softc *lt, int ltimerno)
{
/* /*
* Running on System/161 2.x, we always use the processor * Running on System/161 2.x, we always use the processor
* on-chip timer for hardclock and we don't need ltimer as * on-chip timer for hardclock and we don't need ltimer as
@@ -93,8 +91,7 @@ config_ltimer(struct ltimer_softc *lt, int ltimerno)
/* Wire it to go off once every second. */ /* Wire it to go off once every second. */
bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_ROE, 1); bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_ROE, 1);
bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_COUNT, bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_COUNT, LT_GRANULARITY);
LT_GRANULARITY);
} }
return 0; return 0;
@@ -103,9 +100,7 @@ config_ltimer(struct ltimer_softc *lt, int ltimerno)
/* /*
* Interrupt handler. * Interrupt handler.
*/ */
void void ltimer_irq(void *vlt) {
ltimer_irq(void *vlt)
{
struct ltimer_softc *lt = vlt; struct ltimer_softc *lt = vlt;
uint32_t val; uint32_t val;
@@ -132,9 +127,7 @@ ltimer_irq(void *vlt)
* doesn't matter what value you write. This function is called if * doesn't matter what value you write. This function is called if
* the beep device is attached to this timer. * the beep device is attached to this timer.
*/ */
void void ltimer_beep(void *vlt) {
ltimer_beep(void *vlt)
{
struct ltimer_softc *lt = vlt; struct ltimer_softc *lt = vlt;
bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_SPKR, 440); bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_SPKR, 440);
@@ -145,9 +138,7 @@ ltimer_beep(void *vlt)
* This function gets called if the rtclock device is attached * This function gets called if the rtclock device is attached
* to this timer. * to this timer.
*/ */
void void ltimer_gettime(void *vlt, struct timespec *ts) {
ltimer_gettime(void *vlt, struct timespec *ts)
{
struct ltimer_softc *lt = vlt; struct ltimer_softc *lt = vlt;
uint32_t secs1, secs2; uint32_t secs1, secs2;
int spl; int spl;
@@ -169,19 +160,15 @@ ltimer_gettime(void *vlt, struct timespec *ts)
spl = splhigh(); spl = splhigh();
secs1 = bus_read_register(lt->lt_bus, lt->lt_buspos, secs1 = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_SEC);
LT_REG_SEC); ts->tv_nsec = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_NSEC);
ts->tv_nsec = bus_read_register(lt->lt_bus, lt->lt_buspos, secs2 = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_SEC);
LT_REG_NSEC);
secs2 = bus_read_register(lt->lt_bus, lt->lt_buspos,
LT_REG_SEC);
splx(spl); splx(spl);
if (ts->tv_nsec < 5000000) { if (ts->tv_nsec < 5000000) {
ts->tv_sec = secs2; ts->tv_sec = secs2;
} } else {
else {
ts->tv_sec = secs1; ts->tv_sec = secs1;
} }
} }

View File

@@ -39,12 +39,11 @@
/* Lowest revision we support */ /* Lowest revision we support */
#define LOW_VERSION 1 #define LOW_VERSION 1
struct ltimer_softc * struct ltimer_softc *attach_ltimer_to_lamebus(int ltimerno,
attach_ltimer_to_lamebus(int ltimerno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{
struct ltimer_softc *lt; struct ltimer_softc *lt;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TIMER, int slot =
LOW_VERSION, NULL); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TIMER, LOW_VERSION, NULL);
if (slot < 0) { if (slot < 0) {
/* No ltimer (or no additional ltimer) found */ /* No ltimer (or no additional ltimer) found */
return NULL; return NULL;

View File

@@ -44,72 +44,56 @@
static struct ltrace_softc *the_trace; static struct ltrace_softc *the_trace;
void void ltrace_on(uint32_t code) {
ltrace_on(uint32_t code)
{
if (the_trace != NULL) { if (the_trace != NULL) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_TRON, code); LTRACE_REG_TRON, code);
} }
} }
void void ltrace_off(uint32_t code) {
ltrace_off(uint32_t code)
{
if (the_trace != NULL) { if (the_trace != NULL) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_TROFF, code); LTRACE_REG_TROFF, code);
} }
} }
void void ltrace_debug(uint32_t code) {
ltrace_debug(uint32_t code)
{
if (the_trace != NULL) { if (the_trace != NULL) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_DEBUG, code); LTRACE_REG_DEBUG, code);
} }
} }
void void ltrace_dump(uint32_t code) {
ltrace_dump(uint32_t code)
{
if (the_trace != NULL) { if (the_trace != NULL) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_DUMP, code); LTRACE_REG_DUMP, code);
} }
} }
void void ltrace_stop(uint32_t code) {
ltrace_stop(uint32_t code)
{
if (the_trace != NULL && the_trace->lt_canstop) { if (the_trace != NULL && the_trace->lt_canstop) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_STOP, code); LTRACE_REG_STOP, code);
} }
} }
void void ltrace_setprof(uint32_t onoff) {
ltrace_setprof(uint32_t onoff)
{
if (the_trace != NULL && the_trace->lt_canprof) { if (the_trace != NULL && the_trace->lt_canprof) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_PROFEN, onoff); LTRACE_REG_PROFEN, onoff);
} }
} }
void void ltrace_eraseprof(void) {
ltrace_eraseprof(void)
{
if (the_trace != NULL && the_trace->lt_canprof) { if (the_trace != NULL && the_trace->lt_canprof) {
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos, bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
LTRACE_REG_PROFCL, 1); LTRACE_REG_PROFCL, 1);
} }
} }
int int config_ltrace(struct ltrace_softc *sc, int ltraceno) {
config_ltrace(struct ltrace_softc *sc, int ltraceno)
{
(void)ltraceno; (void)ltraceno;
the_trace = sc; the_trace = sc;
return 0; return 0;

View File

@@ -40,13 +40,12 @@
/* Revision that supports ltrace_prof() */ /* Revision that supports ltrace_prof() */
#define PROF_VERSION 3 #define PROF_VERSION 3
struct ltrace_softc * struct ltrace_softc *attach_ltrace_to_lamebus(int ltraceno,
attach_ltrace_to_lamebus(int ltraceno, struct lamebus_softc *sc) struct lamebus_softc *sc) {
{
struct ltrace_softc *lt; struct ltrace_softc *lt;
uint32_t drl; uint32_t drl;
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TRACE, int slot =
LOW_VERSION, &drl); lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TRACE, LOW_VERSION, &drl);
if (slot < 0) { if (slot < 0) {
return NULL; return NULL;
} }

View File

@@ -38,9 +38,8 @@
#include <lamebus/lrandom.h> #include <lamebus/lrandom.h>
#include "autoconf.h" #include "autoconf.h"
struct random_softc * struct random_softc *attach_random_to_lrandom(int randomno,
attach_random_to_lrandom(int randomno, struct lrandom_softc *ls) struct lrandom_softc *ls) {
{
struct random_softc *rs = kmalloc(sizeof(struct random_softc)); struct random_softc *rs = kmalloc(sizeof(struct random_softc));
if (rs == NULL) { if (rs == NULL) {
return NULL; return NULL;

View File

@@ -44,9 +44,8 @@
#include <lamebus/ltimer.h> #include <lamebus/ltimer.h>
#include "autoconf.h" #include "autoconf.h"
struct rtclock_softc * struct rtclock_softc *attach_rtclock_to_ltimer(int rtclockno,
attach_rtclock_to_ltimer(int rtclockno, struct ltimer_softc *ls) struct ltimer_softc *ls) {
{
/* /*
* No need to probe; ltimer always has a clock. * No need to probe; ltimer always has a clock.
* Just allocate the rtclock, set our fields, and return it. * Just allocate the rtclock, set our fields, and return it.

View File

@@ -104,7 +104,6 @@ struct semfs {
DEFARRAY(semfs_sem, SEMFS_INLINE); DEFARRAY(semfs_sem, SEMFS_INLINE);
DEFARRAY(semfs_direntry, SEMFS_INLINE); DEFARRAY(semfs_direntry, SEMFS_INLINE);
/* /*
* Functions. * Functions.
*/ */
@@ -119,5 +118,4 @@ void semfs_direntry_destroy(struct semfs_direntry *);
/* in semfs_vnops.c */ /* in semfs_vnops.c */
int semfs_getvnode(struct semfs *, unsigned, struct vnode **ret); int semfs_getvnode(struct semfs *, unsigned, struct vnode **ret);
#endif /* SEMFS_H */ #endif /* SEMFS_H */

View File

@@ -42,10 +42,7 @@
/* /*
* Sync doesn't need to do anything. * Sync doesn't need to do anything.
*/ */
static static int semfs_sync(struct fs *fs) {
int
semfs_sync(struct fs *fs)
{
(void)fs; (void)fs;
return 0; return 0;
} }
@@ -53,10 +50,7 @@ semfs_sync(struct fs *fs)
/* /*
* We have only one volume name and it's hardwired. * We have only one volume name and it's hardwired.
*/ */
static static const char *semfs_getvolname(struct fs *fs) {
const char *
semfs_getvolname(struct fs *fs)
{
(void)fs; (void)fs;
return "sem"; return "sem";
} }
@@ -64,18 +58,14 @@ semfs_getvolname(struct fs *fs)
/* /*
* Get the root directory vnode. * Get the root directory vnode.
*/ */
static static int semfs_getroot(struct fs *fs, struct vnode **ret) {
int
semfs_getroot(struct fs *fs, struct vnode **ret)
{
struct semfs *semfs = fs->fs_data; struct semfs *semfs = fs->fs_data;
struct vnode *vn; struct vnode *vn;
int result; int result;
result = semfs_getvnode(semfs, SEMFS_ROOTDIR, &vn); result = semfs_getvnode(semfs, SEMFS_ROOTDIR, &vn);
if (result) { if (result) {
kprintf("semfs: couldn't load root vnode: %s\n", kprintf("semfs: couldn't load root vnode: %s\n", strerror(result));
strerror(result));
return result; return result;
} }
*ret = vn; *ret = vn;
@@ -85,14 +75,10 @@ semfs_getroot(struct fs *fs, struct vnode **ret)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// mount and unmount logic // mount and unmount logic
/* /*
* Destructor for struct semfs. * Destructor for struct semfs.
*/ */
static static void semfs_destroy(struct semfs *semfs) {
void
semfs_destroy(struct semfs *semfs)
{
struct semfs_sem *sem; struct semfs_sem *sem;
struct semfs_direntry *dent; struct semfs_direntry *dent;
unsigned i, num; unsigned i, num;
@@ -123,10 +109,7 @@ semfs_destroy(struct semfs *semfs)
* Unmount routine. XXX: Since semfs is attached at boot and can't be * Unmount routine. XXX: Since semfs is attached at boot and can't be
* remounted, maybe unmounting it shouldn't be allowed. * remounted, maybe unmounting it shouldn't be allowed.
*/ */
static static int semfs_unmount(struct fs *fs) {
int
semfs_unmount(struct fs *fs)
{
struct semfs *semfs = fs->fs_data; struct semfs *semfs = fs->fs_data;
lock_acquire(semfs->semfs_tablelock); lock_acquire(semfs->semfs_tablelock);
@@ -154,10 +137,7 @@ static const struct fs_ops semfs_fsops = {
/* /*
* Constructor for struct semfs. * Constructor for struct semfs.
*/ */
static static struct semfs *semfs_create(void) {
struct semfs *
semfs_create(void)
{
struct semfs *semfs; struct semfs *semfs;
semfs = kmalloc(sizeof(*semfs)); semfs = kmalloc(sizeof(*semfs));
@@ -209,9 +189,7 @@ semfs_create(void)
* Create the semfs. There is only one semfs and it's attached as * Create the semfs. There is only one semfs and it's attached as
* "sem:" during bootup. * "sem:" during bootup.
*/ */
void void semfs_bootstrap(void) {
semfs_bootstrap(void)
{
struct semfs *semfs; struct semfs *semfs;
int result; int result;

View File

@@ -40,9 +40,7 @@
/* /*
* Constructor for semfs_sem. * Constructor for semfs_sem.
*/ */
struct semfs_sem * struct semfs_sem *semfs_sem_create(const char *name) {
semfs_sem_create(const char *name)
{
struct semfs_sem *sem; struct semfs_sem *sem;
char lockname[32]; char lockname[32];
char cvname[32]; char cvname[32];
@@ -78,9 +76,7 @@ semfs_sem_create(const char *name)
/* /*
* Destructor for semfs_sem. * Destructor for semfs_sem.
*/ */
void void semfs_sem_destroy(struct semfs_sem *sem) {
semfs_sem_destroy(struct semfs_sem *sem)
{
cv_destroy(sem->sems_cv); cv_destroy(sem->sems_cv);
lock_destroy(sem->sems_lock); lock_destroy(sem->sems_lock);
kfree(sem); kfree(sem);
@@ -89,9 +85,8 @@ semfs_sem_destroy(struct semfs_sem *sem)
/* /*
* Helper to insert a semfs_sem into the semaphore table. * Helper to insert a semfs_sem into the semaphore table.
*/ */
int int semfs_sem_insert(struct semfs *semfs, struct semfs_sem *sem,
semfs_sem_insert(struct semfs *semfs, struct semfs_sem *sem, unsigned *ret) unsigned *ret) {
{
unsigned i, num; unsigned i, num;
KASSERT(lock_do_i_hold(semfs->semfs_tablelock)); KASSERT(lock_do_i_hold(semfs->semfs_tablelock));
@@ -116,9 +111,8 @@ semfs_sem_insert(struct semfs *semfs, struct semfs_sem *sem, unsigned *ret)
/* /*
* Constructor for semfs_direntry. * Constructor for semfs_direntry.
*/ */
struct semfs_direntry * struct semfs_direntry *semfs_direntry_create(const char *name,
semfs_direntry_create(const char *name, unsigned semnum) unsigned semnum) {
{
struct semfs_direntry *dent; struct semfs_direntry *dent;
dent = kmalloc(sizeof(*dent)); dent = kmalloc(sizeof(*dent));
@@ -137,9 +131,7 @@ semfs_direntry_create(const char *name, unsigned semnum)
/* /*
* Destructor for semfs_direntry. * Destructor for semfs_direntry.
*/ */
void void semfs_direntry_destroy(struct semfs_direntry *dent) {
semfs_direntry_destroy(struct semfs_direntry *dent)
{
kfree(dent->semd_name); kfree(dent->semd_name);
kfree(dent); kfree(dent);
} }

View File

@@ -44,10 +44,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// basic ops // basic ops
static static int semfs_eachopen(struct vnode *vn, int openflags) {
int
semfs_eachopen(struct vnode *vn, int openflags)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
if (semv->semv_semnum == SEMFS_ROOTDIR) { if (semv->semv_semnum == SEMFS_ROOTDIR) {
@@ -62,30 +59,21 @@ semfs_eachopen(struct vnode *vn, int openflags)
return 0; return 0;
} }
static static int semfs_ioctl(struct vnode *vn, int op, userptr_t data) {
int
semfs_ioctl(struct vnode *vn, int op, userptr_t data)
{
(void)vn; (void)vn;
(void)op; (void)op;
(void)data; (void)data;
return EINVAL; return EINVAL;
} }
static static int semfs_gettype(struct vnode *vn, mode_t *ret) {
int
semfs_gettype(struct vnode *vn, mode_t *ret)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
*ret = semv->semv_semnum == SEMFS_ROOTDIR ? S_IFDIR : S_IFREG; *ret = semv->semv_semnum == SEMFS_ROOTDIR ? S_IFDIR : S_IFREG;
return 0; return 0;
} }
static static bool semfs_isseekable(struct vnode *vn) {
bool
semfs_isseekable(struct vnode *vn)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
if (semv->semv_semnum != SEMFS_ROOTDIR) { if (semv->semv_semnum != SEMFS_ROOTDIR) {
@@ -95,10 +83,7 @@ semfs_isseekable(struct vnode *vn)
return true; return true;
} }
static static int semfs_fsync(struct vnode *vn) {
int
semfs_fsync(struct vnode *vn)
{
(void)vn; (void)vn;
return 0; return 0;
} }
@@ -110,10 +95,8 @@ semfs_fsync(struct vnode *vn)
* XXX fold these two together * XXX fold these two together
*/ */
static static struct semfs_sem *semfs_getsembynum(struct semfs *semfs,
struct semfs_sem * unsigned semnum) {
semfs_getsembynum(struct semfs *semfs, unsigned semnum)
{
struct semfs_sem *sem; struct semfs_sem *sem;
lock_acquire(semfs->semfs_tablelock); lock_acquire(semfs->semfs_tablelock);
@@ -123,10 +106,7 @@ semfs_getsembynum(struct semfs *semfs, unsigned semnum)
return sem; return sem;
} }
static static struct semfs_sem *semfs_getsem(struct semfs_vnode *semv) {
struct semfs_sem *
semfs_getsem(struct semfs_vnode *semv)
{
struct semfs *semfs = semv->semv_semfs; struct semfs *semfs = semv->semv_semfs;
return semfs_getsembynum(semfs, semv->semv_semnum); return semfs_getsembynum(semfs, semv->semv_semnum);
@@ -138,17 +118,13 @@ semfs_getsem(struct semfs_vnode *semv)
* potentially need to wake more than one sleeper if the new count * potentially need to wake more than one sleeper if the new count
* will be more than 1. * will be more than 1.
*/ */
static static void semfs_wakeup(struct semfs_sem *sem, unsigned newcount) {
void
semfs_wakeup(struct semfs_sem *sem, unsigned newcount)
{
if (sem->sems_count > 0 || newcount == 0) { if (sem->sems_count > 0 || newcount == 0) {
return; return;
} }
if (newcount == 1) { if (newcount == 1) {
cv_signal(sem->sems_cv, sem->sems_lock); cv_signal(sem->sems_cv, sem->sems_lock);
} } else {
else {
cv_broadcast(sem->sems_cv, sem->sems_lock); cv_broadcast(sem->sems_cv, sem->sems_lock);
} }
} }
@@ -156,10 +132,7 @@ semfs_wakeup(struct semfs_sem *sem, unsigned newcount)
/* /*
* stat() for semaphore vnodes * stat() for semaphore vnodes
*/ */
static static int semfs_semstat(struct vnode *vn, struct stat *buf) {
int
semfs_semstat(struct vnode *vn, struct stat *buf)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
struct semfs_sem *sem; struct semfs_sem *sem;
@@ -184,10 +157,7 @@ semfs_semstat(struct vnode *vn, struct stat *buf)
* Read. This is P(); decrease the count by the amount read. * Read. This is P(); decrease the count by the amount read.
* Don't actually bother to transfer any data. * Don't actually bother to transfer any data.
*/ */
static static int semfs_read(struct vnode *vn, struct uio *uio) {
int
semfs_read(struct vnode *vn, struct uio *uio)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
struct semfs_sem *sem; struct semfs_sem *sem;
size_t consume; size_t consume;
@@ -201,9 +171,8 @@ semfs_read(struct vnode *vn, struct uio *uio)
if (consume > sem->sems_count) { if (consume > sem->sems_count) {
consume = sem->sems_count; consume = sem->sems_count;
} }
DEBUG(DB_SEMFS, "semfs: sem%u: P, count %u -> %u\n", DEBUG(DB_SEMFS, "semfs: sem%u: P, count %u -> %u\n", semv->semv_semnum,
semv->semv_semnum, sem->sems_count, sem->sems_count, sem->sems_count - consume);
sem->sems_count - consume);
sem->sems_count -= consume; sem->sems_count -= consume;
/* don't bother advancing the uio data pointers */ /* don't bother advancing the uio data pointers */
uio->uio_offset += consume; uio->uio_offset += consume;
@@ -213,8 +182,7 @@ semfs_read(struct vnode *vn, struct uio *uio)
break; break;
} }
if (sem->sems_count == 0) { if (sem->sems_count == 0) {
DEBUG(DB_SEMFS, "semfs: sem%u: blocking\n", DEBUG(DB_SEMFS, "semfs: sem%u: blocking\n", semv->semv_semnum);
semv->semv_semnum);
cv_wait(sem->sems_cv, sem->sems_lock); cv_wait(sem->sems_cv, sem->sems_lock);
} }
} }
@@ -226,10 +194,7 @@ semfs_read(struct vnode *vn, struct uio *uio)
* Write. This is V(); increase the count by the amount written. * Write. This is V(); increase the count by the amount written.
* Don't actually bother to transfer any data. * Don't actually bother to transfer any data.
*/ */
static static int semfs_write(struct vnode *vn, struct uio *uio) {
int
semfs_write(struct vnode *vn, struct uio *uio)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
struct semfs_sem *sem; struct semfs_sem *sem;
unsigned newcount; unsigned newcount;
@@ -244,8 +209,8 @@ semfs_write(struct vnode *vn, struct uio *uio)
lock_release(sem->sems_lock); lock_release(sem->sems_lock);
return EFBIG; return EFBIG;
} }
DEBUG(DB_SEMFS, "semfs: sem%u: V, count %u -> %u\n", DEBUG(DB_SEMFS, "semfs: sem%u: V, count %u -> %u\n", semv->semv_semnum,
semv->semv_semnum, sem->sems_count, newcount); sem->sems_count, newcount);
semfs_wakeup(sem, newcount); semfs_wakeup(sem, newcount);
sem->sems_count = newcount; sem->sems_count = newcount;
uio->uio_offset += uio->uio_resid; uio->uio_offset += uio->uio_resid;
@@ -262,10 +227,7 @@ semfs_write(struct vnode *vn, struct uio *uio)
* semaphore as one would expect. Also it allows creating semaphores * semaphore as one would expect. Also it allows creating semaphores
* and then initializing their counts to values other than zero. * and then initializing their counts to values other than zero.
*/ */
static static int semfs_truncate(struct vnode *vn, off_t len) {
int
semfs_truncate(struct vnode *vn, off_t len)
{
/* We should just use UINT_MAX but we don't have it in the kernel */ /* We should just use UINT_MAX but we don't have it in the kernel */
const unsigned max = (unsigned)-1; const unsigned max = (unsigned)-1;
@@ -298,10 +260,7 @@ semfs_truncate(struct vnode *vn, off_t len)
* Directory read. Note that there's only one directory (the semfs * Directory read. Note that there's only one directory (the semfs
* root) that has all the semaphores in it. * root) that has all the semaphores in it.
*/ */
static static int semfs_getdirentry(struct vnode *dirvn, struct uio *uio) {
int
semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
{
struct semfs_vnode *dirsemv = dirvn->vn_data; struct semfs_vnode *dirsemv = dirvn->vn_data;
struct semfs *semfs = dirsemv->semv_semfs; struct semfs *semfs = dirsemv->semv_semfs;
struct semfs_direntry *dent; struct semfs_direntry *dent;
@@ -317,11 +276,9 @@ semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
if (pos >= num) { if (pos >= num) {
/* EOF */ /* EOF */
result = 0; result = 0;
} } else {
else {
dent = semfs_direntryarray_get(semfs->semfs_dents, pos); dent = semfs_direntryarray_get(semfs->semfs_dents, pos);
result = uiomove(dent->semd_name, strlen(dent->semd_name), result = uiomove(dent->semd_name, strlen(dent->semd_name), uio);
uio);
} }
lock_release(semfs->semfs_dirlock); lock_release(semfs->semfs_dirlock);
@@ -331,10 +288,7 @@ semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
/* /*
* stat() for dirs * stat() for dirs
*/ */
static static int semfs_dirstat(struct vnode *vn, struct stat *buf) {
int
semfs_dirstat(struct vnode *vn, struct stat *buf)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
struct semfs *semfs = semv->semv_semfs; struct semfs *semfs = semv->semv_semfs;
@@ -357,10 +311,7 @@ semfs_dirstat(struct vnode *vn, struct stat *buf)
* Backend for getcwd. Since we don't support subdirs, it's easy; send * Backend for getcwd. Since we don't support subdirs, it's easy; send
* back the empty string. * back the empty string.
*/ */
static static int semfs_namefile(struct vnode *vn, struct uio *uio) {
int
semfs_namefile(struct vnode *vn, struct uio *uio)
{
(void)vn; (void)vn;
(void)uio; (void)uio;
return 0; return 0;
@@ -369,11 +320,8 @@ semfs_namefile(struct vnode *vn, struct uio *uio)
/* /*
* Create a semaphore. * Create a semaphore.
*/ */
static static int semfs_creat(struct vnode *dirvn, const char *name, bool excl,
int mode_t mode, struct vnode **resultvn) {
semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
struct vnode **resultvn)
{
struct semfs_vnode *dirsemv = dirvn->vn_data; struct semfs_vnode *dirsemv = dirvn->vn_data;
struct semfs *semfs = dirsemv->semv_semfs; struct semfs *semfs = dirsemv->semv_semfs;
struct semfs_direntry *dent; struct semfs_direntry *dent;
@@ -403,8 +351,7 @@ semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
lock_release(semfs->semfs_dirlock); lock_release(semfs->semfs_dirlock);
return EEXIST; return EEXIST;
} }
result = semfs_getvnode(semfs, dent->semd_semnum, result = semfs_getvnode(semfs, dent->semd_semnum, resultvn);
resultvn);
lock_release(semfs->semfs_dirlock); lock_release(semfs->semfs_dirlock);
return result; return result;
} }
@@ -430,10 +377,8 @@ semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
if (empty < num) { if (empty < num) {
semfs_direntryarray_set(semfs->semfs_dents, empty, dent); semfs_direntryarray_set(semfs->semfs_dents, empty, dent);
} } else {
else { result = semfs_direntryarray_add(semfs->semfs_dents, dent, &empty);
result = semfs_direntryarray_add(semfs->semfs_dents, dent,
&empty);
if (result) { if (result) {
goto fail_undent; goto fail_undent;
} }
@@ -467,10 +412,7 @@ semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
* Unlink a semaphore. As with other files, it may not actually * Unlink a semaphore. As with other files, it may not actually
* go away if it's currently open. * go away if it's currently open.
*/ */
static static int semfs_remove(struct vnode *dirvn, const char *name) {
int
semfs_remove(struct vnode *dirvn, const char *name)
{
struct semfs_vnode *dirsemv = dirvn->vn_data; struct semfs_vnode *dirsemv = dirvn->vn_data;
struct semfs *semfs = dirsemv->semv_semfs; struct semfs *semfs = dirsemv->semv_semfs;
struct semfs_direntry *dent; struct semfs_direntry *dent;
@@ -497,13 +439,11 @@ semfs_remove(struct vnode *dirvn, const char *name)
sem->sems_linked = false; sem->sems_linked = false;
if (sem->sems_hasvnode == false) { if (sem->sems_hasvnode == false) {
lock_acquire(semfs->semfs_tablelock); lock_acquire(semfs->semfs_tablelock);
semfs_semarray_set(semfs->semfs_sems, semfs_semarray_set(semfs->semfs_sems, dent->semd_semnum, NULL);
dent->semd_semnum, NULL);
lock_release(semfs->semfs_tablelock); lock_release(semfs->semfs_tablelock);
lock_release(sem->sems_lock); lock_release(sem->sems_lock);
semfs_sem_destroy(sem); semfs_sem_destroy(sem);
} } else {
else {
lock_release(sem->sems_lock); lock_release(sem->sems_lock);
} }
semfs_direntryarray_set(semfs->semfs_dents, i, NULL); semfs_direntryarray_set(semfs->semfs_dents, i, NULL);
@@ -521,10 +461,8 @@ semfs_remove(struct vnode *dirvn, const char *name)
/* /*
* Lookup: get a semaphore by name. * Lookup: get a semaphore by name.
*/ */
static static int semfs_lookup(struct vnode *dirvn, char *path,
int struct vnode **resultvn) {
semfs_lookup(struct vnode *dirvn, char *path, struct vnode **resultvn)
{
struct semfs_vnode *dirsemv = dirvn->vn_data; struct semfs_vnode *dirsemv = dirvn->vn_data;
struct semfs *semfs = dirsemv->semv_semfs; struct semfs *semfs = dirsemv->semv_semfs;
struct semfs_direntry *dent; struct semfs_direntry *dent;
@@ -545,8 +483,7 @@ semfs_lookup(struct vnode *dirvn, char *path, struct vnode **resultvn)
continue; continue;
} }
if (!strcmp(path, dent->semd_name)) { if (!strcmp(path, dent->semd_name)) {
result = semfs_getvnode(semfs, dent->semd_semnum, result = semfs_getvnode(semfs, dent->semd_semnum, resultvn);
resultvn);
lock_release(semfs->semfs_dirlock); lock_release(semfs->semfs_dirlock);
return result; return result;
} }
@@ -559,11 +496,9 @@ semfs_lookup(struct vnode *dirvn, char *path, struct vnode **resultvn)
* Lookparent: because we don't have subdirs, just return the root * Lookparent: because we don't have subdirs, just return the root
* dir and copy the name. * dir and copy the name.
*/ */
static static int semfs_lookparent(struct vnode *dirvn, char *path,
int struct vnode **resultdirvn, char *namebuf,
semfs_lookparent(struct vnode *dirvn, char *path, size_t bufmax) {
struct vnode **resultdirvn, char *namebuf, size_t bufmax)
{
if (strlen(path) + 1 > bufmax) { if (strlen(path) + 1 > bufmax) {
return ENAMETOOLONG; return ENAMETOOLONG;
} }
@@ -580,10 +515,7 @@ semfs_lookparent(struct vnode *dirvn, char *path,
/* /*
* Destructor for semfs_vnode. * Destructor for semfs_vnode.
*/ */
static static void semfs_vnode_destroy(struct semfs_vnode *semv) {
void
semfs_vnode_destroy(struct semfs_vnode *semv)
{
vnode_cleanup(&semv->semv_absvn); vnode_cleanup(&semv->semv_absvn);
kfree(semv); kfree(semv);
} }
@@ -591,10 +523,7 @@ semfs_vnode_destroy(struct semfs_vnode *semv)
/* /*
* Reclaim - drop a vnode that's no longer in use. * Reclaim - drop a vnode that's no longer in use.
*/ */
static static int semfs_reclaim(struct vnode *vn) {
int
semfs_reclaim(struct vnode *vn)
{
struct semfs_vnode *semv = vn->vn_data; struct semfs_vnode *semv = vn->vn_data;
struct semfs *semfs = semv->semv_semfs; struct semfs *semfs = semv->semv_semfs;
struct vnode *vn2; struct vnode *vn2;
@@ -631,8 +560,7 @@ semfs_reclaim(struct vnode *vn)
KASSERT(sem->sems_hasvnode); KASSERT(sem->sems_hasvnode);
sem->sems_hasvnode = false; sem->sems_hasvnode = false;
if (sem->sems_linked == false) { if (sem->sems_linked == false) {
semfs_semarray_set(semfs->semfs_sems, semfs_semarray_set(semfs->semfs_sems, semv->semv_semnum, NULL);
semv->semv_semnum, NULL);
semfs_sem_destroy(sem); semfs_sem_destroy(sem);
} }
} }
@@ -714,18 +642,15 @@ static const struct vnode_ops semfs_semops = {
/* /*
* Constructor for semfs vnodes. * Constructor for semfs vnodes.
*/ */
static static struct semfs_vnode *semfs_vnode_create(struct semfs *semfs,
struct semfs_vnode * unsigned semnum) {
semfs_vnode_create(struct semfs *semfs, unsigned semnum)
{
const struct vnode_ops *optable; const struct vnode_ops *optable;
struct semfs_vnode *semv; struct semfs_vnode *semv;
int result; int result;
if (semnum == SEMFS_ROOTDIR) { if (semnum == SEMFS_ROOTDIR) {
optable = &semfs_dirops; optable = &semfs_dirops;
} } else {
else {
optable = &semfs_semops; optable = &semfs_semops;
} }
@@ -737,8 +662,7 @@ semfs_vnode_create(struct semfs *semfs, unsigned semnum)
semv->semv_semfs = semfs; semv->semv_semfs = semfs;
semv->semv_semnum = semnum; semv->semv_semnum = semnum;
result = vnode_init(&semv->semv_absvn, optable, result = vnode_init(&semv->semv_absvn, optable, &semfs->semfs_absfs, semv);
&semfs->semfs_absfs, semv);
/* vnode_init doesn't actually fail */ /* vnode_init doesn't actually fail */
KASSERT(result == 0); KASSERT(result == 0);
@@ -749,9 +673,7 @@ semfs_vnode_create(struct semfs *semfs, unsigned semnum)
* Look up the vnode for a semaphore by number; if it doesn't exist, * Look up the vnode for a semaphore by number; if it doesn't exist,
* create it. * create it.
*/ */
int int semfs_getvnode(struct semfs *semfs, unsigned semnum, struct vnode **ret) {
semfs_getvnode(struct semfs *semfs, unsigned semnum, struct vnode **ret)
{
struct vnode *vn; struct vnode *vn;
struct semfs_vnode *semv; struct semfs_vnode *semv;
struct semfs_sem *sem; struct semfs_sem *sem;

View File

@@ -41,10 +41,7 @@
/* /*
* Zero out a disk block. * Zero out a disk block.
*/ */
static static int sfs_clearblock(struct sfs_fs *sfs, daddr_t block) {
int
sfs_clearblock(struct sfs_fs *sfs, daddr_t block)
{
/* static -> automatically initialized to zero */ /* static -> automatically initialized to zero */
static char zeros[SFS_BLOCKSIZE]; static char zeros[SFS_BLOCKSIZE];
@@ -54,9 +51,7 @@ sfs_clearblock(struct sfs_fs *sfs, daddr_t block)
/* /*
* Allocate a block. * Allocate a block.
*/ */
int int sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock) {
sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
{
int result; int result;
result = bitmap_alloc(sfs->sfs_freemap, diskblock); result = bitmap_alloc(sfs->sfs_freemap, diskblock);
@@ -66,8 +61,8 @@ sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
sfs->sfs_freemapdirty = true; sfs->sfs_freemapdirty = true;
if (*diskblock >= sfs->sfs_sb.sb_nblocks) { if (*diskblock >= sfs->sfs_sb.sb_nblocks) {
panic("sfs: %s: balloc: invalid block %u\n", panic("sfs: %s: balloc: invalid block %u\n", sfs->sfs_sb.sb_volname,
sfs->sfs_sb.sb_volname, *diskblock); *diskblock);
} }
/* Clear block before returning it */ /* Clear block before returning it */
@@ -81,9 +76,7 @@ sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
/* /*
* Free a block. * Free a block.
*/ */
void void sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock) {
sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock)
{
bitmap_unmark(sfs->sfs_freemap, diskblock); bitmap_unmark(sfs->sfs_freemap, diskblock);
sfs->sfs_freemapdirty = true; sfs->sfs_freemapdirty = true;
} }
@@ -91,13 +84,10 @@ sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock)
/* /*
* Check if a block is in use. * Check if a block is in use.
*/ */
int int sfs_bused(struct sfs_fs *sfs, daddr_t diskblock) {
sfs_bused(struct sfs_fs *sfs, daddr_t diskblock)
{
if (diskblock >= sfs->sfs_sb.sb_nblocks) { if (diskblock >= sfs->sfs_sb.sb_nblocks) {
panic("sfs: %s: sfs_bused called on out of range block %u\n", panic("sfs: %s: sfs_bused called on out of range block %u\n",
sfs->sfs_sb.sb_volname, diskblock); sfs->sfs_sb.sb_volname, diskblock);
} }
return bitmap_isset(sfs->sfs_freemap, diskblock); return bitmap_isset(sfs->sfs_freemap, diskblock);
} }

View File

@@ -45,10 +45,8 @@
* file. If DOALLOC is set, and no such block exists, one will be * file. If DOALLOC is set, and no such block exists, one will be
* allocated. * allocated.
*/ */
int int sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc, daddr_t *diskblock) {
daddr_t *diskblock)
{
/* /*
* I/O buffer for handling indirect blocks. * I/O buffer for handling indirect blocks.
* *
@@ -97,8 +95,8 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
*/ */
if (block != 0 && !sfs_bused(sfs, block)) { if (block != 0 && !sfs_bused(sfs, block)) {
panic("sfs: %s: Data block %u (block %u of file %u) " panic("sfs: %s: Data block %u (block %u of file %u) "
"marked free\n", sfs->sfs_sb.sb_volname, "marked free\n",
block, fileblock, sv->sv_ino); sfs->sfs_sb.sb_volname, block, fileblock, sv->sv_ino);
} }
*diskblock = block; *diskblock = block;
return 0; return 0;
@@ -135,8 +133,7 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
*/ */
*diskblock = 0; *diskblock = 0;
return 0; return 0;
} } else if (idblock == 0) {
else if (idblock==0) {
/* /*
* There's no indirect block allocated, but we need to * There's no indirect block allocated, but we need to
* allocate a block whose number needs to be stored in * allocate a block whose number needs to be stored in
@@ -156,8 +153,7 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
/* Clear the indirect block buffer */ /* Clear the indirect block buffer */
bzero(idbuf, sizeof(idbuf)); bzero(idbuf, sizeof(idbuf));
} } else {
else {
/* /*
* We already have an indirect block allocated; load it. * We already have an indirect block allocated; load it.
*/ */
@@ -190,8 +186,8 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
/* Hand back the result and return. */ /* Hand back the result and return. */
if (block != 0 && !sfs_bused(sfs, block)) { if (block != 0 && !sfs_bused(sfs, block)) {
panic("sfs: %s: Data block %u (block %u of file %u) " panic("sfs: %s: Data block %u (block %u of file %u) "
"marked free\n", sfs->sfs_sb.sb_volname, "marked free\n",
block, fileblock, sv->sv_ino); sfs->sfs_sb.sb_volname, block, fileblock, sv->sv_ino);
} }
*diskblock = block; *diskblock = block;
return 0; return 0;
@@ -200,9 +196,7 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
/* /*
* Called for ftruncate() and from sfs_reclaim. * Called for ftruncate() and from sfs_reclaim.
*/ */
int int sfs_itrunc(struct sfs_vnode *sv, off_t len) {
sfs_itrunc(struct sfs_vnode *sv, off_t len)
{
/* /*
* I/O buffer for handling the indirect block. * I/O buffer for handling the indirect block.
* *
@@ -279,11 +273,9 @@ sfs_itrunc(struct sfs_vnode *sv, off_t len)
sfs_bfree(sfs, idblock); sfs_bfree(sfs, idblock);
sv->sv_i.sfi_indirect = 0; sv->sv_i.sfi_indirect = 0;
sv->sv_dirty = true; sv->sv_dirty = true;
} } else if (iddirty) {
else if (iddirty) {
/* The indirect block is dirty; write it back */ /* The indirect block is dirty; write it back */
result = sfs_writeblock(sfs, idblock, idbuf, result = sfs_writeblock(sfs, idblock, idbuf, sizeof(idbuf));
sizeof(idbuf));
if (result) { if (result) {
vfs_biglock_release(); vfs_biglock_release();
return result; return result;
@@ -300,4 +292,3 @@ sfs_itrunc(struct sfs_vnode *sv, off_t len)
vfs_biglock_release(); vfs_biglock_release();
return 0; return 0;
} }

View File

@@ -43,10 +43,8 @@
* Read the directory entry out of slot SLOT of a directory vnode. * Read the directory entry out of slot SLOT of a directory vnode.
* The "slot" is the index of the directory entry, starting at 0. * The "slot" is the index of the directory entry, starting at 0.
*/ */
static static int sfs_readdir(struct sfs_vnode *sv, int slot,
int struct sfs_direntry *sd) {
sfs_readdir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
{
off_t actualpos; off_t actualpos;
/* Compute the actual position in the directory to read. */ /* Compute the actual position in the directory to read. */
@@ -59,10 +57,8 @@ sfs_readdir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
* Write (overwrite) the directory entry in slot SLOT of a directory * Write (overwrite) the directory entry in slot SLOT of a directory
* vnode. * vnode.
*/ */
static static int sfs_writedir(struct sfs_vnode *sv, int slot,
int struct sfs_direntry *sd) {
sfs_writedir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
{
off_t actualpos; off_t actualpos;
/* Compute the actual position in the directory. */ /* Compute the actual position in the directory. */
@@ -77,10 +73,7 @@ sfs_writedir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
* This actually computes the number of existing slots, and does not * This actually computes the number of existing slots, and does not
* account for empty slots. * account for empty slots.
*/ */
static static int sfs_dir_nentries(struct sfs_vnode *sv) {
int
sfs_dir_nentries(struct sfs_vnode *sv)
{
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
off_t size; off_t size;
@@ -88,8 +81,8 @@ sfs_dir_nentries(struct sfs_vnode *sv)
size = sv->sv_i.sfi_size; size = sv->sv_i.sfi_size;
if (size % sizeof(struct sfs_direntry) != 0) { if (size % sizeof(struct sfs_direntry) != 0) {
panic("sfs: %s: directory %u: Invalid size %llu\n", panic("sfs: %s: directory %u: Invalid size %llu\n", sfs->sfs_sb.sb_volname,
sfs->sfs_sb.sb_volname, sv->sv_ino, size); sv->sv_ino, size);
} }
return size / sizeof(struct sfs_direntry); return size / sizeof(struct sfs_direntry);
@@ -100,10 +93,8 @@ sfs_dir_nentries(struct sfs_vnode *sv)
* return its inode number, its slot, and/or the slot number of an * return its inode number, its slot, and/or the slot number of an
* empty directory slot if one is found. * empty directory slot if one is found.
*/ */
int int sfs_dir_findname(struct sfs_vnode *sv, const char *name, uint32_t *ino,
sfs_dir_findname(struct sfs_vnode *sv, const char *name, int *slot, int *emptyslot) {
uint32_t *ino, int *slot, int *emptyslot)
{
struct sfs_direntry tsd; struct sfs_direntry tsd;
int found, nentries, i, result; int found, nentries, i, result;
@@ -123,8 +114,7 @@ sfs_dir_findname(struct sfs_vnode *sv, const char *name,
if (emptyslot != NULL) { if (emptyslot != NULL) {
*emptyslot = i; *emptyslot = i;
} }
} } else {
else {
/* Ensure null termination, just in case */ /* Ensure null termination, just in case */
tsd.sfd_name[sizeof(tsd.sfd_name) - 1] = 0; tsd.sfd_name[sizeof(tsd.sfd_name) - 1] = 0;
if (!strcmp(tsd.sfd_name, name)) { if (!strcmp(tsd.sfd_name, name)) {
@@ -150,9 +140,8 @@ sfs_dir_findname(struct sfs_vnode *sv, const char *name,
* Create a link in a directory to the specified inode by number, with * Create a link in a directory to the specified inode by number, with
* the specified name, and optionally hand back the slot. * the specified name, and optionally hand back the slot.
*/ */
int int sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino,
sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino, int *slot) int *slot) {
{
int emptyslot = -1; int emptyslot = -1;
int result; int result;
struct sfs_direntry sd; struct sfs_direntry sd;
@@ -192,9 +181,7 @@ sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino, int *slot)
/* /*
* Unlink a name in a directory, by slot number. * Unlink a name in a directory, by slot number.
*/ */
int int sfs_dir_unlink(struct sfs_vnode *sv, int slot) {
sfs_dir_unlink(struct sfs_vnode *sv, int slot)
{
struct sfs_direntry sd; struct sfs_direntry sd;
/* Initialize a suitable directory entry... */ /* Initialize a suitable directory entry... */
@@ -209,11 +196,8 @@ sfs_dir_unlink(struct sfs_vnode *sv, int slot)
* Look for a name in a directory and hand back a vnode for the * Look for a name in a directory and hand back a vnode for the
* file, if there is one. * file, if there is one.
*/ */
int int sfs_lookonce(struct sfs_vnode *sv, const char *name, struct sfs_vnode **ret,
sfs_lookonce(struct sfs_vnode *sv, const char *name, int *slot) {
struct sfs_vnode **ret,
int *slot)
{
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
uint32_t ino; uint32_t ino;
int result; int result;
@@ -230,10 +214,9 @@ sfs_lookonce(struct sfs_vnode *sv, const char *name,
if ((*ret)->sv_i.sfi_linkcount == 0) { if ((*ret)->sv_i.sfi_linkcount == 0) {
panic("sfs: %s: name %s (inode %u) in dir %u has " panic("sfs: %s: name %s (inode %u) in dir %u has "
"linkcount 0\n", sfs->sfs_sb.sb_volname, "linkcount 0\n",
name, (*ret)->sv_ino, sv->sv_ino); sfs->sfs_sb.sb_volname, name, (*ret)->sv_ino, sv->sv_ino);
} }
return 0; return 0;
} }

View File

@@ -44,7 +44,6 @@
#include <sfs.h> #include <sfs.h>
#include "sfsprivate.h" #include "sfsprivate.h"
/* Shortcuts for the size macros in kern/sfs.h */ /* Shortcuts for the size macros in kern/sfs.h */
#define SFS_FS_NBLOCKS(sfs) ((sfs)->sfs_sb.sb_nblocks) #define SFS_FS_NBLOCKS(sfs) ((sfs)->sfs_sb.sb_nblocks)
#define SFS_FS_FREEMAPBITS(sfs) SFS_FREEMAPBITS(SFS_FS_NBLOCKS(sfs)) #define SFS_FS_FREEMAPBITS(sfs) SFS_FREEMAPBITS(SFS_FS_NBLOCKS(sfs))
@@ -67,10 +66,7 @@
* The sectors used by the superblock and the bitmap itself are * The sectors used by the superblock and the bitmap itself are
* likewise marked in use by mksfs. * likewise marked in use by mksfs.
*/ */
static static int sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw) {
int
sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw)
{
uint32_t j, freemapblocks; uint32_t j, freemapblocks;
char *freemapdata; char *freemapdata;
int result; int result;
@@ -89,12 +85,9 @@ sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw)
/* and read or write it. The freemap starts at sector 2. */ /* and read or write it. The freemap starts at sector 2. */
if (rw == UIO_READ) { if (rw == UIO_READ) {
result = sfs_readblock(sfs, SFS_FREEMAP_START+j, ptr, result = sfs_readblock(sfs, SFS_FREEMAP_START + j, ptr, SFS_BLOCKSIZE);
SFS_BLOCKSIZE); } else {
} result = sfs_writeblock(sfs, SFS_FREEMAP_START + j, ptr, SFS_BLOCKSIZE);
else {
result = sfs_writeblock(sfs, SFS_FREEMAP_START+j, ptr,
SFS_BLOCKSIZE);
} }
/* If we failed, stop. */ /* If we failed, stop. */
@@ -108,10 +101,7 @@ sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw)
/* /*
* Sync routine for the vnode table. * Sync routine for the vnode table.
*/ */
static static int sfs_sync_vnodes(struct sfs_fs *sfs) {
int
sfs_sync_vnodes(struct sfs_fs *sfs)
{
unsigned i, num; unsigned i, num;
/* Go over the array of loaded vnodes, syncing as we go. */ /* Go over the array of loaded vnodes, syncing as we go. */
@@ -126,10 +116,7 @@ sfs_sync_vnodes(struct sfs_fs *sfs)
/* /*
* Sync routine for the freemap. * Sync routine for the freemap.
*/ */
static static int sfs_sync_freemap(struct sfs_fs *sfs) {
int
sfs_sync_freemap(struct sfs_fs *sfs)
{
int result; int result;
if (sfs->sfs_freemapdirty) { if (sfs->sfs_freemapdirty) {
@@ -146,15 +133,12 @@ sfs_sync_freemap(struct sfs_fs *sfs)
/* /*
* Sync routine for the superblock. * Sync routine for the superblock.
*/ */
static static int sfs_sync_superblock(struct sfs_fs *sfs) {
int
sfs_sync_superblock(struct sfs_fs *sfs)
{
int result; int result;
if (sfs->sfs_superdirty) { if (sfs->sfs_superdirty) {
result = sfs_writeblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, result =
sizeof(sfs->sfs_sb)); sfs_writeblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, sizeof(sfs->sfs_sb));
if (result) { if (result) {
return result; return result;
} }
@@ -167,10 +151,7 @@ sfs_sync_superblock(struct sfs_fs *sfs)
* Sync routine. This is what gets invoked if you do FS_SYNC on the * Sync routine. This is what gets invoked if you do FS_SYNC on the
* sfs filesystem structure. * sfs filesystem structure.
*/ */
static static int sfs_sync(struct fs *fs) {
int
sfs_sync(struct fs *fs)
{
struct sfs_fs *sfs; struct sfs_fs *sfs;
int result; int result;
@@ -238,10 +219,7 @@ sfs_sync(struct fs *fs)
* to by their volume name followed by a colon as well as the name * to by their volume name followed by a colon as well as the name
* of the device they're mounted on. * of the device they're mounted on.
*/ */
static static const char *sfs_getvolname(struct fs *fs) {
const char *
sfs_getvolname(struct fs *fs)
{
struct sfs_fs *sfs = fs->fs_data; struct sfs_fs *sfs = fs->fs_data;
const char *ret; const char *ret;
@@ -255,10 +233,7 @@ sfs_getvolname(struct fs *fs)
/* /*
* Destructor for struct sfs_fs. * Destructor for struct sfs_fs.
*/ */
static static void sfs_fs_destroy(struct sfs_fs *sfs) {
void
sfs_fs_destroy(struct sfs_fs *sfs)
{
if (sfs->sfs_freemap != NULL) { if (sfs->sfs_freemap != NULL) {
bitmap_destroy(sfs->sfs_freemap); bitmap_destroy(sfs->sfs_freemap);
} }
@@ -272,10 +247,7 @@ sfs_fs_destroy(struct sfs_fs *sfs)
* *
* VFS calls FS_SYNC on the filesystem prior to unmounting it. * VFS calls FS_SYNC on the filesystem prior to unmounting it.
*/ */
static static int sfs_unmount(struct fs *fs) {
int
sfs_unmount(struct fs *fs)
{
struct sfs_fs *sfs = fs->fs_data; struct sfs_fs *sfs = fs->fs_data;
vfs_biglock_acquire(); vfs_biglock_acquire();
@@ -316,10 +288,7 @@ static const struct fs_ops sfs_fsops = {
* but skips stuff that requires reading the volume, like allocating * but skips stuff that requires reading the volume, like allocating
* the freemap. * the freemap.
*/ */
static static struct sfs_fs *sfs_fs_create(void) {
struct sfs_fs *
sfs_fs_create(void)
{
struct sfs_fs *sfs; struct sfs_fs *sfs;
/* /*
@@ -381,10 +350,7 @@ fail:
* filesystems with the same name mounted at once, or two filesystems * filesystems with the same name mounted at once, or two filesystems
* mounted on the same device at once. * mounted on the same device at once.
*/ */
static static int sfs_domount(void *options, struct device *dev, struct fs **ret) {
int
sfs_domount(void *options, struct device *dev, struct fs **ret)
{
int result; int result;
struct sfs_fs *sfs; struct sfs_fs *sfs;
@@ -418,8 +384,8 @@ sfs_domount(void *options, struct device *dev, struct fs **ret)
sfs->sfs_device = dev; sfs->sfs_device = dev;
/* Load superblock */ /* Load superblock */
result = sfs_readblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, result =
sizeof(sfs->sfs_sb)); sfs_readblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, sizeof(sfs->sfs_sb));
if (result) { if (result) {
sfs->sfs_device = NULL; sfs->sfs_device = NULL;
sfs_fs_destroy(sfs); sfs_fs_destroy(sfs);
@@ -432,8 +398,7 @@ sfs_domount(void *options, struct device *dev, struct fs **ret)
if (sfs->sfs_sb.sb_magic != SFS_MAGIC) { if (sfs->sfs_sb.sb_magic != SFS_MAGIC) {
kprintf("sfs: Wrong magic number in superblock " kprintf("sfs: Wrong magic number in superblock "
"(0x%x, should be 0x%x)\n", "(0x%x, should be 0x%x)\n",
sfs->sfs_sb.sb_magic, sfs->sfs_sb.sb_magic, SFS_MAGIC);
SFS_MAGIC);
sfs->sfs_device = NULL; sfs->sfs_device = NULL;
sfs_fs_destroy(sfs); sfs_fs_destroy(sfs);
vfs_biglock_release(); vfs_biglock_release();
@@ -474,8 +439,6 @@ sfs_domount(void *options, struct device *dev, struct fs **ret)
/* /*
* Actual function called from high-level code to mount an sfs. * Actual function called from high-level code to mount an sfs.
*/ */
int int sfs_mount(const char *device) {
sfs_mount(const char *device)
{
return vfs_mount(device, NULL, sfs_domount); return vfs_mount(device, NULL, sfs_domount);
} }

View File

@@ -39,19 +39,15 @@
#include <sfs.h> #include <sfs.h>
#include "sfsprivate.h" #include "sfsprivate.h"
/* /*
* Write an on-disk inode structure back out to disk. * Write an on-disk inode structure back out to disk.
*/ */
int int sfs_sync_inode(struct sfs_vnode *sv) {
sfs_sync_inode(struct sfs_vnode *sv)
{
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
int result; int result;
if (sv->sv_dirty) { if (sv->sv_dirty) {
result = sfs_writeblock(sfs, sv->sv_ino, &sv->sv_i, result = sfs_writeblock(sfs, sv->sv_ino, &sv->sv_i, sizeof(sv->sv_i));
sizeof(sv->sv_i));
if (result) { if (result) {
return result; return result;
} }
@@ -65,9 +61,7 @@ sfs_sync_inode(struct sfs_vnode *sv)
* *
* This function should try to avoid returning errors other than EBUSY. * This function should try to avoid returning errors other than EBUSY.
*/ */
int int sfs_reclaim(struct vnode *v) {
sfs_reclaim(struct vnode *v)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
struct sfs_fs *sfs = v->vn_fs->fs_data; struct sfs_fs *sfs = v->vn_fs->fs_data;
unsigned ix, i, num; unsigned ix, i, num;
@@ -146,10 +140,8 @@ sfs_reclaim(struct vnode *v)
* Function to load a inode into memory as a vnode, or dig up one * Function to load a inode into memory as a vnode, or dig up one
* that's already resident. * that's already resident.
*/ */
int int sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype, struct sfs_vnode **ret) {
struct sfs_vnode **ret)
{
struct vnode *v; struct vnode *v;
struct sfs_vnode *sv; struct sfs_vnode *sv;
const struct vnode_ops *ops; const struct vnode_ops *ops;
@@ -192,7 +184,8 @@ sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
/* Must be in an allocated block */ /* Must be in an allocated block */
if (!sfs_bused(sfs, ino)) { if (!sfs_bused(sfs, ino)) {
panic("sfs: %s: Tried to load inode %u from " panic("sfs: %s: Tried to load inode %u from "
"unallocated block\n", sfs->sfs_sb.sb_volname, ino); "unallocated block\n",
sfs->sfs_sb.sb_volname, ino);
} }
/* Read the block the inode is in */ /* Read the block the inode is in */
@@ -228,8 +221,8 @@ sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
break; break;
default: default:
panic("sfs: %s: loadvnode: Invalid inode type " panic("sfs: %s: loadvnode: Invalid inode type "
"(inode %u, type %u)\n", sfs->sfs_sb.sb_volname, "(inode %u, type %u)\n",
ino, sv->sv_i.sfi_type); sfs->sfs_sb.sb_volname, ino, sv->sv_i.sfi_type);
} }
/* Call the common vnode initializer */ /* Call the common vnode initializer */
@@ -258,9 +251,7 @@ sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
/* /*
* Create a new filesystem object and hand back its vnode. * Create a new filesystem object and hand back its vnode.
*/ */
int int sfs_makeobj(struct sfs_fs *sfs, int type, struct sfs_vnode **ret) {
sfs_makeobj(struct sfs_fs *sfs, int type, struct sfs_vnode **ret)
{
uint32_t ino; uint32_t ino;
int result; int result;
@@ -289,9 +280,7 @@ sfs_makeobj(struct sfs_fs *sfs, int type, struct sfs_vnode **ret)
* Get vnode for the root of the filesystem. * Get vnode for the root of the filesystem.
* The root vnode is always found in block 1 (SFS_ROOTDIR_INO). * The root vnode is always found in block 1 (SFS_ROOTDIR_INO).
*/ */
int int sfs_getroot(struct fs *fs, struct vnode **ret) {
sfs_getroot(struct fs *fs, struct vnode **ret)
{
struct sfs_fs *sfs = fs->fs_data; struct sfs_fs *sfs = fs->fs_data;
struct sfs_vnode *sv; struct sfs_vnode *sv;
int result; int result;

View File

@@ -55,17 +55,13 @@
/* /*
* Read or write a block, retrying I/O errors. * Read or write a block, retrying I/O errors.
*/ */
static static int sfs_rwblock(struct sfs_fs *sfs, struct uio *uio) {
int
sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
{
int result; int result;
int tries = 0; int tries = 0;
KASSERT(vfs_biglock_do_i_hold()); KASSERT(vfs_biglock_do_i_hold());
DEBUG(DB_SFS, "sfs: %s %llu\n", DEBUG(DB_SFS, "sfs: %s %llu\n", uio->uio_rw == UIO_READ ? "read" : "write",
uio->uio_rw == UIO_READ ? "read" : "write",
uio->uio_offset / SFS_BLOCKSIZE); uio->uio_offset / SFS_BLOCKSIZE);
retry: retry:
@@ -76,26 +72,21 @@ sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
* or the seek address we gave wasn't sector-aligned, * or the seek address we gave wasn't sector-aligned,
* or a couple of other things that are our fault. * or a couple of other things that are our fault.
*/ */
panic("sfs: %s: DEVOP_IO returned EINVAL\n", panic("sfs: %s: DEVOP_IO returned EINVAL\n", sfs->sfs_sb.sb_volname);
sfs->sfs_sb.sb_volname);
} }
if (result == EIO) { if (result == EIO) {
if (tries == 0) { if (tries == 0) {
tries++; tries++;
kprintf("sfs: %s: block %llu I/O error, retrying\n", kprintf("sfs: %s: block %llu I/O error, retrying\n",
sfs->sfs_sb.sb_volname, sfs->sfs_sb.sb_volname, uio->uio_offset / SFS_BLOCKSIZE);
uio->uio_offset / SFS_BLOCKSIZE);
goto retry; goto retry;
} } else if (tries < 10) {
else if (tries < 10) {
tries++; tries++;
goto retry; goto retry;
} } else {
else {
kprintf("sfs: %s: block %llu I/O error, giving up " kprintf("sfs: %s: block %llu I/O error, giving up "
"after %d retries\n", "after %d retries\n",
sfs->sfs_sb.sb_volname, sfs->sfs_sb.sb_volname, uio->uio_offset / SFS_BLOCKSIZE, tries);
uio->uio_offset / SFS_BLOCKSIZE, tries);
} }
} }
return result; return result;
@@ -104,9 +95,7 @@ sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
/* /*
* Read a block. * Read a block.
*/ */
int int sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len) {
sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
{
struct iovec iov; struct iovec iov;
struct uio ku; struct uio ku;
@@ -119,9 +108,7 @@ sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
/* /*
* Write a block. * Write a block.
*/ */
int int sfs_writeblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len) {
sfs_writeblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
{
struct iovec iov; struct iovec iov;
struct uio ku; struct uio ku;
@@ -145,11 +132,8 @@ sfs_writeblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
* the sector; LEN is the number of bytes to actually read or write. * the sector; LEN is the number of bytes to actually read or write.
* UIO is the area to do the I/O into. * UIO is the area to do the I/O into.
*/ */
static static int sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
int uint32_t skipstart, uint32_t len) {
sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
uint32_t skipstart, uint32_t len)
{
/* /*
* I/O buffer for handling partial sectors. * I/O buffer for handling partial sectors.
* *
@@ -188,8 +172,7 @@ sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
*/ */
KASSERT(uio->uio_rw == UIO_READ); KASSERT(uio->uio_rw == UIO_READ);
bzero(iobuf, sizeof(iobuf)); bzero(iobuf, sizeof(iobuf));
} } else {
else {
/* /*
* Read the block. * Read the block.
*/ */
@@ -223,10 +206,7 @@ sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
/* /*
* Do I/O (either read or write) of a single whole block. * Do I/O (either read or write) of a single whole block.
*/ */
static static int sfs_blockio(struct sfs_vnode *sv, struct uio *uio) {
int
sfs_blockio(struct sfs_vnode *sv, struct uio *uio)
{
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
daddr_t diskblock; daddr_t diskblock;
uint32_t fileblock; uint32_t fileblock;
@@ -288,9 +268,7 @@ sfs_blockio(struct sfs_vnode *sv, struct uio *uio)
/* /*
* Do I/O of a whole region of data, whether or not it's block-aligned. * Do I/O of a whole region of data, whether or not it's block-aligned.
*/ */
int int sfs_io(struct sfs_vnode *sv, struct uio *uio) {
sfs_io(struct sfs_vnode *sv, struct uio *uio)
{
uint32_t blkoff; uint32_t blkoff;
uint32_t nblocks, i; uint32_t nblocks, i;
int result = 0; int result = 0;
@@ -374,8 +352,7 @@ sfs_io(struct sfs_vnode *sv, struct uio *uio)
out: out:
/* If writing and we did anything, adjust file length */ /* If writing and we did anything, adjust file length */
if (uio->uio_resid != origresid && if (uio->uio_resid != origresid && uio->uio_rw == UIO_WRITE &&
uio->uio_rw == UIO_WRITE &&
uio->uio_offset > (off_t)sv->sv_i.sfi_size) { uio->uio_offset > (off_t)sv->sv_i.sfi_size) {
sv->sv_i.sfi_size = uio->uio_offset; sv->sv_i.sfi_size = uio->uio_offset;
sv->sv_dirty = true; sv->sv_dirty = true;
@@ -402,10 +379,8 @@ sfs_io(struct sfs_vnode *sv, struct uio *uio)
* more advanced things to handle metadata and user data I/O * more advanced things to handle metadata and user data I/O
* differently. * differently.
*/ */
int int sfs_metaio(struct sfs_vnode *sv, off_t actualpos, void *data, size_t len,
sfs_metaio(struct sfs_vnode *sv, off_t actualpos, void *data, size_t len, enum uio_rw rw) {
enum uio_rw rw)
{
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
off_t endpos; off_t endpos;
uint32_t vnblock; uint32_t vnblock;
@@ -455,14 +430,12 @@ sfs_metaio(struct sfs_vnode *sv, off_t actualpos, void *data, size_t len,
if (rw == UIO_READ) { if (rw == UIO_READ) {
/* Copy out the selected region */ /* Copy out the selected region */
memcpy(data, metaiobuf + blockoffset, len); memcpy(data, metaiobuf + blockoffset, len);
} } else {
else {
/* Update the selected region */ /* Update the selected region */
memcpy(metaiobuf + blockoffset, data, len); memcpy(metaiobuf + blockoffset, data, len);
/* Write the block back */ /* Write the block back */
result = sfs_writeblock(sfs, diskblock, result = sfs_writeblock(sfs, diskblock, metaiobuf, sizeof(metaiobuf));
metaiobuf, sizeof(metaiobuf));
if (result) { if (result) {
return result; return result;
} }

View File

@@ -48,10 +48,7 @@
/* /*
* This is called on *each* open(). * This is called on *each* open().
*/ */
static static int sfs_eachopen(struct vnode *v, int openflags) {
int
sfs_eachopen(struct vnode *v, int openflags)
{
/* /*
* At this level we do not need to handle O_CREAT, O_EXCL, * At this level we do not need to handle O_CREAT, O_EXCL,
* O_TRUNC, or O_APPEND. * O_TRUNC, or O_APPEND.
@@ -70,10 +67,7 @@ sfs_eachopen(struct vnode *v, int openflags)
* This is called on *each* open() of a directory. * This is called on *each* open() of a directory.
* Directories may only be open for read. * Directories may only be open for read.
*/ */
static static int sfs_eachopendir(struct vnode *v, int openflags) {
int
sfs_eachopendir(struct vnode *v, int openflags)
{
switch (openflags & O_ACCMODE) { switch (openflags & O_ACCMODE) {
case O_RDONLY: case O_RDONLY:
break; break;
@@ -93,10 +87,7 @@ sfs_eachopendir(struct vnode *v, int openflags)
/* /*
* Called for read(). sfs_io() does the work. * Called for read(). sfs_io() does the work.
*/ */
static static int sfs_read(struct vnode *v, struct uio *uio) {
int
sfs_read(struct vnode *v, struct uio *uio)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
int result; int result;
@@ -112,10 +103,7 @@ sfs_read(struct vnode *v, struct uio *uio)
/* /*
* Called for write(). sfs_io() does the work. * Called for write(). sfs_io() does the work.
*/ */
static static int sfs_write(struct vnode *v, struct uio *uio) {
int
sfs_write(struct vnode *v, struct uio *uio)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
int result; int result;
@@ -131,10 +119,7 @@ sfs_write(struct vnode *v, struct uio *uio)
/* /*
* Called for ioctl() * Called for ioctl()
*/ */
static static int sfs_ioctl(struct vnode *v, int op, userptr_t data) {
int
sfs_ioctl(struct vnode *v, int op, userptr_t data)
{
/* /*
* No ioctls. * No ioctls.
*/ */
@@ -149,10 +134,7 @@ sfs_ioctl(struct vnode *v, int op, userptr_t data)
/* /*
* Called for stat/fstat/lstat. * Called for stat/fstat/lstat.
*/ */
static static int sfs_stat(struct vnode *v, struct stat *statbuf) {
int
sfs_stat(struct vnode *v, struct stat *statbuf)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
int result; int result;
@@ -178,10 +160,7 @@ sfs_stat(struct vnode *v, struct stat *statbuf)
/* /*
* Return the type of the file (types as per kern/stat.h) * Return the type of the file (types as per kern/stat.h)
*/ */
static static int sfs_gettype(struct vnode *v, uint32_t *ret) {
int
sfs_gettype(struct vnode *v, uint32_t *ret)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
struct sfs_fs *sfs = v->vn_fs->fs_data; struct sfs_fs *sfs = v->vn_fs->fs_data;
@@ -205,10 +184,7 @@ sfs_gettype(struct vnode *v, uint32_t *ret)
/* /*
* Check if seeking is allowed. The answer is "yes". * Check if seeking is allowed. The answer is "yes".
*/ */
static static bool sfs_isseekable(struct vnode *v) {
bool
sfs_isseekable(struct vnode *v)
{
(void)v; (void)v;
return true; return true;
} }
@@ -217,10 +193,7 @@ sfs_isseekable(struct vnode *v)
* Called for fsync(), and also on filesystem unmount, global sync(), * Called for fsync(), and also on filesystem unmount, global sync(),
* and some other cases. * and some other cases.
*/ */
static static int sfs_fsync(struct vnode *v) {
int
sfs_fsync(struct vnode *v)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
int result; int result;
@@ -234,10 +207,7 @@ sfs_fsync(struct vnode *v)
/* /*
* Called for mmap(). * Called for mmap().
*/ */
static static int sfs_mmap(struct vnode *v /* add stuff as needed */) {
int
sfs_mmap(struct vnode *v /* add stuff as needed */)
{
(void)v; (void)v;
return ENOSYS; return ENOSYS;
} }
@@ -245,10 +215,7 @@ sfs_mmap(struct vnode *v /* add stuff as needed */)
/* /*
* Truncate a file. * Truncate a file.
*/ */
static static int sfs_truncate(struct vnode *v, off_t len) {
int
sfs_truncate(struct vnode *v, off_t len)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
return sfs_itrunc(sv, len); return sfs_itrunc(sv, len);
@@ -260,10 +227,7 @@ sfs_truncate(struct vnode *v, off_t len)
* and hand back the empty string. (The VFS layer takes care of the * and hand back the empty string. (The VFS layer takes care of the
* device name, leading slash, etc.) * device name, leading slash, etc.)
*/ */
static static int sfs_namefile(struct vnode *vv, struct uio *uio) {
int
sfs_namefile(struct vnode *vv, struct uio *uio)
{
struct sfs_vnode *sv = vv->vn_data; struct sfs_vnode *sv = vv->vn_data;
KASSERT(sv->sv_ino == SFS_ROOTDIR_INO); KASSERT(sv->sv_ino == SFS_ROOTDIR_INO);
@@ -278,11 +242,8 @@ sfs_namefile(struct vnode *vv, struct uio *uio)
* Create a file. If EXCL is set, insist that the filename not already * Create a file. If EXCL is set, insist that the filename not already
* exist; otherwise, if it already exists, just open it. * exist; otherwise, if it already exists, just open it.
*/ */
static static int sfs_creat(struct vnode *v, const char *name, bool excl, mode_t mode,
int struct vnode **ret) {
sfs_creat(struct vnode *v, const char *name, bool excl, mode_t mode,
struct vnode **ret)
{
struct sfs_fs *sfs = v->vn_fs->fs_data; struct sfs_fs *sfs = v->vn_fs->fs_data;
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
struct sfs_vnode *newguy; struct sfs_vnode *newguy;
@@ -351,10 +312,7 @@ sfs_creat(struct vnode *v, const char *name, bool excl, mode_t mode,
* The VFS layer should prevent this being called unless both * The VFS layer should prevent this being called unless both
* vnodes are ours. * vnodes are ours.
*/ */
static static int sfs_link(struct vnode *dir, const char *name, struct vnode *file) {
int
sfs_link(struct vnode *dir, const char *name, struct vnode *file)
{
struct sfs_vnode *sv = dir->vn_data; struct sfs_vnode *sv = dir->vn_data;
struct sfs_vnode *f = file->vn_data; struct sfs_vnode *f = file->vn_data;
int result; int result;
@@ -387,10 +345,7 @@ sfs_link(struct vnode *dir, const char *name, struct vnode *file)
/* /*
* Delete a file. * Delete a file.
*/ */
static static int sfs_remove(struct vnode *dir, const char *name) {
int
sfs_remove(struct vnode *dir, const char *name)
{
struct sfs_vnode *sv = dir->vn_data; struct sfs_vnode *sv = dir->vn_data;
struct sfs_vnode *victim; struct sfs_vnode *victim;
int slot; int slot;
@@ -427,11 +382,8 @@ sfs_remove(struct vnode *dir, const char *name)
* Since we don't support subdirectories, assumes that the two * Since we don't support subdirectories, assumes that the two
* directories passed are the same. * directories passed are the same.
*/ */
static static int sfs_rename(struct vnode *d1, const char *n1, struct vnode *d2,
int const char *n2) {
sfs_rename(struct vnode *d1, const char *n1,
struct vnode *d2, const char *n2)
{
struct sfs_vnode *sv = d1->vn_data; struct sfs_vnode *sv = d1->vn_data;
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data; struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
struct sfs_vnode *g1; struct sfs_vnode *g1;
@@ -496,12 +448,10 @@ sfs_rename(struct vnode *d1, const char *n1,
*/ */
result2 = sfs_dir_unlink(sv, slot2); result2 = sfs_dir_unlink(sv, slot2);
if (result2) { if (result2) {
kprintf("sfs: %s: rename: %s\n", kprintf("sfs: %s: rename: %s\n", sfs->sfs_sb.sb_volname, strerror(result));
sfs->sfs_sb.sb_volname, strerror(result)); kprintf("sfs: %s: rename: while cleaning up: %s\n", sfs->sfs_sb.sb_volname,
kprintf("sfs: %s: rename: while cleaning up: %s\n", strerror(result2));
sfs->sfs_sb.sb_volname, strerror(result2)); panic("sfs: %s: rename: Cannot recover\n", sfs->sfs_sb.sb_volname);
panic("sfs: %s: rename: Cannot recover\n",
sfs->sfs_sb.sb_volname);
} }
g1->sv_i.sfi_linkcount--; g1->sv_i.sfi_linkcount--;
puke: puke:
@@ -518,11 +468,8 @@ sfs_rename(struct vnode *d1, const char *n1,
* Since we don't support subdirectories, this is very easy - * Since we don't support subdirectories, this is very easy -
* return the root dir and copy the path. * return the root dir and copy the path.
*/ */
static static int sfs_lookparent(struct vnode *v, char *path, struct vnode **ret,
int char *buf, size_t buflen) {
sfs_lookparent(struct vnode *v, char *path, struct vnode **ret,
char *buf, size_t buflen)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
vfs_biglock_acquire(); vfs_biglock_acquire();
@@ -551,10 +498,7 @@ sfs_lookparent(struct vnode *v, char *path, struct vnode **ret,
* Since we don't support subdirectories, it's easy - just look up the * Since we don't support subdirectories, it's easy - just look up the
* name. * name.
*/ */
static static int sfs_lookup(struct vnode *v, char *path, struct vnode **ret) {
int
sfs_lookup(struct vnode *v, char *path, struct vnode **ret)
{
struct sfs_vnode *sv = v->vn_data; struct sfs_vnode *sv = v->vn_data;
struct sfs_vnode *final; struct sfs_vnode *final;
int result; int result;

View File

@@ -32,7 +32,6 @@
#include <uio.h> /* for uio_rw */ #include <uio.h> /* for uio_rw */
/* ops tables (in sfs_vnops.c) */ /* ops tables (in sfs_vnops.c) */
extern const struct vnode_ops sfs_fileops; extern const struct vnode_ops sfs_fileops;
extern const struct vnode_ops sfs_dirops; extern const struct vnode_ops sfs_dirops;
@@ -41,7 +40,6 @@ extern const struct vnode_ops sfs_dirops;
#define SFSUIO(iov, uio, ptr, block, rw) \ #define SFSUIO(iov, uio, ptr, block, rw) \
uio_kinit(iov, uio, ptr, SFS_BLOCKSIZE, ((off_t)(block)) * SFS_BLOCKSIZE, rw) uio_kinit(iov, uio, ptr, SFS_BLOCKSIZE, ((off_t)(block)) * SFS_BLOCKSIZE, rw)
/* Functions in sfs_balloc.c */ /* Functions in sfs_balloc.c */
int sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock); int sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock);
void sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock); void sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock);
@@ -53,13 +51,12 @@ int sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
int sfs_itrunc(struct sfs_vnode *sv, off_t len); int sfs_itrunc(struct sfs_vnode *sv, off_t len);
/* Functions in sfs_dir.c */ /* Functions in sfs_dir.c */
int sfs_dir_findname(struct sfs_vnode *sv, const char *name, int sfs_dir_findname(struct sfs_vnode *sv, const char *name, uint32_t *ino,
uint32_t *ino, int *slot, int *emptyslot); int *slot, int *emptyslot);
int sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino, int sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino,
int *slot); int *slot);
int sfs_dir_unlink(struct sfs_vnode *sv, int slot); int sfs_dir_unlink(struct sfs_vnode *sv, int slot);
int sfs_lookonce(struct sfs_vnode *sv, const char *name, int sfs_lookonce(struct sfs_vnode *sv, const char *name, struct sfs_vnode **ret,
struct sfs_vnode **ret,
int *slot); int *slot);
/* Functions in sfs_inode.c */ /* Functions in sfs_inode.c */
@@ -77,5 +74,4 @@ int sfs_io(struct sfs_vnode *sv, struct uio *uio);
int sfs_metaio(struct sfs_vnode *sv, off_t pos, void *data, size_t len, int sfs_metaio(struct sfs_vnode *sv, off_t pos, void *data, size_t len,
enum uio_rw rw); enum uio_rw rw);
#endif /* _SFSPRIVATE_H_ */ #endif /* _SFSPRIVATE_H_ */

View File

@@ -34,13 +34,11 @@
* Address space structure and operations. * Address space structure and operations.
*/ */
#include <vm.h> #include <vm.h>
#include "opt-dumbvm.h" #include "opt-dumbvm.h"
struct vnode; struct vnode;
/* /*
* Address space - data structure associated with the virtual memory * Address space - data structure associated with the virtual memory
* space of a process. * space of a process.
@@ -109,16 +107,12 @@ void as_activate(void);
void as_deactivate(void); void as_deactivate(void);
void as_destroy(struct addrspace *); void as_destroy(struct addrspace *);
int as_define_region(struct addrspace *as, int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
vaddr_t vaddr, size_t sz, int readable, int writeable, int executable);
int readable,
int writeable,
int executable);
int as_prepare_load(struct addrspace *as); int as_prepare_load(struct addrspace *as);
int as_complete_load(struct addrspace *as); int as_complete_load(struct addrspace *as);
int as_define_stack(struct addrspace *as, vaddr_t *initstackptr); int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
/* /*
* Functions in loadelf.c * Functions in loadelf.c
* load_elf - load an ELF user program executable into the current * load_elf - load an ELF user program executable into the current
@@ -128,5 +122,4 @@ int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
int load_elf(struct vnode *v, vaddr_t *entrypoint); int load_elf(struct vnode *v, vaddr_t *entrypoint);
#endif /* _ADDRSPACE_H_ */ #endif /* _ADDRSPACE_H_ */

View File

@@ -88,29 +88,19 @@ void array_remove(struct array *, unsigned index);
* Inlining for base operations * Inlining for base operations
*/ */
ARRAYINLINE unsigned ARRAYINLINE unsigned array_num(const struct array *a) { return a->num; }
array_num(const struct array *a)
{
return a->num;
}
ARRAYINLINE void * ARRAYINLINE void *array_get(const struct array *a, unsigned index) {
array_get(const struct array *a, unsigned index)
{
ARRAYASSERT(index < a->num); ARRAYASSERT(index < a->num);
return a->v[index]; return a->v[index];
} }
ARRAYINLINE void ARRAYINLINE void array_set(const struct array *a, unsigned index, void *val) {
array_set(const struct array *a, unsigned index, void *val)
{
ARRAYASSERT(index < a->num); ARRAYASSERT(index < a->num);
a->v[index] = val; a->v[index] = val;
} }
ARRAYINLINE int ARRAYINLINE int array_add(struct array *a, void *val, unsigned *index_ret) {
array_add(struct array *a, void *val, unsigned *index_ret)
{
unsigned index; unsigned index;
int ret; int ret;
@@ -183,9 +173,7 @@ array_add(struct array *a, void *val, unsigned *index_ret)
INLINE void ARRAY##_remove(struct ARRAY *a, unsigned index) INLINE void ARRAY##_remove(struct ARRAY *a, unsigned index)
#define DEFARRAY_BYTYPE(ARRAY, T, INLINE) \ #define DEFARRAY_BYTYPE(ARRAY, T, INLINE) \
INLINE struct ARRAY * \ INLINE struct ARRAY *ARRAY##_create(void) { \
ARRAY##_create(void) \
{ \
struct ARRAY *a = kmalloc(sizeof(*a)); \ struct ARRAY *a = kmalloc(sizeof(*a)); \
if (a == NULL) { \ if (a == NULL) { \
return NULL; \ return NULL; \
@@ -194,64 +182,40 @@ array_add(struct array *a, void *val, unsigned *index_ret)
return a; \ return a; \
} \ } \
\ \
INLINE void \ INLINE void ARRAY##_destroy(struct ARRAY *a) { \
ARRAY##_destroy(struct ARRAY *a) \
{ \
array_cleanup(&a->arr); \ array_cleanup(&a->arr); \
kfree(a); \ kfree(a); \
} \ } \
\ \
INLINE void \ INLINE void ARRAY##_init(struct ARRAY *a) { array_init(&a->arr); } \
ARRAY##_init(struct ARRAY *a) \
{ \
array_init(&a->arr); \
} \
\ \
INLINE void \ INLINE void ARRAY##_cleanup(struct ARRAY *a) { array_cleanup(&a->arr); } \
ARRAY##_cleanup(struct ARRAY *a) \
{ \
array_cleanup(&a->arr); \
} \
\ \
INLINE unsigned \ INLINE unsigned ARRAY##_num(const struct ARRAY *a) { \
ARRAY##_num(const struct ARRAY *a) \
{ \
return array_num(&a->arr); \ return array_num(&a->arr); \
} \ } \
\ \
INLINE T * \ INLINE T *ARRAY##_get(const struct ARRAY *a, unsigned index) { \
ARRAY##_get(const struct ARRAY *a, unsigned index) \
{ \
return (T *)array_get(&a->arr, index); \ return (T *)array_get(&a->arr, index); \
} \ } \
\ \
INLINE void \ INLINE void ARRAY##_set(struct ARRAY *a, unsigned index, T *val) { \
ARRAY##_set(struct ARRAY *a, unsigned index, T *val) \
{ \
array_set(&a->arr, index, (void *)val); \ array_set(&a->arr, index, (void *)val); \
} \ } \
\ \
INLINE int \ INLINE int ARRAY##_preallocate(struct ARRAY *a, unsigned num) { \
ARRAY##_preallocate(struct ARRAY *a, unsigned num) \
{ \
return array_preallocate(&a->arr, num); \ return array_preallocate(&a->arr, num); \
} \ } \
\ \
INLINE int \ INLINE int ARRAY##_setsize(struct ARRAY *a, unsigned num) { \
ARRAY##_setsize(struct ARRAY *a, unsigned num) \
{ \
return array_setsize(&a->arr, num); \ return array_setsize(&a->arr, num); \
} \ } \
\ \
INLINE int \ INLINE int ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret) { \
ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret) \
{ \
return array_add(&a->arr, (void *)val, index_ret); \ return array_add(&a->arr, (void *)val, index_ret); \
} \ } \
\ \
INLINE void \ INLINE void ARRAY##_remove(struct ARRAY *a, unsigned index) { \
ARRAY##_remove(struct ARRAY *a, unsigned index) \
{ \
array_remove(&a->arr, index); \ array_remove(&a->arr, index); \
} }
@@ -265,5 +229,4 @@ array_add(struct array *a, void *val, unsigned *index_ret)
DECLARRAY_BYTYPE(stringarray, char, ARRAYINLINE); DECLARRAY_BYTYPE(stringarray, char, ARRAYINLINE);
DEFARRAY_BYTYPE(stringarray, char, ARRAYINLINE); DEFARRAY_BYTYPE(stringarray, char, ARRAYINLINE);
#endif /* ARRAY_H */ #endif /* ARRAY_H */

View File

@@ -44,7 +44,6 @@
* bitmap_destroy - destroy bitmap. * bitmap_destroy - destroy bitmap.
*/ */
struct bitmap; /* Opaque. */ struct bitmap; /* Opaque. */
struct bitmap *bitmap_create(unsigned nbits); struct bitmap *bitmap_create(unsigned nbits);
@@ -55,5 +54,4 @@ void bitmap_unmark(struct bitmap *, unsigned index);
int bitmap_isset(struct bitmap *, unsigned index); int bitmap_isset(struct bitmap *, unsigned index);
void bitmap_destroy(struct bitmap *); void bitmap_destroy(struct bitmap *);
#endif /* _BITMAP_H_ */ #endif /* _BITMAP_H_ */

Some files were not shown because too many files have changed in this diff Show More