├── main ├── lib │ ├── t3 │ ├── tinyc │ ├── t │ └── makefile ├── text_buffer.h ├── README ├── xsh_forever.c ├── xsh_clear.c ├── xsh_reboot.c ├── xsh_echo.c ├── xsh_date.c ├── xsh_gpio.c ├── xsh_sleep.c ├── xsh_memdump.c ├── xsh_ps.c ├── xsh_free.c ├── xsh_kill.c └── xsh_uptime.c ├── www ├── w2.html ├── files │ ├── placa.jpg │ ├── placa2.jpg │ ├── placa3.jpg │ ├── cnbleft01.jpg │ ├── cnbleft02.jpg │ ├── cnbleft03.jpg │ ├── cnbleft04.jpg │ ├── cover-icon.jpeg │ ├── xinu_web_page_heading.jpeg │ ├── page_l.css │ ├── page_p.css │ └── mainpage.css ├── build_web.sh └── w1.html ├── apps ├── shell │ ├── lib │ │ ├── t3 │ │ ├── t │ │ └── makefile │ ├── text_buffer.h │ ├── README │ ├── xsh_forever.c │ ├── xsh_clear.c │ ├── xsh_reboot.c │ ├── xsh_echo.c │ ├── xsh_date.c │ ├── xsh_gpio.c │ ├── xsh_sleep.c │ ├── xsh_memdump.c │ ├── xsh_ps.c │ ├── xsh_free.c │ ├── xsh_kill.c │ └── xsh_uptime.c ├── example1 │ ├── main.c │ └── README.md ├── example0 │ ├── README.md │ └── main.c ├── example2 │ ├── README.md │ └── main.c ├── example3 │ ├── README.md │ └── main.c ├── example4 │ ├── README.md │ └── main.c ├── example5 │ ├── README.md │ └── main.c └── README.md ├── compile ├── DAC_OUT_PUT1.txt ├── DAC_OUT_PUT2.txt ├── version └── bin │ └── mkvers ├── include ├── userland.h ├── uart.h ├── debug.h ├── device.h ├── stddef.h ├── icu.h ├── string.h ├── avr_eeprom_disk.h ├── timer.h ├── stdlib.h ├── resched.h ├── stdarg.h ├── delay.h ├── avr_serial.h ├── semaphore.h ├── mark.h ├── avr_messages.h ├── file.h ├── interrupt.h ├── bufpool.h ├── ip.h ├── name.h ├── xinu.h ├── spi.h ├── ctype.h ├── syscall.h ├── stdio.h ├── icmp.h ├── memory.h ├── ports.h ├── udp.h ├── testsuite.h ├── limits.h ├── queue.h ├── arp.h └── dns.h ├── lib ├── avr_printf.c ├── change_proc_name.c ├── getchar.c ├── abs.c ├── putchar.c ├── bzero.c ├── printf.c ├── userland.c ├── fprintf.c ├── ctype_.c ├── avr_messages.c ├── date.c └── avr_gpio.c ├── TODO ├── system ├── getpid.c ├── ionull.c ├── exit.c ├── ioerr.c ├── userret.c ├── xdone.c ├── getticks.c ├── bufinit.c ├── blink_avr.c ├── yield.c ├── panic.c ├── wakeup.c ├── getprio.c ├── getdev.c ├── gettime.c ├── ready.c ├── platinit.c ├── recvclr.c ├── semcount.c ├── seek.c ├── chprio.c ├── close.c ├── receive.c ├── putc.c ├── getc.c ├── init.c ├── evec.c ├── signal.c ├── resume.c ├── read.c ├── write.c ├── open.c ├── newqueue.c ├── semdelete.c ├── signaln.c ├── control.c ├── insert.c ├── start.S ├── semreset.c ├── wait.c ├── freebuf.c ├── send.c ├── clkhandler.c ├── getbuf.c ├── suspend.c ├── conf.c ├── insertd.c ├── recvtime.c ├── mark.c ├── unsleep.c ├── clkinit.c ├── sleep.c ├── getmem.c ├── semcreate.c ├── kill.c ├── queue.c ├── intr.c ├── getstk.c ├── getitem.c ├── kprintf.c ├── mkbufpool.c └── avr_serial.c ├── device ├── avr_eeprom │ ├── eeprom_close.c │ ├── eeprom_init.c │ ├── eeprom_seek.c │ ├── eeprom_open.c │ ├── eeprom_read.c │ └── eeprom_write.c ├── rfs │ ├── rflputc.c │ ├── rflgetc.c │ ├── rflclose.c │ ├── rflinit.c │ ├── rflseek.c │ ├── rfsinit.c │ ├── rfsndmsg.c │ └── rfsgetmode.c ├── tty │ ├── ttykickout.c │ ├── ttywrite.c │ ├── ttyhandler.c │ ├── ttyputc.c │ ├── ttygetc.c │ ├── ttycontrol.c │ └── ttyread.c ├── lfs │ ├── lfibclear.c │ ├── lfdbfree.c │ ├── lflwrite.c │ ├── lfsinit.c │ ├── lfibget.c │ ├── lflclose.c │ ├── lfiballoc.c │ ├── lflread.c │ ├── lfflush.c │ ├── lfscheck.c │ ├── lflseek.c │ ├── lfibput.c │ ├── lfdballoc.c │ ├── lflcontrol.c │ ├── lfgetmode.c │ ├── lflgetc.c │ ├── lflinit.c │ ├── lflputc.c │ └── lfsckfmt.c ├── nam │ └── namopen.c ├── eth │ └── ethcontrol.c └── rds │ ├── rdsbufalloc.c │ └── rdsclose.c ├── AUTHORS ├── config ├── Makefile ├── conf.c ├── config.l └── conf.h └── LICENSE /main/lib/t3: -------------------------------------------------------------------------------- 1 | { a=0; read(a); print(a); } 2 | -------------------------------------------------------------------------------- /www/w2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /apps/shell/lib/t3: -------------------------------------------------------------------------------- 1 | { a=0; read(a); print(a); } 2 | -------------------------------------------------------------------------------- /main/text_buffer.h: -------------------------------------------------------------------------------- 1 | 2 | #define NLINES 6 3 | #define LINE_LEN 32 4 | 5 | -------------------------------------------------------------------------------- /main/lib/tinyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/main/lib/tinyc -------------------------------------------------------------------------------- /apps/shell/text_buffer.h: -------------------------------------------------------------------------------- 1 | 2 | #define NLINES 6 3 | #define LINE_LEN 32 4 | 5 | -------------------------------------------------------------------------------- /compile/DAC_OUT_PUT1.txt: -------------------------------------------------------------------------------- 1 | ****DAC_OUT_PUT1 : Result of conversion DAC channel 1**** 2 | -------------------------------------------------------------------------------- /compile/DAC_OUT_PUT2.txt: -------------------------------------------------------------------------------- 1 | ****DAC_OUT_PUT2 : Result of conversion DAC channel 2**** 2 | -------------------------------------------------------------------------------- /www/files/placa.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/placa.jpg -------------------------------------------------------------------------------- /main/lib/t: -------------------------------------------------------------------------------- 1 | { i = 0; a=0; read(a); print(a); do { i = i + 10; print(i);} while (i < a);} 2 | -------------------------------------------------------------------------------- /www/files/placa2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/placa2.jpg -------------------------------------------------------------------------------- /www/files/placa3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/placa3.jpg -------------------------------------------------------------------------------- /apps/shell/lib/t: -------------------------------------------------------------------------------- 1 | { i = 0; a=0; read(a); print(a); do { i = i + 10; print(i);} while (i < a);} 2 | -------------------------------------------------------------------------------- /compile/version: -------------------------------------------------------------------------------- 1 | Xinu for ATMEGA328P -- version #281 (lechnerm) mié may 27 10:45:49 -03 2020 2 | -------------------------------------------------------------------------------- /www/files/cnbleft01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/cnbleft01.jpg -------------------------------------------------------------------------------- /www/files/cnbleft02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/cnbleft02.jpg -------------------------------------------------------------------------------- /www/files/cnbleft03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/cnbleft03.jpg -------------------------------------------------------------------------------- /www/files/cnbleft04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/cnbleft04.jpg -------------------------------------------------------------------------------- /www/files/cover-icon.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/cover-icon.jpeg -------------------------------------------------------------------------------- /www/files/xinu_web_page_heading.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrafa/xinu-avr/HEAD/www/files/xinu_web_page_heading.jpeg -------------------------------------------------------------------------------- /include/userland.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | -------------------------------------------------------------------------------- /include/uart.h: -------------------------------------------------------------------------------- 1 | /* avr specific */ 2 | 3 | /* Not useful so far */ 4 | 5 | #define UART_FIFO_SIZE 1 6 | struct uart_csreg { /* avr does not use this so far */ 7 | char c; 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /main/lib/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 3 | 4 | all: mini 5 | 6 | mini: mini.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | mini.o: mini.c 10 | 11 | clean: 12 | $(RM) mini *.o 13 | -------------------------------------------------------------------------------- /apps/shell/lib/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 3 | 4 | all: mini 5 | 6 | mini: mini.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | mini.o: mini.c 10 | 11 | clean: 12 | $(RM) mini *.o 13 | -------------------------------------------------------------------------------- /include/debug.h: -------------------------------------------------------------------------------- 1 | /* debug.h */ 2 | 3 | #define DEBUG_ASCII 0x01 4 | #define DEBUG_HEX 0x02 5 | 6 | void hexdump(void *buffer, uint32 length, bool8 text); 7 | void debugbreak(void); 8 | void debugret(void); 9 | -------------------------------------------------------------------------------- /main/README: -------------------------------------------------------------------------------- 1 | 2 | This app needs the below modificationes into conf/Configuration file: 3 | 4 | #define NPROC 4 /* number of user processes */ 5 | #define NSEM 2 /* number of semaphores */ 6 | 7 | -------------------------------------------------------------------------------- /apps/shell/README: -------------------------------------------------------------------------------- 1 | 2 | This app needs the below modificationes into conf/Configuration file: 3 | 4 | #define NPROC 4 /* number of user processes */ 5 | #define NSEM 2 /* number of semaphores */ 6 | 7 | -------------------------------------------------------------------------------- /include/device.h: -------------------------------------------------------------------------------- 1 | /* device.h - isbaddev */ 2 | 3 | #define DEVNAMLEN 16 /* maximum size of a device name */ 4 | 5 | /* Macro used to verify device ID is valid */ 6 | 7 | #define isbaddev(f) ( ((f) < 0) | ((f) >= NDEVS) ) 8 | -------------------------------------------------------------------------------- /lib/avr_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern serial_put_char(char); 4 | 5 | void avr_kprintf(const __flash char m[]) 6 | { 7 | int i; 8 | for (i=0; i 3 | 4 | void change_proc_name( char *name) 5 | { 6 | struct procent *prptr; /* pointer to proc. table entry */ 7 | int i; 8 | 9 | 10 | prptr = &proctab[currpid]; 11 | 12 | prptr->prname[PNMLEN-1] = NULLCH; 13 | for (i=0 ; iprname[i]=name[i])!=NULLCH; i++) 14 | ; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /system/getpid.c: -------------------------------------------------------------------------------- 1 | /* getpid.c - getpid */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getpid - Return the ID of the currently executing process 7 | *------------------------------------------------------------------------ 8 | */ 9 | pid32 getpid(void) 10 | { 11 | return (currpid); 12 | } 13 | -------------------------------------------------------------------------------- /system/ionull.c: -------------------------------------------------------------------------------- 1 | /* ionull.c - ionull */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ionull - Do nothing (used for "don't care" entries in devtab) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ionull(void) 10 | { 11 | return OK; 12 | } 13 | -------------------------------------------------------------------------------- /lib/getchar.c: -------------------------------------------------------------------------------- 1 | /* getchar.c - getchar */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * getchar - DOCUMENT 8 | *------------------------------------------------------------------------ 9 | */ 10 | int getchar( 11 | void 12 | ) 13 | { 14 | return fgetc(stdin); 15 | } 16 | -------------------------------------------------------------------------------- /system/exit.c: -------------------------------------------------------------------------------- 1 | /* exit.c - exit */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * exit - Cause the calling process to exit 7 | *------------------------------------------------------------------------ 8 | */ 9 | void exit(void) 10 | { 11 | kill(getpid()); /* Kill the current process */ 12 | } 13 | -------------------------------------------------------------------------------- /system/ioerr.c: -------------------------------------------------------------------------------- 1 | /* ioerr.c - ioerr */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ioerr - Return an error status (used for "error" entries in devtab) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ioerr(void) 10 | { 11 | return SYSERR; 12 | } 13 | -------------------------------------------------------------------------------- /lib/abs.c: -------------------------------------------------------------------------------- 1 | /* abs.c - abs */ 2 | 3 | /*------------------------------------------------------------------------ 4 | * abs - Return the absolute value of an integer. 5 | *------------------------------------------------------------------------ 6 | */ 7 | int abs( 8 | int arg 9 | ) 10 | { 11 | if (arg < 0) 12 | arg = -arg; 13 | return (arg); 14 | } 15 | -------------------------------------------------------------------------------- /apps/example1/main.c: -------------------------------------------------------------------------------- 1 | /* ex1.c - main */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * main -- write "hi" on the console 7 | *------------------------------------------------------------------------ 8 | */ 9 | void main(void) 10 | { 11 | putc(CONSOLE, 'h'); putc(CONSOLE, 'i'); 12 | putc(CONSOLE, '\r'); putc(CONSOLE, '\n'); 13 | } 14 | -------------------------------------------------------------------------------- /system/userret.c: -------------------------------------------------------------------------------- 1 | /* userret.c - userret */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * userret - Called when a process returns from the top-level function 7 | *------------------------------------------------------------------------ 8 | */ 9 | void userret(void) 10 | { 11 | kill(getpid()); /* Force process to exit */ 12 | } 13 | -------------------------------------------------------------------------------- /www/build_web.sh: -------------------------------------------------------------------------------- 1 | 2 | markdown_py -f index.html $1 3 | echo '


last edit: '$(date)' - Rafael Ignacio Zurita (rafa at fi.uncoma.edu.ar)

' > /tmp/deleteme2 4 | cat w1.html index.html /tmp/deleteme2 w2.html | grep -v "Visit its Web" | grep -v 'xinu-avr' | grep -v "=====" > /tmp/deleteme.html 5 | rm index.html 6 | rm /tmp/deleteme2 7 | mv /tmp/deleteme.html ../index.html 8 | -------------------------------------------------------------------------------- /main/xsh_forever.c: -------------------------------------------------------------------------------- 1 | /* xsh_forever.c - xsh_forever */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_forever 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_forever(int nargs, char *args[]) 11 | { 12 | 13 | for (;;); 14 | //sleep(1); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /apps/shell/xsh_forever.c: -------------------------------------------------------------------------------- 1 | /* xsh_forever.c - xsh_forever */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_forever 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_forever(int nargs, char *args[]) 11 | { 12 | 13 | for (;;); 14 | //sleep(1); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /system/xdone.c: -------------------------------------------------------------------------------- 1 | /* xdone.c - xdone */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * xdone - Print system completion message as last process exits 7 | *------------------------------------------------------------------------ 8 | */ 9 | void xdone(void) 10 | { 11 | /* avr specific */ 12 | avr_kprintf(m3); 13 | halt(); /* Halt the processor */ 14 | } 15 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /* string.h */ 2 | 3 | extern char *strncpy(char *, const char *, int32); 4 | extern char *strncat(char *, const char *, int32); 5 | extern int32 strncmp(const char *, const char *, int32); 6 | extern char *strchr(const char *, int32); 7 | extern char *strrchr(const char *, int32); 8 | extern char *strstr(const char *, const char *); 9 | extern int32 strnlen(const char *, uint32); 10 | extern int strlen(char *str); 11 | -------------------------------------------------------------------------------- /lib/putchar.c: -------------------------------------------------------------------------------- 1 | /* putchar.c - putchar */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * putchar - C putchar function 8 | *------------------------------------------------------------------------ 9 | */ 10 | int putchar( 11 | int c 12 | ) 13 | { 14 | // RAFA return fputc(c, stdout); 15 | serial_put_char(c); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_close.c: -------------------------------------------------------------------------------- 1 | /* ramclose.c - ramclose */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * eeprom_close - Close a eeprom disk 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall eeprom_close ( 10 | const __flash struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | return OK; 14 | } 15 | -------------------------------------------------------------------------------- /include/avr_eeprom_disk.h: -------------------------------------------------------------------------------- 1 | /* ramdisk.h - definitions for a ram disk (for testing) */ 2 | 3 | /* Ram disk block size */ 4 | 5 | // #define RM_BLKSIZ 512 /* block size */ 6 | // #define RM_BLKS 200 /* number of blocks */ 7 | 8 | #define RM_BLKSIZ 4 /* block size */ 9 | #define RM_BLKS 2 /* number of blocks */ 10 | /* 11 | struct ramdisk { 12 | char disk[RM_BLKSIZ * RM_BLKS]; 13 | }; 14 | 15 | extern struct ramdisk Ram; 16 | */ 17 | -------------------------------------------------------------------------------- /include/timer.h: -------------------------------------------------------------------------------- 1 | /*General purpose timer */ 2 | 3 | extern unsigned long clktime; /* current time in secs since boot */ 4 | extern unsigned long count1000; /* ms since last clock tick */ 5 | 6 | extern qid16 sleepq; /* queue for sleeping processes */ 7 | extern int32 slnonempty; /* nonzero if sleepq is nonempty */ 8 | extern int32 *sltop; /* ptr to key in first item on sleepq */ 9 | extern uint32 preempt; /* preemption counter */ 10 | -------------------------------------------------------------------------------- /main/xsh_clear.c: -------------------------------------------------------------------------------- 1 | /* xsh_clear.c - xsh_clear */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_clear - clear the terminal screen 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_clear(int nargs, char *args[]) 11 | { 12 | fprintf(0, "\033[2J"); 13 | fprintf(0, "\033[H"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /system/getticks.c: -------------------------------------------------------------------------------- 1 | /* getticks.c - getticks */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getticks - Retrieve the number of clock ticks since CPU reset 7 | *------------------------------------------------------------------------ 8 | */ 9 | uint32 getticks() 10 | { 11 | /* Cortex M3 does have a clock cycle cnt register */ 12 | uint32 ret = 0; 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /apps/shell/xsh_clear.c: -------------------------------------------------------------------------------- 1 | /* xsh_clear.c - xsh_clear */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_clear - clear the terminal screen 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_clear(int nargs, char *args[]) 11 | { 12 | fprintf(0, "\033[2J"); 13 | fprintf(0, "\033[H"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /system/bufinit.c: -------------------------------------------------------------------------------- 1 | /* bufinit.c - bufinit */ 2 | 3 | #include 4 | 5 | struct bpentry buftab[NBPOOLS]; /* Buffer pool table */ 6 | bpid32 nbpools; 7 | 8 | /*------------------------------------------------------------------------ 9 | * bufinit - Initialize the buffer pool data structure 10 | *------------------------------------------------------------------------ 11 | */ 12 | status bufinit(void) 13 | { 14 | nbpools = 0; 15 | return OK; 16 | } 17 | -------------------------------------------------------------------------------- /system/blink_avr.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void my_delay(unsigned long delay) { 5 | volatile unsigned long i = 0; 6 | for (i = 0; i < delay; i++) { 7 | __asm__ __volatile__ ("nop"); 8 | } 9 | } 10 | 11 | 12 | void blink_avr(void) { 13 | 14 | DDRB = (1< 4 | 5 | /*------------------------------------------------------------------------ 6 | * yield - Voluntarily relinquish the CPU (end a timeslice) 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall yield(void) 10 | { 11 | intmask mask; /* Saved interrupt mask */ 12 | 13 | mask = disable(); 14 | resched(); 15 | restore(mask); 16 | return OK; 17 | } 18 | -------------------------------------------------------------------------------- /system/panic.c: -------------------------------------------------------------------------------- 1 | /* panic.c - panic */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * panic - Display a message and stop all processing 7 | *------------------------------------------------------------------------ 8 | */ 9 | void panic ( 10 | char *msg /* Message to display */ 11 | ) 12 | { 13 | disable(); /* Disable interrupts */ 14 | kprintf("\n\n\rpanic: %s\n\n", msg); 15 | while(TRUE) {;} /* Busy loop forever */ 16 | } 17 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file stdlib.h 3 | * 4 | * $Id: stdlib.h 2051 2009-08-27 20:55:09Z akoehler $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #define RAND_MAX 2147483646 9 | 10 | int abs(int); 11 | long labs(long); 12 | int atoi(char *); 13 | long atol(char *); 14 | void bzero(void *, int); 15 | void qsort(char *, unsigned int, int, int (*)(void)); 16 | int rand(void); 17 | void srand(unsigned int); 18 | void *malloc(unsigned int nbytes); 19 | void free(void *pmem); 20 | -------------------------------------------------------------------------------- /include/resched.h: -------------------------------------------------------------------------------- 1 | /* resched.h */ 2 | 3 | /* Constants and variables related to deferred rescheduling */ 4 | 5 | #define DEFER_START 1 /* Start deferred rescehduling */ 6 | #define DEFER_STOP 2 /* Stop deferred rescehduling */ 7 | 8 | /* Structure that collects items related to deferred rescheduling */ 9 | 10 | struct defer { 11 | int32 ndefers; /* Number of outstanding defers */ 12 | bool8 attempt; /* Was resched called during the */ 13 | /* deferral period? */ 14 | }; 15 | 16 | extern struct defer Defer; 17 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file stdarg.h 3 | * @provides va_copy, va_start, va_arg, va_end. 4 | * 5 | * $Id: stdarg.h 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /* GCC-specific varargs */ 10 | typedef __builtin_va_list va_list; 11 | 12 | #define va_copy(dst, src) __builtin_va_copy(dst, src) 13 | #define va_start(last, va) __builtin_va_start(last, va) 14 | #define va_arg(va, type) __builtin_va_arg(va, type) 15 | #define va_end(va) __builtin_va_end(va) 16 | -------------------------------------------------------------------------------- /lib/bzero.c: -------------------------------------------------------------------------------- 1 | /* bzero.c - bzero */ 2 | 3 | /*------------------------------------------------------------------------ 4 | * bzero - Clears a block of characters to 0s. 5 | *------------------------------------------------------------------------ 6 | */ 7 | void bzero( 8 | void *p, 9 | int len 10 | ) 11 | { 12 | int n; 13 | char *pch = (char *)p; 14 | 15 | if ((n = len) <= 0) 16 | { 17 | return; 18 | } 19 | do 20 | { 21 | *pch++ = 0; 22 | } 23 | while (--n); 24 | } 25 | -------------------------------------------------------------------------------- /device/rfs/rflputc.c: -------------------------------------------------------------------------------- 1 | /* rflputc.c - rflputc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rflputc - Write one character to a remote file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall rflputc( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | char ch /* Character to write */ 12 | ) 13 | { 14 | if (rflwrite(devptr, &ch, 1) != 1) { 15 | return SYSERR; 16 | } 17 | 18 | return OK; 19 | } 20 | -------------------------------------------------------------------------------- /include/delay.h: -------------------------------------------------------------------------------- 1 | /* delay.h - DELAY */ 2 | 3 | /* 4 | * Delay units are in microseconds. 5 | */ 6 | #define DELAY(n) \ 7 | { \ 8 | volatile long N = 2*n; \ 9 | \ 10 | while(N > 0) { \ 11 | N--; \ 12 | } \ 13 | } 14 | 15 | /* 16 | * Delay units are in milli-seconds. 17 | */ 18 | #define MDELAY(n) \ 19 | { \ 20 | register long i; \ 21 | \ 22 | for (i=n;i>0;i--) { \ 23 | DELAY(1000); \ 24 | } \ 25 | } 26 | -------------------------------------------------------------------------------- /main/xsh_reboot.c: -------------------------------------------------------------------------------- 1 | /* xsh_reboot.c - xsh_reboot */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_reboot - reset Xinu system. WARNING: this is not a hardware reset 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_reboot(int nargs, char *args[]) 12 | { 13 | void(* reset_func) (void) = 0;//declare reset function at address 0 14 | cli(); // disable interrupts 15 | reset_func(); 16 | } 17 | -------------------------------------------------------------------------------- /apps/shell/xsh_reboot.c: -------------------------------------------------------------------------------- 1 | /* xsh_reboot.c - xsh_reboot */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_reboot - reset Xinu system. WARNING: this is not a hardware reset 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_reboot(int nargs, char *args[]) 12 | { 13 | void(* reset_func) (void) = 0;//declare reset function at address 0 14 | cli(); // disable interrupts 15 | reset_func(); 16 | } 17 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_init.c: -------------------------------------------------------------------------------- 1 | /* raminit.c - raminit */ 2 | 3 | #include 4 | #include 5 | 6 | #define EEPROM_SIZE = 1024; 7 | 8 | int eeprom_pos = 0; 9 | 10 | /*------------------------------------------------------------------------ 11 | * eeprom_init - Initialize the eeprom disk 12 | *------------------------------------------------------------------------ 13 | */ 14 | devcall eeprom_init ( 15 | const __flash struct dentry *devptr /* Entry in device switch table */ 16 | ) 17 | { 18 | eeprom_pos = 0; 19 | 20 | return OK; 21 | } 22 | -------------------------------------------------------------------------------- /apps/example0/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example0 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example0/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/example1/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example1 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example1/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/example2/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example2 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example2/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/example3/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example3 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example3/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/example4/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example1 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example1/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/example5/README.md: -------------------------------------------------------------------------------- 1 | 2 | Quick start 3 | ----------- 4 | 5 | 1. get the repository 6 | ``` 7 | # get the repository 8 | git clone http://github.com/zrfa/xinu-avr 9 | cd xinu-avr/ 10 | ``` 11 | 12 | 2. copy the example5 app to main 13 | ``` 14 | # copy an example app to main 15 | rm -rf main/ 16 | cp -r apps/example5/ main/ 17 | ``` 18 | 19 | 3. build 20 | ``` 21 | # build 22 | cd compile/ 23 | make clean 24 | make 25 | ``` 26 | 27 | 4. flash and test 28 | ``` 29 | # flash and test 30 | make flash 31 | screen /dev/ttyUSB0 # it could be /dev/ttyACM0 or whatever. Check dmesg 32 | ``` 33 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | 3 | Xinu OS Copyright (c) 2012, 2015 4 | Douglas E. Comer and CRC Press, Inc. 5 | 6 | xinu-avr for AVR atmega328p microcontroller v0.1 (c) 2020 7 | Rafael Ignacio Zurita 8 | 9 | 10 | Acknowledgments 11 | 12 | Michael M. Minor: he is the author of another AVR port os Xinu 13 | (https://sites.google.com/site/avrxinu/) 14 | We use his context switch code, the addargs in Xinu shell, and 15 | a few lines more. His port is for bigger AVR microcontrollers 16 | (16KB+ of RAM), and he used an old version of Xinu (Xinu from 17 | the 1987 book edition). 18 | 19 | -------------------------------------------------------------------------------- /system/wakeup.c: -------------------------------------------------------------------------------- 1 | /* wakeup.c - wakeup */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * wakeup - Called by clock interrupt handler to awaken processes 7 | *------------------------------------------------------------------------ 8 | */ 9 | void wakeup(void) 10 | { 11 | /* Awaken all processes that have no more time to sleep */ 12 | 13 | resched_cntl(DEFER_START); 14 | while (nonempty(sleepq) && (firstkey(sleepq) <= 0)) { 15 | ready(dequeue(sleepq)); 16 | } 17 | 18 | resched_cntl(DEFER_STOP); 19 | return; 20 | } 21 | -------------------------------------------------------------------------------- /main/xsh_echo.c: -------------------------------------------------------------------------------- 1 | /* xsh_echo.c - xsh_echo */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_echo - write argument strings to stdout 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_echo(int nargs, char *args[]) 11 | { 12 | int32 i; /* walks through args array */ 13 | 14 | if (nargs > 1) { 15 | printf("%s", args[1]); 16 | 17 | for (i = 2; i < nargs; i++) { 18 | printf(" %s", args[i]); 19 | } 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /apps/shell/xsh_echo.c: -------------------------------------------------------------------------------- 1 | /* xsh_echo.c - xsh_echo */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_echo - write argument strings to stdout 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_echo(int nargs, char *args[]) 11 | { 12 | int32 i; /* walks through args array */ 13 | 14 | if (nargs > 1) { 15 | printf("%s", args[1]); 16 | 17 | for (i = 2; i < nargs; i++) { 18 | printf(" %s", args[i]); 19 | } 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /include/avr_serial.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * 3 | * Filename: serial.h 4 | * 5 | * API para la aplicacion embebida 6 | * 7 | * META : ocultar el hardware a la aplicacion 8 | * 9 | **********************************************************************/ 10 | 11 | #ifndef _SERIAL_H 12 | #define _SERIAL_H 13 | 14 | void serial_init(void); 15 | void serial_put_char(char outputChar); 16 | char serial_get_char(void); 17 | void serial_put_str(char * outputStr); 18 | char* serial_get_str(void); 19 | 20 | 21 | #endif /* _SERIAL_H */ 22 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_seek.c: -------------------------------------------------------------------------------- 1 | /* eeprom_seek.c */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * eeprom_seek - Seek to a specified position 8 | *------------------------------------------------------------------------ 9 | */ 10 | devcall eeprom_seek ( 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | uint32 offset /* Byte position */ 13 | ) 14 | { 15 | 16 | if (offset >= EEPROM_SIZE) 17 | return SYSERR; 18 | 19 | eeprom_pos = offset; 20 | 21 | return OK; 22 | } 23 | -------------------------------------------------------------------------------- /main/xsh_date.c: -------------------------------------------------------------------------------- 1 | /* xsh_date.c - xsh_date */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_date - set or get the date and time 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_date(int nargs, char *args[]) 11 | { 12 | char avr_date[80]; 13 | 14 | if (nargs == 1) { 15 | get_date(avr_date); 16 | printf("\n%s\n\n", avr_date); 17 | return 0; 18 | } 19 | 20 | if (nargs != 3) 21 | return -1; 22 | 23 | set_date(args[1], args[2]); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /compile/bin/mkvers: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Generate a new version string to be printed at startup 4 | # 5 | # Use is: mkvers platform_name 6 | 7 | VERS_NUM_FILE=.vers_num 8 | 9 | case $# in 10 | 1) PLAT="$1" 11 | ;; 12 | *) echo 'use is: mkvers platform_name' >&2 13 | exit 1 14 | ;; 15 | esac 16 | 17 | if test -s $VERS_NUM_FILE; then 18 | OLD_VERS=`cat $VERS_NUM_FILE` 19 | VERS=`expr $OLD_VERS + 1` 20 | else 21 | VERS=1 22 | fi 23 | echo $VERS > $VERS_NUM_FILE 24 | if test "x$USER" = "x"; then 25 | USER=`who am i | sed 's/ .*//'` 26 | fi 27 | echo "Xinu for $PLAT -- version #$VERS ($USER) `date`" 28 | -------------------------------------------------------------------------------- /device/rfs/rflgetc.c: -------------------------------------------------------------------------------- 1 | /* rflgetc.c - rflgetc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rflgetc - Read one character from a remote file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall rflgetc( 10 | struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | char ch; /* Character to read */ 14 | int32 retval; /* Return value */ 15 | 16 | retval = rflread(devptr, &ch, 1); 17 | 18 | if (retval != 1) { 19 | return SYSERR; 20 | } 21 | 22 | return (devcall)ch; 23 | } 24 | -------------------------------------------------------------------------------- /apps/shell/xsh_date.c: -------------------------------------------------------------------------------- 1 | /* xsh_date.c - xsh_date */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_date - set or get the date and time 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_date(int nargs, char *args[]) 11 | { 12 | char avr_date[80]; 13 | 14 | if (nargs == 1) { 15 | get_date(avr_date); 16 | printf("\n%s\n\n", avr_date); 17 | return 0; 18 | } 19 | 20 | if (nargs != 3) 21 | return -1; 22 | 23 | set_date(args[1], args[2]); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /system/getprio.c: -------------------------------------------------------------------------------- 1 | /* getprio.c - getprio */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getprio - Return the scheduling priority of a process 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall getprio( 10 | pid32 pid /* Process ID */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | uint32 prio; /* Priority to return */ 15 | 16 | mask = disable(); 17 | if (isbadpid(pid)) { 18 | restore(mask); 19 | return SYSERR; 20 | } 21 | prio = proctab[pid].prprio; 22 | restore(mask); 23 | return prio; 24 | } 25 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_open.c: -------------------------------------------------------------------------------- 1 | /* ramopen.c - ramopen */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * eeprom_open - Open a eeprom disk 7 | *------------------------------------------------------------------------ 8 | */ 9 | 10 | devcall eeprom_open ( 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *name, /* Unused for a ram disk */ 13 | char *mode /* Unused for a ram disk */ 14 | ) 15 | { 16 | /* No action -- just return the device descriptor */ 17 | 18 | //RAFA 19 | kprintf("eou:%i\n",devptr->dvnum); 20 | return devptr->dvnum; 21 | } 22 | -------------------------------------------------------------------------------- /include/semaphore.h: -------------------------------------------------------------------------------- 1 | /* semaphore.h - isbadsem */ 2 | 3 | #ifndef NSEM 4 | #define NSEM 120 /* Number of semaphores, if not defined */ 5 | #endif 6 | 7 | /* Semaphore state definitions */ 8 | 9 | #define S_FREE 0 /* Semaphore table entry is available */ 10 | #define S_USED 1 /* Semaphore table entry is in use */ 11 | 12 | /* Semaphore table entry */ 13 | struct sentry { 14 | byte sstate; /* Whether entry is S_FREE or S_USED */ 15 | int32 scount; /* Count for the semaphore */ 16 | qid16 squeue; /* Queue of processes that are waiting */ 17 | /* on the semaphore */ 18 | }; 19 | 20 | extern struct sentry semtab[]; 21 | 22 | #define isbadsem(s) ((int32)(s) < 0 || (s) >= NSEM) 23 | -------------------------------------------------------------------------------- /device/tty/ttykickout.c: -------------------------------------------------------------------------------- 1 | /* ttykickout.c - ttykickout */ 2 | 3 | #include 4 | 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * ttykickout - "Kick" the hardware for a tty device, causing it to 9 | * generate an output interrupt (interrupts disabled) 10 | *------------------------------------------------------------------------ 11 | */ 12 | void ttykickout( 13 | struct uart_csreg *csrptr /* Address of UART's CSRs */ 14 | ) 15 | { 16 | /* Force the UART hardware generate an output interrupt */ 17 | 18 | cli(); 19 | ttyhandler(1, 'X', 1); /* 1, 'X' arguments useless */ 20 | sei(); 21 | 22 | return; 23 | } 24 | -------------------------------------------------------------------------------- /include/mark.h: -------------------------------------------------------------------------------- 1 | /* mark.h - notmarked */ 2 | 3 | /* avr specific values. Original saved under orig/ folder */ 4 | 5 | #define MAXMARK 10 /* Maximum number of marked locations */ 6 | 7 | extern int32 *(marks[]); 8 | extern int32 nmarks; 9 | extern sid32 mkmutex; 10 | typedef int32 memmark[1]; /* Declare a memory mark to be an array */ 11 | /* so user can reference the name */ 12 | /* without a leading & */ 13 | 14 | /*------------------------------------------------------------------------ 15 | * notmarked - Return nonzero if a location has not been marked 16 | *------------------------------------------------------------------------ 17 | */ 18 | #define notmarked(L) (L[0]<0 || L[0]>=nmarks || marks[L[0]]!=L) 19 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_read.c: -------------------------------------------------------------------------------- 1 | /* ramread.c - ramread */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * eeprom_read - Read a block from a eeprom disk 8 | *------------------------------------------------------------------------ 9 | */ 10 | devcall eeprom_read ( 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *buff, /* Buffer to hold disk block */ 13 | uint32 count /* Count of the bytes to read */ 14 | ) 15 | { 16 | if ((eeprom_pos + count) >= EEPROM_SIZE) 17 | return SYSERR; 18 | 19 | eeprom_read_block((void *)buff, (const void*)eeprom_pos, count); 20 | return OK; 21 | } 22 | -------------------------------------------------------------------------------- /system/getdev.c: -------------------------------------------------------------------------------- 1 | /* getdev.c - getdev */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * getdev - Convert a device name to a device ID 8 | *------------------------------------------------------------------------ 9 | */ 10 | did32 getdev( 11 | char *devname /* Name of the device */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | did32 id; /* Value to return to caller */ 16 | 17 | mask = disable(); 18 | for (id = 0; id < NDEVS; id++) { 19 | if (strncmp(devname, devtab[id].dvname, DEVNAMLEN)) { 20 | restore(mask); 21 | return id; 22 | } 23 | } 24 | restore(mask); 25 | return (did32) SYSERR; 26 | } 27 | -------------------------------------------------------------------------------- /system/gettime.c: -------------------------------------------------------------------------------- 1 | /* gettime.c - gettime */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * gettime - Get xinu time in seconds past Jan 1, 1970 7 | *------------------------------------------------------------------------ 8 | */ 9 | status gettime( 10 | uint32 *timvar /* Location to store the result */ 11 | ) 12 | { 13 | uint32 now; /* Current time (UCT) */ 14 | int32 retval; /* Return value from call */ 15 | 16 | /* Get current time in UCT representation (GMT) */ 17 | 18 | // retval = getutime(&now); 19 | if (retval == SYSERR) { 20 | return SYSERR; 21 | } 22 | 23 | /* Adjust to xinu time and store result */ 24 | 25 | *timvar = utim2ltim(now); 26 | return OK; 27 | } 28 | -------------------------------------------------------------------------------- /system/ready.c: -------------------------------------------------------------------------------- 1 | /* ready.c - ready */ 2 | 3 | #include 4 | 5 | qid16 readylist; /* Index of ready list */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * ready - Make a process eligible for CPU service 9 | *------------------------------------------------------------------------ 10 | */ 11 | status ready( 12 | pid32 pid /* ID of process to make ready */ 13 | ) 14 | { 15 | register struct procent *prptr; 16 | 17 | if (isbadpid(pid)) { 18 | return SYSERR; 19 | } 20 | 21 | /* Set process state to indicate ready and add to ready list */ 22 | 23 | prptr = &proctab[pid]; 24 | prptr->prstate = PR_READY; 25 | insert(pid, readylist, prptr->prprio); 26 | resched(); 27 | 28 | return OK; 29 | } 30 | -------------------------------------------------------------------------------- /system/platinit.c: -------------------------------------------------------------------------------- 1 | /* platinit.c - platinit */ 2 | 3 | /* avr specific */ 4 | 5 | 6 | #include 7 | 8 | /* avr specific */ 9 | #include 10 | #include 11 | 12 | 13 | /*------------------------------------------------------------------------ 14 | * platinit - platform specific initialization 15 | *------------------------------------------------------------------------ 16 | */ 17 | 18 | void platinit(void) 19 | { 20 | 21 | /* avr specific */ 22 | cli(); /* AVR disable interrups */ 23 | 24 | blink_avr(); 25 | blink_avr(); 26 | 27 | /* avr uart init */ 28 | serial_init(); 29 | 30 | /* Initialize the Interrupt Controller (evec.c) */ 31 | initintc(); 32 | 33 | /* System calls */ 34 | // syscall_init(); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /device/lfs/lfibclear.c: -------------------------------------------------------------------------------- 1 | /* lfibclear.c - lfibclear */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfibclear -- Clear an in-core copy of an index block 7 | *------------------------------------------------------------------------ 8 | */ 9 | void lfibclear( 10 | struct lfiblk *ibptr, /* Address of i-block in memory */ 11 | int32 offset /* File offset for this i-block */ 12 | ) 13 | { 14 | int32 i; /* Index for data block array */ 15 | 16 | ibptr->ib_offset = offset; /* Assign specified file offset */ 17 | for (i=0 ; iib_dba[i] = LF_DNULL; 19 | } 20 | ibptr->ib_next = LF_INULL; /* Set next ptr to null */ 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /system/recvclr.c: -------------------------------------------------------------------------------- 1 | /* recvclr.c - recvclr */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * recvclr - Clear incoming message, and return message if one waiting 7 | *------------------------------------------------------------------------ 8 | */ 9 | umsg32 recvclr(void) 10 | { 11 | intmask mask; /* Saved interrupt mask */ 12 | struct procent *prptr; /* Ptr to process's table entry */ 13 | umsg32 msg; /* Message to return */ 14 | 15 | mask = disable(); 16 | prptr = &proctab[currpid]; 17 | if (prptr->prhasmsg == TRUE) { 18 | msg = prptr->prmsg; /* Retrieve message */ 19 | prptr->prhasmsg = FALSE;/* Reset message flag */ 20 | } else { 21 | msg = OK; 22 | } 23 | restore(mask); 24 | return msg; 25 | } 26 | -------------------------------------------------------------------------------- /system/semcount.c: -------------------------------------------------------------------------------- 1 | /* semcount.c - semcount */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * semcount - Return the count of a semaphore (because any integer is 7 | * possible, return of SYSERR may be ambiguous) 8 | *------------------------------------------------------------------------ 9 | */ 10 | syscall semcount( 11 | sid32 semid /* ID of semaphore to use */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | int32 count; /* Current sempahore count */ 16 | 17 | mask = disable(); 18 | 19 | if (isbadsem(semid) || semtab[semid].sstate == S_FREE) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | count = semtab[semid].scount; 24 | restore(mask); 25 | return count; 26 | } 27 | -------------------------------------------------------------------------------- /device/avr_eeprom/eeprom_write.c: -------------------------------------------------------------------------------- 1 | /* ramwrite.c - ramwrite */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * eeprom_write - Write a block to a eeprom disk 8 | *------------------------------------------------------------------------ 9 | */ 10 | devcall eeprom_write ( 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *buff, /* Buffer containing a block */ 13 | uint32 count /* Count of bytes to write */ 14 | ) 15 | { 16 | 17 | if (eeprom_pos + count >= EEPROM_SIZE) 18 | return SYSERR; 19 | 20 | eeprom_write_block((void *)buff, (const void *)eeprom_pos, count); 21 | 22 | eeprom_pos = eeprom_pos + count; 23 | 24 | return OK; 25 | } 26 | -------------------------------------------------------------------------------- /include/avr_messages.h: -------------------------------------------------------------------------------- 1 | /* avr specific */ 2 | 3 | typedef unsigned int size_t; 4 | #include 5 | 6 | // extern const char CONSOLE_RESET[]; 7 | // extern const char m0[]; 8 | extern const char sysinit_m0[]; 9 | extern const char sysinit_m1[]; 10 | extern const char sysinit_m2[]; 11 | extern const char sysinit_m3[]; 12 | extern const char m00[]; 13 | extern const char m000[]; 14 | extern const char m1[]; 15 | extern const char m2[]; 16 | extern const char m3[]; 17 | extern const char m4[]; 18 | extern const char m5[]; 19 | extern const char m6[]; 20 | extern const char m7[]; 21 | extern const char m8[]; 22 | extern const char m9[]; 23 | extern const char m10[]; 24 | extern const char m11[]; 25 | extern const char m12[]; 26 | extern const char m13[]; 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /apps/example3/main.c: -------------------------------------------------------------------------------- 1 | /* ex3.c - main, sndch */ 2 | 3 | #include 4 | 5 | void sndch(char); 6 | 7 | /*------------------------------------------------------------------------ 8 | * main -- example of 2 processes executing the same code concurrently 9 | *------------------------------------------------------------------------ 10 | */ 11 | void main(void) 12 | { 13 | resume( create(sndch, 1024, 20, "send A", 1, 'A') ); 14 | resume( create(sndch, 1024, 20, "send B", 1, 'B') ); 15 | } 16 | 17 | /*------------------------------------------------------------------------ 18 | * sndch -- output a character on a serial device indefinitely 19 | *------------------------------------------------------------------------ 20 | */ 21 | void sndch(char ch) 22 | 23 | { 24 | 25 | while ( 1 ) 26 | putc(CONSOLE, ch); 27 | } 28 | -------------------------------------------------------------------------------- /system/seek.c: -------------------------------------------------------------------------------- 1 | /* seek.c - seek */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * seek - Position a random access device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall seek( 10 | did32 descrp, /* Descriptor for device */ 11 | uint32 pos /* Position */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | const __flash struct dentry *devptr; /* Entry in device switch table */ 16 | int32 retval; /* Value to return to caller */ 17 | 18 | mask = disable(); 19 | if (isbaddev(descrp)) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | devptr = (struct dentry *) &devtab[descrp]; 24 | retval = (*devptr->dvseek) (devptr, pos); 25 | restore(mask); 26 | return retval; 27 | } 28 | -------------------------------------------------------------------------------- /device/lfs/lfdbfree.c: -------------------------------------------------------------------------------- 1 | /* lfdbfree.c - lfdbfree */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfdbfree - Free a data block given its block number (assumes 7 | * directory mutex is held) 8 | *------------------------------------------------------------------------ 9 | */ 10 | status lfdbfree( 11 | did32 diskdev, /* ID of disk device to use */ 12 | dbid32 dnum /* ID of data block to free */ 13 | ) 14 | { 15 | struct lfdir *dirptr; /* Pointer to directory */ 16 | struct lfdbfree buf; /* Buffer to hold data block */ 17 | 18 | dirptr = &Lf_data.lf_dir; 19 | buf.lf_nextdb = dirptr->lfd_dfree; 20 | dirptr->lfd_dfree = dnum; 21 | write(diskdev, (char *)&buf, dnum); 22 | write(diskdev, (char *)dirptr, LF_AREA_DIR); 23 | 24 | return OK; 25 | } 26 | -------------------------------------------------------------------------------- /device/lfs/lflwrite.c: -------------------------------------------------------------------------------- 1 | /* lflwrite.c - lflwrite */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflwrite -- Write data to a previously opened local disk file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflwrite ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | char *buff, /* Buffer holding data to write */ 12 | int32 count /* Number of bytes to write */ 13 | ) 14 | { 15 | int32 i; /* Number of bytes written */ 16 | 17 | if (count < 0) { 18 | return SYSERR; 19 | } 20 | 21 | /* Iteratate and write one byte at a time */ 22 | 23 | for (i=0; i 4 | 5 | /*------------------------------------------------------------------------ 6 | * chprio - Change the scheduling priority of a process 7 | *------------------------------------------------------------------------ 8 | */ 9 | pri16 chprio( 10 | pid32 pid, /* ID of process to change */ 11 | pri16 newprio /* New priority */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | struct procent *prptr; /* Ptr to process's table entry */ 16 | pri16 oldprio; /* Priority to return */ 17 | 18 | mask = disable(); 19 | if (isbadpid(pid)) { 20 | restore(mask); 21 | return (pri16) SYSERR; 22 | } 23 | prptr = &proctab[pid]; 24 | oldprio = prptr->prprio; 25 | prptr->prprio = newprio; 26 | restore(mask); 27 | return oldprio; 28 | } 29 | -------------------------------------------------------------------------------- /system/close.c: -------------------------------------------------------------------------------- 1 | /* close.c - close */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * close - Close a device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall close( 10 | did32 descrp /* Descriptor for device */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | // struct dentry *devptr; /* Entry in device switch table */ 15 | const __flash struct dentry *devptr; /* Entry in device switch table */ 16 | int32 retval; /* Value to return to caller */ 17 | 18 | mask = disable(); 19 | if (isbaddev(descrp)) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | devptr = (struct dentry *) &devtab[descrp]; 24 | retval = (*devptr->dvclose) (devptr); 25 | restore(mask); 26 | return retval; 27 | } 28 | -------------------------------------------------------------------------------- /system/receive.c: -------------------------------------------------------------------------------- 1 | /* receive.c - receive */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * receive - Wait for a message and return the message to the caller 7 | *------------------------------------------------------------------------ 8 | */ 9 | umsg32 receive(void) 10 | { 11 | intmask mask; /* Saved interrupt mask */ 12 | struct procent *prptr; /* Ptr to process's table entry */ 13 | umsg32 msg; /* Message to return */ 14 | 15 | mask = disable(); 16 | prptr = &proctab[currpid]; 17 | if (prptr->prhasmsg == FALSE) { 18 | prptr->prstate = PR_RECV; 19 | resched(); /* Block until message arrives */ 20 | } 21 | msg = prptr->prmsg; /* Retrieve message */ 22 | prptr->prhasmsg = FALSE; /* Reset message flag */ 23 | restore(mask); 24 | return msg; 25 | } 26 | -------------------------------------------------------------------------------- /system/putc.c: -------------------------------------------------------------------------------- 1 | /* putc.c - putc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * putc - Send one character of data (byte) to a device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall putc( 10 | did32 descrp, /* Descriptor for device */ 11 | char ch /* Character to send */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | const __flash struct dentry *devptr; /* Entry in device switch table */ 16 | int32 retval; /* Value to return to caller */ 17 | 18 | mask = disable(); 19 | if (isbaddev(descrp)) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | devptr = (struct dentry *) &devtab[descrp]; 24 | retval = (*devptr->dvputc) (devptr, ch); 25 | restore(mask); 26 | return retval; 27 | } 28 | -------------------------------------------------------------------------------- /system/getc.c: -------------------------------------------------------------------------------- 1 | /* getc.c - getc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getc - Obtain one byte from a device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall getc( 10 | did32 descrp /* Descriptor for device */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | // struct dentry *devptr; /* Entry in device switch table */ 15 | const __flash struct dentry *devptr; /* Entry in device switch table */ 16 | int32 retval; /* Value to return to caller */ 17 | 18 | mask = disable(); 19 | if (isbaddev(descrp)) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | devptr = (struct dentry *) &devtab[descrp]; 24 | retval = (*devptr->dvgetc) (devptr); 25 | restore(mask); 26 | return retval; 27 | } 28 | -------------------------------------------------------------------------------- /device/rfs/rflclose.c: -------------------------------------------------------------------------------- 1 | /* rflclose.c - rflclose */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rflclose - Close a remote file device 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall rflclose ( 10 | struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | struct rflcblk *rfptr; /* Pointer to control block */ 14 | 15 | /* Wait for exclusive access */ 16 | 17 | wait(Rf_data.rf_mutex); 18 | 19 | /* Verify remote file device is open */ 20 | 21 | rfptr = &rfltab[devptr->dvminor]; 22 | if (rfptr->rfstate == RF_FREE) { 23 | signal(Rf_data.rf_mutex); 24 | return SYSERR; 25 | } 26 | 27 | /* Mark device closed */ 28 | 29 | rfptr->rfstate = RF_FREE; 30 | signal(Rf_data.rf_mutex); 31 | return OK; 32 | } 33 | -------------------------------------------------------------------------------- /system/init.c: -------------------------------------------------------------------------------- 1 | /* init.c - init */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * init - Initialize a device and its driver 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall init( 10 | did32 descrp /* Descriptor for device */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | // struct dentry *devptr; /* Entry in device switch table */ 15 | const __flash struct dentry *devptr; /* Entry in device switch table */ 16 | int32 retval; /* Value to return to caller */ 17 | 18 | mask = disable(); 19 | if (isbaddev(descrp)) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | devptr = (struct dentry *) &devtab[descrp]; 24 | retval = (*devptr->dvinit) (devptr); 25 | restore(mask); 26 | return retval; 27 | } 28 | -------------------------------------------------------------------------------- /include/file.h: -------------------------------------------------------------------------------- 1 | /* file.h - definitions commmon to remote and local file systems */ 2 | 3 | /* Definition of file mode bits */ 4 | 5 | #define F_MODE_R 0x01 /* Bit to grant read access */ 6 | #define F_MODE_W 0x02 /* Bit to grant write access */ 7 | #define F_MODE_RW 0x03 /* Mask for read and write bits */ 8 | #define F_MODE_N 0x04 /* Bit for "new" mode */ 9 | #define F_MODE_O 0x08 /* Bit for "old" mode */ 10 | /* Note: new and old mode bits */ 11 | /* are mutually exclusive */ 12 | #define F_MODE_NO 0x0C /* Mask for "n" and "o" bits */ 13 | 14 | /* Control functions for files */ 15 | 16 | #define F_CTL_DEL 1 /* Delete a file */ 17 | #define F_CTL_TRUNC 2 /* Truncate a file */ 18 | #define F_CTL_MKDIR 3 /* make a directory */ 19 | #define F_CTL_RMDIR 4 /* remove a directory */ 20 | #define F_CTL_SIZE 5 /* Obtain the size of a file */ 21 | -------------------------------------------------------------------------------- /lib/printf.c: -------------------------------------------------------------------------------- 1 | /* printf.c - printf*/ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | extern void _fdoprnt(char *, va_list, int (*)(did32, char), int); 8 | extern int xinu_putc(did32, char); 9 | 10 | /*------------------------------------------------------------------------ 11 | * printf - standard C printf function 12 | *------------------------------------------------------------------------ 13 | */ 14 | 15 | #define PRINTF_BUF 81 16 | 17 | int printf( 18 | const char *fmt, 19 | ... 20 | ) 21 | { 22 | 23 | char *c; 24 | char buf[PRINTF_BUF]; 25 | va_list ap; 26 | 27 | va_start(ap, fmt); 28 | vsnprintf(buf, sizeof(buf), fmt, ap); 29 | 30 | c = buf; 31 | while(*c) { 32 | if(*c == '\n') 33 | putc(stdout, '\r'); 34 | putc(stdout, *c); 35 | c++; 36 | }; 37 | 38 | va_end(ap); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /device/rfs/rflinit.c: -------------------------------------------------------------------------------- 1 | /* rflinit.c - rflinit */ 2 | 3 | #include 4 | 5 | struct rflcblk rfltab[Nrfl]; /* Remote file control blocks */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * rflinit - Initialize a remote file device 9 | *------------------------------------------------------------------------ 10 | */ 11 | devcall rflinit( 12 | struct dentry *devptr /* Entry in device switch table */ 13 | ) 14 | { 15 | struct rflcblk *rflptr; /* Ptr. to control block entry */ 16 | int32 i; /* Walks through name arrary */ 17 | 18 | rflptr = &rfltab[ devptr->dvminor ]; 19 | 20 | /* Initialize entry to unused */ 21 | 22 | rflptr->rfstate = RF_FREE; 23 | rflptr->rfdev = devptr->dvnum; 24 | for (i=0; irfname[i] = NULLCH; 26 | } 27 | rflptr->rfpos = rflptr->rfmode = 0; 28 | return OK; 29 | } 30 | -------------------------------------------------------------------------------- /include/interrupt.h: -------------------------------------------------------------------------------- 1 | /* interrupt.h */ 2 | 3 | struct scb_csreg { 4 | volatile uint32 cpuid; 5 | volatile uint32 icsr; 6 | volatile uint32 vtor; 7 | volatile uint32 aircr; 8 | volatile uint32 scr; 9 | volatile uint32 ccr; 10 | volatile uint32 shpr1; 11 | volatile uint32 shpr2; 12 | volatile uint32 shpr3; 13 | volatile uint32 shcsr; 14 | volatile uint32 cfcsr; 15 | volatile uint32 hfsr; 16 | volatile uint32 mmar; 17 | volatile uint32 bfar; 18 | }; 19 | 20 | /* System control block base */ 21 | #define SCB_BASE 0xE000ED00 22 | 23 | /* Faults enable */ 24 | #define MPUFAULT_EN 16 25 | #define BUSFAULT_EN 17 26 | #define USAGEFAULT_EN 18 27 | 28 | /* Exception vector */ 29 | #define MEMFAULT_ENTRY 4 30 | #define BUSFAULT_ENTRY 5 31 | #define USAGEFAULT_ENTRY 6 32 | #define SVC_ENTRY 11 33 | #define PENDSV_ENTRY 14 34 | #define SYSTICK_ENTRY 15 35 | -------------------------------------------------------------------------------- /system/evec.c: -------------------------------------------------------------------------------- 1 | /* evec.c -- initintc, set_evec */ 2 | 3 | typedef unsigned int size_t; 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | /*------------------------------------------------------------------------ 11 | * initintc - Initialize the Interrupt Controller 12 | *------------------------------------------------------------------------ 13 | */ 14 | int32 initintc() 15 | { 16 | return OK; 17 | } 18 | 19 | /*------------------------------------------------------------------------ 20 | * set_evec - set exception vector to point to an exception handler 21 | *------------------------------------------------------------------------ 22 | */ 23 | int32 set_evec(uint32 xnum, uint32 handler) 24 | { 25 | /* There are only 92 interrupts allowed 0-2 */ 26 | 27 | if(xnum > 92) { 28 | return SYSERR; 29 | } 30 | 31 | return OK; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /system/signal.c: -------------------------------------------------------------------------------- 1 | /* signal.c - signal */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * signal - Signal a semaphore, releasing a process if one is waiting 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall signal( 10 | sid32 sem /* ID of semaphore to signal */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct sentry *semptr; /* Ptr to sempahore table entry */ 15 | 16 | mask = disable(); 17 | if (isbadsem(sem)) { 18 | restore(mask); 19 | return SYSERR; 20 | } 21 | semptr= &semtab[sem]; 22 | if (semptr->sstate == S_FREE) { 23 | restore(mask); 24 | return SYSERR; 25 | } 26 | if ((semptr->scount++) < 0) { /* Release a waiting process */ 27 | ready(dequeue(semptr->squeue)); 28 | } 29 | restore(mask); 30 | return OK; 31 | } 32 | -------------------------------------------------------------------------------- /config/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Make the Xinu configuration program 3 | # 4 | 5 | COMPILER_ROOT = /usr/bin/ 6 | 7 | CC = ${COMPILER_ROOT}gcc 8 | LEX = ${COMPILER_ROOT}flex 9 | YACC = ${COMPILER_ROOT}bison -y # Flag enables yacc-compatible filenames 10 | CFLAGS = 11 | LFLAGS = -lfl 12 | 13 | # 14 | # Name of the configuration program 15 | # 16 | 17 | CONFIG = config 18 | 19 | all: conf.h conf.c 20 | 21 | ${CONFIG}: lex.yy.c y.tab.c 22 | $(CC) ${CFLAGS} -o $@ y.tab.c ${LFLAGS} 23 | 24 | lex.yy.c: config.l 25 | $(LEX) config.l 26 | 27 | y.tab.c: config.y 28 | $(YACC) config.y 29 | 30 | clean: 31 | rm -f config lex.yy.c y.tab.c 32 | 33 | conf.h: config Configuration 34 | ./config Configuration conf.c conf.h 35 | 36 | conf.c: config Configuration 37 | ./config Configuration conf.c conf.h 38 | 39 | install: conf.h conf.c 40 | cp -p conf.h ../include 41 | cp -p conf.c ../system 42 | -------------------------------------------------------------------------------- /system/resume.c: -------------------------------------------------------------------------------- 1 | /* resume.c - resume */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * resume - Unsuspend a process, making it ready 7 | *------------------------------------------------------------------------ 8 | */ 9 | pri16 resume( 10 | pid32 pid /* ID of process to unsuspend */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct procent *prptr; /* Ptr to process's table entry */ 15 | pri16 prio; /* Priority to return */ 16 | 17 | mask = disable(); 18 | if (isbadpid(pid)) { 19 | restore(mask); 20 | return (pri16)SYSERR; 21 | } 22 | prptr = &proctab[pid]; 23 | if (prptr->prstate != PR_SUSP) { 24 | restore(mask); 25 | return (pri16)SYSERR; 26 | } 27 | prio = prptr->prprio; /* Record priority to return */ 28 | ready(pid); 29 | restore(mask); 30 | return prio; 31 | } 32 | -------------------------------------------------------------------------------- /apps/example0/main.c: -------------------------------------------------------------------------------- 1 | /* main.c - main */ 2 | 3 | /* Basic Xinu app for quick start */ 4 | 5 | #include 6 | 7 | 8 | process example0(int nargs, char *args[]) 9 | { 10 | printf(" nargs = %d\n", nargs); 11 | printf(" args[0]: %d\n", args[0]); 12 | printf(" args[1]: %s\n", args[1]); 13 | 14 | return OK; 15 | } 16 | 17 | process main(void) 18 | { 19 | /* We create() a new process. Arguments: 20 | * process code: example0() 21 | * stack size: 128 bytes 22 | * priority: 50 23 | * name: "ex0" 24 | * arguments: 2 25 | * first argument: 3 (int) 26 | * second argument: "hello world" 27 | */ 28 | 29 | resume(create(example0, 128, 50, "ex_0", 2, 3, "hello world")); 30 | 31 | /* Wait for example0 to exit */ 32 | 33 | receive(); 34 | printf("\n %s process has completed.\n", proctab[currpid].prname); 35 | 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /system/read.c: -------------------------------------------------------------------------------- 1 | /* read.c - read */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * read - Read one or more bytes from a device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall read( 10 | did32 descrp, /* Descriptor for device */ 11 | char *buffer, /* Address of buffer */ 12 | uint32 count /* Length of buffer */ 13 | ) 14 | { 15 | intmask mask; /* Saved interrupt mask */ 16 | const __flash struct dentry *devptr; /* Entry in device switch table */ 17 | int32 retval; /* Value to return to caller */ 18 | 19 | mask = disable(); 20 | if (isbaddev(descrp)) { 21 | restore(mask); 22 | return SYSERR; 23 | } 24 | devptr = (struct dentry *) &devtab[descrp]; 25 | retval = (*devptr->dvread) (devptr, buffer, count); 26 | restore(mask); 27 | return retval; 28 | } 29 | -------------------------------------------------------------------------------- /device/rfs/rflseek.c: -------------------------------------------------------------------------------- 1 | /* rflseek.c - rflseek */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rflseek - Change the current position in an open file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall rflseek ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | uint32 pos /* New file position */ 12 | ) 13 | { 14 | struct rflcblk *rfptr; /* Pointer to control block */ 15 | 16 | /* Wait for exclusive access */ 17 | 18 | wait(Rf_data.rf_mutex); 19 | 20 | /* Verify remote file device is open */ 21 | 22 | rfptr = &rfltab[devptr->dvminor]; 23 | if (rfptr->rfstate == RF_FREE) { 24 | signal(Rf_data.rf_mutex); 25 | return SYSERR; 26 | } 27 | 28 | /* Set the new position */ 29 | 30 | rfptr->rfpos = pos; 31 | signal(Rf_data.rf_mutex); 32 | return OK; 33 | } 34 | -------------------------------------------------------------------------------- /system/write.c: -------------------------------------------------------------------------------- 1 | /* write.c - write */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * write - Write one or more bytes to a device 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall write( 10 | did32 descrp, /* Descriptor for device */ 11 | char *buffer, /* Address of buffer */ 12 | uint32 count /* Length of buffer */ 13 | ) 14 | { 15 | intmask mask; /* Saved interrupt mask */ 16 | const __flash struct dentry *devptr; /* Entry in device switch table */ 17 | int32 retval; /* Value to return to caller */ 18 | 19 | mask = disable(); 20 | if (isbaddev(descrp)) { 21 | restore(mask); 22 | return SYSERR; 23 | } 24 | devptr = (struct dentry *) &devtab[descrp]; 25 | retval = (*devptr->dvwrite) (devptr, buffer, count); 26 | restore(mask); 27 | return retval; 28 | } 29 | -------------------------------------------------------------------------------- /device/tty/ttywrite.c: -------------------------------------------------------------------------------- 1 | /* ttywrite.c - ttywrite */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttywrite - Write character(s) to a tty device (interrupts disabled) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ttywrite( 10 | // struct dentry *devptr, /* Entry in device switch table */ 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *buff, /* Buffer of characters */ 13 | int32 count /* Count of character to write */ 14 | ) 15 | { 16 | /* Handle negative and zero counts */ 17 | 18 | if (count < 0) { 19 | return SYSERR; 20 | } else if (count == 0){ 21 | return OK; 22 | } 23 | 24 | /* Write count characters one at a time */ 25 | 26 | for (; count>0 ; count--) { 27 | ttyputc(devptr, *buff++); 28 | } 29 | return OK; 30 | } 31 | -------------------------------------------------------------------------------- /device/lfs/lfsinit.c: -------------------------------------------------------------------------------- 1 | /* lfsinit.c - lfsinit */ 2 | 3 | #include 4 | 5 | struct lfdata Lf_data; 6 | 7 | /*------------------------------------------------------------------------ 8 | * lfsinit - Initialize the local file system master device 9 | *------------------------------------------------------------------------ 10 | */ 11 | devcall lfsinit ( 12 | struct dentry *devptr /* Entry in device switch table */ 13 | ) 14 | { 15 | /* Assign ID of disk device that will be used */ 16 | 17 | Lf_data.lf_dskdev = LF_DISK_DEV; 18 | 19 | /* Create a mutual exclusion semaphore */ 20 | 21 | Lf_data.lf_mutex = semcreate(1); 22 | 23 | /* Zero directory area (for debugging) */ 24 | 25 | memset((char *)&Lf_data.lf_dir, NULLCH, sizeof(struct lfdir)); 26 | 27 | /* Initialize directory to "not present" in memory */ 28 | 29 | Lf_data.lf_dirpresent = Lf_data.lf_dirdirty = FALSE; 30 | 31 | return OK; 32 | } 33 | -------------------------------------------------------------------------------- /system/open.c: -------------------------------------------------------------------------------- 1 | /* open.c - open */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * open - Open a device (some devices ignore name and mode parameters) 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall open( 10 | did32 descrp, /* Descriptor for device */ 11 | char *name, /* Name to use, if any */ 12 | char *mode /* Mode for device, if any */ 13 | ) 14 | { 15 | intmask mask; /* Saved interrupt mask */ 16 | const __flash struct dentry *devptr; /* Entry in device switch table */ 17 | int32 retval; /* Value to return to caller */ 18 | 19 | mask = disable(); 20 | if (isbaddev(descrp)) { 21 | restore(mask); 22 | return SYSERR; 23 | } 24 | devptr = (struct dentry *) &devtab[descrp]; 25 | retval = (*devptr->dvopen) (devptr, name, mode); 26 | restore(mask); 27 | return retval; 28 | } 29 | -------------------------------------------------------------------------------- /lib/userland.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __attribute__((naked)) 4 | uint32 xinu_syscall(int nr, uint32 arg1, uint32 arg2, uint32 arg3) 5 | { 6 | /* 7 | asm volatile("push {r0-r11}"); 8 | asm volatile("push {lr}"); 9 | asm volatile("svc 1"); /* Hack: For all service call use 1, arg1 got number */ 10 | /* 11 | asm volatile("pop {lr}"); 12 | asm volatile("pop {r0-r11}"); 13 | asm volatile("bx lr"); 14 | */ 15 | 16 | } 17 | 18 | 19 | 20 | //void xinu_open(did32 descrp, char * name, char * mode) { 21 | // 22 | // xinu_syscall(XINU_OPEN, descrp, name, mode); 23 | //} 24 | 25 | int xinu_uptime() { 26 | 27 | return xinu_syscall(XINU_UPTIME, 0, 0, 0); 28 | } 29 | 30 | int xinu_putc(int dev, char c) { 31 | 32 | return xinu_syscall(XINU_PUTC, dev, c, 0 ); 33 | //return xinu_syscall(XINU_PUTC, dev, c, 0); 34 | } 35 | 36 | 37 | //int xinu_close(dev); 38 | //int xinu_putc(dev); 39 | // 40 | //int xinu_yield(); 41 | //int xinu_receive(); 42 | // 43 | //int xinu_gettime(); 44 | -------------------------------------------------------------------------------- /device/nam/namopen.c: -------------------------------------------------------------------------------- 1 | /* namopen.c - namopen */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * namopen - Open a file or device based on the name 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall namopen( 10 | // struct dentry *devptr, /* Entry in device switch table */ 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *name, /* Name to open */ 13 | char *mode /* Mode argument */ 14 | ) 15 | { 16 | char newname[NM_MAXLEN]; /* Name with prefix replaced */ 17 | did32 newdev; /* Device ID after mapping */ 18 | 19 | /* Use namespace to map name to a new name and new descriptor */ 20 | 21 | newdev = nammap(name, newname, devptr->dvnum); 22 | 23 | if (newdev == SYSERR) { 24 | return SYSERR; 25 | } 26 | 27 | /* Open underlying device and return status */ 28 | 29 | return open(newdev, newname, mode); 30 | } 31 | -------------------------------------------------------------------------------- /device/eth/ethcontrol.c: -------------------------------------------------------------------------------- 1 | /* ethcontrol.c - ethcontrol */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ethcontrol - implement control function for a quark ethernet device 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ethcontrol ( 10 | struct dentry *devptr, /* entry in device switch table */ 11 | int32 func, /* control function */ 12 | int32 arg1, /* argument 1, if needed */ 13 | int32 arg2 /* argument 2, if needed */ 14 | ) 15 | { 16 | struct ethcblk *ethptr; /* Ethertab entry pointer */ 17 | int32 retval = OK; /* Return value of cntl function*/ 18 | 19 | ethptr = ðertab[devptr->dvminor]; 20 | 21 | switch (func) { 22 | 23 | /* Get MAC address */ 24 | 25 | case ETH_CTRL_GET_MAC: 26 | memcpy((byte *)arg1, ethptr->devAddress, 27 | ETH_ADDR_LEN); 28 | break; 29 | 30 | default: 31 | return SYSERR; 32 | } 33 | 34 | return retval; 35 | } 36 | -------------------------------------------------------------------------------- /device/tty/ttyhandler.c: -------------------------------------------------------------------------------- 1 | /* ttyhandler.c - ttyhandler */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttyhandler - Handle an interrupt for a tty (serial) device 7 | *------------------------------------------------------------------------ 8 | */ 9 | void ttyhandler(uint32 xnum, char c, int flag) { 10 | const __flash struct dentry *devptr; /* Address of device control blk*/ 11 | struct ttycblk *typtr; /* Pointer to ttytab entry */ 12 | struct uart_csreg *csrptr; /* Address of UART's CSR */ 13 | 14 | /* Get CSR address of the device (assume console for now) */ 15 | 16 | devptr = (struct dentry *) &devtab[CONSOLE]; 17 | 18 | /* Obtain a pointer to the tty control block */ 19 | 20 | typtr = &ttytab[devptr->dvminor]; 21 | 22 | /* Test type of UART interrupt */ 23 | 24 | /* AVR */ 25 | 26 | if (flag) /* TX */ 27 | ttyhandle_out(typtr, csrptr); 28 | else /* RX */ 29 | ttyhandle_in(typtr, csrptr, c); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /system/newqueue.c: -------------------------------------------------------------------------------- 1 | /* newqueue.c - newqueue */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * newqueue - Allocate and initialize a queue in the global queue table 7 | *------------------------------------------------------------------------ 8 | */ 9 | qid16 newqueue(void) 10 | { 11 | static qid16 nextqid=NPROC; /* Next list in queuetab to use */ 12 | qid16 q; /* ID of allocated queue */ 13 | 14 | q = nextqid; 15 | if (q >= NQENT) { /* Check for table overflow */ 16 | return SYSERR; 17 | } 18 | 19 | nextqid += 2; /* Increment index for next call*/ 20 | 21 | /* Initialize head and tail nodes to form an empty queue */ 22 | 23 | queuetab[queuehead(q)].qnext = queuetail(q); 24 | queuetab[queuehead(q)].qprev = EMPTY; 25 | queuetab[queuehead(q)].qkey = MAXKEY; 26 | queuetab[queuetail(q)].qnext = EMPTY; 27 | queuetab[queuetail(q)].qprev = queuehead(q); 28 | queuetab[queuetail(q)].qkey = MINKEY; 29 | return q; 30 | } 31 | -------------------------------------------------------------------------------- /system/semdelete.c: -------------------------------------------------------------------------------- 1 | /* semdelete.c - semdelete */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * semdelete - Delete a semaphore by releasing its table entry 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall semdelete( 10 | sid32 sem /* ID of semaphore to delete */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct sentry *semptr; /* Ptr to semaphore table entry */ 15 | 16 | mask = disable(); 17 | if (isbadsem(sem)) { 18 | restore(mask); 19 | return SYSERR; 20 | } 21 | 22 | semptr = &semtab[sem]; 23 | if (semptr->sstate == S_FREE) { 24 | restore(mask); 25 | return SYSERR; 26 | } 27 | semptr->sstate = S_FREE; 28 | 29 | resched_cntl(DEFER_START); 30 | while (semptr->scount++ < 0) { /* Free all waiting processes */ 31 | ready(getfirst(semptr->squeue)); 32 | } 33 | resched_cntl(DEFER_STOP); 34 | restore(mask); 35 | return OK; 36 | } 37 | -------------------------------------------------------------------------------- /main/xsh_gpio.c: -------------------------------------------------------------------------------- 1 | /* xsh_gpio.c - xsh_gpio */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_gpio - write a value v in port p 8 | *------------------------------------------------------------------------ 9 | * 10 | * Two modes: 11 | * Normal mode. Example: gpio b 32 # arduino pin 13 high 12 | * Extra Arduino mode. Example: gpio 13 1 # arduino pin 13 high 13 | */ 14 | shellcmd xsh_gpio(int nargs, char *args[]) 15 | { 16 | char p; 17 | unsigned char v; 18 | 19 | char pin; 20 | unsigned char val; 21 | 22 | 23 | /* Normal mode. Example: gpio b 32 # arduino pin 13 high */ 24 | 25 | p = *args[1]; 26 | v = number(args[2]); 27 | 28 | if ((p == 'b') | (p == 'c') | (p == 'd')) { 29 | gpio_write(p, v); 30 | return 0; 31 | } 32 | 33 | /* Extra arduino mode. Example: gpio 13 1 # arduino pin 13 high */ 34 | 35 | pin = number(args[1]); 36 | gpio_arduino_write(pin, v); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /apps/shell/xsh_gpio.c: -------------------------------------------------------------------------------- 1 | /* xsh_gpio.c - xsh_gpio */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_gpio - write a value v in port p 8 | *------------------------------------------------------------------------ 9 | * 10 | * Two modes: 11 | * Normal mode. Example: gpio b 32 # arduino pin 13 high 12 | * Extra Arduino mode. Example: gpio 13 1 # arduino pin 13 high 13 | */ 14 | shellcmd xsh_gpio(int nargs, char *args[]) 15 | { 16 | char p; 17 | unsigned char v; 18 | 19 | char pin; 20 | unsigned char val; 21 | 22 | 23 | /* Normal mode. Example: gpio b 32 # arduino pin 13 high */ 24 | 25 | p = *args[1]; 26 | v = number(args[2]); 27 | 28 | if ((p == 'b') | (p == 'c') | (p == 'd')) { 29 | gpio_write(p, v); 30 | return 0; 31 | } 32 | 33 | /* Extra arduino mode. Example: gpio 13 1 # arduino pin 13 high */ 34 | 35 | pin = number(args[1]); 36 | gpio_arduino_write(pin, v); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /main/xsh_sleep.c: -------------------------------------------------------------------------------- 1 | /* xsh_sleep.c - xsh_sleep */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_sleep - Shell command to delay for a specified number of seconds 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_sleep(int nargs, char *args[]) 12 | { 13 | int32 delay; /* Delay in seconds */ 14 | char *chptr; /* Walks through argument */ 15 | char ch; /* Next character of argument */ 16 | 17 | /* Check for valid number of arguments */ 18 | 19 | if (nargs != 2) { 20 | return 1; 21 | } 22 | 23 | chptr = args[1]; 24 | ch = *chptr++; 25 | delay = 0; 26 | while (ch != NULLCH) { 27 | if ( (ch < '0') || (ch > '9') ) { 28 | // fprintf(stderr, "%s: nondigit in argument\n", 29 | // args[0]); 30 | return 1; 31 | } 32 | delay = 10*delay + (ch - '0'); 33 | ch = *chptr++; 34 | } 35 | sleep(delay); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /apps/shell/xsh_sleep.c: -------------------------------------------------------------------------------- 1 | /* xsh_sleep.c - xsh_sleep */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_sleep - Shell command to delay for a specified number of seconds 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_sleep(int nargs, char *args[]) 12 | { 13 | int32 delay; /* Delay in seconds */ 14 | char *chptr; /* Walks through argument */ 15 | char ch; /* Next character of argument */ 16 | 17 | /* Check for valid number of arguments */ 18 | 19 | if (nargs != 2) { 20 | return 1; 21 | } 22 | 23 | chptr = args[1]; 24 | ch = *chptr++; 25 | delay = 0; 26 | while (ch != NULLCH) { 27 | if ( (ch < '0') || (ch > '9') ) { 28 | // fprintf(stderr, "%s: nondigit in argument\n", 29 | // args[0]); 30 | return 1; 31 | } 32 | delay = 10*delay + (ch - '0'); 33 | ch = *chptr++; 34 | } 35 | sleep(delay); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /lib/fprintf.c: -------------------------------------------------------------------------------- 1 | /* fprintf.c - _fdoprnt */ 2 | 3 | #include 4 | #include 5 | 6 | extern void _fdoprnt(char *, va_list, int (*)(did32, char), int); 7 | 8 | /*------------------------------------------------------------------------ 9 | * fprintf - Print a formatted message on specified device (file). 10 | * Return 0 if the output was printed successfully, 11 | * and -1 if an error occurred. 12 | *------------------------------------------------------------------------ 13 | */ 14 | int fprintf( 15 | int dev, /* device to write to */ 16 | char *fmt, /* format string */ 17 | ... 18 | ) 19 | { 20 | syscall putc(did32, char); 21 | 22 | va_list ap; 23 | char output[81]; 24 | char *c; 25 | 26 | memset(output, 0, 81); 27 | va_start(ap, fmt); 28 | vsnprintf(output, 80, fmt, ap); 29 | va_end(ap); 30 | 31 | c = output; 32 | while(*c) { 33 | putc(dev, *c); 34 | c++; 35 | }; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /include/bufpool.h: -------------------------------------------------------------------------------- 1 | /* bufpool.h */ 2 | 3 | #ifndef NBPOOLS 4 | // RAFA #define NBPOOLS 20 /* Maximum number of buffer pools */ 5 | #define NBPOOLS 5 /* Maximum number of buffer pools */ 6 | #endif 7 | 8 | #ifndef BP_MAXB 9 | // #define BP_MAXB 8192 /* Maximum buffer size in bytes */ 10 | #define BP_MAXB 20 /* Maximum buffer size in bytes */ 11 | #endif 12 | 13 | #define BP_MINB 8 /* Minimum buffer size in bytes */ 14 | #ifndef BP_MAXN 15 | // RAFA #define BP_MAXN 2048 /* Maximum number of buffers in a pool */ 16 | #define BP_MAXN 10 /* Maximum number of buffers in a pool */ 17 | #endif 18 | 19 | struct bpentry { /* Description of a single buffer pool */ 20 | struct bpentry *bpnext;/* pointer to next free buffer */ 21 | sid32 bpsem; /* semaphore that counts buffers */ 22 | /* currently available in the pool */ 23 | uint32 bpsize; /* size of buffers in this pool */ 24 | }; 25 | 26 | extern struct bpentry buftab[];/* Buffer pool table */ 27 | extern bpid32 nbpools; /* current number of allocated pools */ 28 | -------------------------------------------------------------------------------- /include/ip.h: -------------------------------------------------------------------------------- 1 | /* ip.h - Constants related to Internet Protocol version 4 (IPv4) */ 2 | 3 | #define IP_BCAST 0xffffffff /* IP local broadcast address */ 4 | #define IP_THIS 0xffffffff /* "this host" src IP address */ 5 | #define IP_ALLZEROS 0x00000000 /* The all-zeros IP address */ 6 | 7 | #define IP_ICMP 1 /* ICMP protocol type for IP */ 8 | #define IP_UDP 17 /* UDP protocol type for IP */ 9 | 10 | #define IP_ASIZE 4 /* Bytes in an IP address */ 11 | #define IP_HDR_LEN 20 /* Bytes in an IP header */ 12 | #define IP_VH 0x45 /* IP version and hdr length */ 13 | 14 | #define IP_OQSIZ 8 /* Size of IP output queue */ 15 | 16 | /* Queue of outgoing IP packets waiting for ipout process */ 17 | 18 | struct iqentry { 19 | int32 iqhead; /* Index of next packet to send */ 20 | int32 iqtail; /* Index of next free slot */ 21 | sid32 iqsem; /* Semaphore that counts pkts */ 22 | struct netpacket *iqbuf[IP_OQSIZ];/* Circular packet queue */ 23 | }; 24 | 25 | extern struct iqentry ipoqueue; /* Network output queue */ 26 | -------------------------------------------------------------------------------- /system/signaln.c: -------------------------------------------------------------------------------- 1 | /* signaln.c - signaln */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * signaln - Signal a semaphore n times, releasing n waiting processes 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall signaln( 10 | sid32 sem, /* ID of semaphore to signal */ 11 | int32 count /* Number of times to signal */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | struct sentry *semptr; /* Ptr to sempahore table entry */ 16 | 17 | mask = disable(); 18 | if (isbadsem(sem) || (count < 0)) { 19 | restore(mask); 20 | return SYSERR; 21 | } 22 | semptr = &semtab[sem]; 23 | if (semptr->sstate == S_FREE) { 24 | restore(mask); 25 | return SYSERR; 26 | } 27 | 28 | resched_cntl(DEFER_START); 29 | for (; count > 0; count--) { 30 | if ((semptr->scount++) < 0) { 31 | ready(dequeue(semptr->squeue)); 32 | } 33 | } 34 | resched_cntl(DEFER_STOP); 35 | restore(mask); 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /device/lfs/lfibget.c: -------------------------------------------------------------------------------- 1 | /* lfibget.c - lfibget */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfibget - Get an index block from disk given its number (assumes 7 | * mutex is held) 8 | *------------------------------------------------------------------------ 9 | */ 10 | void lfibget( 11 | did32 diskdev, /* Device ID of disk to use */ 12 | ibid32 inum, /* ID of index block to fetch */ 13 | struct lfiblk *ibuff /* Buffer to hold index block */ 14 | ) 15 | { 16 | char *from, *to; /* Pointers used in copying */ 17 | int32 i; /* Loop index used during copy */ 18 | char dbuff[LF_BLKSIZ]; /* Buffer to hold disk block */ 19 | 20 | /* Read disk block that contains the specified index block */ 21 | 22 | read(diskdev, dbuff, ib2sect(inum)); 23 | 24 | /* Copy specified index block to caller's ibuff */ 25 | 26 | from = dbuff + ib2disp(inum); 27 | to = (char *)ibuff; 28 | for (i=0 ; i 4 | #include 5 | #include 6 | 7 | // RAFA 8 | #include 9 | 10 | static void printnl(void) 11 | { 12 | printf("\n\r"); 13 | } 14 | 15 | 16 | /*------------------------------------------------------------------------ 17 | * xsh_memdump - Print memory content 18 | *------------------------------------------------------------------------ 19 | */ 20 | shellcmd xsh_memdump(int nargs, char *args[]) 21 | { 22 | 23 | int from = 0; 24 | int to = 0x8FF; /* AVR atmega328p top RAM address */ 25 | 26 | if (nargs == 3) { 27 | from = args[1]; 28 | to = args[2]; 29 | } 30 | 31 | long i; 32 | int j=0; 33 | char * c = 0; 34 | for (i = from; i < to ; i++) { 35 | c = (char *)i; 36 | if (j==0) { 37 | printf("\n"); 38 | printf ("0x%08x ", c); 39 | } 40 | j++; 41 | if (j==16) j=0; 42 | if (*c < 33) 43 | printf("-"); 44 | else 45 | printf("%c", *c); 46 | } 47 | printnl(); 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /apps/shell/xsh_memdump.c: -------------------------------------------------------------------------------- 1 | /* xsh_memdump.c - xsh_memdump */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | // RAFA 8 | #include 9 | 10 | static void printnl(void) 11 | { 12 | printf("\n\r"); 13 | } 14 | 15 | 16 | /*------------------------------------------------------------------------ 17 | * xsh_memdump - Print memory content 18 | *------------------------------------------------------------------------ 19 | */ 20 | shellcmd xsh_memdump(int nargs, char *args[]) 21 | { 22 | 23 | int from = 0; 24 | int to = 0x8FF; /* AVR atmega328p top RAM address */ 25 | 26 | if (nargs == 3) { 27 | from = args[1]; 28 | to = args[2]; 29 | } 30 | 31 | long i; 32 | int j=0; 33 | char * c = 0; 34 | for (i = from; i < to ; i++) { 35 | c = (char *)i; 36 | if (j==0) { 37 | printf("\n"); 38 | printf ("0x%08x ", c); 39 | } 40 | j++; 41 | if (j==16) j=0; 42 | if (*c < 33) 43 | printf("-"); 44 | else 45 | printf("%c", *c); 46 | } 47 | printnl(); 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /system/control.c: -------------------------------------------------------------------------------- 1 | /* control.c - control */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * control - Control a device or a driver (e.g., set the driver mode) 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall control( 10 | did32 descrp, /* Descriptor for device */ 11 | int32 func, /* Specific control function */ 12 | int32 arg1, /* Specific argument for func */ 13 | int32 arg2 /* Specific argument for func */ 14 | ) 15 | { 16 | intmask mask; /* Saved interrupt mask */ 17 | // struct dentry *devptr; /* Entry in device switch table */ 18 | const __flash struct dentry *devptr; /* Entry in device switch table */ 19 | int32 retval; /* Value to return to caller */ 20 | 21 | mask = disable(); 22 | if (isbaddev(descrp)) { 23 | restore(mask); 24 | return SYSERR; 25 | } 26 | devptr = (struct dentry *) &devtab[descrp]; 27 | retval = (*devptr->dvcntl) (devptr, func, arg1, arg2); 28 | restore(mask); 29 | return retval; 30 | } 31 | -------------------------------------------------------------------------------- /include/name.h: -------------------------------------------------------------------------------- 1 | /* name.h */ 2 | 3 | /* avr specific values. Original saved under orig/ folder */ 4 | 5 | /* Constants that define the namespace mapping table sizes */ 6 | 7 | #define NM_PRELEN 16 /* Max size of a prefix string */ 8 | // RAFA #define NM_REPLLEN 8 /* Maximum size of a replacement*/ 9 | // RAFA #define NM_MAXLEN 8 /* Maximum size of a file name */ 10 | // #define NM_REPLLEN 16 /* Maximum size of a replacement*/ 11 | #define NM_REPLLEN 1 /* Maximum size of a replacement*/ 12 | #define NM_MAXLEN 16 /* Maximum size of a file name */ 13 | #define NNAMES 4 /* Number of prefix definitions */ 14 | 15 | /* Definition of the name prefix table that defines all name mappings */ 16 | 17 | struct nmentry { /* Definition of prefix table */ 18 | char nprefix[NM_PRELEN]; /* Null-terminated prefix */ 19 | char nreplace[NM_REPLLEN]; /* Null-terminated replacement */ 20 | did32 ndevice; /* Device descriptor for prefix */ 21 | }; 22 | 23 | extern struct nmentry nametab[]; /* Table of name mappings */ 24 | extern int32 nnames; /* Number of entries allocated */ 25 | -------------------------------------------------------------------------------- /include/xinu.h: -------------------------------------------------------------------------------- 1 | /* xinu.h - include all system header files */ 2 | 3 | /* avr specific */ 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include /* avr UART peripheral */ 18 | #include 19 | #include /* avr GPIO peripherals */ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | -------------------------------------------------------------------------------- /main/xsh_ps.c: -------------------------------------------------------------------------------- 1 | /* xsh_ps.c - xsh_ps */ 2 | 3 | #include 4 | #include 5 | 6 | const __flash char ps_msg0[] = "\ntable of current processes\n"; 7 | const __flash char ps_msg1[] = "\nname\tid\tparent\tprio\tstate\tstklen\tsem waits\n--\n"; 8 | 9 | /*------------------------------------------------------------------------ 10 | * xsh_ps - show processes 11 | *------------------------------------------------------------------------ 12 | */ 13 | shellcmd xsh_ps(int nargs, char *args[]) 14 | { 15 | int32 i; /* walks through args array */ 16 | 17 | /* check all NPROC slots */ 18 | 19 | printf("%S", ps_msg0); 20 | printf("%S", ps_msg1); 21 | for (i = 0; i < NPROC; i++) { 22 | if (proctab[i].prstate == PR_FREE) 23 | continue; 24 | printf("%s\t%d", proctab[i].prname, i); 25 | printf("\t%d ", proctab[i].prparent); 26 | printf("\t%d ", proctab[i].prprio); 27 | printf("\t%d ", proctab[i].prstate); 28 | printf("\t%d ", proctab[i].prstklen); 29 | printf("\t%d ", proctab[i].prsem); 30 | printf("\n"); 31 | } 32 | 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /apps/shell/xsh_ps.c: -------------------------------------------------------------------------------- 1 | /* xsh_ps.c - xsh_ps */ 2 | 3 | #include 4 | #include 5 | 6 | const __flash char ps_msg0[] = "\ntable of current processes\n"; 7 | const __flash char ps_msg1[] = "\nname\tid\tparent\tprio\tstate\tstklen\tsem waits\n--\n"; 8 | 9 | /*------------------------------------------------------------------------ 10 | * xsh_ps - show processes 11 | *------------------------------------------------------------------------ 12 | */ 13 | shellcmd xsh_ps(int nargs, char *args[]) 14 | { 15 | int32 i; /* walks through args array */ 16 | 17 | /* check all NPROC slots */ 18 | 19 | printf("%S", ps_msg0); 20 | printf("%S", ps_msg1); 21 | for (i = 0; i < NPROC; i++) { 22 | if (proctab[i].prstate == PR_FREE) 23 | continue; 24 | printf("%s\t%d", proctab[i].prname, i); 25 | printf("\t%d ", proctab[i].prparent); 26 | printf("\t%d ", proctab[i].prprio); 27 | printf("\t%d ", proctab[i].prstate); 28 | printf("\t%d ", proctab[i].prstklen); 29 | printf("\t%d ", proctab[i].prsem); 30 | printf("\n"); 31 | } 32 | 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Portions of this software are covered by the following copyright: 2 | 3 | Copyright (c) 2012, 2015 Douglas E. Comer and CRC Press, Inc. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms are permitted 7 | provided that this notice is preserved and that due credit is given 8 | to the copyright holders. The names of the copyright holders 9 | may not be used to endorse or promote products derived from this 10 | software without specific prior written permission. This software 11 | is provided `as is'' without express or implied warranty. The author 12 | assumes no liability for damages incidental or consequential, nor is the 13 | software warranted for correctness or suitability for any purpose. 14 | Portions of this software are documented in the book: 15 | 16 | Operating System Design -- The Xinu Approach, CRC Press, 17 | Boca Raton, FL, Linksys version 2012, Second Edition 2015. 18 | 19 | This software may not be sold or published in printed form without written 20 | permission from the copyright holders. 21 | -------------------------------------------------------------------------------- /device/lfs/lflclose.c: -------------------------------------------------------------------------------- 1 | /* lflclose.c - lflclose.c */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflclose - Close a file by flushing output and freeing device entry 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflclose ( 10 | struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | struct lflcblk *lfptr; /* Ptr to open file table entry */ 14 | 15 | /* Obtain exclusive use of the file */ 16 | 17 | lfptr = &lfltab[devptr->dvminor]; 18 | wait(lfptr->lfmutex); 19 | 20 | /* If file is not open, return an error */ 21 | 22 | if (lfptr->lfstate != LF_USED) { 23 | signal(lfptr->lfmutex); 24 | return SYSERR; 25 | } 26 | 27 | /* Write index or data blocks to disk if they have changed */ 28 | 29 | if (Lf_data.lf_dirdirty || lfptr->lfdbdirty || lfptr->lfibdirty) { 30 | lfflush(lfptr); 31 | } 32 | 33 | /* Set device state to FREE and return to caller */ 34 | 35 | lfptr->lfstate = LF_FREE; 36 | signal(lfptr->lfmutex); 37 | return OK; 38 | } 39 | -------------------------------------------------------------------------------- /device/lfs/lfiballoc.c: -------------------------------------------------------------------------------- 1 | /* lfiballoc.c - lfiballoc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfiballoc - Allocate a new index block from free list on disk 7 | * (assumes directory mutex held) 8 | *------------------------------------------------------------------------ 9 | */ 10 | ibid32 lfiballoc (void) 11 | { 12 | ibid32 ibnum; /* ID of next block on the free list */ 13 | struct lfiblk iblock; /* Buffer to hold an index block */ 14 | 15 | /* Get ID of first index block on free list */ 16 | 17 | ibnum = Lf_data.lf_dir.lfd_ifree; 18 | if (ibnum == LF_INULL) { /* Ran out of free index blocks */ 19 | panic("out of index blocks"); 20 | } 21 | lfibget(Lf_data.lf_dskdev, ibnum, &iblock); 22 | 23 | /* Unlink index block from the directory free list */ 24 | 25 | Lf_data.lf_dir.lfd_ifree = iblock.ib_next; 26 | 27 | /* Write a copy of the directory to disk after the change */ 28 | 29 | write(Lf_data.lf_dskdev, (char *) &Lf_data.lf_dir, LF_AREA_DIR); 30 | Lf_data.lf_dirdirty = FALSE; 31 | 32 | return ibnum; 33 | } 34 | -------------------------------------------------------------------------------- /system/insert.c: -------------------------------------------------------------------------------- 1 | /* insert.c - insert */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * insert - Insert a process into a queue in descending key order 7 | *------------------------------------------------------------------------ 8 | */ 9 | status insert( 10 | pid32 pid, /* ID of process to insert */ 11 | qid16 q, /* ID of queue to use */ 12 | char key /* Key for the inserted process */ 13 | ) 14 | { 15 | qid16 curr; /* Runs through items in a queue*/ 16 | qid16 prev; /* Holds previous node index */ 17 | 18 | if (isbadqid(q) || isbadpid(pid)) { 19 | return SYSERR; 20 | } 21 | 22 | curr = firstid(q); 23 | while (queuetab[curr].qkey >= key) { 24 | curr = queuetab[curr].qnext; 25 | } 26 | 27 | /* Insert process between curr node and previous node */ 28 | 29 | prev = queuetab[curr].qprev; /* Get index of previous node */ 30 | queuetab[pid].qnext = curr; 31 | queuetab[pid].qprev = prev; 32 | queuetab[pid].qkey = key; 33 | queuetab[prev].qnext = pid; 34 | queuetab[curr].qprev = pid; 35 | return OK; 36 | } 37 | -------------------------------------------------------------------------------- /www/files/page_l.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | margin:10px 10px 0px 10px; 4 | padding:0px; 5 | 6 | /* font-family: Sans-Serif; */ 7 | font-family: Tahoma,Verdana,Helvetica,Arial; 8 | color:#333; 9 | background-color: #fafafa; 10 | /* background-color: #EeEeFA; */ 11 | } 12 | 13 | img{ 14 | width:30%; 15 | max-width:60em; 16 | border: 5px solid #000; 17 | } 18 | 19 | h1 20 | { 21 | margin-left:15px; 22 | color:#2277bb; 23 | } 24 | 25 | 26 | h2 27 | { 28 | margin-left:15px; 29 | color:#2266bb; 30 | } 31 | 32 | h3 33 | { 34 | margin-left:15px; 35 | color:#2266bb; 36 | } 37 | 38 | h4 39 | { 40 | margin-left:40px; 41 | color:#2266bb; 42 | } 43 | 44 | p 45 | { 46 | margin-left:70px; 47 | margin-right:70px; 48 | margin-top:5px; 49 | font-size:12pt; 50 | } 51 | 52 | pre 53 | { 54 | margin-left:70px; 55 | margin-right:70px; 56 | margin-top:5px; 57 | } 58 | 59 | ol 60 | { 61 | margin-left:100px; 62 | margin-right:70px; 63 | margin-top:5px; 64 | font-size:12pt; 65 | } 66 | 67 | 68 | ul 69 | { 70 | margin-left:60px; 71 | margin-right:100px; 72 | font-size:12pt; 73 | } 74 | 75 | table 76 | { 77 | font-size:16px; 78 | } 79 | -------------------------------------------------------------------------------- /apps/example2/main.c: -------------------------------------------------------------------------------- 1 | /* ex2.c - main, sndA, sndB */ 2 | 3 | #include 4 | 5 | void sndA(void), sndB(void); 6 | 7 | /*------------------------------------------------------------------------ 8 | * main -- example of creating processes in Xinu 9 | *------------------------------------------------------------------------ 10 | */ 11 | void main(void) 12 | { 13 | resume( create(sndA, 128, 20, "process 1", 0) ); 14 | resume( create(sndB, 128, 20, "process 2", 0) ); 15 | } 16 | 17 | /*------------------------------------------------------------------------ 18 | * sndA -- repeatedly emit 'A' on the console without terminating 19 | *------------------------------------------------------------------------ 20 | */ 21 | void sndA(void) 22 | { 23 | while( 1 ) 24 | putc(CONSOLE, 'A'); 25 | } 26 | 27 | /*------------------------------------------------------------------------ 28 | * sndB -- repeatedly emit 'B' on the console without terminating 29 | *------------------------------------------------------------------------ 30 | */ 31 | void sndB(void) 32 | { 33 | while( 1 ) 34 | putc(CONSOLE, 'B'); 35 | } 36 | -------------------------------------------------------------------------------- /lib/ctype_.c: -------------------------------------------------------------------------------- 1 | /* ctype_.c - _ctype_ */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * _ctype_ - Provides _ctype_. 7 | *------------------------------------------------------------------------ 8 | */ 9 | #include 10 | typedef unsigned int size_t; 11 | #include 12 | const char _ctype_[] PROGMEM = { 13 | 0, 14 | _C, _C, _C, _C, _C, _C, _C, _C, 15 | _C, _S, _S, _S, _S, _S, _C, _C, 16 | _C, _C, _C, _C, _C, _C, _C, _C, 17 | _C, _C, _C, _C, _C, _C, _C, _C, 18 | _S, _P, _P, _P, _P, _P, _P, _P, 19 | _P, _P, _P, _P, _P, _P, _P, _P, 20 | _N, _N, _N, _N, _N, _N, _N, _N, 21 | _N, _N, _P, _P, _P, _P, _P, _P, 22 | _P, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, 23 | _U, 24 | _U, _U, _U, _U, _U, _U, _U, _U, 25 | _U, _U, _U, _U, _U, _U, _U, _U, 26 | _U, _U, _U, _P, _P, _P, _P, _P, 27 | _P, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, 28 | _L, 29 | _L, _L, _L, _L, _L, _L, _L, _L, 30 | _L, _L, _L, _L, _L, _L, _L, _L, 31 | _L, _L, _L, _P, _P, _P, _P, _C 32 | }; 33 | -------------------------------------------------------------------------------- /www/files/page_p.css: -------------------------------------------------------------------------------- 1 | 2 | body{ 3 | margin:1em auto; 4 | padding:1.5em 1.5em 1.5em 1.5em; 5 | /* padding:0;*/ 6 | /* margin:0;*/ 7 | font-size:0.7em; 8 | font-family: Sans-Serif; 9 | color:#333; 10 | background-color: #fafafa; 11 | } 12 | 13 | img{ 14 | width:100%; 15 | /* max-width:60em;*/ 16 | border: 5px solid #000; 17 | } 18 | 19 | /* 20 | body 21 | { 22 | margin:10px 10px 0px 10px; 23 | padding:0px; 24 | font-size:18px; 25 | } 26 | */ 27 | 28 | h1 29 | { 30 | /* margin-left:15px; */ 31 | color:#2277bb; 32 | } 33 | 34 | 35 | h2 36 | { 37 | color:#2266bb; 38 | } 39 | 40 | h3 41 | { 42 | color:#2266bb; 43 | } 44 | 45 | h4 46 | { 47 | color:#2266bb; 48 | } 49 | 50 | p 51 | { 52 | /* 53 | margin-left:70px; 54 | margin-right:70px; 55 | margin-top:5px; 56 | font-size:12pt; 57 | */ 58 | } 59 | 60 | ol 61 | { 62 | /* 63 | margin-left:100px; 64 | margin-right:70px; 65 | margin-top:5px; 66 | font-size:12pt; 67 | */ 68 | } 69 | 70 | 71 | ul 72 | { 73 | /* 74 | margin-left:60px; 75 | margin-right:100px; 76 | font-size:12pt; 77 | */ 78 | } 79 | 80 | table 81 | { 82 | /* 83 | font-size:16px; 84 | */ 85 | } 86 | -------------------------------------------------------------------------------- /device/lfs/lflread.c: -------------------------------------------------------------------------------- 1 | /* lflread.c - lflread */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflread - Read from a previously opened local file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflread ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | char *buff, /* Buffer to hold bytes */ 12 | int32 count /* Max bytes to read */ 13 | ) 14 | { 15 | uint32 numread; /* Number of bytes read */ 16 | int32 nxtbyte; /* Character or SYSERR/EOF */ 17 | 18 | if (count < 0) { 19 | return SYSERR; 20 | } 21 | 22 | /* Iterate and use lflgetc to read individual bytes */ 23 | 24 | for (numread=0 ; numread < count ; numread++) { 25 | nxtbyte = lflgetc(devptr); 26 | if (nxtbyte == SYSERR) { 27 | return SYSERR; 28 | } else if (nxtbyte == EOF) { /* EOF before finished */ 29 | if (numread == 0) { 30 | return EOF; 31 | } else { 32 | return numread; 33 | } 34 | } else { 35 | *buff++ = (char) (0xff & nxtbyte); 36 | } 37 | } 38 | return numread; 39 | } 40 | -------------------------------------------------------------------------------- /include/spi.h: -------------------------------------------------------------------------------- 1 | /* spi.h - SPI definitions */ 2 | 3 | /* avr : this port does not use spi yet */ 4 | /* values below for another platform-arch */ 5 | 6 | struct spi_csreg { 7 | volatile uint32 cr1; 8 | volatile uint32 cr2; 9 | volatile uint32 sr; 10 | volatile uint32 dr; 11 | volatile uint32 crcpr; 12 | volatile uint32 rxcrcr; 13 | volatile uint32 txcrcr; 14 | volatile uint32 i2scfgr; 15 | volatile uint32 i2spr; 16 | }; 17 | 18 | /* No SPI0 peripheral, starts from 1*/ 19 | #define SPI1_BASE 0x40013000 20 | 21 | /* Control register settings */ 22 | #define SPI_MSTR 2 23 | #define SPI_ENABLE 6 24 | #define SPI_SSM 9 25 | #define SPI_SSI 8 26 | #define SPI_BIDIMODE 15 27 | #define SPI_BIDIOE 14 28 | 29 | /* Status register flags */ 30 | #define SPI_BSY 7 // Busy 31 | #define SPI_TXE 1 // Transfer buffer empty 32 | #define SPI_RXNE 2 // Receive buffer NOT empty 33 | 34 | /* Baud rate control */ 35 | #define BR_FPCLKDIV2 0x00000000 36 | #define BR_FPCLKDIV4 0x00000008 37 | #define BR_FPCLKDIV8 0x00000010 38 | #define BR_FPCLKDIV16 0x00000018 39 | #define BR_FPCLKDIV32 0x00000020 40 | #define BR_FPCLKDIV64 0x00000028 41 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | /* ctype.h 2 | * 3 | * Includes isalpha, isupper, islower, isdigit, isspace, ispunct, isalnum, 4 | * isprint, iscntrl, toupper, tolower, toascii, iseof 5 | */ 6 | 7 | #define _U 0x01 8 | #define _L 0x02 9 | #define _N 0x04 10 | #define _S 0x08 11 | #define _P 0x10 12 | #define _C 0x20 13 | #define _X 0x40 14 | 15 | extern const char _ctype_[]; 16 | 17 | #define isalpha(c) ((_ctype_+1)[(int)c]&(_U|_L)) 18 | #define isupper(c) ((_ctype_+1)[(int)c]&_U) 19 | #define islower(c) ((_ctype_+1)[(int)c]&_L) 20 | #define isdigit(c) ((_ctype_+1)[(int)c]&_N) 21 | #define isxdigit(c) ((_ctype_+1)[(int)c]&(_N|_X)) 22 | #define isspace(c) ((_ctype_+1)[(int)c]&_S) 23 | #define ispunct(c) ((_ctype_+1)[(int)c]&_P) 24 | #define isalnum(c) ((_ctype_+1)[(int)c]&(_U|_L|_N)) 25 | #define isprint(c) ((_ctype_+1)[(int)c]&(_P|_U|_L|_N|_S)) 26 | #define iscntrl(c) ((_ctype_+1)[(int)c]&_C) 27 | #define isascii(c) ((unsigned)((int)(c))<=0x7F) 28 | 29 | #define toupper(c) (((int)(c))-'a'+'A') 30 | #define tolower(c) (((int)(c))-'A'+'a') 31 | #define toascii(c) (((int)(c))&0x7F) 32 | 33 | #define iseof(c) (0x04 == (int)c) 34 | -------------------------------------------------------------------------------- /lib/avr_messages.c: -------------------------------------------------------------------------------- 1 | 2 | /* avr specific */ 3 | 4 | typedef unsigned int size_t; 5 | #include 6 | 7 | const __flash char sysinit_m0[] = "\nWelcome to Xinu!\n\n\r\tXinu OS Copyright (c) 2012, 2015\n\r\tDouglas E. Comer and CRC Press, Inc.\n\n\r\tXinu OS for AVR atmega328p v0.1 (c) 2020\n\r\tRafael Ignacio Zurita \n\n\r"; 8 | const __flash char m1[] = "\n\nRecreating shell\n\n"; 9 | const __flash char m2[] = "Out of message nodes"; 10 | const __flash char m3[] = "\n\nAll user processes have completed.\n\n"; 11 | const __flash char m4[] = "namespace: cannot mount %d\r\n"; 12 | const __flash char m5[] = "namespace: device name %s too long\r\n"; 13 | const __flash char m6[] = "Can't startup system"; 14 | const __flash char m7[] = "ptinit - insufficient memory"; 15 | const __flash char m8[] = "freemem: %10d bytes. Free-list:\n"; 16 | const __flash char m9[] = "Syscall not implemented\n"; 17 | const __flash char m10[] = "ERROR GETSTK %s\n"; 18 | const __flash char m11[] = "0x%08x %d\n"; 19 | const __flash char m12[] = "looping... press reset\n"; 20 | const __flash char m13[] = "naminit (devices):\r\n"; 21 | 22 | -------------------------------------------------------------------------------- /system/start.S: -------------------------------------------------------------------------------- 1 | /* avr specific */ 2 | /* We do a hack for calling (insert) nulluser before main, 3 | * so avr-libc does everything : ld scripts, startup, etc 4 | */ 5 | #include 6 | 7 | .weak __heap_end 8 | .set __heap_end, 0 9 | 10 | .macro vector name 11 | .weak \name 12 | .set \name, __vectors 13 | jmp \name 14 | .endm 15 | 16 | .section .vectors 17 | __vectors: 18 | jmp __ctors_end 19 | vector __vector_1 20 | vector __vector_2 21 | vector __vector_3 22 | vector __vector_4 23 | vector __vector_5 24 | vector __vector_6 25 | vector __vector_7 26 | vector __vector_8 27 | vector __vector_9 28 | vector __vector_10 29 | vector __vector_11 30 | vector __vector_12 31 | vector __vector_13 32 | vector __vector_14 33 | vector __vector_15 34 | vector __vector_16 35 | vector __vector_17 36 | vector __vector_18 37 | vector __vector_19 38 | vector __vector_20 39 | vector __vector_21 40 | vector __vector_22 41 | vector __vector_23 42 | vector __vector_24 43 | vector __vector_25 44 | 45 | .section .init8 46 | jmp nulluser 47 | -------------------------------------------------------------------------------- /device/rfs/rfsinit.c: -------------------------------------------------------------------------------- 1 | /* rfsinit.c - rfsinit */ 2 | 3 | #include 4 | 5 | struct rfdata Rf_data; 6 | 7 | /*------------------------------------------------------------------------ 8 | * rfsinit - Initialize the remote file system master device 9 | *------------------------------------------------------------------------ 10 | */ 11 | devcall rfsinit( 12 | struct dentry *devptr /* Entry in device switch table */ 13 | ) 14 | { 15 | 16 | /* Choose an initial message sequence number */ 17 | 18 | Rf_data.rf_seq = 1; 19 | 20 | /* Set the server IP address, server port, and local port */ 21 | 22 | if ( dot2ip(RF_SERVER_IP, &Rf_data.rf_ser_ip) == SYSERR ) { 23 | panic("invalid IP address for remote file server"); 24 | } 25 | Rf_data.rf_ser_port = RF_SERVER_PORT; 26 | Rf_data.rf_loc_port = RF_LOC_PORT; 27 | 28 | /* Create a mutual exclusion semaphore */ 29 | 30 | if ( (Rf_data.rf_mutex = semcreate(1)) == SYSERR ) { 31 | panic("Cannot create remote file system semaphore"); 32 | } 33 | 34 | /* Specify that the server port is not yet registered */ 35 | 36 | Rf_data.rf_registered = FALSE; 37 | 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /include/syscall.h: -------------------------------------------------------------------------------- 1 | /* Xinu system calls */ 2 | 3 | enum { 4 | XINU_NULLPROCESS = 0, 5 | XINU_UPTIME, 6 | XINU_PUTC, 7 | XINU_CLOSE, /* Devices */ 8 | XINU_CONTROL, 9 | XINU_GETC, 10 | XINU_INIT, 11 | XINU_OPEN, 12 | XINU_READ, 13 | XINU_SEEK, 14 | XINU_WRITE, 15 | 16 | XINU_CREATE, /* Processes */ 17 | XINU_CHPRIO, 18 | XINU_KILL, /* Exit */ 19 | XINU_GETPRIO, 20 | XINU_READY, 21 | XINU_RECEIVE, 22 | XINU_RECVCLR, 23 | XINU_RECVTIME, 24 | XINU_RESCHED_CNTL, 25 | XINU_RESUME, 26 | XINU_SEND, 27 | XINU_SIGNAL, 28 | XINU_SIGNALN, 29 | XINU_SLEEP, 30 | XINU_SLEEPMS, 31 | XINU_SUSPEND, 32 | XINU_UNSLEEP, 33 | XINU_WAKE, 34 | XINU_WAKEUP, 35 | XINU_YIELD, 36 | 37 | XINU_MKBUFPOOL, /* Buffers */ 38 | XINU_FREEBUF, 39 | XINU_FREEMEM, 40 | XINU_GETBUF, 41 | 42 | XINU_KPRINTF, /* Kernel */ 43 | XINU_KPUTC, 44 | XINU_GETDEV, 45 | XINU_GETMEM, 46 | XINU_GETSTK, 47 | 48 | XINU_PTCOUNT, /* Ports */ 49 | XINU_PTCREATE, 50 | XINU_PTDELETE, 51 | XINU_PTINIT, 52 | XINU_PTRCV, 53 | XINU_PTRESET, 54 | 55 | XINU_SEMCOUNT, /* Semaphores */ 56 | XINU_SEMCREATE, 57 | XINU_SEMRESET, 58 | XINU_SEMDELET, 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /main/xsh_free.c: -------------------------------------------------------------------------------- 1 | /* xsh_free.c - xsh_free */ 2 | 3 | #include 4 | #include 5 | 6 | const __flash char free_msg0[] = "\nfree mem list:\n\raddr\t\tlen\n"; 7 | const __flash char free_msg1[] = "\n\t\ttotal\tused\tfree\nSRAM Mem\t"; 8 | 9 | /*------------------------------------------------------------------------ 10 | * xsh_free - show free memory available 11 | *------------------------------------------------------------------------ 12 | */ 13 | shellcmd xsh_free(int nargs, char *args[]) 14 | { 15 | int32 i; /* walks through args array */ 16 | long free_mem; 17 | struct memblk *block; 18 | 19 | printf("%S", free_msg0); 20 | 21 | /* Output Xinu memory layout */ 22 | free_mem = 0; 23 | for (block = memlist.mnext; block != NULL; 24 | block = block->mnext) { 25 | free_mem += block->mlength; 26 | 27 | printf("0x%08x\t%d\n", block, 28 | (uint32) block->mlength); 29 | } 30 | 31 | printf("%S", free_msg1); 32 | printf("%d\t%d\t%d\n", maxheap, maxheap-free_mem, free_mem); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /apps/shell/xsh_free.c: -------------------------------------------------------------------------------- 1 | /* xsh_free.c - xsh_free */ 2 | 3 | #include 4 | #include 5 | 6 | const __flash char free_msg0[] = "\nfree mem list:\n\raddr\t\tlen\n"; 7 | const __flash char free_msg1[] = "\n\t\ttotal\tused\tfree\nSRAM Mem\t"; 8 | 9 | /*------------------------------------------------------------------------ 10 | * xsh_free - show free memory available 11 | *------------------------------------------------------------------------ 12 | */ 13 | shellcmd xsh_free(int nargs, char *args[]) 14 | { 15 | int32 i; /* walks through args array */ 16 | long free_mem; 17 | struct memblk *block; 18 | 19 | printf("%S", free_msg0); 20 | 21 | /* Output Xinu memory layout */ 22 | free_mem = 0; 23 | for (block = memlist.mnext; block != NULL; 24 | block = block->mnext) { 25 | free_mem += block->mlength; 26 | 27 | printf("0x%08x\t%d\n", block, 28 | (uint32) block->mlength); 29 | } 30 | 31 | printf("%S", free_msg1); 32 | printf("%d\t%d\t%d\n", maxheap, maxheap-free_mem, free_mem); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /device/lfs/lfflush.c: -------------------------------------------------------------------------------- 1 | /* lfflush.c - lfflush */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfflush - Flush directory, data block, and index block for an open 7 | * file (assumes file mutex is held) 8 | *------------------------------------------------------------------------ 9 | */ 10 | status lfflush ( 11 | struct lflcblk *lfptr /* Ptr to file pseudo device */ 12 | ) 13 | { 14 | 15 | if (lfptr->lfstate == LF_FREE) { 16 | return SYSERR; 17 | } 18 | 19 | /* Write the directory if it has changed */ 20 | 21 | if (Lf_data.lf_dirdirty) { 22 | write(Lf_data.lf_dskdev, (char *)&Lf_data.lf_dir, 23 | LF_AREA_DIR); 24 | Lf_data.lf_dirdirty = FALSE; 25 | } 26 | 27 | /* Write data block if it has changed */ 28 | 29 | if (lfptr->lfdbdirty) { 30 | write(Lf_data.lf_dskdev, lfptr->lfdblock, lfptr->lfdnum); 31 | lfptr->lfdbdirty = FALSE; 32 | } 33 | 34 | /* Write i-block if it has changed */ 35 | 36 | if (lfptr->lfibdirty) { 37 | lfibput(Lf_data.lf_dskdev, lfptr->lfinum, &lfptr->lfiblock); 38 | lfptr->lfibdirty = FALSE; 39 | } 40 | 41 | return OK; 42 | } 43 | -------------------------------------------------------------------------------- /system/semreset.c: -------------------------------------------------------------------------------- 1 | /* semreset.c - semreset */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * semreset - Reset a semaphore's count and release waiting processes 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall semreset( 10 | sid32 sem, /* ID of semaphore to reset */ 11 | int32 count /* New count (must be >= 0) */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | struct sentry *semptr; /* Ptr to semaphore table entry */ 16 | qid16 semqueue; /* Semaphore's process queue ID */ 17 | pid32 pid; /* ID of a waiting process */ 18 | 19 | mask = disable(); 20 | 21 | if (count < 0 || isbadsem(sem) || semtab[sem].sstate==S_FREE) { 22 | restore(mask); 23 | return SYSERR; 24 | } 25 | 26 | semptr = &semtab[sem]; 27 | semqueue = semptr->squeue; /* Free any waiting processes */ 28 | resched_cntl(DEFER_START); 29 | while ((pid=getfirst(semqueue)) != EMPTY) 30 | ready(pid); 31 | semptr->scount = count; /* Reset count as specified */ 32 | resched_cntl(DEFER_STOP); 33 | restore(mask); 34 | return OK; 35 | } 36 | -------------------------------------------------------------------------------- /system/wait.c: -------------------------------------------------------------------------------- 1 | /* wait.c - wait */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * wait - Cause current process to wait on a semaphore 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall wait( 10 | sid32 sem /* Semaphore on which to wait */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct procent *prptr; /* Ptr to process's table entry */ 15 | struct sentry *semptr; /* Ptr to sempahore table entry */ 16 | 17 | mask = disable(); 18 | if (isbadsem(sem)) { 19 | restore(mask); 20 | return SYSERR; 21 | } 22 | 23 | semptr = &semtab[sem]; 24 | if (semptr->sstate == S_FREE) { 25 | restore(mask); 26 | return SYSERR; 27 | } 28 | 29 | if (--(semptr->scount) < 0) { /* If caller must block */ 30 | prptr = &proctab[currpid]; 31 | prptr->prstate = PR_WAIT; /* Set state to waiting */ 32 | prptr->prsem = sem; /* Record semaphore ID */ 33 | enqueue(currpid,semptr->squeue);/* Enqueue on semaphore */ 34 | resched(); /* and reschedule */ 35 | } 36 | 37 | restore(mask); 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /system/freebuf.c: -------------------------------------------------------------------------------- 1 | /* freebuf.c - freebuf */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * freebuf - Free a buffer that was allocated from a pool by getbuf 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall freebuf( 10 | char *bufaddr /* Address of buffer to return */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct bpentry *bpptr; /* Pointer to entry in buftab */ 15 | bpid32 poolid; /* ID of buffer's pool */ 16 | 17 | mask = disable(); 18 | 19 | /* Extract pool ID from integer prior to buffer address */ 20 | 21 | bufaddr -= sizeof(bpid32); 22 | poolid = *(bpid32 *)bufaddr; 23 | if (poolid < 0 || poolid >= nbpools) { 24 | restore(mask); 25 | return SYSERR; 26 | } 27 | 28 | /* Get address of correct pool entry in table */ 29 | 30 | bpptr = &buftab[poolid]; 31 | 32 | /* Insert buffer into list and signal semaphore */ 33 | 34 | ((struct bpentry *)bufaddr)->bpnext = bpptr->bpnext; 35 | bpptr->bpnext = (struct bpentry *)bufaddr; 36 | signal(bpptr->bpsem); 37 | restore(mask); 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /system/send.c: -------------------------------------------------------------------------------- 1 | /* send.c - send */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * send - Pass a message to a process and start recipient if waiting 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall send( 10 | pid32 pid, /* ID of recipient process */ 11 | umsg32 msg /* Contents of message */ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | struct procent *prptr; /* Ptr to process's table entry */ 16 | 17 | mask = disable(); 18 | if (isbadpid(pid)) { 19 | restore(mask); 20 | return SYSERR; 21 | } 22 | 23 | prptr = &proctab[pid]; 24 | if (prptr->prhasmsg) { 25 | restore(mask); 26 | return SYSERR; 27 | } 28 | prptr->prmsg = msg; /* Deliver message */ 29 | prptr->prhasmsg = TRUE; /* Indicate message is waiting */ 30 | 31 | /* If recipient waiting or in timed-wait make it ready */ 32 | 33 | if (prptr->prstate == PR_RECV) { 34 | ready(pid); 35 | } else if (prptr->prstate == PR_RECTIM) { 36 | unsleep(pid); 37 | ready(pid); 38 | } 39 | restore(mask); /* Restore interrupts */ 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /system/clkhandler.c: -------------------------------------------------------------------------------- 1 | /* clkhandler.c - clkhandler */ 2 | 3 | /* avr specific */ 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | volatile unsigned int avr_ticks=0; 11 | 12 | /*----------------------------------------------------------------------- 13 | * clkhandler - high level clock interrupt handler 14 | *----------------------------------------------------------------------- 15 | */ 16 | 17 | /* void clkhandler() */ 18 | 19 | ISR(TIMER0_COMPA_vect) 20 | { 21 | 22 | /* Every ms */ 23 | 24 | /* Increment 1000ms counter */ 25 | 26 | count1000++; 27 | 28 | /* After 1 sec, increment clktime */ 29 | 30 | if(count1000 >= 1000) { /* previous was: if(count1000 >= 1000) */ 31 | clktime++; 32 | count1000 = 0; 33 | } 34 | 35 | if(!isempty(sleepq)) { 36 | /* sleepq nonempty, decrement the key of */ 37 | /* topmost process on sleepq */ 38 | 39 | if((--queuetab[firstid(sleepq)].qkey) == 0) { 40 | 41 | wakeup(); 42 | } 43 | } 44 | 45 | /* Decrement the preemption counter */ 46 | /* Reschedule if necessary */ 47 | if((--preempt) == 0) { 48 | preempt = QUANTUM; 49 | resched(); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /include/stdio.h: -------------------------------------------------------------------------------- 1 | /* stdio.h - definintions and constants for standard I/O functions */ 2 | 3 | /* avr specific values. Original saved under orig/ folder */ 4 | 5 | 6 | /* Prototypes for formatted input functions */ 7 | 8 | extern int32 _doscan(char *,int32 *, int32 (*)(void), 9 | int32 (*)(char), int32, int32); 10 | extern int32 sscanf(char *, char *, int32); 11 | extern int32 fscanf(int32, char *, int32); 12 | #define scanf(fmt, args) fscanf(CONSOLE, fmt, args) 13 | 14 | 15 | /* Definintion of standard input/ouput/error used with shell commands */ 16 | 17 | #define stdin ((proctab[currpid]).prdesc[0]) 18 | #define stdout ((proctab[currpid]).prdesc[1]) 19 | #define stderr ((proctab[currpid]).prdesc[2]) 20 | 21 | 22 | /* Prototypes for formatted output functions */ 23 | 24 | extern int fprintf(int, char *, ...); 25 | extern int printf(const char *, ...); 26 | extern int32 sprintf(char *, char *, ...); 27 | 28 | 29 | /* Prototypes for character input and output functions */ 30 | 31 | extern int32 fgetc(int); 32 | extern char *fgets(char *, int32, int32); 33 | extern int32 fputc(int32, int32); 34 | extern int32 fputs(char *, int32); 35 | extern int putchar(int c); 36 | extern int getchar(void); 37 | -------------------------------------------------------------------------------- /main/xsh_kill.c: -------------------------------------------------------------------------------- 1 | /* xsh_kill.c - xsh_kill */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_kill - obtain and print the current month, day, year, and time 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_kill(int nargs, char *args[]) { 12 | 13 | int32 retval; /* return value */ 14 | pid32 pid; /* ID of process to kill */ 15 | char ch; /* next character of argument */ 16 | char *chptr; /* walks along argument string */ 17 | 18 | /* Check argument count */ 19 | 20 | if (nargs != 2) { 21 | return SYSERR; 22 | } 23 | 24 | /* compute process ID from argument string */ 25 | 26 | chptr = args[1]; 27 | ch = *chptr++; 28 | pid = 0; 29 | while(ch != NULLCH) { 30 | if ( (ch < '0') || (ch > '9') ) { 31 | return 1; 32 | } 33 | pid = 10*pid + (ch - '0'); 34 | ch = *chptr++; 35 | } 36 | if (pid == 0) { 37 | return 1; 38 | } 39 | 40 | retval = kill(pid); 41 | if (retval == SYSERR) { 42 | //fprintf(stderr, "%s: cannot kill process %d\n", 43 | // args[0], pid); 44 | return 1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /apps/shell/xsh_kill.c: -------------------------------------------------------------------------------- 1 | /* xsh_kill.c - xsh_kill */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /*------------------------------------------------------------------------ 8 | * xsh_kill - obtain and print the current month, day, year, and time 9 | *------------------------------------------------------------------------ 10 | */ 11 | shellcmd xsh_kill(int nargs, char *args[]) { 12 | 13 | int32 retval; /* return value */ 14 | pid32 pid; /* ID of process to kill */ 15 | char ch; /* next character of argument */ 16 | char *chptr; /* walks along argument string */ 17 | 18 | /* Check argument count */ 19 | 20 | if (nargs != 2) { 21 | return SYSERR; 22 | } 23 | 24 | /* compute process ID from argument string */ 25 | 26 | chptr = args[1]; 27 | ch = *chptr++; 28 | pid = 0; 29 | while(ch != NULLCH) { 30 | if ( (ch < '0') || (ch > '9') ) { 31 | return 1; 32 | } 33 | pid = 10*pid + (ch - '0'); 34 | ch = *chptr++; 35 | } 36 | if (pid == 0) { 37 | return 1; 38 | } 39 | 40 | retval = kill(pid); 41 | if (retval == SYSERR) { 42 | //fprintf(stderr, "%s: cannot kill process %d\n", 43 | // args[0], pid); 44 | return 1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /device/lfs/lfscheck.c: -------------------------------------------------------------------------------- 1 | /* lfscheck.c - lfscheck */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * lfscheck - Check a directory to verify it contains a Xinu file system 8 | *------------------------------------------------------------------------ 9 | */ 10 | status lfscheck ( 11 | struct lfdir *dirptr /* Ptr to an in-core directory */ 12 | ) 13 | { 14 | uint32 reverse; /* LFS_ID in reverse byte order */ 15 | 16 | /* Verify the File System ID, all 0's and all 1's fields */ 17 | 18 | if ( (dirptr->lfd_fsysid != LFS_ID) || 19 | (dirptr->lfd_allzeros != 0x00000000) || 20 | (dirptr->lfd_allones != 0xffffffff) ) { 21 | return SYSERR; 22 | } 23 | 24 | /* Check the reverse-order File System ID field */ 25 | 26 | reverse = ((LFS_ID>>24) & 0x000000ff) | 27 | ((LFS_ID>> 8) & 0x0000ff00) | 28 | ((LFS_ID<< 8) & 0x00ff0000) | 29 | ((LFS_ID<<24) & 0xff000000) ; 30 | 31 | if (dirptr->lfd_revid != reverse) { 32 | return SYSERR; 33 | } 34 | 35 | /* Extra sanity check - verify file count is positive */ 36 | if (dirptr->lfd_nfiles < 0){ 37 | return SYSERR; 38 | } 39 | return OK; 40 | } 41 | -------------------------------------------------------------------------------- /device/tty/ttyputc.c: -------------------------------------------------------------------------------- 1 | /* ttyputc.c - ttyputc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttyputc - Write one character to a tty device (interrupts disabled) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ttyputc( 10 | // struct dentry *devptr, /* Entry in device switch table */ 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char ch /* Character to write */ 13 | ) 14 | { 15 | struct ttycblk *typtr; /* Pointer to tty control block */ 16 | 17 | typtr = &ttytab[devptr->dvminor]; 18 | 19 | /* Handle output CRLF by sending CR first */ 20 | 21 | if ( ch==TY_NEWLINE && typtr->tyocrlf ) { 22 | ttyputc(devptr, TY_RETURN); 23 | } 24 | 25 | wait(typtr->tyosem); /* Wait for space in queue */ 26 | *typtr->tyotail++ = ch; 27 | 28 | /* Wrap around to beginning of buffer, if needed */ 29 | 30 | if (typtr->tyotail >= &typtr->tyobuff[TY_OBUFLEN]) { 31 | typtr->tyotail = typtr->tyobuff; 32 | } 33 | 34 | /* Start output in case device is idle */ 35 | 36 | ttykickout((struct uart_csreg *)devptr->dvcsr); 37 | 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /include/icmp.h: -------------------------------------------------------------------------------- 1 | /* icmp.h - definintions for the Internet Control Message Protocol */ 2 | 3 | #define ICMP_SLOTS 10 /* num. of open ICMP endpoints */ 4 | #define ICMP_QSIZ 8 /* incoming packets per slot */ 5 | 6 | /* Constants for the state of an entry */ 7 | 8 | #define ICMP_FREE 0 /* entry is unused */ 9 | #define ICMP_USED 1 /* entry is being used */ 10 | #define ICMP_RECV 2 /* entry has a process waiting */ 11 | 12 | #define ICMP_HDR_LEN 8 /* bytes in an ICMP header */ 13 | 14 | /* ICMP message types for ping */ 15 | 16 | #define ICMP_ECHOREPLY 0 /* ICMP Echo Reply message */ 17 | #define ICMP_ECHOREQST 8 /* ICMP Echo Request message */ 18 | 19 | /* table of processes that are waiting for ping replies */ 20 | 21 | struct icmpentry { /* entry in the ICMP table */ 22 | int32 icstate; /* state of entry: free/used */ 23 | uint32 icremip; /* remote IP address */ 24 | int32 ichead; /* index of next packet to read */ 25 | int32 ictail; /* index of next slot to insert */ 26 | int32 iccount; /* count of packets enqueued */ 27 | pid32 icpid; /* ID of waiting process */ 28 | struct netpacket *icqueue[ICMP_QSIZ];/* circular packet queue */ 29 | }; 30 | 31 | extern struct icmpentry icmptab[]; /* table of UDP endpoints */ 32 | -------------------------------------------------------------------------------- /system/getbuf.c: -------------------------------------------------------------------------------- 1 | /* getbuf.c - getbuf */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getbuf - Get a buffer from a preestablished buffer pool 7 | *------------------------------------------------------------------------ 8 | */ 9 | char *getbuf( 10 | bpid32 poolid /* Index of pool in buftab */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct bpentry *bpptr; /* Pointer to entry in buftab */ 15 | struct bpentry *bufptr; /* Pointer to a buffer */ 16 | 17 | mask = disable(); 18 | 19 | /* Check arguments */ 20 | 21 | if ( (poolid < 0 || poolid >= nbpools) ) { 22 | restore(mask); 23 | return (char *)SYSERR; 24 | 25 | } 26 | bpptr = &buftab[poolid]; 27 | 28 | /* Wait for pool to have > 0 buffers and allocate a buffer */ 29 | 30 | wait(bpptr->bpsem); 31 | bufptr = bpptr->bpnext; 32 | 33 | /* Unlink buffer from pool */ 34 | 35 | bpptr->bpnext = bufptr->bpnext; 36 | 37 | /* Record pool ID in first four bytes of buffer and skip */ 38 | 39 | *(bpid32 *)bufptr = poolid; 40 | bufptr = (struct bpentry *)(sizeof(bpid32) + (char *)bufptr); 41 | restore(mask); 42 | return (char *)bufptr; 43 | } 44 | -------------------------------------------------------------------------------- /device/lfs/lflseek.c: -------------------------------------------------------------------------------- 1 | /* lflseek.c - lflseek */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflseek - Seek to a specified position in a file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflseek ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | uint32 offset /* Byte position in the file */ 12 | ) 13 | { 14 | struct lflcblk *lfptr; /* Ptr to open file table entry */ 15 | 16 | /* If file is not open, return an error */ 17 | 18 | lfptr = &lfltab[devptr->dvminor]; 19 | wait(lfptr->lfmutex); 20 | if (lfptr->lfstate != LF_USED) { 21 | signal(lfptr->lfmutex); 22 | return SYSERR; 23 | } 24 | 25 | /* Verify offset is within current file size */ 26 | 27 | if (offset > lfptr->lfdirptr->ld_size) { 28 | signal(lfptr->lfmutex); 29 | return SYSERR; 30 | } 31 | 32 | /* Record new offset and invalidate byte pointer (i.e., force */ 33 | /* the index and data blocks to be replaced if a successive */ 34 | /* call is made to read or write) */ 35 | 36 | lfptr->lfpos = offset; 37 | lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ]; 38 | 39 | signal(lfptr->lfmutex); 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /config/conf.c: -------------------------------------------------------------------------------- 1 | /* conf.c (GENERATED FILE; DO NOT EDIT) */ 2 | 3 | #include 4 | 5 | 6 | extern devcall ioerr(void); 7 | extern devcall ionull(void); 8 | 9 | /* Device independent I/O switch */ 10 | 11 | struct dentry devtab[] = 12 | { 13 | /** 14 | * Format of entries is: 15 | * dev-number, minor-number, dev-name, 16 | * init, open, close, 17 | * read, write, seek, 18 | * getc, putc, control, 19 | * dev-csr-address, intr-handler, irq 20 | */ 21 | 22 | /* CONSOLE is tty */ 23 | { 0, 0, "CONSOLE", 24 | (void *)ttyinit, (void *)ionull, (void *)ionull, 25 | (void *)ttyread, (void *)ttywrite, (void *)ioerr, 26 | (void *)ttygetc, (void *)ttyputc, (void *)ttycontrol, 27 | (void *)0x40013800, (void *)ttyhandler, 53 }, 28 | 29 | /* NULLDEV is null */ 30 | { 1, 0, "NULLDEV", 31 | (void *)ionull, (void *)ionull, (void *)ionull, 32 | (void *)ionull, (void *)ionull, (void *)ioerr, 33 | (void *)ionull, (void *)ionull, (void *)ioerr, 34 | (void *)0x0, (void *)ioerr, 0 }, 35 | 36 | /* NAMESPACE is nam */ 37 | { 2, 0, "NAMESPACE", 38 | (void *)naminit, (void *)namopen, (void *)ioerr, 39 | (void *)ioerr, (void *)ioerr, (void *)ioerr, 40 | (void *)ioerr, (void *)ioerr, (void *)ioerr, 41 | (void *)0x0, (void *)ioerr, 0 } 42 | }; 43 | -------------------------------------------------------------------------------- /apps/example4/main.c: -------------------------------------------------------------------------------- 1 | /* ex4.c - main, produce, consume */ 2 | 3 | #include 4 | 5 | void produce(void), consume(void); 6 | 7 | int32 n = 0; /* external variables are shared by all processes */ 8 | 9 | /*------------------------------------------------------------------------ 10 | * main -- example of unsynchronized producer and consumer processes 11 | *------------------------------------------------------------------------ 12 | */ 13 | void main(void) 14 | { 15 | resume( create(consume, 256, 20, "cons", 0) ); 16 | resume( create(produce, 256, 20, "prod", 0) ); 17 | } 18 | 19 | /*------------------------------------------------------------------------ 20 | * produce -- increment n 2000 times and exit 21 | *------------------------------------------------------------------------ 22 | */ 23 | void produce(void) 24 | { 25 | int32 i; 26 | 27 | for( i=1 ; i<=2000 ; i++ ) 28 | n++; 29 | } 30 | 31 | /*------------------------------------------------------------------------ 32 | * consume -- print n 2000 times and exit 33 | *------------------------------------------------------------------------ 34 | */ 35 | void consume(void) 36 | { 37 | int32 i; 38 | 39 | for( i=1 ; i<=2000 ; i++ ) 40 | printf("The value of n is %d \n", n); 41 | } 42 | -------------------------------------------------------------------------------- /include/memory.h: -------------------------------------------------------------------------------- 1 | /* memory.h - roundmb, truncmb, freestk */ 2 | 3 | /* avr specific values. Original saved under orig/ folder */ 4 | 5 | #define PAGE_SIZE 1024 // TODO: unused? 6 | 7 | /*---------------------------------------------------------------------- 8 | * roundmb, truncmb - Round or truncate address to memory block size 9 | *---------------------------------------------------------------------- 10 | */ 11 | #define roundmb(x) (char *)( (7 + (uint32)(x)) & (~7) ) 12 | #define truncmb(x) (char *)( ((uint32)(x)) & (~7) ) 13 | 14 | /*---------------------------------------------------------------------- 15 | * freestk -- Free stack memory allocated by getstk 16 | *---------------------------------------------------------------------- 17 | */ 18 | #define freestk(p,len) freemem((char *)((uint32)(p) \ 19 | - ((uint32)roundmb(len)) \ 20 | + (uint32)sizeof(uint32)), \ 21 | (uint32)roundmb(len) ) 22 | 23 | struct memblk { /* See roundmb & truncmb */ 24 | struct memblk *mnext; /* Ptr to next free memory blk */ 25 | uint32 mlength; /* Size of blk (includes memblk)*/ 26 | }; 27 | extern struct memblk memlist; /* Head of free memory list */ 28 | extern void *minheap; /* Start of heap */ 29 | extern void *maxheap; /* Highest valid heap address */ 30 | -------------------------------------------------------------------------------- /system/suspend.c: -------------------------------------------------------------------------------- 1 | /* suspend.c - suspend */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * suspend - Suspend a process, placing it in hibernation 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall suspend( 10 | pid32 pid /* ID of process to suspend */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct procent *prptr; /* Ptr to process's table entry */ 15 | pri16 prio; /* Priority to return */ 16 | 17 | mask = disable(); 18 | if (isbadpid(pid) || (pid == NULLPROC)) { 19 | restore(mask); 20 | return SYSERR; 21 | } 22 | 23 | /* Only suspend a process that is current or ready */ 24 | 25 | prptr = &proctab[pid]; 26 | if ((prptr->prstate != PR_CURR) && (prptr->prstate != PR_READY)) { 27 | restore(mask); 28 | return SYSERR; 29 | } 30 | if (prptr->prstate == PR_READY) { 31 | getitem(pid); /* Remove a ready process */ 32 | /* from the ready list */ 33 | prptr->prstate = PR_SUSP; 34 | } else { 35 | prptr->prstate = PR_SUSP; /* Mark the current process */ 36 | resched(); /* suspended and resched. */ 37 | } 38 | prio = prptr->prprio; 39 | restore(mask); 40 | return prio; 41 | } 42 | -------------------------------------------------------------------------------- /system/conf.c: -------------------------------------------------------------------------------- 1 | /* conf.c (GENERATED FILE; DO NOT EDIT) */ 2 | 3 | #include 4 | 5 | 6 | extern devcall ioerr(void); 7 | extern devcall ionull(void); 8 | 9 | /* Device independent I/O switch */ 10 | 11 | const __flash struct dentry devtab[] = 12 | { 13 | /** 14 | * Format of entries is: 15 | * dev-number, minor-number, dev-name, 16 | * init, open, close, 17 | * read, write, seek, 18 | * getc, putc, control, 19 | * dev-csr-address, intr-handler, irq 20 | */ 21 | 22 | /* CONSOLE is tty */ 23 | { 0, 0, "CONSOLE", 24 | (void *)ttyinit, (void *)ionull, (void *)ionull, 25 | (void *)ttyread, (void *)ttywrite, (void *)ioerr, 26 | (void *)ttygetc, (void *)ttyputc, (void *)ttycontrol, 27 | (void *)0x40013800, (void *)ttyhandler, 53 }, 28 | 29 | /* NULLDEV is null */ 30 | { 1, 0, "NULLDEV", 31 | (void *)ionull, (void *)ionull, (void *)ionull, 32 | (void *)ionull, (void *)ionull, (void *)ioerr, 33 | (void *)ionull, (void *)ionull, (void *)ioerr, 34 | (void *)0x0, (void *)ioerr, 0 }, 35 | 36 | /* NAMESPACE is nam */ 37 | { 2, 0, "NAMESPACE", 38 | (void *)naminit, (void *)namopen, (void *)ioerr, 39 | (void *)ioerr, (void *)ioerr, (void *)ioerr, 40 | (void *)ioerr, (void *)ioerr, (void *)ioerr, 41 | (void *)0x0, (void *)ioerr, 0 } 42 | }; 43 | -------------------------------------------------------------------------------- /include/ports.h: -------------------------------------------------------------------------------- 1 | /* ports.h - isbadport */ 2 | 3 | /* avr specific values. Original saved under orig/ folder */ 4 | 5 | #define NPORTS 3 /* Maximum number of ports */ 6 | #define PT_MSGS 10 /* Total messages in system */ 7 | #define PT_FREE 1 /* Port is free */ 8 | #define PT_LIMBO 2 /* Port is being deleted/reset */ 9 | #define PT_ALLOC 3 /* Port is allocated */ 10 | 11 | struct ptnode { /* Node on list of messages */ 12 | uint32 ptmsg; /* A one-word message */ 13 | struct ptnode *ptnext; /* Pointer to next node on list */ 14 | }; 15 | 16 | struct ptentry { /* Entry in the port table */ 17 | sid32 ptssem; /* Sender semaphore */ 18 | sid32 ptrsem; /* Receiver semaphore */ 19 | uint16 ptstate; /* Port state (FREE/LIMBO/ALLOC)*/ 20 | uint16 ptmaxcnt; /* Max messages to be queued */ 21 | int32 ptseq; /* Sequence changed at creation */ 22 | struct ptnode *pthead; /* List of message pointers */ 23 | struct ptnode *pttail; /* Tail of message list */ 24 | }; 25 | 26 | extern struct ptnode *ptfree; /* List of free nodes */ 27 | extern struct ptentry porttab[]; /* Port table */ 28 | extern int32 ptnextid; /* Next port ID to try when */ 29 | /* looking for a free slot */ 30 | 31 | #define isbadport(portid) ( (portid)<0 || (portid)>=NPORTS ) 32 | -------------------------------------------------------------------------------- /system/insertd.c: -------------------------------------------------------------------------------- 1 | /* insertd.c - insertd */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * insertd - Insert a process in delta list using delay as the key 7 | *------------------------------------------------------------------------ 8 | */ 9 | status insertd( /* Assumes interrupts disabled */ 10 | pid32 pid, /* ID of process to insert */ 11 | qid16 q, /* ID of queue to use */ 12 | uint16 key /* Delay from "now" (in ms.) */ 13 | ) 14 | { 15 | int32 next; /* Runs through the delta list */ 16 | int32 prev; /* Follows next through the list*/ 17 | 18 | if (isbadqid(q) || isbadpid(pid)) { 19 | return SYSERR; 20 | } 21 | 22 | prev = queuehead(q); 23 | next = queuetab[queuehead(q)].qnext; 24 | while ((next != queuetail(q)) && (queuetab[next].qkey <= key)) { 25 | key -= queuetab[next].qkey; 26 | prev = next; 27 | next = queuetab[next].qnext; 28 | } 29 | 30 | /* Insert new node between prev and next nodes */ 31 | 32 | queuetab[pid].qnext = next; 33 | queuetab[pid].qprev = prev; 34 | queuetab[pid].qkey = key; 35 | queuetab[prev].qnext = pid; 36 | queuetab[next].qprev = pid; 37 | if (next != queuetail(q)) { 38 | queuetab[next].qkey -= key; 39 | } 40 | 41 | return OK; 42 | } 43 | -------------------------------------------------------------------------------- /device/lfs/lfibput.c: -------------------------------------------------------------------------------- 1 | /* lfibput.c - lfibput */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfibput - Write an index block to disk given its ID (assumes 7 | * mutex is held) 8 | *------------------------------------------------------------------------ 9 | */ 10 | status lfibput( 11 | did32 diskdev, /* ID of disk device */ 12 | ibid32 inum, /* ID of index block to write */ 13 | struct lfiblk *ibuff /* Buffer holding the index blk */ 14 | ) 15 | { 16 | dbid32 diskblock; /* ID of disk sector (block) */ 17 | char *from, *to; /* Pointers used in copying */ 18 | int32 i; /* Loop index used during copy */ 19 | char dbuff[LF_BLKSIZ]; /* Temp. buffer to hold d-block */ 20 | 21 | /* Compute disk block number and offset of index block */ 22 | 23 | diskblock = ib2sect(inum); 24 | to = dbuff + ib2disp(inum); 25 | from = (char *)ibuff; 26 | 27 | /* Read disk block */ 28 | 29 | if (read(diskdev, dbuff, diskblock) == SYSERR) { 30 | return SYSERR; 31 | } 32 | 33 | /* Copy index block into place */ 34 | 35 | for (i=0 ; i 4 | 5 | /*------------------------------------------------------------------------ 6 | * recvtime - Wait specified time to receive a message and return 7 | *------------------------------------------------------------------------ 8 | */ 9 | umsg32 recvtime( 10 | int32 maxwait /* Ticks to wait before timeout */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct procent *prptr; /* Tbl entry of current process */ 15 | umsg32 msg; /* Message to return */ 16 | 17 | if (maxwait < 0) { 18 | return SYSERR; 19 | } 20 | mask = disable(); 21 | 22 | /* Schedule wakeup and place process in timed-receive state */ 23 | 24 | prptr = &proctab[currpid]; 25 | if (prptr->prhasmsg == FALSE) { /* Delay if no message waiting */ 26 | if (insertd(currpid,sleepq,maxwait) == SYSERR) { 27 | restore(mask); 28 | return SYSERR; 29 | } 30 | prptr->prstate = PR_RECTIM; 31 | resched(); 32 | } 33 | 34 | /* Either message arrived or timer expired */ 35 | 36 | if (prptr->prhasmsg) { 37 | msg = prptr->prmsg; /* Retrieve message */ 38 | prptr->prhasmsg = FALSE;/* Reset message indicator */ 39 | } else { 40 | msg = TIMEOUT; 41 | } 42 | restore(mask); 43 | return msg; 44 | } 45 | -------------------------------------------------------------------------------- /apps/README.md: -------------------------------------------------------------------------------- 1 | ### Several applications for getting started 2 | 3 | ``` 4 | example0 : basic Xinu app for quick start 5 | 6 | example1 : write "hi" on the console 7 | 8 | 9 | example2 : example of creating processes in Xinu: 10 | sndA -- repeatedly emit 'A' on the console without terminating 11 | sndB -- repeatedly emit 'B' on the console without terminating 12 | 13 | example3 : example of 2 processes executing the same code concurrently 14 | sndch -- output a character on a serial device indefinitely 15 | 16 | example4 : main, produce, consume 17 | n = 0; /* external variables are shared by all processes 18 | main -- example of unsynchronized producer and consumer processes 19 | produce -- increment n 2000 times and exit 20 | consume -- print n 2000 times and exit 21 | 22 | example5 : main, prod2, cons2 */ 23 | n = 0; /* external variables are shared by all processes 24 | main -- producer and consumer processes synchronized with 25 | semaphores 26 | prod2 -- increment n 2000 times, waiting for it to be consumed 27 | cons2 -- print n 2000 times, waiting for it to be produced 28 | 29 | shell : the Xinu Shell application 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /main/xsh_uptime.c: -------------------------------------------------------------------------------- 1 | /* xsh_uptime.c - xsh_uptime */ 2 | #include 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_uptime - shell to print the time the system has been up 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_uptime(int nargs, char *args[]) 11 | { 12 | long days, hrs, mins, secs; /* days, hours, minutes, and */ 13 | /* seconds since system boot */ 14 | long secperday = 86400; /* seconds in a day */ 15 | long secperhr = 3600; /* seconds in an hour */ 16 | long secpermin = 60; /* seconds in a minute */ 17 | 18 | /* Check for valid number of arguments */ 19 | 20 | if (nargs > 1) { 21 | return 1; 22 | } 23 | 24 | secs = clktime; /* total seconds since boot */ 25 | 26 | /* subtract number of whole days */ 27 | 28 | days = secs/secperday; 29 | secs -= days*secperday; 30 | 31 | /* subtract number of hours */ 32 | 33 | hrs = secs/secperhr; 34 | secs -= hrs*secperhr; 35 | 36 | /* subtract number of minutes */ 37 | 38 | mins = secs/secpermin; 39 | secs -= mins*secpermin; 40 | 41 | printf("\r\n%d day(s) &", days); 42 | printf(" %dh:", hrs); 43 | printf("%dm:", mins); 44 | printf("%ds\r\n\n", secs); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /system/mark.c: -------------------------------------------------------------------------------- 1 | /* mark.c - markinit, mark */ 2 | 3 | #include 4 | 5 | int32 *marks[MAXMARK]; /* Pointers to marked locations */ 6 | int32 nmarks; /* Number of marked locations */ 7 | sid32 mkmutex; /* Mutual exclusion semaphore */ 8 | 9 | /*------------------------------------------------------------------------ 10 | * markinit - Called once at system startup 11 | *------------------------------------------------------------------------ 12 | */ 13 | void markinit(void) 14 | { 15 | nmarks = 0; 16 | mkmutex = semcreate(1); 17 | } 18 | 19 | 20 | /*------------------------------------------------------------------------ 21 | * mark - Mark a specified memory location 22 | *------------------------------------------------------------------------ 23 | */ 24 | status mark( 25 | int32 *loc /* Location to mark */ 26 | ) 27 | { 28 | 29 | /* If location is already marked, do nothing */ 30 | 31 | if ( (*loc>=0) && (*loc= MAXMARK) { 38 | return SYSERR; 39 | } 40 | 41 | /* Obtain exclusive access and mark the specified location */ 42 | 43 | wait(mkmutex); 44 | marks[ (*loc) = nmarks++ ] = loc; 45 | signal(mkmutex); 46 | return OK; 47 | } 48 | -------------------------------------------------------------------------------- /apps/shell/xsh_uptime.c: -------------------------------------------------------------------------------- 1 | /* xsh_uptime.c - xsh_uptime */ 2 | #include 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * xsh_uptime - shell to print the time the system has been up 8 | *------------------------------------------------------------------------ 9 | */ 10 | shellcmd xsh_uptime(int nargs, char *args[]) 11 | { 12 | long days, hrs, mins, secs; /* days, hours, minutes, and */ 13 | /* seconds since system boot */ 14 | long secperday = 86400; /* seconds in a day */ 15 | long secperhr = 3600; /* seconds in an hour */ 16 | long secpermin = 60; /* seconds in a minute */ 17 | 18 | /* Check for valid number of arguments */ 19 | 20 | if (nargs > 1) { 21 | return 1; 22 | } 23 | 24 | secs = clktime; /* total seconds since boot */ 25 | 26 | /* subtract number of whole days */ 27 | 28 | days = secs/secperday; 29 | secs -= days*secperday; 30 | 31 | /* subtract number of hours */ 32 | 33 | hrs = secs/secperhr; 34 | secs -= hrs*secperhr; 35 | 36 | /* subtract number of minutes */ 37 | 38 | mins = secs/secpermin; 39 | secs -= mins*secpermin; 40 | 41 | printf("\r\n%d day(s) &", days); 42 | printf(" %dh:", hrs); 43 | printf("%dm:", mins); 44 | printf("%ds\r\n\n", secs); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /device/lfs/lfdballoc.c: -------------------------------------------------------------------------------- 1 | /* lfdballoc.c - lfdballoc */ 2 | 3 | #include 4 | 5 | #define DFILL '+' /* character used to fill a disk block */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * lfdballoc - Allocate a new data block from free list on disk 9 | * (assumes directory mutex held) 10 | *------------------------------------------------------------------------ 11 | */ 12 | dbid32 lfdballoc ( 13 | struct lfdbfree *dbuff /* Addr. of buffer to hold data block */ 14 | ) 15 | { 16 | dbid32 dnum; /* ID of next d-block on the free list */ 17 | int32 retval; /* Return value */ 18 | 19 | /* Get the ID of first data block on the free list */ 20 | 21 | dnum = Lf_data.lf_dir.lfd_dfree; 22 | if (dnum == LF_DNULL) { /* Ran out of free data blocks */ 23 | panic("out of data blocks"); 24 | } 25 | retval = read(Lf_data.lf_dskdev, (char *)dbuff, dnum); 26 | if (retval == SYSERR) { 27 | panic("lfdballoc cannot read disk block\n\r"); 28 | } 29 | 30 | /* Unlink d-block from in-memory directory */ 31 | 32 | Lf_data.lf_dir.lfd_dfree = dbuff->lf_nextdb; 33 | write(Lf_data.lf_dskdev, (char *)&Lf_data.lf_dir, LF_AREA_DIR); 34 | Lf_data.lf_dirdirty = FALSE; 35 | 36 | /* Fill data block to erase old data */ 37 | 38 | memset((char *)dbuff, DFILL, LF_BLKSIZ); 39 | return dnum; 40 | } 41 | -------------------------------------------------------------------------------- /device/lfs/lflcontrol.c: -------------------------------------------------------------------------------- 1 | /* lflcontrol.c - lflcontrol */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflcontrol - Provide control functions for a local file pseudo-device 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflcontrol ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | int32 func, /* A control function */ 12 | int32 arg1, /* Argument #1 */ 13 | int32 arg2 /* Argument #2 */ 14 | ) 15 | { 16 | struct lflcblk *lfptr; /* Ptr to open file table entry */ 17 | int32 retval; /* Return value from func. call */ 18 | 19 | /* Obtain exclusive use of the file */ 20 | 21 | lfptr = &lfltab[devptr->dvminor]; 22 | wait(lfptr->lfmutex); 23 | 24 | /* If file is not open, return an error */ 25 | 26 | if (lfptr->lfstate != LF_USED) { 27 | signal(lfptr->lfmutex); 28 | return SYSERR; 29 | } 30 | 31 | switch (func) { 32 | 33 | /* Truncate a file */ 34 | 35 | case LF_CTL_TRUNC: 36 | wait(Lf_data.lf_mutex); 37 | retval = lftruncate(lfptr); 38 | signal(Lf_data.lf_mutex); 39 | signal(lfptr->lfmutex); 40 | return retval; 41 | 42 | default: 43 | kprintf("lfcontrol: function %d not valid\n\r", func); 44 | signal(lfptr->lfmutex); 45 | return SYSERR; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /device/rfs/rfsndmsg.c: -------------------------------------------------------------------------------- 1 | /* rfsndmsg.c - rfsndmsg */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rfsndmsg - Create and send a message that only has header fields 7 | *------------------------------------------------------------------------ 8 | */ 9 | status rfsndmsg ( 10 | uint16 type, /* Message type */ 11 | char *name /* Null-terminated file name */ 12 | ) 13 | { 14 | struct rf_msg_hdr req; /* Request message to send */ 15 | struct rf_msg_hdr resp; /* Buffer for response */ 16 | int32 retval; /* Return value */ 17 | char *to; /* Used during name copy */ 18 | 19 | /* Form a request */ 20 | 21 | req.rf_type = htons(type); 22 | req.rf_status = htons(0); 23 | req.rf_seq = 0; /* Rfscomm will set sequence */ 24 | to = req.rf_name; 25 | while ( (*to++ = *name++) ) { /* Copy name to request */ 26 | ; 27 | } 28 | 29 | /* Send message and receive response */ 30 | 31 | retval = rfscomm(&req, sizeof(struct rf_msg_hdr), 32 | &resp, sizeof(struct rf_msg_hdr) ); 33 | 34 | /* Check response */ 35 | 36 | if (retval == SYSERR) { 37 | return SYSERR; 38 | } else if (retval == TIMEOUT) { 39 | kprintf("Timeout during remote file server access\n"); 40 | return SYSERR; 41 | } else if (ntohl(resp.rf_status) != 0) { 42 | return SYSERR; 43 | } 44 | 45 | return OK; 46 | } 47 | -------------------------------------------------------------------------------- /include/udp.h: -------------------------------------------------------------------------------- 1 | /* udp.h - Declarations pertaining to User Datagram Protocol (UDP) */ 2 | 3 | #define UDP_SLOTS 6 /* Number of open UDP endpoints */ 4 | #define UDP_QSIZ 8 /* Packets enqueued per endpoint*/ 5 | 6 | #define UDP_DHCP_CPORT 68 /* Port number for DHCP client */ 7 | #define UDP_DHCP_SPORT 67 /* Port number for DHCP server */ 8 | 9 | /* Constants for the state of an entry */ 10 | 11 | #define UDP_FREE 0 /* Entry is unused */ 12 | #define UDP_USED 1 /* Entry is being used */ 13 | #define UDP_RECV 2 /* Entry has a process waiting */ 14 | 15 | #define UDP_ANYIF -2 /* Register an endpoint for any */ 16 | /* interface on the machine */ 17 | 18 | #define UDP_HDR_LEN 8 /* Bytes in a UDP header */ 19 | 20 | struct udpentry { /* Entry in the UDP endpoint tbl*/ 21 | int32 udstate; /* State of entry: free/used */ 22 | uint32 udremip; /* Remote IP address (zero */ 23 | /* means "don't care") */ 24 | uint16 udremport; /* Remote protocol port number */ 25 | uint16 udlocport; /* Local protocol port number */ 26 | int32 udhead; /* Index of next packet to read */ 27 | int32 udtail; /* Index of next slot to insert */ 28 | int32 udcount; /* Count of packets enqueued */ 29 | pid32 udpid; /* ID of waiting process */ 30 | struct netpacket *udqueue[UDP_QSIZ];/* Circular packet queue */ 31 | }; 32 | 33 | extern struct udpentry udptab[]; 34 | -------------------------------------------------------------------------------- /system/unsleep.c: -------------------------------------------------------------------------------- 1 | /* unsleep.c - unsleep */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * unsleep - Internal function to remove a process from the sleep 7 | * queue prematurely. The caller must adjust the delay 8 | * of successive processes. 9 | *------------------------------------------------------------------------ 10 | */ 11 | status unsleep( 12 | pid32 pid /* ID of process to remove */ 13 | ) 14 | { 15 | intmask mask; /* Saved interrupt mask */ 16 | struct procent *prptr; /* Ptr to process's table entry */ 17 | 18 | pid32 pidnext; /* ID of process on sleep queue */ 19 | /* that follows the process */ 20 | /* which is being removed */ 21 | 22 | mask = disable(); 23 | 24 | if (isbadpid(pid)) { 25 | restore(mask); 26 | return SYSERR; 27 | } 28 | 29 | /* Verify that candidate process is on the sleep queue */ 30 | 31 | prptr = &proctab[pid]; 32 | if ((prptr->prstate!=PR_SLEEP) && (prptr->prstate!=PR_RECTIM)) { 33 | restore(mask); 34 | return SYSERR; 35 | } 36 | 37 | /* Increment delay of next process if such a process exists */ 38 | 39 | pidnext = queuetab[pid].qnext; 40 | if (pidnext < NPROC) { 41 | queuetab[pidnext].qkey += queuetab[pid].qkey; 42 | } 43 | 44 | getitem(pid); /* Unlink process from queue */ 45 | restore(mask); 46 | return OK; 47 | } 48 | -------------------------------------------------------------------------------- /system/clkinit.c: -------------------------------------------------------------------------------- 1 | /* clkinit.c */ 2 | 3 | /* avr specific */ 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | uint32 clktime; /* Seconds since boot */ 11 | unsigned long count1000; /* ms since last clock tick */ 12 | qid16 sleepq; /* Queue of sleeping processes */ 13 | unsigned long preempt; /* Preemption counter */ 14 | 15 | /*------------------------------------------------------------------------ 16 | * clkinit - Initialize the clock and sleep queue at startup 17 | *------------------------------------------------------------------------ 18 | */ 19 | void clkinit(void) 20 | { 21 | 22 | struct clock_csreg * clockptr; 23 | 24 | sleepq = newqueue(); /* Allocate a queue to hold the delta */ 25 | /* list of sleeping processes */ 26 | preempt = QUANTUM; /* Set the preemption time */ 27 | clktime = 0; /* Start counting seconds */ 28 | count1000 = 0; 29 | 30 | 31 | /* 32 | * AVR atmega328p timer/clock init: interrupt every 1ms 33 | * The AVR TIMER interrupt rutine is in clkhandler.c 34 | */ 35 | TCCR0B |= (1< 4 | 5 | #define MAXSECONDS 2147483 /* Max seconds per 32-bit msec */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * sleep - Delay the calling process n seconds 9 | *------------------------------------------------------------------------ 10 | */ 11 | syscall sleep( 12 | int32 delay /* Time to delay in seconds */ 13 | ) 14 | { 15 | if ( (delay < 0) || (delay > MAXSECONDS) ) { 16 | return SYSERR; 17 | } 18 | sleepms(1000*delay); 19 | return OK; 20 | } 21 | 22 | /*------------------------------------------------------------------------ 23 | * sleepms - Delay the calling process n x 1000 milliseconds 24 | * for example: 1 second = sleepms(1000) 25 | * avr atmega328p specific 26 | *------------------------------------------------------------------------ 27 | */ 28 | syscall sleepms( 29 | int32 delay /* Time to delay in msec. */ 30 | ) 31 | { 32 | intmask mask; /* Saved interrupt mask */ 33 | 34 | if (delay < 0) { 35 | return SYSERR; 36 | } 37 | 38 | if (delay == 0) { 39 | yield(); 40 | return OK; 41 | } 42 | 43 | /* Delay calling process */ 44 | 45 | mask = disable(); 46 | if (insertd(currpid, sleepq, delay) == SYSERR) { 47 | restore(mask); 48 | return SYSERR; 49 | } 50 | 51 | proctab[currpid].prstate = PR_SLEEP; 52 | resched(); 53 | restore(mask); 54 | return OK; 55 | } 56 | -------------------------------------------------------------------------------- /device/tty/ttygetc.c: -------------------------------------------------------------------------------- 1 | /* ttygetc.c - ttygetc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttygetc - Read one character from a tty device (interrupts disabled) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ttygetc( 10 | // struct dentry *devptr /* Entry in device switch table */ 11 | const __flash struct dentry *devptr /* Entry in device switch table */ 12 | ) 13 | { 14 | char ch; /* Character to return */ 15 | struct ttycblk *typtr; /* Pointer to ttytab entry */ 16 | 17 | typtr = &ttytab[devptr->dvminor]; 18 | 19 | /* Wait for a character in the buffer and extract one character */ 20 | 21 | wait(typtr->tyisem); 22 | 23 | // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER 24 | // ch = 0; // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER 25 | // while (ch == 0) { // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER 26 | 27 | ch = *typtr->tyihead++; 28 | 29 | // } // RAFA : HORRIBLE WORKAROUND TO THE BUG FOREVER 30 | 31 | /* Wrap around to beginning of buffer, if needed */ 32 | 33 | if (typtr->tyihead >= &typtr->tyibuff[TY_IBUFLEN]) { 34 | typtr->tyihead = typtr->tyibuff; 35 | } 36 | 37 | /* In cooked mode, check for the EOF character */ 38 | 39 | if ( (typtr->tyimode == TY_IMCOOKED) && (typtr->tyeof) && 40 | (ch == typtr->tyeofch) ) { 41 | return (devcall)EOF; 42 | } 43 | 44 | return (devcall)ch; 45 | } 46 | -------------------------------------------------------------------------------- /include/testsuite.h: -------------------------------------------------------------------------------- 1 | /* testsuite.h - failif */ 2 | 3 | process test_addargs(bool8); 4 | process test_bigargs(bool8); 5 | process test_schedule(bool8 verbose); 6 | process test_preempt(bool8 verbose); 7 | process test_recursion(bool8 verbose); 8 | process test_semaphore(bool8 verbose); 9 | process test_semaphore2(bool8 verbose); 10 | process test_semaphore3(bool8 verbose); 11 | process test_semaphore4(bool8 verbose); 12 | process test_semaphore5(bool8 verbose); 13 | process test_libStdio(bool8 verbose); 14 | 15 | void testPass(bool8, const char *); 16 | void testFail(bool8, const char *); 17 | void testSkip(bool8, const char *); 18 | void testPrint(bool8, const char *); 19 | 20 | /*------------------------------------------------------------------------ 21 | * failif - report failure by displaying a message is condition is met 22 | *------------------------------------------------------------------------ 23 | */ 24 | #define failif(cond, failmsg) \ 25 | if ( cond ) { testFail(verbose, failmsg); passed = FALSE; } \ 26 | else { testPass(verbose, ""); } 27 | 28 | /* Define the strcuture of an entry in the table of test cases */ 29 | 30 | struct testcase { 31 | char *name; /* Name of test case */ 32 | process (*test) (bool8);/* Test case function */ 33 | }; 34 | 35 | extern int ntests; /* total number of tests */ 36 | extern struct testcase testtab[]; /* table of test cases */ 37 | 38 | #define TESTSTK 8192 /* size of process stack used for test */ 39 | -------------------------------------------------------------------------------- /system/getmem.c: -------------------------------------------------------------------------------- 1 | /* getmem.c - getmem */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getmem - Allocate heap storage, returning lowest word address 7 | *------------------------------------------------------------------------ 8 | */ 9 | char *getmem( 10 | uint32 nbytes /* Size of memory requested */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct memblk *prev, *curr, *leftover; 15 | 16 | mask = disable(); 17 | if (nbytes == 0) { 18 | restore(mask); 19 | return (char *)SYSERR; 20 | } 21 | 22 | nbytes = (uint32) roundmb(nbytes); /* Use memblk multiples */ 23 | 24 | prev = &memlist; 25 | curr = memlist.mnext; 26 | while (curr != NULL) { /* Search free list */ 27 | 28 | if (curr->mlength == nbytes) { /* Block is exact match */ 29 | prev->mnext = curr->mnext; 30 | memlist.mlength -= nbytes; 31 | restore(mask); 32 | return (char *)(curr); 33 | 34 | } else if (curr->mlength > nbytes) { /* Split big block */ 35 | leftover = (struct memblk *)((uint32) curr + 36 | nbytes); 37 | prev->mnext = leftover; 38 | leftover->mnext = curr->mnext; 39 | leftover->mlength = curr->mlength - nbytes; 40 | memlist.mlength -= nbytes; 41 | restore(mask); 42 | return (char *)(curr); 43 | } else { /* Move to next block */ 44 | prev = curr; 45 | curr = curr->mnext; 46 | } 47 | } 48 | restore(mask); 49 | return (char *)SYSERR; 50 | } 51 | -------------------------------------------------------------------------------- /system/semcreate.c: -------------------------------------------------------------------------------- 1 | /* semcreate.c - semcreate, newsem */ 2 | 3 | #include 4 | 5 | local sid32 newsem(void); 6 | 7 | /*------------------------------------------------------------------------ 8 | * semcreate - Create a new semaphore and return the ID to the caller 9 | *------------------------------------------------------------------------ 10 | */ 11 | sid32 semcreate( 12 | int32 count /* Initial semaphore count */ 13 | ) 14 | { 15 | intmask mask; /* Saved interrupt mask */ 16 | sid32 sem; /* Semaphore ID to return */ 17 | 18 | mask = disable(); 19 | 20 | if (count < 0 || ((sem=newsem())==SYSERR)) { 21 | restore(mask); 22 | return SYSERR; 23 | } 24 | semtab[sem].scount = count; /* Initialize table entry */ 25 | 26 | restore(mask); 27 | return sem; 28 | } 29 | 30 | /*------------------------------------------------------------------------ 31 | * newsem - Allocate an unused semaphore and return its index 32 | *------------------------------------------------------------------------ 33 | */ 34 | local sid32 newsem(void) 35 | { 36 | static sid32 nextsem = 0; /* Next semaphore index to try */ 37 | sid32 sem; /* Semaphore ID to return */ 38 | int32 i; /* Iterate through # entries */ 39 | 40 | for (i=0 ; i= NSEM) 43 | nextsem = 0; 44 | if (semtab[sem].sstate == S_FREE) { 45 | semtab[sem].sstate = S_USED; 46 | return sem; 47 | } 48 | } 49 | return SYSERR; 50 | } 51 | -------------------------------------------------------------------------------- /include/limits.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file limits.h 3 | * 4 | * $Id: limits.h 2020 2009-08-13 17:50:08Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _LIMITS_H_ 9 | #define _LIMITS_H_ 10 | 11 | #define CHAR_BIT 8 /**< bits in a char */ 12 | #define CHAR_MAX 127 /**< maximum value of char */ 13 | #define CHAR_MIN (-128) /**< minimum value of char */ 14 | #define SCHAR_MAX 127 /**< maximum value of signed char */ 15 | #define SCHAR_MIN (-128) /**< minimum value of signed char */ 16 | #define UCHAR_MAX 255 /**< maximum value of unsigned char */ 17 | 18 | #define INT_MAX 2147483647 /**< maximum value of int */ 19 | #define INT_MIN (-INT_MAX-1) /**< minimum value of int */ 20 | #define UINT_MAX (2U*INT_MAX+1) /**< maximum value of unsigned int */ 21 | 22 | #define LONG_MAX 2147483647 /**< maximum value of int32 */ 23 | #define LONG_MIN (-LONG_MAX-1) /**< minimum value of int32 */ 24 | #define ULONG_MAX (2UL*LONG_MAX+1) /**< maximum value of unsigned int32 */ 25 | 26 | #define SHRT_MAX 32767 /**< maximum value of int16 */ 27 | #define SHRT_MIN (-SHRT_MAX-1) /**< minimum value of int16 */ 28 | #define USHRT_MAX 65535 /**< maximum value of unsigned int16 */ 29 | 30 | #endif /* _LIMITS_H_ */ 31 | -------------------------------------------------------------------------------- /system/kill.c: -------------------------------------------------------------------------------- 1 | /* kill.c - kill */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * kill - Kill a process and remove it from the system 7 | *------------------------------------------------------------------------ 8 | */ 9 | syscall kill( 10 | pid32 pid /* ID of process to kill */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct procent *prptr; /* Ptr to process's table entry */ 15 | int32 i; /* Index into descriptors */ 16 | 17 | mask = disable(); 18 | if (isbadpid(pid) || (pid == NULLPROC) 19 | || ((prptr = &proctab[pid])->prstate) == PR_FREE) { 20 | restore(mask); 21 | return SYSERR; 22 | } 23 | 24 | if (--prcount <= 1) { /* Last user process completes */ 25 | xdone(); 26 | } 27 | 28 | send(prptr->prparent, pid); 29 | for (i=0; i<3; i++) { 30 | close(prptr->prdesc[i]); 31 | } 32 | freestk(prptr->prstkbase, prptr->prstklen); 33 | 34 | switch (prptr->prstate) { 35 | case PR_CURR: 36 | prptr->prstate = PR_FREE; /* Suicide */ 37 | resched(); 38 | 39 | case PR_SLEEP: 40 | case PR_RECTIM: 41 | unsleep(pid); 42 | prptr->prstate = PR_FREE; 43 | break; 44 | 45 | case PR_WAIT: 46 | semtab[prptr->prsem].scount++; 47 | /* Fall through */ 48 | 49 | case PR_READY: 50 | getitem(pid); /* Remove from queue */ 51 | /* Fall through */ 52 | 53 | default: 54 | prptr->prstate = PR_FREE; 55 | } 56 | 57 | restore(mask); 58 | return OK; 59 | } 60 | -------------------------------------------------------------------------------- /include/queue.h: -------------------------------------------------------------------------------- 1 | /* queue.h - firstid, firstkey, isempty, lastkey, nonempty */ 2 | 3 | /* Queue structure declarations, constants, and inline functions */ 4 | 5 | /* Default # of queue entries: 1 per process plus 2 for ready list plus */ 6 | /* 2 for sleep list plus 2 per semaphore */ 7 | #ifndef NQENT 8 | #define NQENT (NPROC + 4 + NSEM + NSEM) 9 | #endif 10 | 11 | #define EMPTY (-1) /* Null value for qnext or qprev index */ 12 | #define MAXKEY 0x7FFFFFFF /* Max key that can be stored in queue */ 13 | #define MINKEY 0x80000000 /* Min key that can be stored in queue */ 14 | 15 | struct qentry { /* One per process plus two per list */ 16 | uint16 qkey; /* Key on which the queue is ordered */ 17 | // int32 qkey; /* Key on which the queue is ordered */ 18 | qid16 qnext; /* Index of next process or tail */ 19 | qid16 qprev; /* Index of previous process or head */ 20 | }; 21 | 22 | extern struct qentry queuetab[]; 23 | 24 | /* Inline queue manipulation functions */ 25 | 26 | #define queuehead(q) (q) 27 | #define queuetail(q) ((q) + 1) 28 | #define firstid(q) (queuetab[queuehead(q)].qnext) 29 | #define lastid(q) (queuetab[queuetail(q)].qprev) 30 | #define isempty(q) (firstid(q) >= NPROC) 31 | #define nonempty(q) (firstid(q) < NPROC) 32 | #define firstkey(q) (queuetab[firstid(q)].qkey) 33 | #define lastkey(q) (queuetab[ lastid(q)].qkey) 34 | 35 | /* Inline to check queue id assumes interrupts are disabled */ 36 | 37 | #define isbadqid(x) (((int32)(x) < NPROC) || (int32)(x) >= NQENT-1) 38 | -------------------------------------------------------------------------------- /system/queue.c: -------------------------------------------------------------------------------- 1 | /* queue.c - enqueue, dequeue */ 2 | 3 | #include 4 | 5 | struct qentry queuetab[NQENT]; /* Table of process queues */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * enqueue - Insert a process at the tail of a queue 9 | *------------------------------------------------------------------------ 10 | */ 11 | pid32 enqueue( 12 | pid32 pid, /* ID of process to insert */ 13 | qid16 q /* ID of queue to use */ 14 | ) 15 | { 16 | qid16 tail, prev; /* Tail & previous node indexes */ 17 | 18 | if (isbadqid(q) || isbadpid(pid)) { 19 | return SYSERR; 20 | } 21 | 22 | tail = queuetail(q); 23 | prev = queuetab[tail].qprev; 24 | 25 | queuetab[pid].qnext = tail; /* Insert just before tail node */ 26 | queuetab[pid].qprev = prev; 27 | queuetab[prev].qnext = pid; 28 | queuetab[tail].qprev = pid; 29 | return pid; 30 | } 31 | 32 | /*------------------------------------------------------------------------ 33 | * dequeue - Remove and return the first process on a list 34 | *------------------------------------------------------------------------ 35 | */ 36 | pid32 dequeue( 37 | qid16 q /* ID of queue to use */ 38 | ) 39 | { 40 | pid32 pid; /* ID of process removed */ 41 | 42 | if (isbadqid(q)) { 43 | return SYSERR; 44 | } else if (isempty(q)) { 45 | return EMPTY; 46 | } 47 | 48 | pid = getfirst(q); 49 | queuetab[pid].qprev = EMPTY; 50 | queuetab[pid].qnext = EMPTY; 51 | return pid; 52 | } 53 | -------------------------------------------------------------------------------- /www/w1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | xinu-avr: The Xinu OS for AVR atmega328p 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 19 |

xinu-avr: the Xinu OS for AVR atmega328p devices (e.g. Arduino)

20 | 21 |
22 | 23 |

24 | 25 | [What is Xinu?] 26 | [code for download] 27 | [authors] 28 | [Douglas Comer] 29 | [getting started] 30 | [notes] 31 | [contact us] 32 |

33 |
34 | 35 | 36 |
37 | 38 | 39 | 40 |

Introduction

41 | 42 | 43 | -------------------------------------------------------------------------------- /device/lfs/lfgetmode.c: -------------------------------------------------------------------------------- 1 | /* lfgetmode.c - lfgetmode */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lfgetmode - Parse mode argument and generate integer of mode bits 7 | *------------------------------------------------------------------------ 8 | */ 9 | int32 lfgetmode ( 10 | char *mode /* String of mode characters */ 11 | ) 12 | { 13 | int32 mbits; /* Mode bits to return */ 14 | char ch; /* Next char in mode string */ 15 | 16 | mbits = 0; 17 | 18 | /* Mode string specifies: */ 19 | /* r - read */ 20 | /* w - write */ 21 | /* o - old (file must exist) */ 22 | /* n - new (create a new file) */ 23 | 24 | while ( (ch = *mode++) != NULLCH) { 25 | switch (ch) { 26 | 27 | case 'r': if (mbits&LF_MODE_R) { 28 | return SYSERR; 29 | } 30 | mbits |= LF_MODE_R; 31 | continue; 32 | 33 | case 'w': if (mbits&LF_MODE_W) { 34 | return SYSERR; 35 | } 36 | mbits |= LF_MODE_W; 37 | continue; 38 | 39 | case 'o': if (mbits&LF_MODE_O || mbits&LF_MODE_N) { 40 | return SYSERR; 41 | } 42 | mbits |= LF_MODE_O; 43 | break; 44 | 45 | case 'n': if (mbits&LF_MODE_O || mbits&LF_MODE_N) { 46 | return SYSERR; 47 | } 48 | mbits |= LF_MODE_N; 49 | break; 50 | 51 | default: return SYSERR; 52 | } 53 | } 54 | 55 | /* If neither read nor write specified, allow both */ 56 | 57 | if ( (mbits&LF_MODE_RW) == 0 ) { 58 | mbits |= LF_MODE_RW; 59 | } 60 | return mbits; 61 | } 62 | -------------------------------------------------------------------------------- /device/lfs/lflgetc.c: -------------------------------------------------------------------------------- 1 | /* lflgetc.c - lfgetc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflgetc - Read the next byte from an open local file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflgetc ( 10 | struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | struct lflcblk *lfptr; /* Ptr to open file table entry */ 14 | struct ldentry *ldptr; /* Ptr to file's entry in the */ 15 | /* in-memory directory */ 16 | int32 onebyte; /* Next data byte in the file */ 17 | 18 | /* Obtain exclusive use of the file */ 19 | 20 | lfptr = &lfltab[devptr->dvminor]; 21 | wait(lfptr->lfmutex); 22 | 23 | /* If file is not open, return an error */ 24 | 25 | if (lfptr->lfstate != LF_USED) { 26 | signal(lfptr->lfmutex); 27 | return SYSERR; 28 | } 29 | 30 | /* Return EOF for any attempt to read beyond the end-of-file */ 31 | 32 | ldptr = lfptr->lfdirptr; 33 | if (lfptr->lfpos >= ldptr->ld_size) { 34 | signal(lfptr->lfmutex); 35 | return EOF; 36 | } 37 | 38 | /* If byte pointer is beyond the current data block, set up */ 39 | /* a new data block */ 40 | 41 | if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) { 42 | lfsetup(lfptr); 43 | } 44 | 45 | /* Extract the next byte from block, update file position, and */ 46 | /* return the byte to the caller */ 47 | 48 | onebyte = 0xff & *lfptr->lfbyte++; 49 | lfptr->lfpos++; 50 | signal(lfptr->lfmutex); 51 | return onebyte; 52 | } 53 | -------------------------------------------------------------------------------- /device/lfs/lflinit.c: -------------------------------------------------------------------------------- 1 | /* lflinit.c - lflinit */ 2 | 3 | #include 4 | 5 | struct lflcblk lfltab[Nlfl]; /* Pseudo-device control blocks */ 6 | 7 | /*------------------------------------------------------------------------ 8 | * lflinit - Initialize control blocks for local file pseudo-devices 9 | *------------------------------------------------------------------------ 10 | */ 11 | devcall lflinit ( 12 | struct dentry *devptr /* Entry in device switch table */ 13 | ) 14 | { 15 | struct lflcblk *lfptr; /* Ptr. to control block entry */ 16 | int32 i; /* Walks through name array */ 17 | 18 | lfptr = &lfltab[ devptr->dvminor ]; 19 | 20 | /* Initialize control block entry */ 21 | 22 | lfptr->lfstate = LF_FREE; /* Device is currently unused */ 23 | lfptr->lfdev = devptr->dvnum; /* Set device ID */ 24 | lfptr->lfmutex = semcreate(1); /* Create the mutex semaphore */ 25 | 26 | /* Initialize the directory and file position */ 27 | 28 | lfptr->lfdirptr = (struct ldentry *) NULL; 29 | lfptr->lfpos = 0; 30 | for (i=0; ilfname[i] = NULLCH; 32 | } 33 | 34 | /* Zero the in-memory index block and data block */ 35 | 36 | lfptr->lfinum = LF_INULL; 37 | memset((char *) &lfptr->lfiblock, NULLCH, sizeof(struct lfiblk)); 38 | lfptr->lfdnum = 0; 39 | memset((char *) &lfptr->lfdblock, NULLCH, LF_BLKSIZ); 40 | 41 | /* Start with the byte beyond the current data block */ 42 | 43 | lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ]; 44 | lfptr->lfibdirty = lfptr->lfdbdirty = FALSE; 45 | return OK; 46 | } 47 | -------------------------------------------------------------------------------- /device/rds/rdsbufalloc.c: -------------------------------------------------------------------------------- 1 | /* rdsbufalloc.c - rdsbufalloc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rdsbufalloc - Allocate a buffer from the free list or the cache 7 | *------------------------------------------------------------------------ 8 | */ 9 | struct rdbuff *rdsbufalloc ( 10 | struct rdscblk *rdptr /* Ptr to device control block */ 11 | ) 12 | { 13 | struct rdbuff *bptr; /* Pointer to a buffer */ 14 | struct rdbuff *pptr; /* Pointer to previous buffer */ 15 | struct rdbuff *nptr; /* Pointer to next buffer */ 16 | 17 | /* Wait for an available buffer */ 18 | 19 | wait(rdptr->rd_availsem); 20 | 21 | /* If free list contains a buffer, extract it */ 22 | 23 | bptr = rdptr->rd_free; 24 | 25 | if ( bptr != (struct rdbuff *)NULL ) { 26 | rdptr->rd_free = bptr->rd_next; 27 | return bptr; 28 | } 29 | 30 | /* Extract oldest item in cache that has ref count zero (at */ 31 | /* least one such entry must exist because the semaphore */ 32 | /* had a nonzero count) */ 33 | 34 | bptr = rdptr->rd_ctprev; 35 | while (bptr != (struct rdbuff *) &rdptr->rd_chnext) { 36 | if (bptr->rd_refcnt <= 0) { 37 | 38 | /* Remove from cache and return to caller */ 39 | 40 | pptr = bptr->rd_prev; 41 | nptr = bptr->rd_next; 42 | pptr->rd_next = nptr; 43 | nptr->rd_prev = pptr; 44 | return bptr; 45 | } 46 | bptr = bptr->rd_prev; 47 | } 48 | panic("Remote disk cannot find an available buffer"); 49 | return (struct rdbuff *)SYSERR; 50 | } 51 | -------------------------------------------------------------------------------- /lib/date.c: -------------------------------------------------------------------------------- 1 | /* date.c: set and get the locate date and time */ 2 | 3 | #include 4 | #include 5 | 6 | // typedef long unsigned int size_t; 7 | typedef uint32_t time_t; 8 | 9 | #include 10 | 11 | time_t seconds; 12 | extern uint32 clktime; 13 | 14 | int get_date(char * s) 15 | { 16 | struct tm avr_tm; 17 | time_t sec; 18 | 19 | sec = seconds + clktime; 20 | localtime_r(&sec, &avr_tm); 21 | asctime_r(&avr_tm, s); 22 | } 23 | 24 | int set_date(const char *s) 25 | { 26 | struct tm avr_tm; 27 | 28 | int m, d, y; 29 | int hour, min, sec; 30 | char two[3]; 31 | 32 | two[2] = 0; 33 | 34 | /* month */ 35 | two[0] = *s; s++; two[1] = *s; s++; 36 | m = atoi(two); 37 | 38 | s++; 39 | 40 | /* day */ 41 | two[0] = *s; s++; two[1] = *s; s++; 42 | d = atoi(two); 43 | 44 | s++; 45 | 46 | /* year */ 47 | two[0] = *s; s++; two[1] = *s; s++; 48 | y = atoi(two); 49 | 50 | s++; 51 | 52 | /* hour */ 53 | two[0] = *s; s++; two[1] = *s; s++; 54 | hour = atoi(two); 55 | 56 | s++; 57 | 58 | /* minutes */ 59 | two[0] = *s; s++; two[1] = *s; s++; 60 | min = atoi(two); 61 | 62 | s++; 63 | 64 | /* seconds */ 65 | two[0] = *s; s++; two[1] = *s; s++; 66 | sec = atoi(two); 67 | 68 | avr_tm.tm_sec = sec; 69 | avr_tm.tm_min = min; 70 | avr_tm.tm_hour = hour; 71 | avr_tm.tm_mon = m - 1; 72 | avr_tm.tm_mday = d; 73 | avr_tm.tm_year = y + 100; 74 | avr_tm.tm_isdst = 0; 75 | 76 | /* FIXME - WARNING: interrupts should be disable before */ 77 | seconds = mktime(&avr_tm) - clktime; 78 | 79 | return 0; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /device/tty/ttycontrol.c: -------------------------------------------------------------------------------- 1 | /* ttycontrol.c - ttycontrol */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttycontrol - Control a tty device by setting modes 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ttycontrol( 10 | // struct dentry *devptr, /* Entry in device switch table */ 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | int32 func, /* Function to perform */ 13 | int32 arg1, /* Argument 1 for request */ 14 | int32 arg2 /* Argument 2 for request */ 15 | ) 16 | { 17 | struct ttycblk *typtr; /* Pointer to tty control block */ 18 | char ch; /* Character for lookahead */ 19 | 20 | typtr = &ttytab[devptr->dvminor]; 21 | 22 | /* Process the request */ 23 | 24 | switch ( func ) { 25 | 26 | case TC_NEXTC: 27 | wait(typtr->tyisem); 28 | ch = *typtr->tyitail; 29 | signal(typtr->tyisem); 30 | return (devcall)ch; 31 | 32 | case TC_MODER: 33 | typtr->tyimode = TY_IMRAW; 34 | return (devcall)OK; 35 | 36 | case TC_MODEC: 37 | typtr->tyimode = TY_IMCOOKED; 38 | return (devcall)OK; 39 | 40 | case TC_MODEK: 41 | typtr->tyimode = TY_IMCBREAK; 42 | return (devcall)OK; 43 | 44 | case TC_ICHARS: 45 | return(semcount(typtr->tyisem)); 46 | 47 | case TC_ECHO: 48 | typtr->tyiecho = TRUE; 49 | return (devcall)OK; 50 | 51 | case TC_NOECHO: 52 | typtr->tyiecho = FALSE; 53 | return (devcall)OK; 54 | 55 | default: 56 | return (devcall)SYSERR; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /system/intr.c: -------------------------------------------------------------------------------- 1 | /* intr.S - enable, disable, restore, halt, pause, (ARM) */ 2 | 3 | /* avr specific */ 4 | 5 | #include 6 | #include 7 | 8 | /* 9 | * This code is based on AVR-Xinu by Michael Minor 10 | */ 11 | 12 | #include 13 | 14 | /*------------------------------------------------------------------------ 15 | * disable - Disable interrupts and return the previous state 16 | *------------------------------------------------------------------------ 17 | */ 18 | intmask disable(void) 19 | { 20 | int x = SREG; 21 | asm("cli"); /*and disable interrupts*/ 22 | return x; 23 | } 24 | 25 | /*------------------------------------------------------------------------ 26 | * restore - Restore interrupts to value given by mask argument 27 | *------------------------------------------------------------------------ 28 | */ 29 | void restore(uint8 x) 30 | { 31 | SREG = x; /*restore the status register, possibly reenabling interrupts*/ 32 | } 33 | 34 | /*------------------------------------------------------------------------ 35 | * enable - Enable interrupts 36 | *------------------------------------------------------------------------ 37 | */ 38 | inline void enable() { 39 | sei(); 40 | } 41 | 42 | /*------------------------------------------------------------------------ 43 | * pause or halt - Place the processor in a hard loop 44 | *------------------------------------------------------------------------ 45 | */ 46 | inline void halt() { 47 | for (;;); 48 | } 49 | 50 | inline void pause() { 51 | for (;;); 52 | } 53 | -------------------------------------------------------------------------------- /device/rfs/rfsgetmode.c: -------------------------------------------------------------------------------- 1 | /* rfsgetmode.c - rfsgetmode */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rfsgetmode - Parse mode argument and generate integer of mode bits 7 | *------------------------------------------------------------------------ 8 | */ 9 | 10 | int32 rfsgetmode ( 11 | char *mode /* String of mode characters */ 12 | ) 13 | { 14 | int32 mbits; /* Mode bits to return (in host */ 15 | /* byte order) */ 16 | char ch; /* Next character in mode string*/ 17 | 18 | mbits = 0; 19 | 20 | /* Mode string specifies: */ 21 | /* r - read */ 22 | /* w - write */ 23 | /* o - old (file must exist) */ 24 | /* n - new (create a new file) */ 25 | 26 | while ( (ch = *mode++) != NULLCH) { 27 | switch (ch) { 28 | 29 | case 'r': if (mbits&RF_MODE_R) { 30 | return SYSERR; 31 | } 32 | mbits |= RF_MODE_R; 33 | continue; 34 | 35 | case 'w': if (mbits&RF_MODE_W) { 36 | return SYSERR; 37 | } 38 | mbits |= RF_MODE_W; 39 | continue; 40 | 41 | case 'o': if (mbits&RF_MODE_O || mbits&RF_MODE_N) { 42 | return SYSERR; 43 | } 44 | mbits |= RF_MODE_O; 45 | break; 46 | 47 | case 'n': if (mbits&RF_MODE_O || mbits&RF_MODE_N) { 48 | return SYSERR; 49 | } 50 | mbits |= RF_MODE_N; 51 | break; 52 | 53 | default: return SYSERR; 54 | } 55 | } 56 | 57 | /* If neither read nor write specified, allow both */ 58 | 59 | if ( (mbits&RF_MODE_RW) == 0 ) { 60 | mbits |= RF_MODE_RW; 61 | } 62 | return mbits; 63 | } 64 | -------------------------------------------------------------------------------- /config/config.l: -------------------------------------------------------------------------------- 1 | %{ 2 | extern int linectr; 3 | extern int brkcount; 4 | int skipping; 5 | %} 6 | OCT 0[0-7]* 7 | DEC [1-9][0-9]* 8 | HEX 0x[0-9a-fA-F]+ 9 | ID [a-z_A-Z][a-z_A-Z0-9]* 10 | %% 11 | "/*" { skipping = 1; } 12 | "*/" { skipping = 0; } 13 | "%%" { if (! skipping) 14 | if (++brkcount >= 2) 15 | { return 0; /* EOF */ } 16 | else 17 | { return DEFBRK; } } 18 | ":" { if (! skipping) return COLON; } 19 | {OCT} { if (! skipping) return INTEGER; } 20 | {DEC} { if (! skipping) return INTEGER; } 21 | {HEX} { if (! skipping) return INTEGER; } 22 | is { if (! skipping) return IS; } 23 | on { if (! skipping) return ON; } 24 | "=" ; 25 | -?intr { if (! skipping) return INTR; } 26 | -?csr { if (! skipping) return CSR; } 27 | -?irq { if (! skipping) return IRQ; } 28 | -?i { if (! skipping) return INIT; } 29 | -?o { if (! skipping) return OPEN; } 30 | -?c { if (! skipping) return CLOSE; } 31 | -?r { if (! skipping) return READ; } 32 | -?g { if (! skipping) return GETC; } 33 | -?p { if (! skipping) return PUTC; } 34 | -?w { if (! skipping) return WRITE; } 35 | -?s { if (! skipping) return SEEK; } 36 | -?n { if (! skipping) return CONTROL; } 37 | [ \t]+ ; 38 | "\n" { linectr++; } 39 | {ID} { if (! skipping) return IDENT; } 40 | . { if (! skipping) return yytext[0]; } 41 | -------------------------------------------------------------------------------- /lib/avr_gpio.c: -------------------------------------------------------------------------------- 1 | 2 | /* avr_gpio.c - little lib to set/unset AVR digital out pins */ 3 | 4 | void gpio_write(char p, unsigned char v) 5 | { 6 | volatile unsigned char * DDR; /* port b _B = 0x24; DDR B address */ 7 | volatile unsigned char * PORT; /* port b = 0x25; PORT address */ 8 | switch (p) { 9 | case 'b': 10 | DDR = 0x24; 11 | PORT = 0x25; 12 | break; 13 | default: 14 | return -1; 15 | } 16 | 17 | 18 | 19 | *(PORT) = 0x00; 20 | *(DDR) = 0xff; 21 | *(PORT) = v; 22 | } 23 | 24 | /* p : port. e.g. 'b' */ 25 | char gpio_read(char p) 26 | { 27 | volatile unsigned char * DDR; /* port b _B = 0x24; DDR B address */ 28 | volatile unsigned char * PORT; /* port b = 0x25; PORT address */ 29 | char v; 30 | 31 | switch (p) { 32 | case 'b': 33 | DDR = 0x24; 34 | PORT = 0x25; 35 | break; 36 | default: 37 | return -1; 38 | } 39 | 40 | v = *(PORT); 41 | return v; 42 | 43 | 44 | } 45 | 46 | /* digital set high/low using arduino board pin number */ 47 | gpio_arduino_write(char pin, unsigned char v) 48 | { 49 | char p; 50 | unsigned char val; 51 | 52 | 53 | /* Extra arduino mode */ 54 | 55 | if (pin <= 8) { 56 | pin = (1 << pin); /* e.g. p = 3 (pin 3, port d) */ 57 | p = 'd'; 58 | } else if (pin <= 13) { 59 | pin = (1 << (pin-8)); /* e.g. p = 3 (pin 3, port d) */ 60 | p = 'b'; 61 | } else { 62 | pin = (1 << (pin-13)); /* e.g. p = 3 (pin 3, port d) */ 63 | p = 'c'; 64 | } 65 | 66 | val = gpio_read(p); 67 | 68 | if (v) /* 1 = high ; 0 = low */ 69 | v = val | pin; 70 | else 71 | v = val & (~pin); 72 | 73 | gpio_write(p, v); 74 | return 0; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /device/rds/rdsclose.c: -------------------------------------------------------------------------------- 1 | /* rdsclose.c - rdsclose */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * rdsclose - Close a remote disk device 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall rdsclose ( 10 | struct dentry *devptr /* Entry in device switch table */ 11 | ) 12 | { 13 | struct rdscblk *rdptr; /* Ptr to control block entry */ 14 | struct rdbuff *bptr; /* Ptr to buffer on a list */ 15 | struct rdbuff *nptr; /* Ptr to next buff on the list */ 16 | int32 nmoved; /* Number of buffers moved */ 17 | 18 | /* Device must be open */ 19 | 20 | rdptr = &rdstab[devptr->dvminor]; 21 | if (rdptr->rd_state != RD_OPEN) { 22 | return SYSERR; 23 | } 24 | 25 | /* Request queue must be empty */ 26 | 27 | if (rdptr->rd_rhnext != (struct rdbuff *)&rdptr->rd_rtnext) { 28 | return SYSERR; 29 | } 30 | 31 | /* Move all buffers from the cache to the free list */ 32 | 33 | bptr = rdptr->rd_chnext; 34 | nmoved = 0; 35 | while (bptr != (struct rdbuff *)&rdptr->rd_ctnext) { 36 | nmoved++; 37 | 38 | /* Unlink buffer from cache */ 39 | 40 | nptr = bptr->rd_next; 41 | (bptr->rd_prev)->rd_next = nptr; 42 | nptr->rd_prev = bptr->rd_prev; 43 | 44 | /* Insert buffer into free list */ 45 | 46 | bptr->rd_next = rdptr->rd_free; 47 | 48 | rdptr->rd_free = bptr; 49 | bptr->rd_status = RD_INVALID; 50 | 51 | /* Move to next buffer in the cache */ 52 | 53 | bptr = nptr; 54 | } 55 | 56 | /* Set the state to indicate the device is closed */ 57 | 58 | rdptr->rd_state = RD_FREE; 59 | return OK; 60 | } 61 | -------------------------------------------------------------------------------- /config/conf.h: -------------------------------------------------------------------------------- 1 | /* conf.h (GENERATED FILE; DO NOT EDIT) */ 2 | 3 | /* Device switch table declarations */ 4 | 5 | /* Device table entry */ 6 | struct dentry { 7 | int32 dvnum; 8 | int32 dvminor; 9 | char dvname[16]; 10 | devcall (*dvinit) (struct dentry *); 11 | devcall (*dvopen) (struct dentry *, char *, char *); 12 | devcall (*dvclose)(struct dentry *); 13 | devcall (*dvread) (struct dentry *, void *, uint32); 14 | devcall (*dvwrite)(struct dentry *, void *, uint32); 15 | devcall (*dvseek) (struct dentry *, int32); 16 | devcall (*dvgetc) (struct dentry *); 17 | devcall (*dvputc) (struct dentry *, char); 18 | devcall (*dvcntl) (struct dentry *, int32, int32, int32); 19 | void *dvcsr; 20 | void (*dvintr)(void); 21 | byte dvirq; 22 | }; 23 | 24 | extern struct dentry devtab[]; /* one entry per device */ 25 | 26 | /* Device name definitions */ 27 | 28 | #define CONSOLE 0 /* type tty */ 29 | #define NULLDEV 1 /* type null */ 30 | #define NAMESPACE 2 /* type nam */ 31 | 32 | /* Control block sizes */ 33 | 34 | #define Nnull 1 35 | #define Ntty 1 36 | #define Nnam 1 37 | 38 | #define NDEVS 3 39 | 40 | 41 | /* Configuration and Size Constants */ 42 | 43 | #define NPROC 4 /* number of user processes */ 44 | // RAFA #define NSEM 4 /* number of semaphores */ 45 | #define NSEM 2 /* number of semaphores */ 46 | #define IRQBASE 32 /* base ivec for IRQ0 */ 47 | #define IRQ_TIMER IRQ_HW5 /* timer IRQ is wired to hardware 5 */ 48 | #define IRQ_ATH_MISC IRQ_HW4 /* Misc. IRQ is wired to hardware 4 */ 49 | #define CLKFREQ 200000000 /* 200 MHz clock */ 50 | 51 | // #define LF_DISK_DEV RAM0 52 | -------------------------------------------------------------------------------- /system/getstk.c: -------------------------------------------------------------------------------- 1 | /* getstk.c - getstk */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getstk - Allocate stack memory, returning highest word address 7 | *------------------------------------------------------------------------ 8 | */ 9 | char *getstk( 10 | uint32 nbytes /* Size of memory requested */ 11 | ) 12 | { 13 | intmask mask; /* Saved interrupt mask */ 14 | struct memblk *prev, *curr; /* Walk through memory list */ 15 | struct memblk *fits, *fitsprev; /* Record block that fits */ 16 | 17 | mask = disable(); 18 | if (nbytes == 0) { 19 | restore(mask); 20 | return (char *)SYSERR; 21 | } 22 | 23 | nbytes = (uint32) roundmb(nbytes); /* Use mblock multiples */ 24 | 25 | prev = &memlist; 26 | curr = memlist.mnext; 27 | fits = NULL; 28 | fitsprev = NULL; /* Just to avoid a compiler warning */ 29 | 30 | while (curr != NULL) { /* Scan entire list */ 31 | // RAFA kprintf("c:%d ",curr->mlength); 32 | // RAFA kprintf("n:%d ",nbytes); 33 | if (curr->mlength >= nbytes) { /* Record block address */ 34 | fits = curr; /* when request fits */ 35 | fitsprev = prev; 36 | } 37 | prev = curr; 38 | curr = curr->mnext; 39 | } 40 | 41 | if (fits == NULL) { /* No block was found */ 42 | restore(mask); 43 | return (char *)SYSERR; 44 | } 45 | if (nbytes == fits->mlength) { /* Block is exact match */ 46 | fitsprev->mnext = fits->mnext; 47 | } else { /* Remove top section */ 48 | fits->mlength -= nbytes; 49 | fits = (struct memblk *)((uint32)fits + fits->mlength); 50 | } 51 | memlist.mlength -= nbytes; 52 | restore(mask); 53 | return (char *)((uint32) fits + nbytes - sizeof(uint32)); 54 | } 55 | -------------------------------------------------------------------------------- /apps/example5/main.c: -------------------------------------------------------------------------------- 1 | /* ex5.c - main, prod2, cons2 */ 2 | 3 | #include 4 | 5 | void prod2(int nargs, char *args[]); 6 | void cons2(int nargs, char *args[]); 7 | 8 | int32 n = 0; /* n assigned an initial value of zero */ 9 | 10 | /*------------------------------------------------------------------------ 11 | * main -- producer and consumer processes synchronized with semaphores 12 | *------------------------------------------------------------------------ 13 | */ 14 | void main(void) 15 | { 16 | sid32 produced, consumed; 17 | 18 | consumed = semcreate(0); 19 | produced = semcreate(1); 20 | resume( create(cons2, 256, 20, "cons", 2, consumed, produced) ); 21 | resume( create(prod2, 256, 20, "prod", 2, consumed, produced) ); 22 | } 23 | 24 | /*------------------------------------------------------------------------ 25 | * prod2 -- increment n 2000 times, waiting for it to be consumed 26 | *------------------------------------------------------------------------ 27 | */ 28 | void prod2(int nargs, char *args[]) 29 | { 30 | sid32 consumed = args[0]; 31 | sid32 produced = args[1]; 32 | int32 i; 33 | 34 | for( i=1 ; i<=2000 ; i++ ) { 35 | wait(consumed); 36 | n++; 37 | signal(produced); 38 | } 39 | } 40 | 41 | /*------------------------------------------------------------------------ 42 | * cons2 -- print n 2000 times, waiting for it to be produced 43 | *------------------------------------------------------------------------ 44 | */ 45 | void cons2(int nargs, char *args[]) 46 | { 47 | sid32 consumed = args[0]; 48 | sid32 produced = args[1]; 49 | int32 i; 50 | 51 | for( i=1 ; i<=2000 ; i++ ) { 52 | wait(produced); 53 | printf("n is %d \n", n); 54 | signal(consumed); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /system/getitem.c: -------------------------------------------------------------------------------- 1 | /* getitem.c - getfirst, getlast, getitem */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * getfirst - Remove a process from the front of a queue 7 | *------------------------------------------------------------------------ 8 | */ 9 | pid32 getfirst( 10 | qid16 q /* ID of queue from which to */ 11 | ) /* Remove a process (assumed */ 12 | /* valid with no check) */ 13 | { 14 | pid32 head; 15 | 16 | if (isempty(q)) { 17 | return EMPTY; 18 | } 19 | 20 | head = queuehead(q); 21 | return getitem(queuetab[head].qnext); 22 | } 23 | 24 | /*------------------------------------------------------------------------ 25 | * getlast - Remove a process from end of queue 26 | *------------------------------------------------------------------------ 27 | */ 28 | pid32 getlast( 29 | qid16 q /* ID of queue from which to */ 30 | ) /* Remove a process (assumed */ 31 | /* valid with no check) */ 32 | { 33 | pid32 tail; 34 | 35 | if (isempty(q)) { 36 | return EMPTY; 37 | } 38 | 39 | tail = queuetail(q); 40 | return getitem(queuetab[tail].qprev); 41 | } 42 | 43 | /*------------------------------------------------------------------------ 44 | * getitem - Remove a process from an arbitrary point in a queue 45 | *------------------------------------------------------------------------ 46 | */ 47 | pid32 getitem( 48 | pid32 pid /* ID of process to remove */ 49 | ) 50 | { 51 | pid32 prev, next; 52 | 53 | next = queuetab[pid].qnext; /* Following node in list */ 54 | prev = queuetab[pid].qprev; /* Previous node in list */ 55 | queuetab[prev].qnext = next; 56 | queuetab[next].qprev = prev; 57 | return pid; 58 | } 59 | -------------------------------------------------------------------------------- /system/kprintf.c: -------------------------------------------------------------------------------- 1 | /* kprintf.c - kputc, kgetc, kprintf */ 2 | /* Kprintf uses a direct method to write to serial 3 | * Used for debugging purposes. Should in normal cases 4 | * use printf that does a syscall 5 | * */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | /*------------------------------------------------------------------------ 13 | * kputc - use polled I/O to write a character to the console serial line 14 | *------------------------------------------------------------------------ 15 | */ 16 | syscall kputc( 17 | byte c /* character to write */ 18 | ) 19 | { 20 | intmask mask; 21 | 22 | mask = disable(); 23 | 24 | if (c == '\n') 25 | serial_put_char('\r'); 26 | serial_put_char(c); 27 | 28 | restore(mask); 29 | return OK; 30 | } 31 | 32 | /*------------------------------------------------------------------------ 33 | * kgetc - use polled I/O to read a character from the console serial line 34 | *------------------------------------------------------------------------ 35 | */ 36 | syscall kgetc(void) 37 | { 38 | // Not used 39 | } 40 | 41 | extern void _doprnt(char *, va_list, int (*)(int)); 42 | 43 | 44 | 45 | 46 | /*------------------------------------------------------------------------ 47 | * kprintf - use polled I/O to print formatted output on the console 48 | *------------------------------------------------------------------------ 49 | */ 50 | syscall kprintf(char *fmt, ...) 51 | { 52 | va_list ap; 53 | char output[81]; 54 | char *c; 55 | 56 | memset(output, 0, 81); 57 | va_start(ap, fmt); 58 | vsnprintf(output, 80, fmt, ap); 59 | va_end(ap); 60 | 61 | c = output; 62 | while(*c) { 63 | kputc(*c); 64 | c++; 65 | }; 66 | 67 | return OK; 68 | } 69 | -------------------------------------------------------------------------------- /system/mkbufpool.c: -------------------------------------------------------------------------------- 1 | /* mkbufpool.c - mkbufpool */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * mkbufpool - Allocate memory for a buffer pool and link the buffers 7 | *------------------------------------------------------------------------ 8 | */ 9 | bpid32 mkbufpool( 10 | int32 bufsiz, /* Size of a buffer in the pool */ 11 | int32 numbufs /* Number of buffers in the pool*/ 12 | ) 13 | { 14 | intmask mask; /* Saved interrupt mask */ 15 | bpid32 poolid; /* ID of pool that is created */ 16 | struct bpentry *bpptr; /* Pointer to entry in buftab */ 17 | char *buf; /* Pointer to memory for buffer */ 18 | 19 | mask = disable(); 20 | if (bufsizBP_MAXB 21 | || numbufs<1 || numbufs>BP_MAXN 22 | || nbpools >= NBPOOLS) { 23 | restore(mask); 24 | return (bpid32)SYSERR; 25 | } 26 | /* Round request to a multiple of 4 bytes */ 27 | 28 | bufsiz = ( (bufsiz + 3) & (~3) ); 29 | 30 | buf = (char *)getmem( numbufs * (bufsiz+sizeof(bpid32)) ); 31 | if ((int32)buf == SYSERR) { 32 | restore(mask); 33 | return (bpid32)SYSERR; 34 | } 35 | poolid = nbpools++; 36 | bpptr = &buftab[poolid]; 37 | bpptr->bpnext = (struct bpentry *)buf; 38 | bpptr->bpsize = bufsiz; 39 | if ( (bpptr->bpsem = semcreate(numbufs)) == SYSERR) { 40 | freemem(buf, numbufs * (bufsiz+sizeof(bpid32)) ); 41 | nbpools--; 42 | restore(mask); 43 | return (bpid32)SYSERR; 44 | } 45 | bufsiz+=sizeof(bpid32); 46 | for (numbufs-- ; numbufs>0 ; numbufs-- ) { 47 | bpptr = (struct bpentry *)buf; 48 | buf += bufsiz; 49 | bpptr->bpnext = (struct bpentry *)buf; 50 | } 51 | bpptr = (struct bpentry *)buf; 52 | bpptr->bpnext = (struct bpentry *)NULL; 53 | restore(mask); 54 | return poolid; 55 | } 56 | -------------------------------------------------------------------------------- /www/files/mainpage.css: -------------------------------------------------------------------------------- 1 | /* 2 | @media (min-width: 858px) { 3 | html { 4 | font-size: 12px; 5 | } 6 | } 7 | 8 | @media (min-width: 780px) { 9 | html { 10 | font-size: 11px; 11 | } 12 | } 13 | 14 | @media (min-width: 702px) { 15 | html { 16 | font-size: 10px; 17 | } 18 | } 19 | 20 | @media (min-width: 724px) { 21 | html { 22 | font-size: 9px; 23 | } 24 | } 25 | 26 | @media (max-width: 623px) { 27 | html { 28 | font-size: 8px; 29 | } 30 | } 31 | */ 32 | 33 | body{ 34 | margin:1em auto; 35 | max-width:40em; 36 | padding:0.5em .5em; 37 | color:#222222; 38 | background-color: #EeEeFA; 39 | font-family: Tahoma,Verdana,Helvetica,Arial; 40 | } 41 | img{ 42 | width:100%; 43 | max-width:40em; 44 | } 45 | 46 | /* 47 | body 48 | { 49 | margin:10px 10px 0px 10px; 50 | padding:0px; 51 | font-size:18px; 52 | } 53 | */ 54 | 55 | h1 56 | { 57 | /* margin-left:15px; */ 58 | color:#2277bb; 59 | } 60 | 61 | 62 | h2 63 | { 64 | color:#2266bb; 65 | } 66 | 67 | h3 68 | { 69 | color:#2266bb; 70 | } 71 | 72 | h4 73 | { 74 | } 75 | 76 | p 77 | { 78 | /* 79 | margin-left:70px; 80 | margin-right:70px; 81 | margin-top:5px; 82 | font-size:12pt; 83 | */ 84 | } 85 | 86 | ol 87 | { 88 | /* 89 | margin-left:100px; 90 | margin-right:70px; 91 | margin-top:5px; 92 | font-size:12pt; 93 | */ 94 | } 95 | 96 | 97 | ul 98 | { 99 | /* 100 | margin-left:60px; 101 | margin-right:100px; 102 | font-size:12pt; 103 | */ 104 | } 105 | 106 | table 107 | { 108 | /* 109 | font-size:16px; 110 | */ 111 | } 112 | -------------------------------------------------------------------------------- /device/lfs/lflputc.c: -------------------------------------------------------------------------------- 1 | /* lflputc.c - lfputc */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * lflputc - Write a single byte to an open local file 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall lflputc ( 10 | struct dentry *devptr, /* Entry in device switch table */ 11 | char ch /* Character (byte) to write */ 12 | ) 13 | { 14 | struct lflcblk *lfptr; /* Ptr to open file table entry */ 15 | struct ldentry *ldptr; /* Ptr to file's entry in the */ 16 | /* in-memory directory */ 17 | 18 | /* Obtain exclusive use of the file */ 19 | 20 | lfptr = &lfltab[devptr->dvminor]; 21 | wait(lfptr->lfmutex); 22 | 23 | /* If file is not open, return an error */ 24 | 25 | if (lfptr->lfstate != LF_USED) { 26 | signal(lfptr->lfmutex); 27 | return SYSERR; 28 | } 29 | 30 | /* Return SYSERR for an attempt to skip bytes beyond the byte */ 31 | /* that is currently the end of the file */ 32 | 33 | ldptr = lfptr->lfdirptr; 34 | if (lfptr->lfpos > ldptr->ld_size) { 35 | signal(lfptr->lfmutex); 36 | return SYSERR; 37 | } 38 | 39 | /* If pointer is outside current block, set up new block */ 40 | 41 | if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) { 42 | 43 | /* Set up block for current file position */ 44 | 45 | lfsetup(lfptr); 46 | } 47 | 48 | /* If appending a byte to the file, increment the file size. */ 49 | /* Note: comparison might be equal, but should not be greater.*/ 50 | 51 | if (lfptr->lfpos >= ldptr->ld_size) { 52 | ldptr->ld_size++; 53 | Lf_data.lf_dirdirty = TRUE; 54 | } 55 | 56 | /* Place byte in buffer and mark buffer "dirty" */ 57 | 58 | *lfptr->lfbyte++ = ch; 59 | lfptr->lfpos++; 60 | lfptr->lfdbdirty = TRUE; 61 | 62 | signal(lfptr->lfmutex); 63 | return OK; 64 | } 65 | -------------------------------------------------------------------------------- /device/tty/ttyread.c: -------------------------------------------------------------------------------- 1 | /* ttyread.c - ttyread */ 2 | 3 | #include 4 | 5 | /*------------------------------------------------------------------------ 6 | * ttyread - Read character(s) from a tty device (interrupts disabled) 7 | *------------------------------------------------------------------------ 8 | */ 9 | devcall ttyread( 10 | // struct dentry *devptr, /* Entry in device switch table */ 11 | const __flash struct dentry *devptr, /* Entry in device switch table */ 12 | char *buff, /* Buffer of characters */ 13 | int32 count /* Count of character to read */ 14 | ) 15 | { 16 | struct ttycblk *typtr; /* Pointer to tty control block */ 17 | int32 avail; /* Characters available in buff.*/ 18 | int32 nread; /* Number of characters read */ 19 | int32 firstch; /* First input character on line*/ 20 | char ch; /* Next input character */ 21 | 22 | if (count < 0) { 23 | return SYSERR; 24 | } 25 | typtr= &ttytab[devptr->dvminor]; 26 | 27 | if (typtr->tyimode != TY_IMCOOKED) { 28 | 29 | /* For count of zero, return all available characters */ 30 | 31 | if (count == 0) { 32 | avail = semcount(typtr->tyisem); 33 | if (avail == 0) { 34 | return 0; 35 | } else { 36 | count = avail; 37 | } 38 | } 39 | for (nread = 0; nread < count; nread++) { 40 | *buff++ = (char) ttygetc(devptr); 41 | } 42 | return nread; 43 | } 44 | 45 | 46 | /* Block until input arrives */ 47 | 48 | firstch = ttygetc(devptr); 49 | 50 | /* Check for End-Of-File */ 51 | 52 | if (firstch == EOF) { 53 | return EOF; 54 | } 55 | 56 | /* Read up to a line */ 57 | 58 | ch = (char) firstch; 59 | *buff++ = ch; 60 | nread = 1; 61 | while ( (nread < count) && (ch != TY_NEWLINE) && 62 | (ch != TY_RETURN) ) { 63 | ch = ttygetc(devptr); 64 | *buff++ = ch; 65 | nread++; 66 | } 67 | return nread; 68 | } 69 | -------------------------------------------------------------------------------- /include/arp.h: -------------------------------------------------------------------------------- 1 | /* arp.h */ 2 | 3 | /* Items related to ARP - definition of cache and the packet format */ 4 | 5 | #define ARP_HALEN 6 /* Size of Ethernet MAC address */ 6 | #define ARP_PALEN 4 /* Size of IP address */ 7 | 8 | #define ARP_HTYPE 1 /* Ethernet hardware type */ 9 | #define ARP_PTYPE 0x0800 /* IP protocol type */ 10 | 11 | #define ARP_OP_REQ 1 /* Request op code */ 12 | #define ARP_OP_RPLY 2 /* Reply op code */ 13 | 14 | #define ARP_SIZ 16 /* Number of entries in a cache */ 15 | 16 | #define ARP_RETRY 3 /* Num. retries for ARP request */ 17 | 18 | #define ARP_TIMEOUT 300 /* Retry timer in milliseconds */ 19 | 20 | /* State of an ARP cache entry */ 21 | 22 | #define AR_FREE 0 /* Slot is unused */ 23 | #define AR_PENDING 1 /* Resolution in progress */ 24 | #define AR_RESOLVED 2 /* Entry is valid */ 25 | 26 | #pragma pack(2) 27 | struct arppacket { /* ARP packet for IP & Ethernet */ 28 | byte arp_ethdst[ETH_ADDR_LEN];/* Ethernet dest. MAC addr */ 29 | byte arp_ethsrc[ETH_ADDR_LEN];/* Ethernet source MAC address */ 30 | uint16 arp_ethtype; /* Ethernet type field */ 31 | uint16 arp_htype; /* ARP hardware type */ 32 | uint16 arp_ptype; /* ARP protocol type */ 33 | byte arp_hlen; /* ARP hardware address length */ 34 | byte arp_plen; /* ARP protocol address length */ 35 | uint16 arp_op; /* ARP operation */ 36 | byte arp_sndha[ARP_HALEN]; /* ARP sender's Ethernet addr */ 37 | uint32 arp_sndpa; /* ARP sender's IP address */ 38 | byte arp_tarha[ARP_HALEN]; /* ARP target's Ethernet addr */ 39 | uint32 arp_tarpa; /* ARP target's IP address */ 40 | }; 41 | #pragma pack() 42 | 43 | struct arpentry { /* Entry in the ARP cache */ 44 | int32 arstate; /* State of the entry */ 45 | uint32 arpaddr; /* IP address of the entry */ 46 | pid32 arpid; /* Waiting process or -1 */ 47 | byte arhaddr[ARP_HALEN]; /* Ethernet address of the entry*/ 48 | }; 49 | 50 | extern struct arpentry arpcache[]; 51 | -------------------------------------------------------------------------------- /include/dns.h: -------------------------------------------------------------------------------- 1 | /* dns.h */ 2 | 3 | /* Constants and data structures used for DNS */ 4 | 5 | #define DNSTIMEOUT 3000 /* Timeout for a response (ms) */ 6 | #define DNSRETRY 3 /* Number of times to retry */ 7 | #define DNSPORT 53 /* Well-known DNS UDP port */ 8 | #define DNSLPORT 51525 /* Local UDP port to use */ 9 | #define DNSDATASIZ 500 /* Size of the data area */ 10 | 11 | 12 | /* Format of a DNS Query/Response packet */ 13 | 14 | struct dnspkt { 15 | uint16 id; /* DNS Query ID */ 16 | struct { 17 | byte rd:1; /* Recursion Desired */ 18 | byte tc:1; /* Truncation */ 19 | byte aa:1; /* Authoritative Answer */ 20 | byte opcode:4; /* Operation Code */ 21 | byte qr:1; /* Query=0, Response=1 */ 22 | }; 23 | struct { 24 | byte rcode:4; /* Response Code */ 25 | byte z:3; /* Reserved, must be 0 */ 26 | byte ra:1; /* Recursion Available */ 27 | }; 28 | uint16 qucount; /* No. of Questions */ 29 | uint16 ancount; /* No. of RRs in Answer */ 30 | uint16 nscount; /* No of Name Server RRs */ 31 | uint16 arcount; /* No. of RRs in Additional info*/ 32 | char data[DNSDATASIZ]; /* DNS data area */ 33 | }; 34 | 35 | /* QType Values */ 36 | 37 | #define DNS_QT_A 1 /* DNS Address Type (A) */ 38 | #define DNS_QT_NS 2 /* DNS Name Server Type */ 39 | 40 | /* QClass values */ 41 | 42 | #define DNS_QC_IN 1 /* DNS QClass Internet */ 43 | 44 | /* Format of a DNS Question */ 45 | 46 | struct dns_q { 47 | char *qname; /* Domain Name in the query */ 48 | uint16 *qtype; /* Question Type */ 49 | uint16 *qclass; /* Question Class */ 50 | }; 51 | 52 | /* Format of a DNS Resource Record */ 53 | 54 | struct dns_rr { 55 | char *rname; /* Domain Name */ 56 | uint16 *rtype; /* Resource Record Type */ 57 | uint16 *rclass; /* Resource Record Class */ 58 | uint32 *ttl; /* Resource Record Time-to-Live */ 59 | uint16 *rdlen; /* Resource Record RD Length */ 60 | char *rdata; /* Resource Record Data area */ 61 | }; 62 | -------------------------------------------------------------------------------- /system/avr_serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #define F_CPU 16000000UL 6 | #define USART_BAUDRATE 9600 7 | #define BAUD_PRESCALE (((F_CPU/(USART_BAUDRATE*16UL)))-1) 8 | #define INIT 0x06 9 | #define EN_RX_TX 0x18 10 | #define UART_RXCIE0 7 11 | #define EN_TX 0x20 12 | #define EN_RX 0x80 13 | 14 | typedef struct { 15 | uint8_t status_control_a; /* ucsr0a USART Control and Status A */ 16 | uint8_t status_control_b; /* ucsr0b USART Control and Status B */ 17 | uint8_t status_control_c; /* ucsr0c USART Control and Status C */ 18 | uint8_t _reserved; 19 | uint8_t baud_rate_l; /* ubrr0l baud rate low */ 20 | uint8_t baud_rate_h; /* ubrr0h baud rate high */ 21 | uint8_t data_es; /* udr0 i/o data */ 22 | 23 | } volatile uart_t; 24 | 25 | volatile uart_t *serial_port = (uart_t *) (0xc0); 26 | 27 | void serial_init() 28 | { 29 | /* conf High and Low registers using BAUD_PRESCALE */ 30 | 31 | serial_port->baud_rate_h = (unsigned char) (BAUD_PRESCALE>>8); 32 | serial_port->baud_rate_l = (unsigned char) (BAUD_PRESCALE); 33 | 34 | /* 8bits frame, one parity bit and stop bit */ 35 | serial_port->status_control_c = (unsigned char)(INIT); 36 | 37 | /* activates transmision and reception */ 38 | serial_port->status_control_b = (unsigned char)(EN_RX_TX | (1<status_control_a) & (EN_TX))); 47 | serial_port->data_es = outputChar; 48 | } 49 | 50 | char value; 51 | 52 | /* 53 | * RX interrupt service rutine 54 | */ 55 | ISR(USART_RX_vect){ 56 | value = UDR0; /* read UART register into value */ 57 | ttyhandler (1, value, 0); 58 | } 59 | 60 | char serial_get_char(void) 61 | { 62 | /* Wait for the next character to arrive. */ 63 | while (!((serial_port->status_control_a) & (EN_RX))); 64 | return (serial_port->data_es); 65 | } 66 | 67 | void serial_put_str (char * msg) 68 | { 69 | while (*msg) { 70 | serial_put_char(*msg); 71 | msg++; 72 | }; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /device/lfs/lfsckfmt.c: -------------------------------------------------------------------------------- 1 | /* lfckfmt.c - lfckfmt */ 2 | 3 | #include 4 | #include 5 | 6 | /*------------------------------------------------------------------------ 7 | * lfckfmt - Check the format of an initially-created disk 8 | *------------------------------------------------------------------------ 9 | */ 10 | status lfsckfmt ( 11 | did32 disk /* ID of an open disk device */ 12 | ) 13 | { 14 | uint32 ibsectors; /* Number of sectors of i-blocks*/ 15 | struct lfdir dir; /* Buffer to hold the directory */ 16 | uint32 dblks; /* Total free data blocks */ 17 | struct lfiblk iblock; /* Space for one i-block */ 18 | struct lfdbfree dblock; /* Data block on the free list */ 19 | int32 lfiblks; /* Total free index blocks */ 20 | int32 retval; 21 | ibid32 nextib; 22 | dbid32 nextdb; 23 | 24 | /* Read directory */ 25 | 26 | retval = read(disk,(char *)&dir, LF_AREA_DIR); 27 | if (retval == SYSERR) { 28 | panic("cannot read directory"); 29 | } 30 | kprintf("Have read directory from disk device %d\n\r", 31 | disk); 32 | 33 | /* Check to see if directory contains a Xinu file system */ 34 | 35 | if (lfscheck(&dir) == SYSERR) { 36 | panic("directory does not contain a Xinu file system"); 37 | } 38 | kprintf("Directory corresponds to a local Xinu file system\n"); 39 | 40 | /* Follow index block list */ 41 | 42 | lfiblks = 0; 43 | nextib = dir.lfd_ifree; 44 | kprintf("initial index block is %d\n\r", nextib); 45 | while (nextib != LF_INULL) { 46 | lfiblks++; 47 | lfibget(disk, nextib, &iblock); 48 | nextib = iblock.ib_next; 49 | } 50 | ibsectors = (lfiblks + 6) /7; 51 | kprintf("Found %d index blocks (%d sectors)\n\r", lfiblks, ibsectors); 52 | 53 | /* Follow data block list */ 54 | 55 | dblks = 0; 56 | nextdb = dir.lfd_dfree; 57 | kprintf("initial data block is %d\n\r", nextdb); 58 | while (nextdb != LF_DNULL) { 59 | dblks++; 60 | read(disk, (char *)&dblock, nextdb); 61 | nextdb = dblock.lf_nextdb; 62 | } 63 | kprintf("Found %d data blocks\n\r", dblks); 64 | return OK; 65 | } 66 | --------------------------------------------------------------------------------