Created ECHO system call for testing purposes.

Furthermore, a quick way to get one's own process number.
This commit is contained in:
Jorrit Herder 2005-05-27 13:57:00 +00:00
parent 07d582872f
commit 8d9c0886cd
7 changed files with 60 additions and 42 deletions

View File

@ -60,7 +60,6 @@
#include <sys/ioc_tty.h> #include <sys/ioc_tty.h>
#include <signal.h> #include <signal.h>
#include <minix/callnr.h> #include <minix/callnr.h>
#include <minix/com.h>
#if (CHIP == INTEL) #if (CHIP == INTEL)
#include <minix/keymap.h> #include <minix/keymap.h>
#endif #endif
@ -107,7 +106,7 @@ FORWARD _PROTOTYPE( void do_close, (tty_t *tp, message *m_ptr) );
FORWARD _PROTOTYPE( void do_read, (tty_t *tp, message *m_ptr) ); FORWARD _PROTOTYPE( void do_read, (tty_t *tp, message *m_ptr) );
FORWARD _PROTOTYPE( void do_write, (tty_t *tp, message *m_ptr) ); FORWARD _PROTOTYPE( void do_write, (tty_t *tp, message *m_ptr) );
FORWARD _PROTOTYPE( void in_transfer, (tty_t *tp) ); FORWARD _PROTOTYPE( void in_transfer, (tty_t *tp) );
FORWARD _PROTOTYPE( int echo, (tty_t *tp, int ch) ); FORWARD _PROTOTYPE( int tty_echo, (tty_t *tp, int ch) );
FORWARD _PROTOTYPE( void rawecho, (tty_t *tp, int ch) ); FORWARD _PROTOTYPE( void rawecho, (tty_t *tp, int ch) );
FORWARD _PROTOTYPE( int back_over, (tty_t *tp) ); FORWARD _PROTOTYPE( int back_over, (tty_t *tp) );
FORWARD _PROTOTYPE( void reprint, (tty_t *tp) ); FORWARD _PROTOTYPE( void reprint, (tty_t *tp) );
@ -883,7 +882,7 @@ int count; /* number of input characters */
if (ch == tp->tty_termios.c_cc[VERASE]) { if (ch == tp->tty_termios.c_cc[VERASE]) {
(void) back_over(tp); (void) back_over(tp);
if (!(tp->tty_termios.c_lflag & ECHOE)) { if (!(tp->tty_termios.c_lflag & ECHOE)) {
(void) echo(tp, ch); (void) tty_echo(tp, ch);
} }
continue; continue;
} }
@ -892,7 +891,7 @@ int count; /* number of input characters */
if (ch == tp->tty_termios.c_cc[VKILL]) { if (ch == tp->tty_termios.c_cc[VKILL]) {
while (back_over(tp)) {} while (back_over(tp)) {}
if (!(tp->tty_termios.c_lflag & ECHOE)) { if (!(tp->tty_termios.c_lflag & ECHOE)) {
(void) echo(tp, ch); (void) tty_echo(tp, ch);
if (tp->tty_termios.c_lflag & ECHOK) if (tp->tty_termios.c_lflag & ECHOK)
rawecho(tp, '\n'); rawecho(tp, '\n');
} }
@ -938,7 +937,7 @@ int count; /* number of input characters */
sig = SIGINT; sig = SIGINT;
if (ch == tp->tty_termios.c_cc[VQUIT]) sig = SIGQUIT; if (ch == tp->tty_termios.c_cc[VQUIT]) sig = SIGQUIT;
sigchar(tp, sig); sigchar(tp, sig);
(void) echo(tp, ch); (void) tty_echo(tp, ch);
continue; continue;
} }
} }
@ -963,7 +962,7 @@ int count; /* number of input characters */
} }
/* Perform the intricate function of echoing. */ /* Perform the intricate function of echoing. */
if (tp->tty_termios.c_lflag & (ECHO|ECHONL)) ch = echo(tp, ch); if (tp->tty_termios.c_lflag & (ECHO|ECHONL)) ch = tty_echo(tp, ch);
/* Save the character in the input queue. */ /* Save the character in the input queue. */
*tp->tty_inhead++ = ch; *tp->tty_inhead++ = ch;
@ -982,7 +981,7 @@ int count; /* number of input characters */
/*===========================================================================* /*===========================================================================*
* echo * * echo *
*===========================================================================*/ *===========================================================================*/
PRIVATE int echo(tp, ch) PRIVATE int tty_echo(tp, ch)
register tty_t *tp; /* terminal on which to echo */ register tty_t *tp; /* terminal on which to echo */
register int ch; /* pointer to character to echo */ register int ch; /* pointer to character to echo */
{ {
@ -1111,14 +1110,14 @@ register tty_t *tp; /* pointer to tty struct */
if (count == tp->tty_incount) return; /* no reason to reprint */ if (count == tp->tty_incount) return; /* no reason to reprint */
/* Show REPRINT (^R) and move to a new line. */ /* Show REPRINT (^R) and move to a new line. */
(void) echo(tp, tp->tty_termios.c_cc[VREPRINT] | IN_ESC); (void) tty_echo(tp, tp->tty_termios.c_cc[VREPRINT] | IN_ESC);
rawecho(tp, '\r'); rawecho(tp, '\r');
rawecho(tp, '\n'); rawecho(tp, '\n');
/* Reprint from the last break onwards. */ /* Reprint from the last break onwards. */
do { do {
if (head == bufend(tp->tty_inbuf)) head = tp->tty_inbuf; if (head == bufend(tp->tty_inbuf)) head = tp->tty_inbuf;
*head = echo(tp, *head); *head = tty_echo(tp, *head);
head++; head++;
count++; count++;
} while (count < tp->tty_incount); } while (count < tp->tty_incount);

View File

@ -1,23 +1,7 @@
/*===========================================================================* /*===========================================================================*
* System calls and magic process numbers * * Magic process numbers *
*===========================================================================*/ *===========================================================================*/
/* Masks and flags for system calls. */
#define SYSCALL_FUNC 0x0F /* mask for system call function */
#define SYSCALL_FLAGS 0xF0 /* mask for system call flags */
#define NON_BLOCKING 0x10 /* prevent blocking, return error */
#define FRESH_ANSWER 0x20 /* ignore pending notifications as answer */
/* default behaviour for SENDREC calls */
/* System calls (numbers passed when trapping to the kernel) */
#define SEND 1 /* function code for sending messages */
#define RECEIVE 2 /* function code for receiving messages */
#define SENDREC 3 /* function code for SEND + RECEIVE */
#define NOTIFY 4 /* function code for notifications */
#define NB_SEND (SEND | NON_BLOCKING) /* non-blocking SEND */
#define NB_RECEIVE (RECEIVE | NON_BLOCKING) /* non-blocking RECEIVE */
/* Magic, invalid process numbers. */
#define ANY 0x7ace /* used to indicate 'any process' */ #define ANY 0x7ace /* used to indicate 'any process' */
#define NONE 0x6ace /* used to indicate 'no process at all' */ #define NONE 0x6ace /* used to indicate 'no process at all' */
#define SELF 0x8ace /* used to indicate 'own process' */ #define SELF 0x8ace /* used to indicate 'own process' */

View File

@ -91,6 +91,7 @@ typedef struct {
*==========================================================================*/ *==========================================================================*/
/* Hide names to avoid name space pollution. */ /* Hide names to avoid name space pollution. */
#define echo _echo
#define sendrec _sendrec #define sendrec _sendrec
#define receive _receive #define receive _receive
#define send _send #define send _send
@ -98,6 +99,7 @@ typedef struct {
#define nb_receive _nb_receive #define nb_receive _nb_receive
#define nb_send _nb_send #define nb_send _nb_send
_PROTOTYPE( int echo, (message *m_ptr) );
_PROTOTYPE( int sendrec, (int src_dest, message *m_ptr) ); _PROTOTYPE( int sendrec, (int src_dest, message *m_ptr) );
_PROTOTYPE( int receive, (int src, message *m_ptr) ); _PROTOTYPE( int receive, (int src, message *m_ptr) );
_PROTOTYPE( int send, (int dest, message *m_ptr) ); _PROTOTYPE( int send, (int dest, message *m_ptr) );

View File

@ -103,6 +103,7 @@ proc.o: $a
proc.o: $h/callnr.h proc.o: $h/callnr.h
proc.o: $h/com.h proc.o: $h/com.h
proc.o: proc.h proc.o: proc.h
proc.o: ipc.h
proc.o: sendmask.h proc.o: sendmask.h
protect.o: $a protect.o: $a

14
kernel/ipc.h Normal file
View File

@ -0,0 +1,14 @@
/* Masks and flags for system calls. */
#define SYSCALL_FUNC 0x0F /* mask for system call function */
#define SYSCALL_FLAGS 0xF0 /* mask for system call flags */
#define NON_BLOCKING 0x10 /* prevent blocking, return error */
#define FRESH_ANSWER 0x20 /* ignore pending notifications as answer */
/* (default behaviour for SENDREC calls) */
/* System calls (numbers passed when trapping to the kernel) */
#define ECHO 0 /* function code for echoing messages */
#define SEND 1 /* function code for sending messages */
#define RECEIVE 2 /* function code for receiving messages */
#define SENDREC 3 /* function code for SEND + RECEIVE */
#define NOTIFY 4 /* function code for notifications */

View File

@ -29,6 +29,7 @@
#include <minix/callnr.h> #include <minix/callnr.h>
#include <minix/com.h> #include <minix/com.h>
#include "proc.h" #include "proc.h"
#include "ipc.h"
#include "sendmask.h" #include "sendmask.h"
@ -99,7 +100,7 @@ message *m_ptr; /* pointer to message in the caller's space */
return(ECALLDENIED); /* SENDREC was required */ return(ECALLDENIED); /* SENDREC was required */
/* Verify that requested source and/ or destination is a valid process. */ /* Verify that requested source and/ or destination is a valid process. */
if (! isoksrc_dst(src_dst)) if (! isoksrc_dst(src_dst) && function != ECHO)
return(EBADSRCDST); return(EBADSRCDST);
/* Check validity of message pointer. */ /* Check validity of message pointer. */
@ -153,6 +154,11 @@ message *m_ptr; /* pointer to message in the caller's space */
case NOTIFY: case NOTIFY:
result = mini_notify(caller_ptr, src_dst, m_ptr); result = mini_notify(caller_ptr, src_dst, m_ptr);
break; break;
case ECHO:
kprintf("Echo message from process %s\n", proc_nr(caller_ptr));
CopyMess(caller_ptr->p_nr, caller_ptr, m_ptr, caller_ptr, m_ptr);
result = OK;
break;
default: default:
result = EBADCALL; /* illegal system call */ result = EBADCALL; /* illegal system call */
} }

View File

@ -1,30 +1,31 @@
.sect .text; .sect .rom; .sect .data; .sect .bss .sect .text; .sect .rom; .sect .data; .sect .bss
.define __send, __nb_send, __receive, __nb_receive, __sendrec, __notify .define __echo, __send, __nb_send, __receive, __nb_receive, __sendrec, __notify
! See ../h/com.h for C definitions ! See src/kernel/ipc.h for C definitions
ECHO = 0
SEND = 1 SEND = 1
RECEIVE = 2 RECEIVE = 2
BOTH = 3 BOTH = 3
NOTIFY = 4 NOTIFY = 4
NB_SEND = 1 + 16 ! SEND | 0xF0 NB_SEND = 1 + 16 ! SEND | 0xF0
NB_RECEIVE = 2 + 16 ! RECEIVE | 0xF0 NB_RECEIVE = 2 + 16 ! RECEIVE | 0xF0
SYSVEC = 33 SYSVEC = 33 ! trap to kernel
SRCDEST = 8 SRC_DST = 8 ! source/ destination process
MESSAGE = 12 ECHO_MESS = 8 ! doesn't have SRC_DST
MESSAGE = 12 ! message pointer
!*========================================================================* !*========================================================================*
! _send and _receive * ! IPC assembly routines *
!*========================================================================* !*========================================================================*
! _send(), _nb_send(), _receive(), _nb_receive(), and _sendrec() all ! all message passing routines save ebp, but destroy eax and ecx.
! save ebp, but destroy eax and ecx. .define __echo, __send, __nb_send, __receive, __nb_receive, __sendrec, __notify
.define __send, __nb_send, __receive, __nb_receive, __sendrec, __notify
.sect .text .sect .text
__send: __send:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, SEND ! _send(dest, ptr) mov ecx, SEND ! _send(dest, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -36,7 +37,7 @@ __nb_send:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, NB_SEND ! _nb_send(dest, ptr) mov ecx, NB_SEND ! _nb_send(dest, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -48,7 +49,7 @@ __receive:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, RECEIVE ! _receive(src, ptr) mov ecx, RECEIVE ! _receive(src, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -60,7 +61,7 @@ __nb_receive:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, NB_RECEIVE ! _nb_receive(src, ptr) mov ecx, NB_RECEIVE ! _nb_receive(src, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -72,7 +73,7 @@ __sendrec:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, BOTH ! _sendrec(srcdest, ptr) mov ecx, BOTH ! _sendrec(srcdest, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -84,7 +85,7 @@ __notify:
push ebp push ebp
mov ebp, esp mov ebp, esp
push ebx push ebx
mov eax, SRCDEST(ebp) ! eax = dest-src mov eax, SRC_DST(ebp) ! eax = dest-src
mov ebx, MESSAGE(ebp) ! ebx = message pointer mov ebx, MESSAGE(ebp) ! ebx = message pointer
mov ecx, NOTIFY ! _notify(srcdest, ptr) mov ecx, NOTIFY ! _notify(srcdest, ptr)
int SYSVEC ! trap to the kernel int SYSVEC ! trap to the kernel
@ -92,3 +93,14 @@ __notify:
pop ebp pop ebp
ret ret
__echo:
push ebp
mov ebp, esp
push ebx
mov ebx, ECHO_MESS(ebp) ! ebx = message pointer
mov ecx, ECHO ! _echo(srcdest, ptr)
int SYSVEC ! trap to the kernel
pop ebx
pop ebp
ret