clang-format
This commit is contained in:
2
.clang-format
Normal file
2
.clang-format
Normal file
@@ -0,0 +1,2 @@
|
||||
IncludeBlocks: Preserve
|
||||
SortIncludes: Never
|
||||
@@ -43,9 +43,7 @@
|
||||
* is less than either x or y (the choice to compare with x or y is
|
||||
* arbitrary).
|
||||
*/
|
||||
long long
|
||||
__adddi3(long long a, long long b)
|
||||
{
|
||||
long long __adddi3(long long a, long long b) {
|
||||
union uu aa, bb, sum;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Return a & b, in long long.
|
||||
*/
|
||||
long long
|
||||
__anddi3(long long a, long long b)
|
||||
{
|
||||
long long __anddi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
* Shift a (signed) long long value left (arithmetic shift left).
|
||||
* This is the same as logical shift left!
|
||||
*/
|
||||
long long
|
||||
__ashldi3(long long a, unsigned int shift)
|
||||
{
|
||||
long long __ashldi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
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[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) |
|
||||
(aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Shift a (signed) long long value right (arithmetic shift right).
|
||||
*/
|
||||
long long
|
||||
__ashrdi3(long long a, unsigned int shift)
|
||||
{
|
||||
long long __ashrdi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
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[H] = s;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) |
|
||||
(aa.ui[H] << (INT_BITS - shift));
|
||||
aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
|
||||
/* LINTED inherits machine dependency */
|
||||
aa.si[H] >>= shift;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,14 @@
|
||||
* Both a and b are considered signed---which means only the high word is
|
||||
* signed.
|
||||
*/
|
||||
int
|
||||
__cmpdi2(long long a, long long b)
|
||||
{
|
||||
int __cmpdi2(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
bb.ll = b;
|
||||
return (aa.si[H] < bb.si[H] ? 0 : aa.si[H] > bb.si[H] ? 2 :
|
||||
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1);
|
||||
return (aa.si[H] < bb.si[H] ? 0
|
||||
: aa.si[H] > bb.si[H] ? 2
|
||||
: aa.ui[L] < bb.ui[L] ? 0
|
||||
: aa.ui[L] > bb.ui[L] ? 2
|
||||
: 1);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
* Divide two signed long longs.
|
||||
* ??? if -1/2 should produce -1 on this machine, this code is wrong
|
||||
*/
|
||||
long long
|
||||
__divdi3(long long a, long long b)
|
||||
{
|
||||
long long __divdi3(long long a, long long b) {
|
||||
unsigned long long ua, ub, uq;
|
||||
int neg = 0;
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Return a | b, in long long.
|
||||
*/
|
||||
long long
|
||||
__iordi3(long long a, long long b)
|
||||
{
|
||||
long long __iordi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -87,7 +87,6 @@ union uu {
|
||||
#define L 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
* Shift an (unsigned) long long value left (logical shift left).
|
||||
* This is the same as arithmetic shift left!
|
||||
*/
|
||||
long long
|
||||
__lshldi3(long long a, unsigned int shift)
|
||||
{
|
||||
long long __lshldi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
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[L] = 0;
|
||||
} else {
|
||||
aa.ui[H] = (aa.ui[H] << shift) |
|
||||
(aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[H] = (aa.ui[H] << shift) | (aa.ui[L] >> (INT_BITS - shift));
|
||||
aa.ui[L] <<= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Shift an (unsigned) long long value right (logical shift right).
|
||||
*/
|
||||
long long
|
||||
__lshrdi3(long long a, unsigned int shift)
|
||||
{
|
||||
long long __lshrdi3(long long a, unsigned int shift) {
|
||||
union uu aa;
|
||||
|
||||
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[H] = 0;
|
||||
} else {
|
||||
aa.ui[L] = (aa.ui[L] >> shift) |
|
||||
(aa.ui[H] << (INT_BITS - shift));
|
||||
aa.ui[L] = (aa.ui[L] >> shift) | (aa.ui[H] << (INT_BITS - shift));
|
||||
aa.ui[H] >>= shift;
|
||||
}
|
||||
return (aa.ll);
|
||||
|
||||
@@ -42,9 +42,7 @@
|
||||
*
|
||||
* XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent.
|
||||
*/
|
||||
long long
|
||||
__moddi3(long long a, long long b)
|
||||
{
|
||||
long long __moddi3(long long a, long long b) {
|
||||
unsigned long long ua, ub, ur;
|
||||
int neg = 0;
|
||||
|
||||
|
||||
@@ -96,9 +96,7 @@
|
||||
*/
|
||||
static long long __lmulq(unsigned int, unsigned int);
|
||||
|
||||
long long
|
||||
__muldi3(long long a, long long b)
|
||||
{
|
||||
long long __muldi3(long long a, long long b) {
|
||||
union uu u, v, low, prod;
|
||||
unsigned int high, mid, udiff, vdiff;
|
||||
int negall, negmid;
|
||||
@@ -152,8 +150,7 @@ __muldi3(long long a, long long b)
|
||||
/*
|
||||
* Assemble the final product.
|
||||
*/
|
||||
prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] +
|
||||
low.ui[H];
|
||||
prod.ui[H] = high + (negmid ? -mid : mid) + low.ui[L] + low.ui[H];
|
||||
prod.ui[L] = low.ui[L];
|
||||
}
|
||||
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.
|
||||
*/
|
||||
static long long
|
||||
__lmulq(unsigned int u, unsigned int v)
|
||||
{
|
||||
static long long __lmulq(unsigned int u, unsigned int v) {
|
||||
unsigned int u1, u0, v1, v0, udiff, vdiff, high, mid, low;
|
||||
unsigned int prodh, prodl, was;
|
||||
union uu prod;
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Return -a (or, equivalently, 0 - a), in long long. See subdi3.c.
|
||||
*/
|
||||
long long
|
||||
__negdi2(long long a)
|
||||
{
|
||||
long long __negdi2(long long a) {
|
||||
union uu aa, res;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -41,9 +41,7 @@
|
||||
* Return ~a. For some reason gcc calls this `one's complement' rather
|
||||
* than `not'.
|
||||
*/
|
||||
long long
|
||||
__one_cmpldi2(long long a)
|
||||
{
|
||||
long long __one_cmpldi2(long long a) {
|
||||
union uu aa;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -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
|
||||
* shorter if they have leading zeros).
|
||||
*/
|
||||
unsigned long long
|
||||
__qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
unsigned long long *arq)
|
||||
{
|
||||
unsigned long long __qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
unsigned long long *arq) {
|
||||
union uu tmp;
|
||||
digit *u, *v, *q;
|
||||
digit v1, v2;
|
||||
@@ -248,8 +246,7 @@ __qdivrem(unsigned long long ull, unsigned long long vll,
|
||||
if (d) {
|
||||
for (i = m + n; i > m; --i)
|
||||
u[i] = (digit)(((unsigned int)u[i] >> d) |
|
||||
LHALF((unsigned int)u[i - 1] <<
|
||||
(HALF_BITS - d)));
|
||||
LHALF((unsigned int)u[i - 1] << (HALF_BITS - d)));
|
||||
u[i] = 0;
|
||||
}
|
||||
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).
|
||||
* We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS.
|
||||
*/
|
||||
static void
|
||||
shl(digit *p, int len, int sh)
|
||||
{
|
||||
static void shl(digit *p, int len, int sh) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
|
||||
@@ -42,9 +42,7 @@
|
||||
* carry from a single unsigned int difference x-y occurs if and only
|
||||
* if (x-y) > x.
|
||||
*/
|
||||
long long
|
||||
__subdi3(long long a, long long b)
|
||||
{
|
||||
long long __subdi3(long long a, long long b) {
|
||||
union uu aa, bb, diff;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -41,13 +41,14 @@
|
||||
* Return 0, 1, or 2 as a <, =, > b respectively.
|
||||
* Neither a nor b are considered signed.
|
||||
*/
|
||||
int
|
||||
__ucmpdi2(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
int __ucmpdi2(unsigned long long a, unsigned long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ull = a;
|
||||
bb.ull = b;
|
||||
return (aa.ui[H] < bb.ui[H] ? 0 : aa.ui[H] > bb.ui[H] ? 2 :
|
||||
aa.ui[L] < bb.ui[L] ? 0 : aa.ui[L] > bb.ui[L] ? 2 : 1);
|
||||
return (aa.ui[H] < bb.ui[H] ? 0
|
||||
: aa.ui[H] > bb.ui[H] ? 2
|
||||
: aa.ui[L] < bb.ui[L] ? 0
|
||||
: aa.ui[L] > bb.ui[L] ? 2
|
||||
: 1);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Divide two unsigned long longs.
|
||||
*/
|
||||
unsigned long long
|
||||
__udivdi3(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
unsigned long long __udivdi3(unsigned long long a, unsigned long long b) {
|
||||
|
||||
return __qdivrem(a, b, NULL);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Return remainder after dividing two unsigned long longs.
|
||||
*/
|
||||
unsigned long long
|
||||
__umoddi3(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
unsigned long long __umoddi3(unsigned long long a, unsigned long long b) {
|
||||
unsigned long long r;
|
||||
|
||||
(void)__qdivrem(a, b, &r);
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Return a ^ b, in long long.
|
||||
*/
|
||||
long long
|
||||
__xordi3(long long a, long long b)
|
||||
{
|
||||
long long __xordi3(long long a, long long b) {
|
||||
union uu aa, bb;
|
||||
|
||||
aa.ll = a;
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/*
|
||||
* Do we want to support "long long" types with %lld?
|
||||
*
|
||||
@@ -72,7 +71,6 @@
|
||||
#define INTTYPE long
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Space for a long long in base 8, plus a NUL, plus one
|
||||
* 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,
|
||||
* since that's what most printf-like functions want to return.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_print(PF *pf, const char *txt, size_t len)
|
||||
{
|
||||
static void __pf_print(PF *pf, const char *txt, size_t len) {
|
||||
pf->sendfunc(pf->clientdata, txt, 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.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_endfield(PF *pf)
|
||||
{
|
||||
static void __pf_endfield(PF *pf) {
|
||||
pf->in_pct = 0;
|
||||
pf->size = INTSZ;
|
||||
pf->num = 0;
|
||||
@@ -177,10 +169,7 @@ __pf_endfield(PF *pf)
|
||||
* 0-9 field width
|
||||
* leading 0 pad with zeros instead of spaces
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_modifier(PF *pf, int ch)
|
||||
{
|
||||
static void __pf_modifier(PF *pf, int ch) {
|
||||
switch (ch) {
|
||||
case '#':
|
||||
pf->altformat = 1;
|
||||
@@ -193,8 +182,7 @@ __pf_modifier(PF *pf, int ch)
|
||||
#ifdef USE_LONGLONG
|
||||
pf->size = LLONGSZ;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pf->size = LONGSZ;
|
||||
}
|
||||
break;
|
||||
@@ -208,8 +196,7 @@ __pf_modifier(PF *pf, int ch)
|
||||
* field size.
|
||||
*/
|
||||
pf->spacing = pf->spacing * 10;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* 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
|
||||
* the numeric type specified by ch.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_getnum(PF *pf, int ch)
|
||||
{
|
||||
static void __pf_getnum(PF *pf, int ch) {
|
||||
if (ch == 'p') {
|
||||
/*
|
||||
* Pointer.
|
||||
@@ -249,8 +233,7 @@ __pf_getnum(PF *pf, int ch)
|
||||
* integer the same size as a pointer.
|
||||
*/
|
||||
pf->num = (uintptr_t)va_arg(pf->ap, void *);
|
||||
}
|
||||
else if (ch=='d') {
|
||||
} else if (ch == 'd') {
|
||||
/* signed integer */
|
||||
INTTYPE signednum = 0;
|
||||
switch (pf->size) {
|
||||
@@ -280,12 +263,10 @@ __pf_getnum(PF *pf, int ch)
|
||||
if (signednum < 0) {
|
||||
pf->sign = -1;
|
||||
pf->num = -signednum;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pf->num = signednum;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* unsigned integer */
|
||||
switch (pf->size) {
|
||||
case INTSZ:
|
||||
@@ -320,10 +301,7 @@ __pf_getnum(PF *pf, int ch)
|
||||
* If the "alternate format" was requested, or always for pointers,
|
||||
* note to print the C prefix for the type.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_setbase(PF *pf, int ch)
|
||||
{
|
||||
static void __pf_setbase(PF *pf, int ch) {
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
case 'u':
|
||||
@@ -345,10 +323,7 @@ __pf_setbase(PF *pf, int ch)
|
||||
/*
|
||||
* Function to print "spc" instances of the fill character.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_fill(PF *pf, int spc)
|
||||
{
|
||||
static void __pf_fill(PF *pf, int spc) {
|
||||
char f = pf->fillchar;
|
||||
int 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
|
||||
* *before* zero padding, if padding is on the left.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_printstuff(PF *pf,
|
||||
const char *prefix, const char *prefix2,
|
||||
const char *stuff)
|
||||
{
|
||||
static void __pf_printstuff(PF *pf, const char *prefix, const char *prefix2,
|
||||
const char *stuff) {
|
||||
/* Total length to print. */
|
||||
int len = strlen(prefix) + strlen(prefix2) + strlen(stuff);
|
||||
|
||||
@@ -375,8 +346,7 @@ __pf_printstuff(PF *pf,
|
||||
int spc = pf->spacing;
|
||||
if (spc > len) {
|
||||
spc -= len;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
spc = 0;
|
||||
}
|
||||
|
||||
@@ -410,10 +380,7 @@ __pf_printstuff(PF *pf,
|
||||
* NUMBER_BUF_SIZE is set so that the longest number string we can
|
||||
* generate (a long long printed in octal) will fit. See above.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_printnum(PF *pf)
|
||||
{
|
||||
static void __pf_printnum(PF *pf) {
|
||||
/* Digits to print with. */
|
||||
const char *const digits = "0123456789abcdef";
|
||||
|
||||
@@ -471,11 +438,9 @@ __pf_printnum(PF *pf)
|
||||
*/
|
||||
if (pf->baseprefix && pf->base == 16) {
|
||||
bprefix = "0x";
|
||||
}
|
||||
else if (pf->baseprefix && pf->base==8) {
|
||||
} else if (pf->baseprefix && pf->base == 8) {
|
||||
bprefix = "0";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bprefix = "";
|
||||
}
|
||||
|
||||
@@ -493,10 +458,7 @@ __pf_printnum(PF *pf)
|
||||
/*
|
||||
* Process a single character out of the format string.
|
||||
*/
|
||||
static
|
||||
void
|
||||
__pf_send(PF *pf, int ch)
|
||||
{
|
||||
static void __pf_send(PF *pf, int ch) {
|
||||
/* Cannot get NULs here. */
|
||||
assert(ch != 0);
|
||||
|
||||
@@ -507,21 +469,18 @@ __pf_send(PF *pf, int ch)
|
||||
*/
|
||||
char c = ch;
|
||||
__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.
|
||||
*/
|
||||
pf->in_pct = 1;
|
||||
}
|
||||
else if (strchr("#-lz0123456789", ch)) {
|
||||
} else if (strchr("#-lz0123456789", ch)) {
|
||||
/*
|
||||
* These are the modifier characters we recognize.
|
||||
* (These are the characters between the % and the type.)
|
||||
*/
|
||||
__pf_modifier(pf, ch);
|
||||
}
|
||||
else if (strchr("doupx", ch)) {
|
||||
} else if (strchr("doupx", ch)) {
|
||||
/*
|
||||
* Integer types.
|
||||
* Fetch the number, set the base, print it, then
|
||||
@@ -531,8 +490,7 @@ __pf_send(PF *pf, int ch)
|
||||
__pf_setbase(pf, ch);
|
||||
__pf_printnum(pf);
|
||||
__pf_endfield(pf);
|
||||
}
|
||||
else if (ch=='s') {
|
||||
} else if (ch == 's') {
|
||||
/*
|
||||
* Print a string.
|
||||
*/
|
||||
@@ -542,8 +500,7 @@ __pf_send(PF *pf, int ch)
|
||||
}
|
||||
__pf_printstuff(pf, "", "", str);
|
||||
__pf_endfield(pf);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* %%, %c, or illegal character.
|
||||
* Illegal characters are printed like %%.
|
||||
@@ -552,8 +509,7 @@ __pf_send(PF *pf, int ch)
|
||||
char x[2];
|
||||
if (ch == 'c') {
|
||||
x[0] = va_arg(pf->ap, int);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
x[0] = ch;
|
||||
}
|
||||
x[1] = 0;
|
||||
@@ -567,10 +523,8 @@ __pf_send(PF *pf, int ch)
|
||||
* Create and initialize a printf state object,
|
||||
* then send it each character from the format string.
|
||||
*/
|
||||
int
|
||||
__vprintf(void (*func)(void *clientdata, const char *str, size_t len),
|
||||
void *clientdata, const char *format, va_list ap)
|
||||
{
|
||||
int __vprintf(void (*func)(void *clientdata, const char *str, size_t len),
|
||||
void *clientdata, const char *format, va_list ap) {
|
||||
PF pf;
|
||||
int i;
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
* Standard C string/IO function: printf into a character buffer.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Context structure for snprintf: buffer to print into, maximum
|
||||
* length, and index of the next character to write.
|
||||
@@ -70,10 +69,7 @@ typedef struct {
|
||||
* null-terminated.
|
||||
*/
|
||||
|
||||
static
|
||||
void
|
||||
__snprintf_send(void *mydata, const char *data, size_t len)
|
||||
{
|
||||
static void __snprintf_send(void *mydata, const char *data, size_t len) {
|
||||
SNP *snp = mydata;
|
||||
unsigned i;
|
||||
|
||||
@@ -95,9 +91,7 @@ __snprintf_send(void *mydata, const char *data, size_t len)
|
||||
/*
|
||||
* The va_list version of snprintf.
|
||||
*/
|
||||
int
|
||||
vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
|
||||
{
|
||||
int vsnprintf(char *buf, size_t len, const char *fmt, va_list ap) {
|
||||
int chars;
|
||||
SNP snp;
|
||||
|
||||
@@ -111,8 +105,7 @@ vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
|
||||
snp.buf = buf;
|
||||
if (len == 0) {
|
||||
snp.buflen = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
snp.buflen = len - 1;
|
||||
}
|
||||
snp.bufpos = 0;
|
||||
@@ -144,9 +137,7 @@ vsnprintf(char *buf, size_t len, const char *fmt, va_list ap)
|
||||
/*
|
||||
* snprintf - hand off to vsnprintf.
|
||||
*/
|
||||
int
|
||||
snprintf(char *buf, size_t len, const char *fmt, ...)
|
||||
{
|
||||
int snprintf(char *buf, size_t len, const char *fmt, ...) {
|
||||
int chars;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
@@ -154,4 +145,3 @@ snprintf(char *buf, size_t len, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
return chars;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
* really report syntax errors or overflow in any useful way.
|
||||
*/
|
||||
|
||||
int
|
||||
atoi(const char *s)
|
||||
{
|
||||
int atoi(const char *s) {
|
||||
static const char digits[] = "0123456789"; /* legal digits in order */
|
||||
unsigned val = 0; /* value we're accumulating */
|
||||
int neg = 0; /* set to true if we see a minus sign */
|
||||
@@ -62,8 +60,7 @@ atoi(const char *s)
|
||||
if (*s == '-') {
|
||||
neg = 1;
|
||||
s++;
|
||||
}
|
||||
else if (*s=='+') {
|
||||
} else if (*s == '+') {
|
||||
s++;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,7 @@
|
||||
* memory.
|
||||
*/
|
||||
|
||||
void
|
||||
bzero(void *vblock, size_t len)
|
||||
{
|
||||
void bzero(void *vblock, size_t len) {
|
||||
char *block = vblock;
|
||||
size_t i;
|
||||
|
||||
@@ -61,14 +59,12 @@ bzero(void *vblock, size_t len)
|
||||
* divides and moduli out. Fortunately, it is.
|
||||
*/
|
||||
|
||||
if ((uintptr_t)block % sizeof(long) == 0 &&
|
||||
len % sizeof(long) == 0) {
|
||||
if ((uintptr_t)block % sizeof(long) == 0 && len % sizeof(long) == 0) {
|
||||
long *lb = (long *)block;
|
||||
for (i = 0; i < len / sizeof(long); i++) {
|
||||
lb[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (i = 0; i < len; i++) {
|
||||
block[i] = 0;
|
||||
}
|
||||
|
||||
@@ -44,9 +44,7 @@
|
||||
* C standard function - copy a block of memory.
|
||||
*/
|
||||
|
||||
void *
|
||||
memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
void *memcpy(void *dst, const void *src, size_t len) {
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
@@ -63,8 +61,7 @@ memcpy(void *dst, const void *src, size_t len)
|
||||
*/
|
||||
|
||||
if ((uintptr_t)dst % sizeof(long) == 0 &&
|
||||
(uintptr_t)src % sizeof(long) == 0 &&
|
||||
len % sizeof(long) == 0) {
|
||||
(uintptr_t)src % sizeof(long) == 0 && len % sizeof(long) == 0) {
|
||||
|
||||
long *d = dst;
|
||||
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++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
|
||||
@@ -45,9 +45,7 @@
|
||||
* regions correctly.
|
||||
*/
|
||||
|
||||
void *
|
||||
memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
void *memmove(void *dst, const void *src, size_t len) {
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
@@ -89,8 +87,7 @@ memmove(void *dst, const void *src, size_t len)
|
||||
*/
|
||||
|
||||
if ((uintptr_t)dst % sizeof(long) == 0 &&
|
||||
(uintptr_t)src % sizeof(long) == 0 &&
|
||||
len % sizeof(long) == 0) {
|
||||
(uintptr_t)src % sizeof(long) == 0 && len % sizeof(long) == 0) {
|
||||
|
||||
long *d = dst;
|
||||
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--) {
|
||||
d[i - 1] = s[i - 1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
* C standard function - initialize a block of memory
|
||||
*/
|
||||
|
||||
void *
|
||||
memset(void *ptr, int ch, size_t len)
|
||||
{
|
||||
void *memset(void *ptr, int ch, size_t len) {
|
||||
char *p = ptr;
|
||||
size_t i;
|
||||
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
* Standard C string function: append one string to another.
|
||||
*/
|
||||
|
||||
char *
|
||||
strcat(char *dest, const char *src)
|
||||
{
|
||||
char *strcat(char *dest, const char *src) {
|
||||
size_t offset;
|
||||
|
||||
offset = strlen(dest);
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
* C standard string function: find leftmost instance of a character
|
||||
* in a string.
|
||||
*/
|
||||
char *
|
||||
strchr(const char *s, int ch_arg)
|
||||
{
|
||||
char *strchr(const char *s, int ch_arg) {
|
||||
/* avoid sign-extension problems */
|
||||
const char ch = ch_arg;
|
||||
|
||||
|
||||
@@ -44,9 +44,7 @@
|
||||
* sort order.
|
||||
*/
|
||||
|
||||
int
|
||||
strcmp(const char *a, const char *b)
|
||||
{
|
||||
int strcmp(const char *a, const char *b) {
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
@@ -82,8 +80,7 @@ strcmp(const char *a, const char *b)
|
||||
*/
|
||||
if ((unsigned char)a[i] > (unsigned char)b[i]) {
|
||||
return 1;
|
||||
}
|
||||
else if (a[i] == b[i]) {
|
||||
} else if (a[i] == b[i]) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -42,9 +42,7 @@
|
||||
/*
|
||||
* Standard C string function: copy one string to another.
|
||||
*/
|
||||
char *
|
||||
strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *strcpy(char *dest, const char *src) {
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
* C standard string function: get length of a string
|
||||
*/
|
||||
|
||||
size_t
|
||||
strlen(const char *str)
|
||||
{
|
||||
size_t strlen(const char *str) {
|
||||
size_t ret = 0;
|
||||
|
||||
while (str[ret]) {
|
||||
|
||||
@@ -43,9 +43,7 @@
|
||||
* C standard string function: find rightmost instance of a character
|
||||
* in a string.
|
||||
*/
|
||||
char *
|
||||
strrchr(const char *s, int ch_arg)
|
||||
{
|
||||
char *strrchr(const char *s, int ch_arg) {
|
||||
/* avoid sign-extension problems */
|
||||
const char ch = ch_arg;
|
||||
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
* The "context" argument should point to a "char *" that is preserved
|
||||
* between calls to strtok_r that wish to operate on same string.
|
||||
*/
|
||||
char *
|
||||
strtok_r(char *string, const char *seps, char **context)
|
||||
{
|
||||
char *strtok_r(char *string, const char *seps, char **context) {
|
||||
char *head; /* start 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 */
|
||||
if (*tail == 0) {
|
||||
*context = NULL;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*tail = 0;
|
||||
tail++;
|
||||
*context = tail;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#ifndef _MIPS_CURRENT_H_
|
||||
#define _MIPS_CURRENT_H_
|
||||
|
||||
|
||||
/*
|
||||
* Macro for current thread, or current cpu.
|
||||
*
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
* MIPS machine-dependent definitions for the ELF binary format.
|
||||
*/
|
||||
|
||||
|
||||
/* The ELF executable type. */
|
||||
#define EM_MACHINE EM_MIPS
|
||||
|
||||
@@ -54,5 +53,4 @@
|
||||
#define R_MIPS_GPREL32 12 /* s32 offset from GP register */
|
||||
/* %hi/%lo are defined so %hi(sym) << 16 + %lo(sym) = sym */
|
||||
|
||||
|
||||
#endif /* _MIPS_ELF_H_ */
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#ifndef _KERN_MIPS_REGDEFS_H_
|
||||
#define _KERN_MIPS_REGDEFS_H_
|
||||
|
||||
|
||||
#define z0 $0 /* always zero register */
|
||||
#define AT $1 /* assembler temp register */
|
||||
#define v0 $2 /* value 0 */
|
||||
@@ -70,5 +69,4 @@
|
||||
#define s8 $30 /* saved (callee-save) 8 = frame pointer */
|
||||
#define ra $31 /* return address */
|
||||
|
||||
|
||||
#endif /* _KERN_MIPS_REGDEFS_H_ */
|
||||
|
||||
@@ -43,5 +43,4 @@
|
||||
/* A jmp_buf is an array of __JB_REGS registers */
|
||||
typedef uint32_t jmp_buf[__JB_REGS];
|
||||
|
||||
|
||||
#endif /* _MIPS_SETJMP_H_ */
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _KERN_MIPS_SIGNAL_H_
|
||||
#define _KERN_MIPS_SIGNAL_H_
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
* See kern/types.h for an explanation of the underscores.
|
||||
*/
|
||||
|
||||
|
||||
/* Sized integer types, with convenient short names */
|
||||
typedef char __i8; /* 8-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. */
|
||||
#define __CHAR_BIT 8
|
||||
|
||||
|
||||
#endif /* _KERN_MIPS_TYPES_H_ */
|
||||
|
||||
@@ -41,11 +41,8 @@
|
||||
*/
|
||||
|
||||
MEMBAR_INLINE
|
||||
void
|
||||
membar_any_any(void)
|
||||
{
|
||||
__asm volatile(
|
||||
".set push;" /* save assembler mode */
|
||||
void membar_any_any(void) {
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 instructions */
|
||||
"sync;" /* do it */
|
||||
".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_any_store(void) { membar_any_any(); }
|
||||
|
||||
|
||||
#endif /* _MIPS_MEMBAR_H_ */
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#ifndef _MIPS_SPECIALREG_H_
|
||||
#define _MIPS_SPECIALREG_H_
|
||||
|
||||
|
||||
/*
|
||||
* Coprocessor 0 (system processor) register numbers
|
||||
*/
|
||||
@@ -113,5 +112,4 @@
|
||||
#define EXADDR_UTLB 0x80000000
|
||||
#define EXADDR_GENERAL 0x80000080
|
||||
|
||||
|
||||
#endif /* _MIPS_SPECIALREG_H_ */
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include <cdefs.h>
|
||||
|
||||
|
||||
/* Type of value needed to actually spin on */
|
||||
typedef unsigned spinlock_data_t;
|
||||
|
||||
@@ -55,9 +54,7 @@ spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd);
|
||||
* memory.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
void
|
||||
spinlock_data_set(volatile spinlock_data_t *sd, unsigned val)
|
||||
{
|
||||
void spinlock_data_set(volatile spinlock_data_t *sd, unsigned 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.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
spinlock_data_t
|
||||
spinlock_data_get(volatile spinlock_data_t *sd)
|
||||
{
|
||||
return *sd;
|
||||
}
|
||||
spinlock_data_t spinlock_data_get(volatile spinlock_data_t *sd) { return *sd; }
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
SPINLOCK_INLINE
|
||||
spinlock_data_t
|
||||
spinlock_data_testandset(volatile spinlock_data_t *sd)
|
||||
{
|
||||
spinlock_data_t spinlock_data_testandset(volatile spinlock_data_t *sd) {
|
||||
spinlock_data_t x;
|
||||
spinlock_data_t y;
|
||||
|
||||
@@ -104,19 +95,18 @@ spinlock_data_testandset(volatile spinlock_data_t *sd)
|
||||
*/
|
||||
|
||||
y = 1;
|
||||
__asm volatile(
|
||||
".set push;" /* save assembler mode */
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 instructions */
|
||||
".set volatile;" /* avoid unwanted optimization */
|
||||
"ll %0, 0(%2);" /* x = *sd */
|
||||
"sc %1, 0(%2);" /* *sd = y; y = success? */
|
||||
".set pop" /* restore assembler mode */
|
||||
: "=&r" (x), "+r" (y) : "r" (sd));
|
||||
: "=&r"(x), "+r"(y)
|
||||
: "r"(sd));
|
||||
if (y == 0) {
|
||||
return 1;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _MIPS_SPINLOCK_H_ */
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#ifndef _MIPS_THREAD_H_
|
||||
#define _MIPS_THREAD_H_
|
||||
|
||||
|
||||
/*
|
||||
* Machine-dependent thread bits.
|
||||
*/
|
||||
@@ -44,5 +43,4 @@ struct thread_machdep {
|
||||
jmp_buf tm_copyjmp; /* longjmp area used by copyin/out */
|
||||
};
|
||||
|
||||
|
||||
#endif /* _MIPS_THREAD_H_ */
|
||||
|
||||
@@ -101,5 +101,4 @@ int tlb_probe(uint32_t entryhi, uint32_t entrylo);
|
||||
|
||||
#define NUM_TLB 64
|
||||
|
||||
|
||||
#endif /* _MIPS_TLB_H_ */
|
||||
|
||||
@@ -104,5 +104,4 @@ __DEAD void mips_usermode(struct trapframe *tf);
|
||||
extern vaddr_t cpustacks[];
|
||||
extern vaddr_t cputhreads[];
|
||||
|
||||
|
||||
#endif /* _MIPS_TRAPFRAME_H_ */
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#ifndef _MIPS_VM_H_
|
||||
#define _MIPS_VM_H_
|
||||
|
||||
|
||||
/*
|
||||
* Machine-dependent VM system definitions.
|
||||
*/
|
||||
@@ -125,5 +124,4 @@ struct tlbshootdown {
|
||||
|
||||
#define TLBSHOOTDOWN_MAX 16
|
||||
|
||||
|
||||
#endif /* _MIPS_VM_H_ */
|
||||
|
||||
@@ -40,39 +40,26 @@
|
||||
#include <mainbus.h>
|
||||
#include <syscall.h>
|
||||
|
||||
|
||||
/* in exception-*.S */
|
||||
extern __DEAD void asm_usermode(struct trapframe *tf);
|
||||
|
||||
/* called only from assembler, so not declared in a header */
|
||||
void mips_trap(struct trapframe *tf);
|
||||
|
||||
|
||||
/* Names for trap codes */
|
||||
#define NTRAPCODES 13
|
||||
static const char *const trapcodenames[NTRAPCODES] = {
|
||||
"Interrupt",
|
||||
"TLB modify trap",
|
||||
"TLB miss on load",
|
||||
"TLB miss on store",
|
||||
"Address error on load",
|
||||
"Address error on store",
|
||||
"Bus error on code",
|
||||
"Bus error on data",
|
||||
"System call",
|
||||
"Break instruction",
|
||||
"Illegal instruction",
|
||||
"Coprocessor unusable",
|
||||
"Interrupt", "TLB modify trap", "TLB miss on load",
|
||||
"TLB miss on store", "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",
|
||||
};
|
||||
|
||||
/*
|
||||
* Function called when user-level code hits a fatal fault.
|
||||
*/
|
||||
static
|
||||
void
|
||||
kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr)
|
||||
{
|
||||
static void kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr) {
|
||||
int sig = 0;
|
||||
|
||||
KASSERT(code < NTRAPCODES);
|
||||
@@ -112,8 +99,8 @@ kill_curthread(vaddr_t epc, unsigned code, vaddr_t vaddr)
|
||||
* You will probably want to change this.
|
||||
*/
|
||||
|
||||
kprintf("Fatal user mode trap %u sig %d (%s, epc 0x%x, vaddr 0x%x)\n",
|
||||
code, sig, trapcodenames[code], epc, vaddr);
|
||||
kprintf("Fatal user mode trap %u sig %d (%s, epc 0x%x, vaddr 0x%x)\n", code,
|
||||
sig, trapcodenames[code], epc, vaddr);
|
||||
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
|
||||
* the trapframe has been set up.
|
||||
*/
|
||||
void
|
||||
mips_trap(struct trapframe *tf)
|
||||
{
|
||||
void mips_trap(struct trapframe *tf) {
|
||||
uint32_t code;
|
||||
/*bool isutlb; -- not used */
|
||||
bool iskern;
|
||||
@@ -145,8 +130,7 @@ mips_trap(struct trapframe *tf)
|
||||
/* Make sure we haven't run off our stack */
|
||||
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
|
||||
+ STACK_SIZE));
|
||||
KASSERT((vaddr_t)tf < (vaddr_t)(curthread->t_stack + STACK_SIZE));
|
||||
}
|
||||
|
||||
/* Interrupt? Call the interrupt handler and return. */
|
||||
@@ -180,8 +164,7 @@ mips_trap(struct trapframe *tf)
|
||||
curthread->t_curspl = IPL_HIGH;
|
||||
curthread->t_iplhigh_count++;
|
||||
doadjust = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
doadjust = false;
|
||||
}
|
||||
|
||||
@@ -218,8 +201,8 @@ mips_trap(struct trapframe *tf)
|
||||
KASSERT(curthread->t_curspl == 0);
|
||||
KASSERT(curthread->t_iplhigh_count == 0);
|
||||
|
||||
DEBUG(DB_SYSCALL, "syscall: #%d, args %x %x %x %x\n",
|
||||
tf->tf_v0, tf->tf_a0, tf->tf_a1, tf->tf_a2, tf->tf_a3);
|
||||
DEBUG(DB_SYSCALL, "syscall: #%d, args %x %x %x %x\n", tf->tf_v0, tf->tf_a0,
|
||||
tf->tf_a1, tf->tf_a2, tf->tf_a3);
|
||||
|
||||
syscall(tf);
|
||||
goto done;
|
||||
@@ -297,8 +280,7 @@ mips_trap(struct trapframe *tf)
|
||||
* from the exception handler.
|
||||
*/
|
||||
|
||||
if (curthread != NULL &&
|
||||
curthread->t_machdep.tm_badfaultfunc != NULL) {
|
||||
if (curthread != NULL && curthread->t_machdep.tm_badfaultfunc != NULL) {
|
||||
tf->tf_epc = (vaddr_t)curthread->t_machdep.tm_badfaultfunc;
|
||||
goto done;
|
||||
}
|
||||
@@ -309,8 +291,7 @@ mips_trap(struct trapframe *tf)
|
||||
|
||||
kprintf("panic: Fatal exception %u (%s) in kernel mode\n", code,
|
||||
trapcodenames[code]);
|
||||
kprintf("panic: EPC 0x%x, exception vaddr 0x%x\n",
|
||||
tf->tf_epc, tf->tf_vaddr);
|
||||
kprintf("panic: EPC 0x%x, exception vaddr 0x%x\n", tf->tf_epc, tf->tf_vaddr);
|
||||
|
||||
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_forked_process, in syscall.c, for use by fork.
|
||||
*/
|
||||
void
|
||||
mips_usermode(struct trapframe *tf)
|
||||
{
|
||||
void mips_usermode(struct trapframe *tf) {
|
||||
|
||||
/*
|
||||
* Interrupts should be off within the kernel while entering
|
||||
@@ -419,10 +398,8 @@ mips_usermode(struct trapframe *tf)
|
||||
*
|
||||
* Works by creating an ersatz trapframe.
|
||||
*/
|
||||
void
|
||||
enter_new_process(int argc, userptr_t argv, userptr_t env,
|
||||
vaddr_t stack, vaddr_t entry)
|
||||
{
|
||||
void enter_new_process(int argc, userptr_t argv, userptr_t env, vaddr_t stack,
|
||||
vaddr_t entry) {
|
||||
struct trapframe tf;
|
||||
|
||||
bzero(&tf, sizeof(tf));
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <current.h>
|
||||
#include <syscall.h>
|
||||
|
||||
|
||||
/*
|
||||
* System call dispatcher.
|
||||
*
|
||||
@@ -75,9 +74,7 @@
|
||||
* stack, starting at sp+16 to skip over the slots for the
|
||||
* registerized values, with copyin().
|
||||
*/
|
||||
void
|
||||
syscall(struct trapframe *tf)
|
||||
{
|
||||
void syscall(struct trapframe *tf) {
|
||||
int callno;
|
||||
int32_t retval;
|
||||
int err;
|
||||
@@ -105,8 +102,7 @@ syscall(struct trapframe *tf)
|
||||
break;
|
||||
|
||||
case SYS___time:
|
||||
err = sys___time((userptr_t)tf->tf_a0,
|
||||
(userptr_t)tf->tf_a1);
|
||||
err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1);
|
||||
break;
|
||||
|
||||
/* Add stuff here */
|
||||
@@ -117,7 +113,6 @@ syscall(struct trapframe *tf)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (err) {
|
||||
/*
|
||||
* Return the error code. This gets converted at
|
||||
@@ -126,8 +121,7 @@ syscall(struct trapframe *tf)
|
||||
*/
|
||||
tf->tf_v0 = err;
|
||||
tf->tf_a3 = 1; /* signal an error */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Success. */
|
||||
tf->tf_v0 = retval;
|
||||
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.
|
||||
*/
|
||||
void
|
||||
enter_forked_process(struct trapframe *tf)
|
||||
{
|
||||
(void)tf;
|
||||
}
|
||||
void enter_forked_process(struct trapframe *tf) { (void)tf; }
|
||||
|
||||
@@ -72,17 +72,14 @@ vaddr_t cputhreads[MAXCPUS];
|
||||
* associated with a new cpu. Note that we're not running on the new
|
||||
* cpu when this is called.
|
||||
*/
|
||||
void
|
||||
cpu_machdep_init(struct cpu *c)
|
||||
{
|
||||
void cpu_machdep_init(struct cpu *c) {
|
||||
vaddr_t stackpointer;
|
||||
|
||||
KASSERT(c->c_number < MAXCPUS);
|
||||
|
||||
if (c->c_curthread->t_stack == NULL) {
|
||||
/* boot cpu; don't need to do anything here */
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* Stick the stack in cpustacks[], and thread pointer
|
||||
* in cputhreads[].
|
||||
@@ -110,20 +107,14 @@ cpu_machdep_init(struct cpu *c)
|
||||
#define SYS161_PRID_ORIG 0x000003ff
|
||||
#define SYS161_PRID_2X 0x000000a1
|
||||
|
||||
static inline
|
||||
uint32_t
|
||||
cpu_getprid(void)
|
||||
{
|
||||
static inline uint32_t cpu_getprid(void) {
|
||||
uint32_t prid;
|
||||
|
||||
__asm volatile("mfc0 %0,$15" : "=r"(prid));
|
||||
return prid;
|
||||
}
|
||||
|
||||
static inline
|
||||
uint32_t
|
||||
cpu_getfeatures(void)
|
||||
{
|
||||
static inline uint32_t cpu_getfeatures(void) {
|
||||
uint32_t features;
|
||||
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
@@ -134,10 +125,7 @@ cpu_getfeatures(void)
|
||||
return features;
|
||||
}
|
||||
|
||||
static inline
|
||||
uint32_t
|
||||
cpu_getifeatures(void)
|
||||
{
|
||||
static inline uint32_t cpu_getifeatures(void) {
|
||||
uint32_t features;
|
||||
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
@@ -148,9 +136,7 @@ cpu_getifeatures(void)
|
||||
return features;
|
||||
}
|
||||
|
||||
void
|
||||
cpu_identify(char *buf, size_t max)
|
||||
{
|
||||
void cpu_identify(char *buf, size_t max) {
|
||||
uint32_t prid;
|
||||
uint32_t features;
|
||||
|
||||
@@ -161,17 +147,16 @@ cpu_identify(char *buf, size_t max)
|
||||
break;
|
||||
case SYS161_PRID_2X:
|
||||
features = cpu_getfeatures();
|
||||
snprintf(buf, max, "MIPS/161 (System/161 2.x) features 0x%x",
|
||||
features);
|
||||
snprintf(buf, max, "MIPS/161 (System/161 2.x) features 0x%x", features);
|
||||
features = cpu_getifeatures();
|
||||
if (features != 0) {
|
||||
kprintf("WARNING: unknown CPU incompatible features "
|
||||
"0x%x\n", features);
|
||||
"0x%x\n",
|
||||
features);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
snprintf(buf, max, "32-bit MIPS (unknown type, CPU ID 0x%x)",
|
||||
prid);
|
||||
snprintf(buf, max, "32-bit MIPS (unknown type, CPU ID 0x%x)", prid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -206,9 +191,7 @@ cpu_identify(char *buf, size_t max)
|
||||
/*
|
||||
* Interrupts on.
|
||||
*/
|
||||
void
|
||||
cpu_irqon(void)
|
||||
{
|
||||
void cpu_irqon(void) {
|
||||
uint32_t x;
|
||||
|
||||
GET_STATUS(x);
|
||||
@@ -219,9 +202,7 @@ cpu_irqon(void)
|
||||
/*
|
||||
* Interrupts off.
|
||||
*/
|
||||
void
|
||||
cpu_irqoff(void)
|
||||
{
|
||||
void cpu_irqoff(void) {
|
||||
uint32_t x;
|
||||
|
||||
GET_STATUS(x);
|
||||
@@ -232,10 +213,7 @@ cpu_irqoff(void)
|
||||
/*
|
||||
* Used below.
|
||||
*/
|
||||
static
|
||||
void
|
||||
cpu_irqonoff(void)
|
||||
{
|
||||
static void cpu_irqonoff(void) {
|
||||
uint32_t x, xon, xoff;
|
||||
|
||||
GET_STATUS(x);
|
||||
@@ -261,11 +239,7 @@ cpu_irqonoff(void)
|
||||
* appropriate the mips32 WAIT instruction.
|
||||
*/
|
||||
|
||||
static
|
||||
inline
|
||||
void
|
||||
wait(void)
|
||||
{
|
||||
static inline void wait(void) {
|
||||
/*
|
||||
* The WAIT instruction goes into powersave mode until an
|
||||
* interrupt is trying to occur.
|
||||
@@ -277,8 +251,7 @@ wait(void)
|
||||
* System/161 simulator is partly guesswork. This code may not
|
||||
* work on a real mips.
|
||||
*/
|
||||
__asm volatile(
|
||||
".set push;" /* save assembler mode */
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 instructions */
|
||||
".set volatile;" /* avoid unwanted optimization */
|
||||
"wait;" /* suspend until interrupted */
|
||||
@@ -289,9 +262,7 @@ wait(void)
|
||||
/*
|
||||
* Idle the processor until something happens.
|
||||
*/
|
||||
void
|
||||
cpu_idle(void)
|
||||
{
|
||||
void cpu_idle(void) {
|
||||
wait();
|
||||
cpu_irqonoff();
|
||||
}
|
||||
@@ -299,9 +270,7 @@ cpu_idle(void)
|
||||
/*
|
||||
* Halt the CPU permanently.
|
||||
*/
|
||||
void
|
||||
cpu_halt(void)
|
||||
{
|
||||
void cpu_halt(void) {
|
||||
cpu_irqoff();
|
||||
while (1) {
|
||||
wait();
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
/* in threadstart.S */
|
||||
extern void mips_threadstart(/* arguments are in unusual registers */);
|
||||
|
||||
|
||||
/*
|
||||
* Function to initialize the switchframe of a new thread, which is
|
||||
* *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
|
||||
* (mips_threadstart) to move them and then jump to thread_startup.
|
||||
*/
|
||||
void
|
||||
switchframe_init(struct thread *thread,
|
||||
void switchframe_init(struct thread *thread,
|
||||
void (*entrypoint)(void *data1, unsigned long data2),
|
||||
void *data1, unsigned long data2)
|
||||
{
|
||||
void *data1, unsigned long data2) {
|
||||
vaddr_t stacktop;
|
||||
struct switchframe *sf;
|
||||
|
||||
|
||||
@@ -36,14 +36,10 @@
|
||||
#include <thread.h>
|
||||
#include <threadprivate.h>
|
||||
|
||||
void
|
||||
thread_machdep_init(struct thread_machdep *tm)
|
||||
{
|
||||
void thread_machdep_init(struct thread_machdep *tm) {
|
||||
tm->tm_badfaultfunc = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
thread_machdep_cleanup(struct thread_machdep *tm)
|
||||
{
|
||||
void thread_machdep_cleanup(struct thread_machdep *tm) {
|
||||
KASSERT(tm->tm_badfaultfunc == NULL);
|
||||
}
|
||||
|
||||
@@ -64,11 +64,7 @@
|
||||
*/
|
||||
static struct spinlock stealmem_lock = SPINLOCK_INITIALIZER;
|
||||
|
||||
void
|
||||
vm_bootstrap(void)
|
||||
{
|
||||
/* Do nothing. */
|
||||
}
|
||||
void vm_bootstrap(void) { /* Do nothing. */ }
|
||||
|
||||
/*
|
||||
* 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
|
||||
* dumbvm starts blowing up during the VM assignment.
|
||||
*/
|
||||
static
|
||||
void
|
||||
dumbvm_can_sleep(void)
|
||||
{
|
||||
static void dumbvm_can_sleep(void) {
|
||||
if (CURCPU_EXISTS()) {
|
||||
/* must not hold spinlocks */
|
||||
KASSERT(curcpu->c_spinlocks == 0);
|
||||
@@ -90,10 +83,7 @@ dumbvm_can_sleep(void)
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
paddr_t
|
||||
getppages(unsigned long npages)
|
||||
{
|
||||
static paddr_t getppages(unsigned long npages) {
|
||||
paddr_t addr;
|
||||
|
||||
spinlock_acquire(&stealmem_lock);
|
||||
@@ -105,9 +95,7 @@ getppages(unsigned long npages)
|
||||
}
|
||||
|
||||
/* Allocate/free some kernel-space virtual pages */
|
||||
vaddr_t
|
||||
alloc_kpages(unsigned npages)
|
||||
{
|
||||
vaddr_t alloc_kpages(unsigned npages) {
|
||||
paddr_t pa;
|
||||
|
||||
dumbvm_can_sleep();
|
||||
@@ -118,24 +106,18 @@ alloc_kpages(unsigned npages)
|
||||
return PADDR_TO_KVADDR(pa);
|
||||
}
|
||||
|
||||
void
|
||||
free_kpages(vaddr_t addr)
|
||||
{
|
||||
void free_kpages(vaddr_t addr) {
|
||||
/* nothing - leak the memory. */
|
||||
|
||||
(void)addr;
|
||||
}
|
||||
|
||||
void
|
||||
vm_tlbshootdown(const struct tlbshootdown *ts)
|
||||
{
|
||||
void vm_tlbshootdown(const struct tlbshootdown *ts) {
|
||||
(void)ts;
|
||||
panic("dumbvm tried to do tlb shootdown?!\n");
|
||||
}
|
||||
|
||||
int
|
||||
vm_fault(int faulttype, vaddr_t faultaddress)
|
||||
{
|
||||
int vm_fault(int faulttype, vaddr_t faultaddress) {
|
||||
vaddr_t vbase1, vtop1, vbase2, vtop2, stackbase, stacktop;
|
||||
paddr_t paddr;
|
||||
int i;
|
||||
@@ -199,14 +181,11 @@ vm_fault(int faulttype, vaddr_t faultaddress)
|
||||
|
||||
if (faultaddress >= vbase1 && faultaddress < vtop1) {
|
||||
paddr = (faultaddress - vbase1) + as->as_pbase1;
|
||||
}
|
||||
else if (faultaddress >= vbase2 && faultaddress < vtop2) {
|
||||
} else if (faultaddress >= vbase2 && faultaddress < vtop2) {
|
||||
paddr = (faultaddress - vbase2) + as->as_pbase2;
|
||||
}
|
||||
else if (faultaddress >= stackbase && faultaddress < stacktop) {
|
||||
} else if (faultaddress >= stackbase && faultaddress < stacktop) {
|
||||
paddr = (faultaddress - stackbase) + as->as_stackpbase;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
@@ -234,9 +213,7 @@ vm_fault(int faulttype, vaddr_t faultaddress)
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
struct addrspace *
|
||||
as_create(void)
|
||||
{
|
||||
struct addrspace *as_create(void) {
|
||||
struct addrspace *as = kmalloc(sizeof(struct addrspace));
|
||||
if (as == NULL) {
|
||||
return NULL;
|
||||
@@ -253,16 +230,12 @@ as_create(void)
|
||||
return as;
|
||||
}
|
||||
|
||||
void
|
||||
as_destroy(struct addrspace *as)
|
||||
{
|
||||
void as_destroy(struct addrspace *as) {
|
||||
dumbvm_can_sleep();
|
||||
kfree(as);
|
||||
}
|
||||
|
||||
void
|
||||
as_activate(void)
|
||||
{
|
||||
void as_activate(void) {
|
||||
int i, spl;
|
||||
struct addrspace *as;
|
||||
|
||||
@@ -281,16 +254,10 @@ as_activate(void)
|
||||
splx(spl);
|
||||
}
|
||||
|
||||
void
|
||||
as_deactivate(void)
|
||||
{
|
||||
/* nothing */
|
||||
}
|
||||
void as_deactivate(void) { /* nothing */ }
|
||||
|
||||
int
|
||||
as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
|
||||
int readable, int writeable, int executable)
|
||||
{
|
||||
int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
|
||||
int readable, int writeable, int executable) {
|
||||
size_t npages;
|
||||
|
||||
dumbvm_can_sleep();
|
||||
@@ -328,16 +295,11 @@ as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
as_zero_region(paddr_t paddr, unsigned npages)
|
||||
{
|
||||
static void as_zero_region(paddr_t paddr, unsigned npages) {
|
||||
bzero((void *)PADDR_TO_KVADDR(paddr), npages * PAGE_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
as_prepare_load(struct addrspace *as)
|
||||
{
|
||||
int as_prepare_load(struct addrspace *as) {
|
||||
KASSERT(as->as_pbase1 == 0);
|
||||
KASSERT(as->as_pbase2 == 0);
|
||||
KASSERT(as->as_stackpbase == 0);
|
||||
@@ -366,26 +328,20 @@ as_prepare_load(struct addrspace *as)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
as_complete_load(struct addrspace *as)
|
||||
{
|
||||
int as_complete_load(struct addrspace *as) {
|
||||
dumbvm_can_sleep();
|
||||
(void)as;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
as_define_stack(struct addrspace *as, vaddr_t *stackptr)
|
||||
{
|
||||
int as_define_stack(struct addrspace *as, vaddr_t *stackptr) {
|
||||
KASSERT(as->as_stackpbase != 0);
|
||||
|
||||
*stackptr = USERSTACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
as_copy(struct addrspace *old, struct addrspace **ret)
|
||||
{
|
||||
int as_copy(struct addrspace *old, struct addrspace **ret) {
|
||||
struct addrspace *new;
|
||||
|
||||
dumbvm_can_sleep();
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <vm.h>
|
||||
#include <mainbus.h>
|
||||
|
||||
|
||||
vaddr_t firstfree; /* first free virtual address; set by start.S */
|
||||
|
||||
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
|
||||
* RAM is available.
|
||||
*/
|
||||
void
|
||||
ram_bootstrap(void)
|
||||
{
|
||||
void ram_bootstrap(void) {
|
||||
size_t ramsize;
|
||||
|
||||
/* Get size of RAM. */
|
||||
@@ -69,8 +66,7 @@ ram_bootstrap(void)
|
||||
*/
|
||||
firstpaddr = firstfree - MIPS_KSEG0;
|
||||
|
||||
kprintf("%uk physical memory available\n",
|
||||
(lastpaddr-firstpaddr)/1024);
|
||||
kprintf("%uk physical memory available\n", (lastpaddr - firstpaddr) / 1024);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -91,9 +87,7 @@ ram_bootstrap(void)
|
||||
* This function should not be called once the VM system is initialized,
|
||||
* so it is not synchronized.
|
||||
*/
|
||||
paddr_t
|
||||
ram_stealmem(unsigned long npages)
|
||||
{
|
||||
paddr_t ram_stealmem(unsigned long npages) {
|
||||
size_t size;
|
||||
paddr_t paddr;
|
||||
|
||||
@@ -124,11 +118,7 @@ ram_stealmem(unsigned long npages)
|
||||
* initialize the VM system, after which the VM system should take
|
||||
* charge of knowing what memory exists.
|
||||
*/
|
||||
paddr_t
|
||||
ram_getsize(void)
|
||||
{
|
||||
return lastpaddr;
|
||||
}
|
||||
paddr_t ram_getsize(void) { return lastpaddr; }
|
||||
|
||||
/*
|
||||
* 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,
|
||||
* so it is not synchronized.
|
||||
*/
|
||||
paddr_t
|
||||
ram_getfirstfree(void)
|
||||
{
|
||||
paddr_t ram_getfirstfree(void) {
|
||||
paddr_t ret;
|
||||
|
||||
ret = firstpaddr;
|
||||
|
||||
@@ -60,16 +60,12 @@
|
||||
* matches the c0_compare register, the timer interrupt line is
|
||||
* asserted. Writing to c0_compare again clears the interrupt.
|
||||
*/
|
||||
static
|
||||
void
|
||||
mips_timer_set(uint32_t count)
|
||||
{
|
||||
static void mips_timer_set(uint32_t count) {
|
||||
/*
|
||||
* $11 == c0_compare; we can't use the symbolic name inside
|
||||
* the asm string.
|
||||
*/
|
||||
__asm volatile(
|
||||
".set push;" /* save assembler mode */
|
||||
__asm volatile(".set push;" /* save assembler mode */
|
||||
".set mips32;" /* allow MIPS32 registers */
|
||||
"mtc0 %0, $11;" /* do it */
|
||||
".set pop" /* restore assembler mode */
|
||||
@@ -83,9 +79,7 @@ mips_timer_set(uint32_t count)
|
||||
*/
|
||||
static struct lamebus_softc *lamebus;
|
||||
|
||||
void
|
||||
mainbus_bootstrap(void)
|
||||
{
|
||||
void mainbus_bootstrap(void) {
|
||||
/* Interrupts should be off (and have been off since startup) */
|
||||
KASSERT(curthread->t_curspl > 0);
|
||||
|
||||
@@ -122,20 +116,14 @@ mainbus_bootstrap(void)
|
||||
/*
|
||||
* Start all secondary CPUs.
|
||||
*/
|
||||
void
|
||||
mainbus_start_cpus(void)
|
||||
{
|
||||
lamebus_start_cpus(lamebus);
|
||||
}
|
||||
void mainbus_start_cpus(void) { lamebus_start_cpus(lamebus); }
|
||||
|
||||
/*
|
||||
* Function to generate the memory address (in the uncached segment)
|
||||
* for the specified offset into the specified slot's region of the
|
||||
* LAMEbus.
|
||||
*/
|
||||
void *
|
||||
lamebus_map_area(struct lamebus_softc *bus, int slot, uint32_t offset)
|
||||
{
|
||||
void *lamebus_map_area(struct lamebus_softc *bus, int slot, uint32_t offset) {
|
||||
uint32_t address;
|
||||
|
||||
(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.
|
||||
*/
|
||||
uint32_t
|
||||
lamebus_read_register(struct lamebus_softc *bus, int slot, uint32_t offset)
|
||||
{
|
||||
uint32_t lamebus_read_register(struct lamebus_softc *bus, int slot,
|
||||
uint32_t offset) {
|
||||
uint32_t *ptr;
|
||||
|
||||
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.
|
||||
*/
|
||||
void
|
||||
lamebus_write_register(struct lamebus_softc *bus, int slot,
|
||||
uint32_t offset, uint32_t val)
|
||||
{
|
||||
void lamebus_write_register(struct lamebus_softc *bus, int slot,
|
||||
uint32_t offset, uint32_t val) {
|
||||
uint32_t *ptr;
|
||||
|
||||
ptr = lamebus_map_area(bus, slot, offset);
|
||||
@@ -184,13 +169,10 @@ lamebus_write_register(struct lamebus_softc *bus, int slot,
|
||||
membar_store_store();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Power off the system.
|
||||
*/
|
||||
void
|
||||
mainbus_poweroff(void)
|
||||
{
|
||||
void mainbus_poweroff(void) {
|
||||
/*
|
||||
*
|
||||
* Note that lamebus_write_register() doesn't actually access
|
||||
@@ -203,9 +185,7 @@ mainbus_poweroff(void)
|
||||
/*
|
||||
* Reboot the system.
|
||||
*/
|
||||
void
|
||||
mainbus_reboot(void)
|
||||
{
|
||||
void mainbus_reboot(void) {
|
||||
/*
|
||||
* The MIPS doesn't appear to have any on-chip reset.
|
||||
* 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
|
||||
* have one.
|
||||
*/
|
||||
void
|
||||
mainbus_halt(void)
|
||||
{
|
||||
cpu_halt();
|
||||
}
|
||||
void mainbus_halt(void) { cpu_halt(); }
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* (We'd reboot, but System/161 doesn't do that.)
|
||||
*/
|
||||
void
|
||||
mainbus_panic(void)
|
||||
{
|
||||
mainbus_poweroff();
|
||||
}
|
||||
void mainbus_panic(void) { mainbus_poweroff(); }
|
||||
|
||||
/*
|
||||
* Function to get the size of installed physical RAM from the LAMEbus
|
||||
* controller.
|
||||
*/
|
||||
uint32_t
|
||||
mainbus_ramsize(void)
|
||||
{
|
||||
uint32_t mainbus_ramsize(void) {
|
||||
uint32_t ramsize;
|
||||
|
||||
ramsize = lamebus_ramsize();
|
||||
@@ -270,20 +240,14 @@ mainbus_ramsize(void)
|
||||
/*
|
||||
* Send IPI.
|
||||
*/
|
||||
void
|
||||
mainbus_send_ipi(struct cpu *target)
|
||||
{
|
||||
void mainbus_send_ipi(struct cpu *target) {
|
||||
lamebus_assert_ipi(lamebus, target);
|
||||
}
|
||||
|
||||
/*
|
||||
* Trigger the debugger.
|
||||
*/
|
||||
void
|
||||
mainbus_debugger(void)
|
||||
{
|
||||
ltrace_stop(0);
|
||||
}
|
||||
void mainbus_debugger(void) { ltrace_stop(0); }
|
||||
|
||||
/*
|
||||
* Interrupt dispatcher.
|
||||
@@ -294,9 +258,7 @@ mainbus_debugger(void)
|
||||
#define LAMEBUS_IPI_BIT 0x00000800 /* inter-processor interrupt */
|
||||
#define MIPS_TIMER_BIT 0x00008000 /* on-chip timer */
|
||||
|
||||
void
|
||||
mainbus_interrupt(struct trapframe *tf)
|
||||
{
|
||||
void mainbus_interrupt(struct trapframe *tf) {
|
||||
uint32_t cause;
|
||||
bool seen = false;
|
||||
|
||||
@@ -330,15 +292,13 @@ mainbus_interrupt(struct trapframe *tf)
|
||||
* reading the cause register. This was
|
||||
* actually seen... once.
|
||||
*/
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* But if we get an interrupt on an interrupt
|
||||
* line that's not supposed to be wired up,
|
||||
* complain.
|
||||
*/
|
||||
panic("Unknown interrupt; cause register is %08x\n",
|
||||
cause);
|
||||
panic("Unknown interrupt; cause register is %08x\n", cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@
|
||||
#define bus_read_register(bus, slot, offset) \
|
||||
lamebus_read_register(bus, slot, offset)
|
||||
|
||||
#define bus_map_area(bus, slot, offset) \
|
||||
lamebus_map_area(bus, slot, offset)
|
||||
#define bus_map_area(bus, slot, offset) lamebus_map_area(bus, slot, offset)
|
||||
|
||||
/*
|
||||
* Machine-dependent LAMEbus definitions
|
||||
@@ -56,5 +55,4 @@
|
||||
/* Base address of the LAMEbus mapping area */
|
||||
#define LB_BASEADDR (MIPS_KSEG1 + 0x1fe00000)
|
||||
|
||||
|
||||
#endif /* _SYS161_BUS_H_ */
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
|
||||
static struct beep_softc *the_beep = NULL;
|
||||
|
||||
int
|
||||
config_beep(struct beep_softc *bs, int unit)
|
||||
{
|
||||
int config_beep(struct beep_softc *bs, int unit) {
|
||||
/* We use only the first beep device. */
|
||||
if (unit != 0) {
|
||||
return ENODEV;
|
||||
@@ -59,13 +57,10 @@ config_beep(struct beep_softc *bs, int unit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
beep(void)
|
||||
{
|
||||
void beep(void) {
|
||||
if (the_beep != NULL) {
|
||||
the_beep->bs_beep(the_beep->bs_devdata);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
kprintf("beep: Warning: no beep device\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,10 +83,7 @@ static struct lock *con_userlock_write = NULL;
|
||||
static char delayed_outbuf[DELAYBUFSIZE];
|
||||
static size_t delayed_outbuf_pos = 0;
|
||||
|
||||
static
|
||||
void
|
||||
putch_delayed(int ch)
|
||||
{
|
||||
static void putch_delayed(int ch) {
|
||||
/*
|
||||
* No synchronization needed: called only during system startup
|
||||
* by main thread.
|
||||
@@ -96,10 +93,7 @@ putch_delayed(int ch)
|
||||
delayed_outbuf[delayed_outbuf_pos++] = ch;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
flush_delay_buf(void)
|
||||
{
|
||||
static void flush_delay_buf(void) {
|
||||
size_t i;
|
||||
for (i = 0; i < delayed_outbuf_pos; i++) {
|
||||
putch(delayed_outbuf[i]);
|
||||
@@ -113,10 +107,7 @@ flush_delay_buf(void)
|
||||
* Print a character, using polling instead of interrupts to wait for
|
||||
* I/O completion.
|
||||
*/
|
||||
static
|
||||
void
|
||||
putch_polled(struct con_softc *cs, int ch)
|
||||
{
|
||||
static void putch_polled(struct con_softc *cs, int 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.
|
||||
*/
|
||||
static
|
||||
void
|
||||
putch_intr(struct con_softc *cs, int ch)
|
||||
{
|
||||
static void putch_intr(struct con_softc *cs, int ch) {
|
||||
P(cs->cs_wsem);
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
getch_intr(struct con_softc *cs)
|
||||
{
|
||||
static int getch_intr(struct con_softc *cs) {
|
||||
unsigned char ret;
|
||||
|
||||
P(cs->cs_rsem);
|
||||
ret = cs->cs_gotchars[cs->cs_gotchars_tail];
|
||||
cs->cs_gotchars_tail =
|
||||
(cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
cs->cs_gotchars_tail = (cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -158,9 +142,7 @@ getch_intr(struct con_softc *cs)
|
||||
* too) would be with a second semaphore used with a nonblocking P,
|
||||
* but we don't have that in OS/161.
|
||||
*/
|
||||
void
|
||||
con_input(void *vcs, int ch)
|
||||
{
|
||||
void con_input(void *vcs, int ch) {
|
||||
struct con_softc *cs = vcs;
|
||||
unsigned nexthead;
|
||||
|
||||
@@ -179,9 +161,7 @@ con_input(void *vcs, int ch)
|
||||
/*
|
||||
* Called from underlying device when a write-done interrupt occurs.
|
||||
*/
|
||||
void
|
||||
con_start(void *vcs)
|
||||
{
|
||||
void con_start(void *vcs) {
|
||||
struct con_softc *cs = vcs;
|
||||
|
||||
V(cs->cs_wsem);
|
||||
@@ -197,27 +177,20 @@ con_start(void *vcs)
|
||||
* not, and does not.
|
||||
*/
|
||||
|
||||
void
|
||||
putch(int ch)
|
||||
{
|
||||
void putch(int ch) {
|
||||
struct con_softc *cs = the_console;
|
||||
|
||||
if (cs == NULL) {
|
||||
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) {
|
||||
putch_polled(cs, ch);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
putch_intr(cs, ch);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
getch(void)
|
||||
{
|
||||
int getch(void) {
|
||||
struct con_softc *cs = the_console;
|
||||
KASSERT(cs != NULL);
|
||||
KASSERT(!curthread->t_in_interrupt && curthread->t_iplhigh_count == 0);
|
||||
@@ -231,19 +204,13 @@ getch(void)
|
||||
* VFS interface functions
|
||||
*/
|
||||
|
||||
static
|
||||
int
|
||||
con_eachopen(struct device *dev, int openflags)
|
||||
{
|
||||
static int con_eachopen(struct device *dev, int openflags) {
|
||||
(void)dev;
|
||||
(void)openflags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
con_io(struct device *dev, struct uio *uio)
|
||||
{
|
||||
static int con_io(struct device *dev, struct uio *uio) {
|
||||
int result;
|
||||
char ch;
|
||||
struct lock *lk;
|
||||
@@ -252,8 +219,7 @@ con_io(struct device *dev, struct uio *uio)
|
||||
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
lk = con_userlock_read;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lk = con_userlock_write;
|
||||
}
|
||||
|
||||
@@ -274,8 +240,7 @@ con_io(struct device *dev, struct uio *uio)
|
||||
if (ch == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
result = uiomove(&ch, 1, uio);
|
||||
if (result) {
|
||||
lock_release(lk);
|
||||
@@ -291,10 +256,7 @@ con_io(struct device *dev, struct uio *uio)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
con_ioctl(struct device *dev, int op, userptr_t data)
|
||||
{
|
||||
static int con_ioctl(struct device *dev, int op, userptr_t data) {
|
||||
/* No ioctls. */
|
||||
(void)dev;
|
||||
(void)op;
|
||||
@@ -308,10 +270,7 @@ static const struct device_ops console_devops = {
|
||||
.devop_ioctl = con_ioctl,
|
||||
};
|
||||
|
||||
static
|
||||
int
|
||||
attach_console_to_vfs(struct con_softc *cs)
|
||||
{
|
||||
static int attach_console_to_vfs(struct con_softc *cs) {
|
||||
struct device *dev;
|
||||
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.
|
||||
*/
|
||||
|
||||
int
|
||||
config_con(struct con_softc *cs, int unit)
|
||||
{
|
||||
int config_con(struct con_softc *cs, int unit) {
|
||||
struct semaphore *rsem, *wsem;
|
||||
struct lock *rlk, *wlk;
|
||||
|
||||
|
||||
@@ -53,10 +53,7 @@ static struct random_softc *the_random = NULL;
|
||||
* VFS device functions.
|
||||
* open: allow reading only.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randeachopen(struct device *dev, int openflags)
|
||||
{
|
||||
static int randeachopen(struct device *dev, int openflags) {
|
||||
(void)dev;
|
||||
|
||||
if (openflags != O_RDONLY) {
|
||||
@@ -69,10 +66,7 @@ randeachopen(struct device *dev, int openflags)
|
||||
/*
|
||||
* VFS I/O function. Hand off to implementation.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randio(struct device *dev, struct uio *uio)
|
||||
{
|
||||
static int randio(struct device *dev, struct uio *uio) {
|
||||
struct random_softc *rs = dev->d_data;
|
||||
|
||||
if (uio->uio_rw != UIO_READ) {
|
||||
@@ -85,10 +79,7 @@ randio(struct device *dev, struct uio *uio)
|
||||
/*
|
||||
* VFS ioctl function.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randioctl(struct device *dev, int op, userptr_t data)
|
||||
{
|
||||
static int randioctl(struct device *dev, int op, userptr_t data) {
|
||||
/*
|
||||
* We don't support any ioctls.
|
||||
*/
|
||||
@@ -107,9 +98,7 @@ static const struct device_ops random_devops = {
|
||||
/*
|
||||
* Config function.
|
||||
*/
|
||||
int
|
||||
config_random(struct random_softc *rs, int unit)
|
||||
{
|
||||
int config_random(struct random_softc *rs, int unit) {
|
||||
int result;
|
||||
|
||||
/* We use only the first random device. */
|
||||
@@ -134,23 +123,18 @@ config_random(struct random_softc *rs, int unit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Random number functions exported to the rest of the kernel.
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
random(void)
|
||||
{
|
||||
uint32_t random(void) {
|
||||
if (the_random == NULL) {
|
||||
panic("No random device\n");
|
||||
}
|
||||
return the_random->rs_random(the_random->rs_devdata);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
randmax(void)
|
||||
{
|
||||
uint32_t randmax(void) {
|
||||
if (the_random == NULL) {
|
||||
panic("No random device\n");
|
||||
}
|
||||
|
||||
@@ -49,9 +49,7 @@
|
||||
|
||||
static struct rtclock_softc *the_clock = NULL;
|
||||
|
||||
int
|
||||
config_rtclock(struct rtclock_softc *rtc, int unit)
|
||||
{
|
||||
int config_rtclock(struct rtclock_softc *rtc, int unit) {
|
||||
/* We use only the first clock device. */
|
||||
if (unit != 0) {
|
||||
return ENODEV;
|
||||
@@ -62,9 +60,7 @@ config_rtclock(struct rtclock_softc *rtc, int unit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
gettime(struct timespec *ts)
|
||||
{
|
||||
void gettime(struct timespec *ts) {
|
||||
KASSERT(the_clock != NULL);
|
||||
the_clock->rtc_gettime(the_clock->rtc_devdata, ts);
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
#include <lamebus/ltimer.h>
|
||||
#include "autoconf.h"
|
||||
|
||||
struct beep_softc *
|
||||
attach_beep_to_ltimer(int beepno, struct ltimer_softc *ls)
|
||||
{
|
||||
struct beep_softc *attach_beep_to_ltimer(int beepno, struct ltimer_softc *ls) {
|
||||
struct beep_softc *bs = kmalloc(sizeof(struct beep_softc));
|
||||
if (bs == NULL) {
|
||||
return NULL;
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
#include <lamebus/lscreen.h>
|
||||
#include "autoconf.h"
|
||||
|
||||
struct con_softc *
|
||||
attach_con_to_lscreen(int consno, struct lscreen_softc *ls)
|
||||
{
|
||||
struct con_softc *attach_con_to_lscreen(int consno, struct lscreen_softc *ls) {
|
||||
struct con_softc *cs = kmalloc(sizeof(struct con_softc));
|
||||
if (cs == NULL) {
|
||||
return NULL;
|
||||
@@ -56,4 +54,3 @@ attach_con_to_lscreen(int consno, struct lscreen_softc *ls)
|
||||
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,7 @@
|
||||
#include <lamebus/lser.h>
|
||||
#include "autoconf.h"
|
||||
|
||||
struct con_softc *
|
||||
attach_con_to_lser(int consno, struct lser_softc *ls)
|
||||
{
|
||||
struct con_softc *attach_con_to_lser(int consno, struct lser_softc *ls) {
|
||||
struct con_softc *cs = kmalloc(sizeof(struct con_softc));
|
||||
if (cs == NULL) {
|
||||
return NULL;
|
||||
@@ -58,4 +56,3 @@ attach_con_to_lser(int consno, struct lser_softc *ls)
|
||||
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,31 +99,21 @@
|
||||
/*
|
||||
* Shortcut for reading a register
|
||||
*/
|
||||
static
|
||||
inline
|
||||
uint32_t
|
||||
emu_rreg(struct emu_softc *sc, uint32_t reg)
|
||||
{
|
||||
static inline uint32_t emu_rreg(struct emu_softc *sc, uint32_t reg) {
|
||||
return bus_read_register(sc->e_busdata, sc->e_buspos, reg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shortcut for writing a register
|
||||
*/
|
||||
static
|
||||
inline
|
||||
void
|
||||
emu_wreg(struct emu_softc *sc, uint32_t reg, uint32_t val)
|
||||
{
|
||||
static 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the underlying bus code when an interrupt happens
|
||||
*/
|
||||
void
|
||||
emu_irq(void *dev)
|
||||
{
|
||||
void emu_irq(void *dev) {
|
||||
struct emu_softc *sc = dev;
|
||||
|
||||
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.
|
||||
* Or, on cases that indicate a programming error in emu.c, panic.
|
||||
*/
|
||||
static
|
||||
uint32_t
|
||||
translate_err(struct emu_softc *sc, uint32_t code)
|
||||
{
|
||||
static uint32_t translate_err(struct emu_softc *sc, uint32_t code) {
|
||||
switch (code) {
|
||||
case EMU_RES_SUCCESS: return 0;
|
||||
case EMU_RES_SUCCESS:
|
||||
return 0;
|
||||
case EMU_RES_BADHANDLE:
|
||||
case EMU_RES_BADOP:
|
||||
case EMU_RES_BADSIZE:
|
||||
panic("emu%d: got fatal result code %d\n", sc->e_unit, code);
|
||||
case EMU_RES_BADPATH: return ENOENT;
|
||||
case EMU_RES_EXISTS: return EEXIST;
|
||||
case EMU_RES_ISDIR: return EISDIR;
|
||||
case EMU_RES_MEDIA: return EIO;
|
||||
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;
|
||||
case EMU_RES_BADPATH:
|
||||
return ENOENT;
|
||||
case EMU_RES_EXISTS:
|
||||
return EEXIST;
|
||||
case EMU_RES_ISDIR:
|
||||
return EISDIR;
|
||||
case EMU_RES_MEDIA:
|
||||
return EIO;
|
||||
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);
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_waitdone(struct emu_softc *sc)
|
||||
{
|
||||
static int emu_waitdone(struct emu_softc *sc) {
|
||||
P(sc->e_sem);
|
||||
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
|
||||
* files are already open.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
|
||||
bool create, bool excl, mode_t mode,
|
||||
uint32_t *newhandle, int *newisdir)
|
||||
{
|
||||
static int emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
|
||||
bool create, bool excl, mode_t mode, uint32_t *newhandle,
|
||||
int *newisdir) {
|
||||
uint32_t op;
|
||||
int result;
|
||||
|
||||
@@ -192,11 +183,9 @@ emu_open(struct emu_softc *sc, uint32_t handle, const char *name,
|
||||
|
||||
if (create && excl) {
|
||||
op = EMU_OP_EXCLCREATE;
|
||||
}
|
||||
else if (create) {
|
||||
} else if (create) {
|
||||
op = EMU_OP_CREATE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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
|
||||
* at VOP_RECLAIM time.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_close(struct emu_softc *sc, uint32_t handle)
|
||||
{
|
||||
static int emu_close(struct emu_softc *sc, uint32_t handle) {
|
||||
int result;
|
||||
bool mine;
|
||||
int retries = 0;
|
||||
@@ -247,8 +233,7 @@ emu_close(struct emu_softc *sc, uint32_t handle)
|
||||
result = emu_waitdone(sc);
|
||||
|
||||
if (result == EIO && retries < 10) {
|
||||
kprintf("emu%d: I/O error on close, retrying\n",
|
||||
sc->e_unit);
|
||||
kprintf("emu%d: I/O error on close, retrying\n", sc->e_unit);
|
||||
retries++;
|
||||
continue;
|
||||
}
|
||||
@@ -264,11 +249,8 @@ emu_close(struct emu_softc *sc, uint32_t handle)
|
||||
/*
|
||||
* Common code for read and readdir.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_doread(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
uint32_t op, struct uio *uio)
|
||||
{
|
||||
static int emu_doread(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
uint32_t op, struct uio *uio) {
|
||||
int result;
|
||||
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_read(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
struct uio *uio)
|
||||
{
|
||||
static int 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a directory entry from a hardware-level file handle.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_readdir(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
struct uio *uio)
|
||||
{
|
||||
static int 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to a hardware-level file handle.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_write(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
struct uio *uio)
|
||||
{
|
||||
static int emu_write(struct emu_softc *sc, uint32_t handle, uint32_t len,
|
||||
struct uio *uio) {
|
||||
int result;
|
||||
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_getsize(struct emu_softc *sc, uint32_t handle, off_t *retval)
|
||||
{
|
||||
static int emu_getsize(struct emu_softc *sc, uint32_t handle, off_t *retval) {
|
||||
int result;
|
||||
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emu_trunc(struct emu_softc *sc, uint32_t handle, off_t len)
|
||||
{
|
||||
static int emu_trunc(struct emu_softc *sc, uint32_t handle, off_t len) {
|
||||
int result;
|
||||
|
||||
KASSERT(len >= 0);
|
||||
@@ -417,10 +384,7 @@ static int emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
|
||||
/*
|
||||
* VOP_EACHOPEN on files
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_eachopen(struct vnode *v, int openflags)
|
||||
{
|
||||
static int emufs_eachopen(struct vnode *v, int openflags) {
|
||||
/*
|
||||
* At this level we do not need to handle O_CREAT, O_EXCL,
|
||||
* O_TRUNC, or O_APPEND.
|
||||
@@ -438,10 +402,7 @@ emufs_eachopen(struct vnode *v, int openflags)
|
||||
/*
|
||||
* VOP_EACHOPEN on directories
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_eachopendir(struct vnode *v, int openflags)
|
||||
{
|
||||
static int emufs_eachopendir(struct vnode *v, int openflags) {
|
||||
switch (openflags & O_ACCMODE) {
|
||||
case O_RDONLY:
|
||||
break;
|
||||
@@ -463,10 +424,7 @@ emufs_eachopendir(struct vnode *v, int openflags)
|
||||
*
|
||||
* Reclaim should make an effort to returning errors other than EBUSY.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_reclaim(struct vnode *v)
|
||||
{
|
||||
static int emufs_reclaim(struct vnode *v) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
struct emufs_fs *ef = v->vn_fs->fs_data;
|
||||
unsigned ix, i, num;
|
||||
@@ -519,8 +477,8 @@ emufs_reclaim(struct vnode *v)
|
||||
}
|
||||
}
|
||||
if (ix == num) {
|
||||
panic("emu%d: reclaim vnode %u not in vnode pool\n",
|
||||
ef->ef_emu->e_unit, ev->ev_handle);
|
||||
panic("emu%d: reclaim vnode %u not in vnode pool\n", ef->ef_emu->e_unit,
|
||||
ev->ev_handle);
|
||||
}
|
||||
|
||||
vnodearray_remove(ef->ef_vnodes, ix);
|
||||
@@ -536,10 +494,7 @@ emufs_reclaim(struct vnode *v)
|
||||
/*
|
||||
* VOP_READ
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_read(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_read(struct vnode *v, struct uio *uio) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
uint32_t amt;
|
||||
size_t oldresid;
|
||||
@@ -572,10 +527,7 @@ emufs_read(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* VOP_READDIR
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_getdirentry(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_getdirentry(struct vnode *v, struct uio *uio) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
uint32_t amt;
|
||||
|
||||
@@ -592,10 +544,7 @@ emufs_getdirentry(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* VOP_WRITE
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_write(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_write(struct vnode *v, struct uio *uio) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
uint32_t amt;
|
||||
size_t oldresid;
|
||||
@@ -628,10 +577,7 @@ emufs_write(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* VOP_IOCTL
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_ioctl(struct vnode *v, int op, userptr_t data)
|
||||
{
|
||||
static int emufs_ioctl(struct vnode *v, int op, userptr_t data) {
|
||||
/*
|
||||
* No ioctls.
|
||||
*/
|
||||
@@ -646,10 +592,7 @@ emufs_ioctl(struct vnode *v, int op, userptr_t data)
|
||||
/*
|
||||
* VOP_STAT
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_stat(struct vnode *v, struct stat *statbuf)
|
||||
{
|
||||
static int emufs_stat(struct vnode *v, struct stat *statbuf) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
int result;
|
||||
|
||||
@@ -674,10 +617,7 @@ emufs_stat(struct vnode *v, struct stat *statbuf)
|
||||
/*
|
||||
* VOP_GETTYPE for files
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_file_gettype(struct vnode *v, uint32_t *result)
|
||||
{
|
||||
static int emufs_file_gettype(struct vnode *v, uint32_t *result) {
|
||||
(void)v;
|
||||
*result = S_IFREG;
|
||||
return 0;
|
||||
@@ -686,10 +626,7 @@ emufs_file_gettype(struct vnode *v, uint32_t *result)
|
||||
/*
|
||||
* VOP_GETTYPE for directories
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_dir_gettype(struct vnode *v, uint32_t *result)
|
||||
{
|
||||
static int emufs_dir_gettype(struct vnode *v, uint32_t *result) {
|
||||
(void)v;
|
||||
*result = S_IFDIR;
|
||||
return 0;
|
||||
@@ -698,10 +635,7 @@ emufs_dir_gettype(struct vnode *v, uint32_t *result)
|
||||
/*
|
||||
* VOP_ISSEEKABLE
|
||||
*/
|
||||
static
|
||||
bool
|
||||
emufs_isseekable(struct vnode *v)
|
||||
{
|
||||
static bool emufs_isseekable(struct vnode *v) {
|
||||
(void)v;
|
||||
return true;
|
||||
}
|
||||
@@ -709,10 +643,7 @@ emufs_isseekable(struct vnode *v)
|
||||
/*
|
||||
* VOP_FSYNC
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_fsync(struct vnode *v)
|
||||
{
|
||||
static int emufs_fsync(struct vnode *v) {
|
||||
(void)v;
|
||||
return 0;
|
||||
}
|
||||
@@ -720,10 +651,7 @@ emufs_fsync(struct vnode *v)
|
||||
/*
|
||||
* VOP_TRUNCATE
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_truncate(struct vnode *v, off_t len)
|
||||
{
|
||||
static int emufs_truncate(struct vnode *v, off_t len) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
return emu_trunc(ev->ev_emu, ev->ev_handle, len);
|
||||
}
|
||||
@@ -731,11 +659,8 @@ emufs_truncate(struct vnode *v, off_t len)
|
||||
/*
|
||||
* VOP_CREAT
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
|
||||
struct vnode **ret)
|
||||
{
|
||||
static int 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_fs *ef = dir->vn_fs->fs_data;
|
||||
struct emufs_vnode *newguy;
|
||||
@@ -743,8 +668,8 @@ emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
|
||||
int result;
|
||||
int isdir;
|
||||
|
||||
result = emu_open(ev->ev_emu, ev->ev_handle, name, true, excl, mode,
|
||||
&handle, &isdir);
|
||||
result = emu_open(ev->ev_emu, ev->ev_handle, name, true, excl, mode, &handle,
|
||||
&isdir);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -762,10 +687,7 @@ emufs_creat(struct vnode *dir, const char *name, bool excl, mode_t mode,
|
||||
/*
|
||||
* VOP_LOOKUP
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret)
|
||||
{
|
||||
static int emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret) {
|
||||
struct emufs_vnode *ev = dir->vn_data;
|
||||
struct emufs_fs *ef = dir->vn_fs->fs_data;
|
||||
struct emufs_vnode *newguy;
|
||||
@@ -792,11 +714,8 @@ emufs_lookup(struct vnode *dir, char *pathname, struct vnode **ret)
|
||||
/*
|
||||
* VOP_LOOKPARENT
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_lookparent(struct vnode *dir, char *pathname, struct vnode **ret,
|
||||
char *buf, size_t len)
|
||||
{
|
||||
static int emufs_lookparent(struct vnode *dir, char *pathname,
|
||||
struct vnode **ret, char *buf, size_t len) {
|
||||
char *s;
|
||||
|
||||
s = strrchr(pathname, '/');
|
||||
@@ -824,10 +743,7 @@ emufs_lookparent(struct vnode *dir, char *pathname, struct vnode **ret,
|
||||
/*
|
||||
* VOP_NAMEFILE
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_namefile(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_namefile(struct vnode *v, struct uio *uio) {
|
||||
struct emufs_vnode *ev = v->vn_data;
|
||||
struct emufs_fs *ef = v->vn_fs->fs_data;
|
||||
|
||||
@@ -846,10 +762,7 @@ emufs_namefile(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* VOP_MMAP
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_mmap(struct vnode *v)
|
||||
{
|
||||
static int emufs_mmap(struct vnode *v) {
|
||||
(void)v;
|
||||
return ENOSYS;
|
||||
}
|
||||
@@ -860,59 +773,42 @@ emufs_mmap(struct vnode *v)
|
||||
* Bits not implemented at all on emufs
|
||||
*/
|
||||
|
||||
static
|
||||
int
|
||||
emufs_symlink(struct vnode *v, const char *contents, const char *name)
|
||||
{
|
||||
static int emufs_symlink(struct vnode *v, const char *contents,
|
||||
const char *name) {
|
||||
(void)v;
|
||||
(void)contents;
|
||||
(void)name;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_mkdir(struct vnode *v, const char *name, mode_t mode)
|
||||
{
|
||||
static int emufs_mkdir(struct vnode *v, const char *name, mode_t mode) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
(void)mode;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_link(struct vnode *v, const char *name, struct vnode *target)
|
||||
{
|
||||
static int emufs_link(struct vnode *v, const char *name, struct vnode *target) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
(void)target;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_remove(struct vnode *v, const char *name)
|
||||
{
|
||||
static int emufs_remove(struct vnode *v, const char *name) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_rmdir(struct vnode *v, const char *name)
|
||||
{
|
||||
static int emufs_rmdir(struct vnode *v, const char *name) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_rename(struct vnode *v1, const char *n1,
|
||||
struct vnode *v2, const char *n2)
|
||||
{
|
||||
static int emufs_rename(struct vnode *v1, const char *n1, struct vnode *v2,
|
||||
const char *n2) {
|
||||
(void)v1;
|
||||
(void)n1;
|
||||
(void)v2;
|
||||
@@ -935,55 +831,37 @@ emufs_rename(struct vnode *v1, const char *n1,
|
||||
* problem but is otherwise not very appealing.
|
||||
*/
|
||||
|
||||
static
|
||||
int
|
||||
emufs_void_op_isdir(struct vnode *v)
|
||||
{
|
||||
static int emufs_void_op_isdir(struct vnode *v) {
|
||||
(void)v;
|
||||
return EISDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_uio_op_isdir(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_uio_op_isdir(struct vnode *v, struct uio *uio) {
|
||||
(void)v;
|
||||
(void)uio;
|
||||
return EISDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_uio_op_notdir(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_uio_op_notdir(struct vnode *v, struct uio *uio) {
|
||||
(void)v;
|
||||
(void)uio;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_name_op_notdir(struct vnode *v, const char *name)
|
||||
{
|
||||
static int emufs_name_op_notdir(struct vnode *v, const char *name) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_readlink_notlink(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int emufs_readlink_notlink(struct vnode *v, struct uio *uio) {
|
||||
(void)v;
|
||||
(void)uio;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_creat_notdir(struct vnode *v, const char *name, bool excl, mode_t mode,
|
||||
struct vnode **retval)
|
||||
{
|
||||
static int emufs_creat_notdir(struct vnode *v, const char *name, bool excl,
|
||||
mode_t mode, struct vnode **retval) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
(void)excl;
|
||||
@@ -992,41 +870,31 @@ emufs_creat_notdir(struct vnode *v, const char *name, bool excl, mode_t mode,
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_symlink_notdir(struct vnode *v, const char *contents, const char *name)
|
||||
{
|
||||
static int emufs_symlink_notdir(struct vnode *v, const char *contents,
|
||||
const char *name) {
|
||||
(void)v;
|
||||
(void)contents;
|
||||
(void)name;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_mkdir_notdir(struct vnode *v, const char *name, mode_t mode)
|
||||
{
|
||||
static int emufs_mkdir_notdir(struct vnode *v, const char *name, mode_t mode) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
(void)mode;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_link_notdir(struct vnode *v, const char *name, struct vnode *target)
|
||||
{
|
||||
static int emufs_link_notdir(struct vnode *v, const char *name,
|
||||
struct vnode *target) {
|
||||
(void)v;
|
||||
(void)name;
|
||||
(void)target;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_rename_notdir(struct vnode *v1, const char *n1,
|
||||
struct vnode *v2, const char *n2)
|
||||
{
|
||||
static int emufs_rename_notdir(struct vnode *v1, const char *n1,
|
||||
struct vnode *v2, const char *n2) {
|
||||
(void)v1;
|
||||
(void)n1;
|
||||
(void)v2;
|
||||
@@ -1034,21 +902,17 @@ emufs_rename_notdir(struct vnode *v1, const char *n1,
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_lookup_notdir(struct vnode *v, char *pathname, struct vnode **result)
|
||||
{
|
||||
static int emufs_lookup_notdir(struct vnode *v, char *pathname,
|
||||
struct vnode **result) {
|
||||
(void)v;
|
||||
(void)pathname;
|
||||
(void)result;
|
||||
return ENOTDIR;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
emufs_lookparent_notdir(struct vnode *v, char *pathname, struct vnode **result,
|
||||
char *buf, size_t len)
|
||||
{
|
||||
static int emufs_lookparent_notdir(struct vnode *v, char *pathname,
|
||||
struct vnode **result, char *buf,
|
||||
size_t len) {
|
||||
(void)v;
|
||||
(void)pathname;
|
||||
(void)result;
|
||||
@@ -1057,11 +921,7 @@ emufs_lookparent_notdir(struct vnode *v, char *pathname, struct vnode **result,
|
||||
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)len;
|
||||
return ENOTDIR;
|
||||
@@ -1140,11 +1000,8 @@ static const struct vnode_ops emufs_dirops = {
|
||||
/*
|
||||
* Function to load a vnode into memory.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
|
||||
struct emufs_vnode **ret)
|
||||
{
|
||||
static int emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
|
||||
struct emufs_vnode **ret) {
|
||||
struct vnode *v;
|
||||
struct emufs_vnode *ev;
|
||||
unsigned i, num;
|
||||
@@ -1217,10 +1074,7 @@ emufs_loadvnode(struct emufs_fs *ef, uint32_t handle, int isdir,
|
||||
/*
|
||||
* FSOP_SYNC
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_sync(struct fs *fs)
|
||||
{
|
||||
static int emufs_sync(struct fs *fs) {
|
||||
(void)fs;
|
||||
return 0;
|
||||
}
|
||||
@@ -1228,10 +1082,7 @@ emufs_sync(struct fs *fs)
|
||||
/*
|
||||
* FSOP_GETVOLNAME
|
||||
*/
|
||||
static
|
||||
const char *
|
||||
emufs_getvolname(struct fs *fs)
|
||||
{
|
||||
static const char *emufs_getvolname(struct fs *fs) {
|
||||
/* We don't have a volume name beyond the device name */
|
||||
(void)fs;
|
||||
return NULL;
|
||||
@@ -1240,10 +1091,7 @@ emufs_getvolname(struct fs *fs)
|
||||
/*
|
||||
* FSOP_GETROOT
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_getroot(struct fs *fs, struct vnode **ret)
|
||||
{
|
||||
static int emufs_getroot(struct fs *fs, struct vnode **ret) {
|
||||
struct emufs_fs *ef;
|
||||
|
||||
KASSERT(fs != NULL);
|
||||
@@ -1261,10 +1109,7 @@ emufs_getroot(struct fs *fs, struct vnode **ret)
|
||||
/*
|
||||
* FSOP_UNMOUNT
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_unmount(struct fs *fs)
|
||||
{
|
||||
static int emufs_unmount(struct fs *fs) {
|
||||
/* Always prohibit unmount, as we're not really "mounted" */
|
||||
(void)fs;
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
emufs_addtovfs(struct emu_softc *sc, const char *devname)
|
||||
{
|
||||
static int emufs_addtovfs(struct emu_softc *sc, const char *devname) {
|
||||
struct emufs_fs *ef;
|
||||
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.
|
||||
*/
|
||||
int
|
||||
config_emu(struct emu_softc *sc, int emuno)
|
||||
{
|
||||
int config_emu(struct emu_softc *sc, int emuno) {
|
||||
char name[32];
|
||||
|
||||
sc->e_lock = lock_create("emufs-lock");
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#ifndef _LAMEBUS_EMU_H_
|
||||
#define _LAMEBUS_EMU_H_
|
||||
|
||||
|
||||
#define EMU_MAXIO 16384
|
||||
#define EMU_ROOTHANDLE 0
|
||||
|
||||
@@ -58,5 +57,4 @@ struct emu_softc {
|
||||
/* Functions called by lower-level drivers */
|
||||
void emu_irq(/*struct emu_softc*/ void *);
|
||||
|
||||
|
||||
#endif /* _LAMEBUS_EMU_H_ */
|
||||
|
||||
@@ -40,12 +40,10 @@
|
||||
/* Lowest revision we support */
|
||||
#define LOW_VERSION 1
|
||||
|
||||
struct emu_softc *
|
||||
attach_emu_to_lamebus(int emuno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct emu_softc *attach_emu_to_lamebus(int emuno, struct lamebus_softc *sc) {
|
||||
struct emu_softc *es;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_EMUFS,
|
||||
LOW_VERSION, NULL);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_EMUFS, LOW_VERSION, NULL);
|
||||
if (slot < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -58,15 +58,11 @@
|
||||
#define CTLCPU_CIPI 0x004
|
||||
#define CTLCPU_CRAM 0x300
|
||||
|
||||
|
||||
/*
|
||||
* Read a config register for the given slot.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
uint32_t
|
||||
read_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset)
|
||||
{
|
||||
static inline 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. */
|
||||
offset += LB_CONFIG_SIZE * slot;
|
||||
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.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
void
|
||||
write_cfg_register(struct lamebus_softc *lb, int slot, uint32_t offset,
|
||||
uint32_t val)
|
||||
{
|
||||
static inline void write_cfg_register(struct lamebus_softc *lb, int slot,
|
||||
uint32_t offset, uint32_t val) {
|
||||
offset += LB_CONFIG_SIZE * slot;
|
||||
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.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
uint32_t
|
||||
read_ctl_register(struct lamebus_softc *lb, uint32_t offset)
|
||||
{
|
||||
static inline uint32_t read_ctl_register(struct lamebus_softc *lb,
|
||||
uint32_t offset) {
|
||||
/* Note that lb might be NULL on some platforms in some contexts. */
|
||||
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.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
void
|
||||
write_ctl_register(struct lamebus_softc *lb, uint32_t offset, uint32_t val)
|
||||
{
|
||||
static inline void write_ctl_register(struct lamebus_softc *lb, uint32_t offset,
|
||||
uint32_t val) {
|
||||
write_cfg_register(lb, LB_CONTROLLER_SLOT, offset, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write one of the bus controller's CPU control registers.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
void
|
||||
write_ctlcpu_register(struct lamebus_softc *lb, unsigned hw_cpunum,
|
||||
uint32_t offset, uint32_t val)
|
||||
{
|
||||
static inline void 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;
|
||||
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.
|
||||
*/
|
||||
void
|
||||
lamebus_find_cpus(struct lamebus_softc *lamebus)
|
||||
{
|
||||
void lamebus_find_cpus(struct lamebus_softc *lamebus) {
|
||||
uint32_t mainboard_vid, mainboard_did;
|
||||
uint32_t cpumask, self, bit, val;
|
||||
unsigned i, numcpus, bootcpu;
|
||||
unsigned hwnum[32];
|
||||
|
||||
mainboard_vid = read_cfg_register(lamebus, LB_CONTROLLER_SLOT,
|
||||
CFGREG_VID);
|
||||
mainboard_did = read_cfg_register(lamebus, LB_CONTROLLER_SLOT,
|
||||
CFGREG_DID);
|
||||
if (mainboard_vid == LB_VENDOR_CS161 &&
|
||||
mainboard_did == LBCS161_UPBUSCTL) {
|
||||
mainboard_vid = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, CFGREG_VID);
|
||||
mainboard_did = read_cfg_register(lamebus, LB_CONTROLLER_SLOT, CFGREG_DID);
|
||||
if (mainboard_vid == LB_VENDOR_CS161 && mainboard_did == LBCS161_UPBUSCTL) {
|
||||
/* Old uniprocessor mainboard; no cpu registers. */
|
||||
lamebus->ls_uniprocessor = 1;
|
||||
return;
|
||||
@@ -175,8 +153,7 @@ lamebus_find_cpus(struct lamebus_softc *lamebus)
|
||||
for (i = 0; i < numcpus; i++) {
|
||||
if (i != bootcpu) {
|
||||
val = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val = 0xffffffff;
|
||||
}
|
||||
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
|
||||
* this logic will have to be made more complex.
|
||||
*/
|
||||
void
|
||||
lamebus_start_cpus(struct lamebus_softc *lamebus)
|
||||
{
|
||||
void lamebus_start_cpus(struct lamebus_softc *lamebus) {
|
||||
uint32_t cpumask, self, bit;
|
||||
uint32_t ctlcpuoffset;
|
||||
uint32_t *cram;
|
||||
@@ -218,8 +193,7 @@ lamebus_start_cpus(struct lamebus_softc *lamebus)
|
||||
continue;
|
||||
}
|
||||
ctlcpuoffset = LB_CTLCPU_OFFSET + i * LB_CTLCPU_SIZE;
|
||||
cram = lamebus_map_area(lamebus,
|
||||
LB_CONTROLLER_SLOT,
|
||||
cram = lamebus_map_area(lamebus, LB_CONTROLLER_SLOT,
|
||||
ctlcpuoffset + CTLCPU_CRAM);
|
||||
cram[0] = (uint32_t)cpu_start_secondary;
|
||||
cram[1] = cpunum++;
|
||||
@@ -247,11 +221,8 @@ lamebus_start_cpus(struct lamebus_softc *lamebus)
|
||||
* more specific checks.
|
||||
*/
|
||||
|
||||
int
|
||||
lamebus_probe(struct lamebus_softc *sc,
|
||||
uint32_t vendorid, uint32_t deviceid,
|
||||
uint32_t lowver, uint32_t *version_ret)
|
||||
{
|
||||
int lamebus_probe(struct lamebus_softc *sc, uint32_t vendorid,
|
||||
uint32_t deviceid, uint32_t lowver, uint32_t *version_ret) {
|
||||
int slot;
|
||||
uint32_t val;
|
||||
|
||||
@@ -306,9 +277,7 @@ lamebus_probe(struct lamebus_softc *sc,
|
||||
* This prevents the probe routine from returning the same device over
|
||||
* and over again.
|
||||
*/
|
||||
void
|
||||
lamebus_mark(struct lamebus_softc *sc, int slot)
|
||||
{
|
||||
void lamebus_mark(struct lamebus_softc *sc, int slot) {
|
||||
uint32_t mask = ((uint32_t)1) << slot;
|
||||
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.
|
||||
*/
|
||||
void
|
||||
lamebus_unmark(struct lamebus_softc *sc, int slot)
|
||||
{
|
||||
void lamebus_unmark(struct lamebus_softc *sc, int slot) {
|
||||
uint32_t mask = ((uint32_t)1) << slot;
|
||||
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
|
||||
* when a particular slot signals an interrupt.
|
||||
*/
|
||||
void
|
||||
lamebus_attach_interrupt(struct lamebus_softc *sc, int slot,
|
||||
void *devdata,
|
||||
void (*irqfunc)(void *devdata))
|
||||
{
|
||||
void lamebus_attach_interrupt(struct lamebus_softc *sc, int slot, void *devdata,
|
||||
void (*irqfunc)(void *devdata)) {
|
||||
uint32_t mask = ((uint32_t)1) << slot;
|
||||
KASSERT(slot >= 0 && slot < LB_NSLOTS);
|
||||
|
||||
spinlock_acquire(&sc->ls_lock);
|
||||
|
||||
if ((sc->ls_slotsinuse & mask) == 0) {
|
||||
panic("lamebus_attach_interrupt: slot %d not marked in use\n",
|
||||
slot);
|
||||
panic("lamebus_attach_interrupt: slot %d not marked in use\n", slot);
|
||||
}
|
||||
|
||||
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
|
||||
* signaled an interrupt.
|
||||
*/
|
||||
void
|
||||
lamebus_detach_interrupt(struct lamebus_softc *sc, int slot)
|
||||
{
|
||||
void lamebus_detach_interrupt(struct lamebus_softc *sc, int slot) {
|
||||
uint32_t mask = ((uint32_t)1) << slot;
|
||||
KASSERT(slot >= 0 && slot < LB_NSLOTS);
|
||||
|
||||
spinlock_acquire(&sc->ls_lock);
|
||||
|
||||
if ((sc->ls_slotsinuse & mask) == 0) {
|
||||
panic("lamebus_detach_interrupt: slot %d not marked in use\n",
|
||||
slot);
|
||||
panic("lamebus_detach_interrupt: slot %d not marked in use\n", slot);
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
void
|
||||
lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot)
|
||||
{
|
||||
void lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot) {
|
||||
uint32_t bits, mask = ((uint32_t)1) << slot;
|
||||
KASSERT(slot >= 0 && slot < LB_NSLOTS);
|
||||
|
||||
@@ -412,9 +370,7 @@ lamebus_mask_interrupt(struct lamebus_softc *lamebus, int slot)
|
||||
spinlock_release(&lamebus->ls_lock);
|
||||
}
|
||||
|
||||
void
|
||||
lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot)
|
||||
{
|
||||
void lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot) {
|
||||
uint32_t bits, mask = ((uint32_t)1) << slot;
|
||||
KASSERT(slot >= 0 && slot < LB_NSLOTS);
|
||||
|
||||
@@ -425,13 +381,10 @@ lamebus_unmask_interrupt(struct lamebus_softc *lamebus, int slot)
|
||||
spinlock_release(&lamebus->ls_lock);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* LAMEbus interrupt handling function. (Machine-independent!)
|
||||
*/
|
||||
void
|
||||
lamebus_interrupt(struct lamebus_softc *lamebus)
|
||||
{
|
||||
void lamebus_interrupt(struct lamebus_softc *lamebus) {
|
||||
/*
|
||||
* Note that despite the fact that "spl" stands for "set
|
||||
* 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.
|
||||
*/
|
||||
kprintf("lamebus: stray interrupt on cpu %u\n",
|
||||
curcpu->c_number);
|
||||
kprintf("lamebus: stray interrupt on cpu %u\n", curcpu->c_number);
|
||||
duds++;
|
||||
duds_this_time++;
|
||||
|
||||
@@ -543,7 +495,6 @@ lamebus_interrupt(struct lamebus_softc *lamebus)
|
||||
irqs = read_ctl_register(lamebus, CTLREG_IRQS);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If we get interrupts for a slot with no driver or no
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
lamebus_poweroff(struct lamebus_softc *lamebus)
|
||||
{
|
||||
void lamebus_poweroff(struct lamebus_softc *lamebus) {
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
uint32_t
|
||||
lamebus_ramsize(void)
|
||||
{
|
||||
uint32_t lamebus_ramsize(void) {
|
||||
/*
|
||||
* Note that this has to work before bus initialization.
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
lamebus_assert_ipi(struct lamebus_softc *lamebus, struct cpu *target)
|
||||
{
|
||||
void lamebus_assert_ipi(struct lamebus_softc *lamebus, struct cpu *target) {
|
||||
if (lamebus->ls_uniprocessor) {
|
||||
return;
|
||||
}
|
||||
write_ctlcpu_register(lamebus, target->c_hardware_number,
|
||||
CTLCPU_CIPI, 1);
|
||||
write_ctlcpu_register(lamebus, target->c_hardware_number, CTLCPU_CIPI, 1);
|
||||
}
|
||||
|
||||
void
|
||||
lamebus_clear_ipi(struct lamebus_softc *lamebus, struct cpu *target)
|
||||
{
|
||||
void lamebus_clear_ipi(struct lamebus_softc *lamebus, struct cpu *target) {
|
||||
if (lamebus->ls_uniprocessor) {
|
||||
return;
|
||||
}
|
||||
write_ctlcpu_register(lamebus, target->c_hardware_number,
|
||||
CTLCPU_CIPI, 0);
|
||||
write_ctlcpu_register(lamebus, target->c_hardware_number, CTLCPU_CIPI, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initial setup.
|
||||
* Should be called from mainbus_bootstrap().
|
||||
*/
|
||||
struct lamebus_softc *
|
||||
lamebus_init(void)
|
||||
{
|
||||
struct lamebus_softc *lamebus_init(void) {
|
||||
struct lamebus_softc *lamebus;
|
||||
int i;
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
* Machine-independent definitions.
|
||||
*/
|
||||
|
||||
|
||||
/* Vendors */
|
||||
#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.
|
||||
*/
|
||||
int lamebus_probe(struct lamebus_softc *,
|
||||
uint32_t vendorid, uint32_t deviceid,
|
||||
int lamebus_probe(struct lamebus_softc *, uint32_t vendorid, uint32_t deviceid,
|
||||
uint32_t lowver, uint32_t *version_ret);
|
||||
|
||||
/*
|
||||
@@ -128,8 +126,7 @@ void lamebus_unmark(struct lamebus_softc *, int slot);
|
||||
/*
|
||||
* Attach to an interrupt.
|
||||
*/
|
||||
void lamebus_attach_interrupt(struct lamebus_softc *, int slot,
|
||||
void *devdata,
|
||||
void lamebus_attach_interrupt(struct lamebus_softc *, int slot, void *devdata,
|
||||
void (*irqfunc)(void *devdata));
|
||||
/*
|
||||
* 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 offset);
|
||||
void lamebus_write_register(struct lamebus_softc *, int slot,
|
||||
uint32_t offset, uint32_t val);
|
||||
void lamebus_write_register(struct lamebus_softc *, int slot, uint32_t offset,
|
||||
uint32_t val);
|
||||
|
||||
/*
|
||||
* Map a buffer that starts at offset OFFSET within slot SLOT.
|
||||
*/
|
||||
void *lamebus_map_area(struct lamebus_softc *, int slot,
|
||||
uint32_t offset);
|
||||
|
||||
void *lamebus_map_area(struct lamebus_softc *, int slot, uint32_t offset);
|
||||
|
||||
#endif /* _LAMEBUS_H_ */
|
||||
|
||||
@@ -63,33 +63,28 @@
|
||||
/*
|
||||
* Shortcut for reading a register.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
uint32_t lhd_rdreg(struct lhd_softc *lh, uint32_t reg)
|
||||
{
|
||||
static inline uint32_t lhd_rdreg(struct lhd_softc *lh, uint32_t reg) {
|
||||
return bus_read_register(lh->lh_busdata, lh->lh_buspos, reg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shortcut for writing a register.
|
||||
*/
|
||||
static
|
||||
inline
|
||||
void lhd_wreg(struct lhd_softc *lh, uint32_t reg, uint32_t val)
|
||||
{
|
||||
static 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a result code from the hardware to an errno value.
|
||||
*/
|
||||
static
|
||||
int lhd_code_to_errno(struct lhd_softc *lh, int code)
|
||||
{
|
||||
static int lhd_code_to_errno(struct lhd_softc *lh, int code) {
|
||||
switch (code & LHD_STATEMASK) {
|
||||
case LHD_OK: return 0;
|
||||
case LHD_INVSECT: return EINVAL;
|
||||
case LHD_MEDIA: return EIO;
|
||||
case LHD_OK:
|
||||
return 0;
|
||||
case LHD_INVSECT:
|
||||
return EINVAL;
|
||||
case LHD_MEDIA:
|
||||
return EIO;
|
||||
}
|
||||
kprintf("lhd%d: Unknown result code %d\n", lh->lh_unit, code);
|
||||
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
|
||||
* completion semaphore.
|
||||
*/
|
||||
static
|
||||
void
|
||||
lhd_iodone(struct lhd_softc *lh, int err)
|
||||
{
|
||||
static void lhd_iodone(struct lhd_softc *lh, int err) {
|
||||
lh->lh_result = err;
|
||||
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
|
||||
* register and report completion.
|
||||
*/
|
||||
void
|
||||
lhd_irq(void *vlh)
|
||||
{
|
||||
void lhd_irq(void *vlh) {
|
||||
struct lhd_softc *lh = vlh;
|
||||
uint32_t val;
|
||||
|
||||
@@ -136,10 +126,7 @@ lhd_irq(void *vlh)
|
||||
/*
|
||||
* Function called when we are open()'d.
|
||||
*/
|
||||
static
|
||||
int
|
||||
lhd_eachopen(struct device *d, int openflags)
|
||||
{
|
||||
static int lhd_eachopen(struct device *d, int openflags) {
|
||||
/*
|
||||
* Don't need to do anything.
|
||||
*/
|
||||
@@ -152,10 +139,7 @@ lhd_eachopen(struct device *d, int openflags)
|
||||
/*
|
||||
* Function for handling ioctls.
|
||||
*/
|
||||
static
|
||||
int
|
||||
lhd_ioctl(struct device *d, int op, userptr_t data)
|
||||
{
|
||||
static int lhd_ioctl(struct device *d, int op, userptr_t data) {
|
||||
/*
|
||||
* We don't support any ioctls.
|
||||
*/
|
||||
@@ -182,10 +166,7 @@ lhd_reset(struct lhd_softc *lh)
|
||||
/*
|
||||
* I/O function (for both reads and writes)
|
||||
*/
|
||||
static
|
||||
int
|
||||
lhd_io(struct device *d, struct uio *uio)
|
||||
{
|
||||
static int lhd_io(struct device *d, struct uio *uio) {
|
||||
struct lhd_softc *lh = d->d_data;
|
||||
|
||||
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.
|
||||
*/
|
||||
int
|
||||
config_lhd(struct lhd_softc *lh, int lhdno)
|
||||
{
|
||||
int config_lhd(struct lhd_softc *lh, int lhdno) {
|
||||
char name[32];
|
||||
|
||||
/* Figure out what our name is. */
|
||||
@@ -298,8 +277,8 @@ config_lhd(struct lhd_softc *lh, int lhdno)
|
||||
|
||||
/* Set up the VFS device structure. */
|
||||
lh->lh_dev.d_ops = &lhd_devops;
|
||||
lh->lh_dev.d_blocks = bus_read_register(lh->lh_busdata, lh->lh_buspos,
|
||||
LHD_REG_NSECT);
|
||||
lh->lh_dev.d_blocks =
|
||||
bus_read_register(lh->lh_busdata, lh->lh_buspos, LHD_REG_NSECT);
|
||||
lh->lh_dev.d_blocksize = LHD_SECTSIZE;
|
||||
lh->lh_dev.d_data = lh;
|
||||
|
||||
|
||||
@@ -39,12 +39,10 @@
|
||||
/* Lowest revision we support */
|
||||
#define LOW_VERSION 2
|
||||
|
||||
struct lhd_softc *
|
||||
attach_lhd_to_lamebus(int lhdno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct lhd_softc *attach_lhd_to_lamebus(int lhdno, struct lamebus_softc *sc) {
|
||||
struct lhd_softc *lh;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_DISK,
|
||||
LOW_VERSION, NULL);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_DISK, LOW_VERSION, NULL);
|
||||
if (slot < 0) {
|
||||
/* None found */
|
||||
return NULL;
|
||||
|
||||
@@ -33,14 +33,10 @@
|
||||
/*#include <lamebus/lnet.h>*/ /* not yet */
|
||||
#include "autoconf.h"
|
||||
|
||||
int
|
||||
config_lnet(struct lnet_softc *sc, int lnetno)
|
||||
{
|
||||
int config_lnet(struct lnet_softc *sc, int lnetno) {
|
||||
(void)sc;
|
||||
|
||||
kprintf("lnet%d: No network support in system\n", lnetno);
|
||||
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,11 +37,10 @@
|
||||
/* Highest revision we support */
|
||||
#define HIGH_VERSION 1
|
||||
|
||||
struct lnet_softc *
|
||||
attach_lnet_to_lamebus(int lnetno, struct lamebus_softc *sc)
|
||||
{
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_NET,
|
||||
LOW_VERSION, HIGH_VERSION);
|
||||
struct lnet_softc *attach_lnet_to_lamebus(int lnetno,
|
||||
struct lamebus_softc *sc) {
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_NET, LOW_VERSION,
|
||||
HIGH_VERSION);
|
||||
if (slot < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -43,38 +43,29 @@
|
||||
/* Constants */
|
||||
#define LR_RANDMAX 0xffffffff
|
||||
|
||||
int
|
||||
config_lrandom(struct lrandom_softc *lr, int lrandomno)
|
||||
{
|
||||
int config_lrandom(struct lrandom_softc *lr, int lrandomno) {
|
||||
(void)lrandomno;
|
||||
(void)lr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
lrandom_random(void *devdata)
|
||||
{
|
||||
uint32_t lrandom_random(void *devdata) {
|
||||
struct lrandom_softc *lr = devdata;
|
||||
return bus_read_register(lr->lr_bus, lr->lr_buspos, LR_REG_RAND);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
lrandom_randmax(void *devdata)
|
||||
{
|
||||
uint32_t lrandom_randmax(void *devdata) {
|
||||
(void)devdata;
|
||||
return LR_RANDMAX;
|
||||
}
|
||||
|
||||
int
|
||||
lrandom_read(void *devdata, struct uio *uio)
|
||||
{
|
||||
int lrandom_read(void *devdata, struct uio *uio) {
|
||||
struct lrandom_softc *lr = devdata;
|
||||
uint32_t val;
|
||||
int result;
|
||||
|
||||
while (uio->uio_resid > 0) {
|
||||
val = bus_read_register(lr->lr_bus, lr->lr_buspos,
|
||||
LR_REG_RAND);
|
||||
val = bus_read_register(lr->lr_bus, lr->lr_buspos, LR_REG_RAND);
|
||||
result = uiomove(&val, sizeof(val), uio);
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
@@ -36,12 +36,11 @@
|
||||
/* Lowest revision we support */
|
||||
#define LOW_VERSION 1
|
||||
|
||||
struct lrandom_softc *
|
||||
attach_lrandom_to_lamebus(int lrandomno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct lrandom_softc *attach_lrandom_to_lamebus(int lrandomno,
|
||||
struct lamebus_softc *sc) {
|
||||
struct lrandom_softc *lr;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_RANDOM,
|
||||
LOW_VERSION, NULL);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_RANDOM, LOW_VERSION, NULL);
|
||||
if (slot < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -54,21 +54,13 @@
|
||||
#define LSCR_SCREEN 32768
|
||||
|
||||
/* Convert a 32-bit X/Y pair to X and Y coordinates. */
|
||||
static
|
||||
inline
|
||||
void
|
||||
splitxy(uint32_t xy, unsigned *x, unsigned *y)
|
||||
{
|
||||
static inline void splitxy(uint32_t xy, unsigned *x, unsigned *y) {
|
||||
*x = xy >> 16;
|
||||
*y = xy & 0xffff;
|
||||
}
|
||||
|
||||
/* Convert X and Y coordinates to a single 32-bit value. */
|
||||
static
|
||||
inline
|
||||
uint32_t
|
||||
mergexy(unsigned x, unsigned y)
|
||||
{
|
||||
static inline uint32_t mergexy(unsigned x, unsigned y) {
|
||||
uint32_t val = x;
|
||||
|
||||
return (val << 16) | y;
|
||||
@@ -79,9 +71,7 @@ mergexy(unsigned x, unsigned y)
|
||||
/*
|
||||
* Interrupt handler.
|
||||
*/
|
||||
void
|
||||
lscreen_irq(void *vsc)
|
||||
{
|
||||
void lscreen_irq(void *vsc) {
|
||||
struct lscreen_softc *sc = vsc;
|
||||
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);
|
||||
if (x & LSCR_IRQ_ACTIVE) {
|
||||
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_CHAR);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_RIRQ, LSCR_IRQ_ENABLE);
|
||||
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_CHAR);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ,
|
||||
LSCR_IRQ_ENABLE);
|
||||
|
||||
spinlock_release(&sc->ls_lock);
|
||||
if (sc->ls_input) {
|
||||
sc->ls_input(sc->ls_devdata, ch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
spinlock_release(&sc->ls_lock);
|
||||
}
|
||||
}
|
||||
@@ -109,10 +97,7 @@ lscreen_irq(void *vsc)
|
||||
/*
|
||||
* Handle a newline on the screen.
|
||||
*/
|
||||
static
|
||||
void
|
||||
lscreen_newline(struct lscreen_softc *sc)
|
||||
{
|
||||
static void lscreen_newline(struct lscreen_softc *sc) {
|
||||
if (sc->ls_cy >= sc->ls_height - 1) {
|
||||
/*
|
||||
* Scroll
|
||||
@@ -120,10 +105,8 @@ lscreen_newline(struct lscreen_softc *sc)
|
||||
|
||||
memmove(sc->ls_screen, sc->ls_screen + sc->ls_width,
|
||||
sc->ls_width * (sc->ls_height - 1));
|
||||
bzero(sc->ls_screen + sc->ls_width * (sc->ls_height-1),
|
||||
sc->ls_width);
|
||||
}
|
||||
else {
|
||||
bzero(sc->ls_screen + sc->ls_width * (sc->ls_height - 1), sc->ls_width);
|
||||
} else {
|
||||
sc->ls_cy++;
|
||||
}
|
||||
sc->ls_cx = 0;
|
||||
@@ -132,10 +115,7 @@ lscreen_newline(struct lscreen_softc *sc)
|
||||
/*
|
||||
* Handle a printable character being written to the screen.
|
||||
*/
|
||||
static
|
||||
void
|
||||
lscreen_char(struct lscreen_softc *sc, int ch)
|
||||
{
|
||||
static void lscreen_char(struct lscreen_softc *sc, int ch) {
|
||||
if (sc->ls_cx >= sc->ls_width) {
|
||||
lscreen_newline(sc);
|
||||
}
|
||||
@@ -148,17 +128,19 @@ lscreen_char(struct lscreen_softc *sc, int ch)
|
||||
* Send a character to the screen.
|
||||
* This should probably know about backspace and tab.
|
||||
*/
|
||||
void
|
||||
lscreen_write(void *vsc, int ch)
|
||||
{
|
||||
void lscreen_write(void *vsc, int ch) {
|
||||
struct lscreen_softc *sc = vsc;
|
||||
int ccx, ccy;
|
||||
|
||||
spinlock_acquire(&sc->ls_lock);
|
||||
|
||||
switch (ch) {
|
||||
case '\n': lscreen_newline(sc); break;
|
||||
default: lscreen_char(sc, ch); break;
|
||||
case '\n':
|
||||
lscreen_newline(sc);
|
||||
break;
|
||||
default:
|
||||
lscreen_char(sc, ch);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -173,8 +155,8 @@ lscreen_write(void *vsc, int ch)
|
||||
}
|
||||
|
||||
/* Set the cursor position */
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_POSN, mergexy(ccx, ccy));
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_POSN,
|
||||
mergexy(ccx, ccy));
|
||||
|
||||
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.
|
||||
*/
|
||||
int
|
||||
config_lscreen(struct lscreen_softc *sc, int lscreenno)
|
||||
{
|
||||
int config_lscreen(struct lscreen_softc *sc, int lscreenno) {
|
||||
uint32_t val;
|
||||
|
||||
(void)lscreenno;
|
||||
@@ -197,29 +177,25 @@ config_lscreen(struct lscreen_softc *sc, int lscreenno)
|
||||
* Enable interrupting.
|
||||
*/
|
||||
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_RIRQ, LSCR_IRQ_ENABLE);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_RIRQ,
|
||||
LSCR_IRQ_ENABLE);
|
||||
|
||||
/*
|
||||
* Get screen size.
|
||||
*/
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_SIZE);
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_SIZE);
|
||||
splitxy(val, &sc->ls_width, &sc->ls_height);
|
||||
|
||||
/*
|
||||
* Get cursor position.
|
||||
*/
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_REG_POSN);
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSCR_REG_POSN);
|
||||
splitxy(val, &sc->ls_cx, &sc->ls_cy);
|
||||
|
||||
/*
|
||||
* Get a pointer to the memory-mapped screen area.
|
||||
*/
|
||||
sc->ls_screen = bus_map_area(sc->ls_busdata, sc->ls_buspos,
|
||||
LSCR_SCREEN);
|
||||
sc->ls_screen = bus_map_area(sc->ls_busdata, sc->ls_buspos, LSCR_SCREEN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,12 +41,11 @@
|
||||
/* Highest revision we support */
|
||||
#define HIGH_VERSION 1
|
||||
|
||||
struct lscreen_softc *
|
||||
attach_lscreen_to_lamebus(int lscreenno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct lscreen_softc *attach_lscreen_to_lamebus(int lscreenno,
|
||||
struct lamebus_softc *sc) {
|
||||
struct lscreen_softc *ls;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SCREEN,
|
||||
LOW_VERSION, HIGH_VERSION);
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SCREEN, LOW_VERSION,
|
||||
HIGH_VERSION);
|
||||
if (slot < 0) {
|
||||
/* Not found */
|
||||
return NULL;
|
||||
|
||||
@@ -44,9 +44,7 @@
|
||||
#define LSER_IRQ_ACTIVE 2
|
||||
#define LSER_IRQ_FORCE 4
|
||||
|
||||
void
|
||||
lser_irq(void *vsc)
|
||||
{
|
||||
void lser_irq(void *vsc) {
|
||||
struct lser_softc *sc = vsc;
|
||||
uint32_t x;
|
||||
bool clear_to_write = false;
|
||||
@@ -60,18 +58,15 @@ lser_irq(void *vsc)
|
||||
x = LSER_IRQ_ENABLE;
|
||||
sc->ls_wbusy = 0;
|
||||
clear_to_write = true;
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ, x);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ, x);
|
||||
}
|
||||
|
||||
x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ);
|
||||
if (x & LSER_IRQ_ACTIVE) {
|
||||
x = LSER_IRQ_ENABLE;
|
||||
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_CHAR);
|
||||
ch = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_CHAR);
|
||||
got_a_read = true;
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_RIRQ, x);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ, x);
|
||||
}
|
||||
|
||||
spinlock_release(&sc->ls_lock);
|
||||
@@ -84,9 +79,7 @@ lser_irq(void *vsc)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
lser_write(void *vls, int ch)
|
||||
{
|
||||
void lser_write(void *vls, int ch) {
|
||||
struct lser_softc *ls = vls;
|
||||
|
||||
spinlock_acquire(&ls->ls_lock);
|
||||
@@ -112,24 +105,17 @@ lser_write(void *vls, int ch)
|
||||
spinlock_release(&ls->ls_lock);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
lser_poll_until_write(struct lser_softc *sc)
|
||||
{
|
||||
static void lser_poll_until_write(struct lser_softc *sc) {
|
||||
uint32_t val;
|
||||
|
||||
KASSERT(spinlock_do_i_hold(&sc->ls_lock));
|
||||
|
||||
do {
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ);
|
||||
}
|
||||
while ((val & LSER_IRQ_ACTIVE) == 0);
|
||||
val = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ);
|
||||
} while ((val & LSER_IRQ_ACTIVE) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
lser_writepolled(void *vsc, int ch)
|
||||
{
|
||||
void lser_writepolled(void *vsc, int ch) {
|
||||
struct lser_softc *sc = vsc;
|
||||
bool irqpending;
|
||||
|
||||
@@ -139,15 +125,12 @@ lser_writepolled(void *vsc, int ch)
|
||||
irqpending = true;
|
||||
lser_poll_until_write(sc);
|
||||
/* Clear the ready condition, but leave the IRQ asserted */
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ,
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
|
||||
LSER_IRQ_FORCE | LSER_IRQ_ENABLE);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
irqpending = false;
|
||||
/* Clear the interrupt enable bit */
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ, 0);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ, 0);
|
||||
}
|
||||
|
||||
/* Send the character. */
|
||||
@@ -164,16 +147,14 @@ lser_writepolled(void *vsc, int ch)
|
||||
* interrupt handler and they'll be cleared.
|
||||
*/
|
||||
if (!irqpending) {
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ, LSER_IRQ_ENABLE);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
|
||||
LSER_IRQ_ENABLE);
|
||||
}
|
||||
|
||||
spinlock_release(&sc->ls_lock);
|
||||
}
|
||||
|
||||
int
|
||||
config_lser(struct lser_softc *sc, int lserno)
|
||||
{
|
||||
int config_lser(struct lser_softc *sc, int lserno) {
|
||||
(void)lserno;
|
||||
|
||||
/*
|
||||
@@ -183,10 +164,10 @@ config_lser(struct lser_softc *sc, int lserno)
|
||||
spinlock_init(&sc->ls_lock);
|
||||
sc->ls_wbusy = false;
|
||||
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_RIRQ, LSER_IRQ_ENABLE);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos,
|
||||
LSER_REG_WIRQ, LSER_IRQ_ENABLE);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ,
|
||||
LSER_IRQ_ENABLE);
|
||||
bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ,
|
||||
LSER_IRQ_ENABLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,12 +36,11 @@
|
||||
/* Lowest revision we support */
|
||||
#define LOW_VERSION 1
|
||||
|
||||
struct lser_softc *
|
||||
attach_lser_to_lamebus(int lserno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct lser_softc *attach_lser_to_lamebus(int lserno,
|
||||
struct lamebus_softc *sc) {
|
||||
struct lser_softc *ls;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SERIAL,
|
||||
LOW_VERSION, NULL);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_SERIAL, LOW_VERSION, NULL);
|
||||
if (slot < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -54,9 +54,7 @@ static bool havetimerclock;
|
||||
/*
|
||||
* Setup routine called by autoconf stuff when an ltimer is found.
|
||||
*/
|
||||
int
|
||||
config_ltimer(struct ltimer_softc *lt, int ltimerno)
|
||||
{
|
||||
int config_ltimer(struct ltimer_softc *lt, int ltimerno) {
|
||||
/*
|
||||
* Running on System/161 2.x, we always use the processor
|
||||
* 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. */
|
||||
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,
|
||||
LT_GRANULARITY);
|
||||
bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_COUNT, LT_GRANULARITY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -103,9 +100,7 @@ config_ltimer(struct ltimer_softc *lt, int ltimerno)
|
||||
/*
|
||||
* Interrupt handler.
|
||||
*/
|
||||
void
|
||||
ltimer_irq(void *vlt)
|
||||
{
|
||||
void ltimer_irq(void *vlt) {
|
||||
struct ltimer_softc *lt = vlt;
|
||||
uint32_t val;
|
||||
|
||||
@@ -132,9 +127,7 @@ ltimer_irq(void *vlt)
|
||||
* doesn't matter what value you write. This function is called if
|
||||
* the beep device is attached to this timer.
|
||||
*/
|
||||
void
|
||||
ltimer_beep(void *vlt)
|
||||
{
|
||||
void ltimer_beep(void *vlt) {
|
||||
struct ltimer_softc *lt = vlt;
|
||||
|
||||
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
|
||||
* to this timer.
|
||||
*/
|
||||
void
|
||||
ltimer_gettime(void *vlt, struct timespec *ts)
|
||||
{
|
||||
void ltimer_gettime(void *vlt, struct timespec *ts) {
|
||||
struct ltimer_softc *lt = vlt;
|
||||
uint32_t secs1, secs2;
|
||||
int spl;
|
||||
@@ -169,19 +160,15 @@ ltimer_gettime(void *vlt, struct timespec *ts)
|
||||
|
||||
spl = splhigh();
|
||||
|
||||
secs1 = bus_read_register(lt->lt_bus, lt->lt_buspos,
|
||||
LT_REG_SEC);
|
||||
ts->tv_nsec = bus_read_register(lt->lt_bus, lt->lt_buspos,
|
||||
LT_REG_NSEC);
|
||||
secs2 = bus_read_register(lt->lt_bus, lt->lt_buspos,
|
||||
LT_REG_SEC);
|
||||
secs1 = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_SEC);
|
||||
ts->tv_nsec = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_NSEC);
|
||||
secs2 = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_SEC);
|
||||
|
||||
splx(spl);
|
||||
|
||||
if (ts->tv_nsec < 5000000) {
|
||||
ts->tv_sec = secs2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ts->tv_sec = secs1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,11 @@
|
||||
/* Lowest revision we support */
|
||||
#define LOW_VERSION 1
|
||||
|
||||
struct ltimer_softc *
|
||||
attach_ltimer_to_lamebus(int ltimerno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct ltimer_softc *attach_ltimer_to_lamebus(int ltimerno,
|
||||
struct lamebus_softc *sc) {
|
||||
struct ltimer_softc *lt;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TIMER,
|
||||
LOW_VERSION, NULL);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TIMER, LOW_VERSION, NULL);
|
||||
if (slot < 0) {
|
||||
/* No ltimer (or no additional ltimer) found */
|
||||
return NULL;
|
||||
|
||||
@@ -44,72 +44,56 @@
|
||||
|
||||
static struct ltrace_softc *the_trace;
|
||||
|
||||
void
|
||||
ltrace_on(uint32_t code)
|
||||
{
|
||||
void ltrace_on(uint32_t code) {
|
||||
if (the_trace != NULL) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_TRON, code);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_off(uint32_t code)
|
||||
{
|
||||
void ltrace_off(uint32_t code) {
|
||||
if (the_trace != NULL) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_TROFF, code);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_debug(uint32_t code)
|
||||
{
|
||||
void ltrace_debug(uint32_t code) {
|
||||
if (the_trace != NULL) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_DEBUG, code);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_dump(uint32_t code)
|
||||
{
|
||||
void ltrace_dump(uint32_t code) {
|
||||
if (the_trace != NULL) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_DUMP, code);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_stop(uint32_t code)
|
||||
{
|
||||
void ltrace_stop(uint32_t code) {
|
||||
if (the_trace != NULL && the_trace->lt_canstop) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_STOP, code);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_setprof(uint32_t onoff)
|
||||
{
|
||||
void ltrace_setprof(uint32_t onoff) {
|
||||
if (the_trace != NULL && the_trace->lt_canprof) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_PROFEN, onoff);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ltrace_eraseprof(void)
|
||||
{
|
||||
void ltrace_eraseprof(void) {
|
||||
if (the_trace != NULL && the_trace->lt_canprof) {
|
||||
bus_write_register(the_trace->lt_busdata, the_trace->lt_buspos,
|
||||
LTRACE_REG_PROFCL, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
config_ltrace(struct ltrace_softc *sc, int ltraceno)
|
||||
{
|
||||
int config_ltrace(struct ltrace_softc *sc, int ltraceno) {
|
||||
(void)ltraceno;
|
||||
the_trace = sc;
|
||||
return 0;
|
||||
|
||||
@@ -40,13 +40,12 @@
|
||||
/* Revision that supports ltrace_prof() */
|
||||
#define PROF_VERSION 3
|
||||
|
||||
struct ltrace_softc *
|
||||
attach_ltrace_to_lamebus(int ltraceno, struct lamebus_softc *sc)
|
||||
{
|
||||
struct ltrace_softc *attach_ltrace_to_lamebus(int ltraceno,
|
||||
struct lamebus_softc *sc) {
|
||||
struct ltrace_softc *lt;
|
||||
uint32_t drl;
|
||||
int slot = lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TRACE,
|
||||
LOW_VERSION, &drl);
|
||||
int slot =
|
||||
lamebus_probe(sc, LB_VENDOR_CS161, LBCS161_TRACE, LOW_VERSION, &drl);
|
||||
if (slot < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@
|
||||
#include <lamebus/lrandom.h>
|
||||
#include "autoconf.h"
|
||||
|
||||
struct random_softc *
|
||||
attach_random_to_lrandom(int randomno, struct lrandom_softc *ls)
|
||||
{
|
||||
struct random_softc *attach_random_to_lrandom(int randomno,
|
||||
struct lrandom_softc *ls) {
|
||||
struct random_softc *rs = kmalloc(sizeof(struct random_softc));
|
||||
if (rs == NULL) {
|
||||
return NULL;
|
||||
|
||||
@@ -44,9 +44,8 @@
|
||||
#include <lamebus/ltimer.h>
|
||||
#include "autoconf.h"
|
||||
|
||||
struct rtclock_softc *
|
||||
attach_rtclock_to_ltimer(int rtclockno, struct ltimer_softc *ls)
|
||||
{
|
||||
struct rtclock_softc *attach_rtclock_to_ltimer(int rtclockno,
|
||||
struct ltimer_softc *ls) {
|
||||
/*
|
||||
* No need to probe; ltimer always has a clock.
|
||||
* Just allocate the rtclock, set our fields, and return it.
|
||||
|
||||
@@ -104,7 +104,6 @@ struct semfs {
|
||||
DEFARRAY(semfs_sem, SEMFS_INLINE);
|
||||
DEFARRAY(semfs_direntry, SEMFS_INLINE);
|
||||
|
||||
|
||||
/*
|
||||
* Functions.
|
||||
*/
|
||||
@@ -119,5 +118,4 @@ void semfs_direntry_destroy(struct semfs_direntry *);
|
||||
/* in semfs_vnops.c */
|
||||
int semfs_getvnode(struct semfs *, unsigned, struct vnode **ret);
|
||||
|
||||
|
||||
#endif /* SEMFS_H */
|
||||
|
||||
@@ -42,10 +42,7 @@
|
||||
/*
|
||||
* Sync doesn't need to do anything.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_sync(struct fs *fs)
|
||||
{
|
||||
static int semfs_sync(struct fs *fs) {
|
||||
(void)fs;
|
||||
return 0;
|
||||
}
|
||||
@@ -53,10 +50,7 @@ semfs_sync(struct fs *fs)
|
||||
/*
|
||||
* We have only one volume name and it's hardwired.
|
||||
*/
|
||||
static
|
||||
const char *
|
||||
semfs_getvolname(struct fs *fs)
|
||||
{
|
||||
static const char *semfs_getvolname(struct fs *fs) {
|
||||
(void)fs;
|
||||
return "sem";
|
||||
}
|
||||
@@ -64,18 +58,14 @@ semfs_getvolname(struct fs *fs)
|
||||
/*
|
||||
* Get the root directory vnode.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_getroot(struct fs *fs, struct vnode **ret)
|
||||
{
|
||||
static int semfs_getroot(struct fs *fs, struct vnode **ret) {
|
||||
struct semfs *semfs = fs->fs_data;
|
||||
struct vnode *vn;
|
||||
int result;
|
||||
|
||||
result = semfs_getvnode(semfs, SEMFS_ROOTDIR, &vn);
|
||||
if (result) {
|
||||
kprintf("semfs: couldn't load root vnode: %s\n",
|
||||
strerror(result));
|
||||
kprintf("semfs: couldn't load root vnode: %s\n", strerror(result));
|
||||
return result;
|
||||
}
|
||||
*ret = vn;
|
||||
@@ -85,14 +75,10 @@ semfs_getroot(struct fs *fs, struct vnode **ret)
|
||||
////////////////////////////////////////////////////////////
|
||||
// mount and unmount logic
|
||||
|
||||
|
||||
/*
|
||||
* Destructor for struct semfs.
|
||||
*/
|
||||
static
|
||||
void
|
||||
semfs_destroy(struct semfs *semfs)
|
||||
{
|
||||
static void semfs_destroy(struct semfs *semfs) {
|
||||
struct semfs_sem *sem;
|
||||
struct semfs_direntry *dent;
|
||||
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
|
||||
* remounted, maybe unmounting it shouldn't be allowed.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_unmount(struct fs *fs)
|
||||
{
|
||||
static int semfs_unmount(struct fs *fs) {
|
||||
struct semfs *semfs = fs->fs_data;
|
||||
|
||||
lock_acquire(semfs->semfs_tablelock);
|
||||
@@ -154,10 +137,7 @@ static const struct fs_ops semfs_fsops = {
|
||||
/*
|
||||
* Constructor for struct semfs.
|
||||
*/
|
||||
static
|
||||
struct semfs *
|
||||
semfs_create(void)
|
||||
{
|
||||
static struct semfs *semfs_create(void) {
|
||||
struct semfs *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
|
||||
* "sem:" during bootup.
|
||||
*/
|
||||
void
|
||||
semfs_bootstrap(void)
|
||||
{
|
||||
void semfs_bootstrap(void) {
|
||||
struct semfs *semfs;
|
||||
int result;
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@
|
||||
/*
|
||||
* Constructor for semfs_sem.
|
||||
*/
|
||||
struct semfs_sem *
|
||||
semfs_sem_create(const char *name)
|
||||
{
|
||||
struct semfs_sem *semfs_sem_create(const char *name) {
|
||||
struct semfs_sem *sem;
|
||||
char lockname[32];
|
||||
char cvname[32];
|
||||
@@ -78,9 +76,7 @@ semfs_sem_create(const char *name)
|
||||
/*
|
||||
* Destructor for semfs_sem.
|
||||
*/
|
||||
void
|
||||
semfs_sem_destroy(struct semfs_sem *sem)
|
||||
{
|
||||
void semfs_sem_destroy(struct semfs_sem *sem) {
|
||||
cv_destroy(sem->sems_cv);
|
||||
lock_destroy(sem->sems_lock);
|
||||
kfree(sem);
|
||||
@@ -89,9 +85,8 @@ semfs_sem_destroy(struct semfs_sem *sem)
|
||||
/*
|
||||
* Helper to insert a semfs_sem into the semaphore table.
|
||||
*/
|
||||
int
|
||||
semfs_sem_insert(struct semfs *semfs, struct semfs_sem *sem, unsigned *ret)
|
||||
{
|
||||
int semfs_sem_insert(struct semfs *semfs, struct semfs_sem *sem,
|
||||
unsigned *ret) {
|
||||
unsigned i, num;
|
||||
|
||||
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.
|
||||
*/
|
||||
struct semfs_direntry *
|
||||
semfs_direntry_create(const char *name, unsigned semnum)
|
||||
{
|
||||
struct semfs_direntry *semfs_direntry_create(const char *name,
|
||||
unsigned semnum) {
|
||||
struct semfs_direntry *dent;
|
||||
|
||||
dent = kmalloc(sizeof(*dent));
|
||||
@@ -137,9 +131,7 @@ semfs_direntry_create(const char *name, unsigned semnum)
|
||||
/*
|
||||
* Destructor for semfs_direntry.
|
||||
*/
|
||||
void
|
||||
semfs_direntry_destroy(struct semfs_direntry *dent)
|
||||
{
|
||||
void semfs_direntry_destroy(struct semfs_direntry *dent) {
|
||||
kfree(dent->semd_name);
|
||||
kfree(dent);
|
||||
}
|
||||
|
||||
@@ -44,10 +44,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// basic ops
|
||||
|
||||
static
|
||||
int
|
||||
semfs_eachopen(struct vnode *vn, int openflags)
|
||||
{
|
||||
static int semfs_eachopen(struct vnode *vn, int openflags) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
|
||||
if (semv->semv_semnum == SEMFS_ROOTDIR) {
|
||||
@@ -62,30 +59,21 @@ semfs_eachopen(struct vnode *vn, int openflags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
semfs_ioctl(struct vnode *vn, int op, userptr_t data)
|
||||
{
|
||||
static int semfs_ioctl(struct vnode *vn, int op, userptr_t data) {
|
||||
(void)vn;
|
||||
(void)op;
|
||||
(void)data;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
semfs_gettype(struct vnode *vn, mode_t *ret)
|
||||
{
|
||||
static int semfs_gettype(struct vnode *vn, mode_t *ret) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
|
||||
*ret = semv->semv_semnum == SEMFS_ROOTDIR ? S_IFDIR : S_IFREG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
semfs_isseekable(struct vnode *vn)
|
||||
{
|
||||
static bool semfs_isseekable(struct vnode *vn) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
|
||||
if (semv->semv_semnum != SEMFS_ROOTDIR) {
|
||||
@@ -95,10 +83,7 @@ semfs_isseekable(struct vnode *vn)
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
semfs_fsync(struct vnode *vn)
|
||||
{
|
||||
static int semfs_fsync(struct vnode *vn) {
|
||||
(void)vn;
|
||||
return 0;
|
||||
}
|
||||
@@ -110,10 +95,8 @@ semfs_fsync(struct vnode *vn)
|
||||
* XXX fold these two together
|
||||
*/
|
||||
|
||||
static
|
||||
struct semfs_sem *
|
||||
semfs_getsembynum(struct semfs *semfs, unsigned semnum)
|
||||
{
|
||||
static struct semfs_sem *semfs_getsembynum(struct semfs *semfs,
|
||||
unsigned semnum) {
|
||||
struct semfs_sem *sem;
|
||||
|
||||
lock_acquire(semfs->semfs_tablelock);
|
||||
@@ -123,10 +106,7 @@ semfs_getsembynum(struct semfs *semfs, unsigned semnum)
|
||||
return sem;
|
||||
}
|
||||
|
||||
static
|
||||
struct semfs_sem *
|
||||
semfs_getsem(struct semfs_vnode *semv)
|
||||
{
|
||||
static struct semfs_sem *semfs_getsem(struct semfs_vnode *semv) {
|
||||
struct semfs *semfs = semv->semv_semfs;
|
||||
|
||||
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
|
||||
* will be more than 1.
|
||||
*/
|
||||
static
|
||||
void
|
||||
semfs_wakeup(struct semfs_sem *sem, unsigned newcount)
|
||||
{
|
||||
static void semfs_wakeup(struct semfs_sem *sem, unsigned newcount) {
|
||||
if (sem->sems_count > 0 || newcount == 0) {
|
||||
return;
|
||||
}
|
||||
if (newcount == 1) {
|
||||
cv_signal(sem->sems_cv, sem->sems_lock);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cv_broadcast(sem->sems_cv, sem->sems_lock);
|
||||
}
|
||||
}
|
||||
@@ -156,10 +132,7 @@ semfs_wakeup(struct semfs_sem *sem, unsigned newcount)
|
||||
/*
|
||||
* stat() for semaphore vnodes
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_semstat(struct vnode *vn, struct stat *buf)
|
||||
{
|
||||
static int semfs_semstat(struct vnode *vn, struct stat *buf) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
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.
|
||||
* Don't actually bother to transfer any data.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_read(struct vnode *vn, struct uio *uio)
|
||||
{
|
||||
static int semfs_read(struct vnode *vn, struct uio *uio) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
struct semfs_sem *sem;
|
||||
size_t consume;
|
||||
@@ -201,9 +171,8 @@ semfs_read(struct vnode *vn, struct uio *uio)
|
||||
if (consume > sem->sems_count) {
|
||||
consume = sem->sems_count;
|
||||
}
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: P, count %u -> %u\n",
|
||||
semv->semv_semnum, sem->sems_count,
|
||||
sem->sems_count - consume);
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: P, count %u -> %u\n", semv->semv_semnum,
|
||||
sem->sems_count, sem->sems_count - consume);
|
||||
sem->sems_count -= consume;
|
||||
/* don't bother advancing the uio data pointers */
|
||||
uio->uio_offset += consume;
|
||||
@@ -213,8 +182,7 @@ semfs_read(struct vnode *vn, struct uio *uio)
|
||||
break;
|
||||
}
|
||||
if (sem->sems_count == 0) {
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: blocking\n",
|
||||
semv->semv_semnum);
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: blocking\n", semv->semv_semnum);
|
||||
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.
|
||||
* Don't actually bother to transfer any data.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_write(struct vnode *vn, struct uio *uio)
|
||||
{
|
||||
static int semfs_write(struct vnode *vn, struct uio *uio) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
struct semfs_sem *sem;
|
||||
unsigned newcount;
|
||||
@@ -244,8 +209,8 @@ semfs_write(struct vnode *vn, struct uio *uio)
|
||||
lock_release(sem->sems_lock);
|
||||
return EFBIG;
|
||||
}
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: V, count %u -> %u\n",
|
||||
semv->semv_semnum, sem->sems_count, newcount);
|
||||
DEBUG(DB_SEMFS, "semfs: sem%u: V, count %u -> %u\n", semv->semv_semnum,
|
||||
sem->sems_count, newcount);
|
||||
semfs_wakeup(sem, newcount);
|
||||
sem->sems_count = newcount;
|
||||
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
|
||||
* and then initializing their counts to values other than zero.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_truncate(struct vnode *vn, off_t len)
|
||||
{
|
||||
static int semfs_truncate(struct vnode *vn, off_t len) {
|
||||
/* We should just use UINT_MAX but we don't have it in the kernel */
|
||||
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
|
||||
* root) that has all the semaphores in it.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
|
||||
{
|
||||
static int semfs_getdirentry(struct vnode *dirvn, struct uio *uio) {
|
||||
struct semfs_vnode *dirsemv = dirvn->vn_data;
|
||||
struct semfs *semfs = dirsemv->semv_semfs;
|
||||
struct semfs_direntry *dent;
|
||||
@@ -317,11 +276,9 @@ semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
|
||||
if (pos >= num) {
|
||||
/* EOF */
|
||||
result = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dent = semfs_direntryarray_get(semfs->semfs_dents, pos);
|
||||
result = uiomove(dent->semd_name, strlen(dent->semd_name),
|
||||
uio);
|
||||
result = uiomove(dent->semd_name, strlen(dent->semd_name), uio);
|
||||
}
|
||||
|
||||
lock_release(semfs->semfs_dirlock);
|
||||
@@ -331,10 +288,7 @@ semfs_getdirentry(struct vnode *dirvn, struct uio *uio)
|
||||
/*
|
||||
* stat() for dirs
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_dirstat(struct vnode *vn, struct stat *buf)
|
||||
{
|
||||
static int semfs_dirstat(struct vnode *vn, struct stat *buf) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
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
|
||||
* back the empty string.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_namefile(struct vnode *vn, struct uio *uio)
|
||||
{
|
||||
static int semfs_namefile(struct vnode *vn, struct uio *uio) {
|
||||
(void)vn;
|
||||
(void)uio;
|
||||
return 0;
|
||||
@@ -369,11 +320,8 @@ semfs_namefile(struct vnode *vn, struct uio *uio)
|
||||
/*
|
||||
* Create a semaphore.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
|
||||
struct vnode **resultvn)
|
||||
{
|
||||
static int 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 *semfs = dirsemv->semv_semfs;
|
||||
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);
|
||||
return EEXIST;
|
||||
}
|
||||
result = semfs_getvnode(semfs, dent->semd_semnum,
|
||||
resultvn);
|
||||
result = semfs_getvnode(semfs, dent->semd_semnum, resultvn);
|
||||
lock_release(semfs->semfs_dirlock);
|
||||
return result;
|
||||
}
|
||||
@@ -430,10 +377,8 @@ semfs_creat(struct vnode *dirvn, const char *name, bool excl, mode_t mode,
|
||||
|
||||
if (empty < num) {
|
||||
semfs_direntryarray_set(semfs->semfs_dents, empty, dent);
|
||||
}
|
||||
else {
|
||||
result = semfs_direntryarray_add(semfs->semfs_dents, dent,
|
||||
&empty);
|
||||
} else {
|
||||
result = semfs_direntryarray_add(semfs->semfs_dents, dent, &empty);
|
||||
if (result) {
|
||||
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
|
||||
* go away if it's currently open.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_remove(struct vnode *dirvn, const char *name)
|
||||
{
|
||||
static int semfs_remove(struct vnode *dirvn, const char *name) {
|
||||
struct semfs_vnode *dirsemv = dirvn->vn_data;
|
||||
struct semfs *semfs = dirsemv->semv_semfs;
|
||||
struct semfs_direntry *dent;
|
||||
@@ -497,13 +439,11 @@ semfs_remove(struct vnode *dirvn, const char *name)
|
||||
sem->sems_linked = false;
|
||||
if (sem->sems_hasvnode == false) {
|
||||
lock_acquire(semfs->semfs_tablelock);
|
||||
semfs_semarray_set(semfs->semfs_sems,
|
||||
dent->semd_semnum, NULL);
|
||||
semfs_semarray_set(semfs->semfs_sems, dent->semd_semnum, NULL);
|
||||
lock_release(semfs->semfs_tablelock);
|
||||
lock_release(sem->sems_lock);
|
||||
semfs_sem_destroy(sem);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lock_release(sem->sems_lock);
|
||||
}
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_lookup(struct vnode *dirvn, char *path, struct vnode **resultvn)
|
||||
{
|
||||
static int semfs_lookup(struct vnode *dirvn, char *path,
|
||||
struct vnode **resultvn) {
|
||||
struct semfs_vnode *dirsemv = dirvn->vn_data;
|
||||
struct semfs *semfs = dirsemv->semv_semfs;
|
||||
struct semfs_direntry *dent;
|
||||
@@ -545,8 +483,7 @@ semfs_lookup(struct vnode *dirvn, char *path, struct vnode **resultvn)
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(path, dent->semd_name)) {
|
||||
result = semfs_getvnode(semfs, dent->semd_semnum,
|
||||
resultvn);
|
||||
result = semfs_getvnode(semfs, dent->semd_semnum, resultvn);
|
||||
lock_release(semfs->semfs_dirlock);
|
||||
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
|
||||
* dir and copy the name.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_lookparent(struct vnode *dirvn, char *path,
|
||||
struct vnode **resultdirvn, char *namebuf, size_t bufmax)
|
||||
{
|
||||
static int semfs_lookparent(struct vnode *dirvn, char *path,
|
||||
struct vnode **resultdirvn, char *namebuf,
|
||||
size_t bufmax) {
|
||||
if (strlen(path) + 1 > bufmax) {
|
||||
return ENAMETOOLONG;
|
||||
}
|
||||
@@ -580,10 +515,7 @@ semfs_lookparent(struct vnode *dirvn, char *path,
|
||||
/*
|
||||
* Destructor for semfs_vnode.
|
||||
*/
|
||||
static
|
||||
void
|
||||
semfs_vnode_destroy(struct semfs_vnode *semv)
|
||||
{
|
||||
static void semfs_vnode_destroy(struct semfs_vnode *semv) {
|
||||
vnode_cleanup(&semv->semv_absvn);
|
||||
kfree(semv);
|
||||
}
|
||||
@@ -591,10 +523,7 @@ semfs_vnode_destroy(struct semfs_vnode *semv)
|
||||
/*
|
||||
* Reclaim - drop a vnode that's no longer in use.
|
||||
*/
|
||||
static
|
||||
int
|
||||
semfs_reclaim(struct vnode *vn)
|
||||
{
|
||||
static int semfs_reclaim(struct vnode *vn) {
|
||||
struct semfs_vnode *semv = vn->vn_data;
|
||||
struct semfs *semfs = semv->semv_semfs;
|
||||
struct vnode *vn2;
|
||||
@@ -631,8 +560,7 @@ semfs_reclaim(struct vnode *vn)
|
||||
KASSERT(sem->sems_hasvnode);
|
||||
sem->sems_hasvnode = false;
|
||||
if (sem->sems_linked == false) {
|
||||
semfs_semarray_set(semfs->semfs_sems,
|
||||
semv->semv_semnum, NULL);
|
||||
semfs_semarray_set(semfs->semfs_sems, semv->semv_semnum, NULL);
|
||||
semfs_sem_destroy(sem);
|
||||
}
|
||||
}
|
||||
@@ -714,18 +642,15 @@ static const struct vnode_ops semfs_semops = {
|
||||
/*
|
||||
* Constructor for semfs vnodes.
|
||||
*/
|
||||
static
|
||||
struct semfs_vnode *
|
||||
semfs_vnode_create(struct semfs *semfs, unsigned semnum)
|
||||
{
|
||||
static struct semfs_vnode *semfs_vnode_create(struct semfs *semfs,
|
||||
unsigned semnum) {
|
||||
const struct vnode_ops *optable;
|
||||
struct semfs_vnode *semv;
|
||||
int result;
|
||||
|
||||
if (semnum == SEMFS_ROOTDIR) {
|
||||
optable = &semfs_dirops;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
optable = &semfs_semops;
|
||||
}
|
||||
|
||||
@@ -737,8 +662,7 @@ semfs_vnode_create(struct semfs *semfs, unsigned semnum)
|
||||
semv->semv_semfs = semfs;
|
||||
semv->semv_semnum = semnum;
|
||||
|
||||
result = vnode_init(&semv->semv_absvn, optable,
|
||||
&semfs->semfs_absfs, semv);
|
||||
result = vnode_init(&semv->semv_absvn, optable, &semfs->semfs_absfs, semv);
|
||||
/* vnode_init doesn't actually fail */
|
||||
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,
|
||||
* create it.
|
||||
*/
|
||||
int
|
||||
semfs_getvnode(struct semfs *semfs, unsigned semnum, struct vnode **ret)
|
||||
{
|
||||
int semfs_getvnode(struct semfs *semfs, unsigned semnum, struct vnode **ret) {
|
||||
struct vnode *vn;
|
||||
struct semfs_vnode *semv;
|
||||
struct semfs_sem *sem;
|
||||
|
||||
@@ -41,10 +41,7 @@
|
||||
/*
|
||||
* Zero out a disk block.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_clearblock(struct sfs_fs *sfs, daddr_t block)
|
||||
{
|
||||
static int sfs_clearblock(struct sfs_fs *sfs, daddr_t block) {
|
||||
/* static -> automatically initialized to zero */
|
||||
static char zeros[SFS_BLOCKSIZE];
|
||||
|
||||
@@ -54,9 +51,7 @@ sfs_clearblock(struct sfs_fs *sfs, daddr_t block)
|
||||
/*
|
||||
* Allocate a block.
|
||||
*/
|
||||
int
|
||||
sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
|
||||
{
|
||||
int sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock) {
|
||||
int result;
|
||||
|
||||
result = bitmap_alloc(sfs->sfs_freemap, diskblock);
|
||||
@@ -66,8 +61,8 @@ sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
|
||||
sfs->sfs_freemapdirty = true;
|
||||
|
||||
if (*diskblock >= sfs->sfs_sb.sb_nblocks) {
|
||||
panic("sfs: %s: balloc: invalid block %u\n",
|
||||
sfs->sfs_sb.sb_volname, *diskblock);
|
||||
panic("sfs: %s: balloc: invalid block %u\n", sfs->sfs_sb.sb_volname,
|
||||
*diskblock);
|
||||
}
|
||||
|
||||
/* Clear block before returning it */
|
||||
@@ -81,9 +76,7 @@ sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock)
|
||||
/*
|
||||
* Free a block.
|
||||
*/
|
||||
void
|
||||
sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock)
|
||||
{
|
||||
void sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock) {
|
||||
bitmap_unmark(sfs->sfs_freemap, diskblock);
|
||||
sfs->sfs_freemapdirty = true;
|
||||
}
|
||||
@@ -91,13 +84,10 @@ sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock)
|
||||
/*
|
||||
* Check if a block is in use.
|
||||
*/
|
||||
int
|
||||
sfs_bused(struct sfs_fs *sfs, daddr_t diskblock)
|
||||
{
|
||||
int sfs_bused(struct sfs_fs *sfs, daddr_t diskblock) {
|
||||
if (diskblock >= sfs->sfs_sb.sb_nblocks) {
|
||||
panic("sfs: %s: sfs_bused called on out of range block %u\n",
|
||||
sfs->sfs_sb.sb_volname, diskblock);
|
||||
}
|
||||
return bitmap_isset(sfs->sfs_freemap, diskblock);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,8 @@
|
||||
* file. If DOALLOC is set, and no such block exists, one will be
|
||||
* allocated.
|
||||
*/
|
||||
int
|
||||
sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
|
||||
daddr_t *diskblock)
|
||||
{
|
||||
int sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
|
||||
daddr_t *diskblock) {
|
||||
/*
|
||||
* 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)) {
|
||||
panic("sfs: %s: Data block %u (block %u of file %u) "
|
||||
"marked free\n", sfs->sfs_sb.sb_volname,
|
||||
block, fileblock, sv->sv_ino);
|
||||
"marked free\n",
|
||||
sfs->sfs_sb.sb_volname, block, fileblock, sv->sv_ino);
|
||||
}
|
||||
*diskblock = block;
|
||||
return 0;
|
||||
@@ -135,8 +133,7 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
|
||||
*/
|
||||
*diskblock = 0;
|
||||
return 0;
|
||||
}
|
||||
else if (idblock==0) {
|
||||
} else if (idblock == 0) {
|
||||
/*
|
||||
* There's no indirect block allocated, but we need to
|
||||
* 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 */
|
||||
bzero(idbuf, sizeof(idbuf));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* 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. */
|
||||
if (block != 0 && !sfs_bused(sfs, block)) {
|
||||
panic("sfs: %s: Data block %u (block %u of file %u) "
|
||||
"marked free\n", sfs->sfs_sb.sb_volname,
|
||||
block, fileblock, sv->sv_ino);
|
||||
"marked free\n",
|
||||
sfs->sfs_sb.sb_volname, block, fileblock, sv->sv_ino);
|
||||
}
|
||||
*diskblock = block;
|
||||
return 0;
|
||||
@@ -200,9 +196,7 @@ sfs_bmap(struct sfs_vnode *sv, uint32_t fileblock, bool doalloc,
|
||||
/*
|
||||
* Called for ftruncate() and from sfs_reclaim.
|
||||
*/
|
||||
int
|
||||
sfs_itrunc(struct sfs_vnode *sv, off_t len)
|
||||
{
|
||||
int sfs_itrunc(struct sfs_vnode *sv, off_t len) {
|
||||
/*
|
||||
* 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);
|
||||
sv->sv_i.sfi_indirect = 0;
|
||||
sv->sv_dirty = true;
|
||||
}
|
||||
else if (iddirty) {
|
||||
} else if (iddirty) {
|
||||
/* The indirect block is dirty; write it back */
|
||||
result = sfs_writeblock(sfs, idblock, idbuf,
|
||||
sizeof(idbuf));
|
||||
result = sfs_writeblock(sfs, idblock, idbuf, sizeof(idbuf));
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
@@ -300,4 +292,3 @@ sfs_itrunc(struct sfs_vnode *sv, off_t len)
|
||||
vfs_biglock_release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,8 @@
|
||||
* Read the directory entry out of slot SLOT of a directory vnode.
|
||||
* The "slot" is the index of the directory entry, starting at 0.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_readdir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
|
||||
{
|
||||
static int sfs_readdir(struct sfs_vnode *sv, int slot,
|
||||
struct sfs_direntry *sd) {
|
||||
off_t actualpos;
|
||||
|
||||
/* 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
|
||||
* vnode.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_writedir(struct sfs_vnode *sv, int slot, struct sfs_direntry *sd)
|
||||
{
|
||||
static int sfs_writedir(struct sfs_vnode *sv, int slot,
|
||||
struct sfs_direntry *sd) {
|
||||
off_t actualpos;
|
||||
|
||||
/* 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
|
||||
* account for empty slots.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_dir_nentries(struct sfs_vnode *sv)
|
||||
{
|
||||
static int sfs_dir_nentries(struct sfs_vnode *sv) {
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
off_t size;
|
||||
|
||||
@@ -88,8 +81,8 @@ sfs_dir_nentries(struct sfs_vnode *sv)
|
||||
|
||||
size = sv->sv_i.sfi_size;
|
||||
if (size % sizeof(struct sfs_direntry) != 0) {
|
||||
panic("sfs: %s: directory %u: Invalid size %llu\n",
|
||||
sfs->sfs_sb.sb_volname, sv->sv_ino, size);
|
||||
panic("sfs: %s: directory %u: Invalid size %llu\n", sfs->sfs_sb.sb_volname,
|
||||
sv->sv_ino, size);
|
||||
}
|
||||
|
||||
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
|
||||
* empty directory slot if one is found.
|
||||
*/
|
||||
int
|
||||
sfs_dir_findname(struct sfs_vnode *sv, const char *name,
|
||||
uint32_t *ino, int *slot, int *emptyslot)
|
||||
{
|
||||
int sfs_dir_findname(struct sfs_vnode *sv, const char *name, uint32_t *ino,
|
||||
int *slot, int *emptyslot) {
|
||||
struct sfs_direntry tsd;
|
||||
int found, nentries, i, result;
|
||||
|
||||
@@ -123,8 +114,7 @@ sfs_dir_findname(struct sfs_vnode *sv, const char *name,
|
||||
if (emptyslot != NULL) {
|
||||
*emptyslot = i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Ensure null termination, just in case */
|
||||
tsd.sfd_name[sizeof(tsd.sfd_name) - 1] = 0;
|
||||
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
|
||||
* the specified name, and optionally hand back the slot.
|
||||
*/
|
||||
int
|
||||
sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino, int *slot)
|
||||
{
|
||||
int sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino,
|
||||
int *slot) {
|
||||
int emptyslot = -1;
|
||||
int result;
|
||||
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.
|
||||
*/
|
||||
int
|
||||
sfs_dir_unlink(struct sfs_vnode *sv, int slot)
|
||||
{
|
||||
int sfs_dir_unlink(struct sfs_vnode *sv, int slot) {
|
||||
struct sfs_direntry sd;
|
||||
|
||||
/* 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
|
||||
* file, if there is one.
|
||||
*/
|
||||
int
|
||||
sfs_lookonce(struct sfs_vnode *sv, const char *name,
|
||||
struct sfs_vnode **ret,
|
||||
int *slot)
|
||||
{
|
||||
int sfs_lookonce(struct sfs_vnode *sv, const char *name, struct sfs_vnode **ret,
|
||||
int *slot) {
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
uint32_t ino;
|
||||
int result;
|
||||
@@ -230,10 +214,9 @@ sfs_lookonce(struct sfs_vnode *sv, const char *name,
|
||||
|
||||
if ((*ret)->sv_i.sfi_linkcount == 0) {
|
||||
panic("sfs: %s: name %s (inode %u) in dir %u has "
|
||||
"linkcount 0\n", sfs->sfs_sb.sb_volname,
|
||||
name, (*ret)->sv_ino, sv->sv_ino);
|
||||
"linkcount 0\n",
|
||||
sfs->sfs_sb.sb_volname, name, (*ret)->sv_ino, sv->sv_ino);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <sfs.h>
|
||||
#include "sfsprivate.h"
|
||||
|
||||
|
||||
/* Shortcuts for the size macros in kern/sfs.h */
|
||||
#define SFS_FS_NBLOCKS(sfs) ((sfs)->sfs_sb.sb_nblocks)
|
||||
#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
|
||||
* likewise marked in use by mksfs.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw)
|
||||
{
|
||||
static int sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw) {
|
||||
uint32_t j, freemapblocks;
|
||||
char *freemapdata;
|
||||
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. */
|
||||
if (rw == UIO_READ) {
|
||||
result = sfs_readblock(sfs, SFS_FREEMAP_START+j, ptr,
|
||||
SFS_BLOCKSIZE);
|
||||
}
|
||||
else {
|
||||
result = sfs_writeblock(sfs, SFS_FREEMAP_START+j, ptr,
|
||||
SFS_BLOCKSIZE);
|
||||
result = sfs_readblock(sfs, SFS_FREEMAP_START + j, ptr, SFS_BLOCKSIZE);
|
||||
} else {
|
||||
result = sfs_writeblock(sfs, SFS_FREEMAP_START + j, ptr, SFS_BLOCKSIZE);
|
||||
}
|
||||
|
||||
/* If we failed, stop. */
|
||||
@@ -108,10 +101,7 @@ sfs_freemapio(struct sfs_fs *sfs, enum uio_rw rw)
|
||||
/*
|
||||
* Sync routine for the vnode table.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_sync_vnodes(struct sfs_fs *sfs)
|
||||
{
|
||||
static int sfs_sync_vnodes(struct sfs_fs *sfs) {
|
||||
unsigned i, num;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_sync_freemap(struct sfs_fs *sfs)
|
||||
{
|
||||
static int sfs_sync_freemap(struct sfs_fs *sfs) {
|
||||
int result;
|
||||
|
||||
if (sfs->sfs_freemapdirty) {
|
||||
@@ -146,15 +133,12 @@ sfs_sync_freemap(struct sfs_fs *sfs)
|
||||
/*
|
||||
* Sync routine for the superblock.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_sync_superblock(struct sfs_fs *sfs)
|
||||
{
|
||||
static int sfs_sync_superblock(struct sfs_fs *sfs) {
|
||||
int result;
|
||||
|
||||
if (sfs->sfs_superdirty) {
|
||||
result = sfs_writeblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb,
|
||||
sizeof(sfs->sfs_sb));
|
||||
result =
|
||||
sfs_writeblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, sizeof(sfs->sfs_sb));
|
||||
if (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
|
||||
* sfs filesystem structure.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_sync(struct fs *fs)
|
||||
{
|
||||
static int sfs_sync(struct fs *fs) {
|
||||
struct sfs_fs *sfs;
|
||||
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
|
||||
* of the device they're mounted on.
|
||||
*/
|
||||
static
|
||||
const char *
|
||||
sfs_getvolname(struct fs *fs)
|
||||
{
|
||||
static const char *sfs_getvolname(struct fs *fs) {
|
||||
struct sfs_fs *sfs = fs->fs_data;
|
||||
const char *ret;
|
||||
|
||||
@@ -255,10 +233,7 @@ sfs_getvolname(struct fs *fs)
|
||||
/*
|
||||
* Destructor for struct sfs_fs.
|
||||
*/
|
||||
static
|
||||
void
|
||||
sfs_fs_destroy(struct sfs_fs *sfs)
|
||||
{
|
||||
static void sfs_fs_destroy(struct sfs_fs *sfs) {
|
||||
if (sfs->sfs_freemap != NULL) {
|
||||
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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_unmount(struct fs *fs)
|
||||
{
|
||||
static int sfs_unmount(struct fs *fs) {
|
||||
struct sfs_fs *sfs = fs->fs_data;
|
||||
|
||||
vfs_biglock_acquire();
|
||||
@@ -316,10 +288,7 @@ static const struct fs_ops sfs_fsops = {
|
||||
* but skips stuff that requires reading the volume, like allocating
|
||||
* the freemap.
|
||||
*/
|
||||
static
|
||||
struct sfs_fs *
|
||||
sfs_fs_create(void)
|
||||
{
|
||||
static struct sfs_fs *sfs_fs_create(void) {
|
||||
struct sfs_fs *sfs;
|
||||
|
||||
/*
|
||||
@@ -381,10 +350,7 @@ fail:
|
||||
* filesystems with the same name mounted at once, or two filesystems
|
||||
* mounted on the same device at once.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_domount(void *options, struct device *dev, struct fs **ret)
|
||||
{
|
||||
static int sfs_domount(void *options, struct device *dev, struct fs **ret) {
|
||||
int result;
|
||||
struct sfs_fs *sfs;
|
||||
|
||||
@@ -418,8 +384,8 @@ sfs_domount(void *options, struct device *dev, struct fs **ret)
|
||||
sfs->sfs_device = dev;
|
||||
|
||||
/* Load superblock */
|
||||
result = sfs_readblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb,
|
||||
sizeof(sfs->sfs_sb));
|
||||
result =
|
||||
sfs_readblock(sfs, SFS_SUPER_BLOCK, &sfs->sfs_sb, sizeof(sfs->sfs_sb));
|
||||
if (result) {
|
||||
sfs->sfs_device = NULL;
|
||||
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) {
|
||||
kprintf("sfs: Wrong magic number in superblock "
|
||||
"(0x%x, should be 0x%x)\n",
|
||||
sfs->sfs_sb.sb_magic,
|
||||
SFS_MAGIC);
|
||||
sfs->sfs_sb.sb_magic, SFS_MAGIC);
|
||||
sfs->sfs_device = NULL;
|
||||
sfs_fs_destroy(sfs);
|
||||
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.
|
||||
*/
|
||||
int
|
||||
sfs_mount(const char *device)
|
||||
{
|
||||
int sfs_mount(const char *device) {
|
||||
return vfs_mount(device, NULL, sfs_domount);
|
||||
}
|
||||
|
||||
@@ -39,19 +39,15 @@
|
||||
#include <sfs.h>
|
||||
#include "sfsprivate.h"
|
||||
|
||||
|
||||
/*
|
||||
* Write an on-disk inode structure back out to disk.
|
||||
*/
|
||||
int
|
||||
sfs_sync_inode(struct sfs_vnode *sv)
|
||||
{
|
||||
int sfs_sync_inode(struct sfs_vnode *sv) {
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
int result;
|
||||
|
||||
if (sv->sv_dirty) {
|
||||
result = sfs_writeblock(sfs, sv->sv_ino, &sv->sv_i,
|
||||
sizeof(sv->sv_i));
|
||||
result = sfs_writeblock(sfs, sv->sv_ino, &sv->sv_i, sizeof(sv->sv_i));
|
||||
if (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.
|
||||
*/
|
||||
int
|
||||
sfs_reclaim(struct vnode *v)
|
||||
{
|
||||
int sfs_reclaim(struct vnode *v) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
struct sfs_fs *sfs = v->vn_fs->fs_data;
|
||||
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
|
||||
* that's already resident.
|
||||
*/
|
||||
int
|
||||
sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
|
||||
struct sfs_vnode **ret)
|
||||
{
|
||||
int sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
|
||||
struct sfs_vnode **ret) {
|
||||
struct vnode *v;
|
||||
struct sfs_vnode *sv;
|
||||
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 */
|
||||
if (!sfs_bused(sfs, ino)) {
|
||||
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 */
|
||||
@@ -228,8 +221,8 @@ sfs_loadvnode(struct sfs_fs *sfs, uint32_t ino, int forcetype,
|
||||
break;
|
||||
default:
|
||||
panic("sfs: %s: loadvnode: Invalid inode type "
|
||||
"(inode %u, type %u)\n", sfs->sfs_sb.sb_volname,
|
||||
ino, sv->sv_i.sfi_type);
|
||||
"(inode %u, type %u)\n",
|
||||
sfs->sfs_sb.sb_volname, ino, sv->sv_i.sfi_type);
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
int
|
||||
sfs_makeobj(struct sfs_fs *sfs, int type, struct sfs_vnode **ret)
|
||||
{
|
||||
int sfs_makeobj(struct sfs_fs *sfs, int type, struct sfs_vnode **ret) {
|
||||
uint32_t ino;
|
||||
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.
|
||||
* The root vnode is always found in block 1 (SFS_ROOTDIR_INO).
|
||||
*/
|
||||
int
|
||||
sfs_getroot(struct fs *fs, struct vnode **ret)
|
||||
{
|
||||
int sfs_getroot(struct fs *fs, struct vnode **ret) {
|
||||
struct sfs_fs *sfs = fs->fs_data;
|
||||
struct sfs_vnode *sv;
|
||||
int result;
|
||||
|
||||
@@ -55,17 +55,13 @@
|
||||
/*
|
||||
* Read or write a block, retrying I/O errors.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
|
||||
{
|
||||
static int sfs_rwblock(struct sfs_fs *sfs, struct uio *uio) {
|
||||
int result;
|
||||
int tries = 0;
|
||||
|
||||
KASSERT(vfs_biglock_do_i_hold());
|
||||
|
||||
DEBUG(DB_SFS, "sfs: %s %llu\n",
|
||||
uio->uio_rw == UIO_READ ? "read" : "write",
|
||||
DEBUG(DB_SFS, "sfs: %s %llu\n", uio->uio_rw == UIO_READ ? "read" : "write",
|
||||
uio->uio_offset / SFS_BLOCKSIZE);
|
||||
|
||||
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 a couple of other things that are our fault.
|
||||
*/
|
||||
panic("sfs: %s: DEVOP_IO returned EINVAL\n",
|
||||
sfs->sfs_sb.sb_volname);
|
||||
panic("sfs: %s: DEVOP_IO returned EINVAL\n", sfs->sfs_sb.sb_volname);
|
||||
}
|
||||
if (result == EIO) {
|
||||
if (tries == 0) {
|
||||
tries++;
|
||||
kprintf("sfs: %s: block %llu I/O error, retrying\n",
|
||||
sfs->sfs_sb.sb_volname,
|
||||
uio->uio_offset / SFS_BLOCKSIZE);
|
||||
sfs->sfs_sb.sb_volname, uio->uio_offset / SFS_BLOCKSIZE);
|
||||
goto retry;
|
||||
}
|
||||
else if (tries < 10) {
|
||||
} else if (tries < 10) {
|
||||
tries++;
|
||||
goto retry;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
kprintf("sfs: %s: block %llu I/O error, giving up "
|
||||
"after %d retries\n",
|
||||
sfs->sfs_sb.sb_volname,
|
||||
uio->uio_offset / SFS_BLOCKSIZE, tries);
|
||||
sfs->sfs_sb.sb_volname, uio->uio_offset / SFS_BLOCKSIZE, tries);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -104,9 +95,7 @@ sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
|
||||
/*
|
||||
* Read a block.
|
||||
*/
|
||||
int
|
||||
sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
|
||||
{
|
||||
int sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len) {
|
||||
struct iovec iov;
|
||||
struct uio ku;
|
||||
|
||||
@@ -119,9 +108,7 @@ sfs_readblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
|
||||
/*
|
||||
* Write a block.
|
||||
*/
|
||||
int
|
||||
sfs_writeblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len)
|
||||
{
|
||||
int sfs_writeblock(struct sfs_fs *sfs, daddr_t block, void *data, size_t len) {
|
||||
struct iovec iov;
|
||||
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.
|
||||
* UIO is the area to do the I/O into.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
|
||||
uint32_t skipstart, uint32_t len)
|
||||
{
|
||||
static int sfs_partialio(struct sfs_vnode *sv, struct uio *uio,
|
||||
uint32_t skipstart, uint32_t len) {
|
||||
/*
|
||||
* 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);
|
||||
bzero(iobuf, sizeof(iobuf));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_blockio(struct sfs_vnode *sv, struct uio *uio)
|
||||
{
|
||||
static int sfs_blockio(struct sfs_vnode *sv, struct uio *uio) {
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
daddr_t diskblock;
|
||||
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.
|
||||
*/
|
||||
int
|
||||
sfs_io(struct sfs_vnode *sv, struct uio *uio)
|
||||
{
|
||||
int sfs_io(struct sfs_vnode *sv, struct uio *uio) {
|
||||
uint32_t blkoff;
|
||||
uint32_t nblocks, i;
|
||||
int result = 0;
|
||||
@@ -374,8 +352,7 @@ sfs_io(struct sfs_vnode *sv, struct uio *uio)
|
||||
out:
|
||||
|
||||
/* If writing and we did anything, adjust file length */
|
||||
if (uio->uio_resid != origresid &&
|
||||
uio->uio_rw == UIO_WRITE &&
|
||||
if (uio->uio_resid != origresid && uio->uio_rw == UIO_WRITE &&
|
||||
uio->uio_offset > (off_t)sv->sv_i.sfi_size) {
|
||||
sv->sv_i.sfi_size = uio->uio_offset;
|
||||
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
|
||||
* differently.
|
||||
*/
|
||||
int
|
||||
sfs_metaio(struct sfs_vnode *sv, off_t actualpos, void *data, size_t len,
|
||||
enum uio_rw rw)
|
||||
{
|
||||
int sfs_metaio(struct sfs_vnode *sv, off_t actualpos, void *data, size_t len,
|
||||
enum uio_rw rw) {
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
off_t endpos;
|
||||
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) {
|
||||
/* Copy out the selected region */
|
||||
memcpy(data, metaiobuf + blockoffset, len);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Update the selected region */
|
||||
memcpy(metaiobuf + blockoffset, data, len);
|
||||
|
||||
/* Write the block back */
|
||||
result = sfs_writeblock(sfs, diskblock,
|
||||
metaiobuf, sizeof(metaiobuf));
|
||||
result = sfs_writeblock(sfs, diskblock, metaiobuf, sizeof(metaiobuf));
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,7 @@
|
||||
/*
|
||||
* This is called on *each* open().
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_eachopen(struct vnode *v, int openflags)
|
||||
{
|
||||
static int sfs_eachopen(struct vnode *v, int openflags) {
|
||||
/*
|
||||
* At this level we do not need to handle O_CREAT, O_EXCL,
|
||||
* 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.
|
||||
* Directories may only be open for read.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_eachopendir(struct vnode *v, int openflags)
|
||||
{
|
||||
static int sfs_eachopendir(struct vnode *v, int openflags) {
|
||||
switch (openflags & O_ACCMODE) {
|
||||
case O_RDONLY:
|
||||
break;
|
||||
@@ -93,10 +87,7 @@ sfs_eachopendir(struct vnode *v, int openflags)
|
||||
/*
|
||||
* Called for read(). sfs_io() does the work.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_read(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int sfs_read(struct vnode *v, struct uio *uio) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
int result;
|
||||
|
||||
@@ -112,10 +103,7 @@ sfs_read(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* Called for write(). sfs_io() does the work.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_write(struct vnode *v, struct uio *uio)
|
||||
{
|
||||
static int sfs_write(struct vnode *v, struct uio *uio) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
int result;
|
||||
|
||||
@@ -131,10 +119,7 @@ sfs_write(struct vnode *v, struct uio *uio)
|
||||
/*
|
||||
* Called for ioctl()
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_ioctl(struct vnode *v, int op, userptr_t data)
|
||||
{
|
||||
static int sfs_ioctl(struct vnode *v, int op, userptr_t data) {
|
||||
/*
|
||||
* No ioctls.
|
||||
*/
|
||||
@@ -149,10 +134,7 @@ sfs_ioctl(struct vnode *v, int op, userptr_t data)
|
||||
/*
|
||||
* Called for stat/fstat/lstat.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_stat(struct vnode *v, struct stat *statbuf)
|
||||
{
|
||||
static int sfs_stat(struct vnode *v, struct stat *statbuf) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
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)
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_gettype(struct vnode *v, uint32_t *ret)
|
||||
{
|
||||
static int sfs_gettype(struct vnode *v, uint32_t *ret) {
|
||||
struct sfs_vnode *sv = v->vn_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".
|
||||
*/
|
||||
static
|
||||
bool
|
||||
sfs_isseekable(struct vnode *v)
|
||||
{
|
||||
static bool sfs_isseekable(struct vnode *v) {
|
||||
(void)v;
|
||||
return true;
|
||||
}
|
||||
@@ -217,10 +193,7 @@ sfs_isseekable(struct vnode *v)
|
||||
* Called for fsync(), and also on filesystem unmount, global sync(),
|
||||
* and some other cases.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_fsync(struct vnode *v)
|
||||
{
|
||||
static int sfs_fsync(struct vnode *v) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
int result;
|
||||
|
||||
@@ -234,10 +207,7 @@ sfs_fsync(struct vnode *v)
|
||||
/*
|
||||
* Called for mmap().
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_mmap(struct vnode *v /* add stuff as needed */)
|
||||
{
|
||||
static int sfs_mmap(struct vnode *v /* add stuff as needed */) {
|
||||
(void)v;
|
||||
return ENOSYS;
|
||||
}
|
||||
@@ -245,10 +215,7 @@ sfs_mmap(struct vnode *v /* add stuff as needed */)
|
||||
/*
|
||||
* Truncate a file.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_truncate(struct vnode *v, off_t len)
|
||||
{
|
||||
static int sfs_truncate(struct vnode *v, off_t len) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
|
||||
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
|
||||
* device name, leading slash, etc.)
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_namefile(struct vnode *vv, struct uio *uio)
|
||||
{
|
||||
static int sfs_namefile(struct vnode *vv, struct uio *uio) {
|
||||
struct sfs_vnode *sv = vv->vn_data;
|
||||
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
|
||||
* exist; otherwise, if it already exists, just open it.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_creat(struct vnode *v, const char *name, bool excl, mode_t mode,
|
||||
struct vnode **ret)
|
||||
{
|
||||
static int 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_vnode *sv = v->vn_data;
|
||||
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
|
||||
* vnodes are ours.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_link(struct vnode *dir, const char *name, struct vnode *file)
|
||||
{
|
||||
static int sfs_link(struct vnode *dir, const char *name, struct vnode *file) {
|
||||
struct sfs_vnode *sv = dir->vn_data;
|
||||
struct sfs_vnode *f = file->vn_data;
|
||||
int result;
|
||||
@@ -387,10 +345,7 @@ sfs_link(struct vnode *dir, const char *name, struct vnode *file)
|
||||
/*
|
||||
* Delete a file.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_remove(struct vnode *dir, const char *name)
|
||||
{
|
||||
static int sfs_remove(struct vnode *dir, const char *name) {
|
||||
struct sfs_vnode *sv = dir->vn_data;
|
||||
struct sfs_vnode *victim;
|
||||
int slot;
|
||||
@@ -427,11 +382,8 @@ sfs_remove(struct vnode *dir, const char *name)
|
||||
* Since we don't support subdirectories, assumes that the two
|
||||
* directories passed are the same.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_rename(struct vnode *d1, const char *n1,
|
||||
struct vnode *d2, const char *n2)
|
||||
{
|
||||
static int sfs_rename(struct vnode *d1, const char *n1, struct vnode *d2,
|
||||
const char *n2) {
|
||||
struct sfs_vnode *sv = d1->vn_data;
|
||||
struct sfs_fs *sfs = sv->sv_absvn.vn_fs->fs_data;
|
||||
struct sfs_vnode *g1;
|
||||
@@ -496,12 +448,10 @@ sfs_rename(struct vnode *d1, const char *n1,
|
||||
*/
|
||||
result2 = sfs_dir_unlink(sv, slot2);
|
||||
if (result2) {
|
||||
kprintf("sfs: %s: rename: %s\n",
|
||||
sfs->sfs_sb.sb_volname, strerror(result));
|
||||
kprintf("sfs: %s: rename: while cleaning up: %s\n",
|
||||
sfs->sfs_sb.sb_volname, strerror(result2));
|
||||
panic("sfs: %s: rename: Cannot recover\n",
|
||||
sfs->sfs_sb.sb_volname);
|
||||
kprintf("sfs: %s: rename: %s\n", sfs->sfs_sb.sb_volname, strerror(result));
|
||||
kprintf("sfs: %s: rename: while cleaning up: %s\n", sfs->sfs_sb.sb_volname,
|
||||
strerror(result2));
|
||||
panic("sfs: %s: rename: Cannot recover\n", sfs->sfs_sb.sb_volname);
|
||||
}
|
||||
g1->sv_i.sfi_linkcount--;
|
||||
puke:
|
||||
@@ -518,11 +468,8 @@ sfs_rename(struct vnode *d1, const char *n1,
|
||||
* Since we don't support subdirectories, this is very easy -
|
||||
* return the root dir and copy the path.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_lookparent(struct vnode *v, char *path, struct vnode **ret,
|
||||
char *buf, size_t buflen)
|
||||
{
|
||||
static int sfs_lookparent(struct vnode *v, char *path, struct vnode **ret,
|
||||
char *buf, size_t buflen) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
|
||||
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
|
||||
* name.
|
||||
*/
|
||||
static
|
||||
int
|
||||
sfs_lookup(struct vnode *v, char *path, struct vnode **ret)
|
||||
{
|
||||
static int sfs_lookup(struct vnode *v, char *path, struct vnode **ret) {
|
||||
struct sfs_vnode *sv = v->vn_data;
|
||||
struct sfs_vnode *final;
|
||||
int result;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include <uio.h> /* for uio_rw */
|
||||
|
||||
|
||||
/* ops tables (in sfs_vnops.c) */
|
||||
extern const struct vnode_ops sfs_fileops;
|
||||
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) \
|
||||
uio_kinit(iov, uio, ptr, SFS_BLOCKSIZE, ((off_t)(block)) * SFS_BLOCKSIZE, rw)
|
||||
|
||||
|
||||
/* Functions in sfs_balloc.c */
|
||||
int sfs_balloc(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);
|
||||
|
||||
/* Functions in sfs_dir.c */
|
||||
int sfs_dir_findname(struct sfs_vnode *sv, const char *name,
|
||||
uint32_t *ino, int *slot, int *emptyslot);
|
||||
int sfs_dir_findname(struct sfs_vnode *sv, const char *name, uint32_t *ino,
|
||||
int *slot, int *emptyslot);
|
||||
int sfs_dir_link(struct sfs_vnode *sv, const char *name, uint32_t ino,
|
||||
int *slot);
|
||||
int sfs_dir_unlink(struct sfs_vnode *sv, int slot);
|
||||
int sfs_lookonce(struct sfs_vnode *sv, const char *name,
|
||||
struct sfs_vnode **ret,
|
||||
int sfs_lookonce(struct sfs_vnode *sv, const char *name, struct sfs_vnode **ret,
|
||||
int *slot);
|
||||
|
||||
/* 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,
|
||||
enum uio_rw rw);
|
||||
|
||||
|
||||
#endif /* _SFSPRIVATE_H_ */
|
||||
|
||||
@@ -34,13 +34,11 @@
|
||||
* Address space structure and operations.
|
||||
*/
|
||||
|
||||
|
||||
#include <vm.h>
|
||||
#include "opt-dumbvm.h"
|
||||
|
||||
struct vnode;
|
||||
|
||||
|
||||
/*
|
||||
* Address space - data structure associated with the virtual memory
|
||||
* space of a process.
|
||||
@@ -109,16 +107,12 @@ void as_activate(void);
|
||||
void as_deactivate(void);
|
||||
void as_destroy(struct addrspace *);
|
||||
|
||||
int as_define_region(struct addrspace *as,
|
||||
vaddr_t vaddr, size_t sz,
|
||||
int readable,
|
||||
int writeable,
|
||||
int executable);
|
||||
int as_define_region(struct addrspace *as, vaddr_t vaddr, size_t sz,
|
||||
int readable, int writeable, int executable);
|
||||
int as_prepare_load(struct addrspace *as);
|
||||
int as_complete_load(struct addrspace *as);
|
||||
int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);
|
||||
|
||||
|
||||
/*
|
||||
* Functions in loadelf.c
|
||||
* 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);
|
||||
|
||||
|
||||
#endif /* _ADDRSPACE_H_ */
|
||||
|
||||
@@ -88,29 +88,19 @@ void array_remove(struct array *, unsigned index);
|
||||
* Inlining for base operations
|
||||
*/
|
||||
|
||||
ARRAYINLINE unsigned
|
||||
array_num(const struct array *a)
|
||||
{
|
||||
return a->num;
|
||||
}
|
||||
ARRAYINLINE unsigned array_num(const struct array *a) { return a->num; }
|
||||
|
||||
ARRAYINLINE void *
|
||||
array_get(const struct array *a, unsigned index)
|
||||
{
|
||||
ARRAYINLINE void *array_get(const struct array *a, unsigned index) {
|
||||
ARRAYASSERT(index < a->num);
|
||||
return a->v[index];
|
||||
}
|
||||
|
||||
ARRAYINLINE void
|
||||
array_set(const struct array *a, unsigned index, void *val)
|
||||
{
|
||||
ARRAYINLINE void array_set(const struct array *a, unsigned index, void *val) {
|
||||
ARRAYASSERT(index < a->num);
|
||||
a->v[index] = val;
|
||||
}
|
||||
|
||||
ARRAYINLINE int
|
||||
array_add(struct array *a, void *val, unsigned *index_ret)
|
||||
{
|
||||
ARRAYINLINE int array_add(struct array *a, void *val, unsigned *index_ret) {
|
||||
unsigned index;
|
||||
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)
|
||||
|
||||
#define DEFARRAY_BYTYPE(ARRAY, T, INLINE) \
|
||||
INLINE struct ARRAY * \
|
||||
ARRAY##_create(void) \
|
||||
{ \
|
||||
INLINE struct ARRAY *ARRAY##_create(void) { \
|
||||
struct ARRAY *a = kmalloc(sizeof(*a)); \
|
||||
if (a == NULL) { \
|
||||
return NULL; \
|
||||
@@ -194,64 +182,40 @@ array_add(struct array *a, void *val, unsigned *index_ret)
|
||||
return a; \
|
||||
} \
|
||||
\
|
||||
INLINE void \
|
||||
ARRAY##_destroy(struct ARRAY *a) \
|
||||
{ \
|
||||
INLINE void ARRAY##_destroy(struct ARRAY *a) { \
|
||||
array_cleanup(&a->arr); \
|
||||
kfree(a); \
|
||||
} \
|
||||
\
|
||||
INLINE void \
|
||||
ARRAY##_init(struct ARRAY *a) \
|
||||
{ \
|
||||
array_init(&a->arr); \
|
||||
} \
|
||||
INLINE void ARRAY##_init(struct ARRAY *a) { array_init(&a->arr); } \
|
||||
\
|
||||
INLINE void \
|
||||
ARRAY##_cleanup(struct ARRAY *a) \
|
||||
{ \
|
||||
array_cleanup(&a->arr); \
|
||||
} \
|
||||
INLINE void ARRAY##_cleanup(struct ARRAY *a) { array_cleanup(&a->arr); } \
|
||||
\
|
||||
INLINE unsigned \
|
||||
ARRAY##_num(const struct ARRAY *a) \
|
||||
{ \
|
||||
INLINE unsigned ARRAY##_num(const struct ARRAY *a) { \
|
||||
return array_num(&a->arr); \
|
||||
} \
|
||||
\
|
||||
INLINE T * \
|
||||
ARRAY##_get(const struct ARRAY *a, unsigned index) \
|
||||
{ \
|
||||
INLINE T *ARRAY##_get(const struct ARRAY *a, unsigned index) { \
|
||||
return (T *)array_get(&a->arr, index); \
|
||||
} \
|
||||
\
|
||||
INLINE void \
|
||||
ARRAY##_set(struct ARRAY *a, unsigned index, T *val) \
|
||||
{ \
|
||||
INLINE void ARRAY##_set(struct ARRAY *a, unsigned index, T *val) { \
|
||||
array_set(&a->arr, index, (void *)val); \
|
||||
} \
|
||||
\
|
||||
INLINE int \
|
||||
ARRAY##_preallocate(struct ARRAY *a, unsigned num) \
|
||||
{ \
|
||||
INLINE int ARRAY##_preallocate(struct ARRAY *a, unsigned num) { \
|
||||
return array_preallocate(&a->arr, num); \
|
||||
} \
|
||||
\
|
||||
INLINE int \
|
||||
ARRAY##_setsize(struct ARRAY *a, unsigned num) \
|
||||
{ \
|
||||
INLINE int ARRAY##_setsize(struct ARRAY *a, unsigned num) { \
|
||||
return array_setsize(&a->arr, num); \
|
||||
} \
|
||||
\
|
||||
INLINE int \
|
||||
ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret) \
|
||||
{ \
|
||||
INLINE int ARRAY##_add(struct ARRAY *a, T *val, unsigned *index_ret) { \
|
||||
return array_add(&a->arr, (void *)val, index_ret); \
|
||||
} \
|
||||
\
|
||||
INLINE void \
|
||||
ARRAY##_remove(struct ARRAY *a, unsigned index) \
|
||||
{ \
|
||||
INLINE void ARRAY##_remove(struct ARRAY *a, unsigned 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);
|
||||
DEFARRAY_BYTYPE(stringarray, char, ARRAYINLINE);
|
||||
|
||||
|
||||
#endif /* ARRAY_H */
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
* bitmap_destroy - destroy bitmap.
|
||||
*/
|
||||
|
||||
|
||||
struct bitmap; /* Opaque. */
|
||||
|
||||
struct bitmap *bitmap_create(unsigned nbits);
|
||||
@@ -55,5 +54,4 @@ void bitmap_unmark(struct bitmap *, unsigned index);
|
||||
int bitmap_isset(struct bitmap *, unsigned index);
|
||||
void bitmap_destroy(struct bitmap *);
|
||||
|
||||
|
||||
#endif /* _BITMAP_H_ */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user