├── compile ├── .deps ├── data │ ├── testarp.pcap │ ├── testip.pcap │ ├── testraw.pcap │ ├── testudp.pcap │ ├── testnetif.pcap │ ├── testsnoop.pcap │ ├── testnetif.txt │ ├── Makerules │ └── testraw.txt ├── mkvers.sh ├── reference.txt ├── upload.sh ├── config │ └── Makefile └── platforms │ ├── wrt160nl │ └── ld.script │ ├── wrt54gl │ └── ld.script │ ├── mipsel-qemu │ └── ld.script │ └── arm-qemu │ └── ld.script ├── device ├── uart-arm-qemu │ ├── power.h │ ├── usleep.h │ ├── driver.h │ ├── Makerules │ ├── usleep.S │ ├── uartPutc.c │ ├── xinu.c │ └── power.c ├── uart-fluke-bluetooth │ ├── power.h │ ├── usleep.h │ ├── driver.h │ ├── Makerules │ ├── usleep.S │ ├── uartPutc.c │ ├── xinu.c │ └── power.c ├── led │ ├── Makerules │ └── fluke-led.h ├── udp │ ├── udpFreebuf.c │ ├── Makerules │ ├── udpGetbuf.c │ ├── udpInit.c │ ├── udpAlloc.c │ └── udpClose.c ├── uart-pl01x │ └── Makerules ├── ag71xx │ ├── vlanStat.c │ └── Makerules ├── bcmbus │ ├── Makerules │ └── backplaneCoreUp.c ├── ethloop │ ├── Makerules │ └── ethloopInit.c ├── raw │ ├── Makerules │ ├── rawInit.c │ └── rawWrite.c ├── tty │ ├── Makerules │ ├── ttyInit.c │ ├── ttyGetc.c │ ├── ttyClose.c │ └── ttyWrite.c ├── uart-pl011 │ ├── Makerules │ ├── uartGetc.c │ └── uartPutc.c ├── uart-ns16550 │ ├── Makerules │ ├── uartGetc.c │ └── uartPutc.c ├── uart-ns16550a │ ├── Makerules │ ├── uartGetc.c │ └── uartPutc.c ├── loopback │ ├── Makerules │ ├── loopbackInit.c │ ├── loopbackGetc.c │ ├── loopbackClose.c │ ├── loopbackRead.c │ └── loopbackWrite.c ├── flash │ └── Makerules ├── tcp │ ├── tcpPutc.c │ ├── tcpGetc.c │ ├── tcpSendAck.c │ ├── tcpTimerTrigger.c │ ├── tcpAlloc.c │ ├── tcpInit.c │ ├── tcpOpenActive.c │ ├── Makerules │ ├── tcpSeqdiff.c │ ├── tcpTimerRemain.c │ ├── tcpChksum.c │ ├── tcpFree.c │ └── tcpSendSyn.c ├── telnet │ ├── Makerules │ ├── telnetPutc.c │ ├── telnetGetc.c │ ├── telnetClose.c │ ├── telnetAlloc.c │ └── telnetInit.c ├── bcm4713 │ ├── Makerules │ ├── vlanClose.c │ └── vlanOpen.c ├── http │ ├── httpGetc.c │ ├── httpFree.c │ ├── httpFlushWBuffer.c │ ├── Makerules │ ├── httpAlloc.c │ └── httpPutc.c └── interrupt-controller │ └── pl190.h ├── system ├── platforms │ ├── arm-qemu │ │ ├── debugret.c │ │ ├── debug.h │ │ ├── irq.c │ │ ├── platform-local.h │ │ ├── halt.S │ │ ├── pause.S │ │ ├── handlers.c │ │ ├── stdint.h │ │ ├── versatile-arm926ej-s.h │ │ └── Makerules │ ├── fluke-arm │ │ ├── debug.h │ │ ├── handlers.c │ │ ├── platform-local.h │ │ ├── pause.S │ │ ├── stdint.h │ │ └── Makerules │ ├── wrt160nl │ │ ├── mips.h │ │ ├── platform-local.h │ │ ├── halt.S │ │ ├── pause.S │ │ ├── ar9130.h │ │ └── Makerules │ ├── wrt54gl │ │ ├── mips.h │ │ ├── platform-local.h │ │ ├── halt.S │ │ ├── pause.S │ │ ├── debugbreak.S │ │ └── Makerules │ └── mipsel-qemu │ │ ├── halt.S │ │ ├── pause.S │ │ ├── pic8259.h │ │ ├── Makerules │ │ └── platform-local.h ├── userret.c ├── ionull.c ├── ioerr.c ├── gettid.c ├── yield.c ├── semcount.c ├── wakeup.c ├── xdone.c ├── close.c ├── getc.c ├── getprio.c ├── getdev.c ├── putc.c ├── constants.h ├── seek.c ├── read.c ├── open.c ├── signal.c ├── write.c ├── unistd.c ├── resume.c ├── chprio.c ├── recvclr.c ├── ready.c ├── receive.c ├── control.c ├── bfpfree.c ├── wait.c ├── signaln.c ├── bufget.c ├── queinit.c ├── buffree.c ├── sleep.c ├── semfree.c ├── unsleep.c └── insert.c ├── boot └── raspberry-pi │ ├── start.elf │ ├── bootcode.bin │ ├── README │ └── config.txt ├── lib ├── libxc │ ├── getchar.c │ ├── putchar.c │ ├── abs.c │ ├── labs.c │ ├── printf.c │ ├── rand.c │ ├── bzero.c │ ├── fputs.c │ ├── strnlen.c │ ├── fgetc.c │ ├── fputc.c │ ├── memset.c │ ├── strncmp.c │ ├── memcpy.c │ ├── fprintf.c │ ├── strncat.c │ ├── memchr.c │ ├── strchr.c │ ├── memcmp.c │ ├── atoi.c │ ├── atol.c │ ├── strrchr.c │ ├── strncpy.c │ ├── sprintf.c │ ├── ctype_.c │ ├── free.c │ ├── fgets.c │ └── strstr.c └── libdsp │ └── Makefile ├── include ├── null.h ├── dsp.h ├── debug.h ├── netemu.h ├── stdlib.h ├── backplane.h ├── stdarg.h ├── platform.h ├── string.h ├── kernel.h ├── clock.h └── device.h ├── apps └── Makerules ├── network ├── Makerules ├── netaddr │ ├── Makerules │ ├── netaddrhost.c │ ├── netaddrequal.c │ ├── netaddrmask.c │ └── netaddrsprintf.c ├── emulate │ ├── Makerules │ ├── netemu.c │ ├── emuReorder.c │ ├── emuCorrupt.c │ ├── emuDelay.c │ ├── emuDrop.c │ └── emuDuplicate.c ├── net │ ├── Makerules │ ├── netFreebuf.c │ ├── netChksum.c │ ├── netLookup.c │ └── netGetbuf.c ├── route │ ├── Makerules │ ├── rtAlloc.c │ ├── rtDaemon.c │ ├── rtClear.c │ ├── rtRemove.c │ ├── rtRecv.c │ └── rtInit.c ├── arp │ ├── Makerules │ ├── arpDaemon.c │ ├── arpFree.c │ └── arpInit.c ├── icmp │ ├── Makerules │ └── icmpInit.c ├── ipv4 │ └── Makerules └── snoop │ ├── Makerules │ └── snoopRead.c ├── loader └── platforms │ ├── mipsel-qemu │ ├── Makerules │ └── start.S │ ├── wrt160nl │ ├── Makerules │ └── start.S │ ├── wrt54gl │ ├── Makerules │ └── start.S │ ├── fluke-arm │ └── Makerules │ └── arm-qemu │ └── Makerules ├── mailbox ├── Makerules ├── mailboxInit.c └── mailboxCount.c ├── shell ├── xsh_echo.c ├── xsh_netemu.c └── xsh_test.c ├── mem ├── memRegionClear.c ├── memRegionTransfer.c ├── Makerules ├── memRegionValid.c ├── safeUnmapRange.c ├── tlbInit.c ├── safeMapRange.c ├── safeUnmap.c └── memRegionReclaim.c ├── test ├── Makerules ├── test_stub.c └── test_bigargs.c └── .gitignore /compile/.deps: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/power.h: -------------------------------------------------------------------------------- 1 | void set_bluetooth( int power ); 2 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/usleep.h: -------------------------------------------------------------------------------- 1 | void usleep( int microseconds ); 2 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/power.h: -------------------------------------------------------------------------------- 1 | void set_bluetooth( int power ); 2 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/usleep.h: -------------------------------------------------------------------------------- 1 | void usleep( int microseconds ); 2 | -------------------------------------------------------------------------------- /compile/data/testarp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testarp.pcap -------------------------------------------------------------------------------- /compile/data/testip.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testip.pcap -------------------------------------------------------------------------------- /compile/data/testraw.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testraw.pcap -------------------------------------------------------------------------------- /compile/data/testudp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testudp.pcap -------------------------------------------------------------------------------- /system/platforms/arm-qemu/debugret.c: -------------------------------------------------------------------------------- 1 | void debugret( void ) 2 | { 3 | kill( gettid() ); 4 | } 5 | -------------------------------------------------------------------------------- /boot/raspberry-pi/start.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/boot/raspberry-pi/start.elf -------------------------------------------------------------------------------- /compile/data/testnetif.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testnetif.pcap -------------------------------------------------------------------------------- /compile/data/testsnoop.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/compile/data/testsnoop.pcap -------------------------------------------------------------------------------- /boot/raspberry-pi/bootcode.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetcom/xinu-arm/HEAD/boot/raspberry-pi/bootcode.bin -------------------------------------------------------------------------------- /device/uart-arm-qemu/driver.h: -------------------------------------------------------------------------------- 1 | void uart1Init(uint16_t baud, uint8_t mode, uint8_t fmode); 2 | int uart1Putch(int ch); 3 | int uart1GetchRTS(void); 4 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/driver.h: -------------------------------------------------------------------------------- 1 | void uart1Init(uint16_t baud, uint8_t mode, uint8_t fmode); 2 | int uart1Putch(int ch); 3 | int uart1GetchRTS(void); 4 | -------------------------------------------------------------------------------- /compile/data/testnetif.txt: -------------------------------------------------------------------------------- 1 | AABBCCDDEEAA 2 | AABBCCDDEEFF 3 | 0806 4 | 0001 5 | 0800 6 | 06 7 | 04 8 | 0002 9 | AABBCCDDEEFF 10 | C0A80106 11 | AABBCCDDEEAA 12 | C0A80101 13 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Temporary debug functions for the Fluke. 3 | */ 4 | 5 | void setup_pins( void ); 6 | void led_on( void ); 7 | void led_off( void ); 8 | void die( void ); 9 | -------------------------------------------------------------------------------- /system/platforms/fluke-arm/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Temporary debug functions for the Fluke. 3 | */ 4 | 5 | void setup_pins( void ); 6 | void led_on( void ); 7 | void led_off( void ); 8 | void die( void ); 9 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/mips.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mips.h 3 | * Inherit main mips mips.h. 4 | */ 5 | /* Copyright 2012 Nathan Phillip Brink */ 6 | 7 | #include "../mipsel-qemu/mips.h" 8 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/mips.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mips.h 3 | * Inherit main mips mips.h. 4 | */ 5 | /* Copyright 2012 Nathan Phillip Brink */ 6 | 7 | #include "../mipsel-qemu/mips.h" 8 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/irq.c: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | static volatile struct spc804_timer *timer0 = (struct spc804_timer *) 0x101E2000; 3 | 4 | void idAndClearIRQ() 5 | { 6 | // Hard coded for now 7 | // timer0->int_clr = 1; 8 | } 9 | -------------------------------------------------------------------------------- /lib/libxc/getchar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file getchar.c 3 | * @provides getchar. 4 | */ 5 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 6 | 7 | #include 8 | 9 | int getchar(void) 10 | { 11 | return fgetc(stdin); 12 | } 13 | -------------------------------------------------------------------------------- /lib/libxc/putchar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file putchar.c 3 | * @provides putchar. 4 | */ 5 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 6 | 7 | #include 8 | 9 | int putchar(int c) 10 | { 11 | return fputc(c, stdout); 12 | } 13 | -------------------------------------------------------------------------------- /compile/mkvers.sh: -------------------------------------------------------------------------------- 1 | if [ -f vn ]; then 2 | expr `cat vn` + 1 > vn 3 | else 4 | echo 0 > vn 5 | fi 6 | if [ -z "$USER" ]; then 7 | USER=`whoami` 8 | fi 9 | HOST=`hostname` 10 | VN=`cat vn` 11 | echo "(ARM Xinu) #$VN ("$USER"@"$HOST") "`date` > version 12 | -------------------------------------------------------------------------------- /include/null.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file null.h 3 | * 4 | * $Id: null.h 1986 2009-08-12 00:33:27Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | 9 | /* File automatically included by xinu.conf system for null device */ 10 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/platform-local.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform-local.h 3 | * Inherit settings from main mips platform-local.h. 4 | */ 5 | /* Copyright 2012 Nathan Phillip Brink */ 6 | 7 | #include "../mipsel-qemu/platform-local.h" 8 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/platform-local.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform-local.h 3 | * Inherit settings from main mips platform-local.h. 4 | */ 5 | /* Copyright 2012 Nathan Phillip Brink */ 6 | 7 | #include "../mipsel-qemu/platform-local.h" 8 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/platform-local.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform-local.h 3 | * 4 | */ 5 | 6 | #ifndef _ARM_QEMU_PLATFORM_LOCAL_H 7 | #define _ARM_QEMU_PLATFORM_LOCAL_H 8 | 9 | #include 10 | 11 | #endif /* _ARM_QEMU_PLATFORM_LOCAL_H */ 12 | -------------------------------------------------------------------------------- /compile/reference.txt: -------------------------------------------------------------------------------- 1 | http://infocenter.arm.com/help/topic/com.arm.doc.ddi0181e/DDI0181.pdf 2 | http://infocenter.arm.com/help/topic/com.arm.doc.ddi0273a/DDI0273.pdf 3 | http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0290g/I27695.htmlhttp://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/3677.html 4 | -------------------------------------------------------------------------------- /system/platforms/fluke-arm/handlers.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Functions to handle ARM interrups. These are called 3 | * by the jump table in loader/start-arm.S. 4 | */ 5 | 6 | void SWI_Routine( void ) 7 | { 8 | 9 | } 10 | 11 | void UNDEF_Routine( void ) 12 | { 13 | 14 | } 15 | 16 | void FIQ_Routine( void ) 17 | { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /include/dsp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file dsp.h 3 | * 4 | * $Id: dsp.h 2111 2009-10-30 19:24:43Z zlund $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _DSP_H_ 9 | #define _DSP_H_ 10 | 11 | unsigned char linear2ulaw(int); 12 | int ulaw2linear(unsigned char); 13 | 14 | #endif /* _DSP_H_ */ 15 | -------------------------------------------------------------------------------- /system/userret.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file userret.c 3 | * @provides userret. 4 | * 5 | * $Id: userret.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Entered when a thread exits by return. 13 | */ 14 | void userret(void) 15 | { 16 | kill(gettid()); 17 | } 18 | -------------------------------------------------------------------------------- /apps/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = apps 5 | 6 | # Source files for this component 7 | C_FILES = date.c rdate.c 8 | 9 | S_FILES = 10 | 11 | # Add the files to the compile source path 12 | DIR = ${TOPDIR}/${COMP} 13 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 14 | -------------------------------------------------------------------------------- /network/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build devices within this directory 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network 5 | 6 | # Name of networking modules to include in the built system 7 | NETWORKING = arp emulate icmp ipv4 net netaddr route snoop 8 | 9 | DIR = ${TOPDIR}/${COMP} 10 | include ${NETWORKING:%=${DIR}/%/Makerules} 11 | -------------------------------------------------------------------------------- /system/ionull.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ionull.c 3 | * @provides ionull. 4 | * 5 | * $Id: ionull.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * do nothing (use for irrelevant entries in devtab) 13 | * @return OK 14 | */ 15 | devcall ionull(void) 16 | { 17 | return OK; 18 | } 19 | -------------------------------------------------------------------------------- /system/ioerr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ioerr.c 3 | * @provides ioerr. 4 | * 5 | * $Id: ioerr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * return an error (used for "error" entries in devtab) 13 | * @return SYSERR 14 | */ 15 | devcall ioerr(void) 16 | { 17 | return SYSERR; 18 | } 19 | -------------------------------------------------------------------------------- /compile/upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Uploader script for xinu boot image to Fluke. 4 | # 5 | # @author John Kloosterman for CS320 at Calvin College 6 | # @date March 12, 2012 7 | # 8 | # See http://xinu.ohnopub.net/mediawiki/index.php/Firmware 9 | # 10 | # Use "make upload" to run this script, so that the transfer 11 | # program gets compiled. 12 | # 13 | sudo ./lpc21isp-ipre -control xinu.hex /dev/ttyUSB0 38400 20000 -------------------------------------------------------------------------------- /loader/platforms/mipsel-qemu/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the loader/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = loader 5 | 6 | # Source files for this component 7 | C_FILES = 8 | S_FILES = start.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /loader/platforms/wrt160nl/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the loader/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = loader 5 | 6 | # Source files for this component 7 | C_FILES = 8 | S_FILES = start.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /loader/platforms/wrt54gl/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the loader/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = loader 5 | 6 | # Source files for this component 7 | C_FILES = 8 | S_FILES = start.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/led/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/flash/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/led 5 | 6 | # Source files for this component 7 | C_FILES = ledInit.c ledWrite.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /system/platforms/fluke-arm/platform-local.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform-local.h 3 | * 4 | */ 5 | 6 | #ifndef _FLUKE_ARM_PLATFORM_LOCAL_H 7 | #define _FLUKE_ARM_PLATFORM_LOCAL_H 8 | 9 | /* 10 | * The fluke-arm platform has so little memory that the global default 11 | * of 64k for INITSTK is too big. Try something more conservativer. 12 | */ 13 | #define INITSTK (1337) 14 | 15 | #endif /* _FLUKE_ARM_PLATFORM_LOCAL_H */ 16 | -------------------------------------------------------------------------------- /device/udp/udpFreebuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file udpFreebuf.c 3 | * @provides udpFreebuf 4 | * 5 | * $Id: udpFreebuf.c 2076 2009-09-24 23:05:39Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | syscall udpFreebuf(struct udpPkt *udppkt) 15 | { 16 | return buffree(udppkt); 17 | } 18 | -------------------------------------------------------------------------------- /device/uart-pl01x/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-pl01x 5 | 6 | # Source files for this component 7 | C_FILES = pl01x.c kprintf.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/halt.S: -------------------------------------------------------------------------------- 1 | /* 2 | * A low power halt routine. 3 | */ 4 | 5 | /* When the I bit is high, interrupts are disabled. */ 6 | .set PSR_I_BIT, 0x80 7 | 8 | /* When the F bit is high, fast interrupts are disabled. */ 9 | .set PSR_F_BIT, 0x40 10 | 11 | .text 12 | .align 4 13 | .global halt 14 | .type halt, %function 15 | 16 | halt: 17 | msr cpsr, #(PSR_I_BIT | PSR_F_BIT) @ Diable interrupts 18 | wfi 19 | b halt 20 | -------------------------------------------------------------------------------- /device/ag71xx/vlanStat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file vlanStat.c 3 | * @provides vlanStat. 4 | * 5 | * $Id: vlanStat.c 2108 2009-10-29 05:07:39Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include "ag71xx.h" 11 | #include 12 | #include 13 | 14 | int vlanStat(void) 15 | { 16 | fprintf(stderr, "Switch Core not found!\n"); 17 | return SYSERR; 18 | } 19 | -------------------------------------------------------------------------------- /loader/platforms/fluke-arm/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the loader/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = loader/platforms/${PLATFORM} 5 | 6 | # Source files for this component 7 | C_FILES = 8 | S_FILES = start.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /system/gettid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file gettid.c 3 | * @provides gettid. 4 | * 5 | * $Id: gettid.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Get the thread id of currently executing thread. 13 | * @return thread id of the currently running thread 14 | */ 15 | tid_typ gettid(void) 16 | { 17 | return thrcurrent; 18 | } 19 | -------------------------------------------------------------------------------- /boot/raspberry-pi/README: -------------------------------------------------------------------------------- 1 | The files contained in this directory are required to get the Raspberry Pi to boot. 2 | 3 | Here are descriptions of what the files do: 4 | bootcode.bin - GPU firmware 5 | start.elf - GPU firmware 6 | LICENCE.broadcom - license for the GPU firmware 7 | config.txt - GPU and ARM configuration 8 | 9 | To set up the SD card: simply format the card as FAT32 and copy these files plus an ARM binary file named kernel.img to it. 10 | -------------------------------------------------------------------------------- /network/netaddr/Makerules: -------------------------------------------------------------------------------- 1 | #This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/netaddr 5 | 6 | # Source files for this component 7 | C_FILES = netaddrequal.c netaddrhost.c netaddrmask.c netaddrsprintf.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /lib/libxc/abs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file abs.c 3 | * @provides abs. 4 | * 5 | * $Id: abs.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Calculates the absolute value of a number. 11 | * @param arg number to get absolute value of 12 | * @return absolute value of arg 13 | */ 14 | int abs(int arg) 15 | { 16 | if (arg < 0) 17 | arg = -arg; 18 | return (arg); 19 | } 20 | -------------------------------------------------------------------------------- /device/bcmbus/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/bcmbus 5 | 6 | # Source files for this component 7 | C_FILES = backplaneInit.c backplaneCoreDisable.c backplaneCoreReset.c backplaneCoreUp.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /lib/libxc/labs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file labs.c 3 | * @provides labs. 4 | * 5 | * $Id: labs.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Calculates the absolute value of a number. 11 | * @param arg number to get absolute value of 12 | * @return absolute value of arg 13 | */ 14 | long labs(long arg) 15 | { 16 | if (arg < 0) 17 | arg = -arg; 18 | return (arg); 19 | } 20 | -------------------------------------------------------------------------------- /network/emulate/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/emulate 5 | 6 | # Source files for this component 7 | C_FILES = emuCorrupt.c emuDelay.c emuDrop.c emuDuplicate.c emuReorder.c netemu.c 8 | 9 | S_FILES = 10 | 11 | # Add the files to the compile source path 12 | DIR = ${TOPDIR}/${COMP} 13 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 14 | -------------------------------------------------------------------------------- /device/ethloop/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/ethloop 5 | 6 | # Source files for this component 7 | C_FILES = ethloopClose.c ethloopControl.c ethloopOpen.c ethloopWrite.c ethloopRead.c ethloopInit.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/raw/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/raw 5 | 6 | # Source files for this component 7 | C_FILES = rawClose.c rawControl.c rawDemux.c rawInit.c rawOpen.c rawRead.c rawRecv.c rawSend.c rawWrite.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /network/net/Makerules: -------------------------------------------------------------------------------- 1 | #This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/net 5 | 6 | # Source files for this component 7 | C_FILES = netChksum.c netDown.c netFreebuf.c netGetbuf.c netInit.c netLookup.c netRecv.c netSend.c netUp.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /mailbox/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the mailbox/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = mailbox 5 | 6 | # Source files for this component 7 | C_FILES = mailboxAlloc.c mailboxCount.c mailboxFree.c mailboxInit.c mailboxReceive.c mailboxSend.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/tty/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/tty/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/tty 5 | 6 | # Source files for this component 7 | C_FILES = ttyControl.c ttyOpen.c ttyRead.c ttyClose.c ttyGetc.c ttyInit.c ttyPutc.c ttyWrite.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /system/yield.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file yield.c 3 | * @provides yield. 4 | * 5 | * $Id: yield.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Yield processor. 13 | * @return OK when the thread is context switched back 14 | */ 15 | syscall yield(void) 16 | { 17 | irqmask im; 18 | 19 | im = disable(); 20 | resched(); 21 | restore(im); 22 | return OK; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libxc/printf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file printf.c 3 | * @provides printf. 4 | * 5 | * $Id: printf.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | int printf(const char *fmt, ...) 13 | { 14 | va_list ap; 15 | int putc(int, int); 16 | 17 | va_start(ap, fmt); 18 | _doprnt((char *)fmt, ap, putc, stdout); 19 | va_end(ap); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/pause.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pause.S 3 | * @provides pause. 4 | * Platform-dependent code for idling the processor 5 | */ 6 | 7 | .text 8 | .align 4 9 | .global pause 10 | 11 | /** 12 | * @fn void pause(void) 13 | * 14 | * Enter some kind of powerdown state (if it exists) that suspends 15 | * execution until an interrupt is detected. 16 | */ 17 | .type pause, %function 18 | pause: 19 | wfi /* wait for interrupt */ 20 | mov pc, lr 21 | .end pause 22 | 23 | -------------------------------------------------------------------------------- /include/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file debug.h 3 | * 4 | * $Id: debug.h 2020 2009-08-13 17:50:08Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _DEBUG_H_ 9 | #define _DEBUG_H_ 10 | 11 | #include 12 | 13 | #define DEBUG_ASCII 0x01 14 | #define DEBUG_HEX 0x02 15 | 16 | void hexdump(void *buffer, ulong length, bool text); 17 | void debugbreak(void); 18 | void debugret(void); 19 | 20 | #endif /* _DEBGU_H_ */ 21 | -------------------------------------------------------------------------------- /network/route/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/route 5 | 6 | # Source files for this component 7 | C_FILES = rtAdd.c rtAlloc.c rtClear.c rtDaemon.c rtDefault.c rtInit.c rtLookup.c rtRecv.c rtRemove.c rtSend.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /system/platforms/fluke-arm/pause.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pause.S 3 | * @provides pause. 4 | * Platform-dependent code for idling the processor 5 | */ 6 | 7 | .text 8 | .align 4 9 | .global pause 10 | 11 | /** 12 | * @fn void pause(void) 13 | * 14 | * Enter some kind of powerdown state (if it exists) that suspends 15 | * execution until an interrupt is detected. 16 | */ 17 | .type pause, %function 18 | pause: 19 | wfi /* wait for interrupt */ 20 | mov pc, lr 21 | .end pause 22 | 23 | -------------------------------------------------------------------------------- /network/arp/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/arp 5 | 6 | # Source files for this component 7 | C_FILES = arpAlloc.c arpDaemon.c arpGetEntry.c arpFree.c arpInit.c arpLookup.c arpNotify.c arpRecv.c arpSendReply.c arpSendRqst.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/ag71xx/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/ag71xx 5 | 6 | # Source files for this component 7 | C_FILES = etherInit.c etherOpen.c etherClose.c etherRead.c etherWrite.c etherControl.c etherInterrupt.c allocRxBuffer.c etherStat.c vlanStat.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /network/net/netFreebuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * file netGetbuf.c 3 | * @provides netFreebuf 4 | * 5 | * $Id: netFreebuf.c 2079 2009-10-05 22:32:48Z zlund $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Frees a buffer for storing a packet. 15 | * @return OK if successful, SYSERR if an error occured 16 | */ 17 | syscall netFreebuf(struct packet *pkt) 18 | { 19 | return buffree(pkt); 20 | } 21 | -------------------------------------------------------------------------------- /device/uart-pl011/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-pl011 5 | 6 | # Source files for this component 7 | C_FILES = uartInit.c uartInterrupt.c uartPutc.c uartRead.c uartWrite.c uartGetc.c uartControl.c uartStat.c kprintf.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/udp/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/udp 5 | 6 | # Source files for this component 7 | C_FILES = udpAlloc.c udpChksum.c udpClose.c udpControl.c udpDemux.c udpFreebuf.c udpGetbuf.c udpInit.c udpOpen.c udpRead.c udpRecv.c udpSend.c udpWrite.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /network/icmp/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/icmp 5 | 6 | # Source files for this component 7 | C_FILES = icmpDestUnreach.c icmpEchoReply.c icmpEchoRequest.c icmpInit.c icmpRecv.c icmpRedirect.c icmpSend.c icmpTimeExceeded.c icmpDaemon.c 8 | 9 | S_FILES = 10 | 11 | # Add the files to the compile source path 12 | DIR = ${TOPDIR}/${COMP} 13 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 14 | -------------------------------------------------------------------------------- /network/ipv4/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the network/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/ipv4 5 | 6 | # Source files for this component 7 | 8 | # Important network components 9 | C_FILES = dot2ipv4.c ipv4Recv.c ipv4RecvDemux.c ipv4RecvValid.c ipv4Send.c ipv4SendFrag.c 10 | S_FILES = 11 | 12 | # Add the files to the compile source path 13 | DIR = ${TOPDIR}/${COMP} 14 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 15 | -------------------------------------------------------------------------------- /device/uart-ns16550/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-ns16550 5 | 6 | # Source files for this component 7 | C_FILES = uartInit.c uartInterrupt.c uartPutc.c uartRead.c uartWrite.c uartGetc.c uartControl.c uartStat.c kprintf.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/uart-ns16550a/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-ns16550a 5 | 6 | # Source files for this component 7 | C_FILES = kprintf.c uartInit.c uartInterrupt.c uartPutc.c uartRead.c uartWrite.c uartGetc.c uartControl.c uartStat.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /loader/platforms/arm-qemu/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the loader/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = loader/platforms/${PLATFORM} 5 | 6 | # Source files for this component 7 | C_FILES = 8 | S_FILES = start.S 9 | 10 | # Grab an interrupt controller 11 | INCLUDE += -I../device/interrupt-controller 12 | 13 | # Add the files to the compile source path 14 | DIR = ${TOPDIR}/${COMP} 15 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 16 | -------------------------------------------------------------------------------- /device/loopback/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/tty/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/loopback 5 | 6 | # Source files for this component 7 | C_FILES = loopbackGetc.c loopbackClose.c loopbackOpen.c loopbackPutc.c loopbackWrite.c loopbackRead.c loopbackControl.c loopbackInit.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-arm-qemu 5 | 6 | # Source files for this component 7 | C_FILES = uartInit.c uartWrite.c uartRead.c uartPutc.c uartGetc.c uartInterrupt.c kprintf.c power.c #xinu.c driver.c 8 | S_FILES = usleep.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/uart-ns16550/uartGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartGetc.c 3 | * @provides uartGetc. 4 | * 5 | * $Id: uartGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read a single character from UART. 15 | * @param pdev pointer to UART device 16 | */ 17 | devcall uartGetc(device *devptr) 18 | { 19 | uchar ch = 0; 20 | 21 | uartRead(devptr, &ch, 1); 22 | return ch; 23 | } 24 | -------------------------------------------------------------------------------- /device/uart-ns16550a/uartGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartGetc.c 3 | * @provides uartGetc. 4 | * 5 | * $Id: uartGetc.c 2103 2009-10-27 01:43:40Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read a single character from UART. 15 | * @param pdev pointer to UART device 16 | */ 17 | devcall uartGetc(device *devptr) 18 | { 19 | uchar ch = 0; 20 | 21 | uartRead(devptr, &ch, 1); 22 | return ch; 23 | } 24 | -------------------------------------------------------------------------------- /device/uart-pl011/uartGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartGetc.c 3 | * @provides uartGetc. 4 | * 5 | * $Id: uartGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read a single character from UART. 15 | * @param pdev pointer to UART device 16 | */ 17 | devcall uartGetc(device *devptr) 18 | { 19 | uchar ch = 0; 20 | 21 | uartRead(devptr, &ch, 1); 22 | return ch; 23 | } 24 | -------------------------------------------------------------------------------- /compile/data/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to include data in the data/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = data 5 | 6 | # pcap files 7 | PCAP_FILES = testarp.pcap testip.pcap testnetif.pcap testraw.pcap testsnoop.pcap testudp.pcap 8 | 9 | # tar files 10 | TAR_FILES = mytar.tar 11 | 12 | # Muster all the needed files together 13 | FILES = ${PCAP_FILES} ${TAR_FILES} 14 | 15 | # Add the files to the compile source path 16 | DIR = ${COMP} 17 | DATA_SRC += ${FILES:%=${DIR}/%} 18 | -------------------------------------------------------------------------------- /include/netemu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netemu.h 3 | * 4 | * $Id: netemu.h 2126 2009-11-12 07:23:04Z svn $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _NETEMU_H_ 9 | #define _NETEMU_H_ 10 | 11 | syscall netemu(struct packet *pkt); 12 | syscall emuCorrupt(struct packet *pkt); 13 | syscall emuDelay(struct packet *pkt); 14 | syscall emuDrop(struct packet *pkt); 15 | syscall emuDuplicate(struct packet *pkt); 16 | syscall emuReorder(struct packet *pkt); 17 | #endif /* _NETEMU_H_ */ 18 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/uart/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/uart-fluke-bluetooth 5 | 6 | # Source files for this component 7 | C_FILES = uartInit.c uartWrite.c uartRead.c uartPutc.c uartGetc.c uartInterrupt.c kprintf.c power.c #xinu.c driver.c 8 | S_FILES = usleep.S 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /network/emulate/netemu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file netemu.c 3 | * @provides netemu 4 | * 5 | * $Id: netemu.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Process a packet through the network emulator 14 | * @param pkt pointer to the incoming packet 15 | * @return OK if packet was processed succesfully, otherwise SYSERR 16 | */ 17 | syscall netemu(struct packet *pkt) 18 | { 19 | 20 | return emuDrop(pkt); 21 | } 22 | -------------------------------------------------------------------------------- /device/flash/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the device/flash/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/flash 5 | 6 | # Source files for this component 7 | C_FILES = flashClose.c flashControl.c flashInit.c flashOpen.c flashRead.c flashWrite.c logical.c nvram.c physical.c physicalAMD.c physicalIntel.c validateTrx.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /device/uart-pl011/uartPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartPutc.c 3 | * @provides uartPutc. 4 | * 5 | * $Id: uartPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a single character to the UART 15 | * @param pdev pointer to UART device 16 | * @param ch character to write 17 | */ 18 | devcall uartPutc(device *devptr, char ch) 19 | { 20 | return uartWrite(devptr, (void *)&ch, 1); 21 | } 22 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/handlers.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Functions to handle ARM interrups. These are called 3 | * by the jump table in loader/start-arm.S. 4 | */ 5 | 6 | void SWI_Routine( void ) 7 | { 8 | 9 | } 10 | 11 | void UNDEF_Routine( void ) 12 | { 13 | 14 | } 15 | 16 | void FIQ_Routine( void ) 17 | { 18 | 19 | } 20 | 21 | void PAbt_Routine( void ) 22 | { 23 | kprintf("PAbt!\n"); 24 | } 25 | void DAbt_Routine( void ) 26 | { 27 | //http://www.embedded.com/design/embedded/4006695/How-to-use-ARM-s-data-abort-exception 28 | kprintf("DAbt\n"); 29 | } 30 | -------------------------------------------------------------------------------- /device/uart-ns16550/uartPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartPutc.c 3 | * @provides uartPutc. 4 | * 5 | * $Id: uartPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a single character to the UART 15 | * @param pdev pointer to UART device 16 | * @param ch character to write 17 | */ 18 | devcall uartPutc(device *devptr, char ch) 19 | { 20 | return uartWrite(devptr, (void *)&ch, 1); 21 | } 22 | -------------------------------------------------------------------------------- /device/uart-ns16550a/uartPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartPutc.c 3 | * @provides uartPutc. 4 | * 5 | * $Id: uartPutc.c 2103 2009-10-27 01:43:40Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a single character to the UART 15 | * @param pdev pointer to UART device 16 | * @param ch character to write 17 | */ 18 | devcall uartPutc(device *devptr, char ch) 19 | { 20 | return uartWrite(devptr, (void *)&ch, 1); 21 | } 22 | -------------------------------------------------------------------------------- /network/emulate/emuReorder.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file emuReorder.c 3 | * @provides emuReorder 4 | * 5 | * $Id: emuReorder.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Reorder packets as specified by the user 14 | * @param pkt pointer to the incoming packet 15 | * @return OK if packet was processed succesfully, otherwise SYSERR 16 | */ 17 | syscall emuReorder(struct packet *pkt) 18 | { 19 | 20 | return emuCorrupt(pkt); 21 | } 22 | -------------------------------------------------------------------------------- /system/semcount.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file semcount.c 3 | * @provides semcount. 4 | * 5 | * $Id: semcount.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Return a semaphore's count 13 | * @param sem target semaphore 14 | * @return count from semtab entry on success, SYSERR on failure 15 | */ 16 | syscall semcount(semaphore sem) 17 | { 18 | if (isbadsem(sem)) 19 | { 20 | return SYSERR; 21 | } 22 | 23 | return (semtab[sem].count); 24 | } 25 | -------------------------------------------------------------------------------- /device/tcp/tcpPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpPutc.c 3 | * @provides tcpPutc 4 | * 5 | * $Id: tcpPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a single octet to send via TCP. 15 | * @param devptr TCP device table entry 16 | * @param ch character to output 17 | * @return count of characters written 18 | */ 19 | devcall tcpPutc(device *devptr, char ch) 20 | { 21 | return tcpWrite(devptr, &ch, 1); 22 | } 23 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/stdint.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file stdint.h 3 | * Platform-specific types. 4 | * 5 | * Based on inttypes.h from IPRE Fluke Firmware: 6 | * Ben Johnson , , 10 | #include 11 | #include 12 | 13 | /** 14 | * Corrupts packets as specified by user 15 | * @param pkt pointer to the incoming packet 16 | * @return OK if packet was processed succesfully, otherwise SYSERR 17 | */ 18 | syscall emuCorrupt(struct packet *pkt) 19 | { 20 | 21 | return rtRecv(pkt); 22 | } 23 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/halt.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file halt.s 3 | * @provides halt. 4 | * 5 | * $Id: halt.S 2092 2009-10-07 23:08:36Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2008. All rights reserved. */ 8 | 9 | #include 10 | 11 | .text 12 | .align 4 13 | .globl halt 14 | 15 | /** 16 | * @fn void halt(void) 17 | * 18 | * Essentially this is a busy wait, however the opcode 'wait' puts the 19 | * processor in a powersave state (which can be awoken for arbitrary 20 | * reasons) 21 | */ 22 | .ent halt 23 | halt: 24 | wait 25 | j halt 26 | .end halt 27 | 28 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/halt.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file halt.s 3 | * @provides halt. 4 | * 5 | * $Id: halt.S 2086 2009-10-06 22:24:27Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | .text 12 | .align 4 13 | .globl halt 14 | 15 | /** 16 | * @fn void halt(void) 17 | * 18 | * Essentially this is a busy wait, however the opcode 'wait' puts the 19 | * processor in a powersave state (which can be awoken for arbitrary 20 | * reasons) 21 | */ 22 | .ent halt 23 | halt: 24 | wait 25 | j halt 26 | .end halt 27 | 28 | -------------------------------------------------------------------------------- /device/bcm4713/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/bcm4713 5 | 6 | # Source files for this component 7 | C_FILES = etherInit.c etherOpen.c etherClose.c etherRead.c etherWrite.c etherControl.c etherInterrupt.c etherStat.c colon2mac.c allocRxBuffer.c waitOnBit.c switchInit.c vlanInit.c vlanOpen.c vlanClose.c vlanStat.c 8 | S_FILES = 9 | 10 | # Add the files to the compile source path 11 | DIR = ${TOPDIR}/${COMP} 12 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 13 | -------------------------------------------------------------------------------- /lib/libxc/rand.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rand.c 3 | * @provides srand, rand. 4 | * 5 | * $Id: rand.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | static unsigned long randx = 1; 10 | 11 | /** 12 | * Sets the random seed. 13 | * @param x random seed 14 | */ 15 | void srand(unsigned long x) 16 | { 17 | randx = x; 18 | } 19 | 20 | /** 21 | * Generates a random long. 22 | * @return random long 23 | */ 24 | unsigned long rand(void) 25 | { 26 | return (((randx = randx * 1103515245 + 12345) >> 16) & 077777); 27 | } 28 | -------------------------------------------------------------------------------- /system/platforms/mipsel-qemu/halt.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file halt.s 3 | * @provides halt. 4 | * 5 | * $Id: halt.S 2086 2009-10-06 22:24:27Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | .text 12 | .align 4 13 | .globl halt 14 | 15 | /** 16 | * @fn void halt(void) 17 | * 18 | * Essentially this is a busy wait, however the opcode 'wait' puts the 19 | * processor in a powersave state (which can be awoken for arbitrary 20 | * reasons) 21 | */ 22 | .ent halt 23 | halt: 24 | wait 25 | j halt 26 | .end halt 27 | 28 | -------------------------------------------------------------------------------- /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 | #ifndef _STDLIB_H_ 9 | #define _STDLIB_H_ 10 | 11 | int abs(int); 12 | long labs(long); 13 | int atoi(char *); 14 | long atol(char *); 15 | void bzero(void *, int); 16 | void qsort(char *, unsigned int, int, int (*)(void)); 17 | unsigned long rand(void); 18 | void srand(unsigned int); 19 | void *malloc(unsigned int nbytes); 20 | void free(void *pmem); 21 | 22 | #endif /* _STDLIB_H_ */ 23 | -------------------------------------------------------------------------------- /lib/libxc/bzero.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bzero.c 3 | * @provides bzero. 4 | * 5 | * $Id: bzero.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Clears a block of characters to 0s 11 | * @param *p pointer to start of block 12 | * @param len length of the block 13 | */ 14 | void bzero(void *p, int len) 15 | { 16 | int n; 17 | char *pch = (char *)p; 18 | 19 | if ((n = len) <= 0) 20 | { 21 | return; 22 | } 23 | do 24 | { 25 | *pch++ = 0; 26 | } 27 | while (--n); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libxc/fputs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fputs.c 3 | * @provides fputs. 4 | * 5 | * $Id: fputs.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | extern int putc(int, char); 10 | 11 | /** 12 | * Write a null-terminated string to a device (file) 13 | * @param dev device to write to 14 | * @param *s string to write 15 | * @return result of last putc 16 | */ 17 | int fputs(char *s, int dev) 18 | { 19 | int r = 0, c; 20 | 21 | while ((c = (*s++))) 22 | { 23 | r = putc(dev, c); 24 | } 25 | return r; 26 | } 27 | -------------------------------------------------------------------------------- /system/wakeup.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wakeup.c 3 | * @provides wakeup. 4 | * 5 | * $Id: wakeup.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Wakeup and ready all threads that have no more time to sleep 16 | */ 17 | void wakeup(void) 18 | { 19 | while (nonempty(sleepq) && (firstkey(sleepq) <= 0)) 20 | { 21 | ready(dequeue(sleepq), RESCHED_NO); 22 | } 23 | } 24 | 25 | void testFn() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /network/snoop/Makerules: -------------------------------------------------------------------------------- 1 | #This Makefile contains rules to build files in the net/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = network/snoop 5 | 6 | # Source files for this component 7 | 8 | # Important network components 9 | C_FILES = snoopCapture.c snoopClose.c snoopFilter.c snoopOpen.c snoopPrint.c snoopPrintArp.c snoopPrintEthernet.c snoopPrintIpv4.c snoopPrintTcp.c snoopPrintUdp.c snoopRead.c 10 | S_FILES = 11 | 12 | # Add the files to the compile source path 13 | DIR = ${TOPDIR}/${COMP} 14 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 15 | -------------------------------------------------------------------------------- /lib/libxc/strnlen.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strnlen.c 3 | * @provides strnlen. 4 | * 5 | * $Id: strnlen.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Returns the number of non-NULL bytes in a string or len. 11 | * @param *s string 12 | * @param len length you wish to scan s too 13 | * @return length of the string up to user specified length 14 | */ 15 | int strnlen(const char *s, unsigned int len) 16 | { 17 | int n; 18 | 19 | n = 0; 20 | while (*s++ && n < len) 21 | n++; 22 | 23 | return (n); 24 | } 25 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/pause.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pause.S 3 | * @provides pause. 4 | * Platform-dependent code for idling the processor 5 | * 6 | * $Id: pause.S 2092 2009-10-07 23:08:36Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2008. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl pause 15 | 16 | /** 17 | * @fn void pause(void) 18 | * 19 | * Enter some kind of powerdown state (if it exists) that suspends 20 | * execution until an interrupt is detected. 21 | */ 22 | .ent pause 23 | pause: 24 | wait 25 | jr ra 26 | .end pause 27 | 28 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/pause.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pause.S 3 | * @provides pause. 4 | * Platform-dependent code for idling the processor 5 | * 6 | * $Id: pause.S 2086 2009-10-06 22:24:27Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl pause 15 | 16 | /** 17 | * @fn void pause(void) 18 | * 19 | * Enter some kind of powerdown state (if it exists) that suspends 20 | * execution until an interrupt is detected. 21 | */ 22 | .ent pause 23 | pause: 24 | wait 25 | jr ra 26 | .end pause 27 | 28 | -------------------------------------------------------------------------------- /system/platforms/mipsel-qemu/pause.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pause.S 3 | * @provides pause. 4 | * Platform-dependent code for idling the processor 5 | * 6 | * $Id: pause.S 2086 2009-10-06 22:24:27Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl pause 15 | 16 | /** 17 | * @fn void pause(void) 18 | * 19 | * Enter some kind of powerdown state (if it exists) that suspends 20 | * execution until an interrupt is detected. 21 | */ 22 | .ent pause 23 | pause: 24 | wait 25 | jr ra 26 | .end pause 27 | 28 | -------------------------------------------------------------------------------- /compile/data/testraw.txt: -------------------------------------------------------------------------------- 1 | # (1) ICMP request 192.168.1.1 > 192.168.1.6 2 | AABBCCDD 3 | EEFFAABB 4 | CCDDEEAA 5 | 08004500 6 | 001C0000 7 | 00004001 8 | F789C0A8 9 | 0101C0A8 10 | 01060800 11 | F7FE0000 12 | 0001 13 | 14 | # (2) ARP Reply 192.168.1.1 > 192.168.1.6 15 | AABBCCDDEEFF 16 | AABBCCDDEEAA 17 | 0806 18 | 0001 19 | 0800 20 | 06 21 | 04 22 | 0002 23 | AABBCCDDEEAA 24 | C0A80101 25 | AABBCCDDEEFF 26 | C0A80106 27 | 28 | # (3) ICMP request 192.168.1.6 > 192.168.1.1 29 | AABBCCDD 30 | EEAAAABB 31 | CCDDEEFF 32 | 08004500 33 | 001C0000 34 | 00004001 35 | F789C0A8 36 | 0106C0A8 37 | 01010800 38 | F7FF0000 39 | 0000 40 | -------------------------------------------------------------------------------- /include/backplane.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file backplane.h 3 | * 4 | * $Id: backplane.h 2020 2009-08-13 17:50:08Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _BACKPLANE_H__ 9 | #define _BACKPLANE_H__ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | devcall backplaneInit(device *); 16 | int backplaneCoreUp(volatile struct backplaneConfig *); 17 | int backplaneReset(volatile struct backplaneConfig *); 18 | int backplaneCoreDisable(volatile struct backplaneConfig *); 19 | 20 | #endif /* _BACKPLANE_H_ */ 21 | -------------------------------------------------------------------------------- /boot/raspberry-pi/config.txt: -------------------------------------------------------------------------------- 1 | # Don't delay before loading the code. 2 | boot_delay=0 3 | boot_delay_ms=0 4 | 5 | # Configure the serial port. 6 | init_uart_baud=9600 7 | init_uart_clock=3000000 8 | 9 | # Load and run code starting at the same address our QMEU system does. 10 | # By default, the GPU in the Pi will try to boot the ARM at 0x8000. 11 | kernel_address=0x00010000 12 | 13 | # Clocking options. 14 | # WARNING: Changing these may effect the timing of ARM peripheral devices. 15 | arm_freq=700 16 | gpu_freq=250 17 | core_freq=250 18 | sdram_freq=400 19 | arm_freq_min=700 20 | core_freq_min=250 21 | sdram_freq_min=400 22 | -------------------------------------------------------------------------------- /system/xdone.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file xdone.c 3 | * @provides xdone. 4 | * 5 | * $Id: xdone.c 2157 2010-01-19 00:40:07Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | extern void halt(void); 13 | 14 | /** 15 | * Print system completion message as last thread exits. 16 | */ 17 | void xdone(void) 18 | { 19 | kprintf("\r\n\r\nAll user processes have completed.\r\n\r\n"); 20 | #ifdef GPIO_BASE 21 | gpioLEDOff(GPIO_LED_CISCOWHT); 22 | #endif /* GPIO_BASE */ 23 | disable(); 24 | halt(); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libxc/fgetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fgetc.c 3 | * @provides fgetc. 4 | * 5 | * $Id: fgetc.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | extern int getc(int); 10 | 11 | #define EOF (-2) 12 | 13 | /** 14 | * Read a character from a device (file) 15 | * @param dev device to read from 16 | * @return character read, EOF if error 17 | */ 18 | int fgetc(int dev) 19 | { 20 | int result = (int)getc(dev); 21 | 22 | if (0 > result) 23 | { 24 | return EOF; 25 | } 26 | else 27 | { 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /shell/xsh_echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file xsh_echo.c 3 | * @provides xsh_echo 4 | */ 5 | /* Embedded Xinu, Copyright (C) 2008. All rights reserved. */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /** 13 | * Shell command (echo). 14 | * @param nargs number of arguments in args array 15 | * @param args array of arguments 16 | * @return OK for success, SYSERR for syntax error 17 | */ 18 | shellcmd xsh_echo(int nargs, char *args[]) 19 | { 20 | int i; 21 | for( i=1; i 10 | #include 11 | #include 12 | 13 | /** 14 | * Shell command (netemu). Allows user to set network emulator options. 15 | * @param nargs number of arguments 16 | * @param args array of arguments 17 | * @return non-zero value on error 18 | */ 19 | shellcmd xsh_netemu(int nargs, char *args[]) 20 | { 21 | srand(getRdate("192.168.6.10")); 22 | return 0; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /system/close.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file close.c 3 | * @provides close. 4 | * 5 | * $Id: close.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * close a device 14 | * @param descrp definition of device to close 15 | * @return function to close device on success, SYSERR on failure 16 | */ 17 | devcall close(int descrp) 18 | { 19 | device *devptr; 20 | 21 | if (isbaddev(descrp)) 22 | { 23 | return SYSERR; 24 | } 25 | devptr = (device *)&devtab[descrp]; 26 | return ((*devptr->close) (devptr)); 27 | } 28 | -------------------------------------------------------------------------------- /device/udp/udpGetbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file udpGetbuf.c 3 | * @provides udpGetbuf 4 | * 5 | * $Id: udpGetbuf.c 2076 2009-09-24 23:05:39Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | struct udpPkt *udpGetbuf(struct udp *udpptr) 16 | { 17 | struct udpPkt *udppkt = NULL; 18 | 19 | udppkt = bufget(udpptr->inPool); 20 | if (SYSERR == (int)udppkt) 21 | { 22 | return (struct udpPkt *)SYSERR; 23 | } 24 | 25 | bzero(udppkt, NET_MAX_PKTLEN); 26 | 27 | return udppkt; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libxc/fputc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fputc.c 3 | * @provides fputc. 4 | * 5 | * $Id: fputc.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | extern int putc(int, char); 10 | 11 | #define SYSERR (-1) 12 | #define EOF (-2) 13 | 14 | /** 15 | * Write a character string to a device (file) 16 | * @param c string to write 17 | * @param dev device to write to 18 | * @return character written, EOF if error 19 | */ 20 | int fputc(int c, int dev) 21 | { 22 | if (SYSERR == (int)putc(dev, c)) 23 | { 24 | return EOF; 25 | } 26 | else 27 | { 28 | return c; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /device/tcp/tcpGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpGetc.c 3 | * @provides tcpGetc 4 | * 5 | * $Id: tcpGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read into a single octet from TCP. 15 | * @param devptr TCP device table entry 16 | * @return character read from TCP 17 | */ 18 | devcall tcpGetc(device *devptr) 19 | { 20 | uchar ch; 21 | int result = 0; 22 | 23 | result = tcpRead(devptr, &ch, 1); 24 | 25 | if (result != 1) 26 | { 27 | return result; 28 | } 29 | 30 | return ch; 31 | } 32 | -------------------------------------------------------------------------------- /compile/config/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Make the Xinu configuration program 3 | # 4 | 5 | CC = gcc 6 | LEX = flex 7 | YACC = bison -y # Flag enables yacc-compatible filenames 8 | CFLAGS = 9 | LFLAGS = -lfl 10 | 11 | CONFIG = config 12 | 13 | all: ${CONFIG} 14 | 15 | ${CONFIG}: lex.yy.c y.tab.c 16 | $(CC) ${CFLAGS} -o $@ $^ ${LFLAGS} 17 | 18 | lex.yy.c: config.l y.tab.h 19 | $(LEX) --header-file=lex.yy.h config.l 20 | 21 | lex.yy.h: config.l 22 | $(LEX) --header-file=lex.yy.h config.l 23 | 24 | y.tab.c: config.y lex.yy.h 25 | $(YACC) config.y 26 | 27 | y.tab.h: config.y 28 | $(YACC) --defines=$@ $^ 29 | 30 | clean: 31 | rm -f ${CONFIG} lex.yy.c y.tab.c lex.yy.h y.tab.h 32 | -------------------------------------------------------------------------------- /device/tty/ttyInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ttyInit.c 3 | * @provides ttyInit. 4 | * 5 | * $Id: ttyInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct tty ttytab[NTTY]; 15 | 16 | /** 17 | * Initialize TTY structures. 18 | * @param devptr TTY device table entry 19 | * @return OK if device is initialized 20 | */ 21 | devcall ttyInit(device *devptr) 22 | { 23 | struct tty *ttyptr; 24 | 25 | ttyptr = &ttytab[devptr->minor]; 26 | bzero(ttyptr, sizeof(struct tty)); 27 | 28 | return OK; 29 | } 30 | -------------------------------------------------------------------------------- /device/udp/udpInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file udpInit.c 3 | * @provides udpInit 4 | * 5 | * $Id: udpInit.c 2114 2009-11-03 01:13:43Z zlund $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct udp udptab[NUDP]; 15 | 16 | /** 17 | * Set aside some space for a UDP device to be opened on 18 | * @param devptr UDP device table entry 19 | * @return OK 20 | */ 21 | devcall udpInit(device *devptr) 22 | { 23 | struct udp *udpptr; 24 | 25 | udpptr = &udptab[devptr->minor]; 26 | bzero(udpptr, sizeof(struct udp)); 27 | 28 | return OK; 29 | } 30 | -------------------------------------------------------------------------------- /device/raw/rawInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rawInit.c 3 | * @provides rawInit 4 | * 5 | * $Id: rawInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct raw rawtab[NRAW]; 15 | 16 | /** 17 | * Initialize raw socket structures. 18 | * @param devptr RAW device table entry 19 | * @return OK if device is initialized 20 | */ 21 | devcall rawInit(device *devptr) 22 | { 23 | struct raw *rawptr; 24 | 25 | rawptr = &rawtab[devptr->minor]; 26 | bzero(rawptr, sizeof(struct raw)); 27 | 28 | return OK; 29 | } 30 | -------------------------------------------------------------------------------- /device/telnet/telnetPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file telnetPutc.c 3 | * @provides telnetPutc. 4 | * 5 | * $Id: telnetPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Write a single character to TELNET. 14 | * @param devptr TELNET device table entry 15 | * @param ch character to output 16 | * @return OK if character was written sucessfully, otherwise SYSERR 17 | */ 18 | devcall telnetPutc(device *devptr, char ch) 19 | { 20 | if (SYSERR == telnetWrite(devptr, &ch, 1)) 21 | { 22 | return SYSERR; 23 | } 24 | 25 | return OK; 26 | } 27 | -------------------------------------------------------------------------------- /lib/libxc/memset.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memset.c 3 | * @provides memset. 4 | * 5 | * $Id: memset.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Place a character into first n characters. 11 | * @param s memory to place character into 12 | * @param c character to place 13 | * @param n number of times to place character 14 | * @return the pointer to memory 15 | */ 16 | void *memset(void *s, int c, int n) 17 | { 18 | register int i; 19 | char *cp = (char *)s; 20 | 21 | for (i = 0; i < n; i++) 22 | { 23 | *cp = (unsigned char)c; 24 | cp++; 25 | } 26 | return s; 27 | } 28 | -------------------------------------------------------------------------------- /lib/libxc/strncmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strncmp.c 3 | * @provides sstrncmp. 4 | * 5 | * $Id: strncmp.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Compare strings (at most n bytes). 11 | * @param *s1 first memory location 12 | * @param *s2 second memory location 13 | * @param n length to compare 14 | * @return s1>s2: >0 s1==s2: 0 s1= 0 && *s1 == *s2++) 20 | { 21 | if (*s1++ == '\0') 22 | { 23 | return 0; 24 | } 25 | } 26 | return (n < 0 ? 0 : *s1 - *--s2); 27 | } 28 | -------------------------------------------------------------------------------- /system/getc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file getc.c 3 | * @provides getc. 4 | * 5 | * $Id: getc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * get one character from a device 14 | * @param descrp definition of device from which to acquire character 15 | * @return function to get character on success, SYSERR on failure 16 | */ 17 | devcall getc(int descrp) 18 | { 19 | device *devptr; 20 | 21 | if (isbaddev(descrp)) 22 | { 23 | return SYSERR; 24 | } 25 | devptr = (device *)&devtab[descrp]; 26 | return ((*devptr->getc) (devptr)); 27 | } 28 | -------------------------------------------------------------------------------- /system/getprio.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file getprio.c 3 | * @provides getprio. 4 | * 5 | * $Id: getprio.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Return the scheduling priority of a thread 13 | * @param tid thread ID 14 | * @return priority of thread on success, SYSERR on failure 15 | */ 16 | syscall getprio(tid_typ tid) 17 | { 18 | int prio; 19 | irqmask im; 20 | 21 | im = disable(); 22 | if (isbadtid(tid)) 23 | { 24 | restore(im); 25 | return SYSERR; 26 | } 27 | 28 | prio = thrtab[tid].prio; 29 | restore(im); 30 | return prio; 31 | } 32 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/debugbreak.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file debugbreak.S 3 | * @provides debugbreak. 4 | * Give access to the assembly debug breakpoint command that drops 5 | * straight into debug mode. 6 | */ 7 | 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .set mips32 15 | 16 | /** 17 | * @fn debugbreak 18 | * 19 | * Inserts breakpoint and drops into debug mode. 20 | * Stores return address to DEPC register and jumps 21 | * back to it if processor returns from breakpoint. 22 | */ 23 | .globl debugbreak 24 | debugbreak: 25 | .set noreorder 26 | sdbbp 27 | nop 28 | jr ra 29 | nop 30 | .set reorder 31 | -------------------------------------------------------------------------------- /device/http/httpGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file httpGetc.c 3 | * @provides httpGetc. 4 | * 5 | * $Id: httpGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Read a single character from a HTTP. 14 | * @param devptr HTTP device table entry 15 | * @return character read from HTTP, or result if invalid read return 16 | */ 17 | devcall httpGetc(device *devptr) 18 | { 19 | char ch; 20 | int result = NULL; 21 | 22 | result = httpRead(devptr, &ch, 1); 23 | 24 | if (1 != result) 25 | { 26 | return result; 27 | } 28 | 29 | return ch; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libxc/memcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memcpy.c 3 | * @provides memcpy. 4 | * 5 | * $Id: memcpy.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Memory copy, copy a location in memory from src to dst. 11 | * @param s destination location 12 | * @param ct source location 13 | * @param n amount of data (in bytes) to copy 14 | * @return pointer to destination 15 | */ 16 | void *memcpy(void *s, const void *ct, int n) 17 | { 18 | register int i; 19 | char *dst = (char *)s; 20 | char *src = (char *)ct; 21 | 22 | for (i = 0; i < n; i++) 23 | { 24 | *dst++ = *src++; 25 | } 26 | return s; 27 | } 28 | -------------------------------------------------------------------------------- /device/led/fluke-led.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fluke-led.h 3 | * 4 | * $Id: fluke-led.h 2102 2009-10-26 20:36:13Z brylow $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _FLUKE_LED_H_ 9 | #define _FLUKE_LED_H_ 10 | 11 | #include 12 | 13 | /** 14 | * Control and status registers for the Fluke LEDs. This structure is 15 | * mapped directly to the base address for the CSR. 16 | */ 17 | struct led_csreg 18 | { 19 | volatile uint ioset; /**< the IOSET register */ 20 | volatile uint iodir; /**< the IODIR register (?) */ 21 | volatile uint ioclr; /**< the IOCLR register */ 22 | }; 23 | 24 | 25 | #endif /* _FLUKE_LED_H_ */ 26 | 27 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/versatile-arm926ej-s.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Platform specific definitons for the: 3 | * 4 | * ARM RealView Versatile Baseboard, using the ARM926EJ-S core. 5 | * 6 | * defined in: 7 | * ARM document HBI-0118 8 | */ 9 | 10 | #ifndef _VERSATILE_ARM926EJS_H 11 | #define _VERSATILE_ARM926EJS_H 12 | 13 | /* Memory-mapped location for the vectored interrupt controller. */ 14 | #define VIC_BASE_ADDRESS 0x10140000 15 | 16 | /* UART */ 17 | #define UART0_BASE_ADDRESS 0x101F1000 18 | #define UART1_BASE_ADDRESS 0x101F2000 19 | #define UART2_BASE_ADDRESS 0x101F3000 20 | 21 | #define UART0_IRQ 12 22 | #define UART1_IRQ 13 23 | #define UART2_IRq 14 24 | 25 | #endif /* _VERSATILE_ARM926EJS_H */ 26 | -------------------------------------------------------------------------------- /device/tty/ttyGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ttyGetc.c 3 | * @provides ttyGetc. 4 | * 5 | * $Id: ttyGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Read a single character from a TTY. 16 | * @param devptr TTY device table entry 17 | * @return character read from TTY, or EOF 18 | */ 19 | devcall ttyGetc(device *devptr) 20 | { 21 | char ch; 22 | int result = NULL; 23 | 24 | result = ttyRead(devptr, &ch, 1); 25 | 26 | if (1 != result) 27 | { 28 | return result; 29 | } 30 | 31 | return ch; 32 | } 33 | -------------------------------------------------------------------------------- /device/telnet/telnetGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file telnetGetc.c 3 | * @provides telnetGetc. 4 | * 5 | * $Id: telnetGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read a single character from TELNET. 15 | * @param devptr TELNET device table entry 16 | * @return character read from TELNET, or EOF 17 | */ 18 | devcall telnetGetc(device *devptr) 19 | { 20 | char ch; 21 | int result = NULL; 22 | 23 | result = telnetRead(devptr, &ch, 1); 24 | 25 | if (1 != result) 26 | { 27 | return result; 28 | } 29 | 30 | return ch; 31 | } 32 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/ar9130.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ar9130.h 3 | * 4 | * Constants and declarations associated with the Atheros 9130 5 | * wireless System On A Chip. 6 | * 7 | * $Id: ar9130.h 2092 2009-10-07 23:08:36Z brylow $ 8 | */ 9 | 10 | #define RST_MISC_INTERRUPT_MASK 0xB8060014 11 | #define RST_MISC_INTERRUPT_STATUS 0xB8060010 12 | 13 | #define RST_MISC_IRQ_TIMER (1 << 0) 14 | #define RST_MISC_IRQ_ERROR (1 << 1) 15 | #define RST_MISC_IRQ_GPIO (1 << 2) 16 | #define RST_MISC_IRQ_UART (1 << 3) 17 | #define RST_MISC_IRQ_WATCHDOG (1 << 4) 18 | #define RST_MISC_IRQ_PERF (1 << 5) 19 | #define RST_MISC_IRQ_MBOX (1 << 7) 20 | #define RST_MISC_IRQ_MASK 0x00FF 21 | -------------------------------------------------------------------------------- /device/raw/rawWrite.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rawWrite.c 3 | * @provides rawWrite 4 | * 5 | * $Id: rawWrite.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a packet to a raw socket. 15 | * @param devptr pointer to RAW device 16 | * @param buf buffer to write 17 | * @param len size of the buffer 18 | * @return number of octets written, SYSERR if error occurred 19 | */ 20 | devcall rawWrite(device *devptr, void *buf, uint len) 21 | { 22 | struct raw *rawptr; 23 | 24 | rawptr = &rawtab[devptr->minor]; 25 | return rawSend(rawptr, buf, len); 26 | } 27 | -------------------------------------------------------------------------------- /mem/memRegionClear.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memRegionClear.c 3 | * @provides memRegionClear. 4 | * Clear (initialize) a memory region to safe default values. 5 | * 6 | * $Id: memRegionClear.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Clear all the values of a given memory region to "safe" defaults. 14 | * @param region region of memory to clear. 15 | */ 16 | void memRegionClear(struct memregion *region) 17 | { 18 | region->prev = (struct memregion *)SYSERR; 19 | region->next = (struct memregion *)SYSERR; 20 | region->start = NULL; 21 | region->length = 0; 22 | region->thread_id = 0; 23 | } 24 | -------------------------------------------------------------------------------- /system/platforms/wrt160nl/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = system/platforms/wrt160nl 5 | 6 | # Source files for this component 7 | 8 | # Important system components 9 | S_FILES = startup.S pause.S 10 | C_FILES = platforminit.c 11 | 12 | # Files for process control 13 | S_FILES += ctxsw.S 14 | C_FILES += create.c 15 | 16 | # Files for preemption and interrupts 17 | S_FILES += clkupdate.S intutils.S intdispatch.S halt.S 18 | C_FILES += dispatch.c exception.c 19 | 20 | # Add the files to the compile source path 21 | DIR = ${TOPDIR}/${COMP} 22 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 23 | -------------------------------------------------------------------------------- /device/telnet/telnetClose.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file telnetClose.c 3 | * @provides telnetClose. 4 | * 5 | * $Id: telnetClose.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /* Close a TELNET device. 15 | * @param devptr TELNET device table entry 16 | * @return OK if TELNET is closed properly, otherwise SYSERR 17 | */ 18 | devcall telnetClose(device *devptr) 19 | { 20 | struct telnet *tntptr; 21 | 22 | tntptr = &telnettab[devptr->minor]; 23 | bzero(tntptr, sizeof(struct telnet)); 24 | tntptr->state = TELNET_STATE_FREE; 25 | return OK; 26 | } 27 | -------------------------------------------------------------------------------- /include/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform.h 3 | * @modified by Andrew Webster 4 | * 5 | * $Id: platform.h 2086 2009-10-06 22:24:27Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #ifndef _PLATFORM_H_ 10 | #define _PLATFORM_H_ 11 | 12 | #include 13 | #include 14 | 15 | #define PLT_STRMAX 18 16 | /** 17 | * Various platform specific settings 18 | */ 19 | struct platform 20 | { 21 | char name[PLT_STRMAX]; 22 | char family[PLT_STRMAX]; 23 | void *maxaddr; 24 | ulong clkfreq; 25 | uchar uart_dll; 26 | uchar uart_irqnum; 27 | }; 28 | 29 | extern struct platform platform; 30 | 31 | #endif /* _PLATFORM_H_ */ 32 | -------------------------------------------------------------------------------- /system/getdev.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file getdev.c 3 | * @provides getdev. 4 | * 5 | * $Id: getdev.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Returns the numerical identifier for the given device. 15 | * @param *dev device name 16 | * @return device number 17 | */ 18 | syscall getdev(char *dev) 19 | { 20 | int devnum; 21 | 22 | for (devnum = 0; devnum < NDEVS; devnum++) 23 | { 24 | if (0 == strncmp(dev, devtab[devnum].name, DEVMAXNAME)) 25 | { 26 | return devnum; 27 | } 28 | } 29 | 30 | return SYSERR; 31 | } 32 | -------------------------------------------------------------------------------- /device/ethloop/ethloopInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ethloopInit.c 3 | * @provides ethloopInit 4 | * 5 | * $Id: ethloopInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct ethloop elooptab[NETHLOOP]; 15 | 16 | /** 17 | * Initialize ethloop device 18 | * @param devptr 19 | * @return OK on open 20 | */ 21 | devcall ethloopInit(device *devptr) 22 | { 23 | struct ethloop *elpptr; 24 | 25 | elpptr = &elooptab[devptr->minor]; 26 | bzero(elpptr, sizeof(struct ethloop)); 27 | elpptr->state = ELOOP_STATE_FREE; 28 | 29 | return OK; 30 | } 31 | -------------------------------------------------------------------------------- /device/loopback/loopbackInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loopbackInit.c 3 | * @provides loopbackInit. 4 | * 5 | * $Id: loopbackInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct loopback looptab[NLOOPBACK]; 15 | 16 | /** 17 | * Initialize loopback device 18 | * @param devptr 19 | * @return OK on open 20 | */ 21 | devcall loopbackInit(device *devptr) 22 | { 23 | struct loopback *lbkptr = NULL; 24 | 25 | lbkptr = &looptab[devptr->minor]; 26 | lbkptr->state = LOOP_STATE_FREE; 27 | lbkptr->index = 0; 28 | 29 | return OK; 30 | } 31 | -------------------------------------------------------------------------------- /system/putc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file putc.c 3 | * @provides putc. 4 | * 5 | * $Id: putc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * write a single character to a device 14 | * @param descrp definition of device on which to write 15 | * @param ch character to write 16 | * @return function to write character on success, SYSERR on failure 17 | */ 18 | devcall putc(int descrp, char ch) 19 | { 20 | device *devptr; 21 | 22 | if (isbaddev(descrp)) 23 | { 24 | return SYSERR; 25 | } 26 | devptr = (device *)&devtab[descrp]; 27 | return ((*devptr->putc) (devptr, ch)); 28 | } 29 | -------------------------------------------------------------------------------- /device/tcp/tcpSendAck.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpSendAck.c 3 | * @provides tcpSendAck 4 | * 5 | * $Id: tcpSendAck.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Sends an ACK packet to ackowledge all received data for a TCP connection. 14 | * @param tcpptr pointer to the transmission control block for connection 15 | * @pre-condition TCB mutex is already held 16 | * @post-condition TCB mutex is still held 17 | */ 18 | int tcpSendAck(struct tcb *tcbptr) 19 | { 20 | tcbptr->sndflg &= ~TCP_FLG_SNDACK; 21 | return tcpSend(tcbptr, TCP_CTRL_ACK, tcbptr->sndnxt, 22 | tcbptr->rcvnxt, 0, 0); 23 | } 24 | -------------------------------------------------------------------------------- /shell/xsh_test.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file xsh_test.c 3 | * @provides xsh_test. 4 | * 5 | * $Id: xsh_test.c 2070 2009-09-18 22:36:02Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | 13 | /** 14 | * Shell command (test) provides a mechanism for testing Xinu features. The 15 | * action and output varies depending on the feature currently being tested. 16 | * This is not meant to serve as a permanent shell command for a particular 17 | * action. 18 | * @param nargs number of arguments 19 | * @param args array of arguments 20 | * @return non-zero value on error 21 | */ 22 | shellcmd xsh_test(int nargs, char *args[]) 23 | { 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /device/bcm4713/vlanClose.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file vlanClose.c 3 | * @provides vlanClose. 4 | * 5 | * $Id: vlanClose.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Close a virtual ethernet device. 17 | * @param devptr ether device table entry 18 | * @return OK if device is closed properly 19 | */ 20 | devcall vlanClose(device *devptr) 21 | { 22 | struct ether *ethptr = NULL; 23 | 24 | ethptr = ðertab[devptr->minor]; 25 | 26 | /* flag interface as down */ 27 | ethptr->state = ETH_STATE_DOWN; 28 | 29 | return OK; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libxc/fprintf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fprintf.c 3 | * @provides fprintf. 4 | * 5 | * $Id: fprintf.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | extern void _doprnt(char *, va_list, int (*)(int, int), int); 12 | 13 | /** 14 | * Print a formatted message on specified device (file) 15 | * @param dev device to write to 16 | * @param *fmt format string 17 | * @return 0 if the output was printed sucessfully, -1 if an error occured 18 | */ 19 | int fprintf(int dev, char *fmt, ...) 20 | { 21 | va_list ap; 22 | int putc(int, int); 23 | 24 | va_start(ap, fmt); 25 | _doprnt(fmt, ap, putc, dev); 26 | va_end(ap); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /mailbox/mailboxInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mailboxInit.c 3 | * @provides mailboxInit. 4 | * 5 | * $Id: mailboxInit.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | struct mbox mboxtab[NMAILBOX]; 13 | semaphore mboxtabsem; 14 | 15 | /** 16 | * Initialize mailbox structures. 17 | * @return OK if all mailboxes are initialized successfully 18 | */ 19 | syscall mailboxInit(void) 20 | { 21 | int i = 0; 22 | 23 | mboxtabsem = semcreate(1); 24 | 25 | /* set all mailbox states to MAILBOX_FREE */ 26 | for (i = 0; i < NMAILBOX; i++) 27 | { 28 | mboxtab[i].state = MAILBOX_FREE; 29 | } 30 | 31 | return OK; 32 | } 33 | -------------------------------------------------------------------------------- /system/constants.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define D2A_CS (1 << 21) 4 | #define A2D_CS (1 << 22) 5 | #define MCS (1 << 23) 6 | #define MCLK (1 << 4) 7 | #define MDIN (1 << 6) 8 | #define B_TXD (1 << 8) 9 | #define B_RTS (1 << 10) 10 | #define S_RST (1 << 12) 11 | #define IROUT2 (1 << 19) 12 | #define IROUT3 (1 << 20) 13 | #define IROUT1 (1 << 13) 14 | #define LED (1 << 17) 15 | 16 | /* General Purpose Input/Output (GPIO) */ 17 | #define IOPIN (*((volatile unsigned long *) 0xE0028000)) 18 | #define IOSET (*((volatile unsigned long *) 0xE0028004)) 19 | #define IODIR (*((volatile unsigned long *) 0xE0028008)) 20 | #define IOCLR (*((volatile unsigned long *) 0xE002800C)) 21 | 22 | -------------------------------------------------------------------------------- /system/seek.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file seek.c 3 | * @provides seek. 4 | * 5 | * $Id: seek.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * position a device (very common special case of control) 14 | * @param descrp definition of device on which to seek 15 | * @param pos requested position to seek 16 | * @return function to seek on device on success, SYSERR on failure 17 | */ 18 | devcall seek(int descrp, uint pos) 19 | { 20 | device *devptr; 21 | 22 | if (isbaddev(descrp)) 23 | { 24 | return SYSERR; 25 | } 26 | devptr = (device *)&devtab[descrp]; 27 | return ((*devptr->seek) (devptr, pos)); 28 | } 29 | -------------------------------------------------------------------------------- /device/http/httpFree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file httpFree.c 3 | * @provides httpFree 4 | * 5 | * $Id: httpFree.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Free an allocated HTTP device. 16 | * @param devptr pointer to HTTP device 17 | * @return OK if HTTP is freed properly, otherwise SYSERR 18 | */ 19 | int httpFree(device *devptr) 20 | { 21 | irqmask im; 22 | 23 | im = disable(); 24 | httptab[devptr->minor].state = HTTP_STATE_FREE; 25 | restore(im); 26 | 27 | /* Signal the counter for HTTP threads */ 28 | signal(maxhttp); 29 | 30 | return OK; 31 | } 32 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file string.h 3 | * 4 | * $Id: string.h 2033 2009-08-13 21:25:14Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #ifndef _STRING_H_ 9 | #define _STRING_H_ 10 | 11 | char *strncpy(char *, const char *, int); 12 | char *strncat(char *, const char *, int); 13 | int strncmp(const char *, const char *, int); 14 | char *strchr(const char *, int); 15 | char *strrchr(const char *, int); 16 | char *strstr(const char *, const char *); 17 | int strnlen(const char *, uint); 18 | 19 | int memcmp(const void *, const void *, int); 20 | void *memcpy(void *, const void *, int); 21 | void *memchr(const void *, int, int); 22 | void *memset(void *, int, int); 23 | 24 | #endif /* _STRING_H_ */ 25 | -------------------------------------------------------------------------------- /system/platforms/mipsel-qemu/pic8259.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pic8259.h 3 | * 4 | * PC-style i8259 programmable interrupt controller. 5 | * 6 | * $Id: pic8259.h 2157 2010-01-19 00:40:07Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #ifndef _PIC8259_H_ 11 | #define _PIC8259_H_ 12 | 13 | #ifdef PIC8259 14 | 15 | #define PIC_MASTER PIC8259 16 | #define PIC_MASTER_IMR (PIC_MASTER + 1) 17 | #define PIC_SLAVE (PIC_MASTER + 0x80) 18 | #define PIC_SLAVE_IMR (PIC_SLAVE + 1) 19 | #define PIC_MASTER_ELCR (PIC_MASTER + 0x4B0) 20 | #define PIC_SLAVE_ELCR (PIC_MASTER + 0x4B1) 21 | 22 | #endif /* PIC8259 */ 23 | 24 | /* PIC function prototypes */ 25 | 26 | #endif /* _PIC8259_H_ */ 27 | -------------------------------------------------------------------------------- /include/kernel.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file kernel.h 3 | * 4 | * The base include file for the Xinu kernel. Defines symbolic constants, 5 | * universal return constants, intialization constants, machine size 6 | * definitions, inline utility functions, and include types 7 | * 8 | * $Id: kernel.h 2020 2009-08-13 17:50:08Z mschul $ 9 | */ 10 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 11 | 12 | #ifndef _KERNEL_H_ 13 | #define _KERNEL_H_ 14 | 15 | #include 16 | #include 17 | 18 | /* Kernel function prototypes */ 19 | int nulluser(void); 20 | 21 | /* Kernel function prototypes */ 22 | syscall kprintf(char *fmt, ...); 23 | syscall kputc(device *, uchar); 24 | syscall kgetc(device *); 25 | 26 | #endif /* _KERNEL_H_ */ 27 | -------------------------------------------------------------------------------- /lib/libxc/strncat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strncat.c 3 | * @provides strncat. 4 | * 5 | * $Id: strncat.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Concatenate s2 on the end of s1. S1's space must be large enough. 11 | * At most n characters are moved. 12 | * @param *s1 first string 13 | * @param *s2 second string 14 | * @param n length to concatenate 15 | * @return s1 16 | */ 17 | char *strncat(char *s1, const char *s2, int n) 18 | { 19 | char *os1; 20 | 21 | os1 = s1; 22 | while (*s1++) 23 | ; 24 | --s1; 25 | while ((*s1++ = *s2++)) 26 | if (--n < 0) 27 | { 28 | *--s1 = '\0'; 29 | break; 30 | } 31 | return (os1); 32 | } 33 | -------------------------------------------------------------------------------- /mem/memRegionTransfer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memRegionTransfer.c 3 | * @provides memRegionTransfer. 4 | * Transfer a memory region to a new thread. 5 | * 6 | * $Id: memRegionTransfer.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Transfer a memory region from the owning thread to a new thread. 14 | * @param start beginning address of memory region. 15 | * @param tid thread id to transfer region to. 16 | */ 17 | void memRegionTransfer(void *start, tid_typ tid) 18 | { 19 | struct memregion *region; 20 | 21 | region = memRegionValid(start); 22 | if (SYSERR == (int)region) 23 | { 24 | return; 25 | } 26 | 27 | region->thread_id = tid; 28 | } 29 | -------------------------------------------------------------------------------- /lib/libxc/memchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memchr.c 3 | * @provides memchr. 4 | * 5 | * $Id: memchr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Returns a pointer to the location in memory at which which a particular 11 | * character appears. 12 | * @param *cs string to search 13 | * @param c character to locate 14 | * @param n number of bytes to search 15 | * @return the pointer in the string, NULL if character not found 16 | */ 17 | void *memchr(const void *cs, int c, int n) 18 | { 19 | char *cp = (char *)cs; 20 | 21 | for (; *cp != '\0'; cp++) 22 | { 23 | if (*cp == (unsigned char)c) 24 | { 25 | return (void *)cp; 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /lib/libxc/strchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strchr.c 3 | * @provides strchr. 4 | * 5 | * $Id: strchr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Returns a pointer to the location in a string at which which a particular 11 | * character appears. 12 | * @param *s string to search 13 | * @param c character to locate 14 | * @return the pointer in the string, NULL if character not found 15 | */ 16 | char *strchr(const char *s, int c) 17 | { 18 | for (; *s != '\0'; s++) 19 | { 20 | if (*s == (const char)c) 21 | { 22 | return (char *)s; 23 | } 24 | } 25 | 26 | if ((const char)c == *s) 27 | { 28 | return (char *)s; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /network/emulate/emuDelay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file emuDelay.c 3 | * @provides emuDelay 4 | * 5 | * $Id: emuDelay.c 2126 2009-11-12 07:23:04Z svn $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Delay packets as specified by user 16 | * @param pkt pointer to the incoming packet 17 | * @return OK if packet was processed succesfully, otherwise SYSERR 18 | */ 19 | syscall emuDelay(struct packet *pkt) 20 | { 21 | /* 22 | short delayTime = 100; 23 | short delayPercent = 100; 24 | 25 | if ((rand() % 100) < delayPercent) 26 | { 27 | sleep(delayTime); 28 | } 29 | */ 30 | return emuDuplicate(pkt); 31 | } 32 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/usleep.S: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * usleep (when clock is set to 60 Mhz) 4 | * 5 | * Parameters: 6 | * R0 - sleep time in microseconds 7 | * 8 | * 9 | * keith.ohara@gatech.edu 10 | * April 2008 11 | * IPRE Fluke Firmware 12 | * 13 | ******************************************************************************/ 14 | 15 | .file "usleep.s" 16 | .arm 17 | .align 18 | .globl usleep 19 | .type usleep, %function 20 | /* .section .data,"ax",%progbits */ 21 | usleep: 22 | STMFD SP!, {R0-R12, LR} 23 | usleep_delay: 24 | LDR R5, =14 25 | usleep_delay_inner: 26 | SUBS R5, R5, #1 27 | BNE usleep_delay_inner 28 | 29 | SUBS R0, R0, #1 30 | BNE usleep_delay 31 | 32 | /* return */ 33 | LDMFD SP!, {R0-R12, PC} 34 | -------------------------------------------------------------------------------- /lib/libxc/memcmp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memcmp.c 3 | * @provides memcmp. 4 | * 5 | * $Id: memcmp.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Compare memory (ISO C89). 11 | * Assumes memory locations are same length 12 | * @param s1 first memory location 13 | * @param s2 second memory location 14 | * @param n length to compare 15 | * @return s1>s2: >0 s1==s2: 0 s1 0; n--, c1++, c2++) 23 | { 24 | if (*c1 != *c2) 25 | { 26 | return ((int)*c1) - ((int)*c2); 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /device/tcp/tcpTimerTrigger.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpTimerTrigger.c 3 | * @provides tcpTimerTrigger 4 | * 5 | * $Id: tcpTimerTrigger.c 2076 2009-09-24 23:05:39Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Processes TCP timer events. 15 | * @param evtptr timer event to process 16 | */ 17 | void tcpTimerTrigger(uchar type, struct tcb *tcbptr) 18 | { 19 | switch (type) 20 | { 21 | case TCP_EVT_TIMEWT: 22 | wait(tcbptr->mutex); 23 | tcpFree(tcbptr); 24 | return; 25 | case TCP_EVT_RXT: 26 | tcpSendRxt(tcbptr); 27 | return; 28 | case TCP_EVT_PERSIST: 29 | tcpSendPersist(tcbptr); 30 | return; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/usleep.S: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * usleep (when clock is set to 60 Mhz) 4 | * 5 | * Parameters: 6 | * R0 - sleep time in microseconds 7 | * 8 | * 9 | * keith.ohara@gatech.edu 10 | * April 2008 11 | * IPRE Fluke Firmware 12 | * 13 | ******************************************************************************/ 14 | 15 | .file "usleep.s" 16 | .arm 17 | .align 18 | .globl usleep 19 | .type usleep, %function 20 | /* .section .data,"ax",%progbits */ 21 | usleep: 22 | STMFD SP!, {R0-R12, LR} 23 | usleep_delay: 24 | LDR R5, =14 25 | usleep_delay_inner: 26 | SUBS R5, R5, #1 27 | BNE usleep_delay_inner 28 | 29 | SUBS R0, R0, #1 30 | BNE usleep_delay 31 | 32 | /* return */ 33 | LDMFD SP!, {R0-R12, PC} 34 | -------------------------------------------------------------------------------- /lib/libxc/atoi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file atoi.c 3 | * @provides atoi. 4 | * 5 | * $Id: atoi.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Converts an ascii value to an integer. 11 | * @param *p pointer to ascii string 12 | * @return integer 13 | */ 14 | int atoi(char *p) 15 | { 16 | int n = 0, f = 0; 17 | 18 | for (;; p++) 19 | { 20 | switch (*p) 21 | { 22 | case ' ': 23 | case '\t': 24 | continue; 25 | case '-': 26 | f++; 27 | case '+': 28 | p++; 29 | } 30 | break; 31 | } 32 | 33 | while (*p >= '0' && *p <= '9') 34 | { 35 | n = n * 10 + *p++ - '0'; 36 | } 37 | 38 | return (f ? -n : n); 39 | } 40 | -------------------------------------------------------------------------------- /loader/platforms/wrt160nl/start.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file start.S 3 | * @provides _start. 4 | * This is where the firmware environment begins to execute code. 5 | * 6 | * $Id: start.S 2103 2009-10-27 01:43:40Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl _start 15 | 16 | /** 17 | * The firmware will load the image into temporary 18 | * memory via TFTP and will then jump to this (_start) label. 19 | * The boot loader (_start) flushes L1 instruction and data caches. 20 | */ 21 | .ent _start 22 | _start: 23 | /* Clear and invalidate the L1 instruction and data caches */ 24 | jal flushcache 25 | 26 | /* Pass control to Xinu kernel. */ 27 | j _startup 28 | .end _start 29 | -------------------------------------------------------------------------------- /loader/platforms/wrt54gl/start.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file start.S 3 | * @provides _start. 4 | * This is where the firmware environment begins to execute code. 5 | * 6 | * $Id: start.S 2103 2009-10-27 01:43:40Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl _start 15 | 16 | /** 17 | * The firmware will load the image into temporary 18 | * memory via TFTP and will then jump to this (_start) label. 19 | * The boot loader (_start) flushes L1 instruction and data caches. 20 | */ 21 | .ent _start 22 | _start: 23 | /* Clear and invalidate the L1 instruction and data caches */ 24 | jal flushcache 25 | 26 | /* Pass control to Xinu kernel. */ 27 | j _startup 28 | .end _start 29 | -------------------------------------------------------------------------------- /system/read.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file read.c 3 | * @provides read. 4 | * 5 | * $Id: read.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * read one or more bytes from a device 14 | * @param descrp definition of device from which to read 15 | * @param *buffer pointer into read-to location 16 | * @param count length of buffer 17 | * @return function to read from device on success, SYSERR on failure 18 | */ 19 | devcall read(int descrp, void *buffer, uint count) 20 | { 21 | device *devptr; 22 | 23 | if (isbaddev(descrp)) 24 | { 25 | return SYSERR; 26 | } 27 | devptr = (device *)&devtab[descrp]; 28 | return ((*devptr->read) (devptr, buffer, count)); 29 | } 30 | -------------------------------------------------------------------------------- /device/udp/udpAlloc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file udpAlloc.c 3 | * @provides udpAlloc. 4 | * 5 | * $Id: udpAlloc.c 2114 2009-11-03 01:13:43Z zlund $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Allocate an available udp device. 15 | * @return device number for a udp device, SYSERR if none are free 16 | */ 17 | ushort udpAlloc(void) 18 | { 19 | irqmask im; 20 | int i; 21 | 22 | im = disable(); 23 | for (i = 0; i < NUDP; i++) 24 | { 25 | if (UDP_FREE == udptab[i].state) 26 | { 27 | udptab[i].state = UDP_ALLOC; 28 | restore(im); 29 | return i + UDP0; 30 | } 31 | } 32 | restore(im); 33 | 34 | return SYSERR; 35 | } 36 | -------------------------------------------------------------------------------- /loader/platforms/mipsel-qemu/start.S: -------------------------------------------------------------------------------- 1 | /** 2 | * @file start.S 3 | * @provides _start. 4 | * This is where the firmware environment begins to execute code. 5 | * 6 | * $Id: start.S 2103 2009-10-27 01:43:40Z brylow $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | .text 13 | .align 4 14 | .globl _start 15 | 16 | /** 17 | * The firmware will load the image into temporary 18 | * memory via TFTP and will then jump to this (_start) label. 19 | * The boot loader (_start) flushes L1 instruction and data caches. 20 | */ 21 | .ent _start 22 | _start: 23 | /* Clear and invalidate the L1 instruction and data caches */ 24 | jal flushcache 25 | 26 | /* Pass control to Xinu kernel. */ 27 | j _startup 28 | .end _start 29 | -------------------------------------------------------------------------------- /system/open.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file open.c 3 | * @provides open. 4 | * 5 | * $Id: open.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * open a connection to a device 15 | * @param descrp definition of device to open 16 | * @return function to open device on success, SYSERR on failure 17 | */ 18 | devcall open(int descrp, ...) 19 | { 20 | device *devptr; 21 | va_list ap; 22 | devcall result; 23 | 24 | if (isbaddev(descrp)) 25 | { 26 | return SYSERR; 27 | } 28 | devptr = (device *)&devtab[descrp]; 29 | va_start(ap, descrp); 30 | result = ((*devptr->open) (devptr, ap)); 31 | va_end(ap); 32 | return result; 33 | } 34 | -------------------------------------------------------------------------------- /system/signal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file signal.c 3 | * @provides signal. 4 | * 5 | * $Id: signal.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * signal a semaphore, releasing one waiting thread 13 | * @param sem target semaphore 14 | * @return OK on success, SYSERR on failure 15 | */ 16 | syscall signal(semaphore sem) 17 | { 18 | register struct sement *semptr; 19 | irqmask im; 20 | 21 | im = disable(); 22 | if (isbadsem(sem)) 23 | { 24 | restore(im); 25 | return SYSERR; 26 | } 27 | semptr = &semtab[sem]; 28 | if ((semptr->count++) < 0) 29 | { 30 | ready(dequeue(semptr->queue), RESCHED_YES); 31 | } 32 | restore(im); 33 | return OK; 34 | } 35 | -------------------------------------------------------------------------------- /system/platforms/mipsel-qemu/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = system/platforms/mipsel-qemu 5 | 6 | # Source files for this component 7 | 8 | # Important system components 9 | S_FILES = startup.S pause.S 10 | C_FILES = platforminit.c 11 | 12 | # Files for process control 13 | S_FILES += ctxsw.S 14 | C_FILES += create.c 15 | 16 | # Files for preemption and interrupts 17 | S_FILES += clkupdate.S intutils.S intdispatch.S halt.S 18 | C_FILES += dispatch.c exception.c 19 | 20 | # Files for system calls 21 | S_FILES += syscall_entry.S 22 | C_FILES += syscall_dispatch.c 23 | 24 | # Add the files to the compile source path 25 | DIR = ${TOPDIR}/${COMP} 26 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 27 | -------------------------------------------------------------------------------- /system/write.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file write.c 3 | * @provides write. 4 | * 5 | * $Id: write.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * write 1 or more bytes to a device 14 | * @param descrp definition of device on which to write 15 | * @param *buffer pointer to data to be written 16 | * @param count length of data to be written 17 | * @return function to write data on success, SYSERR on failure 18 | */ 19 | devcall write(int descrp, void *buffer, uint count) 20 | { 21 | device *devptr; 22 | 23 | if (isbaddev(descrp)) 24 | { 25 | return SYSERR; 26 | } 27 | devptr = (device *)&devtab[descrp]; 28 | return ((*devptr->write) (devptr, buffer, count)); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libxc/atol.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file atol.c 3 | * @provides atol. 4 | * 5 | * $Id: atol.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Converts an ascii value to a long. 11 | * @param *p pointer to ascii string 12 | * @return long 13 | */ 14 | long atol(char *p) 15 | { 16 | long n; 17 | int f; 18 | 19 | n = 0; 20 | f = 0; 21 | for (;; p++) 22 | { 23 | switch (*p) 24 | { 25 | case ' ': 26 | case '\t': 27 | continue; 28 | case '-': 29 | f++; 30 | case '+': 31 | p++; 32 | } 33 | break; 34 | } 35 | while (*p >= '0' && *p <= '9') 36 | { 37 | n = n * 10 + *p++ - '0'; 38 | } 39 | return (f ? -n : n); 40 | } 41 | -------------------------------------------------------------------------------- /lib/libxc/strrchr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strrchr.c 3 | * @provides strrchr. 4 | * 5 | * $Id: strrchr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Returns a pointer to the location in a string at which which a particular 11 | * character last appears. 12 | * @param *s string to search 13 | * @param c character to locate 14 | * @return the pointer in the string, NULL if character not found 15 | */ 16 | char *strrchr(const char *s, int c) 17 | { 18 | char *r = 0; 19 | 20 | for (; *s != '\0'; s++) 21 | { 22 | if (*s == (const char)c) 23 | { 24 | r = (char *)s; 25 | } 26 | } 27 | 28 | if ((const char)c == *s) 29 | { 30 | return (char *)s; 31 | } 32 | 33 | return r; 34 | } 35 | -------------------------------------------------------------------------------- /system/unistd.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file unistd.c 3 | * @provides getnum, printnum. 4 | */ 5 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | syscall getnum(void) 13 | { 14 | int i = 0, c = 0; 15 | 16 | control(CONSOLE, TTY_CTRL_SET_IFLAG, TTY_ECHO, 0); 17 | fprintf(CONSOLE, "? "); 18 | 19 | c = getchar(); 20 | while (('\n' != c) && ('\r' != c) && (!iseof(c))) 21 | { 22 | if (('0' <= c) && ('9' >= c)) 23 | { 24 | i = i * 10 + c - '0'; 25 | } 26 | 27 | c = getchar(); 28 | } 29 | 30 | if (EOF == c) 31 | return c; 32 | 33 | return i; 34 | } 35 | 36 | syscall printnum(int i) 37 | { 38 | return fprintf(CONSOLE, "%d\n", i); 39 | } 40 | -------------------------------------------------------------------------------- /system/platforms/fluke-arm/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = system/platforms/fluke-arm 5 | 6 | # Source files for this component 7 | 8 | # Important system components 9 | S_FILES = ctxsw.S pause.S 10 | C_FILES = create.c debug.c handlers.c interrupt.c platforminit.c stubs.c vic.c timer.c 11 | 12 | PDIR = $(TOPDIR)/$(COMP) 13 | $(PDIR)/vic.o: $(PDIR)/vic.c $(PDIR)/vic.h 14 | $(PDIR)/interrupts.o: $(PDIR)/interrupts.c $(PDIR)/vic.h 15 | 16 | 17 | # Files for testing memory locations 18 | C_FILES += mem.c 19 | 20 | # Files for helping modularization 21 | C_FILES += test.c 22 | 23 | # Add the files to the compile source path 24 | DIR = ${TOPDIR}/${COMP} 25 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 26 | -------------------------------------------------------------------------------- /system/resume.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file resume.c 3 | * @provides resume. 4 | * 5 | * $Id: resume.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Unsuspend a thread, making it ready 14 | * @param tid target thread 15 | * @return priority 16 | */ 17 | syscall resume(tid_typ tid) 18 | { 19 | register struct thrent *thrptr; /* thread control block */ 20 | irqmask im; 21 | int prio; 22 | 23 | im = disable(); 24 | thrptr = &thrtab[tid]; 25 | if (isbadtid(tid) || (thrptr->state != THRSUSP)) 26 | { 27 | restore(im); 28 | return SYSERR; 29 | } 30 | 31 | prio = thrptr->prio; 32 | ready(tid, RESCHED_YES); 33 | restore(im); 34 | return prio; 35 | } 36 | -------------------------------------------------------------------------------- /device/tcp/tcpAlloc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpAlloc.c 3 | * @provides tcpAlloc. 4 | * 5 | * $Id: tcpAlloc.c 1991 2009-08-12 01:35:28Z agember $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Allocate an available tcp device. 15 | * @return device number for a tcp device, SYSERR if none are free 16 | */ 17 | ushort tcpAlloc(void) 18 | { 19 | int i; 20 | 21 | for (i = 0; i < NTCP; i++) 22 | { 23 | wait(tcptab[i].mutex); 24 | if (TCP_FREE == tcptab[i].devstate) 25 | { 26 | tcptab[i].devstate = TCP_ALLOC; 27 | signal(tcptab[i].mutex); 28 | return i + TCP0; 29 | } 30 | signal(tcptab[i].mutex); 31 | } 32 | return SYSERR; 33 | } 34 | -------------------------------------------------------------------------------- /network/snoop/snoopRead.c: -------------------------------------------------------------------------------- 1 | /* @file snoopRead.c 2 | * @provides snoopRead 3 | * 4 | * $Id: snoopRead.c 2020 2009-08-13 17:50:08Z mschul $ 5 | */ 6 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 7 | 8 | #include 9 | #include 10 | 11 | /** 12 | * Returns a packet captured from a network interface. 13 | * @return a packet if read was successful, otherwise SYSERR 14 | */ 15 | struct packet *snoopRead(struct snoop *cap) 16 | { 17 | struct packet *pkt; 18 | 19 | /* Error check pointers */ 20 | if (NULL == cap) 21 | { 22 | return (struct packet *)SYSERR; 23 | } 24 | 25 | pkt = (struct packet *)mailboxReceive(cap->queue); 26 | if ((SYSERR == (int)pkt) || (NULL == pkt)) 27 | { 28 | return (struct packet *)SYSERR; 29 | } 30 | 31 | return pkt; 32 | } 33 | -------------------------------------------------------------------------------- /device/http/httpFlushWBuffer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file httpFlushWBuffer.c 3 | * @provides httpFlushWBuffer 4 | * 5 | * $Id: httpFlushWBuffer.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Flush the intermediate write buffer out to underlying device. 14 | * @param devptr HTTP device that has the buffer to flush 15 | */ 16 | void httpFlushWBuffer(device *devptr) 17 | { 18 | /* Set the flush flag */ 19 | httpControl(devptr, HTTP_CTRL_SET_FLAG, HTTP_FLAG_FLUSHWOUT, NULL); 20 | 21 | /* Write a zero length buf, write will flush because of set flag */ 22 | httpWrite(devptr, NULL, 0); 23 | 24 | /* Clear the flush flag */ 25 | httpControl(devptr, HTTP_CTRL_CLR_FLAG, HTTP_FLAG_FLUSHWOUT, NULL); 26 | } 27 | -------------------------------------------------------------------------------- /device/tty/ttyClose.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ttyClose.c 3 | * @provides ttyClose. 4 | * 5 | * $Id: ttyClose.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Close a TTY device. 17 | * @param devptr TTY device table entry 18 | * @return OK if TTY is closed properly, otherwise SYSERR 19 | */ 20 | devcall ttyClose(device *devptr) 21 | { 22 | struct tty *ttyptr; 23 | irqmask im; 24 | 25 | im = disable(); 26 | /* Setup and error check pointers to structures */ 27 | ttyptr = &ttytab[devptr->minor]; 28 | bzero(ttyptr, sizeof(struct tty)); /* Clear TTY structure. */ 29 | restore(im); 30 | return OK; 31 | } 32 | -------------------------------------------------------------------------------- /lib/libxc/strncpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strncpy.c 3 | * @provides strncpy. 4 | * 5 | * $Id: strncpy.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Copy string s2 to s1, truncating or null-padding to always copy n bytes. 11 | * @param s1 first string 12 | * @param s2 second string 13 | * @param n length of s2 to copy 14 | * @return s1 15 | */ 16 | char *strncpy(char *s1, const char *s2, int n) 17 | { 18 | register int i; 19 | register char *os1; 20 | 21 | os1 = s1; 22 | for (i = 0; i < n; i++) 23 | { 24 | if (((*s1++) = (*s2++)) == '\0') 25 | { 26 | while (++i < n) 27 | { 28 | *s1++ = '\0'; 29 | } 30 | return os1; 31 | } 32 | } 33 | return os1; 34 | } 35 | -------------------------------------------------------------------------------- /mem/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the mem/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = mem 5 | 6 | # Region Allocator files 7 | ALLOC_FILES = memRegionInit.c memRegionClear.c memRegionInsert.c memRegionRemove.c memRegionSplit.c memRegionValid.c memRegionTransfer.c memRegionAlloc.c memRegionReclaim.c 8 | 9 | # User Allocator files 10 | USER_FILES = malloc.c free.c 11 | 12 | # Memory Protection files 13 | SAFEMEM_FILES = safeInit.c safeMap.c safeMapRange.c safeUnmap.c safeUnmapRange.c safeKmapInit.c 14 | 15 | # TLB Handler files 16 | TLB_FILES = tlbInit.c tlbMiss.S tlbMissHandler.c 17 | 18 | FILES = ${ALLOC_FILES} ${USER_FILES} ${SAFEMEM_FILES} ${TLB_FILES} 19 | 20 | # Add the files to the compile source path 21 | DIR = ${TOPDIR}/${COMP} 22 | COMP_SRC += ${FILES:%=${DIR}/%} 23 | -------------------------------------------------------------------------------- /system/chprio.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file chprio.c 3 | * @provides chprio. 4 | * 5 | * $Id: chprio.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Change the scheduling priority of a thread 13 | * @param tid target thread 14 | * @param newprio new priority 15 | * @return old priority of thread 16 | */ 17 | syscall chprio(tid_typ tid, int newprio) 18 | { 19 | register struct thrent *thrptr; /* thread control block */ 20 | irqmask im; 21 | int oldprio; 22 | 23 | im = disable(); 24 | if (isbadtid(tid)) 25 | { 26 | restore(im); 27 | return SYSERR; 28 | } 29 | thrptr = &thrtab[tid]; 30 | oldprio = thrptr->prio; 31 | thrptr->prio = newprio; 32 | restore(im); 33 | return oldprio; 34 | } 35 | -------------------------------------------------------------------------------- /system/recvclr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file recvclr.c 3 | * @provides recvclr. 4 | * 5 | * $Id: recvclr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Clear messages, return waiting message (if any) 13 | * @return msg if available, NOMSG if no message 14 | */ 15 | message recvclr(void) 16 | { 17 | register struct thrent *thrptr; 18 | irqmask im; 19 | message msg; 20 | 21 | im = disable(); 22 | thrptr = &thrtab[thrcurrent]; 23 | if (thrptr->hasmsg) 24 | { 25 | msg = thrptr->msg; 26 | } /* retrieve message */ 27 | else 28 | { 29 | msg = NOMSG; 30 | } 31 | thrptr->hasmsg = FALSE; /* reset message flag */ 32 | restore(im); 33 | return msg; 34 | } 35 | -------------------------------------------------------------------------------- /device/http/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/http 5 | 6 | # Source files for this component 7 | DEV_FILES = httpClose.c httpControl.c \ 8 | httpGetc.c httpInit.c httpOpen.c httpPutc.c \ 9 | httpRead.c httpWrite.c 10 | HELP_FILES = httpAlloc.c httpCleanPrompts.c httpConfigPage.c \ 11 | httpErrorResponse.c \ 12 | httpFlushWBuffer.c httpFree.c \ 13 | httpHtmlBegin.c httpReadRqst.c \ 14 | httpReadHdrs.c httpValidations.c 15 | SERVER_FILES = httpServer.c 16 | 17 | S_FILES = 18 | 19 | C_FILES = ${DEV_FILES} ${HELP_FILES} ${SERVER_FILES} 20 | 21 | # Add the files to the compile source path 22 | DIR = ${TOPDIR}/${COMP} 23 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 24 | -------------------------------------------------------------------------------- /network/netaddr/netaddrhost.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netaddrhost.c 3 | * @provides netaddrhost 4 | * 5 | * $Id: netaddrhost.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Return host portion of network address 14 | * @param a network address 15 | * @param b mask 16 | * @return host portion of network address 17 | */ 18 | syscall netaddrhost(struct netaddr *a, struct netaddr *mask) 19 | { 20 | int i; 21 | if (a->type != mask->type) 22 | { 23 | return SYSERR; 24 | } 25 | 26 | if (a->len != mask->len) 27 | { 28 | return SYSERR; 29 | } 30 | 31 | for (i = 0; i < a->len; i++) 32 | { 33 | a->addr[i] = a->addr[i] & ~mask->addr[i]; 34 | } 35 | 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /system/ready.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ready.c 3 | * @provides ready. 4 | * 5 | * $Id: ready.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Make a thread eligible for CPU service. 14 | * @param tid target thread 15 | * @param resch if RESCHED_YES, reschedules 16 | * @return OK if thread has been added to readylist, else SYSERR 17 | */ 18 | int ready(tid_typ tid, bool resch) 19 | { 20 | register struct thrent *thrptr; 21 | 22 | if (isbadtid(tid)) 23 | { 24 | return SYSERR; 25 | } 26 | 27 | thrptr = &thrtab[tid]; 28 | thrptr->state = THRREADY; 29 | 30 | insert(tid, readylist, thrptr->prio); 31 | 32 | if (resch == RESCHED_YES) 33 | { 34 | resched(); 35 | } 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /device/http/httpAlloc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file httpAlloc.c 3 | * @provides httpAlloc. 4 | * 5 | * $Id: httpAlloc.c 2051 2009-08-27 20:55:09Z akoehler $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | /** 16 | * Allocate an available http device. 17 | * @return device number for a http device, SYSERR if none are free 18 | */ 19 | int httpAlloc(void) 20 | { 21 | irqmask ps; 22 | int i; 23 | 24 | ps = disable(); 25 | for (i = 0; i < NHTTP; ++i) 26 | { 27 | if (HTTP_STATE_FREE == httptab[i].state) 28 | { 29 | httptab[i].state = HTTP_STATE_ALLOC; 30 | restore(ps); 31 | return i + HTTP0; 32 | } 33 | } 34 | restore(ps); 35 | 36 | return SYSERR; 37 | } 38 | -------------------------------------------------------------------------------- /system/platforms/arm-qemu/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = system/platforms/arm-qemu 5 | 6 | # Source files for this component 7 | 8 | # Important system components 9 | S_FILES = ctxsw.S pause.S halt.S 10 | C_FILES = debug.c debugret.c create.c debug.c handlers.c interrupt.c platforminit.c stubs.c vic.c timer.c clkupdate.c irq.c 11 | 12 | PDIR = $(TOPDIR)/$(COMP) 13 | $(PDIR)/vic.o: $(PDIR)/vic.c $(PDIR)/vic.h 14 | $(PDIR)/interrupts.o: $(PDIR)/interrupts.c $(PDIR)/vic.h 15 | 16 | 17 | # Files for testing memory locations 18 | C_FILES += mem.c 19 | 20 | # Files for helping modularization 21 | C_FILES += test.c 22 | 23 | # Add the files to the compile source path 24 | DIR = ${TOPDIR}/${COMP} 25 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 26 | -------------------------------------------------------------------------------- /lib/libdsp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Make the Xinu version of the C run-time support library 3 | # 4 | 5 | INCLUDE = -I../../include -I../../system/platforms/${PLATFORM} 6 | LIBDIR = .. 7 | 8 | LIBNAME = libdsp 9 | 10 | # Make sure the library is optimized for size, if we want any optimization 11 | CFLAGS := ${CFLAGS:-O%=-Os} 12 | 13 | # Update the include flag 14 | CFLAGS := ${CFLAGS:-I%=${INCLUDE}} 15 | 16 | .s.o: 17 | ${AS} -o $@ ${AFLAGS} $< 18 | 19 | .c.o: 20 | ${CC} ${CFLAGS} $< 21 | 22 | CFILES = linear2ulaw.c ulaw2linear.c 23 | 24 | OFILE2 = ${CFILES:%.c=%.o} 25 | OFILES = ${OFILE2:%.s=%.o} 26 | 27 | all: ${LIBNAME}.a 28 | 29 | ${LIBNAME}.a: ${OFILES} 30 | rm -f ${LIBNAME}.a 31 | ${AR} cr ${LIBNAME}.a ${OFILES} 32 | 33 | install: ${LIBNAME}.a 34 | cp ${LIBNAME}.a ${LIBDIR}/${LIBNAME}.a 35 | 36 | clean: 37 | rm -f ${OFILES} ${LIBNAME}.a ${LIBDIR}/${LIBNAME}.a 38 | -------------------------------------------------------------------------------- /device/tcp/tcpInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpInit.c 3 | * @provides tcpInit 4 | * 5 | * $Id: tcpInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct tcb tcptab[NTCP]; 15 | 16 | /** 17 | * Initialize TCP structures. 18 | * @param devptr tcp device table entry 19 | * @return OK if device is initialized 20 | */ 21 | devcall tcpInit(device *devptr) 22 | { 23 | struct tcb *tcbptr; 24 | 25 | tcbptr = &tcptab[devptr->minor]; 26 | bzero(tcbptr, sizeof(struct tcb)); 27 | tcbptr->state = TCP_CLOSED; 28 | tcbptr->devstate = TCP_FREE; 29 | tcbptr->mutex = semcreate(1); 30 | if (SYSERR == (int)tcbptr->mutex) 31 | { 32 | return SYSERR; 33 | } 34 | 35 | return OK; 36 | } 37 | -------------------------------------------------------------------------------- /network/net/netChksum.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netChksum.c 3 | * @provides netChksum 4 | * 5 | * $Id: netChksum.c 2134 2009-11-20 02:12:30Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | ushort netChksum(void *data, uint len) 13 | { 14 | uint sum; 15 | ushort *ptr; 16 | 17 | /* Add data to sum */ 18 | ptr = (ushort *)data; 19 | sum = 0; 20 | while (len > 1) 21 | { 22 | sum += *ptr; 23 | ptr++; 24 | len -= 2; 25 | } 26 | 27 | /* Add left-over byte, if any */ 28 | if (len > 0) 29 | { 30 | sum += net2hs(*((uchar *)ptr) << 8); 31 | } 32 | 33 | /* Fold 32-bit sum into 16 bits */ 34 | while (sum >> 16) 35 | { 36 | sum = (sum >> 16) + (sum & 0xFFFF); 37 | } 38 | 39 | return (~sum); 40 | } 41 | -------------------------------------------------------------------------------- /network/netaddr/netaddrequal.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netaddrequal.c 3 | * @provides netaddrequal 4 | * 5 | * $Id: netaddrequal.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Compare to network addresses 15 | * @param a first network address 16 | * @param b second network address 17 | * @return TRUE if addresses are the same, otherwise FALSE 18 | */ 19 | bool netaddrequal(struct netaddr *a, struct netaddr *b) 20 | { 21 | if (a->type != b->type) 22 | { 23 | return FALSE; 24 | } 25 | 26 | if (a->len != b->len) 27 | { 28 | return FALSE; 29 | } 30 | 31 | if (0 != memcmp(a->addr, b->addr, a->len)) 32 | { 33 | return FALSE; 34 | } 35 | 36 | return TRUE; 37 | } 38 | -------------------------------------------------------------------------------- /system/receive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file receive.c 3 | * @provides receive. 4 | * 5 | * $Id: receive.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * receive - wait for a message and return it 13 | * @return message 14 | */ 15 | message receive(void) 16 | { 17 | register struct thrent *thrptr; 18 | irqmask im; 19 | message msg; 20 | 21 | im = disable(); 22 | thrptr = &thrtab[thrcurrent]; 23 | if (FALSE == thrptr->hasmsg) 24 | { /* if no message, wait for one */ 25 | thrptr->state = THRRECV; 26 | resched(); 27 | } 28 | msg = thrptr->msg; /* retrieve message */ 29 | thrptr->hasmsg = FALSE; /* reset message flag */ 30 | restore(im); 31 | return msg; 32 | } 33 | -------------------------------------------------------------------------------- /test/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in the test/ directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = test 5 | 6 | # Source files for this component 7 | C_FILES = testhelper.c test_arp.c test_mailbox.c test_semaphore3.c test_bigargs.c test_memory.c test_semaphore4.c test_bufpool.c test_messagePass.c test_semaphore.c test_deltaQueue.c test_netaddr.c test_snoop.c test_ether.c test_netif.c test_ethloop.c test_nvram.c test_system.c test_ip.c test_preempt.c test_tlb.c test_libCtype.c test_procQueue.c test_ttydriver.c test_libLimits.c test_raw.c test_udp.c test_libStdio.c test_recursion.c test_umemory.c test_libStdlib.c test_schedule.c test_libString.c test_semaphore2.c 8 | 9 | 10 | S_FILES = 11 | 12 | # Add the files to the compile source path 13 | DIR = ${TOPDIR}/${COMP} 14 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 15 | -------------------------------------------------------------------------------- /system/control.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file control.c 3 | * @provides control. 4 | * 5 | * $Id: control.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * control a device (e.g., set the mode) 14 | * @param descrp definition of device to control 15 | * @param func specific control function for device 16 | * @param arg1 specific argument for func 17 | * @param arg2 specific argument for func 18 | * @return function to control device on success, SYSERR on failure 19 | */ 20 | devcall control(int descrp, int func, long arg1, long arg2) 21 | { 22 | device *devptr; 23 | 24 | if (isbaddev(descrp)) 25 | { 26 | return SYSERR; 27 | } 28 | devptr = (device *)&devtab[descrp]; 29 | return ((*devptr->control) (devptr, func, arg1, arg2)); 30 | } 31 | -------------------------------------------------------------------------------- /system/platforms/wrt54gl/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build files in this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = system/platforms/wrt54gl 5 | 6 | # Source files for this component 7 | 8 | # Important system components 9 | S_FILES = startup.S pause.S 10 | C_FILES = platforminit.c 11 | 12 | # Files for process control 13 | S_FILES += ctxsw.S 14 | C_FILES += create.c 15 | 16 | # Files for preemption and interrupts 17 | S_FILES += clkupdate.S intutils.S intdispatch.S halt.S 18 | C_FILES += dispatch.c exception.c 19 | 20 | # Files for JTAG debugging 21 | S_FILES += debugbreak.S debugret.S 22 | 23 | # Files for system calls 24 | S_FILES += syscall_entry.S 25 | C_FILES += syscall_dispatch.c 26 | 27 | # Add the files to the compile source path 28 | DIR = ${TOPDIR}/${COMP} 29 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 30 | -------------------------------------------------------------------------------- /compile/platforms/wrt160nl/ld.script: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(mips) 2 | ENTRY(_start) 3 | SECTIONS { 4 | . = 0x80010000; /* Image starts here */ 5 | .text : 6 | { 7 | *(.text .text.*) /* asm text, then C text */ 8 | *(.rodata .rodata.*) /* asm and C read-only data */ 9 | _etext = . ; /* provide _etext constant */ 10 | } 11 | 12 | .data : 13 | { 14 | *(.data .data.*) /* asm and C data */ 15 | _edata = . ; /* end of data constant */ 16 | } 17 | 18 | .bss : 19 | { 20 | _bss = . ; /* beginning of bss segment */ 21 | *(.bss .bss.*) /* asm and C bss */ 22 | *(COMMON) /* extra sections that are common */ 23 | _end = . ; /* end of image constant */ 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compile/platforms/wrt54gl/ld.script: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(mips) 2 | ENTRY(_start) 3 | SECTIONS { 4 | . = 0x80001000; /* Image starts here */ 5 | .text : 6 | { 7 | *(.text .text.*) /* asm text, then C text */ 8 | *(.rodata .rodata.*) /* asm and C read-only data */ 9 | _etext = . ; /* provide _etext constant */ 10 | } 11 | 12 | .data : 13 | { 14 | *(.data .data.*) /* asm and C data */ 15 | _edata = . ; /* end of data constant */ 16 | } 17 | 18 | .bss : 19 | { 20 | _bss = . ; /* beginning of bss segment */ 21 | *(.bss .bss.*) /* asm and C bss */ 22 | *(COMMON) /* extra sections that are common */ 23 | _end = . ; /* end of image constant */ 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /include/clock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file clock.h 3 | * Definitions relating to the hardware clock and the Xinu clock interrupt. 4 | * 5 | * $Id: clock.h 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #ifndef _CLOCK_H_ 10 | #define _CLOCK_H_ 11 | 12 | #include 13 | #include 14 | 15 | #define CLKTICKS_PER_SEC 1000 /**< clock timer resolution */ 16 | 17 | extern ulong clkticks; /**< counts clock interrupts */ 18 | extern ulong clktime; /**< current time in secs since boot */ 19 | 20 | extern qid_typ sleepq; /**< queue for sleeping processes */ 21 | 22 | /* Clock function prototypes */ 23 | void clkinit(void); 24 | void clkupdate(ulong); 25 | ulong clkcount(void); 26 | interrupt clkhandler(void); 27 | 28 | #endif /* _CLOCK_H_ */ 29 | -------------------------------------------------------------------------------- /compile/platforms/mipsel-qemu/ld.script: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(mips) 2 | ENTRY(_start) 3 | SECTIONS { 4 | . = 0x80001000; /* Image starts here */ 5 | .text : 6 | { 7 | *(.text .text.*) /* asm text, then C text */ 8 | *(.rodata .rodata.*) /* asm and C read-only data */ 9 | _etext = . ; /* provide _etext constant */ 10 | } 11 | 12 | .data : 13 | { 14 | *(.data .data.*) /* asm and C data */ 15 | _edata = . ; /* end of data constant */ 16 | } 17 | 18 | .bss : 19 | { 20 | _bss = . ; /* beginning of bss segment */ 21 | *(.bss .bss.*) /* asm and C bss */ 22 | *(COMMON) /* extra sections that are common */ 23 | _end = . ; /* end of image constant */ 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /device/http/httpPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file httpPutc.c 3 | * @provides httpPutc. 4 | * 5 | * $Id: httpPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Write a single character to a HTTP. 14 | * @param devptr HTTP device table entry 15 | * @param ch character to output 16 | * @return OK if character was written successfully, otherwise SYSERR 17 | */ 18 | devcall httpPutc(device *devptr, char ch) 19 | { 20 | struct http *webptr; 21 | device *phw = NULL; 22 | 23 | /* Setup and error check pointers to structures */ 24 | webptr = &httptab[devptr->minor]; 25 | phw = webptr->phw; 26 | if (NULL == phw) 27 | { 28 | return SYSERR; 29 | } 30 | 31 | /* Write character to httpWrite */ 32 | return httpWrite(devptr, &ch, 1); 33 | } 34 | -------------------------------------------------------------------------------- /device/telnet/telnetAlloc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file telnetAlloc.c 3 | * @provides telnetAlloc. 4 | * 5 | * $Id: telnetAlloc.c 2112 2009-11-02 22:15:54Z kthurow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | /** 16 | * Allocate an available telnet device. 17 | * @return device number for a telnet device, SYSERR if none are free 18 | */ 19 | int telnetAlloc(void) 20 | { 21 | irqmask im; 22 | int i; 23 | 24 | im = disable(); 25 | for (i = 0; i < NTELNET; ++i) 26 | { 27 | if (TELNET_STATE_FREE == telnettab[i].state) 28 | { 29 | telnettab[i].state = TELNET_STATE_ALLOC; 30 | restore(im); 31 | return i + TELNET0; 32 | } 33 | } 34 | restore(im); 35 | 36 | return SYSERR; 37 | } 38 | -------------------------------------------------------------------------------- /mem/memRegionValid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memRegionValid.c 3 | * @provides memRegionValid. 4 | * Determine if and address is within an allocated region. 5 | * 6 | * $Id: memRegionValid.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Determine if the address in memory is in an allocated memory region. 14 | * @param start address of memory to check. 15 | * @return memory region belonging to start, SYSERR if not found. 16 | */ 17 | struct memregion *memRegionValid(void *start) 18 | { 19 | struct memregion *region; 20 | start = (void *)truncpage(start); 21 | 22 | /* check allocated regions */ 23 | region = regalloclist; 24 | while (((int)region != SYSERR) && (region->start != start)) 25 | { 26 | region = region->next; 27 | } 28 | 29 | return region; 30 | } 31 | -------------------------------------------------------------------------------- /network/net/netLookup.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netLookup.c 3 | * @provides netLookup 4 | * 5 | * $Id: netLookup.c 2126 2009-11-12 07:23:04Z svn $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Lookup a network interface, given an underlying device. 15 | * @param devnum device number to find netif for. 16 | * @return network interface, NULL if none exists 17 | */ 18 | struct netif *netLookup(int devnum) 19 | { 20 | #if NNETIF 21 | int i; 22 | 23 | for (i = 0; i < NNETIF; i++) 24 | { 25 | /* Check if network interface is allocated and device matches */ 26 | if ((NET_ALLOC == netiftab[i].state) 27 | && (netiftab[i].dev == devnum)) 28 | { 29 | return &netiftab[i]; 30 | } 31 | } 32 | #endif 33 | return NULL; 34 | } 35 | -------------------------------------------------------------------------------- /system/bfpfree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bfpfree.c 3 | * @provides bfpfree. 4 | * 5 | * $Id: bfpfree.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | syscall bfpfree(int id) 15 | { 16 | struct bfpentry *bfpptr; 17 | irqmask im; 18 | 19 | if (isbadpool(id)) 20 | { 21 | return SYSERR; 22 | } 23 | 24 | bfpptr = &bfptab[id]; 25 | 26 | im = disable(); 27 | bfpptr->state = BFPFREE; 28 | if (SYSERR == memfree(bfpptr->head, bfpptr->nbuf * bfpptr->bufsize)) 29 | { 30 | restore(im); 31 | return SYSERR; 32 | } 33 | if (SYSERR == semfree(bfpptr->freebuf)) 34 | { 35 | restore(im); 36 | return SYSERR; 37 | } 38 | restore(im); 39 | 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /device/telnet/telnetInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file telnetInit.c 3 | * @provides telnetInit 4 | * 5 | * $Id: telnetInit.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct telnet telnettab[NTELNET]; 15 | 16 | /** 17 | * Initialize TELNET structures. 18 | * @param devptr TELNET device table entry 19 | * @return OK if device is initialized 20 | */ 21 | devcall telnetInit(device *devptr) 22 | { 23 | struct telnet *tntptr; 24 | 25 | tntptr = &telnettab[devptr->minor]; 26 | bzero(tntptr, sizeof(struct telnet)); 27 | if (0 == devptr->minor) 28 | { 29 | tntptr->killswitch = semcreate(0); 30 | } 31 | else 32 | { 33 | tntptr->killswitch = telnettab[0].killswitch; 34 | } 35 | 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/uartPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartPutc.c 3 | * @provides uartPutc. 4 | * 5 | * $Id: uartPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "qemu-uart.h" 13 | 14 | /** 15 | * Write a single character to the UART 16 | * @param devptr pointer to UART device 17 | * @param ch character to write 18 | */ 19 | devcall uartPutc(device *devptr, char ch) 20 | { 21 | /* struct uart_csreg * regptr; 22 | regptr = (struct uart_csreg *)uarttab[devptr->minor].csr; 23 | while(!(regptr->lsr & UART_LSR_THRE)) 24 | continue; // spin-wait until the transmit holding register is not empty 25 | 26 | regptr->thr = ch; 27 | */ 28 | write(SERIAL1, (void *) &ch, 1); 29 | return OK; 30 | // return uartWrite(devptr, (void *)&ch, 1); 31 | } 32 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/uartPutc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uartPutc.c 3 | * @provides uartPutc. 4 | * 5 | * $Id: uartPutc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "fluke-uart.h" 13 | 14 | /** 15 | * Write a single character to the UART 16 | * @param devptr pointer to UART device 17 | * @param ch character to write 18 | */ 19 | devcall uartPutc(device *devptr, char ch) 20 | { 21 | /* struct uart_csreg * regptr; 22 | regptr = (struct uart_csreg *)uarttab[devptr->minor].csr; 23 | while(!(regptr->lsr & UART_LSR_THRE)) 24 | continue; // spin-wait until the transmit holding register is not empty 25 | 26 | regptr->thr = ch; 27 | */ 28 | write(SERIAL1, (void *) &ch, 1); 29 | return OK; 30 | // return uartWrite(devptr, (void *)&ch, 1); 31 | } 32 | -------------------------------------------------------------------------------- /device/tty/ttyWrite.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ttyWrite.c 3 | * @provides ttyWrite. 4 | * 5 | * $Id: ttyWrite.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a buffer to a tty 15 | * @param devptr TTY device table entry 16 | * @param buf buffer of characters to output 17 | * @param len size of the buffer 18 | * @return count of characters output 19 | */ 20 | devcall ttyWrite(device *devptr, void *buf, uint len) 21 | { 22 | uchar ch = 0; 23 | uint count = 0; 24 | uchar *buffer = buf; 25 | 26 | /* Write all characters in buffer */ 27 | while (count < len) 28 | { 29 | ch = *buffer++; 30 | if (SYSERR == ttyPutc(devptr, ch)) 31 | { 32 | return SYSERR; 33 | } 34 | count++; 35 | } 36 | 37 | return count; 38 | } 39 | -------------------------------------------------------------------------------- /mailbox/mailboxCount.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mailboxCount.c 3 | * @provides mailboxCount. 4 | * 5 | * $Id: mailboxCount.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Count the number of messages in a mailbox. 15 | * @param box the number of the mailbox to count 16 | * @return count of messages in mailbox, SYSERR if error occured 17 | */ 18 | syscall mailboxCount(mailbox box) 19 | { 20 | struct mbox *mbxptr; 21 | irqmask im; 22 | uint count; 23 | 24 | if (box >= NMAILBOX) 25 | { 26 | return SYSERR; 27 | } 28 | 29 | mbxptr = &mboxtab[box]; 30 | if (mbxptr->state != MAILBOX_ALLOC) 31 | { 32 | return SYSERR; 33 | } 34 | 35 | im = disable(); 36 | count = mbxptr->count; 37 | restore(im); 38 | 39 | return count; 40 | } 41 | -------------------------------------------------------------------------------- /network/arp/arpDaemon.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file arpDaemon.c 3 | * @provides arpDaemon 4 | * 5 | * $Id: arpDaemon.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * ARP daemon to manage the ARP table. 15 | */ 16 | thread arpDaemon(void) 17 | { 18 | struct packet *pkt = NULL; 19 | 20 | while (TRUE) 21 | { 22 | pkt = (struct packet *)mailboxReceive(arpqueue); 23 | ARP_TRACE("Daemon received ARP packet"); 24 | if (SYSERR == (int)pkt) 25 | { 26 | continue; 27 | } 28 | 29 | arpSendReply(pkt); 30 | 31 | /* Free buffer for the packet */ 32 | if (SYSERR == netFreebuf(pkt)) 33 | { 34 | ARP_TRACE("Failed to free packet buffer"); 35 | continue; 36 | } 37 | } 38 | 39 | return OK; 40 | } 41 | -------------------------------------------------------------------------------- /system/wait.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wait.c 3 | * @provides wait. 4 | * 5 | * $Id: wait.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Make current process wait on a semaphore 13 | * @param sem target semaphore 14 | * @return OK on success, SYSERR on failure 15 | */ 16 | syscall wait(semaphore sem) 17 | { 18 | register struct sement *semptr; 19 | register struct thrent *thrptr; 20 | irqmask im; 21 | 22 | im = disable(); 23 | if (isbadsem(sem)) 24 | { 25 | restore(im); 26 | return SYSERR; 27 | } 28 | thrptr = &thrtab[thrcurrent]; 29 | semptr = &semtab[sem]; 30 | if (--(semptr->count) < 0) 31 | { 32 | thrptr->state = THRWAIT; 33 | thrptr->sem = sem; 34 | enqueue(thrcurrent, semptr->queue); 35 | resched(); 36 | } 37 | restore(im); 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /network/emulate/emuDrop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file emuDrop.c 3 | * @provides emuDrop 4 | * 5 | * $Id: emuDrop.c 2122 2009-11-11 01:06:21Z kthurow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * Drop packets based on user settings 19 | * @param pkt pointer to the incoming packet 20 | * @return OK if packet was processed succesfully, otherwise SYSERR 21 | */ 22 | syscall emuDrop(struct packet *pkt) 23 | { 24 | /* TODO: make this user specifiable */ 25 | short dropPercent = 0; 26 | 27 | /* drop packet when random value < percent to drop */ 28 | if ((rand() % 100) < dropPercent) 29 | { 30 | RT_TRACE("Dropped by Emulator: %d\n"); 31 | netFreebuf(pkt); 32 | return OK; 33 | } 34 | 35 | return emuDelay(pkt); 36 | } 37 | -------------------------------------------------------------------------------- /include/device.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file device.h 3 | * @provides isbaddev. 4 | * 5 | * Contains all definitions relating to the Xinu device subsystem. 6 | * 7 | * $Id: device.h 2020 2009-08-13 17:50:08Z mschul $ 8 | */ 9 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 10 | 11 | /* Device table declarations */ 12 | #ifndef _DEVICE_H_ 13 | #define _DEVICE_H_ 14 | 15 | #include 16 | #include 17 | 18 | /** 19 | * Check that device id is between 0 and NDEVS. 20 | * 21 | * @param f id number to test 22 | */ 23 | #define isbaddev(f) ( !(0 <= (f) && (f) < NDEVS) ) 24 | 25 | /* Standard driver functions */ 26 | devcall open(int, ...); 27 | devcall close(int); 28 | devcall read(int, void *, uint); 29 | devcall write(int, void *, uint); 30 | devcall getc(int); 31 | devcall putc(int, char); 32 | devcall seek(int, uint); 33 | devcall control(int, int, long, long); 34 | syscall getdev(char *); 35 | 36 | #endif /* _DEVICE_H_ */ 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.swp 3 | *.elf 4 | *.hex 5 | *.bin 6 | *.a 7 | 8 | # Generated Source Files # 9 | ########################## 10 | compile/config/config 11 | compile/config/lex.yy.c 12 | compile/config/lex.yy.h 13 | compile/config/y.tab.c 14 | compile/config/y.tab.h 15 | compile/version 16 | compile/vn 17 | compile/xinu.map 18 | include/conf.h 19 | system/conf.c 20 | 21 | # Compiled source # 22 | ################### 23 | *.com 24 | *.class 25 | *.dll 26 | *.exe 27 | *.o 28 | *.so 29 | 30 | # Packages # 31 | ############ 32 | # it's better to unpack these files and commit the raw source 33 | # git has its own built in compression methods 34 | *.7z 35 | *.dmg 36 | *.gz 37 | *.iso 38 | *.jar 39 | *.rar 40 | *.tar 41 | *.zip 42 | 43 | # Logs and databases # 44 | ###################### 45 | *.log 46 | *.sql 47 | *.sqlite 48 | 49 | # OS generated files # 50 | ###################### 51 | .DS_Store 52 | .DS_Store? 53 | ._* 54 | .Spotlight-V100 55 | .Trashes 56 | Icon? 57 | ehthumbs.db 58 | Thumbs.db 59 | -------------------------------------------------------------------------------- /lib/libxc/sprintf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sprintf.c 3 | * @provides sprintf. 4 | * 5 | * $Id: sprintf.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | static int sprntf(int, int); 12 | extern void _doprnt(char *, va_list, int (*func) (int, int), int); 13 | 14 | /** 15 | * Format arguments and place output in a string 16 | * @param *str output string 17 | * @param *fmt format string 18 | */ 19 | int sprintf(char *str, char *fmt, ...) 20 | { 21 | va_list ap; 22 | char *s; 23 | 24 | s = str; 25 | va_start(ap, fmt); 26 | _doprnt(fmt, ap, sprntf, (int)&s); 27 | va_end(ap); 28 | *s++ = '\0'; 29 | 30 | return ((int)str); 31 | } 32 | 33 | /** 34 | * Routine called by _doprnt to handle each character 35 | */ 36 | static int sprntf(int acpp, int ac) 37 | { 38 | char **cpp = (char **)acpp; 39 | char c = (char)ac; 40 | 41 | return (*(*cpp)++ = c); 42 | } 43 | -------------------------------------------------------------------------------- /system/signaln.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file signaln.c 3 | * @provides signaln. 4 | * 5 | * $Id: signaln.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Signal a semaphore n times, releasing n waiting threads. 13 | * @param sem target semaphore 14 | * @param count number of times to signal 15 | * @return OK on success, SYSERR on failure 16 | */ 17 | syscall signaln(semaphore sem, int count) 18 | { 19 | register struct sement *semptr; 20 | irqmask im; 21 | 22 | im = disable(); 23 | if (isbadsem(sem) || (count <= 0)) 24 | { 25 | restore(im); 26 | return SYSERR; 27 | } 28 | semptr = &semtab[sem]; 29 | for (; count > 0; count--) 30 | { 31 | if ((semptr->count++) < 0) 32 | { 33 | ready(dequeue(semptr->queue), RESCHED_NO); 34 | } 35 | } 36 | resched(); 37 | restore(im); 38 | return OK; 39 | } 40 | -------------------------------------------------------------------------------- /device/loopback/loopbackGetc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loopbackGetc.c 3 | * @provides loopbackGetc. 4 | * 5 | * $Id: loopbackGetc.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** 17 | * Get a character from the loopback buffer 18 | * @param devptr Loopback device 19 | * @return character from buffer 20 | */ 21 | devcall loopbackGetc(device *devptr) 22 | { 23 | irqmask im; 24 | struct loopback *lbkptr; 25 | int i; 26 | 27 | lbkptr = &looptab[devptr->minor]; 28 | 29 | /* wait until the buffer has data */ 30 | wait(lbkptr->sem); 31 | 32 | im = disable(); 33 | 34 | i = lbkptr->index; 35 | lbkptr->index = (i + 1) % LOOP_BUFFER; 36 | 37 | restore(im); 38 | 39 | /* consume the data */ 40 | return lbkptr->buffer[i]; 41 | } 42 | -------------------------------------------------------------------------------- /device/tcp/tcpOpenActive.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpOpenActive.c 3 | * @provides tcpOpenActive, tcpIss 4 | * 5 | * $Id: tcpOpenActive.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Actively opens a TCP connection. 14 | * @param tcbptr TCB for connection 15 | * @return OK if tcp is opened properly, otherwise SYSERR 16 | * @pre-condition TCB mutex is already held 17 | * @post-condition TCB mutex is still held 18 | */ 19 | devcall tcpOpenActive(struct tcb *tcbptr) 20 | { 21 | /* Verify connection is fully specified */ 22 | if ((NULL == tcbptr->remotept) || (NULL == tcbptr->remoteip.type) 23 | || (NULL == tcbptr->localip.type)) 24 | { 25 | return TCP_ERR_NOSPEC; 26 | } 27 | 28 | if (SYSERR == tcpSendSyn(tcbptr)) 29 | { 30 | return SYSERR; 31 | } 32 | 33 | tcbptr->state = TCP_SYNSENT; 34 | 35 | return OK; 36 | } 37 | -------------------------------------------------------------------------------- /device/loopback/loopbackClose.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loopbackClose.c 3 | * @provides loopbackClose. 4 | * 5 | * $Id: loopbackClose.c 2077 2009-09-24 23:58:54Z mschul $ 6 | **/ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Close a loopback device. 17 | * @param devptr loopback device table entry 18 | * @return OK if loopback is closed properly, otherwise SYSERR 19 | **/ 20 | devcall loopbackClose(device *devptr) 21 | { 22 | struct loopback *lbkptr; 23 | irqmask im; 24 | 25 | lbkptr = &looptab[devptr->minor]; 26 | 27 | im = disable(); 28 | if (LOOP_STATE_ALLOC != lbkptr->state) 29 | { 30 | restore(im); 31 | return SYSERR; 32 | } 33 | 34 | /* free the semaphore */ 35 | semfree(lbkptr->sem); 36 | lbkptr->state = LOOP_STATE_FREE; 37 | 38 | restore(im); 39 | return OK; 40 | } 41 | -------------------------------------------------------------------------------- /lib/libxc/ctype_.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ctype_.c 3 | * @provides _ctype_. 4 | * 5 | * $Id: ctype_.c 2072 2009-09-21 22:26:50Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | const char _ctype_[] = { 12 | 0, 13 | _C, _C, _C, _C, _C, _C, _C, _C, 14 | _C, _S, _S, _S, _S, _S, _C, _C, 15 | _C, _C, _C, _C, _C, _C, _C, _C, 16 | _C, _C, _C, _C, _C, _C, _C, _C, 17 | _S, _P, _P, _P, _P, _P, _P, _P, 18 | _P, _P, _P, _P, _P, _P, _P, _P, 19 | _N, _N, _N, _N, _N, _N, _N, _N, 20 | _N, _N, _P, _P, _P, _P, _P, _P, 21 | _P, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, 22 | _U, 23 | _U, _U, _U, _U, _U, _U, _U, _U, 24 | _U, _U, _U, _U, _U, _U, _U, _U, 25 | _U, _U, _U, _P, _P, _P, _P, _P, 26 | _P, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, 27 | _L, 28 | _L, _L, _L, _L, _L, _L, _L, _L, 29 | _L, _L, _L, _L, _L, _L, _L, _L, 30 | _L, _L, _L, _P, _P, _P, _P, _C 31 | }; 32 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/xinu.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | devcall uartInit(device *d) { return 0; } 4 | 5 | devcall uartRead(device *d, void *buffer, uint len) { 6 | // spin and wait for input. 7 | int ch; 8 | 9 | while( ( ch = kgetc( d ) ) == SYSERR ) 10 | { 11 | // block 12 | } 13 | 14 | 15 | *(char *)buffer = ch; 16 | return 1; 17 | } 18 | devcall uartWrite(device *d, void *buffer, uint len) 19 | { 20 | int i; 21 | char *cbuf = buffer; 22 | 23 | for( i = 0; i < len; i++ ) 24 | kputc( d, cbuf[i] ); 25 | return len; 26 | } 27 | 28 | devcall uartGetc(device *d) { 29 | int ch; 30 | 31 | while( ( ch = kgetc( d ) ) == SYSERR ) 32 | { 33 | // block 34 | } 35 | 36 | return ch; 37 | } 38 | 39 | devcall uartPutc(device *d, char e) { 40 | kputc( d, e ); 41 | return e; 42 | } 43 | 44 | devcall uartControl(device *d, int e, long f, long g) { return 0; } 45 | interrupt uartInterrupt(void) { } 46 | void uartStat(ushort d) { } 47 | 48 | */ 49 | -------------------------------------------------------------------------------- /network/route/rtAlloc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtAlloc.c 3 | * @provides rtAlloc 4 | * 5 | * $Id: rtAlloc.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /* Allocates an entry from the route table. 14 | * @return entry in route table, NULL if all used, SYSERR if error occurs 15 | */ 16 | struct rtEntry *rtAlloc(void) 17 | { 18 | int i; 19 | irqmask im; 20 | 21 | RT_TRACE("Allocating route entry"); 22 | 23 | im = disable(); 24 | for (i = 0; i < RT_NENTRY; i++) 25 | { 26 | /* If entry is free, return entry */ 27 | if (RT_FREE == rttab[i].state) 28 | { 29 | rttab[i].state = RT_PEND; 30 | RT_TRACE("Free entry %d", i); 31 | restore(im); 32 | return &rttab[i]; 33 | } 34 | } 35 | 36 | restore(im); 37 | RT_TRACE("No free entry"); 38 | return NULL; 39 | } 40 | -------------------------------------------------------------------------------- /device/tcp/Makerules: -------------------------------------------------------------------------------- 1 | # This Makefile contains rules to build this directory. 2 | 3 | # Name of this component (the directory this file is stored in) 4 | COMP = device/tcp 5 | 6 | # Source files for this component 7 | C_FILES = tcpAlloc.c tcpChksum.c tcpClose.c tcpControl.c \ 8 | tcpDemux.c tcpFree.c tcpGetc.c tcpInit.c tcpOpen.c \ 9 | tcpOpenActive.c tcpPutc.c tcpRead.c \ 10 | tcpRecvAck.c tcpRecv.c tcpRecvData.c tcpRecvListen.c \ 11 | tcpRecvOpts.c tcpRecvOther.c tcpRecvRtt.c \ 12 | tcpRecvSynsent.c tcpRecvValid.c tcpSendAck.c tcpSend.c \ 13 | tcpSendData.c tcpSendPersist.c tcpSendRst.c tcpSendRxt.c \ 14 | tcpSendSyn.c tcpSendWindow.c tcpSeqdiff.c tcpSetup.c tcpStat.c \ 15 | tcpTimer.c tcpTimerPurge.c tcpTimerRemain.c tcpTimerSched.c \ 16 | tcpTimerTrigger.c tcpWrite.c 17 | 18 | S_FILES = 19 | 20 | # Add the files to the compile source path 21 | DIR = ${TOPDIR}/${COMP} 22 | COMP_SRC += ${S_FILES:%=${DIR}/%} ${C_FILES:%=${DIR}/%} 23 | -------------------------------------------------------------------------------- /mem/safeUnmapRange.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file safeUnmapRange.c 3 | * @provides safeUnmapRange. 4 | * Remove a range of pages from page table. 5 | * 6 | * $Id: safeUnmapRange.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Remove a range of pages from a page table starting at start and ending 14 | * after length bytes. 15 | * @param start beginning page address to remove. 16 | * @param length number of bytes to unmap for. 17 | * @return non-zero value on failure. 18 | */ 19 | int safeUnmapRange(void *start, uint length) 20 | { 21 | uint addr, end; 22 | int result; 23 | 24 | length = roundpage(length); 25 | addr = (uint)truncpage(start); 26 | end = addr + length; 27 | 28 | for (; addr < end; addr += PAGE_SIZE) 29 | { 30 | if ((result = safeUnmap((void *)addr)) != 0) 31 | { 32 | return result; 33 | } 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/test_stub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * Example of a test program for the Xinu testsuite. Beyond this file you 7 | * must add an entry to the testtab in testhelper.c and a prototype in 8 | * testsuite.h. 9 | */ 10 | thread test_stub(bool verbose) 11 | { 12 | /* the failif macro depends on 'passed' and 'verbose' vars */ 13 | bool passed = TRUE; 14 | 15 | /* This is the first "subtest" of this suite */ 16 | testPrint(verbose, "subtest one"); 17 | test = ionull(); 18 | failif((test != OK), "ionull not OK"); 19 | 20 | /* This is the second "subtest" of this suite */ 21 | testPrint(verbose, "subtest two"); 22 | value = ioerr(); 23 | failif((value != SYSERR), "ioerr not SYSERR"); 24 | 25 | /* always print out the overall tests status */ 26 | if (passed) 27 | { 28 | testPass(TRUE, ""); 29 | } 30 | else 31 | { 32 | testFail(TRUE, ""); 33 | } 34 | 35 | return OK; 36 | } 37 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/xinu.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | devcall uartInit(device *d) { return 0; } 4 | 5 | devcall uartRead(device *d, void *buffer, uint len) { 6 | // spin and wait for input. 7 | int ch; 8 | 9 | while( ( ch = kgetc( d ) ) == SYSERR ) 10 | { 11 | // block 12 | } 13 | 14 | 15 | *(char *)buffer = ch; 16 | return 1; 17 | } 18 | devcall uartWrite(device *d, void *buffer, uint len) 19 | { 20 | int i; 21 | char *cbuf = buffer; 22 | 23 | for( i = 0; i < len; i++ ) 24 | kputc( d, cbuf[i] ); 25 | return len; 26 | } 27 | 28 | devcall uartGetc(device *d) { 29 | int ch; 30 | 31 | while( ( ch = kgetc( d ) ) == SYSERR ) 32 | { 33 | // block 34 | } 35 | 36 | return ch; 37 | } 38 | 39 | devcall uartPutc(device *d, char e) { 40 | kputc( d, e ); 41 | return e; 42 | } 43 | 44 | devcall uartControl(device *d, int e, long f, long g) { return 0; } 45 | interrupt uartInterrupt(void) { } 46 | void uartStat(ushort d) { } 47 | 48 | */ 49 | -------------------------------------------------------------------------------- /system/bufget.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bufget.c 3 | * @provides bufget. 4 | * 5 | * $Id: bufget.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Acquire buffer from initialized pool 16 | * @param poolid index of pool in bptab 17 | * @return pointer to buffer on success, SYSERR on failure 18 | */ 19 | void *bufget(int poolid) 20 | { 21 | struct bfpentry *bfpptr; 22 | struct poolbuf *bufptr; 23 | irqmask im; 24 | 25 | if (isbadpool(poolid)) 26 | { 27 | return (void *)SYSERR; 28 | } 29 | 30 | bfpptr = &bfptab[poolid]; 31 | 32 | im = disable(); 33 | wait(bfpptr->freebuf); 34 | bufptr = bfpptr->next; 35 | bfpptr->next = bufptr->next; 36 | restore(im); 37 | 38 | bufptr->next = bufptr; 39 | return (void *)(bufptr + 1); /* +1 to skip past accounting structure */ 40 | } 41 | -------------------------------------------------------------------------------- /device/interrupt-controller/pl190.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Address offsets for the pl190 Vector Interrupt Controller. 3 | */ 4 | 5 | #ifndef _PL190_H 6 | #define _PL190_H 7 | 8 | /* 9 | * VIC registers, and their offsets from the VIC_BASE_ADDRESS. 10 | */ 11 | 12 | /* Read only */ 13 | #define VIC_IRQ_STATUS 0x0 14 | #define VIC_FIQ_STATUS 0x4 15 | #define VIC_RAW_INTR 0x8 16 | 17 | /* Read-write */ 18 | #define VIC_INT_SELECT 0xC 19 | #define VIC_INT_ENABLE 0x10 20 | 21 | /* Write-only */ 22 | #define VIC_ENABLE_AND_CLEAR 0x14 23 | 24 | /* Read-write */ 25 | #define VIC_SOFT_INT 0x18 26 | 27 | /* Write-only */ 28 | #define VIC_SOFT_INT_CLEAR 0x1C 29 | 30 | /* Read-write */ 31 | #define VIC_PROTECTION 0x20 32 | #define VIC_VEC_ADDR 0x30 33 | #define VIC_DEF_VEC_ADDR 0x34 34 | 35 | /* Base address for the IRQs, zero indexed */ 36 | #define VIC_VECT_ADDR_BASE 0x100 37 | 38 | /* Base address for the vector control registers, zero indexed */ 39 | #define VIC_VECT_CNTL_BASE 0x200 40 | 41 | #endif /* _PL190_H */ 42 | -------------------------------------------------------------------------------- /device/loopback/loopbackRead.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loopbackRead.c 3 | * @provides loopbackRead. 4 | * 5 | * $Id: loopbackRead.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Read characters from a loopback. 15 | * @param devptr 16 | * @param buf buffer for read characters 17 | * @param len size of the buffer 18 | * @return number of characters read, SYSERR if closed 19 | */ 20 | devcall loopbackRead(device *devptr, void *buf, uint len) 21 | { 22 | struct loopback *lbkptr = NULL; 23 | uint i; 24 | char *buffer = buf; 25 | 26 | lbkptr = &looptab[devptr->minor]; 27 | 28 | /* Check if loopback is open */ 29 | if (LOOP_STATE_ALLOC != lbkptr->state) 30 | { 31 | return SYSERR; 32 | } 33 | 34 | for (i = 0; i < len; i++) 35 | { 36 | buffer[i] = loopbackGetc(devptr); 37 | } 38 | 39 | return i; 40 | } 41 | -------------------------------------------------------------------------------- /mem/tlbInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tlbInit.c 3 | * @provides tlbInit. 4 | * Initialize the Translation lookaside buffer. 5 | * 6 | * $Id: tlbInit.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | interrupt tlbMiss(void); 16 | interrupt tlbMissLong(void); 17 | 18 | /** 19 | * Initialize the TLB. This function is called at startup. Installs 20 | * handler for both TLB load and store operations in normal exceptionVector 21 | * table, also copies the handler to the quick tlbMiss memory 0x80000000. 22 | */ 23 | void tlbInit(void) 24 | { 25 | /* Register slow TLB exception handler (KSEG2 and USEG misses) */ 26 | exceptionVector[EXC_TLBS] = (void *)tlbMissLong; 27 | exceptionVector[EXC_TLBL] = (void *)tlbMissLong; 28 | 29 | /* install the quick handler (for USEG mappings) */ 30 | memcpy(TLB_EXC_START, tlbMiss, TLB_EXC_LENGTH); 31 | } 32 | -------------------------------------------------------------------------------- /compile/platforms/arm-qemu/ld.script: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | ENTRY(Reset_Handler) 3 | 4 | SECTIONS { 5 | . = 0x10000; 6 | . = ALIGN(4); 7 | .text : 8 | { 9 | *(.text .text.*) /* asm text, then C text */ 10 | *(.rodata .rodata.*) /* asm and C read-only data */ 11 | *(.glue_7 .glue_7t) /* mystery sections */ 12 | _etext = . ; /* provide _etext constant */ 13 | } 14 | 15 | .data : 16 | { 17 | _data = . ; 18 | *(.data .data.*) /* asm and C data */ 19 | _edata = . ; /* end of data constant */ 20 | } 21 | 22 | .bss : 23 | { 24 | _bss = . ; /* beginning of bss segment */ 25 | *(.bss .bss.*) /* asm and C bss */ 26 | *(COMMON) /* extra sections that are common */ 27 | } 28 | . = ALIGN(4); 29 | _bss_end = .; 30 | _end = . ; /* end of image constant */ 31 | } 32 | 33 | -------------------------------------------------------------------------------- /network/route/rtDaemon.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtDaemon.c 3 | * @provides rtDaemon 4 | * 5 | * $Id: rtDaemon.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Route dameon to route packets 17 | */ 18 | thread rtDaemon(void) 19 | { 20 | struct packet *pkt = NULL; 21 | 22 | enable(); 23 | 24 | while (TRUE) 25 | { 26 | pkt = (struct packet *)mailboxReceive(rtqueue); 27 | RT_TRACE("Daemon received packet"); 28 | if (SYSERR == (int)pkt) 29 | { 30 | RT_TRACE("Daemon received packet has an error"); 31 | continue; 32 | } 33 | 34 | rtSend(pkt); 35 | if (SYSERR == netFreebuf(pkt)) 36 | { 37 | RT_TRACE("Failed to free packet buffer"); 38 | continue; 39 | } 40 | } 41 | 42 | return OK; 43 | } 44 | -------------------------------------------------------------------------------- /system/queinit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file queinit.c 3 | * @provides queinit. 4 | * 5 | * $Id: queinit.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Initialize a new queue in the global thread queue table 13 | * @return newly allocated queue ID or SYSERR 14 | */ 15 | qid_typ queinit(void) 16 | { 17 | static int nextqid = NTHREAD; 18 | /**< next available quetab entry */ 19 | qid_typ q; 20 | 21 | if (nextqid > NQENT) 22 | { 23 | kprintf("%s:%d: could not initialize queue. nextqid > NQENT\n"); 24 | return SYSERR; 25 | } 26 | q = nextqid; 27 | nextqid += 2; 28 | quetab[quehead(q)].next = quetail(q); 29 | quetab[quehead(q)].prev = EMPTY; 30 | quetab[quehead(q)].key = MAXKEY; 31 | quetab[quetail(q)].next = EMPTY; 32 | quetab[quetail(q)].prev = quehead(q); 33 | quetab[quetail(q)].key = MINKEY; 34 | return q; 35 | } 36 | -------------------------------------------------------------------------------- /device/bcm4713/vlanOpen.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file vlanOpen.c 3 | * @provides vlanOpen. 4 | * 5 | * $Id: vlanOpen.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * Open a virtual ethernet device for use 19 | * @param devptr ethernet device table entry 20 | * @return OK if opened properly, otherwise SYSERR 21 | */ 22 | devcall vlanOpen(device *devptr) 23 | { 24 | struct ether *ethptr; 25 | 26 | /* Initialize structure pointers */ 27 | ethptr = ðertab[devptr->minor]; 28 | 29 | /* Rx and Tx buffers associated with hardware device */ 30 | ethptr->inPool = ETH_INVALID; 31 | ethptr->outPool = ETH_INVALID; 32 | ethptr->state = ETH_STATE_UP; 33 | 34 | etherControl(devptr, ETH_CTRL_SET_MAC, (ulong)ethptr->devAddress, 0); 35 | 36 | return OK; 37 | } 38 | -------------------------------------------------------------------------------- /network/route/rtClear.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtClear.c 3 | * @provides rtClear. 4 | * 5 | * $Id: rtClear.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Removes all entries for a network interface from the routing table. 16 | * @param nif network interface 17 | * @return OK if entries are removed successfully, otherwise SYSERR 18 | */ 19 | syscall rtClear(struct netif *nif) 20 | { 21 | int i; 22 | irqmask im; 23 | 24 | /* Error check pointers */ 25 | if (NULL == nif) 26 | { 27 | return SYSERR; 28 | } 29 | 30 | im = disable(); 31 | for (i = 0; i < RT_NENTRY; i++) 32 | { 33 | if ((RT_USED == rttab[i].state) && (nif == rttab[i].nif)) 34 | { 35 | rttab[i].state = RT_FREE; 36 | rttab[i].nif = NULL; 37 | } 38 | } 39 | restore(im); 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /device/tcp/tcpSeqdiff.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpSeqdiff.c 3 | * @provides tcpSeqdiff 4 | * 5 | * $Id: tcpSeqdiff.c 2134 2009-11-20 02:12:30Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Calculates the difference between two sequence numbers. 14 | * @param first sequence number that occurs first 15 | * @param second sequence number that occurs second 16 | * @return difference between two sequence numbers 17 | */ 18 | tcpseq tcpSeqdiff(tcpseq first, tcpseq second) 19 | { 20 | /* if (first <= second) 21 | { return (second-first); } 22 | else 23 | { return ((TCP_MAXSEQ - first) + second); }*/ 24 | 25 | if ((first < (TCP_MAXSEQ / 2)) && (second > (TCP_MAXSEQ / 2))) 26 | { 27 | return ((TCP_MAXSEQ - first) + second); 28 | } 29 | 30 | if ((second < (TCP_MAXSEQ / 2)) && (first > (TCP_MAXSEQ / 2))) 31 | { 32 | return ((TCP_MAXSEQ - first) + second); 33 | } 34 | 35 | return first - second; 36 | } 37 | -------------------------------------------------------------------------------- /network/route/rtRemove.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtRemove.c 3 | * @provides rtRemove 4 | * 5 | * $Id: rtRemove.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Removes any entry based on its destination. 16 | * @param dst destination IP address 17 | * @return OK if the entry is removed successfully, otherwise SYSERR 18 | */ 19 | syscall rtRemove(struct netaddr *dst) 20 | { 21 | int i; 22 | irqmask im; 23 | 24 | /* Error check pointers */ 25 | if (NULL == dst) 26 | { 27 | return SYSERR; 28 | } 29 | 30 | im = disable(); 31 | for (i = 0; i < RT_NENTRY; i++) 32 | { 33 | if ((RT_USED == rttab[i].state) 34 | && netaddrequal(dst, &rttab[i].dst)) 35 | { 36 | rttab[i].state = RT_FREE; 37 | rttab[i].nif = NULL; 38 | } 39 | } 40 | restore(im); 41 | return OK; 42 | } 43 | -------------------------------------------------------------------------------- /network/emulate/emuDuplicate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * @file emuDuplicate.c 3 | * @provides emuDuplicate 4 | * 5 | * $Id: emuDuplicate.c 2126 2009-11-12 07:23:04Z svn $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | //int test(struct packet *pkt, int dupes); 14 | /** 15 | * Duplicate packets as specified by user 16 | * @param pkt pointer to the incoming packet 17 | * @return OK if packet was processed succesfully, otherwise SYSERR 18 | */ 19 | syscall emuDuplicate(struct packet *pkt) 20 | { 21 | /* 22 | short dupePercent = 100; 23 | int dupes = 2; 24 | 25 | if ((rand() % 100) < dupePercent) 26 | { 27 | return test(pkt, dupes); 28 | } 29 | */ 30 | return emuReorder(pkt); 31 | } 32 | 33 | /* 34 | syscall test(struct packet *pkt, int dupes) 35 | { 36 | if (dupes == 1) 37 | { 38 | return emuReorder(pkt); 39 | } 40 | 41 | return (emuReorder(pkt) | test(pkt, dupes - 1)); 42 | }*/ 43 | -------------------------------------------------------------------------------- /network/net/netGetbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * file netGetbuf.c 3 | * @provides netGetbuf 4 | * 5 | * $Id: netGetbuf.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Provides a buffer for storing a packet. 16 | * @return pointer to a packet buffer, SYSERR if an error occured 17 | */ 18 | struct packet *netGetbuf(void) 19 | { 20 | struct packet *pkt = NULL; /**< pointer to packet */ 21 | 22 | /* Obtain a buffer for the packet */ 23 | pkt = bufget(netpool); 24 | if (SYSERR == (int)pkt) 25 | { 26 | return (struct packet *)SYSERR; 27 | } 28 | 29 | bzero(pkt, sizeof(struct packet) + NET_MAX_PKTLEN); 30 | 31 | /* Initialize packet buffer */ 32 | pkt->nif = NULL; 33 | pkt->len = 0; 34 | /* Initialize curr to point to end of buffer */ 35 | pkt->curr = pkt->data + NET_MAX_PKTLEN; 36 | 37 | return pkt; 38 | } 39 | -------------------------------------------------------------------------------- /mem/safeMapRange.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file safeMapRange.c 3 | * @provides safeMapRange. 4 | * Map a range of pages to a page table. 5 | * 6 | * $Id: safeMapRange.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Map a range of pages to a page table starting at start, ending at 14 | * start+length. 15 | * @param start beginning page address to map. 16 | * @param length length of memory range to map. 17 | * @param attr attributes to apply to page table entries. 18 | * @return non-zero value on failure. 19 | */ 20 | int safeMapRange(void *start, uint length, short attr) 21 | { 22 | uint addr, end; 23 | int result; 24 | 25 | length = roundpage(length); 26 | addr = (uint)truncpage(start); 27 | end = addr + length; 28 | 29 | for (; addr < end; addr += PAGE_SIZE) 30 | { 31 | if ((result = safeMap((void *)addr, attr)) != 0) 32 | { 33 | return result; 34 | } 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /system/buffree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file buffree.c 3 | * @provides buffree. 4 | * 5 | * $Id: buffree.c 2079 2009-10-05 22:32:48Z zlund $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Return buffer to pool 16 | * @param buffer address of returning buffer 17 | * @return OK on success, SYSERR on failure 18 | */ 19 | syscall buffree(void *buffer) 20 | { 21 | struct bfpentry *bfpptr; 22 | struct poolbuf *bufptr; 23 | irqmask im; 24 | 25 | bufptr = ((struct poolbuf *)buffer) - 1; 26 | 27 | if (isbadpool(bufptr->poolid)) 28 | { 29 | return SYSERR; 30 | } 31 | 32 | if (bufptr->next != bufptr) 33 | { 34 | return SYSERR; 35 | } 36 | 37 | bfpptr = &bfptab[bufptr->poolid]; 38 | 39 | im = disable(); 40 | bufptr->next = bfpptr->next; 41 | bfpptr->next = bufptr; 42 | restore(im); 43 | signaln(bfpptr->freebuf, 1); 44 | 45 | return OK; 46 | } 47 | -------------------------------------------------------------------------------- /system/sleep.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sleep.c 3 | * @provides sleep. 4 | * 5 | * $Id: sleep.c 2094 2009-10-09 22:20:18Z zlund $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** 17 | * Delay the calling thread n milliseconds. 18 | * @param ms number of milliseconds to sleep 19 | * @return OK if thread is sleeping, SYSERR if no clock 20 | */ 21 | syscall sleep(uint ms) 22 | { 23 | #if RTCLOCK 24 | irqmask im; 25 | int ticks = 0; 26 | 27 | ticks = (ms * CLKTICKS_PER_SEC) / 1000; 28 | 29 | im = disable(); 30 | if (ticks > 0) 31 | { 32 | if (SYSERR == insertd(thrcurrent, sleepq, ticks)) 33 | { 34 | restore(im); 35 | return SYSERR; 36 | } 37 | thrtab[thrcurrent].state = THRSLEEP; 38 | } 39 | 40 | resched(); 41 | restore(im); 42 | return OK; 43 | #else 44 | return SYSERR; 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /lib/libxc/free.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file free.c 3 | * @provides free. 4 | * This file is deprecated in favor of mem/free.c and the user heap 5 | * allocator. However, it remains here for backup purposes. 6 | * 7 | * $Id: free.c 2065 2009-09-04 21:44:36Z brylow $ 8 | */ 9 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 10 | 11 | #include 12 | #include 13 | 14 | /** 15 | * Attempt to free block of memory based on malloc() accounting 16 | * information stored in preceding two words. 17 | * @param *pmem pointer to memory block 18 | * @return OK on success, SYSERR on failure 19 | */ 20 | __attribute__ ((deprecated)) 21 | void free(void *pmem) 22 | { 23 | struct memblock *block; 24 | 25 | /* block points at the memblock we want to free */ 26 | block = (struct memblock *)pmem; 27 | 28 | /* back up to accounting information */ 29 | block--; 30 | 31 | /* don't memfree if we fail basic checks */ 32 | if (block->next != block) 33 | { 34 | return; 35 | } 36 | 37 | memfree(block, block->length); 38 | } 39 | -------------------------------------------------------------------------------- /system/platforms/mipsel-qemu/platform-local.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file platform-local.h 3 | * Platform-specific defines. 4 | */ 5 | 6 | #ifndef _MIPSEL_QEMU_PLATFORM_LOCAL_H 7 | #define _MIPSEL_QEMU_PLATFORM_LOCAL_H 8 | 9 | #include 10 | 11 | /* Max RAM addresses */ 12 | #define MAXADDR_DEFAULT 0x00800000 /**< default 8MB RAM */ 13 | #define MAXADDR_WRT54G 0x00800000 /**< G has 8MB RAM */ 14 | #define MAXADDR_WRT54GL 0x01000000 /**< GL has 16MB RAM */ 15 | #define MAXADDR_WRT350N 0x02000000 /**< 350N has 32MB RAM */ 16 | #define MAXADDR_WRT160NL 0x02000000 /**< 160NL has 32MB RAM */ 17 | 18 | /* Time Base Frequency */ 19 | #define CLKFREQ_DEFAULT 100000000 20 | #define CLKFREQ_WRT54G 120000000 21 | #define CLKFREQ_WRT54GL 100000000 22 | #define CLKFREQ_WRT350N 150000000 23 | #define CLKFREQ_WRT160NL 200000000 24 | 25 | 26 | /* UART DLL (Divisor Latch LS) */ 27 | #define UART_DLL_DEFAULT 0x0B 28 | #define UART_DLL_WRT54G 0x0E 29 | #define UART_DLL_WRT54GL 0x0B 30 | #define UART_DLL_WRT350N 0x29 31 | 32 | #endif /* _MIPSEL_QEMU_PLATFORM_LOCAL_H */ 33 | -------------------------------------------------------------------------------- /system/semfree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file semfree.c 3 | * @provides semfree. 4 | * 5 | * $Id: semfree.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | 11 | /** 12 | * Deallocate a semaphore. 13 | * Reset the semaphore count, releasing any threads 14 | * in the waiting queue. Deallocate entry in global 15 | * semaphore table. 16 | * @param sem target semaphore 17 | * @return OK on success, SYSERR on failure 18 | */ 19 | syscall semfree(semaphore sem) 20 | { 21 | register struct sement *semptr; 22 | irqmask im; 23 | tid_typ tid; 24 | 25 | im = disable(); 26 | if (isbadsem(sem)) 27 | { 28 | restore(im); 29 | return SYSERR; 30 | } 31 | 32 | semptr = &semtab[sem]; 33 | while (nonempty(semptr->queue)) 34 | { 35 | tid = dequeue(semptr->queue); /* free waiting threads */ 36 | ready(tid, RESCHED_NO); 37 | } 38 | 39 | semptr->count = 0; 40 | semptr->state = SFREE; 41 | restore(im); 42 | return OK; 43 | } 44 | -------------------------------------------------------------------------------- /device/tcp/tcpTimerRemain.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpTimerRemain.c 3 | * @provides tcpTimerRemain 4 | * 5 | * $Id: tcpTimerRemain.c 2076 2009-09-24 23:05:39Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Determine time reamining for a TCP timer event for a particular TCB. 15 | * @param tcbptr TCB to which event corresponds 16 | * @param type type of timer event 17 | * @return time remaining for event, 0 if no event exists 18 | */ 19 | int tcpTimerRemain(struct tcb *tcbptr, uchar type) 20 | { 21 | struct tcpEvent *cur = NULL; 22 | int time = 0; 23 | 24 | wait(tcpmutex); 25 | cur = tcptimertab[TCP_EVT_HEAD].next; 26 | while (cur != NULL) 27 | { 28 | time += cur->remain; 29 | if ((cur->tcbptr == tcbptr) && (cur->type == type)) 30 | { 31 | signal(tcpmutex); 32 | return time; 33 | } 34 | cur = cur->next; 35 | } 36 | signal(tcpmutex); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/test_bigargs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void bigargs(uchar a, uchar b, uchar c, uchar d, uchar e, uchar f, 7 | uchar *testArray) 8 | { 9 | testArray[0] = a; 10 | testArray[1] = b; 11 | testArray[2] = c; 12 | testArray[3] = d; 13 | testArray[4] = e; 14 | testArray[5] = f; 15 | testArray[6] = a + b + c + d + e + f; 16 | return; 17 | } 18 | 19 | thread test_bigargs(bool verbose) 20 | { 21 | uchar testArray[20]; 22 | 23 | ready(create((void *)bigargs, INITSTK, 31, "BIGARGS", 24 | 7, 10, 20, 30, 40, 50, 60, testArray), RESCHED_YES); 25 | 26 | if ((10 == testArray[0]) 27 | && (20 == testArray[1]) 28 | && (30 == testArray[2]) 29 | && (40 == testArray[3]) 30 | && (50 == testArray[4]) 31 | && (60 == testArray[5]) && (210 == testArray[6])) 32 | { 33 | testPass(TRUE, ""); 34 | } 35 | else 36 | { 37 | testFail(TRUE, ""); 38 | } 39 | 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /lib/libxc/fgets.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fgets.c 3 | * @provides fgets. 4 | * 5 | * $Id: fgets.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #define NULL 0 10 | extern int getc(int); 11 | 12 | /** 13 | * Read a newline-terminated string from device (file) dev 14 | * @param *s buffer for result 15 | * @param n maximum read length 16 | * @param dev device to read from 17 | */ 18 | char *fgets(char *s, int n, int dev) 19 | { 20 | int c = 0; 21 | char *cs; 22 | 23 | cs = s; 24 | 25 | /* Read characters until maximum read length, */ 26 | /* end of line, or end of file */ 27 | while ((--n > 0) && ((c = getc(dev)) >= 0)) 28 | { 29 | *cs++ = c; 30 | if (('\n' == c) || ('\r' == c)) 31 | { 32 | break; 33 | } 34 | } 35 | 36 | /* Check for EOF or empty string */ 37 | if ((c < 0) && (cs == s)) 38 | { 39 | return NULL; 40 | } 41 | 42 | /* Terminate string and return */ 43 | *cs++ = '\0'; 44 | return s; 45 | } 46 | -------------------------------------------------------------------------------- /network/arp/arpFree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file arpFree.c 3 | * @provides arpFree 4 | * 5 | * $Id: arpFree.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Frees an entry from the ARP table. 16 | * @return SYSERR if error occurs, otherwise OK 17 | */ 18 | syscall arpFree(struct arpEntry *entry) 19 | { 20 | ARP_TRACE("Freeing ARP entry"); 21 | 22 | /* Error check pointers */ 23 | if (NULL == entry) 24 | { 25 | return SYSERR; 26 | } 27 | 28 | /* Notify threads waiting on resolution */ 29 | if (ARP_UNRESOLVED == entry->state) 30 | { 31 | arpNotify(entry, TIMEOUT); 32 | ARP_TRACE("Waiting threads notified"); 33 | } 34 | 35 | /* Clear ARP table entry */ 36 | bzero(entry, sizeof(struct arpEntry)); 37 | entry->state = ARP_FREE; 38 | ARP_TRACE("Freed entry %d", 39 | ((int)entry - (int)arptab) / sizeof(struct arpEntry)); 40 | return OK; 41 | } 42 | -------------------------------------------------------------------------------- /device/bcmbus/backplaneCoreUp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file backplaneCoreUp.c 3 | * @provides backplaneCoreUp. 4 | * 5 | * $Id: backplaneCoreUp.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Query Silicon Backplane status to determine if a core is "up". 17 | * @param bpConfig pointer to device Silicon Backplane configuration space 18 | * @return True if device core is up 19 | */ 20 | int backplaneCoreUp(volatile struct backplaneConfig *bpConfig) 21 | { 22 | /* Core status can be determined by checking the target state */ 23 | /* low register's Reset, Reject and Clock bits. */ 24 | /* Only 'Clock' should be set. */ 25 | if (NULL == bpConfig) 26 | { 27 | return SYSERR; 28 | } 29 | return (SBTML_CLK == 30 | (bpConfig->tmStateLow & 31 | (SBTML_RESET | SBTML_REJ | SBTML_CLK))); 32 | } 33 | -------------------------------------------------------------------------------- /device/udp/udpClose.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file udpClose.c 3 | * @provides udpClose 4 | * 5 | * $Id 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** 17 | * Close and clear a UDP device 18 | * @param devptr UDP device table entry 19 | * @return OK is UDP is closed properly, otherwise SYSERR 20 | */ 21 | devcall udpClose(device *devptr) 22 | { 23 | struct udp *udpptr; 24 | irqmask im; 25 | 26 | /* Setup and error check pointers to structures */ 27 | udpptr = &udptab[devptr->minor]; 28 | 29 | im = disable(); 30 | /* Free the in buffer pool */ 31 | bfpfree(udpptr->inPool); 32 | 33 | /* Free the in semaphore */ 34 | semfree(udpptr->isem); 35 | 36 | /* Clear the UDP structure and the device IO block */ 37 | bzero(udpptr, sizeof(struct udp)); 38 | 39 | /* Set device state to free */ 40 | udpptr->state = UDP_FREE; 41 | 42 | restore(im); 43 | return OK; 44 | } 45 | -------------------------------------------------------------------------------- /network/icmp/icmpInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file icmpInit.c 3 | * @provides icmpInit 4 | * 5 | * $Id: icmpInit.c 2065 2009-09-04 21:44:36Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | mailbox icmpqueue; 16 | struct icmpEchoQueue echotab[NPINGQUEUE]; 17 | 18 | /** 19 | * Initializes ICMP daemon. 20 | * @return OK if initialization is successful, otherwise SYSERR 21 | */ 22 | syscall icmpInit(void) 23 | { 24 | int i; 25 | 26 | /* Initialize ICMP queue */ 27 | icmpqueue = mailboxAlloc(ICMP_NQUEUE); 28 | if (SYSERR == icmpqueue) 29 | { 30 | return SYSERR; 31 | } 32 | 33 | bzero(echotab, sizeof(echotab)); 34 | for (i = 0; i < NPINGQUEUE; i++) 35 | { 36 | echotab[i].tid = BADTID; 37 | } 38 | 39 | /* Spawn icmpDaemon thread */ 40 | ready(create 41 | ((void *)icmpDaemon, ICMP_THR_STK, ICMP_THR_PRIO, "icmpDaemon", 42 | 0), RESCHED_NO); 43 | 44 | return OK; 45 | } 46 | -------------------------------------------------------------------------------- /lib/libxc/strstr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file strstr.c 3 | * @provides strstr. 4 | * 5 | * $Id: strstr.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | /** 10 | * Returns a pointer to the location in a string at which a particular 11 | * string appears. 12 | * @param cs string to search 13 | * @param ct string to locate 14 | * @return the pointer in the string, NULL if string not found 15 | */ 16 | char *strstr(const char *cs, const char *ct) 17 | { 18 | char *cq; 19 | char *cr; 20 | 21 | for (; *cs != '\0'; cs++) 22 | { 23 | if (*cs == *ct) 24 | { 25 | cq = (char *)cs; 26 | cr = (char *)ct; 27 | while ((*cq != '\0') && (*cr != '\0')) 28 | { 29 | if (*cq != *cr) 30 | { 31 | break; 32 | } 33 | cq++; 34 | cr++; 35 | } 36 | if ('\0' == *cr) 37 | { 38 | return (char *)cs; 39 | } 40 | } 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /mem/safeUnmap.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file safeUnmap.c 3 | * @provides safeUnmap. 4 | * Unmap a page from the page table. 5 | * 6 | * $Id: safeUnmap.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * Unmap a page from the page table. 16 | * @param page page to remove from page table. 17 | * @return non-zero value on failure. 18 | */ 19 | int safeUnmap(void *page) 20 | { 21 | int index; 22 | struct pgtblent *entry; 23 | 24 | if (NULL == pgtbl || NULL == page) 25 | { 26 | return 1; /* invalid */ 27 | } 28 | 29 | /* find index of page table entry */ 30 | index = (((uint)page & PMEM_MASK) >> 12); 31 | entry = &(pgtbl[index]); 32 | 33 | /* make sure entry is correctly mapped */ 34 | if ((entry->entry & 0xffffffc0) != ((uint)page >> 6)) 35 | { 36 | return 1; /* corrupted page */ 37 | } 38 | 39 | /* clear entry from page table */ 40 | bzero(entry, sizeof(struct pgtblent)); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /device/loopback/loopbackWrite.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file loopbackWrite.c 3 | * @provides loopbackWrite. 4 | * 5 | * $Id: loopbackWrite.c 2077 2009-09-24 23:58:54Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Write a character to the loopback. 15 | * @param devptr 16 | * @param buf buffer of characters to output 17 | * @param len size of the buffer 18 | * @return count of characters output 19 | */ 20 | devcall loopbackWrite(device *devptr, void *buf, uint len) 21 | { 22 | struct loopback *lbkptr = NULL; 23 | uint i; 24 | char *buffer = buf; 25 | 26 | lbkptr = &looptab[devptr->minor]; 27 | 28 | /* Check if loopback is open */ 29 | if (LOOP_STATE_ALLOC != lbkptr->state) 30 | { 31 | return SYSERR; 32 | } 33 | 34 | for (i = 0; i < len; i++) 35 | { 36 | /* If char wasn't put into buffer return SYSERR */ 37 | if (SYSERR == loopbackPutc(devptr, buffer[i])) 38 | { 39 | return i; 40 | } 41 | } 42 | 43 | return i; 44 | } 45 | -------------------------------------------------------------------------------- /device/uart-arm-qemu/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Commands for turning the Bluetooth power on. 3 | * 4 | * Ripped from the Fluke firmware. 5 | */ 6 | 7 | #include "power.h" 8 | #include "usleep.h" 9 | 10 | #define IOSET (*((volatile unsigned long *) 0xE0028004)) 11 | #define IOCLR (*((volatile unsigned long *) 0xE002800C)) 12 | #define MCLK (1 << 4) 13 | #define MDIN (1 << 6) 14 | #define D2A_CS (1 << 21) 15 | 16 | void d2a_wait( void ) 17 | { 18 | usleep(100); 19 | } 20 | 21 | void set_d2a(int power, int channel) 22 | { 23 | int i, data; 24 | 25 | data = (power & 0xFF) | channel; 26 | 27 | IOCLR=D2A_CS; d2a_wait(); 28 | for (i = 11; i >= 0; i--) 29 | { 30 | IOCLR=MCLK; d2a_wait(); 31 | if (data & (1 << i)) 32 | { 33 | IOSET = MDIN; 34 | } 35 | else 36 | { 37 | IOCLR = MDIN; 38 | } 39 | d2a_wait(); 40 | IOSET=MCLK; d2a_wait(); 41 | } 42 | 43 | IOCLR = MCLK; d2a_wait(); 44 | IOSET = D2A_CS; d2a_wait(); 45 | } 46 | 47 | #define D2A_CHAN_BT 0x0800 48 | void set_bluetooth(int power) 49 | { 50 | set_d2a(power, D2A_CHAN_BT); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /network/route/rtRecv.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtRecv.c 3 | * @provides rtRecv 4 | * 5 | * $Id: rtRecv.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | syscall rtRecv(struct packet *pkt) 16 | { 17 | irqmask im; 18 | 19 | /* Error check pointers */ 20 | if (NULL == pkt) 21 | { 22 | return SYSERR; 23 | } 24 | 25 | /* If route queue is full, then drop packet */ 26 | im = disable(); 27 | if (mailboxCount(rtqueue) >= RT_NQUEUE) 28 | { 29 | restore(im); 30 | RT_TRACE("Route queue full"); 31 | netFreebuf(pkt); 32 | return OK; 33 | } 34 | 35 | /* Place packet in queue */ 36 | if (SYSERR == mailboxSend(rtqueue, (int)pkt)) 37 | { 38 | restore(im); 39 | RT_TRACE("Failed to enqueue packet"); 40 | netFreebuf(pkt); 41 | return SYSERR; 42 | } 43 | 44 | restore(im); 45 | RT_TRACE("Enqueued packet for routing"); 46 | return OK; 47 | } 48 | -------------------------------------------------------------------------------- /device/uart-fluke-bluetooth/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Commands for turning the Bluetooth power on. 3 | * 4 | * Ripped from the Fluke firmware. 5 | */ 6 | 7 | #include "power.h" 8 | #include "usleep.h" 9 | 10 | #define IOSET (*((volatile unsigned long *) 0xE0028004)) 11 | #define IOCLR (*((volatile unsigned long *) 0xE002800C)) 12 | #define MCLK (1 << 4) 13 | #define MDIN (1 << 6) 14 | #define D2A_CS (1 << 21) 15 | 16 | void d2a_wait( void ) 17 | { 18 | usleep(100); 19 | } 20 | 21 | void set_d2a(int power, int channel) 22 | { 23 | int i, data; 24 | 25 | data = (power & 0xFF) | channel; 26 | 27 | IOCLR=D2A_CS; d2a_wait(); 28 | for (i = 11; i >= 0; i--) 29 | { 30 | IOCLR=MCLK; d2a_wait(); 31 | if (data & (1 << i)) 32 | { 33 | IOSET = MDIN; 34 | } 35 | else 36 | { 37 | IOCLR = MDIN; 38 | } 39 | d2a_wait(); 40 | IOSET=MCLK; d2a_wait(); 41 | } 42 | 43 | IOCLR = MCLK; d2a_wait(); 44 | IOSET = D2A_CS; d2a_wait(); 45 | } 46 | 47 | #define D2A_CHAN_BT 0x0800 48 | void set_bluetooth(int power) 49 | { 50 | set_d2a(power, D2A_CHAN_BT); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /network/arp/arpInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file arpInit.c 3 | * @provides arpInit 4 | * 5 | * $Id: arpInit.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | struct arpEntry arptab[ARP_NENTRY]; 16 | mailbox arpqueue; 17 | 18 | /** 19 | * Initializes ARP table and ARP daemon. 20 | * @return OK if initialization is successful, otherwise SYSERR 21 | */ 22 | syscall arpInit(void) 23 | { 24 | int i = 0; 25 | 26 | /* Initialize ARP table */ 27 | for (i = 0; i < ARP_NENTRY; i++) 28 | { 29 | bzero(&arptab[i], sizeof(struct arpEntry)); 30 | arptab[i].state = ARP_FREE; 31 | } 32 | 33 | /* Initialize ARP queue */ 34 | arpqueue = mailboxAlloc(ARP_NQUEUE); 35 | if (SYSERR == arpqueue) 36 | { 37 | return SYSERR; 38 | } 39 | 40 | /* Spawn arpDaemon thread */ 41 | ready(create 42 | ((void *)arpDaemon, ARP_THR_STK, ARP_THR_PRIO, "arpDaemon", 0), 43 | RESCHED_NO); 44 | 45 | return OK; 46 | } 47 | -------------------------------------------------------------------------------- /network/netaddr/netaddrmask.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netaddrmask.c 3 | * @provides netaddrmask 4 | * 5 | * $Id: netaddrmask.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | struct netaddr NETADDR_GLOBAL_IP_BRC = { NETADDR_IPv4, IPv4_ADDR_LEN, 14 | {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} 15 | }; 16 | 17 | struct netaddr NETADDR_GLOBAL_ETH_BRC = { NETADDR_ETHERNET, ETH_ADDR_LEN, 18 | {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} 19 | }; 20 | 21 | /** 22 | * Apply a mask to a network address 23 | * @param a network address 24 | * @param b mask 25 | * @return network address with host portion masked away 26 | */ 27 | syscall netaddrmask(struct netaddr *a, struct netaddr *mask) 28 | { 29 | int i; 30 | if (a->type != mask->type) 31 | { 32 | return SYSERR; 33 | } 34 | 35 | if (a->len != mask->len) 36 | { 37 | return SYSERR; 38 | } 39 | 40 | for (i = 0; i < a->len; i++) 41 | { 42 | a->addr[i] = a->addr[i] & mask->addr[i]; 43 | } 44 | 45 | return OK; 46 | } 47 | -------------------------------------------------------------------------------- /device/tcp/tcpChksum.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpChksum.c 3 | * @provides tcpChcksum 4 | * 5 | * $Id: tcpChksum.c 2065 2009-09-04 21:44:36Z brylow $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | ushort tcpChksum(struct packet *pkt, ushort len, struct netaddr *src, 15 | struct netaddr *dst) 16 | { 17 | struct tcpPseudo *pseu; 18 | uchar buf[TCP_PSEUDO_LEN]; 19 | ushort sum; 20 | 21 | /* Store current data before TCP header in temporary buffer */ 22 | pseu = (struct tcpPseudo *)(pkt->curr - TCP_PSEUDO_LEN); 23 | memcpy(buf, pseu, TCP_PSEUDO_LEN); 24 | 25 | /* Generate TCP psuedo header */ 26 | memcpy(pseu->srcIp, src->addr, IPv4_ADDR_LEN); 27 | memcpy(pseu->dstIp, dst->addr, IPv4_ADDR_LEN); 28 | pseu->zero = 0; 29 | pseu->proto = IPv4_PROTO_TCP; 30 | pseu->len = hs2net(len); 31 | 32 | sum = netChksum(pseu, len + TCP_PSEUDO_LEN); 33 | 34 | /* Restore data before TCP header from temporary buffer */ 35 | memcpy(pseu, buf, TCP_PSEUDO_LEN); 36 | 37 | return sum; 38 | } 39 | -------------------------------------------------------------------------------- /mem/memRegionReclaim.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file memRegionReclaim.c 3 | * @provides memRegionReclaim 4 | * Attempt to reclaim an allocated memory region. 5 | * 6 | * $Id: memRegionReclaim.c 2020 2009-08-13 17:50:08Z mschul $ 7 | */ 8 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 9 | 10 | #include 11 | 12 | /** 13 | * Given a thread id, attempt to reclaim all the memory regions that were 14 | * allocated to that thread and return them to the region free list. 15 | * @param tid thread id holding memory regions. 16 | */ 17 | void memRegionReclaim(tid_typ tid) 18 | { 19 | struct memregion *region, *nextregion; 20 | 21 | /* Free allocated regions with tid */ 22 | region = regalloclist; 23 | while ((int)region != SYSERR) 24 | { 25 | /* store next region before mutating */ 26 | nextregion = region->next; 27 | 28 | if (region->thread_id == tid) 29 | { 30 | memRegionRemove(region, ®alloclist); 31 | safeUnmapRange(region->start, region->length); 32 | memRegionInsert(region, ®freelist); 33 | } 34 | 35 | region = nextregion; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /network/route/rtInit.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rtInit.c 3 | * @provides rtInit 4 | * 5 | * $Id: rtInit.c 2118 2009-11-05 05:22:51Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | struct rtEntry rttab[RT_NENTRY]; 17 | mailbox rtqueue; 18 | 19 | /** 20 | * Initialize the route table and route daemon. 21 | * @return OK if initialization is successful, otherwise SYSERR 22 | */ 23 | syscall rtInit(void) 24 | { 25 | int i = 0; 26 | 27 | /* Initialize route table */ 28 | for (i = 0; i < RT_NENTRY; i++) 29 | { 30 | bzero(&rttab[i], sizeof(struct rtEntry)); 31 | rttab[i].state = RT_FREE; 32 | } 33 | 34 | /* Initialize route queue */ 35 | rtqueue = mailboxAlloc(RT_NQUEUE); 36 | if (SYSERR == rtqueue) 37 | { 38 | return SYSERR; 39 | } 40 | 41 | /* Spawn rtDameon thread */ 42 | ready(create 43 | ((void *)rtDaemon, RT_THR_STK, RT_THR_PRIO, "rtDaemon", 0), 44 | RESCHED_NO); 45 | 46 | return OK; 47 | } 48 | -------------------------------------------------------------------------------- /system/unsleep.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file unsleep.c 3 | * @provides unsleep. 4 | * 5 | * $Id: unsleep.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** 17 | * Remove thread from the sleep queue prematurely 18 | * @param tid target thread 19 | * @return OK if thread removed, else SYSERR 20 | */ 21 | syscall unsleep(tid_typ tid) 22 | { 23 | register struct thrent *thrptr; 24 | irqmask im; 25 | tid_typ next = 0; 26 | 27 | im = disable(); 28 | 29 | if (isbadtid(tid)) 30 | { 31 | restore(im); 32 | return SYSERR; 33 | } 34 | 35 | thrptr = &thrtab[tid]; 36 | if ((thrptr->state != THRSLEEP) && (thrptr->state != THRTMOUT)) 37 | { 38 | restore(im); 39 | return SYSERR; 40 | } 41 | 42 | next = quetab[tid].next; 43 | if (next < NTHREAD) 44 | { 45 | quetab[next].key += quetab[tid].key; 46 | } 47 | 48 | getitem(tid); 49 | restore(im); 50 | return OK; 51 | } 52 | -------------------------------------------------------------------------------- /system/insert.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file insert.c 3 | * @provides insert. 4 | * 5 | * $Id: insert.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Insert a thread into a queue in descending key order. 15 | * @param tid thread ID to insert 16 | * @param q target queue 17 | * @param key sorting key 18 | * @return OK 19 | */ 20 | int insert(tid_typ tid, qid_typ q, int key) 21 | { 22 | int next; /* runs through list */ 23 | int prev; /* follows next through list */ 24 | 25 | if (isbadqid(q) || isbadtid(tid)) 26 | { 27 | return SYSERR; 28 | } 29 | 30 | next = quetab[quehead(q)].next; 31 | while (quetab[next].key >= key) 32 | { 33 | next = quetab[next].next; 34 | } 35 | 36 | /* insert tid between prev and next */ 37 | quetab[tid].next = next; 38 | quetab[tid].prev = prev = quetab[next].prev; 39 | quetab[tid].key = key; 40 | quetab[prev].next = tid; 41 | quetab[next].prev = tid; 42 | return OK; 43 | } 44 | -------------------------------------------------------------------------------- /device/tcp/tcpFree.c: -------------------------------------------------------------------------------- 1 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /** 11 | * Delete a TCB. 12 | * @param tcbptr pointer to transmission control block for connection 13 | * @precondition TCB mutex is already held 14 | */ 15 | devcall tcpFree(struct tcb *tcbptr) 16 | { 17 | irqmask im; 18 | semaphore temp; 19 | 20 | /* Verify TCB is not already free */ 21 | if (TCP_CLOSED == tcbptr->state) 22 | { 23 | signal(tcbptr->mutex); 24 | return SYSERR; 25 | } 26 | 27 | TCP_TRACE("Free TCB"); 28 | 29 | im = disable(); 30 | 31 | /* Free TCB */ 32 | temp = tcbptr->mutex; 33 | semfree(tcbptr->openclose); 34 | semfree(tcbptr->readers); 35 | semfree(tcbptr->writers); 36 | tcpTimerPurge(tcbptr, NULL); 37 | bzero(tcbptr, sizeof(struct tcb)); /* Clear tcp structure. */ 38 | tcbptr->state = TCP_CLOSED; 39 | tcbptr->devstate = TCP_FREE; 40 | tcbptr->mutex = temp; 41 | restore(im); 42 | signal(tcbptr->mutex); 43 | return OK; 44 | } 45 | -------------------------------------------------------------------------------- /device/tcp/tcpSendSyn.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tcpSendSyn.c 3 | * @provides tcpSendSyn 4 | * 5 | * $Id: tcpSendSyn.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Sends an SYN packet to establish a TCP connection. 14 | * @param tcpptr pointer to the transmission control block for connection 15 | * @pre-condition TCB mutex is already held 16 | * @post-condition TCB mutex is still held 17 | */ 18 | int tcpSendSyn(struct tcb *tcbptr) 19 | { 20 | uchar control; 21 | control = TCP_CTRL_SYN; 22 | 23 | if (tcbptr->sndflg & TCP_FLG_SNDACK) 24 | { 25 | tcbptr->sndflg &= ~TCP_FLG_SNDACK; 26 | control |= TCP_CTRL_ACK; 27 | } 28 | 29 | if (SYSERR == tcpSend(tcbptr, control, tcbptr->sndnxt, 30 | tcbptr->rcvnxt, NULL, 1)) 31 | { 32 | return SYSERR; 33 | } 34 | 35 | tcbptr->sndnxt++; 36 | tcbptr->sndflg |= TCP_FLG_SYN; 37 | 38 | if (SYSERR == tcpTimerSched(tcbptr->rxttime, tcbptr, TCP_EVT_RXT)) 39 | { 40 | return SYSERR; 41 | } 42 | 43 | return OK; 44 | } 45 | -------------------------------------------------------------------------------- /network/netaddr/netaddrsprintf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file netaddrsprintf.c 3 | * @provides netaddrsprintf 4 | * 5 | * $Id: netaddrsprintf.c 2020 2009-08-13 17:50:08Z mschul $ 6 | */ 7 | /* Embedded Xinu, Copyright (C) 2009. All rights reserved. */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | * Format netaddr and place in a string 15 | * @param str output string 16 | * @param addr netaddr to format 17 | * @return pointer to string 18 | */ 19 | int netaddrsprintf(char *str, struct netaddr *addr) 20 | { 21 | switch (addr->type) 22 | { 23 | case NETADDR_ETHERNET: 24 | sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", 25 | addr->addr[0], addr->addr[1], addr->addr[2], 26 | addr->addr[3], addr->addr[4], addr->addr[5]); 27 | break; 28 | case NETADDR_IPv4: 29 | sprintf(str, "%d.%d.%d.%d", 30 | addr->addr[0], addr->addr[1], addr->addr[2], 31 | addr->addr[3]); 32 | break; 33 | case NULL: 34 | sprintf(str, "NULL"); 35 | break; 36 | default: 37 | sprintf(str, "ERROR"); 38 | } 39 | return (int)str; 40 | } 41 | --------------------------------------------------------------------------------