1*433d6423SLionel Sambuc /* The kernel call implemented in this file:
2*433d6423SLionel Sambuc * m_type: SYS_DIAGCTL
3*433d6423SLionel Sambuc *
4*433d6423SLionel Sambuc * The parameters for this kernel call are:
5*433d6423SLionel Sambuc * m_lsys_krn_sys_diagctl.code request
6*433d6423SLionel Sambuc * and then request-specific arguments in
7*433d6423SLionel Sambuc * m_lsys_krn_sys_diagctl.buf
8*433d6423SLionel Sambuc * m_lsys_krn_sys_diagctl.len
9*433d6423SLionel Sambuc * m_lsys_krn_sys_diagctl.endpt
10*433d6423SLionel Sambuc */
11*433d6423SLionel Sambuc
12*433d6423SLionel Sambuc #include "kernel/system.h"
13*433d6423SLionel Sambuc
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc /*===========================================================================*
16*433d6423SLionel Sambuc * do_diagctl *
17*433d6423SLionel Sambuc *===========================================================================*/
do_diagctl(struct proc * caller,message * m_ptr)18*433d6423SLionel Sambuc int do_diagctl(struct proc * caller, message * m_ptr)
19*433d6423SLionel Sambuc {
20*433d6423SLionel Sambuc vir_bytes len, buf;
21*433d6423SLionel Sambuc static char mybuf[DIAG_BUFSIZE];
22*433d6423SLionel Sambuc int s, i, proc_nr;
23*433d6423SLionel Sambuc
24*433d6423SLionel Sambuc switch (m_ptr->m_lsys_krn_sys_diagctl.code) {
25*433d6423SLionel Sambuc case DIAGCTL_CODE_DIAG:
26*433d6423SLionel Sambuc buf = m_ptr->m_lsys_krn_sys_diagctl.buf;
27*433d6423SLionel Sambuc len = m_ptr->m_lsys_krn_sys_diagctl.len;
28*433d6423SLionel Sambuc if(len < 1 || len > DIAG_BUFSIZE) {
29*433d6423SLionel Sambuc printf("do_diagctl: diag for %d: len %d out of range\n",
30*433d6423SLionel Sambuc caller->p_endpoint, len);
31*433d6423SLionel Sambuc return EINVAL;
32*433d6423SLionel Sambuc }
33*433d6423SLionel Sambuc if((s=data_copy_vmcheck(caller, caller->p_endpoint, buf, KERNEL,
34*433d6423SLionel Sambuc (vir_bytes) mybuf, len)) != OK) {
35*433d6423SLionel Sambuc printf("do_diagctl: diag for %d: len %d: copy failed: %d\n",
36*433d6423SLionel Sambuc caller->p_endpoint, len, s);
37*433d6423SLionel Sambuc return s;
38*433d6423SLionel Sambuc }
39*433d6423SLionel Sambuc for(i = 0; i < len; i++)
40*433d6423SLionel Sambuc kputc(mybuf[i]);
41*433d6423SLionel Sambuc kputc(END_OF_KMESS);
42*433d6423SLionel Sambuc return OK;
43*433d6423SLionel Sambuc case DIAGCTL_CODE_STACKTRACE:
44*433d6423SLionel Sambuc if(!isokendpt(m_ptr->m_lsys_krn_sys_diagctl.endpt, &proc_nr))
45*433d6423SLionel Sambuc return EINVAL;
46*433d6423SLionel Sambuc proc_stacktrace(proc_addr(proc_nr));
47*433d6423SLionel Sambuc return OK;
48*433d6423SLionel Sambuc case DIAGCTL_CODE_REGISTER:
49*433d6423SLionel Sambuc if (!(priv(caller)->s_flags & SYS_PROC))
50*433d6423SLionel Sambuc return EPERM;
51*433d6423SLionel Sambuc priv(caller)->s_diag_sig = TRUE;
52*433d6423SLionel Sambuc /* If the message log is not empty, send a first notification
53*433d6423SLionel Sambuc * immediately. After bootup the log is basically never empty.
54*433d6423SLionel Sambuc */
55*433d6423SLionel Sambuc if (kmess.km_size > 0 && !kinfo.do_serial_debug)
56*433d6423SLionel Sambuc send_sig(caller->p_endpoint, SIGKMESS);
57*433d6423SLionel Sambuc return OK;
58*433d6423SLionel Sambuc case DIAGCTL_CODE_UNREGISTER:
59*433d6423SLionel Sambuc if (!(priv(caller)->s_flags & SYS_PROC))
60*433d6423SLionel Sambuc return EPERM;
61*433d6423SLionel Sambuc priv(caller)->s_diag_sig = FALSE;
62*433d6423SLionel Sambuc return OK;
63*433d6423SLionel Sambuc default:
64*433d6423SLionel Sambuc printf("do_diagctl: invalid request %d\n", m_ptr->m_lsys_krn_sys_diagctl.code);
65*433d6423SLionel Sambuc return(EINVAL);
66*433d6423SLionel Sambuc }
67*433d6423SLionel Sambuc }
68*433d6423SLionel Sambuc
69