Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode Clean up extern mess by adding an API for ...



details:   https://anonhg.NetBSD.org/src/rev/30240e21a7f5
branches:  trunk
changeset: 768214:30240e21a7f5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Aug 12 00:57:23 2011 +0000

description:
Clean up extern mess by adding an API for kernel components to call libc
functions. thunk.c is built with special cflags that makes it compile
against standard system headers instead of kernel ones.

diffstat:

 sys/arch/usermode/conf/Makefile.usermode |   13 ++-
 sys/arch/usermode/dev/clock.c            |   12 +-
 sys/arch/usermode/dev/cpu.c              |   25 +++---
 sys/arch/usermode/dev/ttycons.c          |   11 +-
 sys/arch/usermode/include/cpu.h          |    7 +-
 sys/arch/usermode/include/pcb.h          |    7 +-
 sys/arch/usermode/include/thunk.h        |   51 ++++++++++++++
 sys/arch/usermode/usermode/thunk.c       |  110 +++++++++++++++++++++++++++++++
 8 files changed, 195 insertions(+), 41 deletions(-)

diffs (truncated from 467 to 300 lines):

diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/conf/Makefile.usermode
--- a/sys/arch/usermode/conf/Makefile.usermode  Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/conf/Makefile.usermode  Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.usermode,v 1.7 2011/08/11 22:38:25 jmcneill Exp $
+# $NetBSD: Makefile.usermode,v 1.8 2011/08/12 00:57:23 jmcneill Exp $
 
 MACHINE_ARCH=                  usermode
 USETOOLS?=                     no
@@ -18,6 +18,8 @@
 CPPFLAGS+=     -Dusermode
 CPPFLAGS.init_main.c+= -Dmain=kernmain
 
+CPPFLAGS.thunk.c+=     -U_KERNEL -I/usr/include
+
 ##
 ## (3) libkern and compat
 ##
@@ -27,14 +29,14 @@
 ##
 ## (4) local objects, compile rules, and dependencies
 ##
-MD_OBJS=
-MD_CFILES=
+MD_OBJS=       thunk.o
+MD_CFILES=     ${USERMODE}/usermode/thunk.c
 MD_SFILES=
 
 ##
 ## (5) link settings
 ##
-SYSTEM_LD=     @${_MKSHMSG} "   link  ${.CUTDIR:T}/${.TARGET}"; \
+SYSTEM_LD=     @${_MKSHMSG} "   link  ${.CURDIR:T}/${.TARGET}"; \
                ${_MKSHECHO}\
                ${CC} ${COPTS} -Wl,-Map,$@.map -o $@ '$${SYSTEM_OBJ}' '$${EXTRA_OBJ}' vers.o; \
                ${CC} ${COPTS} -Wl,-Map,$@.map -o $@ ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
@@ -44,6 +46,9 @@
 ## (6) port specific target dependencies
 ##
 
+thunk.o: ${USERMODE}/usermode/thunk.c
+       ${CC} ${COPTS} -I${.CURDIR} -c -o $@ ${USERMODE}/usermode/thunk.c
+
 ##
 ## (7) misc settings
 ##
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/dev/clock.c
--- a/sys/arch/usermode/dev/clock.c     Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/dev/clock.c     Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.5 2011/08/10 01:32:44 jmcneill Exp $ */
+/* $NetBSD: clock.c,v 1.6 2011/08/12 00:57:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.5 2011/08/10 01:32:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.6 2011/08/12 00:57:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -37,6 +37,7 @@
 #include <sys/time.h>
 
 #include <machine/mainbus.h>
+#include <machine/thunk.h>
 
 static int     clock_match(device_t, cfdata_t, void *);
 static void    clock_attach(device_t, device_t, void *);
@@ -48,8 +49,6 @@
        device_t        sc_dev;
 } clock_softc_t;
 
-extern int     setitimer(int, const struct itimerval *, struct itimerval *);
-
 static struct timecounter clock_timecounter = {
        clock_getcounter,       /* get_timecount */
        0,                      /* no poll_pps */
@@ -91,7 +90,7 @@
        itimer.it_interval.tv_sec = 0;
        itimer.it_interval.tv_usec = 10000;
        itimer.it_value = itimer.it_interval;
-       (void)setitimer(ITIMER_REAL, &itimer, NULL);
+       thunk_setitimer(ITIMER_REAL, &itimer, NULL);
 
        tc_init(&clock_timecounter);
 }
@@ -114,9 +113,8 @@
 static u_int
 clock_getcounter(struct timecounter *tc)
 {
-       extern int gettimeofday(struct timeval *, void *);
        struct timeval tv;
 
-       gettimeofday(&tv, NULL);
+       thunk_gettimeofday(&tv, NULL);
        return tv.tv_sec * 1000000 + tv.tv_usec;
 }
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.9 2011/08/11 23:04:44 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.10 2011/08/12 00:57:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.9 2011/08/11 23:04:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.10 2011/08/12 00:57:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -44,6 +44,7 @@
 #include <machine/cpu.h>
 #include <machine/mainbus.h>
 #include <machine/pcb.h>
+#include <machine/thunk.h>
 
 #include <uvm/uvm_extern.h>
 #include <uvm/uvm_page.h>
@@ -90,7 +91,7 @@
        sc->sc_ci->ci_self = &cpu_info_primary;
        sc->sc_ci->ci_curlwp = &lwp0;
 
-       if (getcontext(&lwp0pcb))
+       if (thunk_getcontext(&lwp0pcb))
                panic("getcontext failed");
        uvm_lwp_setuarea(&lwp0, (vaddr_t)&lwp0pcb);
 }
@@ -107,13 +108,10 @@
 void
 cpu_reboot(int howto, char *bootstr)
 {
-       extern void exit(int);
-       extern void abort(void);
-
        splhigh();
 
        if ((howto & RB_POWERDOWN) == RB_POWERDOWN)
-               exit(0);
+               thunk_exit(0);
 
        if (howto & RB_HALT) {
                printf("\n");
@@ -129,7 +127,7 @@
        /*
         * XXXJDM If we've panic'd, make sure we dump a core
         */
-       abort();
+       thunk_abort();
 
        /* NOTREACHED */
 }
@@ -176,10 +174,10 @@
        ci->ci_stash = oldlwp;
        curlwp = newlwp;
        if (oldpcb) {
-               if (swapcontext(&oldpcb->pcb_ucp, &newpcb->pcb_ucp))
+               if (thunk_swapcontext(&oldpcb->pcb_ucp, &newpcb->pcb_ucp))
                        panic("swapcontext failed: %d", errno);
        } else {
-               if (setcontext(&newpcb->pcb_ucp))
+               if (thunk_setcontext(&newpcb->pcb_ucp))
                        panic("setcontext failed: %d", errno);
        }
 
@@ -225,14 +223,13 @@
 void
 cpu_idle(void)
 {
-       extern int usleep(useconds_t);
        struct cpu_info *ci = curcpu();
 
        if (ci->ci_want_resched)
                return;
 
 #if notyet
-       usleep(10000);
+       thunk_usleep(10000);
 #endif
 }
 
@@ -294,13 +291,13 @@
        } else
                pcb->pcb_needfree = false;
 
-       if (getcontext(&pcb->pcb_ucp))
+       if (thunk_getcontext(&pcb->pcb_ucp))
                panic("getcontext failed: %d", errno);
        pcb->pcb_ucp.uc_stack.ss_sp = stack;
        pcb->pcb_ucp.uc_stack.ss_size = stacksize;
        pcb->pcb_ucp.uc_link = NULL;
        pcb->pcb_ucp.uc_flags = _UC_STACK | _UC_CPU;
-       makecontext(&pcb->pcb_ucp, (void (*)(void))cpu_lwp_trampoline,
+       thunk_makecontext(&pcb->pcb_ucp, (void (*)(void))cpu_lwp_trampoline,
            2, func, arg);
 }
 
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/dev/ttycons.c
--- a/sys/arch/usermode/dev/ttycons.c   Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/dev/ttycons.c   Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ttycons.c,v 1.3 2009/11/27 03:23:14 rmind Exp $ */
+/* $NetBSD: ttycons.c,v 1.4 2011/08/12 00:57:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.3 2009/11/27 03:23:14 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.4 2011/08/12 00:57:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -37,6 +37,7 @@
 #include <dev/cons.h>
 
 #include <machine/mainbus.h>
+#include <machine/thunk.h>
 
 static int     ttycons_match(device_t, cfdata_t, void *);
 static void    ttycons_attach(device_t, device_t, void *);
@@ -94,15 +95,13 @@
 int
 ttycons_cngetc(dev_t dev)
 {
-       extern int getchar(void);
-       return getchar();
+       return thunk_getchar();
 }
 
 void
 ttycons_cnputc(dev_t dev, int c)
 {
-       extern void putchar(int);
-       putchar(c);
+       thunk_putchar(c);
 }
 
 void
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/include/cpu.h
--- a/sys/arch/usermode/include/cpu.h   Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/include/cpu.h   Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.4 2011/08/11 23:04:44 jmcneill Exp $ */
+/* $NetBSD: cpu.h,v 1.5 2011/08/12 00:57:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -33,6 +33,7 @@
 #include <sys/cpu_data.h>
 
 #include <machine/intrdefs.h>
+#include <machine/thunk.h>
 
 extern void    cpu_signotify(struct lwp *);
 extern void    cpu_need_proftick(struct lwp *);
@@ -61,9 +62,7 @@
 __inline static void
 usermode_delay(unsigned int ms)
 {
-       extern int usleep(useconds_t);
-
-       usleep(ms);
+       thunk_usleep(ms);
 }
 
 #define        curcpu()        usermode_curcpu()
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/include/pcb.h
--- a/sys/arch/usermode/include/pcb.h   Thu Aug 11 23:15:35 2011 +0000
+++ b/sys/arch/usermode/include/pcb.h   Fri Aug 12 00:57:23 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcb.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: pcb.h,v 1.3 2011/08/12 00:57:24 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -32,11 +32,6 @@
 #include <sys/cdefs.h>
 #include <sys/ucontext.h>
 
-extern int     getcontext(ucontext_t *);
-extern int     setcontext(const ucontext_t *);
-extern void    makecontext(ucontext_t *, void (*)(void), int, ...);
-extern int     swapcontext(ucontext_t *, const ucontext_t *);
-
 struct pcb {
        ucontext_t      pcb_ucp;
        bool            pcb_needfree;
diff -r ac79a7b58704 -r 30240e21a7f5 sys/arch/usermode/include/thunk.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000



Home | Main Index | Thread Index | Old Index