Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.95 KB | None | 0 0
  1. /*  Copyright (c) 1984 AT&T */
  2. /*    All Rights Reserved   */
  3.  
  4. /*  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
  5. /*  The copyright notice above does not evidence any    */
  6. /*  actual or intended publication of such source code. */
  7.  
  8. #ident  "@(#)kern-port:os/main.c    10.7"
  9. #include "sys/types.h"
  10. #include "sys/param.h"
  11. #include "sys/psw.h"
  12. #include "sys/sbd.h"
  13. #include "sys/sysmacros.h"
  14. #include "sys/pcb.h"
  15. #include "sys/immu.h"
  16. #include "sys/systm.h"
  17. #include "sys/fs/s5dir.h"
  18. #include "sys/signal.h"
  19. #include "sys/user.h"
  20. #include "sys/mount.h"
  21. #include "sys/inode.h"
  22. #include "sys/region.h"
  23. #include "sys/proc.h"
  24. #include "sys/var.h"
  25. #include "sys/debug.h"
  26. #include "sys/conf.h"
  27. #include "sys/cmn_err.h"
  28.  
  29. int physmem;    /* Physical memory size in clicks.  */
  30. int maxmem;     /* Maximum available memory in clicks.  */
  31. int freemem;    /* Current available memory in clicks.  */
  32. inode_t *rootdir;
  33.  
  34.  
  35. extern int  icode[];
  36. extern int  szicode;
  37. extern int  userstack[];
  38.  
  39. /*
  40.  *  Initialization code.
  41.  *  fork - process 0 to schedule
  42.  *       - process 1 execute bootstrap
  43.  *
  44.  *  loop at low address in user mode -- /etc/init
  45.  *  cannot be executed.
  46.  */
  47.  
  48. main()
  49. {
  50.     register int    (**initptr)();
  51.     extern int  (*io_init[])();
  52.     extern int  (*init_tbl[])();
  53.     extern int  (*io_start[])();
  54.     extern int  sched();
  55.     extern int  vhand();
  56.     extern int  bdflush();
  57.     extern int  mappodflag;
  58.  
  59.     startup();
  60.     clkstart();
  61.     dmainit();
  62.  
  63.  
  64.     /*  Call all system initialization functions.
  65.     */
  66.  
  67.     for (initptr= &io_init[0]; *initptr; initptr++) (**initptr)();
  68.     for (initptr= &init_tbl[0]; *initptr; initptr++) (**initptr)();
  69.     for (initptr= &io_start[0]; *initptr; initptr++) (**initptr)();
  70.  
  71.  
  72.     cmn_err(CE_CONT,
  73.         "Available memory   = %d\n\n", ctob(freemem));
  74.  
  75.     prt_where = PRW_CONS;
  76.  
  77.     printf("***********************************************************************\n\n");
  78.     printf("Copyright (c) 1984 AT&T - All Rights Reserved\n\n");
  79.     printf("THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T INC.\n");
  80.     printf("The copyright notice above does not evidence any actual or\n");
  81.     printf("intended publication of such source code.\n\n");
  82.     printf("***********************************************************************\n\n");
  83.  
  84.  
  85.     u.u_start = time;
  86.  
  87.     /*  This call of swapadd must come after devinit in case
  88.      *  swap is moved by devinit.  It must also come after
  89.      *  dskinit so that the disk is don'ed.  This call should
  90.      *  return 0 since the first slot of swaptab should be used.
  91.      */
  92.  
  93.     if (swapdev != NODEV)
  94.         if (swapadd(swapdev, swplo, nswap) != 0)
  95.             cmn_err(CE_PANIC, "main - swapadd failed");
  96.  
  97.     /*
  98.      * make init process
  99.      * enter scheduling loop
  100.      * with system process
  101.      */
  102.  
  103.     if (newproc(0)) {
  104.         register preg_t *prp;
  105.         register reg_t  *rp;
  106.         register int    npgs;
  107.         register sde_t  *sp;
  108.         u.u_cstime = u.u_stime = u.u_cutime = u.u_utime = 0;
  109.  
  110.         /*  Set up the text region to do an exec
  111.         **  of /etc/init.  The "icode" is in misc.s.
  112.         */
  113.  
  114.         rp = allocreg(NULL, RT_PRIVATE, 0);
  115.         prp = attachreg(rp, &u, UVTEXT, PT_TEXT, SEG_RW);
  116.         npgs = btoc(szicode);
  117.         growreg(prp, npgs, DBD_DFILL);
  118.         loadmmu(u.u_procp, SCN2);
  119.         regrele(rp);
  120.  
  121.         if (copyout((caddr_t)icode, (caddr_t)(UVTEXT), szicode))
  122.             cmn_err(CE_PANIC, "main - copyout of icode failed");
  123.  
  124.         /*  The following software workaround is for
  125.         **  the WE32000 which does not have the
  126.         **  capability of getting write and execute
  127.         **  access to a segment at the same time.
  128.         **  The kernel normally wants to read and
  129.         **  write the user's text but in this case
  130.         **  we must execute the user's text in
  131.         **  kernel mode because it is going to
  132.         **  change %pcbp to switch to user mode.
  133.         **  Therefore, we must change the mode of the
  134.         **  text segment.
  135.         */
  136.  
  137.         if (!is32b()) {
  138.             /*  We need a loop here if szicode
  139.             **  ever gets larger than a segment.
  140.             */
  141.  
  142.             sp = (sde_t *)u.u_procp->p_srama[SCN2 - SCN2];
  143.             sp[snum(UVTEXT)].seg_prot = KRE | URE;
  144.             flushmmu(UVTEXT, btoc(szicode));
  145.         } else {
  146.             /*  Give kernel RWE and user RE access.
  147.             */
  148.  
  149.             chgprot(prp, SEG_RO);
  150.         }
  151.  
  152.         /*  Allocate a stack region and grow it to
  153.         **  SSIZE pages.
  154.         */
  155.  
  156.         rp = allocreg(NULL, RT_PRIVATE, 0);
  157.         prp = attachreg(rp, &u, userstack, PT_STACK, SEG_RW);
  158.         growreg(prp, SSIZE, DBD_DFILL);
  159.         loadmmu(u.u_procp, SCN3);
  160.         u.u_pcb.sub = (int *)((uint)userstack + ctob(SSIZE));
  161.         regrele(rp);
  162.         return(UVTEXT);
  163.     }
  164.     if (newproc(0)) {
  165.         u.u_procp->p_flag |= SLOAD|SSYS;
  166.         u.u_cstime = u.u_stime = u.u_cutime = u.u_utime = 0;
  167.         bcopy("vhand", u.u_psargs, 6);
  168.         bcopy("vhand", u.u_comm, 5);
  169.         if(mappodflag)
  170.             mappod(u.u_procp);
  171.         return((int)vhand);
  172.     }
  173.  
  174.     if (newproc(0)) {
  175.         u.u_procp->p_flag |= SLOAD|SSYS;
  176.         u.u_cstime = u.u_stime = u.u_cutime = u.u_utime = 0;
  177.         bcopy("bdflush", u.u_psargs, 8);
  178.         bcopy("bdflush", u.u_comm, 7);
  179.         if(mappodflag)
  180.             mappod(u.u_procp);
  181.         return((int)bdflush);
  182.     }
  183.     bcopy("sched", u.u_psargs, 6);
  184.     bcopy("sched", u.u_comm, 5);
  185.     if(mappodflag)
  186.         mappod(u.u_procp);
  187.     return((int)sched);
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement