mirror of https://github.com/zrafa/xinu-avr.git
46 changed files with 277 additions and 5545 deletions
@ -1,34 +1,11 @@
|
||||
#include <xinu.h> |
||||
|
||||
void avr_printf(char mess[]) |
||||
{ |
||||
char t[80]; |
||||
|
||||
memset(t, 0, 80); |
||||
strncpy_P(t, mess, 79); |
||||
printf("%s", t); |
||||
} |
||||
extern serial_put_char(char); |
||||
|
||||
// void avr_kprintf(char mess[])
|
||||
void avr_kprintf(const unsigned char *msg) |
||||
void avr_kprintf(const __flash char m[]) |
||||
{ |
||||
// char t[80];
|
||||
|
||||
intmask mask; |
||||
|
||||
mask = disable(); |
||||
|
||||
|
||||
while( pgm_read_byte( msg ) != 0 ) { |
||||
// printf( "%c", pgm_read_byte( msg++ ) );
|
||||
putchar(pgm_read_byte( msg++ ) ); |
||||
}; |
||||
|
||||
|
||||
restore(mask); |
||||
/*
|
||||
memset(t, 0, 80); |
||||
strncpy_P(t, mess, 79); |
||||
printf("%s", t); |
||||
*/ |
||||
int i; |
||||
for (i=0; i<strlen_P(m); i++) |
||||
serial_put_char(m[i]); |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,225 @@
|
||||
/* xsh_cal.c - xsh_cal */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
const __flash char dayw[] = { |
||||
" S M Tu W Th F S" |
||||
}; |
||||
/*
|
||||
const __flash char *smon[]= { |
||||
"Jan", "Feb", "Mar", "Apr", |
||||
"May", "Jun", "Jul", "Aug", |
||||
"Sep", "Oct", "Nov", "Dec", |
||||
}; |
||||
*/ |
||||
|
||||
const __flash uint8_t * const __flash smon[] = |
||||
{ |
||||
(const __flash uint8_t[]) { "Jan" }, |
||||
(const __flash uint8_t[]) { "Feb" }, |
||||
(const __flash uint8_t[]) { "Mar" }, |
||||
(const __flash uint8_t[]) { "Apr" }, |
||||
(const __flash uint8_t[]) { "May" }, |
||||
(const __flash uint8_t[]) { "Jun" }, |
||||
(const __flash uint8_t[]) { "Jul" }, |
||||
(const __flash uint8_t[]) { "Aug" }, |
||||
(const __flash uint8_t[]) { "Sep" }, |
||||
(const __flash uint8_t[]) { "Oct" }, |
||||
(const __flash uint8_t[]) { "Nov" }, |
||||
(const __flash uint8_t[]) { "Dec" } |
||||
}; |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_cal - calendar |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
shellcmd xsh_cal(int nargs, char *args[]) |
||||
|
||||
{ |
||||
// char string[4];
|
||||
register y, i, j; |
||||
int m; |
||||
|
||||
if(nargs < 2) { |
||||
// printf("usage: cal [month] year\n");
|
||||
exit(0); |
||||
} |
||||
if(nargs == 2) |
||||
goto xlong; |
||||
|
||||
/*
|
||||
* print out just month |
||||
*/ |
||||
|
||||
m = number(args[1]); |
||||
if(m<1 || m>12) |
||||
goto badarg; |
||||
y = number(args[2]); |
||||
if(y<1 || y>9999) |
||||
goto badarg; |
||||
printf("\n %S ", smon[m-1]); |
||||
printf("%u\n", y); |
||||
printf("%S\n", dayw); |
||||
// cal_p(m, y, string, 24);
|
||||
cal_p(m, y); |
||||
printf("\n"); |
||||
exit(0); |
||||
|
||||
/*
|
||||
* print out complete year |
||||
*/ |
||||
|
||||
xlong: |
||||
y = number(args[1]); |
||||
if(y<1 || y>9999) |
||||
goto badarg; |
||||
for(i=1; i<=12; i++) { |
||||
printf("\n %S ", smon[i-1]); |
||||
printf("%u\n", y); |
||||
printf("%S\n", dayw); |
||||
// cal_p(i, y, string, 24);
|
||||
cal_p(i, y); |
||||
} |
||||
|
||||
printf("\n"); |
||||
exit(0); |
||||
|
||||
badarg: |
||||
printf("Bad argument\n"); |
||||
} |
||||
|
||||
number(str) |
||||
char *str; |
||||
{ |
||||
register n, c; |
||||
register char *s; |
||||
|
||||
n = 0; |
||||
s = str; |
||||
while(c = *s++) { |
||||
if(c<'0' || c>'9') |
||||
return(0); |
||||
n = n*10 + c-'0'; |
||||
} |
||||
return(n); |
||||
} |
||||
|
||||
char mon[] = { |
||||
0, |
||||
31, 29, 31, 30, |
||||
31, 30, 31, 31, |
||||
30, 31, 30, 31, |
||||
}; |
||||
|
||||
|
||||
/*
|
||||
* return day of the week |
||||
* of jan 1 of given year |
||||
*/ |
||||
|
||||
jan1(yr) |
||||
{ |
||||
register y, d; |
||||
|
||||
/*
|
||||
* normal gregorian calendar |
||||
* one extra day per four years |
||||
*/ |
||||
|
||||
y = yr; |
||||
d = 4+y+(y+3)/4; |
||||
|
||||
/*
|
||||
* julian calendar |
||||
* regular gregorian |
||||
* less three days per 400 |
||||
*/ |
||||
|
||||
if(y > 1800) { |
||||
d -= (y-1701)/100; |
||||
d += (y-1601)/400; |
||||
} |
||||
|
||||
/*
|
||||
* great calendar changeover instant |
||||
*/ |
||||
|
||||
if(y > 1752) |
||||
d += 3; |
||||
|
||||
return(d%7); |
||||
} |
||||
|
||||
print_spaces(int d) { |
||||
int i; |
||||
for (i=1; i<d; i++) |
||||
printf(" "); |
||||
|
||||
} |
||||
|
||||
cal_p(m, y) |
||||
{ |
||||
register d, i; |
||||
register char *s; |
||||
|
||||
// s = p;
|
||||
d = jan1(y); |
||||
mon[2] = 29; |
||||
mon[9] = 30; |
||||
|
||||
switch((jan1(y+1)+7-d)%7) { |
||||
|
||||
/*
|
||||
* non-leap year |
||||
*/ |
||||
case 1: |
||||
mon[2] = 28; |
||||
break; |
||||
|
||||
/*
|
||||
* 1752 |
||||
*/ |
||||
default: |
||||
mon[9] = 19; |
||||
break; |
||||
|
||||
/*
|
||||
* leap year |
||||
*/ |
||||
case 2: |
||||
; |
||||
} |
||||
for(i=1; i<m; i++) |
||||
d += mon[i]; |
||||
d %= 7; |
||||
// s += 3*d;
|
||||
print_spaces(3*d+1); |
||||
for(i=1; i<=mon[m]; i++) { |
||||
if(i==3 && mon[m]==19) { |
||||
i += 11; |
||||
mon[m] += 11; |
||||
} |
||||
if(i > 9) |
||||
// *s = i/10+'0';
|
||||
printf("%c", i/10+'0'); |
||||
else |
||||
printf(" "); |
||||
//s++;
|
||||
// printf(" ");
|
||||
// *s++ = i%10+'0';
|
||||
printf("%c", i%10+'0'); |
||||
// s++;
|
||||
printf(" "); |
||||
if(++d == 7) { |
||||
d = 0; |
||||
// s = p+w;
|
||||
// print_spaces(p+w);
|
||||
printf("\n"); |
||||
//p = s;
|
||||
} |
||||
} |
||||
printf("\n"); |
||||
} |
||||
|
||||
@ -1,93 +0,0 @@
|
||||
/* addargs.c - addargs */ |
||||
|
||||
#include <xinu.h> |
||||
#include "shprototypes.h" |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* addargs - Add local copy of argv-style arguments to the stack of |
||||
* a command process that has been created by the shell |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
status addargs( |
||||
pid32 pid, /* ID of process to use */ |
||||
int32 ntok, /* Count of arguments */ |
||||
int32 tok[], /* Index of tokens in tokbuf */ |
||||
int32 tlen, /* Length of data in tokbuf */ |
||||
char *tokbuf, /* Array of null-term. tokens */ |
||||
void *dummy /* Dummy argument that was */ |
||||
/* used at creation and must */ |
||||
/* be replaced by a pointer */ |
||||
/* to an argument vector */ |
||||
) |
||||
{ |
||||
intmask mask; /* Saved interrupt mask */ |
||||
struct procent *prptr; /* Ptr to process' table entry */ |
||||
uint32 aloc; /* Argument location in process */ |
||||
/* stack as an integer */ |
||||
uint32 *argloc; /* Location in process's stack */ |
||||
/* to place args vector */ |
||||
char *argstr; /* Location in process's stack */ |
||||
/* to place arg strings */ |
||||
uint32 *search; /* pointer that searches for */ |
||||
/* dummy argument on stack */ |
||||
uint32 *aptr; /* Walks through args array */ |
||||
int32 i; /* Index into tok array */ |
||||
|
||||
mask = disable(); |
||||
|
||||
/* Check argument count and data length */ |
||||
|
||||
if ( (ntok <= 0) || (tlen < 0) ) { |
||||
restore(mask); |
||||
return SYSERR; |
||||
} |
||||
|
||||
prptr = &proctab[pid]; |
||||
|
||||
/* Compute lowest location in the process stack where the */ |
||||
/* 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 */ |
||||
|
||||
/* Compute the first location beyond args array for the strings */ |
||||
|
||||
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]); |
||||
} |
||||
|
||||
/* Add a null pointer to the args array */ |
||||
|
||||
*aptr++ = (uint32)NULL; |
||||
|
||||
/* Copy the argument strings from tokbuf into process's stack */ |
||||
/* just beyond the args vector */ |
||||
|
||||
memcpy(aptr, tokbuf, tlen); |
||||
|
||||
/* Find the second argument in process's stack */ |
||||
|
||||
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; |
||||
} |
||||
} |
||||
|
||||
/* Argument value not found on the stack - report an error */ |
||||
|
||||
restore(mask); |
||||
return SYSERR; |
||||
} |
||||
@ -1,148 +0,0 @@
|
||||
/* lexan.c - lexan */ |
||||
|
||||
#include <xinu.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* lexan - Ad hoc lexical analyzer to divide command line into tokens |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
int32 lexan ( |
||||
char *line, /* Input line terminated with */ |
||||
/* NEWLINE or NULLCH */ |
||||
int32 len, /* Length of the input line, */ |
||||
/* including NEWLINE */ |
||||
char *tokbuf, /* Buffer into which tokens are */ |
||||
/* stored with a null */ |
||||
/* following each token */ |
||||
int32 *tlen, /* Place to store number of */ |
||||
/* chars in tokbuf */ |
||||
int32 tok[], /* Array of pointers to the */ |
||||
/* start of each token */ |
||||
int32 toktyp[] /* Array that gives the type */ |
||||
/* of each token */ |
||||
) |
||||
{ |
||||
char quote; /* Character for quoted string */ |
||||
uint32 ntok; /* Number of tokens found */ |
||||
char *p; /* Pointer that walks along the */ |
||||
/* input line */ |
||||
int32 tbindex; /* Index into tokbuf */ |
||||
char ch; /* Next char from input line */ |
||||
|
||||
/* Start at the beginning of the line with no tokens */ |
||||
|
||||
ntok = 0; |
||||
p = line; |
||||
tbindex = 0; |
||||
|
||||
/* While not yet at end of line, get next token */ |
||||
|
||||
while ( (*p != NULLCH) && (*p != SH_NEWLINE) ) { |
||||
|
||||
/* If too many tokens, return error */ |
||||
|
||||
if (ntok >= SHELL_MAXTOK) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Skip whitespace before token */ |
||||
|
||||
while ( (*p == SH_BLANK) || (*p == SH_TAB) ) { |
||||
p++; |
||||
} |
||||
|
||||
/* Stop parsing at end of line (or end of string) */ |
||||
|
||||
ch = *p; |
||||
if ( (ch==SH_NEWLINE) || (ch==NULLCH) ) { |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
|
||||
/* Set next entry in tok array to be an index to the */ |
||||
/* current location in the token buffer */ |
||||
|
||||
tok[ntok] = tbindex; /* the start of the token */ |
||||
|
||||
/* Set the token type */ |
||||
|
||||
switch (ch) { |
||||
|
||||
case SH_AMPER: toktyp[ntok] = SH_TOK_AMPER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_LESS: toktyp[ntok] = SH_TOK_LESS; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_GREATER: toktyp[ntok] = SH_TOK_GREATER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
default: toktyp[ntok] = SH_TOK_OTHER; |
||||
}; |
||||
|
||||
/* Handle quoted string (single or double quote) */ |
||||
|
||||
if ( (ch==SH_SQUOTE) || (ch==SH_DQUOTE) ) { |
||||
quote = ch; /* remember opening quote */ |
||||
|
||||
/* Copy quoted string to arg area */ |
||||
|
||||
p++; /* Move past starting quote */ |
||||
|
||||
while ( ((ch=*p++) != quote) && (ch != SH_NEWLINE) |
||||
&& (ch != NULLCH) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
} |
||||
if (ch != quote) { /* string missing end quote */ |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Finished string - count token and go on */ |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate token */ |
||||
ntok++; /* count string as one token */ |
||||
continue; /* go to next token */ |
||||
} |
||||
|
||||
/* Handle a token other than a quoted string */ |
||||
|
||||
tokbuf[tbindex++] = ch; /* put first character in buffer*/ |
||||
p++; |
||||
|
||||
while ( ((ch = *p) != SH_NEWLINE) && (ch != NULLCH) |
||||
&& (ch != SH_LESS) && (ch != SH_GREATER) |
||||
&& (ch != SH_BLANK) && (ch != SH_TAB) |
||||
&& (ch != SH_AMPER) && (ch != SH_SQUOTE) |
||||
&& (ch != SH_DQUOTE) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
p++; |
||||
} |
||||
|
||||
/* Report error if other token is appended */ |
||||
|
||||
if ( (ch == SH_SQUOTE) || (ch == SH_DQUOTE) |
||||
|| (ch == SH_LESS) || (ch == SH_GREATER) ) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate the token */ |
||||
|
||||
ntok++; /* count valid token */ |
||||
|
||||
} |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
@ -1,303 +0,0 @@
|
||||
/* shell.c - shell */ |
||||
|
||||
#include <xinu.h> |
||||
//#include <stdio.h>
|
||||
#include "shprototypes.h" |
||||
|
||||
/************************************************************************/ |
||||
/* Table of Xinu shell commands and the function associated with each */ |
||||
/************************************************************************/ |
||||
const struct cmdent cmdtab[] = { |
||||
{"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 */ |
||||
/* commands. Each command begins with a command name, has */ |
||||
/* a set of optional arguments, has optional input or */ |
||||
/* output redirection, and an optional specification for */ |
||||
/* background execution (ampersand). The syntax is: */ |
||||
/* */ |
||||
/* command_name [args*] [redirection] [&] */ |
||||
/* */ |
||||
/* Redirection is either or both of: */ |
||||
/* */ |
||||
/* < input_file */ |
||||
/* or */ |
||||
/* > output_file */ |
||||
/* */ |
||||
/************************************************************************/ |
||||
|
||||
process shell ( |
||||
did32 dev /* ID of tty device from which */ |
||||
) /* to accept commands */ |
||||
{ |
||||
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 */ |
||||
|
||||
/* 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 */ |
||||
|
||||
child = create(cmdtab[j].cfunc, |
||||
SHELL_CMDSTK, SHELL_CMDPRIO, |
||||
cmdtab[j].cname, 2, ntok, &tmparg); |
||||
|
||||
/* If creation or argument copy fails, report error */ |
||||
|
||||
if ((child == SYSERR) || |
||||
(addargs(child, ntok, tok, tlen, tokbuf, &tmparg) |
||||
== SYSERR) ) { |
||||
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); |
||||
|
||||
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; |
||||
} |
||||
@ -1,21 +0,0 @@
|
||||
/* xsh_argecho.c - xsh_argecho */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xhs_argecho - display argecho message that lists shell commands |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_argecho(int nargs, char *args[]) |
||||
{ |
||||
int32 i; |
||||
|
||||
printf("\n\nThe %d arguments are:\n", nargs); |
||||
for (i = 0; i < nargs; i++) { |
||||
printf(" %2d: %s\n", i, args[i]); |
||||
} |
||||
printf("\n"); |
||||
|
||||
return 0; |
||||
} |
||||
@ -1,59 +0,0 @@
|
||||
/* xsh_cat.c - xsh_cat */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_cat - shell command to cat one or more files |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_cat(int nargs, char *args[]) |
||||
{ |
||||
int32 i; /* index into proctabl */ |
||||
int32 nextch; /* character read from file */ |
||||
did32 descr; /* descriptor for a file */ |
||||
char *argptr; /* pointer to next arg string */ |
||||
|
||||
|
||||
/* For argument '--help', emit help about the 'cat' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Use: %s [file...]\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\twrites contents of files or stdin to stdout\n"); |
||||
printf("Options:\n"); |
||||
printf("\tfile...\tzero or more file names\n"); |
||||
printf("\t--help\t display this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
if (nargs == 1) { |
||||
nextch = getc(stdin); |
||||
while (nextch != EOF) { |
||||
putc(stdout, nextch); |
||||
nextch = getc(stdin); |
||||
} |
||||
return 0; |
||||
} |
||||
for (i = 1; i < nargs; i++) { |
||||
argptr = args[i]; |
||||
if ( (argptr[0] == '-') && (argptr[1] == NULLCH) ) { |
||||
descr = stdin; |
||||
} else { |
||||
descr = open(NAMESPACE, argptr, "ro"); |
||||
if (descr == (did32)SYSERR) { |
||||
fprintf(stderr, "%s: cannot open file %s\n", |
||||
args[0], argptr); |
||||
return 1; |
||||
} |
||||
} |
||||
nextch = getc(descr); |
||||
while (nextch != EOF) { |
||||
putc(stdout, nextch); |
||||
nextch = getc(descr); |
||||
} |
||||
close(descr); |
||||
} |
||||
return 0; |
||||
} |
||||
@ -1,22 +0,0 @@
|
||||
/* xsh_clear.c - xsh_clear */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_clear - clear the display window (assumes xterm / VT100) |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_clear(int nargs, char *args[]) |
||||
{ |
||||
|
||||
/* Insure no arguments were passed */ |
||||
|
||||
if (nargs > 1) { |
||||
fprintf(stderr,"use is: %s\n", args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
printf("\033[0m\033[2J\033[H\n"); |
||||
return 0; |
||||
} |
||||
@ -1,69 +0,0 @@
|
||||
/* xsh_date.c - xsh_date */ |
||||
|
||||
#include <xinu.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_date - obtain and print the current month, day, year, and time |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_date(int nargs, char *args[]) { |
||||
|
||||
int32 retval; /* return value */ |
||||
uint32 now; /* current local time */ |
||||
char datestr[64]; /* printable date in ascii */ |
||||
|
||||
/* Output info for '--help' argument */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Usage: %s\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDisplays the current date and time\n"); |
||||
printf("Options (one per invocation):\n"); |
||||
printf("\t-f\tforce a time server request to be sent\n"); |
||||
printf("\t-d\tset daylight savings time on\n"); |
||||
printf("\t-s\tset standard time (not daylight savings)\n"); |
||||
printf("\t-a\tset daylight savings to automatic\n"); |
||||
printf("\t--help\tdisplay this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check argument count */ |
||||
|
||||
if (nargs > 2) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
if (nargs == 2) { |
||||
if (strncmp(args[1], "-f", 3) == 0) { |
||||
Date.dt_bootvalid = FALSE; |
||||
} else if (strncmp(args[1], "-d", 3) == 0) { |
||||
Date.dt_daylight = DATE_DST_ON; |
||||
} else if (strncmp(args[1], "-s", 3) == 0) { |
||||
Date.dt_daylight = DATE_DST_OFF; |
||||
} else if (strncmp(args[1], "-a", 3) == 0) { |
||||
Date.dt_daylight = DATE_DST_AUTO; |
||||
} else { |
||||
fprintf(stderr, "%s: invalid argument\n", args[0]); |
||||
fprintf(stderr, |
||||
"Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
retval = gettime(&now); |
||||
if (retval == SYSERR) { |
||||
fprintf(stderr, |
||||
"%s: could not obtain the current date\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
ascdate(now, datestr); |
||||
printf("%s\n", datestr); |
||||
return 0; |
||||
} |
||||
@ -1,36 +0,0 @@
|
||||
/* xsh_devdump.c - xsh_devdump */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_devdump - shell command to print info from the device switch table |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_devdump ( |
||||
int nargs, /* number of arguments */ |
||||
char *args[] /* list of arguments */ |
||||
) |
||||
{ |
||||
struct dentry *devptr; /* pointer to device entry */ |
||||
int32 i; /* walks through device table */ |
||||
|
||||
/* No arguments are expected */ |
||||
|
||||
if (nargs > 1) { |
||||
fprintf(stderr, "No arguments allowed\n"); |
||||
return 1; |
||||
} |
||||
|
||||
/* Walk through device table */ |
||||
|
||||
printf("Device Name Minor\n"); |
||||
printf("------ ------------ -----\n"); |
||||
|
||||
for (i = 0; i < NDEVS; i++) { |
||||
devptr = &devtab[i]; |
||||
printf("%4d %-12s %3d\n", i, devptr->dvname, |
||||
devptr->dvminor); |
||||
} |
||||
return 0; |
||||
} |
||||
@ -1,24 +0,0 @@
|
||||
/* 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; |
||||
} |
||||
@ -1,13 +0,0 @@
|
||||
/* xsh_exit.c - xshexit */ |
||||
|
||||
#include <xinu.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_exit - shell command returns the exit code causing shell exit |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
shellcmd xsh_exit(int nargs, char *args[]) |
||||
{ |
||||
return SHELL_EXIT; |
||||
} |
||||
@ -1,124 +0,0 @@
|
||||
/* xsh_help.c - xsh_help */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xhs_help - display help message that lists shell commands |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_help(int nargs, char *args[]) |
||||
{ |
||||
int32 i; |
||||
char *argv[2]; /* argument vector for call */ |
||||
char *src, *cmp; /* used for string compare */ |
||||
int32 len; /* length of a command name */ |
||||
int32 maxlen; /* maximum length of all */ |
||||
/* command names */ |
||||
int32 cols; /* number of columns in the */ |
||||
/* formatted command list */ |
||||
int32 spac; /* space per column in the */ |
||||
/* formatted command list */ |
||||
int32 lines; /* total lines of output in the */ |
||||
/* formatted command list */ |
||||
int32 j; /* index of commands across one */ |
||||
/* line of formatted output */ |
||||
|
||||
/* For argument '--help', emit help about the 'help' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
|
||||
printf("Use:\n"); |
||||
printf("\t%s [command]\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tProvides a list of shell commands or\n"); |
||||
printf("\thelp information for a specific command\n"); |
||||
printf("Options:\n"); |
||||
printf("\tcommand\tspecific command for which to\n"); |
||||
printf("\t\tdisplay help information\n"); |
||||
printf("\t--help\tdisplay this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs > 2) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
/* Output help for specific command given as an argument */ |
||||
|
||||
if (nargs == 2) { |
||||
for (i = 0; i < ncmd; i++) { |
||||
src = cmdtab[i].cname; |
||||
cmp = args[1]; |
||||
while (*src != NULLCH) { |
||||
if (*src != *cmp) { |
||||
break; |
||||
} |
||||
src++; |
||||
cmp++; |
||||
} |
||||
if ( (*src != NULLCH) || (*cmp != NULLCH) ) { |
||||
continue; |
||||
} |
||||
|
||||
/* prepare args for shell command */ |
||||
|
||||
argv[0] = args[1]; |
||||
argv[1] = "--help"; |
||||
(*cmdtab[i].cfunc) (2, argv); |
||||
return 0; |
||||
} |
||||
printf("%s: no such command as '%s'\n", args[0], args[1]); |
||||
return 1; |
||||
} |
||||
|
||||
/* No arguments -- print a list of shell commands */ |
||||
|
||||
printf("\nshell commands are:\n\n"); |
||||
|
||||
/* Calculate the maximum length of a command name */ |
||||
|
||||
maxlen = 0; |
||||
for (i = 0; i < ncmd; i++) { |
||||
len = strnlen(cmdtab[i].cname, 80); |
||||
if (len > maxlen) { |
||||
maxlen = len; |
||||
} |
||||
} |
||||
|
||||
/* Calculate the number of command names per line */ |
||||
|
||||
cols = 80/(maxlen+1); |
||||
if (cols > 6) { |
||||
cols = 6; |
||||
} |
||||
|
||||
/* Calculate the width of a column */ |
||||
|
||||
spac = 80/cols; |
||||
|
||||
/* Calculate the number of lines of output */ |
||||
|
||||
lines = (ncmd+(cols-1))/cols; |
||||
|
||||
/* print the lines of command names */ |
||||
|
||||
for (i=0; i<lines; i++) { |
||||
for (j=i; j<ncmd; j+=lines) { |
||||
len = strnlen(cmdtab[j].cname,80); |
||||
printf("%s", cmdtab[j].cname); |
||||
while (len < spac) { |
||||
printf(" "); |
||||
len++; |
||||
} |
||||
} |
||||
printf("\n"); |
||||
} |
||||
return 0; |
||||
} |
||||
@ -1,66 +0,0 @@
|
||||
/* xsh_kill.c - xsh_kill */ |
||||
|
||||
#include <xinu.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_kill - obtain and print the current month, day, year, and time |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_kill(int nargs, char *args[]) { |
||||
|
||||
int32 retval; /* return value */ |
||||
pid32 pid; /* ID of process to kill */ |
||||
char ch; /* next character of argument */ |
||||
char *chptr; /* walks along argument string */ |
||||
|
||||
/* Output info for '--help' argument */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Usage: %s PID\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tterminates a process\n"); |
||||
printf("Options:\n"); |
||||
printf("\tPID \tthe ID of a process to terminate\n"); |
||||
printf("\t--help\tdisplay this help and exit\n"); |
||||
return OK; |
||||
} |
||||
|
||||
/* Check argument count */ |
||||
|
||||
if (nargs != 2) { |
||||
fprintf(stderr, "%s: incorrect argument\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* compute process ID from argument string */ |
||||
|
||||
chptr = args[1]; |
||||
ch = *chptr++; |
||||
pid = 0; |
||||
while(ch != NULLCH) { |
||||
if ( (ch < '0') || (ch > '9') ) { |
||||
fprintf(stderr, "%s: non-digit in process ID\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
pid = 10*pid + (ch - '0'); |
||||
ch = *chptr++; |
||||
} |
||||
if (pid == 0) { |
||||
fprintf(stderr, "%s: cannot kill the null process\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
retval = kill(pid); |
||||
if (retval == SYSERR) { |
||||
fprintf(stderr, "%s: cannot kill process %d\n", |
||||
args[0], pid); |
||||
return 1; |
||||
} |
||||
return 0; |
||||
} |
||||
@ -1,165 +0,0 @@
|
||||
/* xsh_memdump.c - xsh_memdump */ |
||||
|
||||
#include <xinu.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
|
||||
static uint32 parseval(char *); |
||||
extern uint32 start; |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_memdump - dump a region of memory by displaying values in hex |
||||
* and ascii |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_memdump(int nargs, char *args[]) |
||||
{ |
||||
bool8 force = FALSE; /* ignore address sanity checks */ |
||||
uint32 begin; /* begining address */ |
||||
uint32 stop; /* last address to dump */ |
||||
uint32 length; /* length of region to dump */ |
||||
int32 arg; /* index into args array */ |
||||
uint32 l; /* counts length during dump */ |
||||
int32 i; /* counts words during dump */ |
||||
uint32 *addr; /* address to dump */ |
||||
char *chptr; /* character address to dump */ |
||||
char ch; /* next character to print */ |
||||
|
||||
/* For argument '--help', emit help about the 'memdump' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Use: %s [-f] Address Length\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDumps Length bytes of memory begining at the\n"); |
||||
printf("\tspecified starting address (both the address\n"); |
||||
printf("\tand length can be specified in decimal or hex)\n"); |
||||
printf("Options:\n"); |
||||
printf("\t-f ignore sanity checks for addresses\n"); |
||||
printf("\tAddress memory address at which to start\n"); |
||||
printf("\tLength the number of bytes to dump\n"); |
||||
printf("\t--help display this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs < 3 || nargs > 4) { |
||||
fprintf(stderr, "%s: incorrect number of arguments\n", |
||||
args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
arg = 1; |
||||
if (strncmp(args[arg], "-f", 2) == 0) { |
||||
force = TRUE; |
||||
arg++; |
||||
nargs --; |
||||
} |
||||
|
||||
if (nargs != 3) { |
||||
fprintf(stderr, "%s: too few arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
if ( (begin=parseval(args[arg])) == 0 ) { |
||||
fprintf(stderr, "%s: invalid begining address\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
if ( (length =parseval(args[arg+1])) == 0 ) { |
||||
fprintf(stderr, "%s: invalid length address\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
/* Round begining address down to multiple of four and round */ |
||||
/* length up to a multiple of four */ |
||||
|
||||
begin &= ~0x3; |
||||
length = (length + 3) & ~0x3; |
||||
|
||||
/* Add length to begin address */ |
||||
|
||||
stop = begin + length; |
||||
|
||||
/* verify that the address and length are reasonable */ |
||||
|
||||
if ( force || ( (begin >= (uint32)&start) && (stop > begin) && |
||||
(((void *)stop) < maxheap)) ) { |
||||
|
||||
/* values are valid; perform dump */ |
||||
|
||||
chptr = (char *)begin; |
||||
for (l=0; l<length; l+=16) { |
||||
printf("%08x: ", begin); |
||||
addr = (uint32 *)begin; |
||||
for (i=0; i<4; i++) { |
||||
printf("%08x ",*addr++); |
||||
} |
||||
printf(" *"); |
||||
for (i=0; i<16; i++) { |
||||
ch = *chptr++; |
||||
if ( (ch >= 0x20) && (ch <= 0x7e) ) { |
||||
printf("%c",ch); |
||||
} else { |
||||
printf("."); |
||||
} |
||||
} |
||||
printf("*\n"); |
||||
begin += 16; |
||||
} |
||||
return 0; |
||||
} else { |
||||
printf("Values are out of range; use -f to force\n"); |
||||
} |
||||
return 1; |
||||
} |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* parse - parse an argument that is either a decimal or hex value |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static uint32 parseval( |
||||
char *string /* argument string to parse */ |
||||
) |
||||
{ |
||||
uint32 value; /* value to return */ |
||||
char ch; /* next character */ |
||||
|
||||
|
||||
value = 0; |
||||
|
||||
/* argument string must consists of decimal digits or */ |
||||
/* 0x followed by hex digits */ |
||||
|
||||
ch = *string++; |
||||
if (ch == '0') { /* hexadecimal */ |
||||
if (*string++ != 'x') { |
||||
return 0; |
||||
} |
||||
for (ch = *string++; ch != NULLCH; ch = *string++) { |
||||
if ((ch >= '0') && (ch <= '9') ) { |
||||
value = 16*value + (ch - '0'); |
||||
} else if ((ch >= 'a') && (ch <= 'f') ) { |
||||
value = 16*value + 10 + (ch - 'a'); |
||||
} else if ((ch >= 'A') && (ch <= 'F') ) { |
||||
value = 16*value + 10 + (ch - 'A'); |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
} else { /* decimal */ |
||||
while (ch != NULLCH) { |
||||
if ( (ch < '0') || (ch > '9') ) { |
||||
return 0; |
||||
} |
||||
value = 10*value + (ch - '0'); |
||||
ch = *string++; |
||||
} |
||||
} |
||||
return value; |
||||
} |
||||
@ -1,115 +0,0 @@
|
||||
/* xsh_memstat.c - xsh_memstat */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
static void printMemUse(void); |
||||
static void printFreeList(void); |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_memstat - Print statistics about memory use and dump the free list |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_memstat(int nargs, char *args[]) |
||||
{ |
||||
|
||||
/* For argument '--help', emit help about the 'memstat' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("use: %s \n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDisplays the current memory use and prints the\n"); |
||||
printf("\tfree list.\n"); |
||||
printf("Options:\n"); |
||||
printf("\t--help\t\tdisplay this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs > 1) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
printMemUse(); |
||||
printFreeList(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printFreeList - Walk the list of free memory blocks and print the |
||||
* location and size of each |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printFreeList(void) |
||||
{ |
||||
struct memblk *block; |
||||
|
||||
/* Output a heading for the free list */ |
||||
|
||||
printf("Free List:\n"); |
||||
printf("Block address Length (dec) Length (hex)\n"); |
||||
printf("------------- ------------ ------------\n"); |
||||
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
printf(" 0x%08x %9d 0x%08x\n", block, |
||||
block->mlength, block->mlength); |
||||
} |
||||
printf("\n"); |
||||
} |
||||
|
||||
extern void start(void); |
||||
extern void *_end; |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printMemUse - Print statistics about memory use |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printMemUse(void) |
||||
{ |
||||
int i; /* Index into process table */ |
||||
uint32 code = 0; /* Total Xinu code memory */ |
||||
uint32 stack = 0; /* Total used stack memory */ |
||||
uint32 mspstack = HANDLERSTACK; /* Total used handler stack mem */ |
||||
uint32 kheap = 0; /* Free kernel heap memory */ |
||||
uint32 kfree = 0; /* Total free memory */ |
||||
struct memblk *block; /* Ptr to memory block */ |
||||
|
||||
/* Calculate amount of text memory */ |
||||
|
||||
code = (uint32)&etext - (uint32)&text; |
||||
|
||||
/* Calculate amount of allocated stack memory */ |
||||
/* Skip the NULL process since it has a private stack */ |
||||
|
||||
for (i = 0; i < NPROC; i++) { |
||||
if (proctab[i].prstate != PR_FREE) { |
||||
stack += (uint32)proctab[i].prstklen; |
||||
} |
||||
} |
||||
|
||||
/* Calculate the amount of memory on the free list */ |
||||
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
kfree += block->mlength; |
||||
} |
||||
|
||||
/* Calculate the amount of free kernel heap memory */ |
||||
|
||||
kheap = kfree - stack; |
||||
|
||||
/* Output statistics on current memory use */ |
||||
|
||||
printf("Current system memory statistics:\n"); |
||||
printf("---------------------------------\n"); |
||||
printf("%10d bytes (0x%08x) of Xinu code\n", code, code); |
||||
printf("%10d bytes (0x%08x) of allocated stack space\n", stack, stack); |
||||
printf("%10d bytes (0x%08x) of allocated kernel stack space\n", mspstack, mspstack); |
||||
printf("%10d bytes (0x%08x) of available kernel heap space\n\n", kheap, kheap); |
||||
} |
||||
@ -1,69 +0,0 @@
|
||||
/* xsh_ps.c - xsh_ps */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_ps - shell command to print the process table |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_ps(int nargs, char *args[]) |
||||
{ |
||||
|
||||
// uint32 * linkreg;
|
||||
// asm volatile ("mov %0, lr" : : "r" (linkreg));
|
||||
// kprintf("LINK REG: %x\n", linkreg);
|
||||
|
||||
struct procent *prptr; /* pointer to process */ |
||||
int32 i; /* index into proctabl */ |
||||
char *pstate[] = { /* names for process states */ |
||||
"free ", "curr ", "ready", "recv ", "sleep", "susp ", |
||||
"wait ", "rtime"}; |
||||
|
||||
/* For argument '--help', emit help about the 'ps' command */ |
||||
|
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Use: %s\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDisplays information about running processes\n"); |
||||
printf("Options:\n"); |
||||
printf("\t--help\t display this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs > 1) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
/* Print header for items from the process table */ |
||||
|
||||
printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n", |
||||
"Pid", "Name", "State", "Prio", "Ppid", "Stack Base", |
||||
"Stack Ptr", "Stack Size"); |
||||
|
||||
printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n", |
||||
"---", "----------------", "-----", "----", "----", |
||||
"----------", "----------", "----------"); |
||||
|
||||
/* Output information for each process */ |
||||
|
||||
for (i = 0; i < NPROC; i++) { |
||||
prptr = &proctab[i]; |
||||
if (prptr->prstate == PR_FREE) { /* skip unused slots */ |
||||
continue; |
||||
} |
||||
printf("%3d %-16s %s %4d %4d 0x%08X 0x%08X %8d\n", |
||||
i, prptr->prname, pstate[(int)prptr->prstate], |
||||
prptr->prprio, prptr->prparent, prptr->prstkbase, |
||||
prptr->prstkptr, prptr->prstklen); |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
@ -1,118 +0,0 @@
|
||||
/* xsh_rdstest.c - xsh_rdstest */ |
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_rdstest - shell to print the time the system has been up |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_rdstest(int nargs, char *args[]) |
||||
{ |
||||
bool8 err; |
||||
int32 retval; |
||||
int32 i, j; |
||||
char dskname[] = "TestDisk"; |
||||
|
||||
char buff[2048]; |
||||
char buff2[2048]; |
||||
|
||||
retval = open(RDISK,dskname,"rw"); |
||||
|
||||
if (retval < 0) { |
||||
kprintf("xsh_rdstest: open %s returns %s, stopping\r\n", |
||||
dskname, retval==SYSERR?"SYSERR":"TIMEOUT"); |
||||
close( RDISK ); |
||||
return 1; |
||||
} else { |
||||
kprintf("xsh_rdstest: open %s returns %d\r\n", |
||||
dskname, retval); |
||||
} |
||||
|
||||
kprintf("writing eight blocks to the disk\r\n"); |
||||
for (i=7; i>=0; i--) { |
||||
memset(buff, (char)(i&0xff), RD_BLKSIZ); |
||||
kprintf("\n\r*** writing block %d\n\r",i); |
||||
retval = write(RDISK, buff, i); |
||||
if (retval < 0) { |
||||
kprintf("write to block %d returns %d\r\n", i, retval); |
||||
} |
||||
} |
||||
kprintf("reading block 1\n\r"); |
||||
retval = read(RDISK, buff, 1); |
||||
kprintf("read from block 1 has return value %d\r\n", retval); |
||||
|
||||
err = 0; |
||||
for (i=0; i<RD_BLKSIZ; i++) { |
||||
if (buff[i] != (char) (0xff&1)) { |
||||
err = 1; |
||||
break; |
||||
} |
||||
} |
||||
if (err == 0) { |
||||
kprintf("Block 1 came back intact!!!\r\n"); |
||||
} else { |
||||
kprintf("Sadly :-( byte %d is not correct!!!\r\n", i); |
||||
} |
||||
|
||||
kprintf("reading block 6\n\r"); |
||||
retval = read(RDISK, buff, 6); |
||||
err = 0; |
||||
for (i=0; i<RD_BLKSIZ; i++) { |
||||
if (buff[i] != (char) (0xff&6)) { |
||||
err = 1; |
||||
break; |
||||
} |
||||
} |
||||
if (err == 0) { |
||||
kprintf("Block 6 came back intact!!!\r\n"); |
||||
} else { |
||||
kprintf("Sadly :-( byte %d is not correct!!!\r\n", i); |
||||
} |
||||
|
||||
j = 0; |
||||
for (i=0; i<RD_BLKSIZ; i++) { |
||||
buff2[i] = "abcdefghijklmnopqrstuvwxyz"[j++]; |
||||
j %= 13; |
||||
} |
||||
|
||||
kprintf("rewriting block 5\n\r"); |
||||
retval = write(RDISK, buff2, 5); |
||||
kprintf("write to block 5 has return value %d\r\n", retval); |
||||
|
||||
kprintf("reading block 5\n\r"); |
||||
retval = read(RDISK, buff2, 5); |
||||
|
||||
err = 0; |
||||
for (i=0; i<RD_BLKSIZ; i++) { |
||||
if (buff2[i] != buff[i]) { |
||||
err = 1; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (err == 0) { |
||||
kprintf("Block 5 came back intact!!!\r\n"); |
||||
} else { |
||||
kprintf("Sadly :-( byte %d is not correct!!!\r\n", i); |
||||
} |
||||
|
||||
memset(buff, NULLCH, RD_BLKSIZ); |
||||
|
||||
kprintf("reading block 6 again\n\r"); |
||||
retval = read(RDISK, buff, 6); |
||||
kprintf("read from block 6 has return value %d\r\n", retval); |
||||
|
||||
err = 0; |
||||
for (i=0; i<RD_BLKSIZ; i++) { |
||||
if ( buff[i] != (char)(0xff&6) ) { |
||||
err = 1; |
||||
break; |
||||
} |
||||
} |
||||
if (err == 0) { |
||||
kprintf("Got back identical results!!!\r\n"); |
||||
} else { |
||||
kprintf("Sadly :-( byte %d differs!!!\r\n", i); |
||||
} |
||||
return 0; |
||||
} |
||||
@ -1,58 +0,0 @@
|
||||
/* xsh_sleep.c - xsh_sleep */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_sleep - Shell command to delay for a specified number of seconds |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_sleep(int nargs, char *args[]) |
||||
{ |
||||
int32 delay; /* Delay in seconds */ |
||||
char *chptr; /* Walks through argument */ |
||||
char ch; /* Next character of argument */ |
||||
|
||||
/* For argument '--help', emit help about the 'sleep' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Use: %s\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDelay for a specified number of seconds\n"); |
||||
printf("Options:\n"); |
||||
printf("\t--help\t display this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs > 2) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
if (nargs != 2) { |
||||
fprintf(stderr, "%s: argument in error\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
chptr = args[1]; |
||||
ch = *chptr++; |
||||
delay = 0; |
||||
while (ch != NULLCH) { |
||||
if ( (ch < '0') || (ch > '9') ) { |
||||
fprintf(stderr, "%s: nondigit in argument\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
delay = 10*delay + (ch - '0'); |
||||
ch = *chptr++; |
||||
} |
||||
sleep(delay); |
||||
return 0; |
||||
} |
||||
@ -1,76 +0,0 @@
|
||||
/* xsh_uptime.c - xsh_uptime */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_uptime - shell to print the time the system has been up |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_uptime(int nargs, char *args[]) |
||||
{ |
||||
|
||||
uint32 days, hrs, mins, secs; /* days, hours, minutes, and */ |
||||
/* seconds since system boot */ |
||||
uint32 secperday = 86400; /* seconds in a day */ |
||||
uint32 secperhr = 3600; /* seconds in an hour */ |
||||
uint32 secpermin = 60; /* seconds in a minute */
|
||||
|
||||
/* For argument '--help', emit help about the 'uptime' command */ |
||||
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("Use: %s\n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDisplays time since the system booted\n"); |
||||
printf("Options:\n"); |
||||
printf("\t--help\t display this help and exit\n"); |
||||
return 0; |
||||
} |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
if (nargs > 1) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
|
||||
secs = clktime; /* total seconds since boot */ |
||||
|
||||
/* subtract number of whole days */ |
||||
|
||||
days = secs/secperday; |
||||
secs -= days*secperday; |
||||
|
||||
/* subtract number of hours */ |
||||
|
||||
hrs = secs/secperhr; |
||||
secs -= hrs*secperhr; |
||||
|
||||
/* subtract number of minutes */ |
||||
|
||||
mins = secs/secpermin; |
||||
secs -= mins*secpermin; |
||||
|
||||
printf("Xinu has been up "); |
||||
if (days > 0) { |
||||
printf(" %d day(s) ", days); |
||||
} |
||||
|
||||
if (hrs > 0) { |
||||
printf(" %d hour(s) ", hrs); |
||||
} |
||||
|
||||
if (mins > 0) { |
||||
printf(" %d minute(s) ", mins); |
||||
} |
||||
|
||||
if (secs > 0) { |
||||
printf(" %d second(s) ", secs); |
||||
} |
||||
printf("\n"); |
||||
|
||||
return 0; |
||||
} |
||||
@ -1,6 +0,0 @@
|
||||
|
||||
This app needs the below modificationes into conf/Configuration file: |
||||
|
||||
#define NPROC 3 /* number of user processes */ |
||||
#define NSEM 2 /* number of semaphores */ |
||||
|
||||
@ -1,119 +0,0 @@
|
||||
/* addargs.c - addargs */ |
||||
|
||||
#include <xinu.h> |
||||
#include "shprototypes.h" |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* addargs - Add local copy of argv-style arguments to the stack of |
||||
* a command process that has been created by the shell |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
status addargs( |
||||
pid32 pid, /* ID of process to use */ |
||||
int32 ntok, /* Count of arguments */ |
||||
int32 tok[], /* Index of tokens in tokbuf */ |
||||
int32 tlen, /* Length of data in tokbuf */ |
||||
char *tokbuf, /* Array of null-term. tokens */ |
||||
void *dummy /* Dummy argument that was */ |
||||
/* used at creation and must */ |
||||
/* be replaced by a pointer */ |
||||
/* to an argument vector */ |
||||
) |
||||
{ |
||||
intmask mask; /* Saved interrupt mask */ |
||||
struct procent *prptr; /* Ptr to process' table entry */ |
||||
uint32 aloc; /* Argument location in process */ |
||||
/* stack as an integer */ |
||||
uint32 *argloc; /* Location in process's stack */ |
||||
/* to place args vector */ |
||||
char *argstr; /* Location in process's stack */ |
||||
/* to place arg strings */ |
||||
uint32 *search; /* pointer that searches for */ |
||||
/* dummy argument on stack */ |
||||
uint32 *aptr; /* Walks through args array */ |
||||
int32 i; /* Index into tok array */ |
||||
|
||||
mask = disable(); |
||||
|
||||
/* Check argument count and data length */ |
||||
|
||||
if ( (ntok <= 0) || (tlen < 0) ) { |
||||
// serial_put_char('M');
|
||||
restore(mask); |
||||
return SYSERR; |
||||
} |
||||
|
||||
prptr = &proctab[pid]; |
||||
|
||||
/* Compute lowest location in the process stack where the */ |
||||
/* 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 */
|
||||
|
||||
/* Compute the first location beyond args array for the strings */ |
||||
//
|
||||
// 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]);
|
||||
// }
|
||||
|
||||
/* Add a null pointer to the args array */ |
||||
|
||||
// *aptr++ = (uint32)NULL;
|
||||
|
||||
/* Copy the argument strings from tokbuf into process's stack */ |
||||
/* just beyond the args vector */ |
||||
|
||||
// memcpy(aptr, tokbuf, tlen);
|
||||
|
||||
/* Find the second argument in process's stack */ |
||||
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
|
||||
/* 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 OK; |
||||
// return SYSERR;
|
||||
} |
||||
@ -1,119 +0,0 @@
|
||||
/* addargs.c - addargs */ |
||||
|
||||
#include <xinu.h> |
||||
#include "shprototypes.h" |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* addargs - Add local copy of argv-style arguments to the stack of |
||||
* a command process that has been created by the shell |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
status addargs( |
||||
pid32 pid, /* ID of process to use */ |
||||
int32 ntok, /* Count of arguments */ |
||||
int32 tok[], /* Index of tokens in tokbuf */ |
||||
int32 tlen, /* Length of data in tokbuf */ |
||||
char *tokbuf, /* Array of null-term. tokens */ |
||||
void *dummy /* Dummy argument that was */ |
||||
/* used at creation and must */ |
||||
/* be replaced by a pointer */ |
||||
/* to an argument vector */ |
||||
) |
||||
{ |
||||
intmask mask; /* Saved interrupt mask */ |
||||
struct procent *prptr; /* Ptr to process' table entry */ |
||||
uint32 aloc; /* Argument location in process */ |
||||
/* stack as an integer */ |
||||
uint32 *argloc; /* Location in process's stack */ |
||||
/* to place args vector */ |
||||
char *argstr; /* Location in process's stack */ |
||||
/* to place arg strings */ |
||||
uint32 *search; /* pointer that searches for */ |
||||
/* dummy argument on stack */ |
||||
uint32 *aptr; /* Walks through args array */ |
||||
int32 i; /* Index into tok array */ |
||||
|
||||
mask = disable(); |
||||
|
||||
/* Check argument count and data length */ |
||||
|
||||
if ( (ntok <= 0) || (tlen < 0) ) { |
||||
// serial_put_char('M');
|
||||
restore(mask); |
||||
return SYSERR; |
||||
} |
||||
|
||||
prptr = &proctab[pid]; |
||||
|
||||
/* Compute lowest location in the process stack where the */ |
||||
/* 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 */
|
||||
|
||||
/* Compute the first location beyond args array for the strings */ |
||||
//
|
||||
// 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]);
|
||||
// }
|
||||
|
||||
/* Add a null pointer to the args array */ |
||||
|
||||
// *aptr++ = (uint32)NULL;
|
||||
|
||||
/* Copy the argument strings from tokbuf into process's stack */ |
||||
/* just beyond the args vector */ |
||||
|
||||
// memcpy(aptr, tokbuf, tlen);
|
||||
|
||||
/* Find the second argument in process's stack */ |
||||
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
|
||||
/* 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 OK; |
||||
// return SYSERR;
|
||||
} |
||||
@ -1,148 +0,0 @@
|
||||
/* lexan.c - lexan */ |
||||
|
||||
#include <xinu.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* lexan - Ad hoc lexical analyzer to divide command line into tokens |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
int32 lexan ( |
||||
char *line, /* Input line terminated with */ |
||||
/* NEWLINE or NULLCH */ |
||||
int32 len, /* Length of the input line, */ |
||||
/* including NEWLINE */ |
||||
char *tokbuf, /* Buffer into which tokens are */ |
||||
/* stored with a null */ |
||||
/* following each token */ |
||||
int32 *tlen, /* Place to store number of */ |
||||
/* chars in tokbuf */ |
||||
int32 tok[], /* Array of pointers to the */ |
||||
/* start of each token */ |
||||
int32 toktyp[] /* Array that gives the type */ |
||||
/* of each token */ |
||||
) |
||||
{ |
||||
char quote; /* Character for quoted string */ |
||||
uint32 ntok; /* Number of tokens found */ |
||||
char *p; /* Pointer that walks along the */ |
||||
/* input line */ |
||||
int32 tbindex; /* Index into tokbuf */ |
||||
char ch; /* Next char from input line */ |
||||
|
||||
/* Start at the beginning of the line with no tokens */ |
||||
|
||||
ntok = 0; |
||||
p = line; |
||||
tbindex = 0; |
||||
|
||||
/* While not yet at end of line, get next token */ |
||||
|
||||
while ( (*p != NULLCH) && (*p != SH_NEWLINE) ) { |
||||
|
||||
/* If too many tokens, return error */ |
||||
|
||||
if (ntok >= SHELL_MAXTOK) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Skip whitespace before token */ |
||||
|
||||
while ( (*p == SH_BLANK) || (*p == SH_TAB) ) { |
||||
p++; |
||||
} |
||||
|
||||
/* Stop parsing at end of line (or end of string) */ |
||||
|
||||
ch = *p; |
||||
if ( (ch==SH_NEWLINE) || (ch==NULLCH) ) { |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
|
||||
/* Set next entry in tok array to be an index to the */ |
||||
/* current location in the token buffer */ |
||||
|
||||
tok[ntok] = tbindex; /* the start of the token */ |
||||
|
||||
/* Set the token type */ |
||||
|
||||
switch (ch) { |
||||
|
||||
case SH_AMPER: toktyp[ntok] = SH_TOK_AMPER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_LESS: toktyp[ntok] = SH_TOK_LESS; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_GREATER: toktyp[ntok] = SH_TOK_GREATER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
default: toktyp[ntok] = SH_TOK_OTHER; |
||||
}; |
||||
|
||||
/* Handle quoted string (single or double quote) */ |
||||
|
||||
if ( (ch==SH_SQUOTE) || (ch==SH_DQUOTE) ) { |
||||
quote = ch; /* remember opening quote */ |
||||
|
||||
/* Copy quoted string to arg area */ |
||||
|
||||
p++; /* Move past starting quote */ |
||||
|
||||
while ( ((ch=*p++) != quote) && (ch != SH_NEWLINE) |
||||
&& (ch != NULLCH) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
} |
||||
if (ch != quote) { /* string missing end quote */ |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Finished string - count token and go on */ |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate token */ |
||||
ntok++; /* count string as one token */ |
||||
continue; /* go to next token */ |
||||
} |
||||
|
||||
/* Handle a token other than a quoted string */ |
||||
|
||||
tokbuf[tbindex++] = ch; /* put first character in buffer*/ |
||||
p++; |
||||
|
||||
while ( ((ch = *p) != SH_NEWLINE) && (ch != NULLCH) |
||||
&& (ch != SH_LESS) && (ch != SH_GREATER) |
||||
&& (ch != SH_BLANK) && (ch != SH_TAB) |
||||
&& (ch != SH_AMPER) && (ch != SH_SQUOTE) |
||||
&& (ch != SH_DQUOTE) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
p++; |
||||
} |
||||
|
||||
/* Report error if other token is appended */ |
||||
|
||||
if ( (ch == SH_SQUOTE) || (ch == SH_DQUOTE) |
||||
|| (ch == SH_LESS) || (ch == SH_GREATER) ) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate the token */ |
||||
|
||||
ntok++; /* count valid token */ |
||||
|
||||
} |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
@ -1,329 +0,0 @@
|
||||
/* shell.c - shell */ |
||||
|
||||
#include <xinu.h> |
||||
//#include <stdio.h>
|
||||
#include "shprototypes.h" |
||||
|
||||
/************************************************************************/ |
||||
/* Table of Xinu shell commands and the function associated with each */ |
||||
/************************************************************************/ |
||||
const struct cmdent cmdtab[] = { |
||||
{"memstat", TRUE, xsh_memstat}, /* Make built-in */ |
||||
{"editor", FALSE, xsh_editor}, /* Make built-in */ |
||||
{"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},
|
||||
// {"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 */ |
||||
/* commands. Each command begins with a command name, has */ |
||||
/* a set of optional arguments, has optional input or */ |
||||
/* output redirection, and an optional specification for */ |
||||
/* background execution (ampersand). The syntax is: */ |
||||
/* */ |
||||
/* command_name [args*] [redirection] [&] */ |
||||
/* */ |
||||
/* Redirection is either or both of: */ |
||||
/* */ |
||||
/* < input_file */ |
||||
/* or */ |
||||
/* > output_file */ |
||||
/* */ |
||||
/************************************************************************/ |
||||
|
||||
process shell ( |
||||
// did32 dev /* ID of tty device from which */
|
||||
) /* to accept commands */ |
||||
{ |
||||
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) { |
||||
|
||||
// RAFA
|
||||
// fprintf(dev, "\033[2J");
|
||||
// fprintf(dev, "\033[H");
|
||||
|
||||
/* 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); |
||||
} |
||||
} |
||||
|
||||
// int eeprom_fd = open(RAM0, nombre, "w");
|
||||
// char raf[32] = "pepe";
|
||||
// write(fd, pepe, 32);
|
||||
// int eeprom_fd = open(RAM0, nombre, "w");
|
||||
|
||||
/* 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);
|
||||
/* 160 bytes de stack perfecto */ |
||||
child = create(cmdtab[j].cfunc, |
||||
160, 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; |
||||
} |
||||
@ -1,137 +0,0 @@
|
||||
/* xsh_test.c - xsh_test */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
/*
|
||||
void sndA(void); |
||||
void sndB(void); |
||||
*/ |
||||
// void prod2(sid32 consumed, sid32 produced, int a);
|
||||
// void cons2(sid32 consumed, sid32 produced, int a);
|
||||
|
||||
int32 n = 0; |
||||
int32 j = 0; |
||||
|
||||
//void cons2(sid32 consumed, sid32 produced, int a);
|
||||
void cons2(int argc, char * argv[]); |
||||
void prod2(int argc, char * argv[]); |
||||
|
||||
void freem(void) |
||||
{ |
||||
int mask = disable(); |
||||
uint32 free_mem=0; |
||||
struct memblk *memptr; |
||||
/* Output Xinu memory layout */ |
||||
free_mem = 0; |
||||
for (memptr = memlist.mnext; memptr != NULL; |
||||
memptr = memptr->mnext) { |
||||
free_mem += memptr->mlength; |
||||
} |
||||
kprintf("\n\rFreeMEM:%d\n", free_mem); |
||||
restore(mask); |
||||
} |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xhs_test |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
process test(int nargs, char *args[]) |
||||
{ |
||||
// int32 a = roundmb(81);
|
||||
|
||||
/* EEPROM TEST
|
||||
char buf[6]; |
||||
char buf2[6]; |
||||
memset(buf, 0, 6); |
||||
memset(buf2, 0, 6); |
||||
buf[0] = 49; |
||||
buf[1] = 50; |
||||
printf("b=%s\n", buf); |
||||
write(EEPROM0, buf, 4); |
||||
buf[0] = 0; |
||||
buf[1] = 0; |
||||
read(EEPROM0, buf2, 4); |
||||
buf2[1] = 0; |
||||
printf("b=%s\n", buf2); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
EN EEPROM TEST */ |
||||
|
||||
sid32 produced, consumed; |
||||
consumed = semcreate(0); |
||||
produced = semcreate(1); |
||||
printf ("prod=%d \n", produced); |
||||
printf ("consu=%d \n", consumed); |
||||
blink_avr(); |
||||
blink_avr(); |
||||
resume(create(cons2, 200, 20, "cons", 3, consumed, produced, 4)); |
||||
resume(create(prod2, 200, 20, "prod", 3, consumed, produced, 4)); |
||||
return 0; |
||||
} |
||||
|
||||
void prod2(int argc, char * argv[]) |
||||
{ |
||||
sid32 consumed, produced; |
||||
consumed = argv[0]; |
||||
produced = argv[1]; |
||||
int a = argv[2]; |
||||
int32 i; |
||||
|
||||
printf("argc=%d\n", argc); |
||||
printf("n1=%d\n", consumed); |
||||
printf("n2=%d\n", produced); |
||||
printf("n3=%d\n", a); |
||||
//for (i=1; i<=2000; i++) {
|
||||
for (i=1; i<=100; i++) { |
||||
// printf("n3=%d\n", a);
|
||||
wait(consumed); |
||||
j = j + 1; |
||||
//n++;
|
||||
signal(produced); |
||||
} |
||||
} |
||||
|
||||
void cons2(int argc, char * argv[]) |
||||
//void cons2(sid32 consumed, sid32 produced, int a)
|
||||
{ |
||||
int32 i; |
||||
|
||||
sid32 consumed, produced; |
||||
consumed = argv[0]; |
||||
produced = argv[1]; |
||||
//for (i=1; i<=2000; i++) {
|
||||
for (i=1; i<=100; i++) { |
||||
wait(produced); |
||||
n = n + (j*2); |
||||
printf("n is %d \n", n); |
||||
signal(consumed); |
||||
} |
||||
|
||||
} |
||||
/* original test
|
||||
process test(int nargs, char *args[]) |
||||
{ |
||||
resume(create(sndA, 64, 20, "proc1", 0)); |
||||
resume(create(sndB, 64, 20, "proc1", 0)); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void sndA(void) |
||||
{ |
||||
while(1) |
||||
putc(CONSOLE, 'A'); |
||||
} |
||||
|
||||
void sndB(void) |
||||
{ |
||||
while(1) |
||||
putc(CONSOLE, 'B'); |
||||
|
||||
} |
||||
end of original test */ |
||||
@ -1,24 +0,0 @@
|
||||
/* 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; |
||||
} |
||||
@ -1,94 +0,0 @@
|
||||
/* xsh_editor.c - xsh_editor */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
#define NLINES 10 |
||||
#define LINE_LEN 24 |
||||
/*------------------------------------------------------------------------
|
||||
* xhs_editor - text editor
|
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_editor(int nargs, char *args[]) |
||||
{ |
||||
|
||||
/*
|
||||
int32 i; |
||||
|
||||
if (nargs > 1) { |
||||
printf("%s", args[1]); |
||||
|
||||
for (i = 2; i < nargs; i++) { |
||||
printf(" %s", args[i]); |
||||
} |
||||
} |
||||
printf("\n"); |
||||
*/ |
||||
char buffer[NLINES][LINE_LEN+1]; |
||||
int page = 0; |
||||
int i = 0; |
||||
int dev = 0; |
||||
int c; |
||||
int cursor = 0; |
||||
int line = 0; |
||||
|
||||
fprintf(dev, "\033[2J"); |
||||
fprintf(dev, "\033[H"); |
||||
fprintf(dev, "Text editor. page: %i\n", page); |
||||
|
||||
memset(buffer, NLINES*(LINE_LEN+1), 0); |
||||
for (i=0; i<LINE_LEN; i++) |
||||
printf("%s\n",buffer[i]); |
||||
|
||||
// control(dev, TC_NOECHO, 0, 0);
|
||||
|
||||
control(dev, TC_MODER, 0, 0); |
||||
|
||||
while (TRUE) { |
||||
// c = -1;
|
||||
c = getc(0); |
||||
//printf("%i \n", c);
|
||||
|
||||
if (c == 27) { |
||||
c = getc(0); |
||||
if (c == '[') { |
||||
c = getc(0); |
||||
switch (c) { |
||||
case 'D':
|
||||
cursor--; if (cursor < 0) cursor = 0; |
||||
printf("\033[D"); |
||||
break; |
||||
case 'C':
|
||||
cursor++;
|
||||
printf("\033[C"); |
||||
if (cursor > LINE_LEN) { |
||||
cursor = 0; |
||||
line++; |
||||
printf("\n\r"); |
||||
} |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
continue; |
||||
} |
||||
|
||||
printf("%c", c); |
||||
buffer[line][cursor] = c; |
||||
cursor++; |
||||
if (cursor > LINE_LEN) { |
||||
cursor = 0; |
||||
line++; |
||||
printf("\n\r"); |
||||
if (line > NLINES) { |
||||
// pasar_pagina();
|
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
// RAFA
|
||||
return 0; |
||||
} |
||||
@ -1,116 +0,0 @@
|
||||
/* xsh_memstat.c - xsh_memstat */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
static void printMemUse(void); |
||||
static void printFreeList(void); |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_memstat - Print statistics about memory use and dump the free list |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_memstat(int nargs, char *args[]) |
||||
{ |
||||
|
||||
/* For argument '--help', emit help about the 'memstat' command */ |
||||
|
||||
/*
|
||||
if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { |
||||
printf("use: %s \n\n", args[0]); |
||||
printf("Description:\n"); |
||||
printf("\tDisplays the current memory use and prints the\n"); |
||||
printf("\tfree list.\n"); |
||||
printf("Options:\n"); |
||||
printf("\t--help\t\tdisplay this help and exit\n"); |
||||
return 0; |
||||
} |
||||
*/ |
||||
|
||||
/* Check for valid number of arguments */ |
||||
|
||||
/*
|
||||
if (nargs > 1) { |
||||
fprintf(stderr, "%s: too many arguments\n", args[0]); |
||||
fprintf(stderr, "Try '%s --help' for more information\n", |
||||
args[0]); |
||||
return 1; |
||||
} |
||||
*/ |
||||
|
||||
printMemUse(); |
||||
printFreeList(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printFreeList - Walk the list of free memory blocks and print the |
||||
* location and size of each |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printFreeList(void) |
||||
{ |
||||
char t[80]; |
||||
struct memblk *block; |
||||
|
||||
/* Output a heading for the free list */ |
||||
|
||||
// printf("Free:\n");
|
||||
printf("FreeMEM: addr len\n"); |
||||
|
||||
// avr_printf(m11);
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
printf("0x%08x %d\n", block, |
||||
(uint32) block->mlength); |
||||
} |
||||
} |
||||
|
||||
extern void start(void); |
||||
extern void *_end; |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printMemUse - Print statistics about memory use |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printMemUse(void) |
||||
{ |
||||
int i; /* Index into process table */ |
||||
uint32 code = 0; /* Total Xinu code memory */ |
||||
uint32 stack = 0; /* Total used stack memory */ |
||||
uint32 kheap = 0; /* Free kernel heap memory */ |
||||
uint32 kfree = 0; /* Total free memory */ |
||||
struct memblk *block; /* Ptr to memory block */ |
||||
|
||||
/* Calculate amount of text memory */ |
||||
|
||||
// code = (uint32)&etext - (uint32)&text;
|
||||
|
||||
/* Calculate amount of allocated stack memory */ |
||||
/* Skip the NULL process since it has a private stack */ |
||||
|
||||
for (i = 0; i < NPROC; i++) { |
||||
if (proctab[i].prstate != PR_FREE) { |
||||
stack += (uint32)proctab[i].prstklen; |
||||
} |
||||
} |
||||
|
||||
/* Calculate the amount of memory on the free list */ |
||||
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
kfree += block->mlength; |
||||
} |
||||
|
||||
/* Calculate the amount of free kernel heap memory */ |
||||
|
||||
kheap = kfree - stack; |
||||
|
||||
/* Output statistics on current memory use */ |
||||
|
||||
// printf("code: %10d\n", (uint32) code);
|
||||
// printf("stack:%10d bytes\n", (uint32) stack);
|
||||
// printf("kernel stk:%10d bytes\n", (uint32) mspstack);
|
||||
// printf("heap:%10d bytes\n\n", (uint32) kheap);
|
||||
} |
||||
@ -1,148 +0,0 @@
|
||||
/* lexan.c - lexan */ |
||||
|
||||
#include <xinu.h> |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* lexan - Ad hoc lexical analyzer to divide command line into tokens |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
int32 lexan ( |
||||
char *line, /* Input line terminated with */ |
||||
/* NEWLINE or NULLCH */ |
||||
int32 len, /* Length of the input line, */ |
||||
/* including NEWLINE */ |
||||
char *tokbuf, /* Buffer into which tokens are */ |
||||
/* stored with a null */ |
||||
/* following each token */ |
||||
int32 *tlen, /* Place to store number of */ |
||||
/* chars in tokbuf */ |
||||
int32 tok[], /* Array of pointers to the */ |
||||
/* start of each token */ |
||||
int32 toktyp[] /* Array that gives the type */ |
||||
/* of each token */ |
||||
) |
||||
{ |
||||
char quote; /* Character for quoted string */ |
||||
uint32 ntok; /* Number of tokens found */ |
||||
char *p; /* Pointer that walks along the */ |
||||
/* input line */ |
||||
int32 tbindex; /* Index into tokbuf */ |
||||
char ch; /* Next char from input line */ |
||||
|
||||
/* Start at the beginning of the line with no tokens */ |
||||
|
||||
ntok = 0; |
||||
p = line; |
||||
tbindex = 0; |
||||
|
||||
/* While not yet at end of line, get next token */ |
||||
|
||||
while ( (*p != NULLCH) && (*p != SH_NEWLINE) ) { |
||||
|
||||
/* If too many tokens, return error */ |
||||
|
||||
if (ntok >= SHELL_MAXTOK) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Skip whitespace before token */ |
||||
|
||||
while ( (*p == SH_BLANK) || (*p == SH_TAB) ) { |
||||
p++; |
||||
} |
||||
|
||||
/* Stop parsing at end of line (or end of string) */ |
||||
|
||||
ch = *p; |
||||
if ( (ch==SH_NEWLINE) || (ch==NULLCH) ) { |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
|
||||
/* Set next entry in tok array to be an index to the */ |
||||
/* current location in the token buffer */ |
||||
|
||||
tok[ntok] = tbindex; /* the start of the token */ |
||||
|
||||
/* Set the token type */ |
||||
|
||||
switch (ch) { |
||||
|
||||
case SH_AMPER: toktyp[ntok] = SH_TOK_AMPER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_LESS: toktyp[ntok] = SH_TOK_LESS; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
case SH_GREATER: toktyp[ntok] = SH_TOK_GREATER; |
||||
tokbuf[tbindex++] = ch; |
||||
tokbuf[tbindex++] = NULLCH; |
||||
ntok++; |
||||
p++; |
||||
continue; |
||||
|
||||
default: toktyp[ntok] = SH_TOK_OTHER; |
||||
}; |
||||
|
||||
/* Handle quoted string (single or double quote) */ |
||||
|
||||
if ( (ch==SH_SQUOTE) || (ch==SH_DQUOTE) ) { |
||||
quote = ch; /* remember opening quote */ |
||||
|
||||
/* Copy quoted string to arg area */ |
||||
|
||||
p++; /* Move past starting quote */ |
||||
|
||||
while ( ((ch=*p++) != quote) && (ch != SH_NEWLINE) |
||||
&& (ch != NULLCH) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
} |
||||
if (ch != quote) { /* string missing end quote */ |
||||
return SYSERR; |
||||
} |
||||
|
||||
/* Finished string - count token and go on */ |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate token */ |
||||
ntok++; /* count string as one token */ |
||||
continue; /* go to next token */ |
||||
} |
||||
|
||||
/* Handle a token other than a quoted string */ |
||||
|
||||
tokbuf[tbindex++] = ch; /* put first character in buffer*/ |
||||
p++; |
||||
|
||||
while ( ((ch = *p) != SH_NEWLINE) && (ch != NULLCH) |
||||
&& (ch != SH_LESS) && (ch != SH_GREATER) |
||||
&& (ch != SH_BLANK) && (ch != SH_TAB) |
||||
&& (ch != SH_AMPER) && (ch != SH_SQUOTE) |
||||
&& (ch != SH_DQUOTE) ) { |
||||
tokbuf[tbindex++] = ch; |
||||
p++; |
||||
} |
||||
|
||||
/* Report error if other token is appended */ |
||||
|
||||
if ( (ch == SH_SQUOTE) || (ch == SH_DQUOTE) |
||||
|| (ch == SH_LESS) || (ch == SH_GREATER) ) { |
||||
return SYSERR; |
||||
} |
||||
|
||||
tokbuf[tbindex++] = NULLCH; /* terminate the token */ |
||||
|
||||
ntok++; /* count valid token */ |
||||
|
||||
} |
||||
*tlen = tbindex; |
||||
return ntok; |
||||
} |
||||
@ -1,343 +0,0 @@
|
||||
/* main.c - main */ |
||||
|
||||
/* shell.c - shell */ |
||||
|
||||
|
||||
#include <xinu.h> |
||||
//#include <stdio.h>
|
||||
#include "shprototypes.h" |
||||
|
||||
void xsh_help(void)
|
||||
{ |
||||
int i; |
||||
|
||||
printf("\n\rCommands:\n\n\r"); |
||||
for (i=0; i<ncmd; i++)
|
||||
printf("%s\n", cmdtab[i].cname); |
||||
printf("\n\r"); |
||||
|
||||
} |
||||
|
||||
/************************************************************************/ |
||||
/* Table of Xinu shell commands and the function associated with each */ |
||||
/************************************************************************/ |
||||
const struct cmdent cmdtab[] = { |
||||
{"memstat", FALSE, xsh_memstat}, /* Make built-in */ |
||||
{"editor", FALSE, xsh_editor}, /* Make built-in */ |
||||
{"basic", FALSE, xsh_basic}, /* Make built-in */ |
||||
{"help", TRUE, xsh_help}, /* Make built-in */ |
||||
{"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},
|
||||
// {"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 */ |
||||
/* commands. Each command begins with a command name, has */ |
||||
/* a set of optional arguments, has optional input or */ |
||||
/* output redirection, and an optional specification for */ |
||||
/* background execution (ampersand). The syntax is: */ |
||||
/* */ |
||||
/* command_name [args*] [redirection] [&] */ |
||||
/* */ |
||||
/* Redirection is either or both of: */ |
||||
/* */ |
||||
/* < input_file */ |
||||
/* or */ |
||||
/* > output_file */ |
||||
/* */ |
||||
/************************************************************************/ |
||||
|
||||
process main(void) |
||||
{ |
||||
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) { |
||||
|
||||
// RAFA
|
||||
// fprintf(dev, "\033[2J");
|
||||
// fprintf(dev, "\033[H");
|
||||
|
||||
/* 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); |
||||
} |
||||
} |
||||
|
||||
// int eeprom_fd = open(RAM0, nombre, "w");
|
||||
// char raf[32] = "pepe";
|
||||
// write(fd, pepe, 32);
|
||||
// int eeprom_fd = open(RAM0, nombre, "w");
|
||||
|
||||
/* 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);
|
||||
/* 160 bytes de stack perfecto */ |
||||
child = create(cmdtab[j].cfunc, |
||||
460, 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; |
||||
} |
||||
@ -1,24 +0,0 @@
|
||||
/* 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; |
||||
} |
||||
@ -1,101 +0,0 @@
|
||||
/* xsh_editor.c - xsh_editor */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
|
||||
// #include "text_buffer.h"
|
||||
#define NLINES 3 |
||||
#define LINE_LEN 24 |
||||
|
||||
//extern unsigned char program[NLINES*LINE_LEN];
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xhs_editor - text editor
|
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_editor(int nargs, char *args[]) |
||||
{ |
||||
|
||||
/*
|
||||
int32 i; |
||||
|
||||
if (nargs > 1) { |
||||
printf("%s", args[1]); |
||||
|
||||
for (i = 2; i < nargs; i++) { |
||||
printf(" %s", args[i]); |
||||
} |
||||
} |
||||
printf("\n"); |
||||
*/ |
||||
char buffer[NLINES*LINE_LEN]; |
||||
int page = 0; |
||||
int i = 0; |
||||
int j = 0; |
||||
int dev = 0; |
||||
int c; |
||||
int cursor = 0; |
||||
int line = 0; |
||||
|
||||
fprintf(dev, "\033[2J"); |
||||
fprintf(dev, "\033[H"); |
||||
fprintf(dev, "Text editor. page: %i\n", page); |
||||
|
||||
for (i=0; i<NLINES*LINE_LEN; i++) |
||||
buffer[i] = 0; |
||||
|
||||
// control(dev, TC_NOECHO, 0, 0);
|
||||
|
||||
control(dev, TC_MODER, 0, 0); |
||||
|
||||
while (TRUE) { |
||||
// c = -1;
|
||||
c = getc(0); |
||||
//printf("%i \n", c);
|
||||
if (c == '!') { |
||||
control(dev, TC_MODEC, 0, 0); |
||||
return 0; |
||||
}; |
||||
if (c == 27) { |
||||
c = getc(0); |
||||
if (c == '[') { |
||||
c = getc(0); |
||||
switch (c) { |
||||
case 'D':
|
||||
cursor--; if (cursor < 0) cursor = 0; |
||||
printf("\033[D"); |
||||
break; |
||||
case 'C':
|
||||
cursor++;
|
||||
printf("\033[C"); |
||||
if (cursor > LINE_LEN) { |
||||
cursor = 0; |
||||
line++; |
||||
printf("\n\r"); |
||||
} |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
continue; |
||||
} |
||||
|
||||
printf("%c", c); |
||||
buffer[line*LINE_LEN+cursor] = c; |
||||
cursor++; |
||||
if (cursor > LINE_LEN) { |
||||
cursor = 0; |
||||
line++; |
||||
printf("\n\r"); |
||||
if (line > NLINES) { |
||||
// pasar_pagina();
|
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
// RAFA
|
||||
return 0; |
||||
} |
||||
@ -1,114 +0,0 @@
|
||||
/* xsh_memstat.c - xsh_memstat */ |
||||
|
||||
#include <xinu.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
// RAFA
|
||||
#include <avr/interrupt.h> |
||||
|
||||
|
||||
static void printMemUse(void); |
||||
static void printFreeList(void); |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* xsh_memstat - Print statistics about memory use and dump the free list |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
shellcmd xsh_memstat(int nargs, char *args[]) |
||||
{ |
||||
|
||||
|
||||
// printMemUse();
|
||||
printFreeList(); |
||||
|
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printFreeList - Walk the list of free memory blocks and print the |
||||
* location and size of each |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printFreeList(void) |
||||
{ |
||||
// char t[80];
|
||||
struct memblk *block; |
||||
|
||||
/* Output a heading for the free list */ |
||||
|
||||
// printf("Free:\n");
|
||||
printf("FreeMEM: addr len\n"); |
||||
|
||||
// avr_printf(m11);
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
printf("0x%08x %d\n", block, |
||||
(uint32) block->mlength); |
||||
} |
||||
long i; |
||||
int j=0; |
||||
char * c = 0; |
||||
for (i=0; i<0x5bd ; i++) { |
||||
c = (char *)i; |
||||
if (j==0) { |
||||
serial_put_char('\n'); |
||||
serial_put_char('\r'); |
||||
printf ("0x%08x ", c); |
||||
} |
||||
j++; |
||||
if (j==16) j=0; |
||||
if (*c < 33) |
||||
serial_put_char('-'); |
||||
else |
||||
serial_put_char(*c); |
||||
} |
||||
} |
||||
|
||||
extern void start(void); |
||||
extern void *_end; |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* printMemUse - Print statistics about memory use |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void printMemUse(void) |
||||
{ |
||||
int i; /* Index into process table */ |
||||
uint32 code = 0; /* Total Xinu code memory */ |
||||
uint32 stack = 0; /* Total used stack memory */ |
||||
uint32 kheap = 0; /* Free kernel heap memory */ |
||||
uint32 kfree = 0; /* Total free memory */ |
||||
struct memblk *block; /* Ptr to memory block */ |
||||
|
||||
/* Calculate amount of text memory */ |
||||
|
||||
// code = (uint32)&etext - (uint32)&text;
|
||||
|
||||
/* Calculate amount of allocated stack memory */ |
||||
/* Skip the NULL process since it has a private stack */ |
||||
|
||||
for (i = 0; i < NPROC; i++) { |
||||
if (proctab[i].prstate != PR_FREE) { |
||||
stack += (uint32)proctab[i].prstklen; |
||||
} |
||||
} |
||||
|
||||
/* Calculate the amount of memory on the free list */ |
||||
|
||||
for (block = memlist.mnext; block != NULL; block = block->mnext) { |
||||
kfree += block->mlength; |
||||
} |
||||
|
||||
/* Calculate the amount of free kernel heap memory */ |
||||
|
||||
kheap = kfree - stack; |
||||
|
||||
/* Output statistics on current memory use */ |
||||
|
||||
// printf("code: %10d\n", (uint32) code);
|
||||
// printf("stack:%10d bytes\n", (uint32) stack);
|
||||
// printf("kernel stk:%10d bytes\n", (uint32) mspstack);
|
||||
// printf("heap:%10d bytes\n\n", (uint32) kheap);
|
||||
} |
||||
@ -1,261 +0,0 @@
|
||||
/* Xinu for STM32
|
||||
* |
||||
* Original license applies |
||||
* Modifications for STM32 by Robin Krens |
||||
* Please see LICENSE and AUTHORS
|
||||
*
|
||||
* $LOG$ |
||||
* 2019/11/11 - ROBIN KRENS |
||||
* Initial version
|
||||
*
|
||||
* $DESCRIPTION$ |
||||
* |
||||
* */ |
||||
|
||||
/* initialize.c - nulluser, sysinit */ |
||||
|
||||
/* Handle system initialization and become the null process */ |
||||
|
||||
#include <xinu.h> |
||||
#include <string.h> |
||||
|
||||
extern void start(void); /* Start of Xinu code */ |
||||
extern void *_end; /* End of Xinu code */ |
||||
|
||||
/* Function prototypes */ |
||||
|
||||
extern void main(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); |
||||
void startup(int, struct procent *); /* Process to finish startup tasks */ |
||||
|
||||
/* Declarations of major kernel variables */ |
||||
|
||||
struct procent proctab[NPROC]; /* Process table */ |
||||
struct sentry semtab[NSEM]; /* Semaphore table */ |
||||
struct memblk memlist; /* List of free memory blocks */ |
||||
|
||||
/* Active system status */ |
||||
|
||||
int prcount; /* Total number of live processes */ |
||||
pid32 currpid; /* ID of currently executing process */ |
||||
|
||||
/* Control sequence to reset the console colors and cusor positiion */ |
||||
|
||||
#define CONSOLE_RESET " \033[0m\033[2J\033[;H" |
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* nulluser - initialize the system and become the null process |
||||
* |
||||
* Note: execution begins here after the C run-time environment has been |
||||
* established. Interrupts are initially DISABLED, and must eventually |
||||
* be enabled explicitly. The code turns itself into the null process |
||||
* after initialization. Because it must always remain ready to execute, |
||||
* the null process cannot execute code that might cause it to be |
||||
* suspended, wait for a semaphore, put to sleep, or exit. In |
||||
* particular, the code must not perform I/O except for polled versions |
||||
* such as kprintf. |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
// RAFA
|
||||
// void PUT32 ( unsigned int, unsigned int );
|
||||
unsigned int GET32 ( unsigned int ); |
||||
void dummy ( unsigned int ); |
||||
|
||||
#define GPIOCBASE 0x40011000 |
||||
#define RCCBASE 0x40021000 |
||||
|
||||
void notmain ( void ) |
||||
{ |
||||
unsigned int ra; |
||||
unsigned int rx; |
||||
|
||||
ra=GET32(RCCBASE+0x18); |
||||
ra|=1<<4; //enable port c
|
||||
PUT32(RCCBASE+0x18,ra); |
||||
//config
|
||||
ra=GET32(GPIOCBASE+0x04); |
||||
ra&=~(3<<20); //PC13
|
||||
ra|=1<<20; //PC13
|
||||
ra&=~(3<<22); //PC13
|
||||
ra|=0<<22; //PC13
|
||||
PUT32(GPIOCBASE+0x04,ra); |
||||
|
||||
for(rx=0;rx<10;rx++) |
||||
{ |
||||
PUT32(GPIOCBASE+0x10,1<<(13+0)); |
||||
for(ra=0;ra<200000;ra++) dummy(ra); |
||||
PUT32(GPIOCBASE+0x10,1<<(13+16)); |
||||
for(ra=0;ra<200000;ra++) dummy(ra); |
||||
} |
||||
} |
||||
|
||||
// FIN RAFA
|
||||
|
||||
|
||||
void nullprocess(void) { |
||||
|
||||
notmain(); |
||||
|
||||
|
||||
|
||||
resume(create((void *)main, INITSTK, INITPRIO, "Main Process", 0, NULL)); |
||||
|
||||
for(;;); |
||||
} |
||||
|
||||
|
||||
|
||||
void nulluser() |
||||
{
|
||||
struct memblk *memptr; /* Ptr to memory block */ |
||||
uint32 free_mem; /* Total amount of free memory */ |
||||
|
||||
/* Initialize the system */ |
||||
|
||||
sysinit(); |
||||
|
||||
/* Output Xinu memory layout */ |
||||
free_mem = 0; |
||||
for (memptr = memlist.mnext; memptr != NULL; |
||||
memptr = memptr->mnext) { |
||||
free_mem += memptr->mlength; |
||||
} |
||||
kprintf("%10d bytes of free memory. Free list:\n", free_mem); |
||||
for (memptr=memlist.mnext; memptr!=NULL;memptr = memptr->mnext) { |
||||
kprintf(" [0x%08X to 0x%08X]\n", |
||||
(uint32)memptr, ((uint32)memptr) + memptr->mlength - 1); |
||||
} |
||||
|
||||
kprintf("%10d bytes of Xinu code.\n", |
||||
(uint32)&etext - (uint32)&text); |
||||
kprintf(" [0x%08X to 0x%08X]\n", |
||||
(uint32)&text, (uint32)&etext - 1); |
||||
kprintf("%10d bytes of data.\n", |
||||
(uint32)&ebss - (uint32)&data); |
||||
kprintf(" [0x%08X to 0x%08X]\n\n", |
||||
(uint32)&data, (uint32)&ebss - 1); |
||||
|
||||
|
||||
/* Initialize the Null process entry */
|
||||
int pid = create((void *)nullprocess, INITSTK, 10, "Null process", 0, NULL); |
||||
|
||||
struct procent * prptr = &proctab[pid]; |
||||
prptr->prstate = PR_CURR; |
||||
|
||||
/* Enable interrupts */ |
||||
enable(); |
||||
|
||||
/* Initialize the real time clock */ |
||||
clkinit(); |
||||
|
||||
/* Start of nullprocess */ |
||||
startup(0, prptr); |
||||
|
||||
for(;;); |
||||
|
||||
} |
||||
|
||||
/* Startup does a system call, the processor switches to handler
|
||||
* mode and prepares for executing the null process (see syscall.c)
|
||||
* This is also where a kernel mode to user mode switch can |
||||
* take place */ |
||||
void startup(int INIT, struct procent *p) { |
||||
|
||||
asm volatile ( |
||||
"push {r0}" "\n\t" |
||||
//"mov r0, 0x3" "\n\t" // kernel to user mode switch
|
||||
//"msr control, r0" "\n\t"
|
||||
//"isb" "\n\t"
|
||||
"pop {r0}" ); |
||||
asm volatile("svc 1"); |
||||
|
||||
/* Should not be here, panic */ |
||||
panic("Can't startup system");
|
||||
} |
||||
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* |
||||
* sysinit - Initialize all Xinu data structures and devices |
||||
* |
||||
*------------------------------------------------------------------------ |
||||
*/ |
||||
static void sysinit() |
||||
{ |
||||
int32 i; |
||||
struct procent *prptr; /* Ptr to process table entry */ |
||||
struct sentry *semptr; /* Ptr to semaphore table entry */ |
||||
|
||||
|
||||
/* Platform Specific Initialization */ |
||||
|
||||
platinit(); |
||||
|
||||
kprintf(CONSOLE_RESET); |
||||
kprintf("\n%s\n\n", VERSION); |
||||
|
||||
/* Initialize free memory list */ |
||||
|
||||
meminit(); |
||||
|
||||
/* Initialize system variables */ |
||||
|
||||
/* Count the Null process as the first process in the system */ |
||||
prcount = 0; |
||||
// prcount = 1;
|
||||
|
||||
/* Scheduling is not currently blocked */ |
||||
|
||||
Defer.ndefers = 0; |
||||
|
||||
/* Initialize process table entries free */ |
||||
|
||||
for (i = 0; i < NPROC; i++) { |
||||
prptr = &proctab[i]; |
||||
prptr->prstate = PR_FREE; |
||||
prptr->prname[0] = NULLCH; |
||||
prptr->prstkbase = NULL; |
||||
prptr->prprio = 0; |
||||
} |
||||
|
||||
|
||||
/* Initialize semaphores */ |
||||
|
||||
for (i = 0; i < NSEM; i++) { |
||||
semptr = &semtab[i]; |
||||
semptr->sstate = S_FREE; |
||||
semptr->scount = 0; |
||||
semptr->squeue = newqueue(); |
||||
} |
||||
|
||||
/* Initialize buffer pools */ |
||||
|
||||
bufinit(); |
||||
|
||||
/* Create a ready list for processes */ |
||||
|
||||
readylist = newqueue(); |
||||
|
||||
|
||||
for (i = 0; i < NDEVS; i++) { |
||||
init(i); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
int32 stop(char *s) |
||||
{ |
||||
kprintf("%s\n", s); |
||||
kprintf("looping... press reset\n"); |
||||
while(1) |
||||
/* Empty */; |
||||
} |
||||
|
||||
int32 delay(int n) |
||||
{ |
||||
DELAY(n); |
||||
return OK; |
||||
} |
||||
Loading…
Reference in new issue