2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains the printer driver. It is a fairly simple driver,
|
|
|
|
* supporting only one printer. Characters that are written to the driver
|
|
|
|
* are written to the printer without any changes at all.
|
|
|
|
*
|
|
|
|
* Changes:
|
2005-04-29 17:36:43 +02:00
|
|
|
* May 07, 2004 fix: wait until printer is ready (Jorrit N. Herder)
|
2005-04-21 16:53:53 +02:00
|
|
|
* May 06, 2004 printer driver moved to user-space (Jorrit N. Herder)
|
|
|
|
*
|
|
|
|
* The valid messages and their parameters are:
|
|
|
|
*
|
|
|
|
* DEV_OPEN: initializes the printer
|
|
|
|
* DEV_CLOSE: does nothing
|
|
|
|
* HARD_INT: interrupt handler has finished current chunk of output
|
|
|
|
* DEV_WRITE: a process wants to write on a terminal
|
2005-06-24 18:21:54 +02:00
|
|
|
* CANCEL: terminate a previous incomplete system call immediately
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2006-03-03 11:21:45 +01:00
|
|
|
* m_type TTY_LINE IO_ENDPT COUNT ADDRESS
|
2005-04-21 16:53:53 +02:00
|
|
|
* |-------------+---------+---------+---------+---------|
|
|
|
|
* | DEV_OPEN | | | | |
|
|
|
|
* |-------------+---------+---------+---------+---------|
|
|
|
|
* | DEV_CLOSE | | proc nr | | |
|
|
|
|
* -------------------------------------------------------
|
|
|
|
* | HARD_INT | | | | |
|
|
|
|
* |-------------+---------+---------+---------+---------|
|
2005-07-26 14:50:25 +02:00
|
|
|
* | SYS_EVENT | | | | |
|
2005-04-21 16:53:53 +02:00
|
|
|
* |-------------+---------+---------+---------+---------|
|
|
|
|
* | DEV_WRITE |minor dev| proc nr | count | buf ptr |
|
|
|
|
* |-------------+---------+---------+---------+---------|
|
|
|
|
* | CANCEL |minor dev| proc nr | | |
|
|
|
|
* -------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Note: since only 1 printer is supported, minor dev is not used at present.
|
|
|
|
*/
|
|
|
|
|
2009-09-29 20:47:56 +02:00
|
|
|
#include <minix/endpoint.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "../drivers.h"
|
|
|
|
|
|
|
|
/* Control bits (in port_base + 2). "+" means positive logic and "-" means
|
|
|
|
* negative logic. Most of the signals are negative logic on the pins but
|
|
|
|
* many are converted to positive logic in the ports. Some manuals are
|
|
|
|
* misleading because they only document the pin logic.
|
|
|
|
*
|
|
|
|
* +0x01 Pin 1 -Strobe
|
|
|
|
* +0x02 Pin 14 -Auto Feed
|
|
|
|
* -0x04 Pin 16 -Initialize Printer
|
|
|
|
* +0x08 Pin 17 -Select Printer
|
|
|
|
* +0x10 IRQ7 Enable
|
|
|
|
*
|
|
|
|
* Auto Feed and Select Printer are always enabled. Strobe is enabled briefly
|
|
|
|
* when characters are output. Initialize Printer is enabled briefly when
|
|
|
|
* the task is started. IRQ7 is enabled when the first character is output
|
|
|
|
* and left enabled until output is completed (or later after certain
|
|
|
|
* abnormal completions).
|
|
|
|
*/
|
|
|
|
#define ASSERT_STROBE 0x1D /* strobe a character to the interface */
|
|
|
|
#define NEGATE_STROBE 0x1C /* enable interrupt on interface */
|
2005-06-06 13:40:32 +02:00
|
|
|
#define PR_SELECT 0x0C /* select printer bit */
|
2005-04-21 16:53:53 +02:00
|
|
|
#define INIT_PRINTER 0x08 /* init printer bits */
|
|
|
|
|
|
|
|
/* Status bits (in port_base + 2).
|
|
|
|
*
|
|
|
|
* -0x08 Pin 15 -Error
|
|
|
|
* +0x10 Pin 13 +Select Status
|
|
|
|
* +0x20 Pin 12 +Out of Paper
|
|
|
|
* -0x40 Pin 10 -Acknowledge
|
|
|
|
* -0x80 Pin 11 +Busy
|
|
|
|
*/
|
|
|
|
#define BUSY_STATUS 0x10 /* printer gives this status when busy */
|
|
|
|
#define NO_PAPER 0x20 /* status bit saying that paper is out */
|
|
|
|
#define NORMAL_STATUS 0x90 /* printer gives this status when idle */
|
|
|
|
#define ON_LINE 0x10 /* status bit saying that printer is online */
|
|
|
|
#define STATUS_MASK 0xB0 /* mask to filter out status bits */
|
|
|
|
|
|
|
|
#define MAX_ONLINE_RETRIES 120 /* about 60s: waits 0.5s after each retry */
|
|
|
|
|
|
|
|
/* Centronics interface timing that must be met by software (in microsec).
|
|
|
|
*
|
|
|
|
* Strobe length: 0.5u to 100u (not sure about the upper limit).
|
|
|
|
* Data set up: 0.5u before strobe.
|
|
|
|
* Data hold: 0.5u after strobe.
|
|
|
|
* Init pulse length: over 200u (not sure).
|
|
|
|
*
|
|
|
|
* The strobe length is about 50u with the code here and function calls for
|
|
|
|
* sys_outb() - not much to spare. The 0.5u minimums will not be violated
|
|
|
|
* with the sys_outb() messages exchanged.
|
|
|
|
*/
|
|
|
|
|
|
|
|
PRIVATE int caller; /* process to tell when printing done (FS) */
|
2005-07-27 17:04:30 +02:00
|
|
|
PRIVATE int revive_pending; /* set to true if revive is pending */
|
|
|
|
PRIVATE int revive_status; /* revive status */
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE int done_status; /* status of last output completion */
|
|
|
|
PRIVATE int oleft; /* bytes of output left in obuf */
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
PRIVATE unsigned char obuf[128]; /* output buffer */
|
2010-02-09 16:23:38 +01:00
|
|
|
PRIVATE unsigned const char *optr; /* ptr to next char in obuf to print */
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE int orig_count; /* original byte count */
|
|
|
|
PRIVATE int port_base; /* I/O port for printer */
|
|
|
|
PRIVATE int proc_nr; /* user requesting the printing */
|
2006-06-20 11:49:02 +02:00
|
|
|
PRIVATE cp_grant_id_t grant_nr; /* grant on which print happens */
|
2005-04-21 16:53:53 +02:00
|
|
|
PRIVATE int user_left; /* bytes of output left in user buf */
|
2006-06-20 11:49:02 +02:00
|
|
|
PRIVATE vir_bytes user_vir_g; /* start of user buf (address or grant) */
|
|
|
|
PRIVATE vir_bytes user_vir_d; /* offset in user buf */
|
|
|
|
PRIVATE int user_safe; /* address or grant? */
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
PUBLIC int writing; /* nonzero while write is in progress */
|
2005-05-02 16:30:04 +02:00
|
|
|
PRIVATE int irq_hook_id; /* id of irq hook at kernel */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
FORWARD _PROTOTYPE( void do_cancel, (message *m_ptr) );
|
|
|
|
FORWARD _PROTOTYPE( void output_done, (void) );
|
2006-06-20 11:49:02 +02:00
|
|
|
FORWARD _PROTOTYPE( void do_write, (message *m_ptr, int safe) );
|
2005-07-27 17:04:30 +02:00
|
|
|
FORWARD _PROTOTYPE( void do_status, (message *m_ptr) );
|
2005-04-21 16:53:53 +02:00
|
|
|
FORWARD _PROTOTYPE( void prepare_output, (void) );
|
|
|
|
FORWARD _PROTOTYPE( void do_initialize, (void) );
|
|
|
|
FORWARD _PROTOTYPE( void reply, (int code,int replyee,int proc,int status));
|
|
|
|
FORWARD _PROTOTYPE( void do_printer_output, (void) );
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
FORWARD _PROTOTYPE( void do_signal, (void) );
|
2005-06-24 18:21:54 +02:00
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF functions and variables. */
|
|
|
|
FORWARD _PROTOTYPE( void sef_local_startup, (void) );
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
FORWARD _PROTOTYPE( int sef_cb_init_fresh, (int type, sef_init_info_t *info) );
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
EXTERN _PROTOTYPE( void sef_cb_lu_prepare, (int state) );
|
|
|
|
EXTERN _PROTOTYPE( int sef_cb_lu_state_isvalid, (int state) );
|
|
|
|
EXTERN _PROTOTYPE( void sef_cb_lu_state_dump, (int state) );
|
|
|
|
PUBLIC int is_status_msg_expected = FALSE;
|
2005-06-24 18:21:54 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* printer_task *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void main(void)
|
|
|
|
{
|
|
|
|
/* Main routine of the printer task. */
|
|
|
|
message pr_mess; /* buffer for all incoming messages */
|
2005-10-12 17:06:00 +02:00
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF local startup. */
|
|
|
|
sef_local_startup();
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
while (TRUE) {
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
sef_receive(ANY, &pr_mess);
|
2009-09-29 20:47:56 +02:00
|
|
|
|
|
|
|
if (is_notify(pr_mess.m_type)) {
|
|
|
|
switch (_ENDPOINT_P(pr_mess.m_source)) {
|
|
|
|
case HARDWARE:
|
|
|
|
do_printer_output();
|
|
|
|
break;
|
|
|
|
case PM_PROC_NR:
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
do_signal();
|
2009-09-29 20:47:56 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
reply(TASK_REPLY, pr_mess.m_source,
|
|
|
|
pr_mess.IO_ENDPT, EINVAL);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
switch(pr_mess.m_type) {
|
|
|
|
case DEV_OPEN:
|
|
|
|
do_initialize(); /* initialize */
|
|
|
|
/* fall through */
|
|
|
|
case DEV_CLOSE:
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, pr_mess.m_source, pr_mess.IO_ENDPT, OK);
|
2005-04-21 16:53:53 +02:00
|
|
|
break;
|
2006-06-20 11:49:02 +02:00
|
|
|
case DEV_WRITE_S: do_write(&pr_mess, 1); break;
|
2005-07-27 17:04:30 +02:00
|
|
|
case DEV_STATUS: do_status(&pr_mess); break;
|
2005-08-05 20:57:20 +02:00
|
|
|
case CANCEL: do_cancel(&pr_mess); break;
|
2005-04-21 16:53:53 +02:00
|
|
|
default:
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, pr_mess.m_source, pr_mess.IO_ENDPT, EINVAL);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void sef_local_startup()
|
|
|
|
{
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/* Register init callbacks. */
|
|
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_lu(sef_cb_init_fresh);
|
|
|
|
sef_setcb_init_restart(sef_cb_init_fresh);
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* Register live update callbacks. */
|
|
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare);
|
|
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid);
|
|
|
|
sef_setcb_lu_state_dump(sef_cb_lu_state_dump);
|
|
|
|
|
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
2005-10-12 17:06:00 +02:00
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_init_fresh *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
|
|
|
|
{
|
|
|
|
/* Initialize the printer driver. */
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
/* Install signal handlers. Ask PM to transform signal into message. */
|
|
|
|
sa.sa_handler = SIG_MESS;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = 0;
|
2010-03-05 16:05:11 +01:00
|
|
|
if (sigaction(SIGTERM,&sa,NULL)<0) panic("sigaction failed: %d", errno);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
2005-10-12 17:06:00 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_signal *
|
|
|
|
*===========================================================================*/
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
PRIVATE void do_signal()
|
2005-10-12 17:06:00 +02:00
|
|
|
{
|
Merge of David's ptrace branch. Summary:
o Support for ptrace T_ATTACH/T_DETACH and T_SYSCALL
o PM signal handling logic should now work properly, even with debuggers
being present
o Asynchronous PM/VFS protocol, full IPC support for senda(), and
AMF_NOREPLY senda() flag
DETAILS
Process stop and delay call handling of PM:
o Added sys_runctl() kernel call with sys_stop() and sys_resume()
aliases, for PM to stop and resume a process
o Added exception for sending/syscall-traced processes to sys_runctl(),
and matching SIGKREADY pseudo-signal to PM
o Fixed PM signal logic to deal with requests from a process after
stopping it (so-called "delay calls"), using the SIGKREADY facility
o Fixed various PM panics due to race conditions with delay calls versus
VFS calls
o Removed special PRIO_STOP priority value
o Added SYS_LOCK RTS kernel flag, to stop an individual process from
running while modifying its process structure
Signal and debugger handling in PM:
o Fixed debugger signals being dropped if a second signal arrives when
the debugger has not retrieved the first one
o Fixed debugger signals being sent to the debugger more than once
o Fixed debugger signals unpausing process in VFS; removed PM_UNPAUSE_TR
protocol message
o Detached debugger signals from general signal logic and from being
blocked on VFS calls, meaning that even VFS can now be traced
o Fixed debugger being unable to receive more than one pending signal in
one process stop
o Fixed signal delivery being delayed needlessly when multiple signals
are pending
o Fixed wait test for tracer, which was returning for children that were
not waited for
o Removed second parallel pending call from PM to VFS for any process
o Fixed process becoming runnable between exec() and debugger trap
o Added support for notifying the debugger before the parent when a
debugged child exits
o Fixed debugger death causing child to remain stopped forever
o Fixed consistently incorrect use of _NSIG
Extensions to ptrace():
o Added T_ATTACH and T_DETACH ptrace request, to attach and detach a
debugger to and from a process
o Added T_SYSCALL ptrace request, to trace system calls
o Added T_SETOPT ptrace request, to set trace options
o Added TO_TRACEFORK trace option, to attach automatically to children
of a traced process
o Added TO_ALTEXEC trace option, to send SIGSTOP instead of SIGTRAP upon
a successful exec() of the tracee
o Extended T_GETUSER ptrace support to allow retrieving a process's priv
structure
o Removed T_STOP ptrace request again, as it does not help implementing
debuggers properly
o Added MINIX3-specific ptrace test (test42)
o Added proper manual page for ptrace(2)
Asynchronous PM/VFS interface:
o Fixed asynchronous messages not being checked when receive() is called
with an endpoint other than ANY
o Added AMF_NOREPLY senda() flag, preventing such messages from
satisfying the receive part of a sendrec()
o Added asynsend3() that takes optional flags; asynsend() is now a
#define passing in 0 as third parameter
o Made PM/VFS protocol asynchronous; reintroduced tell_fs()
o Made PM_BASE request/reply number range unique
o Hacked in a horrible temporary workaround into RS to deal with newly
revealed RS-PM-VFS race condition triangle until VFS is asynchronous
System signal handling:
o Fixed shutdown logic of device drivers; removed old SIGKSTOP signal
o Removed is-superuser check from PM's do_procstat() (aka getsigset())
o Added sigset macros to allow system processes to deal with the full
signal set, rather than just the POSIX subset
Miscellaneous PM fixes:
o Split do_getset into do_get and do_set, merging common code and making
structure clearer
o Fixed setpriority() being able to put to sleep processes using an
invalid parameter, or revive zombie processes
o Made find_proc() global; removed obsolete proc_from_pid()
o Cleanup here and there
Also included:
o Fixed false-positive boot order kernel warning
o Removed last traces of old NOTIFY_FROM code
THINGS OF POSSIBLE INTEREST
o It should now be possible to run PM at any priority, even lower than
user processes
o No assumptions are made about communication speed between PM and VFS,
although communication must be FIFO
o A debugger will now receive incoming debuggee signals at kill time
only; the process may not yet be fully stopped
o A first step has been made towards making the SYSTEM task preemptible
2009-09-30 11:57:22 +02:00
|
|
|
sigset_t sigset;
|
|
|
|
|
|
|
|
if (getsigset(&sigset) != 0) return;
|
2005-10-12 17:06:00 +02:00
|
|
|
|
|
|
|
/* Expect a SIGTERM signal when this server must shutdown. */
|
|
|
|
if (sigismember(&sigset, SIGTERM)) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* Ignore all other signals. */
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_write *
|
|
|
|
*===========================================================================*/
|
2006-06-20 11:49:02 +02:00
|
|
|
PRIVATE void do_write(m_ptr, safe)
|
2005-04-21 16:53:53 +02:00
|
|
|
register message *m_ptr; /* pointer to the newly arrived message */
|
2006-06-20 11:49:02 +02:00
|
|
|
int safe; /* use virtual addresses or grant id's? */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* The printer is used by sending DEV_WRITE messages to it. Process one. */
|
|
|
|
|
|
|
|
register int r = SUSPEND;
|
|
|
|
int retries;
|
2006-03-25 00:05:21 +01:00
|
|
|
unsigned long status;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Reject command if last write is not yet finished, the count is not
|
|
|
|
* positive, or the user address is bad.
|
|
|
|
*/
|
|
|
|
if (writing) r = EIO;
|
|
|
|
else if (m_ptr->COUNT <= 0) r = EINVAL;
|
|
|
|
|
|
|
|
/* Reply to FS, no matter what happened, possible SUSPEND caller. */
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, r);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* If no errors occurred, continue printing with SUSPENDED caller.
|
|
|
|
* First wait until the printer is online to prevent stupid errors.
|
|
|
|
*/
|
|
|
|
if (SUSPEND == r) {
|
|
|
|
caller = m_ptr->m_source;
|
2006-03-03 11:21:45 +01:00
|
|
|
proc_nr = m_ptr->IO_ENDPT;
|
2005-04-21 16:53:53 +02:00
|
|
|
user_left = m_ptr->COUNT;
|
|
|
|
orig_count = m_ptr->COUNT;
|
2006-06-20 11:49:02 +02:00
|
|
|
user_vir_g = (vir_bytes) m_ptr->ADDRESS; /* Address or grant id. */
|
|
|
|
user_vir_d = 0; /* Offset. */
|
|
|
|
user_safe = safe; /* Address or grant? */
|
2005-04-21 16:53:53 +02:00
|
|
|
writing = TRUE;
|
2006-06-20 11:49:02 +02:00
|
|
|
grant_nr = safe ? (cp_grant_id_t) m_ptr->ADDRESS : GRANT_INVALID;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
retries = MAX_ONLINE_RETRIES + 1;
|
|
|
|
while (--retries > 0) {
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_inb(port_base + 1, &status) != OK) {
|
|
|
|
printf("printer: sys_inb of %x failed\n", port_base+1);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_inb failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
if ((status & ON_LINE)) { /* printer online! */
|
|
|
|
prepare_output();
|
|
|
|
do_printer_output();
|
|
|
|
return;
|
|
|
|
}
|
2008-12-11 15:42:23 +01:00
|
|
|
micro_delay(500000); /* wait before retry */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
/* If we reach this point, the printer was not online in time. */
|
|
|
|
done_status = status;
|
|
|
|
output_done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2005-10-12 17:06:00 +02:00
|
|
|
* output_done *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void output_done()
|
|
|
|
{
|
|
|
|
/* Previous chunk of printing is finished. Continue if OK and more.
|
|
|
|
* Otherwise, reply to caller (FS).
|
|
|
|
*/
|
|
|
|
register int status;
|
|
|
|
|
|
|
|
if (!writing) return; /* probably leftover interrupt */
|
|
|
|
if (done_status != OK) { /* printer error occurred */
|
|
|
|
status = EIO;
|
|
|
|
if ((done_status & ON_LINE) == 0) {
|
|
|
|
printf("Printer is not on line\n");
|
|
|
|
} else if ((done_status & NO_PAPER)) {
|
|
|
|
printf("Printer is out of paper\n");
|
|
|
|
status = EAGAIN;
|
|
|
|
} else {
|
|
|
|
printf("Printer error, status is 0x%02X\n", done_status);
|
|
|
|
}
|
|
|
|
/* Some characters have been printed, tell how many. */
|
|
|
|
if (status == EAGAIN && user_left < orig_count) {
|
|
|
|
status = orig_count - user_left;
|
|
|
|
}
|
|
|
|
oleft = 0; /* cancel further output */
|
|
|
|
}
|
|
|
|
else if (user_left != 0) { /* not yet done, continue! */
|
|
|
|
prepare_output();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else { /* done! report back to FS */
|
|
|
|
status = orig_count;
|
|
|
|
}
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
is_status_msg_expected = TRUE;
|
2005-07-27 17:04:30 +02:00
|
|
|
revive_pending = TRUE;
|
|
|
|
revive_status = status;
|
2005-07-29 17:00:22 +02:00
|
|
|
notify(caller);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2005-07-27 17:04:30 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_status *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void do_status(m_ptr)
|
|
|
|
register message *m_ptr; /* pointer to the newly arrived message */
|
|
|
|
{
|
|
|
|
if (revive_pending) {
|
|
|
|
m_ptr->m_type = DEV_REVIVE; /* build message */
|
2006-03-03 11:21:45 +01:00
|
|
|
m_ptr->REP_ENDPT = proc_nr;
|
2005-07-27 17:04:30 +02:00
|
|
|
m_ptr->REP_STATUS = revive_status;
|
2006-06-20 11:49:02 +02:00
|
|
|
m_ptr->REP_IO_GRANT = grant_nr;
|
2005-07-27 17:04:30 +02:00
|
|
|
|
|
|
|
writing = FALSE; /* unmark event */
|
|
|
|
revive_pending = FALSE; /* unmark event */
|
|
|
|
} else {
|
|
|
|
m_ptr->m_type = DEV_NO_STATUS;
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
|
|
|
|
is_status_msg_expected = FALSE;
|
2005-07-27 17:04:30 +02:00
|
|
|
}
|
|
|
|
send(m_ptr->m_source, m_ptr); /* send the message */
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_cancel *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void do_cancel(m_ptr)
|
|
|
|
register message *m_ptr; /* pointer to the newly arrived message */
|
|
|
|
{
|
|
|
|
/* Cancel a print request that has already started. Usually this means that
|
|
|
|
* the process doing the printing has been killed by a signal. It is not
|
|
|
|
* clear if there are race conditions. Try not to cancel the wrong process,
|
|
|
|
* but rely on FS to handle the EINTR reply and de-suspension properly.
|
|
|
|
*/
|
|
|
|
|
2006-03-03 11:21:45 +01:00
|
|
|
if (writing && m_ptr->IO_ENDPT == proc_nr) {
|
2005-04-21 16:53:53 +02:00
|
|
|
oleft = 0; /* cancel output by interrupt handler */
|
|
|
|
writing = FALSE;
|
2005-07-27 17:04:30 +02:00
|
|
|
revive_pending = FALSE;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2006-03-03 11:21:45 +01:00
|
|
|
reply(TASK_REPLY, m_ptr->m_source, m_ptr->IO_ENDPT, EINTR);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void reply(code, replyee, process, status)
|
|
|
|
int code; /* TASK_REPLY or REVIVE */
|
|
|
|
int replyee; /* destination for message (normally FS) */
|
|
|
|
int process; /* which user requested the printing */
|
|
|
|
int status; /* number of chars printed or error code */
|
|
|
|
{
|
|
|
|
/* Send a reply telling FS that printing has started or stopped. */
|
|
|
|
|
|
|
|
message pr_mess;
|
|
|
|
|
|
|
|
pr_mess.m_type = code; /* TASK_REPLY or REVIVE */
|
|
|
|
pr_mess.REP_STATUS = status; /* count or EIO */
|
2006-03-03 11:21:45 +01:00
|
|
|
pr_mess.REP_ENDPT = process; /* which user does this pertain to */
|
2005-04-21 16:53:53 +02:00
|
|
|
send(replyee, &pr_mess); /* send the message */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_initialize *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void do_initialize()
|
|
|
|
{
|
|
|
|
/* Set global variables and initialize the printer. */
|
|
|
|
static int initialized = FALSE;
|
|
|
|
if (initialized) return;
|
|
|
|
initialized = TRUE;
|
|
|
|
|
2005-05-02 16:30:04 +02:00
|
|
|
/* Get the base port for first printer. */
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_vircopy(SELF, BIOS_SEG, LPT1_IO_PORT_ADDR,
|
|
|
|
SELF, D, (vir_bytes) &port_base, LPT1_IO_PORT_SIZE) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_initialize: sys_vircopy failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
|
|
|
if(sys_outb(port_base + 2, INIT_PRINTER) != OK) {
|
|
|
|
printf("printer: sys_outb of %x failed\n", port_base+2);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_initialize: sys_outb init failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2008-12-11 15:42:23 +01:00
|
|
|
micro_delay(1000000/20); /* easily satisfies Centronics minimum */
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_outb(port_base + 2, PR_SELECT) != OK) {
|
|
|
|
printf("printer: sys_outb of %x failed\n", port_base+2);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_initialize: sys_outb select failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-07-29 14:44:42 +02:00
|
|
|
irq_hook_id = 0;
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_irqsetpolicy(PRINTER_IRQ, 0, &irq_hook_id) != OK ||
|
|
|
|
sys_irqenable(&irq_hook_id) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_initialize: irq enabling failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* prepare_output *
|
|
|
|
*==========================================================================*/
|
|
|
|
PRIVATE void prepare_output()
|
|
|
|
{
|
|
|
|
/* Start next chunk of printer output. Fetch the data from user space. */
|
2006-06-20 11:49:02 +02:00
|
|
|
int s;
|
2005-04-21 16:53:53 +02:00
|
|
|
register int chunk;
|
|
|
|
|
|
|
|
if ( (chunk = user_left) > sizeof obuf) chunk = sizeof obuf;
|
2006-06-20 11:49:02 +02:00
|
|
|
if(user_safe) {
|
|
|
|
s=sys_safecopyfrom(proc_nr, user_vir_g, user_vir_d,
|
|
|
|
(vir_bytes) obuf, chunk, D);
|
|
|
|
} else {
|
|
|
|
s=sys_datacopy(proc_nr, user_vir_g, SELF, (vir_bytes) obuf, chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s != OK) {
|
2005-04-21 16:53:53 +02:00
|
|
|
done_status = EFAULT;
|
|
|
|
output_done();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
optr = obuf;
|
|
|
|
oleft = chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_printer_output *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE void do_printer_output()
|
|
|
|
{
|
2009-09-29 20:47:56 +02:00
|
|
|
/* This function does the actual output to the printer. This is called on an
|
|
|
|
* interrupt message sent from the generic interrupt handler that 'forwards'
|
|
|
|
* interrupts to this driver. The generic handler did not reenable the printer
|
|
|
|
* IRQ yet!
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
2006-03-25 00:05:21 +01:00
|
|
|
unsigned long status;
|
2005-04-21 16:53:53 +02:00
|
|
|
pvb_pair_t char_out[3];
|
|
|
|
|
|
|
|
if (oleft == 0) {
|
|
|
|
/* Nothing more to print. Turn off printer interrupts in case they
|
|
|
|
* are level-sensitive as on the PS/2. This should be safe even
|
|
|
|
* when the printer is busy with a previous character, because the
|
|
|
|
* interrupt status does not affect the printer.
|
|
|
|
*/
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_outb(port_base + 2, PR_SELECT) != OK) {
|
|
|
|
printf("printer: sys_outb of %x failed\n", port_base+2);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_outb failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
|
|
|
if(sys_irqenable(&irq_hook_id) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqenable failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* Loop to handle fast (buffered) printers. It is important that
|
|
|
|
* processor interrupts are not disabled here, just printer interrupts.
|
|
|
|
*/
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_inb(port_base + 1, &status) != OK) {
|
|
|
|
printf("printer: sys_inb of %x failed\n", port_base+1);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_inb failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
if ((status & STATUS_MASK) == BUSY_STATUS) {
|
|
|
|
/* Still busy with last output. This normally happens
|
|
|
|
* immediately after doing output to an unbuffered or slow
|
|
|
|
* printer. It may happen after a call from prepare_output or
|
|
|
|
* pr_restart, since they are not synchronized with printer
|
|
|
|
* interrupts. It may happen after a spurious interrupt.
|
|
|
|
*/
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_irqenable(&irq_hook_id) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqenable failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((status & STATUS_MASK) == NORMAL_STATUS) {
|
|
|
|
/* Everything is all right. Output another character. */
|
2007-09-11 13:22:29 +02:00
|
|
|
pv_set(char_out[0], port_base, *optr);
|
|
|
|
optr++;
|
2005-04-21 16:53:53 +02:00
|
|
|
pv_set(char_out[1], port_base+2, ASSERT_STROBE);
|
|
|
|
pv_set(char_out[2], port_base+2, NEGATE_STROBE);
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_voutb(char_out, 3) != OK) {
|
|
|
|
/* request series of port outb */
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_voutb failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-06-20 11:49:02 +02:00
|
|
|
user_vir_d++;
|
2005-04-21 16:53:53 +02:00
|
|
|
user_left--;
|
|
|
|
} else {
|
|
|
|
/* Error. This would be better ignored (treat as busy). */
|
|
|
|
done_status = status;
|
|
|
|
output_done();
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_irqenable(&irq_hook_id) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqenable failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (--oleft != 0);
|
|
|
|
|
|
|
|
/* Finished printing chunk OK. */
|
|
|
|
done_status = OK;
|
|
|
|
output_done();
|
2007-08-06 13:17:08 +02:00
|
|
|
if(sys_irqenable(&irq_hook_id) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqenable failed");
|
2007-08-06 13:17:08 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|