Re: occasional SSIGSEGV on C++ exception handling

2021-02-22 Thread Miod Vallat


> No problem, real-life often takes precedence.

No way! operator(7) would need an update!



hppa: terminate backtrace of secondary processors

2021-02-07 Thread Miod Vallat
When asking for the backtrace of a secondary processor in ddb, if that
backtrace reaches the secondary cpu startup code before the
switch_trampoline call, it will trust uninitialized stack data and is
likely to panic with an unaligned access at db_stack_trace_print+0x1d0.
(this was found the hard way by landry@ many years ago due to another
bug which got quickly fixed)

The following diff makes sure the secondary processor stack is correctly
set up to hint the backtrace code that it should not attempt to go
further.

Index: locore.S
===
RCS file: /OpenBSD/src/sys/arch/hppa/hppa/locore.S,v
retrieving revision 1.193
diff -u -p -r1.193 locore.S
--- locore.S23 Oct 2014 16:57:45 -  1.193
+++ locore.S2 Feb 2021 17:08:57 -
@@ -2970,6 +2970,9 @@ ENTRY(hw_cpu_spinup_trampoline, 0)
stw r0, HPPA_FRAME_CRP(sp)
stw r0, HPPA_FRAME_PSP(sp)
 
+   ldilL%TFF_LAST, t1
+   stw t1, TF_FLAGS-TRAPFRAME_SIZEOF(sp)
+
/* Provide CPU with page tables. */
ldilL%hppa_vtop, t1
ldw R%hppa_vtop(t1), t1



Re: all platforms: isolate hardclock(9) from statclock()

2021-01-14 Thread Miod Vallat
> My understanding is that HZ=100 was a practical choice because the
> machines of the day could not reliably drive a faster clock interrupt.

The VAX architecture defines a 100Hz timer, which is the only timer you
can be sure will be available to the kernel. A few of the later models
(VAXstation 4000 comes to mind) have a so-called diagnostic timer with a
better precision.

Thus when BSD was ported to VAX, there was no choice but have HZ=100.
And when it was ported to other platforms (such as hp300), that value
was kept because there was no good reason to change it.

The value of hz became adjustable because some hardware came with clocks
which required a power-of-two divider, such as the 4.4BSD pmax port
which had HZ=64. And of course, later, alpha was architected to have a
1024Hz timer, so HZ=1024 on these systems as well.



Re: libc/regex: safer pointer arithmetic

2021-01-03 Thread Miod Vallat


> regcomp.c uses the "start + count < end" idiom to check that there are
> "count" bytes available in an array of char "start" and "end" both point
> to.
>
> This is fine, unless "start + count" goes beyond the last element of the
> array. In this case, pedantic interpretation of the C standard makes
> the comparison of such a pointer against "end" undefined, and optimizers
> from hell will happily remove as much code as possible because of this.

I am only noticing now that llvm contains a copy of OpenBSD's libc regex
code (with an llvm_ prefix to the public interfaces) in its llvmSupport
library.

I am thus surprised that one of their sanitizers did not expose that
wrong construct already. I'll report this to the llvm project tomorrow.

In the meantime, under OpenBSD, it might be worth investigating shutting
that copy and having llvm_re* aliases of libc's re* functions, if only
to make the code smaller.



Re: compress sparc64 bsd.rd

2021-01-03 Thread Miod Vallat
> > Rebooting with command: boot bsd.rd.gz   
> 
> This is interesting. The change has it just being named bsd.rd, without the
> .gz.

That's just me testing a compressed bsd.rd.



Re: compress sparc64 bsd.rd

2021-01-03 Thread Miod Vallat
> Since this change went in, bsd.rd doesn't boot unless I uncompress it first.
> 
> upgrade detected: switching to /bsd.upgrade
> Trying /bsd.upgrade...
> NOTE: random seed is being reused.
> Booting /pci@400/pci@2/pci@0/pci@c/nvme@0/disk@1:a/bsd.upgrade
> 4246528@0x100+5120@0x140cc00+3248796@0x1c0+945508@0x1f1929c 
> OF_map_phys(ff84,8192,fee5,-1) failed
> no space for symbol table
> Program terminated

What machine and OpenBoot version are you using?

gzipped kernels work here (as they used to) on:

Sun Ultra 1 UPA/SBus (UltraSPARC 167MHz), No Keyboard
OpenBoot 3.1, 128 MB memory installed, Serial #8592590.
Ethernet address 8:0:20:83:1c:ce, Host ID: 80831cce.



Rebooting with command: boot bsd.rd.gz   
Boot device: /sbus/SUNW,fas@e,880/sd@0,0  File and args: bsd.rd.gz
OpenBSD IEEE 1275 Bootblock 2.1
..>> OpenBSD BOOT 1.21
Booting /sbus@1f,0/SUNW,fas@e,880/sd@0,0:a/bsd.rd.gz
4249968@0x100+1680@0x140d970+3249820@0x1c0+944484@0x1f1969c 
symbols @ 0xffe88400 249148+165+369384+224195 start=0x100
console is /sbus@1f,0/zs@f,110:a
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2020 OpenBSD. All rights reserved.  https://www.OpenBSD.org
(etc, etc)



libc/regex: drop debug helpers

2021-01-03 Thread Miod Vallat
regex(3) documents non-standard extensions REG_ITOA and REG_ATOI to
regerror(). In the OpenBSD tree, the only use of them is by the regress
test, so why not move that specific code to the regress test and shrink
libc a bit - remember that this code is present in the installation
media through grep(1).

Assuming there are no objections against this, it would be worth trying
a ports build with this diff to confirm there are no 3rd-party users of
these extensions.

Index: include/regex.h
===
RCS file: /OpenBSD/src/include/regex.h,v
retrieving revision 1.7
diff -u -p -r1.7 regex.h
--- include/regex.h 5 Dec 2012 23:19:57 -   1.7
+++ include/regex.h 3 Jan 2021 17:48:03 -
@@ -83,8 +83,6 @@ typedef struct {
 #defineREG_EMPTY   14
 #defineREG_ASSERT  15
 #defineREG_INVARG  16
-#defineREG_ATOI255 /* convert name to number (!) */
-#defineREG_ITOA0400/* convert number to name (!) */
 
 /* regexec() flags */
 #defineREG_NOTBOL  1
Index: lib/libc/regex/regerror.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regerror.c,v
retrieving revision 1.15
diff -u -p -r1.15 regerror.c
--- lib/libc/regex/regerror.c   30 Dec 2020 08:56:38 -  1.15
+++ lib/libc/regex/regerror.c   3 Jan 2021 17:48:03 -
@@ -48,26 +48,25 @@ static const char *regatoi(const regex_t
 
 static const struct rerr {
int code;
-   const char *name;
const char *explain;
 } rerrs[] = {
-   { REG_NOMATCH,  "REG_NOMATCH",  "regexec() failed to match" },
-   { REG_BADPAT,   "REG_BADPAT",   "invalid regular expression" },
-   { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" },
-   { REG_ECTYPE,   "REG_ECTYPE",   "invalid character class" },
-   { REG_EESCAPE,  "REG_EESCAPE",  "trailing backslash (\\)" },
-   { REG_ESUBREG,  "REG_ESUBREG",  "invalid backreference number" },
-   { REG_EBRACK,   "REG_EBRACK",   "brackets ([ ]) not balanced" },
-   { REG_EPAREN,   "REG_EPAREN",   "parentheses not balanced" },
-   { REG_EBRACE,   "REG_EBRACE",   "braces not balanced" },
-   { REG_BADBR,"REG_BADBR","invalid repetition count(s)" },
-   { REG_ERANGE,   "REG_ERANGE",   "invalid character range" },
-   { REG_ESPACE,   "REG_ESPACE",   "out of memory" },
-   { REG_BADRPT,   "REG_BADRPT",   "repetition-operator operand invalid" },
-   { REG_EMPTY,"REG_EMPTY","empty (sub)expression" },
-   { REG_ASSERT,   "REG_ASSERT",   "\"can't happen\" -- you found a bug" },
-   { REG_INVARG,   "REG_INVARG",   "invalid argument to regex routine" },
-   { 0,"", "*** unknown regexp error code ***" }
+   { REG_NOMATCH,  "regexec() failed to match" },
+   { REG_BADPAT,   "invalid regular expression" },
+   { REG_ECOLLATE, "invalid collating element" },
+   { REG_ECTYPE,   "invalid character class" },
+   { REG_EESCAPE,  "trailing backslash (\\)" },
+   { REG_ESUBREG,  "invalid backreference number" },
+   { REG_EBRACK,   "brackets ([ ]) not balanced" },
+   { REG_EPAREN,   "parentheses not balanced" },
+   { REG_EBRACE,   "braces not balanced" },
+   { REG_BADBR,"invalid repetition count(s)" },
+   { REG_ERANGE,   "invalid character range" },
+   { REG_ESPACE,   "out of memory" },
+   { REG_BADRPT,   "repetition-operator operand invalid" },
+   { REG_EMPTY,"empty (sub)expression" },
+   { REG_ASSERT,   "\"can't happen\" -- you found a bug" },
+   { REG_INVARG,   "invalid argument to regex routine" },
+   { 0,"unknown regexp error code ***" }
 };
 
 /*
@@ -79,51 +78,15 @@ regerror(int errcode, const regex_t *pre
 {
const struct rerr *r;
size_t len;
-   int target = errcode &~ REG_ITOA;
-   const char *s;
-   char convbuf[50];
 
-   if (errcode == REG_ATOI)
-   s = regatoi(preg, convbuf, sizeof convbuf);
-   else {
-   for (r = rerrs; r->code != 0; r++)
-   if (r->code == target)
-   break;
-   
-   if (errcode_ITOA) {
-   if (r->code != 0) {
-   assert(strlen(r->name) < sizeof(convbuf));
-   (void) strlcpy(convbuf, r->name, sizeof 
convbuf);
-   } else
-   (void)snprintf(convbuf, sizeof convbuf,
-   "REG_0x%x", target);
-   s = convbuf;
-   } else
-   s = r->explain;
-   }
+   for (r = rerrs; r->code != 0; r++)
+   if (r->code == errcode)
+   break;
 
if (errbuf_size != 0)
-   len = strlcpy(errbuf, s, errbuf_size);
+   len = 

Re: libc/regex: turn unsafe macros to inline functions

2021-01-03 Thread Miod Vallat
> Is there a reason not to do
> 
>   return (cs->ptr[(uch)c] & cs->mask) != 0;
> 
> This would allow us to get rid of the !! construct in regcomp.c

Why not. What about that?

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.41
diff -u -p -r1.41 regcomp.c
--- regcomp.c   31 Dec 2020 17:24:05 -  1.41
+++ regcomp.c   3 Jan 2021 16:43:50 -
@@ -1101,7 +1099,7 @@ freezeset(struct parse *p, cset *cs)
if (cs2->hash == h && cs2 != cs) {
/* maybe */
for (i = 0; i < css; i++)
-   if (!!CHIN(cs2, i) != !!CHIN(cs, i))
+   if (CHIN(cs2, i) != CHIN(cs, i))
break;  /* no */
if (i == css)
break;  /* yes */
Index: regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.10
diff -u -p -r1.10 regex2.h
--- regex2.h31 Dec 2020 17:20:19 -  1.10
+++ regex2.h3 Jan 2021 16:43:50 -
@@ -107,10 +107,26 @@ typedef struct {
uch mask;   /* bit within array */
uch hash;   /* hash code */
 } cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#defineCHadd(cs, c)((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash 
+= (c))
-#defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
-#defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
+
+static inline void
+CHadd(cset *cs, char c)
+{
+   cs->ptr[(uch)c] |= cs->mask;
+   cs->hash += c;
+}
+
+static inline void
+CHsub(cset *cs, char c)
+{
+   cs->ptr[(uch)c] &= ~cs->mask;
+   cs->hash -= c;
+}
+
+static inline int
+CHIN(const cset *cs, char c)
+{
+   return (cs->ptr[(uch)c] & cs->mask) != 0;
+}
 
 /*
  * main compiled-expression structure



libc/regex: turn unsafe macros to inline functions

2021-01-02 Thread Miod Vallat
That code was written before inline functions were supported by
compilers; now that they are even part of the language standard, turn
macros into inline functions so that there is no need to document in
comments that they will evaluate their arguments multiple times.

(one may consider switching their names to lowercase now that these are
no longer macros.)

Index: regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.10
diff -u -p -r1.10 regex2.h
--- regex2.h31 Dec 2020 17:20:19 -  1.10
+++ regex2.h2 Jan 2021 15:59:51 -
@@ -107,10 +107,24 @@ typedef struct {
uch mask;   /* bit within array */
uch hash;   /* hash code */
 } cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#defineCHadd(cs, c)((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash 
+= (c))
-#defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
-#defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
+
+static inline void
+CHadd(cset *cs, char c)
+{
+   cs->ptr[(uch)c] |= cs->mask;
+   cs->hash += c;
+}
+static inline void
+CHsub(cset *cs, char c)
+{
+   cs->ptr[(uch)c] &= ~cs->mask;
+   cs->hash -= c;
+}
+static inline uch
+CHIN(const cset *cs, char c)
+{
+   return cs->ptr[(uch)c] & cs->mask;
+}
 
 /*
  * main compiled-expression structure



libc/regex: more dead code

2021-01-02 Thread Miod Vallat
The removal of the categories code made these two functions unused, so
remove them as well.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.41
diff -u -p -r1.41 regcomp.c
--- regcomp.c   31 Dec 2020 17:24:05 -  1.41
+++ regcomp.c   2 Jan 2021 15:59:51 -
@@ -90,8 +90,6 @@ static void freeset(struct parse *, cset
 static int freezeset(struct parse *, cset *);
 static int firstch(struct parse *, cset *);
 static int nch(struct parse *, cset *);
-static int isinsets(struct re_guts *, int);
-static int samesets(struct re_guts *, int, int);
 static sopno dupl(struct parse *, sopno, sopno);
 static void doemit(struct parse *, sop, size_t);
 static void doinsert(struct parse *, sop, size_t, sopno);
@@ -1148,41 +1146,6 @@ nch(struct parse *p, cset *cs)
 }
 
 /*
- - isinsets - is this character in any sets?
- */
-static int /* predicate */
-isinsets(struct re_guts *g, int c)
-{
-   uch *col;
-   int i;
-   int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
-   unsigned uc = (uch)c;
-
-   for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
-   if (col[uc] != 0)
-   return(1);
-   return(0);
-}
-
-/*
- - samesets - are these two characters in exactly the same sets?
- */
-static int /* predicate */
-samesets(struct re_guts *g, int c1, int c2)
-{
-   uch *col;
-   int i;
-   int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
-   unsigned uc1 = (uch)c1;
-   unsigned uc2 = (uch)c2;
-
-   for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
-   if (col[uc1] != col[uc2])
-   return(0);
-   return(1);
-}
-
-/*
  - dupl - emit a duplicate of a bunch of sops
  */
 static sopno   /* start of duplicate */
@@ -1394,7 +1357,7 @@ findmust(struct parse *p, struct re_guts
*cp++ = (char)OPND(s);
}
assert(cp == g->must + g->mlen);
-   *cp++ = '\0';   /* just on general principles */
+   *cp = '\0'; /* just on general principles */
 }
 
 /*



libc/regex: more regular error handling

2020-12-30 Thread Miod Vallat
The REQUIRE macro is used to check for a condition, and set an error in
the parse struct if it is not satisfied.

This changes it from ((condition) || function call) to a, IMHO more
readable, if() test.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- regcomp.c   30 Dec 2020 08:59:17 -  1.38
+++ regcomp.c   31 Dec 2020 07:21:31 -
@@ -84,7 +84,7 @@ static void ordinary(struct parse *, int
 static void backslash(struct parse *, int);
 static void nonnewline(struct parse *);
 static void repeat(struct parse *, sopno, int, int);
-static int seterr(struct parse *, int);
+static void seterr(struct parse *, int);
 static cset *allocset(struct parse *);
 static void freeset(struct parse *, cset *);
 static int freezeset(struct parse *, cset *);
@@ -121,7 +120,7 @@ static char nuls[10];   /* place to point
 #defineNEXTn(n)(p->next += (n))
 #defineGETNEXT()   (*p->next++)
 #defineSETERROR(e) seterr(p, (e))
-#defineREQUIRE(co, e)  (void) ((co) || SETERROR(e))
+#defineREQUIRE(co, e)  do { if (!(co)) SETERROR(e); } while (0)
 #defineEMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
 #defineINSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
 #defineAHEAD(pos)  dofwd(p, pos, HERE()-(pos))
@@ -1010,14 +996,13 @@ repeat(struct parse *p,
 /*
  - seterr - set an error condition
  */
-static int /* useless but makes type checking happy */
+static void
 seterr(struct parse *p, int e)
 {
if (p->error == 0)  /* keep earliest error condition */
p->error = e;
p->next = nuls; /* try to bring things to a halt */
p->end = nuls;
-   return(0);  /* make the return value well-defined */
 }
 
 /*



libc/regex: drop more unused data

2020-12-30 Thread Miod Vallat
re_guts catspace[] is only written to (via categories[]), and never used
for anything, so don't bother keeping that.

Index: lib/libc/regex/regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- lib/libc/regex/regcomp.c30 Dec 2020 08:59:17 -  1.38
+++ lib/libc/regex/regcomp.c31 Dec 2020 07:20:39 -
@@ -92,7 +92,6 @@ static int firstch(struct parse *, cset 
 static int nch(struct parse *, cset *);
 static int isinsets(struct re_guts *, int);
 static int samesets(struct re_guts *, int, int);
-static void categorize(struct parse *, struct re_guts *);
 static sopno dupl(struct parse *, sopno, sopno);
 static void doemit(struct parse *, sop, size_t);
 static void doinsert(struct parse *, sop, size_t, sopno);
@@ -198,9 +197,6 @@ regcomp(regex_t *preg, const char *patte
g->must = NULL;
g->mlen = 0;
g->nsub = 0;
-   g->ncategories = 1; /* category 0 is "everything else" */
-   g->categories = >catspace[-(CHAR_MIN)];
-   memset(g->catspace, 0, sizeof(g->catspace));
g->backrefs = 0;
 
/* do it */
@@ -216,7 +212,6 @@ regcomp(regex_t *preg, const char *patte
g->laststate = THERE();
 
/* tidy up loose ends and fill things in */
-   categorize(p, g);
stripsnug(p, g);
findmust(p, g);
g->nplus = pluscount(p, g);
@@ -883,15 +878,10 @@ bothcases(struct parse *p, int ch)
 static void
 ordinary(struct parse *p, int ch)
 {
-   cat_t *cap = p->g->categories;
-
if ((p->g->cflags_ICASE) && isalpha((uch)ch) && othercase(ch) != ch)
bothcases(p, ch);
-   else {
+   else
EMIT(OCHAR, (uch)ch);
-   if (cap[ch] == 0)
-   cap[ch] = p->g->ncategories++;
-   }
 }
 
 /*
@@ -1195,31 +1180,6 @@ samesets(struct re_guts *g, int c1, int 
if (col[uc1] != col[uc2])
return(0);
return(1);
-}
-
-/*
- - categorize - sort out character categories
- */
-static void
-categorize(struct parse *p, struct re_guts *g)
-{
-   cat_t *cats = g->categories;
-   int c;
-   int c2;
-   cat_t cat;
-
-   /* avoid making error situations worse */
-   if (p->error != 0)
-   return;
-
-   for (c = CHAR_MIN; c <= CHAR_MAX; c++)
-   if (cats[c] == 0 && isinsets(g, c)) {
-   cat = g->ncategories++;
-   cats[c] = cat;
-   for (c2 = c+1; c2 <= CHAR_MAX; c2++)
-   if (cats[c2] == 0 && samesets(g, c, c2))
-   cats[c2] = cat;
-   }
 }
 
 /*
Index: lib/libc/regex/regex2.h
===
RCS file: /OpenBSD/src/lib/libc/regex/regex2.h,v
retrieving revision 1.9
diff -u -p -r1.9 regex2.h
--- lib/libc/regex/regex2.h 30 Dec 2020 08:54:42 -  1.9
+++ lib/libc/regex/regex2.h 31 Dec 2020 07:20:39 -
@@ -112,9 +112,6 @@ typedef struct {
 #defineCHsub(cs, c)((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash 
-= (c))
 #defineCHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
 
-/* stuff for character categories */
-typedef unsigned char cat_t;
-
 /*
  * main compiled-expression structure
  */
@@ -136,15 +133,11 @@ struct re_guts {
 #  define  BAD 04  /* something wrong */
int nbol;   /* number of ^ used */
int neol;   /* number of $ used */
-   int ncategories;/* how many character categories */
-   cat_t *categories;  /* ->catspace[-CHAR_MIN] */
char *must; /* match must contain this string */
int mlen;   /* length of must */
size_t nsub;/* copy of re_nsub */
int backrefs;   /* does it use back references? */
sopno nplus;/* how deep does it nest +s? */
-   /* catspace must be last */
-   cat_t catspace[NC]; /* actually [NC] */
 };
 
 /* misc utilities */
Index: regress/lib/libc/regex/debug.c
===
RCS file: /OpenBSD/src/regress/lib/libc/regex/debug.c,v
retrieving revision 1.4
diff -u -p -r1.4 debug.c
--- regress/lib/libc/regex/debug.c  31 Jul 2003 21:48:03 -  1.4
+++ regress/lib/libc/regex/debug.c  31 Dec 2020 07:20:39 -
@@ -26,10 +26,8 @@ FILE *d;
register int i;
register int c;
register int last;
-   int nincat[NC];
 
-   fprintf(d, "%ld states, %d categories", (long)g->nstates,
-   g->ncategories);
+   fprintf(d, "%ld states", (long)g->nstates);
fprintf(d, ", first %ld last %ld", (long)g->firststate,
(long)g->laststate);
if 

libc/regex: const'r'us

2020-12-30 Thread Miod Vallat
Spencer's code was written before const was a thing, but we can do
better. Neither regcomp(3) nor regex(3) modify the strings they are
being passed, so we can keep internal pointers as const as well and
avoid {dub,spur}ious casts.

While there, the temporary array in nonnewline() can be made static
const as well rather than recreated every time.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.38
diff -u -p -r1.38 regcomp.c
--- regcomp.c   30 Dec 2020 08:59:17 -  1.38
+++ regcomp.c   31 Dec 2020 07:21:31 -
@@ -53,8 +53,8 @@
  * other clumsinesses
  */
 struct parse {
-   char *next; /* next character in RE */
-   char *end;  /* end of string (-> NUL normally) */
+   const char *next;   /* next character in RE */
+   const char *end;/* end of string (-> NUL normally) */
int error;  /* has an error been seen? */
sop *strip; /* malloced strip */
sopno ssize;/* malloced strip size (allocated) */
@@ -179,7 +178,7 @@ regcomp(regex_t *preg, const char *patte
 
/* set things up */
p->g = g;
-   p->next = (char *)pattern;  /* convenience; we do not modify it */
+   p->next = pattern;
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
@@ -754,7 +749,7 @@ p_b_term(struct parse *p, cset *cs)
 static void
 p_b_cclass(struct parse *p, cset *cs)
 {
-   char *sp = p->next;
+   const char *sp = p->next;
const struct cclass *cp;
size_t len;
const char *u;
@@ -816,7 +811,7 @@ static char /* value of collating elem
 p_b_coll_elem(struct parse *p,
 int endc)  /* name ended by endc,']' */
 {
-   char *sp = p->next;
+   const char *sp = p->next;
const struct cname *cp;
size_t len;
 
@@ -860,8 +855,8 @@ othercase(int ch)
 static void
 bothcases(struct parse *p, int ch)
 {
-   char *oldnext = p->next;
-   char *oldend = p->end;
+   const char *oldnext = p->next;
+   const char *oldend = p->end;
char bracket[3];
 
ch = (uch)ch;
@@ -921,16 +911,12 @@ backslash(struct parse *p, int ch)
 static void
 nonnewline(struct parse *p)
 {
-   char *oldnext = p->next;
-   char *oldend = p->end;
-   char bracket[4];
+   const char *oldnext = p->next;
+   const char *oldend = p->end;
+   static const char bracket[4] = { '^', '\n', ']', '\0' };
 
p->next = bracket;
p->end = bracket+3;
-   bracket[0] = '^';
-   bracket[1] = '\n';
-   bracket[2] = ']';
-   bracket[3] = '\0';
p_bracket(p);
assert(p->next == bracket+3);
p->next = oldnext;



compress sparc64 bsd.rd

2020-12-30 Thread Miod Vallat
Up until 6.5, sparc64 bsd.rd were gzipped kernels. This got lost during
the Great Installation Media Unification of the 6.6 release cycle, and
since then bsd.rd are uncompressed.

The following diff ought to fix this and bring back sparc64 netboot
times down to acceptable times.

Index: miniroot/Makefile
===
RCS file: /OpenBSD/src/distrib/sparc64/miniroot/Makefile,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile
--- miniroot/Makefile   18 May 2020 06:20:44 -  1.23
+++ miniroot/Makefile   30 Dec 2020 20:35:55 -
@@ -100,7 +100,7 @@ unconfig:
 
 .ifdef RELEASEDIR
 install:
-   cp bsd.rd ${RELEASEDIR}/bsd.rd
+   cp bsd.gz ${RELEASEDIR}/bsd.rd
chmod a+r ${RELEASEDIR}/bsd.rd
cp ${FS} ${RELEASEDIR}
cp ${CDROM} ${RELEASEDIR}



libc/regex: safer pointer arithmetic

2020-12-29 Thread Miod Vallat
regcomp.c uses the "start + count < end" idiom to check that there are
"count" bytes available in an array of char "start" and "end" both point
to.

This is fine, unless "start + count" goes beyond the last element of the
array. In this case, pedantic interpretation of the C standard makes
the comparison of such a pointer against "end" undefined, and optimizers
from hell will happily remove as much code as possible because of this.

An example of this occurs in regcomp.c's bothcases(), which defines
bracket[3], sets "next" to "bracket" and "end" to "bracket + 2". Then it
invokes p_bracket(), which starts with "if (p->next + 5 < p->end)"...

Because bothcases() and p_bracket() are static functions in regcomp.c,
there is a real risk of miscompilation if aggressive inlining happens.

The following diff rewrites the "start + count < end" constructs into
"end - start > count". Assuming "end" and "start" are always pointing in
the array (such as "bracket[3]" above), "end - start" is well-defined
and can be compared without trouble.

As a bonus, MORE2() implies MORE() therefore SEETWO() can be simplified
a bit.

Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 10:24:18 -
@@ -113,10 +110,10 @@ static char nuls[10]; /* place to point
  */
 #definePEEK()  (*p->next)
 #definePEEK2() (*(p->next+1))
-#defineMORE()  (p->next < p->end)
-#defineMORE2() (p->next+1 < p->end)
+#defineMORE()  (p->end - p->next > 0)
+#defineMORE2() (p->end - p->next > 1)
 #defineSEE(c)  (MORE() && PEEK() == (c))
-#defineSEETWO(a, b)(MORE() && MORE2() && PEEK() == (a) && PEEK2() 
== (b))
+#defineSEETWO(a, b)(MORE2() && PEEK() == (a) && PEEK2() == (b))
 #defineEAT(c)  ((SEE(c)) ? (NEXT(), 1) : 0)
 #defineEATTWO(a, b)((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
 #defineNEXT()  (p->next++)
@@ -623,15 +620,17 @@ p_bracket(struct parse *p)
int invert = 0;
 
/* Dept of Truly Sickening Special-Case Kludges */
-   if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
-   EMIT(OBOW, 0);
-   NEXTn(6);
-   return;
-   }
-   if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
-   EMIT(OEOW, 0);
-   NEXTn(6);
-   return;
+   if (p->end - p->next > 5) {
+   if (strncmp(p->next, "[:<:]]", 6) == 0) {
+   EMIT(OBOW, 0);
+   NEXTn(6);
+   return;
+   }
+   if (strncmp(p->next, "[:>:]]", 6) == 0) {
+   EMIT(OEOW, 0);
+   NEXTn(6);
+   return;
+   }
}
 
if ((cs = allocset(p)) == NULL) {



libc/regex: regerror minor tweaks

2020-12-29 Thread Miod Vallat
The following diff constifies the strings in regerror.c and also makes
use of the strlcpy() return value to avoid a redundant strlen() call.

Index: regerror.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regerror.c,v
retrieving revision 1.14
diff -u -p -r1.14 regerror.c
--- regerror.c  1 Nov 2015 03:45:29 -   1.14
+++ regerror.c  29 Dec 2020 10:24:18 -
@@ -44,12 +44,12 @@
 
 #include "utils.h"
 
-static char *regatoi(const regex_t *, char *, int);
+static const char *regatoi(const regex_t *, char *, int);
 
-static struct rerr {
+static const struct rerr {
int code;
-   char *name;
-   char *explain;
+   const char *name;
+   const char *explain;
 } rerrs[] = {
{ REG_NOMATCH,  "REG_NOMATCH",  "regexec() failed to match" },
{ REG_BADPAT,   "REG_BADPAT",   "invalid regular expression" },
@@ -77,10 +77,10 @@ static struct rerr {
 size_t
 regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
 {
-   struct rerr *r;
+   const struct rerr *r;
size_t len;
int target = errcode &~ REG_ITOA;
-   char *s;
+   const char *s;
char convbuf[50];
 
if (errcode == REG_ATOI)
@@ -102,21 +102,21 @@ regerror(int errcode, const regex_t *pre
s = r->explain;
}
 
-   len = strlen(s) + 1;
-   if (errbuf_size > 0) {
-   strlcpy(errbuf, s, errbuf_size);
-   }
+   if (errbuf_size != 0)
+   len = strlcpy(errbuf, s, errbuf_size);
+   else
+   len = strlen(s);
 
-   return(len);
+   return len + 1;
 }
 
 /*
  - regatoi - internal routine to implement REG_ATOI
  */
-static char *
+static const char *
 regatoi(const regex_t *preg, char *localbuf, int localbufsize)
 {
-   struct rerr *r;
+   const struct rerr *r;
 
for (r = rerrs; r->code != 0; r++)
if (strcmp(r->name, preg->re_endp) == 0)



libc/regex: remove dead code

2020-12-29 Thread Miod Vallat
cclasses[] multis field is always an empty string. Remove it and code
dealing with it. This code was incomplete anyway.

Index: cclass.h
===
RCS file: /OpenBSD/src/lib/libc/regex/cclass.h,v
retrieving revision 1.6
diff -u -p -r1.6 cclass.h
--- cclass.h13 Oct 2020 04:42:28 -  1.6
+++ cclass.h29 Dec 2020 09:30:53 -
@@ -39,30 +39,22 @@
 static const struct cclass {
const char *name;
const char *chars;
-   const char *multis;
 } cclasses[] = {
{ "alnum",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789",   ""} ,
-   { "alpha",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
-   ""} ,
-   { "blank",  " \t",  ""} ,
+0123456789" },
+   { "alpha",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 
},
+   { "blank",  " \t" },
{ "cntrl",  "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
-\25\26\27\30\31\32\33\34\35\36\37\177",""} ,
-   { "digit",  "0123456789",   ""} ,
+\25\26\27\30\31\32\33\34\35\36\37\177" },
+   { "digit",  "0123456789" },
{ "graph",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-   ""} ,
-   { "lower",  "abcdefghijklmnopqrstuvwxyz",
-   ""} ,
+0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" },
+   { "lower",  "abcdefghijklmnopqrstuvwxyz" },
{ "print",  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
-0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
-   ""} ,
-   { "punct",  "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
-   ""} ,
-   { "space",  "\t\n\v\f\r ",  ""} ,
-   { "upper",  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
-   ""} ,
-   { "xdigit", "0123456789ABCDEFabcdef",
-   ""} ,
-   { NULL, 0,  "" }
+0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ " },
+   { "punct",  "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" },
+   { "space",  "\t\n\v\f\r " },
+   { "upper",  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
+   { "xdigit", "0123456789ABCDEFabcdef" },
+   { NULL, 0 }
 };
Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 09:30:53 -
@@ -90,9 +90,6 @@ static void freeset(struct parse *, cset
 static int freezeset(struct parse *, cset *);
 static int firstch(struct parse *, cset *);
 static int nch(struct parse *, cset *);
-static void mcadd(struct parse *, cset *, const char *);
-static void mcinvert(struct parse *, cset *);
-static void mccase(struct parse *, cset *);
 static int isinsets(struct re_guts *, int);
 static int samesets(struct re_guts *, int, int);
 static void categorize(struct parse *, struct re_guts *);
@@ -666,8 +663,6 @@ p_bracket(struct parse *p)
if (ci != i)
CHadd(cs, ci);
}
-   if (cs->multis != NULL)
-   mccase(p, cs);
}
if (invert) {
int i;
@@ -679,12 +674,8 @@ p_bracket(struct parse *p)
CHadd(cs, i);
if (p->g->cflags_NEWLINE)
CHsub(cs, '\n');
-   if (cs->multis != NULL)
-   mcinvert(p, cs);
}
 
-   assert(cs->multis == NULL); /* xxx */
-
if (nch(p, cs) == 1) {  /* optimize singleton sets */
ordinary(p, firstch(p, cs));
freeset(p, cs);
@@ -782,8 +773,6 @@ p_b_cclass(struct parse *p, cset *cs)
u = cp->chars;
while ((c = *u++) != '\0')
CHadd(cs, c);
-   for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
-   MCadd(p, cs, u);
 }
 
 /*
@@ -1073,8 +1062,6 @@ allocset(struct parse *p)
cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
cs->mask = 1 << ((no) % CHAR_BIT);
cs->hash = 0;
-   cs->smultis = 0;
-   cs->multis = NULL;
 
return(cs);
 nomem:
@@ -1171,52 +1158,6 @@ nch(struct parse *p, cset *cs)
if (CHIN(cs, i))
n++;
return(n);
-}
-
-/*
- - mcadd - add a collating element to a cset
- */
-static void
-mcadd( struct parse *p, cset *cs, const char *cp)
-{
-   size_t oldend = cs->smultis;
-   void *np;
-
-   cs->smultis += strlen(cp) + 1;
-   np = realloc(cs->multis, cs->smultis);
-   if (np == NULL) {
-   

libc/regex: constify more data

2020-12-29 Thread Miod Vallat
The following diff constifies the strings in cnames[]. No functional
change.

Index: cname.h
===
RCS file: /OpenBSD/src/lib/libc/regex/cname.h,v
retrieving revision 1.5
diff -u -p -r1.5 cname.h
--- cname.h 2 Jun 2003 20:18:36 -   1.5
+++ cname.h 29 Dec 2020 09:30:53 -
@@ -36,8 +36,8 @@
  */
 
 /* character-name table */
-static struct cname {
-   char *name;
+static const struct cname {
+   const char *name;
char code;
 } cnames[] = {
{ "NUL",'\0' },
Index: regcomp.c
===
RCS file: /OpenBSD/src/lib/libc/regex/regcomp.c,v
retrieving revision 1.35
diff -u -p -r1.35 regcomp.c
--- regcomp.c   13 Oct 2020 04:42:28 -  1.35
+++ regcomp.c   29 Dec 2020 09:30:53 -
@@ -826,7 +815,7 @@ p_b_coll_elem(struct parse *p,
 int endc)  /* name ended by endc,']' */
 {
char *sp = p->next;
-   struct cname *cp;
+   const struct cname *cp;
size_t len;
 
while (MORE() && !SEETWO(endc, ']'))



Re: uvm_map_inentry() checks in trap()

2020-09-25 Thread Miod Vallat
> Repeating diffs from i386, amd64, sh.  Improve alpha diff to handle an
> additional fault case.  Adding diffs for powerpc, powerc64, and m88k.

The m88k diff is incomplete:
- changes need to be done in both m88100_trap() and m88110_trap().
- the uvm_map_inentry() check should be put after the user_fault and
  m88110_user_fault labels, which implies the KERNEL_LOCK must be moved
  after these labels and removed from the two code paths jumping to
  these labels.



Re: fix eeprom(8) on macppc

2020-09-20 Thread Miod Vallat
> > Suggested diff below; clue from NetBSD.
> I looked for openprom code there but only found it for SPARC, can you
> point me to where you got the "clue" from exactly?

http://bxr.su/NetBSD/sys/dev/ofw/openfirmio.c#205



fix eeprom(8) on macppc

2020-09-20 Thread Miod Vallat
I had noticed for years that eeprom(8) always reported failure when
attempting to change OpenFirmware environment variables on macppc.

Upon further examination, it doesn't - the variables get changed, but
error is reported. This is caused by a difference in implementation
behaviour between Apple's OpenFirmware and Sun's.

Suggested diff below; clue from NetBSD.

Before:
# eeprom boot-command
boot-command=mac-boot
# eeprom boot-command=boot
eeprom: invalid keyword: boot-command
# eeprom boot-command
boot-command=boot   <-- yet the value has been changed

After:
# eeprom boot-command
boot-command=mac-boot
# eeprom boot-command=boot
# eeprom boot-command
boot-command=boot


Index: openprom.c
===
RCS file: /OpenBSD/src/sys/arch/macppc/macppc/openprom.c,v
retrieving revision 1.4
diff -u -p -r1.4 openprom.c
--- openprom.c  19 Sep 2015 21:07:04 -  1.4
+++ openprom.c  20 Sep 2020 17:56:35 -
@@ -186,7 +186,11 @@ openpromioctl(dev_t dev, u_long cmd, cad
strlcpy(buf, name, 32); /* XXX */
len = OF_setprop(node, buf, value, op->op_buflen + 1);
splx(s);
-   if (len != op->op_buflen)
+   /*
+* For string properties, the Apple OpenFirmware implementation
+* returns the buffer length including the trailing NUL.
+*/
+   if (len != op->op_buflen && len != op->op_buflen + 1)
error = EINVAL;
break;
 



Re: sigabort(), p_sigmask & p_siglist

2020-09-16 Thread Miod Vallat
> Something doesn't feel right.
> 
> db_kill_cmd finds a process, called p, then kills it.  In your new diff
> calling sigexit, take note of the comment at the top:
> 
>  * Force the current process to exit with the specified signal, dumping core
> 
> current process?  Doesn't look like it, it looks like it kills p.  But then
> it calls exit1?

Ah, yes, sigexit() ends up with a context switch. This is not a good
idea for the places where Martin wants to use it, his first diff was
better. Sorry for the noise.



Re: sigabort(), p_sigmask & p_siglist

2020-09-16 Thread Miod Vallat


> Diff below introduces an helper for sending an uncatchable SIGABRT and
> annotate that `p_siglist' and `p_sigmask' are updated using atomic
> operations.

Why not use sigexit(p, SIGABRT); for that purpose?



Re: symmetric toeplitz hashing

2020-06-14 Thread Miod Vallat


>> Others have pointed out off-list that one can use __builtin_popcount(),
>> but __builtin_parity() is exactly what I want. Is it available on all
>> architectures?
>
> I don't think it is available on gcc 3.x for m88k but someone with
> an m88k should confirm.

__builtin_popcount() does not exist in gcc 3.



Re: powerpc64: ldbrx/stdbrx for endian.h?

2020-06-08 Thread Miod Vallat


> There is an interest in supporting PowerPC 970 ("G5").  That would
> allow people to use more than 2G of RAM on the last generations of
> Apple PowerMac machines.  Otherwise I don't think we are interested in
> anything before POWER8.

Years ago, a decision was made to ditch 64-bit PA-RISC (mostly because
toolchain limitations for 64-bit userland) and keep running a 32-bit
kernels on 64-bit PA-RISC systems with a 32-bit PDC.

Before that, mickey@ was adamant that earlier hppa64 systems (pre-astro)
with 32-bit PCI busses and no way to have more than 2GB of memory (such
as C240) were not worth supporting in 64-bit mode.

At about the same time, it was also decided that G5 systems with more
than 2 or 3 GB of memory were rare enough not to be worth supporting in
64-bit mode.

Given the current "3GHz and gobs of ram or dust" party's line those days,
I don't see a point in attempting to support G5 systems in 64-bit mode,
if this seriously impacts support for sexier^Wmore modern designs.



Re: sparc64 boot issue on qemu

2020-05-30 Thread Miod Vallat
Yet another case where the emulator does not match the real hardware.

Why bother with them?

Get qemu to fix their shit so that the frame buffer metrics variable are
aligned on 64-bit boundaries. There might not be a written specification
for this requirement, but that's the way real hardware behaves, and it
makes complete sense (the variables are OFW cells, which are 64-bit
values and 64-bit aligned).

If you really want to accomodate their broken firmware, you can avoid
using memcpy by relying upon sparc64 being big-endian and do something
like:

-   *fontwidth = (int)*(uint64_t *)romwidth;
-   *fontheight = (int)*(uint64_t *)romheight;
-   *wtop = (int)*(uint64_t *)windowtop;
-   *wleft = (int)*(uint64_t *)windowleft;
+   *fontwidth = *(uint32_t *)(romwidth + 4);
+   *fontheight = *(uint32_t *)(romheight + 4);
+   *wtop = *(uint32_t *)(windowtop + 4);
+   *wleft = *(uint32_t *)(windowleft + 4);

Miod



tcpdump gtp bugfix

2020-05-19 Thread Miod Vallat
There seems to be a logic error in tcpdump's print-gtp.c.

The code is printing some values by passing a pointer to the array of
strings, and the index within the array, and the routine uses
sizeof(array) / sizeof(array[0]) to figure out the bound.

But since the caller is passing a pointer, sizeof returns the size of
the pointer and not of the array itself (and clang will rightfully warn
about this).

The right fix is to have the caller pass the upper bound.

Suggested fix below.

Index: print-gtp.c
===
RCS file: /OpenBSD/src/usr.sbin/tcpdump/print-gtp.c,v
retrieving revision 1.11
diff -u -p -r1.11 print-gtp.c
--- print-gtp.c 22 Oct 2018 16:12:45 -  1.11
+++ print-gtp.c 1 May 2020 09:37:58 -
@@ -57,12 +57,16 @@
 #include "interface.h"
 #include "gtp.h"
 
+#ifndef nitems
+#define nitems(_a)  (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
 void   gtp_print(const u_char *, u_int, u_short, u_short);
 void   gtp_decode_ie(const u_char *, u_short, int);
 void   gtp_print_tbcd(const u_char *, u_int);
 void   gtp_print_user_address(const u_char *, u_int);
 void   gtp_print_apn(const u_char *, u_int);
-void   gtp_print_str(const char **, u_int);
+void   gtp_print_str(const char **, u_int, u_int);
 
 void   gtp_v0_print(const u_char *, u_int, u_short, u_short);
 void   gtp_v0_print_prime(const u_char *);
@@ -466,10 +470,9 @@ gtp_print_apn(const u_char *cp, u_int le
 
 /* Print string from array. */
 void
-gtp_print_str(const char **strs, u_int index)
+gtp_print_str(const char **strs, u_int bound, u_int index)
 {
-
-   if (index >= (sizeof(*strs) / sizeof(*strs[0])))
+   if (index >= bound)
printf(": %u", index);
else if (strs[index] != NULL)
printf(": %s", strs[index]);
@@ -727,7 +730,8 @@ gtp_v0_print_tv(const u_char *cp, u_int 
/* 12.15 7.3.4.5.3 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV0_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
-   gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
+   gtp_print_str(gtp_packet_xfer_cmd, nitems(gtp_packet_xfer_cmd),
+   cp[0]);
ielen = GTPV0_TV_PACKET_XFER_CMD_LENGTH;
break;

@@ -1315,7 +1319,8 @@ gtp_v1_print_tv(const u_char *cp, u_int 
/* 32.295 6.2.4.5.2 - Packet Transfer Command. */
TCHECK2(cp[0], GTPV1_TV_PACKET_XFER_CMD_LENGTH - 1);
printf("Packet Transfer Command");
-   gtp_print_str(gtp_packet_xfer_cmd, cp[0]);
+   gtp_print_str(gtp_packet_xfer_cmd, nitems(gtp_packet_xfer_cmd),
+   cp[0]);
ielen = GTPV1_TV_PACKET_XFER_CMD_LENGTH;
break;
 
@@ -1515,7 +1520,7 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.50 - RAT Type. */
printf("RAT");
-   gtp_print_str(gtp_rat_type, cp[0]);
+   gtp_print_str(gtp_rat_type, nitems(gtp_rat_type), cp[0]);
break;
 
case GTPV1_TLV_USER_LOCATION_INFO:
@@ -1607,7 +1612,8 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.66 - MBMS 2G/3G Indicator. */
printf("MBMS 2G/3G Indicator");
-   gtp_print_str(mbms_2g3g_indicator, cp[0]);
+   gtp_print_str(mbms_2g3g_indicator, nitems(mbms_2g3g_indicator),
+   cp[0]);
break;
 
case GTPV1_TLV_ENHANCED_NSAPI:
@@ -1697,7 +1703,8 @@ gtp_v1_print_tlv(const u_char *cp, u_int
 
/* 29.060 7.7.80 - MS Info Change Reporting. */
printf("MS Info Change Reporting");
-   gtp_print_str(ms_info_change_rpt, cp[0]);
+   gtp_print_str(ms_info_change_rpt, nitems(ms_info_change_rpt),
+   cp[0]);
break;
 
case GTPV1_TLV_DIRECT_TUNNEL_FLAGS:



Re: Increase default number of devices created for LDOMs on sparc64

2020-05-18 Thread Miod Vallat


> Learning how LDOMs work on this T4-1 and we only create 8 devices
> (each /dev/ldom* and /dev/ttyV*) by default. The now-commonly-available
> T4-1 machines can do far more than that pretty easily, so bump up the
> number created by default from 8 to 16.
>
> ok?

MAKEDEV is a generated file. Edit the second-to-last line of MAKEDEV.md
to add the extra 8 nodes.



Re: Code changes for clarity

2020-05-18 Thread Miod Vallat


> For instance, in the wsdisplay_emulops structure, there are:
>
> int   (*alloc_attr)(void *c, int fg, int bg, int flags, long *attrp);
> void  (*unpack_attr)(void *c, long attr, int *fg, int *bg, int *ul);
>
> And at the end of the structure is this comment, showing that at
> least someone (other than me) was confused by it:
>   /* XXX need a free_attr() ??? */

`alloc_attr' was named that way because there was a theoretical
possibility that drivers would actually need to allocate storage for
attribute-related information (which is why attributes are longs rather
than uint32_t). A `free_attr' routine would then make sense, except that
there is no clear lifetime for attributes (e.g. the kernel messages
attribute has to survive free_screen).

Since in practice, no driver actually allocates anything and all
attributes fit in either 8 bits (vga text mode) or 32 bits (rasops), it
would make sense to rename this function to `compute_attr' or
`pack_attr' and narrow the attribute type from `long' to `uint32_t'.

$.02

Miod



ld.so and ldconfig manpage nits

2020-05-08 Thread Miod Vallat
This ensures consistent spelling of set-{user,group}-ID, and also
mentions LD_DEBUG is ignored by ld.so for such binaries.

Index: ld.so.1
===
RCS file: /OpenBSD/src/libexec/ld.so/ld.so.1,v
retrieving revision 1.23
diff -u -p -r1.23 ld.so.1
--- ld.so.1 14 Feb 2019 07:26:31 -  1.23
+++ ld.so.1 8 May 2020 09:11:30 -
@@ -161,6 +161,7 @@ are recognised and have their usual mean
 When set, be verbose about what
 .Nm
 does.
+This variable is ignored for set-user-ID and set-group-ID executables.
 .El
 .Sh FILES
 .Bl -tag -width /var/run/ld.so.hintsXXX -compact
Index: ldconfig/ldconfig.8
===
RCS file: /OpenBSD/src/libexec/ld.so/ldconfig/ldconfig.8,v
retrieving revision 1.29
diff -u -p -r1.29 ldconfig.8
--- ldconfig/ldconfig.8 4 Jul 2016 20:56:50 -   1.29
+++ ldconfig/ldconfig.8 8 May 2020 09:11:30 -
@@ -120,9 +120,7 @@ Switch on verbose mode.
 .El
 .Sh SECURITY
 Special care must be taken when loading shared libraries into the address
-space of
-.Ev set-user-Id
-programs.
+space of set-user-ID and set-group-ID programs.
 Whenever such a program is run,
 .Xr ld.so 1
 will only load shared libraries from the
@@ -141,7 +139,7 @@ It is presumed that the set of directori
 .Nm
 are under control of the system's administrator.
 .Xr ld.so 1
-further assists set-user-Id programs by erasing the
+further assists set-user-ID and set-group-ID programs by erasing the
 .Ev LD_LIBRARY_PATH
 from the environment.
 .Sh ENVIRONMENT



Re: Kill indirect configuration in autoconf(9)

2020-01-21 Thread Miod Vallat


>> While discussing recent config_detach(9) vs close(2) race I figured
>> out that the 'indirect' flag (`cd_indirect') is never set.

Some struct cfdriver initialize it to 1. See isa_cd in
sys/dev/isa/isa.c.

>> Time to kill this feature?

Please don't.



Re: fd(4): tsleep(9) -> tsleep_nsec(9), timeout_add(9) -> timeout_add_msec(9)

2020-01-07 Thread Miod Vallat


> Convert ticks to milliseconds.
>
> The 33 milliseconds in the timeout_add_msec(9) call will be truncated
> to 3 ticks, but that was already the case with the current (hz / 30)
> code so this is no worse.

[...]

>   /* allow 1/30 second for heads to settle */
> - timeout_add(>fdcpseudointr_to, hz / 30);
> + timeout_add_msec(>fdcpseudointr_to, 33);

Why not simply write `1000 / 30' rather than 33, to match the comment?



sparc64: simplify boot()

2020-01-03 Thread Miod Vallat
Although Open Firmware supports it, there is no way from OpenBSD to
reboot with a specified boot command line, so drop vestigial support for
it from boot().

Index: sparc64/machdep.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/machdep.c,v
retrieving revision 1.191
diff -u -p -r1.191 machdep.c
--- sparc64/machdep.c   1 Apr 2019 07:00:52 -   1.191
+++ sparc64/machdep.c   3 Jan 2020 19:24:45 -
@@ -593,9 +593,6 @@ struct pcb dumppcb;
 __dead void
 boot(int howto)
 {
-   int i;
-   static char str[128];
-
if ((howto & RB_RESET) != 0)
goto doreset;
 
@@ -655,30 +652,7 @@ haltsys:
 
 doreset:
printf("rebooting\n\n");
-#if 0
-   if (user_boot_string && *user_boot_string) {
-   i = strlen(user_boot_string);
-   if (i > sizeof(str))
-   OF_boot(user_boot_string);  /* XXX */
-   bcopy(user_boot_string, str, i);
-   } else
-#endif
-   {
-   i = 1;
-   str[0] = '\0';
-   }
-
-   if ((howto & RB_SINGLE) != 0)
-   str[i++] = 's';
-   if ((howto & RB_KDB) != 0)
-   str[i++] = 'd';
-   if (i > 1) {
-   if (str[0] == '\0')
-   str[0] = '-';
-   str[i] = 0;
-   } else
-   str[0] = 0;
-   OF_boot(str);
+   OF_boot("");
panic("cpu_reboot -- failed");
for (;;)
continue;



sparc64: kill BOOT_ARG

2020-01-03 Thread Miod Vallat
BOOT_ARG from  is a NetBSDism which did not make
its way to OpenBSD, where parsing kernel commandline options is done
inline.

It is no surprise then, that it is only used by the sparc64 boot blocks;
but boot blocks really only care about one option, -a, so there is no
need to check for more letters.

The following diff removes BOOT_ARG and simplifies boot blocks logic.
Moreover, since the kernel will pick its options from Open Firmware and
not from the boot blocks, it makes absolutely no sense for the boot
blocks to try and rebuild a commandline with the various options, so
let's get rid of this as well while changing the boot blocks.

Note that, after this diff is applied, none of the original contents of
 remain, and the licence block ought to be updated.
This is left as an exercize for the appropriate developer.

Index: include/boot_flag.h
===
RCS file: /OpenBSD/src/sys/arch/sparc64/include/boot_flag.h,v
retrieving revision 1.5
diff -u -p -r1.5 boot_flag.h
--- include/boot_flag.h 26 Nov 2014 20:06:53 -  1.5
+++ include/boot_flag.h 3 Jan 2020 18:27:05 -
@@ -30,39 +30,6 @@
 #ifndef _MACHINE_BOOT_FLAG_H_
 #define _MACHINE_BOOT_FLAG_H_
 
-#include 
-
-/*
- * Recognize standard boot arguments. If the flag is known, appropriate
- * value is or'ed to retval, otherwise retval is left intact.
- * Note that not all ports use all flags recognized here. This list is mere
- * concatenation of all non-conflicting standard boot flags. Individual ports
- * might use also other flags (see e.g. alpha).
- */
-#defineBOOT_FLAG(arg, retval) do { \
-   switch (arg) {  \
-   case 'a': /* ask for file name to boot from */  \
-   (retval) |= RB_ASKNAME; \
-   break;  \
-   case 'b': /* always halt, never reboot */   \
-   (retval) |= RB_HALT;\
-   break;  \
-   case 'c': /* userconf */\
-   (retval) |= RB_CONFIG;  \
-   break;  \
-   case 'd': /* break into the kernel debugger ASAP (if compiled in) */ \
-   (retval) |= RB_KDB; \
-   break;  \
-   case 's': /* boot to single user */ \
-   (retval) |= RB_SINGLE;  \
-   break;  \
-   default:  /* something else, do nothing */  \
-   break;  \
-   } /* switch */  \
-   \
-   } while (/* CONSTCOND */ 0)
-
-
 /* softraid boot information */
 #define BOOTSR_UUID_MAX 16
 #define BOOTSR_CRYPTO_MAXKEYBYTES 32
Index: stand/ofwboot/boot.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/stand/ofwboot/boot.c,v
retrieving revision 1.32
diff -u -p -r1.32 boot.c
--- stand/ofwboot/boot.c29 Oct 2019 02:55:52 -  1.32
+++ stand/ofwboot/boot.c3 Jan 2020 18:27:05 -
@@ -53,7 +53,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -124,10 +123,18 @@ parseargs(char *str, int *howtop)
while (*cp == ' ')
++cp;
}
+   /*
+* Note that, if only options have been passed, without a kernel
+* name, str == cp and options will be ignored at the boot blocks
+* level.
+* This a feature intended to make `boot -a' behave as intended.
+* If you want the bootblocks to handle arguments explicitly, a
+* kernel filename needs to be provided (as in `boot bsd -a').
+*/
*str = 0;
-   switch(*cp) {
+   switch (*cp) {
default:
-   printf ("boot options string <%s> must start with -\n", cp);
+   printf("boot options string <%s> must start with -\n", cp);
return -1;
case 0:
return 0;
@@ -137,9 +144,10 @@ parseargs(char *str, int *howtop)
 
++cp;
while (*cp) {
-   BOOT_FLAG(*cp, *howtop);
-   /* handle specialties */
switch (*cp++) {
+   case 'a':
+   *howtop |= RB_ASKNAME;
+   break;
case 'd':
if (!debug) debug = 1;
break;
@@ -379,7 +387,7 @@ main(void)
int chosen;
char bootline[512]; /* Should check size? */
char *cp;
-   int i, fd, len;
+   int i, fd;
 #ifdef 

Re: TIMESPEC_TO_NSEC(), futex(2) & __thrsleep(2)

2019-12-31 Thread Miod Vallat
> Should we use inline instead of __inline for new code?

inline is a C99 keyword, C99 is 20 years old now, and the kernel source
is using C99 named initializers, therefore it is safe to assume C99
support from the compiler.

It's time to stop defining __const, __inline, __signed and __volatile in
 and use underscore-free, lo-carb, keywords.



sparc64: remove bogus comment

2019-12-31 Thread Miod Vallat
sparc_bus_protect() was copied from uvm_chgkprot() (which was a KGDB
support routine and is no longer present in uvm_glue.c).

The "cheezy hack" comment predates the pmap_extract() interface change
of 2001 (uvm_glue.c 1.15) and ought to have been removed back then.

Index: machdep.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/machdep.c,v
retrieving revision 1.191
diff -u -p -r1.191 machdep.c
--- machdep.c   1 Apr 2019 07:00:52 -   1.191
+++ machdep.c   31 Dec 2019 08:00:16 -
@@ -1712,15 +1712,10 @@ sparc_bus_protect(bus_space_tag_t t, bus
 
 eva = round_page((vaddr_t)addr + size);
 for (sva = trunc_page((vaddr_t)addr); sva < eva; sva += PAGE_SIZE) {
-/*
- * Extract physical address for the page.
- * We use a cheezy hack to differentiate physical
- * page 0 from an invalid mapping, not that it
- * really matters...
- */
 if (pmap_extract(pmap_kernel(), sva, ) == FALSE)
 panic("bus_space_protect(): invalid page");
-pmap_enter(pmap_kernel(), sva, pa | pm_flags, prot, prot | 
PMAP_WIRED);
+pmap_enter(pmap_kernel(), sva, pa | pm_flags, prot,
+   prot | PMAP_WIRED);
 }
pmap_update(pmap_kernel());
 



grep -R with no path

2019-12-02 Thread Miod Vallat
grep(1), when invoked with the -R option but no path, displays a
"recursive search of stdin" warning and acts as if -R had not been
specified.

GNU grep, in that case, will perform a recursive search in the current
directory, i.e. uses an implicit "." path if none is given.

This is IMO a much better behaviour. What about the following diff?

Index: grep.c
===
RCS file: /OpenBSD/src/usr.bin/grep/grep.c,v
retrieving revision 1.62
diff -u -p -r1.62 grep.c
--- grep.c  7 Oct 2019 20:04:00 -   1.62
+++ grep.c  2 Dec 2019 08:27:09 -
@@ -473,8 +473,12 @@ main(int argc, char *argv[])
++argv;
}
 
-   if (Rflag && argc == 0)
-   warnx("warning: recursive search of stdin");
+   if (Rflag && argc == 0) {
+   /* default to . if no path given */
+   static char *dot_argv[] = { ".", NULL };
+   argv = dot_argv;
+   argc = 1;
+   }
if (Eflag)
cflags |= REG_EXTENDED;
if (Fflag)



Re: syscall call-from verification

2019-11-28 Thread Miod Vallat


> For dynamic binaries, valid regions are ld.so's text segment, the signal
> trampoline, and libc.so's text segment... AND the main program's text.
>
> Unfortunately our current go build model hasn't followed solaris/macos
> approach yet of calling libc stubs, and uses the inappropriate "embed
> system calls directly" method, so for now we'll need to authorize the main
> program text as well.  A comment in exec_elf.c explains this.
>
> If go is adapted to call library-based system call stubs on OpenBSD as
> well, this problem will go away.  There may be other environments creating
> raw system calls. I guess we'll need to find them as time goes by, and
> hope in time we can repair those also.

Or you could use an ELF note to flag binaries allowed to issue syscalls
from their text section: only static binaries (including ld.so) and go
binaries would need them.



Re: ppppoe octeon kernel panic .6.6

2019-10-23 Thread Miod Vallat


> Try changing all the final 0 in sppp_auth_send() to 0UL and this ought
> to work. This function needs __attribute__((__sentinel__)) as well to
> prevent such mistakes from occurring again.

The sentinel attribute wants a pointer, not a zero size_t,
unfortunately.

Please try this diff.

Index: if_spppsubr.c
===
RCS file: /OpenBSD/src/sys/net/if_spppsubr.c,v
retrieving revision 1.179
diff -u -p -r1.179 if_spppsubr.c
--- if_spppsubr.c   24 Jun 2019 21:36:53 -  1.179
+++ if_spppsubr.c   23 Oct 2019 17:12:53 -
@@ -3340,7 +3340,7 @@ sppp_chap_input(struct sppp *sp, struct 
   sizeof digest, digest,
   strlen(sp->myauth.name),
   sp->myauth.name,
-  0);
+  0UL);
break;
 
case CHAP_SUCCESS:
@@ -3460,7 +3460,7 @@ sppp_chap_input(struct sppp *sp, struct 
/* action scn, tld */
sppp_auth_send(, sp, CHAP_FAILURE, h->ident,
   sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
-  0);
+  0UL);
chap.tld(sp);
break;
}
@@ -3469,7 +3469,7 @@ sppp_chap_input(struct sppp *sp, struct 
sp->state[IDX_CHAP] == STATE_OPENED)
sppp_auth_send(, sp, CHAP_SUCCESS, h->ident,
   sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
-  0);
+  0UL);
if (sp->state[IDX_CHAP] == STATE_REQ_SENT) {
sppp_cp_change_state(, sp, STATE_OPENED);
chap.tlu(sp);
@@ -3647,7 +3647,7 @@ sppp_chap_scr(struct sppp *sp)
   (size_t)AUTHCHALEN, sp->chap_challenge,
   strlen(sp->myauth.name),
   sp->myauth.name,
-  0);
+  0UL);
 }
 /*
  *--*
@@ -3726,7 +3726,7 @@ sppp_pap_input(struct sppp *sp, struct m
sppp_auth_send(, sp, PAP_NAK, h->ident,
   sizeof mlen, (const char *),
   sizeof(FAILMSG) - 1, (u_char *)FAILMSG,
-  0);
+  0UL);
pap.tld(sp);
break;
}
@@ -3737,7 +3737,7 @@ sppp_pap_input(struct sppp *sp, struct m
sppp_auth_send(, sp, PAP_ACK, h->ident,
   sizeof mlen, (const char *),
   sizeof(SUCCMSG) - 1, (u_char *)SUCCMSG,
-  0);
+  0UL);
}
if (sp->state[IDX_PAP] == STATE_REQ_SENT) {
sppp_cp_change_state(, sp, STATE_OPENED);
@@ -3952,7 +3952,7 @@ sppp_pap_scr(struct sppp *sp)
   (size_t)idlen, sp->myauth.name,
   sizeof pwdlen, (const char *),
   (size_t)pwdlen, sp->myauth.secret,
-  0);
+  0UL);
 }
 /*
  * Random miscellaneous functions.



Re: ppppoe octeon kernel panic .6.6

2019-10-23 Thread Miod Vallat


> The system has a trap 2, which I looked up as:
>
> #define T_TLB_LD_MISS   2   /* TLB miss on load or ifetch */
>
> what happens before this patch, I think, is that there is a varargs size_t 
> (which is size 8 in mips64), that gets promoted (I think) in varargs to int 
> (which would likely be size 4).  Then what happens is the char * that is 
> va_arg'ed after that is somehow corrupted on length 1, bcopy would trap #2 
> on this.

Try changing all the final 0 in sppp_auth_send() to 0UL and this ought
to work. This function needs __attribute__((__sentinel__)) as well to
prevent such mistakes from occurring again.



Re: minor INSTALL.loongson tweaks

2019-08-13 Thread Miod Vallat


> Is suspend-resume not working on the lemote anymore?

It works (or used to work) on the Yeeloong, not on the Gdium (different
battery controller chip).



minor INSTALL.loongson tweaks

2019-08-10 Thread Miod Vallat
Hello,

  I have noticed a few inaccuracies in the installation notes. The
following diff fixes them.

Index: hardware
===
RCS file: /OpenBSD/src/distrib/notes/loongson/hardware,v
retrieving revision 1.10
diff -u -p -r1.10 hardware
--- hardware27 Feb 2014 18:48:15 -  1.10
+++ hardware10 Aug 2019 16:43:12 -
@@ -21,5 +21,4 @@ The following machines are supported by 
  all onboard devices (keyboard, trackpad, display, SD card reader,
  USB ports, Ethernet adapter, wireless network adapter,
  battery information) are supported except for the audio controller;
- suspend/resume is not supported yet; keyboard actions involving
- the `Fn' key are not working either at the moment.
+ suspend/resume is not supported yet.
Index: install
===
RCS file: /OpenBSD/src/distrib/notes/loongson/install,v
retrieving revision 1.14
diff -u -p -r1.14 install
--- install 19 Mar 2014 01:59:48 -  1.14
+++ install 10 Aug 2019 16:43:12 -
@@ -35,9 +35,12 @@ dnl you can boot the kernel from an usb 
 dnl 
 dnlPMON> boot /dev/fs/fat@usb0:/bsd.rd
 
-Netbooting the installation kernel can be done as well:
+Netbooting the installation kernel can be done as well. First, check the name
+of the PMON device for the onboard interface using the ``devls'' command.
+This is likely to be either rtl0 (on Yeeloong) or rtk0 (on Fuloong). Then,
+assign it an address and fetch the installation kernel from a tftp server:
 
-PMON> ifaddr rtl0 
+PMON> ifaddr  
 PMON> boot -k tftp:///bsd.rd
 
 OpenBSDInstallPart2



missing splnet in network drivers

2019-07-03 Thread Miod Vallat
The recent mii_tick diff made me ponder whether the mii tick timeout
could be put in the mii_data struct rather than each driver softc (not
that a good idea, actually).

While looking at this, I noticed that two drivers may end up invoking
mii_tick() while not being at IPL_NET.

bnx: bnx_tick() can get invoked either from the interrupt handler, or
from a timeout.

sk: on some boards, sk_tick() gets invoked from timeout, but may end up
invoking sk_intr_bcom() which is intended to run at IPL_NET.

This diff has only been compile-tested, for lack of such hardware.

Index: if_bnx.c
===
RCS file: /OpenBSD/src/sys/dev/pci/if_bnx.c,v
retrieving revision 1.125
diff -u -p -r1.125 if_bnx.c
--- if_bnx.c10 Mar 2018 10:51:46 -  1.125
+++ if_bnx.c3 Jul 2019 06:40:47 -
@@ -5457,6 +5457,9 @@ bnx_tick(void *xsc)
struct ifnet*ifp = >arpcom.ac_if;
struct mii_data *mii = NULL;
u_int32_t   msg;
+   int s;
+
+   s = splnet();
 
/* Tell the firmware that the driver is still running. */
 #ifdef BNX_DEBUG
@@ -5489,7 +5492,7 @@ bnx_tick(void *xsc)
}
 
 bnx_tick_exit:
-   return;
+   splx(s);
 }
 
 //
Index: if_sk.c
===
RCS file: /OpenBSD/src/sys/dev/pci/if_sk.c,v
retrieving revision 1.189
diff -u -p -r1.189 if_sk.c
--- if_sk.c 4 Jun 2017 04:29:23 -   1.189
+++ if_sk.c 3 Jul 2019 06:40:47 -
@@ -1703,15 +1703,20 @@ sk_tick(void *xsc_if)
struct sk_if_softc *sc_if = xsc_if;
struct mii_data *mii = _if->sk_mii;
struct ifnet *ifp = _if->arpcom.ac_if;
-   int i;
+   int i, s;
 
DPRINTFN(2, ("sk_tick\n"));
 
-   if (!(ifp->if_flags & IFF_UP))
+   s = splnet();
+
+   if (!(ifp->if_flags & IFF_UP)) {
+   splx(s);
return;
+   }
 
if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
sk_intr_bcom(sc_if);
+   splx(s);
return;
}
 
@@ -1729,6 +1734,7 @@ sk_tick(void *xsc_if)
 
if (i != 3) {
timeout_add_sec(_if->sk_tick_ch, 1);
+   splx(s);
return;
}
 
@@ -1736,6 +1742,7 @@ sk_tick(void *xsc_if)
SK_XM_CLRBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
SK_XM_READ_2(sc_if, XM_ISR);
mii_tick(mii);
+   splx(s);
timeout_del(_if->sk_tick_ch);
 }
 



unused sparc64 extern

2019-06-29 Thread Miod Vallat
The following declaration has actually never been used, for `ver' is a
local in cpuattach() and locore does rdpr %ver every time it needs the
value.

Index: include/psl.h
===
RCS file: /OpenBSD/src/sys/arch/sparc64/include/psl.h,v
retrieving revision 1.34
diff -u -p -r1.34 psl.h
--- include/psl.h   20 Aug 2018 15:02:07 -  1.34
+++ include/psl.h   29 Jun 2019 10:35:40 -
@@ -227,8 +227,6 @@
 
 #if defined(_KERNEL) && !defined(_LOCORE)
 
-extern u_int64_t ver;  /* Copy of v9 version register.  We need to read this 
only once, in locore.s. */
-
 #ifdef DIAGNOSTIC
 /*
  * Although this function is implemented in MI code, it must be in this MD



missing trap.c code for m88k

2019-06-17 Thread Miod Vallat
Exception handling code on superH and m88k does not check for a valid
stack pointer, like other platforms do.

The following (mechanical) diff addresses the m88k case, and has been
tested to work on 88100 and 88110 processors.

Index: sys/arch/m88k/m88k/trap.c
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/trap.c,v
retrieving revision 1.107
diff -u -p -u -p -r1.107 trap.c
--- sys/arch/m88k/m88k/trap.c   8 Sep 2017 05:36:52 -   1.107
+++ sys/arch/m88k/m88k/trap.c   17 Jun 2019 17:54:48 -
@@ -239,6 +239,9 @@ m88100_trap(u_int type, struct trapframe
type += T_USER;
p->p_md.md_tf = frame;  /* for ptrace/signals */
refreshcreds(p);
+   if (!uvm_map_inentry(p, >p_spinentry, PROC_STACK(p), "sp",
+   uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial))
+   return;
}
fault_type = SI_NOINFO;
fault_code = 0;
@@ -679,6 +682,9 @@ m88110_trap(u_int type, struct trapframe
type += T_USER;
p->p_md.md_tf = frame;  /* for ptrace/signals */
refreshcreds(p);
+   if (!uvm_map_inentry(p, >p_spinentry, PROC_STACK(p), "sp",
+   uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial))
+   return;
}
 
if (sig != 0)



Re: free() sizes in zlib

2019-05-14 Thread Miod Vallat
> I have serious doubt whether the whole "plan" for using the sizes to
> change the malloc implementation is feasable.  The drm(4) code for
> example relies on emulation of Linux memory allocation APIs to keep
> the diffs small and jsg@ and myself sane.  Most of these APIs don't
> pass sizes in their "free" interfaces.

There's always the choice of keeping the existing implementation for
some types (such as M_DRM) and use a different implementation for other
types.

And then see how better the new implementation fares.

> If passing the sizes around in this bit of code has benefits for
> sanity checking purposes, I have no objection.  But if it is just
> there to silence the kernel printf and actually hurts updating the
> code in the future then I wouldn't bother.

I seriously doubt there is much coming from upstream zlib in the future.



free() sizes in zlib

2019-05-14 Thread Miod Vallat
This tries to keep diffability against upstream, hence a questionable
choice of the size type for zcfree() - but all sizes should fit in 32
bits anyway.

Since all zcfree routines used in the tree cope with NULL arguments
(including the various alloc.c used by the boot blocks), I have
simplified TRY_FREE to compensate for the growth.

Index: lib/libz/deflate.c
===
RCS file: /OpenBSD/src/sys/lib/libz/deflate.c,v
retrieving revision 1.3
diff -u -p -r1.3 deflate.c
--- lib/libz/deflate.c  14 Mar 2016 23:08:06 -  1.3
+++ lib/libz/deflate.c  14 May 2019 13:47:03 -
@@ -873,12 +873,12 @@ int ZEXPORT deflateEnd (strm)
 }
 
 /* Deallocate in reverse order of allocations: */
-TRY_FREE(strm, strm->state->pending_buf);
-TRY_FREE(strm, strm->state->head);
-TRY_FREE(strm, strm->state->prev);
-TRY_FREE(strm, strm->state->window);
+TRY_FREE(strm, strm->state->pending_buf, strm->state->pending_buf_size);
+TRY_FREE(strm, strm->state->head, strm->state->hash_size * sizeof(Pos));
+TRY_FREE(strm, strm->state->prev, strm->state->w_size * sizeof(Pos));
+TRY_FREE(strm, strm->state->window, strm->state->w_size * 2 * 
sizeof(Byte));
 
-ZFREE(strm, strm->state);
+ZFREE(strm, strm->state, sizeof(deflate_state));
 strm->state = Z_NULL;
 
 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
Index: lib/libz/infback.c
===
RCS file: /OpenBSD/src/sys/lib/libz/infback.c,v
retrieving revision 1.5
diff -u -p -r1.5 infback.c
--- lib/libz/infback.c  20 Jul 2005 15:56:45 -  1.5
+++ lib/libz/infback.c  14 May 2019 13:47:03 -
@@ -630,7 +630,7 @@ z_streamp strm;
 {
 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
 return Z_STREAM_ERROR;
-ZFREE(strm, strm->state);
+ZFREE(strm, strm->state, sizeof(struct inflate_state));
 strm->state = Z_NULL;
 Tracev((stderr, "inflate: end\n"));
 return Z_OK;
Index: lib/libz/inflate.c
===
RCS file: /OpenBSD/src/sys/lib/libz/inflate.c,v
retrieving revision 1.14
diff -u -p -r1.14 inflate.c
--- lib/libz/inflate.c  23 Mar 2016 19:39:48 -  1.14
+++ lib/libz/inflate.c  14 May 2019 13:47:03 -
@@ -176,7 +176,7 @@ int stream_size;
 #endif
 }
 if (windowBits < 8 || windowBits > 15) {
-ZFREE(strm, state);
+ZFREE(strm, state, sizeof(struct inflate_state));
 strm->state = Z_NULL;
 return Z_STREAM_ERROR;
 }
@@ -1238,8 +1238,8 @@ z_streamp strm;
 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
 return Z_STREAM_ERROR;
 state = (struct inflate_state FAR *)strm->state;
-if (state->window != Z_NULL) ZFREE(strm, state->window);
-ZFREE(strm, strm->state);
+if (state->window != Z_NULL) ZFREE(strm, state->window, 1U << 
state->wbits);
+ZFREE(strm, strm->state, sizeof(struct inflate_state));
 strm->state = Z_NULL;
 Tracev((stderr, "inflate: end\n"));
 return Z_OK;
@@ -1423,7 +1423,7 @@ z_streamp source;
 window = (unsigned char FAR *)
  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
 if (window == Z_NULL) {
-ZFREE(source, copy);
+ZFREE(source, copy, sizeof(struct inflate_state));
 return Z_MEM_ERROR;
 }
 }
Index: lib/libz/zlib.h
===
RCS file: /OpenBSD/src/sys/lib/libz/zlib.h,v
retrieving revision 1.11
diff -u -p -r1.11 zlib.h
--- lib/libz/zlib.h 12 May 2019 15:56:56 -  1.11
+++ lib/libz/zlib.h 14 May 2019 13:47:04 -
@@ -76,7 +76,7 @@ extern "C" {
 */
 
 typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
+typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt size));
 
 struct internal_state;
 
Index: lib/libz/zopenbsd.c
===
RCS file: /OpenBSD/src/sys/lib/libz/zopenbsd.c,v
retrieving revision 1.6
diff -u -p -r1.6 zopenbsd.c
--- lib/libz/zopenbsd.c 14 Mar 2015 03:38:51 -  1.6
+++ lib/libz/zopenbsd.c 14 May 2019 13:47:04 -
@@ -5,17 +5,13 @@
  * Space allocation and freeing routines for use by zlib routines.
  */
 void *
-zcalloc(notused, items, size)
-void *notused;
-u_int items, size;
+zcalloc(void *notused, u_int items, u_int size)
 {
 return mallocarray(items, size, M_DEVBUF, M_NOWAIT);
 }
 
 void
-zcfree(notused, ptr)
-void *notused;
-void *ptr;
+zcfree(void *notused, void *ptr, u_int size)
 {
-free(ptr, M_DEVBUF, 0);
+free(ptr, M_DEVBUF, size);
 }
Index: lib/libz/zutil.h
===
RCS file: /OpenBSD/src/sys/lib/libz/zutil.h,v
retrieving revision 1.18
diff 

free() sizes for ahc(4)

2019-05-14 Thread Miod Vallat
Note ahc_set_name() gets invoked with the dv_xname field of a struct
device, so it's not a good idea to free anything, should it be invoked
more than once.

Tested on:
ahc0 at pci0 dev 1 function 0 "Adaptec AIC-7880" rev 0x00: irq 8
ahc0: Host Adapter Bios disabled.  Using default SCSI device parameters
scsibus0 at ahc0: 16 targets, initiator 7
sd0 at scsibus0 targ 1 lun 0:  SCSI3 0/direct 
fixed serial.SGI_IBM_DNES-318350Y_AK0T7943
sd0: 17364MB, 512 bytes/sector, 35563040 sectors
cd0 at scsibus0 targ 4 lun 0:  SCSI2 5/cdrom 
removable
ahc1 at pci0 dev 2 function 0 "Adaptec AIC-7880" rev 0x00: irq 9
ahc1: Host Adapter Bios disabled.  Using default SCSI device parameters
scsibus1 at ahc1: 16 targets, initiator 7

Index: dev/ic/aic7xxx.c
===
RCS file: /OpenBSD/src/sys/dev/ic/aic7xxx.c,v
retrieving revision 1.93
diff -u -p -u -p -r1.93 aic7xxx.c
--- dev/ic/aic7xxx.c12 Dec 2017 12:33:36 -  1.93
+++ dev/ic/aic7xxx.c14 May 2019 10:28:10 -
@@ -1688,7 +1688,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u
scsi_id += 8;
tstate = ahc->enabled_targets[scsi_id];
if (tstate != NULL)
-   free(tstate, M_DEVBUF, 0);
+   free(tstate, M_DEVBUF, sizeof(*tstate));
ahc->enabled_targets[scsi_id] = NULL;
 }
 #endif
@@ -3957,8 +3957,6 @@ ahc_set_unit(struct ahc_softc *ahc, int 
 void
 ahc_set_name(struct ahc_softc *ahc, char *name)
 {
-   if (ahc->name != NULL)
-   free(ahc->name, M_DEVBUF, 0);
ahc->name = name;
 }
 
@@ -3997,21 +3995,21 @@ ahc_free(struct ahc_softc *ahc)
lstate = tstate->enabled_luns[j];
if (lstate != NULL) {
  /*xpt_free_path(lstate->path);*/
-   free(lstate, M_DEVBUF, 0);
+   free(lstate, M_DEVBUF, sizeof(*lstate));
}
}
 #endif
-   free(tstate, M_DEVBUF, 0);
+   free(tstate, M_DEVBUF, sizeof(*tstate));
}
}
 #ifdef AHC_TARGET_MODE
if (ahc->black_hole != NULL) {
  /*xpt_free_path(ahc->black_hole->path);*/
-   free(ahc->black_hole, M_DEVBUF, 0);
+   free(ahc->black_hole, M_DEVBUF, sizeof(*ahc->black_hole));
}
 #endif
if (ahc->seep_config != NULL)
-   free(ahc->seep_config, M_DEVBUF, 0);
+   free(ahc->seep_config, M_DEVBUF, sizeof(*ahc->seep_config));
return;
 }
 
@@ -4329,7 +4327,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
ahc_freedmamem(ahc->parent_dmat, PAGE_SIZE,
sg_map->sg_dmamap, (caddr_t)sg_map->sg_vaddr,
_map->sg_dmasegs, sg_map->sg_nseg);
-   free(sg_map, M_DEVBUF, 0);
+   free(sg_map, M_DEVBUF, sizeof(*sg_map));
}
}
/*FALLTHROUGH*/
@@ -4350,8 +4348,10 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
case 0:
break;
}
-   if (scb_data->scbarray != NULL)
-   free(scb_data->scbarray, M_DEVBUF, 0);
+   if (scb_data->scbarray != NULL) {
+   free(scb_data->scbarray, M_DEVBUF,
+   AHC_SCB_MAX_ALLOC * sizeof(struct scb));
+   }
 }
 
 void
@@ -4383,7 +4383,7 @@ ahc_alloc_scbs(struct ahc_softc *ahc)
 (caddr_t *)_map->sg_vaddr, _map->sg_physaddr,
 _map->sg_dmasegs, _map->sg_nseg, 
ahc_name(ahc),
 "SG space") < 0) {
-   free(sg_map, M_DEVBUF, 0);
+   free(sg_map, M_DEVBUF, sizeof(*sg_map));
return;
}
 
@@ -6859,7 +6859,7 @@ ahc_handle_en_lun(struct ahc_softc *ahc,
 xpt_path_target_id(ccb->ccb_h.path),
 xpt_path_lun_id(ccb->ccb_h.path));
if (status != CAM_REQ_CMP) {
-   free(lstate, M_DEVBUF, 0);
+   free(lstate, M_DEVBUF, sizeof(*lstate));
xpt_print_path(ccb->ccb_h.path);
printf("Couldn't allocate path\n");
ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
@@ -6980,7 +6980,7 @@ ahc_handle_en_lun(struct ahc_softc *ahc,
xpt_print_path(ccb->ccb_h.path);
printf("Target mode disabled\n");
xpt_free_path(lstate->path);
-   free(lstate, M_DEVBUF, 0);
+   free(lstate, M_DEVBUF, sizeof(*lstate));
 
ahc_pause(ahc);
/* Can we clean up the target too? */
Index: dev/ic/aic7xxx_seeprom.c
===
RCS file: /OpenBSD/src/sys/dev/ic/aic7xxx_seeprom.c,v
retrieving revision 1.7
diff 

free() sizes in sys/arch/alpha

2019-05-13 Thread Miod Vallat
Index: dev/sgmap_common.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/dev/sgmap_common.c,v
retrieving revision 1.14
diff -u -p -r1.14 sgmap_common.c
--- dev/sgmap_common.c  9 Dec 2014 06:58:28 -   1.14
+++ dev/sgmap_common.c  13 May 2019 16:39:50 -
@@ -150,6 +150,8 @@ alpha_sgmap_dmamap_setup(map, nsegments,
 {
map->_dm_cookie = mallocarray(nsegments, sizeof(struct extent_region),
M_DEVBUF, (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
+   if (map->_dm_cookie != NULL)
+   map->_dm_cookiesize = nsegments * sizeof(struct extent_region);
return (map->_dm_cookie == NULL);
 }
 
@@ -187,7 +189,7 @@ void
 alpha_sgmap_dmamap_teardown(map)
bus_dmamap_t map;
 {
-   free(map->_dm_cookie, M_DEVBUF, 0);
+   free(map->_dm_cookie, M_DEVBUF, map->_dm_cookiesize);
 }
 
 void
Index: include/bus.h
===
RCS file: /OpenBSD/src/sys/arch/alpha/include/bus.h,v
retrieving revision 1.31
diff -u -p -r1.31 bus.h
--- include/bus.h   8 May 2017 00:27:45 -   1.31
+++ include/bus.h   13 May 2019 16:39:50 -
@@ -648,6 +648,7 @@ struct alpha_bus_dmamap {
 * Private cookie to be used by the DMA back-end.
 */
void*_dm_cookie;
+   size_t  _dm_cookiesize; /* size allocated for _dm_cookie */
 
/*
 * The DMA window that we ended up being mapped in.
Index: isa/isadma_bounce.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/isa/isadma_bounce.c,v
retrieving revision 1.12
diff -u -p -r1.12 isadma_bounce.c
--- isa/isadma_bounce.c 27 Sep 2015 10:12:09 -  1.12
+++ isa/isadma_bounce.c 13 May 2019 16:39:50 -
@@ -115,6 +115,7 @@ isadma_bounce_dmamap_create(bus_dma_tag_
 
map = *dmamp;
map->_dm_cookie = NULL;
+   map->_dm_cookiesize = 0;
 
cookiesize = sizeof(*cookie);
 
@@ -156,6 +157,7 @@ isadma_bounce_dmamap_create(bus_dma_tag_
cookie = (struct isadma_bounce_cookie *)cookiestore;
cookie->id_flags = cookieflags;
map->_dm_cookie = cookie;
+   map->_dm_cookiesize = cookiesize;
 
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
/*
@@ -190,7 +192,7 @@ isadma_bounce_dmamap_destroy(bus_dma_tag
if (cookie->id_flags & ID_HAS_BOUNCE)
isadma_bounce_free_bouncebuf(t, map);
 
-   free(cookie, M_DEVBUF, 0);
+   free(cookie, M_DEVBUF, map->_dm_cookiesize);
_bus_dmamap_destroy(t, map);
 }
 



Re: Removing PF

2019-04-01 Thread Miod Vallat


> Will the bpf JIT changes be done in time for 6.6?  I have no doubt
> that "pfctl -p /dev/bfp" can be made to work in time but for a truly
> performant firewall we will need bpf JIT.

I wrote a vax BPF jit as a simple exercize some time ago, so all you
really need now is to implement vax-to-${ARCH} jit on an MD basis. This
should be very easy to do as long as BPF does not get extended to use
floating-point values.



Re: replacing timeout_add() with timeout_add_msec()

2019-01-21 Thread Miod Vallat
> The intent was to wait a 30th of a second.  In practice it has always
> fired 30ms hence.  It's a magic number, so I'd just call it 30ms.
> miod might have an opinion on whether those extra milliseconds would
> be useful in the event that sparc64 is ever able to timeout with
> millisecond or better precision on OpenBSD.

That's not sparc64-specific. There is the same 1/30th logic in
sys/dev/isa/fd.c which is used on i386 and amd64, you know.



Re: minor ttyflags(8) diff

2019-01-13 Thread Miod Vallat
> > Opening a pseudo-tty (/dev/tty[p-zP-T][0-9a-zA-Z]) causes the kernel to
> > allocate a struct tty for it, as well as ring buffers for tty data. This
> > memory will not get released if the pseudo-tty is closed, for it may be
> > opened again in the future.
> 
> The change seems reasonable to me.
> 
> Years ago weren't we more lazy about allocating the tty buffer data?

I have had a look at the history, but not beyond ~15 years. ttymalloc()
will always cause the ring buffers to be allocated, and only removable
devices such as ucom will release tty resources (upon detach).



minor ttyflags(8) diff

2019-01-13 Thread Miod Vallat
Opening a pseudo-tty (/dev/tty[p-zP-T][0-9a-zA-Z]) causes the kernel to
allocate a struct tty for it, as well as ring buffers for tty data. This
memory will not get released if the pseudo-tty is closed, for it may be
opened again in the future.

On pseudo-ttys, the largest possible ring buffer size is used, which
causes 26KB to be allocated (three 8KB rings plus two 1KB quote
buffers).

On a default OpenBSD install, only /dev/tty[pqr][0-9a-zA-Z] are created.
That's 186 ttys. If they were to be opened, this would cause 4836KB of
kernel memory to be allocated.

And that's exactly what ttyflags(8) does: it will happily open every tty
listed in /etc/ttys, and issue a TIOCSFLAGS ioctl to it, then close it.
But pseudo-ttys ignore TIOCSFLAGS completely, so there is no point for
ttyflags to open them, to begin with.

On memory challenged systems, this is a significant waste of memory. I
am therefore proposing the following diff, which will cause ttyflags -a
to skip pseudo-ttys.

Without this diff, after a multiuser boot:
kern.malloc.kmemstat.ttys=(inuse = 1128, calls = 1128, memuse = 4982K, 
limblocks = 0, mapblocks = 0, maxused = 4982K, limit = 78644K, spare = 0, sizes 
= (512,1024,8192))

With this diff:
kern.malloc.kmemstat.ttys=(inuse = 18, calls = 18, memuse = 80K, limblocks = 0, 
mapblocks = 0, maxused = 80K, limit = 78644K, spare = 0, sizes = 
(512,1024,8192))


Index: ttyflags.c
===
RCS file: /OpenBSD/src/sbin/ttyflags/ttyflags.c,v
retrieving revision 1.13
diff -u -p -r1.13 ttyflags.c
--- ttyflags.c  4 Dec 2012 02:27:00 -   1.13
+++ ttyflags.c  13 Jan 2019 16:14:59 -
@@ -112,9 +112,13 @@ all(int print)
int rval;
 
rval = 0;
-   for (tep = getttyent(); tep != NULL; tep = getttyent())
+   for (tep = getttyent(); tep != NULL; tep = getttyent()) {
+   /* pseudo-tty ignore TIOCSFLAGS, so don't bother */
+   if (strcmp(tep->ty_type, "network") == 0)
+   continue;
if (ttyflags(tep, print))
rval = 1;
+   }
return (rval);
 }
 



SGI O2 mec(4) cold boot issue (and workaround)

2018-12-08 Thread Miod Vallat
I have noticed, for a while, that my O2 systems were horribly slow
during installs or upgrades, when fetching sets from the network (28
*minutes* to fetch base64.tgz).

At first, I thought this was a bsd.rd specific bug, but couldn't find
anything obvious. After gathering enough data, I found out that the
problem only occurs on a cold boot. After a reboot, the network
performance is as good as it can be. That would explain why I would only
notice it during upgrades.

I also noticed that, on a warm boot, the dmesg would show:

mec0 at macebus0 base 0x0028 irq 3: MAC-110 rev 1, address 08:00:69:0e:bf:a1
nsphy0 at mec0 phy 8: DP83840 10/100 PHY, rev. 1

but on cold boots, it would show:

mec0 at macebus0 base 0x0028 irq 3: MAC-110 rev 1, address 08:00:69:0e:bf:a1
nsphy0 at mec0 phy 10: DP83840 10/100 PHY, rev. 1

Note that, in these cases, the phy seems to attach to a different
address. In these cases, after booting, "ifconfig mec0" would show:

mec0: flags=8843 mtu 1500
lladdr 08:00:69:0e:bf:a1
llprio 3
media: Ethernet autoselect
status: active
inet 10.0.1.193 netmask 0xff00 broadcast 10.255.255.255

while one would expect the "media" line to be similar to:

media: Ethernet autoselect (100baseTX full-duplex)

Investigating further, it seems that, after a cold boot, the MII bus
takes some time to initialize; the phy does not answer to address 8 but
to a larger address (10 or 11), then, after being reset, to its correct
address of 8.

So the kernel would discover the phy at a wrong address, attach it, and
after it gets reset, reading from the phy at the wrong address would
return either all bits clear or all bits set, confusing the link speed
logic without any way to recover.

What I tried but did not work:
- invoking mii_attach() twice in the mec driver. This would attach nsphy
  twice, once at the wrong address, then once at the correct address,
  but the first (wrong) attachment would be preferred.
- adding a one second delay between the Ethernet interface reset and
  mii_attach(). This would work most of the time, but not always.

What I tried and works:
- the first time the interface is reset, the mii bus is walked and all
  phys found on it are reset. Thus, by the time mii_attach() runs and
  walks the bus again, the phy will answer at the right address.

The diff below implements this (last chunk of if_mec.c), and also cleans
the mii read/write routines a bit (all the other chunks).

Tested on three different R5K family O2 systems, which have all been
exposing that problem on cold boot.

Index: dev/if_mec.c
===
RCS file: /OpenBSD/src/sys/arch/sgi/dev/if_mec.c,v
retrieving revision 1.37
diff -u -p -r1.37 if_mec.c
--- dev/if_mec.c22 Jan 2017 10:17:37 -  1.37
+++ dev/if_mec.c8 Dec 2018 15:00:04 -
@@ -264,7 +264,6 @@ struct mec_softc {
bus_dma_tag_t sc_dmat;  /* bus_dma tag. */
 
struct mii_data sc_mii; /* MII/media information. */
-   int sc_phyaddr; /* MII address. */
struct timeout sc_tick_ch;  /* Tick timeout. */
 
bus_dmamap_t sc_cddmamap;   /* bus_dma map for control data. */
@@ -329,7 +328,7 @@ voidmec_start(struct ifnet *);
 void   mec_watchdog(struct ifnet *);
 void   mec_tick(void *);
 intmec_ioctl(struct ifnet *, u_long, caddr_t);
-void   mec_reset(struct mec_softc *);
+void   mec_reset(struct mec_softc *, int);
 void   mec_iff(struct mec_softc *);
 intmec_intr(void *arg);
 void   mec_stop(struct ifnet *);
@@ -422,7 +421,7 @@ mec_attach(struct device *parent, struct
enaddr_aton(bios_enaddr, sc->sc_ac.ac_enaddr);
 
/* Reset device. */
-   mec_reset(sc);
+   mec_reset(sc, 1);
 
command = bus_space_read_8(sc->sc_st, sc->sc_sh, MEC_MAC_CONTROL);
 
@@ -451,7 +450,6 @@ mec_attach(struct device *parent, struct
ifmedia_set(>sc_mii.mii_media, IFM_ETHER | IFM_MANUAL);
} else {
ifmedia_set(>sc_mii.mii_media, IFM_ETHER | IFM_AUTO);
-   sc->sc_phyaddr = child->mii_phy;
}
 
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
@@ -499,21 +497,19 @@ mec_mii_readreg(struct device *self, int
struct mec_softc *sc = (void *)self;
bus_space_tag_t st = sc->sc_st;
bus_space_handle_t sh = sc->sc_sh;
-   uint32_t val;
+   uint64_t val;
int i;
 
if (mec_mii_wait(sc) != 0)
return 0;
 
-   bus_space_write_4(st, sh, MEC_PHY_ADDRESS,
+   bus_space_write_8(st, sh, MEC_PHY_ADDRESS,
(phy << MEC_PHY_ADDR_DEVSHIFT) | (reg & MEC_PHY_ADDR_REGISTER));
bus_space_write_8(st, sh, MEC_PHY_READ_INITIATE, 1);
-   delay(25);
 
for (i = 0; i < 20; i++) {
-   delay(30);
-
-   val = bus_space_read_4(st, sh, MEC_PHY_DATA);
+   delay(25);
+   val = 

hppa minor cleanup

2018-11-15 Thread Miod Vallat
In the never ending story of "encoding of diag instructions is hard,
let's go shopping" (as shown by at least rev 1.65, 1.66 and 1.189 of
hppa locore.S), the following diff attempts to clean and fix things for
good:
  - macros get a cpu-family suffix, since encoding differ accross
processor families.
  - source of the information, when known, is mentioned.
  - two unused routines get removed.

This does not change anything in the object code, as the remaining wrong
encodings were only used in pbtlb_l which has not been used for ages.

Index: hppa/locore.S
===
RCS file: /OpenBSD/src/sys/arch/hppa/hppa/locore.S,v
retrieving revision 1.199
diff -u -p -r1.199 locore.S
--- hppa/locore.S   16 Jul 2017 22:47:37 -  1.199
+++ hppa/locore.S   15 Nov 2018 20:25:21 -
@@ -76,16 +76,23 @@
 #include "assym.h"
 
 /*
- * hv-specific instructions
+ * hw-specific instructions
  */
-#defineDR_PAGE0.word   0x14001200
-#defineDR_PAGE1.word   0x14001240
-#defineMTCPU_T(x,t).word   0x14001600 | ((t) << 21) | ((x) << 16)
-#defineMFCPU_T(r,x).word   0x14001a00 | ((r) << 21) | ((x) << 16)
-#defineMTCPU_C(x,t).word   0x14000240 | ((t) << 21) | ((x) << 16)
-#defineMFCPU_C(r,x).word   0x14000600 | ((r) << 21) | ((x) << 16)
-#defineMFCPU_U(r,x).word   0x140008a0 | ((r) << 21) | ((x))
-#defineMTCPU_U(x,r).word   0x14001840 | ((r) << 21) | ((x) << 16)
+
+/* source: mklinux cache.s */
+#defineMFCPU_C_PCXST(r,x)  .word   0x14001a00 | ((r) << 21) | ((x) 
<< 16)
+#defineMTCPU_PCXST(x,r).word   0x14001600 | ((r) << 21) | ((x) 
<< 16)
+
+/* source: PCXL and PCXL2 ERS */
+/* Use MFCPU_C for DR0-8; MFCPU_T for DR25,27,28,29 */
+#defineMFCPU_C_PCXL(r,x)   .word   0x14000600 | ((r) << 21) | ((x) 
<< 16)
+#defineMFCPU_T_PCXL(r,x)   .word   0x14001800 | ((r) << 21) | ((x))
+#defineMTCPU_PCXL(x,r) .word   0x14000240 | ((r) << 21) | ((x) 
<< 16)
+#defineDR_PAGE0_PCXL   .word   0x14000e00
+#defineDR_PAGE1_PCXL   .word   0x14000e40
+
+#defineMFCPU_PCXU(r,x) .word   0x140008a0 | ((r) << 21) | ((x))
+#defineMTCPU_PCXU(x,r) .word   0x14001840 | ((r) << 21) | ((x) 
<< 16)
 
.import $global$, data
.import pdc, data
@@ -1646,8 +1653,8 @@ EXIT(TLABEL(all))
  */
 LEAF_ENTRY(desidhash_s)
sync
-   MFCPU_T(DR_CPUCFG,22)   /* t1 */
-   MFCPU_T(DR_CPUCFG,22)
+   MFCPU_C_PCXST(DR_CPUCFG,22) /* t1 */
+   MFCPU_C_PCXST(DR_CPUCFG,22)
nop
nop
depi0, DR0_PCXS_DHE, 3, t1  /* 3: DR0_PCXS_DOMAIN|DR0_PCXS_IHE */
@@ -1656,8 +1663,8 @@ LEAF_ENTRY(desidhash_s)
depi0, DR0_PCXS_DHPMC, 1, t1
depi0, DR0_PCXS_ILPMC, 1, t1
sync
-   MTCPU_T(22,DR_CPUCFG)
-   MTCPU_T(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
nop
nop
bv  0(rp)
@@ -1671,8 +1678,8 @@ EXIT(desidhash_s)
  */
 LEAF_ENTRY(desidhash_t)
sync
-   MFCPU_T(DR_CPUCFG,22)   /* t1 */
-   MFCPU_T(DR_CPUCFG,22)
+   MFCPU_C_PCXST(DR_CPUCFG,22) /* t1 */
+   MFCPU_C_PCXST(DR_CPUCFG,22)
nop
nop
depi0, DR0_PCXT_IHE, 1, t1
@@ -1681,8 +1688,8 @@ LEAF_ENTRY(desidhash_t)
depi0, DR0_PCXT_DHPMC, 1, t1
depi0, DR0_PCXT_ILPMC, 1, t1
sync
-   MTCPU_T(22,DR_CPUCFG)
-   MTCPU_T(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
+   MTCPU_PCXST(22,DR_CPUCFG)
nop
nop
bv  0(rp)
@@ -1697,7 +1704,7 @@ LEAF_ENTRY(eaio_l2)
ldilL%eaio_l2_mask, t2
ldw R%eaio_l2_mask(t2), t1
or  t1, arg0, t1
-   MTCPU_C(22, DR0_PCXL2_ACCEL_IO)
+   MTCPU_PCXL(22, DR0_PCXL2_ACCEL_IO)
nop
nop
bv  0(rp)
@@ -1719,54 +1726,11 @@ LEAF_ENTRY(ibtlb_l)
mtsmt4
 EXIT(ibtlb_l)
 
-/* hpti_l(addr,size) */
-LEAF_ENTRY(hpti_l)
-   ldo -1(arg1), arg1
-   depi0, 31, 12, arg1
-   ldi 0x1c0, t1   /* cache size assumed 128k XXX */
-   or  arg0, t1, arg0
-   sync
-   MTCPU_C(26,DR0_PCXL2_HTLB_ADDR)
-   MTCPU_C(25,DR0_PCXL2_HTLB_CFG)
-   nop
-   nop
-   bv,nr0(rp)
-   nop
-EXIT(hpti_l)
-
-/*
- * int
- * pbtlb_l(int i)
- */
-LEAF_ENTRY(pbtlb_l)
-   ; DR_PAGE0
-   rsm (PSL_R|PSL_I), t4
-   nop ! nop ! nop ! nop
-   ldilL%0xc041, t1
-   ldo R%0xc041(t1), t1
-   dep arg0, 30, 3, t1
-   sync
-   MTCPU_T(22,DR_DTLB) /* t1 */
-   nop
-   nop
-   mtspr0, sr1
-   idtlba  r0,(sr1,r0)
-   idtlbp  r0,(sr1,r0)
-   zdepi   -1, 18, 1, t1
-   nop
-   sync
-   MTCPU_T(22,DR_DTLB)
-   nop
-   nop
-   bv  0(rp)
-   mtsmt4

Remove debug options in hppa GENERIC

2018-11-03 Thread Miod Vallat
The hppa GENERIC kernel contains various debug options for pcmcia and
cardbus code. None of the other platforms enables these options in
GENERIC.

Index: sys/arch/hppa/conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.177
diff -u -p -u -p -r1.177 GENERIC
--- sys/arch/hppa/conf/GENERIC  22 Aug 2018 15:38:46 -  1.177
+++ sys/arch/hppa/conf/GENERIC  3 Nov 2018 13:54:34 -
@@ -78,9 +78,8 @@ lpt0  at ssio?
 # CardBus bus support
 cbb*   at pci?
 cardslot*  at cbb?
-option CARDBUS_DEBUG,CARDSLOT_DEBUG,CARDBUS_MAP_DEBUG
 cardbus*   at cardslot?
-option PCMCIADEBUG,PCMCIAVERBOSE
+option PCMCIAVERBOSE
 pcmcia*at cardslot?
 
 # PCI USB Controllers



Re: re-enable -Wshadow for openssl(1)?

2018-08-23 Thread Miod Vallat


> The -Wshadow warning was briefly enabled, but it turned out to break vax
> builds with gcc3. Among other things, this warning helps catching stupid
> mistakes in refactoring early, so I was wondering whether we could
> re-enable it. The commit that disabled it also mentions gcc3, so I'm
> unsure whether luna88k would be affected by this.

gcc3 will warn like this:

  In file included from /usr/src/usr.bin/openssl/apps.h:117,
   from /usr/src/usr.bin/openssl/apps.c:138:
  /usr/include/openssl/bio.h:342: warning: declaration of `write' shadows a 
global declaration
  /usr/include/unistd.h:374: warning: shadowed declaration is here

This is caused by the BIO_meth_*() prototypes using formal parameters
nawed `read', `puts', etc.

Alternatively, you may choose to enable -Wshadow only if building with a
non-gcc3 toolchain.



[sparc64] dead code in emul.c

2018-08-07 Thread Miod Vallat
emul.c r1.19 removed a bunch of code, but not enough, and left dead code
around.

Index: emul.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/emul.c,v
retrieving revision 1.23
diff -u -p -r1.23 emul.c
--- emul.c  16 Nov 2014 12:30:59 -  1.23
+++ emul.c  6 Aug 2018 20:11:00 -
@@ -49,13 +49,9 @@
 
 #define GPR(tf, i) ((int32_t *)(u_long)>tf_global)[i]
 #define IPR(tf, i) ((int32_t *)(u_long)tf->tf_out[6])[i - 16]
-#define FPR(p, i)  ((int32_t) p->p_md.md_fpstate->fs_regs[i])
-#define FPRSET(p, i, v)p->p_md.md_fpstate->fs_regs[i] = (v)
 
 static __inline int readgpreg(struct trapframe64 *, int, void *);
-static __inline int readfpreg(struct proc *, int, void *);
 static __inline int writegpreg(struct trapframe64 *, int, const void *);
-static __inline int writefpreg(struct proc *, int, const void *);
 static __inline int decodeaddr(struct trapframe64 *, union instr *, void *);
 static int muldiv(struct trapframe64 *, union instr *, int32_t *, int32_t *,
 int32_t *);
@@ -81,7 +77,6 @@ readgpreg(tf, i, val)
return error;
 }
 
-   
 static __inline int
 writegpreg(tf, i, val)
struct trapframe64 *tf;
@@ -99,28 +94,6 @@ writegpreg(tf, i, val)
error = copyout((caddr_t) val, (tf, i), sizeof(int32_t));
 
return error;
-}
-   
-
-static __inline int
-readfpreg(p, i, val)
-   struct proc *p;
-   int i;
-   void *val;
-{
-   *(int32_t *) val = FPR(p, i);
-   return 0;
-}
-
-   
-static __inline int
-writefpreg(p, i, val)
-   struct proc *p;
-   int i;
-   const void *val;
-{
-   FPRSET(p, i, *(const int32_t *) val);
-   return 0;
 }
 
 static __inline int



Re: reduce hppa interrupt guts awfulness

2018-05-03 Thread Miod Vallat
> Regarding your diff.  The approach seems reasonable to me.  The magic
> number in the gscbus.c doesn't fill me with joy.
> 
> > +   r[4] = cpu_gethpa(0) | (31 - irqbit);   /* iar */
> 
> I realise you're following existing practice, but maybe you could you
> add a gscbus_reg struct similar to what was used in the asp/lasi/wax
> code and use that?

I agree this wouldn't hurt, but then, locore uses hardcoded numbers
because these offsets don't end up in genassym.cf.

Oh well, some partial cleanup can't hurt.

New diff - also, because the interrupt assignments at gsc are actually
local to gsc interrupt controllers, there is no need to reverse the
order of cpu_intr_findirq(). The "irq" mention in dmesg is a bit
misleading, but fixing that would require the print function to be
passed to pdc_scanbus() and it's a bit out of scope of these changes.

Index: conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.175
diff -u -p -r1.175 GENERIC
--- conf/GENERIC14 Feb 2018 23:51:49 -  1.175
+++ conf/GENERIC3 May 2018 17:08:26 -
@@ -46,21 +46,19 @@ uturn0  at mainbus0 # U2/UTurn Runway IO
 uturn1 at mainbus0
 astro* at mainbus0 # Astro memory & I/O controller
 
-lasi0  at mainbus0 offset 0x10 irq 28  # LASI host adapter
-lasi0  at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, J2[01]0
-lasi0  at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
-lasi0  at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
-lasi1  at mainbus0 offset 0x50 irq 27  # 712 GIO card
-asp*   at mainbus0 irq 28  # this one comes w/ Viper and LEDs
-wax*   at mainbus0 irq 24  # Wax may host EISA as well
-wax*   at phantomas0 irq 24# Wax on [AB]*
-wax*   at uturn? irq 24# Wax on C*
+lasi0  at mainbus0 offset 0x10 # LASI host adapter
+lasi0  at mainbus0 offset 0xfd0# LASI on C1[01]0, J2[01]0
+lasi0  at phantomas0 offset 0xfd0  # LASI on [AB]*
+lasi0  at uturn? offset 0xfd0  # LASI on [CJ]*
+lasi1  at mainbus0 offset 0x50 # 712 GIO card
+asp*   at mainbus0 # this one comes w/ Viper and LEDs
+wax*   at mainbus0 # Wax may host EISA as well
+wax*   at phantomas0   # Wax on [AB]*
+wax*   at uturn?   # Wax on C*
 mongoose* at mainbus0 irq 17   # EISA Bus Adapter (i82350 or TI???)
 #vmeb* at mainbus0 irq ?   # VME bus adapter
-dino0  at phantomas? irq 26# PCI bus bridge on [AB]*
-dino1  at phantomas? irq 25
-dino0  at uturn0 irq 26# PCI bus bridge on [CJ]*
-dino1  at uturn1 irq 25
+dino*  at phantomas?   # PCI bus bridge on [AB]*
+dino*  at uturn?   # PCI bus bridge on [CJ]*
 pci*   at dino?
 option PCIVERBOSE
 #pckbc0at dino? irq 9
@@ -176,12 +174,9 @@ onewire* at uow?
 udl*   at uhub?# DisplayLink USB displays
 wsdisplay* at udl?
 
-sti0   at mainbus0 irq 11  # [H]CRX-{8,24,48}[Z] graphics
-sti0   at phantomas0 irq 11# builtin graphics on BC*
-sti0   at uturn? irq 11
-sti1   at mainbus0 irq 12
-sti1   at phantomas0 irq 12
-sti1   at uturn? irq 12
+sti*   at mainbus0 # [H]CRX-{8,24,48}[Z] graphics
+sti*   at phantomas0   # builtin graphics on BC*
+sti*   at uturn?
 sti*   at pci? # EG-PCI, FX*
 
 # internal i/o space
Index: conf/RAMDISK
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/RAMDISK,v
retrieving revision 1.109
diff -u -p -r1.109 RAMDISK
--- conf/RAMDISK30 Dec 2016 22:36:07 -  1.109
+++ conf/RAMDISK3 May 2018 17:08:26 -
@@ -48,20 +48,18 @@ uturn0  at mainbus0 # U2/UTurn 
Runway I
 uturn1 at mainbus0
 astro* at mainbus0 # Astro memory & I/O controller
 
-lasi0  at mainbus0 offset 0x10 irq 28  # LASI host adapter
-lasi0  at mainbus0 offset 0xfd0 irq 28 # LASI on C1[01]0, 
J2[01]0
-lasi0  at phantomas0 offset 0xfd0 irq 28   # LASI on [AB]*
-lasi0  at uturn? offset 0xfd0 irq 28   # LASI on [CJ]*
-lasi1  at mainbus0 offset 0x50 irq 27  # 712 GIO card
-asp*   at mainbus0 irq 28  # this one comes w/ Viper and LEDs
-wax*   at mainbus0 irq 24  # Wax may host EISA as well
-wax*   at phantomas0 irq 24# Wax on [AB]*
-wax*   at uturn? irq 24# Wax on C*
+lasi0  at mainbus0 offset 0x10 # LASI host adapter
+lasi0  at mainbus0 offset 0xfd0# LASI on C1[01]0, J2[01]0
+lasi0  at phantomas0 offset 0xfd0  # LASI on [AB]*
+lasi0  at uturn? offset 0xfd0  # LASI on [CJ]*
+lasi1  at mainbus0 offset 0x50 # 712 GIO card
+asp*   at mainbus0 # this one comes w/ Viper and LEDs
+wax*

unbreak gsckbc (possibly iockbc and mkbc)

2018-05-03 Thread Miod Vallat
sys/dev/pckbc/pckbd.c introduces a buglet, where the value computed for
local variable `table' in pckbd_set_xtscancode() in the non-translating
case, is overwritten by accident.

Unfortunately, this means that the keyboard ends up using a scancode set
which is not the one expected by the driver, and hilarity ensues, such
as key up events not translated correctly, and neither ctrl or caps
lock.

Unfortunately this breaks at least gsckbc(4/hppa), which is a controller
where you can't plug a DIN keyboard so a "modern" PS/2 keyboard is
required, and that logic can be shunt.

This is very inconvenient, as most of the hppa machines where the X
server works are gsckbc machines, and 6.3 can't be installed on them
because of this bug (but then, noone seems to have noticed, so this is
hardly relevant).

Simple fix below.

Index: pckbd.c
===
RCS file: /OpenBSD/src/sys/dev/pckbc/pckbd.c,v
retrieving revision 1.44
diff -u -p -r1.44 pckbd.c
--- pckbd.c 6 Jan 2018 18:51:20 -   1.44
+++ pckbd.c 2 May 2018 18:58:28 -
@@ -214,7 +214,7 @@ int
 pckbd_set_xtscancode(pckbc_tag_t kbctag, pckbc_slot_t kbcslot,
 struct pckbd_internal *id)
 {
-   int table;
+   int table = 3;
 
if (pckbc_xt_translation(kbctag)) {
 #ifdef DEBUG
@@ -247,7 +247,7 @@ pckbd_set_xtscancode(pckbc_tag_t kbctag,
}
 
/* keep falling back until we hit a table that looks usable. */
-   for (table = 3; table >= 1; table--) {
+   for (; table >= 1; table--) {
u_char cmd[2];
 #ifdef DEBUG
printf("pckbd: trying table %d\n", table);



Re: avoid uninitialised attr in rasops_scrollback()

2018-05-01 Thread Miod Vallat
> Thanks, looks good/ok.  Shouldn't the eraserows call in
> rasops_doswitch() also use scr->rs_defattr for the attr argument?

Yes, indeed. Good catch!



reduce hppa interrupt guts awfulness

2018-05-01 Thread Miod Vallat
[this is long, and hppa-specific, feel free to ignore if you don't care
 about OpenBSD/hppa. Noone does anyway nowadays]

At the beginning of the hppa port, no interrupts were shared - the
processor allows for 32 interrupt sources and the existing designs made
sure to allocate distinct interrupts to every device.

Every device, but the PS/2 keyboard and mouse controller. So mickey
added a kluge about 15 years ago for them when I wrote the keyboard
controller driver. [Yes, really 15 years ago now... time flies]

And then the port grew PCI bus support, where interrupts have to be
shareable, by design. So the interrupt code got some form of shared
interrupts, but, well, the interrupt handling code is definitely not for
the faint of heart. Yet it works... to some extent. This mostly involves
magic, and the ability to understand locore0.s.

Because most of the native hppa drivers have been designed with
exclusive interrupts in mind, the hppa kernel configuration has many
hardwired interrupt vector lines (`irq' locators).

This is the reason why you have distinct foo0 and foo1 lines in the
kernel configuration, even for devices which driver do not use
interrupts at all, such as sti(4).

While working on ``card-mode'' dino(4) support [coming soon], I ended up
with having more than one dino(4) attachment to the same parent. To my
surprise, both were using the same interrupt, which - in the current
state of the interrupt handling code, which I won't touch without a
ten-feet pole - meant interrupts from the first device were completely
ignored, because the second one would happily overwrite all the relevant
interrupt structures for that interrupt bit.

This happens, because of this in mbsubmatch() in
sys/arch/hppa/hppa/mainbus.c:

int
mbsubmatch(parent, match, aux)
struct device *parent;
void *match, *aux;
{
[..]
if ((ret = (*cf->cf_attach->ca_match)(parent, match, aux)))
ca->ca_irq = cf->hppacf_irq;

return ret;
}

This means that "everytime a kernel configuration line matches, we pick
its irq value". And while many devices have stricter checks based on
their physical addresses, PCI bridges such as dino(4) don't.

So, with a kernel configuration having
dino0   at phantomas? irq 26# PCI bus bridge on [AB]*
dino1   at phantomas? irq 25
both lines would match, and both dino controllers would end up using -
but not sharing! - irq 25.

This was not noticed because systems with two dino attachments AT THE
SAME PARENT do not exist in their DEFAULT configuration.

However, adding support for cardmode dino changes the rules. And one can
end up with THREE dino controllers although the kernel only allows for
dino0 and dino1.

The only correct way to address this is to relax this fixed irq
assignments and let the kernel pick unused interrupt vectors. In fact,
this logic was already in use on higher-end elroy(4) systems.

The following diff does:
- dynamic allocation of interrupts for dino(4) and gsc(4).
- only mention irq locators for devices which use interrupts.
- for gsc(4), this actually postpones interrupt allocation until gsc(4)
  attaches, so asp(4)/lasi(4)/wax(4) won't route the interrupt yet, but
  the gsc(4) child will take care of this.
- because of hardwired interrupt line assignment on the pre-PCI systems,
  the logic looking for a free interrupt pin looks from 31 to 0, while
  it used to search in the opposite order. This WILL affect all elroy
  systems (C3xxx, J) but shouldn't have any noticeable effect. Even
  though gsckbc will pick interrupt 26, systems with gsckbc will have
  the asp/lasi/wax controller attaching early enough to leave irq 26
  available by the time gsckbc attacheѕ.
- remove the irq locator for the drivers which do not need a fixed
  assignment. siop and moongoose could benefit from this but don't work
  at the moment so this is left as an exercize to future kernel hackers.
  A side effect from this is that we do not need multiple sti(4)
  attachment lines, so PCI sti(4) devices will now attach as sti0 rather
  than sti2.

With this diff, multiple dino(4) devices attached to the same parent
will use different interrupt sources, and more than two dino(4) devices
can attach.

Tested on 715/75 (old-gen using asp), 715/100/XC (new-gen using lasi),
B132L+, B180L, C240, B2000, C3650.

B2000 and C3650 test have been done with sys/dev/ic/com.c downgraded to
1.166 in order to avoid freezes (bug resolution ongoing and not related
to this diff).

715 and B1xx tests have been done with sys/dev/pckbc/pckbd.c downgraded
to 1.43 (bug resolution ongoing and not related to this diff).

$ cat levandes.vari
Index: conf/GENERIC
===
RCS file: /OpenBSD/src/sys/arch/hppa/conf/GENERIC,v
retrieving revision 1.175
diff -u -p -r1.175 GENERIC
--- conf/GENERIC14 Feb 2018 23:51:49 -  

Re: avoid uninitialised attr in rasops_scrollback()

2018-05-01 Thread Miod Vallat
> scrollback isn't part of wsdisplay_emulops but rather wsdisplay_accessops.
> It isn't clear how to properly get an attr in wsscrollback()
> GETCHAR/getchar is part of wsmoused and sc->sc_accessops->getchar
> may be NULL.

Ok, ignore that. There is a simpler solution.

Index: rasops.c
===
RCS file: /OpenBSD/src/sys/dev/rasops/rasops.c,v
retrieving revision 1.53
diff -u -p -r1.53 rasops.c
--- rasops.c27 Apr 2018 21:36:12 -  1.53
+++ rasops.c1 May 2018 17:02:43 -
@@ -1373,6 +1373,7 @@ struct rasops_screen {
int rs_visible;
int rs_crow;
int rs_ccol;
+   long rs_defattr;
 
int rs_sbscreens;
 #define RS_SCROLLBACK_SCREENS 5
@@ -1412,10 +1413,11 @@ rasops_alloc_screen(void *v, void **cook
scr->rs_visible = (ri->ri_nscreens == 0);
scr->rs_crow = -1;
scr->rs_ccol = -1;
+   scr->rs_defattr = *attrp;
 
for (i = 0; i < scr->rs_dispoffset; i++) {
scr->rs_bs[i].uc = ' ';
-   scr->rs_bs[i].attr = *attrp;
+   scr->rs_bs[i].attr = scr->rs_defattr;
}
 
if (ri->ri_bs && scr->rs_visible) {
@@ -1425,7 +1427,8 @@ rasops_alloc_screen(void *v, void **cook
} else {
for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
scr->rs_bs[scr->rs_dispoffset + i].uc = ' ';
-   scr->rs_bs[scr->rs_dispoffset + i].attr = *attrp;
+   scr->rs_bs[scr->rs_dispoffset + i].attr =
+   scr->rs_defattr;
}
}
 
@@ -1906,7 +1909,6 @@ rasops_scrollback(void *v, void *cookie,
struct rasops_info *ri = v;
struct rasops_screen *scr = cookie;
int row, col, oldvoff;
-   long attr;
 
oldvoff = scr->rs_visibleoffset;
 
@@ -1927,7 +1929,7 @@ rasops_scrollback(void *v, void *cookie,
return;
 
rasops_cursor(ri, 0, 0, 0);
-   ri->ri_eraserows(ri, 0, ri->ri_rows, attr);
+   ri->ri_eraserows(ri, 0, ri->ri_rows, scr->rs_defattr);
for (row = 0; row < ri->ri_rows; row++) {
for (col = 0; col < ri->ri_cols; col++) {
int off = row * scr->rs_ri->ri_cols + col +



Re: avoid uninitialised attr in rasops_scrollback()

2018-04-30 Thread Miod Vallat
> On Sun, Apr 29, 2018 at 09:42:00AM +0000, Miod Vallat wrote:
> > 
> > > Don't use attr uninitialised.  Avoids glitches seen when using
> > > scrollback with radeondrm.
> > 
> > That's horrible. The bg attribute should be passed to the function,
> > rather than computed here with possibly wrong values.
> > 
> 
> You didn't include a diff so I guess you propose something like this?

I'm not sure this is correct, but that's probably better.

My point is that, if you need to erase a few rows, you need to use the
default (non kernel) background attribute. This attribute depends from
the wsdisplay emulation in use (it's edp->defattr). But since the
emulation is the one asking for scrollback, it should be easy to plumb
it down the way - adding an extra argument to the .scrollback
wsdisplay_accessops and then to rasops_scrollback().



Re: avoid uninitialised attr in rasops_scrollback()

2018-04-29 Thread Miod Vallat

> Don't use attr uninitialised.  Avoids glitches seen when using
> scrollback with radeondrm.

That's horrible. The bg attribute should be passed to the function,
rather than computed here with possibly wrong values.



Re: Stop ping telling world its pid

2018-04-12 Thread Miod Vallat
> what we need is an eventually consistent 16 bit number microservice message
> bus that all ping processes can subscribe to.

And it should be available as early as possible during boot, so I think
its place is in init(8).



Re: sparc64 ci_cpuid

2017-12-01 Thread Miod Vallat

> sparc64 uses a different name of storing the CPU number.  I'd like to
> use `ci_cpuid' to be able to use it in MI code without adding another
> abstraction layer.

Isn't that what CPU_INFO_UNIT() is for?



Re: [PATCH] intel_uncore.c - Horrible, ugly hack to avoid dmesg spam

2017-10-29 Thread Miod Vallat
> The patch below simply stops printing additional messages after 10
> lines have been printed.
>
You might want to use ratecheck(9) rather than a simple limit.



Re: pow() returns a negative result on loongson

2017-10-10 Thread Miod Vallat
> My first thought would on Loongson would be softfloat bug.
> But I am not 100% sure it (still) uses softfloat.

Loongson has never used softfloat. But all mips ports embed the
softfloat code in order to perform tricky computations the FPU won't
perform (mostly edge cases involving denormals and infinities).

So in this case, either the computation gets entirely done in hardware,
but the hardware yields a wrong results, and there won't likely be a fix
for this, or it asks the kernel for assistance, and there might be a
sign bug in there.



Ethernet media autoselect for DEC 3000

2017-09-22 Thread Miod Vallat
The on-board Ethernet interface on DEC 3000 systems (except for models
300) has both a 10base5 and a 10baseT connector, which is software
selected.

The following diff, based upon sparc le@ledma attachment, lets the user
force a specific media regardless of the PROM settings, and will also,
when in 'autoselect' mode, alternate between medias when career is lost.

Tested on 3000/600 (both connectors) and 3000/300LX (10baseT only). This
has zero impact on Ethernet TURBOchannel boards, which use a different
attachment.

Index: dev/tc/if_le_ioasic.c
===
RCS file: /OpenBSD/src/sys/dev/tc/if_le_ioasic.c,v
retrieving revision 1.17
diff -u -p -r1.17 if_le_ioasic.c
--- dev/tc/if_le_ioasic.c   22 Dec 2014 02:28:52 -  1.17
+++ dev/tc/if_le_ioasic.c   22 Sep 2017 20:59:34 -
@@ -55,6 +55,10 @@
 #include 
 #include 
 
+#ifdef __alpha__
+#include 
+#endif /* __alpha__ */
+
 struct le_ioasic_softc {
struct  am7990_softc sc_am7990; /* glue to MI code */
struct  lereg1 *sc_r1;  /* LANCE registers */
@@ -77,6 +81,14 @@ void le_ioasic_copytobuf_gap16(struct la
 void le_ioasic_copyfrombuf_gap16(struct lance_softc *, void *, int, int);
 void le_ioasic_zerobuf_gap16(struct lance_softc *, int, int);
 
+#ifdef __alpha__
+#ifdef DEC_3000_500
+intle_ioasic_ifmedia_change(struct lance_softc *);
+void   le_ioasic_ifmedia_status(struct lance_softc *, struct ifmediareq *);
+void   le_ioasic_nocarrier(struct lance_softc *);
+#endif
+#endif /* __alpha__ */
+
 int
 le_ioasic_match(struct device *parent, void *match, void *aux)
 {
@@ -155,6 +167,27 @@ le_ioasic_attach(struct device *parent, 
le->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
le->sc_zerobuf = le_ioasic_zerobuf_gap16;
 
+#ifdef __alpha__
+#ifdef DEC_3000_500
+   /*
+* On non-300 DEC 3000 models, both AUI and UTP are available.
+*/
+   if (cputype == ST_DEC_3000_500) {
+   static const uint64_t media[] = {
+   IFM_ETHER | IFM_10_T,
+   IFM_ETHER | IFM_10_5,
+   IFM_ETHER | IFM_AUTO
+   };
+   le->sc_mediachange = le_ioasic_ifmedia_change;
+   le->sc_mediastatus = le_ioasic_ifmedia_status;
+   le->sc_supmedia = media;
+   le->sc_nsupmedia = nitems(media);
+   le->sc_defaultmedia = IFM_ETHER | IFM_AUTO;
+   le->sc_nocarrier = le_ioasic_nocarrier;
+   }
+#endif
+#endif /* __alpha__ */
+
dec_le_common_attach(>sc_am7990,
(u_char *)((struct ioasic_softc *)parent)->sc_base
+ IOASIC_SLOT_2_START);
@@ -414,3 +447,96 @@ le_ioasic_zerobuf_gap16(struct lance_sof
xfer = min(len, 16);
}
 }
+
+#ifdef __alpha__
+#ifdef DEC_3000_500
+int
+le_ioasic_ifmedia_change(struct lance_softc *lsc)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   struct ifmedia *ifm = >sc_am7990.lsc.sc_ifmedia;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ossr, ssr;
+
+   if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
+   return EINVAL;
+
+   ossr = ssr = bus_space_read_4(ioasic_bst, ioasic_bsh, IOASIC_CSR);
+
+   switch (IFM_SUBTYPE(ifm->ifm_media)) {
+   case IFM_10_5:
+   ssr &= ~IOASIC_CSR_ETHERNET_UTP;
+   break;
+   case IFM_10_T:
+   ssr |= IOASIC_CSR_ETHERNET_UTP;
+   break;
+   case IFM_AUTO:
+   break;
+   default:
+   return EINVAL;
+   }
+
+   if (ossr != ssr)
+   bus_space_write_4(ioasic_bst, ioasic_bsh, IOASIC_CSR, ssr);
+
+   return 0;
+}
+
+void
+le_ioasic_ifmedia_status(struct lance_softc *lsc, struct ifmediareq *req)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ssr;
+
+   ssr = bus_space_read_4(ioasic_bst, ioasic_bsh, IOASIC_CSR);
+
+   if (ssr & IOASIC_CSR_ETHERNET_UTP)
+   req->ifm_active = IFM_ETHER | IFM_10_T;
+   else
+   req->ifm_active = IFM_ETHER | IFM_10_5;
+}
+
+void
+le_ioasic_nocarrier(struct lance_softc *lsc)
+{
+   struct le_ioasic_softc *sc = (struct le_ioasic_softc *)lsc;
+   bus_space_tag_t ioasic_bst =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bst;
+   bus_space_handle_t ioasic_bsh =
+   ((struct ioasic_softc *)sc->sc_am7990.lsc.sc_dev.dv_parent)->sc_bsh;
+   u_int32_t ossr, ssr;
+
+  

fix blinkenlichten on TURBOchannel alpha

2017-09-12 Thread Miod Vallat
Blinkenlichten used to be disabled by default, and became enabled by
default some releases ago.

However, the tc alpha blinkenlichten code was expecting to be triggered
by a sysctl machdep.led_blink change, and would not start by default.

The following diff fixes this, and restores the balance of serenity and
peace of mind, to some extent.

Index: sys/arch/alpha/tc/ioasic.c
===
RCS file: /OpenBSD/src/sys/arch/alpha/tc/ioasic.c,v
retrieving revision 1.17
diff -u -p -r1.17 ioasic.c
--- sys/arch/alpha/tc/ioasic.c  20 Sep 2010 06:33:46 -  1.17
+++ sys/arch/alpha/tc/ioasic.c  12 Sep 2017 20:37:09 -
@@ -91,6 +91,7 @@ struct cfdriver ioasic_cd = {
 
 intioasic_intr(void *);
 intioasic_intrnull(void *);
+void   ioasic_led_blink(void *);
 
 #defineC(x)((void *)(u_long)(x))
 #defineKV(x)   (ALPHA_PHYS_TO_K0SEG(x))
@@ -207,6 +208,8 @@ ioasicattach(parent, self, aux)
 * Try to configure each device.
 */
ioasic_attach_devs(sc, ioasic_devs, ioasic_ndevs);
+
+   ioasic_led_blink(NULL);
 }
 
 void
@@ -348,7 +351,7 @@ static const uint8_t led_pattern8[] = {
 void
 ioasic_led_blink(void *unused)
 {
-   extern int alpha_led_blink;
+   extern int alpha_led_blink; /* machdep.c */
vaddr_t rw_csr;
u_int32_t pattern;
int display_loadavg;



Re: Looking for testers with a floppy drive

2017-08-26 Thread Miod Vallat

> Hi,
>
> is anyone still using floppies? If yes, it would be nice if they could 
> give the diff below a test. It defers probing of the drives which reduces 
> boot time quite a bit. If floppy does not work with the diff, please also 
> test if it works without it. On qemu, floppy access seems to be broken (or 
> I did something wrong).

With this diff, floppies still work here.

$ dmesg
OpenBSD 6.2-beta (GENERIC) #0: Fri Aug 25 23:36:31 GMT 2017
m...@alfador.gentiane.org:/data/src/sys/arch/i386/compile/GENERIC
cpu0: AMD-K6tm w/ multimedia extensions ("AuthenticAMD" 586-class) 234 MHz
cpu0: FPU,V86,DE,PSE,TSC,MSR,MCE,CX8,MMX
real mem  = 66600960 (63MB)
avail mem = 51343360 (48MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: date 02/26/98, BIOS32 rev. 0 @ 0xfb440
apm0 at bios0: Power Management spec V1.2 (slowidle)
pcibios0 at bios0: rev 2.1 @ 0xf/0xb8b8
pcibios0: PCI IRQ Routing Table rev 1.0 @ 0xfdd30/128 (6 entries)
pcibios0: PCI Exclusive IRQs: 5 9 10 11
pcibios0: PCI Interrupt Router at 000:07:0 ("Intel 82371SB ISA" rev 0x00)
pcibios0: PCI bus #0 is the last bus
bios0: ROM list: 0xc/0x8000
cpu0 at mainbus0: (uniprocessor)
pci0 at mainbus0 bus 0: configuration mode 1 (bios)
pchb0 at pci0 dev 0 function 0 "Intel 82439TX" rev 0x01
piixpcib0 at pci0 dev 7 function 0 "Intel 82371AB PIIX4 ISA" rev 0x01
pciide0 at pci0 dev 7 function 1 "Intel 82371AB IDE" rev 0x01: DMA, channel 0 
wired to compatibility, channel 1 wired to compatibility
wd0 at pciide0 channel 0 drive 0: 
wd0: 16-sector PIO, LBA, 3098MB, 6346368 sectors
wd0(pciide0:0:0): using PIO mode 4, DMA mode 2
atapiscsi0 at pciide0 channel 1 drive 0
scsibus1 at atapiscsi0: 2 targets
cd0 at scsibus1 targ 0 lun 0:  ATAPI 5/cdrom 
removable
cd0(pciide0:1:0): using PIO mode 4, Ultra-DMA mode 2
uhci0 at pci0 dev 7 function 2 "Intel 82371AB USB" rev 0x01: irq 11
piixpm0 at pci0 dev 7 function 3 "Intel 82371AB Power" rev 0x01: SMI
iic0 at piixpm0
"eeprom" at iic0 addr 0x50 not configured
vga1 at pci0 dev 11 function 0 "S3 ViRGE DX/GX" rev 0x01
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
yds0 at pci0 dev 13 function 0 "Yamaha 724" rev 0x05: irq 9
rl0 at pci0 dev 15 function 0 "Realtek 8139" rev 0x10: irq 10, address 
00:e0:7d:e6:ae:d5
rlphy0 at rl0 phy 0: RTL internal PHY
isa0 at piixpcib0
isadma0 at isa0
fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com1 at isa0 port 0x2f8/8 irq 3: ns16550a, 16 byte fifo
pckbc0 at isa0 port 0x60/5 irq 1 irq 12
pckbd0 at pckbc0 (kbd slot)
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
lpt0 at isa0 port 0x378/4 irq 7
npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16
usb0 at uhci0: USB revision 1.0
uhub0 at usb0 configuration 1 interface 0 "Intel UHCI root hub" rev 1.00/1.00 
addr 1
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on wd0a (4330659be0e105e7.a) swap on wd0b dump on wd0b
ac97: codec id 0x414b4d00 (Asahi Kasei AK4540 rev 0)
audio0 at yds0
opl at yds0 not configured
opl at yds0 not configured
opl at yds0 not configured
opl at yds0 not configured
mpu at yds0 not configured
mpu at yds0 not configured
mpu at yds0 not configured
mpu at yds0 not configured
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
$ disklabel fd0
# /dev/rfd0c:
type: floppy
disk: floppy disk
label: fictitious
duid: 
flags:
bytes/sector: 512
sectors/track: 18
tracks/cylinder: 2
sectors/cylinder: 36
cylinders: 80
total sectors: 2880
boundstart: 0
boundend: 2880
drivedata: 0 

16 partitions:
#size   offset  fstype [fsize bsize   cpg]
  c: 28800  unused
  i: 28800   MSDOS
$ doas mount -o ro /dev/fd0i /mnt
...



Re: wsfont: remove iso7/pcvt encoding macros and entries

2017-06-13 Thread Miod Vallat

> Hi tech@,
>
> We do not support iso7 nor pcvt encoding, so remove macro definitions
> and commented entries.

If you do that, then you can probably optimize away
vga_valid_primary_font() in sys/dev/ic/vga.c as well.



Re: monop(6): drop the conditional shrt macro definitions

2017-06-10 Thread Miod Vallat

> Hi tech@,
>
> Drop the conditional shrt macro definitions and use short everywhere.

Why not use uint8_t then?



g/c ASPICFLAG

2017-06-06 Thread Miod Vallat
This used to be necessary in the gcc 2.95 days. Nowadays nothing in base
or X uses it.

Index: share/mk/bsd.own.mk
===
RCS file: /OpenBSD/src/share/mk/bsd.own.mk,v
retrieving revision 1.184
diff -u -p -r1.184 bsd.own.mk
--- share/mk/bsd.own.mk 18 Apr 2017 14:03:08 -  1.184
+++ share/mk/bsd.own.mk 6 Jun 2017 19:12:04 -
@@ -129,10 +129,6 @@ PICFLAG?=-fPIC
 PICFLAG?=-fpic
 .endif
 
-.if ${MACHINE_ARCH} == "sparc64"
-ASPICFLAG=-KPIC
-.endif
-
 .if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "powerpc" || \
 ${MACHINE_ARCH} == "sparc64"
 # big PIE



Re: Makefile.cross tweaks

2017-06-06 Thread Miod Vallat

>> The following diff attempts to cross-build more things, in particular
>> gnu/lib (except for libiberty). It also passes the proper optimization
>> flags so that libstdc++-v3 gets built with optimization.
>
> Doesn't build for arm64, probably because BUILD_GCC4 is transparently
> set by the host and not reset to NO.

Damn. This diff ought to work better.

Index: Makefile.cross
===
RCS file: /OpenBSD/src/Makefile.cross,v
retrieving revision 1.94
diff -u -p -r1.94 Makefile.cross
--- Makefile.cross  23 May 2017 14:57:30 -  1.94
+++ Makefile.cross  6 Jun 2017 18:15:11 -
@@ -43,9 +43,15 @@ MACHINE_IS_LP64 =
 
 #CROSSCPPFLAGS?=   -nostdinc -I${CROSSDIR}/usr/include
 #CROSSLDFLAGS?=-nostdlib -L${CROSSDIR}/usr/lib -static
+DEBUG?=-g
 CROSSCFLAGS?=  ${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
-CROSSCXXFLAGS?=${CROSSCPPFLAGS}
+CROSSCXXFLAGS?=${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
 #LDSTATIC?=-static
+.if (${TARGET_ARCH} == "alpha") || (${TARGET_ARCH} == "sparc64")
+CROSSPICFLAG?=-fPIC
+.else
+CROSSPICFLAG?=-fpic
+.endif
 
 CROSSDIR=  ${DESTDIR}/usr/cross/${TARGET}
 CROSSENV=  AR=${CROSSDIR}/usr/${TARGET_CANON}/bin/ar \
@@ -63,6 +69,7 @@ CROSSENV= AR=${CROSSDIR}/usr/${TARGET_CA
CFLAGS=\"${CROSSCFLAGS}\" CPPFLAGS=\"${CROSSCPPFLAGS}\" \
CXXFLAGS=\"${CROSSCXXFLAGS}\" \
LDFLAGS=\"${CROSSLDFLAGS}\" \
+   PICFLAG=\"${CROSSPICFLAG}\" \
CROSSDIR=\"${CROSSDIR}\"
 CROSSADDPATH=:${CROSSDIR}/usr/${TARGET_CANON}/bin
 CROSSPATH= /usr/bin:/bin:/usr/sbin:/sbin${CROSSADDPATH}
@@ -75,18 +82,31 @@ CROSSOBJ=   ${CROSSDIR}/.obj_done
 CROSSINCLUDES= ${CROSSDIR}/.includes_done
 CROSSBINUTILS= ${CROSSDIR}/.binutils_done
 CROSSGCC=  ${CROSSDIR}/.gcc_done
-#NO_CROSS= isakmpd keynote ssh
+NO_CROSS=  libiberty
 
 .include 
 
+BUILD_CLANG=no
+BUILD_GCC3=no
+BUILD_GCC4=no
+
 .for _arch in ${TARGET_ARCH}
-.if !empty(CLANG_ARCH:M${_arch})
-COMPILER_VERSION=clang
-BUILD_CLANG=yes
-.elif !empty(GCC3_ARCH:M${_arch})
+.if !empty(GCC3_ARCH:M${_arch})
 COMPILER_VERSION=gcc3
-.else
+.elif !empty(GCC4_ARCH:M${_arch})
 COMPILER_VERSION=gcc4
+.else
+COMPILER_VERSION=clang
+.endif
+
+.if !empty(CLANG_ARCH:M${_arch})
+BUILD_CLANG=yes
+.endif
+.if !empty(GCC3_ARCH:M${_arch})
+BUILD_GCC3=yes
+.endif
+.if !empty(GCC4_ARCH:M${_arch})
+BUILD_GCC4=yes
 .endif
 
 .if !empty(PIE_ARCH:M${_arch})
@@ -101,6 +121,7 @@ PIE_DEFAULT=
 BINUTILS=  ar as gasp ld nm objcopy objdump ranlib readelf size \
strings strip
 BINUTILS_DIR=gnu/usr.bin/binutils-2.17
+
 .endfor
 
 # no libcrypto these won't build
@@ -113,6 +134,13 @@ NO_CROSS+=nsd
 NO_CROSS+=bind
 NO_CROSS+=unbound
 
+.if ${BUILD_GCC3:L} != "yes"
+NO_CROSS+=libobjc libstdc++
+.endif
+.if ${BUILD_GCC4:L} != "yes"
+NO_CROSS+=../usr.bin/cc/libobjc libstdc++-v3 libsupc++-v3
+.endif
+
 cross-dirs:${CROSSDIRS}
 cross-obj: ${CROSSOBJ}
 cross-includes:${CROSSINCLUDES}
@@ -172,12 +200,18 @@ ${CROSSINCLUDES}: ${CROSSOBJ}
MACHINE_ARCH=${TARGET_ARCH} MACHINE_CPU=${TARGET_CPU} \
MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
TARGET_ARCH=${TARGET_ARCH} TARGET_CPU=${TARGET_CPU} \
+   BUILD_GCC3=${BUILD_GCC3} \
+   BUILD_GCC4=${BUILD_GCC4} \
+   BUILD_CLANG=${BUILD_CLANG} \
${MAKE} prereq && \
COMPILER_VERSION=${COMPILER_VERSION} \
MACHINE=${TARGET} \
MACHINE_ARCH=${TARGET_ARCH} MACHINE_CPU=${TARGET_CPU} \
MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
TARGET_ARCH=${TARGET_ARCH} TARGET_CPU=${TARGET_CPU} \
+   BUILD_GCC3=${BUILD_GCC3} \
+   BUILD_GCC4=${BUILD_GCC4} \
+   BUILD_CLANG=${BUILD_CLANG} \
${MAKE} DESTDIR=${CROSSDIR} includes)
@touch ${CROSSINCLUDES}
 
@@ -222,7 +256,7 @@ ${CROSSBINUTILS}:   ${CROSSINCLUDES}
 
 
 ${CROSSGCC}:   ${CROSSBINUTILS}
-.if ${COMPILER_VERSION:L} == "clang"
+.if ${BUILD_CLANG:L} == "yes"
(cd ${.CURDIR}/gnu/usr.bin/clang; \
MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
MACHINE_ARCH=${TARGET_ARCH} \
@@ -253,7 +287,8 @@ ${CROSSGCC}:${CROSSBINUTILS}
chmod +x ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc;
echo 
"#!/bin/sh\n${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-clang 
--driver-mode=g++ --sysroot ${CROSSDIR} \"$$""@\"" > 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-c++; \
chmod +x ${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-c++;
-.elif ${COMPILER_VERSION:L} == "gcc3"
+.endif
+.if ${BUILD_GCC3:L} == "yes"
(cd ${.CURDIR}/gnu/usr.bin/gcc; \
MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
TARGET_ARCH=${TARGET_ARCH} TARGET_CPU=${TARGET_CPU} \
@@ -280,21 +315,22 @@ ${CROSSGCC}:  ${CROSSBINUTILS}
chmod ${BINMODE} 

Makefile.cross tweaks

2017-05-29 Thread Miod Vallat
The following diff attempts to cross-build more things, in particular
gnu/lib (except for libiberty). It also passes the proper optimization
flags so that libstdc++-v3 gets built with optimization.

Index: Makefile.cross
===
RCS file: /OpenBSD/src/Makefile.cross,v
retrieving revision 1.94
diff -u -p -r1.94 Makefile.cross
--- Makefile.cross  23 May 2017 14:57:30 -  1.94
+++ Makefile.cross  29 May 2017 20:15:01 -
@@ -43,8 +43,9 @@ MACHINE_IS_LP64 =
 
 #CROSSCPPFLAGS?=   -nostdinc -I${CROSSDIR}/usr/include
 #CROSSLDFLAGS?=-nostdlib -L${CROSSDIR}/usr/lib -static
+DEBUG?=-g
 CROSSCFLAGS?=  ${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
-CROSSCXXFLAGS?=${CROSSCPPFLAGS}
+CROSSCXXFLAGS?=${CROSSCPPFLAGS} -O2 ${PIPE} ${DEBUG}
 #LDSTATIC?=-static
 
 CROSSDIR=  ${DESTDIR}/usr/cross/${TARGET}
@@ -75,7 +76,7 @@ CROSSOBJ= ${CROSSDIR}/.obj_done
 CROSSINCLUDES= ${CROSSDIR}/.includes_done
 CROSSBINUTILS= ${CROSSDIR}/.binutils_done
 CROSSGCC=  ${CROSSDIR}/.gcc_done
-#NO_CROSS= isakmpd keynote ssh
+NO_CROSS=  libiberty
 
 .include 
 
@@ -307,6 +308,7 @@ ${CROSSGCC}:${CROSSBINUTILS}
cp -f ${CROSSDIR}/usr/libexec/cpp 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-libexeccpp
cp -f ${CROSSDIR}/usr/bin/gcc 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc
ln -sf ${TARGET_CANON}-cc ${CROSSDIR}/usr/${TARGET_CANON}/bin/cc
+   ln -sf ${TARGET_CANON}-c++ ${CROSSDIR}/usr/${TARGET_CANON}/bin/c++
 
cp -f ${CROSSDIR}/usr/bin/gcc 
${CROSSDIR}/usr/${TARGET_CANON}/bin/${TARGET_CANON}-cc
rm -f ${CROSSDIR}/usr/bin/gcc  ${CROSSDIR}/usr/bin/g++  
${CROSSDIR}/usr/bin/cc ${CROSSDIR}/usr/libexec/cpp 
@@ -343,6 +345,13 @@ cross-lib: ${CROSSGCC}
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
SKIPDIR=\"${NO_CROSS}\" \
${MAKE} install)
+   (cd ${.CURDIR}/gnu/lib; \
+   eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
+   SKIPDIR=\"${NO_CROSS}\" \
+   ${MAKE} depend all ; \
+   eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
+   SKIPDIR=\"${NO_CROSS}\" \
+   ${MAKE} install)
 
 cross-bin: ${CROSSOBJ}
MACHINE=${TARGET} \
@@ -351,10 +360,10 @@ cross-bin:${CROSSOBJ}
for i in libexec bin sbin usr.bin usr.sbin; do \
(cd ${.CURDIR}/$$i; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
-   SKIPDIR=\"${BINUTILS} ${NO_CROSS}\" \
+   SKIPDIR=\"${NO_CROSS}\" \
${MAKE} depend all ; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} 
DESTDIR=${CROSSDIR} \
-   SKIPDIR=\"${BINUTILS} ${NO_CROSS}\" \
+   SKIPDIR=\"${NO_CROSS}\" \
${MAKE} install); \
done
 
@@ -362,7 +371,7 @@ cross-gnu:  ${CROSSOBJ}
MACHINE=${TARGET} \
MACHINE_ARCH=${TARGET_ARCH} MACHINE_CPU=${TARGET_CPU}; \
export MACHINE MACHINE_ARCH MACHINE_CPU; \
-   for i in gnu/lib gnu/usr.sbin gnu/usr.bin ; do \
+   for i in gnu/usr.sbin gnu/usr.bin ; do \
(cd ${.CURDIR}/$$i; \
eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
SKIPDIR=\"${NO_CROSS}\" \



Re: Use copyin32(9) to implement futex(2)

2017-05-28 Thread Miod Vallat

> This makes MULTIPROCESSOR kernels use copyin32(9) to guarantee
> atomicity.  This will break m88k GENERIC.MP; shouldn't be too
> difficult to fix for someone whu understands m88k assembly.

Index: subr.S
===
RCS file: /OpenBSD/src/sys/arch/m88k/m88k/subr.S,v
retrieving revision 1.26
diff -u -p -r1.26 subr.S
--- subr.S  21 Jun 2016 12:31:19 -  1.26
+++ subr.S  28 May 2017 19:20:34 -
@@ -372,6 +372,48 @@ ASLOCAL(Lciflt)
 #undef DEST
 #undef LEN
 
+/*
+ * Specific flavour for a single 32-bit word copy.
+ * copyin32(from, to)
+ * r2 == from (user source address)
+ * r3 == to (kernel destination address)
+ */
+
+#defineSRC %r2
+#defineDEST%r3
+
+ENTRY(copyin32)
+   /* check for source alignment */
+   mask%r8,  SRC,  0x3
+   bcndne0,  %r8,  _ASM_LABEL(copyin32_misaligned)
+
+   /* set up fault handler */
+   ldcr%r5,  CPU
+   ld  %r6,  %r5,  CI_CURPCB
+   or.u%r5,  %r0,  %hi16(_ASM_LABEL(Lciflt))
+   or  %r5,  %r5,  %lo16(_ASM_LABEL(Lciflt))
+   st  %r5,  %r6,  PCB_ONFAULT /* pcb_onfault = Lciflt */
+
+#ifdef ERRATA__XXX_USR
+   NOP
+   ld.usr  %r5,  SRC,  %r0
+   NOP
+   NOP
+   NOP
+#else
+   ld.usr  %r5,  SRC,  %r0
+#endif
+   st  %r5,  DEST, %r0
+   br.n_ASM_LABEL(Lcidone)
+or %r2, %r0, %r0   /* successful return */
+
+ASLOCAL(copyin32_misaligned)
+   jmp.n   %r1
+or %r2, %r0, EFAULT/* return fault */
+
+#undef SRC
+#undef DEST
+
 /*##*/
 /*##*/
 



Re: Atomic copyin(9)/copyout(9) for amd64

2017-05-15 Thread Miod Vallat
>   So I implemented a new function called
> copyin_futex(9), which is all we really need.

But it is not specific to futex - in fact, it could be used in syscall()
as well.

Better call it fuword() or aligned_fuword() since it has the extra
alignment requirement that fuword() didn't have.



Re: Include packet timestamp into the mbuf packet header

2017-05-02 Thread Miod Vallat

> diff --git sys/sys/mbuf.h sys/sys/mbuf.h
> index 202ce8ced8b..7ca1a779fe0 100644
> --- sys/sys/mbuf.h
> +++ sys/sys/mbuf.h
> @@ -127,10 +127,11 @@ struct  pkthdr {
>   u_int16_tph_flowid; /* pseudo unique flow id */
>   u_int16_tcsum_flags;/* checksum flags */
>   u_int16_tether_vtag;/* Ethernet 802.1p+Q vlan tag */
>   u_intph_rtableid;   /* routing table id */
>   u_intph_ifidx;  /* rcv interface index */
> + int64_t  ph_timestamp;  /* packet timestamp */

That field ought to be moved much earlier, in order to prevent wasting
an extra 32 bits due to alignment.



Re: sync root.mail

2017-03-30 Thread Miod Vallat
>> > Ambiguous: choose package for emacs--no_x11
>> > a   0: 
>> > 1: emacs-21.4p37-no_x11
>> > 2: emacs-25.1p3-no_x11
>> > Your choice:
>> 
>> Time to choose another package?
>
> I think in this case choice is good.

Indeed, but why aren't vim-no_x11 packages listed as possible (and
better!) choices in this situation?



Re: Linking userland with lld

2017-01-21 Thread Miod Vallat

> The plan is to use lld (the llvm linker) on arm64 to avoid GLPv3
> binutils.  Mostly works, but it triggers an issue in building ldapd
> and ldapctl.
>
> The problem here is that the code uses the SHA1 functions in
> libcrypto, but doesn't explicitly link against that library.  With our
> ancient binutils we don't notice this, because we link against libtls,
> which as a DT_NEEDED entry for libcrypto.  But lld doesn't fall for
> this.  And I believe modern binutils don't do this either.

This also prevents them from building in cross-bin, FWIW.



libcrypto: get rid of I386_ONLY

2016-11-04 Thread Miod Vallat
I386_ONLY was used to prefer a different assembler sequence in the
sha512 code, which would be faster on 80386 processors, but slower on
80486 and above.

This code path has never been enabled, and there are actually no plans
to make libcrypto friendlier to genuine 80386 chips, so why bother
keeping this - it's only contributing to obfuscation.

Index: cryptlib.c
===
RCS file: /cvs/src/lib/libcrypto/cryptlib.c,v
retrieving revision 1.37
diff -u -p -r1.37 cryptlib.c
--- cryptlib.c  13 Sep 2015 16:56:11 -  1.37
+++ cryptlib.c  4 Nov 2016 08:49:22 -
@@ -635,7 +635,7 @@ OPENSSL_cpu_caps(void)
return *(uint64_t *)OPENSSL_ia32cap_P;
 }
 
-#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && 
!defined(I386_ONLY)
+#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
 #define OPENSSL_CPUID_SETUP
 typedef unsigned long long IA32CAP;
 void
Index: md32_common.h
===
RCS file: /cvs/src/lib/libcrypto/md32_common.h,v
retrieving revision 1.21
diff -u -p -r1.21 md32_common.h
--- md32_common.h   4 Sep 2016 14:31:29 -   1.21
+++ md32_common.h   4 Nov 2016 08:49:22 -
@@ -152,8 +152,8 @@ static inline uint32_t ROTATE(uint32_t a
 #if defined(DATA_ORDER_IS_BIG_ENDIAN)
 
 #if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && 
!defined(OPENSSL_NO_INLINE_ASM)
-# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \
-  (defined(__x86_64) || defined(__x86_64__))
+# if (defined(__i386) || defined(__i386__) || \
+  defined(__x86_64) || defined(__x86_64__))
 /*
  * This gives ~30-40% performance improvement in SHA-256 compiled
  * with gcc [on P4]. Well, first macro to be frank. We can pull
Index: arch/alpha/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/alpha/opensslconf.h,v
retrieving revision 1.7
diff -u -p -r1.7 opensslconf.h
--- arch/alpha/opensslconf.h19 Jun 2015 06:05:11 -  1.7
+++ arch/alpha/opensslconf.h4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
 #define OPENSSLDIR "/etc/ssl"
 #endif
Index: arch/amd64/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/amd64/opensslconf.h,v
retrieving revision 1.9
diff -u -p -r1.9 opensslconf.h
--- arch/amd64/opensslconf.h19 Jun 2015 06:05:11 -  1.9
+++ arch/amd64/opensslconf.h4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
 #define OPENSSLDIR "/etc/ssl"
 #endif
Index: arch/arm/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/arm/opensslconf.h,v
retrieving revision 1.7
diff -u -p -r1.7 opensslconf.h
--- arch/arm/opensslconf.h  19 Jun 2015 06:05:11 -  1.7
+++ arch/arm/opensslconf.h  4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
 #define OPENSSLDIR "/etc/ssl"
 #endif
Index: arch/hppa/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/hppa/opensslconf.h,v
retrieving revision 1.7
diff -u -p -r1.7 opensslconf.h
--- arch/hppa/opensslconf.h 19 Jun 2015 06:05:11 -  1.7
+++ arch/hppa/opensslconf.h 4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
 #define OPENSSLDIR "/etc/ssl"
 #endif
Index: arch/i386/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/i386/opensslconf.h,v
retrieving revision 1.7
diff -u -p -r1.7 opensslconf.h
--- arch/i386/opensslconf.h 19 Jun 2015 06:05:11 -  1.7
+++ arch/i386/opensslconf.h 4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
 #define OPENSSLDIR "/etc/ssl"
 #endif
Index: arch/m88k/opensslconf.h
===
RCS file: /cvs/src/lib/libcrypto/arch/m88k/opensslconf.h,v
retrieving revision 1.7
diff -u -p -r1.7 opensslconf.h
--- arch/m88k/opensslconf.h 19 Jun 2015 06:05:11 -  1.7
+++ arch/m88k/opensslconf.h 4 Nov 2016 08:49:22 -
@@ -1,9 +1,6 @@
 #include 
 /* crypto/opensslconf.h.in */
 
-/* Generate 80386 code? */
-#undef I386_ONLY
-
 #if 

obsolete bits in libcrypto Makefile

2016-11-04 Thread Miod Vallat
libcrypto no longer needs to use internal headers from libssl; and no
longer checks for TERMIOS being defined.

Index: Makefile
===
RCS file: /cvs/src/lib/libcrypto/Makefile,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile
--- Makefile16 Oct 2016 19:28:44 -  1.8
+++ Makefile4 Nov 2016 08:40:33 -
@@ -7,7 +7,6 @@ PC_FILES=libcrypto.pc
 
 CLEANFILES=${PC_FILES}
 
-SSL_SRC=   ${.CURDIR}/../libssl
 LCRYPTO_SRC=   ${.CURDIR}
 
 CFLAGS+= -Wall -Wundef -Werror
@@ -18,11 +17,9 @@ CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H -DHA
 .endif
 
 CFLAGS+= -DLIBRESSL_INTERNAL
-CFLAGS+= -DTERMIOS
 # Hardware engines
 CFLAGS+= -DOPENSSL_NO_HW_PADLOCK # XXX enable this?
 
-CFLAGS+= -I${SSL_SRC}
 CFLAGS+= -I${LCRYPTO_SRC}
 CFLAGS+= -I${LCRYPTO_SRC}/modes -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/evp
 



Smarter OpenBSD/sgi boot blocks

2016-10-04 Thread Miod Vallat
The sgi boot blocks use the PROM (ARCBios or ARCS) for its I/O routines.
When using a disk-based path, these routines are using the partition
table found in the ``volume header''.

In order to be able to use 16 partitions per disk, the OpenBSD port only
claims one volume header partition, #0, as the OpenBSD area, and puts
its own label in there.

Unfortunately, this means that `sd0a', the OpenBSD partition on which
the kernel is found, may not actually start at the same location as the
volume header partition #0, even though this is the case in most setups.

When reinstalling an O2 some time ago, I did not pay attention to this
during install:

  Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout? [a] c
  [...]
  Label editor (enter '?' for help at any prompt)
  > p
  OpenBSD area: 0-17773524; size: 17773524; free: 0
  #size   offset  fstype [fsize bsize   cpg]
a: 17770389 3135  4.2BSD   1024  819216
c: 177735240  unused
p: 31350 unknown
  > d a
  > a
  partition: [a]
  offset: [3135]
  size: [17770389] 400M
  Rounding size to cylinder (3360 sectors): 816705
  FS type: [4.2BSD]
  mount point: [none] /
  Rounding offset to bsize (32 sectors): 3136
  Rounding size to bsize (32 sectors): 816704

And `sd0a' ended up starting one sector after the beginning of the
volume header partition #0.

Of course, rebooting afterwards did not work as expected:

  OpenBSD/sgi-IP32 ARCBios boot version 1.7
  arg 0: pci(0)scsi(0)disk(1)rdisk(0)partition(8)/boot
  arg 1: OSLoadOptions=auto
  arg 2: ConsoleIn=serial(0)
  arg 3: ConsoleOut=serial(0)
  arg 4: SystemPartition=pci(0)scsi(0)disk(1)rdisk(0)partition(8)
  arg 5: OSLoader=boot
  arg 6: OSLoadPartition=pci(0)scsi(0)disk(1)rdisk(0)partition(0)
  arg 7: OSLoadFilename=bsd
  Boot: pci(0)scsi(0)disk(1)rdisk(0)partition(0)bsd
  cannot open pci(0)scsi(0)disk(1)rdisk(0)partition(0)/etc/random.seed: Invalid 
argument
  open pci(0)scsi(0)disk(1)rdisk(0)partition(0)bsd: Invalid argument
  Boot FAILED!

The proper way to fix this is to make the boot blocks read the real
OpenBSD label instead of assuming sd0a spans volume header partition #0
in all cases.

This is achieved by the diff below, which will attempt to use the raw
disk device (volume header partition #10, equivalent to sd0c) for disk
accesses and will read both the volume header (to know where the OpenBSD
disklabel lies) and then the OpenBSD label (to know where sd0a really
is).

Of course, this has to cope with the two valid disk syntaxes (true
ARCBios used on older sgi systems, and ARCS dksc() syntax used on Origin
and later systems).

This diff has been tested on O2 (IP32) and Origin 350 (IP27). It is
written in a conservative way, in order to revert to the existing
behaviour if anything fails (invalid volume header, no OpenBSD label
yet...) and should not cause any regression.

Note that network boots are not affected by these changes.

Index: Makefile32.inc
===
RCS file: /OpenBSD/src/sys/arch/sgi/stand/Makefile32.inc,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile32.inc
--- Makefile32.inc  19 Oct 2012 13:51:59 -  1.5
+++ Makefile32.inc  30 Sep 2016 09:19:15 -
@@ -18,6 +18,7 @@ AS+=  -32
 LD?=   ld
 LD+=   -m elf32btsmip
 LIBSA_CPPFLAGS=
+CFLAGS+=   -DLIBSA_LONGLONG_PRINTF
 .endif
 
 ### Figure out what to use for libsa and libz
Index: boot/Makefile
===
RCS file: /OpenBSD/src/sys/arch/sgi/stand/boot/Makefile,v
retrieving revision 1.16
diff -u -p -r1.16 Makefile
--- boot/Makefile   30 Jul 2016 03:25:49 -  1.16
+++ boot/Makefile   30 Sep 2016 09:19:15 -
@@ -13,14 +13,14 @@ AFLAGS+=${SAABI}
 
 S= ${.CURDIR}/../../../..
 SRCS=  start.S arcbios.c boot.c conf.c diskio.c filesystem.c \
-   netfs.c netio.c strchr.c strstr.c
+   netfs.c netio.c strstr.c
 
 .PATH: ${S}/lib/libsa
 SRCS+= loadfile.c
 
 .PATH: ${S}/lib/libkern/arch/mips64 ${S}/lib/libkern
-SRCS+= strlcpy.c memcpy.c strlen.c strrchr.c strlcat.c strncmp.c \
-   strcmp.S
+SRCS+= memcpy.c strchr.c strcmp.S strlcat.c strlcpy.c strlen.c \
+   strncmp.c strrchr.c
 
 CLEANFILES+=   machine mips64
 
Index: boot/diskio.c
===
RCS file: /OpenBSD/src/sys/arch/sgi/stand/boot/diskio.c,v
retrieving revision 1.10
diff -u -p -r1.10 diskio.c
--- boot/diskio.c   30 Sep 2015 22:45:57 -  1.10
+++ boot/diskio.c   30 Sep 2016 09:19:15 -
@@ -1,6 +1,21 @@
 /* $OpenBSD: diskio.c,v 1.10 2015/09/30 22:45:57 krw Exp $ */
 
 /*
+ * Copyright (c) 2016 Miodrag Vallat.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is 

Re: squeeze some isa drivers

2016-08-31 Thread Miod Vallat

> Time to play whack i386/conf/GENERIC with a bat and see what pops out.
>
> Extensive research in the archives indicates that these devices are extinct.

You'll need to remove out the commented wss line in alpha GENERIC as
well.



com(4) mcr games

2016-08-18 Thread Miod Vallat
While everyone is looking at com(4)...

Some systems use reserved (and sometimes not) bits of the MCR register
for extra features. In particular, on some systems, clearing the DCS bit
in the MCR is not a good idea (kudos if you can guess what historical
machine I am thinking of).

It makes sense for com(4) to know better what bits to set in the MCR.

What about the following diff?

Index: sys/arch/arm/xscale/pxa2x0_com.c
===
RCS file: /OpenBSD/src/sys/arch/arm/xscale/pxa2x0_com.c,v
retrieving revision 1.12
diff -u -p -r1.12 pxa2x0_com.c
--- sys/arch/arm/xscale/pxa2x0_com.c7 Sep 2010 16:21:35 -   1.12
+++ sys/arch/arm/xscale/pxa2x0_com.c18 Aug 2016 09:59:56 -
@@ -129,6 +129,7 @@ pxauart_attach(struct device *parent, st
sc->sc_iobase = pxa->pxa_addr;
sc->sc_frequency = PXA2X0_COM_FREQ;
sc->sc_uarttype = COM_UART_PXA2X0;
+   sc->sc_mcr_out = MCR_IENABLE;
 
 #if 0
if (com_is_console(sc->sc_iot, sc->sc_iobase, >sc_ioh) == 0 &&
Index: sys/arch/armv7/broadcom/bcm2835_muart.c
===
RCS file: /OpenBSD/src/sys/arch/armv7/broadcom/bcm2835_muart.c,v
retrieving revision 1.1
diff -u -p -r1.1 bcm2835_muart.c
--- sys/arch/armv7/broadcom/bcm2835_muart.c 7 Aug 2016 17:46:36 -   
1.1
+++ sys/arch/armv7/broadcom/bcm2835_muart.c 18 Aug 2016 09:59:56 -
@@ -68,6 +68,7 @@ bcmmuart_attach(struct device *parent, s
 
sc->sc_frequency = 5;
sc->sc_uarttype = COM_UART_16550;
+   sc->sc_mcr_out = MCR_IENABLE;
 
if (faa->fa_reg[0].addr == comconsaddr + 0x3f00) {
sc->sc_iobase = comconsaddr;
Index: sys/arch/armv7/dev/com_fdt.c
===
RCS file: /OpenBSD/src/sys/arch/armv7/dev/com_fdt.c,v
retrieving revision 1.6
diff -u -p -r1.6 com_fdt.c
--- sys/arch/armv7/dev/com_fdt.c17 Aug 2016 13:44:48 -  1.6
+++ sys/arch/armv7/dev/com_fdt.c18 Aug 2016 09:59:56 -
@@ -114,6 +114,7 @@ com_fdt_attach(struct device *parent, st
sc->sc.sc_iobase = faa->fa_reg[0].addr;
sc->sc.sc_frequency = 4800;
sc->sc.sc_uarttype = COM_UART_TI16750;
+   sc->sc_mcr_out = MCR_IENABLE;
 
if (OF_is_compatible(faa->fa_node, "snps,dw-apb-uart")) {
sc->sc.sc_uarttype = COM_UART_16550;
Index: sys/arch/hppa/dev/com_dino.c
===
RCS file: /OpenBSD/src/sys/arch/hppa/dev/com_dino.c,v
retrieving revision 1.4
diff -u -p -r1.4 com_dino.c
--- sys/arch/hppa/dev/com_dino.c15 Jul 2007 19:25:49 -  1.4
+++ sys/arch/hppa/dev/com_dino.c18 Aug 2016 09:59:56 -
@@ -108,6 +108,7 @@ com_dino_attach(parent, self, aux)
/* select clock freq */
regs->test = COM_DINO_CLK_SEL;
sc->sc_frequency = COM_DINO_FREQ;
+   sc->sc_mcr_out = MCR_IENABLE;
 
com_attach_subr(sc);
 
Index: sys/arch/hppa/dev/com_ssio.c
===
RCS file: /OpenBSD/src/sys/arch/hppa/dev/com_ssio.c,v
retrieving revision 1.2
diff -u -p -r1.2 com_ssio.c
--- sys/arch/hppa/dev/com_ssio.c24 Jun 2007 16:28:39 -  1.2
+++ sys/arch/hppa/dev/com_ssio.c18 Aug 2016 09:59:56 -
@@ -76,6 +76,7 @@ com_ssio_attach(struct device *parent, s
}
 
sc->sc_frequency = COM_SSIO_FREQ;
+   sc->sc_mcr_out = MCR_IENABLE;
com_attach_subr(sc);
 
sc->sc_ih = ssio_intr_establish(IPL_TTY, saa->saa_irq,
Index: sys/arch/hppa/gsc/com_gsc.c
===
RCS file: /OpenBSD/src/sys/arch/hppa/gsc/com_gsc.c,v
retrieving revision 1.21
diff -u -p -r1.21 com_gsc.c
--- sys/arch/hppa/gsc/com_gsc.c 15 Jul 2007 19:25:49 -  1.21
+++ sys/arch/hppa/gsc/com_gsc.c 18 Aug 2016 09:59:56 -
@@ -99,6 +99,7 @@ com_gsc_attach(parent, self, aux)
}
 
sc->sc_frequency = COM_GSC_FREQ;
+   sc->sc_mcr_out = MCR_IENABLE;
com_attach_subr(sc);
 
sc->sc_ih = gsc_intr_establish((struct gsc_softc *)parent,
Index: sys/arch/octeon/dev/cn30xxuart.c
===
RCS file: /OpenBSD/src/sys/arch/octeon/dev/cn30xxuart.c,v
retrieving revision 1.9
diff -u -p -r1.9 cn30xxuart.c
--- sys/arch/octeon/dev/cn30xxuart.c14 Apr 2016 13:51:58 -  1.9
+++ sys/arch/octeon/dev/cn30xxuart.c18 Aug 2016 09:59:56 -
@@ -112,6 +112,7 @@ cn30xxuart_attach(struct device *parent,
sc->sc_frequency = octeon_ioclock_speed();
sc->sc_uarttype = COM_UART_16550A;
sc->sc_fifolen = OCTEON_UART_FIFO_SIZE;
+   sc->sc_mcr_out = MCR_IENABLE;
 
/* if it's in use as console, it's there. */
if (bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS, 0, 
>sc_ioh)) {
Index: sys/arch/sgi/dev/com_ioc.c

Re: RELRO on mips64

2016-08-10 Thread Miod Vallat
> Also, since mips64 doesn't have a real hardware NX bit, splitting the 
> .text and .rodata segments doesn't actually get us anything from a 
> protection standpoint.  So, unset PAD_NO to smoosh them back together. 

The Loongson processors are supposed to have an NX bit, but it's only
mentioned once in the documentation, without enough details (in
particular, there is no mention of what exception is triggered when an
instruction fetch would hit a tlb entry with the NX bit set).

Mention of this bit disappeared in the 2F documentation, but that's
because most of the english language 2F documentation is actually the
R4000 manual with "R4000" replaced with "Loongson 2F" in it.

> What I'm not sure is if the pmap would be happier with them separate: the 
> workaround for the "R4000 EOP" bug applies to PROT_EXEC pages only, so 
> maybe it would be better to keep them separate for that?  Anyone?

The R4000 EOP workaround is triggered by pmap_enter() when entering a
page with PROT_EXEC, and rodata pages could cause false positives. It
would make sense to keep text and rodata separate.



Re: libcrypto: explicitly initialize constant

2016-07-12 Thread Miod Vallat
>> Noted by VS2013, const values should be initialized (though I think
>> the 'static' should also implicitly zero).
>
> this sounds like the compiler doesn't know C?

He is talking about Visual Studio. The C part of that piece of shit
pretending to be a compiler only supports a subset of C89.



Re: cbfb: coreboot framebuffer console

2016-06-16 Thread Miod Vallat

> Here is a third version that just integrates the coreboot code into
> efifb.  The cnattach path still has to be different to allow vga to
> try to attach before doing the coreboot version.
>
>
> Index: arch/amd64/amd64/efifb.c

> @@ -55,6 +102,8 @@ int efifb_show_screen(void *, void *, i
>  int   efifb_list_font(void *, struct wsdisplay_font *);
>  int   efifb_load_font(void *, void *, struct wsdisplay_font *);
>  
> +struct cb_framebuffer * cb_find_fb(paddr_t);
  ^
spurious space.

>  struct cfattach efifb_ca = {
>   sizeof(struct efifb_softc), efifb_match, efifb_attach, NULL
>  };

const.

> @@ -112,7 +161,8 @@ efifb_attach(struct device *parent, stru
>   bus_space_handle_t   ioh;
>   long defattr;
>  
> - printf("\n");
> + printf(": %dx%d, %dbpp\n", efifb_console.rinfo.ri_width,
> + efifb_console.rinfo.ri_height, efifb_console.rinfo.ri_depth);

Someone (TM) needs to fix all frame buffer attachments to report
visible geometry and depth in the same way, BTW. This output looks like
tga(4), which is not a good example to follow...



Re: cbfb: coreboot framebuffer console

2016-06-15 Thread Miod Vallat

> On Wed, 15 Jun 2016 19:01:23 +0200, Mark Kettenis wrote:
>
>> I don't really consider it to be terribly important to rename the
>> efifb(4).  The chromebooks are weird machines, and I don't expect the
>> coreboot-based framebuffer to show up on many systems.
>
> Agreed, just keep it as efifb(4).  If we really need to change the
> name in the future we can do so.

Come on, it's obvious the proper name for it is `fafb`, for Firmware
Agnostic Frame Buffer.



Re: cbfb: coreboot framebuffer console

2016-06-11 Thread Miod Vallat

> Index: arch/amd64/amd64/cbfb.c

> +struct cfattach cbfb_ca = {
> + sizeof(struct cbfb_softc), cbfb_match, cbfb_attach, NULL
> +};

Make it const.

> +void
> +cbfb_rasops_preinit(struct cbfb *cbfb)
> +{
> +#define bmnum(_x) (fls(_x) - ffs(_x) + 1)
> +#define bmpos(_x) (ffs(_x) - 1)

These two macros do not seem to get used anywhere in this file.



Re: smu(4) PWM Fan Support

2016-05-12 Thread Miod Vallat
> > fcu(4) could benefit from a similar change, as there may be pwm fans
> > there too. At least RackMac3,1 has two pwm fans according to the eeprom
> > -p output.
> 
> Hmm, looking at the fcu(4) code it already should support pwm fans, no?

Doh! I was looking for `fan' in the sensors output and did not notice
`percent'. Sorry for the noise.



Re: smu(4) PWM Fan Support

2016-05-11 Thread Miod Vallat

> I've recently noticed that two of five fans in my G5 don't spin up.
> That's because smu(4) currently just supports RPM fans.
> The attached diff adds initial support for PWM fans as well.

fcu(4) could benefit from a similar change, as there may be pwm fans
there too. At least RackMac3,1 has two pwm fans according to the eeprom
-p output.



Re: SROP mitigation

2016-05-09 Thread Miod Vallat

> This is just a draft.
>
> Index: arch/hppa/hppa/machdep.c

> @@ -1329,11 +1330,31 @@ sys_sigreturn(struct proc *p, void *v, r
>   struct trapframe *tf = p->p_md.md_regs;
>   int error;
>  
> + if (PROC_PC(p) != (u_int64_t)p->p_p->ps_sigcode +

Why uint64_t here? This is a 32-bit platfoⅻm.

> Index: arch/m88k/m88k/sig_machdep.c

> @@ -207,18 +207,34 @@ sys_sigreturn(struct proc *p, void *v, r
>   struct sys_sigreturn_args /* {
>  syscallarg(struct sigcontext *) sigcntxp;
>   } */ *uap = v;
> - struct sigcontext *scp;
> + struct sigcontext *scp = SCARG(uap, sigcntxp);
>   struct trapframe *tf;
>   struct sigcontext ksc;
>  
> - scp = (struct sigcontext *)SCARG(uap, sigcntxp);
> -#ifdef DEBUG
> - if (sigdebug & SDB_FOLLOW)
> - printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
> -#endif
> - if (((vaddr_t)scp & 3) != 0 ||
> - copyin((caddr_t)scp, (caddr_t), sizeof(struct sigcontext)))
> + if (PROC_PC(p) != (u_int64_t)p->p_p->ps_sigcode +

Ditto.

> Index: arch/macppc/macppc/machdep.c

> @@ -512,8 +513,29 @@ sys_sigreturn(struct proc *p, void *v, r
>   struct trapframe *tf;
>   int error;
>  
> + if (PROC_PC(p) != (u_int64_t)p->p_p->ps_sigcode +

Same.

> Index: arch/sh/sh/sh_machdep.c

> @@ -519,18 +520,32 @@ sys_sigreturn(struct proc *p, void *v, r
>   struct sys_sigreturn_args /* {
>   syscallarg(struct sigcontext *) sigcntxp;
>   } */ *uap = v;
> - struct sigcontext *scp, context;
> + struct sigcontext *scp = SCARG(uap, sigcntxp), context;
>   struct trapframe *tf;
>   int error;
>  
> - /*
> -  * The trampoline code hands us the context.
> -  * It is unsafe to keep track of it ourselves, in the event that a
> -  * program jumps out of a signal handler.
> -  */
> - scp = SCARG(uap, sigcntxp);
> + if (PROC_PC(p) != (u_int64_t)p->p_p->ps_sigcode +

Guess.

> Index: arch/socppc/socppc/machdep.c

> @@ -539,8 +540,30 @@ sys_sigreturn(struct proc *p, void *v, r
>   struct trapframe *tf;
>   int error;
>  
> + if (PROC_PC(p) != (u_int64_t)p->p_p->ps_sigcode +

Yawn.



Re: anti-ROP mechanism in libc

2016-04-25 Thread Miod Vallat

>> Wait!  Does that mean there is a moment where there is not a valid
>> libc.so installed?  That would be wrong wouldn't it?
>> 
>> Doesn't the install command guarantee atomicity?
>
> Well, this is the same procedure we use during every make build,
> and it works.

It had been fixed to use install -S some years ago because it was not
atomic enough otherwise.



Re: Spurious serial console interrupts

2016-04-13 Thread Miod Vallat

> It should be latched, at least on modern 16550-like UARTs. From
> a PC16550D datasheet:

Keep in mind that com(4) is intended to support 16450 chips, which have
no FIFO. I believe that the current ordering of the operations is needed
to correctly support them, so you might want to decide at runtime where
to unmask this based upon whether the chip has a working FIFO or not.



Re: Keyboard resume (zzz) diff

2016-04-12 Thread Miod Vallat
> I think the best idea is to proceed with the diff as posted, with
> the added check to make sure the keyboard is enabled, and to always
> call config_activate_children on all paths through pckbd_activate?
> 
> In other words, no changes to wskbd_enable or wskbd_activate.
> 
> Sound right?

I think so.



Re: Keyboard resume (zzz) diff

2016-04-12 Thread Miod Vallat
> wskbd_enable (calls pckbd_enable) does not appear to be called from
> wskbd_activate, perhaps just calling wskbd_enable from there would be
> better? (as a matter of fact, wskbd_activate doesn't really do much at
> all except set sc_dying=1, and I'm not sure where that gets reset.)

Nooo! wskbd_enable() is not used in the physical device activation
path, but in the logical path, so that keyboard input gets ignored
unless its device is actually opened. If you are running with serial
console and no getty listening to /dev/ttyC*, for example, then
wskbd_enable() should not get invoked at all!

Now, some of the work done in wskbd_enable() might be worth doing in
wskbd_activate(), but be very careful when changing this.



Re: bufcache KNF

2016-04-11 Thread Miod Vallat

>> fwiw i like names in prototypes, so i know what's going on. i know
>> style says that, but i think the advice is obsolete.
>
> The compiler doesn't check that the argument names in the prototype
> match those in the definition. The below program compiles without
> warning.

This is not the point. The point is that putting argument names in
public headers increases the risk of breaking third-party software
thanks to the preprocessor.



  1   2   3   4   >