/*===========================================================================* * init_timer * *===========================================================================*/ void init_timer(timer_t *tp) { tmr_inittimer(tp); }
/*===========================================================================* * initialize * *===========================================================================*/ PRIVATE void initialize(void) { register struct priv *sp; int i; /* Initialize IRQ handler hooks. Mark all hooks available. */ for (i=0; i<NR_IRQ_HOOKS; i++) { irq_hooks[i].proc_nr = NONE; } /* Initialize all alarm timers for all processes. */ for (sp=BEG_PRIV_ADDR; sp < END_PRIV_ADDR; sp++) { tmr_inittimer(&(sp->s_alarm_timer)); } /* Initialize the call vector to a safe default handler. Some kernel calls * may be disabled or nonexistant. Then explicitly map known calls to their * handler functions. This is done with a macro that gives a compile error * if an illegal call number is used. The ordering is not important here. */ for (i=0; i<NR_SYS_CALLS; i++) { call_vec[i] = do_unused; } /* Process management. */ map(SYS_FORK, do_fork); /* a process forked a new process */ map(SYS_EXEC, do_exec); /* update process after execute */ map(SYS_EXIT, do_exit); /* clean up after process exit */ map(SYS_NICE, do_nice); /* set scheduling priority */ map(SYS_PRIVCTL, do_privctl); /* system privileges control */ map(SYS_TRACE, do_trace); /* request a trace operation */ /* Signal handling. */ map(SYS_KILL, do_kill); /* cause a process to be signaled */ map(SYS_GETKSIG, do_getksig); /* PM checks for pending signals */ map(SYS_ENDKSIG, do_endksig); /* PM finished processing signal */ map(SYS_SIGSEND, do_sigsend); /* start POSIX-style signal */ map(SYS_SIGRETURN, do_sigreturn); /* return from POSIX-style signal */ /* Device I/O. */ map(SYS_IRQCTL, do_irqctl); /* interrupt control operations */ map(SYS_DEVIO, do_devio); /* inb, inw, inl, outb, outw, outl */ map(SYS_SDEVIO, do_sdevio); /* phys_insb, _insw, _outsb, _outsw */ map(SYS_VDEVIO, do_vdevio); /* vector with devio requests */ map(SYS_INT86, do_int86); /* real-mode BIOS calls */ /* Memory management. */ map(SYS_NEWMAP, do_newmap); /* set up a process memory map */ map(SYS_SEGCTL, do_segctl); /* add segment and get selector */ map(SYS_MEMSET, do_memset); /* write char to memory area */ /* Copying. */ map(SYS_UMAP, do_umap); /* map virtual to physical address */ map(SYS_VIRCOPY, do_vircopy); /* use pure virtual addressing */ map(SYS_PHYSCOPY, do_physcopy); /* use physical addressing */ map(SYS_VIRVCOPY, do_virvcopy); /* vector with copy requests */ map(SYS_PHYSVCOPY, do_physvcopy); /* vector with copy requests */ /* Clock functionality. */ map(SYS_TIMES, do_times); /* get uptime and process times */ map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */ /* System control. */ map(SYS_ABORT, do_abort); /* abort MINIX */ map(SYS_GETINFO, do_getinfo); /* request system information */ }
/*===========================================================================* * initialize * *===========================================================================*/ void system_init(void) { register struct priv *sp; int i; /* Initialize IRQ handler hooks. Mark all hooks available. */ for (i=0; i<NR_IRQ_HOOKS; i++) { irq_hooks[i].proc_nr_e = NONE; } /* Initialize all alarm timers for all processes. */ for (sp=BEG_PRIV_ADDR; sp < END_PRIV_ADDR; sp++) { tmr_inittimer(&(sp->s_alarm_timer)); } /* Initialize the call vector to a safe default handler. Some system calls * may be disabled or nonexistant. Then explicitely map known calls to their * handler functions. This is done with a macro that gives a compile error * if an illegal call number is used. The ordering is not important here. */ for (i=0; i<NR_SYS_CALLS; i++) { call_vec[i] = NULL; } /* Process management. */ map(SYS_FORK, do_fork); /* a process forked a new process */ map(SYS_EXEC, do_exec); /* update process after execute */ map(SYS_CLEAR, do_clear); /* clean up after process exit */ map(SYS_EXIT, do_exit); /* a system process wants to exit */ map(SYS_PRIVCTL, do_privctl); /* system privileges control */ map(SYS_TRACE, do_trace); /* request a trace operation */ map(SYS_SETGRANT, do_setgrant); /* get/set own parameters */ map(SYS_RUNCTL, do_runctl); /* set/clear stop flag of a process */ map(SYS_UPDATE, do_update); /* update a process into another */ map(SYS_STATECTL, do_statectl); /* let a process control its state */ /* Signal handling. */ map(SYS_KILL, do_kill); /* cause a process to be signaled */ map(SYS_GETKSIG, do_getksig); /* signal manager checks for signals */ map(SYS_ENDKSIG, do_endksig); /* signal manager finished signal */ map(SYS_SIGSEND, do_sigsend); /* start POSIX-style signal */ map(SYS_SIGRETURN, do_sigreturn); /* return from POSIX-style signal */ /* Device I/O. */ map(SYS_IRQCTL, do_irqctl); /* interrupt control operations */ #if defined(__i386__) map(SYS_DEVIO, do_devio); /* inb, inw, inl, outb, outw, outl */ map(SYS_VDEVIO, do_vdevio); /* vector with devio requests */ #endif /* Memory management. */ map(SYS_MEMSET, do_memset); /* write char to memory area */ map(SYS_VMCTL, do_vmctl); /* various VM process settings */ /* Copying. */ map(SYS_UMAP, do_umap); /* map virtual to physical address */ map(SYS_UMAP_REMOTE, do_umap_remote); /* do_umap for non-caller process */ map(SYS_VUMAP, do_vumap); /* vectored virtual to physical map */ map(SYS_VIRCOPY, do_vircopy); /* use pure virtual addressing */ map(SYS_PHYSCOPY, do_copy); /* use physical addressing */ map(SYS_SAFECOPYFROM, do_safecopy_from);/* copy with pre-granted permission */ map(SYS_SAFECOPYTO, do_safecopy_to); /* copy with pre-granted permission */ map(SYS_VSAFECOPY, do_vsafecopy); /* vectored safecopy */ /* safe memset */ map(SYS_SAFEMEMSET, do_safememset); /* safememset */ /* Clock functionality. */ map(SYS_TIMES, do_times); /* get uptime and process times */ map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */ map(SYS_STIME, do_stime); /* set the boottime */ map(SYS_VTIMER, do_vtimer); /* set or retrieve a virtual timer */ /* System control. */ map(SYS_ABORT, do_abort); /* abort MINIX */ map(SYS_GETINFO, do_getinfo); /* request system information */ map(SYS_SYSCTL, do_sysctl); /* misc system manipulation */ /* Profiling. */ map(SYS_SPROF, do_sprofile); /* start/stop statistical profiling */ map(SYS_CPROF, do_cprofile); /* get/reset call profiling data */ map(SYS_PROFBUF, do_profbuf); /* announce locations to kernel */ /* i386-specific. */ #if defined(__i386__) map(SYS_READBIOS, do_readbios); /* read from BIOS locations */ map(SYS_IOPENABLE, do_iopenable); /* Enable I/O */ map(SYS_SDEVIO, do_sdevio); /* phys_insb, _insw, _outsb, _outsw */ #endif /* Machine state switching. */ map(SYS_SETMCONTEXT, do_setmcontext); /* set machine context */ map(SYS_GETMCONTEXT, do_getmcontext); /* get machine context */ /* Scheduling */ map(SYS_SCHEDULE, do_schedule); /* reschedule a process */ map(SYS_SCHEDCTL, do_schedctl); /* change process scheduler */ /*OS Programming Exercise */ map(SYS_CPUVAR, do_cpuvar); /*get the process running on the CPU */ map(SYS_QPTAB, do_qptab); }
/*===========================================================================* * initialize * *===========================================================================*/ PRIVATE void initialize(void) { register struct priv *sp; int i; /* Initialize IRQ handler hooks. Mark all hooks available. */ for (i=0; i<NR_IRQ_HOOKS; i++) { irq_hooks[i].proc_nr_e = NONE; } /* Initialize all alarm timers for all processes. */ for (sp=BEG_PRIV_ADDR; sp < END_PRIV_ADDR; sp++) { tmr_inittimer(&(sp->s_alarm_timer)); } /* Initialize the call vector to a safe default handler. Some system calls * may be disabled or nonexistant. Then explicitely map known calls to their * handler functions. This is done with a macro that gives a compile error * if an illegal call number is used. The ordering is not important here. */ for (i=0; i<NR_SYS_CALLS; i++) { call_vec[i] = do_unused; callnames[i] = "unused"; } /* Process management. */ map(SYS_FORK, do_fork); /* a process forked a new process */ map(SYS_EXEC, do_exec); /* update process after execute */ map(SYS_EXIT, do_exit); /* clean up after process exit */ map(SYS_NICE, do_nice); /* set scheduling priority */ map(SYS_PRIVCTL, do_privctl); /* system privileges control */ map(SYS_TRACE, do_trace); /* request a trace operation */ map(SYS_SETGRANT, do_setgrant); /* get/set own parameters */ map(SYS_RUNCTL, do_runctl); /* set/clear stop flag of a process */ /* Signal handling. */ map(SYS_KILL, do_kill); /* cause a process to be signaled */ map(SYS_GETKSIG, do_getksig); /* PM checks for pending signals */ map(SYS_ENDKSIG, do_endksig); /* PM finished processing signal */ map(SYS_SIGSEND, do_sigsend); /* start POSIX-style signal */ map(SYS_SIGRETURN, do_sigreturn); /* return from POSIX-style signal */ /* Device I/O. */ map(SYS_IRQCTL, do_irqctl); /* interrupt control operations */ map(SYS_DEVIO, do_devio); /* inb, inw, inl, outb, outw, outl */ map(SYS_VDEVIO, do_vdevio); /* vector with devio requests */ /* Memory management. */ map(SYS_NEWMAP, do_newmap); /* set up a process memory map */ map(SYS_SEGCTL, do_segctl); /* add segment and get selector */ map(SYS_MEMSET, do_memset); /* write char to memory area */ map(SYS_VMCTL, do_vmctl); /* various VM process settings */ /* Copying. */ map(SYS_UMAP, do_umap); /* map virtual to physical address */ map(SYS_VIRCOPY, do_vircopy); /* use pure virtual addressing */ map(SYS_PHYSCOPY, do_copy); /* use physical addressing */ map(SYS_VIRVCOPY, do_virvcopy); /* vector with copy requests */ map(SYS_PHYSVCOPY, do_vcopy); /* vector with copy requests */ map(SYS_SAFECOPYFROM, do_safecopy); /* copy with pre-granted permission */ map(SYS_SAFECOPYTO, do_safecopy); /* copy with pre-granted permission */ map(SYS_VSAFECOPY, do_vsafecopy); /* vectored safecopy */ /* Clock functionality. */ map(SYS_TIMES, do_times); /* get uptime and process times */ map(SYS_SETALARM, do_setalarm); /* schedule a synchronous alarm */ map(SYS_STIME, do_stime); /* set the boottime */ map(SYS_VTIMER, do_vtimer); /* set or retrieve a virtual timer */ /* System control. */ map(SYS_ABORT, do_abort); /* abort MINIX */ map(SYS_GETINFO, do_getinfo); /* request system information */ map(SYS_SYSCTL, do_sysctl); /* misc system manipulation */ /* Profiling. */ map(SYS_SPROF, do_sprofile); /* start/stop statistical profiling */ map(SYS_CPROF, do_cprofile); /* get/reset call profiling data */ map(SYS_PROFBUF, do_profbuf); /* announce locations to kernel */ /* i386-specific. */ #if _MINIX_CHIP == _CHIP_INTEL map(SYS_INT86, do_int86); /* real-mode BIOS calls */ map(SYS_READBIOS, do_readbios); /* read from BIOS locations */ map(SYS_IOPENABLE, do_iopenable); /* Enable I/O */ map(SYS_SDEVIO, do_sdevio); /* phys_insb, _insw, _outsb, _outsw */ map(SYS_MAPDMA, do_mapdma); #endif }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the process manager. * Memory use info is collected from the boot monitor, the kernel, and * all processes compiled into the system image. Initially this information * is put into an array mem_chunks. Elements of mem_chunks are struct memory, * and hold base, size pairs in units of clicks. This array is small, there * should be no more than 8 chunks. After the array of chunks has been built * the contents are used to initialize the hole list. Space for the hole list * is reserved as an array with twice as many elements as the maximum number * of processes allowed. It is managed as a linked list, and elements of the * array are struct hole, which, in addition to storage for a base and size in * click units also contain space for a link, a pointer to another element. */ int s; static struct boot_image image[NR_BOOT_PROCS]; register struct boot_image *ip; static char core_sigs[] = { SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGEMT, SIGFPE, SIGBUS, SIGSEGV }; static char ign_sigs[] = { SIGCHLD, SIGWINCH, SIGCONT }; static char noign_sigs[] = { SIGILL, SIGTRAP, SIGEMT, SIGFPE, SIGBUS, SIGSEGV }; register struct mproc *rmp; register char *sig_ptr; message mess; /* Initialize process table, including timers. */ for (rmp=&mproc[0]; rmp<&mproc[NR_PROCS]; rmp++) { tmr_inittimer(&rmp->mp_timer); } /* Build the set of signals which cause core dumps, and the set of signals * that are by default ignored. */ sigemptyset(&core_sset); for (sig_ptr = core_sigs; sig_ptr < core_sigs+sizeof(core_sigs); sig_ptr++) sigaddset(&core_sset, *sig_ptr); sigemptyset(&ign_sset); for (sig_ptr = ign_sigs; sig_ptr < ign_sigs+sizeof(ign_sigs); sig_ptr++) sigaddset(&ign_sset, *sig_ptr); sigemptyset(&noign_sset); for (sig_ptr = noign_sigs; sig_ptr < noign_sigs+sizeof(noign_sigs); sig_ptr++) sigaddset(&noign_sset, *sig_ptr); /* Obtain a copy of the boot monitor parameters and the kernel info struct. * Parse the list of free memory chunks. This list is what the boot monitor * reported, but it must be corrected for the kernel and system processes. */ if ((s=sys_getmonparams(monitor_params, sizeof(monitor_params))) != OK) panic("get monitor params failed: %d", s); if ((s=sys_getkinfo(&kinfo)) != OK) panic("get kernel info failed: %d", s); /* Initialize PM's process table. Request a copy of the system image table * that is defined at the kernel level to see which slots to fill in. */ if (OK != (s=sys_getimage(image))) panic("couldn't get image table: %d", s); procs_in_use = 0; /* start populating table */ for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) { if (ip->proc_nr >= 0) { /* task have negative nrs */ procs_in_use += 1; /* found user process */ /* Set process details found in the image table. */ rmp = &mproc[ip->proc_nr]; strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN); rmp->mp_nice = get_nice_value(ip->priority); sigemptyset(&rmp->mp_ignore); sigemptyset(&rmp->mp_sigmask); sigemptyset(&rmp->mp_catch); if (ip->proc_nr == INIT_PROC_NR) { /* user process */ /* INIT is root, we make it father of itself. This is * not really OK, INIT should have no father, i.e. * a father with pid NO_PID. But PM currently assumes * that mp_parent always points to a valid slot number. */ rmp->mp_parent = INIT_PROC_NR; rmp->mp_procgrp = rmp->mp_pid = INIT_PID; rmp->mp_flags |= IN_USE; } else { /* system process */ if(ip->proc_nr == RS_PROC_NR) { rmp->mp_parent = INIT_PROC_NR; } else { rmp->mp_parent = RS_PROC_NR; } rmp->mp_pid = get_free_pid(); rmp->mp_flags |= IN_USE | PRIV_PROC; } /* Get kernel endpoint identifier. */ rmp->mp_endpoint = ip->endpoint; /* Set scheduling info */ rmp->mp_scheduler = KERNEL; /* Tell FS about this system process. */ mess.m_type = PM_INIT; mess.PM_SLOT = ip->proc_nr; mess.PM_PID = rmp->mp_pid; mess.PM_PROC = rmp->mp_endpoint; if (OK != (s=send(FS_PROC_NR, &mess))) panic("can't sync up with FS: %d", s); } } /* Tell FS that no more system processes follow and synchronize. */ mess.PR_ENDPT = NONE; if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK) panic("can't sync up with FS"); #if (CHIP == INTEL) uts_val.machine[0] = 'i'; strcpy(uts_val.machine + 1, itoa(getprocessor())); #endif system_hz = sys_hz(); /* Map out our own text and data. This is normally done in crtso.o * but PM is an exception - we don't get to talk to VM so early on. * That's why we override munmap() and munmap_text() in utility.c. * * _minix_unmapzero() is the same code in crtso.o that normally does * it on startup. It's best that it's there as crtso.o knows exactly * what the ranges are of the filler data. */ unmap_ok = 1; _minix_unmapzero(); return(OK); }