1 /* A server must occasionally print some message. It uses a simple version of
2 * printf() found in the system lib that calls kputc() to output characters.
3 * Printing is done with a call to the kernel, and not by going through FS.
5 * This routine can only be used by servers and device drivers. The kernel
6 * must define its own kputc(). Note that the log driver also defines its own
7 * kputc() to directly call the TTY instead of going through this library.
12 static char print_buf
[80]; /* output is buffered here */
14 int kputc_use_private_grants
= 0;
16 /*===========================================================================*
18 *===========================================================================*/
22 /* Accumulate another character. If 0 or buffer full, print it. */
23 static int buf_count
; /* # characters in the buffer */
26 if ((c
== 0 && buf_count
> 0) || buf_count
== sizeof(print_buf
)) {
27 #define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
28 int procs
[] = OUTPUT_PROCS_ARRAY
;
29 static int firstprint
= 1;
30 static cp_grant_id_t printgrants
[PRINTPROCS
];
33 if (kputc_use_private_grants
)
35 for (p
= 0; p
<PRINTPROCS
; p
++)
36 printgrants
[p
]= GRANT_INVALID
;
40 for(p
= 0; procs
[p
] != NONE
; p
++) {
41 printgrants
[p
] = GRANT_INVALID
;
46 /* First time? Initialize grant table;
47 * Grant printing processes read copy access to our
48 * print buffer forever. (So buffer can't be on stack!)
50 for(p
= 0; procs
[p
] != NONE
; p
++) {
51 printgrants
[p
] = cpf_grant_direct(procs
[p
], print_buf
,
52 sizeof(print_buf
), CPF_READ
);
56 for(p
= 0; procs
[p
] != NONE
; p
++) {
57 /* Send the buffer to this output driver. */
58 m
.DIAG_BUF_COUNT
= buf_count
;
59 if(GRANT_VALID(printgrants
[p
])) {
60 m
.m_type
= DIAGNOSTICS_S
;
61 m
.DIAG_PRINT_BUF_G
= printgrants
[p
];
63 m
.m_type
= DIAGNOSTICS
;
64 m
.DIAG_PRINT_BUF_G
= print_buf
;
66 (void) _sendrec(procs
[p
], &m
);
71 /* If the output fails, e.g., due to an ELOCKED, do not retry output
72 * at the FS as if this were a normal user-land printf(). This may
73 * result in even worse problems.
78 /* Append a single character to the output buffer. */
79 print_buf
[buf_count
++] = c
;