Browse Source

Wow basic

pull/1/head
Rafael Zurita 6 years ago
parent
commit
bba5edaee4
  1. 20
      README.md
  2. 8
      device/nam/naminit.c
  3. 4
      device/tty/ttyinit.c
  4. 3
      include/avr_messages.h
  5. 4
      include/name.h
  6. 4
      include/prototypes.h
  7. 1
      include/shprototypes.h
  8. 1
      lib/avr_messages.c
  9. 23
      lib/avr_printf.c
  10. 30
      lib/printf.c
  11. 15
      shell/shell.c
  12. 4
      shell/text_buffer.h
  13. 1818
      shell/xsh_basic.c
  14. 101
      shell/xsh_editor.c
  15. 50
      shell/xsh_memstat.c
  16. 2
      system/getstk.c
  17. 24
      system/initialize.c
  18. 6
      system/kprintf.c
  19. 1
      system/platinit.c
  20. 9
      system/serial_avr.c
  21. 5
      xinu-avr-port.txt

20
README.md

@ -20,12 +20,20 @@ ventional operating systems supply.
Xinu originally ran on Digital Equipment Corporation
LSI 11's with only 64K bytes of memory, at the end of 1979
and the inning of 1980. Over the years Xinu versions have been ported
to many architectures , CISC and RISC: including the IBM PC (x86), Sun 3,
Transputer, MacIntosh, ARM, PowerPC and MIPS. There
are current versions of Xinu for Galileo Intel boards,
Beagle Boards, several MIPS platforms, and for PC hardware and virtual
machines.
and the inning of 1980. Over the years Xinu versions
Xinu have been expanded and ported to a wide variety of architectures and platforms, including: IBM PC,
Macintosh, Digital Equipment Corporation VAX and DECStation 3100, Sun Microsystems Sun 2,
Sun 3 and Sparcstations, and for several ARM, MIPS and x86 embedded boards.
It has been used as the basis for many research projects.
Furthermore, Xinu has been used as an embedded system in products
by companies such as Motorola, Mitsubishi, Hewlett-Packard, and Lexmark.
There is a full TCP/IP stack, and even the original version of Xinu
(for the PDP-11) supported arbitrary processes and network I/O.
have been ported
There are current versions of Xinu for Galileo Intel boards,
ARM Beagle Boards, several MIPS platforms, and for x86 PC hardware
and virtual machines.
Xinu differs completely
from the internal structure of Unix (or Linux).

8
device/nam/naminit.c

@ -65,16 +65,16 @@ status naminit(void)
if (len > NM_MAXLEN) {
// RAFA kprintf("namespace: device name %s too long\r\n",
kprintf(&m5[0],
devptr->dvname);
avr_kprintf(m5);
kprintf("%s", devptr->dvname);
continue;
}
retval = mount(tmpstr, NULLSTR, devptr->dvnum);
if (retval == SYSERR) {
// RAFA kprintf("namespace: cannot mount device %d\r\n",
kprintf(&m4[0],
devptr->dvname);
avr_kprintf(m4);
kprintf("%s", devptr->dvname);
continue;
}
}

4
device/tty/ttyinit.c

@ -13,7 +13,7 @@ devcall ttyinit(
)
{
struct ttycblk *typtr; /* Pointer to ttytab entry */
struct uart_csreg *uptr; /* Address of UART's CSRs */
// struct uart_csreg *uptr; /* Address of UART's CSRs */
typtr = &ttytab[ devptr->dvminor ];
@ -52,6 +52,6 @@ devcall ttyinit(
/* Initialize UART */
/* avr: TODO port uart to here */
ttykickout(uptr);
// ttykickout(uptr);
return OK;
}

3
include/avr_messages.h

@ -5,6 +5,9 @@ typedef unsigned int size_t;
// extern const char CONSOLE_RESET[];
// extern const char m0[];
extern const char m0[];
extern const char m00[];
extern const char m000[];
extern const char m1[];
extern const char m2[];
extern const char m3[];

4
include/name.h

@ -4,10 +4,10 @@
/* Constants that define the namespace mapping table sizes */
#define NM_PRELEN 8 /* Max size of a prefix string */
#define NM_PRELEN 16 /* Max size of a prefix string */
#define NM_REPLLEN 8 /* Maximum size of a replacement*/
#define NM_MAXLEN 8 /* Maximum size of a file name */
#define NNAMES 3 /* Number of prefix definitions */
#define NNAMES 4 /* Number of prefix definitions */
/* Definition of the name prefix table that defines all name mappings */

4
include/prototypes.h

@ -631,7 +631,9 @@ extern devcall spiputc(struct dentry *, char);
/* avr specific */
extern void avr_printf(char mess[]);
extern void avr_kprintf(char mess[]);
extern void avr_kprintf(const unsigned char *msg);
// extern void avr_kprintf(char mess[]);
extern void blink_avr();
typedef unsigned int size_t;
#define hibyte(x) (unsigned char)(((int)(x)>>8)&0xff)

1
include/shprototypes.h

@ -80,3 +80,4 @@ extern shellcmd xsh_help (int32, char *[]);
// RAFA AGREGO TODO ESTO
/* in file xsh_editor.c */
extern shellcmd xsh_editor (int32, char *[]);
extern shellcmd xsh_basic (int32, char *[]);

1
lib/avr_messages.c

@ -6,6 +6,7 @@ typedef unsigned int size_t;
// const char CONSOLE_RESET[] PROGMEM = " \033[0m\033[2J\033[;H";
// const char m0[] PROGMEM = "Welcome to Xinu for AVR microcontrollers!\n v0.1 rafa@fi.uncoma.edu.ar";
const char m0[] PROGMEM = "\nWelcome to Xinu!\n\n\r\tXinu OS Copyright (c) 2012, 2015\n\r\tDouglas E. Comer and CRC Press, Inc.\n\n\r\tThis version for AVR atmega328p v0.1 (c) 2020\n\r\tRafael Ignacio Zurita <rafa@fi.uncoma.edu.ar>\n\n\r";
const char m1[] PROGMEM = "\n\nMain process recreating shell\n\n";
const char m2[] PROGMEM = "Port system ran out of message nodes";
const char m3[] PROGMEM = "\n\nAll user processes have completed.\n\n";

23
lib/avr_printf.c

@ -4,16 +4,31 @@ void avr_printf(char mess[])
{
char t[80];
memset(t, 80, 0);
memset(t, 0, 80);
strncpy_P(t, mess, 79);
printf("%s", t);
}
void avr_kprintf(char mess[])
// void avr_kprintf(char mess[])
void avr_kprintf(const unsigned char *msg)
{
char t[80];
// char t[80];
intmask mask;
mask = disable();
while( pgm_read_byte( msg ) != 0 ) {
// printf( "%c", pgm_read_byte( msg++ ) );
putchar(pgm_read_byte( msg++ ) );
};
memset(t, 80, 0);
restore(mask);
/*
memset(t, 0, 80);
strncpy_P(t, mess, 79);
printf("%s", t);
*/
}

30
lib/printf.c

@ -11,22 +11,18 @@ extern int xinu_putc(did32, char);
* printf - standard C printf function
*------------------------------------------------------------------------
*/
#define PRINTF_BUF 81
int printf(
const char *fmt,
...
)
{
// va_list ap;
// //syscall putc(did32, char);
// int xinu_putc(did32, char);
// va_start(ap, fmt);
//_fdoprnt((char *)fmt, ap, putc, stdout);
//va_end(ap);
/*
va_list ap;
// RAFA
char output[81];
char *c;
@ -41,6 +37,22 @@ int printf(
putc(stdout, *c);
c++;
};
*/
char buf[PRINTF_BUF];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
for(char *p = &buf[0]; *p; p++) // emulate cooked mode for newlines
{
if(*p == '\n')
{
putchar('\r');
}
putchar(*p);
}
va_end(ap);
return 0;
}

15
shell/shell.c

@ -8,7 +8,9 @@
/* Table of Xinu shell commands and the function associated with each */
/************************************************************************/
const struct cmdent cmdtab[] = {
{"memstat", TRUE, xsh_memstat}, /* Make built-in */
{"memstat", FALSE, xsh_memstat}, /* Make built-in */
{"editor", FALSE, xsh_editor}, /* Make built-in */
{"basic", FALSE, xsh_basic}, /* Make built-in */
{"echo", FALSE, xsh_echo}
// {"argecho", TRUE, xsh_argecho},
// {"cat", FALSE, xsh_cat},
@ -94,6 +96,10 @@ process shell (
while (TRUE) {
// RAFA
// fprintf(dev, "\033[2J");
// fprintf(dev, "\033[H");
/* Display prompt */
fprintf(dev, SHELL_PROMPT);
@ -269,6 +275,11 @@ process shell (
}
}
// 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,
@ -276,7 +287,7 @@ process shell (
// RAFA cmdtab[j].cname, 2, ntok, &tmparg);
/* 160 bytes de stack perfecto */
child = create(cmdtab[j].cfunc,
160, SHELL_CMDPRIO,
460, SHELL_CMDPRIO,
cmdtab[j].cname, 2, ntok, &tmparg);
/* If creation or argument copy fails, report error */

4
shell/text_buffer.h

@ -0,0 +1,4 @@
#define NLINES 6
#define LINE_LEN 32

1818
shell/xsh_basic.c

File diff suppressed because it is too large Load Diff

101
shell/xsh_editor.c

@ -0,0 +1,101 @@
/* 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;
}

50
shell/xsh_memstat.c

@ -4,6 +4,10 @@
#include <stdio.h>
#include <string.h>
// RAFA
#include <avr/interrupt.h>
static void printMemUse(void);
static void printFreeList(void);
@ -14,34 +18,11 @@ static void printFreeList(void);
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();
// printMemUse();
printFreeList();
return 0;
}
@ -53,7 +34,7 @@ shellcmd xsh_memstat(int nargs, char *args[])
*/
static void printFreeList(void)
{
char t[80];
// char t[80];
struct memblk *block;
/* Output a heading for the free list */
@ -66,6 +47,23 @@ static void printFreeList(void)
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);

2
system/getstk.c

@ -28,6 +28,8 @@ char *getstk(
fitsprev = NULL; /* Just to avoid a compiler warning */
while (curr != NULL) { /* Scan entire list */
// RAFA kprintf("c:%d ",curr->mlength);
// RAFA kprintf("n:%d ",nbytes);
if (curr->mlength >= nbytes) { /* Record block address */
fits = curr; /* when request fits */
fitsprev = prev;

24
system/initialize.c

@ -59,16 +59,15 @@ pid32 currpid; /* ID of currently executing process */
void nullprocess(void) {
kprintf("nullp\n");
// kprintf("nullp\n");
// resume(create((void *)main, INITSTK, INITPRIO, "Main Process", 0, NULL));
// 200 ok and 400 ok
// resume(create((void *)shell, 200, INITPRIO, "shell", 0, NULL));
//resume(create((void *)shell, 256, INITPRIO, "shell", 0, NULL));
resume(create((void *)shell, 360, INITPRIO, "shell", 0, NULL));
resume(create((void *)test, 256, INITPRIO, "test", 0, NULL));
//resume(create((void *)test, 400, INITPRIO, "test", 0, NULL));
// resume(create((void *)test, 256, INITPRIO, "test", 0, NULL));
for(;;);
}
@ -116,7 +115,13 @@ void nulluser()
memptr = memptr->mnext) {
free_mem += memptr->mlength;
}
kprintf("\n\rFreeMEM:%d\n", free_mem);
kprintf("\nFreeMEM:%d\n", free_mem);
/*
long * b = (long *) memlist.mnext;
*(b+32) = STACKMAGIC;
kprintf("S2:%X\n", *(b+32));
*/
/* Initialize the Null process entry */
int pid = create((void *)nullprocess, INITSTK, 10, "Null process", 0, NULL);
@ -127,10 +132,9 @@ void nulluser()
/* Enable interrupts */
enable();
/* Initialize the real time clock */
clkinit();
// /* Initialize the real time clock */
// clkinit();
/* Start of nullprocess */
startup(0, prptr);
@ -147,6 +151,7 @@ void startup(int INIT, struct procent *p) {
/* Should not be here, panic */
// resume(INIT);
nullprocess();
//resume(INIT);
avr_kprintf(m6);
panic("");
@ -171,7 +176,7 @@ static void sysinit()
platinit();
kprintf(CONSOLE_RESET);
kprintf("\n\r%s\n", VERSION);
avr_kprintf(m0);
/* Initialize free memory list */
@ -225,7 +230,6 @@ static void sysinit()
clkinit();
return;
}

6
system/kprintf.c

@ -50,9 +50,9 @@ extern void _doprnt(char *, va_list, int (*)(int));
syscall kprintf(char *fmt, ...)
{
va_list ap;
intmask mask;
//intmask mask;
mask = disable();
//mask = disable();
char output[81];
char *c;
@ -68,6 +68,6 @@ syscall kprintf(char *fmt, ...)
c++;
};
restore(mask);
//restore(mask);
return OK;
}

1
system/platinit.c

@ -26,7 +26,6 @@ void platinit(void)
/* avr uart init */
serial_init();
char f = serial_get_char();
/* Initialize the Interrupt Controller (evec.c) */
initintc();

9
system/serial_avr.c

@ -49,8 +49,8 @@ void serial_init() {
puerto_serial->status_control_b = (unsigned char)(EN_RX_TX | (1<<UART_RXCIE0));
/* test */
while(!((puerto_serial->status_control_a) & (EN_TX)));
puerto_serial->data_es = 'R';
// while(!((puerto_serial->status_control_a) & (EN_TX)));
// puerto_serial->data_es = 'R';
}
@ -58,8 +58,7 @@ void serial_put_char (char outputChar)
{
while(!((puerto_serial->status_control_a) & (EN_TX)));
puerto_serial->data_es = outputChar;
puerto_serial->data_es = outputChar;
}
char value;
@ -79,7 +78,7 @@ char serial_get_char(void)
{
/* Wait for the next character to arrive. */
while(!((puerto_serial->status_control_a) & (EN_RX)));
return (puerto_serial->data_es);
return (puerto_serial->data_es);
}
void serial_put_str (char * mensaje)

5
xinu-avr-port.txt

@ -91,3 +91,8 @@ En el resched.c nuevo hay que poner la llamada a ctxswitch.
BASIC: https://github.com/robinhedwards/ArduinoBASIC/blob/master/arduino_BASIC.ino
En
#define STACK_SIZE (sizeof(struct stack_for_frame)*2)
estaba en *5 en vez de *2
Pero pisaba memoria de datos. Y con 2 no anda bien.

Loading…
Cancel
Save