tmp_buf += left;
tmp_phys += left;
}
-#else /* CHIP != INTEL */
- tmp_phys = vir2phys(tmp_buf);
#endif /* CHIP != INTEL */
}
#include "driver.h"
#include "drvlib.h"
+#include <unistd.h>
/* Extended partition? */
#define ext_part(s) ((s) == 0x05 || (s) == 0x0F)
/* Read the partition table at 'offset'. */
if (proc_nr == NONE) {
+#if DEAD_CODE
+ if ((s=getprocnr(&proc_nr)) != OK) {
+#endif
if ((s=sys_getprocnr(&proc_nr,0,0)) != OK) {
printf("%s: can't get own proc nr: %d\n", (*dp->dr_name)(), s);
return(0);
int r;
/* Try to get a fresh copy of the buffer with kernel messages. */
+ r=0;
if ((r=sys_getkmessages(&kmess)) != OK) {
- printf("TTY: couldn't get copy of kmessages: %d\n", r);
+ printf("TTY: couldn't get copy of kmessages: %d, 0x%x\n", r,r);
return;
}
#define EBADREQUEST (_SIGN 107) /* destination cannot handle request */
#define EDONTREPLY (_SIGN 201) /* pseudo-code: don't send a reply */
-/* The following error codes are generated by the kernel itself. */
-#if DEAD_CODE /* replaced by above codes */
-#ifdef _SYSTEM
-#define E_TRY_AGAIN -1003 /* can't send -- tables full */
-#define E_TASK -1006 /* can't send to task */
-#define E_OVERRUN -1004 /* interrupt for task that is not waiting */
-#define E_NO_PERM -1008 /* ordinary users can't send to tasks */
-#define E_BAD_DEST -1001 /* destination address illegal */
-#define E_BAD_BUF -1005 /* message buf outside caller's addr space */
-#define E_BAD_FCN -1009 /* unknown (illegal) request type */
-#define E_BAD_ADDR -1010 /* bad address given to utility routine */
-#define E_BAD_PROC -1011 /* bad proc number given to utility */
-
-#define E_BAD_REQUEST -1009 /* unknown (illegal) request type */
-#define E_DONT_REPLY -2000 /* pseudo-code: do not send a reply message */
-#endif /* DEAD_CODE */
-
-#endif /* _SYSTEM */
#endif /* _ERRNO_H */
#define IDLE -4 /* runs when no one else can run */
#define CLOCK -3 /* alarms and other clock functions */
#define SYSTASK -2 /* request system functionality */
-#define HARDWARE -1 /* used as source on notify() messages */
+#define KERNEL -1 /* used as source on notify() messages */
+#define HARDWARE KERNEL /* for hardware interrupt handlers */
/* Number of tasks. Note that NR_PROCS is defined in <minix/config.h>. */
#define NR_TASKS 4
phys_bytes bootdev_size;
phys_bytes params_base; /* parameters passed by boot monitor */
phys_bytes params_size;
- long notify_held;
- long notify_blocked;
- long notify_switching;
- long notify_reenter;
- long notify_taskcall;
- long notify_ok;
- long notify_unhold;
- long notify_int;
- long notify_alarm;
- long notify_sig;
- long notify_kmess;
- long notify_stop;
+ long nr_ntf_pending;
int nr_procs; /* number of user processes */
int nr_tasks; /* number of kernel tasks */
char version[8]; /* kernel version number */
*/
if (result != EDONTREPLY) {
m.m_type = result;
- lock_send(CLOCK, m.m_source, &m);
+ lock_send(m.m_source, &m);
}
}
}
*
* Many global global and static variables are accessed here. The safety
* of this must be justified. Most of them are not changed here:
- * k_reenter:
- * This safely tells if the clock interrupt is nested.
* proc_ptr, bill_ptr:
* These are used for accounting. It does not matter if proc.c
* is changing them, provided they are always valid pointers,
pending_ticks += ticks;
now = realtime + pending_ticks;
- rp = (k_reenter == 0) ? proc_ptr : proc_addr(HARDWARE);
- rp->user_time += ticks;
- if (rp != bill_ptr && rp != proc_addr(IDLE)) bill_ptr->sys_time += ticks;
+ /* Update administration. */
+ proc_ptr->user_time += ticks;
+ if (proc_ptr != bill_ptr) bill_ptr->sys_time += ticks;
/* Check if do_clocktick() must be called. Done for alarms and scheduling.
* If bill_ptr == prev_ptr, there are no ready users so don't need sched().
&& rdy_head[PPRI_USER] != NIL_PROC))
{
m.NOTIFY_TYPE = HARD_INT;
- lock_notify(HARDWARE, CLOCK, &m);
+ lock_notify(CLOCK, &m);
}
else if (--sched_ticks == 0) {
- sched_ticks = SCHED_RATE; /* reset quantum */
+ sched_ticks = SCHED_RATE; /* reset the quantum */
prev_ptr = bill_ptr; /* new previous process */
}
return(1); /* reenable clock interrupts */
* flag shutting_down must be initialized to FALSE. We rely on the compiler's
* default initialization (0) of global variables here.
*/
-EXTERN int skip_stop_sequence; /* set to TRUE in case of an exception() */
-EXTERN int shutting_down; /* TRUE if the system is shutting down */
+EXTERN char skip_stop_sequence; /* set to TRUE in case of an exception() */
+EXTERN char shutting_down; /* TRUE if the system is shutting down */
EXTERN struct proc *shutdown_process; /* process awaiting shutdown of */
EXTERN timer_t shutdown_timer; /* watchdog function called after timeout */
EXTERN struct kmessages kmess; /* diagnostic messages in kernel */
EXTERN struct memory mem[NR_MEMS]; /* base and size of chunks of memory */
-/* Process table. Here to stop too many things having to include proc.h. */
+/* Process scheduling info and kernel entry count. */
EXTERN struct proc *proc_ptr; /* pointer to currently running process */
-
-/* Miscellaneous. */
+EXTERN struct proc *next_ptr; /* pointer to next process to run */
EXTERN char k_reenter; /* kernel reentry count (entry count less 1) */
EXTERN unsigned lost_ticks; /* clock ticks counted outside clock task */
*/
#include "kernel.h"
+#include "proc.h"
+#include <minix/com.h>
#define ICW1_AT 0x11 /* edge triggered, cascade, need ICW4 */
#define ICW1_PC 0x13 /* edge triggered, no cascade, need ICW4 */
kmess.km_next = (kmess.km_next + 1) % KMESS_BUF_SIZE;
} else {
m.NOTIFY_TYPE = NEW_KMESS;
- lock_notify(HARDWARE, TTY, &m);
+ lock_notify(TTY, &m);
}
}
* primary console for stop sequence output, and one to actually exit.
*/
m.NOTIFY_TYPE = HARD_STOP;
- lock_notify(HARDWARE, TTY, &m);
+ lock_notify(TTY, &m);
/* Run the stop sequence. The timer argument passes the shutdown status.
* The stop sequence is skipped for fatal CPU exceptions.
shutdown_process = p; /* directly continue if exited */
m.NOTIFY_TYPE = HARD_STOP;
m.NOTIFY_ARG = tmr_arg(tp)->ta_int; /* how */
- lock_notify(HARDWARE, proc_number(p), &m);
+ lock_notify(proc_number(p), &m);
set_timer(tp, get_uptime()+STOP_TICKS, stop_sequence);
return; /* allow the process to shut down */
}
prepare_shutdown(RBT_PANIC);
}
-
+#if ENABLE_K_DEBUGGING
/*===========================================================================*
* print_bitmap *
*===========================================================================*/
}
kprintf("\n", NO_ARG);
}
+#endif /* ENABLE_K_DEBUGGING */
/*===========================================================================*
* free_bit *
!* hwint00 - 07 *
!*===========================================================================*
! Note this is a macro, it just looks like a subroutine.
-#define hwint_master_slave_fail(irq) \
- call save /* save interrupted process state */;\
- cli ;\
- inb INT2_CTLMASK /* get current mask */ ;\
- movb ah, al ;\
- inb INT_CTLMASK /* get current mask */ ;\
- push eax ;\
- cli ;\
- movb al, ~[0] ;\
- outb INT_CTLMASK /* mask all */;\
- outb INT2_CTLMASK /* */;\
- cli ;\
- push (_irq_handlers+4*irq) /* irq_handlers[irq] */;\
- call _intr_handle /* intr_handle(irq_handlers[irq]) */;\
- pop ecx ;\
- pop eax ;\
- cmp (_irq_actids+4*irq), 0 /* interrupt still active? */;\
- jz 0f ;\
- or eax, [1<<irq] /* mask irq */ ;\
-0: outb INT_CTLMASK /* restore master irq mask */;\
- movb al, ah ;\
- outb INT2_CTLMASK /* restore slave irq mask */;\
- movb al, END_OF_INT ;\
- outb INT_CTL /* reenable master 8259 */;\
- cmp (irq), 8 ;\
- jb 1f ;\
- outb INT2_CTL /* reenable slave 8259 */;\
-1: ret /* restart (another) process */
-
#define hwint_master(irq) \
call save /* save interrupted process state */;\
push (_irq_handlers+4*irq) /* irq_handlers[irq] */;\
! Restart the current process or the next process if it is set.
- mov esp, (_proc_ptr) ! will assume P_STACKBASE == 0
- lldt P_LDT_SEL(esp) ! enable segment descriptors for task
+ cmp (_next_ptr), 0 ! see if another process is scheduled
+ jz 0f
+ mov eax, (_next_ptr)
+ mov (_proc_ptr), eax
+ mov (_next_ptr), 0
+0: mov esp, (_proc_ptr) ! will assume P_STACKBASE == 0
+ lldt P_LDT_SEL(esp) ! enable process' segment descriptors
lea eax, P_STACKTOP(esp) ! arrange for next interrupt
mov (_tss+TSS3_S_SP0), eax ! to save state in process table
restart1:
/* Now check if the call is known and try to perform the request. The only
* system calls that exist in MINIX are sending and receiving messages.
- * Receiving is straightforward. Sending requires checks to see if sending
- * is allowed by the caller's send mask and to see if the destination is
- * alive.
+ * Receiving is straightforward. Sending requires to check caller's send
+ * mask and whether the destination is alive.
*/
else {
switch(function) {
sizeof(struct notification);
*ntf_q_pp = (*ntf_q_pp)->n_next;/* remove from queue */
free_bit(bit_nr, notify_bitmap, NR_NOTIFY_BUFS);
+ kinfo.nr_ntf_pending --;
return(OK); /* report success */
}
ntf_q_pp = &(*ntf_q_pp)->n_next; /* proceed to next */
/* Add to end of queue. Get a free notification buffer. */
if ((ntf_index = alloc_bit(notify_bitmap, NR_NOTIFY_BUFS)) < 0)
return(ENOSPC); /* should be atomic! */
+ kinfo.nr_ntf_pending ++;
ntf_p = ¬ify_buffer[ntf_index];
ntf_p->n_source = proc_number(caller_ptr);
ntf_p->n_type = m_ptr->NOTIFY_TYPE;
/*==========================================================================*
* lock_notify *
*==========================================================================*/
-PUBLIC int lock_notify(src, dst, m_ptr)
-int src; /* who is trying to send a message? */
+PUBLIC int lock_notify(dst, m_ptr)
int dst; /* to whom is message being sent? */
message *m_ptr; /* pointer to message buffer */
{
-/* Safe gateway to mini_notify() for tasks. */
+/* Safe gateway to mini_notify() for tasks and interrupt handlers. This
+ * function checks if it is called from an interrupt handler and makes sure
+ * that the correct message source is put on the notification. All kernel
+ * generated notifications share the same pseudo-process number, to prevent
+ * conflicts with SENDREC calls to the kernel task.
+ */
int result;
+ struct proc *caller_ptr;
+
lock();
- result = mini_notify(proc_addr(src), dst, m_ptr);
+ caller_ptr = (k_reenter >= 0 || istaskp(proc_ptr)) ?
+ proc_addr(KERNEL) : proc_ptr;
+ result = mini_notify(caller_ptr, dst, m_ptr);
unlock();
return(result);
}
*===========================================================================*/
PRIVATE void pick_proc()
{
-/* Decide who to run now. A new process is selected by setting 'proc_ptr'.
+/* Decide who to run now. A new process is selected by setting 'next_ptr'.
* When a fresh user (or idle) process is selected, record it in 'bill_ptr',
* so the clock task can tell who to bill for system time.
*/
*/
for (q=0; q < NR_SCHED_QUEUES; q++) {
if ( (rp = rdy_head[q]) != NIL_PROC) {
- proc_ptr = rp; /* run process 'rp' next */
+ next_ptr = rp; /* run process 'rp' next */
if (isuserp(rp) || isidlep(rp)) /* possible bill 'rp' */
bill_ptr = rp;
return;
register struct proc *rp; /* this process is now runnable */
{
/* Add 'rp' to one of the queues of runnable processes. */
- int q = rp->p_priority; /* scheduling queue to use */
+ register int q = rp->p_priority; /* scheduling queue to use */
#if ENABLE_K_DEBUGGING
if(rp->p_ready) {
rp->p_nextready = NIL_PROC;
}
- /* Run 'rp' next if it has a higher priority than 'proc_ptr'. This actually
- * should be done via pick_proc(), but the message passing functions rely
- * on this side-effect.
+ /* Run 'rp' next if it has a higher priority than 'proc_ptr' or 'next_ptr'.
+ * This actually should be done via pick_proc(), but the message passing
+ * functions rely on this side-effect. High priorities have a lower number.
*/
+ if (next_ptr && next_ptr->p_priority > rp->p_priority) next_ptr = rp;
+ else if (proc_ptr->p_priority > rp->p_priority) next_ptr = rp;
+
+#if DEAD_CODE
if (rp->p_priority < proc_ptr->p_priority) proc_ptr = rp;
+#endif
}
/*===========================================================================*
register struct proc *xp;
register struct proc **qtail; /* queue's rdy_tail */
- int q = rp->p_priority; /* queue to use */
+ register int q = rp->p_priority; /* queue to use */
#if ENABLE_K_DEBUGGING
if(!rp->p_ready) {
if ( (xp = rdy_head[q]) != NIL_PROC) { /* ready queue is empty */
if (xp == rp) { /* check head of queue */
rdy_head[q] = xp->p_nextready; /* new head of queue */
- if (rp == proc_ptr) /* current process removed */
+ if (rp == proc_ptr || rp == next_ptr) /* current process removed */
pick_proc(); /* pick new process to run */
if(rp == rdy_tail[q])
rdy_tail[q] = NIL_PROC;
/*==========================================================================*
* lock_send *
*==========================================================================*/
-PUBLIC int lock_send(src, dst, m_ptr)
-int src; /* who is trying to send a message? */
+PUBLIC int lock_send(dst, m_ptr)
int dst; /* to whom is message being sent? */
message *m_ptr; /* pointer to message buffer */
{
/* Safe gateway to mini_send() for tasks. */
int result;
lock();
- result = mini_send(proc_addr(src), dst, m_ptr, FALSE);
+ result = mini_send(proc_ptr, dst, m_ptr, FALSE);
unlock();
return(result);
}
* 'proc', be sure to change sconst.h to match.
*
* Changes:
+ * May 24, 2005 new field for pending notifications (Jorrit N. Herder)
* Nov 10, 2004 separated process types/ priorities (Jorrit N. Herder)
- * Sep 30, 2004 bit masks for notifications (Jorrit N. Herder)
* Sep 24, 2004 one timer per type of alarm (Jorrit N. Herder)
* May 01, 2004 new p_sendmask to protect syscalls (Jorrit N. Herder)
*/
struct stackframe_s p_reg; /* process' registers saved in stack frame */
#if (CHIP == INTEL)
- reg_t p_ldt_sel; /* selector in gdt giving ldt base and limit*/
+ reg_t p_ldt_sel; /* selector in gdt with ldt base and limit */
struct segdesc_s p_ldt[2+NR_REMOTE_SEGS]; /* CS, DS and remote segments */
#endif /* (CHIP == INTEL) */
reg_t *p_stguard; /* stack guard word */
proc_nr_t p_nr; /* number of this process (for fast access) */
-
- int p_flags; /* SENDING, RECEIVING, etc. */
struct mem_map p_memmap[NR_LOCAL_SEGS]; /* local memory map (T, D, S) */
struct far_mem p_farmem[NR_REMOTE_SEGS]; /* remote memory map */
+
+ short p_flags; /* SENDING, RECEIVING, etc. */
char p_type; /* task, system, driver, server, user, idle */
char p_priority; /* scheduling priority */
timer_t p_flagalrm; /* flag alarm timer */
timer_t p_syncalrm; /* synchronous alarm timer */
- send_mask_t p_sendmask; /* mask indicating to whom proc may send */
+ struct proc *p_nextready; /* pointer to next ready process */
+ struct notification *p_ntf_q; /* queue of pending notifications */
struct proc *p_caller_q; /* head of list of procs wishing to send */
struct proc *p_sendlink; /* link to next proc wishing to send */
message *p_messbuf; /* pointer to message buffer */
- int p_getfrom; /* from whom does process want to receive? */
- int p_sendto; /* to whom does process want to send? */
-
- struct notification *p_ntf_q; /* queue of pending notifications */
+ proc_nr_t p_getfrom; /* from whom does process want to receive? */
+ proc_nr_t p_sendto; /* to whom does process want to send? */
+ send_mask_t p_sendmask; /* mask indicating to whom proc may send */
- struct proc *p_nextready; /* pointer to next ready process */
sigset_t p_pending; /* bit map for pending signals */
unsigned p_pendcount; /* count of pending and unfinished signals */
/* proc.c */
_PROTOTYPE( int sys_call, (int function, int src_dest, message *m_ptr) );
-_PROTOTYPE( int lock_notify, (int src, int dst, message *m_ptr) );
-_PROTOTYPE( int lock_send, (int src, int dst, message *m_ptr) );
+_PROTOTYPE( int lock_notify, (int dst, message *m_ptr) );
+_PROTOTYPE( int lock_send, (int dst, message *m_ptr) );
_PROTOTYPE( void lock_pick_proc, (void) );
_PROTOTYPE( void lock_ready, (struct proc *rp) );
_PROTOTYPE( void lock_sched, (void) );
_PROTOTYPE( void put_irq_handler, (irq_hook_t *hook, int irq,
irq_handler_t handler) );
_PROTOTYPE( int rm_irq_handler, (int irq, int id) );
+
/* klib*.s */
_PROTOTYPE( void int86, (void) );
_PROTOTYPE( void cp_mess, (int src,phys_clicks src_clicks,vir_bytes src_offset,
*/
if (result != EDONTREPLY) {
m.m_type = result; /* report status of call */
- lock_send(SYSTASK, m.m_source, &m);
+ lock_send(m.m_source, &m);
}
}
}
message m;
m.NOTIFY_TYPE = HARD_INT;
m.NOTIFY_ARG = hook->irq;
- lock_notify(HARDWARE, hook->proc_nr, &m);
+ lock_notify(hook->proc_nr, &m);
return(hook->policy & IRQ_REENABLE);
}
m.NOTIFY_TYPE = KSIG_PENDING;
m.NOTIFY_ARG = 0;
m.NOTIFY_FLAGS = 0;
- lock_notify(HARDWARE, PM_PROC_NR, &m);
+ lock_notify(PM_PROC_NR, &m);
}
* process given with a SYN_ALARM message.
*/
message m;
- m.NOTIFY_SOURCE = HARDWARE;
+ m.NOTIFY_SOURCE = SYSTASK;
m.NOTIFY_TYPE = SYN_ALARM;
m.NOTIFY_ARG = get_uptime();
m.NOTIFY_FLAGS = 0;
- lock_notify(HARDWARE, tmr_arg(tp)->ta_int, &m);
+ lock_notify(tmr_arg(tp)->ta_int, &m);
}
}
case GET_PROCNR: {
if (m_ptr->I_KEY_LEN == 0) { /* get own process nr */
-#if DEAD_CODE
/* GET_PROCNR functionality will be moved to the Process Manager! */
kprintf("GET_PROCNR (own) from %d\n", m_ptr->m_source);
-#endif
src_phys = vir2phys(&proc_nr);
length = sizeof(int);
} else { /* lookup nr by name */
struct proc *pp;
struct vir_addr vsrc, vdst;
char key[8]; /* storage for process name to lookup */
-#if DEAD_CODE
/* GET_PROCNR functionality will be moved to the Process Manager! */
kprintf("GET_PROCNR (by name) from %d\n", m_ptr->m_source);
-#endif
proc_nr = m_ptr->m_source; /* only caller can request copy */
if (m_ptr->I_KEY_LEN > sizeof(key)) return(EINVAL);
vsrc.proc_nr = proc_nr; vsrc.segment = D; vsrc.offset = (vir_bytes) m_ptr->I_KEY_PTR;
source= mq->mq_mess.m_source;
if (source == FS_PROC_NR) {
sr_rec(mq);
- } else if (source == HARDWARE) /* a notification! */
+ } else if (mq->mq_mess.m_type & NOTIFICATION )
{
if (mq->mq_mess.m_type == SYN_ALARM) {
clck_tick(&mq->mq_mess);
printf("- bootdev_size: %5u\n", kinfo.bootdev_size);
printf("- params_base: %5u\n", kinfo.params_base);
printf("- params_size: %5u\n", kinfo.params_size);
- printf("- notify_blocked:%8u\n", kinfo.notify_blocked);
- printf("- notify_ok: %8u\n", kinfo.notify_ok);
- printf("- notify_held: %8u\n", kinfo.notify_held);
- printf("- notify_switch: %8u\n", kinfo.notify_switching);
- printf("- notify_reenter:%8u\n", kinfo.notify_reenter);
- printf("- notify_taskcall:%7u\n", kinfo.notify_taskcall);
- printf("- notify_unhold: %8u\n", kinfo.notify_unhold);
- printf("- hard_int: %8u\n", kinfo.notify_int);
- printf("- hard_stop: %8u\n", kinfo.notify_stop);
- printf("- sync_alarm: %8u\n", kinfo.notify_alarm);
- printf("- ksig_pending: %8u\n", kinfo.notify_sig);
- printf("- new_kmess: %8u\n", kinfo.notify_kmess);
+ printf("- notify_pending:%8u\n", kinfo.nr_ntf_pending);
printf("- nr_procs: %3u\n", kinfo.nr_procs);
printf("- nr_tasks: %3u\n", kinfo.nr_tasks);
printf("- version: %.6s\n", kinfo.version);
phys_clicks new_base;
static char zero[1024]; /* used to zero bss */
phys_bytes bytes, base, count, bss_offset;
+ int s;
/* No need to allocate text if it can be shared. */
if (sh_mp != NULL) text_bytes = 0;
while (bytes > 0) {
count = MIN(bytes, (phys_bytes) sizeof(zero));
- if (sys_physcopy(PM_PROC_NR, D, (phys_bytes) zero,
- NONE, PHYS_SEG, base, count) != OK) {
- panic("new_mem can't zero", NO_NUM);
+ if ((s=sys_physcopy(PM_PROC_NR, D, (phys_bytes) zero,
+ NONE, PHYS_SEG, base, count)) != OK) {
+ panic("new_mem can't zero", s);
}
base += count;
bytes -= count;