Browse Source

shell working

pull/1/head
Rafael Zurita 6 years ago
parent
commit
b33a93295f
  1. 13
      device/tty/ttyhandle_in.c
  2. 1
      device/tty/ttyhandle_out.c
  3. 2
      include/messages.h
  4. 3
      include/process.h
  5. 3
      include/prototypes.h
  6. 8
      include/shell.h
  7. 8
      include/tty.h
  8. 371
      lib/fdoprnt.c
  9. 28
      lib/fprintf.c
  10. 2
      lib/messages.c
  11. 28
      lib/printf.c
  12. 4
      lib/putchar.c
  13. 64
      shell/addargs.c
  14. 296
      shell/shell.c
  15. 24
      shell/xsh_echo.c
  16. 14
      system/create.c
  17. 6
      system/initialize.c
  18. 4
      system/main.c
  19. 3
      system/ready.c
  20. 9
      system/resched.c
  21. 7
      system/serial_avr.c
  22. 2
      system/syscall.c
  23. 3
      system/wait.c

13
device/tty/ttyhandle_in.c

@ -260,13 +260,16 @@ local void eputc(
struct uart_csreg *csrptr /* Address of UART's CSRs */
)
{
*typtr->tyetail++ = ch;
// *typtr->tyetail++ = ch;
// RAFA
serial_put_char(ch);
/* Wrap around buffer, if needed */
if (typtr->tyetail >= &typtr->tyebuff[TY_EBUFLEN]) {
typtr->tyetail = typtr->tyebuff;
}
ttykickout(csrptr);
// if (typtr->tyetail >= &typtr->tyebuff[TY_EBUFLEN]) {
// typtr->tyetail = typtr->tyebuff;
// }
// ttykickout(csrptr);
return;
}

1
device/tty/ttyhandle_out.c

@ -26,6 +26,7 @@ void ttyhandle_out(
return;
}
/* If echo and output queues empty, turn off interrupts */
if ( (typtr->tyehead == typtr->tyetail) &&

2
include/messages.h

@ -11,6 +11,8 @@ extern const char m5[];
extern const char m6[];
extern const char m7[];
extern const char m8[];
extern const char m9[];
extern const char m10[];

3
include/process.h

@ -62,7 +62,8 @@ struct procent { /* Entry in the process table */
unsigned char pregs[PNREGS];/* saved context (see ctxsw) */
int pargs; /* initial number of arguments */
int parg[MAXARG]; /* arguments */
// int parg[MAXARG]; /* arguments */
void * parg[MAXARG]; /* arguments */
int *paddr; /* initial code address */
char *prstkptr; /* Saved stack pointer */

3
include/prototypes.h

@ -516,7 +516,8 @@ extern syscall semreset(sid32, int32);
extern syscall send(pid32, umsg32);
/* in file shell.c */
extern process shell(did32);
// RAFA extern process shell(did32);
extern process shell(void);
/* in file signal.c */
extern syscall signal(sid32);

8
include/shell.h

@ -3,8 +3,10 @@
/* Size constants */
#define SHELL_BUFLEN TY_IBUFLEN+1 /* Length of input buffer */
#define SHELL_MAXTOK 32 /* Maximum tokens per line */
#define SHELL_CMDSTK 4096 /* Size of stack for process */
// RAFA #define SHELL_MAXTOK 32 /* Maximum tokens per line */
#define SHELL_MAXTOK 3 /* Maximum tokens per line */
// RAFA #define SHELL_CMDSTK 4096 /* Size of stack for process */
#define SHELL_CMDSTK 256 /* Size of stack for process */
/* that executes command */
#define SHELL_ARGLEN (SHELL_BUFLEN+SHELL_MAXTOK) /* Argument area */
#define SHELL_CMDPRIO 20 /* Process priority for command */
@ -75,3 +77,5 @@ struct cmdent { /* Entry in command table */
extern uint32 ncmd;
// RAFA extern const struct cmdent cmdtab[];
extern const struct cmdent cmdtab[] ;

8
include/tty.h

@ -1,7 +1,9 @@
/* tty.h */
// RAFA #define TY_OBMINSP 20 /* Min space in buffer before */
#define TY_OBMINSP 1 /* Min space in buffer before */
/* processes awakened to write*/
// RAFA #define TY_EBUFLEN 20 /* Size of echo queue */
#define TY_EBUFLEN 1 /* Size of echo queue */
/* Size constants */
@ -10,10 +12,12 @@
#define Ntty 1 /* Number of serial tty lines */
#endif
#ifndef TY_IBUFLEN
#define TY_IBUFLEN 5 /* Num. chars in input queue */
// RAFA #define TY_IBUFLEN 128 /* Num. chars in input queue */
#define TY_IBUFLEN 8 /* Num. chars in input queue */
#endif
#ifndef TY_OBUFLEN
#define TY_OBUFLEN 5 /* Num. chars in output queue */
// RAFA #define TY_OBUFLEN 64 /* Num. chars in output queue */
#define TY_OBUFLEN 8 /* Num. chars in output queue */
#endif
/* Mode constants for input and output modes */

371
lib/fdoprnt.c

@ -0,0 +1,371 @@
/* fdoprnt.c - _fdoprnt, _prtl2, _prtl8, _prtl10, _prtX16, _prtl16 */
#include <stdarg.h>
#define MAXSTR 80
#define NULL 0
static void _prtl10(long num, char *str);
static void _prtl8(long num, char *str);
static void _prtX16(long num, char *str);
static void _prtl16(long num, char *str);
static void _prtl2(long num, char *str);
/*------------------------------------------------------------------------
* _fdoprnt - Format and write output using 'func' to write characters.
* (Patched for Sun3 by Shawn Ostermann.)
* All arguments passed as 4 bytes, long==int.
*------------------------------------------------------------------------
*/
void _fdoprnt(
char *fmt, /* format string */
va_list ap, /* ap list of values */
int (*func)(int, int), /* char output function */
int farg /* arg for char output */
)
{
int c;
int i;
int f; /* The format character (comes after %) */
char *str; /* Running pointer in string */
char string[20]; /* The string str points to this output */
/* from number conversion */
int length; /* Length of string "str" */
char fill; /* Fill character (' ' or '0') */
int leftjust; /* 0 = right-justified, else left-just */
int fmax, fmin; /* Field specifications % MIN . MAX s */
int leading; /* No. of leading/trailing fill chars */
char sign; /* Set to '-' for negative decimals */
char digit1; /* Offset to add to first numeric digit */
long larg;
for (;;)
{
/* Echo characters until '%' or end of fmt string */
while ((c = *fmt++) != '%')
{
if (c == '\0')
{
return;
}
(*func) (farg, c);
}
/* Echo "...%%..." as '%' */
if (*fmt == '%')
{
(*func) (farg, *fmt++);
continue;
}
/* Check for "%-..." == Left-justified output */
if ((leftjust = ((*fmt == '-')) ? 1 : 0))
{
fmt++;
}
/* Allow for zero-filled numeric outputs ("%0...") */
fill = (*fmt == '0') ? *fmt++ : ' ';
/* Allow for minimum field width specifier for %d,u,x,o,c,s */
/* Also allow %* for variable width (%0* as well) */
fmin = 0;
if (*fmt == '*')
{
fmin = va_arg(ap, int);
++fmt;
}
else
{
while ('0' <= *fmt && *fmt <= '9')
{
fmin = fmin * 10 + *fmt++ - '0';
}
}
/* Allow for maximum string width for %s */
fmax = 0;
if (*fmt == '.')
{
if (*(++fmt) == '*')
{
fmax = va_arg(ap, int);
++fmt;
}
else
{
while ('0' <= *fmt && *fmt <= '9')
{
fmax = fmax * 10 + *fmt++ - '0';
}
}
}
str = string;
if ((f = *fmt++) == '\0')
{
(*func) (farg, '%');
return;
}
sign = '\0'; /* sign == '-' for negative decimal */
switch (f)
{
case 'c':
string[0] = va_arg(ap, int);
string[1] = '\0';
fmax = 0;
fill = ' ';
break;
case 's':
str = va_arg(ap, char *);
if (NULL == str)
{
str = "(null)";
}
fill = ' ';
break;
case 'd':
larg = va_arg(ap, long);
if (larg < 0)
{
sign = '-';
larg = -larg;
}
_prtl10(larg, str);
break;
case 'u':
digit1 = '\0';
/* "negative" longs in unsigned format */
/* can't be computed with long division */
/* convert *args to "positive", digit1 */
/* = how much to add back afterwards */
larg = va_arg(ap, long);
while (larg < 0)
{
larg -= 1000000000L;
++digit1;
}
_prtl10(larg, str);
str[0] += digit1;
fmax = 0;
break;
case 'o':
larg = va_arg(ap, long);
_prtl8(larg, str);
fmax = 0;
break;
case 'X':
larg = va_arg(ap, long);
_prtX16(larg, str);
fmax = 0;
break;
case 'x':
larg = va_arg(ap, long);
_prtl16(larg, str);
fmax = 0;
break;
case 'b':
larg = va_arg(ap, long);
_prtl2(larg, str);
fmax = 0;
break;
default:
(*func) (farg, f);
break;
}
for (length = 0; str[length] != '\0'; length++)
{;
}
if (fmin > MAXSTR || fmin < 0)
{
fmin = 0;
}
if (fmax > MAXSTR || fmax < 0)
{
fmax = 0;
}
leading = 0;
if (fmax != 0 || fmin != 0)
{
if (fmax != 0)
{
if (length > fmax)
{
length = fmax;
}
}
if (fmin != 0)
{
leading = fmin - length;
}
if (sign == '-')
{
--leading;
}
}
if (sign == '-' && fill == '0')
{
(*func) (farg, sign);
}
if (leftjust == 0)
{
for (i = 0; i < leading; i++)
{
(*func) (farg, fill);
}
}
if (sign == '-' && fill == ' ')
{
(*func) (farg, sign);
}
for (i = 0; i < length; i++)
{
(*func) (farg, str[i]);
}
if (leftjust != 0)
{
for (i = 0; i < leading; i++)
(*func) (farg, fill);
}
}
}
/*------------------------------------------------------------------------
* _prtl10 - Converts long to base 10 string.
*------------------------------------------------------------------------
*/
static void _prtl10(
long num,
char *str
)
{
int i;
char temp[11];
temp[0] = '\0';
for (i = 1; i <= 10; i++)
{
temp[i] = num % 10 + '0';
num /= 10;
}
for (i = 10; temp[i] == '0'; i--);
if (i == 0)
i++;
while (i >= 0)
*str++ = temp[i--];
}
/*------------------------------------------------------------------------
* _prtl8 - Converts long to base 8 string.
*------------------------------------------------------------------------
*/
static void _prtl8(
long num,
char *str
)
{
int i;
char temp[12];
temp[0] = '\0';
for (i = 1; i <= 11; i++)
{
temp[i] = (num & 07) + '0';
num = num >> 3;
}
temp[11] &= '3';
for (i = 11; temp[i] == '0'; i--);
if (i == 0)
i++;
while (i >= 0)
*str++ = temp[i--];
}
/*------------------------------------------------------------------------
* _prtl16 - Converts long to lowercase hex string.
*------------------------------------------------------------------------
*/
static void _prtl16(
long num,
char *str
)
{
int i;
char temp[9];
temp[0] = '\0';
for (i = 1; i <= 8; i++)
{
temp[i] = "0123456789abcdef"[num & 0x0F];
num = num >> 4;
}
for (i = 8; temp[i] == '0'; i--);
if (i == 0)
i++;
while (i >= 0)
*str++ = temp[i--];
}
/*------------------------------------------------------------------------
* _prtX16 - Converts long to uppercase hex string.
*------------------------------------------------------------------------
*/
static void _prtX16(
long num,
char *str
)
{
int i;
char temp[9];
temp[0] = '\0';
for (i = 1; i <= 8; i++)
{
temp[i] = "0123456789ABCDEF"[num & 0x0F];
num = num >> 4;
}
for (i = 8; temp[i] == '0'; i--);
if (i == 0)
i++;
while (i >= 0)
*str++ = temp[i--];
}
/*------------------------------------------------------------------------
* _prtl2 - Converts long to binary string.
*------------------------------------------------------------------------
*/
static void _prtl2(
long num,
char *str
)
{
int i;
char temp[35];
temp[0] = '\0';
for (i = 1; i <= 32; i++)
{
temp[i] = ((num % 2) == 0) ? '0' : '1';
num = num >> 1;
}
for (i = 32; temp[i] == '0'; i--);
if (i == 0)
i++;
while (i >= 0)
*str++ = temp[i--];
}

28
lib/fprintf.c

@ -0,0 +1,28 @@
/* fprintf.c - _fdoprnt */
#include <xinu.h>
#include <stdarg.h>
extern void _fdoprnt(char *, va_list, int (*)(did32, char), int);
/*------------------------------------------------------------------------
* fprintf - Print a formatted message on specified device (file).
* Return 0 if the output was printed successfully,
* and -1 if an error occurred.
*------------------------------------------------------------------------
*/
int fprintf(
int dev, /* device to write to */
char *fmt, /* format string */
...
)
{
va_list ap;
syscall putc(did32, char);
va_start(ap, fmt);
_fdoprnt(fmt, ap, putc, dev);
va_end(ap);
return 0;
}

2
lib/messages.c

@ -11,6 +11,8 @@ const char m5[] PROGMEM = "namespace: device name %s too long\r\n";
const char m6[] PROGMEM = "Can't startup system";
const char m7[] PROGMEM = "ptinit - insufficient memory";
const char m8[] PROGMEM = "free mem: %10d bytes. Free-list:\n";
const char m9[] PROGMEM = "System call not implemented\n";
const char m10[] PROGMEM = "ERROR GETSTK %s\n";

28
lib/printf.c

@ -0,0 +1,28 @@
/* printf.c - printf*/
#include <xinu.h>
#include <stdio.h>
#include <stdarg.h>
extern void _fdoprnt(char *, va_list, int (*)(did32, char), int);
extern int xinu_putc(did32, char);
/*------------------------------------------------------------------------
* printf - standard C printf function
*------------------------------------------------------------------------
*/
int printf(
const char *fmt,
...
)
{
va_list ap;
//syscall putc(did32, char);
int xinu_putc(did32, char);
va_start(ap, fmt);
_fdoprnt((char *)fmt, ap, putc, stdout);
va_end(ap);
return 0;
}

4
lib/putchar.c

@ -11,5 +11,7 @@ int putchar(
int c
)
{
return fputc(c, stdout);
// RAFA return fputc(c, stdout);
serial_put_char(c);
return 0;
}

64
shell/addargs.c

@ -38,6 +38,7 @@ status addargs(
/* Check argument count and data length */
if ( (ntok <= 0) || (tlen < 0) ) {
// serial_put_char('M');
restore(mask);
return SYSERR;
}
@ -48,46 +49,71 @@ status addargs(
/* args array will be stored followed by the argument */
/* strings */
aloc = (uint32) (prptr->prstkbase
- prptr->prstklen + sizeof(uint32));
argloc = (uint32*) ((aloc + 3) & ~0x3); /* round multiple of 4 */
// aloc = (uint32) (prptr->prstkbase
// - prptr->prstklen + sizeof(uint32));
// argloc = (uint32*) ((aloc + 3) & ~0x3); /* round multiple of 4 */
/* Compute the first location beyond args array for the strings */
argstr = (char *) (argloc + (ntok+1)); /* +1 for a null ptr */
//
// argstr = (char *) (argloc + (ntok+1)); /* +1 for a null ptr */
/* Set each location in the args vector to be the address of */
/* string area plus the offset of this argument */
for (aptr=argloc, i=0; i < ntok; i++) {
*aptr++ = (uint32) (argstr + tok[i]);
}
// for (aptr=argloc, i=0; i < ntok; i++) {
// *aptr++ = (uint32) (argstr + tok[i]);
// }
/* Add a null pointer to the args array */
*aptr++ = (uint32)NULL;
// *aptr++ = (uint32)NULL;
/* Copy the argument strings from tokbuf into process's stack */
/* just beyond the args vector */
memcpy(aptr, tokbuf, tlen);
// memcpy(aptr, tokbuf, tlen);
/* Find the second argument in process's stack */
for (search = (uint32 *)prptr->prstkptr;
search < (uint32 *)prptr->prstkbase; search++) {
// for (search = (uint32 *)prptr->prstkptr;
// search < (uint32 *)prptr->prstkbase; search++) {
/* If found, replace with the address of the args vector*/
if (*search == (uint32)dummy) {
*search = (uint32)argloc;
restore(mask);
return OK;
}
}
// if (*search == (uint32)dummy) {
// *search = (uint32)argloc;
// restore(mask);
// return OK;
// }
// }
/* Argument value not found on the stack - report an error */
// serial_put_char('\n');
// for (fromarg=Shl.shtok ; nargs > 0 ; nargs--) {
for (i=0 ; i < ntok; i++) {
// prptr->parg[i+prptr->pargs] = (int)tok[i]; /******** change int parg[] TO void *parg[] in proc.h ******/
// prptr->parg[i+prptr->pargs] = (void *)tok[i]; /******** change int parg[] TO void *parg[] in proc.h ******/
// serial_put_char(48+i);
// serial_put_char(' ');
// serial_put_char(tokbuf[tok[i]]);
// serial_put_char(' ');
prptr->parg[i] = &tokbuf[tok[i]];
}
// *toarg = 0;
prptr->pargs = ntok;
prptr->parg[ntok] = 0;
// RAFA prptr->pargs += ntok;
// RAFA prptr->parg[prptr->pargs] = 0;
/* machine/compiler dependent pass arguments to created process */
prptr->pregs[24] = lobyte((unsigned)prptr->pargs); /*r24*/
prptr->pregs[25] = hibyte((unsigned)prptr->pargs);
restore(mask);
return SYSERR;
return OK;
// return SYSERR;
}

296
shell/shell.c

@ -7,7 +7,27 @@
/************************************************************************/
/* Table of Xinu shell commands and the function associated with each */
/************************************************************************/
// RAFA const struct cmdent cmdtab[] = {
const struct cmdent cmdtab[] = {
{"echo", FALSE, xsh_echo}
// {"argecho", TRUE, xsh_argecho},
// {"cat", FALSE, xsh_cat},
// {"clear", TRUE, xsh_clear},
// {"date", FALSE, xsh_date},
// {"devdump", FALSE, xsh_devdump},
// {"echo", FALSE, xsh_echo},
// {"exit", TRUE, xsh_exit},
// {"help", FALSE, xsh_help},
// {"kill", TRUE, xsh_kill},
// {"memdump", FALSE, xsh_memdump},
// {"memstat", TRUE, xsh_memstat}, /* Make built-in */
// {"ps", FALSE, xsh_ps},
// {"sleep", FALSE, xsh_sleep},
// {"uptime", FALSE, xsh_uptime},
// {"?", FALSE, xsh_help}
};
uint32 ncmd = sizeof(cmdtab) / sizeof(struct cmdent);
/************************************************************************/
/* shell - Provide an interactive user interface that executes */
@ -27,14 +47,272 @@
/************************************************************************/
process shell (
did32 dev /* ID of tty device from which */
// did32 dev /* ID of tty device from which */
) /* to accept commands */
{
kprintf("shell\n");
blink_avr();
blink_avr();
blink_avr();
blink_avr();
return OK;
}
char buf[SHELL_BUFLEN]; /* Input line (large enough for */
int32 len; /* Length of line read */
char tokbuf[SHELL_BUFLEN + /* Buffer to hold a set of */
SHELL_MAXTOK]; /* Contiguous null-terminated */
int32 tlen; /* Current length of all data */
/* in array tokbuf */
int32 tok[SHELL_MAXTOK]; /* Index of each token in */
int32 toktyp[SHELL_MAXTOK]; /* Type of each token in tokbuf */
int32 ntok; /* Number of tokens on line */
pid32 child; /* Process ID of spawned child */
bool8 backgnd; /* Run command in background? */
char *outname, *inname; /* Pointers to strings for file */
/* names that follow > and < */
did32 stdinput, stdoutput; /* Descriptors for redirected */
/* input and output */
int32 i; /* Index into array of tokens */
int32 j; /* Index into array of commands */
int32 msg; /* Message from receive() for */
/* child termination */
int32 tmparg; /* Address of this var is used */
/* when first creating child */
/* process, but is replaced */
char *src, *cmp; /* Pointers used during name */
/* comparison */
bool8 diff; /* Was difference found during */
char *args[SHELL_MAXTOK]; /* Argument vector passed to */
/* builtin commands */
did32 dev = 0; /* ID of tty device from which */
/* Print shell banner and startup message */
/*
fprintf(dev, "\n\n%s%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
SHELL_BAN0,SHELL_BAN1,SHELL_BAN2,SHELL_BAN3,SHELL_BAN4,
SHELL_BAN5,SHELL_BAN6,SHELL_BAN7,SHELL_BAN8,SHELL_BAN9,SHELL_BAN10);
fprintf(dev, "%s\n\n", SHELL_STRTMSG);
*/
/* Continually prompt the user, read input, and execute command */
while (TRUE) {
/* Display prompt */
fprintf(dev, SHELL_PROMPT);
len = read(dev, buf, sizeof(buf));
/* Exit gracefully on end-of-file */
if (len == EOF) {
break;
}
/* If line contains only NEWLINE, go to next line */
if (len <= 1) {
continue;
}
buf[len] = SH_NEWLINE; /* terminate line */
/* Parse input line and divide into tokens */
ntok = lexan(buf, len, tokbuf, &tlen, tok, toktyp);
/* Handle parsing error */
if (ntok == SYSERR) {
// fprintf(dev,"%s\n", SHELL_SYNERRMSG);
continue;
}
/* If line is empty, go to next input line */
if (ntok == 0) {
// fprintf(dev, "\n");
continue;
}
/* If last token is '&', set background */
if (toktyp[ntok-1] == SH_TOK_AMPER) {
ntok-- ;
tlen-= 2;
backgnd = TRUE;
} else {
backgnd = FALSE;
}
/* Check for input/output redirection (default is none) */
outname = inname = NULL;
if ( (ntok >=3) && ( (toktyp[ntok-2] == SH_TOK_LESS)
||(toktyp[ntok-2] == SH_TOK_GREATER))){
if (toktyp[ntok-1] != SH_TOK_OTHER) {
// fprintf(dev,"%s\n", SHELL_SYNERRMSG);
continue;
}
if (toktyp[ntok-2] == SH_TOK_LESS) {
inname = &tokbuf[tok[ntok-1]];
} else {
outname = &tokbuf[tok[ntok-1]];
}
ntok -= 2;
tlen = tok[ntok];
}
if ( (ntok >=3) && ( (toktyp[ntok-2] == SH_TOK_LESS)
||(toktyp[ntok-2] == SH_TOK_GREATER))){
if (toktyp[ntok-1] != SH_TOK_OTHER) {
// fprintf(dev,"%s\n", SHELL_SYNERRMSG);
continue;
}
if (toktyp[ntok-2] == SH_TOK_LESS) {
if (inname != NULL) {
// fprintf(dev,"%s\n", SHELL_SYNERRMSG);
continue;
}
inname = &tokbuf[tok[ntok-1]];
} else {
if (outname != NULL) {
// fprintf(dev,"%s\n", SHELL_SYNERRMSG);
continue;
}
outname = &tokbuf[tok[ntok-1]];
}
ntok -= 2;
tlen = tok[ntok];
}
/* Verify remaining tokens are type "other" */
for (i=0; i<ntok; i++) {
if (toktyp[i] != SH_TOK_OTHER) {
break;
}
}
if ((ntok == 0) || (i < ntok)) {
// fprintf(dev, SHELL_SYNERRMSG);
continue;
}
stdinput = stdoutput = dev;
/* Lookup first token in the command table */
for (j = 0; j < ncmd; j++) {
src = cmdtab[j].cname;
cmp = tokbuf;
diff = FALSE;
while (*src != NULLCH) {
if (*cmp != *src) {
diff = TRUE;
break;
}
src++;
cmp++;
}
if (diff || (*cmp != NULLCH)) {
continue;
} else {
break;
}
}
/* Handle command not found */
if (j >= ncmd) {
// fprintf(dev, "command %s not found\n", tokbuf);
continue;
}
/* Handle built-in command */
if (cmdtab[j].cbuiltin) { /* No background or redirect. */
if (inname != NULL || outname != NULL || backgnd){
// fprintf(dev, SHELL_BGERRMSG);
continue;
} else {
/* Set up arg vector for call */
for (i=0; i<ntok; i++) {
args[i] = &tokbuf[tok[i]];
}
/* Call builtin shell function */
if ((*cmdtab[j].cfunc)(ntok, args)
== SHELL_EXIT) {
break;
}
}
continue;
}
/* Open files and redirect I/O if specified */
if (inname != NULL) {
stdinput = open(NAMESPACE,inname,"ro");
if (stdinput == SYSERR) {
// fprintf(dev, SHELL_INERRMSG, inname);
continue;
}
}
if (outname != NULL) {
stdoutput = open(NAMESPACE,outname,"w");
if (stdoutput == SYSERR) {
// fprintf(dev, SHELL_OUTERRMSG, outname);
continue;
} else {
control(stdoutput, F_CTL_TRUNC, 0, 0);
}
}
/* Spawn child thread for non-built-in commands */
// RAFA child = create(cmdtab[j].cfunc,
// RAFA SHELL_CMDSTK, SHELL_CMDPRIO,
// RAFA cmdtab[j].cname, 2, ntok, &tmparg);
child = create(cmdtab[j].cfunc,
300, SHELL_CMDPRIO,
cmdtab[j].cname, 2, ntok, &tmparg);
/* If creation or argument copy fails, report error */
// serial_put_char('X');
// if (child == SYSERR)
// serial_put_char('Y');
if ((child == SYSERR) ||
(addargs(child, ntok, tok, tlen, tokbuf, &tmparg)
== SYSERR) ) {
// serial_put_char('Z');
fprintf(dev, SHELL_CREATMSG);
continue;
}
/* Set stdinput and stdoutput in child to redirect I/O */
proctab[child].prdesc[0] = stdinput;
proctab[child].prdesc[1] = stdoutput;
msg = recvclr();
resume(child);
// RAFA AGREGA
resched();
// serial_put_char('X');
if (! backgnd) {
msg = receive();
while (msg != child) {
msg = receive();
}
}
}
/* Terminate the shell process by returning from the top level */
// fprintf(dev,SHELL_EXITMSG);
return OK;
}

24
shell/xsh_echo.c

@ -0,0 +1,24 @@
/* xsh_echo.c - xsh_echo */
#include <xinu.h>
#include <stdio.h>
/*------------------------------------------------------------------------
* xhs_echo - write argument strings to stdout
*------------------------------------------------------------------------
*/
shellcmd xsh_echo(int nargs, char *args[])
{
int32 i; /* walks through args array */
if (nargs > 1) {
printf("%s", args[1]);
for (i = 2; i < nargs; i++) {
printf(" %s", args[i]);
}
}
printf("\n");
return 0;
}

14
system/create.c

@ -33,7 +33,7 @@ pid32 create(
pid32 pid; /* stores new process id */
struct procent *prptr; /* pointer to proc. table entry */
int32 i;
uint32 *a; /* points to list of args */
// uint32 *a; /* points to list of args */
// RAFA uint32 *saddr; /* stack address */
unsigned char *saddr; /* stack address */
va_list ap;
@ -48,8 +48,8 @@ pid32 create(
if (((saddr = (unsigned char *)getstk(ssize)) ==
(uint32 *)SYSERR ) ||
(pid=newpid()) == SYSERR || priority < 1 ) {
kprintf("STK_ERR"); /* m10[] */
restore(mask);
kprintf("ERROR GETSTK %s\n",name);
return SYSERR;
}
@ -110,16 +110,18 @@ pid32 create(
// POR AHORA NO prptr->pdevs[0] = prptr->pdevs[1] = BADDEV;
//RAFA a = (uint32 *)(&nargs + 1);
//RAFA for (int i = 0; i < nargs; i++) {
//RAFA prptr->parg[i] = (uint32) *a++;
//RAFA }
int * a = (int *)(&nargs + 1);
for (int i = 0; i < nargs; i++) {
prptr->parg[i] = (int) *a++;
}
/* RAFA ESTO ANDA
va_start(ap,nargs);
for (i=0 ; i < nargs; i++)
{
prptr->parg[i] = va_arg(ap, unsigned int);
}
va_end(ap);
/* FIN RAFA ESTO ANDA */
prptr->parg[nargs] = 0;

6
system/initialize.c

@ -46,6 +46,7 @@ extern void *_end; /* End of Xinu code */
/* Function prototypes */
extern void main(void); /* Main is the first process created */
extern process shell(void); /* Main is the first process created */
static void sysinit(); /* Internal system initialization */
extern void meminit(void); /* Initializes the free memory list */
extern int32 initintc(void);
@ -98,7 +99,8 @@ void nullprocess(void) {
kprintf("nullp\n");
resume(create((void *)main, INITSTK, INITPRIO, "Main Process", 0, NULL));
// resume(create((void *)main, INITSTK, INITPRIO, "Main Process", 0, NULL));
resume(create((void *)shell, 300, INITPRIO, "shell", 0, NULL));
for(;;);
}
@ -167,7 +169,7 @@ void nulluser()
free_mem += memptr->mlength;
}
kprintf("FreeMEM:%d", free_mem);
kprintf("\n\rFreeMEM:%d", free_mem);
// for (memptr=memlist.mnext; memptr!=NULL;memptr = memptr->mnext) {
// kprintf("[0x%08X to 0x%08X]\n",
// // RAFA (uint32)memptr, ((uint32)memptr) + memptr->mlength - 1);

4
system/main.c

@ -28,10 +28,10 @@ process main(void)
//blink_avr();
blink_avr();
blink_avr();
// RAFA resume(create(shell, 4096, 50, "shell", 1, 0));
resume(create(shell, 64, 50, "shell", 1, 0));
// resume(create(shell, 64, 50, "shell", 1, 0));
// resume(create(shell, 64, 50, "shell", 0, NULL));
resume(create((void *)main2, INITSTK, 50, "main2", 0, NULL));
// resume(create((void *)main2, INITSTK, 50, "main2", 0, NULL));
for(;;)

3
system/ready.c

@ -15,7 +15,7 @@ status ready(
register struct procent volatile *prptr;
if (isbadpid(pid)) {
kprintf("ready1\n");
kprintf("ready1:%d\n",pid);
return SYSERR;
}
@ -26,6 +26,7 @@ status ready(
insert(pid, readylist, prptr->prprio);
kprintf("readyok\n");
// *SCB_ICSR |= (1 << PENDSV_INTR);
return OK;

9
system/resched.c

@ -151,14 +151,14 @@ int resched(void)
// print_free_mem();
preempt = QUANTUM; /* reset preemption counter */
serial_put_char('X');
// serial_put_char('X');
/* no switch needed if current process priority higher than next */
ptold = (struct pentry *)&proctab[currpid];
if (ptold->prstate == PR_CURR) { /* Process remains eligible */
if (ptold->prprio > firstkey(readylist)) {
kprintf("resch no %s\n", ptold->prname);
// kprintf("resch no %s\n", ptold->prname);
return (OK);
}
@ -191,10 +191,7 @@ int resched(void)
// kprintf("resched: Yes Switch currpid=%d\n", currpid);
// kprintf("ctxs %s\n", ptnew->prname);
serial_put_char('W');
// if ((*ptnew->prname) == 's')
// serial_put_char('S');
// serial_put_char(*ptold->prname);;
// serial_put_char('W');
ctxsw(&ptold->pregs[0],&ptnew->pregs[0]); /* switch context from old to new */
return(OK);

7
system/serial_avr.c

@ -20,7 +20,6 @@ typedef struct
// volatile uart_t *puerto_serial = (uart_t *) (0xc0);
char letra_start = 'R';
// char cadena[100];
#define F_CPU 16000000UL
@ -41,16 +40,13 @@ void serial_init() {
/* Configurar los registros High y Low con BAUD_PRESCALE */
blink_avr();
puerto_serial->baud_rate_h = (unsigned char) (BAUD_PRESCALE>>8);
puerto_serial->baud_rate_l = (unsigned char) (BAUD_PRESCALE);
/* Configurar un frame de 8bits, con un bit de paridad y bit de stop */
puerto_serial->status_control_c = (unsigned char)(INIT);
/* Activar la recepcion y transmicion e interrupcion de recepcion */
puerto_serial->status_control_b = (unsigned char)(EN_RX_TX | UART_RXCIE0);
puerto_serial->status_control_b = (unsigned char)(EN_RX_TX | (1<<UART_RXCIE0));
/* test */
while(!((puerto_serial->status_control_a) & (EN_TX)));
@ -74,6 +70,7 @@ char value;
ISR(USART_RX_vect){
cli();
value = UDR0; //read UART register into value
// serial_put_char (value);
ttyhandler (1, value, 0);
sei();
}

2
system/syscall.c

@ -78,7 +78,7 @@ void _svc_handler(void) {
ret = putc(args[1], args[2]);
break;
default:
kprintf("System call not implemented\n");
kprintf(&m9[0]);
break;
}

3
system/wait.c

@ -31,7 +31,8 @@ syscall wait(
prptr->prstate = PR_WAIT; /* Set state to waiting */
prptr->prsem = sem; /* Record semaphore ID */
enqueue(currpid,semptr->squeue);/* Enqueue on semaphore */
*SCB_ICSR |= (1 << PENDSV_INTR);
// RAFA *SCB_ICSR |= (1 << PENDSV_INTR);
resched();
}
restore(mask);

Loading…
Cancel
Save