diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..2d69f48 --- /dev/null +++ b/.cproject @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..36cd27c --- /dev/null +++ b/.project @@ -0,0 +1,77 @@ + + + ubixos-kernel + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.core.cnature + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dac72ca --- /dev/null +++ b/Makefile @@ -0,0 +1,90 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +all: pci-code ufs-code vfs-code isa-code kernel-code lib-code vmm-code sys-code init-code devfs-code mpi-code kmods-code kernel-img + +generic-code: generic + (cd generic;make) + +init-code: init + (cd init;make) + +kernel-code: kernel + (cd kernel;make) + +isa-code: isa + (cd isa;make) + +pci-code: pci + (cd pci;make) + +sys-code: sys + (cd sys;make) + +vmm-code: vmm + (cd vmm;make) + +ubixfs-code: ubixfs + (cd ubixfs;make) + +devfs-code: devfs + (cd devfs;make) + +graphics-code: graphics + (cd graphics;make) + +ld-code: ld + (cd ld;make) + +lib-code: lib + (cd lib;make) + +sde-code: sde + (cd sde;make) + +vfs-code: vfs + (cd vfs;make) + +net-code: net + (cd net;make) + +mpi-code: mpi + (cd mpi;make) + +ufs-code: ufs + (cd ufs;make) + +kmods-code: kmods + (cd kmods;make) + +kernel-img: compile + (/bin/echo "/* " > ./compile/null.c) + (date >> ./compile/null.c) + (echo $user >> ./compile/null.c) + (/bin/echo " */" >> ./compile/null.c) + (cd compile;make) + +install: +# (cd compile;cp ./ubix.elf /mnts/ubix/boot/loader) +# (cd boot;make install) +# (cd ../tools/;make format-dsk) + (cd ../tools/;make install-ubix) + +clean: + (cd init;make clean) + (cd compile;make clean) + (cd sys;make clean) + (cd vmm;make clean) + (cd lib;make clean) + (cd kernel;make clean) + (cd isa;make clean) + (cd vfs;make clean) + (cd ubixfs;make clean) + (cd pci;make clean) + (cd sde;make clean) + (cd devfs;make clean) + #(cd net;make clean) + (cd mpi;make clean) + (cd kmods;make clean) + (cd ufs;make clean) + (cd ../tools/;make clean) diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..882e13f --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,6 @@ +# $Id$ +# global 'sys' options + +INCLUDES = -I../include +CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O -DNOTIMP #-DVFSDEBUG -DDEBUG #-DVMMDEBUG #-DVFSDEBUG +KERNEL = ubix.elf diff --git a/README b/README new file mode 100644 index 0000000..8e48707 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +Directory Structure: + + boot - Contains boot strapping code + compile - Contains Information to build UbixOS kernel + devfs - Contains the devfs code + include - All of the kernel include files + init - Initialization code for kernel + isa - ISA drivers + kernel - Kernel code (things not directly connected with the system) + lib - Kernel library + mpi - Message passing interface code + net - Networking subsystem code (LwIP) + pci - PCI drivers and subsystem + sde - Screen drawing engine code + sys - System related code IDT etc. + ubixfs - UbixFS code + vfs - VFS subsystem code + vmm - VMM subsystem code diff --git a/compile/Makefile b/compile/Makefile new file mode 100644 index 0000000..1277ec6 --- /dev/null +++ b/compile/Makefile @@ -0,0 +1,39 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = null.o + +#Kernel Parts +KPARTS = ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../vfs/*.o ../pci/*.o ../devfs/*.o ../mpi/*.o ../ufs/*.o +# ../sde/*.o ../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 ../ubixfs/*.o + +# Link the kernel statically with fixed text+data address @1M +$(KERNEL) : $(OBJS) + #$(LD) -nostdlib -nostdinc --warn-section-align -o $@ $(OBJS) $(KPARTS) -Ttext 0x30000 -Tdata 0x20000 + $(LD) -T ./ldscript.i386 -o $@ $(OBJS) $(KPARTS) + #/usr/bin/strip $@ + +# Compile the source files +.cc.o: + $(CXX) -${CFLAGS} $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) ${CFLAGS} $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(KERNEL) null.c diff --git a/compile/ldscript.i386 b/compile/ldscript.i386 new file mode 100644 index 0000000..3cbcda8 --- /dev/null +++ b/compile/ldscript.i386 @@ -0,0 +1,77 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) + +ENTRY(_start) +SEARCH_DIR("libgcc"); +SECTIONS +{ + . = 0x30000 + SIZEOF_HEADERS; + + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } + .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } + .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } + .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } + .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } + .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : { *(.init) } =0x9090 + .plt : { *(.plt) } + + /* text/read-only data */ + .text : { *(.text .gnu.linkonce.t.*) } =0x9090 + + .rodata : { *(.rodata) .rodata.* .gnu.linkonce.r.* } + + /* writable data */ + . = ALIGN(0x1000); + __data_start = .; + .data : { *(.data .gnu.linkonce.d.*) } + + __ctor_list = .; + .ctors : + { + LONG((__ctor_end - __ctor_list) / 4 - 2) + *(.ctors) + LONG(0) + } + __ctor_end = .; + + __dtor_list = .; + .dtors : + { + LONG((__dtor_end - __dtor_list) / 4 - 2) + *(.dtors) + LONG(0) + } + __dtor_end = .; + + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + + /* unintialized data (in same segment as writable data) */ + __bss_start = .; + .bss : { *(.bss) } + + . = ALIGN(0x1000); + _end = . ; + + /* Strip unnecessary stuff */ + /DISCARD/ : { *(.comment .note .eh_frame) } +} diff --git a/devfs/Makefile b/devfs/Makefile new file mode 100644 index 0000000..2e6a497 --- /dev/null +++ b/devfs/Makefile @@ -0,0 +1,33 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Linker +LINKER = ld + +# Remove +REMOVE = rm -fr + +# Objects +OBJS = devfs.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/devfs/devfs.c b/devfs/devfs.c new file mode 100644 index 0000000..19ab909 --- /dev/null +++ b/devfs/devfs.c @@ -0,0 +1,260 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Spinlock for devfs we should start converting to sem/mutex */ +static spinLock_t devfsSpinLock = SPIN_LOCK_INITIALIZER; + +/* Length of dev list */ +static int devfs_len = 0x0; + +/** + This is the initialized called by the vfs system when enabling devfs + basically it allocates memory for the devfs module +*/ +static void devfs_initialize(struct vfs_mountPoint *mp) { + struct devfs_info *fsInfo = 0x0; + + /* Allocate memory for the fsInfo */ + if ((mp->fsInfo = (struct devfs_info *)kmalloc(sizeof(struct devfs_info))) == 0x0) + K_PANIC("devfs: failed to allocate memor\n"); + + fsInfo = mp->fsInfo; + fsInfo->deviceList = 0x0; + + /* Return */ + return; + } + +/** + This is the open routine called by the vfs when a fopen or open is called within the user or kernel space + file - this is the file node + fd - this is the file descriptor + + This format will be changing down the road +*/ +static int devfs_open(char *file,struct file *fd) { + struct devfs_info *fsInfo = fd->mp->fsInfo; + struct devfs_devices *tmpDev = 0x0; + struct device_node *device = 0x0; + struct devfs_obj *devfsObj = 0x0; + + spinLock(&devfsSpinLock); + + if (strcmp(file,"/") == 0x0) { + devfsObj->start = -1; + fd->size = devfs_len; + spinUnlock(&devfsSpinLock); + return(0x1); + } + if (file[0] == '/') + file++; + for (tmpDev = fsInfo->deviceList;tmpDev != 0x0;tmpDev = tmpDev->next) { + if (strcmp(tmpDev->devName,file) == 0x0) { + switch ((fd->mode & 0x3)) { + case 0: + case 1: + devfsObj = (struct devfs_obj *)kmalloc(sizeof(struct devfs_obj)); + fd->fsObj = devfsObj; + device = device_find(tmpDev->devMajor,tmpDev->devMinor); + devfsObj->start = (int)tmpDev; + fd->size = device->devInfo->size; + break; + default: + kprintf("Invalid File Mode\n"); + spinUnlock(&devfsSpinLock); + return(-1); + break; + } + spinUnlock(&devfsSpinLock); + return(0x1); + } + } + spinUnlock(&devfsSpinLock); + return(0x0); + } + +/** + Function: int readDevFS(fileDescriptor *fd,char *data,long offset,long size) + Description: Read File Into Data + Notes: +*/ +static int devfs_read(struct file *fd,char *data,long offset,long size) { + int i = 0x0,x = 0x0; + uInt32 sectors = 0x0; + uInt16 diff = 0x0; + struct device_node *device = 0x0; + struct devfs_obj *devfsObj = fd->fsObj; + struct devfs_devices *tmpDev = 0x0; + + tmpDev = (void *)devfsObj->start; + + if ((u_int32_t)tmpDev == -1) { + kprintf("Hi Ubie [%i]!!!\n", size); + for (i = 0;i < size;i++) { + data[i] = 'a'; + fd->buffer[i] = 'a'; + } + data[size - 1] = '\n'; + return(size); + } + + device = device_find(tmpDev->devMajor,tmpDev->devMinor); + + sectors = ((size+511)/512); + diff = (offset - ((offset/512)*512)); + + for (i=0x0;idevInfo->read(device->devInfo->info,fd->buffer,i + (offset/512),1); + for (x=0x0;x<(size - (i*512));x++) { + if (diff > 0) { + data[x] = fd->buffer[x + diff]; + } + else { + data[x] = fd->buffer[x]; + } + } + diff = 0x0; + data += 512; + } + + return(size); + } + +/************************************************************************ + +Function: int writeDevFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Write Data Into File +Notes: + +************************************************************************/ +static int devfs_write(struct file *fd,char *data,long offset,long size) { + int i = 0x0,x = 0x0; + struct device_node *device = 0x0; + struct devfs_devices *tmpDev = 0x0; + struct devfs_obj *devfsObj = fd->fsObj; + tmpDev = (void *)devfsObj->start; + + device = device_find(tmpDev->devMajor,tmpDev->devMinor); + for (i=0x0;i<((size+511)/512);i++) { + device->devInfo->read(device->devInfo->info,fd->buffer,i + (offset/512),1); + for (x=0x0;((x < 512) && ((x + (i * 512)) < size));x++) { + fd->buffer[x] = data[x]; + } + device->devInfo->write(device->devInfo->info,fd->buffer,i + (offset/512),1); + data += 512; + } + return(size); + } + + +int devfs_makeNode(char *name,uInt8 type,uInt16 major,uInt16 minor) { + struct vfs_mountPoint *mp = 0x0; + struct devfs_info *fsInfo = 0x0; + struct devfs_devices *tmpDev = 0x0; + + spinLock(&devfsSpinLock); + + mp = vfs_findMount("devfs"); + + if (mp == 0x0) { + kprintf("Error: Can't Find Mount Point\n"); + spinUnlock(&devfsSpinLock); + return(-1); + } + + fsInfo = mp->fsInfo; + + tmpDev = (struct devfs_devices *)kmalloc(sizeof(struct devfs_devices)); + + tmpDev->devType = type; + tmpDev->devMajor = major; + tmpDev->devMinor = minor; + sprintf(tmpDev->devName,name); + devfs_len += strlen(name) + 1; + + tmpDev->next = fsInfo->deviceList; + tmpDev->prev = 0x0; + if (fsInfo->deviceList != 0x0) { + fsInfo->deviceList->prev = tmpDev; + } + + fsInfo->deviceList = tmpDev; + + spinUnlock(&devfsSpinLock); + return(0x0); + } + +int devfs_dummy() { + kprintf("PLACE HOLDER\n"); + return(0x0); + } + +int devfs_init() { + /* Build our devfs struct */ + struct fileSystem devFS = { + NULL, /* prev */ + NULL, /* next */ + (void *)devfs_initialize, /* vfsInitFS */ + (void *)devfs_read, /* vfsRead */ + (void *)devfs_write, /* vfsWrite */ + (void *)devfs_open, /* vfsOpenFile */ + devfs_dummy, /* vfsCloseFile */ + devfs_dummy, /* vfsUnlink */ + devfs_dummy, /* vfsMakeDir */ + devfs_dummy, /* vfsRemDir */ + devfs_dummy, /* vfsSync */ + 0x1 /* vfsType */ + }; /* devFS */ + + if (vfsRegisterFS(devFS) != 0x0) { + //sysErr(systemErr,"Unable To Enable DevFS"); + return(0x1); + } + /* Mount our devfs this will build the devfs container node */ + vfs_mount(-1,0x0,0x0,0x1,"devfs","rw"); // Mount Device File System + + kprintf("Devfs\n"); + + /* Return */ + return(0x0); + } + +/*** + END + ***/ diff --git a/devfs/major.txt b/devfs/major.txt new file mode 100644 index 0000000..27e323d --- /dev/null +++ b/devfs/major.txt @@ -0,0 +1 @@ +TTY - 0x10 diff --git a/include/assert.h b/include/assert.h new file mode 100644 index 0000000..e6c3f51 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/assert.h,v 1.4 2002/03/23 17:24:53 imp Exp $ + */ + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#undef assert +#undef _assert + +#ifdef NDEBUG +#define assert(e) ((void)0) +#define _assert(e) ((void)0) +#else +#define _assert(e) assert(e) + +#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \ + __LINE__, #e)) +#endif /* NDEBUG */ + +__BEGIN_DECLS +void __assert(const char *, const char *, int, const char *); +__END_DECLS diff --git a/include/devfs/devfs.h b/include/devfs/devfs.h new file mode 100644 index 0000000..9fddaf0 --- /dev/null +++ b/include/devfs/devfs.h @@ -0,0 +1,103 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DEVFS_H +#define _DEVFS_H + +#include +#include + +struct devfs_devices { + struct devfs_devices *next; + struct devfs_devices *prev; + uInt8 devType; + uInt16 devMajor; + uInt16 devMinor; + char devName[32]; + }; + +struct devfs_info { + struct devfs_devices *deviceList; + }; + +struct devfs_obj { + uInt16 length; + uInt32 start; + }; + +int devfs_init(); +int devfs_makeNode(char *name,uInt8 type,uInt16 major,uInt16 minor); +/* +int devfs_open(char *file,fileDescriptor *fd); +void devFSInit(struct mountPoints *mp); +int devfs_read(fileDescriptor *fd,char *data,long offset,long size); +int devfs_write(fileDescriptor *fd,char *data,long offset,long size); +*/ + +#endif + +/*** + $Log$ + Revision 1.2 2007/01/26 19:33:19 reddawg + More vfs fixes + + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:38 reddawg + no message + + Revision 1.5 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.4 2004/07/14 12:17:52 reddawg + devfs: devFSEnable to devfs_init + Changed Startup Routines + + Revision 1.3 2004/05/21 14:54:41 reddawg + Cleaned up + + + END + ***/ diff --git a/include/isa/8259.h b/include/isa/8259.h new file mode 100644 index 0000000..41158ed --- /dev/null +++ b/include/isa/8259.h @@ -0,0 +1,78 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _8259_H +#define _8259_H + +#include + +#define mPic 0x20 // I/O for master PIC +#define mImr 0x21 // I/O for master IMR +#define sPic 0xA0 // I/O for slave PIC +#define sImr 0xA1 // I/O for slace IMR +#define eoi 0x20 // EOI command +#define icw1 0x11 // Cascade, Edge triggered +#define icw4 0x01 // 8088 mode +#define mVec 0x68 // Vector for master +#define sVec 0x70 // Vector for slave +#define ocw3Irr 0x0A // Read IRR +#define ocw3Isr 0x0B // Read ISR + +int i8259_init(); +void irqEnable(uInt16 irqNo); +void irqDisable(uInt16 irqNo); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:39 reddawg + no message + + Revision 1.4 2004/07/09 13:20:08 reddawg + Oh yeah duh you can not name functions with numbers + + Revision 1.3 2004/07/09 13:14:29 reddawg + 8259: changed init8259 to 8259_init + Adjusted Startup Routines + + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + END + ***/ diff --git a/include/isa/atkbd.h b/include/isa/atkbd.h new file mode 100644 index 0000000..d3d2105 --- /dev/null +++ b/include/isa/atkbd.h @@ -0,0 +1,73 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _ATKBD_H +#define _ATKBD_H + +#define shiftKey 1 +#define controlKey 2 +#define altKey 4 +#define ledNumlock 2 +#define ledScrolllock 1 +#define ledCapslock 4 + +int atkbd_init(); +void atkbd_isr(); + +void keyboardHandler(); +void setLED(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:39 reddawg + no message + + Revision 1.4 2004/07/29 21:32:16 reddawg + My quick lunchs breaks worth of updates.... + + Revision 1.3 2004/07/09 13:34:51 reddawg + keyboard: keyboardInit to atkbd_init + Adjusted initialization routines + + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + END + ***/ diff --git a/include/isa/fdc.h b/include/isa/fdc.h new file mode 100644 index 0000000..2a56ff2 --- /dev/null +++ b/include/isa/fdc.h @@ -0,0 +1,111 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _FDC_H +#define _FDC_H + +#include + +typedef struct DrvGeom { + Int8 heads; + Int8 tracks; + Int8 spt; +} drvGeom; + + +#define fdcMsr (0x3f4) +#define fdcData (0x3f5) +#define fdcDir (0x3f7) +#define fdcCcr (0x3f7) +#define fdcDor (0x3f2) +#define fdcDrs (0x3f4) + +#define cmdWrite (0xc5) +#define cmdRead (0xe6) +#define cmdSeek (0x0f) +#define cmdSensei (0x08) +#define cmdRecal (0x07) +#define cmdSpecify (0x03) + +#define dg144Heads 2 /* heads per drive (1.44M) */ +#define dg144Tracks 80 +#define dg144Spt 18 +#define dg144Gap3rw 0x1b +#define dg168Gap3rw 0x1c + + + +int fdc_init(); +void floppyIsr(); +void floppyIsrhndlr(); +void sendByte(int Int8); +int getByte(); +bool fdcRw(int block,Int8 *blockBuffer,bool read,unsigned long numSectors); +void block2Hts(int block,int *head,int *track,int *sector); +void motorOn(void); +void motorOff(void); +bool seek(int track); +bool waitFdc(bool sensei); +int getByte(); +void sendByte(int Int8); +void recalibrate(void); +void reset(void); +bool writeBlock(int block,Int8 *blockBuffer, unsigned long numSectors); +bool readBlock(int block,Int8 *blockBuffer, unsigned long numSectors); +void fdcWrite(void *info,void *,uInt32 startSector,uInt32 sectorCount); +void fdcRead(void *info,void *,uInt32 startSector,uInt32 sectorCount); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:39 reddawg + no message + + Revision 1.6 2004/07/17 02:38:31 reddawg + Fixed a few problems + + Revision 1.5 2004/07/14 12:42:46 reddawg + fdc: fdcInit to fdc_init + Changed Startup Routines + + Revision 1.4 2004/05/21 14:57:16 reddawg + Cleaned up + + END + ***/ diff --git a/include/isa/mouse.h b/include/isa/mouse.h new file mode 100644 index 0000000..596b6fa --- /dev/null +++ b/include/isa/mouse.h @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MOUE_H +#define _MOUSE_H + +int mouseInit(); +void mouseISR(); +void mouseHandler(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:39 reddawg + no message + + Revision 1.1 2004/06/04 10:20:53 reddawg + mouse drive: fixed a few bugs works a bit better now + + END + ***/ diff --git a/include/isa/ne2k.h b/include/isa/ne2k.h new file mode 100644 index 0000000..b408360 --- /dev/null +++ b/include/isa/ne2k.h @@ -0,0 +1,200 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _NE2K_H +#define _NE2K_H + +#include +#include + +#define ether_addr ether_addr_t +typedef struct dp_rcvhdr +{ + uInt8 dr_status; /* Copy of rsr */ + uInt8 dr_next; /* Pointer to next packet */ + uInt8 dr_rbcl; /* Receive Byte Count Low */ + uInt8 dr_rbch; /* Receive Byte Count High */ +} dp_rcvhdr_t; + +typedef union etheraddr { + unsigned char bytes[6]; /* byteorder safe initialization */ + unsigned short shorts[3]; /* force 2-byte alignment */ +} ether_addr; + + +struct nicBuffer { + struct nicBuffer *next; + int length; + char *buffer; + }; + +#define RSR_FO 0x08 +#define RSR_PRX 0x01 +#define DEF_ENABLED 0x200 + +#define OK 0 + + +#define startPage 0x4C +#define stopPage 0x80 + + +#define NE_CMD 0x00 +#define NE_PSTART 0x01 +#define NE_PSTOP 0x02 +#define NE_BNRY 0x03 +#define NE_TPSR 0x04 +#define NE_ISR 0x07 +#define NE_CURRENT 0x07 +#define NE_RBCR0 0x0A +#define NE_RBCR1 0x0B +#define NE_RCR 0x0C +#define NE_TCR 0x0D +#define NE_DCR 0x0E +#define NE_IMR 0x0F + + +#define NE_DCR_WTS 0x01 +#define NE_DCR_LS 0x08 +#define NE_DCR_AR 0x10 +#define NE_DCR_FT1 0x40 +#define NE_DCR_FT0 0x20 + + + +#define E8390_STOP 0x01 +#define E8390_NODMA 0x20 +#define E8390_PAGE0 0x00 +#define E8390_PAGE1 0x40 +#define E8390_CMD 0x00 +#define E8390_START 0x02 +#define E8390_RREAD 0x08 +#define E8390_RWRITE 0x10 +#define E8390_RXOFF 0x20 +#define E8390_TXOFF 0x00 +#define E8390_RXCONFIG 0x04 +#define E8390_TXCONFIG 0x00 + +#define EN0_COUNTER0 0x0d +#define EN0_DCFG 0x0e +#define EN0_RCNTLO 0x0a +#define EN0_RCNTHI 0x0b +#define EN0_ISR 0x07 +#define EN0_IMR 0x0f +#define EN0_RSARLO 0x08 +#define EN0_RSARHI 0x09 +#define EN0_TPSR 0x04 +#define EN0_RXCR 0x0c +#define EN0_TXCR 0x0D +#define EN0_STARTPG 0x01 +#define EN0_STOPPG 0x02 +#define EN0_BOUNDARY 0x03 + +#define EN1_PHYS 0x01 +#define EN1_CURPAG 0x07 +#define EN1_MULT 0x08 + +#define NE1SM_START_PG 0x20 +#define NE1SM_STOP_PG 0x40 +#define NESM_START_PG 0x40 +#define NESM_STOP_PG 0x80 + +#define ENISR_ALL 0x3f + +#define ENDCFG_WTS 0x01 + +#define NE_DATAPORT 0x10 + +#define TX_2X_PAGES 12 +#define TX_1X_PAGES 6 +#define TX_PAGES (dev->priv->pingPong ? TX_2X_PAGES : TX_1X_PAGES) + + +#define DP_CURR 0x7 /* Current Page Register */ +#define DP_MAR0 0x8 /* Multicast Address Register 0 */ +#define DP_MAR1 0x9 /* Multicast Address Register 1 */ +#define DP_MAR2 0xA /* Multicast Address Register 2 */ +#define DP_MAR3 0xB /* Multicast Address Register 3 */ +#define DP_MAR4 0xC /* Multicast Address Register 4 */ +#define DP_MAR5 0xD /* Multicast Address Register 5 */ +#define DP_MAR6 0xE /* Multicast Address Register 6 */ +#define DP_MAR7 0xF /* Multicast Address Register 7 */ + +#define DP_CNTR0 0xD /* Tally Counter 0 */ +#define DP_CNTR1 0xE /* Tally Counter 1 */ +#define DP_CNTR2 0xF /* Tally Counter 2 */ + + +#define DP_PAGESIZE 256 + +extern char *nicPacket; +extern uInt32 packetLength; + + +int ne2k_init(); +int ne2kProbe(int,struct device *); +int ne2kDevInit(struct device *); +void NS8390_init(struct device *dev,int startp); + +void ne2kISR(); +void ne2kHandler(); + +int NICtoPC(struct device *dev,void *packet,int length,int nic_addr); +int PCtoNIC(struct device *dev,void *packet,int length); + +struct nicBuffer *ne2kAllocBuffer(int); +struct nicBuffer *ne2kGetBuffer(); +void ne2kFreeBuffer(struct nicBuffer *); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:39 reddawg + no message + + Revision 1.6 2004/07/14 12:03:49 reddawg + ne2k: ne2kInit to ne2k_init + Changed Startup Routines + + Revision 1.5 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ diff --git a/include/isa/pit.h b/include/isa/pit.h new file mode 100644 index 0000000..23a6a2f --- /dev/null +++ b/include/isa/pit.h @@ -0,0 +1,71 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PIT_H +#define _PIT_H + +#define PIT_TIMER 200 + +int pit_init(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.6 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.5 2004/07/16 04:06:32 reddawg + Tune ups this stuff should of been taken care of months ago + + Revision 1.4 2004/07/16 01:08:58 reddawg + Whew we work once again + + Revision 1.3 2004/07/09 13:29:15 reddawg + pit: pitInit to pit_init + Adjusted initialization routines + + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + END + ***/ + diff --git a/include/lib/bioscall.h b/include/lib/bioscall.h new file mode 100644 index 0000000..ca3aa11 --- /dev/null +++ b/include/lib/bioscall.h @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _BIOSCALL_H +#define _BIOSCALL_H + +#include + +#define EFLAG_TF 0x100 +#define EFLAG_IF 0x200 +#define EFLAG_IOPL3 0x3000 +#define EFLAG_VM 0x20000 + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds); +void bios16Code(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/include/lib/kmalloc.h b/include/lib/kmalloc.h new file mode 100644 index 0000000..aba34c1 --- /dev/null +++ b/include/lib/kmalloc.h @@ -0,0 +1,100 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KMALLOC_H +#define _KMALLOC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define sysID -2 +#define MALLOC_ALIGN_SIZE 32 +#define MALLOC_ALIGN(size) (size + ((((size) % (MALLOC_ALIGN_SIZE)) == 0)? 0 : ((MALLOC_ALIGN_SIZE) - ((size) % (MALLOC_ALIGN_SIZE))))) + +struct memDescriptor { + struct memDescriptor *prev; //4 + struct memDescriptor *next; //4 + void *baseAddr; //4 + uInt32 limit; //4 + /*uInt8 status; //1 */ + /*char reserved[11]; //11 */ + }; + +void kfree(void *baseAddr); +void *kmalloc(uInt32 len); + +#ifdef __cplusplus + } +#endif + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.7 2004/09/14 20:57:01 reddawg + Bug fixes: macro problem over opt a multiply + + Revision 1.6 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.5 2004/07/19 02:08:27 reddawg + Cleaned out the rest of debuging code also temporarily disabled the ip stack to improve boot time + + Revision 1.4 2004/07/18 05:24:15 reddawg + Fixens + + Revision 1.3 2004/05/21 15:00:27 reddawg + Cleaned up + + END + ***/ diff --git a/include/lib/kprint.h b/include/lib/kprint.h new file mode 100644 index 0000000..51a18b0 --- /dev/null +++ b/include/lib/kprint.h @@ -0,0 +1,60 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPRINT_H +#define _KPRINT_H + +#include + +int kprintf(const char *fmt, ...); + +extern int printOff; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/include/lib/kprintf.h b/include/lib/kprintf.h new file mode 100644 index 0000000..f957dda --- /dev/null +++ b/include/lib/kprintf.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPRINTF_H +#define _KPRINTF_H + +#include + +int kprintf(const char *fmt, ...); +int ogPrintf(char *); + +extern int printOff; +extern int ogprintOff; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/include/lib/libcpp.h b/include/lib/libcpp.h new file mode 100644 index 0000000..6fbb726 --- /dev/null +++ b/include/lib/libcpp.h @@ -0,0 +1,61 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef __LIBCPP_H +#define __LIBCPP_H + +#include + +void * operator new(unsigned size); +void operator delete(void * ptr); +void * operator new[](unsigned size); +void operator delete[](void * ptr); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:40 reddawg + no message + + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/include/lib/string.h b/include/lib/string.h new file mode 100644 index 0000000..1d6008e --- /dev/null +++ b/include/lib/string.h @@ -0,0 +1,89 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +char * strcpy(char *, const char *); +int strcmp(const char *str1,const char *str2); +int strncmp(const char * a, const char * b, size_t c); +void *memcpy(const void *dst, const void * src, size_t length); +void *memset(void * dst, int c, size_t length); +int strlen(const char * string); +int memcmp(const void * dst, const void * src, size_t length); +void strncpy(char * dest, const char * src, size_t size); +char *strtok(char *str, const char *sep); +char *strtok_r(char *str, const char *sep, char **last); +char *strstr(const char *s,char *find); + +int sprintf(char *buf,const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:41 reddawg + no message + + Revision 1.5 2004/07/20 19:09:40 flameshadow + chg: put strcpy() declaration in the right .h file + add: prototypes for the dirCaching functions in dirCache.h + chg: renamed dirCaching functions + + Revision 1.4 2004/07/06 23:26:12 reddawg + Fixed A Compilation Error + + Revision 1.3 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/include/math.h b/include/math.h new file mode 100644 index 0000000..bce9c5f --- /dev/null +++ b/include/math.h @@ -0,0 +1,67 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef __MATH_H +#define __MATH_H + +#include + +//typedef long long int quad_t; +typedef unsigned long long int u_quad_t; + +double atan(double x); +double sqrt(double x); +u_quad_t __udivdi3(u_quad_t a,u_quad_t b); +quad_t __divdi3(quad_t a,quad_t b); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.2 2006/10/31 20:41:16 reddawg + Includes + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:38 reddawg + no message + + Revision 1.2 2004/05/21 15:22:35 reddawg + Cleaned up + + + END + ***/ diff --git a/include/mpi/mpi.h b/include/mpi/mpi.h new file mode 100644 index 0000000..51add8f --- /dev/null +++ b/include/mpi/mpi.h @@ -0,0 +1,106 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MPI_H +#define _MPI_H + +#include +#include + +#define MESSAGE_LENGTH 248 + +struct mpi_message { + char data[MESSAGE_LENGTH]; + uInt32 header; + pidType pid; + struct mpi_message *next; + }; + +struct mpi_mbox { + struct mpi_mbox *next; + struct mpi_mbox *prev; + struct mpi_message *msg; + struct mpi_message *msgLast; + char name[64]; + pidType pid; + }; + +typedef struct mpi_mbox mpi_mbox_t; +typedef struct mpi_message mpi_message_t; + + +int mpi_createMbox(char *); +int mpi_destroyMbox(char *); +int mpi_postMessage(char *,uInt32,mpi_message_t *); +int mpi_fetchMessage(char *,mpi_message_t *); +int mpi_spam(uInt32,void *); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:42 reddawg + no message + + Revision 1.8 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.7 2004/05/28 03:52:56 reddawg + mpi: took a few suggestions from TCA + + Revision 1.6 2004/05/25 18:33:11 reddawg + We now use 128byte messages I can increase later + + Revision 1.5 2004/05/25 18:29:57 reddawg + We now lock onto a pid + + Revision 1.4 2004/05/25 16:52:22 reddawg + We now have mpiDestroyMbox(char *) This will of course destroy a mail box + + Revision 1.3 2004/05/25 16:28:21 reddawg + Made mpiFindMbox() static + + Revision 1.2 2004/05/25 15:42:19 reddawg + Enabled mpiSpam(); + + Revision 1.1 2004/05/25 14:07:01 reddawg + Sorry we can't forget the headers files + + END + ***/ + diff --git a/include/net/api.h b/include/net/api.h new file mode 100644 index 0000000..1d97411 --- /dev/null +++ b/include/net/api.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_API_H__ +#define __LWIP_API_H__ + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "net/ipv4/ip.h" + +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/err.h" + +#define NETCONN_NOCOPY 0x00 +#define NETCONN_COPY 0x01 + +enum netconn_type { + NETCONN_TCP, + NETCONN_UDP, + NETCONN_UDPLITE, + NETCONN_UDPNOCHKSUM +}; + +enum netconn_state { + NETCONN_NONE, + NETCONN_WRITE, + NETCONN_ACCEPT, + NETCONN_RECV, + NETCONN_CONNECT, + NETCONN_CLOSE +}; + +struct netbuf { + struct pbuf *p, *ptr; + struct ip_addr *fromaddr; + uInt16 fromport; + err_t err; +}; + +struct netconn { + enum netconn_type type; + enum netconn_state state; + union { + struct tcp_pcb *tcp; + struct udp_pcb *udp; + } pcb; + err_t err; + sys_mbox_t mbox; + sys_mbox_t recvmbox; + sys_mbox_t acceptmbox; + sys_sem_t sem; +}; + +/* Network buffer functions: */ +struct netbuf * netbuf_new (void); +void netbuf_delete (struct netbuf *buf); +void * netbuf_alloc (struct netbuf *buf, uInt16 size); +void netbuf_free (struct netbuf *buf); +void netbuf_ref (struct netbuf *buf, + void *dataptr, uInt16 size); +void netbuf_chain (struct netbuf *head, + struct netbuf *tail); + +uInt16 netbuf_len (struct netbuf *buf); +err_t netbuf_data (struct netbuf *buf, + void **dataptr, uInt16 *len); +Int8 netbuf_next (struct netbuf *buf); +void netbuf_first (struct netbuf *buf); + +void netbuf_copy (struct netbuf *buf, + void *dataptr, uInt16 len); +struct ip_addr * netbuf_fromaddr (struct netbuf *buf); +uInt16 netbuf_fromport (struct netbuf *buf); + +/* Network connection functions: */ +struct netconn * netconn_new (enum netconn_type type); +err_t netconn_delete (struct netconn *conn); +enum netconn_type netconn_type (struct netconn *conn); +err_t netconn_peer (struct netconn *conn, + struct ip_addr **addr, + uInt16 *port); +err_t netconn_addr (struct netconn *conn, + struct ip_addr **addr, + uInt16 *port); +err_t netconn_bind (struct netconn *conn, + struct ip_addr *addr, + uInt16 port); +err_t netconn_connect (struct netconn *conn, + struct ip_addr *addr, + uInt16 port); +err_t netconn_listen (struct netconn *conn); +struct netconn * netconn_accept (struct netconn *conn); +struct netbuf * netconn_recv (struct netconn *conn); +err_t netconn_send (struct netconn *conn, + struct netbuf *buf); +err_t netconn_write (struct netconn *conn, + void *dataptr, uInt16 size, + uInt8 copy); +err_t netconn_close (struct netconn *conn); + +err_t netconn_err (struct netconn *conn); + +void netbuf_copy_partial(struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset); + +#endif /* __LWIP_API_H__ */ + + diff --git a/include/net/api_msg.h b/include/net/api_msg.h new file mode 100644 index 0000000..2728f5f --- /dev/null +++ b/include/net/api_msg.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_API_MSG_H__ +#define __LWIP_API_MSG_H__ + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "net/ipv4/ip.h" + +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/api.h" + +enum api_msg_type { + API_MSG_NEWCONN, + API_MSG_DELCONN, + + API_MSG_BIND, + API_MSG_CONNECT, + + API_MSG_LISTEN, + API_MSG_ACCEPT, + + API_MSG_SEND, + API_MSG_RECV, + API_MSG_WRITE, + + API_MSG_CLOSE, + + API_MSG_MAX +}; + +struct api_msg_msg { + struct netconn *conn; + enum netconn_type conntype; + union { + struct pbuf *p; + struct { + struct ip_addr *ipaddr; + uInt16 port; + } bc; + struct { + void *dataptr; + uInt16 len; + unsigned char copy; + } w; + sys_mbox_t mbox; + uInt16 len; + } msg; +}; + +struct api_msg { + enum api_msg_type type; + struct api_msg_msg msg; +}; + +void api_msg_input(struct api_msg *msg); +void api_msg_post(struct api_msg *msg); + +#endif /* __LWIP_API_MSG_H__ */ + diff --git a/include/net/arch.h b/include/net/arch.h new file mode 100644 index 0000000..8be38c0 --- /dev/null +++ b/include/net/arch.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ARCH_H__ +#define __LWIP_ARCH_H__ + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +#include "arch/cpu.h" +#include "arch/cc.h" + +#ifndef PACK_STRUCT_BEGIN +#define PACK_STRUCT_BEGIN +#endif /* PACK_STRUCT_BEGIN */ + +#ifndef PACK_STRUCT_END +#define PACK_STRUCT_END +#endif /* PACK_STRUCT_END */ + +#ifndef PACK_STRUCT_FIELD +#define PACK_STRUCT_FIELD(x) x +#endif /* PACK_STRUCT_FIELD */ + +#endif /* __LWIP_ARCH_H__ */ diff --git a/include/net/arch/cc.h b/include/net/arch/cc.h new file mode 100644 index 0000000..a2f83a5 --- /dev/null +++ b/include/net/arch/cc.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_CC_H__ +#define __ARCH_CC_H__ + +#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) +#define PACK_STRUCT_STRUCT __attribute__((packed)) +#define PACK_STRUCT_BEGIN +#define PACK_STRUCT_END + +#endif /* __ARCH_CC_H__ */ diff --git a/include/net/arch/cpu.h b/include/net/arch/cpu.h new file mode 100644 index 0000000..0a6d531 --- /dev/null +++ b/include/net/arch/cpu.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_CPU_H__ +#define __ARCH_CPU_H__ + +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif /* BYTE_ORDER */ + +#endif /* __ARCH_CPU_H__ */ diff --git a/include/net/arch/init.h b/include/net/arch/init.h new file mode 100644 index 0000000..0b5409d --- /dev/null +++ b/include/net/arch/init.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_INIT_H__ +#define __ARCH_INIT_H__ + +#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg) + +#endif /* __ARCH_INIT_H__ */ + + + + diff --git a/include/net/arch/lib.h b/include/net/arch/lib.h new file mode 100644 index 0000000..13d5446 --- /dev/null +++ b/include/net/arch/lib.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_LIB_H__ +#define __ARCH_LIB_H__ + +#ifndef _STRING_H_ +#ifndef _STRING_H +int strlen(const char *str); +int strncmp(const char *str1, const char *str2, int len); +void bcopy(const void *src, void *dest, int len); +void bzero(void *data, int n); +#endif /* _STRING_H */ +#endif /* _STRING_H_ */ + +#endif /* __ARCH_LIB_H__ */ diff --git a/include/net/arch/perf.h b/include/net/arch/perf.h new file mode 100644 index 0000000..9b47e5b --- /dev/null +++ b/include/net/arch/perf.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_PERF_H__ +#define __ARCH_PERF_H__ + +#include + +#ifdef PERF +#define PERF_START { \ + unsigned long __c1l, __c1h, __c2l, __c2h; \ + __asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h)) +#define PERF_STOP(x) __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \ + perf_print(__c1l, __c1h, __c2l, __c2h, x);} + +/*#define PERF_START do { \ + struct tms __perf_start, __perf_end; \ + times(&__perf_start) +#define PERF_STOP(x) times(&__perf_end); \ + perf_print_times(&__perf_start, &__perf_end, x);\ + } while(0)*/ +#else /* PERF */ +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ +#endif /* PERF */ + +void perf_print(unsigned long c1l, unsigned long c1h, + unsigned long c2l, unsigned long c2h, + char *key); + +void perf_print_times(struct tms *start, struct tms *end, char *key); + +void perf_init(char *fname); + +#endif /* __ARCH_PERF_H__ */ diff --git a/include/net/arch/sys_arch.h b/include/net/arch/sys_arch.h new file mode 100644 index 0000000..9ef598f --- /dev/null +++ b/include/net/arch/sys_arch.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_SYS_ARCH_H__ +#define __ARCH_SYS_ARCH_H__ + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +struct sys_sem; +typedef struct sys_sem * sys_sem_t; + +struct sys_mbox; +typedef struct sys_mbox *sys_mbox_t; + +struct sys_thread; +typedef struct sys_thread * sys_thread_t; + +#endif /* __ARCH_SYS_ARCH_H__ */ + diff --git a/include/net/debug.h b/include/net/debug.h new file mode 100644 index 0000000..3d9899f --- /dev/null +++ b/include/net/debug.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_DEBUG_H__ +#define __LWIP_DEBUG_H__ + +#ifdef LWIP_DEBUG + +#define ASSERT(x,y) if(!(y)) {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); fflush(NULL); abort();} + +/* These defines control the amount of debugging output: */ +#define MEM_TRACKING + +#define DEMO_DEBUG 1 + +#define ARP_DEBUG 0 + +#define NETIF_DEBUG 1 +#define PBUF_DEBUG 0 +#define DELIF_DEBUG 0 +#define DROPIF_DEBUG 0 +#define TUNIF_DEBUG 0 +#define UNIXIF_DEBUG 0 +#define TAPIF_DEBUG 0 + +#define API_LIB_DEBUG 0 +#define API_MSG_DEBUG 0 +#define SOCKETS_DEBUG 1 +#define ICMP_DEBUG 0 +#define INET_DEBUG 0 +#define IP_DEBUG 0 +#define IP_REASS_DEBUG 1 +#define MEM_DEBUG 0 +#define MEMP_DEBUG 0 +#define SYS_DEBUG 0 +#define TCP_DEBUG 0 +#define TCP_INPUT_DEBUG 0 +#define TCP_FR_DEBUG 0 +#define TCP_RTO_DEBUG 0 +#define TCP_REXMIT_DEBUG 0 +#define TCP_CWND_DEBUG 0 +#define TCP_WND_DEBUG 0 +#define TCP_OUTPUT_DEBUG 0 +#define TCP_RST_DEBUG 0 +#define TCP_QLEN_DEBUG 0 +#define UDP_DEBUG 0 +#define TCPIP_DEBUG 0 +#define TCPDUMP_DEBUG 0 +#define DHCP_DEBUG 1 + +#include +#define DEBUGF(debug, x) do { if(debug){ printf x; } } while(0) + + +#else /* LWIP_DEBUG */ + +/* DEBUG is not defined, so we define null macros for ASSERT and DEBUGF */ + +#define ASSERT(x,y) +#define DEBUGF(debug, x) + +/* And we define those to be zero: */ + +#define DEMO_DEBUG 0 +#define ARP_DEBUG 0 +#define NETIF_DEBUG 0 +#define PBUF_DEBUG 0 +#define DELIF_DEBUG 0 +#define DROPIF_DEBUG 0 +#define TUNIF_DEBUG 0 +#define UNIXIF_DEBUG 0 +#define TAPIF_DEBUG 0 +#define API_LIB_DEBUG 0 +#define API_MSG_DEBUG 0 +#define SOCKETS_DEBUG 0 +#define ICMP_DEBUG 0 +#define INET_DEBUG 0 +#define IP_DEBUG 0 +#define IP_REASS_DEBUG 0 +#define MEM_DEBUG 0 +#define MEMP_DEBUG 0 +#define SYS_DEBUG 0 +#define TCP_DEBUG 0 +#define TCP_INPUT_DEBUG 0 +#define TCP_FR_DEBUG 0 +#define TCP_RTO_DEBUG 0 +#define TCP_REXMIT_DEBUG 0 +#define TCP_CWND_DEBUG 0 +#define TCP_WND_DEBUG 0 +#define TCP_OUTPUT_DEBUG 0 +#define TCP_RST_DEBUG 0 +#define TCP_QLEN_DEBUG 0 +#define UDP_DEBUG 0 +#define TCPIP_DEBUG 0 +#define TCPDUMP_DEBUG 0 +#define DHCP_DEBUG 0 + +#endif /* LWIP_DEBUG */ + + +#endif /* __LWIP_DEBUG_H__ */ + + + + + + diff --git a/include/net/def.h b/include/net/def.h new file mode 100644 index 0000000..19e2289 --- /dev/null +++ b/include/net/def.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_DEF_H__ +#define __LWIP_DEF_H__ + +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#include "arch/lib.h" + +#endif /* __LWIP_DEF_H__ */ + diff --git a/include/net/err.h b/include/net/err.h new file mode 100644 index 0000000..ddaba06 --- /dev/null +++ b/include/net/err.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ERR_H__ +#define __LWIP_ERR_H__ + +#include + +#include "net/debug.h" + +#include "net/arch/cc.h" + +typedef Int8 err_t; + +/* Definitions for error constants. */ + +#define ERR_OK 0 /* No error, everything OK. */ +#define ERR_MEM -1 /* Out of memory error. */ +#define ERR_BUF -2 /* Buffer error. */ + + +#define ERR_ABRT -3 /* Connection aborted. */ +#define ERR_RST -4 /* Connection reset. */ +#define ERR_CLSD -5 /* Connection closed. */ +#define ERR_CONN -6 /* Not connected. */ + +#define ERR_VAL -7 /* Illegal value. */ + +#define ERR_ARG -8 /* Illegal argument. */ + +#define ERR_RTE -9 /* Routing problem. */ + +#define ERR_USE -10 /* Address in use. */ + + + +#ifdef LWIP_DEBUG +extern char *lwip_strerr(err_t err); +#else +#define lwip_strerr(x) "" +#endif /* LWIP_DEBUG */ +#endif /* __LWIP_ERR_H__ */ diff --git a/include/net/ipv4/icmp.h b/include/net/ipv4/icmp.h new file mode 100644 index 0000000..0a12aeb --- /dev/null +++ b/include/net/ipv4/icmp.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ICMP_H__ +#define __LWIP_ICMP_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" + +#include "net/netif.h" + +#define ICMP_ER 0 /* echo reply */ +#define ICMP_DUR 3 /* destination unreachable */ +#define ICMP_SQ 4 /* source quench */ +#define ICMP_RD 5 /* redirect */ +#define ICMP_ECHO 8 /* echo */ +#define ICMP_TE 11 /* time exceeded */ +#define ICMP_PP 12 /* parameter problem */ +#define ICMP_TS 13 /* timestamp */ +#define ICMP_TSR 14 /* timestamp reply */ +#define ICMP_IRQ 15 /* information request */ +#define ICMP_IR 16 /* information reply */ + +enum icmp_dur_type { + ICMP_DUR_NET = 0, /* net unreachable */ + ICMP_DUR_HOST = 1, /* host unreachable */ + ICMP_DUR_PROTO = 2, /* protocol unreachable */ + ICMP_DUR_PORT = 3, /* port unreachable */ + ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ + ICMP_DUR_SR = 5 /* source route failed */ +}; + +enum icmp_te_type { + ICMP_TE_TTL = 0, /* time to live exceeded in transit */ + ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ +}; + +void icmp_input(struct pbuf *p, struct netif *inp); + +void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); +void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); + +struct icmp_echo_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt16 id); + PACK_STRUCT_FIELD(uInt16 seqno); +} PACK_STRUCT_STRUCT; + + + +struct icmp_dur_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt32 unused); +} PACK_STRUCT_STRUCT; + +struct icmp_te_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt32 unused); +} PACK_STRUCT_STRUCT; + +#define ICMPH_TYPE(hdr) (NTOHS((hdr)->_type_code) >> 8) +#define ICMPH_CODE(hdr) (NTOHS((hdr)->_type_code) & 0xff) + +#define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = HTONS(ICMPH_CODE(hdr) | ((type) << 8))) +#define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = HTONS((code) | (ICMPH_TYPE(hdr) << 8))) + +#endif /* __LWIP_ICMP_H__ */ + diff --git a/include/net/ipv4/inet.h b/include/net/ipv4/inet.h new file mode 100644 index 0000000..7752f4e --- /dev/null +++ b/include/net/ipv4/inet.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_INET_H__ +#define __LWIP_INET_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" + +uInt16 inet_chksum(void *dataptr, uInt16 len); +uInt16 inet_chksum_pbuf(struct pbuf *p); +uInt16 inet_chksum_pseudo(struct pbuf *p, + struct ip_addr *src, struct ip_addr *dest, + uInt8 proto, uInt16 proto_len); + +#ifdef HTONS +#undef HTONS +#endif /* HTONS */ +#ifdef NTOHS +#undef NTOHS +#endif /* NTOHS */ +#ifdef HTONL +#undef HTONL +#endif /* HTONL */ +#ifdef NTOHL +#undef NTOHL +#endif /* NTOHL */ + +#ifndef HTONS +# if BYTE_ORDER == BIG_ENDIAN +# define HTONS(n) (n) +# define htons(n) HTONS(n) +# else /* BYTE_ORDER == BIG_ENDIAN */ +# define HTONS(n) (((((uInt16)(n) & 0xff)) << 8) | (((uInt16)(n) & 0xff00) >> 8)) +# endif /* BYTE_ORDER == BIG_ENDIAN */ +#endif /* HTONS */ + +#ifdef NTOHS +#undef NTOHS +#endif /* NTOHS */ + +#ifdef ntohs +#undef ntohs +#endif /* ntohs */ + +#define NTOHS HTONS +#define ntohs htons + + +#ifndef HTONL +# if BYTE_ORDER == BIG_ENDIAN +# define HTONL(n) (n) +# define htonl(n) HTONL(n) +# else /* BYTE_ORDER == BIG_ENDIAN */ +# define HTONL(n) (((((uInt32)(n) & 0xff)) << 24) | \ + ((((uInt32)(n) & 0xff00)) << 8) | \ + ((((uInt32)(n) & 0xff0000)) >> 8) | \ + ((((uInt32)(n) & 0xff000000)) >> 24)) +# endif /* BYTE_ORDER == BIG_ENDIAN */ +#endif /* HTONL */ + +#ifdef ntohl +#undef ntohl +#endif /* ntohl */ + +#ifdef NTOHL +#undef NTOHL +#endif /* NTOHL */ + +#define NTOHL HTONL +#define ntohl htonl + +#ifndef _MACHINE_ENDIAN_H_ +#ifndef _NETINET_IN_H +#ifndef _LINUX_BYTEORDER_GENERIC_H + +#if BYTE_ORDER == LITTLE_ENDIAN +uInt16 htons(uInt16 n); +uInt32 htonl(uInt32 n); +#else +#endif /* BYTE_ORDER == LITTLE_ENDIAN */ + +#endif /* _LINUX_BYTEORDER_GENERIC_H */ +#endif /* _NETINET_IN_H */ +#endif /* _MACHINE_ENDIAN_H_ */ + +#endif /* __LWIP_INET_H__ */ + diff --git a/include/net/ipv4/ip.h b/include/net/ipv4/ip.h new file mode 100644 index 0000000..fcef881 --- /dev/null +++ b/include/net/ipv4/ip.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_H__ +#define __LWIP_IP_H__ + +#include "net/arch.h" + +#include "net/def.h" +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" +#include "net/netif.h" + +#include "net/err.h" + +void ip_init(void); +uInt8 ip_lookup(void *header, struct netif *inp); +struct netif *ip_route(struct ip_addr *dest); +err_t ip_input(struct pbuf *p, struct netif *inp); +err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + uInt8 ttl, uInt8 proto); +err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + uInt8 ttl, uInt8 proto, + struct netif *netif); + +#define IP_HLEN 20 + +#define IP_PROTO_ICMP 1 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 170 +#define IP_PROTO_TCP 6 + +/* This is passed as the destination address to ip_output_if (not + to ip_output), meaning that an IP header already is constructed + in the pbuf. This is used when TCP retransmits. */ +#ifdef IP_HDRINCL +#undef IP_HDRINCL +#endif /* IP_HDRINCL */ +#define IP_HDRINCL NULL + +struct ip_hdr { + /* version / header length / type of service */ + PACK_STRUCT_FIELD(uInt16 _v_hl_tos); + /* total length */ + PACK_STRUCT_FIELD(uInt16 _len); + /* identification */ + PACK_STRUCT_FIELD(uInt16 _id); + /* fragment offset field */ + PACK_STRUCT_FIELD(uInt16 _offset); +#define IP_RF 0x8000 /* reserved fragment flag */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + /* time to live / protocol*/ + PACK_STRUCT_FIELD(uInt16 _ttl_proto); + /* checksum */ + PACK_STRUCT_FIELD(uInt16 _chksum); + /* source and destination IP addresses */ + PACK_STRUCT_FIELD(struct ip_addr src); + PACK_STRUCT_FIELD(struct ip_addr dest); +} PACK_STRUCT_STRUCT; + +#define IPH_V(hdr) (NTOHS((hdr)->_v_hl_tos) >> 12) +#define IPH_HL(hdr) ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f) +#define IPH_TOS(hdr) HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff)) +#define IPH_LEN(hdr) ((hdr)->_len) +#define IPH_ID(hdr) ((hdr)->_id) +#define IPH_OFFSET(hdr) ((hdr)->_offset) +#define IPH_TTL(hdr) (NTOHS((hdr)->_ttl_proto) >> 8) +#define IPH_PROTO(hdr) (NTOHS((hdr)->_ttl_proto) & 0xff) +#define IPH_CHKSUM(hdr) ((hdr)->_chksum) + +#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos)) +#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) +#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) +#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) +#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8)) +#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8)) +#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) + + + +#if IP_DEBUG +void ip_debug_print(struct pbuf *p); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_H__ */ + + diff --git a/include/net/ipv4/ip_addr.h b/include/net/ipv4/ip_addr.h new file mode 100644 index 0000000..2fb5168 --- /dev/null +++ b/include/net/ipv4/ip_addr.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_ADDR_H__ +#define __LWIP_IP_ADDR_H__ + +#include "net/arch.h" + +#define IP_ADDR_ANY 0 + +#define IP_ADDR_BROADCAST (&ip_addr_broadcast) + +PACK_STRUCT_BEGIN +struct ip_addr { + PACK_STRUCT_FIELD(uInt32 addr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END + +extern struct ip_addr ip_addr_broadcast; + +#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = htonl(((uInt32)(a & 0xff) << 24) | ((uInt32)(b & 0xff) << 16) | \ + ((uInt32)(c & 0xff) << 8) | (uInt32)(d & 0xff)) + +#define ip_addr_set(dest, src) (dest)->addr = \ + ((src) == IP_ADDR_ANY? IP_ADDR_ANY:\ + ((struct ip_addr *)src)->addr) +#define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \ + (mask)->addr) == \ + ((addr2)->addr & \ + (mask)->addr)) +#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr) + +#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0) + +#define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \ + (0xffffffff & ~((mask)->addr))) || \ + ((addr1)->addr == 0xffffffff) || \ + ((addr1)->addr == 0x00000000)) + + +#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000)) + + +#define ip_addr_debug_print(ipaddr) kprintf("%d.%d.%d.%d", \ + (uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff, \ + (uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff, \ + (uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff, \ + (uInt8)ntohl((ipaddr)->addr) & 0xff) + + +#define ip4_addr1(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff) +#define ip4_addr2(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff) +#define ip4_addr3(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff) +#define ip4_addr4(ipaddr) ((uInt8)(ntohl((ipaddr)->addr)) & 0xff) +#endif /* __LWIP_IP_ADDR_H__ */ + + + + + + diff --git a/include/net/ipv6/icmp.h b/include/net/ipv6/icmp.h new file mode 100644 index 0000000..ac428e9 --- /dev/null +++ b/include/net/ipv6/icmp.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ICMP_H__ +#define __LWIP_ICMP_H__ + +#include "lwip/arch.h" + +#include "lwip/opt.h" +#include "lwip/pbuf.h" + +#include "lwip/netif.h" + +#define ICMP6_DUR 1 +#define ICMP6_TE 3 +#define ICMP6_ECHO 128 /* echo */ +#define ICMP6_ER 129 /* echo reply */ + + +enum icmp_dur_type { + ICMP_DUR_NET = 0, /* net unreachable */ + ICMP_DUR_HOST = 1, /* host unreachable */ + ICMP_DUR_PROTO = 2, /* protocol unreachable */ + ICMP_DUR_PORT = 3, /* port unreachable */ + ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ + ICMP_DUR_SR = 5 /* source route failed */ +}; + +enum icmp_te_type { + ICMP_TE_TTL = 0, /* time to live exceeded in transit */ + ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ +}; + +void icmp_input(struct pbuf *p, struct netif *inp); + +void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); +void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); + +struct icmp_echo_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u16_t id; + u16_t seqno; +}; + +struct icmp_dur_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u32_t unused; +}; + +struct icmp_te_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u32_t unused; +}; + +#endif /* __LWIP_ICMP_H__ */ + diff --git a/include/net/ipv6/inet.h b/include/net/ipv6/inet.h new file mode 100644 index 0000000..8f1f203 --- /dev/null +++ b/include/net/ipv6/inet.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_INET_H__ +#define __LWIP_INET_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/ipv6/ip_addr.h" + +u16_t inet_chksum(void *data, u16_t len); +u16_t inet_chksum_pbuf(struct pbuf *p); +u16_t inet_chksum_pseudo(struct pbuf *p, + struct ip_addr *src, struct ip_addr *dest, + u8_t proto, u32_t proto_len); + + +#ifndef _MACHINE_ENDIAN_H_ +#ifndef _NETINET_IN_H +#ifndef _LINUX_BYTEORDER_GENERIC_H +u16_t htons(u16_t n); +u16_t ntohs(u16_t n); +u32_t htonl(u32_t n); +u32_t ntohl(u32_t n); +#endif /* _LINUX_BYTEORDER_GENERIC_H */ +#endif /* _NETINET_IN_H */ +#endif /* _MACHINE_ENDIAN_H_ */ + +#endif /* __LWIP_INET_H__ */ + diff --git a/include/net/ipv6/ip.h b/include/net/ipv6/ip.h new file mode 100644 index 0000000..82ca272 --- /dev/null +++ b/include/net/ipv6/ip.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_H__ +#define __LWIP_IP_H__ + +#include "lwip/debug.h" +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" + +#include "lwip/err.h" + +#define IP_HLEN 40 + +#define IP_PROTO_ICMP 58 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 170 +#define IP_PROTO_TCP 6 + +/* This is passed as the destination address to ip_output_if (not + to ip_output), meaning that an IP header already is constructed + in the pbuf. This is used when TCP retransmits. */ +#ifdef IP_HDRINCL +#undef IP_HDRINCL +#endif /* IP_HDRINCL */ +#define IP_HDRINCL NULL + + +/* The IPv6 header. */ +struct ip_hdr { +#if BYTE_ORDER == LITTLE_ENDIAN + u8_t tclass1:4, v:4; + u8_t flow1:4, tclass2:4; +#else + u8_t v:4, tclass1:4; + u8_t tclass2:8, flow1:4; +#endif + u16_t flow2; + u16_t len; /* payload length */ + u8_t nexthdr; /* next header */ + u8_t hoplim; /* hop limit (TTL) */ + struct ip_addr src, dest; /* source and destination IP addresses */ +}; + +void ip_init(void); + +#include "lwip/netif.h" + +struct netif *ip_route(struct ip_addr *dest); + +void ip_input(struct pbuf *p, struct netif *inp); + +/* source and destination addresses in network byte order, please */ +err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + unsigned char ttl, unsigned char proto); + +err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + unsigned char ttl, unsigned char proto, + struct netif *netif); + +#if IP_DEBUG +void ip_debug_print(struct pbuf *p); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_H__ */ + + diff --git a/include/net/ipv6/ip_addr.h b/include/net/ipv6/ip_addr.h new file mode 100644 index 0000000..a082805 --- /dev/null +++ b/include/net/ipv6/ip_addr.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_ADDR_H__ +#define __LWIP_IP_ADDR_H__ + +#include "net/arch.h" + +#define IP_ADDR_ANY 0 + +struct ip_addr { + u32_t addr[4]; +}; + +#define IP6_ADDR(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = htonl((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \ + (ipaddr)->addr[1] = htonl(((c & 0xffff) << 16) | (d & 0xffff)); \ + (ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \ + (ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0) + +int ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2, + struct ip_addr *mask); +int ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2); +void ip_addr_set(struct ip_addr *dest, struct ip_addr *src); +int ip_addr_isany(struct ip_addr *addr); + + +#if IP_DEBUG +void ip_addr_debug_print(struct ip_addr *addr); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_ADDR_H__ */ diff --git a/include/net/list.h b/include/net/list.h new file mode 100644 index 0000000..f2afc5f --- /dev/null +++ b/include/net/list.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_LIST_H__ +#define __LWIP_LIST_H__ + +struct list; + +struct list *list_new(int size); +int list_push(struct list *list, void *elem); +void *list_pop(struct list *list); +int list_remove(struct list *list, void *elem); +void *list_first(struct list *list); +int list_elems(struct list *list); +void list_delete(struct list *list); + +void list_map(struct list *list, void (* func)(void *arg)); + +#endif /* __LWIP_LIST_H__ */ diff --git a/include/net/lwipopts.h b/include/net/lwipopts.h new file mode 100644 index 0000000..1499b27 --- /dev/null +++ b/include/net/lwipopts.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +/* ---------- Memory options ---------- */ +/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which + lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 + byte alignment -> define MEM_ALIGNMENT to 2. */ +#define MEM_ALIGNMENT 2 + +/* MEM_SIZE: the size of the heap memory. If the application will send +a lot of data that needs to be copied, this should be set high. */ +#define MEM_SIZE 1000 + +/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application + sends a lot of data out of ROM (or other static memory), this + should be set high. */ +#define MEMP_NUM_PBUF 8 +/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + per active UDP "connection". */ +#define MEMP_NUM_UDP_PCB 4 +/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP + connections. */ +#define MEMP_NUM_TCP_PCB 5 +/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP + connections. */ +#define MEMP_NUM_TCP_PCB_LISTEN 8 +/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP + segments. */ +#define MEMP_NUM_TCP_SEG 8 +/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active + timeouts. */ +#define MEMP_NUM_SYS_TIMEOUT 3 + + +/* The following four are used only with the sequential API and can be + set to 0 if the application only will use the raw API. */ +/* MEMP_NUM_NETBUF: the number of struct netbufs. */ +#define MEMP_NUM_NETBUF 2 +/* MEMP_NUM_NETCONN: the number of struct netconns. */ +#define MEMP_NUM_NETCONN 4 +/* MEMP_NUM_APIMSG: the number of struct api_msg, used for + communication between the TCP/IP stack and the sequential + programs. */ +#define MEMP_NUM_API_MSG 8 +/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used + for sequential API communication and incoming packets. Used in + src/api/tcpip.c. */ +#define MEMP_NUM_TCPIP_MSG 8 + +/* These two control is reclaimer functions should be compiled + in. Should always be turned on (1). */ +#define MEM_RECLAIM 1 +#define MEMP_RECLAIM 1 + +/* ---------- Pbuf options ---------- */ +/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ +#define PBUF_POOL_SIZE 6 + +/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ +#define PBUF_POOL_BUFSIZE 128 + +/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a + link level header. */ +#define PBUF_LINK_HLEN 16 + +/* ---------- TCP options ---------- */ +#define LWIP_TCP 1 +#define TCP_TTL 255 + +/* Controls if TCP should queue segments that arrive out of + order. Define to 0 if your device is low on memory. */ +#define TCP_QUEUE_OOSEQ 1 + +/* TCP Maximum segment size. */ +#define TCP_MSS 128 + +/* TCP sender buffer space (bytes). */ +#define TCP_SND_BUF 256 + +/* TCP sender buffer space (pbufs). This must be at least = 2 * + TCP_SND_BUF/TCP_MSS for things to work. */ +#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS + +/* TCP receive window. */ +#define TCP_WND 1024 + +/* Maximum number of retransmissions of data segments. */ +#define TCP_MAXRTX 12 + +/* Maximum number of retransmissions of SYN segments. */ +#define TCP_SYNMAXRTX 4 + +/* ---------- ARP options ---------- */ +#define ARP_TABLE_SIZE 10 + +/* ---------- IP options ---------- */ +/* Define IP_FORWARD to 1 if you wish to have the ability to forward + IP packets across network interfaces. If you are going to run lwIP + on a device with only one network interface, define this to 0. */ +#define IP_FORWARD 1 + +/* If defined to 1, IP options are allowed (but not parsed). If + defined to 0, all packets with IP options are dropped. */ +#define IP_OPTIONS 1 + +/* ---------- ICMP options ---------- */ +#define ICMP_TTL 255 + + +/* ---------- DHCP options ---------- */ +/* Define LWIP_DHCP to 1 if you want DHCP configuration of + interfaces. DHCP is not implemented in lwIP 0.5.1, however, so + turning this on does currently not work. */ +#define LWIP_DHCP 0 + +/* 1 if you want to do an ARP check on the offered address + (recommended). */ +#define DHCP_DOES_ARP_CHECK 1 + +/* ---------- UDP options ---------- */ +#define LWIP_UDP 1 +#define UDP_TTL 255 + + +/* ---------- Statistics options ---------- */ +#define STATS + +#ifdef STATS +#define LINK_STATS +#define IP_STATS +#define ICMP_STATS +#define UDP_STATS +#define TCP_STATS +#define MEM_STATS +#define MEMP_STATS +#define PBUF_STATS +#define SYS_STATS +#endif /* STATS */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/include/net/mem.h b/include/net/mem.h new file mode 100644 index 0000000..342c208 --- /dev/null +++ b/include/net/mem.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_MEM_H__ +#define __LWIP_MEM_H__ + +#include + +#include "net/debug.h" +#include "net/opt.h" +#include "net/arch.h" + +#if MEM_SIZE > 64000l +typedef uInt32 mem_size_t; +#else +typedef uInt16 mem_size_t; +#endif /* MEM_SIZE > 64000 */ + + +void mem_init(void); + +void *mem_malloc(mem_size_t size); +void *mem_malloc2(mem_size_t size); +void mem_free(void *mem); +void *mem_realloc(void *mem, mem_size_t size); +void *mem_reallocm(void *mem, mem_size_t size); + +#ifdef MEM_PERF +void mem_perf_start(void); +void mem_perf_init(char *fname); +#endif /* MEM_PERF */ + +#ifdef MEM_RECLAIM +typedef mem_size_t (*mem_reclaim_func)(void *arg, mem_size_t size); +void mem_register_reclaim(mem_reclaim_func f, void *arg); +void mem_reclaim(unsigned int size); +#else +#define mem_register_reclaim(f, arg) +#endif /* MEM_RECLAIM */ + + +#define MEM_ALIGN_SIZE(size) (size + \ + ((((size) % (MEM_ALIGNMENT)) == 0)? 0 : \ + ((MEM_ALIGNMENT) - ((size) % (MEM_ALIGNMENT))))) + +#define MEM_ALIGN(addr) (void *)MEM_ALIGN_SIZE((uInt32)addr) + +#endif /* __LWIP_MEM_H__ */ + diff --git a/include/net/memp.h b/include/net/memp.h new file mode 100644 index 0000000..3e0b849 --- /dev/null +++ b/include/net/memp.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#ifndef __LWIP_MEMP_H__ +#define __LWIP_MEMP_H__ + +#include + +#include "net/debug.h" +#include "net/arch/cc.h" +#include "net/lwipopts.h" + +typedef enum { + MEMP_PBUF, + MEMP_UDP_PCB, + MEMP_TCP_PCB, + MEMP_TCP_PCB_LISTEN, + MEMP_TCP_SEG, + + MEMP_NETBUF, + MEMP_NETCONN, + MEMP_API_MSG, + MEMP_TCPIP_MSG, + + MEMP_SYS_TIMEOUT, + + MEMP_MAX +} memp_t; + +void memp_init(void); + +void *memp_malloc(memp_t type); +void *memp_mallocp(memp_t type); +void *memp_malloc2(memp_t type); +void *memp_realloc(memp_t fromtype, memp_t totype, void *mem); +void memp_free(memp_t type, void *mem); +void memp_freep(memp_t type, void *mem); + +#if MEMP_RECLAIM +typedef uInt8 (*memp_reclaim_func)(void *arg, memp_t type); +void memp_register_reclaim(memp_t type, memp_reclaim_func f, void *arg); +#else +#define memp_register_reclaim(t, f, arg) +#endif /* MEMP_RECLAIM */ + +#endif /* __LWIP_MEMP_H__ */ + diff --git a/include/net/net.h b/include/net/net.h new file mode 100644 index 0000000..b1fa875 --- /dev/null +++ b/include/net/net.h @@ -0,0 +1,36 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#ifndef _NET_H +#define _NET_H + +#include + +int net_init(); + +#endif + +/*** + END + ***/ + diff --git a/include/net/netif.h b/include/net/netif.h new file mode 100644 index 0000000..545ec7e --- /dev/null +++ b/include/net/netif.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_NETIF_H__ +#define __LWIP_NETIF_H__ + +#include "net/opt.h" + +#include "net/err.h" + +#include "net/ipv4/ip_addr.h" +#include "net/ipv4/inet.h" + +#include "net/pbuf.h" + + +struct netif { + struct netif *next; + uInt8 num; + struct ip_addr ip_addr; + struct ip_addr netmask; /* netmask in network byte order */ + struct ip_addr gw; + char hwaddr[6]; + + /* This function is called by the network device driver + when it wants to pass a packet to the TCP/IP stack. */ + err_t (* input)(struct pbuf *p, struct netif *inp); + + /* The following two fields should be filled in by the + initialization function for the device driver. */ + + char name[2]; + /* This function is called by the IP module when it wants + to send a packet on the interface. */ + err_t (* output)(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); + err_t (* linkoutput)(struct netif *netif, struct pbuf *p); + + /* This field can be set bu the device driver and could point + to state information for the device. */ + void *state; +}; + +/* The list of network interfaces. */ +extern struct netif *netif_list; +extern struct netif *netif_default; + + +/* netif_init() must be called first. */ +void netif_init(); + +struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, + struct ip_addr *gw, + void (* init)(struct netif *netif), + err_t (* input)(struct pbuf *p, struct netif *netif)); + +/* Returns a network interface given its name. The name is of the form + "et0", where the first two letters are the "name" field in the + netif structure, and the digit is in the num field in the same + structure. */ +struct netif *netif_find(char *name); + +void netif_set_default(struct netif *netif); + +void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr); +void netif_set_netmask(struct netif *netif, struct ip_addr *netmast); +void netif_set_gw(struct netif *netif, struct ip_addr *gw); + +#endif /* __LWIP_NETIF_H__ */ diff --git a/include/net/opt.h b/include/net/opt.h new file mode 100644 index 0000000..71d42c3 --- /dev/null +++ b/include/net/opt.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_OPT_H__ +#define __LWIP_OPT_H__ + +#include "net/lwipopts.h" + +/* Define some handy default values for configuration parameters. */ + +#ifndef ICMP_TTL +#define ICMP_TTL 255 +#endif + +#ifndef UDP_TTL +#define UDP_TTL 255 +#endif + +#ifndef TCP_TTL +#define TCP_TTL 255 +#endif + +#ifndef TCP_MSS +#define TCP_MSS 128 /* A *very* conservative default. */ +#endif + +#ifndef TCP_WND +#define TCP_WND 2048 +#endif + +#ifndef TCP_MAXRTX +#define TCP_MAXRTX 12 +#endif + +#ifndef TCP_SYNMAXRTX +#define TCP_SYNMAXRTX 6 +#endif + +#ifndef MEM_ALIGNMENT +#define MEM_ALIGNMENT 1 +#endif + +#ifndef PBUF_POOL_SIZE +#define PBUF_POOL_SIZE 16 +#endif + +#ifndef PBUF_POOL_BUFSIZE +#define PBUF_POOL_BUFSIZE 128 +#endif + +#ifndef PBUF_LINK_HLEN +#define PBUF_LINK_HLEN 0 +#endif + +#ifndef LWIP_UDP +#define LWIP_UDP 1 +#endif + +#ifndef LWIP_TCP +#define LWIP_TCP 1 +#endif + +#endif /* __LWIP_OPT_H__ */ + + + diff --git a/include/net/pbuf.h b/include/net/pbuf.h new file mode 100644 index 0000000..293ac35 --- /dev/null +++ b/include/net/pbuf.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +/*-----------------------------------------------------------------------------------*/ +#ifndef __LWIP_PBUF_H__ +#define __LWIP_PBUF_H__ + +#include "net/debug.h" +#include "net/arch.h" + + +#define PBUF_TRANSPORT_HLEN 20 +#define PBUF_IP_HLEN 20 + +typedef enum { + PBUF_TRANSPORT, + PBUF_IP, + PBUF_LINK, + PBUF_RAW +} pbuf_layer; + +typedef enum { + PBUF_RAM, + PBUF_ROM, + PBUF_POOL +} pbuf_flag; + +/* Definitions for the pbuf flag field (these are not the flags that + are passed to pbuf_alloc()). */ +#define PBUF_FLAG_RAM 0x00 /* Flags that pbuf data is stored in RAM. */ +#define PBUF_FLAG_ROM 0x01 /* Flags that pbuf data is stored in ROM. */ +#define PBUF_FLAG_POOL 0x02 /* Flags that the pbuf comes from the + pbuf pool. */ + +struct pbuf { + struct pbuf *next; + + /* high 4 bits, flags, low 4 bits reference count */ + uInt8 flags, ref; + void *payload; + + /* Total length of buffer + additionally chained buffers. */ + uInt16 tot_len; + /* Length of this buffer. */ + uInt16 len; + +}; + +/* pbuf_init(): + + Initializes the pbuf module. The num parameter determines how many + pbufs that should be allocated to the pbuf pool, and the size + parameter specifies the size of the data allocated to those. */ +void pbuf_init(void); + +/* pbuf_alloc(): + + Allocates a pbuf at protocol layer l. The actual memory allocated + for the pbuf is determined by the layer at which the pbuf is + allocated and the requested size (from the size parameter). The + flag parameter decides how and where the pbuf should be allocated + as follows: + + * PBUF_RAM: buffer memory for pbuf is allocated as one large + chunk. This includesprotocol headers as well. + + * RBUF_ROM: no buffer memory is allocated for the pbuf, even for + protocol headers. Additional headers must be + prepended by allocating another pbuf and chain in to + the front of the ROM pbuf. + + * PBUF_ROOL: the pbuf is allocated as a pbuf chain, with pbufs from + the pbuf pool that is allocated during pbuf_init(). */ +struct pbuf *pbuf_alloc(pbuf_layer l, uInt16 size, pbuf_flag flag); + +/* pbuf_realloc(): + + Shrinks the pbuf to the size given by the size parameter. + */ +void pbuf_realloc(struct pbuf *p, uInt16 size); + +/* pbuf_header(): + + Tries to move the p->payload pointer header_size number of bytes + upward within the pbuf. The return value is non-zero if it + fails. If so, an additional pbuf should be allocated for the header + and it should be chained to the front. */ +uInt8 pbuf_header(struct pbuf *p, Int16 header_size); + +/* pbuf_ref(): + + Increments the reference count of the pbuf p. + */ +void pbuf_ref(struct pbuf *p); + +/* pbuf_free(): + + Decrements the reference count and deallocates the pbuf if the + reference count is zero. If the pbuf is a chain all pbufs in the + chain are deallocated. */ +uInt8 pbuf_free(struct pbuf *p); + +/* pbuf_clen(): + + Returns the length of the pbuf chain. */ +uInt8 pbuf_clen(struct pbuf *p); + +/* pbuf_chain(): + + Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len + field adjusted accordingly. Pbuf t should no be used any more after + a call to this function, since pbuf t is now a part of pbuf h. */ +void pbuf_chain(struct pbuf *h, struct pbuf *t); + +/* pbuf_dechain(): + + Picks off the first pbuf from the pbuf chain p. Returns the tail of + the pbuf chain or NULL if the pbuf p was not chained. */ +struct pbuf *pbuf_dechain(struct pbuf *p); + +#endif /* __LWIP_PBUF_H__ */ diff --git a/include/net/sockets.h b/include/net/sockets.h new file mode 100644 index 0000000..577a2eb --- /dev/null +++ b/include/net/sockets.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + + +#ifndef __LWIP_SOCKETS_H__ +#define __LWIP_SOCKETS_H__ + +#include + +struct in_addr { + uInt32 s_addr; +}; + + +struct sockaddr_in { + uInt8 sin_len; + uInt8 sin_family; + uInt16 sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +struct sockaddr { + uInt8 sa_len; + uInt8 sa_family; + char sa_data[14]; +}; + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 + +#define AF_INET 2 +#define PF_INET AF_INET + +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 + +#define INADDR_ANY 0 +#define INADDR_BROADCAST 0xffffffff + +int lwip_accept(int s, struct sockaddr *addr, int *addrlen); +int lwip_bind(int s, struct sockaddr *name, int namelen); +int lwip_close(int s); +int lwip_connect(int s, struct sockaddr *name, int namelen); +int lwip_listen(int s, int backlog); +int lwip_recv(int s, void *mem, int len, unsigned int flags); +int lwip_read(int s, void *mem, int len); +int lwip_recvfrom(int s, void *mem, int len, unsigned int flags, + struct sockaddr *from, int *fromlen); +int lwip_send(int s, void *dataptr, int size, unsigned int flags); +int lwip_sendto(int s, void *dataptr, int size, unsigned int flags, + struct sockaddr *to, int tolen); +int lwip_socket(int domain, int type, int protocol); +int lwip_write(int s, void *dataptr, int size); + +#ifdef LWIP_COMPAT_SOCKETS +#define accept(a,b,c) lwip_accept(a,b,c) +#define bind(a,b,c) lwip_bind(a,b,c) +#define close(s) lwip_close(s) +#define connect(a,b,c) lwip_connect(a,b,c) +#define listen(a,b) lwip_listen(a,b) +#define recv(a,b,c,d) lwip_recv(a,b,c,d) +#define read(a,b,c) lwip_read(a,b,c) +#define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f) +#define send(a,b,c,d) lwip_send(a,b,c,d) +#define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f) +#define socket(a,b,c) lwip_socket(a,b,c) +#define write(a,b,c) lwip_write(a,b,c) +#endif /* LWIP_NO_COMPAT_SOCKETS */ + +#endif /* __LWIP_SOCKETS_H__ */ + diff --git a/include/net/stats.h b/include/net/stats.h new file mode 100644 index 0000000..bea1a61 --- /dev/null +++ b/include/net/stats.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_STATS_H__ +#define __LWIP_STATS_H__ + +#include "net/opt.h" +#include "net/arch/cc.h" + +#include "net/memp.h" + +#ifdef STATS + +struct stats_proto { + uInt16 xmit; /* Transmitted packets. */ + uInt16 rexmit; /* Retransmitted packets. */ + uInt16 recv; /* Received packets. */ + uInt16 fw; /* Forwarded packets. */ + uInt16 drop; /* Dropped packets. */ + uInt16 chkerr; /* Checksum error. */ + uInt16 lenerr; /* Invalid length error. */ + uInt16 memerr; /* Out of memory error. */ + uInt16 rterr; /* Routing error. */ + uInt16 proterr; /* Protocol error. */ + uInt16 opterr; /* Error in options. */ + uInt16 err; /* Misc error. */ + uInt16 cachehit; +}; + +struct stats_mem { + uInt16 avail; + uInt16 used; + uInt16 max; + uInt16 err; + uInt16 reclaimed; +}; + +struct stats_pbuf { + uInt16 avail; + uInt16 used; + uInt16 max; + uInt16 err; + uInt16 reclaimed; + + uInt16 alloc_locked; + uInt16 refresh_locked; +}; + +struct stats_syselem { + uInt16 used; + uInt16 max; + uInt16 err; +}; + +struct stats_sys { + struct stats_syselem sem; + struct stats_syselem mbox; +}; + +struct stats_ { + struct stats_proto link; + struct stats_proto ip; + struct stats_proto icmp; + struct stats_proto udp; + struct stats_proto tcp; + struct stats_pbuf pbuf; + struct stats_mem mem; + struct stats_mem memp[MEMP_MAX]; + struct stats_sys sys; +}; + +extern struct stats_ stats; + +#endif /* STATS */ + +void stats_init(void); +#endif /* __LWIP_STATS_H__ */ + + + + diff --git a/include/net/sys.h b/include/net/sys.h new file mode 100644 index 0000000..f453ded --- /dev/null +++ b/include/net/sys.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_SYS_H__ +#define __LWIP_SYS_H__ + +#include "arch/cc.h" +#include "arch/sys_arch.h" + +typedef void (* sys_timeout_handler)(void *arg); + +struct sys_timeout { + struct sys_timeout *next; + uInt16 time; + sys_timeout_handler h; + void *arg; +}; + +struct sys_timeouts { + struct sys_timeout *next; +}; + +/* sys_init() must be called before anthing else. */ +void sys_init(void); + +/* + * sys_timeout(): + * + * Schedule a timeout a specified amount of milliseconds in the + * future. When the timeout occurs, the specified timeout handler will + * be called. The handler will be passed the "arg" argument when + * called. + * + */ +void sys_timeout(uInt16 msecs, sys_timeout_handler h, void *arg); +struct sys_timeouts *sys_arch_timeouts(void); + +/* Semaphore functions. */ +sys_sem_t sys_sem_new(uInt8 count); +void sys_sem_signal(sys_sem_t sem); +uInt16 sys_arch_sem_wait(sys_sem_t sem, uInt16 timeout); +void sys_sem_free(sys_sem_t sem); + +void sys_sem_wait(sys_sem_t sem); + +/* Mailbox functions. */ +sys_mbox_t sys_mbox_new(void); +void sys_mbox_post(sys_mbox_t mbox, void *msg); +uInt16 sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, uInt16 timeout); +void sys_mbox_free(sys_mbox_t mbox); + +void sys_mbox_fetch(sys_mbox_t mbox, void **msg); + +/* Thread functions. */ +//void sys_thread_new(void (* thread)(void *arg), void *arg); +void sys_thread_new(void (* function)(void), void *arg); + +/* The following functions are used only in Unix code, and + can be omitted when porting the stack. */ +/* Returns the current time in microseconds. */ +unsigned long sys_now(void); + +#endif /* __LWIP_SYS_H__ */ diff --git a/include/net/tcp.h b/include/net/tcp.h new file mode 100644 index 0000000..ee58616 --- /dev/null +++ b/include/net/tcp.h @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_TCP_H__ +#define __LWIP_TCP_H__ + +#include "net/sys.h" +#include "net/mem.h" + +#include "net/pbuf.h" +#include "net/opt.h" +//UBU +#include "net/ipv4/ip.h" +//UBU +#include "net/ipv4/icmp.h" + +#include "net/sys.h" + +#include "net/err.h" + +struct tcp_pcb; + +/* Functions for interfacing with TCP: */ + +/* Lower layer interface to TCP: */ +void tcp_init (void); /* Must be called first to + initialize TCP. */ +void tcp_tmr (void); /* Must be called every + TCP_TMR_INTERVAL + ms. (Typically 100 ms). */ +/* Application program's interface: */ +struct tcp_pcb * tcp_new (void); + +void tcp_arg (struct tcp_pcb *pcb, void *arg); +void tcp_accept (struct tcp_pcb *pcb, + err_t (* accept)(void *arg, struct tcp_pcb *newpcb, + err_t err)); +void tcp_recv (struct tcp_pcb *pcb, + err_t (* recv)(void *arg, struct tcp_pcb *tpcb, + struct pbuf *p, err_t err)); +void tcp_sent (struct tcp_pcb *pcb, + err_t (* sent)(void *arg, struct tcp_pcb *tpcb, + uInt16 len)); +void tcp_poll (struct tcp_pcb *pcb, + err_t (* poll)(void *arg, struct tcp_pcb *tpcb), + uInt8 interval); +void tcp_err (struct tcp_pcb *pcb, + void (* err)(void *arg, err_t err)); + +#define tcp_sndbuf(pcb) ((pcb)->snd_buf) + +void tcp_recved (struct tcp_pcb *pcb, uInt16 len); +err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port, err_t (* connected)(void *arg, + struct tcp_pcb *tpcb, + err_t err)); +struct tcp_pcb * tcp_listen (struct tcp_pcb *pcb); +void tcp_abort (struct tcp_pcb *pcb); +err_t tcp_close (struct tcp_pcb *pcb); +err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, uInt16 len, + uInt8 copy); + +/* It is also possible to call these two functions at the right + intervals (instead of calling tcp_tmr()). */ +void tcp_slowtmr (void); +void tcp_fasttmr (void); + + +/* Only used by IP to pass a TCP segment to TCP: */ +void tcp_input (struct pbuf *p, struct netif *inp); +/* Used within the TCP code only: */ +err_t tcp_output (struct tcp_pcb *pcb); + + + + +#define TCP_SEQ_LT(a,b) ((Int32)((a)-(b)) < 0) +#define TCP_SEQ_LEQ(a,b) ((Int32)((a)-(b)) <= 0) +#define TCP_SEQ_GT(a,b) ((Int32)((a)-(b)) > 0) +#define TCP_SEQ_GEQ(a,b) ((Int32)((a)-(b)) >= 0) + +#define TCP_FIN 0x01 +#define TCP_SYN 0x02 +#define TCP_RST 0x04 +#define TCP_PSH 0x08 +#define TCP_ACK 0x10 +#define TCP_URG 0x20 + +/* Length of the TCP header, excluding options. */ +#define TCP_HLEN 20 + +#define TCP_TMR_INTERVAL 100 /* The TCP timer interval in + milliseconds. */ + +#define TCP_FAST_INTERVAL 200 /* the fine grained timeout in + milliseconds */ +#define TCP_SLOW_INTERVAL 500 /* the coarse grained timeout in + milliseconds */ +#define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */ +#define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */ + +#define TCP_OOSEQ_TIMEOUT 6 /* x RTO */ + +#define TCP_MSL 60000 /* The maximum segment lifetime in microseconds */ + +struct tcp_hdr { + PACK_STRUCT_FIELD(uInt16 src); + PACK_STRUCT_FIELD(uInt16 dest); + PACK_STRUCT_FIELD(uInt32 seqno); + PACK_STRUCT_FIELD(uInt32 ackno); + PACK_STRUCT_FIELD(uInt16 _offset_flags); + PACK_STRUCT_FIELD(uInt16 wnd); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt16 urgp); +} PACK_STRUCT_STRUCT; + +#define TCPH_OFFSET(hdr) (NTOHS((hdr)->_offset_flags) >> 8) +#define TCPH_FLAGS(hdr) (NTOHS((hdr)->_offset_flags) & 0xff) + +#define TCPH_OFFSET_SET(hdr, offset) (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr)) +#define TCPH_FLAGS_SET(hdr, flags) (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags)) + +#define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \ + TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0)) + +enum tcp_state { + CLOSED = 0, + LISTEN = 1, + SYN_SENT = 2, + SYN_RCVD = 3, + ESTABLISHED = 4, + FIN_WAIT_1 = 5, + FIN_WAIT_2 = 6, + CLOSE_WAIT = 7, + CLOSING = 8, + LAST_ACK = 9, + TIME_WAIT = 10 +}; + + +/* the TCP protocol control block */ +struct tcp_pcb { + struct tcp_pcb *next; /* for the linked list */ + + enum tcp_state state; /* TCP state */ + + void *callback_arg; + + /* Function to call when a listener has been connected. */ + err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err); + + struct ip_addr local_ip; + uInt16 local_port; + + struct ip_addr remote_ip; + uInt16 remote_port; + + /* receiver varables */ + uInt32 rcv_nxt; /* next seqno expected */ + uInt16 rcv_wnd; /* receiver window */ + + /* Timers */ + uInt16 tmr; + + /* Retransmission timer. */ + uInt8 rtime; + + uInt16 mss; /* maximum segment size */ + + uInt8 flags; +#define TF_ACK_DELAY 0x01 /* Delayed ACK. */ +#define TF_ACK_NOW 0x02 /* Immediate ACK. */ +#define TF_INFR 0x04 /* In fast recovery. */ +#define TF_RESET 0x08 /* Connection was reset. */ +#define TF_CLOSED 0x10 /* Connection was sucessfully closed. */ +#define TF_GOT_FIN 0x20 /* Connection was closed by the remote end. */ + + /* RTT estimation variables. */ + uInt16 rttest; /* RTT estimate in 500ms ticks */ + uInt32 rtseq; /* sequence number being timed */ + Int32 sa, sv; + + uInt16 rto; /* retransmission time-out */ + uInt8 nrtx; /* number of retransmissions */ + + /* fast retransmit/recovery */ + uInt32 lastack; /* Highest acknowledged seqno. */ + uInt8 dupacks; + + /* congestion avoidance/control variables */ + uInt16 cwnd; + uInt16 ssthresh; + + /* sender variables */ + uInt32 snd_nxt, /* next seqno to be sent */ + snd_max, /* Highest seqno sent. */ + snd_wnd, /* sender window */ + snd_wl1, snd_wl2, + snd_lbb; + + uInt16 snd_buf; /* Avaliable buffer space for sending. */ + uInt8 snd_queuelen; + + /* Function to be called when more send buffer space is avaliable. */ + err_t (* sent)(void *arg, struct tcp_pcb *pcb, uInt16 space); + uInt16 acked; + + /* Function to be called when (in-sequence) data has arrived. */ + err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); + struct pbuf *recv_data; + + /* Function to be called when a connection has been set up. */ + err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err); + + /* Function which is called periodically. */ + err_t (* poll)(void *arg, struct tcp_pcb *pcb); + + /* Function to be called whenever a fatal error occurs. */ + void (* errf)(void *arg, err_t err); + + uInt8 polltmr, pollinterval; + + /* These are ordered by sequence number: */ + struct tcp_seg *unsent; /* Unsent (queued) segments. */ + struct tcp_seg *unacked; /* Sent but unacknowledged segments. */ +#if TCP_QUEUE_OOSEQ + struct tcp_seg *ooseq; /* Received out of sequence segments. */ +#endif /* TCP_QUEUE_OOSEQ */ + +}; + +struct tcp_pcb_listen { + struct tcp_pcb_listen *next; /* for the linked list */ + + enum tcp_state state; /* TCP state */ + + void *callback_arg; + + /* Function to call when a listener has been connected. */ + void (* accept)(void *arg, struct tcp_pcb *newpcb); + + struct ip_addr local_ip; + uInt16 local_port; +}; + +/* This structure is used to repressent TCP segments. */ +struct tcp_seg { + struct tcp_seg *next; /* used when putting segements on a queue */ + struct pbuf *p; /* buffer containing data + TCP header */ + void *dataptr; /* pointer to the TCP data in the pbuf */ + uInt16 len; /* the TCP length of this segment */ + struct tcp_hdr *tcphdr; /* the TCP header */ +}; + +/* Internal functions and global variables: */ +struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb); +void tcp_pcb_purge(struct tcp_pcb *pcb); +void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb); + +uInt8 tcp_segs_free(struct tcp_seg *seg); +uInt8 tcp_seg_free(struct tcp_seg *seg); +struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg); + +#define tcp_ack(pcb) if((pcb)->flags & TF_ACK_DELAY) { \ + (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb); \ + } else { \ + (pcb)->flags |= TF_ACK_DELAY; \ + } + +#define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb) + +err_t tcp_send_ctrl(struct tcp_pcb *pcb, uInt8 flags); +err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, uInt16 len, + uInt8 flags, uInt8 copy, + uInt8 *optdata, uInt8 optlen); + +void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg); + +void tcp_rst(uInt32 seqno, uInt32 ackno, + struct ip_addr *local_ip, struct ip_addr *remote_ip, + uInt16 local_port, uInt16 remote_port); + +uInt32 tcp_next_iss(void); + +extern uInt32 tcp_ticks; + +#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG +void tcp_debug_print(struct tcp_hdr *tcphdr); +void tcp_debug_print_flags(uInt8 flags); +void tcp_debug_print_state(enum tcp_state s); +void tcp_debug_print_pcbs(void); +int tcp_pcbs_sane(void); +#else +#define tcp_pcbs_sane() 1 +#endif /* TCP_DEBUG */ + + +/* The TCP PCB lists. */ +extern struct tcp_pcb_listen *tcp_listen_pcbs; /* List of all TCP PCBs in LISTEN state. */ +extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a + state in which they accept or send + data. */ +extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ + +extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ + +/* Axoims about the above lists: + 1) Every TCP PCB that is not CLOSED is in one of the lists. + 2) A PCB is only in one of the lists. + 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. + 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. +*/ + +/* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB + with a PCB list or removes a PCB from a list, respectively. */ +#ifdef LWIP_DEBUG +#define TCP_REG(pcbs, npcb) do {\ + DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \ + for(tcp_tmp_pcb = *pcbs; \ + tcp_tmp_pcb != NULL; \ + tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \ + } \ + ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \ + npcb->next = *pcbs; \ + ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \ + *pcbs = npcb; \ + ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ + } while(0) +#define TCP_RMV(pcbs, npcb) do { \ + ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \ + DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \ + if(*pcbs == npcb) { \ + *pcbs = (*pcbs)->next; \ + } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ + tcp_tmp_pcb->next = npcb->next; \ + break; \ + } \ + } \ + npcb->next = NULL; \ + ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ + DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \ + } while(0) + +#else /* LWIP_DEBUG */ +#define TCP_REG(pcbs, npcb) do { \ + npcb->next = *pcbs; \ + *pcbs = npcb; \ + } while(0) +#define TCP_RMV(pcbs, npcb) do { \ + if(*pcbs == npcb) { \ + *pcbs = (*pcbs)->next; \ + } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ + tcp_tmp_pcb->next = npcb->next; \ + break; \ + } \ + } \ + npcb->next = NULL; \ + } while(0) +#endif /* LWIP_DEBUG */ +#endif /* __LWIP_TCP_H__ */ + + + diff --git a/include/net/tcpip.h b/include/net/tcpip.h new file mode 100644 index 0000000..1b74d57 --- /dev/null +++ b/include/net/tcpip.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_TCPIP_H__ +#define __LWIP_TCPIP_H__ + +#include "net/api_msg.h" +#include "net/pbuf.h" + +void tcpip_init(void (* tcpip_init_done)(void *), void *arg); +void tcpip_apimsg(struct api_msg *apimsg); +err_t tcpip_input(struct pbuf *p, struct netif *inp); + +enum tcpip_msg_type { + TCPIP_MSG_API, + TCPIP_MSG_INPUT +}; + +struct tcpip_msg { + enum tcpip_msg_type type; + sys_sem_t *sem; + union { + struct api_msg *apimsg; + struct { + struct pbuf *p; + struct netif *netif; + } inp; + } msg; +}; + + +#endif /* __LWIP_TCPIP_H__ */ diff --git a/include/net/udp.h b/include/net/udp.h new file mode 100644 index 0000000..c4c8693 --- /dev/null +++ b/include/net/udp.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_UDP_H__ +#define __LWIP_UDP_H__ + +#include "net/arch.h" + +#include "net/pbuf.h" +//UBU +#include "net/ipv4/inet.h" +//UBU +#include "net/ipv4/ip.h" + +#include "net/err.h" + +#define UDP_HLEN 8 + +struct udp_hdr { + PACK_STRUCT_FIELD(uInt16 src); + PACK_STRUCT_FIELD(uInt16 dest); /* src/dest UDP ports */ + PACK_STRUCT_FIELD(uInt16 len); + PACK_STRUCT_FIELD(uInt16 chksum); +} PACK_STRUCT_STRUCT; + +#define UDP_FLAGS_NOCHKSUM 0x01 +#define UDP_FLAGS_UDPLITE 0x02 + +struct udp_pcb { + struct udp_pcb *next; + + struct ip_addr local_ip, remote_ip; + uInt16 local_port, remote_port; + + uInt8 flags; + uInt16 chksum_len; + + void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *addr, uInt16 port); + void *recv_arg; +}; + +/* The following functions is the application layer interface to the + UDP code. */ +struct udp_pcb * udp_new (void); +void udp_remove (struct udp_pcb *pcb); +err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +void udp_recv (struct udp_pcb *pcb, + void (* recv)(void *arg, struct udp_pcb *upcb, + struct pbuf *p, + struct ip_addr *addr, + uInt16 port), + void *recv_arg); +err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); + +#define udp_flags(pcb) ((pcb)->flags) +#define udp_setflags(pcb, f) ((pcb)->flags = (f)) + + +/* The following functions is the lower layer interface to UDP. */ +uInt8 udp_lookup (struct ip_hdr *iphdr, struct netif *inp); +void udp_input (struct pbuf *p, struct netif *inp); +void udp_init (void); + + +#endif /* __LWIP_UDP_H__ */ + + diff --git a/include/netif/arp.h b/include/netif/arp.h new file mode 100644 index 0000000..d799678 --- /dev/null +++ b/include/netif/arp.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Swedish Institute + * of Computer Science and its contributors. + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + * + */ + +#ifndef __NETIF_ARP_H__ +#define __NETIF_ARP_H__ + +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" +#include "net/netif.h" + +struct eth_addr { + PACK_STRUCT_FIELD(uInt8 addr[6]); +} PACK_STRUCT_STRUCT; + +struct eth_hdr { + PACK_STRUCT_FIELD(struct eth_addr dest); + PACK_STRUCT_FIELD(struct eth_addr src); + PACK_STRUCT_FIELD(uInt16 type); +} PACK_STRUCT_STRUCT; + +#define ARP_TMR_INTERVAL 10000 + +#define ETHTYPE_ARP 0x0806 +#define ETHTYPE_IP 0x0800 + +/* Initializes ARP. */ +void arp_init(void); + +/* The arp_tmr() function should be called every ARP_TMR_INTERVAL + microseconds (10 seconds). This function is responsible for + expiring old entries in the ARP table. */ +void arp_tmr(void); + +/* Should be called for all incoming packets of IP kind. The function + does not alter the packet in any way, it just updates the ARP + table. After this function has been called, the normal TCP/IP stack + input function should be called. */ +void arp_ip_input(struct netif *netif, struct pbuf *p); + +/* Should be called for incoming ARP packets. The pbuf in the argument + is freed by this function. If the function returns a pbuf (i.e., + returns non-NULL), that pbuf constitutes an ARP reply and should be + sent out on the Ethernet. */ +struct pbuf *arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, + struct pbuf *p); + +/* arp_loopup() is called to do an IP address -> Ethernet address + translation. If the function returns NULL, there is no mapping and + the arp_query() function should be called. */ +struct eth_addr *arp_lookup(struct ip_addr *ipaddr); + +/* Constructs an ARP query packet for the given IP address. The + function returns a pbuf that contains the reply and that should be + sent out on the Ethernet. */ +struct pbuf *arp_query(struct netif *netif, struct eth_addr *ethaddr, + struct ip_addr *ipaddr); + +#endif /* __NETIF_ARP_H__ */ diff --git a/include/netif/ethernetif.h b/include/netif/ethernetif.h new file mode 100644 index 0000000..5ea4e5d --- /dev/null +++ b/include/netif/ethernetif.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_ETHERNETIF_H__ +#define __NETIF_ETHERNETIF_H__ + +#include "net/netif.h" + +void ethernetif_init(struct netif *netif); + +#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/include/netif/loopif.h b/include/netif/loopif.h new file mode 100644 index 0000000..fbbf744 --- /dev/null +++ b/include/netif/loopif.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_LOOPIF_H__ +#define __NETIF_LOOPIF_H__ + +#include "net/netif.h" + +void loopif_init(struct netif *netif); + +#endif /* __NETIF_LOOPIF_H__ */ diff --git a/include/netif/tcpdump.h b/include/netif/tcpdump.h new file mode 100644 index 0000000..d2d6afc --- /dev/null +++ b/include/netif/tcpdump.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_TCPDUMP_H__ +#define __NETIF_TCPDUMP_H__ + +#include "net/pbuf.h" + +void tcpdump_init(void); +void tcpdump(struct pbuf *p); + +#endif /* __NETIF_TCPDUMP_H__ */ diff --git a/include/objgfx/ogDisplay_VESA.h b/include/objgfx/ogDisplay_VESA.h new file mode 100644 index 0000000..8c05fc1 --- /dev/null +++ b/include/objgfx/ogDisplay_VESA.h @@ -0,0 +1,95 @@ +#ifndef OGDISPLAY_VESA_H +#define OGDISPLAY_VESA_H + +#include "objgfx30.h" + +struct TMode_Rec { + uInt16 ModeAttributes __attribute__((packed)); + uInt8 WindowAFlags __attribute__((packed)); + uInt8 WindowBFlags __attribute__((packed)); + uInt16 Granularity __attribute__((packed)); + uInt16 WindowSize __attribute__((packed)); + uInt16 WindowASeg __attribute__((packed)); + uInt16 WindowBSeg __attribute__((packed)); + void* BankSwitch __attribute__((packed)); + uInt16 BytesPerLine __attribute__((packed)); + uInt16 xRes __attribute__((packed)); + uInt16 yRes __attribute__((packed)); + uInt8 CharWidth __attribute__((packed)); + uInt8 CharHeight __attribute__((packed)); + uInt8 NumBitPlanes __attribute__((packed)); + uInt8 BitsPerPixel __attribute__((packed)); + uInt8 NumberOfBanks __attribute__((packed)); + uInt8 MemoryModel __attribute__((packed)); + uInt8 BankSize __attribute__((packed)); + uInt8 NumOfImagePages __attribute__((packed)); + uInt8 Reserved __attribute__((packed)); + // Direct colour fields (required for Direct/6 and YUV/7 memory models + uInt8 RedMaskSize __attribute__((packed)); + uInt8 RedFieldPosition __attribute__((packed)); + uInt8 GreenMaskSize __attribute__((packed)); + uInt8 GreenFieldPosition __attribute__((packed)); + uInt8 BlueMaskSize __attribute__((packed)); + uInt8 BlueFieldPosition __attribute__((packed)); + uInt8 AlphaMaskSize __attribute__((packed)); + uInt8 AlphaFieldPosition __attribute__((packed)); + uInt8 DirectColourMode __attribute__((packed)); + // VESA 2.0 specific fields + uInt32 physBasePtr __attribute__((packed)); + void* OffScreenMemOffset __attribute__((packed)); + uInt16 OffScreenMemSize __attribute__((packed)); + uInt8 paddington[461] __attribute__((packed)); +}; + +struct TVESA_Rec { + char VBESignature[4] __attribute__((packed)); + uInt8 minVersion __attribute__((packed)); + uInt8 majVersion __attribute__((packed)); + uInt32 OEMStringPtr __attribute__((packed)); + uInt32 Capabilities __attribute__((packed)); + uInt32 VideoModePtr __attribute__((packed)); + uInt16 TotalMemory __attribute__((packed)); + // VESA 2.0 specific fields + uInt16 OEMSoftwareRev __attribute__((packed)); + uInt32 OEMVendorNamePtr __attribute__((packed)); + uInt32 OEMProductNamePtr __attribute__((packed)); + uInt32 OEMProductRevPtr __attribute__((packed)); + uInt8 paddington[474] __attribute__((packed)); +}; + +class ogDisplay_VESA : public ogSurface { + protected: + uInt16 ScreenSelector; + TVESA_Rec* VESARec; + TMode_Rec* ModeRec; + bool InGraphics; + uInt16 findMode(uInt32, uInt32, uInt32); + void getModeInfo(uInt16); + void getVESAInfo(void); + void setMode(uInt16); + virtual uInt32 rawGetPixel(uInt32, uInt32); + virtual void rawSetPixel(uInt32, uInt32, uInt32); + virtual void rawLine(uInt32, uInt32, uInt32, uInt32, uInt32); + void setPal(void); + public: + ogDisplay_VESA(void); + virtual bool ogAvail(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual void ogClear(uInt32); + virtual bool ogClone(ogSurface&); + virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32); + virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32); + virtual void ogCopyPal(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + virtual uInt32 ogGetPixel(int32, int32); + virtual void * ogGetPtr(uInt32, uInt32); + virtual void ogHLine(int32, int32, int32, uInt32); + virtual bool ogLoadPal(const char *); + virtual void ogSetPixel(int32, int32, uInt32); + virtual void ogSetRGBPalette(uInt8, uInt8, uInt8, uInt8); + virtual void ogVFlip(void); + virtual void ogVLine(int32, int32, int32, uInt32); + virtual ~ogDisplay_VESA(void); +}; // ogDisplay_VESA + +#endif diff --git a/include/pci/hd.h b/include/pci/hd.h new file mode 100644 index 0000000..7d6e3a8 --- /dev/null +++ b/include/pci/hd.h @@ -0,0 +1,225 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _HD_H +#define _HD_H + +#include + +#define hdData 0x0 +#define hdError 0x1 +#define hdSecCount 0x2 +#define hdSecNum 0x3 +#define hdCylLow 0x4 +#define hdCylHi 0x5 +#define hdHead 0x6 +#define hdStat 0x7 +#define hdCmd 0x7 + + +struct driveInfo { + struct driveDiskLabel *diskLabel; + char hdSector[512]; + char hdEnable; + char hdDev; + char hdFlags; + char hdShift; + long hdMask; + long hdMulti; + long hdPort; + long hdSize; + long hdCalc; + long parOffset; + }; + +int initHardDisk(); +void hdWrite(struct driveInfo *hdd,void *,uInt32,uInt32); +void hdRead(struct driveInfo *hdd,void *,uInt32,uInt32); +int hdReset(); +int hdIoctl(); +int hdStart(); +int hdStop(); +int hdStandby(); +int hdInit(struct device_node *dev); + +struct dos_partition { + unsigned char dp_flag; /* bootstrap flags */ + unsigned char dp_shd; /* starting head */ + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_scyl; /* starting cylinder */ + unsigned char dp_type; /* partition type */ + unsigned char dp_ehd; /* end head */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ecyl; /* end cylinder */ + uInt32 dp_start; /* absolute starting sector number */ + uInt32 dp_size; /* partition size in sectors */ + }; + +#define MAXPARTITIONS 8 + +struct bsd_disklabel { + u_int32_t d_magic; /* the magic number */ + u_int16_t d_type; /* drive type */ + u_int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + + char d_packname[16]; /* pack identifier */ + + /* disk geometry: */ + u_int32_t d_secsize; /* # of bytes per sector */ + u_int32_t d_nsectors; /* # of data sectors per track */ + u_int32_t d_ntracks; /* # of tracks per cylinder */ + u_int32_t d_ncylinders; /* # of data cylinders per unit */ + u_int32_t d_secpercyl; /* # of data sectors per cylinder */ + u_int32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * d_nsectors or d_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + u_int16_t d_sparespertrack; /* # of spare sectors per track */ + u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ + /* + * Alternate cylinders include maintenance, replacement, configuration + * description areas, etc. + */ + u_int32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the + * formatter or controller when formatting. When interleaving is + * in use, logically adjacent sectors are not physically + * contiguous, but instead are separated by some number of + * sectors. It is specified as the ratio of physical sectors + * traversed per logical sector. Thus an interleave of 1:1 + * implies contiguous layout, while 2:1 implies that logical + * sector 0 is separated by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N relative to + * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew + * is the offset of sector 0 on cylinder N relative to sector 0 + * on cylinder N-1. + */ + u_int16_t d_rpm; /* rotational speed */ + u_int16_t d_interleave; /* hardware sector interleave */ + u_int16_t d_trackskew; /* sector 0 skew, per track */ + u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ + u_int32_t d_headswitch; /* head switch time, usec */ + u_int32_t d_trkseek; /* track-to-track seek, usec */ + u_int32_t d_flags; /* generic flags */ +#define NDDATA 5 + u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ +#define NSPARE 5 + u_int32_t d_spare[NSPARE]; /* reserved for future use */ + u_int32_t d_magic2; /* the magic number (again) */ + u_int16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + u_int16_t d_npartitions; /* number of partitions in following */ + u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ + u_int32_t d_sbsize; /* max size of fs superblock, bytes */ + struct partition { /* the partition table */ + u_int32_t p_size; /* number of sectors in partition */ + u_int32_t p_offset; /* starting sector */ + u_int32_t p_fsize; /* filesystem basic fragment size */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_frag; /* filesystem fragments per block */ + u_int16_t p_cpg; /* filesystem cylinders per group */ + } d_partitions[MAXPARTITIONS]; /* actually may be more */ +}; + +static const char *fstypenames[] = { + "unused", + "swap", + "Version 6", + "Version 7", + "System V", + "4.1BSD", + "Eighth Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "vinum", + "raid", + "?", + "?", + "?", + "?", + "jfs", + NULL +}; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.2 2006/10/09 02:58:05 reddawg + Fixing UFS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:50 reddawg + no message + + Revision 1.7 2004/08/15 00:33:02 reddawg + Wow the ide driver works again + + Revision 1.6 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.5 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/include/pci/lnc.h b/include/pci/lnc.h new file mode 100644 index 0000000..adba770 --- /dev/null +++ b/include/pci/lnc.h @@ -0,0 +1,206 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _LNC_H +#define _LNC_H + +#include + +#define NDESC(len2) (1 << len2) +#define NORMAL 0 +#define MEM_SLEW 8 +#define TRANSBUFSIZE 1518 +#define RECVBUFSIZE 1518 +#define NRDRE 3 +#define NTDRE 3 +#define ETHER_ADDR_LEN 6 +#define NE2100_IOSIZE 24 +#define PCNET_RDP 0x10 /* Register Data Port */ +#define PCNET_RAP 0x12 /* Register Address Port */ +#define PCNET_RESET 0x14 +#define PCNET_BDP 0x16 +#define PCNET_VSW 0x18 +#define NE2100 2 + +/* mem_mode values */ +#define DMA_FIXED 1 +#define DMA_MBUF 2 +#define SHMEM 4 + + +/********** Chip Types **********/ +#define UNKNOWN 0 /* Unknown */ +#define LANCE 1 /* Am7990 */ +#define C_LANCE 2 /* Am79C90 */ +#define PCnet_ISA 3 /* Am79C960 */ +#define PCnet_ISAplus 4 /* Am79C961 */ +#define PCnet_ISA_II 5 /* Am79C961A */ +#define PCnet_32 6 /* Am79C965 */ +#define PCnet_PCI 7 /* Am79C970 */ +#define PCnet_PCI_II 8 /* Am79C970A */ +#define PCnet_FAST 9 /* Am79C971 */ +#define PCnet_FASTplus 10 /* Am79C972 */ +#define PCnet_Home 11 /* Am79C978 */ + +/******** AM7990 Specifics **************/ +#define CSR0 0x0000 +#define CSR1 1 +#define CSR2 2 +#define CSR3 3 +#define CSR88 88 +#define CSR89 89 + +#define ERR 0x8000 +#define BABL 0x4000 +#define CERR 0x2000 +#define MISS 0x1000 +#define MERR 0x0800 +#define RINT 0x0400 +#define TINT 0x0200 +#define IDON 0x0100 +#define INTR 0x0080 +#define INEA 0x0040 +#define RXON 0x0020 +#define TXON 0x0010 +#define TDMD 0x0008 +#define STOP 0x0004 +#define STRT 0x0002 +#define INIT 0x0001 + + +/* CSR88-89: Chip ID masks */ +#define AMD_MASK 0x003 +#define PART_MASK 0xffff +#define Am79C960 0x0003 +#define Am79C961 0x2260 +#define Am79C961A 0x2261 +#define Am79C965 0x2430 +#define Am79C970 0x0242 +#define Am79C970A 0x2621 +#define Am79C971 0x2623 +#define Am79C972 0x2624 +#define Am79C973 0x2625 +#define Am79C978 0x2626 + +/********** Structs **********/ + + + + +struct initBlock { + uInt16 mode; /* Mode register */ + uInt8 padr[6]; /* Ethernet address */ + uInt8 ladrf[8]; /* Logical address filter (multicast) */ + uInt16 rdra; /* Low order pointer to receive ring */ + uInt16 rlen; /* High order pointer and no. rings */ + uInt16 tdra; /* Low order pointer to transmit ring */ + uInt16 tlen; /* High order pointer and no rings */ + }; + +struct mds { + uInt16 md0; + uInt16 md1; + short md2; + uInt16 md3; + }; + +struct hostRingEntry { + struct mds *md; + union { + //struct mbuf *mbuf; + char *data; + }buff; + }; + +struct arpcom { + //struct ifnet ac_if; /* network-visible interface */ + uInt8 ac_enaddr[6]; /* ethernet hardware address */ + int ac_multicnt; /* length of ac_multiaddrs list */ + void *ac_netgraph; /* ng_ether(4) netgraph node info */ + }; + +struct nicInfo { + int ident; /* Type of card */ + int ic; /* Type of ic, Am7990, Am79C960 etc. */ + int memMode; + int iobase; + int mode; /* Mode setting at initialization */ + }; + +struct lncInfo { + struct arpcom arpcom; + struct nicInfo nic; + struct hostRingEntry *recvRing; + struct hostRingEntry *transRings; + struct initBlock *initBloack; + int rap; + int rdp; + int bdp; + int nrdre; + int ntdre; + }; + +extern struct lncInfo *lnc; + +void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val); +uInt16 readCsr(struct lncInfo *lnc, uInt16 port); +void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val); +uInt16 readBcr(struct lncInfo *lnc, uInt16 port); + +void initLNC(); +int probe(struct lncInfo *lnc); +int lanceProbe(struct lncInfo *lnc); +int lncAttach(struct lncInfo *lnc,int unit); + + +void lncInt(); +void _lncInt(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:50 reddawg + no message + + Revision 1.2 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/include/pci/pci.h b/include/pci/pci.h new file mode 100644 index 0000000..df25540 --- /dev/null +++ b/include/pci/pci.h @@ -0,0 +1,110 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PCI_H +#define _PCI_H + +#include + + +struct pciConfig { + uInt16 vendorId; + uInt16 deviceId; + + uInt16 command; + uInt16 status; + + uInt8 revisionId; + uInt8 interface; + uInt8 subClass; + uInt8 baseClass; + + uInt8 cacheLineSize; + uInt8 latencyTimer; + uInt8 headerType; + uInt8 bist; + + /* device info */ + uInt8 bus; + uInt8 dev; + uInt8 func; + uInt8 irq; + + /* base registers */ + uInt32 base[6]; + uInt32 size[6]; + + uInt16 subsysVendor; + uInt16 subsys; + + }; + +struct confadd { + uInt8 reg:8; + uInt8 func:3; + uInt8 dev:5; + uInt8 bus:8; + uInt8 rsvd:7; + uInt8 enable:1; + }; + +#define countof(a) (sizeof(a) / sizeof(a[0])) + +int pci_init(); + + +bool pciProbe(int bus,int dev,int func,struct pciConfig *cfg); +uInt32 pciRead(int bus, int dev, int func, int reg, int bytes); +void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:51 reddawg + no message + + Revision 1.3 2004/08/20 16:49:11 reddawg + PCI Updates - More to follow as PCI system gets revamped + + Revision 1.2 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sde/ogDisplay_UbixOS.h b/include/sde/ogDisplay_UbixOS.h new file mode 100644 index 0000000..fa8022a --- /dev/null +++ b/include/sde/ogDisplay_UbixOS.h @@ -0,0 +1,87 @@ +#ifndef OGDISPLAY_UBIXOS_H +#define OGDISPLAY_UBIXOS_H + +#include + +struct ogModeInfo { + uInt16 modeAttributes __attribute__((packed)); + uInt8 windowAFlags __attribute__((packed)); + uInt8 windowBFlags __attribute__((packed)); + uInt16 granularity __attribute__((packed)); + uInt16 windowSize __attribute__((packed)); + uInt16 windowASeg __attribute__((packed)); + uInt16 windowBSeg __attribute__((packed)); + void* bankSwitch __attribute__((packed)); + uInt16 bytesPerLine __attribute__((packed)); + uInt16 xRes __attribute__((packed)); + uInt16 yRes __attribute__((packed)); + uInt8 charWidth __attribute__((packed)); + uInt8 charHeight __attribute__((packed)); + uInt8 numBitPlanes __attribute__((packed)); + uInt8 bitsPerPixel __attribute__((packed)); + uInt8 numberOfBanks __attribute__((packed)); + uInt8 memoryModel __attribute__((packed)); + uInt8 bankSize __attribute__((packed)); + uInt8 numOfImagePages __attribute__((packed)); + uInt8 reserved __attribute__((packed)); + // Direct colour fields (required for Direct/6 and YUV/7 memory models + uInt8 redMaskSize __attribute__((packed)); + uInt8 redFieldPosition __attribute__((packed)); + uInt8 greenMaskSize __attribute__((packed)); + uInt8 greenFieldPosition __attribute__((packed)); + uInt8 blueMaskSize __attribute__((packed)); + uInt8 blueFieldPosition __attribute__((packed)); + uInt8 alphaMaskSize __attribute__((packed)); + uInt8 alphaFieldPosition __attribute__((packed)); + uInt8 directColourMode __attribute__((packed)); + // VESA 2.0 specific fields + uInt32 physBasePtr __attribute__((packed)); + void* offScreenMemOffset __attribute__((packed)); + uInt16 offScreenMemSize __attribute__((packed)); + uInt8 paddington[461] __attribute__((packed)); +}; + +struct ogVESAInfo { + char VBESignature[4] __attribute__((packed)); + uInt8 minVersion __attribute__((packed)); + uInt8 majVersion __attribute__((packed)); + uInt32 OEMStringPtr __attribute__((packed)); + uInt32 capabilities __attribute__((packed)); + uInt32 videoModePtr __attribute__((packed)); + uInt16 totalMemory __attribute__((packed)); + // VESA 2.0 specific fields + uInt16 OEMSoftwareRev __attribute__((packed)); + uInt32 OEMVendorNamePtr __attribute__((packed)); + uInt32 OEMProductNamePtr __attribute__((packed)); + uInt32 OEMProductRevPtr __attribute__((packed)); + uInt8 paddington[474] __attribute__((packed)); +}; + + +class ogDisplay_UbixOS : public ogSurface { + protected: + void * pages[2]; + uInt32 activePage; + uInt32 visualPage; + ogVESAInfo * VESAInfo; + ogModeInfo * modeInfo; + + uInt16 FindMode(uInt32, uInt32, uInt32); + void GetModeInfo(uInt16); + void GetVESAInfo(void); + void SetMode(uInt16); + void SetPal(void); + public: + ogDisplay_UbixOS(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual bool ogClone(ogSurface&); + virtual void ogCopyPalette(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + virtual bool ogLoadPalette(const char *); + virtual void ogSetPalette(const ogRGBA8[]); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8, uInt8); + virtual ~ogDisplay_UbixOS(void); +}; // ogDisplay_UbixOS + +#endif diff --git a/include/sde/sde.h b/include/sde/sde.h new file mode 100644 index 0000000..0b27d5d --- /dev/null +++ b/include/sde/sde.h @@ -0,0 +1,55 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#ifndef _SDE_H +#define _SDE_H + +#include + +#define registerWindow 1 +#define windowReady 2 +#define drawWindow 3 +#define killWindow 4 + +#ifdef __cplusplus +extern "C" +#endif +void sdeThread(); + +#ifdef __cplusplus +extern "C" +#endif +void sysSDE(uInt32 cmd,void *ptr); + +struct sdeWindows { + struct sdeWindows *next; + struct sdeWindows *prev; + void *buf; + pidType pid; + uInt8 status; + }; + +extern struct sdeWindows *windows; + +#endif + diff --git a/include/stdarg.h b/include/stdarg.h new file mode 100644 index 0000000..ef3804a --- /dev/null +++ b/include/stdarg.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STDARG_H +#define _STDARG_H + +typedef char *vaList[1]; + +#define vaStart(ap, parm) ((ap)[0] = (char *) &parm \ + + ((sizeof(parm) + sizeof(int) - 1) & ~(sizeof(int) - 1)), (void) 0) + +#define vaArg(ap, type) ((ap)[0] += \ + ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)), \ + (*(type *) ((ap)[0] \ + - ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)) ))) + +#define vaEnd(ap) ((ap)[0] = 0, (void) 0) + + +int vsprintf(char *buf, const char *fmt, vaList args); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:36 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:38 reddawg + no message + + Revision 1.2 2004/05/21 15:22:35 reddawg + Cleaned up + + + END + ***/ diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..2f52ea3 --- /dev/null +++ b/include/string.h @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +char *strcpy(char *dst,const char *src); + +void *memcpy(void * dst, const void * src, size_t length); +void *memset(void * dst, int c, size_t length); +int strlen(const char * string); +int strcmp(const char *,const char *); + +int sprintf(char * str, const char * format, ...); + +long strtol(const char * __restrict nptr, char ** __restrict endptr, int base); + +#endif + +/*** + END + ***/ diff --git a/include/sys/_types.h b/include/sys/_types.h new file mode 100644 index 0000000..9d4f3ae --- /dev/null +++ b/include/sys/_types.h @@ -0,0 +1,66 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef __TYPES_H +#define __TYPES_H + +//#include + +typedef __signed char __int8_t; +typedef unsigned char __uint8_t; +typedef short __int16_t; +typedef unsigned short __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; +typedef long long __int64_t; +typedef unsigned long long __uint64_t; + + +typedef unsigned long __clock_t; +//typedef long __time_t; +typedef __uint32_t __ino_t; +typedef __int32_t __ssize_t; + +/* stat types */ +typedef __uint32_t __dev_t; /* device number */ +typedef __uint16_t __mode_t; +typedef __uint16_t __nlink_t; /* link count */ +typedef __uint32_t __uid_t; +typedef __uint32_t __gid_t; +typedef __int32_t __time_t; +typedef __int64_t __blkcnt_t; /* file block count */ +typedef __uint32_t __blksize_t; /* file block size */ +typedef __uint32_t __fflags_t; /* file flags */ + +#endif + +/*** + END + ***/ + diff --git a/include/sys/buf.h b/include/sys/buf.h new file mode 100644 index 0000000..7fa841e --- /dev/null +++ b/include/sys/buf.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _BUF_H +#define _BUF_H + +#include +#include +#include + +struct buf { + }; + + +#endif + +/*** + END + ***/ + diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h new file mode 100644 index 0000000..77634c6 --- /dev/null +++ b/include/sys/cdefs.h @@ -0,0 +1,59 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _CDEFS_H +#define _CDRES_H + +#include + +#define __dead2 __attribute__((__noreturn__)) + + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:51 reddawg + no message + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/device.h b/include/sys/device.h new file mode 100644 index 0000000..1c4dc53 --- /dev/null +++ b/include/sys/device.h @@ -0,0 +1,117 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +#include + +struct device_node { + struct device_node *prev; + struct device_node *next; + struct device_interface *devInfo; + struct device_resource *devRec; + char type; + int minor; + }; + +struct device_resource { + uInt8 irq; + }; + +struct device_interface { + uInt8 initialized; + uInt32 size; + int major; + void *info; + void (*read)(void *,void *,uInt32,uInt32); + void (*write)(void *,void *,uInt32,uInt32); + void (*reset)(void *); + int (*init)(void *); + void (*ioctl)(void *); + void (*stop)(void *); + void (*start)(void *); + void (*standby)(void *); + }; + + +int device_add(int,char,struct device_interface *); +struct device_node *device_find(int major,int minor); +int device_remove(struct device_node *); +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:51 reddawg + no message + + Revision 1.14 2004/08/15 00:33:02 reddawg + Wow the ide driver works again + + Revision 1.13 2004/08/14 21:56:44 reddawg + Added initialized byte to the device system to make it easy to add child devices which use parent hardware. + + Revision 1.12 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.11 2004/05/22 02:40:04 ionix + + + fixed typo in device.h and initialized previous in device.c :) + + Revision 1.10 2004/05/22 02:34:03 ionix + + + Added proto + + Revision 1.9 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ + diff --git a/include/sys/device.old.h b/include/sys/device.old.h new file mode 100644 index 0000000..ecd8cb2 --- /dev/null +++ b/include/sys/device.old.h @@ -0,0 +1,58 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +#include + +struct device { + struct net *net; + uInt16 ioAddr; + uInt32 irq; + struct ei_device *priv; + uInt32 mtu; + }; + +struct net { + char mac[6]; + char broadcast[6]; + }; + +struct ei_device { + int txStartPage; + int rxStartPage; + int stopPage; + int currentPage; + uInt16 word16; + uInt32 pingPong; + int tx1; + int tx2; + }; + +#endif + +/*** + END + ***/ + diff --git a/include/sys/dma.h b/include/sys/dma.h new file mode 100644 index 0000000..974e99a --- /dev/null +++ b/include/sys/dma.h @@ -0,0 +1,59 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DMA_H +#define _DMA_H + +#include + +void dmaXfer(uInt8 channel,uInt32 address,uInt length,uInt8 read); +void _dmaXfer(uInt8 dmaChannel,uInt8 page,uInt offset,uInt length,uInt8 mode); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:52 reddawg + no message + + Revision 1.3 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/driver.h b/include/sys/driver.h new file mode 100644 index 0000000..28995d8 --- /dev/null +++ b/include/sys/driver.h @@ -0,0 +1,70 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DRIVER_H +#define _DRIVER_H + +#include + + +typedef struct devMethodType devMethod; + +struct devMethodType { + }; + +struct driverType { + const char *devName; + devMethod *methods; + } + + + + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:52 reddawg + no message + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/gdt.h b/include/sys/gdt.h new file mode 100644 index 0000000..6e51312 --- /dev/null +++ b/include/sys/gdt.h @@ -0,0 +1,125 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _GDT_H +#define _GDT_H + +/* Descriptor Definitions */ +#define dCall 0x0C00 /* 386 Call Gate */ +#define dCode 0x1800 /* Code Segment */ +#define dData 0x1000 /* Data Segment */ +#define dInt 0x0E00 /* 386 Interrupt Gate */ +#define dLdt 0x200 /* Local Descriptor Table (LDT) */ +#define dTask 0x500 /* Task gate */ +#define dTrap 0x0F00 /* 386 Trap Gate */ +#define dTss 0x900 /* Task State Segment (TSS) */ + +/* Descriptor Options */ +#define dDpl3 0x6000 /* DPL3 or mask for DPL */ +#define dDpl2 0x4000 /* DPL2 or mask for DPL */ +#define dDpl1 0x2000 /* DPL1 or mask for DPL */ +#define dDpl0 0x0000 /* DPL0 or mask for DPL */ +#define dPresent 0x8000 /* Present */ +#define dNpresent 0x8000 /* Not Present */ +#define dAcc 0x100 /* Accessed (Data or Code) */ +#define dWrite 0x200 /* Writable (Data segments only) */ +#define dRead 0x200 /* Readable (Code segments only) */ +#define dBusy 0xB00 /* Busy (TSS only) was 200 */ +#define dEexdown 0x400 /* Expand down (Data segments only) */ +#define dConform 0x400 /* Conforming (Code segments only) */ +#define dBig 0x40 /* Default to 32 bit mode */ +#define dBiglim 0x80 /* Limit is in 4K units */ + +/* GDT Descriptor */ +struct gdtDescriptor { + unsigned short limitLow; /* Limit 0..15 */ + unsigned short baseLow; /* Base 0..15 */ + unsigned char baseMed; /* Base 16..23 */ + unsigned char access; /* Access Byte */ + unsigned int limitHigh:4; /* Limit 16..19 */ + unsigned int granularity:4; /* Granularity */ + unsigned char baseHigh; /* Base 24..31 */ + } __attribute__ ((packed)); + +struct gdtGate { + unsigned short offsetLow; /* Offset 0..15 */ + unsigned short selector; /* Selector */ + unsigned short access; /* Access Flags */ + unsigned short offsetHigh; /* Offset 16..31 */ + } __attribute__ ((packed)); + +union descriptorTableUnion { + struct gdtDescriptor descriptor; /* Normal descriptor */ + struct gdtGate gate; /* Gate descriptor */ + unsigned long dummy; /* Any other info */ + }; + + +#define ubixDescriptorTable(name,length) union descriptorTableUnion name[length] = +#define ubixStandardDescriptor(base, limit, control) {descriptor: \ + {(limit & 0xffff), \ + (base & 0xffff), \ + ((base >> 16) & 0xff), \ + ((control+dPresent) >> 8), \ + (limit >> 16), \ + ((control & 0xff) >> 4), \ + (base >> 24)}} +#define ubixGateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \ + (control+dPresent), (offset >> 16) }} + +extern union descriptorTableUnion ubixGDT[9]; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:52 reddawg + no message + + Revision 1.5 2004/08/15 16:47:49 reddawg + Fixed + + Revision 1.4 2004/07/22 20:53:07 reddawg + atkbd: fixed problem + + Revision 1.3 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/gen_calls.h b/include/sys/gen_calls.h new file mode 100644 index 0000000..c8e827b --- /dev/null +++ b/include/sys/gen_calls.h @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _GEN_CALLS_H +#define _GEN_CALLS_H + +#include +#include + +int read(struct thread *td,struct read_args *uap); + +int getpid(struct thread *, struct getpid_args *); +int issetugid(register struct thread *, struct issetugid_args *); +int readlink(struct thread *,struct readlink_args *); +int getuid(struct thread *, struct getuid_args *); +int getgid(struct thread *, struct getgid_args *); +int gettimeofday_new(struct thread *, struct gettimeofday_args *); + +#endif + +/*** + END + ***/ + diff --git a/include/sys/idt.h b/include/sys/idt.h new file mode 100644 index 0000000..11906b1 --- /dev/null +++ b/include/sys/idt.h @@ -0,0 +1,90 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _IDT_H +#define _IDT_H + +#include +#include + +#define EFLAG_TF 0x100 +#define EFLAG_IF 0x200 +#define EFLAG_IOPL3 0x3000 +#define EFLAG_VM 0x20000 + +int idt_init(); +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); +void setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector); +void intNull(); + +void _int0(); +void _int1(); +void _int2(); +void _int3(); +void _int4(); +void _int5(); +void _int6(); +void _int7(); +void _int8(); +void _int9(); +void _int10(); +void _int11(); +void _int12(); +void _int13(); +void timerInt(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:52 reddawg + no message + + Revision 1.5 2004/09/07 21:54:38 reddawg + ok reverted back to old scheduling for now.... + + Revision 1.3 2004/07/09 13:16:41 reddawg + idt: idtInit to idt_init + Adjusted Startup Routines + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/io.h b/include/sys/io.h new file mode 100644 index 0000000..c475707 --- /dev/null +++ b/include/sys/io.h @@ -0,0 +1,65 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _IO_H +#define _IO_H + +unsigned char inportByte(unsigned int); +unsigned short inportWord(unsigned int); +unsigned long inportDWord(unsigned int); +void outportByte(unsigned int,unsigned char); +void outportByteP(unsigned int port,unsigned char value); +void outportWord(unsigned int,unsigned short); +void outportDWord(unsigned int port,unsigned long value); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:52 reddawg + no message + + Revision 1.3 2004/07/22 20:14:34 reddawg + still working here + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/kern_descrip.h b/include/sys/kern_descrip.h new file mode 100644 index 0000000..4c9e92a --- /dev/null +++ b/include/sys/kern_descrip.h @@ -0,0 +1,174 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KERN_DESCRIP_H +#define _KERN_DESCRIP_H + +#include +#include + +#include + +typedef __mode_t mode_t; +typedef __nlink_t nlink_t; + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#define F_GETLK 7 /* get record locking information */ +#define F_SETLK 8 /* set record locking information */ +#define F_SETLKW 9 /* F_SETLK; wait if blocked */ + +/* Flag Values */ +#define FREAD 0x0001 +#define FWRITE 0x0002 +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* synchronous writes */ +#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */ +#define O_NOFOLLOW 0x0100 /* don't follow symlinks */ +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ +#define O_DIRECT 0x00010000 +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + + +#define FHASLOCK 0x4000 /* descriptor holds advisory lock */ + + +/* F MAPPERS */ +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_FSYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#define FPOSIXSHM O_NOFOLLOW + + + +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT) + +#define FFLAGS(oflags) ((oflags) + 1) +#define OFLAGS(fflags) ((fflags) - 1) + +struct file { + struct vfs_mountPoint *mp; + u_int16_t status; + u_int16_t mode; + u_int32_t offset; + u_int32_t size; + u_int32_t perms; + int f_flag; + char *buffer; + char path[1024]; + void *fsObj; + }; + +/* TEMP */ +struct __timespec { + __time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +struct stat { + __dev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __dev_t st_rdev; /* device type */ +#if __BSD_VISIBLE + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last file status change */ +#else + time_t st_atime; /* time of last access */ + long __st_atimensec; /* nsec of last access */ + time_t st_mtime; /* time of last data modification */ + long __st_mtimensec; /* nsec of last data modification */ + time_t st_ctime; /* time of last file status change */ + long __st_ctimensec; /* nsec of last file status change */ +#endif + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + __int32_t st_lspare; +#if __BSD_VISIBLE + struct timespec st_birthtimespec; /* time of file creation */ + /* + * Explicitly pad st_birthtimespec to 16 bytes so that the size of + * struct stat is backwards compatible. We use bitfields instead + * of an array of chars so that this doesn't require a C99 compiler + * to compile if the size of the padding is 0. We use 2 bitfields + * to cover up to 64 bits on 32-bit machines. We assume that + * CHAR_BIT is 8... + */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); +#else + time_t st_birthtime; /* time of file creation */ + long st_birthtimensec; /* nsec of file creation */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); +#endif +}; + + +int fcntl(struct thread *, struct fcntl_args *); +int close(struct thread *,struct close_args *); +int falloc(struct thread *, struct file **, int *); +int getdtablesize(struct thread *, struct getdtablesize_args *); +int stat(struct thread *, struct stat_args *); +int fstat(struct thread *, struct fstat_args *); +int lstat(struct thread *, struct lstat_args *); +int ioctl(struct thread *, struct ioctl_args *); +int getfd(struct thread *td,struct file **fp,int fd); + + +#endif + +/*** + END + ***/ diff --git a/include/sys/kern_sig.h b/include/sys/kern_sig.h new file mode 100644 index 0000000..914f5c9 --- /dev/null +++ b/include/sys/kern_sig.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KERN_SIG_H +#define _KERN_SIG_H + +#include +#include + +int sigaction(struct thread *,struct sigaction_args *); +int sigprocmask(struct thread *, struct sigprocmask_args *); + +#endif + +/*** + END + ***/ + diff --git a/include/sys/kern_sysctl.h b/include/sys/kern_sysctl.h new file mode 100644 index 0000000..3df8cae --- /dev/null +++ b/include/sys/kern_sysctl.h @@ -0,0 +1,77 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KERNSYSCTL_H +#define _KERNSYSCTL_H + +#include +#include + +#define CTL_MAXNAME 24 /* largest number of components supported */ + +/* + * Top-level identifiers + */ +#define CTL_UNSPEC 0 /* unused */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +#define CTL_VFS 3 /* filesystem, mount type is next */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +#define CTL_USER 8 /* user-level */ +#define CTL_P1003_1B 9 /* POSIX 1003.1B */ +#define CTL_UBIX 10 /* ubixos */ + +#define CTL_KERN_OPENFILES 1 /* kernel openfiles */ + +#define EINVAL -1 /* */ + +struct sysctl_entry { + struct sysctl_entry *prev; + struct sysctl_entry *next; + struct sysctl_entry *children; + char name[32]; + int id; + void *value; + int val_len; + }; + +int kern_sysctl(int *name,u_int namelen,void *old,size_t *oldlenp,void *new,size_t newlen,size_t *retval,int flags); +int sysctl_add(int *,int,char *,void *,int); +int sysctl_init(); + +extern bool sysctl_enabled; +#endif + +/*** + END + ***/ + diff --git a/include/sys/pipe.h b/include/sys/pipe.h new file mode 100644 index 0000000..fb9f7d6 --- /dev/null +++ b/include/sys/pipe.h @@ -0,0 +1,43 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PIPE_H +#define _PIPE_H + +#include +#include + +int pipe(struct thread *, struct pipe_args *); + +#endif + +/*** + END + ***/ + diff --git a/include/sys/signal.h b/include/sys/signal.h new file mode 100644 index 0000000..3dc692d --- /dev/null +++ b/include/sys/signal.h @@ -0,0 +1,53 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SIGNAL_H +#define _SIGNALL_H + +#include + +#define _SIG_WORDS 4 +#define _SIG_MAXSIG 128 +#define _SIG_IDX(sig) ((sig) - 1) +#define _SIG_WORD(sig) (_SIG_IDX(sig) >> 5) +#define _SIG_BIT(sig) (1 << (_SIG_IDX(sig) & 31)) +#define _SIG_VALID(sig) ((sig) <= _SIG_MAXSIG && (sig) > 0) + +typedef struct __sigset { + __uint32_t __bits[_SIG_WORDS]; + } __sigset_t; + +typedef __sigset_t sigset_t; + +#endif + +/*** + END + ***/ + diff --git a/include/sys/sysproto.h b/include/sys/sysproto.h new file mode 100644 index 0000000..b50e60d --- /dev/null +++ b/include/sys/sysproto.h @@ -0,0 +1,219 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSPROTO_H +#define _SYSPROTO_H + +#include +#include + +typedef int register_t; + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define PADL_(t) 0 +#define PADR_(t) PAD_(t) +#else +#define PADL_(t) PAD_(t) +#define PADR_(t) 0 +#endif + +//Protos +struct fork_args { + register_t dummy; + }; +struct read_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + }; +struct write_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + }; +struct open_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + }; +struct close_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + }; + +struct setitimer_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char itv_l_[PADL_(struct itimerval *)]; struct itimerval * itv; char itv_r_[PADR_(struct itimerval *)]; + char oitv_l_[PADL_(struct itimerval *)]; struct itimerval * oitv; char oitv_r_[PADR_(struct itimerval *)]; + }; + +struct access_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + }; +struct fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; + }; +struct mprotect_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + }; +struct lseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; + }; + + + + +//Old + +struct sysctl_args { + char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)]; + char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)]; + char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)]; + char oldlenp_l_[PADL_(size_t *)]; size_t * oldlenp; char oldlenp_r_[PADR_(size_t *)]; + char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)]; + char newlen_l_[PADL_(size_t)]; size_t newlen; char newlen_r_[PADR_(size_t)]; +}; + +struct getpid_args { + register_t dummy; +}; +struct issetugid_args { + register_t dummy; +}; +struct fcntl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(long)]; long arg; char arg_r_[PADR_(long)]; +}; + +struct pipe_args { + register_t dummy; + }; + +struct readlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(int)]; int count; char count_r_[PADR_(int)]; +}; + +struct getuid_args { + register_t dummy; +}; + +struct getgid_args { + register_t dummy; +}; + +struct mmap_args { + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char pos_l_[PADL_(off_t)]; off_t pos; char pos_r_[PADR_(off_t)]; + }; + +struct obreak_args { + char nsize_l_[PADL_(char *)];char * nsize;char nsize_r_[PADR_(char *)]; + }; + +struct sigaction_args { + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; + char act_l_[PADL_(const struct sigaction *)]; const struct sigaction * act; char act_r_[PADR_(const struct sigaction *)]; + char oact_l_[PADL_(struct sigaction *)]; struct sigaction * oact; char oact_r_[PADR_(struct sigaction *)]; + }; + +struct getdtablesize_args { + register_t dummy; +}; + +struct munmap_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; + +struct sigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char oset_l_[PADL_(sigset_t *)]; sigset_t * oset; char oset_r_[PADR_(sigset_t *)]; + }; +struct gettimeofday_args { + char tp_l_[PADL_(struct timeval *)]; struct timeval * tp; char tp_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; + }; + +struct stat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct stat *)]; struct stat * ub; char ub_r_[PADR_(struct stat *)]; +}; + +struct fstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct stat *)]; struct stat * sb; char sb_r_[PADR_(struct stat *)]; +}; + +struct lstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct stat *)]; struct stat * ub; char ub_r_[PADR_(struct stat *)]; +}; + +struct ioctl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char com_l_[PADL_(u_long)]; u_long com; char com_r_[PADR_(u_long)]; + char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)]; +}; + +//Func Defs +int fork(struct thread *td,struct fork_args *uap); +int read(struct thread *td,struct read_args *uap); +int write(struct thread *td, struct write_args *uap); +int open(struct thread *td, struct open_args *uap); +int close(struct thread *td, struct close_args *uap); +int setitimer(struct thread *td, struct setitimer_args *uap); +int access(struct thread *td, struct access_args *uap); +int fstatfs(struct thread *td, struct fstatfs_args *uap); +int mprotect(struct thread *td, struct mprotect_args *uap); +int lseek(struct thread *td, struct lseek_args *uap); + +#endif + +/*** + END + ***/ + diff --git a/include/sys/thread.h b/include/sys/thread.h new file mode 100644 index 0000000..376457f --- /dev/null +++ b/include/sys/thread.h @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _THREAD_H +#define _THREAD_H + +#include + +#define O_FILES 64 +#define S_GID 0x1 +#define S_UID 0x3 + +struct thread { + int td_retval[2]; + u_int32_t o_files[O_FILES]; + char * vm_daddr; + int32_t vm_dsize; + u_int8_t mode; + }; + +#endif + +/*** + END + ***/ + diff --git a/include/sys/trap.h b/include/sys/trap.h new file mode 100644 index 0000000..ee145d6 --- /dev/null +++ b/include/sys/trap.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TRAP_H +#define _TRAP_H + +struct trapframe { + int tf_fs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_ebp; + int tf_isp; + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_err; + int tf_eip; + int tf_cs; + int tf_eflags; + /* below only when crossing rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; +}; + + +#endif + +/*** + END + ***/ + diff --git a/include/sys/tss.h b/include/sys/tss.h new file mode 100644 index 0000000..8393c26 --- /dev/null +++ b/include/sys/tss.h @@ -0,0 +1,143 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TSS_H +#define _TSS_H + +#include + +struct tssStruct { + short back_link; + short back_link_reserved; + long esp0; + short ss0; + short ss0_reserved; + long esp1; + short ss1; + short ss1_reserved; + long esp2; + short ss2; + short ss2_reserved; + long cr3; + long eip; + long eflags; + long eax,ecx,edx,ebx; + long esp; + long ebp; + long esi; + long edi; + short es; + short es_reserved; + short cs; + short cs_reserved; + short ss; + short ss_reserved; + short ds; + short ds_reserved; + short fs; + short fs_reserved; + short gs; + short gs_reserved; + short ldt; + short ldt_reserved; + short trace_bitmap; + short io_map; + char io_space[8192]; + }; + +struct i387Struct { + long cwd; + long swd; + long twd; + long fip; + long fcs; + long foo; + long fos; + long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */ + }; + +struct i386_frame { + uInt32 gs; + uInt32 fs; + uInt32 es; + uInt32 ds; + uInt32 ss; + uInt32 edi; + uInt32 esi; + uInt32 ebp; + uInt32 esp; + uInt32 ebx; + uInt32 edx; + uInt32 ecx; + uInt32 eax; + /* + uInt32 vector; + uInt32 error_code; + */ + uInt32 eip; + uInt32 cs; + uInt32 flags; + uInt32 user_esp; + uInt32 user_ss; + }; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:53 reddawg + no message + + Revision 1.6 2004/07/27 07:42:29 reddawg + *burp* + + Revision 1.5 2004/07/27 07:40:41 reddawg + does it compile now? + + Revision 1.4 2004/07/27 07:27:50 reddawg + chg: I was fooled thought we failed but it was a casting issue + + Revision 1.3 2004/07/22 20:53:07 reddawg + atkbd: fixed problem + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/sys/video.h b/include/sys/video.h new file mode 100644 index 0000000..37f0237 --- /dev/null +++ b/include/sys/video.h @@ -0,0 +1,67 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VIDEO_H +#define _VIDEO_H + +#include + +#define defaultColor 0x0F + +extern int printColor; + +void screenClear(); +void kprint(char *string); +void backSpace(); + +#endif + +/*** + $Log$ + Revision 1.2 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + + Revision 1.1.1.1 2007/01/17 03:31:53 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:53 reddawg + no message + + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixfs/dirCache.h b/include/ubixfs/dirCache.h new file mode 100644 index 0000000..195b035 --- /dev/null +++ b/include/ubixfs/dirCache.h @@ -0,0 +1,28 @@ +#ifndef DIRCACHE_H +#define DIRCACHE_H + +/* #include "ubixfs.h" */ +#include + +struct cacheNode { + char * name; + struct cacheNode * prev; + struct cacheNode * next; + struct cacheNode * parent; + struct cacheNode * fileListHead; + struct cacheNode * fileListTail; + void * info; + int * size; + int present; + int dirty; + uInt32 * startCluster; + uInt16 * attributes; + uInt16 * permissions; +}; /* cacheNode */ + +struct cacheNode * ubixfs_cacheFind(struct cacheNode *, char *); +struct cacheNode * ubixfs_cacheNew(const char *); +void ubixfs_cacheDelete(struct cacheNode **); +struct cacheNode * ubixfs_cacheAdd(struct cacheNode *, struct cacheNode *); + +#endif /* !DIRCACHE_H */ diff --git a/include/ubixfs/ubixfs.h b/include/ubixfs/ubixfs.h new file mode 100644 index 0000000..1cd6031 --- /dev/null +++ b/include/ubixfs/ubixfs.h @@ -0,0 +1,206 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _UBIXFS_H +#define _UBIXFS_H + +#include +#include +#include +#include +#include + + +#define UBIXFS_BLOCKSIZE_BYTES blockSize*512 +#define UBIXFS_ALIGN(size) (size + ((((size) % (UBIXFS_BLOCKSIZE_BYTES)) == 0)? 0 : ((UBIXFS_BLOCKSIZE_BYTES) - ((size) % (UBIXFS_BLOCKSIZE_BYTES))))) + +#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 +#define blockSize 8 + + +#define EOBC -1 + + +#define typeFile 1 +#define typeContainer 2 +#define typeDirectory 4 +#define typeDeleted 8 + +/* Start */ +struct directoryList { + char dirName[256]; + char *dirCache; + uInt32 dirBlock; + struct directoryList *next; + struct directoryList *prev; + }; + +typedef struct directoryList * dirList_t; + +dirList_t ubixFSLoadDir(char *); +/* End */ + +//Partition Information +struct ubixDiskLabel { + uInt32 magicNum; + uInt32 magicNum2; + uInt16 driveType; + uInt16 numPartitions; + struct ubixPartitions { //the partition table + uInt32 pSize; //number of sectors in partition + uInt32 pOffset; //starting sector + uInt32 pFsSize; //filesystem basic fragment size + uInt32 pBatSize; //BAT size + uInt8 pFsType; //filesystem type, see below + uInt8 pFrag; //filesystem fragments per block + } partitions[MAXUBIXPARTITIONS]; + }; + + +struct partitionInformation { + uInt32 size; //Size In Sectors + uInt32 startSector; //Base Sector Of Partition + uInt32 blockAllocationTable; //Base Sector Of BAT + uInt32 rootDirectory; //Base Sector Of Root Directory + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + +//UbixFS Directory Entry +struct directoryEntry { + uInt32 startCluster; //Starting Cluster Of File + uInt32 size; //Size Of File + uInt32 creationDate; //Date Created + uInt32 lastModified; //Date Last Modified + uInt32 uid; //UID Of Owner + uInt32 gid; //GID Of Owner + uInt16 attributes; //Files Attributes + uInt16 permissions; //Files Permissions + char fileName[256]; //File Name + }; + +struct bootSect { + uInt8 jmp[4]; + uInt8 id[6]; + uInt16 version; + uInt16 tmp; + uInt16 fsStart; + uInt16 tmp2; + uInt32 krnl_start; + uInt BytesPerSector; + uInt SectersPerTrack; + uInt TotalHeads; + uInt32 TotalSectors; + uInt8 code[479]; + }; + +struct ubixFSInfo { + struct blockAllocationTableEntry *blockAllocationTable; + struct cacheNode * dirCache; + uInt32 batEntries; + uInt32 rootDir; +}; /* ubixFSInfo */ + +int readFile(char *file); +int writeFileByte(int ch,fileDescriptor *fd,long offset); +//int openFileUbixFS(char *file,fileDescriptor *fd); +int getFreeBlocks(int count,fileDescriptor *fd); +//extern struct ubixDiskLabel *diskLabel; + +//Good Functions +//void initUbixFS(struct mountPoints *mp); + +int readUbixFS(fileDescriptor *fd,char *data,uInt32,long size); +int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size); +void syncBat(struct vfs_mountPoint *mp); +int freeBlocks(int block,fileDescriptor *fd); +int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd); +void ubixFSUnlink(char *path,struct vfs_mountPoint *mp); +int ubixFSmkDir(char *dir,fileDescriptor *fd); + +int ubixfs_init(); +int ubixfs_initialize(); +void ubixfs_thread(); + + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.2 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:53 reddawg + no message + + Revision 1.21 2004/09/14 20:57:01 reddawg + Bug fixes: macro problem over opt a multiply + + Revision 1.20 2004/08/01 17:58:39 flameshadow + chg: fixed string allocation bug in ubixfs_cacheNew() + + Revision 1.19 2004/07/27 12:02:01 reddawg + chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + + Revision 1.18 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + + Revision 1.17 2004/07/22 22:37:03 reddawg + Caching is working now the FS is extremely fast but needs to be optimized to do 32bit copies over 8bit + + Revision 1.16 2004/07/20 21:28:16 flameshadow + oops + + Revision 1.14 2004/07/20 19:36:49 reddawg + UBU Tags + + Revision 1.13 2004/07/14 12:21:49 reddawg + ubixfs: enableUbixFs to ubixfs_init + Changed Startup Routines + + END + ***/ diff --git a/include/ubixos/elf.h b/include/ubixos/elf.h new file mode 100644 index 0000000..bbe5864 --- /dev/null +++ b/include/ubixos/elf.h @@ -0,0 +1,212 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _ELF_H +#define _ELF_H + +#include +#include + +#define elfExecutable 0x002 +#define elfLibrary 0x003 + +#define R_386_NONE 0 /* none none */ +#define R_386_32 1 /* word32 S + A */ +#define R_386_PC32 2 /* word32 S + A - P */ +#define R_386_GOT32 3 /* word32 G + A - P */ +#define R_386_PLT32 4 /* word32 L + A - P */ +#define R_386_COPY 5 /* none none */ +#define R_386_GLOB_DAT 6 /* word32 S */ +#define R_386_JMP_SLOT 7 /* word32 S */ +#define R_386_RELATIVE 8 /* word32 B + A */ +#define R_386_GOTOFF 9 /* word32 S + A - GOT */ +#define R_386_GOTPC 10 /* word32 GOT + A - P */ + + +/* Elf Types */ +#define ET_NONE 0 // No file type +#define ET_REL 1 // Relocatable file +#define ET_EXEC 2 // Executable file +#define ET_DYN 3 // Shared object file +#define ET_CORE 4 // Core file +#define ET_LOPROC 0xff00 // Processor-specific +#define ET_HIPROC 0xffff +/* End Elf Types */ + +/* Elf Machine Types */ +#define EM_NONE 0 // No machine +#define EM_M32 1 // AT&T WE 32100 +#define EM_SPARC 2 // SPARC +#define EM_386 3 // Intel 80386 +#define EM_68K 4 // Motorola 68000 +#define EM_88K 5 // Motorola 88000 +#define EM_860 7 // Intel 80860 +#define EM_MIPS 8 // MIPS RS3000 +/* End Elf Machines Types */ + +/* Elf Version */ +#define EV_NONE 0 // Invalid version +#define EV_CURRENT 1 // Current version +/* End Elf Version */ + +/* Elf Program Header Types */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_LOOS 0x60000000 +#define PT_HIOS 0x6fffffff +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff +#define PT_GNU_EH_FRAME 0x6474e550 +#define PT_GNU_STACK (PT_LOOS + 0x474e551) +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580) + +/* End Elf Program Header Types */ + +typedef struct { + uInt8 eIdent[16]; /* File identification. */ + uInt16 eType; /* File type. */ + uInt16 eMachine; /* Machine architecture. */ + uInt32 eVersion; /* ELF format version. */ + uInt32 eEntry; /* Entry point. */ + uInt32 ePhoff; /* Program header file offset. */ + uInt32 eShoff; /* Section header file offset. */ + uInt32 eFlags; /* Architecture-specific flags. */ + uInt16 eEhsize; /* Size of ELF header in bytes. */ + uInt16 ePhentsize; /* Size of program header entry. */ + uInt16 ePhnum; /* Number of program header entries. */ + uInt16 eShentsize; /* Size of section header entry. */ + uInt16 eShnum; /* Number of section header entries. */ + uInt16 eShstrndx; /* Section name strings section. */ + } elfHeader; + +typedef struct { + uInt32 phType; /* Entry type. */ + uInt32 phOffset; /* File offset of contents. */ + uInt32 phVaddr; /* Virtual address in memory image. */ + uInt32 phPaddr; /* Physical address (not used). */ + uInt32 phFilesz; /* Size of contents in file. */ + uInt32 phMemsz; /* Size of contents in memory. */ + uInt32 phFlags; /* Access permission flags. */ + uInt32 phAlign; /* Alignment in memory and file. */ + } elfProgramHeader; + +typedef struct { + uInt32 shName; /* Section name (index into the section header string table). */ + uInt32 shType; /* Section type. */ + uInt32 shFlags; /* Section flags. */ + uInt32 shAddr; /* Address in memory image. */ + uInt32 shOffset; /* Offset in file. */ + uInt32 shSize; /* Size in bytes. */ + uInt32 shLink; /* Index of a related section. */ + uInt32 shInfo; /* Depends on section type. */ + uInt32 shAddralign; /* Alignment in bytes. */ + uInt32 shEntsize; /* Size of each entry in section. */ + } elfSectionHeader; + +typedef struct { + uInt32 pltOffset; + uInt32 pltInfo; + } elfPltInfo; + +typedef struct { + uInt32 dynName; + uInt32 dynValue; + uInt32 dynSize; + uInt32 dynInfo; + } elfDynSym; + +typedef struct { + uInt32 dynVal; + uInt32 dynPtr; + } elfDynamic; + +typedef struct { + int32_t execfd; + u_int32_t phdr; + u_int32_t phent; + u_int32_t phnum; + u_int32_t pagesz; + u_int32_t base; + u_int32_t flags; + u_int32_t entry; + u_int32_t trace; +} Elf_Auxargs; + +char *elfGetShType(int); +char *elfGetPhType(int); +char *elfGetRelType(int); +int elf_loadfile(kTask_t *p,const char *file,u_int32_t *addr,u_int32_t *entry); + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t)) + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.2 2006/12/15 15:43:46 reddawg + Changes + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:54 reddawg + no message + + Revision 1.7 2004/09/11 01:20:08 apwillia + Clean up 'Unhandled Header' printfs when compiled in linux + + Revision 1.6 2004/06/16 14:04:51 reddawg + Renamed a typedef + + Revision 1.5 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.4 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.3 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/endtask.h b/include/ubixos/endtask.h new file mode 100644 index 0000000..9777ff9 --- /dev/null +++ b/include/ubixos/endtask.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _ENDTASK_H +#define _ENDTASK_H + +#include +#include + +void endTask(pidType); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.2 2006/10/31 20:41:16 reddawg + Includes + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:54 reddawg + no message + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/exec.h b/include/ubixos/exec.h new file mode 100644 index 0000000..a3600a8 --- /dev/null +++ b/include/ubixos/exec.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _EXEC_H +#define _EXEC_H + +#include +#include + +uInt32 execThread(void (* tproc)(void),uInt32,char *); +void execFile(char *file,int argc,char **argv,int console); +int sys_exec(char *file,char *ap); + +#endif + +/*** + END + ***/ diff --git a/include/ubixos/fork.h b/include/ubixos/fork.h new file mode 100644 index 0000000..2d1a0e9 --- /dev/null +++ b/include/ubixos/fork.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _FORK_H +#define _FORK_H + +#include +#include + +void sysFork(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:54 reddawg + no message + + Revision 1.3 2004/09/11 13:06:39 reddawg + fork: cleaned up comments in fork and made fork_copyProcess static + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/init.h b/include/ubixos/init.h new file mode 100644 index 0000000..ebe94f2 --- /dev/null +++ b/include/ubixos/init.h @@ -0,0 +1,85 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _INIT_H +#define _INIT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef int (*intFunctionPTR)(void); + +intFunctionPTR init_tasks[] = { + vmm_init, + static_constructors, + i8259_init, + idt_init, + vitals_init, + sysctl_init, + vfs_init, + sched_init, + pit_init, + atkbd_init, + time_init, + //net_init, + //ne2k_init, + devfs_init, + //pci_init, + //ubixfs_init, + //fdc_init, + tty_init, + ufs_init, + initHardDisk, + }; + +int init_tasksTotal = sizeof(init_tasks)/sizeof(intFunctionPTR); + +#endif + +/*** + END + ***/ diff --git a/include/ubixos/kmod.h b/include/ubixos/kmod.h new file mode 100644 index 0000000..d1e19ce --- /dev/null +++ b/include/ubixos/kmod.h @@ -0,0 +1,83 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KMOD_H +#define _KMOD_H + +#include + +#define LD_START 0x1000000 + +typedef struct kmod_struct { + struct kmod_struct *next; + struct kmod_struct *prev; + uInt16 id; + uInt16 refs; + uInt32 address; + char name[128]; +} kmod_t; + + +uInt32 kmod_load(const char *); +uInt32 kmod_add(const char *, const char *name); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:55 reddawg + no message + + Revision 1.5 2005/08/04 20:35:19 fsdfs + + various updates. mostly kprints, tabbing code to look cleaner + + Revision 1.4 2004/09/26 20:46:13 reddawg + ok time for bed added kmod_add keeps modules listed now + + Revision 1.3 2004/09/26 20:40:51 reddawg + Added baseAddr to the kmod_t + + Revision 1.2 2004/09/26 20:39:19 reddawg + Added kmod struct type kmod_t + + Revision 1.1 2004/09/20 07:33:10 reddawg + Start of kernel modules will make it much more flexable - These modules can be either in kernel threads or system services... + + END + ***/ diff --git a/include/ubixos/kpanic.h b/include/ubixos/kpanic.h new file mode 100644 index 0000000..7905951 --- /dev/null +++ b/include/ubixos/kpanic.h @@ -0,0 +1,42 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPANIC_H +#define _KPANIC_H + +#define K_PANIC(msg) kpanic("\nKernel Panic!!!!\nError: (%s), File: %s, Function: %s, Line: %i\n",msg ,__FILE__,__FUNCTION__,__LINE__); + +void kpanic(const char *fmt, ...); + +#endif + +/*** + END + ***/ + diff --git a/include/ubixos/ld.h b/include/ubixos/ld.h new file mode 100644 index 0000000..b0c634a --- /dev/null +++ b/include/ubixos/ld.h @@ -0,0 +1,77 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _LD_H +#define _LD_H + +#include + +#define LD_START 0x1000000 + +uInt32 ldEnable(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:55 reddawg + no message + + Revision 1.10 2004/06/17 12:20:32 reddawg + Try this now solarwind + + Revision 1.9 2004/06/17 02:19:29 reddawg + Cleaning out dead code + + Revision 1.8 2004/06/16 17:32:14 reddawg + Removed Dead LD Code now part of ld.so + + Revision 1.7 2004/06/16 17:04:13 reddawg + ld.so: rest of the commit + + Revision 1.4 2004/06/13 03:05:15 reddawg + we now have a dynamic linker + + Revision 1.3 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + END + ***/ diff --git a/include/ubixos/lists.h b/include/ubixos/lists.h new file mode 100644 index 0000000..ab3dedd --- /dev/null +++ b/include/ubixos/lists.h @@ -0,0 +1,51 @@ +#define IN +#define STATUS_FAILURE -1 +#define STATUS_SUCCESS 0 + +typedef struct _item_t Item_t; +typedef struct _list_t List_t; +struct _item_t +{ + Item_t *Previous; + Item_t *Next; + void *data; +}; + +struct _list_t +{ + Item_t *First; + Item_t *Last; +}; + +List_t * +InitializeList(); +Item_t * +CreateItem(); +int +InsertItemAtFront( IN List_t * TList, + IN Item_t * kItem); +int +InsertItemBetweenItems( IN List_t * TList, + IN Item_t * Previous, + IN Item_t * Next, + IN Item_t * Insert); +int +RemoveItem( IN List_t * TList, + IN Item_t * kItem); +int +DestroyItemsInList(IN List_t * ItemList); +int +DestroyItemList(IN List_t * ItemList); +Item_t * +GetFirstItem(IN List_t * kItem); + +Item_t * +GetLastItem(IN List_t * kItem); +List_t * +RemoveItemListBetweenItems( IN Item_t * Previous, + IN Item_t * Next); + +void +InsertItemListBetweenItems( IN Item_t * Previous, + IN Item_t * Next, + IN List_t * Insert); diff --git a/include/ubixos/sched.h b/include/ubixos/sched.h new file mode 100644 index 0000000..8fe7625 --- /dev/null +++ b/include/ubixos/sched.h @@ -0,0 +1,186 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SCHED_H +#define _SCHED_H + +#include +//#include +#include +#include +#include +#include + + +typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4,WAIT=5 } tState; + +struct osInfo { + uInt8 timer; + uInt8 v86Task; + bool v86If; + uInt32 vmStart; + uInt32 stdinSize; + uInt32 controlKeys; + char *stdin; + char cwd[1024]; /* current working dir */ + }; + +typedef struct taskStruct { + pidType id; + struct taskStruct *prev; + struct taskStruct *next; + struct tssStruct tss; + struct i387Struct i387; + struct osInfo oInfo; + struct file *imageFd; + tState state; + uInt32 gid; + uInt32 uid; + uInt16 usedMath; + tty_term *term; + struct thread td; + } kTask_t; + + +int sched_init(); +int sched_setStatus(pidType,tState); +int sched_deleteTask(pidType); +int sched_addDelTask(kTask_t *); +kTask_t *sched_getDelTask(); +void sched_yield(); +void sched(); + +void schedEndTask(pidType pid); +kTask_t *schedNewTask(); +kTask_t *schedFindTask(uInt32 id); + +extern kTask_t *_current; +extern kTask_t *_usedMath; + + +#endif + +/*** + $Log$ + Revision 1.2 2007/01/26 18:29:41 reddawg + Functional changes to vfs not yet 100% complete also need to impliment kopen in kernel + + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.3 2006/12/15 15:43:46 reddawg + Changes + + Revision 1.2 2006/10/27 16:42:42 reddawg + Testing + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:55 reddawg + no message + + Revision 1.30 2004/09/11 22:21:11 reddawg + oInfo.cwd is now an array no longer a pointer.. + + Revision 1.29 2004/09/08 23:19:58 reddawg + hmm + + Revision 1.28 2004/09/08 22:16:02 reddawg + Fixens + + Revision 1.27 2004/09/08 21:19:32 reddawg + All good now + + Revision 1.26 2004/09/07 21:54:38 reddawg + ok reverted back to old scheduling for now.... + + Revision 1.20 2004/08/09 12:58:05 reddawg + let me know when you got the surce + + Revision 1.19 2004/08/06 22:43:04 reddawg + ok + + Revision 1.18 2004/08/06 22:32:16 reddawg + Ubix Works Again + + Revision 1.16 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + + Revision 1.15 2004/07/29 21:32:16 reddawg + My quick lunchs breaks worth of updates.... + + Revision 1.14 2004/07/21 17:15:02 reddawg + removed garbage + + Revision 1.13 2004/07/21 14:43:14 flameshadow + add: added cwc (current working container) to the osInfo strut + + Revision 1.12 2004/07/19 02:32:21 reddawg + sched: we now set task status to dead which then makes the scheduler do some clean it could be some minor overhead but i feel this is our most efficient approach right now to prevent corruption of the queues + + Revision 1.11 2004/07/19 02:08:27 reddawg + Cleaned out the rest of debuging code also temporarily disabled the ip stack to improve boot time + + Revision 1.10 2004/07/18 05:24:15 reddawg + Fixens + + Revision 1.9 2004/07/09 13:23:20 reddawg + sched: schedInit to sched_init + Adjusted initialization routines + + Revision 1.8 2004/06/22 14:02:14 solar + Added the PLACEHOLDER state for a task + + Revision 1.7 2004/06/18 13:01:47 solar + Added nice and timeSlice members to the kTask_t type + + Revision 1.6 2004/06/17 02:12:57 reddawg + Cleaned Out Dead Code + + Revision 1.5 2004/06/16 14:04:51 reddawg + Renamed a typedef + + Revision 1.4 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.3 2004/05/21 15:49:13 reddawg + The os does better housekeeping now when a task is exited + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ + diff --git a/include/ubixos/sem.h b/include/ubixos/sem.h new file mode 100644 index 0000000..19525b8 --- /dev/null +++ b/include/ubixos/sem.h @@ -0,0 +1,54 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SEM_H +#define _SEM_H + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:55 reddawg + no message + + Revision 1.1 2004/07/20 18:58:24 reddawg + Few fixes + + END + ***/ + diff --git a/include/ubixos/smp.h b/include/ubixos/smp.h new file mode 100644 index 0000000..9877f0d --- /dev/null +++ b/include/ubixos/smp.h @@ -0,0 +1,76 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SMP_H +#define _SMP_H + +#include + +struct cpuinfo_t { + uInt8 id; + uInt8 ok; // 1=Ok, 0=Bad + uInt8 apic_id,apic_ver; + uInt32 signature; // Family, Model, Stepping + uInt32 feature; + uInt32 max; + char brand[49]; // Brand name + char ident[17]; + }; + + +void smpInit(); +void cpuidDetect(); +uInt8 cpuInfo(); +uInt32 getEflags(); +void setEflags(uInt32); +void cpuid(uInt32,uInt32 *); +void apicMagic(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:56 reddawg + no message + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/spinlock.h b/include/ubixos/spinlock.h new file mode 100644 index 0000000..a7b4ba6 --- /dev/null +++ b/include/ubixos/spinlock.h @@ -0,0 +1,55 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SPINLOCK_H +#define _SPINLOCK_H + +#include + +#define SPIN_LOCK_INITIALIZER 0 + +typedef volatile int spinLock_t; + +extern spinLock_t Master; + +void spinLockInit(spinLock_t *); +void spinUnlock(spinLock_t *); +int spinTryLock(spinLock_t *); +void spinLock(spinLock_t *); + +void spinLock_scheduler(spinLock_t *); /* Only use this spinlock in the sched. */ + +int spinLockLocked(spinLock_t *); + +#endif + +/*** + END + ***/ + diff --git a/include/ubixos/static.h b/include/ubixos/static.h new file mode 100644 index 0000000..94fe513 --- /dev/null +++ b/include/ubixos/static.h @@ -0,0 +1,6 @@ +#ifndef _UBIXOS_STATIC_H +#define _UBIXOS_STATIC_H + +int static_constructors(void); + +#endif diff --git a/include/ubixos/syscall.h b/include/ubixos/syscall.h new file mode 100644 index 0000000..0766b0d --- /dev/null +++ b/include/ubixos/syscall.h @@ -0,0 +1,66 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSCALL_H +#define _SYSCALL_H + +#include + +void _sysCall(); +void _sysCall_new(); +void invalidCall(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.2 2006/10/26 23:52:02 reddawg + Cleaned + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:56 reddawg + no message + + Revision 1.3 2004/07/05 23:06:32 reddawg + Fixens + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/syscalls.h b/include/ubixos/syscalls.h new file mode 100644 index 0000000..5619338 --- /dev/null +++ b/include/ubixos/syscalls.h @@ -0,0 +1,178 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSCALLS_H +#define _SYSCALLS_H + +#include +#include + +void sysAuth(); +void sysPasswd(); +void sysAddModule(); +void sysRmModule(); +void sysGetpid(); +void sysExit(); +void sysExec(); +int sys_exec(); +void sysFork(); +void sysCheckPid(); +void sysGetFreePage(); + +void sysFwrite(); +void sysFgetc(); +void sysFopen(); +void sysFread(); +void sysFclose(); +void sysSchedYield(); +void sysFseek(); +void sysMkDir(); +void sysRmDir(); +void sysGetUid(); +void sysGetGid(); +void sysSetUid(); +void sysSetGid(); +void sysSDE(); +void sysGetDrives(); +void sysGetCwd(); +void sysChDir(); +void sysGetUptime(); +void sysGetTime(); +void sysStartSDE(); +void sysUnlink(); +void sysMpiCreateMbox(); +void sysMpiDestroyMbox(); +void sysMpiPostMessage(); +void sysMpiFetchMessage(); +void sysMpiSpam(); + +typedef void (*functionPTR)(); + +functionPTR systemCalls[] = { + invalidCall, /** 0 **/ + sysGetpid, /** 1 **/ + sysExit, /** 2 **/ + sysExec, /** 3 **/ + sysFork, /** 4 **/ + sysFgetc, /** 5 **/ + sysCheckPid, /** 6 **/ + sysGetFreePage, /** 7 **/ + sysFopen, /** 8 **/ + invalidCall, /** 9 **/ + sysFclose, /** 10 **/ + sysSchedYield, /** 11 **/ + invalidCall, /** 12 **/ + invalidCall, /** 13 **/ + invalidCall, /** 14 **/ + sys_exec, /** 15 **/ + invalidCall, /** 16 **/ + invalidCall, /** 17 **/ + invalidCall, /** 18 **/ + invalidCall, /** 19 **/ + sysFopen, /** 20 Opens A File Node **/ + sysFclose, /** 21 Closes A File Node **/ + sysFread, /** 22 File Read **/ + sysFwrite, /** 23 File Write **/ + sysMkDir, /** 24 Make Directory **/ + sysRmDir, /** 25 Remove Directory **/ + sysGetCwd, /** 26 Get Current Working Dir **/ + sysFseek, /** 27 Set FD Position **/ + sysChDir, /** 28 Change Dir **/ + sysMkDir, /** 29 Create Directory **/ + sysUnlink, /** 30 Unlink **/ + sysGetUid, /** 31 Get User Id **/ + sysGetGid, /** 32 Get Group Id **/ + sysSetUid, /** 33 Set User Id **/ + sysSetGid, /** 34 Set Group Id **/ + sysAuth, /** 35 Authenticates the user **/ + sysPasswd, /** 36 Change user password **/ + sysAddModule, /** 37 Add Kernel Module **/ + sysRmModule, /** 38 Remove Kernel Module **/ + invalidCall, /** 39 **/ + //sysSDE, /** 40 SDE Kernel Interface **/ + invalidCall, /** 40 **/ + invalidCall, /** 41 **/ + invalidCall, /** 42 **/ + invalidCall, /** 43 **/ + invalidCall, /** 44 **/ + sysGetDrives, /** 45 Get Drives **/ + sysGetUptime, /** 46 Get Uptime **/ + sysGetTime, /** 47 Get Time **/ + sysStartSDE, /** 48 start SDE **/ + invalidCall, /** 49 **/ + sysMpiCreateMbox, /** 50 mpiCreateMbox **/ + sysMpiDestroyMbox, /** 51 mpiDestroyMbox **/ + sysMpiPostMessage, /** 52 mpiPostMessage **/ + sysMpiFetchMessage, /** 53 mpiFetchMessage **/ + sysMpiSpam, /** 54 mpiSpam **/ + }; + +int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); + +#endif + +/*** + $Log$ + Revision 1.2 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.3 2006/12/19 14:12:54 reddawg + rtld-elf almost workign + + Revision 1.2 2006/10/12 17:05:44 reddawg + Removing SDE + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:56 reddawg + no message + + Revision 1.5 2005/08/04 22:48:39 fsdfs + + added 4 new syscalls: sysAuth(), sysPasswd(), sysAddModule(), sysRmModule() + + Revision 1.4 2004/05/26 15:39:22 reddawg + mpi: brought mpiDestroyMbox(char *name) in to the userland + + Revision 1.3 2004/05/25 15:42:19 reddawg + Enabled mpiSpam(); + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/syscalls_new.h b/include/ubixos/syscalls_new.h new file mode 100644 index 0000000..9008e43 --- /dev/null +++ b/include/ubixos/syscalls_new.h @@ -0,0 +1,532 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSCALLS_NEW_H +#define _SYSCALLS_NEW_H + +#include + +int sysExit(); +int getpid(); +int fcntl(); +int issetugid(); +int __sysctl(); +int pipe(); +int readlink(); +int getuid(); +int getgid(); +int mmap(); +int obreak(); +int sigaction(); +int getdtablesize(); +int munmap(); +int sigprocmask(); +int gettimeofday_new(); +int stat(); +int fstat(); +int lstat(); +int ioctl(); + +#define invalid_call 0x0 +#define PSL_C 0x00000001 /* carry bit */ +#define EJUSTRETURN (-2) /* don't modify regs, just return */ +#define ERESTART (-1) /* restart syscall */ + +typedef int (*functionPTR)(); + +/*! + * \brief Mast System Call List + */ +functionPTR systemCalls_new[] = { + invalid_call, /** 0 **/ + sysExit, /** 1 **/ + fork, /** 2 **/ + read, /** 3 **/ + write, /** 4 **/ + open, /** 5 **/ + close, /** 6 **/ + invalid_call, /** 7 **/ + invalid_call, /** 8 **/ + invalid_call, /** 9 **/ + invalid_call, /** 10 **/ + invalid_call, /** 11 **/ + invalid_call, /** 12 **/ + invalid_call, /** 13 **/ + invalid_call, /** 14 **/ + invalid_call, /** 15 **/ + invalid_call, /** 16 **/ + obreak, /** 17 **/ + invalid_call, /** 18 **/ + invalid_call, /** 19 **/ + getpid, /** 20 **/ + invalid_call, /** 21 **/ + invalid_call, /** 22 **/ + invalid_call, /** 23 **/ + getuid, /** 24 **/ + invalid_call, /** 25 **/ + invalid_call, /** 26 **/ + invalid_call, /** 27 **/ + invalid_call, /** 28 **/ + invalid_call, /** 29 **/ + invalid_call, /** 30 **/ + invalid_call, /** 31 **/ + invalid_call, /** 32 **/ + access, /** 33 **/ + invalid_call, /** 34 **/ + invalid_call, /** 35 **/ + invalid_call, /** 36 **/ + invalid_call, /** 37 **/ + invalid_call, /** 38 **/ + invalid_call, /** 39 **/ + invalid_call, /** 40 **/ + invalid_call, /** 41 **/ + pipe, /** 42 **/ + invalid_call, /** 43 **/ + invalid_call, /** 44 **/ + invalid_call, /** 45 **/ + invalid_call, /** 46 **/ + getgid, /** 47 **/ + invalid_call, /** 48 **/ + invalid_call, /** 49 **/ + invalid_call, /** 50 **/ + invalid_call, /** 51 **/ + invalid_call, /** 52 **/ + invalid_call, /** 53 **/ + ioctl, /** 54 **/ + invalid_call, /** 55 **/ + invalid_call, /** 56 **/ + invalid_call, /** 57 **/ + readlink, /** 58 **/ + invalid_call, /** 59 **/ + invalid_call, /** 60 **/ + invalid_call, /** 61 **/ + invalid_call, /** 62 **/ + invalid_call, /** 63 **/ + invalid_call, /** 64 **/ + invalid_call, /** 65 **/ + invalid_call, /** 66 **/ + invalid_call, /** 67 **/ + invalid_call, /** 68 **/ + invalid_call, /** 69 **/ + invalid_call, /** 70 **/ + invalid_call, /** 71 **/ + invalid_call, /** 72 **/ + munmap, /** 73 **/ + mprotect, /** 74 **/ + invalid_call, /** 75 **/ + invalid_call, /** 76 **/ + invalid_call, /** 77 **/ + invalid_call, /** 78 **/ + invalid_call, /** 79 **/ + invalid_call, /** 80 **/ + invalid_call, /** 81 **/ + invalid_call, /** 82 **/ + setitimer, /** 83 **/ + invalid_call, /** 84 **/ + invalid_call, /** 85 **/ + invalid_call, /** 86 **/ + invalid_call, /** 87 **/ + invalid_call, /** 88 **/ + getdtablesize, /** 89 **/ + invalid_call, /** 90 **/ + invalid_call, /** 91 **/ + fcntl, /** 92 **/ + invalid_call, /** 93 **/ + invalid_call, /** 94 **/ + invalid_call, /** 95 **/ + invalid_call, /** 96 **/ + invalid_call, /** 97 **/ + invalid_call, /** 98 **/ + invalid_call, /** 99 **/ + invalid_call, /** 100 **/ + invalid_call, /** 101 **/ + invalid_call, /** 102 **/ + invalid_call, /** 103 **/ + invalid_call, /** 104 **/ + invalid_call, /** 105 **/ + invalid_call, /** 106 **/ + invalid_call, /** 107 **/ + invalid_call, /** 108 **/ + invalid_call, /** 109 **/ + invalid_call, /** 110 **/ + invalid_call, /** 111 **/ + invalid_call, /** 112 **/ + invalid_call, /** 113 **/ + invalid_call, /** 114 **/ + invalid_call, /** 115 **/ + gettimeofday_new, /** 116 **/ + invalid_call, /** 117 **/ + invalid_call, /** 118 **/ + invalid_call, /** 119 **/ + invalid_call, /** 120 **/ + invalid_call, /** 121 **/ + invalid_call, /** 122 **/ + invalid_call, /** 123 **/ + invalid_call, /** 124 **/ + invalid_call, /** 125 **/ + invalid_call, /** 126 **/ + invalid_call, /** 127 **/ + invalid_call, /** 128 **/ + invalid_call, /** 129 **/ + invalid_call, /** 130 **/ + invalid_call, /** 131 **/ + invalid_call, /** 132 **/ + invalid_call, /** 133 **/ + invalid_call, /** 134 **/ + invalid_call, /** 135 **/ + invalid_call, /** 136 **/ + invalid_call, /** 137 **/ + invalid_call, /** 138 **/ + invalid_call, /** 139 **/ + invalid_call, /** 140 **/ + invalid_call, /** 141 **/ + invalid_call, /** 142 **/ + invalid_call, /** 143 **/ + invalid_call, /** 144 **/ + invalid_call, /** 145 **/ + invalid_call, /** 146 **/ + invalid_call, /** 147 **/ + invalid_call, /** 148 **/ + invalid_call, /** 149 **/ + invalid_call, /** 150 **/ + invalid_call, /** 151 **/ + invalid_call, /** 152 **/ + invalid_call, /** 153 **/ + invalid_call, /** 154 **/ + invalid_call, /** 155 **/ + invalid_call, /** 156 **/ + invalid_call, /** 157 **/ + invalid_call, /** 158 **/ + invalid_call, /** 159 **/ + invalid_call, /** 160 **/ + invalid_call, /** 161 **/ + invalid_call, /** 162 **/ + invalid_call, /** 163 **/ + invalid_call, /** 164 **/ + invalid_call, /** 165 **/ + invalid_call, /** 166 **/ + invalid_call, /** 167 **/ + invalid_call, /** 168 **/ + invalid_call, /** 169 **/ + invalid_call, /** 170 **/ + invalid_call, /** 171 **/ + invalid_call, /** 172 **/ + invalid_call, /** 173 **/ + invalid_call, /** 174 **/ + invalid_call, /** 175 **/ + invalid_call, /** 176 **/ + invalid_call, /** 177 **/ + invalid_call, /** 178 **/ + invalid_call, /** 179 **/ + invalid_call, /** 180 **/ + invalid_call, /** 181 **/ + invalid_call, /** 182 **/ + invalid_call, /** 183 **/ + invalid_call, /** 184 **/ + invalid_call, /** 185 **/ + invalid_call, /** 186 **/ + invalid_call, /** 187 **/ + stat, /** 188 **/ + fstat, /** 189 **/ + lstat, /** 190 **/ + invalid_call, /** 191 **/ + invalid_call, /** 192 **/ + invalid_call, /** 193 **/ + invalid_call, /** 194 **/ + invalid_call, /** 195 **/ + invalid_call, /** 196 **/ + mmap, /** 197 **/ + invalid_call, /** 198 **/ + lseek, /** 199 **/ + invalid_call, /** 200 **/ + invalid_call, /** 201 **/ + __sysctl, /** 202 **/ + invalid_call, /** 203 **/ + invalid_call, /** 204 **/ + invalid_call, /** 205 **/ + invalid_call, /** 206 **/ + invalid_call, /** 207 **/ + invalid_call, /** 208 **/ + invalid_call, /** 209 **/ + invalid_call, /** 210 **/ + invalid_call, /** 211 **/ + invalid_call, /** 212 **/ + invalid_call, /** 213 **/ + invalid_call, /** 214 **/ + invalid_call, /** 215 **/ + invalid_call, /** 216 **/ + invalid_call, /** 217 **/ + invalid_call, /** 218 **/ + invalid_call, /** 219 **/ + invalid_call, /** 220 **/ + invalid_call, /** 221 **/ + invalid_call, /** 222 **/ + invalid_call, /** 223 **/ + invalid_call, /** 224 **/ + invalid_call, /** 225 **/ + invalid_call, /** 226 **/ + invalid_call, /** 227 **/ + invalid_call, /** 228 **/ + invalid_call, /** 229 **/ + invalid_call, /** 230 **/ + invalid_call, /** 231 **/ + invalid_call, /** 232 **/ + invalid_call, /** 233 **/ + invalid_call, /** 234 **/ + invalid_call, /** 235 **/ + invalid_call, /** 236 **/ + invalid_call, /** 237 **/ + invalid_call, /** 238 **/ + invalid_call, /** 239 **/ + invalid_call, /** 240 **/ + invalid_call, /** 241 **/ + invalid_call, /** 242 **/ + invalid_call, /** 243 **/ + invalid_call, /** 244 **/ + invalid_call, /** 245 **/ + invalid_call, /** 246 **/ + invalid_call, /** 247 **/ + invalid_call, /** 248 **/ + invalid_call, /** 249 **/ + invalid_call, /** 250 **/ + invalid_call, /** 251 **/ + invalid_call, /** 252 **/ + issetugid, /** 253 **/ + invalid_call, /** 254 **/ + invalid_call, /** 255 **/ + invalid_call, /** 256 **/ + invalid_call, /** 257 **/ + invalid_call, /** 258 **/ + invalid_call, /** 259 **/ + invalid_call, /** 260 **/ + invalid_call, /** 261 **/ + invalid_call, /** 262 **/ + invalid_call, /** 263 **/ + invalid_call, /** 264 **/ + invalid_call, /** 265 **/ + invalid_call, /** 266 **/ + invalid_call, /** 267 **/ + invalid_call, /** 268 **/ + invalid_call, /** 269 **/ + invalid_call, /** 270 **/ + invalid_call, /** 271 **/ + invalid_call, /** 272 **/ + invalid_call, /** 273 **/ + invalid_call, /** 274 **/ + invalid_call, /** 275 **/ + invalid_call, /** 276 **/ + invalid_call, /** 277 **/ + invalid_call, /** 278 **/ + invalid_call, /** 279 **/ + invalid_call, /** 280 **/ + invalid_call, /** 281 **/ + invalid_call, /** 282 **/ + invalid_call, /** 283 **/ + invalid_call, /** 284 **/ + invalid_call, /** 285 **/ + invalid_call, /** 286 **/ + invalid_call, /** 287 **/ + invalid_call, /** 288 **/ + invalid_call, /** 289 **/ + invalid_call, /** 290 **/ + invalid_call, /** 291 **/ + invalid_call, /** 292 **/ + invalid_call, /** 293 **/ + invalid_call, /** 294 **/ + invalid_call, /** 295 **/ + invalid_call, /** 296 **/ + invalid_call, /** 297 **/ + invalid_call, /** 298 **/ + invalid_call, /** 299 **/ + invalid_call, /** 300 **/ + invalid_call, /** 301 **/ + invalid_call, /** 302 **/ + invalid_call, /** 303 **/ + invalid_call, /** 304 **/ + invalid_call, /** 305 **/ + invalid_call, /** 306 **/ + invalid_call, /** 307 **/ + invalid_call, /** 308 **/ + invalid_call, /** 309 **/ + invalid_call, /** 310 **/ + invalid_call, /** 311 **/ + invalid_call, /** 312 **/ + invalid_call, /** 313 **/ + invalid_call, /** 314 **/ + invalid_call, /** 315 **/ + invalid_call, /** 316 **/ + invalid_call, /** 317 **/ + invalid_call, /** 318 **/ + invalid_call, /** 319 **/ + invalid_call, /** 320 **/ + invalid_call, /** 321 **/ + invalid_call, /** 322 **/ + invalid_call, /** 323 **/ + invalid_call, /** 324 **/ + invalid_call, /** 325 **/ + invalid_call, /** 326 **/ + invalid_call, /** 327 **/ + invalid_call, /** 328 **/ + invalid_call, /** 329 **/ + invalid_call, /** 330 **/ + invalid_call, /** 331 **/ + invalid_call, /** 332 **/ + invalid_call, /** 333 **/ + invalid_call, /** 334 **/ + invalid_call, /** 335 **/ + invalid_call, /** 336 **/ + invalid_call, /** 337 **/ + invalid_call, /** 338 **/ + invalid_call, /** 339 **/ + sigprocmask, /** 340 **/ + invalid_call, /** 341 **/ + invalid_call, /** 342 **/ + invalid_call, /** 343 **/ + invalid_call, /** 344 **/ + invalid_call, /** 345 **/ + invalid_call, /** 346 **/ + invalid_call, /** 347 **/ + invalid_call, /** 348 **/ + invalid_call, /** 349 **/ + invalid_call, /** 350 **/ + invalid_call, /** 351 **/ + invalid_call, /** 352 **/ + invalid_call, /** 353 **/ + invalid_call, /** 354 **/ + invalid_call, /** 355 **/ + invalid_call, /** 356 **/ + invalid_call, /** 357 **/ + invalid_call, /** 358 **/ + invalid_call, /** 359 **/ + invalid_call, /** 360 **/ + invalid_call, /** 361 **/ + invalid_call, /** 362 **/ + invalid_call, /** 363 **/ + invalid_call, /** 364 **/ + invalid_call, /** 365 **/ + invalid_call, /** 366 **/ + invalid_call, /** 367 **/ + invalid_call, /** 368 **/ + invalid_call, /** 369 **/ + invalid_call, /** 370 **/ + invalid_call, /** 371 **/ + invalid_call, /** 372 **/ + invalid_call, /** 373 **/ + invalid_call, /** 374 **/ + invalid_call, /** 375 **/ + invalid_call, /** 376 **/ + invalid_call, /** 377 **/ + invalid_call, /** 378 **/ + invalid_call, /** 379 **/ + invalid_call, /** 380 **/ + invalid_call, /** 381 **/ + invalid_call, /** 382 **/ + invalid_call, /** 383 **/ + invalid_call, /** 384 **/ + invalid_call, /** 385 **/ + invalid_call, /** 386 **/ + invalid_call, /** 387 **/ + invalid_call, /** 388 **/ + invalid_call, /** 389 **/ + invalid_call, /** 390 **/ + invalid_call, /** 391 **/ + invalid_call, /** 392 **/ + invalid_call, /** 393 **/ + invalid_call, /** 394 **/ + invalid_call, /** 395 **/ + invalid_call, /** 396 **/ + fstatfs, /** 397 **/ + invalid_call, /** 398 **/ + invalid_call, /** 399 **/ + invalid_call, /** 400 **/ + invalid_call, /** 401 **/ + invalid_call, /** 402 **/ + invalid_call, /** 403 **/ + invalid_call, /** 404 **/ + invalid_call, /** 405 **/ + invalid_call, /** 406 **/ + invalid_call, /** 407 **/ + invalid_call, /** 408 **/ + invalid_call, /** 409 **/ + invalid_call, /** 410 **/ + invalid_call, /** 411 **/ + invalid_call, /** 412 **/ + invalid_call, /** 413 **/ + invalid_call, /** 414 **/ + invalid_call, /** 415 **/ + sigaction, /** 416 **/ + invalid_call, /** 417 **/ + invalid_call, /** 418 **/ + invalid_call, /** 419 **/ + invalid_call, /** 420 **/ + invalid_call, /** 421 **/ + invalid_call, /** 422 **/ + invalid_call, /** 423 **/ + invalid_call, /** 424 **/ + invalid_call, /** 425 **/ + invalid_call, /** 426 **/ + invalid_call, /** 427 **/ + invalid_call, /** 428 **/ + invalid_call, /** 429 **/ + invalid_call, /** 430 **/ + invalid_call, /** 431 **/ + invalid_call, /** 432 **/ + invalid_call, /** 433 **/ + invalid_call, /** 434 **/ + invalid_call, /** 435 **/ + invalid_call, /** 436 **/ + invalid_call, /** 437 **/ + invalid_call, /** 438 **/ + invalid_call, /** 439 **/ + invalid_call, /** 440 **/ + invalid_call, /** 441 **/ + invalid_call, /** 442 **/ + invalid_call, /** 443 **/ + invalid_call, /** 444 **/ + invalid_call, /** 445 **/ + invalid_call, /** 446 **/ + invalid_call, /** 447 **/ + invalid_call, /** 448 **/ + invalid_call, /** 449 **/ + invalid_call, /** 450 **/ + invalid_call, /** 451 **/ + invalid_call, /** 452 **/ + invalid_call, /** 453 **/ + invalid_call, /** 454 **/ + invalid_call, /** 455 **/ + }; + +int totalCalls_new = sizeof(systemCalls_new)/sizeof(functionPTR); + +#endif + +/*** + END + ***/ + diff --git a/include/ubixos/systemtask.h b/include/ubixos/systemtask.h new file mode 100644 index 0000000..1ab2778 --- /dev/null +++ b/include/ubixos/systemtask.h @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSTEMTASK_H +#define _SYSTEMTASK_H + +#include + +void systemTask(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:56 reddawg + no message + + Revision 1.2 2004/06/04 17:49:32 reddawg + Wont work with out the makefile updated + + Revision 1.1 2004/06/04 17:33:33 reddawg + Changed idle task to system task + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/time.h b/include/ubixos/time.h new file mode 100644 index 0000000..7762767 --- /dev/null +++ b/include/ubixos/time.h @@ -0,0 +1,111 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TIME_H +#define _TIME_H + +#include +#include + +typedef long suseconds_t; + +#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) + +#define MINUTE 60 +#define HOUR (60*MINUTE) +#define DAY (24*HOUR) +#define YEAR (365*DAY) + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + + + +struct timeStruct { + int sec; + int min; + int hour; + int day; + int mon; + int year; + }; + + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ + }; + +struct timeval { + long tv_sec; /* seconds (XXX should be time_t) */ + suseconds_t tv_usec; /* and microseconds */ + }; + +int gettimeofday(struct timeval *tp,struct timezone *tzp); + + + +int time_init(); +uInt32 timeMake(struct timeStruct *time); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:56 reddawg + no message + + Revision 1.4 2004/07/09 13:37:30 reddawg + time: timeInit to time_init + Adjusted initialization routines + + Revision 1.3 2004/06/29 11:41:44 reddawg + Fixed some global variables + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + END + ***/ diff --git a/include/ubixos/times.h b/include/ubixos/times.h new file mode 100644 index 0000000..9360513 --- /dev/null +++ b/include/ubixos/times.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TIMES_H +#define _TIMES_H + +#include +#include + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:57 reddawg + no message + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/tty.h b/include/ubixos/tty.h new file mode 100644 index 0000000..178a999 --- /dev/null +++ b/include/ubixos/tty.h @@ -0,0 +1,59 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TTY_H +#define _TTY_H + +#include + +#define TTY_MAX_TERMS 12 + +typedef struct tty_termNode { + char *tty_buffer; + char *tty_pointer; + uInt8 tty_colour; + uInt16 tty_x; + uInt16 tty_y; + pidType owner; + char stdin[512]; + int stdinSize; + } tty_term; + +int tty_init(); +int tty_change(uInt16); +tty_term *tty_find(u_int16_t tty); +int tty_print(char *,tty_term *); + +extern tty_term *tty_foreground; + +#endif + +/*** + END + ***/ diff --git a/include/ubixos/types.h b/include/ubixos/types.h new file mode 100644 index 0000000..f5a7344 --- /dev/null +++ b/include/ubixos/types.h @@ -0,0 +1,118 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TYPES_H +#define _TYPES_H + +#include + +#ifndef NULL +#define NULL 0x0 +#endif + +typedef unsigned char uInt8; +typedef unsigned short uInt16; +typedef unsigned int uInt32; +typedef unsigned int uInt; +typedef char Int8; +typedef short Int16; +typedef long Int32; + +typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; +//typedef long long int quad_t; +typedef __uint64_t quad_t; + +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + + +typedef int pidType; + +typedef int pid_t; +typedef int size_t; /* standart */ + +#ifndef NOBOOL +#ifndef __cplusplus +typedef enum { FALSE=0,TRUE=1 } bool; +#endif +#endif + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; /* inode number */ +#define _INO_T_DECLARED +#endif + +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif + +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif + +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif + +typedef __ssize_t ssize_t; +typedef char * caddr_t; +typedef __int64_t off_t; +typedef __uint32_t vm_offset_t; + +typedef __uid_t uid_t; /* user id */ +typedef __gid_t gid_t; /* group id */ +typedef __blkcnt_t blkcnt_t; +typedef __blksize_t blksize_t; +typedef __fflags_t fflags_t; + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + + +#endif + +/*** + END + ***/ + diff --git a/include/ubixos/ubthread.h b/include/ubixos/ubthread.h new file mode 100644 index 0000000..dc24b17 --- /dev/null +++ b/include/ubixos/ubthread.h @@ -0,0 +1,113 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _UBTHREAD_H +#define _UBTHREAD_H + +#include +#include +#include + +#define ETIMEDOUT -1 + +#define LOCKED 1 +#define UNLOCKED 0 + +typedef struct ubthread *ubthread_t; +typedef struct ubthread_cond *ubthread_cond_t; +typedef struct ubthread_mutex *ubthread_mutex_t; + +struct ubthread { + kTask_t *task; + }; + +struct ubthread_cond { + int id; + uInt8 locked; + }; + +struct ubthread_mutex { + int id; + uInt8 locked; + pidType pid; + }; + +struct ubthread_list { + struct ubthread_list *next; + ubthread_t thread; + }; + +struct ubthread_cond_list { + struct ubthread_cond_list *next; + ubthread_cond_t *cond; + }; + +struct ubthread_mutex_list { + struct ubthread_mutex_list *next; + ubthread_mutex_t *mutex; + }; + + +kTask_t *ubthread_self(); +int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr); +int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr); +int ubthread_cond_destroy(ubthread_cond_t *cond); +int ubthread_mutex_destroy(ubthread_mutex_t *mutex); +int ubthread_create(kTask_t **thread,const uInt32 *attr,void (* tproc)(void), void *arg); +int ubthread_mutex_lock(ubthread_mutex_t *mutex); +int ubthread_mutex_unlock(ubthread_mutex_t *mutex); +int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime); +int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex); +int ubthread_cond_signal(ubthread_cond_t *cond); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:14 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:23:57 reddawg + no message + + Revision 1.3 2004/09/07 20:58:35 reddawg + time to roll back i can't think straight by friday + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/include/ubixos/vitals.h b/include/ubixos/vitals.h new file mode 100644 index 0000000..dae04f0 --- /dev/null +++ b/include/ubixos/vitals.h @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VITALS_H +#define _VITALS_H + +//#include +#include +//#include +#include + +typedef struct vitalsStruct { + uInt32 openFiles; + uInt32 sysTicks; + uInt32 sysUptime; + uInt32 quantum; + uInt32 dQuantum; + uInt32 freePages; + struct fileSystem *fileSystems; + struct vfs_mountPoint *mountPoints; + uInt32 timeStart; + void *screen; + void *font; + char *packet; + uInt32 packetLength; + } vitalsNode; + +extern vitalsNode *systemVitals; + +int vitals_init(); + +#endif + +/*** + END + ***/ diff --git a/include/ufs/ffs.h b/include/ufs/ffs.h new file mode 100644 index 0000000..bb14acf --- /dev/null +++ b/include/ufs/ffs.h @@ -0,0 +1,45 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _FFS_H +#define _FFS_H + +#include +#include +#include +#include + +int ffs_read(struct file *,char *,uInt32,long); + +#endif + +/*** + END + ***/ + diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h new file mode 100644 index 0000000..4a409f2 --- /dev/null +++ b/include/ufs/ufs.h @@ -0,0 +1,309 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _UFS_H +#define _UFS_H + +#include +#include +#include +#include + + +#define DT_REG 8 +#define MAXNAMLEN 255 +#define ROOTINO ((ino_t)2) +#define DT_DIR 4 +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#define DEV_BSIZE (1<fs_nindir) + +/* + * Cylinder group macros to locate things in cylinder groups. + * They calc filesystem addresses of cylinder group data structures. + */ +#define cgbase(fs, c) (((ufs2_daddr_t)(fs)->fs_fpg) * (c)) +#define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */ +#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ +#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */ +#define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */ +#define cgstart(fs, c) \ + ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) : \ + (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask)))) + + +#define fsbtodb(fs, b) ((daddr_t)(b) << (fs)->fs_fsbtodb) +#define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb) + +/* + * Macros for handling inode numbers: + * inode number to filesystem block offset. + * inode number to cylinder group number. + * inode number to filesystem block address. + */ +#define ino_to_cg(fs, x) ((x) / (fs)->fs_ipg) +#define ino_to_fsba(fs, x) \ + ((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) + \ + (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs)))))) +#define ino_to_fsbo(fs, x) ((x) % INOPB(fs)) + + +#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ + ((loc) & (fs)->fs_qbmask) +#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ + ((loc) >> (fs)->fs_bshift) +#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ + (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) + + +#define sblksize(fs, size, lbn) \ + (((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \ + ? (fs)->fs_bsize \ + : (fragroundup(fs, blkoff(fs, (size))))) + + + + +typedef int32_t ufs1_daddr_t; +typedef int64_t ufs2_daddr_t; +typedef int64_t ufs_lbn_t; +typedef int64_t ufs_time_t; +typedef __int64_t daddr_t; + +struct dirent { + __uint32_t d_fileno; /* file number of entry */ + __uint16_t d_reclen; /* length of this record */ + __uint8_t d_type; /* file type, see below */ + __uint8_t d_namlen; /* length of string in d_name */ + char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ + }; + +#define NXADDR 2 /* External addresses in inode. */ +#define NDADDR 12 /* Direct addresses in inode. */ +#define NIADDR 3 /* Indirect addresses in inode. */ + +struct ufs2_dinode { + u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ + int16_t di_nlink; /* 2: File link count. */ + u_int32_t di_uid; /* 4: File owner. */ + u_int32_t di_gid; /* 8: File group. */ + u_int32_t di_blksize; /* 12: Inode blocksize. */ + u_int64_t di_size; /* 16: File byte count. */ + u_int64_t di_blocks; /* 24: Bytes actually held. */ + ufs_time_t di_atime; /* 32: Last access time. */ + ufs_time_t di_mtime; /* 40: Last modified time. */ + ufs_time_t di_ctime; /* 48: Last inode change time. */ + ufs_time_t di_birthtime; /* 56: Inode creation time. */ + int32_t di_mtimensec; /* 64: Last modified time. */ + int32_t di_atimensec; /* 68: Last access time. */ + int32_t di_ctimensec; /* 72: Last inode change time. */ + int32_t di_birthnsec; /* 76: Inode creation time. */ + int32_t di_gen; /* 80: Generation number. */ + u_int32_t di_kernflags; /* 84: Kernel flags. */ + u_int32_t di_flags; /* 88: Status flags (chflags). */ + int32_t di_extsize; /* 92: External attributes block. */ + ufs2_daddr_t di_extb[NXADDR];/* 96: External attributes block. */ + ufs2_daddr_t di_db[NDADDR]; /* 112: Direct disk blocks. */ + ufs2_daddr_t di_ib[NIADDR]; /* 208: Indirect disk blocks. */ + int64_t di_spare[3]; /* 232: Reserved; currently unused */ + }; + +struct ufs1_dinode { + u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ + int16_t di_nlink; /* 2: File link count. */ + union { + u_int16_t oldids[2]; /* 4: Ffs: old user and group ids. */ + } di_u; + u_int64_t di_size; /* 8: File byte count. */ + int32_t di_atime; /* 16: Last access time. */ + int32_t di_atimensec; /* 20: Last access time. */ + int32_t di_mtime; /* 24: Last modified time. */ + int32_t di_mtimensec; /* 28: Last modified time. */ + int32_t di_ctime; /* 32: Last inode change time. */ + int32_t di_ctimensec; /* 36: Last inode change time. */ + ufs1_daddr_t di_db[NDADDR]; /* 40: Direct disk blocks. */ + ufs1_daddr_t di_ib[NIADDR]; /* 88: Indirect disk blocks. */ + u_int32_t di_flags; /* 100: Status flags (chflags). */ + int32_t di_blocks; /* 104: Blocks actually held. */ + int32_t di_gen; /* 108: Generation number. */ + u_int32_t di_uid; /* 112: File owner. */ + u_int32_t di_gid; /* 116: File group. */ + int32_t di_spare[2]; /* 120: Reserved; currently unused */ + }; + +struct csum { + int32_t cs_ndir; /* number of directories */ + int32_t cs_nbfree; /* number of free blocks */ + int32_t cs_nifree; /* number of free inodes */ + int32_t cs_nffree; /* number of free frags */ +}; +struct csum_total { + int64_t cs_ndir; /* number of directories */ + int64_t cs_nbfree; /* number of free blocks */ + int64_t cs_nifree; /* number of free inodes */ + int64_t cs_nffree; /* number of free frags */ + int64_t cs_numclusters; /* number of free clusters */ + int64_t cs_spare[3]; /* future expansion */ +}; + + +struct fs { + int32_t fs_firstfield; /* historic filesystem linked list, */ + int32_t fs_unused_1; /* used for incore super blocks */ + int32_t fs_sblkno; /* offset of super-block in filesys */ + int32_t fs_cblkno; /* offset of cyl-block in filesys */ + int32_t fs_iblkno; /* offset of inode-blocks in filesys */ + int32_t fs_dblkno; /* offset of first data after cg */ + int32_t fs_old_cgoffset; /* cylinder group offset in cylinder */ + int32_t fs_old_cgmask; /* used to calc mod fs_ntrak */ + int32_t fs_old_time; /* last time written */ + int32_t fs_old_size; /* number of blocks in fs */ + int32_t fs_old_dsize; /* number of data blocks in fs */ + int32_t fs_ncg; /* number of cylinder groups */ + int32_t fs_bsize; /* size of basic blocks in fs */ + int32_t fs_fsize; /* size of frag blocks in fs */ + int32_t fs_frag; /* number of frags in a block in fs */ +/* these are configuration parameters */ + int32_t fs_minfree; /* minimum percentage of free blocks */ + int32_t fs_old_rotdelay; /* num of ms for optimal next block */ + int32_t fs_old_rps; /* disk revolutions per second */ +/* these fields can be computed from the others */ + int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */ + int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */ + int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */ + int32_t fs_fshift; /* ``numfrags'' calc number of frags */ +/* these are configuration parameters */ + int32_t fs_maxcontig; /* max number of contiguous blks */ + int32_t fs_maxbpg; /* max number of blks per cyl group */ +/* these fields can be computed from the others */ + int32_t fs_fragshift; /* block to frag shift */ + int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ + int32_t fs_sbsize; /* actual size of super block */ + int32_t fs_spare1[2]; /* old fs_csmask */ + /* old fs_csshift */ + int32_t fs_nindir; /* value of NINDIR */ + int32_t fs_inopb; /* value of INOPB */ + int32_t fs_old_nspf; /* value of NSPF */ +/* yet another configuration parameter */ + int32_t fs_optim; /* optimization preference, see below */ + int32_t fs_old_npsect; /* # sectors/track including spares */ + int32_t fs_old_interleave; /* hardware sector interleave */ + int32_t fs_old_trackskew; /* sector 0 skew, per track */ + int32_t fs_id[2]; /* unique filesystem id */ +/* sizes determined by number of cylinder groups and their sizes */ + int32_t fs_old_csaddr; /* blk addr of cyl grp summary area */ + int32_t fs_cssize; /* size of cyl grp summary area */ + int32_t fs_cgsize; /* cylinder group size */ + int32_t fs_spare2; /* old fs_ntrak */ + int32_t fs_old_nsect; /* sectors per track */ + int32_t fs_old_spc; /* sectors per cylinder */ + int32_t fs_old_ncyl; /* cylinders in filesystem */ + int32_t fs_old_cpg; /* cylinders per group */ + int32_t fs_ipg; /* inodes per group */ + int32_t fs_fpg; /* blocks per group * fs_frag */ +/* this data must be re-computed after crashes */ + struct csum fs_old_cstotal; /* cylinder summary information */ +/* these fields are cleared at mount time */ + int8_t fs_fmod; /* super block modified flag */ + int8_t fs_clean; /* filesystem is clean flag */ + int8_t fs_ronly; /* mounted read-only flag */ + int8_t fs_old_flags; /* old FS_ flags */ + u_char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ + u_char fs_volname[MAXVOLLEN]; /* volume name */ + u_int64_t fs_swuid; /* system-wide uid */ + int32_t fs_pad; /* due to alignment of fs_swuid */ +/* these fields retain the current block allocation info */ + int32_t fs_cgrotor; /* last cg searched */ + void *fs_ocsp[NOCSPTRS]; /* padding; was list of fs_cs buffers */ + u_int8_t *fs_contigdirs; /* (u) # of contig. allocated dirs */ + struct csum *fs_csp; /* (u) cg summary info buffer */ + int32_t *fs_maxcluster; /* (u) max cluster in each cyl group */ + u_int *fs_active; /* (u) used by snapshots to track fs */ + int32_t fs_old_cpc; /* cyl per cycle in postbl */ + int32_t fs_maxbsize; /* maximum blocking factor permitted */ + int64_t fs_sparecon64[17]; /* old rotation block list head */ + int64_t fs_sblockloc; /* byte offset of standard superblock */ + struct csum_total fs_cstotal; /* (u) cylinder summary information */ + ufs_time_t fs_time; /* last time written */ + int64_t fs_size; /* number of blocks in fs */ + int64_t fs_dsize; /* number of data blocks in fs */ + ufs2_daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ + int64_t fs_pendingblocks; /* (u) blocks being freed */ + int32_t fs_pendinginodes; /* (u) inodes being freed */ + int32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */ + int32_t fs_avgfilesize; /* expected average file size */ + int32_t fs_avgfpdir; /* expected # of files per directory */ + int32_t fs_save_cgsize; /* save real cg size to use fs_bsize */ + int32_t fs_sparecon32[26]; /* reserved for future constants */ + int32_t fs_flags; /* see FS_ flags below */ + int32_t fs_contigsumsize; /* size of cluster summary array */ + int32_t fs_maxsymlinklen; /* max length of an internal symlink */ + int32_t fs_old_inodefmt; /* format of on-disk inodes */ + u_int64_t fs_maxfilesize; /* maximum representable file size */ + int64_t fs_qbmask; /* ~fs_bmask for use with 64-bit size */ + int64_t fs_qfmask; /* ~fs_fmask for use with 64-bit size */ + int32_t fs_state; /* validate fs_clean field */ + int32_t fs_old_postblformat; /* format of positional layout tables */ + int32_t fs_old_nrpos; /* number of rotational positions */ + int32_t fs_spare5[2]; /* old fs_postbloff */ + /* old fs_rotbloff */ + int32_t fs_magic; /* magic number */ +}; + +struct ufs_obj { + u_int32_t ino; + struct cacheNode *cacheNode; + struct dmadat *dmadat; + int dsk_meta; + u_int32_t resid; + }; + +int ufs_init(); +int ufs_initialize(); + +#endif + +/*** + END + ***/ + diff --git a/include/vfs/file.h b/include/vfs/file.h new file mode 100644 index 0000000..e18a1a5 --- /dev/null +++ b/include/vfs/file.h @@ -0,0 +1,85 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#ifndef _FILE_H +#define _FILE_H + +#include +#include +#include + +#define VBLKSHIFT 12 +#define VBLKSIZE (1 << VBLKSHIFT) +#define SBLOCKSIZE 8192 +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#define DEV_BSIZE (1< + +typedef struct userFileDescriptorStruct { + struct file *fd; + uInt32 fdSize; + } userFileDescriptor; + +extern fileDescriptor *fdTable; + +struct file *fopen(struct file *,const char *,const char *); +int fclose(struct file *); + +/* UBU */ + + +int unlink(const char *path); +int feof(struct file *fd); +int fgetc(struct file *fd); +size_t fread(void *ptr,size_t size,size_t nmemb,struct file *fd); +size_t fwrite(void *ptr,int size,int nmemb,struct file *fd); +int fseek(struct file *,long,int); + +void sysFseek(userFileDescriptor *,long,int); + +//Good +void sysChDir(const char *path); +void chDir(const char *path); +char *verifyDir(const char *path); + +#endif diff --git a/include/vfs/mount.h b/include/vfs/mount.h new file mode 100644 index 0000000..eede504 --- /dev/null +++ b/include/vfs/mount.h @@ -0,0 +1,85 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MOUNT_H +#define _MOUNT_H + +#include + +#define MFSNAMELEN 16 /* length of type name including null */ +#define MNAMELEN 88 /* size of on/from name bufs */ + +typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */ + +struct statfs { + u_int32_t f_version; /* structure version number */ + u_int32_t f_type; /* type of filesystem */ + u_int64_t f_flags; /* copy of mount exported flags */ + u_int64_t f_bsize; /* filesystem fragment size */ + u_int64_t f_iosize; /* optimal transfer block size */ + u_int64_t f_blocks; /* total data blocks in filesystem */ + u_int64_t f_bfree; /* free blocks in filesystem */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + u_int64_t f_files; /* total file nodes in filesystem */ + int64_t f_ffree; /* free nodes avail to non-superuser */ + u_int64_t f_syncwrites; /* count of sync writes since mount */ + u_int64_t f_asyncwrites; /* count of async writes since mount */ + u_int64_t f_syncreads; /* count of sync reads since mount */ + u_int64_t f_asyncreads; /* count of async reads since mount */ + u_int64_t f_spare[10]; /* unused spare */ + u_int32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the filesystem */ + fsid_t f_fsid; /* filesystem id */ + char f_charspare[80]; /* spare string space */ + char f_fstypename[MFSNAMELEN]; /* filesystem type name */ + char f_mntfromname[MNAMELEN]; /* mounted filesystem */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + }; + +struct vfs_mountPoint { + struct vfs_mountPoint *prev; + struct vfs_mountPoint *next; + struct fileSystem *fs; + struct device_node *device; + struct ubixDiskLabel *diskLabel; + void *fsInfo; + int partition; + char mountPoint[1024]; + char perms; + }; + +int vfs_mount(int major,int minor,int partition,int fsType,char *mountPoint,char *perms); +int vfs_addMount(struct vfs_mountPoint *mp); +struct vfs_mountPoint *vfs_findMount(char *mountPoint); + +#endif + +/*** + END + ***/ diff --git a/include/vfs/vfs.h b/include/vfs/vfs.h new file mode 100644 index 0000000..082fc33 --- /dev/null +++ b/include/vfs/vfs.h @@ -0,0 +1,93 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VFS_H +#define _VFS_H + +#include +#include +#include +#include +#include + +#define maxFd 32 +#define fdAvail 1 +#define fdOpen 2 +#define fdRead 3 +#define fdEof 4 + + +#define fileRead 0x0001 +#define fileWrite 0x0002 +#define fileBinary 0x0004 +#define fileAppend 0x0008 + +/* New Stuff */ + +/* whence values for lseek(2) */ +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + + +/*! + \brief filesSystem Structure + + not sure if we should allow function to point to NULL + + We don't as of 1/28/07 +*/ +struct fileSystem { + struct fileSystem *prev; + struct fileSystem *next; + int (*vfsInitFS)(void *); /*!< pointer to inialization routine */ + int (*vfsRead)(void *,char *,long,long); /*!< pointer to read routine */ + int (*vfsWrite)(void *,char *,long,long); /*!< pointer to write routine */ + int (*vfsOpenFile)(void *,void *); /*!< pointer to openfile routine */ + int (*vfsCloseFile)(void *); /*!< pointer to closefile routine */ + int (*vfsUnlink)(char *,void *); /*!< pointer to unlink routine */ + int (*vfsMakeDir)(char *,void *); /*!< pointer to makedir routine */ + int (*vfsRemDir)(char *); /*!< pointer to remdir routine */ + int (*vfsSync)(void); /*!< pointer to sync routine */ + int vfsType; /*!< vfs type id */ + }; + + +/* VFS Functions */ +int vfs_init(); +int vfsRegisterFS(struct fileSystem); +struct fileSystem *vfs_findFS(int); + +#endif + +/*** + END + ***/ diff --git a/include/vmm/paging.h b/include/vmm/paging.h new file mode 100644 index 0000000..3eb6643 --- /dev/null +++ b/include/vmm/paging.h @@ -0,0 +1,96 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PAGING_H +#define _PAGING_H + +#include +#include +#include + +#define VM_THRD 0 +#define VM_TASK 1 + +#define pageLength 0x00000400 +#define pageSize 4096 +#define pageEntries (pageSize/4) +#define tablesBaseAddress 0xBFC00000 +#define parentPageDirAddr 0x100000 +#define PARENT_PAGEDIR_ADDR 0x100000 /* Address at which the page directory is stored */ + +#define PAGE_COW 0x00000200 +#define PAGE_STACK 0x00000400 +#define PAGE_WIRED 0x00000600 +#define PAGE_PRESENT 0x00000001 +#define PAGE_WRITE 0x00000002 +#define PAGE_USER 0x00000004 +#define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER) +#define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE) + +#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ +#define PAGE_SIZE (1<>PAGE_SHIFT) + + +int vmmClearVirtualPage(uInt32 pageAddr); + +void vmmUnmapPage(uInt32,int); +void vmmUnmapPages(void *,uInt32); +void *vmmMapFromTask(pidType,void *,uInt32); +void *vmmCopyVirtualSpace(pidType); +void *vmmGetFreeKernelPage(pidType); +void *vmmGetFreeKernelPage(pidType pid,uInt16 count); +void *vmmCreateVirtualSpace(pidType); +void *vmmGetFreeVirtualPage(pidType,int,int); + +uInt32 vmm_getPhysicalAddr(uInt32); +int vmm_setPageAttributes(uInt32,uInt16); +int vmm_remapPage(uInt32,uInt32,uInt16); +int vmm_pagingInit(); +void *vmm_getFreeMallocPage(uInt16 count); +void vmm_pageFault(uInt32,uInt32,uInt32); +void _vmm_pageFault(); +int mmap(struct thread *,struct mmap_args *); +int obreak(struct thread *,struct obreak_args *); +int munmap(struct thread *,struct munmap_args *); + + +extern uInt32 *kernelPageDirectory; + +#endif + +/*** + END + ***/ + diff --git a/include/vmm/vmm.h b/include/vmm/vmm.h new file mode 100644 index 0000000..dfc8a00 --- /dev/null +++ b/include/vmm/vmm.h @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VMM_H +#define _VMM_H + +#include +#include + +#define memAvail 1 +#define memNotavail 2 +#define vmmID -3 +#define vmmMemoryMapAddr 0xE6667000 + +typedef struct { + uInt32 pageAddr; + uInt16 status; + uInt16 reserved; + pid_t pid; + int cowCounter; + } mMap; + +extern int numPages; +extern mMap *vmmMemoryMap; + +int vmm_init(); +int vmmMemMapInit(); +int countMemory(); +u_int32_t vmmFindFreePage(pidType pid); +int freePage(uInt32 pageAddr); +int adjustCowCounter(uInt32 baseAddr,int adjustment); +void vmmFreeProcessPages(pidType pid); + +#endif + +/*** + END + ***/ diff --git a/init/Makefile b/init/Makefile new file mode 100644 index 0000000..c3c2d99 --- /dev/null +++ b/init/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = start.o main.o static.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/init/main.c b/init/main.c new file mode 100644 index 0000000..95b40f0 --- /dev/null +++ b/init/main.c @@ -0,0 +1,160 @@ +/***************************************************************************************** + Copyright (c) 2002-2004, 2005, 2007, 2008 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define B_ADAPTORSHIFT 24 +#define B_ADAPTORMASK 0x0f +#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK) +#define B_CONTROLLERSHIFT 20 +#define B_CONTROLLERMASK 0xf +#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK) +#define B_SLICESHIFT 20 +#define B_SLICEMASK 0xff +#define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK) +#define B_UNITSHIFT 16 +#define B_UNITMASK 0xf +#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK) +#define B_PARTITIONSHIFT 8 +#define B_PARTITIONMASK 0xff +#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK) +#define B_TYPESHIFT 0 +#define B_TYPEMASK 0xff +#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK) + + +/***************************************************************************************** + Desc: The Kernels Descriptor table: + 0x00 - Dummy Entry + 0x08 - Ring 0 CS + 0x10 - Ring 0 DS + 0x18 - Dummy LDT + 0x20 - Scheduler TSS + 0x28 - Ring 3 CS + 0x30 - Ring 3 DS + 0x38 - GPF TSS + 0x40 - Stack Fault TSS + + Notes: + +*****************************************************************************************/ +ubixDescriptorTable(ubixGDT,9) { + {dummy:0}, + ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), + ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), + ubixStandardDescriptor(0x0000, 0xFFFFF, (dLdt)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)), + ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), + ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), + }; +struct { + unsigned short limit __attribute__ ((packed)); + union descriptorTableUnion *gdt __attribute__ ((packed)); + } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; + +/** + * \brief This is the entry point into the os where all of the kernels sub systems are started up. + * + * \param rootdev address of root device structure + */ +int kmain(uInt32 rootdev) { + /* Set up counter for startup routine */ + int i = 0x0; + uInt32 *sysTask = 0x0; + + /* We preform a clearScreen to make the TEXT buffer nice and empty */ + screenClear(); + + /* Modify src/sys/include/ubixos/init.h to add a startup routine */ + for (i=0x0;ifreePages); + + kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); + kprintf("Starting UbixOS\n"); + + sysTask = kmalloc(0x2000); + if(sysTask == NULL) + kprintf("OS: Unable to allocate memory\n"); + + execThread(systemTask, (uInt32)sysTask+0x2000,0x0); + + execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer */ +// execFile("sys:/bin/login",0x0,0x0,0x1); +// execFile("sys:/bin/login",0x0,0x0,0x2); + + irqEnable(0x0); + + while (0x1) + asm("hlt"); /* Keep haulting until the scheduler reacts */ + + /* Return to start however we should never get this far */ + return(0x0); +} + +/*** + END + ***/ diff --git a/init/start.S b/init/start.S new file mode 100644 index 0000000..1ea5fe0 --- /dev/null +++ b/init/start.S @@ -0,0 +1,75 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +.globl _start +.text +.code32 +_start: + movw $0x1234,0x472 + pushl %ebp + movl %esp,%ebp + pushl $0x00000002 + popfl + /* Clear the BSS */ + movl $(_end),%ecx + movl $(__bss_start),%edi + subl %edi,%ecx + xorl %eax,%eax + cld + rep + stosb + + /* Load GDT */ + lgdtl (loadGDT) + mov $0x10,%eax + mov %eax,%ds + mov %eax,%es + mov %eax,%fs + mov %eax,%gs + mov %eax,%ss + mov $kStack,%eax + addl $0x2000,%eax + mov %esp,%edx + mov %eax,%esp + mov %eax,%ebp + mov $0x18,%ax + lldt %ax + mov $0x20,%ax + ltr %ax + ljmp $0x08,$start_next +start_next: + push 8(%edx) + call kmain + +.data +.comm kStack,0x2000 + +/*** + END + ***/ diff --git a/init/static.c b/init/static.c new file mode 100644 index 0000000..266e42a --- /dev/null +++ b/init/static.c @@ -0,0 +1,51 @@ +/***************************************************************************************** + Copyright (c) 2002-2004, 2007 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +/** + * \brief Sets up the ctors + */ + +int static_constructors(void) { + + extern void (* __ctor_list)(); + void (** l_ctor)() = &__ctor_list; + int l_ctorCount = *(int *)l_ctor; + + l_ctor++; + while(l_ctorCount) { + (*l_ctor)(); + l_ctorCount--; + l_ctor++; + } + return(0x0); + } + +/*** + END + ***/ diff --git a/isa/8259.c b/isa/8259.c new file mode 100644 index 0000000..483bd5d --- /dev/null +++ b/isa/8259.c @@ -0,0 +1,92 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +static unsigned int irqMask = 0xFFFF; + +/*! + * \brief initialize the 8259 PIC + * + * This will initialize both PICs for all of our IRQs + * + */ +int i8259_init() { + outportByte(mPic, icw1); /* Initialize Master PIC */ + outportByte(sPic, icw1); /* Initialize Seconary PIC */ + outportByte(mPic+1, mVec); /* Master Interrup Vector */ + outportByte(sPic+1, sVec); /* Secondary Interrupt Vector */ + outportByte(mPic+1, 1<<2); /* Bitmask for cascade on IRQ 2 */ + outportByte(sPic+1, 2); /* Cascade on IRQ 2 */ + outportByte(mPic+1, icw4); /* Finish Primary Initialization */ + outportByte(sPic+1, icw4); /* Finish Seconary Initialization */ + outportByte(mImr, 0xff); /* Mask All Primary Interrupts */ + outportByte(sImr, 0xff); /* Mask All Seconary Interrupts */ + + /* Print out the system info for this */ + kprintf("pic0 - Port: [0x%X]\n",mPic); + kprintf("pic1 - Port: [0x%X]\n",sPic); + + /* Return so the system knows it went well */ + return(0x0); + } + +/*! + * \brief enable specified IRQ + * + * \param irqNo IRQ to enable + */ +void irqEnable(u_int16_t irqNo) { + irqMask &= ~(1 << irqNo); + if (irqNo >= 8) { + irqMask &= ~(1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/*! + * \brief disable specified IRQ + * + * \param irqNo IRQ to disable + */ +void irqDisable(u_int16_t irqNo) { + irqMask |= (1 << irqNo); + if ((irqMask & 0xFF00)==0xFF00) { + irqMask |= (1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/*** + END + ***/ diff --git a/isa/Makefile b/isa/Makefile new file mode 100644 index 0000000..b289aec --- /dev/null +++ b/isa/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = mouse.o atkbd.o fdc.o 8259.o pit.o +#ne2k.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/isa/atkbd.c b/isa/atkbd.c new file mode 100644 index 0000000..0607761 --- /dev/null +++ b/isa/atkbd.c @@ -0,0 +1,383 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int atkbd_scan(); + +static unsigned int keyMap = 0x0; +static unsigned int ledStatus = 0x0; +static char stdinBuffer[512]; +static uInt16 stdinSize; +static uInt32 controlKeys = 0x0; + +static spinLock_t atkbdSpinLock = SPIN_LOCK_INITIALIZER; + +static unsigned int keyboardMap[255][8] = { +/* Ascii, Shift, Ctrl, Alt, Num, Caps, Shift Caps, Shift Num */ + { 0, 0, 0, 0, 0, 0, 0, 0}, +/* ESC */ { 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B}, +/* 1,! */ { 0x31, 0x21, 0, 0, 0x31, 0x31, 0x21, 0x21}, +/* 2,@ */ { 0x32, 0x40, 0, 0, 0x32, 0x32, 0x40, 0x40}, +/* 3,# */ { 0x33, 0x23, 0, 0, 0x33, 0x33, 0x23, 0x23}, +/* 4,$ */ { 0x34, 0x24, 0, 0, 0x34, 0x34, 0x24, 0x24}, +/* 5,% */ { 0x35, 0x25, 0, 0, 0x35, 0x35, 0x25, 0x25}, +/* 6,^ */ { 0x36, 0x5E, 0, 0, 0x36, 0x36, 0x5E, 0x5E}, +/* 7,& */ { 0x37, 0x26, 0, 0, 0x37, 0x37, 0x26, 0x26}, +/* 8,* */ { 0x38, 0x2A, 0, 0, 0x38, 0x38, 0x2A, 0x2A}, +/* 9.( */ { 0x39, 0x28, 0, 0, 0x39, 0x39, 0x28, 0x28}, +/* 0,) */ { 0x30, 0x29, 0, 0, 0x30, 0x30, 0x29, 0x29}, +/* -,_ */ { 0x2D, 0x5F, 0, 0, 0x2D, 0x2D, 0x5F, 0x5F}, +/* =,+ */ { 0x3D, 0x2B, 0, 0, 0x3D, 0x3D, 0x2B, 0x2B}, +/* 14 */ { 0x08, 0x08, 0x8, 0x8, 0x08, 0x08, 0x08, 0x08}, +/* 15 */ { 0x09, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x71, 0x51, 0, 0, 0, 0, 0, 0}, +/* */ { 0x77, 0x57, 0, 0, 0, 0, 0, 0}, +/* */ { 0x65, 0x45, 0, 0, 0, 0, 0, 0}, +/* */ { 0x72, 0x52, 0, 0, 0, 0, 0, 0}, +/* */ { 0x74, 0x54, 0, 0, 0, 0, 0, 0}, +/* */ { 0x79, 0x59, 0, 0, 0, 0, 0, 0}, +/* */ { 0x75, 0x55, 0, 0, 0, 0, 0, 0}, +/* */ { 0x69, 0x49, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6F, 0x4F, 0, 0, 0, 0, 0, 0}, +/* */ { 0x70, 0x50, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5B, 0x7B, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5D, 0x7D, 0, 0, 0, 0, 0, 0}, +/* */ { 0x0A, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* a,A */ { 0x61, 0x41, 0x41, 0, 0, 0, 0, 0}, +/* */ { 0x73, 0x53, 0, 0, 0, 0, 0, 0}, +/* */ { 0x64, 0x44, 0, 0, 0, 0, 0, 0}, +/* */ { 0x66, 0x46, 0, 0, 0, 0, 0, 0}, +/* */ { 0x67, 0x47, 0, 0, 0, 0, 0, 0}, +/* */ { 0x68, 0x48, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6A, 0x4A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6B, 0x4B, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6C, 0x4C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x3B, 0x3A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x27, 0x22, 0, 0, 0, 0, 0, 0}, +/* */ { 0x60, 0x7E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2A, 0x0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5C, 0x3C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x7A, 0x5A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x78, 0x58, 0, 0, 0, 0, 0, 0}, +/* c,C */ { 0x63, 0x43, 0x3, 0x9, 0, 0, 0, 0}, +/* */ { 0x76, 0x56, 0, 0, 0, 0, 0, 0}, +/* */ { 0x62, 0x42, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6E, 0x4E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6D, 0x4D, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2C, 0x3C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2E, 0x3E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2F, 0x3F, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x20, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* F1 */ { 0x3000, 0, 0, 0x3000, 0, 0, 0, 0}, +/* */ { 0x3001, 0, 0, 0x3001, 0, 0, 0, 0}, +/* */ { 0x3002, 0, 0, 0x3002, 0, 0, 0, 0}, +/* */ { 0x3003, 0, 0, 0x3003, 0, 0, 0, 0}, +/* */ { 0x3004, 0, 0, 0x3004, 0, 0, 0, 0}, +/* */ { 0x4000, 0, 0, 0x3005, 0, 0, 0, 0}, +/* */ { 0x4100, 0, 0, 0x3006, 0, 0, 0, 0}, +/* */ { 0x4200, 0, 0, 0x3007, 0, 0, 0, 0}, +/* */ { 0x4300, 0, 0, 0x3008, 0, 0, 0, 0}, +/* */ { 0x4400, 0, 0, 0x3009, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0x3010, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0x3011, 0, 0, 0, 0}, +/* */ { 0x4700, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4800, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4900, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2D, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4B00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4C00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4D00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2B, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4F00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5000, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5100, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5200, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5300, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0} + }; + +/************************************************************************ + +Function: int atkbd_init + +Description: This function is used to turn on the keyboard + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int atkbd_init() { + /* Insert the IDT vector for the keyboard handler */ + setVector(&atkbd_isr, mVec+0x1, dPresent + dInt + dDpl0); + + /* Set the LEDS to their defaults */ + setLED(); + + /* Clear Keyboard */ + atkbd_scan(); + + /* Turn on the keyboard vector */ + irqEnable(0x1); + + /* Print out information on keyboard */ + kprintf("atkbd0 - Address: [0x%X], Keyboard Buffer: [0x%X], Buffer Size [%i]\n",&atkbd_isr,&stdinBuffer,512); + + /* Return so we know everything went well */ + return(0x0); + } + +/* + * 2-23-2004 mji I think the pusha/popa should be pushal/popal + */ + +asm( + ".globl atkbd_isr \n" + "atkbd_isr: \n" + " pusha \n" /* Save all registers */ + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " call keyboardHandler \n" + " mov $0x20,%dx \n" + " mov $0x20,%ax \n" + " outb %al,%dx \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +static int atkbd_scan() { + int code = 0x0; + int val = 0x0; + + code = inportByte(0x60); + val = inportByte(0x61); + + outportByte(0x61,val | 0x80); + outportByte(0x61,val); + + return(code); + } + +void keyboardHandler() { + int key = 0x0; + + if (!spinTryLock(&atkbdSpinLock)) + return; + + key = atkbd_scan(); + + if (key > 255) + return; + + /* Control Key */ + if (key == 0x1D && !(controlKeys & controlKey)) { + controlKeys |= controlKey; + } + if (key == 0x80 + 0x1D) { + controlKeys &= (0xFF - controlKey); + } + /* ALT Key */ + if (key == 0x38 && !(controlKeys & altKey)) { + controlKeys |= altKey; + } + if (key == 0x80 + 0x38) { + controlKeys &= (0xFF - altKey); + } + /* Shift Key */ + if ((key == 0x2A || key == 0x36) && !(controlKeys & shiftKey)) { + controlKeys |= shiftKey; + } + if ((key == 0x80 + 0x2A) || (key == 0x80 + 0x36)) { + controlKeys &= (0xFF - shiftKey); + } + /* Caps Lock */ + if (key == 0x3A) { + ledStatus ^= ledCapslock; + setLED(); + } + /* Num Lock */ + if (key == 0x45) { + ledStatus ^= ledNumlock; + setLED(); + } + /* Scroll Lock */ + if (key == 0x46) { + ledStatus ^= ledScrolllock; + setLED(); + } + /* Pick Which Key Map */ + if (controlKeys == 0) { keyMap = 0; } + else if (controlKeys == 1) { keyMap = 1; } + else if (controlKeys == 2) { keyMap = 2; } + else if (controlKeys == 4) { keyMap = 3; } + /* If Key Is Not Null Add It To Handler */ + if (((uInt)(keyboardMap[key][keyMap]) > 0) && ((uInt32)(keyboardMap[key][keyMap]) < 0xFF)) { + switch ((uInt32)keyboardMap[key][keyMap]) { + case 8: + backSpace(); + if (tty_foreground == 0x0) { + stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; + stdinSize++; + } + else { + tty_foreground->stdin[tty_foreground->stdinSize] = keyboardMap[key][keyMap]; + tty_foreground->stdinSize++; + } + break; + case 0x3: + //if (tty_foreground != 0x0) + // endTask(tty_foreground->owner); + //K_PANIC("CTRL-C pressed\n"); + kprintf("CTRL-C pressed\n"); + kprintf("FreePages: [0x%X]\n",systemVitals->freePages); + break; + case 0x9: + kprintf("REBOOTING"); + while(inportByte(0x64) & 0x02); + outportByte(0x64, 0xFE); + break; + default: + if (tty_foreground == 0x0) { + stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; + stdinSize++; + } + else { + tty_foreground->stdin[tty_foreground->stdinSize] = keyboardMap[key][keyMap]; + tty_foreground->stdinSize++; + } + break; + } + } + else { + switch ((keyboardMap[key][keyMap] >> 8)) { + case 0x30: + #ifdef DEBUG + kprintf("Changing Consoles[0x%X:0x%X]\n",_current->id,_current); + #endif + tty_change(keyboardMap[key][keyMap] & 0xFF); + break; + default: + break; + } + } + + /* Return */ + spinUnlock(&atkbdSpinLock); + return; + } + +void setLED() { + outportByte(0x60, 0xED); + while(inportByte(0x64) & 2); + outportByte(0x60, ledStatus); + while(inportByte(0x64) & 2); + } + +/* Temp */ +unsigned char getch() { + uInt8 retKey = 0x0; + uInt32 i = 0x0; + + /* + if ((stdinSize <= 0) && (tty_foreground == 0x0)) { + sched_yield(); + } + if ((tty_foreground != 0x0) && (tty_foreground->stdinSize <= 0x0)) { + sched_yield(); + } + */ + + /* + if (!spinTryLock(&atkbdSpinLock)) + return(0x0); +*/ + + if (tty_foreground == 0x0) { + if (stdinSize == 0x0) { + // spinUnlock(&atkbdSpinLock); + return(0x0); + } + + retKey = stdinBuffer[0]; + stdinSize--; + + for (i=0x0;istdinSize == 0x0) { + // spinUnlock(&atkbdSpinLock); + return(0x0); + } + + retKey = tty_foreground->stdin[0]; + tty_foreground->stdinSize--; + + for (i=0x0;istdinSize;i++) { + tty_foreground->stdin[i] = tty_foreground->stdin[i+0x1]; + } + } + //spinUnlock(&atkbdSpinLock); + return(retKey); + } + +/*** + END + ***/ + diff --git a/isa/fdc.c b/isa/fdc.c new file mode 100644 index 0000000..874d4af --- /dev/null +++ b/isa/fdc.c @@ -0,0 +1,420 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static spinLock_t fdcSpinLock = SPIN_LOCK_INITIALIZER; + +static volatile bool done = FALSE; +static drvGeom geometry = { dg144Heads,dg144Tracks,dg144Spt }; +static bool diskChange = FALSE; +static bool motor = FALSE; +static volatile Int8 fdcTrack = 0xff; +static Int8 sr0 = 0; +static volatile int timeOut = 0; +static Int8 statSize = 0; +static Int8 status[7] = { 0 }; + +unsigned long tbaddr = 0x80000L; + +int fdcInit2(struct device_node *dev) { + dev->devInfo->size = (1024 * 1450); + return(0x0); + } + +int fdc_init() { + struct device_interface *devInfo = (struct device_interface *)kmalloc(sizeof(struct device_interface)); + setVector(floppyIsr, mVec+6, (dInt+dPresent)); + irqEnable(6); + reset(); + devInfo->major = 0x0; + devInfo->init = (void *)&fdcInit2; + devInfo->read = fdcRead; + devInfo->write = fdcWrite; + devInfo->reset = (void *)reset; + + device_add(0,'c',devInfo); + devfs_makeNode("fd0",'b',0x0,0x0); + return(0x0); + } + +asm( + ".globl floppyIsr \n" + "floppyIsr: \n" + " pusha \n" + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " call floppyIsrhndlr \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" + ); + +void floppyIsrhndlr() { + done = TRUE; + outportByte(0x20,0x20); + } + +void sendByte(int Int8) { + volatile int msr; + int tmo; + for (tmo=0;tmo<128;tmo++) { + msr = inportByte(fdcMsr); + if ((msr & 0xc0) == 0x80) { + outportByte(fdcData,Int8); + return; + } + inportByte(0x80); + } + } + +int getByte() { + volatile int msr; + int tmo; + for (tmo=0;tmo<128;tmo++) { + msr = inportByte(fdcMsr); + if ((msr & 0xd0) == 0xd0) { + return inportByte(fdcData); + } + inportByte(0x80); + } + return(-1); + } + +bool fdcRw(int block,Int8 *blockBuffer,bool read,unsigned long numSectors) { + int head = 0x0,track = 0x0,sector = 0x0,tries= 0x0, copyCount = 0x0; + unsigned char *p_tbaddr = (unsigned char *)0x80000; + unsigned char *p_blockbuff = (unsigned char *)blockBuffer; + //kprintf("Block: [%i]\n",block); + block2Hts(block,&head,&track,§or); + motorOn(); + if (!read && blockBuffer) { + /* copy data from data buffer into track buffer */ + for (copyCount=0; copyCount<(numSectors*512); copyCount++) { + *p_tbaddr = *p_blockbuff; + p_blockbuff++; + p_tbaddr++; + } + } + for (tries = 0;tries < 3;tries++) { + if (inportByte(fdcDir) & 0x80) { + diskChange = TRUE; + seek(1); /* clear "disk change" status */ + recalibrate(); + motorOff(); + kprint("FDC: Disk change detected. Trying again.\n"); + return fdcRw(block, blockBuffer, read, numSectors); + } + if (!seek(track)) { + motorOff(); + kprintf("FDC: Error seeking to track [%i]\n",block); + return FALSE; + } + outportByte(fdcCcr,0); + if (read) { + dmaXfer(2,tbaddr,numSectors*512,FALSE); + sendByte(cmdRead); + } + else { + dmaXfer(2,tbaddr,numSectors*512,TRUE); + sendByte(cmdWrite); + } + sendByte(head << 2); + sendByte(track); + sendByte(head); + sendByte(sector); + sendByte(2); /* 512 Int8s/sector */ + sendByte(geometry.spt); + if (geometry.spt == dg144Spt) { + sendByte(dg144Gap3rw); /* gap 3 size for 1.44M read/write */ + } + else { + sendByte(dg168Gap3rw); /* gap 3 size for 1.68M read/write */ + } + sendByte(0xff); /* DTL = unused */ + if (!waitFdc(TRUE)) { + kprint("Timed out, trying operation again after reset()\n"); + reset(); + return fdcRw(block, blockBuffer, read, numSectors); + } + if ((status[0] & 0xc0) == 0) break; /* worked! outta here! */ + recalibrate(); /* oops, try again... */ + } + motorOff(); + if (read && blockBuffer) { + p_blockbuff = (unsigned char *)blockBuffer; + p_tbaddr = (unsigned char *) 0x80000; + for (copyCount=0x0; copyCount<(numSectors*512); copyCount++) { + *p_blockbuff = *p_tbaddr; + p_blockbuff++; + p_tbaddr++; + } + } + return (tries != 3); + } + +void block2Hts(int block,int *head,int *track,int *sector) { + *head = (block % (geometry.spt * geometry.heads)) / (geometry.spt); + *track = block / (geometry.spt * geometry.heads); + *sector = block % geometry.spt + 1; + } + +void motorOn(void) { + if (motor == FALSE) { + outportByte(fdcDor,0x1c); + motor = TRUE; + } + } + +void motorOff(void) { + if (motor == TRUE) { + //outportByte(fdcDor,0x0); + //outportByte(fdcDor,0x0C); + motor = FALSE; + } + } + +bool seek(int track) { + if (fdcTrack == track) { + return(TRUE); + } + sendByte(cmdSeek); + sendByte(0); + sendByte(track); + if (!waitFdc(TRUE)) { + kprintf("wait fdc failed\n"); + return(FALSE); + } + if ((sr0 != 0x20) || (fdcTrack != track)) { + return(FALSE); + } + else { + return(TRUE); + } + } + +bool readBlock(int block,Int8 *blockBuffer, unsigned long numSectors) { + int result = 0x0,loop = 0x0; + if (numSectors > 1) { + for (loop=0; loop +#include +#include +#include +#include +#include +#include + +static uInt8 kbdRead() { + unsigned long Timeout; + uInt8 Stat, Data; + + for (Timeout = 50000L; Timeout != 0; Timeout--) { + Stat = inportByte(0x64); + + /* loop until 8042 output buffer full */ + if ((Stat & 0x01) != 0) + { + Data = inportByte(0x60); + + /* loop if parity error or receive timeout */ + if((Stat & 0xC0) == 0) + return Data; + } + } + + return -1; +} + +static void kbdWrite(uInt16 port,uInt8 data) { + uInt32 timeout; + uInt8 stat; + + for (timeout = 500000L; timeout != 0; timeout--) + { + stat = inportByte(0x64); + + if ((stat & 0x02) == 0) + break; + } + + if (timeout != 0) + outportByte(port, data); + } + +static uInt8 kbdWriteRead(uInt16 port,uInt8 data, const char* expect) +{ + int RetVal; + + kbdWrite(port, data); + for (; *expect; expect++) + { + RetVal = kbdRead(); + if ((uInt8) *expect != RetVal) + { + return RetVal; + } + } + + return 0; +} + + + +int mouseInit() { + static uInt8 s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 }; + static uInt8 s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 }; + const uInt8* ch; + Int8 cmd = 0x0; + + kbdWrite(0x64,0xA8); + for (ch = s1; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + for (ch = s2; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + kbdWrite(0x64,0xD4); + if (kbdWriteRead(0x60,0xF2,"\xFA") != 0x0) { + kprintf("Error With Mouse\n"); + } + cmd = kbdRead(); + kprintf("CMD: [0x%X]\n",cmd); + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, 0xF4,"\xFA"); + + setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + irqEnable(12); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + + kprintf("psm0 - Address: [0x%X]\n",&mouseISR); + + /* Return so we know everything went well */ + return(0x0); + } + +asm( + ".globl mouseISR \n" + "mouseISR: \n" + " pusha \n" /* Save all registers */ + " call mouseHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +void mouseHandler() { + kprintf("MOUSE!!!\n"); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + /* Return */ + return; + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:12 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:02 reddawg + no message + + Revision 1.3 2004/09/07 21:54:38 reddawg + ok reverted back to old scheduling for now.... + + Revision 1.2 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + + Revision 1.1 2004/06/04 10:20:53 reddawg + mouse drive: fixed a few bugs works a bit better now + + END + ***/ + diff --git a/isa/ne2k.c b/isa/ne2k.c new file mode 100644 index 0000000..9a4ecbe --- /dev/null +++ b/isa/ne2k.c @@ -0,0 +1,361 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static spinLock_t ne2k_spinLock = SPIN_LOCK_INITIALIZER; + +static int dp_pkt2user(struct device *dev,int page,int length); +static void getblock(struct device *dev,int page,size_t offset,size_t size,void *dst); +static int dp_recv(struct device *); + +static struct nicBuffer *ne2kBuffer = 0x0; +static struct device *mDev = 0x0; + +asm( + ".globl ne2kISR \n" + "ne2kISR: \n" + " pusha \n" /* Save all registers */ + " call ne2kHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +/************************************************************************ + +Function: int ne2kInit(uInt32 ioAddr) +Description: This Function Will Initialize The Programmable Timer + +Notes: + +************************************************************************/ +int ne2k_init() { + mDev = (struct device *)kmalloc(sizeof(struct device)); + mDev->ioAddr = 0x280; + mDev->irq = 10; + setVector(&ne2kISR, mVec+10, dPresent + dInt + dDpl0); + irqEnable(10); +// kprintf("ne0 - irq: %i, ioAddr: 0x%X MAC: %X:%X:%X:%X:%X:%X\n",dev->irq,dev->ioAddr,dev->net->mac[0] & 0xFF,dev->net->mac[1] & 0xFF,dev->net->mac[2] & 0xFF,dev->net->mac[3] & 0xFF,dev->net->mac[4] & 0xFF,dev->net->mac[5] & 0xFF); + + outportByte(mDev->ioAddr + NE_CMD, 0x21); // stop mode + outportByte(mDev->ioAddr + NE_DCR,0x29); // 0x29 data config reg + outportByte(mDev->ioAddr + NE_RBCR0,0x00); // LOW byte count (remote) + outportByte(mDev->ioAddr + NE_RBCR1,0x00); // HIGH byte count (remote) + outportByte(mDev->ioAddr + NE_RCR,0x3C); // receive config reg + outportByte(mDev->ioAddr + NE_TCR,0x02); // LOOP mode (temp) + outportByte(mDev->ioAddr + NE_PSTART,startPage); // 0x26 PAGE start + outportByte(mDev->ioAddr + NE_BNRY,startPage); // 0x26 BOUNDARY + outportByte(mDev->ioAddr + NE_PSTOP,stopPage); // 0x40 PAGE stop + outportByte(mDev->ioAddr + NE_ISR,0xFF); // interrupt status reg + outportByte(mDev->ioAddr + NE_IMR,0x0B); + outportByte(mDev->ioAddr + NE_CMD,0x61); // PAGE 1 regs + + outportByte(mDev->ioAddr + DP_MAR0, 0xFF); + outportByte(mDev->ioAddr + DP_MAR1, 0xFF); + outportByte(mDev->ioAddr + DP_MAR2, 0xFF); + outportByte(mDev->ioAddr + DP_MAR3, 0xFF); + outportByte(mDev->ioAddr + DP_MAR4, 0xFF); + outportByte(mDev->ioAddr + DP_MAR5, 0xFF); + outportByte(mDev->ioAddr + DP_MAR6, 0xFF); + outportByte(mDev->ioAddr + DP_MAR7, 0xFF); + outportByte(mDev->ioAddr + DP_CURR, startPage + 1); + outportByte(mDev->ioAddr + NE_CMD, 0x20); + inportByte(mDev->ioAddr + DP_CNTR0); /* reset counters by reading */ + inportByte(mDev->ioAddr + DP_CNTR1); + inportByte(mDev->ioAddr + DP_CNTR2); + + outportByte(mDev->ioAddr + NE_TCR, 0x00); + + outportByte(mDev->ioAddr + NE_CMD, 0x0); + outportByte(mDev->ioAddr + NE_DCR, 0x29); + + kprintf("Initialized"); + /* Return so we know everything went well */ + return(0x0); + } /* ne2k_init */ + +int PCtoNIC(struct device *dev,void *packet,int length) { + int i = 0x0; + uInt16 *packet16 = (uInt16 *)packet; + uInt8 *packet8 = (uInt8 *)packet; + uInt8 word16 = 0x1; + + if ((inportByte(dev->ioAddr) & 0x04) == 0x04) { + kpanic("Device Not Ready\n"); + } + + assert(length); + if ((word16 == 1) && (length & 0x01)) { + length++; + } + + outportByte(dev->ioAddr+EN0_RCNTLO,(length & 0xFF)); + outportByte(dev->ioAddr+EN0_RCNTHI,(length >> 8)); + + outportByte(dev->ioAddr+EN0_RSARLO,0x0); + outportByte(dev->ioAddr+EN0_RSARHI,0x41); + + outportByte(dev->ioAddr,E8390_RWRITE+E8390_START); + + if (word16 != 0x0) { + for(i=0;iioAddr + NE_DATAPORT,packet16[i]); + } + } + else { + for(i=0;iioAddr + NE_DATAPORT,packet8[i]); + } + } + + for (i = 0;i<=100;i++) { + if ((inportByte(dev->ioAddr+EN0_ISR) & 0x40) == 0x40) { + break; + } + } + + outportByte(dev->ioAddr+EN0_ISR,0x40); + outportByte(dev->ioAddr+EN0_TPSR,0x41);//ei_local->txStartPage); + outportByte(dev->ioAddr+0x05,(length & 0xFF)); + outportByte(dev->ioAddr+0x06,(length >> 8)); + outportByteP(dev->ioAddr,0x26); + //kprintf("SENT\n"); + return(length); + } + +int NICtoPC(struct device *dev,void *packet,int length,int nic_addr) { + int i = 0x0; + uInt16 *packet16 = (uInt16 *)packet; + + assert(length); + + if (length & 0x01) + length++; + + + + outportByte(dev->ioAddr+EN0_RCNTLO,(length & 0xFF)); + outportByte(dev->ioAddr+EN0_RCNTHI,(length >> 8)); + + outportByte(dev->ioAddr+EN0_RSARLO,nic_addr & 0xFF); + outportByte(dev->ioAddr+EN0_RSARHI,nic_addr >> 8); + + outportByte(dev->ioAddr,0x0A); + + for(i=0;iioAddr + NE_DATAPORT); + } + + outportByte(dev->ioAddr+EN0_ISR,0x40); + return(length); + } /* PCtoNIC */ + +void ne2kHandler() { + uInt16 isr = 0x0; + uInt16 status = 0x0; + + irqDisable(10); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + + asm("sti"); + + isr = inportByte(mDev->ioAddr + NE_ISR); + + if ((isr & 0x02) == 0x02) { + outportByte(mDev->ioAddr + NE_ISR, 0x0A); + status = inportByte(0x280 + NE_TPSR); + } + if ((isr & 0x01) == 0x01) { + if (dp_recv(mDev)) { + kprintf("Error Getting Packet\n"); + } + outportByte(mDev->ioAddr + NE_ISR, 0x05); + } + + outportByte(mDev->ioAddr + NE_IMR,0x0); + outportByte(mDev->ioAddr + NE_IMR,0x0B); + + asm("cli"); + irqEnable(10); + + return; + } /* ne2kHandler */ + +static int dp_recv(struct device *dev) { + dp_rcvhdr_t header; + unsigned int pageno = 0x0, curr = 0x0, next = 0x0; + int packet_processed = 0x0, r = 0x0; + uInt16 eth_type = 0x0; + + uInt32 length = 0x0; + + pageno = inportByte(dev->ioAddr + NE_BNRY) + 1; + if (pageno == stopPage) pageno = startPage; + + do { + outportByte(dev->ioAddr + NE_CMD, 0x40); + curr = inportByte(dev->ioAddr + NE_CURRENT); + outportByte(dev->ioAddr, 0x0); + if (curr == pageno) break; + getblock(dev, pageno, (size_t)0, sizeof(header), &header); + getblock(dev, pageno, sizeof(header) + 2*sizeof(ether_addr_t), sizeof(eth_type), ð_type); + + length = (header.dr_rbcl | (header.dr_rbch << 8)) - sizeof(dp_rcvhdr_t); + next = header.dr_next; + + //kprintf("length: [0x%X:0x%X:0x%X]\n",header.dr_next,header.dr_status,length); + + if (length < 60 || length > 1514) { + kprintf("dp8390: packet with strange length arrived: %d\n",length); + next= curr; + } + else if (next < startPage || next >= stopPage) { + kprintf("dp8390: strange next page\n"); + next= curr; + } + else if (header.dr_status & RSR_FO) { + kpanic("dp8390: fifo overrun, resetting receive buffer\n"); + next = curr; + } + else if (header.dr_status & RSR_PRX) { + r = dp_pkt2user(dev, pageno, length); + if (r != OK) { + kprintf("FRUIT"); + return(0x0); + } + + packet_processed = 0x1; + } + if (next == startPage) + outportByte(dev->ioAddr + NE_BNRY, stopPage - 1); + else + outportByte(dev->ioAddr + NE_BNRY, next - 1); + + pageno = next; + + } while (packet_processed == 0x0); + return(0x0); + } /* dp_recv */ + +static void getblock(struct device *dev,int page,size_t offset,size_t size,void *dst) { + uInt16 *ha = 0x0; + int i = 0x0; + + ha = (uInt16 *) dst; + offset = page * DP_PAGESIZE + offset; + outportByte(dev->ioAddr + NE_RBCR0, size & 0xFF); + outportByte(dev->ioAddr + NE_RBCR1, size >> 8); + outportByte(dev->ioAddr + EN0_RSARLO, offset & 0xFF); + outportByte(dev->ioAddr + EN0_RSARHI, offset >> 8); + outportByte(dev->ioAddr + NE_CMD, E8390_RREAD | E8390_START); + + size /= 2; + for (i= 0; iioAddr + NE_DATAPORT); + outportByte(dev->ioAddr+EN0_ISR,0x40); + } /* getblock */ + +static int dp_pkt2user(struct device *dev,int page,int length) { + int last = 0x0; + struct nicBuffer *tmpBuf = 0x0; + + last = page + (length - 1) / DP_PAGESIZE; + + if (last >= stopPage) { + kprintf("FOOK STOP PAGE!!!"); + } + else { + tmpBuf = ne2kAllocBuffer(length); + NICtoPC(dev,tmpBuf->buffer,length,page * DP_PAGESIZE + sizeof(dp_rcvhdr_t)); + } + return(OK); + } /* db_pkt2user */ + +struct nicBuffer *ne2kAllocBuffer(int length) { + struct nicBuffer *tmpBuf = 0x0; + + spinLock(&ne2k_spinLock); + + if (ne2kBuffer == 0x0) { + ne2kBuffer = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer)); + ne2kBuffer->next = 0x0; + ne2kBuffer->length = length; + ne2kBuffer->buffer = (char *)kmalloc(length); + spinUnlock(&ne2k_spinLock); + return(ne2kBuffer); + } + else { + for (tmpBuf = ne2kBuffer;tmpBuf->next != 0x0;tmpBuf = tmpBuf->next); + + tmpBuf->next = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer)); + tmpBuf = tmpBuf->next; + tmpBuf->next = 0x0; + tmpBuf->length = length; + tmpBuf->buffer = (char *)kmalloc(length); + spinUnlock(&ne2k_spinLock); + return(tmpBuf); + } + spinUnlock(&ne2k_spinLock); + return(0x0); + } /* ne2kAllocBuffer */ + +struct nicBuffer *ne2kGetBuffer() { + struct nicBuffer *tmpBuf = 0x0; + + if (ne2k_spinLock == 0x1) + return(0x0); + + tmpBuf = ne2kBuffer; + if (ne2kBuffer != 0x0) + ne2kBuffer = ne2kBuffer->next; + return(tmpBuf); + } /* nicBuffer */ + +void ne2kFreeBuffer(struct nicBuffer *buf) { + kfree(buf->buffer); + kfree(buf); + return; + } /* ne2kFreeBuffer */ + +/*** + END + ***/ diff --git a/isa/pit.c b/isa/pit.c new file mode 100644 index 0000000..2eefab4 --- /dev/null +++ b/isa/pit.c @@ -0,0 +1,111 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +/***************************************************************************************** + + Function: int pitInit() + + Description: This Function Will Initialize The Programmable Timer + + Notes: + + 0040 r/w PIT counter 0, counter divisor (XT, AT, PS/2) + 0041 r/w PIT counter 1, RAM refresh counter (XT, AT) + 0042 r/w PIT counter 2, cassette & speaker (XT, AT, PS/2) + 0043 r/w PIT mode port, control word register for counters 0-2 + + bit 7-6 = 00 counter 0 select + = 01 counter 1 select (not PS/2) + = 10 counter 2 select + bit 5-4 = 00 counter latch command + = 01 read/write counter bits 0-7 only + = 10 read/write counter bits 8-15 only + = 11 read/write counter bits 0-7 first, then 8-15 + bit 3-1 = 000 mode 0 select + = 001 mode 1 select - programmable one shot + = x10 mode 2 select - rate generator + = x11 mode 3 select - square wave generator + = 100 mode 4 select - software triggered strobe + = 101 mode 5 select - hardware triggered strobe + bit 0 = 0 binary counter 16 bits + = 1 BCD counter + +*****************************************************************************************/ +int pit_init() { + outportByteP(0x43,0x36); + outportByteP(0x40,((1193180/PIT_TIMER) & 0xFF)); + outportByte(0x40,(((1193180/PIT_TIMER) >> 8) & 0xFF)); + + /* Print out information on the PIT */ + kprintf("pit0 - Port [0x%X], Timer Hz: [%iHz]\n",0x43,PIT_TIMER); + + /* Return so we know everything went well */ + return(0x0); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:12 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:03 reddawg + no message + + Revision 1.7 2004/07/16 04:06:32 reddawg + Tune ups this stuff should of been taken care of months ago + + Revision 1.6 2004/07/16 01:08:58 reddawg + Whew we work once again + + Revision 1.5 2004/07/09 13:29:15 reddawg + pit: pitInit to pit_init + Adjusted initialization routines + + Revision 1.4 2004/05/21 12:48:22 reddawg + Cleaned up + + Revision 1.3 2004/05/20 22:51:09 reddawg + Cleaned Up Warnings + + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + END + ***/ + diff --git a/isa/rs232.c b/isa/rs232.c new file mode 100644 index 0000000..f77d556 --- /dev/null +++ b/isa/rs232.c @@ -0,0 +1,55 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +void rs232Init() { + return; + } + +/*** + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:12 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:03 reddawg + no message + + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + + END + ***/ + diff --git a/kernel/Makefile b/kernel/Makefile new file mode 100644 index 0000000..4a2fcb1 --- /dev/null +++ b/kernel/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = kern_sig.o pipe.o kern_descrip.o kern_sysctl.o gen_calls.o schedyield.o tty.o sys_call_new.o sys_call.o endtask.o spinlock.o bioscall.o ld.o time.o fork.o syscall.o syscall_new.o elf.o systemtask.o exec.o sched.o kpanic.o ubthread.o timer.o vitals.o +# ap-boot.o smp.o vitals.o(obsolete) + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/kernel/ap-boot.S b/kernel/ap-boot.S new file mode 100644 index 0000000..2645aff --- /dev/null +++ b/kernel/ap-boot.S @@ -0,0 +1,105 @@ +/* + * Okay, this file contains the code that's going to bootstrap the AP cpus + */ + + + .globl ap_trampoline_start,ap_trampoline_end + .text + .code16 +ap_trampoline_start: + cli + cld + + movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments + movw %ax,%ds + movw %ax,%es + movw %ax,%ss + + // Do some bochs-specific bullshit + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + //lgdt ap_gdt; + lgdt ap_trampoline_gdt_limit - ap_trampoline_start + movl %cr0,%eax + orl $0x1,%eax + movl %eax,%cr0 // PMODE! + +.code32 + .byte 0x66 + ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS + +ap_trampoline_32: + mov $0x32,%al // '2' + mov $0xe9,%dx + outb %al,%dx + + mov $0x10,%ax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + mov %ax,%ss + + // Spinlock + mov ap_trampoline_spl - ap_trampoline_start,%edi +ap_spl: + //cmp $1,(%edi) + //je ap_spl + + mov $1,%eax // Value to be set + xchgl (%edi),%eax + cmp $0,%eax + je ap_spl + // /Spinlock + + mov $0x30,%al // '0' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_stackptr - ap_trampoline_start,%ebx + mov %ebx,%esp + add $0x1000,%ebx + mov %ebx,ap_trampoline_stackptr - ap_trampoline_start + + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + + // spinunlock + mov $0,%eax + mov ap_trampoline_spl - ap_trampoline_start,%edi + xchgl (%edi),%eax + // /spinunlock + + mov $0x33,%al // '3' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_epoint,%eax + call *%eax +1: + hlt + jmp 1b // Halt if we ever get here somehow + + // Stack.. This sucks, since CPU initialization isn't serialized +ap_trampoline_stackptr: + .long 0x10000 // 256KB +ap_trampoline_epoint: + .long c_ap_boot + +ap_trampoline_spl: + .long 0 +ap_gdt: + .long ubixGDT + + // GDT +ap_trampoline_gdt: + .word 0 +ap_trampoline_gdt_limit: + .word 128 // Room for 32 descriptors +ap_trampoline_gdt_base: + .long 0x20000 // 128KB (move this later) + + +ap_trampoline_end: diff --git a/kernel/bioscall.c b/kernel/bioscall.c new file mode 100644 index 0000000..5956306 --- /dev/null +++ b/kernel/bioscall.c @@ -0,0 +1,102 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + + +asm( + ".globl bios16Code\n" + ".code16 \n" + "bios16Code: \n" + "int $0x10 \n" + "int $0x69 \n" + ".code32 \n" + ); + + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { + short segment = 0x0,offset = 0x0; + uInt32 tmpAddr = (uInt32)&bios16Code; + kTask_t *newProcess = 0x0; + + offset = tmpAddr & 0xF; // lower 4 bits + segment = tmpAddr >> 4; + + newProcess = schedNewTask(); + assert(newProcess); + + + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); + newProcess->tss.eip = offset & 0xFFFF; + newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; + newProcess->tss.eax = eax & 0xFFFF; + newProcess->tss.ebx = ebx & 0xFFFF; + newProcess->tss.ecx = ecx & 0xFFFF; + newProcess->tss.edx = edx & 0xFFFF; + newProcess->tss.esp = 0x1000 & 0xFFFF; + newProcess->tss.ebp = 0x1000 & 0xFFFF; + newProcess->tss.esi = esi & 0xFFFF; + newProcess->tss.edi = edi & 0xFFFF; + newProcess->tss.es = es & 0xFFFF; + newProcess->tss.cs = segment & 0xFFFF; + newProcess->tss.ss = 0x1000 & 0xFFFF; + newProcess->tss.ds = ds & 0xFFFF; + newProcess->tss.fs = 0x0 & 0xFFFF; + newProcess->tss.gs = 0x0 & 0xFFFF; + newProcess->tss.ldt = 0x0 & 0xFFFF; + newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; + newProcess->tss.io_map = 0x0 & 0xFFFF; + newProcess->tss.io_map = sizeof(struct tssStruct)-8192; + newProcess->oInfo.v86Task = 0x1; + + newProcess->state = READY; + + while (newProcess->state > 0); + + return; + } + +/*** + END + ***/ + diff --git a/kernel/elf.c b/kernel/elf.c new file mode 100644 index 0000000..d15bb0c --- /dev/null +++ b/kernel/elf.c @@ -0,0 +1,191 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +const struct { + char *elfTypeName; + uInt32 id; + } elfType[] = { + { "ET_NONE", 0 }, + { "ET_REL", 1 }, + { "ET_EXEC", 2 }, + { "ET_DYN", 3 }, + { "ET_CORE", 4 }, + { "ET_LOPROC", 0xff00 }, + { "ET_HIPROC", 0xffff }, + }; + +const struct { + char *phTypeName; + uInt32 id; + } elfPhType[] = { + { "PT_NULL", 0 }, + { "PT_LOAD", 1 }, + { "PT_DYNAMIC", 2 }, + { "PT_INTERP", 3 }, + { "PT_NOTE", 4 }, + { "PT_SHLIB", 5 }, + { "PT_PHDR", 6 }, + { "PT_LOPROC", 0x70000000 }, + { "PT_HIPROC", 0x7fffffff }, + }; + +const struct { + char *shTypeName; + uInt32 id; + } elfShType[] = { + {"SHT_NULL", 0 }, + {"SHT_PROGBITS", 1 }, + {"SHT_SYMTAB", 2 }, + {"SHT_STRTAB", 3 }, + {"SHT_RELA", 4 }, + {"SHT_HASH", 5 }, + {"SHT_DYNAMIC", 6 }, + {"SHT_NOTE", 7 }, + {"SHT_NOBITS", 8 }, + {"SHT_REL", 9 }, + {"SHT_SHLIB", 10 }, + {"SHT_DYNSYM", 11 }, + }; + +const struct { + char *relTypeName; + uInt32 id; + } elfRelType[] = { + {"R_386_NONE", 0 }, + {"R_386_32", 1 }, + {"R_386_PC32", 2 }, + {"R_386_GOT32", 3 }, + {"R_386_PLT32", 4 }, + {"R_386_COPY", 5 }, + {"R_386_GLOB_DAT", 6 }, + {"R_386_JMP_SLOT", 7 }, + {"R_386_RELATIVE", 8 }, + {"R_386_GOTOFF", 9 }, + {"R_386_GOTPC", 10 }, + }; + + +char *elfGetShType(int shType) { + return((char *)elfShType[shType].shTypeName); + } + +char *elfGetPhType(int phType) { + return((char *)elfPhType[phType].phTypeName); + } + +char *elfGetRelType(int relType) { + return((char *)elfRelType[relType].relTypeName); + } + +int elf_loadfile(kTask_t *p,const char *file,u_int32_t *addr,u_int32_t *entry) { + int i = 0x0; + int x = 0x0; + int numsegs = 0x0; + u_int32_t base = 0x0; + u_int32_t base_addr = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + struct file *exec_fd = 0x0; + + exec_fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(exec_fd,file,"r"); + if (exec_fd == 0x0) + return(-1); +kprintf("MOO"); + /* Load the ELF header */ + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + K_PANIC("malloc failed!"); + fread(binaryHeader,sizeof(elfHeader),1,exec_fd); + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kfree(binaryHeader); + fclose(exec_fd); + return(-1); + } + + if (binaryHeader->eType == ET_DYN) + base = *addr; + else if (binaryHeader->eType == ET_EXEC) + base = 0x0; + else + return(-1); + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) + K_PANIC("malloc failed!"); + fseek(exec_fd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,exec_fd); +kprintf("MEW: [0x%X]",base); + for (i = 0x0;i < binaryHeader->ePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + /* Make readonly and read/write */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + base),PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + base),0x0,0x1000); + } + + /* Now Load Section To Memory */ + fseek(exec_fd,programHeader[i].phOffset,0); + fread((void *)programHeader[i].phVaddr + base,programHeader[i].phFilesz,1,exec_fd); + + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x + base,PAGE_PRESENT | PAGE_USER)) != 0x0) + K_PANIC("vmm_setPageAttributes failed"); + } + } + if (numsegs == 0x0) + base_addr = (programHeader[i].phVaddr & 0xFFFFF000) + base; + numsegs++; + break; + } + } + *addr = base_addr; + kprintf("entry: [0x%X]\n",*entry); + *entry = binaryHeader->eEntry + base; + kprintf("entry: [0x%X]\n",*entry); + return(0x0); + } + +/*** + END + ***/ + diff --git a/kernel/endtask.c b/kernel/endtask.c new file mode 100644 index 0000000..493fb08 --- /dev/null +++ b/kernel/endtask.c @@ -0,0 +1,72 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/************************************************************************ + +Function: endTask(pidType pid) + +Description: This will do cleanup for an ending task + +Notes: + +************************************************************************/ +void endTask(pidType pid) { + //kTask_t *tmpTask = 0x0; + + /* Don't mess with scheduler structures from outside the scheduler! */ + /* Just set status to dead, and let the scheduler clean up itself */ + sched_setStatus(pid,DEAD); + //tmpTask = schedFindTask(pid); + //if (sched_deleteTask(pid) != 0x0) + // kpanic("sched_deleteTask: Failed\n"); + //kprintf("Ending Task: (%i:0x%X)\n",tmpTask->id,tmpTask); + //sched_addDelTask(tmpTask); + //tmpTask->state = DEAD; + + //tmpTask->term->owner = tmpTask->parentPid; + + if (pid == _current->id) + while(1) + sched_yield(); + sched_yield(); + + return; + } + +/*** + END + ***/ + diff --git a/kernel/exec.c b/kernel/exec.c new file mode 100644 index 0000000..11f0c01 --- /dev/null +++ b/kernel/exec.c @@ -0,0 +1,784 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* WHERE SHOULD THE STACK BE? */ +#define STACK_ADDR 0x80000000 //0xC800000 + +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ + +//#define AUXARGS_ENTRY(pos, id, val) {memcpy((void *)pos++,(void *)id,sizeof(long)); memcpy((void *)pos++,(void *)val,sizeof(long));} +#define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;} + + + +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + +*****************************************************************************************/ +uInt32 execThread(void (* tproc)(void),uInt32 stack,char *arg) { + kTask_t * newProcess = 0x0; + /* Find A New Thread */ + newProcess = schedNewTask(); + assert(newProcess); + if (stack < 0x100000) + kpanic("exec: stack not in valid area: [0x%X]\n",stack); + + /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int)kernelPageDirectory; + newProcess->tss.eip = (unsigned int)tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + /* + newProcess->tss.es = 0x30+3; + newProcess->tss.cs = 0x28+3; + newProcess->tss.ss = 0x30+3; + newProcess->tss.ds = 0x30+3; + newProcess->tss.fs = 0x30+3; + newProcess->tss.gs = 0x30+3; + */ + + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + + newProcess->imageFd = 0x0; + + /* Set up default stack for thread here filled with arg list 3 times */ + asm volatile( + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "movl %%esp,%%eax \n" + "movl %%eax,%1 \n" + "movl %%ecx,%%esp \n" + "popa \n" + : + : "b" (arg),"m" (newProcess->tss.esp) + ); + + /* Put new thread into the READY state */ + sched_setStatus(newProcess->id,READY); + + /* Return with the new process ID */ + return((uInt32)newProcess); + } + +/***************************************************************************************** + + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: + + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + +*****************************************************************************************/ +void execFile(char *file,int argc,char **argv,int console) { + + int i = 0x0; + int x = 0x0; + u_int32_t *tmp = 0x0; + + struct file *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + + /* Get A New Task For This Proccess */ + _current = schedNewTask(); + assert(_current); + _current->gid = 0x0; + _current->uid = 0x0; + _current->term = tty_find(console); + if (_current->term == 0x0) + kprintf("Error: invalid console\n"); + + /* Set tty ownership */ + _current->term->owner = _current->id; + + /* Now We Must Create A Virtual Space For This Proccess To Run In */ + _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); + + /* To Better Load This Application We Will Switch Over To Its VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(_current->tss.cr3)) + ); + + /* Lets Find The File */ + tmpFd = (struct file *)kmalloc(sizeof(struct file)); + fopen(tmpFd,file,"r"); + + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + if (tmpFd->perms == 0x0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + + + //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + fseek(tmpFd,binaryHeader->ePhoff,0); + + //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); + //kprintf(">d<"); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i=0;iePhnum;i++) { + if (programHeader[i].phType == 1) { + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + K_PANIC("Remap Page Failed"); + + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + } + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *)(programHeader[i].phVaddr & 0xFFFFF000); + /* Now Load Section To Memory */ + fseek(tmpFd,programHeader[i].phOffset,0); + fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + #ifdef DEBUG + kprintf("pH: [0x%X]\n",programHeader[i].phMemsz); + #endif + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n",__FILE__,__LINE__); + } + } + } + } + + /* Set Virtual Memory Start */ + _current->oInfo.vmStart = 0x80000000; + _current->td.vm_daddr = (char *)(programHeader[i].phVaddr & 0xFFFFF000); + + /* Set Up Stack Space */ + for (x = 1;x < 100;x++) { + vmm_remapPage(vmmFindFreePage(_current->id),STACK_ADDR - (x * 0x1000),PAGE_DEFAULT | PAGE_STACK); + } + + /* Kernel Stack 0x2000 bytes long */ + vmm_remapPage(vmmFindFreePage(_current->id),0x5BC000,KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmmFindFreePage(_current->id),0x5BB000,KERNEL_PAGE_DEFAULT | PAGE_STACK); + + /* Set All The Proper Information For The Task */ + _current->tss.back_link = 0x0; + _current->tss.esp0 = 0x5BC000; + _current->tss.ss0 = 0x10; + _current->tss.esp1 = 0x0; + _current->tss.ss1 = 0x0; + _current->tss.esp2 = 0x0; + _current->tss.ss2 = 0x0; + _current->tss.eip = (long)binaryHeader->eEntry; + _current->tss.eflags = 0x206; + _current->tss.esp = STACK_ADDR - 12; + _current->tss.ebp = STACK_ADDR; + _current->tss.esi = 0x0; + _current->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + _current->tss.es = 0x30+3; + _current->tss.cs = 0x28+3; + _current->tss.ss = 0x30+3; + _current->tss.ds = 0x30+3; + _current->tss.fs = 0x30+3; + _current->tss.gs = 0x30+3; + + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x0000; + _current->tss.io_map = 0x8000; + + sched_setStatus(_current->id,READY); + + kfree(binaryHeader); + kfree(programHeader); + fclose(tmpFd); + + tmp = (uInt32 *)_current->tss.esp0 - 5; + tmp[0] = binaryHeader->eEntry; + tmp[3] = STACK_ADDR - 12; + + tmp = (uInt32 *)STACK_ADDR - 2; + /* + if (_current->id > 4) + kprintf("argv[0]: [%s]\n",argv[0]); + kprintf("argv: [0x%X]\n",argv); + */ + tmp[0] = (u_int32_t)argv; + tmp[1] = (u_int32_t)argv; + + + /* Switch Back To The Kernels VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(kernelPageDirectory)) + ); + + /* Finally Return */ + return; + } + +/***************************************************************************************** + + Function: void sysExec(); + Description: This Is The System Call To Execute A New Task + + Notes: + 04-22-03 - It Now Loads Sections Not The Full File + +*****************************************************************************************/ +void sysExec(char *file,char *ap,char *ep) { + int i = 0x0; + int x = 0x0; + int argc = 0x0; + uInt32 *tmp = 0x0; + uInt32 ldAddr = 0x0; + uInt32 seg_size = 0x0; + uInt32 seg_addr = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **envp = 0x0; + char **argvNew = 0x0; + char *args = 0x0; + + struct file *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynamic *elfDynamicS = 0x0; + struct i386_frame *iFrame = 0x0; + + kprint("Sys EXEC\n"); + + /* Need to rewrite this routine? */ + tmpFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + if (fopen(tmpFd,file,"r") == 0x0) { + //kprintf("[0x%X]\n",tmpFd); + //kfree(tmpFd); //We need this but it's being done in fopen right now + return(0x0); + _current->imageFd = 0x0; + } + _current->imageFd = tmpFd; + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + return; + } + if (tmpFd->perms == 0) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + endTask(_current->id); + + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + + return; + } + else if (binaryHeader->eType != 2) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) + endTask(_current->id); + + assert(programHeader); + fseek(tmpFd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); + + if ((sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum)) == 0x0) + endTask(_current->id); + + assert(sectionHeader); + fseek(tmpFd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i=0;iePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + } + + /* Now Load Section To Memory */ + fseek(tmpFd,programHeader[i].phOffset,0); + fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) + kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n",__FILE__,__LINE__); + } + } + #ifdef DEBUG + kprintf("setting daddr\n"); + #endif + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *)seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_DYNAMIC: + //newLoc = (char *)programHeader[i].phVaddr; + elfDynamicS = (elfDynamic *)programHeader[i].phVaddr; + fseek(tmpFd,programHeader[i].phOffset,0); + fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + break; + case PT_INTERP: + interp = (char *)kmalloc(programHeader[i].phFilesz); + fseek(tmpFd,programHeader[i].phOffset,0); + fread((void *)interp,programHeader[i].phFilesz,1,tmpFd); + #ifdef LD_DEBUG + kprintf("Interp: [%s]\n",interp); + #endif + ldAddr = ldEnable(); + break; + default: + break; + } + } + + /* What is this doing? 11/23/06 */ + if (elfDynamicS != 0x0) { + for (i=0;i<12;i++) { + if (elfDynamicS[i].dynVal == 0x3) { + tmp = (uInt32 *)elfDynamicS[i].dynPtr; + if (tmp == 0x0) + kpanic("tmp: NULL\n"); + tmp[2] = (uInt32)ldAddr; + tmp[1] = (uInt32)tmpFd; + break; + } +/* + else { + kprintf("dyn_val: %i",elfDynamicS[i].dynVal); + } +*/ + } + } + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *)seg_addr; + kprintf("STATING: [0x%X][0x%X]\n",_current->td.vm_dsize,_current->td.vm_daddr); + + argv = ap; + envp = ep; + + if ((ep != 0x0) && (envp[0] != 0x0)) + kprintf("ENV SIZE: [0x%X]\n",envp[0]); + + if (argv[1] != 0x0) { + argc = argv[0]; + args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + //! do we need this? + memset(args,0x0,0x1000); + x = 0x0; + argvNew = (char **)kmalloc(sizeof(char *) * argc); + for (i = 0x0;i < argc;i++) { + strcpy(args + x,argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + //args[x] = '\0'; + //x++; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + + //! Adjust iframe + iFrame = _current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = binaryHeader->eEntry; + iFrame->user_esp = STACK_ADDR - 12; + + //if (_current->id > 3) { + + iFrame->user_esp = ((u_int32_t)STACK_ADDR) - (sizeof(u_int32_t) * (argc + 3)); + tmp = iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0;i < argc;i++) { + tmp[i + 1] = argv[i]; + } + tmp[argc + 1] = 0x0; + tmp[argc + 2] = 0x1; + //} + //else { + //tmp = (u_int32_t *)STACK_ADDR - 2; + //tmp[0] = 0x1; + //tmp[1] = 0x0; + //tmp[1] = (u_int32_t)argv; + //} + kfree(argvNew); + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + kfree(binaryHeader); + kfree(programHeader); + + return; + } + +/*! + * \brief New exec... + * + */ +int sys_exec(char *file,char *ap) { + int i = 0x0; + int x = 0x0; + int argc = 0x0; + u_int32_t *tmp = 0x0; + u_int32_t seg_size = 0x0; + u_int32_t seg_addr = 0x0; + u_int32_t addr = 0x0; + u_int32_t eip = 0x0; + u_int32_t proghdr = 0x0; + char *args = 0x0; + char *interp = 0x0; + char **argv = 0x0; + char **argvNew = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + struct i386_frame *iFrame = 0x0; + Elf_Auxargs *auxargs = 0x0; + + + _current->imageFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(_current->imageFd,file,"r"); + if (_current->imageFd == 0x0) + return(-1); + + /* Load the ELF header */ + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + K_PANIC("malloc failed!"); + fread(binaryHeader,sizeof(elfHeader),1,_current->imageFd); + + /* Check If App Is A Real Application */ + if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { + kfree(binaryHeader); + fclose(_current->imageFd); + return(-1); + } + + /* Load The Program Header(s) */ + if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) + K_PANIC("malloc failed!"); + fseek(_current->imageFd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,_current->imageFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i = 0x0;i < binaryHeader->ePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + seg_addr = trunc_page(programHeader[i].phVaddr); + seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + /* Make readonly and read/write !!! */ + if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + K_PANIC("Error: Remap Page Failed"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + } + + /* Now Load Section To Memory */ + fseek(_current->imageFd,programHeader[i].phOffset,0); + fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,_current->imageFd); + if ((programHeader[i].phFlags & 0x2) != 0x2) { + for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) + K_PANIC("vmm_setPageAttributes failed"); + } + } + if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { + /* We're suposed to do something here? */ + } + else { + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *)seg_addr; + } + + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); + break; + case PT_INTERP: + interp = (char *)kmalloc(programHeader[i].phFilesz); + if (interp == 0x0) + K_PANIC("malloc failed"); + + fseek(_current->imageFd,programHeader[i].phOffset,0); + fread((void *)interp,programHeader[i].phFilesz,1,_current->imageFd); + #ifdef LD_DEBUG + kprintf("Interp: [%s]\n",interp); + #endif + //ldAddr = ldEnable(); + break; + case PT_PHDR: + proghdr = programHeader[i].phVaddr; + break; + default: + break; + } + } + + addr = LD_START; + + + if (interp != 0x0) { + //kprintf("TEST"); + elf_loadfile(_current,interp,&addr,&eip); + } + //kprintf("[0x%X][0x%X]\n",eip,addr); + + _current->td.vm_dsize = seg_size >> PAGE_SHIFT; + _current->td.vm_daddr = (char *)seg_addr; + + //! copy in arg strings + argv = (char **)ap; + + if (argv[1] != 0x0) { + argc = (int)argv[0]; + args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + memset(args,0x0,0x1000); + x = 0x0; + argvNew = (char **)kmalloc(sizeof(char *) * argc); + for (i = 0x0;i < argc;i++) { + strcpy(args + x,argv[i + 1]); + argvNew[i] = args + x; + x += strlen(argv[i + 1]) + 1; + } + argv = argvNew; + } + + //! Clean the virtual of COW pages left over from the fork + vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + + //! Adjust iframe + iFrame = (struct i386_frame *)_current->tss.esp0 - sizeof(struct i386_frame); + iFrame->ebp = STACK_ADDR; + iFrame->eip = eip; + + //if (_current->id > 3) { + + iFrame->user_esp = ((u_int32_t)STACK_ADDR) - (sizeof(u_int32_t) * (argc + 4 + (sizeof(Elf_Auxargs) * 2))); + #ifdef DEBUG + kprintf("\n\n\nuser_esp: [0x%X]\n",iFrame->user_esp); + #endif + tmp = (u_int32_t *)iFrame->user_esp; + + //! build argc and argv[] + tmp[0] = argc; + for (i = 0;i < argc;i++) { + tmp[i + 1] = (u_int32_t)argv[i]; + } + //! Build ENV + args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); + memset(args,0x0,0x1000); + + strcpy(args,"LIBRARY_PATH=/lib"); + tmp[argc + 2] = (u_int32_t)args; + #ifdef DEBUG + kprintf("env: [0x%X][0x%X]\n",(uInt32)tmp + argc + 2,tmp[argc + 2]); + #endif + tmp[argc + 3] = 0x0; + #ifdef DEBUG + kprintf("env: [0x%X][0x%X]\n",(uInt32)tmp + argc + 2,tmp[argc + 2]); + #endif + + tmp = (u_int32_t *)iFrame->user_esp; + tmp += argc + 4; + + + auxargs->execfd = -1; + auxargs->phdr = proghdr; + auxargs->phent = binaryHeader->ePhentsize; + auxargs->phnum = binaryHeader->ePhnum; + auxargs->pagesz = PAGE_SIZE; + auxargs->base = addr; + auxargs->flags = 0x0; + auxargs->entry = binaryHeader->eEntry; + auxargs->trace = 0x0; + + AUXARGS_ENTRY(tmp, AT_PHDR, auxargs->phdr); + AUXARGS_ENTRY(tmp, AT_PHENT, auxargs->phent); + AUXARGS_ENTRY(tmp, AT_PHNUM, auxargs->phnum); + AUXARGS_ENTRY(tmp, AT_PAGESZ, auxargs->pagesz); + AUXARGS_ENTRY(tmp, AT_FLAGS, auxargs->flags); + AUXARGS_ENTRY(tmp, AT_ENTRY, auxargs->entry); + AUXARGS_ENTRY(tmp, AT_BASE, auxargs->base); + AUXARGS_ENTRY(tmp, AT_NULL, 0); + + #ifdef DEBUG + kprintf("AT_BASE: [0x%X]\n",auxargs->base); + #endif + + return(0); + } + +/*** + END + ***/ diff --git a/kernel/fork.c b/kernel/fork.c new file mode 100644 index 0000000..a91a496 --- /dev/null +++ b/kernel/fork.c @@ -0,0 +1,142 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/***************************************************************************************** + Functoin: static int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi, + long esi, long none,long ebx,long ecx,long edx,long eip,long cs,long eflags, + long esp,long ss) + + Desc: This function will copy a process + + Notes: + +*****************************************************************************************/ +/* Had to remove static though tihs function is only used in this file */ +int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss) { + volatile struct taskStruct * tmpProcPtr = newProcess; + assert(newProcess); + assert(_current); + + /* Set Up New Tasks Information */ + memcpy(newProcess->oInfo.cwd,_current->oInfo.cwd,1024); + + newProcess->tss.eip = eip; + newProcess->oInfo.vmStart = _current->oInfo.vmStart; + newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + + /* Create A Copy Of The VM Space For New Task */ + newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); + newProcess->state = FORK; + + /* Fix gcc optimization problems */ + while (tmpProcPtr->state == FORK) sched_yield(); + + /* Return Id of Proccess */ + return(newProcess->id); + } + +/***************************************************************************************** + Functoin: void sysFork(); + + Desc: This function + will fork a new task + + Notes: + + 08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + +*****************************************************************************************/ +asm( + ".globl sysFork \n" + "sysFork: \n" + " xor %eax,%eax \n" + " call schedNewTask \n" + " testl %eax,%eax \n" + " je fork_ret \n" + " pushl %esi \n" + " pushl %edi \n" + " pushl %ebp \n" + " pushl %eax \n" + " call fork_copyProcess \n" + " movl %eax,(%ebx) \n" + " addl $16,%esp \n" + "fork_ret: \n" + " ret \n" + ); + +int fork(struct thread *td,struct fork_args *uap) { + td->td_retval[0] = 0x0; + td->td_retval[1] = 0x0; + K_PANIC("Error: The new fork syscall is not yet implimented"); + return(0x0); + } + +/*** + END + ***/ diff --git a/kernel/gen_calls.c b/kernel/gen_calls.c new file mode 100644 index 0000000..d1104b2 --- /dev/null +++ b/kernel/gen_calls.c @@ -0,0 +1,137 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* return the process id */ +int getpid(struct thread *td, struct getpid_args *uap) { + #ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + td->td_retval[0] = _current->id; + return (0); + } + +/* return the process user id */ +int getuid(struct thread *td, struct getuid_args *uap) { + #ifdef DEBUG + kprintf("[%s:%i]\n",__FILE__,__LINE__); + #endif + td->td_retval[0] = _current->uid; + return (0); + } + +/* return the process group id */ +int getgid(struct thread *td, struct getgid_args *uap) { + #ifdef DEBUG + kprintf("[%s:%i]\n",__FILE__,__LINE__); + #endif + td->td_retval[0] = _current->gid; + return (0); + } + +int issetugid(register struct thread *td, struct issetugid_args *uap) { + #ifdef DEBUG + kprintf("Not Implimented: issetugid\n"); + kprintf("[%s:%i]\n",__FILE__,__LINE__); + #endif + if ((td->mode & S_GID) || S_GID) + td->td_retval[0] = 1; + else + td->td_retval[0] = 0; + return (0); + } + +int readlink(struct thread *td,struct readlink_args *uap) { + #ifdef NOTIMP + kprintf("[%s:%i]\n",__FILE__,__LINE__); + kprintf("readlink: [%s:%i]\n",uap->path,uap->count); + #endif + td->td_retval[0] = -1; + td->td_retval[1] = 0x0; + return(0x0); + } + +int gettimeofday_new(struct thread *td, struct gettimeofday_args *uap) { + #ifdef NOTIMP + kprintf("Not Implimented: gettimeofday\n"); + kprintf("[%s:%i]\n",__FILE__,__LINE__); + #endif + return(0x0); + } + +/*! + * \brief place holder for now functionality to be added later + */ +int setitimer(struct thread *td, struct setitimer_args *uap) { + int error = 0x0; + + #ifdef NOTIMP + kprintf("Not Implimented: setitimer\n"); + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + + return(error); + } + +int access(struct thread *td, struct access_args *uap) { + int error = 0x0; + + #ifdef NOTIMP + kprintf("Not Implimented: access\n"); + kprintf("name: [%s]\n",uap->path); + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + + return(error); + } + +int mprotect(struct thread *td, struct mprotect_args *uap) { + int error = 0x0; + + #ifdef NOTIMP + kprintf("Not Implimented: mprotect\n"); + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + + return(error); + } + +/*** + END + ***/ diff --git a/kernel/kern_descrip.c b/kernel/kern_descrip.c new file mode 100644 index 0000000..e0815fc --- /dev/null +++ b/kernel/kern_descrip.c @@ -0,0 +1,241 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int fcntl(struct thread *td, struct fcntl_args *uap) { + struct file *fp = 0x0; + + #ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + + if (td->o_files[uap->fd] == 0x0) { + kprintf("ERROR: No %i\n",uap->fd); +while(1); + return(-1); + } + + fp = (struct file *)td->o_files[uap->fd]; + switch (uap->cmd) { + case 3: + td->td_retval[0] = fp->f_flag; + break; + case 4: + fp->f_flag &= ~FCNTLFLAGS; + fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS; + break; + default: + kprintf("ERROR DEFAULT"); + } + + return(0x0); + } + +int falloc(struct thread *td,struct file **resultfp, int *resultfd) { + struct file *fp = 0x0; + int i = 0; + + #ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); + #endif + + fp = (struct file *)kmalloc(sizeof(struct file)); + /* First 5 Descriptors Are Reserved */ + for (i = 5;i<1024;i++) { + if (td->o_files[i] == 0x0) { + td->o_files[i] = (uInt32)fp; + if (resultfd) + *resultfd = i; + if (resultfp) + *resultfp = fp; + break; + } + } + return(0x0); + } + +/*! + * \brief return data table size + */ +int getdtablesize(struct thread *td, struct getdtablesize_args *uap) { + #ifdef NOTIMP + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + td->td_retval[0] = O_FILES; + return (0); + } + +/* BUGS: Getting closer*/ +int stat(struct thread *td,struct stat_args *uap) { + #ifdef VFSDEBUG + kprintf("[%s:%i]",__FILE__,__LINE__,__FUNCTION__); + #endif + + #ifdef NOTIMP + kprintf("stat: %s\n",uap->path); + #endif + + if (!strcmp(uap->path,"ls")) { + kprintf("LS: [%i]\n",td->td_retval[0]); + uap->ub->st_dev = 81; + uap->ub->st_ino = 31; + uap->ub->st_nlink = 1; + uap->ub->st_atime = 1213841701; + uap->ub->st_mtime = 1213841701; + uap->ub->st_ctime = 1213841701; + uap->ub->st_birthtime = 1213841701; + uap->ub->st_size = 25228; + uap->ub->st_rdev = 2496; + uap->ub->st_mode = 33133; + uap->ub->st_blocks = 52; + uap->ub->st_blksize = 4096; + return(0x0); + } + td->td_retval[0] = -1; + return(0x0); + } + + +int fstat(struct thread *td,struct fstat_args *uap) { + struct file *fp = 0x0; + + #ifdef VFSDEBUG + kprintf("[%s:%i]",__FILE__,__LINE__,__FUNCTION__); + #endif + + fp = (struct file *)_current->td.o_files[uap->fd]; + uap->sb->st_mode = 0x2180; + uap->sb->st_blksize = 0x1000; + uap->sb->st_size = fp->size; + #ifdef NOTIMP + kprintf("fstat: %i\n",uap->fd); + #endif + return(0x0); + } + +int lstat(struct thread *td,struct lstat_args *uap) { + #ifdef VFSDEBUG + kprintf("[%s:%i]",__FILE__,__LINE__,__FUNCTION__); + #endif + + #ifdef NOTIMP + kprintf("lstat: %s\n",uap->path); + #endif + + if (!strcmp(uap->path,"ls")) { + kprintf("LS: [%i]\n",td->td_retval[0]); + uap->ub->st_dev = 81; + uap->ub->st_ino = 31; + uap->ub->st_nlink = 1; + uap->ub->st_atime = 1213841701; + uap->ub->st_mtime = 1213841701; + uap->ub->st_ctime = 1213841701; + uap->ub->st_birthtime = 1213841701; + uap->ub->st_size = 25228; + uap->ub->st_rdev = 2496; + uap->ub->st_mode = 33133; + uap->ub->st_blocks = 52; + uap->ub->st_blksize = 4096; + return(0x0); + } + td->td_retval[0] = -1; + return(0); + } + + +/*! + * \brief ioctl functionality not implimented yet + * + * \returns NULL for now + */ +int ioctl(struct thread *td, struct ioctl_args *uap) { + short *tmpShort = 0x0; + #ifdef NOTIMP + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + if (uap->fd == 1) { + switch (uap->com) { + case 0x40087468: + tmpShort = uap->data; + tmpShort[0] = 0x25; + tmpShort[1] = 0x9B; + tmpShort[2] = 0x0; + tmpShort[3] = 0x0; + break; + default: + kprintf("Unknown Com: 0x%X\n",uap->com); + } + } + else { + kprintf("ioctl: %i, 0x%X\n",uap->fd,uap->com); + } + + td->td_retval[0] = 0x0; + return(0x0); + } + +/*! + * \brief get pointer to file fd in specified thread + * + * \return returns fp + */ +int getfd(struct thread *td,struct file **fp,int fd) { + int error = 0x0; + + #ifdef DEBUG + kprintf("[%s:%i]",__FILE__,__LINE__); + kprintf("GetFD: [%i]\n",fd); + #endif + + if (fd < 5) { + kprintf("Trying to open a system descriptor\n"); + while (1); + } + + *fp = (struct file *)td->o_files[fd]; + + if (fp == 0x0) + error = -1; + + return(error); + } + +/*** + END + ***/ + diff --git a/kernel/kern_sig.c b/kernel/kern_sig.c new file mode 100644 index 0000000..478f7fa --- /dev/null +++ b/kernel/kern_sig.c @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int sigaction(struct thread *td,register struct sigaction_args *uap) { + return(0x0); + } + +int sigprocmask(register struct thread *td, struct sigprocmask_args *uap) { + return (0x0); + } + + + +/*** + END + ***/ + diff --git a/kernel/kern_sysctl.c b/kernel/kern_sysctl.c new file mode 100644 index 0000000..a99f0d6 --- /dev/null +++ b/kernel/kern_sysctl.c @@ -0,0 +1,253 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct sysctl_entry *ctls = 0x0; + +static struct sysctl_entry *sysctl_find(int *,int); + +/* This is a cheat for now */ +static void def_ctls() { + int name[CTL_MAXNAME], name_len; + uInt32 page_val = 0x1000; + name[0] = 6; + name[1] = 7; + name_len = 2; + sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32)); + /* Clock Rate */ + name[0] = 1; + name [1] = 12; + page_val = 0x3E8; + sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32)); + /* User Stack */ + name[0] = 1; + name [1] = 33; + page_val = 0xCBE8000; + sysctl_add(name,name_len,"page_size",&page_val,sizeof(uInt32)); + } + +int sysctl_init() { + struct sysctl_entry *tmpCtl = 0x0; + if (ctls != 0x0) { + kprintf("sysctl already Initialized\n"); + while (1); + } + + ctls = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + ctls->prev = 0x0; + ctls->id = CTL_UNSPEC; + ctls->children = 0x0; + sprintf(ctls->name,"unspec"); + + tmpCtl = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->prev = ctls; + tmpCtl->id = CTL_KERN; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"kern"); + ctls->next = tmpCtl; + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_VM; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"vm"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_VFS; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"vfs"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_NET; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"net"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_DEBUG; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"debug"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_HW; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"hw"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_MACHDEP; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"machdep"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_USER; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"user"); + + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_P1003_1B; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"p1003_1b"); + + tmpCtl->next = (struct sysctl_enctry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next->prev = tmpCtl; + tmpCtl = tmpCtl->next; + tmpCtl->id = CTL_UBIX; + tmpCtl->children = 0x0; + sprintf(tmpCtl->name,"ubix"); + + def_ctls(); + + return(0x0); + } + +int __sysctl(struct thread *td, struct sysctl_args *uap) { + struct sysctl_entry *tmpCtl = 0x0; + int i = 0; + + if (ctls == 0x0) + K_PANIC("sysctl not initialized"); + + if (uap->newlen < 0) { + kprintf("Changing Not supported yet.\n"); + endTask(_current->id); + } + + tmpCtl = sysctl_find(uap->name,uap->namelen); + if (tmpCtl == 0x0) { + kprintf("Invalid CTL\n"); + for (i = 0x0;i < uap->namelen;i++) + kprintf("(%i)",uap->name[i]); + kprintf("\n"); + endTask(_current->id); + } + + if ((u_int32_t)uap->oldlenp < tmpCtl->val_len) + memcpy(uap->old,tmpCtl->value,(uInt32)uap->oldlenp); + else + memcpy(uap->old,tmpCtl->value,tmpCtl->val_len); + + td->td_retval[0] = 0x0; + + return(0x0); + } + +static struct sysctl_entry *sysctl_find(int *name,int namelen) { + int i = 0x0; + struct sysctl_entry *tmpCtl = 0x0; + struct sysctl_entry *lCtl = ctls; + + /* Loop Name Len */ + for (i = 0x0; i < namelen;i++) { + for (tmpCtl = lCtl;tmpCtl != 0x0;tmpCtl = tmpCtl->next) { + //kprintf("ctlName: [%s], ctlId; [%i]\n",tmpCtl->name,tmpCtl->id); + if (tmpCtl->id == name[i]) { + if ((i+1) == namelen) { + return(tmpCtl); + } + lCtl = tmpCtl->children; + break; + } + } + } + return(0x0); + } + +int sysctl_add(int *name,int namelen,char *str_name,void *buf,int buf_size) { + struct sysctl_entry *tmpCtl = 0x0; + struct sysctl_entry *newCtl = 0x0; + + /* Check if it exists */ + tmpCtl = sysctl_find(name,namelen); + if (tmpCtl != 0x0) { + kprintf("Node Exists!\n"); + while (1); + } + + /* Get Parent Node */ + tmpCtl = sysctl_find(name,namelen-1); + if (tmpCtl == 0x0) { + kprintf("Parent Node Non Existant\n"); + return(-1); + } + if (tmpCtl->children == 0x0) { + tmpCtl->children = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->children->children = 0x0; + tmpCtl->children->prev = 0x0; + tmpCtl->children->next = 0x0; + tmpCtl->children->id = name[namelen-1]; + sprintf(tmpCtl->children->name,str_name); + tmpCtl->children->value = (void *)kmalloc(buf_size); + memcpy(tmpCtl->children->value,buf,buf_size); + tmpCtl->children->val_len = buf_size; + } + else { + newCtl = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); + newCtl->prev = 0x0; + newCtl->next = tmpCtl->children; + newCtl->children = 0x0; + newCtl->id = name[namelen-1]; + sprintf(newCtl->name,str_name); + newCtl->value = (void *)kmalloc(buf_size); + memcpy(newCtl->value,buf,buf_size); + newCtl->val_len = buf_size; + tmpCtl->children->prev = newCtl; + tmpCtl->children = newCtl; + } + + return(0x0); + } + + +/*** + END + ***/ diff --git a/kernel/kpanic.c b/kernel/kpanic.c new file mode 100644 index 0000000..49e8b7a --- /dev/null +++ b/kernel/kpanic.c @@ -0,0 +1,66 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/*! + * \brief print panic message and halt system + * + * \param fmt panic message + * + */ +void kpanic(const char *fmt, ...) { + char buf[512]; + vaList args; + + vaStart(args, fmt); + vsprintf(buf, fmt, args); + vaEnd(args); + + /* It's important that we print on the current terminal so let's reset foreground */ + tty_foreground = NULL; + kprint(buf); + + /* Halt The System */ + //asm("cli"); + irqDisable(0x0); + + while (1) + asm("hlt"); + } + +/*** + END + ***/ + diff --git a/kernel/ld.c b/kernel/ld.c new file mode 100644 index 0000000..2d7825c --- /dev/null +++ b/kernel/ld.c @@ -0,0 +1,200 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +uInt32 ldEnable() { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + int sym = 0x0; + char *newLoc = 0x0; + char *shStr = 0x0; + char *dynStr = 0x0; + uInt32 *reMap = 0x0; + fileDescriptor *ldFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynSym *relSymTab = 0x0; + elfPltInfo *elfRel = 0x0; + + /* Open our dynamic linker */ + ldFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(ldFd,"sys:/lib/ld.so","rb"); + + if (ldFd == 0x0) { + kprintf("Can not open ld.so\n"); + } + #ifdef LD_DEBUG + kprintf("Loading LD\n"); + #endif + + fseek(ldFd,0x0,0x0); + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + assert(binaryHeader); + fread(binaryHeader,sizeof(elfHeader),1,ldFd); + + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + assert(programHeader); + fseek(ldFd,binaryHeader->ePhoff,0); + fread(programHeader,sizeof(elfSectionHeader),binaryHeader->ePhnum,ldFd); + + sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + assert(sectionHeader); + fseek(ldFd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,ldFd); + + shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); + fseek(ldFd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); + fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,ldFd); + + for (i = 0x0;i < binaryHeader->ePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + newLoc = (char *)programHeader[i].phVaddr + LD_START; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x < (programHeader[i].phMemsz);x += 0x1000) { + /* make r/w or ro */ + if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage: ld"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); + } + //kprintf("X: 0x%X\n",x); + /* Now Load Section To Memory */ + fseek(ldFd,programHeader[i].phOffset,0x0); + fread(newLoc,programHeader[i].phFilesz,1,ldFd); + //kprintf("Z:[0x%X - 0x%X]\n",programHeader[i].phOffset,programHeader[i].phFilesz); + break; + case PT_DYNAMIC: + newLoc = (char *)programHeader[i].phVaddr + LD_START; + /* Now Load Section To Memory */ + fseek(ldFd,programHeader[i].phOffset,0x0); + //kprintf("fread: [0x%X - 0x%X]",newLoc,fread(newLoc,programHeader[i].phFilesz,1,ldFd)); + break; + case PT_GNU_STACK: + /* Tells us if the stack should be executable. Failsafe to executable + until we add checking */ + kprintf("WTF!"); + break; + case PT_PAX_FLAGS: + /* Not sure... */ + break; + default: + //kprintf("Unhandled Header (kernel) : %08x\n", programHeader[i].phType); + break; + } + } + + for (i=0x0;ieShnum;i++) { + switch (sectionHeader[i].shType) { + case 3: + if (!strcmp((shStr + sectionHeader[i].shName),".dynstr")) { + dynStr = (char *)kmalloc(sectionHeader[i].shSize); + fseek(ldFd,sectionHeader[i].shOffset,0x0); + fread(dynStr,sectionHeader[i].shSize,1,ldFd); + } + break; + case 9: + elfRel = (elfPltInfo *)kmalloc(sectionHeader[i].shSize); + fseek(ldFd,sectionHeader[i].shOffset,0x0); + fread(elfRel,sectionHeader[i].shSize,1,ldFd); +#ifdef LD_DEBUG +kprintf("LD_START: 0x%X\n",LD_START); +#endif + for (x=0x0;xeEntry + LD_START; + + kfree(dynStr); + kfree(shStr); + kfree(relSymTab); + kfree(sectionHeader); + kfree(programHeader); + kfree(binaryHeader); + fclose(ldFd); + + return((uInt32)i); + } + +/*** + END + ***/ + diff --git a/kernel/pipe.c b/kernel/pipe.c new file mode 100644 index 0000000..b1b60fb --- /dev/null +++ b/kernel/pipe.c @@ -0,0 +1,56 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/** + HACK +*/ +int pipe(struct thread *td, struct pipe_args *uap) { + struct file *rf, *wf; + int fd = 0x0; + falloc(td,&rf,&fd); + rf->f_flag = FREAD | FWRITE; + td->td_retval[0] = fd; + falloc(td,&wf,&fd); + wf->f_flag = FREAD | FWRITE; + td->td_retval[1] = fd; + return(0x0); + } + +/*** + END + ***/ + diff --git a/kernel/sched.c b/kernel/sched.c new file mode 100644 index 0000000..cbd4c1a --- /dev/null +++ b/kernel/sched.c @@ -0,0 +1,292 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static kTask_t *taskList = 0x0; +static kTask_t *delList = 0x0; +static uInt32 nextID = -1; + +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; + +static spinLock_t schedulerSpinLock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + +Function: int sched_init() + +Description: This function is used to enable the kernel scheduler + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ + + +int sched_init() { + taskList = (kTask_t *)kmalloc(sizeof(kTask_t)); + if(taskList == 0x0) + kpanic("Unable to create task list"); + + taskList->id = nextID++; + + /* Print out information on scheduler */ + kprintf("sched0 - Address: [0x%X]\n", taskList); + + /* Return so we know everything went well */ + return(0x0); + } + + +void sched(){ + uInt32 memAddr = 0x0; + kTask_t *tmpTask = 0x0; + kTask_t *delTask = 0x0; + + if (!spinTryLock(&schedulerSpinLock)) + return; + + tmpTask = _current->next; + //outportByte(0xE9,_current->id + '0'); + schedStart: + + /* Yield the next task from the current prio queue */ + for (;tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->state > 0x0) { + _current = tmpTask; + if (_current->state == FORK) + _current->state = READY; + break; + } + else if (tmpTask->state == DEAD) + { + delTask = tmpTask; + tmpTask = tmpTask->next; + sched_deleteTask(delTask->id); + sched_addDelTask(delTask); + goto schedStart; + } + } + + /* Finished all the tasks, restarting the list */ + if (0x0 == tmpTask) { + tmpTask = taskList; + goto schedStart; + } + + + if (_current->state > 0x0) { + if (_current->oInfo.v86Task == 0x1) + irqDisable(0x0); + asm("cli"); + memAddr = (uInt32)&(_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + spinUnlock(&schedulerSpinLock); + asm("sti"); + asm("ljmp $0x20,$0\n"); + } + else + { + spinUnlock(&schedulerSpinLock); + } + + return; +} + + +kTask_t *schedNewTask() { + int i = 0; + kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); + struct file *fp = 0x0; + if (tmpTask == 0x0) + kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); + + memset(tmpTask,0x0,sizeof(kTask_t)); + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->state = NEW; + + /* HACK */ + for (i=0;i<3;i++) { + fp = kmalloc(sizeof(struct file)); + tmpTask->td.o_files[i] = (u_int32_t)fp; + fp->f_flag = 0x4; + } + + spinLock(&schedulerSpinLock); + tmpTask->id = nextID++; + tmpTask->next = taskList; + tmpTask->prev = 0x0; + taskList->prev = tmpTask; + taskList = tmpTask; + + spinUnlock(&schedulerSpinLock); + + return(tmpTask); + } + + +int sched_deleteTask(pidType id) { + kTask_t *tmpTask = 0x0; + + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + if (tmpTask->prev != 0x0) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next != 0x0) + tmpTask->next->prev = tmpTask->prev; + if (taskList == tmpTask) + taskList = tmpTask->next; + + return(0x0); + } + } + return(0x1); + } + +int sched_addDelTask(kTask_t *tmpTask) { + tmpTask->next = delList; + tmpTask->prev = 0x0; + if (delList != 0x0) + delList->prev = tmpTask; + delList = tmpTask; + return(0x0); + } + +kTask_t *sched_getDelTask() { + kTask_t *tmpTask = 0x0; + + if (delList == 0x0) + return(0x0); + + tmpTask = delList; + delList = delList->next; + return(tmpTask); + } + + +kTask_t * +schedFindTask(uInt32 id) +{ + kTask_t *tmpTask = 0x0; + + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) + return(tmpTask); + } + + return(0x0); +} + + +/************************************************************************ + + Function: void schedEndTask() + + Description: This function will end a task + + Notes: + + 02/20/2004 - Approved for quality + +************************************************************************/ +void +schedEndTask(pidType pid) { + endTask(_current->id); + sched_yield(); +} + +/************************************************************************ + +Function: int schedEndTask() + +Description: This function will yield a task + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ + +void +sched_yield() { + sched(); + } + +/* +asm( + ".globl sched_yield \n" + "sched_yield: \n" + " cli \n" + " call sched \n" + ); +*/ + +/************************************************************************ + +Function: int sched_setStatus(pidType pid,tState state) + +Description: Change the tasks status + +Notes: + +************************************************************************/ +int sched_setStatus(pidType pid,tState state) { + kTask_t *tmpTask = schedFindTask(pid); + if (tmpTask == 0x0) + return(0x1); + tmpTask->state = state; + return(0x0); + } + +/*** + END + ***/ + diff --git a/kernel/schedyield.S b/kernel/schedyield.S new file mode 100644 index 0000000..a985015 --- /dev/null +++ b/kernel/schedyield.S @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +.globl sched_yield_new +.text +.code32 +sched_yield_new: + pusha /* Save all of the registers */ + push %ss + push %ds + push %es + push %fs + push %gs + call sched + mov %eax,%esp + pop %gs + pop %fs + pop %es + pop %ds + pop %ss + popa /* Restore Registers */ + iret + +/*** + END + ***/ diff --git a/kernel/sem.c b/kernel/sem.c new file mode 100644 index 0000000..57093d6 --- /dev/null +++ b/kernel/sem.c @@ -0,0 +1,35 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +/*** + END + ***/ + diff --git a/kernel/smp.c b/kernel/smp.c new file mode 100644 index 0000000..7505cbd --- /dev/null +++ b/kernel/smp.c @@ -0,0 +1,291 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +static spinLock_t initSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t cpuInfoLock = SPIN_LOCK_INITIALIZER; +static uInt32 cpus = 0; +struct cpuinfo_t cpuinfo[8]; + +uInt8 kernel_function(void); +uInt8 *vram = (uInt8 *)0xB8000; + +static inline unsigned int apicRead(address) { + return *(volatile unsigned int *) (0xFEE00000 + address); + } + +static inline void apicWrite(unsigned int address,unsigned int data) { + *(volatile unsigned int *) (0xFEE00000 + address) = data; + } + +static __inline__ void setDr3 (void *dr3) { + register uInt32 value = (uInt32)dr3; + __asm__ __volatile__ ("mov %0, %%dr3" :: "r" (value)); + } + +static __inline__ uInt32 getDr3 (void) { + register uInt32 value; + __asm__ __volatile__ ("mov %%dr3, %0" : "=r" (value)); + return value; + } + +struct gdt_descr { + uInt16 limit; + uInt32 *base __attribute__ ((packed)); +}; + +static void GDT_fixer() { + struct gdt_descr gdt_descr; + uInt32 *gdt = (uInt32 *)0x20000; // 128KB + + gdt[0] = 0; + gdt[1] = 0; + gdt[2] = 0x0000ffff; // seg 0x8 -- DPL 0 4GB code + gdt[3] = 0x00cf9a00; + gdt[4] = 0x0000ffff; // seg 0x10 -- DPL 0 4GB data + gdt[5] = 0x00cf9200; + gdt[6] = 0x0000ffff; // seg 0x1b -- DPL 3 4GB code + gdt[7] = 0x00cffa00; + gdt[8] = 0x0000ffff; // seg 0x23 -- DPL 3 4GB data + gdt[9] = 0x00cff200; + + gdt_descr.limit = 32 * 4; + gdt_descr.base = gdt; + + /* + asm("lgdt %0;" : : "m" (gdt_descr)); + __asm__ __volatile__ ("ljmp %0,$1f; 1:" :: "i" (0x08)); + __asm__ __volatile__ ("movw %w0,%%ds" :: "r" (0x10)); + __asm__ __volatile__ ("movw %w0,%%es" :: "r" (0x10)); + __asm__ __volatile__ ("movw %w0,%%ss" :: "r" (0x10)); + */ + } + + +void cpu0_thread(void) { + for(;;) { + vram[40+640] = kernel_function(); + vram[42+640]++; + } +} +void cpu1_thread(void) { + for(;;) { + vram[60+640] = kernel_function(); + vram[62+640]++; + } +} +void cpu2_thread(void) { + for(;;) { + vram[80+640] = kernel_function(); + vram[82+640]++; + } +} +void cpu3_thread(void) { + for(;;) { + vram[100+640] = kernel_function(); + vram[102+640]++; + } +} + +static spinLock_t bkl = SPIN_LOCK_INITIALIZER; +uInt8 kernel_function(void) { + struct cpuinfo_t *cpu; + + spinLock(&bkl); + + + cpu = (struct cpuinfo_t *)getDr3(); + + spinUnlock(&bkl); + + return('0' + cpu->id); +} + + +void c_ap_boot(void) { + + while(spinLockLocked(&initSpinLock)); + + switch(cpuInfo()) { + case 1: + cpu1_thread(); + break; + case 2: + cpu2_thread(); + break; + case 3: + cpu3_thread(); + break; + } + + outportByte(0xe9,'5'); + + for(;;) { + asm("nop"); + } +} + + +void smpInit() { + spinLock(&initSpinLock); + GDT_fixer(); + cpuidDetect(); + cpuInfo(); + apicMagic(); + spinUnlock(&initSpinLock); + + //cpu0_thread(); + + } + +void cpuidDetect() { + if (!(getEflags() & (1<<21)) ) { + setEflags(getEflags() | (1<<21)); + if( !(getEflags() & (1<<21)) ) { + kpanic("CPU doesn't support CPUID, get a newer machine\n"); + } + } + } + +uInt8 cpuInfo() { + uInt32 data[4],i; + + if( !(getEflags() & (1<<21)) ) { // If the cpuid bit in eflags not set.. + setEflags(getEflags() | (1<<21)); // ..try and set it to see if it comes on.. + if( !(getEflags() & (1<<21)) ) { // It didn't.. This CPU suck + kpanic("CPU doesn't support CPUID, get a newer machine\n"); + } + } + + spinLock(&cpuInfoLock); + cpuinfo[cpus].ok = 1; + cpuinfo[cpus].apic_id = apicRead(0x20) >> 24; + cpuinfo[cpus].apic_ver = apicRead(0x30) & 0xFF; + + cpuid(0,data); + *(uInt32 *)&cpuinfo[cpus].ident[0] = data[1]; + *(uInt32 *)&cpuinfo[cpus].ident[4] = data[3]; + *(uInt32 *)&cpuinfo[cpus].ident[8] = data[2]; + cpuinfo[cpus].ident[17] = 0; + cpuinfo[cpus].max = data[0]; + + cpuid(1,data); + cpuinfo[cpus].signature = data[0]; + cpuinfo[cpus].feature = data[3]; + + cpuid(0x80000000,data); + if(data[0]>=0x80000004) { + for(i=0;i<3;i++) { + cpuid(0x80000002 + i,data); + + *(unsigned int *)&cpuinfo[cpus].brand[16*i+0] = data[0]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+4] = data[1]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+8] = data[2]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+12] = data[3]; + } + cpuinfo[cpus].brand[48] = 0; + } else { + cpuinfo[cpus].brand[0] = 0; + } + + setDr3(&cpuinfo[cpus]); // DR3 always points to the cpu-struct for that CPU (should be thread-struct of current thread) + cpuinfo[cpus].id = cpus; + + cpus++; + + spinUnlock(&cpuInfoLock); + + return(cpus - 1); + } + +extern void ap_trampoline_start(),ap_trampoline_end(); +void apicMagic(void) { + uInt32 tmp; + + kprintf("Copying %u bytes from 0x%x to 0x00\n",ap_trampoline_end - ap_trampoline_start,ap_trampoline_start); + memcpy(0x0,(char *)ap_trampoline_start,ap_trampoline_end - ap_trampoline_start); + apicWrite(0x280,0); + apicRead(0x280); + + apicWrite(0x300,0x000C4500); // INIT IPI to all CPUs + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 10ms) + apicWrite(0x300,0x000C4600); // INIT SIPI to all CPUs + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 200ms) + apicWrite(0x300,0x000C4600); // Second INIT SIPI + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 200ms) + } + + + +uInt32 getEflags() { + uInt32 eflags = 0x0; + asm( + "pushfl \n" + "popl %%eax \n" + : "=a" (eflags) + ); + return(eflags); + } + +void setEflags(uInt32 eflags) { + asm( + "pushl %%eax \n" + "popfl \n" + : + : "a" (eflags) + ); + } + +asm( + ".globl cpuid \n" + "cpuid: \n" + " pushl %ebx \n" + " pushl %edi \n" + " movl 12(%esp),%eax \n" + " movl 16(%esp),%edi \n" + " cpuid \n" + " movl %eax,0(%edi) \n" + " movl %ebx,4(%edi) \n" + " movl %ecx,8(%edi) \n" + " movl %edx,12(%edi) \n" + " popl %edi \n" + " popl %ebx \n" + " ret \n" + ); + +/*** + END + ***/ + diff --git a/kernel/spinlock.c b/kernel/spinlock.c new file mode 100644 index 0000000..6c4b722 --- /dev/null +++ b/kernel/spinlock.c @@ -0,0 +1,78 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +void spinLockInit(spinLock_t *lock) { + *lock = SPIN_LOCK_INITIALIZER; + } + +void spinUnlock(spinLock_t *lock) { + *lock = 0x0; + /* + register int unlocked; + asm volatile( + "xchgl %0, %1" + : "=&r" (unlocked), "=m" (*lock) : "0" (0) + ); + */ + } + +int spinTryLock(spinLock_t *lock) { + register int locked; + asm volatile("xchgl %0, %1" + : "=&r" (locked), "=m" (*lock) : "0" (1) + ); + return(!locked); + } + +void spinLock(spinLock_t *lock) { + while (!spinTryLock(lock)) + { + while (*lock == 1) + sched_yield(); + } +} + +void spinLock_scheduler(spinLock_t *lock) { + while (!spinTryLock(lock)) + while (*lock == 1); + } + + +int spinLockLocked(spinLock_t *lock) { + return(*lock != 0); + } + + +/*** + END + ***/ + diff --git a/kernel/sys_call.S b/kernel/sys_call.S new file mode 100644 index 0000000..271abfb --- /dev/null +++ b/kernel/sys_call.S @@ -0,0 +1,55 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +.globl _sysCall +.text +.code32 +_sysCall: + cmpl totalCalls,%eax + jae invalidSysCall + + cld + pushl %edx + pushl %ecx + pushl %ebx + call *systemCalls(,%eax,4) + popl %ebx + popl %ecx + popl %edx /* Restore Registers */ + + iret + +invalidSysCall: + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/kernel/sys_call_new.S b/kernel/sys_call_new.S new file mode 100644 index 0000000..7bf7c34 --- /dev/null +++ b/kernel/sys_call_new.S @@ -0,0 +1,68 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx + +.globl _sysCall_new +.text +.code32 +_sysCall_new: + pushl $2 /* sizeof "int 0x80" */ + subl $4,%esp /* skip over tf_trapno */ + pushal + pushl %ds + pushl %es + pushl %fs + /* switch to kernel segments */ + movl $0x10,%eax + movl %eax,%ds + movl %eax,%es + movl %eax,%fs + //FAKE_MCOUNT(TF_EIP(%esp)) + call syscall + //MEXITCOUNT + //jmp doreti + popl %fs + popl %es + popl %ds + popal + addl $8,%esp + iret + +invalidSysCall: + push %eax + call invalidCall + pop %eax + movl $-1,%eax + iret + +/*** + END + ***/ + diff --git a/kernel/syscall.c b/kernel/syscall.c new file mode 100644 index 0000000..379d4ca --- /dev/null +++ b/kernel/syscall.c @@ -0,0 +1,261 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include + +long fuword(const void *base); + +void sdeTestThread(); + +asm( + ".globl _sysCallNew \n" + "_sysCallNew: \n" + " pusha \n" + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " cmpl totalCalls,%eax \n" + " jae invalidSysCallNew \n" + " mov %esp,%ebx \n" + " add $12,%ebx \n" + " push (%ebx) \n" + " call *systemCalls(,%eax,4) \n" + " add $4,%esp \n" + " jmp doneNew \n" + "invalidSysCallNew: \n" + " call InvalidSystemCall \n" + "doneNew: \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" + ); + +void InvalidSystemCall() +{ + kprintf("attempt was made to an invalid system call\n"); + return; +} + +typedef struct _UbixUser UbixUser; +struct _UbixUser +{ + char *username; + char *password; + int uid; + int gid; + char *home; + char *shell; +}; + +void sysAuth(UbixUser *uu) +{ + kprintf("authenticating user %s\n", uu->username); + if(uu->username == "root" && uu->password == "user") + { + uu->uid = 0; + uu->gid = 0; + } + uu->uid = -1; + uu->gid = -1; + return; +} + +void sysPasswd(char *passwd) +{ + kprintf("changing user password for user %d\n", _current->uid); + return; +} + +void sysAddModule() +{ + return; +} + +void sysRmModule() +{ + return; +} + +void sysGetpid(int *pid) +{ + if (pid) + *pid = _current->id; + return; +} + +void sysGetUid(int *uid) { + if (uid) + *uid = _current->uid; + return; + } + +void sysGetGid(int *gid) { + if (gid) + *gid = _current->gid; + return; + } + +void sysSetUid(int uid,int *status) { + if (_current->uid == 0x0) { + _current->uid = uid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; + } + +void sysSetGid(int gid,int *status) { + if (_current->gid == 0x0) { + _current->gid = gid; + if (status) + *status = 0x0; + } + else { + if (status) + *status = 1; + } + return; + } + +void sysExit(int status) { + endTask(_current->id); + } + +void sysCheckPid(int pid,int *ptr) +{ + kTask_t *tmpTask = schedFindTask(pid); + if ((tmpTask != 0x0) && (ptr != 0x0)) { + *ptr = tmpTask->state; + if (*ptr != 1) + kprintf("CP: [%i]\n",*ptr); + } + else + *ptr = 0x0; + return; +} + +/************************************************************************ + +Function: void sysGetFreePage(); +Description: Allocs A Page To The Users VM Space +Notes: + +************************************************************************/ +void sysGetFreePage(long *ptr,int count,int type) { + if (ptr) { + if (type == 2) + *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_THRD); + else + *ptr = (long) vmmGetFreeVirtualPage(_current->id,count,VM_TASK); + } + return; + } + +void sysGetDrives(uInt32 *ptr) +{ + if (ptr) + *ptr = 0x0;//(uInt32)devices; + return; +} + +void sysGetUptime(uInt32 *ptr) +{ + if (ptr) + *ptr = systemVitals->sysTicks; + return; +} + +void sysGetTime(uInt32 *ptr) +{ + if (ptr) + *ptr = systemVitals->sysUptime + systemVitals->timeStart; + return; +} + + +void sysGetCwd(char *data,int len) +{ + if (data) + sprintf(data,"%s", _current->oInfo.cwd); + return; +} + +void sysSchedYield() { + sched_yield(); + } + +void sysStartSDE() { + int i = 0x0; + for (i=0;i<1400;i++) { + asm("hlt"); + } + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + for (i=0;i<1400;i++) { + asm("hlt"); + } + return; + } + +void invalidCall(int sys_call) { + kprintf("Invalid System Call #[%i]\n",sys_call); + return; + } + +/*** + END + ***/ + diff --git a/kernel/syscall_new.c b/kernel/syscall_new.c new file mode 100644 index 0000000..128c10b --- /dev/null +++ b/kernel/syscall_new.c @@ -0,0 +1,94 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +spinLock_t Master = SPIN_LOCK_INITIALIZER; + +void syscall(struct trapframe frame) { + uInt32 code = 0x0; + caddr_t params; + struct thread *td = &_current->td; + int args[8]; + int error = 0x0; + + params = (caddr_t)frame.tf_esp + sizeof(int); + + code = frame.tf_eax; + if (code == 198) { + memcpy(&code,params,sizeof(int)); + params += sizeof(quad_t); + } + + if (code > totalCalls_new) { + kprintf("Invalid Call: [%i]\n",frame.tf_eax); + } + else if ((uInt32)systemCalls_new[code] == 0x0) { + kprintf("Invalid Call: [%i][0x%X]\n",code,(uInt32)systemCalls_new[code]); + frame.tf_eax = -1; + frame.tf_edx = 0x0; + } + else { + memcpy(args,params,8 * sizeof(int)); + td->td_retval[0] = 0; + td->td_retval[1] = frame.tf_edx; + + error = (int)systemCalls_new[code](td,args); + switch (error) { + case 0: + frame.tf_eax = td->td_retval[0]; + frame.tf_edx = td->td_retval[1]; + frame.tf_eflags &= ~PSL_C; + break; + case ERESTART: + frame.tf_eip -= frame.tf_err; + break; + case EJUSTRETURN: + break; + default: + frame.tf_eax = error; + frame.tf_eflags |= PSL_C; + break; + + } + } + } + + +/*** + END + ***/ + diff --git a/kernel/systemtask.c b/kernel/systemtask.c new file mode 100644 index 0000000..c647742 --- /dev/null +++ b/kernel/systemtask.c @@ -0,0 +1,125 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned char *videoBuffer = (char *)0xB8000; + + +void systemTask() { + mpi_message_t myMsg; + uInt32 counter = 0x0; + int i = 0x0; + int *x = 0x0; + kTask_t *tmpTask = 0x0; + + if (mpi_createMbox("system") != 0x0) { + kpanic("Error: Error creating mailbox: system\n"); + } + + while(1) { + if (mpi_fetchMessage("system",&myMsg) == 0x0) { + kprintf("A"); + switch(myMsg.header) { + case 0x69: + x = (int *)&myMsg.data; + kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid); + schedFindTask(myMsg.pid)->term = tty_find(*x); + break; + case 1000: + kprintf("Restarting the system in 5 seconds\n"); + counter = systemVitals->sysUptime + 5; + while (systemVitals->sysUptime < counter) { + sched_yield(); + } + kprintf("Rebooting NOW!!!\n"); + while(inportByte(0x64) & 0x02); + outportByte(0x64, 0xFE); + break; + case 31337: + kprintf("system: backdoor opened\n"); + break; + case 0x80: + if (!strcmp(myMsg.data,"sdeStart")) { + kprintf("Starting SDE\n"); + //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + } + else if (!strcmp(myMsg.data,"freePage")) { + kprintf("kkk Free Pages"); + } + else if (!strcmp(myMsg.data,"sdeStop")) { + printOff = 0x0; + biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0); + for (i=0x0;i<100;i++) asm("hlt"); + } + break; + default: + kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data); + break; + } + } + + /* + Here we get the next task from the delete task queue + we first check to see if it has an fd attached for the binary and after that + we free the pages for the process and then free the task + */ + tmpTask = sched_getDelTask(); + if (tmpTask != 0x0) { + if (tmpTask->imageFd != 0x0) { + kprintf("Closing: [0x%X]\n",tmpTask->imageFd); + fclose(tmpTask->imageFd); + } + vmmFreeProcessPages(tmpTask->id); + kfree(tmpTask); + } + videoBuffer[0] = systemVitals->sysTicks; + sched_yield(); + } + + return; + } + +/*** + END + ***/ + diff --git a/kernel/time.c b/kernel/time.c new file mode 100644 index 0000000..2e76b04 --- /dev/null +++ b/kernel/time.c @@ -0,0 +1,120 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +static int month[12] = { + 0, + DAY*(31), + DAY*(31+29), + DAY*(31+29+31), + DAY*(31+29+31+30), + DAY*(31+29+31+30+31), + DAY*(31+29+31+30+31+30), + DAY*(31+29+31+30+31+30+31), + DAY*(31+29+31+30+31+30+31+31), + DAY*(31+29+31+30+31+30+31+31+30), + DAY*(31+29+31+30+31+30+31+31+30+31), + DAY*(31+29+31+30+31+30+31+31+30+31+30) +}; + +static int timeCmosRead(int addr) { + outportByteP(0x70,addr); + return((int)inportByte(0x71)); + } + +int time_init() { + int i; + struct timeStruct time; + + for (i = 0 ; i < 1000000 ; i++) { + if (!(timeCmosRead(10) & 0x80)) { + break; + } + } + + do { + time.sec = timeCmosRead(0); + time.min = timeCmosRead(2); + time.hour = timeCmosRead(4); + time.day = timeCmosRead(7); + time.mon = timeCmosRead(8); + time.year = timeCmosRead(9); + } while (time.sec != timeCmosRead(0)); + + BCD_TO_BIN(time.sec); + BCD_TO_BIN(time.min); + BCD_TO_BIN(time.hour); + BCD_TO_BIN(time.day); + BCD_TO_BIN(time.mon); + BCD_TO_BIN(time.year); + + /* Set up our start time in seconds */ + systemVitals->timeStart = timeMake(&time); + + kprintf("%i/%i/%i %i:%i.%i\n",time.mon,time.day,time.year,time.hour,time.min,time.sec); + + + /* Return so we know all went well */ + return(0x0); + } + +uInt32 timeMake(struct timeStruct *time) { + uInt32 res; + int year; + + year = (time->year+100) - 70; + /* magic offsets (y+1) needed to get leapyears right.*/ + res = YEAR*year + DAY*((year+1)/4); + res += month[time->mon]; + /* and (y+2) here. If it wasn't a leap-year, we have to adjust */ + if (time->mon>1 && ((year+2)%4)) + res -= DAY; + res += DAY*(time->day-1); + res += HOUR*time->hour; + res += MINUTE*time->min; + res += time->sec; + return(res); + } + +int gettimeofday(struct timeval *tp,struct timezone *tzp) { + //tp->tv_sec = systemVitals->timeStart + systemVitals->sysUptime; + tp->tv_sec = 0x0;//systemVitals->sysUptime; + tp->tv_usec = 0x0; + return(0x0); + } + +/*** + END + ***/ + diff --git a/kernel/timer.S b/kernel/timer.S new file mode 100644 index 0000000..9650c29 --- /dev/null +++ b/kernel/timer.S @@ -0,0 +1,62 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +.globl timerInt +.text +.code32 +timerInt: + pusha /* Save all of the registers */ + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx + movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ + incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ + movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + movl $200,%ebx /* Have Passed */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz next + incl 8(%ecx) +next: + movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 12(%ecx),%ebx /* We Can CALL sched */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz done + call sched +done: + popa /* Restore Registers */ + iret + +/*** + END + ***/ + diff --git a/kernel/tty.c b/kernel/tty.c new file mode 100644 index 0000000..7470c34 --- /dev/null +++ b/kernel/tty.c @@ -0,0 +1,180 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +static tty_term *terms = 0x0; +tty_term *tty_foreground = 0x0; +static spinLock_t tty_spinLock = SPIN_LOCK_INITIALIZER; + +int tty_init() { + int i = 0x0; + + /* Allocate memory for terminals */ + terms = (tty_term *)kmalloc(sizeof(tty_term)*TTY_MAX_TERMS); + if (terms == 0x0) + kpanic("tty_init: Failed to allocate memory. File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Set up all default terminal information */ + for (i = 0;i < TTY_MAX_TERMS;i++) { + terms[i].tty_buffer = (char *)kmalloc(80*60*2); + if (terms[i].tty_buffer == 0x0) + kpanic("tty_init: Failed to allocate buffer memory. File: %s, Line: %i\n",__FILE__,__LINE__); + + terms[i].tty_pointer = terms[i].tty_buffer; /* Set up tty pointer to internal buffer */ + terms[i].tty_x = 0x0; /* Set up default X position */ + terms[i].tty_y = 0x0; /* Set up default Y position */ + terms[i].tty_colour = 0x0A + i; /* Set up default tty text colour */ + } + + /* Read tty0 current position (to migrate from kprintf). */ + outportByte(0x3D4, 0x0e); + terms[0].tty_y = inportByte(0x3D5); + outportByte(0x3D4, 0x0f); + terms[0].tty_x = inportByte(0x3D5); + + + /* Set up pointer for the foreground tty */ + tty_foreground = &terms[0]; + + /* Set up the foreground ttys information */ + tty_foreground->tty_pointer = (char *)0xB8000; + + /* Return to let kernel know initialization is complete */ + kprintf("tty0 - Initialized\n"); + + return(0x0); + } + + + /* + This will change the specified tty. It ultimately copies the screen + to the foreground buffer copies the new ttys buffer to the screen and + adjusts a couple pointers and we are good to go. + */ +int tty_change(uInt16 tty) { + + if (tty > TTY_MAX_TERMS) + kpanic("Error: Changing to an invalid tty. File: %s, Line: %i\n",__FILE__,__LINE__); + + spinLock(&Master); + + /* Copy display buffer to tty buffer */ + memcpy(tty_foreground->tty_buffer,(char *)0xB8000,(80*60*2)); + + /* Copy new tty buffer to display buffer */ + memcpy((char *)0xB8000,terms[tty].tty_buffer,(80*60*2)); + + /* + Set the tty_pointer to the internal buffer so I can continue + writing to what it believes is the screen + */ + tty_foreground->tty_pointer = tty_foreground->tty_buffer; + + terms[tty].tty_pointer = (char *)0xB8000; + + /* set new foreground tty */ + tty_foreground = &terms[tty]; + + /* Adjust cursor when we change consoles */ + outportByte(0x3D4, 0x0F); + outportByte(0x3D5, tty_foreground->tty_x); + outportByte(0x3D4, 0x0E); + outportByte(0x3D5, tty_foreground->tty_y); + + spinUnlock(&Master); + + return(0x0); + } + +int tty_print(char *string,tty_term *term) { + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + spinLock(&tty_spinLock); + + /* We Need To Get The Y Position */ + bufferOffset = term->tty_y; + bufferOffset <<= 8; + + /* Then We Need To Add The X Position */ + bufferOffset += term->tty_x; + bufferOffset <<= 1; + + while ((character = *string++)) { + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + term->tty_pointer[bufferOffset++] = character; + term->tty_pointer[bufferOffset++] = term->tty_colour; + break; + } /* switch */ + + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + term->tty_pointer[i] = term->tty_pointer[i + 160]; + } + for (i = 0; i < 80; i++) { + term->tty_pointer[(160 * 24) + (i * 2)] = 0x20; + term->tty_pointer[(160 * 24) + (i * 2) + 1] = term->tty_colour; + } + bufferOffset -= 160; + } + } + + bufferOffset >>= 1; /* Set the new cursor position */ + term->tty_x = (bufferOffset & 0xFF); + term->tty_y = (bufferOffset >> 0x8); + + if (term == tty_foreground) { + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, term->tty_x); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, term->tty_y); + } + + spinUnlock(&tty_spinLock); + + return(0x0); + } + +tty_term *tty_find(u_int16_t tty) { + return(&terms[tty]); + } + +/*** + END + ***/ diff --git a/kernel/ubthread.c b/kernel/ubthread.c new file mode 100644 index 0000000..8908075 --- /dev/null +++ b/kernel/ubthread.c @@ -0,0 +1,134 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +/* All these must be converted to be done atomically */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct ubthread_cond_list *conds = 0x0; +struct ubthread_mutex_list *mutex = 0x0; + +kTask_t *ubthread_self() { + return(_current); + } + +int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr) { + ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); + ubcond->id = (int)cond; + ubcond->locked = UNLOCKED; + *cond = ubcond; + return(0x0); + } + +int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr) { + ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); + ubmutex->id = (int)mutex; + ubmutex->locked = UNLOCKED; + *mutex = ubmutex; + return(0x0); + } + +int ubthread_cond_destroy(ubthread_cond_t *cond) { + kfree(*cond); + *cond = 0x0; + return(0x0); + } + +int ubthread_mutex_destroy(ubthread_mutex_t *mutex) { + kfree(*mutex); + *mutex = 0x0; + return(0x0); + } + +int ubthread_create(kTask_t **thread,const uInt32 *attr,void (* tproc)(void), void *arg) { + *thread = (void *)execThread(tproc,(int)(kmalloc(0x2000)+0x2000),arg); + return(0x0); + } + +int ubthread_mutex_lock(ubthread_mutex_t *mutex) { + ubthread_mutex_t ubmutex = *mutex; + if (ubmutex->locked == LOCKED) { + kprintf("Mutex Already Lock By %x Trying To Be Relocked By %x\n",ubmutex->pid,_current->id); + while (ubmutex->locked == LOCKED); + } + ubmutex->locked = LOCKED; + ubmutex->pid = _current->id; + return(0x0); + } + +int ubthread_mutex_unlock(ubthread_mutex_t *mutex) { + ubthread_mutex_t ubmutex = *mutex; + if (ubmutex->pid == _current->id) { + ubmutex->locked = UNLOCKED; + return(0x0); + } + else { + //kprintf("Trying To Unlock Mutex From No Locking Thread\n"); + ubmutex->locked = UNLOCKED; + return(-1); + } + } + +int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime) { + ubthread_cond_t ubcond = *cond; + ubthread_mutex_t ubmutex = *mutex; + uInt32 enterTime = systemVitals->sysUptime+20; + while (enterTime > systemVitals->sysUptime) { + if (ubcond->locked == UNLOCKED) break; + sched_yield(); + } + ubmutex->locked = UNLOCKED; + return(0x0); + } + +int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex) { + ubthread_cond_t ubcond = *cond; + ubthread_mutex_t ubmutex = *mutex; + while (ubcond->locked == LOCKED) sched_yield(); + ubmutex->locked = UNLOCKED; + return(0x0); + } + +int ubthread_cond_signal(ubthread_cond_t *cond) { + ubthread_cond_t ubcond = *cond; + ubcond->locked = UNLOCKED; + return(0x0); + } + +/*** + END + ***/ + diff --git a/kernel/vitals.c b/kernel/vitals.c new file mode 100644 index 0000000..fc6a3c5 --- /dev/null +++ b/kernel/vitals.c @@ -0,0 +1,74 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +vitalsNode *systemVitals = 0x0; + +/************************************************************************ + +Function: vitals_init(); +Description: This will enable the vitals subsystem for ubixos + +Notes: + +02/20/2004 - Approved Its Quality + +************************************************************************/ +int vitals_init() { + /* Initialize Memory For The System Vitals Node */ + systemVitals = (vitalsNode *) kmalloc(sizeof(vitalsNode)); + + /* If malloc Failed Then Error */ + if (systemVitals == 0x0) + { + kpanic("Error: kmalloc Failed In initVitals\n"); + } + + /* Set all default values */ + memset(systemVitals,0x0,sizeof(vitalsNode)); + + systemVitals->quantum = 8; + systemVitals->dQuantum = 8; + + /* Print Out Info For Vitals: */ + kprintf("vitals0 - Address: [0x%X]\n",systemVitals); + + /* Return so kernel knows that there is no problem */ + return(0x0); +} + +/*** + END + ***/ + diff --git a/kmods/Makefile b/kmods/Makefile new file mode 100644 index 0000000..ba50da0 --- /dev/null +++ b/kmods/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = kmod.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/kmods/kmod.c b/kmods/kmod.c new file mode 100644 index 0000000..39fc419 --- /dev/null +++ b/kmods/kmod.c @@ -0,0 +1,216 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +List_t *List = 0x0; + +uInt32 kmod_add(const char *kmod_file, const char *name) +{ + uInt32 addr = 0x0; + Item_t *tmp; + kmod_t *kmods; + + + addr = kmod_load(kmod_file); + if (addr == 0x0) + return 0x0; + + if(List == 0x0) + { + List = InitializeList(); + } + + tmp = CreateItem(); + InsertItemAtFront(List, tmp); + kmods = kmalloc(sizeof *kmods); + tmp->data = kmods; + if(kmods == NULL) + { + kprintf("kmod_add: unable to allocate memory!\n"); + return 0x0; + } + + return 0x0; +} + +uInt32 kmod_load(const char *kmod_file) { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + int sym = 0x0; + char *newLoc = 0x0; + char *shStr = 0x0; + char *dynStr = 0x0; + uInt32 *reMap = 0x0; + struct file *kmod_fd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynSym *relSymTab = 0x0; + elfPltInfo *elfRel = 0x0; + + /* Open kernel module */ + kmod_fd = (struct file *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(kmod_fd,kmod_file,"rb"); + if (kmod_fd == 0x0) { + kprintf("Can not open %s\n",kmod_file); + return 0x0; + } + + /* load module header */ + fseek(kmod_fd,0x0,0x0); + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + if(binaryHeader == 0x0) + { + kprintf("kmod: out of memory\n"); + return 0x0; + } + + assert(binaryHeader); + fread(binaryHeader,sizeof(elfHeader),1,kmod_fd); + + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + assert(programHeader); + fseek(kmod_fd,binaryHeader->ePhoff,0); + fread(programHeader,sizeof(elfSectionHeader),binaryHeader->ePhnum,kmod_fd); + + sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + assert(sectionHeader); + fseek(kmod_fd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,kmod_fd); + + shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); + fseek(kmod_fd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); + fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,kmod_fd); + + for (i=0;iePhnum;i++) { + switch (programHeader[i].phType) { + case PT_LOAD: + case PT_DYNAMIC: + newLoc = (char *)programHeader[i].phVaddr + LD_START; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { + /* make r/w or ro */ + if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: ld\n"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); + } + /* Now Load Section To Memory */ + fseek(kmod_fd,programHeader[i].phOffset,0x0); + fread(newLoc,programHeader[i].phFilesz,1,kmod_fd); + break; + case PT_GNU_STACK: + /* Tells us if the stack should be executable. Failsafe to executable + until we add checking */ + break; + case PT_PAX_FLAGS: + /* Not sure... */ + break; + default: + kprintf("Unhandled Header : %08x\n", programHeader[i].phType); + break; + } + } + + for (i=0x0;ieShnum;i++) { + switch (sectionHeader[i].shType) { + case 3: + if (!strcmp((shStr + sectionHeader[i].shName),".dynstr")) { + dynStr = (char *)kmalloc(sectionHeader[i].shSize); + fseek(kmod_fd,sectionHeader[i].shOffset,0x0); + fread(dynStr,sectionHeader[i].shSize,1,kmod_fd); + } + break; + case 9: + elfRel = (elfPltInfo *)kmalloc(sectionHeader[i].shSize); + fseek(kmod_fd,sectionHeader[i].shOffset,0x0); + fread(elfRel,sectionHeader[i].shSize,1,kmod_fd); + + for (x=0x0;xeEntry + LD_START; + + kfree(dynStr); + kfree(shStr); + kfree(relSymTab); + kfree(sectionHeader); + kfree(programHeader); + kfree(binaryHeader); + fclose(kmod_fd); + + return((uInt32)i); + } + +/*** + END + ***/ diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..a5e443b --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,32 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +INCLUDES += -I../../lib/objgfx40/ + +# Objects +OBJS = strcpy.o strlen.o memcpy.o memset.o assert.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o +#ogprintf.o + +all: $(OBJS) + +# Compile Types +.cpp.o: + $(CXX) -DNOBOOL $(CFLAGS) -fno-rtti $(INCLUDES) -c -o $@ $< +.cc.o: + $(CXX) -DNOBOOL -D__UBIXOS_KERNEL__ $(CFLAGS) -fno-rtti $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/lib/assert.c b/lib/assert.c new file mode 100644 index 0000000..7b4845d --- /dev/null +++ b/lib/assert.c @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +/*! + * \brief The underlying assertion call which is wrapped by assert() + * + */ +void __assert(const char *func,const char *file,int line,const char *failedexpr) { + if (func == NULL) + kprintf("Assertion failed: (%s), file %s, line %d.\n", failedexpr, file, line); + else + kprintf("Assertion failed: (%s), function %s, file %s, line %d.\n", failedexpr, func, file, line); + + K_PANIC("Asserted\n"); + } + +/*** + END + ***/ + diff --git a/lib/atan.c b/lib/atan.c new file mode 100644 index 0000000..b63c0d3 --- /dev/null +++ b/lib/atan.c @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +double atan(double x) { + return(x); /* Quick Hack To Make This Work */ + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:10 reddawg + no message + + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/lib/bcopy.c b/lib/bcopy.c new file mode 100644 index 0000000..19baf13 --- /dev/null +++ b/lib/bcopy.c @@ -0,0 +1,138 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $ID: $ + */ + +#include + +/* + * sizeof(word) MUST BE A POWER OF TWO + * SO THAT wmask BELOW IS ALL ONES + */ +typedef int word; /* "word" used for optimal copy speed */ +typedef u_int32_t uintptr_t; + +#define wsize sizeof(word) +#define wmask (wsize - 1) + +/* + * Copy a block of memory, handling overlap. + * This is the routine that actually implements + * (the portable versions of) bcopy, memcpy, and memmove. + */ +#if defined(MEMCOPY) || defined(MEMMOVE) +#include + +void * +#ifdef MEMCOPY +memcpy +#else +memmove +#endif +(void *dst0, const void *src0, size_t length) +#else +#include + +void +bcopy(const void *src0, void *dst0, size_t length) +#endif +{ + char *dst = dst0; + const char *src = src0; + size_t t; + + if (length == 0 || dst == src) /* nothing to do */ + goto done; + + /* + * Macros: loop-t-times; and loop-t-times, t>0 + */ +#define TLOOP(s) if (t) TLOOP1(s) +#define TLOOP1(s) do { s; } while (--t) + + if ((unsigned long)dst < (unsigned long)src) { + /* + * Copy forward. + */ + t = (uintptr_t)src; /* only need low bits */ + if ((t | (uintptr_t)dst) & wmask) { + /* + * Try to align operands. This cannot be done + * unless the low bits match. + */ + if ((t ^ (uintptr_t)dst) & wmask || length < wsize) + t = length; + else + t = wsize - (t & wmask); + length -= t; + TLOOP1(*dst++ = *src++); + } + /* + * Copy whole words, then mop up any trailing bytes. + */ + t = length / wsize; + TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); + t = length & wmask; + TLOOP(*dst++ = *src++); + } else { + /* + * Copy backwards. Otherwise essentially the same. + * Alignment works as before, except that it takes + * (t&wmask) bytes to align, not wsize-(t&wmask). + */ + src += length; + dst += length; + t = (uintptr_t)src; + if ((t | (uintptr_t)dst) & wmask) { + if ((t ^ (uintptr_t)dst) & wmask || length <= wsize) + t = length; + else + t &= wmask; + length -= t; + TLOOP1(*--dst = *--src); + } + t = length / wsize; + TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); + t = length & wmask; + TLOOP(*--dst = *--src); + } +done: +#if defined(MEMCOPY) || defined(MEMMOVE) + return (dst0); +#else + return; +#endif +} diff --git a/lib/divdi3.c b/lib/divdi3.c new file mode 100644 index 0000000..ed63ace --- /dev/null +++ b/lib/divdi3.c @@ -0,0 +1,65 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +u_quad_t __udivdi3(u_quad_t a,u_quad_t b) { + return(0); /* Quick Hack */ + } + +quad_t __divdi3(quad_t a,quad_t b) { + return(0); /* Quick Hack */ + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:10 reddawg + no message + + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/lib/kmalloc.c b/lib/kmalloc.c new file mode 100644 index 0000000..2e6c800 --- /dev/null +++ b/lib/kmalloc.c @@ -0,0 +1,561 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + Set up three descriptor tables: + + kernDesc - The inuse descriptor table + freeKernDesc - The free descriptor table (descriptors with memory backing just not in use) + emptyKernDesc - The empty descriptor table (descriptors with out a memory backing) + +*/ +static struct memDescriptor *usedKernDesc = 0x0; +static struct memDescriptor *freeKernDesc = 0x0; +static struct memDescriptor *emptyKernDesc = 0x0; + +/* + Set up our spinlocks so we do not corrupt linked lists if we have re-entrancy +*/ +static spinLock_t mallocSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t emptyDescSpinLock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + +Function: void *getEmptyDesc() +Description: Find An Empty Descriptor + +Notes: + +02/17/03 - Is This Efficient? + +************************************************************************/ +static void *getEmptyDesc() { + int i = 0x0; + struct memDescriptor *tmpDesc = 0x0; + + spinLock(&emptyDescSpinLock); + + tmpDesc = emptyKernDesc; + + if (tmpDesc != 0x0) { + emptyKernDesc = tmpDesc->next; + if (emptyKernDesc != 0x0) + emptyKernDesc->prev = 0x0; + + + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + spinUnlock(&emptyDescSpinLock); + return(tmpDesc); + } + if ((emptyKernDesc = (struct memDescriptor *)vmm_getFreeMallocPage(4)) == 0x0) + kpanic("Error: vmm_getFreeKernelPage returned NULL\n"); + + /* zero out the memory so we know there is no garbage */ + memset(emptyKernDesc,0x0,0x4000); + + emptyKernDesc[0].next = &emptyKernDesc[1]; + + for (i = 0x1;i < ((0x4000/sizeof(struct memDescriptor)));i++) { + if (i+1 < (0x4000/sizeof(struct memDescriptor))) + emptyKernDesc[i].next = &emptyKernDesc[i+1]; + else + emptyKernDesc[i].next = 0x0; + emptyKernDesc[i].prev = &emptyKernDesc[i-1]; + } + + tmpDesc = &emptyKernDesc[0]; + + emptyKernDesc = tmpDesc->next; + emptyKernDesc->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + spinUnlock(&emptyDescSpinLock); + return(tmpDesc); + } + +/************************************************************************ + +Function: void insertFreeDesc(struct memDescriptor *freeDesc) +Description: This Function Inserts A Free Descriptor On The List Which Is + Kept In Size Order + +Notes: + +02/17/03 - This Was Inspired By TCA's Great Wisdom - + "[20:20:59] You should just insert it in order" + +************************************************************************/ +static int insertFreeDesc(struct memDescriptor *freeDesc) { + struct memDescriptor *tmpDesc = 0x0; + assert(freeDesc); + + if (freeDesc->limit <= 0x0) + kpanic("Inserting Descriptor with no limit\n"); + + if (freeKernDesc != 0x0) { + + #if 0 + freeDesc->next = freeKernDesc; + freeDesc->prev = 0x0; + freeKernDesc->prev = freeDesc; + freeKernDesc = freeDesc; + #endif + + for (tmpDesc = freeKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { + if (freeDesc->limit <= tmpDesc->limit) { + + freeDesc->prev = tmpDesc->prev; + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = freeDesc; + + + tmpDesc->prev = freeDesc; + freeDesc->next = tmpDesc; + + if (tmpDesc == freeKernDesc) + freeKernDesc = freeDesc; + return(0x0); + } + if (tmpDesc->next == 0x0) { + tmpDesc->next = freeDesc; + freeDesc->prev = tmpDesc; + freeDesc->next = 0x0; + return(0x0); + } + } + kpanic("didnt Insert\n"); + return(0x0); + } + else { + freeDesc->prev = 0x0; + freeDesc->next = 0x0; + freeKernDesc = freeDesc; + return(0x0); + } + + return(0x1); + } + +/************************************************************************ + +Function: void mergeMemBlocks() +Description: This Function Will Merge Free Blocks And Free Pages + +Notes: + +03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 + +************************************************************************/ +static void mergeMemBlocks() { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + uInt32 baseAddr = 0x0; + + return; + + //Loop The Free Descriptors See If We Can Merge Them + mergeStart: + for (tmpDesc1=freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { + /* + Compare The Base Addr With The Other Descriptors If You Find The One + That You Are Looking For Lets Merge Them + */ + if (tmpDesc1->limit != 0x0) { + baseAddr = (uInt32)tmpDesc1->baseAddr + (uInt32)tmpDesc1->limit; + for (tmpDesc2=freeKernDesc;tmpDesc2;tmpDesc2=tmpDesc2->next) { + if ((uInt32)tmpDesc2->baseAddr == baseAddr) { + tmpDesc1->limit += tmpDesc2->limit; + tmpDesc2->baseAddr = 0x0; + tmpDesc2->limit = 0x0; + if (tmpDesc2->prev) { + tmpDesc2->prev->next = tmpDesc2->next; + } + if (tmpDesc2->next) { + tmpDesc2->next->prev = tmpDesc2->prev; + } + tmpDesc2->prev = 0x0; + tmpDesc2->next = emptyKernDesc; + emptyKernDesc->prev = tmpDesc2; + emptyKernDesc = tmpDesc2; + if (tmpDesc1->prev) { + tmpDesc1->prev->next = tmpDesc1->next; + } + if (tmpDesc1->next) { + tmpDesc1->next->prev = tmpDesc1->prev; + } + tmpDesc1->prev = 0x0; + tmpDesc1->next = 0x0; + kprintf("mergememBlocks: [%i]\n",tmpDesc1->limit); + insertFreeDesc(tmpDesc1); + //tmpDesc1 = freeKernDesc; + goto mergeStart; + break; + } + } + } + } + return; + } + + +/************************************************************************ + +Function: void *kmalloc(uInt32 len) +Description: Allocate Kernel Memory + +Notes: + +02/17/03 - Do I Still Need To Pass In The Pid? + +************************************************************************/ +void *kmalloc(uInt32 len) { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + char *buf = 0x0; + int i = 0x0; + uInt16 pages = 0x0; + + + spinLock(&mallocSpinLock); + + len = MALLOC_ALIGN(len); + + + if (len == 0x0) { + spinUnlock(&mallocSpinLock); + kprintf("kmalloc: len = 0!\n"); + return(0x0); + } + for (tmpDesc1 = freeKernDesc;tmpDesc1 != 0x0;tmpDesc1=tmpDesc1->next) { + assert(tmpDesc1); + if (tmpDesc1->limit >= len) { + if (tmpDesc1->prev != 0x0) + tmpDesc1->prev->next = tmpDesc1->next; + if (tmpDesc1->next != 0x0) + tmpDesc1->next->prev = tmpDesc1->prev; + + if (tmpDesc1 == freeKernDesc) + freeKernDesc = tmpDesc1->next; + + tmpDesc1->prev = 0x0; + tmpDesc1->next = usedKernDesc; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + if (tmpDesc1->limit > len) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->limit = tmpDesc1->limit - len; + tmpDesc1->limit = len; + tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; + tmpDesc2->next = 0x0; + tmpDesc2->prev = 0x0; + insertFreeDesc(tmpDesc2); + } + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + buf[i] = 0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("m1[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + assert(tmpDesc1->baseAddr); + return(tmpDesc1->baseAddr); + } + } + tmpDesc1 = getEmptyDesc(); + //kprintf("no empty desc\n"); + if (tmpDesc1 != 0x0) { + pages = ((len + 4095)/4096); + tmpDesc1->baseAddr = (struct memDescriptor *)vmm_getFreeMallocPage(pages); + tmpDesc1->limit = len; + tmpDesc1->next = usedKernDesc; + tmpDesc1->prev = 0x0; + if (usedKernDesc != 0x0) + usedKernDesc->prev = tmpDesc1; + usedKernDesc = tmpDesc1; + + if (((pages * 4096)-len) > 0x0) { + tmpDesc2 = getEmptyDesc(); + assert(tmpDesc2); + tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; + tmpDesc2->limit = ((pages * 4096)-len); + tmpDesc2->prev = 0x0; + tmpDesc2->next = 0x0; + if (tmpDesc2->limit <= 0x0) + kprintf("kmalloc-2 tmpDesc2: [%i]\n",tmpDesc2->limit); + insertFreeDesc(tmpDesc2); + } + + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + buf[i] = 0x0; + } + spinUnlock(&mallocSpinLock); + //kprintf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); + //kprintf("m2[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); + assert(tmpDesc1->baseAddr); + return(tmpDesc1->baseAddr); + } + //Return Null If Unable To Malloc + spinUnlock(&mallocSpinLock); + //kprintf("baseAddr3[0x0]"); + return(0x0); + } + +/************************************************************************ + +Function: void kfree(void *baseAddr) +Description: This Will Find The Descriptor And Free It + +Notes: + +02/17/03 - I need To Make It Join Descriptors + +************************************************************************/ +void kfree(void *baseAddr) { + struct memDescriptor *tmpDesc = 0x0; + + if (baseAddr == 0x0) return; + assert(baseAddr); + + assert(usedKernDesc); + spinLock(&mallocSpinLock); + + for (tmpDesc = usedKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { + + if (tmpDesc->baseAddr == baseAddr) { + memset(tmpDesc->baseAddr,0xBE,tmpDesc->limit); + + if (usedKernDesc == tmpDesc) + usedKernDesc = tmpDesc->next; + + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = tmpDesc->next; + + if (tmpDesc->next != 0x0) + tmpDesc->next->prev = tmpDesc->prev; + + + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + + if (tmpDesc->limit <= 0x0) + kprintf("kfree tmpDesc1: [%i]\n",tmpDesc->limit); + //kprintf("{0x%X}",tmpDesc->baseAddr); + insertFreeDesc(tmpDesc); + + // mergeMemBlocks(); + spinUnlock(&mallocSpinLock); + return; + } + } + spinUnlock(&mallocSpinLock); + kprintf("Kernel: Error Freeing Descriptor! [0x%X]\n",(uInt32)baseAddr); + return; + } + +/*** + $Log$ + Revision 1.3 2009/02/14 02:03:24 reddawg + Fixed up vmm_getFreeKernelPage + + Revision 1.2 2007/06/29 11:31:47 reddawg + Cleaning + + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.3 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.2 2006/10/06 15:48:01 reddawg + Starting to make ubixos work with UFS2 + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.4 2006/06/01 12:42:09 reddawg + Getting back to the basics + + Revision 1.3 2006/06/01 03:58:33 reddawg + wondering about this stuff here + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:11 reddawg + no message + + Revision 1.35 2005/08/04 18:32:59 fsdfs + + added error reporting + + Revision 1.34 2005/08/04 18:23:41 reddawg + BUG: Assert has issues that must be looked into + + Revision 1.33 2005/08/04 17:11:11 fsdfs + + ---------------------------------------- + + ------------------- + + Revision 1.32 2004/09/28 21:50:04 reddawg + kmalloc: now when we kfree memory is filled with 0xBE so it is easy to debug if we continue to use free'd memory + + Revision 1.31 2004/09/19 16:17:25 reddawg + fixed memory leak we now lose no memory.... + + Revision 1.30 2004/09/14 21:51:24 reddawg + Debug info + + Revision 1.29 2004/09/11 23:39:31 reddawg + ok time for bed + + Revision 1.28 2004/09/11 23:21:26 reddawg + run now do you get fegfaults with BB? + + Revision 1.27 2004/09/11 22:49:28 reddawg + pat look at lines 276-285 does the math seem right? + + Revision 1.26 2004/09/11 22:33:13 reddawg + minor changes + + Revision 1.25 2004/09/11 12:11:11 reddawg + Cleaning up the VFS more changes to follow... + + Revision 1.24 2004/09/08 23:19:58 reddawg + hmm + + Revision 1.23 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + + Revision 1.22 2004/08/26 22:51:18 reddawg + TCA touched me :( i think he likes men.... + + + sched.h: kTask_t added parentPid + endtask.c: fixed term back to parentPid + exec.c: cleaned warnings + fork.c: fixed term to childPid + sched.c: clean up for dead tasks + systemtask.c: clean up dead tasks + kmalloc.c: cleaned up warnings + udp.c: cleaned up warnings + bot.c: cleaned up warnings + shell.c: cleaned up warnings + tcpdump.c: took a dump + hd.c: cleaned up warnings + ubixfs.c: stopped prning debug info + + Revision 1.21 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + Revision 1.20 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + + Revision 1.19 2004/07/26 19:15:49 reddawg + test code, fixes and the like + + Revision 1.18 2004/07/26 16:52:45 reddawg + here we go + + Revision 1.17 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + + Revision 1.16 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.15 2004/07/20 23:20:50 reddawg + kmalloc: forgot to remove an assert + + Revision 1.14 2004/07/20 23:18:11 reddawg + Made malloc a little more robust but we have a serious memory leak somewhere + + Revision 1.13 2004/07/20 22:29:55 reddawg + assert: remade assert + + Revision 1.12 2004/07/20 18:58:24 reddawg + Few fixes + + Revision 1.11 2004/07/18 05:24:15 reddawg + Fixens + + Revision 1.10 2004/07/17 18:00:47 reddawg + kmalloc: added assert() + + Revision 1.9 2004/07/17 15:54:52 reddawg + kmalloc: added assert() + bioscall: fixed some potential problem by not making 16bit code + paging: added assert() + + Revision 1.8 2004/06/17 14:50:32 reddawg + kmalloc: converted some variables to static + + Revision 1.7 2004/06/17 02:54:54 flameshadow + chg: fixed cast + + Revision 1.6 2004/05/26 11:56:51 reddawg + kmalloc: fixed memrgeMemBlocks hopefully it will prevent future segfault issues + by not having any more overlapping blocks + + Revision 1.5 2004/05/25 14:01:14 reddawg + Implimented Better Spinlocking No More Issues With KMALLOC which actually + was causing bizzare problems + + END + ***/ + diff --git a/lib/kprintf.c b/lib/kprintf.c new file mode 100644 index 0000000..1b00e91 --- /dev/null +++ b/lib/kprintf.c @@ -0,0 +1,63 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +int printOff = 0x0; +int ogprintOff = 0x1; + +int kprintf(const char *fmt, ...) { + char buf[512]; + vaList args; + int i = 0x0; + vaStart(args, fmt); + i = vsprintf(buf,fmt,args); + vaEnd(args); + if (printOff == 0x0) + kprint(buf); + + return(i); + } + +int sprintf(char *buf,const char *fmt, ...) { + vaList args; + int i; + vaStart(args, fmt); + i=vsprintf(buf,fmt,args); + vaEnd(args); + return(i); + } + +/*** + END + ***/ + diff --git a/lib/libcpp.cc b/lib/libcpp.cc new file mode 100644 index 0000000..1535b7d --- /dev/null +++ b/lib/libcpp.cc @@ -0,0 +1,103 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +extern "C" +{ +#include +#include +void __pure_virtual() { while(1); } + +void __cxa_pure_virtual() { while(1); } + +/* Don't plan on exiting the kernel...so do nothing. */ +int __cxa_atexit(void (*func)(void *), void * arg, void * d) { return 0; } + +void __dso_handle() { while(1); } +} + +#include + +void * operator new[](unsigned size) +{ + return kmalloc(size); +} + +void operator delete[](void * ptr) +{ + kfree(ptr); + + return; +} + +void * operator new(unsigned size) +{ + void * ptr = kmalloc(size); + return ptr; +} + +void operator delete(void * ptr) +{ + kfree(ptr); + return; +} + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:12 reddawg + no message + + Revision 1.5 2004/09/08 22:04:10 apwillia + Added calling of static constructors, commented out tty_printf in kprintf (due to deadlock) + + Revision 1.4 2004/07/20 22:58:33 reddawg + retiring to the laptop for the night must sync in work to resume from there + + Revision 1.3 2004/07/02 12:28:24 reddawg + Changes for new libc, someone please test that the kernel still works + + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/lib/memcpy.c b/lib/memcpy.c new file mode 100644 index 0000000..ee11504 --- /dev/null +++ b/lib/memcpy.c @@ -0,0 +1,2 @@ +#define MEMCOPY +#include "bcopy.c" diff --git a/lib/memset.c b/lib/memset.c new file mode 100644 index 0000000..35deee5 --- /dev/null +++ b/lib/memset.c @@ -0,0 +1,86 @@ +/***************************************************************************************** + Copyright (c) 2002,2007 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +#define wsize sizeof(uInt) +#define wmask (wsize - 1) +#define VAL c0 +#define WIDEVAL c + +void *memset(void *dst0, int c0, size_t length) { + size_t t; + uInt c; + uInt8 *dst; + + dst = dst0; + + if (length < 3 * wsize) { + while (length != 0) { + *dst++ = VAL; + --length; + } + return(dst0); + } + + if ((c = (uInt8)c0) != 0) { /* Fill the word. */ + c = (c << 8) | c; /* u_int is 16 bits. */ + c = (c << 16) | c; /* u_int is 32 bits. */ + } + + /* Align destination by filling in bytes. */ + if ((t = (long)dst & wmask) != 0) { + t = wsize - t; + length -= t; + do { + *dst++ = VAL; + } while (--t != 0); + } + + /* Fill words. Length was >= 2*words so we know t >= 1 here. */ + t = length / wsize; + do { + *(u_int *)dst = WIDEVAL; + dst += wsize; + } while (--t != 0); + + /* Mop up trailing bytes, if any. */ + t = length & wmask; + if (t != 0) + do { + *dst++ = VAL; + } while (--t != 0); + return(dst0); + } + + +/*** +END + ***/ + diff --git a/lib/net.c b/lib/net.c new file mode 100644 index 0000000..ac8134f --- /dev/null +++ b/lib/net.c @@ -0,0 +1,217 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:12 reddawg + no message + + Revision 1.6 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.5 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.4 2004/06/17 03:14:59 flameshadow + chg: added missing #include for kprintf() + + Revision 1.3 2004/05/20 22:54:02 reddawg + Cleaned Up Warrnings + + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.8 2004/04/13 21:29:52 reddawg + We now have sockets working. Lots of functionality to be added to continually + improve on the existing layers now its clean up time to get things in a better + working order. + + Revision 1.7 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#include "lib/kprintf.h" + +#ifndef _IN_ADDR_T_DECLARED +typedef uInt32 in_addr_t; +#define _IN_ADDR_T_DECLARED +#endif + +uInt32 htonl(uInt32 n) { + uInt32 retVal = 0x0; + retVal += ((n & 0xff) << 24); + retVal += ((n & 0xff00) << 8); + retVal += ((n & 0xff0000) >> 8); + retVal += ((n & 0xff000000) >> 24); + return(retVal); + } + +uInt32 htons(uInt32 n) { + uInt32 retVal = 0x0; + retVal = (((n & 0xff) << 8) | ((n & 0xff00) >> 8)); + return(retVal); + } + +void bcopy(const void *src, void *dest, int len) { + memcpy(dest,src,len); + } + +void bzero(void *data, int n) { + memset(data, 0, n); + } + + +int inet_aton(cp, addr) + const char *cp; + struct in_addr *addr; +{ + uInt32 parts[4]; + in_addr_t val; + char *c; + char *endptr; + int gotend, n; + + c = (char *)cp; + n = 0; + /* + * Run through the string, grabbing numbers until + * the end of the string, or some error + */ + gotend = 0; + while (!gotend) { + //errno = 0; + val = strtol(c, &endptr, 0); + kprintf("VAL: [%x]",val); + + //if (errno == ERANGE) /* Fail completely if it overflowed. */ + // return (0); + + /* + * If the whole string is invalid, endptr will equal + * c.. this way we can make sure someone hasn't + * gone '.12' or something which would get past + * the next check. + */ + if (endptr == c) + return (0); + parts[n] = val; + c = endptr; + + /* Check the next character past the previous number's end */ + switch (*c) { + case '.' : + /* Make sure we only do 3 dots .. */ + if (n == 3) /* Whoops. Quit. */ + return (0); + n++; + c++; + break; + + case '\0': + gotend = 1; + break; + + default: + /* + if (isspace((unsigned char)*c)) { + gotend = 1; + break; + } else + */ + return (0); /* Invalid character, so fail */ + } + + } + + /* + * Concoct the address according to + * the number of parts specified. + */ + + switch (n) { + case 0: /* a -- 32 bits */ + /* + * Nothing is necessary here. Overflow checking was + * already done in strtoul(). + */ + break; + case 1: /* a.b -- 8.24 bits */ + if (val > 0xffffff || parts[0] > 0xff) + return (0); + val |= parts[0] << 24; + break; + + case 2: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 3: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff || + parts[2] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + + if (addr != NULL) + addr->s_addr = htonl(val); + return (1); +} + +/*** + END + ***/ + diff --git a/lib/ogprintf.cc b/lib/ogprintf.cc new file mode 100644 index 0000000..d8048ff --- /dev/null +++ b/lib/ogprintf.cc @@ -0,0 +1,127 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +extern "C" { + +#include + + +static int screenRow = 0x0; +static int screenCol = 0x1; + +int ogPrintf(char *s) { + int i = 0x0; + int bufHeight; + ogSurface *screen = (ogDisplay_UbixOS *)systemVitals->screen; + ogBitFont *font = (ogBitFont *)systemVitals->font; + + + while ('\0' != s[i]) { + switch (s[i]) { + case '\t': + screenCol += 3; + break; + case '\b': + if (screenCol > 0) --screenCol; + case '\n': + screenCol = 0; + + bufHeight = ((screen->ogGetMaxY()+1) / font->GetHeight())-1; + if (screenRow < bufHeight) + ++screenRow; + else { + screen->ogCopyBuf(0, 0, + *screen, + 0, font->GetHeight(), + screen->ogGetMaxX(), screen->ogGetMaxY()); + screen->ogFillRect(0, bufHeight * font->GetHeight()+1, + screen->ogGetMaxX(), screen->ogGetMaxY(), + screen->ogPack(122, 140, 163)); + } + break; + default: + font->PutChar(*screen, + screenCol * font->GetWidth(), + screenRow * font->GetHeight(), + s[i]); + break; + } /* switch */ + ++screenCol; + ++i; + } /* while */ + + return 0; +} // ogPrintf + +} + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:13 reddawg + no message + + Revision 1.7 2004/07/20 22:58:33 reddawg + retiring to the laptop for the night must sync in work to resume from there + + Revision 1.6 2004/07/17 14:24:22 reddawg + compile: changes to the way we link the kernel should prevent future errors + + Revision 1.5 2004/05/23 23:30:34 reddawg + Fixens + + Revision 1.4 2004/05/23 01:40:19 reddawg + Spinlock + + Revision 1.3 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.2 2004/04/26 12:56:01 reddawg + Made src/sys/sde Copy and Make the ogPixelFormat.cpp + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.19 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/lib/sqrt.c b/lib/sqrt.c new file mode 100644 index 0000000..7006bcc --- /dev/null +++ b/lib/sqrt.c @@ -0,0 +1,59 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +double sqrt(double x) { + return(x); /* Quick Hack */ + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:13 reddawg + no message + + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/lib/strcpy.S b/lib/strcpy.S new file mode 100644 index 0000000..655eb91 --- /dev/null +++ b/lib/strcpy.S @@ -0,0 +1,44 @@ +.globl strcpy +strcpy: + movl 4(%esp),%ecx /* dst address */ + movl 8(%esp),%edx /* src address */ + pushl %ecx /* push dst address */ + + .align 2,0x90 +L1: movb (%edx),%al /* unroll loop, but not too much */ + movb %al,(%ecx) + testb %al,%al + je L2 + movb 1(%edx),%al + movb %al,1(%ecx) + testb %al,%al + je L2 + movb 2(%edx),%al + movb %al,2(%ecx) + testb %al,%al + je L2 + movb 3(%edx),%al + movb %al,3(%ecx) + testb %al,%al + je L2 + movb 4(%edx),%al + movb %al,4(%ecx) + testb %al,%al + je L2 + movb 5(%edx),%al + movb %al,5(%ecx) + testb %al,%al + je L2 + movb 6(%edx),%al + movb %al,6(%ecx) + testb %al,%al + je L2 + movb 7(%edx),%al + movb %al,7(%ecx) + addl $8,%edx + addl $8,%ecx + testb %al,%al + jne L1 +L2: popl %eax /* pop dst address */ + ret + diff --git a/lib/string.c b/lib/string.c new file mode 100644 index 0000000..af946e8 --- /dev/null +++ b/lib/string.c @@ -0,0 +1,183 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +int strcmp(const char *str1,const char *str2) { + while ((*str1 == *str2) && (*str1 != 0x0) && (*str2 != 0x0)) { + str1++; + str2++; + } + if (*str1 == *str2) { + return(0); + } + else if (*str1 > *str2) { + return(1); + } + else { + return(-1); + } + } + +int strncmp(const char * a, const char * b, size_t c) { + int i = 0; + while (i < c) { + if ((a[i] != b[i]) || (a[i] == '\0') || (b[i] == '\0')) + return a[i] - b[i]; + i++; + } + return 0; + } + + + +void *memcpyold(const void *dst, const void * src, size_t length) { + //size_t x = length >> 2; + //size_t y = length;// & 0xf; + size_t i; +/* + for (i = 0; i < x; i++) { + ((unsigned long *)dst)[i] = ((unsigned long *)src)[i]; + } +*/ +/* + for (i = 0; i < y; i++) { + ((char *) dst)[length-y+i] = ((char *) src)[length-y+i]; + } +*/ + for (i = 0x0;i < length;i++) + ((char *)dst)[i] = ((char *)src)[i]; + + return((void *)dst); + } + +int memcmp(const void * dst, const void * src, size_t length) +{ + size_t x = length >> 2; + size_t y = length & 0xf; + size_t i; + + for (i = 0; i < x; i++) + { + if (((unsigned long *)dst)[i] > ((unsigned long *)src)[i]) + return 1; + if (((unsigned long *)dst)[i] < ((unsigned long *)src)[i]) + return -1; + } + + for (i = 0; i < y; i++) + { + if (((char *) dst)[length-y+i] > ((char *) src)[length-y+i]) + return 1; + if (((char *) dst)[length-y+i] < ((char *) src)[length-y+i]) + return -1; + } + + return 0; +} + +void strncpy(char * dest, const char * src, size_t size) +{ + if (size == 0) + return; + do + { + *dest = *src; + dest++; src++; + size--; + } + while(('\0' != *(src-1)) && (size)); +} + +char *strstr(const char *s,char *find) { + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); + } + + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.3 2006/12/12 14:09:18 reddawg + Changes + + Revision 1.2 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:13 reddawg + no message + + Revision 1.6 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + Revision 1.5 2004/07/20 18:42:41 flameshadow + add: strcpy() + chg: modified dirCache.c to use strcpy() + + Revision 1.4 2004/07/05 23:06:32 reddawg + Fixens + + Revision 1.3 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.2 2004/05/19 14:40:58 reddawg + Cleaned up some warning from leaving out typedefs + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.5 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/lib/strlen.S b/lib/strlen.S new file mode 100644 index 0000000..d301949 --- /dev/null +++ b/lib/strlen.S @@ -0,0 +1,13 @@ +.globl strlen +strlen: + pushl %edi + movl 8(%esp),%edi /* string address */ + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movl $-1,%ecx /* set search for lots of characters */ + repne /* search! */ + scasb + notl %ecx /* get length by taking complement */ + leal -1(%ecx),%eax /* and subtracting one */ + popl %edi + ret diff --git a/lib/strtok.c b/lib/strtok.c new file mode 100644 index 0000000..4d0c494 --- /dev/null +++ b/lib/strtok.c @@ -0,0 +1,105 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +char *strtok_r(char *s, const char *delim, char **last) { + char *spanp; + int c, sc; + char *tok; + + if ((s == NULL) && ((s = *last) == NULL)) { + return(NULL); + } + +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0; ) { + if (c == sc) { + goto cont; + } + } + if (c == 0) { + *last = NULL; + return(NULL); + } + tok = s - 1; + + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) { + s = NULL; + } + else { + char *w = s - 1; + *w = '\0'; + } + *last = s; + return(tok); + } + } while (sc != 0); + } + } + +char *strtok(char *s, const char *delim) { + static char *last; + return (strtok_r(s, delim, &last)); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:13 reddawg + no message + + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + + diff --git a/lib/strtol.c b/lib/strtol.c new file mode 100644 index 0000000..becd0b7 --- /dev/null +++ b/lib/strtol.c @@ -0,0 +1,103 @@ +#include +//#include +//#include +//#include + +#define LONG_MIN (-0x7fffffffL - 1) +#define LONG_MAX 0x7fffffffL + + + +long +strtol(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long acc; + char c = 0x0; /* to remove warning */ + unsigned long cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + /* + do { + c = *s++; + } while (isspace((unsigned char)c)); + */ + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX + : LONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + //errno = ERANGE; + } else if (!any) { +noconv: + //errno = EINVAL; + cutoff = 0x0;//UBU + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/lib/vsprintf.c b/lib/vsprintf.c new file mode 100644 index 0000000..3081d03 --- /dev/null +++ b/lib/vsprintf.c @@ -0,0 +1,288 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:14 reddawg + no message + + Revision 1.2 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.3 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include +#include + +/* we use this so that we can do without the ctype library */ +#define is_digit(c) ((c) >= '0' && (c) <= '9') + +static int skip_atoi(const char **s) +{ + int i=0; + + while (is_digit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define SMALL 64 /* use 'abcdef' instead of 'ABCDEF' */ + +#define do_div(n,base) ({ \ +int __res; \ +__asm__("divl %4":"=a" (n),"=d" (__res):"0" (n),"1" (0),"r" (base)); \ +__res; }) + +static char * number(char * str, int num, int base, int size, int precision + ,int type) +{ + char c,sign,tmp[36]; + const char *digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + + if (type&SMALL) digits="0123456789abcdefghijklmnopqrstuvwxyz"; + if (type&LEFT) type &= ~ZEROPAD; + if (base<2 || base>36) + return 0; + c = (type & ZEROPAD) ? '0' : ' ' ; + if (type&SIGN && num<0) { + sign='-'; + num = -num; + } else + sign=(type&PLUS) ? '+' : ((type&SPACE) ? ' ' : 0); + if (sign) size--; + if (type&SPECIAL) { + if (base==16) { size -= 2; } + else if (base==8) { size--; } + } + i=0; + if (num==0) + tmp[i++]='0'; + else while (num!=0) + tmp[i++]=digits[do_div(num,base)]; + if (i>precision) precision=i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type&SPECIAL) { + if (base==8) { + *str++ = '0'; + } + else if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type&LEFT)) + while(size-->0) + *str++ = c; + while(i0) + *str++ = tmp[i]; + while(size-->0) + *str++ = ' '; + return str; +} + +int vsprintf(char *buf, const char *fmt, vaList args) +{ + int len; + int i; + char * str; + char *s; + int *ip; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + + for (str=buf ; *fmt ; ++fmt) { + if (*fmt != '%') { + *str++ = *fmt; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (is_digit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + field_width = vaArg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (is_digit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + precision = vaArg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + ++fmt; + } + + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + *str++ = ' '; + *str++ = (unsigned char) vaArg(args, int); + while (--field_width > 0) + *str++ = ' '; + break; + + case 's': + s = vaArg(args, char *); + len = strlen(s); + if (precision < 0) + precision = len; + else if (len > precision) + len = precision; + + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + break; + + case 'o': + str = number(str, vaArg(args, unsigned long), 8, + field_width, precision, flags); + break; + + case 'p': + if (field_width == -1) { + field_width = 8; + flags |= ZEROPAD; + } + str = number(str, + (unsigned long) vaArg(args, void *), 16, + field_width, precision, flags); + break; + + case 'x': + flags |= SMALL; + case 'X': + str = number(str, vaArg(args, unsigned long), 16, + field_width, precision, flags); + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + str = number(str, vaArg(args, unsigned long), 10, + field_width, precision, flags); + break; + + case 'n': + ip = vaArg(args, int *); + *ip = (str - buf); + break; + + default: + if (*fmt != '%') + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + break; + } + } + *str = '\0'; + return str-buf; +} + +/*** + END + ***/ + diff --git a/mpi/Makefile b/mpi/Makefile new file mode 100644 index 0000000..c06a5a4 --- /dev/null +++ b/mpi/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = system.o message.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX)-DNOBOOL $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/mpi/message.c b/mpi/message.c new file mode 100644 index 0000000..5a842ca --- /dev/null +++ b/mpi/message.c @@ -0,0 +1,84 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +void sysMpiCreateMbox(uInt32 *status,char *name) { + if (status && name) + *status = mpi_createMbox(name); + return; + } + +void sysMpiDestroyMbox(uInt32 *status,char *name) { + if (status && name) + *status = mpi_destroyMbox(name); + return; + } + +void sysMpiPostMessage(char *name,uInt32 *type,mpi_message_t *data) { + if (type && name && data) + *type = mpi_postMessage(name,*type,data); + return; + } + +void sysMpiFetchMessage(char *name,mpi_message_t *msg,uInt32 *status) { + if (status && name && msg) + *status = mpi_fetchMessage(name,msg); + return; + } + +void sysMpiSpam(uInt32 type,void *data,uInt32 *status) { + if (status && data) + *status = mpi_spam(type,data); + return; + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:14 reddawg + no message + + Revision 1.12 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.11 2004/07/28 17:07:25 reddawg + MPI: moved the syscalls + + END + ***/ + diff --git a/mpi/system.c b/mpi/system.c new file mode 100644 index 0000000..5b734e5 --- /dev/null +++ b/mpi/system.c @@ -0,0 +1,259 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static mpi_mbox_t *mboxList = 0x0; +static spinLock_t mpiSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: static mpiMbox_t * mpiFindMbox(char *name) + + Description: This function will find a mail box that matches the supplied name + + Notes: This function is not task-safe! Lock must be done before call. + +*****************************************************************************************/ +static mpi_mbox_t * mpi_findMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + for (mbox = mboxList;mbox;mbox = mbox->next) { + if (!strcmp(mbox->name,name)) { + return(mbox); + } + } + + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiCreateMbox(char *name) + + Description: This function will create a new mailbox if it fails it will return -1 + otherwise it returns 0x0 + + Notes: + +*****************************************************************************************/ +int mpi_createMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + if (mpi_findMbox(name) != 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + mbox = (mpi_mbox_t *)kmalloc(sizeof(mpi_mbox_t)); + + sprintf(mbox->name,name); + mbox->pid = _current->id; + + if (mboxList == 0x0) { + mbox->prev = 0x0; + mbox->next = 0x0; + mboxList = mbox; + } + else { + mbox->next = mboxList; + mbox->prev = 0x0; + mboxList->prev = mbox; + mboxList = mbox; + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiSpam(uInt32 type,void *data) + + Description: This function will send a message to every mailbox + + Notes: + +*****************************************************************************************/ +int mpi_spam(uInt32 type,void *data) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *message = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox = mbox->next) { + message = (mpi_message_t *)kmalloc(sizeof(mpi_message_t)); + + message->header = type; + memcpy(message->data,data,MESSAGE_LENGTH); + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiPostMessage(char *name,uInt32 type,void *data) + + Description: This function will post a message to specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_postMessage(char *name,uInt32 type,mpi_message_t *msg) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *message = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpi_findMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(0x1); + } + + message = (mpi_message_t *)kmalloc(sizeof(mpi_message_t)); + + message->header = msg->header; + memcpy(message->data,msg->data,MESSAGE_LENGTH); + message->pid = _current->id; + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + + spinUnlock(&mpiSpinLock); + + if (type == 0x2) { + while (mbox->msgLast != 0x0); + } + + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiFetchMessage(char *name,mpiMessage_t *msg) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_fetchMessage(char *name,mpi_message_t *msg) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *tmpMsg = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpi_findMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->msg == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + msg->header = mbox->msg->header; + memcpy(msg->data,mbox->msg->data,MESSAGE_LENGTH); + msg->pid = mbox->msg->pid; + + tmpMsg = mbox->msg; + mbox->msg = mbox->msg->next; + + kfree(tmpMsg); + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiDestroyMbox(char *name) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_destroyMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox=mbox->next) { + if (!strcmp(mbox->name,name)) { + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + mbox->prev->next = mbox->next; + mbox->next->prev = mbox->prev; + kfree(mbox); + spinUnlock(&mpiSpinLock); + return(0x0); + } + } + + spinUnlock(&mpiSpinLock); + return(-1); + } + +/*** + END + ***/ diff --git a/net/Makefile b/net/Makefile new file mode 100644 index 0000000..f009abf --- /dev/null +++ b/net/Makefile @@ -0,0 +1,22 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +all: core-code net-code api-code netif-code + +core-code: core + (cd core;make) + +net-code: net + (cd net;make) + +api-code: api + (cd api;make) + +netif-code: netif + (cd netif;make) + +clean: + (cd core;make clean) + (cd net;make clean) + (cd api;make clean) + (cd netif;make clean) diff --git a/net/api/Makefile b/net/api/Makefile new file mode 100644 index 0000000..11a72ae --- /dev/null +++ b/net/api/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = api_lib.o api_msg.o err.o sockets.o tcpip.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS}-DNOBOOL -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS}-DNOBOOL -I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS}-I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS}-c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/net/api/api_lib.c b/net/api/api_lib.c new file mode 100644 index 0000000..ed9100b --- /dev/null +++ b/net/api/api_lib.c @@ -0,0 +1,648 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +/* This is the part of the API that is linked with + the application */ + +#include + +#include "net/debug.h" +#include "net/api.h" +#include "net/api_msg.h" +#include "net/memp.h" + +#include "net/debug.h" + +#include "lib/kprintf.h" +/*-----------------------------------------------------------------------------------*/ +struct +netbuf *netbuf_new(void) +{ + struct netbuf *buf; + + buf = memp_mallocp(MEMP_NETBUF); + if(buf != NULL) { + buf->p = NULL; + buf->ptr = NULL; + return buf; + } else { + return NULL; + } +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_delete(struct netbuf *buf) +{ + if(buf != NULL) { + if(buf->p != NULL) { + pbuf_free(buf->p); + buf->p = buf->ptr = NULL; + } + memp_freep(MEMP_NETBUF, buf); + } +} +/*-----------------------------------------------------------------------------------*/ +void * +netbuf_alloc(struct netbuf *buf, uInt16 size) +{ + /* Deallocate any previously allocated memory. */ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); + if(buf->p == NULL) { + return NULL; + } + buf->ptr = buf->p; + return buf->p->payload; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_free(struct netbuf *buf) +{ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = buf->ptr = NULL; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_ref(struct netbuf *buf, void *dataptr, uInt16 size) +{ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_ROM); + buf->p->payload = dataptr; + buf->p->len = buf->p->tot_len = size; + buf->ptr = buf->p; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_chain(struct netbuf *head, struct netbuf *tail) +{ + pbuf_chain(head->p, tail->p); + head->ptr = head->p; + memp_freep(MEMP_NETBUF, tail); +} +/*-----------------------------------------------------------------------------------*/ +uInt16 +netbuf_len(struct netbuf *buf) +{ + return buf->p->tot_len; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netbuf_data(struct netbuf *buf, void **dataptr, uInt16 *len) +{ + if(buf->ptr == NULL) { + return ERR_BUF; + } + *dataptr = buf->ptr->payload; + *len = buf->ptr->len; + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +Int8 +netbuf_next(struct netbuf *buf) +{ + if(buf->ptr->next == NULL) { + return -1; + } + buf->ptr = buf->ptr->next; + if(buf->ptr->next == NULL) { + return 1; + } + return 0; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_first(struct netbuf *buf) +{ + buf->ptr = buf->p; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_copy_partial(struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset) +{ + struct pbuf *p; + uInt16 i, left; + + left = 0; + + if(buf == NULL) { + return; + } + + /* This implementation is bad. It should use bcopy + instead. */ + for(p = buf->p; left < len && p != NULL; p = p->next) { + if(offset != 0 && offset >= p->len) { + offset -= p->len; + } else { + for(i = offset; i < p->len; ++i) { + ((char *)dataptr)[left] = ((char *)p->payload)[i]; + if(++left >= len) { + return; + } + } + } + } +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_copy(struct netbuf *buf, void *dataptr, uInt16 len) +{ + netbuf_copy_partial(buf, dataptr, len, 0); +} +/*-----------------------------------------------------------------------------------*/ +struct ip_addr * +netbuf_fromaddr(struct netbuf *buf) +{ + return buf->fromaddr; +} +/*-----------------------------------------------------------------------------------*/ +uInt16 +netbuf_fromport(struct netbuf *buf) +{ + return buf->fromport; +} +/*-----------------------------------------------------------------------------------*/ +struct +netconn *netconn_new(enum netconn_type t) +{ + struct netconn *conn; + + conn = memp_mallocp(MEMP_NETCONN); + if(conn == NULL) { + return NULL; + } + conn->type = t; + conn->pcb.tcp = NULL; + + if((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { + memp_freep(MEMP_NETCONN, conn); + return NULL; + } + conn->recvmbox = SYS_MBOX_NULL; + conn->acceptmbox = SYS_MBOX_NULL; + conn->sem = SYS_SEM_NULL; + conn->state = NETCONN_NONE; + return conn; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_delete(struct netconn *conn) +{ + struct api_msg *msg; + void *mem; + + if(conn == NULL) { + return ERR_OK; + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return ERR_MEM; + } + + msg->type = API_MSG_DELCONN; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + + /* Drain the recvmbox. */ + if(conn->recvmbox != SYS_MBOX_NULL) { + while(sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != 0) { + if(conn->type == NETCONN_TCP) { + pbuf_free((struct pbuf *)mem); + } else { + netbuf_delete((struct netbuf *)mem); + } + } + sys_mbox_free(conn->recvmbox); + conn->recvmbox = SYS_MBOX_NULL; + } + + + /* Drain the acceptmbox. */ + if(conn->acceptmbox != SYS_MBOX_NULL) { + while(sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != 0) { + netconn_delete((struct netconn *)mem); + } + + sys_mbox_free(conn->acceptmbox); + conn->acceptmbox = SYS_MBOX_NULL; + } + + sys_mbox_free(conn->mbox); + conn->mbox = SYS_MBOX_NULL; + if(conn->sem != SYS_SEM_NULL) { + sys_sem_free(conn->sem); + } + /* conn->sem = SYS_SEM_NULL;*/ + memp_free(MEMP_NETCONN, conn); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +enum netconn_type +netconn_type(struct netconn *conn) +{ + return conn->type; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_peer(struct netconn *conn, struct ip_addr **addr, + uInt16 *port) +{ + switch(conn->type) { + case NETCONN_UDPLITE: + case NETCONN_UDPNOCHKSUM: + case NETCONN_UDP: + *addr = &(conn->pcb.udp->remote_ip); + *port = conn->pcb.udp->remote_port; + break; + case NETCONN_TCP: + *addr = &(conn->pcb.tcp->remote_ip); + *port = conn->pcb.tcp->remote_port; + break; + } + return (conn->err = ERR_OK); +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_addr(struct netconn *conn, struct ip_addr **addr, + uInt16 *port) +{ + switch(conn->type) { + case NETCONN_UDPLITE: + case NETCONN_UDPNOCHKSUM: + case NETCONN_UDP: + *addr = &(conn->pcb.udp->local_ip); + *port = conn->pcb.udp->local_port; + break; + case NETCONN_TCP: + *addr = &(conn->pcb.tcp->local_ip); + *port = conn->pcb.tcp->local_port; + break; + } + return (conn->err = ERR_OK); +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_bind(struct netconn *conn, struct ip_addr *addr, + uInt16 port) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->type != NETCONN_TCP && + conn->recvmbox == SYS_MBOX_NULL) { + if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_BIND; + msg->msg.conn = conn; + msg->msg.msg.bc.ipaddr = addr; + msg->msg.msg.bc.port = port; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_connect(struct netconn *conn, struct ip_addr *addr, + uInt16 port) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + + if(conn->recvmbox == SYS_MBOX_NULL) { + if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return ERR_MEM; + } + msg->type = API_MSG_CONNECT; + msg->msg.conn = conn; + msg->msg.msg.bc.ipaddr = addr; + msg->msg.msg.bc.port = port; + kprintf("1"); + api_msg_post(msg); + kprintf("2: [0x%X]",conn->mbox); + sys_mbox_fetch(conn->mbox, NULL); + kprintf("3"); + memp_freep(MEMP_API_MSG, msg); + kprintf("4"); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_listen(struct netconn *conn) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->acceptmbox == SYS_MBOX_NULL) { + conn->acceptmbox = sys_mbox_new(); + if(conn->acceptmbox == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_LISTEN; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +struct netconn * +netconn_accept(struct netconn *conn) +{ + struct netconn *newconn; + + if(conn == NULL) { + return NULL; + } + + sys_mbox_fetch(conn->acceptmbox, (void **)&newconn); + + return newconn; +} +/*-----------------------------------------------------------------------------------*/ +struct netbuf * +netconn_recv(struct netconn *conn) +{ + struct api_msg *msg; + struct netbuf *buf; + struct pbuf *p; + + if(conn == NULL) { + return NULL; + } + + if(conn->recvmbox == SYS_MBOX_NULL) { + conn->err = ERR_CONN; + return NULL; + } + + if(conn->err != ERR_OK) { + return NULL; + } + + if(conn->type == NETCONN_TCP) { + if(conn->pcb.tcp->state == LISTEN) { + conn->err = ERR_CONN; + return NULL; + } + + + buf = memp_mallocp(MEMP_NETBUF); + + if(buf == NULL) { + conn->err = ERR_MEM; + return NULL; + } + + sys_mbox_fetch(conn->recvmbox, (void **)&p); + + /* If we are closed, we indicate that we no longer wish to recieve + data by setting conn->recvmbox to SYS_MBOX_NULL. */ + if(p == NULL) { + memp_freep(MEMP_NETBUF, buf); + sys_mbox_free(conn->recvmbox); + conn->recvmbox = SYS_MBOX_NULL; + return NULL; + } + + buf->p = p; + buf->ptr = p; + buf->fromport = 0; + buf->fromaddr = NULL; + + /* Let the stack know that we have taken the data. */ + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + conn->err = ERR_MEM; + return buf; + } + msg->type = API_MSG_RECV; + msg->msg.conn = conn; + if(buf != NULL) { + msg->msg.msg.len = buf->p->tot_len; + } else { + msg->msg.msg.len = 1; + } + api_msg_post(msg); + + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + } else { + sys_mbox_fetch(conn->recvmbox, (void **)&buf); + } + + + + + DEBUGF(API_LIB_DEBUG, ("netconn_recv: received %p (err %d)\n", buf, conn->err)); + + + return buf; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_send(struct netconn *conn, struct netbuf *buf) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->err != ERR_OK) { + return conn->err; + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + + DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %d bytes\n", buf->p->tot_len)); + msg->type = API_MSG_SEND; + msg->msg.conn = conn; + msg->msg.msg.p = buf->p; + api_msg_post(msg); + + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_write(struct netconn *conn, void *dataptr, uInt16 size, uInt8 copy) +{ + struct api_msg *msg; + uInt16 len; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->err != ERR_OK) { + return conn->err; + } + + if(conn->sem == SYS_SEM_NULL) { + conn->sem = sys_sem_new(0); + if(conn->sem == SYS_SEM_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_WRITE; + msg->msg.conn = conn; + + + conn->state = NETCONN_WRITE; + while(conn->err == ERR_OK && size > 0) { + msg->msg.msg.w.dataptr = dataptr; + msg->msg.msg.w.copy = copy; + + if(conn->type == NETCONN_TCP) { + if(tcp_sndbuf(conn->pcb.tcp) == 0) { + sys_sem_wait(conn->sem); + if(conn->err != ERR_OK) { + goto ret; + } + } + if(size > tcp_sndbuf(conn->pcb.tcp)) { + /* We cannot send more than one send buffer's worth of data at a + time. */ + len = tcp_sndbuf(conn->pcb.tcp); + } else { + len = size; + } + } else { + len = size; + } + + DEBUGF(API_LIB_DEBUG, ("netconn_write: writing %d bytes (%d)\n", len, copy)); + msg->msg.msg.w.len = len; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + if(conn->err == ERR_OK) { + dataptr = (void *)((char *)dataptr + len); + size -= len; + } else if(conn->err == ERR_MEM) { + conn->err = ERR_OK; + sys_sem_wait(conn->sem); + } else { + goto ret; + } + } + ret: + memp_freep(MEMP_API_MSG, msg); + conn->state = NETCONN_NONE; + if(conn->sem != SYS_SEM_NULL) { + sys_sem_free(conn->sem); + conn->sem = SYS_SEM_NULL; + } + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_close(struct netconn *conn) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + + conn->state = NETCONN_CLOSE; + again: + msg->type = API_MSG_CLOSE; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + if(conn->err == ERR_MEM && + conn->sem != SYS_SEM_NULL) { + sys_sem_wait(conn->sem); + goto again; + } + conn->state = NETCONN_NONE; + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_err(struct netconn *conn) +{ + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ + + + + diff --git a/net/api/api_msg.c b/net/api/api_msg.c new file mode 100644 index 0000000..a9965d4 --- /dev/null +++ b/net/api/api_msg.c @@ -0,0 +1,529 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include + +#include "net/debug.h" +#include "net/arch.h" +#include "net/api_msg.h" +#include "net/memp.h" +#include "net/sys.h" +#include "net/tcpip.h" + +/*-----------------------------------------------------------------------------------*/ +static err_t +recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) +{ + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + pbuf_free(p); + return ERR_VAL; + } + + if(conn->recvmbox != SYS_MBOX_NULL) { + conn->err = err; + sys_mbox_post(conn->recvmbox, p); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *addr, uInt16 port) +{ + struct netbuf *buf; + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + pbuf_free(p); + return; + } + + if(conn->recvmbox != SYS_MBOX_NULL) { + buf = memp_mallocp(MEMP_NETBUF); + if(buf == NULL) { + pbuf_free(p); + return; + } else { + buf->p = p; + buf->ptr = p; + buf->fromaddr = addr; + buf->fromport = port; + } + + sys_mbox_post(conn->recvmbox, buf); + } +} +/*-----------------------------------------------------------------------------------*/ +static err_t +poll_tcp(void *arg, struct tcp_pcb *pcb) +{ + struct netconn *conn; + + conn = arg; + if(conn != NULL && + (conn->state == NETCONN_WRITE || conn->state == NETCONN_CLOSE) && + conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static err_t +sent_tcp(void *arg, struct tcp_pcb *pcb, uInt16 len) +{ + struct netconn *conn; + + conn = arg; + if(conn != NULL && conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +err_tcp(void *arg, err_t err) +{ + struct netconn *conn; + + conn = arg; + + conn->pcb.tcp = NULL; + + + conn->err = err; + if(conn->recvmbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->recvmbox, NULL); + } + if(conn->mbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->mbox, NULL); + } + if(conn->acceptmbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->acceptmbox, NULL); + } + if(conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +setup_tcp(struct netconn *conn) +{ + struct tcp_pcb *pcb; + + pcb = conn->pcb.tcp; + tcp_arg(pcb, conn); + tcp_recv(pcb, recv_tcp); + tcp_sent(pcb, sent_tcp); + tcp_poll(pcb, poll_tcp, 4); + tcp_err(pcb, err_tcp); +} +/*-----------------------------------------------------------------------------------*/ +static err_t +accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) +{ + sys_mbox_t *mbox; + struct netconn *newconn; + +#if API_MSG_DEBUG +#if TCP_DEBUG + tcp_debug_print_state(newpcb->state); +#endif /* TCP_DEBUG */ +#endif /* API_MSG_DEBUG */ + mbox = (sys_mbox_t *)arg; + newconn = memp_mallocp(MEMP_NETCONN); + if(newconn == NULL) { + return ERR_MEM; + } + newconn->type = NETCONN_TCP; + newconn->pcb.tcp = newpcb; + setup_tcp(newconn); + newconn->recvmbox = sys_mbox_new(); + if(newconn->recvmbox == SYS_MBOX_NULL) { + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->mbox = sys_mbox_new(); + if(newconn->mbox == SYS_MBOX_NULL) { + sys_mbox_free(newconn->recvmbox); + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->sem = sys_sem_new(0); + if(newconn->sem == SYS_SEM_NULL) { + sys_mbox_free(newconn->recvmbox); + sys_mbox_free(newconn->mbox); + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->acceptmbox = SYS_MBOX_NULL; + newconn->err = err; + sys_mbox_post(*mbox, newconn); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +do_newconn(struct api_msg_msg *msg) +{ +} +/*-----------------------------------------------------------------------------------*/ +static void +do_delconn(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + msg->conn->pcb.udp->recv_arg = NULL; + udp_remove(msg->conn->pcb.udp); + break; + case NETCONN_TCP: + tcp_arg(msg->conn->pcb.tcp, NULL); + tcp_sent(msg->conn->pcb.tcp, NULL); + tcp_recv(msg->conn->pcb.tcp, NULL); + tcp_accept(msg->conn->pcb.tcp, NULL); + tcp_poll(msg->conn->pcb.tcp, NULL, 0); + tcp_err(msg->conn->pcb.tcp, NULL); + if(msg->conn->pcb.tcp->state == LISTEN) { + tcp_close(msg->conn->pcb.tcp); + } else { + if(tcp_close(msg->conn->pcb.tcp) != ERR_OK) { + tcp_abort(msg->conn->pcb.tcp); + } + } + break; + } + } + if(msg->conn->mbox != SYS_MBOX_NULL) { + sys_mbox_post(msg->conn->mbox, NULL); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_bind(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp == NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + msg->conn->pcb.udp = udp_new(); + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDPNOCHKSUM: + msg->conn->pcb.udp = udp_new(); + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDP: + msg->conn->pcb.udp = udp_new(); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_new(); + setup_tcp(msg->conn); + break; + } + } + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port); + break; + case NETCONN_TCP: + msg->conn->err = tcp_bind(msg->conn->pcb.tcp, + msg->msg.bc.ipaddr, msg->msg.bc.port); + break; + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static err_t +do_connected(void *arg, struct tcp_pcb *pcb, err_t err) +{ + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + return ERR_VAL; + } + + conn->err = err; + + if(conn->type == NETCONN_TCP && err == ERR_OK) { + setup_tcp(conn); + } + + sys_mbox_post(conn->mbox, NULL); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +do_connect(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp == NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDPNOCHKSUM: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDP: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_new(); + if(msg->conn->pcb.tcp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + break; + } + } + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_connect(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port); + sys_mbox_post(msg->conn->mbox, NULL); + break; + case NETCONN_TCP: + /* tcp_arg(msg->conn->pcb.tcp, msg->conn);*/ + setup_tcp(msg->conn); + tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port, + do_connected); + /*tcp_output(msg->conn->pcb.tcp);*/ + break; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_listen(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + DEBUGF(API_MSG_DEBUG, ("api_msg: listen UDP: cannot listen for UDP.\n")); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp); + if(msg->conn->pcb.tcp == NULL) { + msg->conn->err = ERR_MEM; + } else { + if(msg->conn->acceptmbox == SYS_MBOX_NULL) { + msg->conn->acceptmbox = sys_mbox_new(); + if(msg->conn->acceptmbox == SYS_MBOX_NULL) { + msg->conn->err = ERR_MEM; + break; + } + } + tcp_arg(msg->conn->pcb.tcp, (void *)&(msg->conn->acceptmbox)); + tcp_accept(msg->conn->pcb.tcp, accept_function); + } + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_accept(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + DEBUGF(API_MSG_DEBUG, ("api_msg: accept UDP: cannot accept for UDP.\n")); + break; + case NETCONN_TCP: + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_send(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_send(msg->conn->pcb.udp, msg->msg.p); + break; + case NETCONN_TCP: + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_recv(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + if(msg->conn->type == NETCONN_TCP) { + tcp_recved(msg->conn->pcb.tcp, msg->msg.len); + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_write(struct api_msg_msg *msg) +{ + err_t err; + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + msg->conn->err = ERR_VAL; + break; + case NETCONN_TCP: + err = tcp_write(msg->conn->pcb.tcp, msg->msg.w.dataptr, + msg->msg.w.len, msg->msg.w.copy); + /* This is the Nagle algorithm: inhibit the sending of new TCP + segments when new outgoing data arrives from the user if any + previously transmitted data on the connection remains + unacknowledged. */ + if(err == ERR_OK && msg->conn->pcb.tcp->unacked == NULL) { + tcp_output(msg->conn->pcb.tcp); + } + msg->conn->err = err; + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_close(struct api_msg_msg *msg) +{ + err_t err; + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + break; + case NETCONN_TCP: + if(msg->conn->pcb.tcp->state == LISTEN) { + err = tcp_close(msg->conn->pcb.tcp); + } else { + err = tcp_close(msg->conn->pcb.tcp); + } + msg->conn->err = err; + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +typedef void (* api_msg_decode)(struct api_msg_msg *msg); +static api_msg_decode decode[API_MSG_MAX] = { + do_newconn, + do_delconn, + do_bind, + do_connect, + do_listen, + do_accept, + do_send, + do_recv, + do_write, + do_close + }; +void +api_msg_input(struct api_msg *msg) +{ + decode[msg->type](&(msg->msg)); +} +/*-----------------------------------------------------------------------------------*/ +void +api_msg_post(struct api_msg *msg) +{ + tcpip_apimsg(msg); +} +/*-----------------------------------------------------------------------------------*/ + + diff --git a/net/api/err.c b/net/api/err.c new file mode 100644 index 0000000..43ecf39 --- /dev/null +++ b/net/api/err.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include "net/err.h" + +#ifdef LWIP_DEBUG + +static char *err_strerr[] = {"Ok.", + "Out of memory error.", + "Buffer error.", + "Connection aborted.", + "Connection reset.", + "Connection closed.", + "Not connected.", + "Illegal value.", + "Illegal argument.", + "Routing problem.", + "Address in use." +}; + +/*-----------------------------------------------------------------------------------*/ +char * +lwip_strerr(err_t err) +{ + return err_strerr[-err]; + +} +/*-----------------------------------------------------------------------------------*/ + +#endif /* LWIP_DEBUG */ diff --git a/net/api/sockets.c b/net/api/sockets.c new file mode 100644 index 0000000..4656ba6 --- /dev/null +++ b/net/api/sockets.c @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include + +#include "net/debug.h" +#include "net/api.h" + +#include "net/sockets.h" + +#define NUM_SOCKETS 10 + +struct lwip_socket { + struct netconn *conn; + struct netbuf *lastdata; + uInt16 lastoffset; +}; + +static struct lwip_socket sockets[NUM_SOCKETS]; + +/*-----------------------------------------------------------------------------------*/ +static struct lwip_socket * +get_socket(int s) +{ + struct lwip_socket *sock; + + if(s > NUM_SOCKETS) { + /* errno = EBADF; */ + return NULL; + } + + sock = &sockets[s]; + + if(sock->conn == NULL) { + /* errno = EBADF; */ + return NULL; + } + return sock; +} +/*-----------------------------------------------------------------------------------*/ +static int +alloc_socket(struct netconn *newconn) +{ + int i; + + /* allocate a new socket identifier */ + for(i = 0; i < NUM_SOCKETS; ++i) { + if(sockets[i].conn == NULL) { + sockets[i].conn = newconn; + sockets[i].lastdata = NULL; + sockets[i].lastoffset = 0; + return i; + } + } + return -1; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_accept(int s, struct sockaddr *addr, int *addrlen) +{ + struct lwip_socket *sock; + struct netconn *newconn; + struct ip_addr *naddr; + uInt16 port; + int newsock; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + newconn = netconn_accept(sock->conn); + + /* get the IP address and port of the remote host */ + netconn_peer(newconn, &naddr, &port); + + ((struct sockaddr_in *)addr)->sin_addr.s_addr = naddr->addr; + ((struct sockaddr_in *)addr)->sin_port = port; + + newsock = alloc_socket(newconn); + if(newsock == -1) { + netconn_delete(newconn); + /* errno = ENOBUFS; */ + } + return newsock; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_bind(int s, struct sockaddr *name, int namelen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr; + uInt16 remote_port; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)name)->sin_port; + + err = netconn_bind(sock->conn, &remote_addr, ntohs(remote_port)); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_close(int s) +{ + struct lwip_socket *sock; + + DEBUGF(SOCKETS_DEBUG, ("close: socket %d\n", s)); + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + + netconn_delete(sock->conn); + if(sock->lastdata != NULL) { + netbuf_delete(sock->lastdata); + } + sock->lastdata = NULL; + sock->lastoffset = 0; + sock->conn = NULL; + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_connect(int s, struct sockaddr *name, int namelen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr; + uInt16 remote_port; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)name)->sin_port; + + err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port)); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_listen(int s, int backlog) +{ + struct lwip_socket *sock; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + err = netconn_listen(sock->conn); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_recvfrom(int s, void *mem, int len, unsigned int flags, + struct sockaddr *from, int *fromlen) +{ + struct lwip_socket *sock; + struct netbuf *buf; + uInt16 buflen, copylen; + struct ip_addr *addr; + uInt16 port; + + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + /* Check if there is data left from the last recv operation. */ + if(sock->lastdata != NULL) { + buf = sock->lastdata; + } else { + /* No data was left from the previous operation, so we try to get + some from the network. */ + buf = netconn_recv(sock->conn); + + if(buf == NULL) { + /* We should really do some error checking here. */ + return 0; + } + } + + buflen = netbuf_len(buf); + + buflen -= sock->lastoffset; + + if(len > buflen) { + copylen = buflen; + } else { + copylen = len; + } + + /* copy the contents of the received buffer into + the supplied memory pointer mem */ + netbuf_copy_partial(buf, mem, copylen, sock->lastoffset); + + /* If this is a TCP socket, check if there is data left in the + buffer. If so, it should be saved in the sock structure for next + time around. */ + if(netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) { + sock->lastdata = buf; + sock->lastoffset = buflen - copylen; + } else { + sock->lastdata = NULL; + sock->lastoffset = 0; + netbuf_delete(buf); + } + + /* Check to see from where the data was. */ + if(from != NULL && fromlen != NULL) { + addr = netbuf_fromaddr(buf); + port = htons(netbuf_fromport(buf)); + ((struct sockaddr_in *)from)->sin_addr.s_addr = addr->addr; + ((struct sockaddr_in *)from)->sin_port = port; + *fromlen = sizeof(struct sockaddr_in); + } + + + /* if the length of the received data is larger than + len, this data is discarded and we return len. + otherwise we return the actual length of the received + data */ + if(len > copylen) { + return copylen; + } else { + return len; + } +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_read(int s, void *mem, int len) +{ + return lwip_recv(s, mem, len, 0); +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_recv(int s, void *mem, int len, unsigned int flags) +{ + return lwip_recvfrom(s, mem, len, flags, NULL, NULL); +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_send(int s, void *data, int size, unsigned int flags) +{ + struct lwip_socket *sock; + struct netbuf *buf; + err_t err; + + DEBUGF(SOCKETS_DEBUG, ("send: socket %d, size %d\n", s, size)); + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + switch(netconn_type(sock->conn)) { + case NETCONN_UDP: + /* create a buffer */ + buf = netbuf_new(); + + if(buf == NULL) { + /* errno = ENOBUFS; */ + return -1; + } + + /* make the buffer point to the data that should + be sent */ + netbuf_ref(buf, data, size); + + /* send the data */ + err = netconn_send(sock->conn, buf); + + /* deallocated the buffer */ + netbuf_delete(buf); + break; + case NETCONN_TCP: + err = netconn_write(sock->conn, data, size, NETCONN_COPY); + break; + default: + err = ERR_ARG; + break; + } + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return size; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_sendto(int s, void *data, int size, unsigned int flags, + struct sockaddr *to, int tolen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr, *addr; + uInt16 remote_port, port; + int ret; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + /* get the peer if currently connected */ + netconn_peer(sock->conn, &addr, &port); + + remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)to)->sin_port; + netconn_connect(sock->conn, &remote_addr, remote_port); + + ret = lwip_send(s, data, size, flags); + + /* reset the remote address and port number + of the connection */ + netconn_connect(sock->conn, addr, port); + return ret; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_socket(int domain, int type, int protocol) +{ + struct netconn *conn; + int i; + + /* create a netconn */ + switch(type) { + case SOCK_DGRAM: + conn = netconn_new(NETCONN_UDP); + break; + case SOCK_STREAM: + conn = netconn_new(NETCONN_TCP); + break; + default: + /* errno = ... */ + return -1; + } + + if(conn == NULL) { + DEBUGF(SOCKETS_DEBUG, ("socket: could not create netconn.\n")); + /* errno = ENOBUFS; */ + return -1; + } + + i = alloc_socket(conn); + + if(i == -1) { + /* errno = ENOBUFS; */ + netconn_delete(conn); + } + return i; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_write(int s, void *data, int size) +{ + struct lwip_socket *sock; + err_t err; + + DEBUGF(SOCKETS_DEBUG, ("write: socket %d, size %d\n", s, size)); + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + switch(netconn_type(sock->conn)) { + case NETCONN_UDP: + return lwip_send(s, data, size, 0); + + case NETCONN_TCP: + err = netconn_write(sock->conn, data, size, NETCONN_COPY); + break; + default: + err = ERR_ARG; + break; + } + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + return size; +} +/*-----------------------------------------------------------------------------------*/ diff --git a/net/api/tcpip.c b/net/api/tcpip.c new file mode 100644 index 0000000..62ab8c6 --- /dev/null +++ b/net/api/tcpip.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "net/debug.h" + +#include "net/opt.h" + +#include "net/sys.h" + +#include "net/memp.h" +#include "net/pbuf.h" + +#include "net/ipv4/ip.h" +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/tcpip.h" + +static void (* tcpip_init_done)(void *arg) = NULL; +static void *tcpip_init_done_arg; +static sys_mbox_t mbox; + +/*-----------------------------------------------------------------------------------*/ +static void +tcpip_tcp_timer(void *arg) +{ + tcp_tmr(); + sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ + +static void +tcpip_thread(void *arg) +{ + struct tcpip_msg *msg; + + ip_init(); + udp_init(); + tcp_init(); + + sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL); + + if(tcpip_init_done != NULL) { + tcpip_init_done(tcpip_init_done_arg); + } + + while(1) { /* MAIN Loop */ + sys_mbox_fetch(mbox, (void *)&msg); + switch(msg->type) { + case TCPIP_MSG_API: + //kprintf("tcpip_thread: API message %p\n", msg); + api_msg_input(msg->msg.apimsg); + break; + case TCPIP_MSG_INPUT: + //kprintf("tcpip_thread: IP packet %p\n", msg); + ip_input(msg->msg.inp.p, msg->msg.inp.netif); + break; + default: + break; + } + memp_freep(MEMP_TCPIP_MSG, msg); + } +} +/*-----------------------------------------------------------------------------------*/ +err_t +tcpip_input(struct pbuf *p, struct netif *inp) +{ + struct tcpip_msg *msg; + + msg = memp_mallocp(MEMP_TCPIP_MSG); + if(msg == NULL) { + //kprintf("BAD MESSAGE!!!\n"); + pbuf_free(p); + return ERR_MEM; + } + //kprintf("GOOD MESSAGE\n"); + + msg->type = TCPIP_MSG_INPUT; + msg->msg.inp.p = p; + msg->msg.inp.netif = inp; + sys_mbox_post(mbox, msg); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +void +tcpip_apimsg(struct api_msg *apimsg) +{ + struct tcpip_msg *msg; + msg = memp_mallocp(MEMP_TCPIP_MSG); + if(msg == NULL) { + memp_free(MEMP_TCPIP_MSG, apimsg); + return; + } + msg->type = TCPIP_MSG_API; + msg->msg.apimsg = apimsg; + sys_mbox_post(mbox, msg); +} +/*-----------------------------------------------------------------------------------*/ +void +tcpip_init(void (* initfunc)(void *), void *arg) +{ + tcpip_init_done = initfunc; + tcpip_init_done_arg = arg; + mbox = sys_mbox_new(); + sys_thread_new((void *)tcpip_thread, NULL); +} +/*-----------------------------------------------------------------------------------*/ + + + diff --git a/net/net/Makefile b/net/net/Makefile new file mode 100644 index 0000000..aa3bc32 --- /dev/null +++ b/net/net/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = udpecho.o init.o sys_arch.o shell.o bot.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -DNOBOOL -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -DNOBOOL-I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/net/net/bot.c b/net/net/bot.c new file mode 100644 index 0000000..12da8d7 --- /dev/null +++ b/net/net/bot.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include +#include + +#include "net/mem.h" +#include "net/debug.h" +#include "net/def.h" +#include "net/api.h" +#include "net/stats.h" + +/* UBU +static void sendstr(const char *str, struct netconn *conn) { + netconn_write(conn, (void *)str, strlen(str), NETCONN_NOCOPY); + } + +static void botErr() { + kprintf("ERRROR\n"); + } +*/ + +static void bot_thread(void *arg) { + struct netconn *conn; + int len; + char bufr[1500]; + struct ip_addr ipaddr; + struct netbuf *buf = 0x0; + + IP4_ADDR(&ipaddr,216,152,77,10); + conn = netconn_new(NETCONN_TCP); + kprintf("Starting UbixOS Bot\n"); + while(1) { + kprintf("[A"); + kprintf("\n\nCONNECT: [%i]\n",netconn_connect(conn,&ipaddr,6667)); + kprintf("B]"); + while (1); + if (buf != NULL) { + buf = netconn_recv(conn); + netbuf_copy(buf, bufr, 1024); + len = netbuf_len(buf); + netbuf_delete(buf); + bufr[len-2] = '\0'; + kprintf("Bufr: [%s:%i]",bufr,len); + //sendstr("BLah\n",conn); + } + } + } + +void bot_init(void) { + sys_thread_new(bot_thread, NULL); + } + +/*** + END + ***/ + diff --git a/net/net/init.c b/net/net/init.c new file mode 100644 index 0000000..c43332c --- /dev/null +++ b/net/net/init.c @@ -0,0 +1,104 @@ +/***************************************************************************************** + Copyright (c) 2004 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +void netMainThread(); +static void tcpip_init_done(void *arg); + +int net_init() { + sys_init(); + mem_init(); + memp_init(); + pbuf_init(); + + /* + *thread = (void *)execThread((void *)start_routine,0x0,arg); + */ + + sys_thread_new((void *)(netMainThread), 0x0); + + return(0x0); + } + + +void netMainThread() { + struct ip_addr ipaddr, netmask, gw; + sys_sem_t sem; + + netif_init(); + sem = sys_sem_new(0); + tcpip_init(tcpip_init_done, &sem); + sys_sem_wait(sem); + sys_sem_free(sem); + + kprintf("TCP/IP initialized.\n"); + + IP4_ADDR(&gw, 10,4,0,1); + IP4_ADDR(&ipaddr, 10,4,0,69); + IP4_ADDR(&netmask, 255,255,255,0); + netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); + + IP4_ADDR(&gw, 127,0,0,1); + IP4_ADDR(&ipaddr, 127,0,0,1); + IP4_ADDR(&netmask, 255,0,0,0); + netif_add(&ipaddr, &netmask, &gw, loopif_init, tcpip_input); + + //udpecho_init(); + shell_init(); + //bot_init(); + endTask(_current->id); + } + + +static void tcpip_init_done(void *arg) { + sys_sem_t *sem = 0x0; + sem = arg; + sys_sem_signal(*sem); + } + +/*** + END + ***/ + diff --git a/net/net/shell.c b/net/net/shell.c new file mode 100644 index 0000000..4c73f9c --- /dev/null +++ b/net/net/shell.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include +#include + +#include "net/mem.h" +#include "net/debug.h" +#include "net/def.h" +#include "net/api.h" +#include "net/stats.h" + +#include "lib/kprintf.h" +char *buffer = 0x0; + +#define ESUCCESS 0 +#define ESYNTAX -1 +#define ETOOFEW -2 +#define ETOOMANY -3 +#define ECLOSED -4 + +#define NCONNS 10 +// UBU static struct netconn *conns[NCONNS]; + +static void sendstr(const char *str, struct netconn *conn) { + netconn_write(conn, (void *)str, strlen(str), NETCONN_NOCOPY); + } + +static void prompt(struct netconn *conn) { + sendstr("uBixCube:@sys> ", conn); + } + +static void shell_main(struct netconn *conn) { + struct netbuf *buf = 0x0; + uInt32 len; + // UBU int i; + // UBU char bufr[1500]; + prompt(conn); + while (1) { + buf = netconn_recv(conn); + if (buf != 0x0) + netbuf_copy(buf,buffer,1024); + len = netbuf_len(buf); + netbuf_delete(buf); + buffer[len-2] = '\0'; + kprintf("Buffer: [%s:%i]\n",buffer,len); + if (!strcmp(buffer,"quit")) { + netconn_close(conn); + break; + } + else if (!strcmp(buffer,"ls")) { + sendstr("no\nfiles\nhere\n", conn); + } + else if (!strcmp(buffer,"uname")) { + sendstr("UbixOS v1.0 reddawg@devel.ubixos.com:/ubix.elf\n",conn); + } + prompt(conn); + } + } + +static void shell_thread(void *arg) { + struct netconn *conn = 0x0, *newconn = 0x0; + + buffer = (char *)kmalloc(1024); + + conn = netconn_new(NETCONN_TCP); + netconn_bind(conn, NULL, 23); + netconn_listen(conn); + + while(1) { + kprintf("1"); + newconn = netconn_accept(conn); + kprintf("2"); + shell_main(newconn); + kprintf("3"); + //netconn_delete(newconn); + kprintf("4"); + } + } + +void shell_init(void) { + sys_thread_new(shell_thread, NULL); + } + +/*** + END + ***/ + diff --git a/net/net/shell.h b/net/net/shell.h new file mode 100644 index 0000000..3f2ab99 --- /dev/null +++ b/net/net/shell.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __SHELL_H__ +#define __SHELL_H__ + +void shell_init(void); + +#endif /* __SHELL_H__ */ diff --git a/net/net/sys_arch.c b/net/net/sys_arch.c new file mode 100644 index 0000000..57efd8a --- /dev/null +++ b/net/net/sys_arch.c @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * Sub Author: Christopher Olsen + * + * Notes: + * Modified to work with the ubix operating system + * + * $Log$ + * Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + * UbixOS + * + * Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + * ubix2 + * + * Revision 1.2 2005/10/12 00:13:37 reddawg + * Removed + * + * Revision 1.1.1.1 2005/09/26 17:24:31 reddawg + * no message + * + * Revision 1.6 2004/09/11 21:30:37 apwillia + * Fix race conditions in net thread and scheduler + * + * Revision 1.5 2004/09/07 20:58:35 reddawg + * time to roll back i can't think straight by friday + * + * Revision 1.4 2004/05/25 22:49:29 reddawg + * Stupid Old CODE!!! + * + * Revision 1.3 2004/05/19 04:07:43 reddawg + * kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + * + * Revision 1.2 2004/05/19 03:35:02 reddawg + * Fixed A Few Ordering Issues In The Service Startup Routine + * + * Revision 1.1.1.1 2004/04/15 12:07:14 reddawg + * UbixOS v1.0 + * + * Revision 1.13 2004/04/13 21:29:53 reddawg + * We now have sockets working. Lots of functionality to be added to continually + * improve on the existing layers now its clean up time to get things in a better + * working order. + * + * Revision 1.12 2004/04/13 16:08:07 reddawg + * Removed all of the old debug code the problem seems to be in ubthreads with + * ubthread_mutex_init + * + * Revision 1.11 2004/04/13 16:05:40 reddawg + * Function Renaming + * + * + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include + +#include "net/debug.h" +#include "net/sys.h" +#include "net/opt.h" +#include "net/stats.h" + +#include + +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) + +static struct sys_thread *threads = 0x0; +static spinLock_t netThreadSpinlock = SPIN_LOCK_INITIALIZER; + +struct sys_mbox_msg { + struct sys_mbox_msg *next; + void *msg; +}; + +#define SYS_MBOX_SIZE 100 + +struct sys_mbox { + uInt16 first, last; + void *msgs[SYS_MBOX_SIZE]; + struct sys_sem *mail; + struct sys_sem *mutex; +}; + +struct sys_sem { + unsigned int c; + ubthread_cond_t cond; + ubthread_mutex_t mutex; +}; + +struct sys_thread { + struct sys_thread *next; + struct sys_timeouts timeouts; + kTask_t *ubthread; +}; + + +static struct timeval starttime; + +static struct sys_sem *sys_sem_new_(uInt8 count); +static void sys_sem_free_(struct sys_sem *sem); + +static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout); + +static struct sys_thread *current_thread(void) { + struct sys_thread *st; + kTask_t *pt; + pt = ubthread_self(); + spinLock(&netThreadSpinlock); + for(st = threads; st != NULL; st = st->next) { + if(st->ubthread == pt) { + spinUnlock(&netThreadSpinlock); + return st; + } + } + spinUnlock(&netThreadSpinlock); + kprintf("sys: current_thread: could not find current thread!\n"); + kprintf("This is due to a race condition in the LinuxThreads\n"); + kprintf("ubthreads implementation. Start the program again.\n"); + + kpanic("ABORT"); + return(0x0); + } + + +struct thread_start_param { + struct sys_thread *thread; + void (* function)(void *); + void *arg; + }; + +/* +static void *thread_start(void *arg) { + struct thread_start_param *tp = arg; + tp->thread->ubthread = ubthread_self(); + tp->function(tp->arg); + kfree(tp); + return(NULL); + } +*/ + +void sys_thread_new(void (* function)(void), void *arg) { + struct sys_thread *thread = 0x0; + //struct thread_start_param *thread_param; + kprintf("sys_thread: [0x%X]\n",sizeof(struct sys_thread)); + + thread = kmalloc(sizeof(struct sys_thread)); + kprintf("THREAD: [0x%X]\n",thread); + spinLock(&netThreadSpinlock); + thread->next = threads; + thread->timeouts.next = NULL; + thread->ubthread = 0x0; + threads = thread; + spinUnlock(&netThreadSpinlock); + + + /* + thread_param = kmalloc(sizeof(struct thread_start_param)); + + thread_param->function = function; + thread_param->arg = arg; + thread_param->thread = thread; + */ + //execThread((void *)function,0x0,0x0); + + kprintf("thread->ubthread: [0x%X]\n",thread->ubthread); + if(ubthread_create(&thread->ubthread, 0x0,(void *)(function), arg) != 0x0) { + kpanic("sys_thread_new: ubthread_create"); + } + kprintf("thread->ubthread: [0x%X]\n",thread->ubthread); + + } + +struct sys_mbox *sys_mbox_new() { + struct sys_mbox *mbox; + + mbox = kmalloc(sizeof(struct sys_mbox)); + mbox->first = mbox->last = 0; + mbox->mail = sys_sem_new_(0); + mbox->mutex = sys_sem_new_(1); + + return(mbox); + } + +void sys_mbox_free(struct sys_mbox *mbox) { + if (mbox != SYS_MBOX_NULL) { + sys_sem_wait(mbox->mutex); + + sys_sem_free_(mbox->mail); + sys_sem_free_(mbox->mutex); + mbox->mail = mbox->mutex = NULL; + //kprintf("sys_mbox_free: mbox 0x%lx\n", mbox); + kfree(mbox); + } + } + +void sys_mbox_post(struct sys_mbox *mbox, void *msg) { + uInt8 first; + + sys_sem_wait(mbox->mutex); + + //kprintf("sys_mbox_post: mbox %p msg %p\n", mbox, msg); + + mbox->msgs[mbox->last] = msg; + + if (mbox->last == mbox->first) { + first = 1; + } + else { + first = 0; + } + + mbox->last++; + if(mbox->last == SYS_MBOX_SIZE) { + mbox->last = 0; + } + + if(first) { + sys_sem_signal(mbox->mail); + } + sys_sem_signal(mbox->mutex); + } + +uInt16 sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, uInt16 timeout) { + uInt16 time = 1; + + /* The mutex lock is quick so we don't bother with the timeout + stuff here. */ + sys_arch_sem_wait(mbox->mutex, 0); + + while(mbox->first == mbox->last) { + sys_sem_signal(mbox->mutex); + + /* We block while waiting for a mail to arrive in the mailbox. We + must be prepared to timeout. */ + if(timeout != 0) { + time = sys_arch_sem_wait(mbox->mail, timeout); + + /* If time == 0, the sem_wait timed out, and we return 0. */ + if(time == 0) { + return 0; + } + } else { + sys_arch_sem_wait(mbox->mail, 0); + } + + sys_arch_sem_wait(mbox->mutex, 0); + } + + if(msg != NULL) { + //kprintf("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg); + *msg = mbox->msgs[mbox->first]; + } + + mbox->first++; + if(mbox->first == SYS_MBOX_SIZE) { + mbox->first = 0; + } + + sys_sem_signal(mbox->mutex); + + return(time); + } + +struct sys_sem *sys_sem_new(uInt8 count) { + return sys_sem_new_(count); + } + +static struct sys_sem *sys_sem_new_(uInt8 count) { + struct sys_sem *sem; + + sem = kmalloc(sizeof(struct sys_sem)); + sem->c = count; + + ubthread_cond_init(&(sem->cond), NULL); + ubthread_mutex_init(&(sem->mutex), NULL); + + return sem; + } + +static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout) { + unsigned int tdiff; + unsigned long sec, usec; + struct timeval rtime1, rtime2; + struct timespec ts; + struct timezone tz; + int retval; + + if (timeout > 0) { + /* Get a timestamp and add the timeout value. */ + gettimeofday(&rtime1, &tz); + sec = rtime1.tv_sec; + usec = rtime1.tv_usec; + usec += timeout % 1000 * 1000; + sec += (int)(timeout / 1000) + (int)(usec / 1000000); + usec = usec % 1000000; + ts.tv_nsec = usec * 1000; + ts.tv_sec = sec; + + retval = ubthread_cond_timedwait(cond, mutex, &ts); + if (retval == ETIMEDOUT) { + return 0; + } + else { + /* Calculate for how long we waited for the cond. */ + gettimeofday(&rtime2, &tz); + tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + + (rtime2.tv_usec - rtime1.tv_usec) / 1000; + if (tdiff == 0) { + return 1; + } + return tdiff; + } + } + else { + ubthread_cond_wait(cond, mutex); + return 0; + } + } + +uInt16 sys_arch_sem_wait(struct sys_sem *sem, uInt16 timeout) { + uInt16 time = 1; + ubthread_mutex_lock(&(sem->mutex)); + while(sem->c <= 0) { + if(timeout > 0) { + time = cond_wait(&(sem->cond), &(sem->mutex), timeout); + if(time == 0) { + ubthread_mutex_unlock(&(sem->mutex)); + return 0; + } + } else { + cond_wait(&(sem->cond), &(sem->mutex), 0); + } + } + sem->c--; + ubthread_mutex_unlock(&(sem->mutex)); + return(time); + } + +void sys_sem_signal(struct sys_sem *sem) { + ubthread_mutex_lock(&(sem->mutex)); + sem->c++; + if(sem->c > 1) + sem->c = 1; + ubthread_cond_signal(&(sem->cond)); + ubthread_mutex_unlock(&(sem->mutex)); + } + +void sys_sem_free(struct sys_sem *sem) { + if(sem != SYS_SEM_NULL) { + sys_sem_free_(sem); + } + } + +static void sys_sem_free_(struct sys_sem *sem) { + ubthread_cond_destroy(&(sem->cond)); + ubthread_mutex_destroy(&(sem->mutex)); + kfree(sem); + } + +unsigned long sys_unix_now() { + struct timeval tv; + struct timezone tz; + long sec, usec; + unsigned long msec; + gettimeofday(&tv, &tz); + + sec = tv.tv_sec - starttime.tv_sec; + usec = tv.tv_usec - starttime.tv_usec; + msec = sec * 1000 + usec / 1000; + return msec; + } + +void sys_init() { + struct timezone tz; + gettimeofday(&starttime, &tz); + } + +struct sys_timeouts *sys_arch_timeouts(void) { + struct sys_thread *thread; + thread = current_thread(); + return(&thread->timeouts); + } + +/*** + END + ***/ diff --git a/net/net/udpecho.c b/net/net/udpecho.c new file mode 100644 index 0000000..f8b556a --- /dev/null +++ b/net/net/udpecho.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "net/api.h" +#include "net/sys.h" + +/*-----------------------------------------------------------------------------------*/ +void +udpecho_thread(void *arg) +{ + static struct netconn *conn; + static struct netbuf *buf; + static struct ip_addr *addr; + static unsigned short port; + char buffer[4096]; + + kprintf("1"); + conn = netconn_new(NETCONN_UDP); + kprintf("2"); + netconn_bind(conn, NULL, 7); + kprintf("3"); + + while(1) { + kprintf("a"); + buf = netconn_recv(conn); + kprintf("b"); + addr = netbuf_fromaddr(buf); + kprintf("c"); + port = netbuf_fromport(buf); + kprintf("d"); + netconn_connect(conn, addr, port); + kprintf("e"); + netconn_send(conn, buf); + kprintf("f"); + netbuf_copy(buf, buffer, sizeof(buffer)); + kprintf("got %s\n", buffer); + netbuf_delete(buf); + kprintf("g"); + } +} +/*-----------------------------------------------------------------------------------*/ +void +udpecho_init(void) +{ + sys_thread_new(udpecho_thread, NULL); +} diff --git a/net/net/udpecho.h b/net/net/udpecho.h new file mode 100644 index 0000000..9faea8f --- /dev/null +++ b/net/net/udpecho.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __UDPECHO_H__ +#define __UDPECHO_H__ + +void udpecho_init(void); + +#endif /* __UDPECHO_H__ */ diff --git a/net/netif/Makefile b/net/netif/Makefile new file mode 100644 index 0000000..0617340 --- /dev/null +++ b/net/netif/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = ethernetif.o loopif.o tcpdump.o arp.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -DNOBOOL -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -DNOBOOL -I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/net/netif/arp.c b/net/netif/arp.c new file mode 100644 index 0000000..48f74e6 --- /dev/null +++ b/net/netif/arp.c @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + * + */ + +#include +#include + +#include "net/debug.h" +#include "net/ipv4/inet.h" +#include "netif/arp.h" +#include "net/ipv4/ip.h" + + +#define ARP_MAXAGE 2 /* 120 * 10 seconds = 20 minutes. */ + +#define HWTYPE_ETHERNET 1 + +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +/* MUST be compiled with "pack structs" or equivalent! */ +PACK_STRUCT_BEGIN +struct arp_hdr { + PACK_STRUCT_FIELD(struct eth_hdr ethhdr); + PACK_STRUCT_FIELD(uInt16 hwtype); + PACK_STRUCT_FIELD(uInt16 proto); + PACK_STRUCT_FIELD(uInt16 _hwlen_protolen); + PACK_STRUCT_FIELD(uInt16 opcode); + PACK_STRUCT_FIELD(struct eth_addr shwaddr); + PACK_STRUCT_FIELD(struct ip_addr sipaddr); + PACK_STRUCT_FIELD(struct eth_addr dhwaddr); + PACK_STRUCT_FIELD(struct ip_addr dipaddr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END + +#define ARPH_HWLEN(hdr) (NTOHS((hdr)->_hwlen_protolen) >> 8) +#define ARPH_PROTOLEN(hdr) (NTOHS((hdr)->_hwlen_protolen) & 0xff) + + +#define ARPH_HWLEN_SET(hdr, len) (hdr)->_hwlen_protolen = HTONS(ARPH_PROTOLEN(hdr) | ((len) << 8)) +#define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = HTONS((len) | (ARPH_HWLEN(hdr) << 8)) + +PACK_STRUCT_BEGIN +struct ethip_hdr { + PACK_STRUCT_FIELD(struct eth_hdr eth); + PACK_STRUCT_FIELD(struct ip_hdr ip); +}; +PACK_STRUCT_END + +struct arp_entry { + struct ip_addr ipaddr; + struct eth_addr ethaddr; + uInt8 ctime; +}; + +static struct arp_entry arp_table[ARP_TABLE_SIZE]; +static uInt8 ctime; + +/*-----------------------------------------------------------------------------------*/ +void +arp_init(void) +{ + uInt8 i; + + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + ip_addr_set(&(arp_table[i].ipaddr), + IP_ADDR_ANY); + } +} +/*-----------------------------------------------------------------------------------*/ +void +arp_tmr(void) +{ + uInt8 i; + + ++ctime; + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(!ip_addr_isany(&arp_table[i].ipaddr) && + ctime - arp_table[i].ctime >= ARP_MAXAGE) { + DEBUGF(ARP_DEBUG, ("arp_timer: expired entry %d.\n", i)); + ip_addr_set(&(arp_table[i].ipaddr), + IP_ADDR_ANY); + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +add_arp_entry(struct ip_addr *ipaddr, struct eth_addr *ethaddr) +{ + uInt8 i, j, k; + uInt8 maxtime; + + /* Walk through the ARP mapping table and try to find an entry to + update. If none is found, the IP -> MAC address mapping is + inserted in the ARP table. */ + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + + /* Only check those entries that are actually in use. */ + if(!ip_addr_isany(&arp_table[i].ipaddr)) { + /* Check if the source IP address of the incoming packet matches + the IP address in this ARP table entry. */ + if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { + /* An old entry found, update this and return. */ + for(k = 0; k < 6; ++k) { + arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; + } + arp_table[i].ctime = ctime; + return; + } + } + } + + /* If we get here, no existing ARP table entry was found, so we + create one. */ + + /* First, we try to find an unused entry in the ARP table. */ + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ip_addr_isany(&arp_table[i].ipaddr)) { + break; + } + } + + /* If no unused entry is found, we try to find the oldest entry and + throw it away. */ + if(i == ARP_TABLE_SIZE) { + maxtime = 0; + j = 0; + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ctime - arp_table[i].ctime > maxtime) { + maxtime = ctime - arp_table[i].ctime; + j = i; + } + } + i = j; + } + + /* Now, i is the ARP table entry which we will fill with the new + information. */ + ip_addr_set(&arp_table[i].ipaddr, ipaddr); + for(k = 0; k < 6; ++k) { + arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; + } + arp_table[i].ctime = ctime; + return; + +} +/*-----------------------------------------------------------------------------------*/ +void +arp_ip_input(struct netif *netif, struct pbuf *p) +{ + struct ethip_hdr *hdr; + + hdr = p->payload; + + /* Only insert/update an entry if the source IP address of the + incoming IP packet comes from a host on the local network. */ + if(!ip_addr_maskcmp(&(hdr->ip.src), &(netif->ip_addr), &(netif->netmask))) { + return; + } + DEBUGF(ARP_DEBUG, ("arp_ip_input: updating ARP table.\n")); + add_arp_entry(&(hdr->ip.src), &(hdr->eth.src)); +} +/*-----------------------------------------------------------------------------------*/ +struct pbuf * +arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) +{ + struct arp_hdr *hdr; + uInt8 i; + + if(p->tot_len < sizeof(struct arp_hdr)) { + kprintf("arp_arp_input: packet too short (%d/%d)\n", p->tot_len, sizeof(struct arp_hdr)); + pbuf_free(p); + return NULL; + } + + hdr = p->payload; + + switch(htons(hdr->opcode)) { + case ARP_REQUEST: + /* ARP request. If it asked for our address, we send out a + reply. */ + if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { + hdr->opcode = htons(ARP_REPLY); + + ip_addr_set(&(hdr->dipaddr), &(hdr->sipaddr)); + ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); + + for(i = 0; i < 6; ++i) { + hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i]; + hdr->shwaddr.addr[i] = ethaddr->addr[i]; + hdr->ethhdr.dest.addr[i] = hdr->dhwaddr.addr[i]; + hdr->ethhdr.src.addr[i] = ethaddr->addr[i]; + } + + hdr->hwtype = htons(HWTYPE_ETHERNET); + ARPH_HWLEN_SET(hdr, 6); + + hdr->proto = htons(ETHTYPE_IP); + ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr)); + + hdr->ethhdr.type = htons(ETHTYPE_ARP); + return p; + } + break; + case ARP_REPLY: + /* ARP reply. We insert or update the ARP table. */ + if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { + add_arp_entry(&(hdr->sipaddr), &(hdr->shwaddr)); + } + break; + default: + kprintf("arp_arp_input: unknown type %d\n", htons(hdr->opcode)); + break; + } + + pbuf_free(p); + return NULL; +} +/*-----------------------------------------------------------------------------------*/ +struct eth_addr * +arp_lookup(struct ip_addr *ipaddr) +{ + uInt8 i; + + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { + return &arp_table[i].ethaddr; + } + } + return NULL; +} +/*-----------------------------------------------------------------------------------*/ +struct pbuf * +arp_query(struct netif *netif, struct eth_addr *ethaddr, struct ip_addr *ipaddr) +{ + struct arp_hdr *hdr; + struct pbuf *p; + uInt8 i; + + p = pbuf_alloc(PBUF_LINK, sizeof(struct arp_hdr), PBUF_RAM); + if(p == NULL) { + return NULL; + } + + hdr = p->payload; + + hdr->opcode = htons(ARP_REQUEST); + + for(i = 0; i < 6; ++i) { + hdr->dhwaddr.addr[i] = 0x00; + hdr->shwaddr.addr[i] = ethaddr->addr[i]; + } + + ip_addr_set(&(hdr->dipaddr), ipaddr); + ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); + + hdr->hwtype = htons(HWTYPE_ETHERNET); + ARPH_HWLEN_SET(hdr, 6); + + hdr->proto = htons(ETHTYPE_IP); + ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr)); + + for(i = 0; i < 6; ++i) { + hdr->ethhdr.dest.addr[i] = 0xff; + hdr->ethhdr.src.addr[i] = ethaddr->addr[i]; + } + + hdr->ethhdr.type = htons(ETHTYPE_ARP); + return p; +} +/*-----------------------------------------------------------------------------------*/ + + + + diff --git a/net/netif/ethernetif.c b/net/netif/ethernetif.c new file mode 100644 index 0000000..0d4eb29 --- /dev/null +++ b/net/netif/ethernetif.c @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +/* + * This file is a skeleton for developing Ethernet network interface + * drivers for lwIP. Add code to the low_level functions and do a + * search-and-replace for the word "ethernetif" to replace it with + * something that better describes your network interface. + */ + +#include +#include +#include +#include +#include +#include + + +#include "net/debug.h" + +#include "net/opt.h" +#include "net/def.h" +#include "net/mem.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "netif/arp.h" + +/* Define those to better describe your network interface. */ +#define IFNAME0 'e' +#define IFNAME1 'd' + +struct nicBuffer *tmpBuf = 0x0; + +struct ethernetif { + struct eth_addr *ethaddr; + /* Add whatever per-interface state that is needed here. */ +}; + +static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; + +/* Forward declarations. */ +static void ethernetif_input(struct netif *netif); +static err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); +static void ethernetif_thread(); +struct device *dev = 0x0; + +/*-----------------------------------------------------------------------------------*/ +static void low_level_init(struct netif *netif) { + struct ethernetif *ethernetif; + + ethernetif = netif->state; + dev = (struct device *)kmalloc(sizeof(struct device)); + dev->ioAddr = 0x280; + dev->irq = 0x10; + + /* Obtain MAC address from network interface. */ + ethernetif->ethaddr->addr[0] = 0x00; + ethernetif->ethaddr->addr[1] = 0x00; + ethernetif->ethaddr->addr[2] = 0xC0; + ethernetif->ethaddr->addr[3] = 0x97; + ethernetif->ethaddr->addr[4] = 0xC6; + ethernetif->ethaddr->addr[5] = 0x93; + + /* Do whatever else is needed to initialize interface. */ + kprintf("NETIF: [0x%X:0x%X]\n",netif,ethernetif_thread); + sys_thread_new(ethernetif_thread, netif); + + } +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_output(): + * + * Should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained. + * + */ +/*-----------------------------------------------------------------------------------*/ + +static err_t low_level_output(struct ethernetif *ethernetif, struct pbuf *p) { + struct pbuf *q; + char buf[1500]; + char *bufptr = 0x0; + + dev->ioAddr = 0x280; + dev->irq = 10; + + bufptr = &buf[0]; + + for(q = p; q != NULL; q = q->next) { + bcopy(q->payload, bufptr, q->len); + bufptr += q->len; + } + PCtoNIC(dev,buf,p->tot_len); + //kprintf("Sending Data[%i]\n",p->tot_len); + return ERR_OK; + } + + +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_input(): + * + * Should allocate a pbuf and transfer the bytes of the incoming + * packet from the interface into the pbuf. + * + */ +/*-----------------------------------------------------------------------------------*/ +static struct pbuf *low_level_input(struct ethernetif *ethernetif) { + struct pbuf *p, *q; + uInt16 len; + char *bufptr; + char *buf; + + len = tmpBuf->length; + bufptr = tmpBuf->buffer; + + + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); + + if(p != NULL) { + /* We iterate over the pbuf chain until we have read the entire + packet into the pbuf. */ + //bufptr = &buf[0]; + for(q = p; q != NULL; q = q->next) { + /* Read enough bytes to fill this pbuf in the chain. The + avaliable data in the pbuf is given by the q->len + variable. */ + /* read data into(q->payload, q->len); */ + bcopy(bufptr, q->payload, q->len); + buf = q->payload; + bufptr += q->len; + } + /* acknowledge that packet has been read(); */ + } else { + /* drop packet(); */ + } + return p; +} + + +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_output(): + * + * This function is called by the TCP/IP stack when an IP packet + * should be sent. It calls the function called low_level_output() to + * do the actuall transmission of the packet. + * + */ +/*-----------------------------------------------------------------------------------*/ +static err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) { + struct ethernetif *ethernetif; + struct pbuf *q; + struct eth_hdr *ethhdr; + struct eth_addr *dest, mcastaddr; + struct ip_addr *queryaddr; + err_t err; + uInt8 i; + + ethernetif = netif->state; + + + /* Make room for Ethernet header. */ + if(pbuf_header(p, sizeof(struct eth_hdr)) != 0) { + /* The pbuf_header() call shouldn't fail, but we allocate an extra + pbuf just in case. */ + q = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr), PBUF_RAM); + if(q == NULL) { + return ERR_MEM; + } + pbuf_chain(q, p); + p = q; + } + + /* Construct Ethernet header. Start with looking up deciding which + MAC address to use as a destination address. Broadcasts and + multicasts are special, all other addresses are looked up in the + ARP table. */ + queryaddr = ipaddr; + if(ip_addr_isany(ipaddr) || + ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { + dest = (struct eth_addr *)ðbroadcast; + } else if(ip_addr_ismulticast(ipaddr)) { + /* Hash IP multicast address to MAC address. */ + mcastaddr.addr[0] = 0x01; + mcastaddr.addr[1] = 0x0; + mcastaddr.addr[2] = 0x5e; + mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f; + mcastaddr.addr[4] = ip4_addr3(ipaddr); + mcastaddr.addr[5] = ip4_addr4(ipaddr); + dest = &mcastaddr; + } else { + if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { + /* Use destination IP address if the destination is on the same + subnet as we are. */ + queryaddr = ipaddr; + } else { + /* Otherwise we use the default router as the address to send + the Ethernet frame to. */ + queryaddr = &(netif->gw); + } + dest = arp_lookup(queryaddr); + } + + + /* If the arp_lookup() didn't find an address, we send out an ARP + query for the IP address. */ + if(dest == NULL) { + q = arp_query(netif, ethernetif->ethaddr, queryaddr); + if(q != NULL) { + err = low_level_output(ethernetif, q); + pbuf_free(q); + return err; + } + return ERR_MEM; + } + ethhdr = p->payload; + + for(i = 0; i < 6; i++) { + ethhdr->dest.addr[i] = dest->addr[i]; + ethhdr->src.addr[i] = ethernetif->ethaddr->addr[i]; + } + + ethhdr->type = htons(ETHTYPE_IP); + + return low_level_output(ethernetif, p); + +} +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_input(): + * + * This function should be called when a packet is ready to be read + * from the interface. It uses the function low_level_input() that + * should handle the actual reception of bytes from the network + * interface. + * + */ +/*-----------------------------------------------------------------------------------*/ +static void ethernetif_input(struct netif *netif) { + struct ethernetif *ethernetif = 0x0; + struct eth_hdr *ethhdr = 0x0; + struct pbuf *p = 0x0; + + ethernetif = netif->state; + + p = low_level_input(ethernetif); + + if(p != NULL) { + + ethhdr = p->payload; + + switch(htons(ethhdr->type)) { + case ETHTYPE_IP: + arp_ip_input(netif, p); + pbuf_header(p, -14); + netif->input(p, netif); + break; + case ETHTYPE_ARP: + p = arp_arp_input(netif, ethernetif->ethaddr, p); + if(p != NULL) { + low_level_output(ethernetif, p); + pbuf_free(p); + } + break; + default: + pbuf_free(p); + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +arp_timer(void *arg) +{ + arp_tmr(); + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} + +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_init(): + * + * Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + */ +/*-----------------------------------------------------------------------------------*/ +void ethernetif_init(struct netif *netif) { + struct ethernetif *ethernetif; + + ethernetif = mem_malloc(sizeof(struct ethernetif)); + netif->state = ethernetif; + netif->name[0] = IFNAME0; + netif->name[1] = IFNAME1; + netif->output = ethernetif_output; + netif->linkoutput = (void *)low_level_output; + + ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); + + low_level_init(netif); + arp_init(); + + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); + } + +/*-----------------------------------------------------------------------------------*/ + +void ethernetif_thread(void *arg) { + struct netif *netif = 0x0; + + netif = arg; + + while (1) { + tmpBuf = ne2kGetBuffer(); + if (tmpBuf && tmpBuf->length > 0x0) { + ethernetif_input(netif); + } + } + ne2kFreeBuffer(tmpBuf); + } diff --git a/net/netif/loopif.c b/net/netif/loopif.c new file mode 100644 index 0000000..fbf42a8 --- /dev/null +++ b/net/netif/loopif.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#include "net/debug.h" +#include "net/mem.h" +#include "net/opt.h" +#include "netif/loopif.h" +#include "netif/tcpdump.h" + +#include "net/tcp.h" +#include "net/ipv4/ip.h" + +/*-----------------------------------------------------------------------------------*/ +static err_t +loopif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr) +{ + struct pbuf *q, *r; + char *ptr; + +#ifdef LWIP_DEBUG + tcpdump(p); +#endif /* LWIP_DEBUG */ + + r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); + if(r != NULL) { + ptr = r->payload; + + for(q = p; q != NULL; q = q->next) { + bcopy(q->payload, ptr, q->len); + ptr += q->len; + } + netif->input(r, netif); + return ERR_OK; + } + return ERR_MEM; +} +/*-----------------------------------------------------------------------------------*/ +void +loopif_init(struct netif *netif) +{ + netif->name[0] = 'l'; + netif->name[1] = 'o'; + netif->output = loopif_output; +} +/*-----------------------------------------------------------------------------------*/ + + + + + + + diff --git a/net/netif/tcpdump.c b/net/netif/tcpdump.c new file mode 100644 index 0000000..8fcef44 --- /dev/null +++ b/net/netif/tcpdump.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "netif/tcpdump.h" +#include "net/ipv4/ip.h" +#include "net/tcp.h" +#include "net/udp.h" +#include "net/ipv4/inet.h" + +fileDescriptor *file = NULL; + +void tcpdump_init(void) { + char *fname; + + fname = "tcpdump"; + file = fopen(fname, "wb"); + if(file == NULL) { + kpanic("tcpdump_init: fopen\n"); + } + } + +void tcpdump(struct pbuf *p) { +/* + struct ip_hdr *iphdr; + struct tcp_hdr *tcphdr; + struct udp_hdr *udphdr; + char flags[5]; + int i; + int len; + int offset; +*/ + if (file == NULL) { + return; + } + + /* + iphdr = p->payload; + switch(IPH_PROTO(iphdr)) { + case IP_PROTO_TCP: + tcphdr = (struct tcp_hdr *)((char *)iphdr + IP_HLEN); + + pbuf_header(p, -IP_HLEN); + if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), + (struct ip_addr *)&(iphdr->dest), + IP_PROTO_TCP, p->tot_len) != 0) { + DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n")); + fprintf(file, "!chksum "); + } + + i = 0; + if(TCPH_FLAGS(tcphdr) & TCP_SYN) { + flags[i++] = 'S'; + } + if(TCPH_FLAGS(tcphdr) & TCP_PSH) { + flags[i++] = 'P'; + } + if(TCPH_FLAGS(tcphdr) & TCP_FIN) { + flags[i++] = 'F'; + } + if(TCPH_FLAGS(tcphdr) & TCP_RST) { + flags[i++] = 'R'; + } + if(i == 0) { + flags[i++] = '.'; + } + flags[i++] = 0; + + + + fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ", + (int)(ntohl(iphdr->src.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 0) & 0xff, + ntohs(tcphdr->src), + (int)(ntohl(iphdr->dest.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 0) & 0xff, + ntohs(tcphdr->dest)); + offset = TCPH_OFFSET(tcphdr) >> 4; + + len = ntohs(IPH_LEN(iphdr)) - offset * 4 - IP_HLEN; + if(len != 0 || flags[0] != '.') { + fprintf(file, "%s %lu:%lu(%u) ", + flags, + ntohl(tcphdr->seqno), + ntohl(tcphdr->seqno) + len, + len); + } + if(TCPH_FLAGS(tcphdr) & TCP_ACK) { + fprintf(file, "ack %lu ", + ntohl(tcphdr->ackno)); + } + fprintf(file, "wnd %u\n", + ntohs(tcphdr->wnd)); + + fflush(file); + + pbuf_header(p, IP_HLEN); + break; + + case IP_PROTO_UDP: + udphdr = (struct udp_hdr *)((char *)iphdr + IP_HLEN); + + pbuf_header(p, -IP_HLEN); + if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), + (struct ip_addr *)&(iphdr->dest), + IP_PROTO_UDP, p->tot_len) != 0) { + kprintf("tcpdump: IP checksum failed!\n"); + fprintf(file, "!chksum "); + } + + fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ", + (int)(ntohl(iphdr->src.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 0) & 0xff, + ntohs(udphdr->src), + (int)(ntohl(iphdr->dest.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 0) & 0xff, + ntohs(udphdr->dest)); + fprintf(file, "U "); + len = ntohs(IPH_LEN(iphdr)) - sizeof(struct udp_hdr) - IP_HLEN; + fprintf(file, " %d\n", len); + + fflush(file); + + pbuf_header(p, IP_HLEN); + break; + + } + */ + } + +/*** + END + ***/ + diff --git a/pci/Makefile b/pci/Makefile new file mode 100644 index 0000000..a96850d --- /dev/null +++ b/pci/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = hd.o pci.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/pci/hd.c b/pci/hd.c new file mode 100644 index 0000000..2554f0e --- /dev/null +++ b/pci/hd.c @@ -0,0 +1,451 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int initHardDisk() { + int i = 0x0; + int x = 0x0; + int minor = 0x0; + struct device_interface *devInfo = 0x0; + struct device_interface *devInfo2 = 0x0; + struct dos_partition *d = 0x0; + struct driveInfo *hdd = 0x0; + struct driveInfo *hdd2 = 0x0; + char *data = 0x0; + char *data2 = 0x0; + char name[16]; + struct bsd_disklabel *bsdd = 0x0; + + hdd = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd->hdPort = 0x1F0; + hdd->hdDev = 0x40; + hdd->parOffset = 0x0; + + + /* Alloc memory for device structure and set it up correctly */ + devInfo = (struct device_interface *)kmalloc(sizeof(struct device_interface)); + devInfo->read = (void *)&hdRead; + devInfo->write = (void *)&hdWrite; + devInfo->reset = (void *)&hdReset; + devInfo->init = (void *)&hdInit; + devInfo->ioctl = (void *)&hdIoctl; + devInfo->stop = (void *)&hdStop; + devInfo->start = (void *)&hdStart; + devInfo->standby = (void *)&hdStandby; + devInfo->info = hdd; + + devInfo->major = 0x1; + + data = (char *)kmalloc(512); + d = (struct dos_partition *)(data + 0x1BE); + + data2 = (char *)kmalloc(512); + bsdd = (struct bsd_disklabel *)data2; + + if (device_add(0,'c',devInfo) == 0x0) { + kprintf("ad0 - Start: [0x0], Size: [0x%x/0x%X]\n",hdd->hdSize,hdd->hdSize*512); + devfs_makeNode("ad0",'b',0x1,0x0); + hdRead(devInfo->info,data,0x0,0x1); + for (i = 0x0;i < 0x4;i++) { + if (d[i].dp_type != 0x0) { + devInfo2 = (struct device_interface *)kmalloc(sizeof(struct device_interface)); + hdd2 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + memcpy(devInfo2,devInfo,sizeof(struct device_interface)); + memcpy(hdd2,hdd,sizeof(struct driveInfo)); + hdd2->parOffset = d[i].dp_start; + devInfo2->info = hdd2; + minor++; + if (device_add(minor,'c',devInfo2) == 0x0) { + sprintf(name,"ad0s%i",i + 1); + kprintf("%s - Type: [0x%X], Start: [0x%X], Size: [0x%X]\n",name,d[i].dp_type,d[i].dp_start,d[i].dp_size); + devfs_makeNode(name,'c',0x1,minor); + if (d[i].dp_type == 0xA5) { + //Why do i need to add 1? + hdRead(devInfo->info,data2,d[i].dp_start + 1,0x1); + for (x = 0;x < bsdd->d_npartitions;x++) { + if (bsdd->d_partitions[x].p_size > 0) { + sprintf(name,"ad0s%i%c",i + 1,'a' + x); + //New Nodes + devInfo2 = (struct device_interface *)kmalloc(sizeof(struct device_interface)); + hdd2 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + memcpy(devInfo2,devInfo,sizeof(struct device_interface)); + memcpy(hdd2,hdd,sizeof(struct driveInfo)); + //hdd2->parOffset = d[i].dp_start + bsdd->d_partitions[x].p_offset; + hdd2->parOffset = bsdd->d_partitions[x].p_offset; + devInfo2->info = hdd2; + minor++; + device_add(minor,'c',devInfo2); + devfs_makeNode(name,'c',0x1,minor); + kprintf("%s - Type: [%s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n",name,fstypenames[bsdd->d_partitions[x].p_fstype],bsdd->d_partitions[x].p_offset,bsdd->d_partitions[x].p_size,devInfo->major,minor); + } + } + } + } + } + } + } + kfree(data); + return(0x0); + } + +int hdStandby() { + return(0x0); + } + +int hdStart() { + return(0x0); + } + +int hdStop() { + return(0x0); + } + +int hdIoctl() { + return(0x0); + } + +int hdReset() { + return(0x0); + } + +int hdInit(struct device_node *dev) { + char retVal = 0x0; + long counter = 0x0; + short *tmp = 0x0; + struct driveInfo *hdd = dev->devInfo->info; + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Error Initializing Drive\n"); + return(1); + ready: + outportByte(hdd->hdPort + hdHead,hdd->hdDev); + outportByte(hdd->hdPort + hdCmd,0xEC); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("Error Drive Not Available\n"); + return(1); + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Time Out Waiting On Drive\n"); + return(1); + go: + tmp = (short *)hdd->hdSector; + for (counter = 0;counter < (512/2);counter++) { + tmp[counter] = inportWord(hdd->hdPort + hdData); + } + retVal = tmp[0x2F] & 0xFF; + switch (retVal) { + case 0: + hdd->hdShift = 0; + hdd->hdMulti = 1; + break; + case 2: + hdd->hdShift = 1; + hdd->hdMulti = retVal; + break; + case 4: + hdd->hdShift = 2; + hdd->hdMulti = retVal; + break; + case 8: + hdd->hdShift = 3; + hdd->hdMulti = retVal; + break; + case 16: + hdd->hdShift = 4; + hdd->hdMulti = retVal; + break; + case 32: + hdd->hdShift = 5; + hdd->hdMulti = retVal; + break; + case 64: + hdd->hdShift = 6; + hdd->hdMulti = retVal; + break; + default: + kprintf("Error BLOCK Mode Unavailable: [%i]\n",retVal); + return(1); + } + outportByte(hdd->hdPort + hdSecCount,retVal); + outportByte(hdd->hdPort + hdHead,hdd->hdDev); + outportByte(hdd->hdPort + hdCmd,0xC6); + hdd->hdMask = retVal; + hdd->hdSize = (hdd->hdSector[0x7B] * 256 * 256 * 256) + (hdd->hdSector[0x7A] * 256 * 256) + (hdd->hdSector[0x79] * 256) + hdd->hdSector[0x78]; + hdd->hdEnable = 1; + kprintf("Drive: [0x%X/0x%X], Size: [0x%X Sectors/0x%X KBytes]\n",hdd->hdPort,hdd->hdDev,hdd->hdSize,((hdd->hdSize*512)/1024)); + dev->devInfo->size = hdd->hdSize*512; + dev->devInfo->initialized = 0x1; + return(0x0); + } + +void hdWrite(struct driveInfo *hdd,void *baseAddr,uInt32 startSector,uInt32 sectorCount) { + long counter = 0x0; + long retVal = 0x0; + short transactionCount = 0x0; + short *tmp = (short *)baseAddr; + startSector += hdd->parOffset; + if (hdd->hdEnable == 0x0) { + kprintf("Invalid Drive\n"); + return; + } + if ((sectorCount >> hdd->hdShift) == 0x0) { + hdd->hdCalc = sectorCount; /* hdd->hdMask; */ + transactionCount = 1; + } + else { + hdd->hdCalc = hdd->hdMulti; + transactionCount = sectorCount >> hdd->hdShift; + } + for (;transactionCount > 0;transactionCount--) { + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Time Out Waiting On Drive\n"); + return; + ready: + outportByte(hdd->hdPort + hdSecCount,hdd->hdCalc); + outportByte(hdd->hdPort + hdSecNum,(startSector & 0xFF)); + retVal = startSector >> 8; + outportByte(hdd->hdPort + hdCylLow,(retVal & 0xFF)); + retVal >>= 8; + outportByte(hdd->hdPort + hdCylHi,(retVal & 0xFF)); + retVal >>= 8; + retVal &= 0x0F; + retVal |= (hdd->hdDev | 0xA0); //Test As Per TJ + outportByte(hdd->hdPort + hdHead,(retVal & 0xFF)); + if (hdd->hdShift > 0) + outportByte(hdd->hdPort + hdCmd,0xC5); + else + outportByte(hdd->hdPort + hdCmd,0x30); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("HD Write Error\n"); + return; + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Time Out Waiting On Drive\n"); + return; + go: + for (counter = 0;counter < (hdd->hdCalc << 8);counter++) { + outportWord(hdd->hdPort + hdData,(short)tmp[counter]); + } + tmp += (counter + 0); + startSector += hdd->hdCalc; + } + return; + } + +void hdRead(struct driveInfo *hdd,void *baseAddr,uInt32 startSector,uInt32 sectorCount) { + long counter = 0x0; + long retVal = 0x0; + short transactionCount = 0x0; + short *tmp = (short *)baseAddr; + startSector += hdd->parOffset; + + if (hdd->hdEnable == 0x0) { + kprintf("Invalid Drive\n"); + return; + } + if ((sectorCount >> hdd->hdShift) == 0x0) { + hdd->hdCalc = sectorCount; /* hdd->hdMask); */ + transactionCount = 1; + } + else { + hdd->hdCalc = hdd->hdMulti; + transactionCount = sectorCount >> hdd->hdShift; + } + for (;transactionCount > 0;transactionCount--) { + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Time Out Waiting On Drive\n"); + return; + ready: + outportByte(hdd->hdPort + hdSecCount,hdd->hdCalc); + outportByte(hdd->hdPort + hdSecNum,(startSector & 0xFF)); + retVal = startSector >> 8; + outportByte(hdd->hdPort + hdCylLow,(retVal & 0xFF)); + retVal >>= 8; + outportByte(hdd->hdPort + hdCylHi,(retVal & 0xFF)); + retVal >>= 8; + retVal &= 0x0F; + retVal |= (hdd->hdDev | 0xA0); //Test as per TJ + //retVal |= hdd->hdDev; //retVal |= (hdd->hdDev | 0xA0); //Test as per TJ + outportByte(hdd->hdPort + hdHead,(retVal & 0xFF)); + if (hdd->hdShift > 0) + outportByte(hdd->hdPort + hdCmd,0xC4); + else + outportByte(hdd->hdPort + hdCmd,0x20); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("HD Read Error: [%i:0x%X:%i]\n",counter,(uInt32)baseAddr,startSector); + return; + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Error: Time Out Waiting On Drive\n"); + return; + go: + for (counter = 0;counter < (hdd->hdCalc << 8);counter++) { + tmp[counter] = inportWord(hdd->hdPort + hdData); + } + tmp += (counter + 0); + startSector += hdd->hdCalc; + } + return; + } + +/*** + $Log$ + Revision 1.2 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.5 2006/10/12 15:00:26 reddawg + More changes + + Revision 1.4 2006/10/10 14:14:01 reddawg + UFS Reading + + Revision 1.3 2006/10/09 02:58:05 reddawg + Fixing UFS + + Revision 1.2 2006/10/06 15:48:01 reddawg + Starting to make ubixos work with UFS2 + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:34 reddawg + no message + + Revision 1.16 2004/08/26 22:51:19 reddawg + TCA touched me :( i think he likes men.... + + + sched.h: kTask_t added parentPid + endtask.c: fixed term back to parentPid + exec.c: cleaned warnings + fork.c: fixed term to childPid + sched.c: clean up for dead tasks + systemtask.c: clean up dead tasks + kmalloc.c: cleaned up warnings + udp.c: cleaned up warnings + bot.c: cleaned up warnings + shell.c: cleaned up warnings + tcpdump.c: took a dump + hd.c: cleaned up warnings + ubixfs.c: stopped prning debug info + + Revision 1.15 2004/08/15 00:33:02 reddawg + Wow the ide driver works again + + Revision 1.14 2004/08/14 21:56:44 reddawg + Added initialized byte to the device system to make it easy to add child devices which use parent hardware. + + Revision 1.13 2004/08/02 11:43:17 reddawg + Fixens + + Revision 1.12 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.11 2004/05/19 23:36:52 reddawg + Bug Fixes + + Revision 1.10 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.9 2004/05/19 15:07:59 reddawg + Typo defInfo should of been devInfo + + Revision 1.7 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.6 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.5 2004/04/28 02:37:34 reddawg + More updates for using the new driver subsystem + + Revision 1.4 2004/04/28 02:22:54 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.3 2004/04/27 21:05:19 reddawg + Updating drivers to use new model + + Revision 1.2 2004/04/26 22:22:33 reddawg + DevFS now uses correct size of device + + Revision 1.1.1.1 2004/04/15 12:07:16 reddawg + UbixOS v1.0 + + Revision 1.12 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/pci/lnc.c b/pci/lnc.c new file mode 100644 index 0000000..5c499b2 --- /dev/null +++ b/pci/lnc.c @@ -0,0 +1,316 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:35 reddawg + no message + + Revision 1.1.1.1 2004/04/15 12:07:15 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct lncInfo *lnc = 0x0; + +static char const * const nicIdent[] = { + "Unknown", + "BICC", + "NE2100", + "DEPCA", + "CNET98S", /* PC-98 */ + }; + +static char const * const icIdent[] = { + "Unknown", + "LANCE", + "C-LANCE", + "PCnet-ISA", + "PCnet-ISA+", + "PCnet-ISA II", + "PCnet-32 VL-Bus", + "PCnet-PCI", + "PCnet-PCI II", + "PCnet-FAST", + "PCnet-FAST+", + "PCnet-Home", + }; + +void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val) { + outportWord(lnc->rap, port); + outportWord(lnc->rdp, val); + } + +uInt16 readCsr(struct lncInfo *lnc, uInt16 port) { + outportWord(lnc->rap, port); + return(inportWord(lnc->rdp)); + } + +void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val) { + outportWord(lnc->rap, port); + outportWord(lnc->bdp, val); + } + +uInt16 readBcr(struct lncInfo *sc, uInt16 port) { + outportWord(sc->rap, port); + return (inportWord(sc->bdp)); + } + + +void initLNC() { + int i = 0x0; + lnc = kmalloc(sizeof(struct lncInfo),-2); + + lnc->rap = 0x1000 + PCNET_RAP; + lnc->rdp = 0x1000 + PCNET_RDP; + lnc->bdp = 0x1000 + PCNET_BDP; + + lnc->nic.ic = probe(lnc); + if ((lnc->nic.ic > 0) && (lnc->nic.ic >= PCnet_32)) { + lnc->nic.ident = NE2100; + lnc->nic.memMode = DMA_FIXED; + + lnc->nrdre = NRDRE; + lnc->ntdre = NTDRE; + + /* Extract MAC address from PROM */ + for (i = 0; i < ETHER_ADDR_LEN; i++) { + lnc->arpcom.ac_enaddr[i] = inportByte(0x1000 + i); + kprintf("[0x%X]",lnc->arpcom.ac_enaddr[i]); + } + } + else { + kprintf("LNC Init Error\n"); + return; + } + lncAttach(lnc,0); + writeCsr(lnc, CSR3, 0); + writeCsr(lnc, CSR0, INIT); + for (i = 0; i < 1000; i++) + if (readCsr(lnc, CSR0) & IDON) + break; + + if (readCsr(lnc, CSR0) & IDON) { + writeCsr(lnc, CSR0, STRT | INEA); + setVector(_lncInt,mVec+9, (dInt + dPresent + dDpl3)); + enableIrq(9); + /* + * sc->arpcom.ac_if.if_flags |= IFF_RUNNING; + * sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; + * lnc_start(&sc->arpcom.ac_if); + */ + } + else { + kprintf("LNC init Error\n"); + return; + } + return; + } + +int probe(struct lncInfo *lnc) { + uInt32 chipId = 0x0; + int type = 0x0; + + if ((type = lanceProbe(lnc))) { + chipId = readCsr(lnc, CSR89); + chipId <<= 16; + chipId |= readCsr(lnc, CSR88); + if (chipId & AMD_MASK) { + chipId >>= 12; + switch (chipId & PART_MASK) { + case Am79C960: + return(PCnet_ISA); + case Am79C961: + return (PCnet_ISAplus); + case Am79C961A: + return (PCnet_ISA_II); + case Am79C965: + return (PCnet_32); + case Am79C970: + return (PCnet_PCI); + case Am79C970A: + return (PCnet_PCI_II); + case Am79C971: + return (PCnet_FAST); + case Am79C972: + case Am79C973: + return (PCnet_FASTplus); + case Am79C978: + return (PCnet_Home); + default: + break; + } + } + } + return (type); + } + +int lanceProbe(struct lncInfo *lnc) { + writeCsr(lnc, CSR0, STOP); + if ((inportWord(lnc->rdp) & STOP) && !(readCsr(lnc, CSR3))) { + writeCsr(lnc, CSR0, INEA); + if (readCsr(lnc, CSR0) & INEA) { + return(C_LANCE); + } + else { + return(LANCE); + } + } + else { + return(UNKNOWN); + } + } + +void lncInt() { + uInt16 csr0 = 0x0; + while ((csr0 = inportWord(lnc->rdp)) & INTR) { + outportWord(lnc->rdp, csr0); + kprintf("CSR0: [0x%X]\n",csr0); + if (csr0 & ERR) { + kprintf("Error: [0x%X]\n",csr0); + } + if (csr0 & RINT) { + kprintf("RINT\n"); + } + if (csr0 & TINT) { + kprintf("TINT\n"); + } + } + kprintf("Finished!!!\n"); + outportByte(0x20,0x20); + return; + } + +asm( + ".global _lncInt \n" + "_lncInt : \n" + + " pusha \n" /* Save all registers */ + " pushw %ds \n" /* Set up the data segment */ + " pushw %es \n" + " pushw %ss \n" /* Note that ss is always valid */ + " pushw %ss \n" + " popw %ds \n" + " popw %es \n" + " call lncInt \n" + " popw %es \n" + " popw %ds \n" /* Restore registers */ + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +int lncAttach(struct lncInfo *lnc,int unit) { + int lncMemSize = 0x0; + + lncMemSize = ((NDESC(lnc->nrdre) + NDESC(lnc->ntdre)) * sizeof(struct hostRingEntry)); + + if (lnc->nic.memMode != SHMEM) + lncMemSize += sizeof(struct initBlock) + (sizeof(struct mds) * (NDESC(lnc->nrdre) + NDESC(lnc->ntdre))) + MEM_SLEW; + + if (lnc->nic.memMode == DMA_FIXED) + lncMemSize += (NDESC(lnc->nrdre) * RECVBUFSIZE) + (NDESC(lnc->ntdre) * TRANSBUFSIZE); + + if (lnc->nic.memMode != SHMEM) { + if (lnc->nic.ic < PCnet_32) { + /* ISA based cards */ + kprintf("ISA Board\n"); + /* sc->recv_ring = contigmalloc(lnc_mem_size, M_DEVBUF, M_NOWAIT,0ul, 0xfffffful, 4ul, 0x1000000); */ + } + else { + /* + * For now it still needs to be below 16MB because the + * descriptor's can only hold 16 bit addresses. + */ + /* sc->recv_ring = contigmalloc(lnc_mem_size, M_DEVBUF, M_NOWAIT,0ul, 0xfffffful, 4ul, 0x1000000); */ + lnc->recvRing = kmalloc(lncMemSize,-2); + kprintf("PCI Board\n"); + } + } + + if (!lnc->recvRing) { + kprintf("lnc%d: Couldn't allocate memory for NIC\n", unit); + return (0); + } + + lnc->nic.mode = NORMAL; + + /* Fill in arpcom structure entries */ + /* + lnc->arpcom.ac_if.if_softc = sc; + lnc->arpcom.ac_if.if_name = lncdriver.name; + lnc->arpcom.ac_if.if_unit = unit; + lnc->arpcom.ac_if.if_mtu = ETHERMTU; + lnc->arpcom.ac_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + lnc->arpcom.ac_if.if_timer = 0; + lnc->arpcom.ac_if.if_output = ether_output; + lnc->arpcom.ac_if.if_start = lnc_start; + lnc->arpcom.ac_if.if_ioctl = lnc_ioctl; + lnc->arpcom.ac_if.if_watchdog = lnc_watchdog; + lnc->arpcom.ac_if.if_init = lnc_init; + lnc->arpcom.ac_if.if_type = IFT_ETHER; + lnc->arpcom.ac_if.if_addrlen = ETHER_ADDR_LEN; + lnc->arpcom.ac_if.if_hdrlen = ETHER_HDR_LEN; + lnc->arpcom.ac_if.if_snd.ifq_maxlen = IFQ_MAXLEN; + */ + /* ether_ifattach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED); */ + + kprintf("lnc%d: ", unit); + if (lnc->nic.ic == LANCE || lnc->nic.ic == C_LANCE) + kprintf("%s (%s)",nicIdent[lnc->nic.ident], icIdent[lnc->nic.ic]); + else + kprintf("%s", icIdent[lnc->nic.ic]); + kprintf(" address 0x%X\n", lnc->arpcom.ac_enaddr); + return(1); + } + +/*** + END + ***/ + diff --git a/pci/pci.c b/pci/pci.c new file mode 100644 index 0000000..ac4bae7 --- /dev/null +++ b/pci/pci.c @@ -0,0 +1,344 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +const struct { + uInt8 baseClass; + uInt8 subClass; + uInt8 interface; + const char* name; + } pciClasses[] = { + { 0x00, 0x00, 0x00, "Undefined" }, + { 0x00, 0x01, 0x00, "VGA" }, + + { 0x01, 0x00, 0x00, "SCSI" }, + { 0x01, 0x01, 0x00, "IDE" }, + { 0x01, 0x01, 0x8A, "IDE" }, + { 0x01, 0x02, 0x00, "Floppy" }, + { 0x01, 0x03, 0x00, "IPI" }, + { 0x01, 0x04, 0x00, "RAID" }, + { 0x01, 0x80, 0x00, "Other" }, + + { 0x02, 0x00, 0x00, "Ethernet" }, + { 0x02, 0x01, 0x00, "Token Ring" }, + { 0x02, 0x02, 0x00, "FDDI" }, + { 0x02, 0x03, 0x00, "ATM" }, + { 0x02, 0x04, 0x00, "ISDN" }, + { 0x02, 0x80, 0x00, "Other" }, + + { 0x03, 0x00, 0x00, "VGA" }, + { 0x03, 0x00, 0x01, "VGA+8514" }, + { 0x03, 0x01, 0x00, "XGA" }, + { 0x03, 0x02, 0x00, "3D" }, + { 0x03, 0x80, 0x00, "VGA Other" }, + + { 0x04, 0x00, 0x00, "Video" }, + { 0x04, 0x01, 0x00, "Audio" }, + { 0x04, 0x02, 0x00, "Telephony" }, + { 0x04, 0x80, 0x00, "Other" }, + + { 0x05, 0x00, 0x00, "RAM" }, + { 0x05, 0x01, 0x00, "Flash" }, + { 0x05, 0x80, 0x00, "Other" }, + + { 0x06, 0x00, 0x00, "PCI to HOST" }, + { 0x06, 0x01, 0x00, "PCI to ISA" }, + { 0x06, 0x02, 0x00, "PCI to EISA" }, + { 0x06, 0x03, 0x00, "PCI to MCA" }, + { 0x06, 0x04, 0x00, "PCI to PCI" }, + { 0x06, 0x04, 0x01, "PCI to PCI (Subtractive Decode)" }, + { 0x06, 0x05, 0x00, "PCI to PCMCIA" }, + { 0x06, 0x06, 0x00, "PCI to NuBUS" }, + { 0x06, 0x07, 0x00, "PCI to Cardbus" }, + { 0x06, 0x08, 0x00, "PCI to RACEway" }, + { 0x06, 0x09, 0x00, "PCI to PCI" }, + { 0x06, 0x0A, 0x00, "PCI to InfiBand" }, + { 0x06, 0x80, 0x00, "PCI to Other" }, + + { 0x07, 0x00, 0x00, "Serial" }, + { 0x07, 0x00, 0x01, "Serial - 16450" }, + { 0x07, 0x00, 0x02, "Serial - 16550" }, + { 0x07, 0x00, 0x03, "Serial - 16650" }, + { 0x07, 0x00, 0x04, "Serial - 16750" }, + { 0x07, 0x00, 0x05, "Serial - 16850" }, + { 0x07, 0x00, 0x06, "Serial - 16950" }, + { 0x07, 0x01, 0x00, "Parallel" }, + { 0x07, 0x01, 0x01, "Parallel - BiDir" }, + { 0x07, 0x01, 0x02, "Parallel - ECP" }, + { 0x07, 0x01, 0x03, "Parallel - IEEE1284" }, + { 0x07, 0x01, 0xFE, "Parallel - IEEE1284 Target" }, + { 0x07, 0x02, 0x00, "Multiport Serial" }, + { 0x07, 0x03, 0x00, "Hayes Compatible Modem" }, + { 0x07, 0x03, 0x01, "Hayes Compatible Modem, 16450" }, + { 0x07, 0x03, 0x02, "Hayes Compatible Modem, 16550" }, + { 0x07, 0x03, 0x03, "Hayes Compatible Modem, 16650" }, + { 0x07, 0x03, 0x04, "Hayes Compatible Modem, 16750" }, + { 0x07, 0x80, 0x00, "Other" }, + + { 0x08, 0x00, 0x00, "PIC" }, + { 0x08, 0x00, 0x01, "ISA PIC" }, + { 0x08, 0x00, 0x02, "EISA PIC" }, + { 0x08, 0x00, 0x10, "I/O APIC" }, + { 0x08, 0x00, 0x20, "I/O(x) APIC" }, + { 0x08, 0x01, 0x00, "DMA" }, + { 0x08, 0x01, 0x01, "ISA DMA" }, + { 0x08, 0x01, 0x02, "EISA DMA" }, + { 0x08, 0x02, 0x00, "Timer" }, + { 0x08, 0x02, 0x01, "ISA Timer" }, + { 0x08, 0x02, 0x02, "EISA Timer" }, + { 0x08, 0x03, 0x00, "RTC" }, + { 0x08, 0x03, 0x00, "ISA RTC" }, + { 0x08, 0x03, 0x00, "Hot-Plug" }, + { 0x08, 0x80, 0x00, "Other" }, + + { 0x09, 0x00, 0x00, "Keyboard" }, + { 0x09, 0x01, 0x00, "Pen" }, + { 0x09, 0x02, 0x00, "Mouse" }, + { 0x09, 0x03, 0x00, "Scanner" }, + { 0x09, 0x04, 0x00, "Game Port" }, + { 0x09, 0x80, 0x00, "Other" }, + + { 0x0a, 0x00, 0x00, "Generic" }, + { 0x0a, 0x80, 0x00, "Other" }, + + { 0x0b, 0x00, 0x00, "386" }, + { 0x0b, 0x01, 0x00, "486" }, + { 0x0b, 0x02, 0x00, "Pentium" }, + { 0x0b, 0x03, 0x00, "PentiumPro" }, + { 0x0b, 0x10, 0x00, "DEC Alpha" }, + { 0x0b, 0x20, 0x00, "PowerPC" }, + { 0x0b, 0x30, 0x00, "MIPS" }, + { 0x0b, 0x40, 0x00, "Coprocessor" }, + { 0x0b, 0x80, 0x00, "Other" }, + + { 0x0c, 0x00, 0x00, "FireWire" }, + { 0x0c, 0x00, 0x10, "OHCI FireWire" }, + { 0x0c, 0x01, 0x00, "Access.bus" }, + { 0x0c, 0x02, 0x00, "SSA" }, + { 0x0c, 0x03, 0x00, "USB (UHCI)" }, + { 0x0c, 0x03, 0x10, "USB (OHCI)" }, + { 0x0c, 0x03, 0x80, "USB" }, + { 0x0c, 0x03, 0xFE, "USB Device" }, + { 0x0c, 0x04, 0x00, "Fiber" }, + { 0x0c, 0x05, 0x00, "SMBus Controller" }, + { 0x0c, 0x06, 0x00, "InfiniBand" }, + { 0x0c, 0x80, 0x00, "Other" }, + + { 0x0d, 0x00, 0x00, "iRDA" }, + { 0x0d, 0x01, 0x00, "Consumer IR" }, + { 0x0d, 0x10, 0x00, "RF" }, + { 0x0d, 0x80, 0x00, "Other" }, + + { 0x0e, 0x00, 0x00, "I2O" }, + { 0x0e, 0x80, 0x00, "Other" }, + + { 0x0f, 0x01, 0x00, "TV" }, + { 0x0f, 0x02, 0x00, "Audio" }, + { 0x0f, 0x03, 0x00, "Voice" }, + { 0x0f, 0x04, 0x00, "Data" }, + { 0x0f, 0x80, 0x00, "Other" }, + + { 0x10, 0x00, 0x00, "Network" }, + { 0x10, 0x10, 0x00, "Entertainment" }, + { 0x10, 0x80, 0x00, "Other" }, + + { 0x11, 0x00, 0x00, "DPIO Modules" }, + { 0x11, 0x01, 0x00, "Performance Counters" }, + { 0x11, 0x10, 0x00, "Comm Sync, Time+Frequency Measurement" }, + { 0x11, 0x80, 0x00, "Other" }, + + }; + +uInt32 pciRead(int bus,int dev,int func,int reg,int bytes) { + uInt16 base; + + union { + struct confadd c; + uInt32 n; + } u; + + u.n = 0; + u.c.enable = 1; + u.c.rsvd = 0; + u.c.bus = bus; + u.c.dev = dev; + u.c.func = func; + u.c.reg = reg & 0xFC; + + outportDWord(0xCF8, u.n); + + base = 0xCFC + (reg & 0x03); + + switch(bytes){ + case 1: return(inportByte(base)); + case 2: return(inportWord(base)); + case 4: return(inportDWord(base)); + default: return 0; + } + } + +void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes) { + uInt16 base; + + union { + struct confadd c; + uInt32 n; + } u; + + u.n = 0; + u.c.enable = 1; + u.c.rsvd = 0; + u.c.bus = bus; + u.c.dev = dev; + u.c.func = func; + u.c.reg = reg & 0xFC; + + base = 0xCFC + (reg & 0x03); + outportDWord(0xCF8, u.n); + switch(bytes){ + case 1: outportByte(base, (uInt8) v); break; + case 2: outportWord(base, (uInt16) v); break; + case 4: outportDWord(base, v); break; + } + } + + +bool pciProbe(int bus, int dev, int func,struct pciConfig *cfg) { + uInt32 *word = (uInt32 *) cfg; + uInt32 v; + int i; + for(i=0;i<4;i++) { + word[i] = pciRead(bus,dev,func,4*i,4); + } + if(cfg->vendorId == 0xffff) return FALSE; + if(cfg->vendorId == 0x0) return FALSE; /* Quick Hack */ + + cfg->bus = bus; + cfg->dev = dev; + cfg->func = func; + cfg->subsysVendor = pciRead(bus, dev, func, 0x2c, 2); + cfg->subsys = pciRead(bus, dev, func, 0x2e, 2); + kprintf("Device Info: /bus/pci/%d/%d/%d\n",bus,dev,func); + kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",cfg->vendorId,cfg->deviceId,cfg->baseClass,cfg->subClass,cfg->interface); + kprintf(" * Status: %X Command: %X BIST/Type/Lat/CLS: %X/%X/%X/%X\n",cfg->status, cfg->command, cfg->bist, cfg->headerType,cfg->latencyTimer, cfg->cacheLineSize); + switch(cfg->headerType & 0x7F){ + case 0: /* normal device */ + for(i=0;i<6;i++) { + v = pciRead(bus,dev,func,i*4 + 0x10, 4); + if(v) { + int v2; + pciWrite(bus,dev,func,i*4 + 0x10, 0xffffffff, 4); + v2 = pciRead(bus,dev,func,i*4+0x10, 4) & 0xfffffff0; + pciWrite(bus,dev,func,i*4 + 0x10, v, 4); + v2 = 1 + ~v2; + if(v & 1) { + cfg->base[i] = v & 0xffff; + cfg->size[i] = v2 & 0xffff; + } + else { + cfg->base[i] = v; + cfg->size[i] = v2; + } + } + else { + cfg->base[i] = 0; + cfg->size[i] = 0; + } + } + v = pciRead(bus,dev,func,0x3c,1); + cfg->irq = (v == 0xff ? 0 : v); + break; + case 1: + kprintf(" * PCI <-> PCI Bridge\n"); + break; + default: + kprintf(" * Unknown Header Type\n"); + break; + } + + return(TRUE); + } + +int pci_init() { + uInt16 bus,dev,func; + int i = 0x0; + struct pciConfig pcfg; + for (bus = 0x0; bus < 0x2; bus++) { /* 255 */ + for (dev = 0; dev < 32; dev++) { + for (func = 0; func < 8; func++) { + if (pciProbe(bus, dev, func, &pcfg) == TRUE) { + /* kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",pcfg.vendorId,pcfg.deviceId,pcfg.baseClass,pcfg.subClass,pcfg.interface); */ + for (i=0x0;i +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + } + +extern "C" { +void sdeTestThread() { +// uInt32 count, i = 0x0; + uInt8 r, g, b; + ogSurface *screen = 0x0; + ogPoint2d points[4]; + ogRGBA8 colours[4]; + r = g = b = 0; + while (screen == 0x0) { + screen = (ogDisplay_UbixOS *)systemVitals->screen; + } + while (!screen->ogAvail()); + + points[0].x = screen->ogGetMaxX() - 150; + points[0].y = 0; + points[1].x = screen->ogGetMaxX(); + points[1].y = 0; + points[2].x = screen->ogGetMaxX(); + points[2].y = 150; + points[3].x = screen->ogGetMaxX() - 250; + points[3].y = 250; + + colours[0].red = 255; + colours[0].green = 0; + colours[0].blue = 0; + colours[0].alpha = 255; + colours[1].red = 0; + colours[1].green = 255; + colours[1].blue = 128; + colours[1].alpha = 255; + colours[2].red = 128; + colours[2].green = 255; + colours[2].blue = 128; + colours[2].alpha = 255; + colours[3].red = 63; + colours[3].green = 63; + colours[3].blue = 63; + colours[3].alpha = 255; + screen->ogSetAntiAliasing(true); + + while (true) { +#if 0 + for (count = 150; count > 0; count--) { + screen->Line(screen->GetMaxX() / 2, screen->GetMaxY() / 2, + screen->GetMaxX(), count*8, + screen->RGB(r, g, b)); + screen->FillCircle(screen->GetMaxX() - 50, 50, count, + screen->RGB(r, g, b)); + +// screen->FillRect(screen->GetMaxX() - 50 - count, count, +// screen->GetMaxX() - count, 100 - count, +// screen->RGB(r, g, b)); + r -= 8; + g += 8; + b -= 8; + } // for +#endif + screen->ogFillGouraudPolygon(4, points, colours); + //kprintf("colours(0)[0x%X]\n",colours[0]); + colours[0].red -= 8; + colours[0].green += 8; + colours[0].blue -= 8; + colours[1].red += 8; + colours[1].green += 8; + colours[1].blue -= 8; + colours[2].red += 8; + colours[2].green -= 8; + colours[2].blue += 8; + colours[3].red += 8; + colours[3].green += 8; + colours[3].blue += 8; + + } // while + +} // sdeTestThread + +} + +/*** + END + ***/ + diff --git a/sde/main.cc b/sde/main.cc new file mode 100644 index 0000000..3856781 --- /dev/null +++ b/sde/main.cc @@ -0,0 +1,150 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:16 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:36 reddawg + no message + + Revision 1.3 2004/11/16 18:38:27 reddawg + Oh Man + + Revision 1.2 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.1.1.1 2004/04/15 12:07:16 reddawg + UbixOS v1.0 + + Revision 1.29 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +extern "C" { + #include + #include + #include + #include + #include + } + +#include +#include +#include +#include + +extern "C" void sdeThread() { + ogSurface *screen = new ogDisplay_UbixOS(); + struct sdeWindows *tmp = 0x0; + ogSurface *buf = 0x0; + ogBitFont * font = new ogBitFont(); + + font->Load("ROM8X14.DPF",0); + font->SetFGColor(255, 255, 255, 255); + font->SetBGColor(0, 0, 0, 255); + + printOff = 0x1; + + screen->ogCreate(800,600,OG_PIXFMT_16BPP); + screen->ogClear(screen->ogPack(122,140,163)); + + systemVitals->screen = screen; + systemVitals->font = font; + + ogprintOff = (int)0x0; + + screen->ogSetAntiAliasing(false); + + while (1) { + for (tmp = windows;tmp;tmp=tmp->next) { + switch (tmp->status) { + case registerWindow: + buf = (ogSurface *)tmp->buf; + buf->buffer = (void *)vmmMapFromTask(tmp->pid,buf->buffer,buf->bSize); + if (buf->buffer == 0x0) { + kprintf("Error: buf->buffer\n"); + while (1); + } + buf->lineOfs = (uInt32 *)vmmMapFromTask(tmp->pid,buf->lineOfs,buf->lSize); + if (buf->lineOfs == 0x0) { + kprintf("Error: buf->lineOfs\n"); + while (1); + } + tmp->status = windowReady; + //kprintf("Window Registered!\n"); + break; + case drawWindow: + buf = (ogSurface *)tmp->buf; + screen->ogCopyBuf(screen->ogGetMaxX() - buf->ogGetMaxX(), + screen->ogGetMaxY() - buf->ogGetMaxY(), *buf,0, 0, + buf->ogGetMaxX(), buf->ogGetMaxY()); + tmp->status = windowReady; + //kprintf("Draw Window Routines Here\n"); + break; + case killWindow: + //kprintf("Killed Window\n"); + if (tmp->next != 0x0) { + tmp->next->prev = tmp->prev; + if (tmp->prev != 0x0) + tmp->prev->next = tmp->next; + } + else if (tmp->prev != 0x0) { + tmp->prev->next = tmp->next; + if (tmp->next != 0x0) + tmp->next->prev = tmp->prev; + } + else { + windows = 0x0; + } + vmmUnmapPages(buf->buffer,buf->bSize); + vmmUnmapPages(buf->lineOfs,buf->lSize); + // kfree(tmp->buf); + kfree(tmp); + tmp = 0x0; + break; + default: + break; + } + } + //sched_yield(); + } + } + +/*** + END + ***/ + diff --git a/sde/ogDisplay_UbixOS.cc b/sde/ogDisplay_UbixOS.cc new file mode 100644 index 0000000..1bbc1e3 --- /dev/null +++ b/sde/ogDisplay_UbixOS.cc @@ -0,0 +1,340 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:37 reddawg + no message + + Revision 1.3 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + Revision 1.2 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.20 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + } + +/* + * + * ogDisplay methods + * + */ + +void +initVESAMode(uInt16 mode) { + //kprintf("Pre-initVESAMode\n"); + biosCall(0x10,0x4F02,mode,0x0,0x0,0x0,0x0,0x0,0x0); + //kprintf("Post-initVESAMode\n"); + return; +} + +ogDisplay_UbixOS::ogDisplay_UbixOS(void) { + pages[0] = pages[1] = NULL; + activePage = visualPage = 0; + pal = new ogRGBA8[256]; + attributes = new ogAttributes(); + + VESAInfo = (ogVESAInfo *)0x11000; + modeInfo = (ogModeInfo *)0x11200; + GetVESAInfo(); + return; +} // ogDisplay_UbixOS::ogDisplay_UbixOS + +void +ogDisplay_UbixOS::GetModeInfo(uInt16 mode) { + //kprintf("Pre-getModeInfo\n"); + biosCall(0x10,0x4F01,0x0,mode,0x0,0x0,0x0,0x1120,0x0); + //kprintf("Post-getModeInfo\n"); + return; +} // ogDisplay_UbixOS::GetModeInfo + +void +ogDisplay_UbixOS::GetVESAInfo(void) { + VESAInfo->VBESignature[0] = 'V'; // First off initialize the structure. + VESAInfo->VBESignature[1] = 'B'; + VESAInfo->VBESignature[2] = 'E'; + VESAInfo->VBESignature[3] = '2'; + //kprintf("Pre-getVESAInfo\n"); + biosCall(0x10,0x4F00,0x0,0x0,0x0,0x0,0x0,0x1100,0x0); + //kprintf("Post-getVESAInfo\n"); + return; + } // ogDisplay_UbixOS::GetVESAInfo + +uInt16 +ogDisplay_UbixOS::FindMode(uInt32 _xRes, uInt32 _yRes, uInt32 _BPP) { + uInt16 mode; + + if ((_xRes == 320) && (_yRes == 200) && (_BPP == 8)) return 0x13; + +// if ((VESAInfo==NULL) || (VESAInfo->videoModePtr==NULL)) return 0; + if (modeInfo == NULL) return 0; + + for (mode = 0x100; mode < 0x1FF; mode++) { + GetModeInfo(mode); + if ((modeInfo->xRes >= _xRes) && (modeInfo->yRes >= _yRes) && + (modeInfo->bitsPerPixel == _BPP)) + return mode; + } + + return 0; +} // ogDisplay_UbixOS::FindMode + +void ogDisplay_UbixOS::SetMode(uInt16 mode) { + + uInt32 size = 0x0, count = 0x0, i = 0x0; + + if (mode == 0x13) { + + xRes = 320; + yRes = 200; + maxX = 319; + maxY = 199; + BPP = 8; + bytesPerPix = 1; + + redFieldPosition = 0; + greenFieldPosition = 0; + blueFieldPosition = 0; + alphaFieldPosition = 0; + + redShifter = 0; + greenShifter = 0; + blueShifter = 0; + alphaFieldPosition = 0; + + // UBU, THIS IS NULL BECAUSE WE DON'T EVER USE 320x200x256c! + // THIS COMMENT WILL COME BACK TO BITE YOU ON THE ASS + buffer = NULL; + + } else { + buffer = NULL; + mode |= 0x4000; // attempt lfb + GetModeInfo(mode); + if (modeInfo->physBasePtr == 0) return; + buffer = (void *)modeInfo->physBasePtr; + size = (modeInfo->yRes*modeInfo->bytesPerLine+4095); + + xRes = modeInfo->bytesPerLine; + yRes = modeInfo->yRes; + maxX = modeInfo->xRes-1; + maxY = yRes-1; + + BPP = modeInfo->bitsPerPixel; + bytesPerPix = (BPP + 7) >> 3; + + redFieldPosition = modeInfo->redFieldPosition; + greenFieldPosition = modeInfo->greenFieldPosition; + blueFieldPosition = modeInfo->blueFieldPosition; + alphaFieldPosition = modeInfo->alphaFieldPosition; + + if (bytesPerPix == 4) { + modeInfo->alphaMaskSize = 8; + while ((alphaFieldPosition == redFieldPosition) || + (alphaFieldPosition == greenFieldPosition) || + (alphaFieldPosition == blueFieldPosition)) + alphaFieldPosition += 8; + } // if + + redShifter = 8-modeInfo->redMaskSize; + greenShifter = 8-modeInfo->greenMaskSize; + blueShifter = 8-modeInfo->blueMaskSize; + alphaShifter = 8-modeInfo->alphaMaskSize; + + if (modeInfo->alphaMaskSize != 0) + alphaMasker = ~(OG_MASKS[modeInfo->alphaMaskSize] << alphaFieldPosition); + else + alphaMasker = ~0; + + } // else not mode 0x13 + + printOff = 0; + for (i = 0x0; i < ((size)/4096); i++) { + if ((vmm_remapPage(modeInfo->physBasePtr + (i * 0x1000),modeInfo->physBasePtr + (i * 0x1000),KERNEL_PAGE_DEFAULT)) == 0x0) + kpanic("Error: vmm_remapPage failed\n"); + } // for i + + owner = this; + dataState = ogAliasing; + + initVESAMode(mode); + + if ((lineOfs != NULL) && (lSize != 0)) delete [] lineOfs; + lSize = yRes*sizeof(uInt32); + lineOfs = new uInt32[yRes];; + if (lineOfs == NULL) return; + + lineOfs[0] = 0; + for (count = 1; count < yRes; count++) + lineOfs[count] = lineOfs[count-1]+xRes; + + if (1 == bytesPerPix) { + pixFmtID = 0x08080808; + } else { + pixFmtID = (redFieldPosition) | + (greenFieldPosition << 8) | + (blueFieldPosition << 16) | + (alphaFieldPosition << 24); + } // else + + ogSetAntiAliasing(BPP > 8); + if (pal == NULL) pal = new ogRGBA8[256]; + ogSetPalette(DEFAULT_PALETTE); + + return; +} // ogDisplay_UbixOS::SetMode + +void +ogDisplay_UbixOS::ogSetPalette(const ogRGBA8 newPal[256]) { + ogSurface::ogSetPalette(newPal); + SetPal(); + return; +} // ogDisplay_UbixOS::ogSetPalette + +void ogDisplay_UbixOS::SetPal(void) { + if (bytesPerPix != 1) return; + outportByte(0x3c8,0); + for (uInt32 c = 0; c < 256; c++) { + outportByte(0x3c9, pal[c].red >> 2); + outportByte(0x3c9, pal[c].green >> 2); + outportByte(0x3c9, pal[c].blue >> 2); + } // for + return; +} // ogDisplay_UbixOS::SetPal + +bool +ogDisplay_UbixOS::ogAlias(ogSurface& SrcObject, uInt32 x1, + uInt32 y1, uInt32 x2, uInt32 y2) { + ogSetLastError(ogNoAliasing); + return false; +} // ogDisplay_UbixOS::ogAlias + +bool +ogDisplay_UbixOS::ogCreate(uInt32 _xRes, uInt32 _yRes,ogPixelFmt _pixFormat) { + uInt16 mode; + mode = 0x114; // was 0x111 + SetMode(mode); + /* + mode = FindMode(_xRes, _yRes, _pixFormat.BPP); + if ((mode == 0) && ((_pixFormat.BPP==24) || (_pixFormat.BPP==32))) { + if (_pixFormat.BPP==24) _pixFormat.BPP=32; else _pixFormat.BPP=24; + mode=FindMode(_xRes,_yRes,_pixFormat.BPP); + } // if + if (mode!=0) SetMode(mode); + */ + return (mode!=0); +} // ogDisplay_UbixOS::ogCreate + +bool +ogDisplay_UbixOS::ogClone(ogSurface& SrcObject) { + ogSetLastError(ogNoCloning); + return false; +} // ogDisplay_UbixOS::ogClone + +void +ogDisplay_UbixOS::ogCopyPalette(ogSurface& SrcObject) { + ogSurface::ogCopyPalette(SrcObject); + SetPal(); + return; +} // ogDisplay_UbixOS::ogCopyPalette + +bool +ogDisplay_UbixOS::ogLoadPalette(const char *palfile) { + bool result; + if ((result = ogSurface::ogLoadPalette(palfile))==true) SetPal(); + return result; +} // ogDisplay_UbixOS::ogLoadPalette + +void +ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue); + outportByte(0x3c8, colour); + outportByte(0x3c9, red >> 2); + outportByte(0x3c9, green >> 2); + outportByte(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::ogSetPalette + +void +ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, + uInt8 blue, uInt8 alpha) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue, alpha); + outportByte(0x3c8, colour); + outportByte(0x3c9, red >> 2); + outportByte(0x3c9, green >> 2); + outportByte(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::ogSetPalette + +ogDisplay_UbixOS::~ogDisplay_UbixOS(void) { + delete attributes; + delete pal; +//mji delete VESAInfo; +//mji delete modeInfo; + return; +} // ogDisplay_UbixOS::~ogDisplay_UbixOS + +/*** + END + ***/ + diff --git a/sde/sde.cc b/sde/sde.cc new file mode 100644 index 0000000..af3844a --- /dev/null +++ b/sde/sde.cc @@ -0,0 +1,159 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:37 reddawg + no message + + Revision 1.3 2004/08/21 23:47:50 reddawg + *** empty log message *** + + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.12 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + #include +} +#include + +struct sdeWindows *windows = 0x0; + +extern "C" void sysSDE(uInt32 cmd,void *ptr) { + ogSurface *newBuf = 0x0; + ogSurface *oldBuf = (ogSurface *)ptr; + struct sdeWindows *tmp = 0x0; + + for (tmp=windows;tmp;tmp=tmp->next) { + if (tmp->pid == (int)_current->id) + break; + } + + if (tmp != 0x0) { + while (tmp->status != windowReady) + asm("hlt"); + //sched_yield(); + } + else if (tmp == 0x0 && cmd != registerWindow) { + kprintf("Invalid Window\n"); + return; + } + + switch (cmd) { + case drawWindow: + tmp->status = drawWindow; + while (tmp->status != windowReady) { + //sched(); + //asm("hlt"); + } + break; + case killWindow: + tmp->status = killWindow; + break; + case registerWindow: + if (oldBuf->buffer != 0x0) { + newBuf = new ogSurface(); + newBuf->version = oldBuf->version; + newBuf->buffer = oldBuf->buffer; + newBuf->owner = oldBuf->owner; + newBuf->lineOfs = oldBuf->lineOfs; + newBuf->pal = oldBuf->pal; + newBuf->attributes = oldBuf->attributes; + newBuf->xRes = oldBuf->xRes; + newBuf->yRes = oldBuf->yRes; + newBuf->maxX = oldBuf->maxX; + newBuf->maxY = oldBuf->maxY; + newBuf->bSize = oldBuf->bSize; + newBuf->lSize = oldBuf->lSize; + newBuf->BPP = oldBuf->BPP; + newBuf->bytesPerPix = oldBuf->bytesPerPix; + newBuf->pixFmtID = oldBuf->pixFmtID; + newBuf->redFieldPosition = oldBuf->redFieldPosition; + newBuf->greenFieldPosition = oldBuf->greenFieldPosition; + newBuf->blueFieldPosition = oldBuf->blueFieldPosition; + newBuf->alphaFieldPosition = oldBuf->alphaFieldPosition; + newBuf->redShifter = oldBuf->redShifter; + newBuf->greenShifter = oldBuf->greenShifter; + newBuf->blueShifter = oldBuf->blueShifter; + newBuf->alphaShifter = oldBuf->alphaShifter; + newBuf->lastError = oldBuf->lastError; + newBuf->dataState = oldBuf->dataState; + tmp = (struct sdeWindows *)kmalloc(sizeof(struct sdeWindows)); + tmp->buf = newBuf; + tmp->status = registerWindow; + tmp->pid = _current->id; + tmp->prev = 0x0; + if (windows == 0x0) { + windows = tmp; + tmp->next = 0x0; + } + else { + tmp->next = windows; + windows->prev = tmp; + windows = tmp; + } + } + else { + kprintf("Invalid Window\n"); + } + break; + default: + kprintf("Invalid SDE Command [0x%X]\n",ptr); + break; + } + return; + } + +/*** + END + ***/ + diff --git a/sys/Makefile b/sys/Makefile new file mode 100644 index 0000000..802f90d --- /dev/null +++ b/sys/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = dma.o idt.o io.o video.o device.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/sys/device.c b/sys/device.c new file mode 100644 index 0000000..06cf2d6 --- /dev/null +++ b/sys/device.c @@ -0,0 +1,153 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +/* Linked list of drivers loaded in the system accessable by the subsystem only */ +static struct device_node *devices = 0x0; +static spinLock_t deviceSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: int deviceAdd(int minor,char type,struct device_interface *devInfo); + + Description: This will add a device to the system + + Notes: + + 05/19/2004 - Improving Upon the spec + +*****************************************************************************************/ +int device_add(int minor,char type,struct device_interface *devInfo) { + struct device_node *tmpDev = 0x0; + + + tmpDev = (struct device_node *)kmalloc(sizeof(struct device_node)); + if(tmpDev == NULL) + kprintf("Error Adding Device: memory failure\n"); + + tmpDev->prev = 0x0; + tmpDev->minor = minor; + tmpDev->type = type; + tmpDev->devInfo = devInfo; + + spinLock(&deviceSpinLock); + tmpDev->next = devices; + devices = tmpDev; + spinUnlock(&deviceSpinLock); + + if (tmpDev->devInfo->initialized == 0x0) + return(tmpDev->devInfo->init(tmpDev)); + else + return(0x0); + } + +/***************************************************************************************** + + Function: struct device_node *deviceFind(int major,int minor); + + Description: This will find a device based on major minor + + Notes: + + 05/19/2004 - Improving Upon the spec + +*****************************************************************************************/ +struct device_node *device_find(int major,int minor) { + struct device_node *tmpDev = 0x0; + + if (major == -1) + return(-1); + + spinLock(&deviceSpinLock); + + for (tmpDev = devices;tmpDev;tmpDev=tmpDev->next) { + if ((tmpDev->devInfo->major == major) && (tmpDev->minor == minor)) { + spinUnlock(&deviceSpinLock); + return(tmpDev); + } + } + + spinUnlock(&deviceSpinLock); + return(0x0); + } + + +/******************************************************************************************** + +Function: int deviceRemove(struct *device_node); + +Description: This will remove a device based on it's pointer + +*********************************************************************************************/ +int device_remove(struct device_node *deviceToDelete) +{ +struct device_node *current, *previous; + + +current = devices; +previous=NULL; +spinLock(&deviceSpinLock); + while(current != NULL) + { + if(current==deviceToDelete) break; + else + { + previous = current; + current = current->next; + } + } + if(current == NULL) + { + spinUnlock(&deviceSpinLock); + return 1; + } + else + { + if(current == devices) + devices = devices->next; + else + previous->next = current->next; + kfree(current); + spinUnlock(&deviceSpinLock); + return 1; + } + + spinUnlock(&deviceSpinLock); +return 0x0; +} + + +/*** + END + ***/ diff --git a/sys/dma.c b/sys/dma.c new file mode 100644 index 0000000..c160947 --- /dev/null +++ b/sys/dma.c @@ -0,0 +1,75 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#define lowByte(x) (x & 0x00FF) +#define highByte(x) ((x & 0xFF00) >> 8) + +static uInt8 maskReg[8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 }; +static uInt8 clearReg[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 }; +static uInt8 modeReg[8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 }; +static uInt8 addrPort[8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC }; +static uInt8 pagePort[8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A }; +static uInt8 countPort[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE }; + +void dmaXfer(uInt8 channel,uInt32 address,uInt length,uInt8 read) { + unsigned char page=0, mode=0; + unsigned int offset = 0; + if (read) { + mode = 0x48 + channel; + } + else { + mode = 0x44 + channel; + } + page = address >> 16; + offset = address & 0xFFFF; + length--; + _dmaXfer(channel, page, offset, length, mode); + } + +void _dmaXfer(uInt8 dmaChannel,uInt8 page,uInt offset,uInt length,uInt8 mode) { + //asm("cli"); + outportByte(maskReg[dmaChannel], 0x04 | dmaChannel); + outportByte(clearReg[dmaChannel], 0x00); + outportByte(modeReg[dmaChannel], mode); + outportByte(addrPort[dmaChannel], lowByte(offset)); + outportByte(addrPort[dmaChannel], highByte(offset)); + outportByte(pagePort[dmaChannel], page); + outportByte(countPort[dmaChannel], lowByte(length)); + outportByte(countPort[dmaChannel], highByte(length)); + outportByte(maskReg[dmaChannel], dmaChannel); + //asm("sti"); + } + +/*** + END + ***/ diff --git a/sys/idt.c b/sys/idt.c new file mode 100644 index 0000000..1d06fe7 --- /dev/null +++ b/sys/idt.c @@ -0,0 +1,466 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FP_TO_LINEAR(seg, off) ((void*) ((((uInt16) (seg)) << 4) + ((uInt16) (off)))) + +static ubixDescriptorTable(ubixIDT, 256) { }; + +static struct { + unsigned short limit __attribute__((packed)); + union descriptorTableUnion *idt __attribute__((packed)); + } loadidt = { + (256 * sizeof(union descriptorTableUnion) - 1), ubixIDT + }; + +/************************************************************************ + +Function: int idtInit() +Description: This function is used to enable our IDT subsystem +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int idt_init() { + int i = 0x0; + + struct tssStruct *sfTSS = (struct tssStruct *)0x6200; + struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; + + /* Set up default vector table for all possible 256 interrupts */ + + for (i = 0x0; i < 256; i++) { + setVector(intNull, i, dPresent + dInt + dDpl3); + } + + /* Load the IDT into the system */ + asm volatile( + "cli \n" + "lidt (%0) \n" /* Load the IDT */ + "pushfl \n" /* Clear the NT flag */ + "andl $0xffffbfff,(%%esp) \n" + "popfl \n" + "sti \n" + : + : "r" ((char *)&loadidt) + ); + + /* Set up the basic vectors for the reserved ints */ + setVector(_int0, 0, dPresent + dInt + dDpl0); + setVector(_int1, 1, dPresent + dInt + dDpl0); + setVector(_int2, 2, dPresent + dInt + dDpl0); + setVector(_int3, 3, dPresent + dInt + dDpl0); + setVector(_int4, 4, dPresent + dInt + dDpl0); + setVector(_int5, 5, dPresent + dInt + dDpl0); + setVector(_int6, 6, dPresent + dInt + dDpl0); + setVector(_int7,7,dPresent + dInt + dDpl0); + setTaskVector(8,dPresent + dTask + dDpl0, 0x40); + setVector(_int9, 9, dPresent + dInt + dDpl0); + setVector(_int10, 10, dPresent + dInt + dDpl0); + setVector(_int11, 11, dPresent + dInt + dDpl0); + setVector(_int12, 12, dPresent + dInt + dDpl0); + setTaskVector(13, dPresent + dTask + dDpl0, 0x38); + setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); + setVector(_sysCall, 128, dPresent + dTrap + dDpl3); + setVector(_sysCall_new, 0x81, dPresent + dTrap + dDpl3); + //setVector(_sysCallNew, 0x90, dPresent + dTrap + dDpl3); + setVector(timerInt, 0x68, (dInt + dPresent + dDpl0)); + + + gpfTSS->back_link = 0x0; + gpfTSS->esp0 = 0x0; + gpfTSS->ss0 = 0x0; + gpfTSS->esp1 = 0x0; + gpfTSS->ss1 = 0x0; + gpfTSS->esp2 = 0x0; + gpfTSS->ss2 = 0x0; + gpfTSS->cr3 = (unsigned int)kernelPageDirectory; + gpfTSS->eip = (unsigned int)&_int13; + gpfTSS->eflags = 0x206; + gpfTSS->esp = 0x1D000; + gpfTSS->ebp = 0x1D000; + gpfTSS->esi = 0x0; + gpfTSS->edi = 0x0; + gpfTSS->es = 0x10; + gpfTSS->cs = 0x08; + gpfTSS->ss = 0x10; + gpfTSS->ds = 0x10; + gpfTSS->fs = 0x10; + gpfTSS->gs = 0x10; + gpfTSS->ldt = 0x0; + gpfTSS->trace_bitmap = 0x0000; + gpfTSS->io_map = 0x8000; + + memset(sfTSS,0x0,sizeof(struct tssStruct)); + sfTSS->cr3 = (unsigned int)kernelPageDirectory; + sfTSS->eip = (unsigned int)&_int8; + sfTSS->eflags = 0x206; + sfTSS->esp = 0x1C000; + sfTSS->ebp = 0x1C000; + sfTSS->es = 0x10; + sfTSS->cs = 0x08; + sfTSS->ss = 0x10; + sfTSS->ds = 0x10; + sfTSS->fs = 0x10; + sfTSS->gs = 0x10; + sfTSS->io_map = 0x8000; + + /* Print out information for the IDT */ + kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); + + /* Return so we know all went well */ + return (0x0); + } + + +/* Sets Up IDT Vector */ +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { + unsigned short codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = (unsigned short)(((unsigned long)handler) & 0xffff); + ubixIDT[interrupt].gate.selector = codesegment; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = (unsigned short)(((unsigned long)handler) >> 16); +} + +/************************************************************************ + +Function: void setTaskVector(uInt8,uInt16,uInt8); +Description: This Function Sets Up An IDT Task Vector +Notes: + +************************************************************************/ +void +setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector) +{ + uInt16 codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = 0x0; + ubixIDT[interrupt].gate.selector = selector; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = 0x0; +} + + +/* Null Intterupt Descriptor */ +void intNull() { + kprintf("Invalid Interrupt[%i]\n",_current->id); +/* + kpanic("Invalid Interrupt[%i]\n",_current->id); + while (1); + endTask(_current->id); + sched_yield(); +*/ + } + +void _int0() { + kpanic("int0: Divide-by-Zero [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int1() { + kpanic("int1: Debug exception [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int2() { + kpanic("int2: unknown error [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int3() { + kpanic("int3: Breakpoint [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int4(){ + kpanic("int4: Overflow [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int5() { + kpanic("int5: Bounds check [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int6() { + kpanic("int6: Invalid opcode! [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int8() { + struct tssStruct *sfTSS = (struct tssStruct *)0x6200; + kpanic("int8: Double Fault! [%i]\n",_current->id); + sfTSS->cr3 = (unsigned int)kernelPageDirectory; + sfTSS->eip = (unsigned int)&_int8; + sfTSS->eflags = 0x206; + sfTSS->esp = 0x1C000; + sfTSS->ebp = 0x1C000; + sfTSS->es = 0x10; + sfTSS->cs = 0x08; + sfTSS->ss = 0x10; + sfTSS->ds = 0x10; + sfTSS->fs = 0x10; + sfTSS->gs = 0x10; + sfTSS->io_map = 0x8000; + while (1); + } + +void _int9() { + kpanic("int9: Coprocessor Segment Overrun! [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int10() { + kpanic("int10: Invalid TSS! [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int11() { + kpanic("int11: Segment Not Present! [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int12() { + kpanic("int12: Stack-Segment Fault! [%i]\n",_current->id); + endTask(_current->id); + sched_yield(); + } + +void _int13() { + uInt8 *ip = 0x0; + uInt16 *stack = 0x0, *ivt = 0x0; + uInt32 *stack32 = 0x0; + bool isOperand32 = FALSE, isAddress32 = FALSE; + struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; + + irqDisable(0x0); + + gpfTSS->eip = (unsigned int)&_int13; + gpfTSS->esp = 0x1D000; + gpfTSS->ebp = 0x1D000; + gpfTSS->eflags = 0x206; + + ip = FP_TO_LINEAR(_current->tss.cs, _current->tss.eip); + ivt = (uInt16 *) 0x0; + stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss,_current->tss.esp); + stack32 = (uInt32 *) stack; + +gpfStart: + switch (ip[0]) { + case 0xCD: /* INT n */ + switch (ip[1]) { + case 0x69: + kprintf("Exit Bios [0x%X]\n",_current->id); + _current->state = DEAD; + break; + case 0x20: + case 0x21: + kpanic("GPF OP 0x20/0x21\n"); + break; + default: + stack -= 3; + _current->tss.esp = ((_current->tss.esp & 0xffff) - 6) & 0xffff; + stack[0] = (uInt16) (_current->tss.eip + 2); + stack[1] = _current->tss.cs; stack[2] = (uInt16) _current->tss.eflags; + if (_current->oInfo.v86If) + stack[2] |= EFLAG_IF; + else + stack[2] &= ~EFLAG_IF; + _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; + _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; + break; + } + break; + case 0x66: + isOperand32 = TRUE; + ip++; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + goto gpfStart; + break; + case 0x67: + isAddress32 = TRUE; + ip++; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + goto gpfStart; + break; + case 0xF0: + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + kpanic("GPF OP 0xF0\n"); + break; + case 0x9C: + if (isOperand32 == TRUE) { + _current->tss.esp = ((_current->tss.esp & 0xffff) - 4) & 0xffff; + stack32--; + stack32[0] = _current->tss.eflags & 0xDFF; + if (_current->oInfo.v86If == TRUE) + stack32[0] |= EFLAG_IF; + else stack32[0] &= ~EFLAG_IF; + } else { + _current->tss.esp = ((_current->tss.esp & 0xffff) - 2) & 0xffff; + stack--; + + stack[0] = (uInt16) _current->tss.eflags; + if (_current->oInfo.v86If == TRUE) stack[0] |= EFLAG_IF; + else stack[0] &= ~EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + + } + break; + case 0x9D: + if (isOperand32 == TRUE) { + _current->tss.eflags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); + _current->oInfo.v86If = (stack32[0] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 4) & 0xffff; + } else { + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[0]; + _current->oInfo.v86If = (stack[0] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 2) & 0xffff; + } + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + /* kprintf("popf [0x%X]\n",_current->id); */ + break; + case 0xFA: + _current->oInfo.v86If = FALSE; + _current->tss.eflags &= ~EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->oInfo.timer = 0x1; + break; + case 0xFB: + _current->oInfo.v86If = TRUE; + _current->tss.eflags |= EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->oInfo.timer = 0x0; + /* kprintf("sti [0x%X]\n",_current->id); */ + break; + case 0xCF: + _current->tss.eip = stack[0]; + _current->tss.cs = stack[1]; + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[2]; + _current->oInfo.v86If = (stack[2] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 6) & 0xffff; + /* kprintf("iret [0x%X]\n",_current->id); */ + break; + case 0xEC: /* IN AL,DX */ + _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xED: /* IN AX,DX */ + _current->tss.eax = (_current->tss.eax & ~0xFFFF) | inportWord(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xEE: /* OUT DX,AL */ + outportByte(_current->tss.edx, _current->tss.eax & 0xFF); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xEF: + outportWord(_current->tss.edx, _current->tss.eax); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xF4: + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + default: /* something wrong */ + kprintf("NonHandled OpCode [0x%X:0x%X]\n",_current->id,ip[0]); + _current->state = DEAD; + break; + } + irqEnable(0); + while (1); + } + +/* Removed static however this is the only place it's called from */ +void mathStateRestore() { + if (_usedMath != 0x0) { + asm( + "fnsave %0" + : + : "m" (_usedMath->i387) + ); + } + if (_current->usedMath != 0x0) { + asm( + "frstor %0" + : + : "m" (_current->i387) + ); + } + else { + asm("fninit"); + _current->usedMath = 0x1; + } + + _usedMath=_current; + + //Return + } + +void _int7(); +asm( + ".globl _int7 \n" + "_int7: \n" + " pushl %eax \n" + " clts \n" + " movl _current,%eax \n" + " cmpl _usedMath,%eax \n" + " je mathDone \n" + " call mathStateRestore \n" + "mathDone: \n" + " popl %eax \n" + " iret \n" + ); + +/*** + END + ***/ diff --git a/sys/io.c b/sys/io.c new file mode 100644 index 0000000..53ceab1 --- /dev/null +++ b/sys/io.c @@ -0,0 +1,146 @@ +/***************************************************************************************** + Copyright (c) 2002-2005 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +/*! + * \brief input one byte from specified port + * + * \param port address of port for reading + * \return returns unsigned char value + * + */ +unsigned char inportByte(unsigned int port) { + unsigned char retVal; + asm volatile( + "inb %%dx,%%al" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/*! + * \brief input one word from specified port + * + * \param port address of port for reading + * \return returns unsigned short value + * + */ +unsigned short inportWord(unsigned int port) { + unsigned short retVal; + asm volatile( + "inw %%dx,%%ax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/*! + * \brief outputut one byte to specified port + * + * \param port address of port for writing + * \param value byte to output to port + * + */ +void outportByte(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/*! + * \brief outputut one byte to specified port with a delay + * + * \param port address of port for writing + * \param value byte to output to port + * + */ +void outportByteP(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx\n" + "outb %%al,$0x80\n" + : + : "d" (port), "a" (value) + ); + } + +/*! + * \brief outputut one word to specified port + * + * \param port address of port for writing + * \param value word to output to port + * + */ +void outportWord(unsigned int port,unsigned short value) { + asm volatile( + "outw %%ax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/*! + * \brief outputut one double word to specified port + * + * \param port address of port for writing + * \param value double word to output to port + * + */ +void outportDWord(unsigned int port,unsigned long value) { + asm volatile( + "outl %%eax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/*! + * \brief input one double word from specified port + * + * \param port address of port for reading + * \return returns unsigned double word value + * + */ +unsigned long inportDWord(unsigned int port) { + unsigned long retVal; + asm volatile( + "inl %%dx,%%eax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/*** + END + ***/ diff --git a/sys/video.c b/sys/video.c new file mode 100644 index 0000000..30286fb --- /dev/null +++ b/sys/video.c @@ -0,0 +1,132 @@ +/***************************************************************************************** + Copyright (c) 2002-2005,2007 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +static unsigned char *videoBuffer = (char *)0xB8000; +int printColor = defaultColor; + + +void backSpace() { + uInt32 bufferOffset = 0x0; + outportByte(0x3d4, 0x0e); + bufferOffset = inportByte(0x3d5); + bufferOffset <<= 0x8; /* Shift Address Left 8 Bits */ + outportByte(0x3d4, 0x0f); + bufferOffset += inportByte(0x3d5); + bufferOffset <<= 0x1; /* Shift Address Left 1 Bits */ + videoBuffer[bufferOffset--] = 0x20; + videoBuffer[bufferOffset--] = printColor; + videoBuffer[bufferOffset] = 0x20; + bufferOffset >>= 0x1; + tty_foreground->tty_x = (bufferOffset & 0xFF); + tty_foreground->tty_y = (bufferOffset >> 0x8); + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, tty_foreground->tty_x); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, tty_foreground->tty_y); + return; + } + +void +kprint(char *string) +{ + + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + + /* Short circuit if we're in tty mode */ + if (NULL != tty_foreground) + { + tty_print(string,tty_find(0)); + return; + } + + /* We Need To Get The Y Position */ + outportByte(0x3D4, 0x0e); + bufferOffset = inportByte(0x3D5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + /* Then We Need To Add The X Position */ + outportByte(0x3D4, 0x0f); + bufferOffset += inportByte(0x3D5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + + while ((character = *string++)) { + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + videoBuffer[bufferOffset++] = character; + videoBuffer[bufferOffset++] = printColor; + break; + } /* switch */ + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + videoBuffer[i] = videoBuffer[i + 160]; + } /* for */ + for (i = 0; i < 80; i++) { + videoBuffer[(160 * 24) + (i * 2)] = 0x20; + videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; + } /* for */ + bufferOffset -= 160; + } /* if */ + } /* while */ + bufferOffset >>= 1; /* Set the new cursor position */ + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + + return; +} + +/* Clears The Screen */ +void screenClear() { + short i = 0x0; + + for (i = 0x0; i < (80 * 25); i++) { + videoBuffer[i * 2] = 0x20; + videoBuffer[i * 2 + 1] = defaultColor; + } + + /* This sets the blinking cursor to the top left */ + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, 0); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, 0); + } + +/*** + END + ***/ diff --git a/ubixfs/Makefile b/ubixfs/Makefile new file mode 100644 index 0000000..cc4ef5e --- /dev/null +++ b/ubixfs/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = thread.o ubixfs.o directory.o block.o dirCache.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} ${INCLUDES} -W -Wall -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/ubixfs/block.c b/ubixfs/block.c new file mode 100644 index 0000000..ce00d22 --- /dev/null +++ b/ubixfs/block.c @@ -0,0 +1,132 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + UbixOS + + Revision 1.2 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:39 reddawg + no message + + Revision 1.6 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.5 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + + Revision 1.4 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.3 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:07 reddawg + UbixOS v1.0 + + Revision 1.3 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + + +void syncBat(struct vfs_mountPoint *mp) { + struct ubixFSInfo *fsInfo = mp->fsInfo; + mp->device->devInfo->write(mp->device->devInfo->info,fsInfo->blockAllocationTable,mp->diskLabel->partitions[mp->partition].pOffset,mp->diskLabel->partitions[mp->partition].pBatSize); + } + +int freeBlocks(int block,fileDescriptor *fd) { + int i = block; + + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + while (i != 0x0) { + block = fsInfo->blockAllocationTable[i].nextBlock; + + fsInfo->blockAllocationTable[i].attributes = 0x0; + fsInfo->blockAllocationTable[i].nextBlock = 0x0; + + i = block; + } + syncBat(fd->mp); + return(i); + } + +int getFreeBlocks(int count,fileDescriptor *fd) { + uInt32 i = 0x0; + uInt32 x = 0x0; + + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + getBlocks: + for (i=1;i < fsInfo->batEntries;i++) { + if (fsInfo->blockAllocationTable[i].attributes == 0x0) { + for (x = 1; x < (uInt32)count; x++) { + if (fsInfo->blockAllocationTable[i + x].attributes != 0x0) { + goto getBlocks; + } + } + for (x = i; x < i+count;x++) { + fsInfo->blockAllocationTable[x].attributes = 0x1; + if ((x+1) == (i+count)) { + fsInfo->blockAllocationTable[x].nextBlock = -1; + } + else { + fsInfo->blockAllocationTable[x].nextBlock = x+1; + } + } + syncBat(fd->mp); + return(i); + } + } + return(0x0); + } + +/*** + END + ***/ + diff --git a/ubixfs/dirCache.c b/ubixfs/dirCache.c new file mode 100644 index 0000000..76d7722 --- /dev/null +++ b/ubixfs/dirCache.c @@ -0,0 +1,439 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +$Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +static spinLock_t dca_spinLock = SPIN_LOCK_INITIALIZER; + +static +struct directoryEntry * +ubixfs_findName(struct directoryEntry * dirList, uInt32 size, char * name) { + unsigned int i; + + if (dirList == NULL || name == NULL) return NULL; + //UBU kprintf("dirList: [0x%X],name: [0x%X]\n",dirList,name); + for (i = 0; i < (size / sizeof(struct directoryEntry)) ; i++) { + if (strcmp(dirList[i].fileName, name) == 0) return &dirList[i]; + } /* for */ + return NULL; +} /* ubixfs_findName */ + +struct cacheNode * +ubixfs_cacheFind(struct cacheNode * head, char * name) { + struct cacheNode * tmp = head; + struct directoryEntry * dirList = NULL; + unsigned int i = 0x0; + char dirName[256]; + char * nextDir = NULL; +/* kprintf("looking for %s\n", name); */ +assert(name); +assert(head); +assert(*name); + spinLock(&dca_spinLock); + spinUnlock(&dca_spinLock); + if (name == NULL || head == NULL) return NULL; + if (*name == '\0') return NULL; + + /* + * walk down the tree recursively until we find the node we're looking + * for + */ + i = 0; + while (name[i] != '\0' && name[i] != '/' && i < sizeof(dirName)) { + dirName[i] = name[i]; + i++; + } /* while */ + assert(i < sizeof(dirName)); + if (i == sizeof(dirName)) return NULL; + + if (i == 0) dirName[i++] = '/'; + + dirName[i] = '\0'; + + nextDir = &name[i]; + if (*nextDir == '/') nextDir++; + + /* + * nextDir points to the next dir + * name points to a null terminated directory name + * if nextDir isn't null, then make sure that this dir is present + */ +/* kprintf("nextdir: %s -- dirName: %s\n", nextDir, dirName); */ + if (*nextDir != '\0') { + while (tmp != NULL) { + //UBU kprintf("tmp->name: [0x%X],dirName: [0x%X]\n",tmp->name,dirName); + if (strcmp(tmp->name, dirName) == 0) { + + if ((*tmp->attributes & typeFile) == typeFile + || tmp->fileListHead == NULL) { + + /* if we're here, then there are no subdirs cached to look through */ + dirList = ubixfs_findName((struct directoryEntry *)head->info, + *head->size, nextDir); + if (dirList == NULL) return NULL; +/* kprintf("creating new node %s", dirList->fileName); */ + tmp = ubixfs_cacheAdd(tmp, ubixfs_cacheNew(dirList->fileName)); + tmp->attributes = &dirList->attributes; + tmp->permissions = &dirList->permissions; + tmp->size = &dirList->size; +/* kprintf(" size: %d\n", *tmp->size); */ + tmp->startCluster = &dirList->startCluster; + tmp->present = 0; + return tmp; + } else { + return ubixfs_cacheFind(tmp->fileListHead, nextDir); + } + } /* if */ + tmp = tmp->next; + } /* while */ + /* it wasn't present, return NULL */ + return NULL; + } /* if */ + + /* + * if nextDir was null, then we're at the bottom level. Look for the + * dir listing here + */ + while (tmp != NULL) { + + assert(tmp->name); + assert(name); +/* don't forget to check to see if it's a directory */ + //UBU kprintf("tmpName: [0x%X], name: [0x%X]\n",tmp->name,name); + if (strcmp(tmp->name, name) == 0) { + + /* + * we found the node. Move it to the front of the list + * (if it isn't already) + */ +#if 0 + assert(tmp->parent); + if (tmp != tmp->parent->fileListHead) { + + /* if we're the tail, point the tail to our prev */ + if (tmp == tmp->parent->fileListTail) { + tmp->parent->fileListTail = tmp->prev; + } /* if */ + + if (tmp->next != NULL) tmp->next->prev = tmp->prev; + if (tmp->prev != NULL) tmp->prev->next = tmp->next; + tmp->next = tmp->parent->fileListHead; + tmp->prev = NULL; + tmp->parent->fileListHead = tmp; + } /* if */ +#endif + return tmp; + } /* if */ + tmp = tmp->next; + } /* while */ + /* if we're here, then one level of the dir isn't cached */ + + tmp = head->parent; + assert(tmp); + assert(tmp->info); + dirList = ubixfs_findName((struct directoryEntry *)tmp->info, + *tmp->size, name); + if (dirList == NULL) return NULL; +/* kprintf("creating new node/size %s/%d", dirList->fileName, dirList->size);*/ + tmp = ubixfs_cacheAdd(tmp, ubixfs_cacheNew(dirList->fileName)); + tmp->attributes = &dirList->attributes; + tmp->permissions = &dirList->permissions; + tmp->size = &dirList->size; +/* kprintf(" size: %d\n", *tmp->size); */ + tmp->startCluster = &dirList->startCluster; + tmp->present = 0; + return tmp; +#if 0 + return NULL; /* couldn't find it */ +#endif +} /* ubixfs_cacheFind */ + +struct cacheNode * +ubixfs_cacheNew(const char * name) { + struct cacheNode * tmp = kmalloc(sizeof(struct cacheNode)); + assert(tmp); + tmp->parent = tmp; + tmp->prev = tmp->next = tmp->fileListHead = tmp->fileListTail = NULL; + tmp->info = NULL; + tmp->size = NULL; + tmp->present = tmp->dirty = 0; + tmp->startCluster = NULL; + tmp->attributes = NULL; + tmp->permissions = NULL; + tmp->name = (char *)kmalloc(strlen(name)+1); + strcpy(tmp->name, name); + return tmp; +} /* ubixfs_cacheNew */ + +void +ubixfs_cacheDelete(struct cacheNode ** head) { + struct cacheNode * tmp = NULL; + struct cacheNode * del = NULL; + + if (head == NULL) return; + if (*head == NULL) return; + + tmp = *head; + while (tmp != NULL) { + /* if there are any child nodes, delete them first */ + + /* + * the following commented out ``if'' statement is redundant, since it + * will be caught with the above checks + */ + /* if (tmp->fileListHead != NULL) */ + ubixfs_cacheDelete(&tmp->fileListHead); + + kfree(tmp->info); + kfree(tmp->name); + del = tmp; + tmp = tmp->next; + kfree(del); + } /* while */ + *head = NULL; + return; +} /* deleteNode */ +#if 0 +void +addNode(struct cacheNode ** node, struct cacheNode * newNode) { + if (node == NULL) return; + newNode->next = *node; + if (*node != NULL) (*node)->prev = newNode; + newNode->prev = NULL; + *node = newNode; + return; +} /* addNode */ +#endif + +struct cacheNode * +ubixfs_cacheAdd(struct cacheNode *node, struct cacheNode * newNode) { + struct cacheNode * tmp; + + assert(node); + spinLock(&dca_spinLock); + newNode->parent = node; + newNode->next = node->fileListHead; + newNode->prev = NULL; + if (node->fileListHead == NULL) + node->fileListTail = newNode; + else + node->fileListHead->prev = newNode; + + node->fileListHead = newNode; + tmp = node->fileListHead; + spinUnlock(&dca_spinLock); + return tmp; +} /* ubixfs_cacheAdd */ + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:40 reddawg + no message + + Revision 1.30 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.29 2004/08/09 12:58:05 reddawg + let me know when you got the surce + + Revision 1.28 2004/08/01 17:58:39 flameshadow + chg: fixed string allocation bug in ubixfs_cacheNew() + + Revision 1.27 2004/07/28 17:24:13 flameshadow + chg: no comment + + Revision 1.26 2004/07/28 17:07:29 flameshadow + chg: re-added moving cached nodes to the front of the list when found + add: added an assert() in ubixfs.c + + Revision 1.25 2004/07/27 19:24:31 flameshadow + chg: reduced the number of debugging statements in the kernel. + + Revision 1.24 2004/07/27 12:02:01 reddawg + chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + + Revision 1.23 2004/07/27 09:05:43 flameshadow + chg: fixed file not found bug. Still can't find looping issue + + Revision 1.22 2004/07/27 04:05:20 flameshadow + chg: kinda fixed it. Added bunches of debug info + + Revision 1.21 2004/07/25 22:21:52 flameshadow + chg: re-enabled kprintf() in ubixfs_cacheFind() + + Revision 1.20 2004/07/24 17:19:24 flameshadow + chg: Temporarily disabled the moving of the found cache node to the front + of the list. It seems to cause problems later (race condition, possibly) + + Revision 1.19 2004/07/22 23:01:51 reddawg + Ok checking in before I sleep + + Revision 1.18 2004/07/22 19:54:50 flameshadow + chg: works now. Thanx ubu + + Revision 1.17 2004/07/22 19:01:59 flameshadow + chg: more directory and file caching + + Revision 1.16 2004/07/22 16:34:32 flameshadow + add: file and dir caching kinda work + + Revision 1.15 2004/07/21 22:43:18 flameshadow + one more try + + Revision 1.14 2004/07/21 22:42:25 flameshadow + try it now + + Revision 1.13 2004/07/21 22:40:27 flameshadow + weird + + Revision 1.12 2004/07/21 22:18:37 flameshadow + chg: renamed subDirsHead/Tail members of cacheNode to fileListHead/Tail + + Revision 1.11 2004/07/21 22:12:22 flameshadow + add: attributes tag in cacheNode + add: setting of attributes in ubixfx_cacheNew() and ubixfs_cacheFind() + + Revision 1.10 2004/07/21 22:07:18 flameshadow + chg: renamed caching functions (again) + + Revision 1.9 2004/07/21 22:00:04 flameshadow + chg: ubixfws_dirCacheAdd now returns a pointer to the node it added + chg: minor fix in ubixfs_dirCacheFind() + + Revision 1.6 2004/07/21 14:43:14 flameshadow + add: added cwc (current working container) to the osInfo strut + + Revision 1.5 2004/07/20 19:21:30 reddawg + You like leaving out $Log$ + You like leaving out Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + You like leaving out UbixOS + You like leaving out + You like leaving out Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + You like leaving out ubix2 + You like leaving out + You like leaving out Revision 1.2 2005/10/12 00:13:37 reddawg + You like leaving out Removed + You like leaving out + You like leaving out Revision 1.1.1.1 2005/09/26 17:24:40 reddawg + You like leaving out no message + You like leaving out + You like leaving out Revision 1.30 2004/08/14 11:23:02 reddawg + You like leaving out Changes + You like leaving out + You like leaving out Revision 1.29 2004/08/09 12:58:05 reddawg + You like leaving out let me know when you got the surce + You like leaving out + You like leaving out Revision 1.28 2004/08/01 17:58:39 flameshadow + You like leaving out chg: fixed string allocation bug in ubixfs_cacheNew() + You like leaving out + You like leaving out Revision 1.27 2004/07/28 17:24:13 flameshadow + You like leaving out chg: no comment + You like leaving out + You like leaving out Revision 1.26 2004/07/28 17:07:29 flameshadow + You like leaving out chg: re-added moving cached nodes to the front of the list when found + You like leaving out add: added an assert() in ubixfs.c + You like leaving out + You like leaving out Revision 1.25 2004/07/27 19:24:31 flameshadow + You like leaving out chg: reduced the number of debugging statements in the kernel. + You like leaving out + You like leaving out Revision 1.24 2004/07/27 12:02:01 reddawg + You like leaving out chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + You like leaving out + You like leaving out Revision 1.23 2004/07/27 09:05:43 flameshadow + You like leaving out chg: fixed file not found bug. Still can't find looping issue + You like leaving out + You like leaving out Revision 1.22 2004/07/27 04:05:20 flameshadow + You like leaving out chg: kinda fixed it. Added bunches of debug info + You like leaving out + You like leaving out Revision 1.21 2004/07/25 22:21:52 flameshadow + You like leaving out chg: re-enabled kprintf() in ubixfs_cacheFind() + You like leaving out + You like leaving out Revision 1.20 2004/07/24 17:19:24 flameshadow + You like leaving out chg: Temporarily disabled the moving of the found cache node to the front + You like leaving out of the list. It seems to cause problems later (race condition, possibly) + You like leaving out + You like leaving out Revision 1.19 2004/07/22 23:01:51 reddawg + You like leaving out Ok checking in before I sleep + You like leaving out + You like leaving out Revision 1.18 2004/07/22 19:54:50 flameshadow + You like leaving out chg: works now. Thanx ubu + You like leaving out + You like leaving out Revision 1.17 2004/07/22 19:01:59 flameshadow + You like leaving out chg: more directory and file caching + You like leaving out + You like leaving out Revision 1.16 2004/07/22 16:34:32 flameshadow + You like leaving out add: file and dir caching kinda work + You like leaving out + You like leaving out Revision 1.15 2004/07/21 22:43:18 flameshadow + You like leaving out one more try + You like leaving out + You like leaving out Revision 1.14 2004/07/21 22:42:25 flameshadow + You like leaving out try it now + You like leaving out + You like leaving out Revision 1.13 2004/07/21 22:40:27 flameshadow + You like leaving out weird + You like leaving out + You like leaving out Revision 1.12 2004/07/21 22:18:37 flameshadow + You like leaving out chg: renamed subDirsHead/Tail members of cacheNode to fileListHead/Tail + You like leaving out + You like leaving out Revision 1.11 2004/07/21 22:12:22 flameshadow + You like leaving out add: attributes tag in cacheNode + You like leaving out add: setting of attributes in ubixfx_cacheNew() and ubixfs_cacheFind() + You like leaving out + You like leaving out Revision 1.10 2004/07/21 22:07:18 flameshadow + You like leaving out chg: renamed caching functions (again) + You like leaving out + You like leaving out Revision 1.9 2004/07/21 22:00:04 flameshadow + You like leaving out chg: ubixfws_dirCacheAdd now returns a pointer to the node it added + You like leaving out chg: minor fix in ubixfs_dirCacheFind() + You like leaving out + You like leaving out Revision 1.6 2004/07/21 14:43:14 flameshadow + You like leaving out add: added cwc (current working container) to the osInfo strut + You like leaving out so i don't know what is going on eh? + + END + ***/ + + diff --git a/ubixfs/directory.c b/ubixfs/directory.c new file mode 100644 index 0000000..6cac9b8 --- /dev/null +++ b/ubixfs/directory.c @@ -0,0 +1,188 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +static dirList_t dirList = 0x0; + +dirList_t +ubixFSLoadDir(char *data) { + dirList_t tmpDir = 0x0; + + tmpDir = (dirList_t)kmalloc(sizeof(struct directoryList)); + + sprintf(tmpDir->dirName,"%s",data); + + if (0x0 == dirList) { + dirList = tmpDir; + } + else { + tmpDir->next = dirList; + tmpDir->prev = 0x0; + dirList->prev = tmpDir; + dirList = tmpDir; + } + + if (!strcmp(":",data)) { + tmpDir->dirCache = (char *)kmalloc(0x4000); + } + + return(tmpDir); + } + +int +addDirEntry(struct directoryEntry *dir,fileDescriptor *fd) { + uInt32 i = 0x0; + uInt32 entries = 0x0; + struct directoryEntry *tmp = 0x0; + + tmp = (struct directoryEntry *)kmalloc(fd->size); + + readUbixFS(fd,(char *)tmp,fd->offset,fd->size); + entries = fd->size/sizeof(struct directoryEntry); + for (i=0;(tmp[i].attributes != 0x0) && (i < entries);i++); + + if (i == entries) { + tmp = (struct directoryEntry *)kmalloc(0x1000); + i = 0x0; + } + else { + fd->offset = 0x0; + } + memcpy(&tmp[i],dir,sizeof(struct directoryEntry)); + + if (writeUbixFS(fd,(char *)tmp,fd->offset,fd->size) == 0x0) { + kprintf("Error Creating Directory\n"); + } + + return(0x0); + } + +int +ubixFSmkDir(char *directory,fileDescriptor *fd) { + int block = 0x0; + + struct directoryEntry *dir = 0x0; + struct directoryEntry *entry = 0x0; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + //kprintf("Creating Directory: %s",directory); + + block = getFreeBlocks(1,fd); + if (block != 0x0) { + dir = (struct directoryEntry *)kmalloc(UBIXFS_BLOCKSIZE_BYTES); + entry = (struct directoryEntry *)kmalloc(sizeof(struct directoryEntry)); + + entry->startCluster = block; + entry->size = UBIXFS_BLOCKSIZE_BYTES; + entry->attributes = typeDirectory; + entry->permissions = 0xEAA; + sprintf(entry->fileName, directory); + + //dir->attributes = typeDirectory; + //sprintf(dir->fileName,"Test Entry"); + + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info, + dir, + fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[block].realSector, + blockSize); + addDirEntry(entry,fd); + kfree(dir); + kfree(entry); + } + + return(0x0); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:41 reddawg + no message + + Revision 1.12 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.11 2004/08/01 17:58:39 flameshadow + chg: fixed string allocation bug in ubixfs_cacheNew() + + Revision 1.10 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + + Revision 1.9 2004/07/16 20:17:29 flameshadow + chg: broke the ufs stuff + chg: changed vfsRegisterFS() to accept a fileSystem struct + chg: modified calls to vfsRegisterFS() to pass fileSystem struct + + Revision 1.8 2004/06/29 03:59:47 reddawg + Fixed a few issues with subdirectories they are working much better now + + Revision 1.7 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.6 2004/06/04 13:20:22 reddawg + ubixFSmkDir(): played with it a bit to see if it still worked + + Revision 1.5 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.4 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:07 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/ubixfs/thread.c b/ubixfs/thread.c new file mode 100644 index 0000000..cefad3d --- /dev/null +++ b/ubixfs/thread.c @@ -0,0 +1,90 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static struct { + int mounts; + } ubixFS_Info; + +void ubixfs_thread(struct vfs_mountPoint *mp) { + mpi_message_t myMsg; + + ubixFS_Info.mounts = 0; + + if (mp == 0x0) + kpanic("bah"); + + if (mpi_createMbox("ubixfs") != 0x0) { + kpanic("Error: Error creating mailbox: ubixfs\n"); + } + while (1) { + if (mpi_fetchMessage("ubixfs",&myMsg) == 0x0) { + switch(myMsg.header) { + default: + kprintf("Unhandled Message: %i\n",myMsg.header); + break; + } + } + } + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + UbixOS + + Revision 1.2 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:41 reddawg + no message + + Revision 1.3 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.2 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + + Revision 1.1 2004/06/28 18:12:44 reddawg + We need these files + + END + ***/ diff --git a/ubixfs/ubixfs.c b/ubixfs/ubixfs.c new file mode 100644 index 0000000..b885e3a --- /dev/null +++ b/ubixfs/ubixfs.c @@ -0,0 +1,646 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Static defines */ +static int ubixfs_loadData(fileDescriptor *fd,char *data,uInt32 size,uInt32 batIndex); + + +static int openFileUbixFS(const char *file, fileDescriptor *fd) { + //int x = 0; +/* mji struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x4000); */ + struct cacheNode * cacheNode = NULL; + //struct directoryEntry * dirEntry = NULL; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + + +/* kprintf("openFileUbixFS(%s), cwd: %s\n", file, _current->oInfo.cwd); */ + +//if (fsInfo->dirCache == NULL) kprintf("dirCache is null!\n"); + assert(fd); + assert(fd->mp); + assert(fd->mp->device); + assert(fd->mp->device->devInfo); + assert(fd->mp->device->devInfo->read); + assert(fsInfo); + assert(fsInfo->dirCache); + assert(file); + + if ((fd->mode & fileRead) == fileRead) { + do { + cacheNode = ubixfs_cacheFind(fsInfo->dirCache,(char *) file); + if (cacheNode == NULL) return 0; + if (cacheNode->present == 1) break; + assert(cacheNode->size); + if (*cacheNode->size != 0 && cacheNode->info == NULL) { + //kprintf("caching name(size): %s(%d)\n",cacheNode->name,*cacheNode->size); + cacheNode->info = kmalloc(UBIXFS_ALIGN(*cacheNode->size)); + fd->size = *cacheNode->size; + assert(cacheNode->startCluster); + ubixfs_loadData(fd, + cacheNode->info, + *cacheNode->size, + *cacheNode->startCluster); + cacheNode->present = 1; + } /* if */ + } while(1); + + assert(cacheNode); + if (cacheNode == NULL) return 0; /* this should be caught above */ + + fd->start = *cacheNode->startCluster; + fd->size = *cacheNode->size; + fd->perms = *cacheNode->permissions; + fd->cacheNode = cacheNode; /* Directory Start Sector */ + /* + if (cacheNode->size != 0x0 && cacheNode->info == NULL) { + cacheNode->info = kmalloc(UBIXFS_ALIGN(*cacheNode->size)); + ubixfs_loadData(fd,cacheNode->info,cacheNode->size,cacheNode->startCluster); + cacheNode->present = 0x1; + } + */ + return(0x1); + } + else + if ((fd->mode & fileWrite) == fileWrite) { +kprintf("Ouch! in filewrite!\n"); +#if 0 + fd->start = dirEntry->startCluster; + fd->size = dirEntry->size; + fd->perms = dirEntry->permissions; + // fd->dirBlock = 0x0; /* Directory Start Sector */ +#endif + return(0x1); + } + + return 0; + + } + +int writeFileByte(int ch, fileDescriptor *fd, long offset) { + + int blockCount = 0x0,batIndex = 0x0,batIndexPrev = 0x0; + uInt32 i = 0x0; + struct directoryEntry *dirEntry = 0x0; + struct ubixFSInfo *fsInfo = NULL; + + assert(fd); + assert(fd->mp); + assert(fd->mp->diskLabel); + + batIndexPrev = fd->start; + fsInfo = fd->mp->fsInfo; + + /* Find Out How Many Blocks Long This File Is */ + blockCount = (offset/4096); + + /* Find The Block If It Doesn't Exist We Will Have To Allocate One */ + for (i=0x0; i <= fd->mp->diskLabel->partitions[fd->mp->partition].pBatSize; + i++) { + batIndex = fsInfo->blockAllocationTable[batIndexPrev].nextBlock; + if (batIndex == 0x0) { + break; + } + batIndexPrev = batIndex; + } + + if ((offset%4096 == 0) && (fd->status == fdRead)) { + fd->status = fdOpen; + } + + /* If batIndex == 0x0 Then We Must Allocate A New Block */ + if (batIndex == 0x0) { + for (i=1;i < fsInfo->batEntries;i++) { + if (fsInfo->blockAllocationTable[i].attributes == 0x0) { + fsInfo->blockAllocationTable[batIndexPrev].nextBlock = i; + fsInfo->blockAllocationTable[batIndex].nextBlock = -1; + batIndex = i; + fd->start = i; + break; + } + } + /* fd->mp->drive->read(fd->mp->drive->driveInfoStruct,diskLabel->partitions[0].pOffset+blockAllocationTable[batIndex].realSector,8,fd->buffer); */ + fd->buffer[offset-(blockCount*4096)] = ch; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + } + else { + if (fd->status != fdRead) { + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + fd->status = fdRead; + } + fd->buffer[offset-(blockCount*4096)] = ch; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + } + if ((uInt32)offset > fd->size) { + fd->size = offset; + dirEntry = (struct directoryEntry *)kmalloc(4096); + /* + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),8); + */ + for (i=0x0;i<(4096/sizeof(struct directoryEntry));i++) { + if ((int)!strcmp(dirEntry[i].fileName,fd->fileName)) + break; + } + dirEntry[i].size = fd->size; +/* + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),8); +*/ + kfree(dirEntry); + } + return(ch); + } + +/* Verified Functions */ + + +int readUbixFS(fileDescriptor *fd,char *data,uInt32 offset,long size) { + int i = 0x0; + char *buffer = 0x0; + struct ubixFSInfo *fsInfo = NULL; + + assert(fd); + assert(fd->mp); + assert(fd->mp->fsInfo); + + fsInfo = fd->mp->fsInfo; + + if (fd->cacheNode->present != 1) + kpanic("ERROR with cache node\n"); + + buffer = (char *)fd->cacheNode->info; + + for (i=0x0; i fd->size) { + /* Set File EOF If There Is Nothing To Do */ + /* data[i] = '\0'; Is this safe? */ + fd->status = fdEof; + return(size); + } + /* Copy Data From Buffer To Data */ + data[i] = buffer[i + offset]; + } + /* Return */ + return(size); + } + + +/************************************************************************ + +Function: int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Write Data Into File +Notes: + +************************************************************************/ +int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size) { + uInt32 blockOffset = 0x0; + uInt32 blockIndex; + uInt32 blockIndexPrev; + uInt32 i = 0x0; + struct ubixFSInfo *fsInfo = NULL; + struct directoryEntry *dirEntry = 0x0; + + assert(fd); + assert(fd->mp); + assert(fd->mp->fsInfo); + assert(fd->mp->device); + assert(fd->mp->device->devInfo); + + blockIndex = blockIndexPrev = fd->start; + fsInfo = fd->mp->fsInfo; + + blockOffset = (offset/0x1000); + + if (fd->size != 0x0) { + for (i = 0x0;i < blockOffset;i++) { + blockIndex = fsInfo->blockAllocationTable[blockIndexPrev].nextBlock; + if ((int)blockIndex == EOBC) { + blockIndex = getFreeBlocks(1,fd); + fsInfo->blockAllocationTable[blockIndexPrev].nextBlock = blockIndex; + fsInfo->blockAllocationTable[blockIndex].nextBlock = EOBC; + break; + } + blockIndexPrev = blockIndex; + } + } + + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + for (i = 0x0;i < (uInt32)size;i++) { + + fd->buffer[(offset- (blockOffset *0x1000))] = data[i]; + offset++; + + if (offset%4096 == 0x0) { + blockOffset++; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + + if (fsInfo->blockAllocationTable[blockIndex].nextBlock == EOBC) { + blockIndexPrev = blockIndex; + blockIndex = getFreeBlocks(1,fd); + fsInfo->blockAllocationTable[blockIndexPrev].nextBlock = blockIndex; + fsInfo->blockAllocationTable[blockIndex].nextBlock = EOBC; + } + else { + blockIndex = fsInfo->blockAllocationTable[blockIndex].nextBlock; + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + } + } + } + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + + if ((uInt32)offset > fd->size) { + fd->size = offset; + dirEntry = (struct directoryEntry *)kmalloc(4096); +/* + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),blockSize); +*/ + for (i=0x0;i<(4096/sizeof(struct directoryEntry));i++) { + if ((int)!strcmp(dirEntry[i].fileName,fd->fileName)) + break; + } + dirEntry[i].size = fd->size; + dirEntry[i].startCluster = fd->start; +/* + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),blockSize); +*/ + kfree(dirEntry); + } + /* Return */ + return(size); + } + +void ubixFSUnlink(char *path,struct vfs_mountPoint *mp) { + int x=0; + struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x1000); + struct ubixFSInfo *fsInfo = mp->fsInfo; + + mp->device->devInfo->read(mp->device->devInfo->info,dirEntry,(mp->diskLabel->partitions[mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); + + for (x=0;(uInt32)x<(4096/sizeof(struct directoryEntry));x++) { + if ((int)!strcmp(dirEntry[x].fileName,path)) { + dirEntry[x].attributes |= typeDeleted; + dirEntry[x].fileName[0] = '?'; + mp->device->devInfo->write(mp->device->devInfo->info,dirEntry,(mp->diskLabel->partitions[mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); + return; + } + } + kprintf("File Not Found\n"); + return; + } + + +/***************************************************************************************** + +Function: static + int ubixfs_loadData(fileDescriptor *fd,char *data,uInt32 size,uInt32 batIndex) + +Description: This will load the node data in from the disk + +Notes: + 07/23/2004 - This loads complete blocks from disk so it is aligned to 0x1000 not the + actual file size + +*****************************************************************************************/ +static int ubixfs_loadData(fileDescriptor *fd,char *data,uInt32 size,uInt32 batIndex) { + uInt32 i = 0x0; + + struct ubixFSInfo *fsInfo = NULL; + + assert(fd); + assert(fd->mp); + assert(fd->mp->fsInfo); + + fsInfo = fd->mp->fsInfo; + + size = UBIXFS_ALIGN(size); + /* Loop by block size */ + + for (i=0x0; iblockAllocationTable[batIndex].nextBlock; + /* Read data in from media */ + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,data+i,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); + } + /* Return */ + return(0x0); + } + + +/***************************************************************************************** + +Function: int ubixfs_initialize() + +Description: This will initialize a mount point it loads the BAT and Caches the rootDir + +Notes: + +*****************************************************************************************/ +int ubixfs_initialize(struct vfs_mountPoint *mp) { + struct ubixFSInfo *fsInfo = 0x0; + + assert(mp); + assert(mp->diskLabel); + assert(mp->diskLabel->partitions); + + mp->fsInfo = (struct ubixFSInfo *)kmalloc(sizeof(struct ubixFSInfo)); + assert(mp->fsInfo); + + fsInfo = mp->fsInfo; + fsInfo->rootDir = 0x0; /* Root directory is always 0x0 on the UbixFS */ + + /* + Check the disk label to ensure this is an UbixFS partition + */ + if ((mp->diskLabel->magicNum == UBIXDISKMAGIC) && (mp->diskLabel->magicNum2 == UBIXDISKMAGIC)) { + + /* Allocate memory for BAT */ + fsInfo->blockAllocationTable = (struct blockAllocationTableEntry *)kmalloc(mp->diskLabel->partitions[mp->partition].pBatSize * 512); + assert(fsInfo->blockAllocationTable); + + /* Set up the amount of BAT entries */ + fsInfo->batEntries = (mp->diskLabel->partitions[mp->partition].pBatSize*512) / sizeof(struct blockAllocationTableEntry); + + /* Read the BAT to memory */ + assert(mp->device->devInfo->read); + mp->device->devInfo->read(mp->device->devInfo->info, + fsInfo->blockAllocationTable, + mp->diskLabel->partitions[mp->partition].pOffset, + mp->diskLabel->partitions[mp->partition].pBatSize); + + /* Set up root directory cache */ + fsInfo->dirCache = ubixfs_cacheNew("/"); + assert(fsInfo->dirCache); + fsInfo->dirCache->info = (struct directoryEntry *)kmalloc(0x4000); /* allocate root dir */ + fsInfo->dirCache->present = 1; + fsInfo->dirCache->size = kmalloc(sizeof(fsInfo->dirCache->size)); + fsInfo->dirCache->startCluster = kmalloc(sizeof(fsInfo->dirCache->startCluster)); + fsInfo->dirCache->attributes = kmalloc(sizeof(fsInfo->dirCache->attributes)); + fsInfo->dirCache->permissions = kmalloc(sizeof(fsInfo->dirCache->permissions)); + + *fsInfo->dirCache->size = 0x4000; + *fsInfo->dirCache->startCluster = fsInfo->rootDir; + + assert(fsInfo->dirCache->info); + /* Read root dir in from disk it is always 0x4000 bytes long */ + mp->device->devInfo->read(mp->device->devInfo->info, + fsInfo->dirCache->info, + (mp->diskLabel->partitions[mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector), + 0x4000 / 512); + + /* Start our ubixfs_thread to manage the mount point */ + /* + UBU disable for now + execThread(ubixfs_Thread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + */ + kprintf(" Offset: [%i], Partition: [%i]\n", + mp->diskLabel->partitions[mp->partition].pOffset,mp->partition); + kprintf("UbixFS Initialized\n"); + return(0x1); + } + + kprintf("Not a valid UbixFS disk.\n"); + /* Return */ + return(0x0); + } + +/***************************************************************************************** + +Function: int ubixfs_init() + +Description: This is the master initialization for the Ubix File System it will make the + OS UbixFS aware. + It does not in any way shape or form connect a mount point an medium that is + upto the ubixfs_initialize() function + +Notes: + +*****************************************************************************************/ +int ubixfs_init() { + /* Set up our file system structure */ + struct fileSystem ubixFileSystem = + {NULL, /* prev */ + NULL, /* next */ + (void *)ubixfs_initialize, /* vfsInitFS */ + (void *)readUbixFS, /* vfsRead */ + (void *)writeUbixFS, /* vfsWrite */ + (void *)openFileUbixFS, /* vfsOpenFile */ + (void *)ubixFSUnlink, /* vfsUnlink */ + (void *)ubixFSmkDir, /* vfsMakeDir */ + NULL, /* vfsRemDir */ + NULL, /* vfsSync */ + 0 /* vfsType */ + }; /* ubixFileSystem */ + + /* Add UbixFS */ + if (vfsRegisterFS(ubixFileSystem) != 0x0) { + kpanic("Unable To Enable UbixFS"); + return(0x1); + } + + /* Return */ + return(0x0); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:56 reddawg + UbixOS + + Revision 1.2 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.1.1.1 2006/06/01 12:46:17 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:37 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:42 reddawg + no message + + Revision 1.44 2004/08/26 22:51:19 reddawg + TCA touched me :( i think he likes men.... + + + sched.h: kTask_t added parentPid + endtask.c: fixed term back to parentPid + exec.c: cleaned warnings + fork.c: fixed term to childPid + sched.c: clean up for dead tasks + systemtask.c: clean up dead tasks + kmalloc.c: cleaned up warnings + udp.c: cleaned up warnings + bot.c: cleaned up warnings + shell.c: cleaned up warnings + tcpdump.c: took a dump + hd.c: cleaned up warnings + ubixfs.c: stopped prning debug info + + Revision 1.43 2004/08/14 11:23:02 reddawg + Changes + + Revision 1.42 2004/08/09 12:58:05 reddawg + let me know when you got the surce + + Revision 1.41 2004/08/01 17:58:39 flameshadow + chg: fixed string allocation bug in ubixfs_cacheNew() + + Revision 1.40 2004/07/28 17:07:29 flameshadow + chg: re-added moving cached nodes to the front of the list when found + add: added an assert() in ubixfs.c + + Revision 1.39 2004/07/27 19:24:31 flameshadow + chg: reduced the number of debugging statements in the kernel. + + Revision 1.38 2004/07/27 12:02:01 reddawg + chg: fixed marks bug readFile did a lookup which is why it looked like it was loopping so much + + Revision 1.37 2004/07/27 09:05:43 flameshadow + chg: fixed file not found bug. Still can't find looping issue + + Revision 1.36 2004/07/27 04:05:20 flameshadow + chg: kinda fixed it. Added bunches of debug info + + Revision 1.35 2004/07/26 19:15:49 reddawg + test code, fixes and the like + + Revision 1.34 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + + Revision 1.33 2004/07/23 09:10:06 reddawg + ubixfs: cleaned up some functions played with the caching a bit + vfs: renamed a bunch of functions + cleaned up a few misc bugs + + Revision 1.32 2004/07/22 23:01:51 reddawg + Ok checking in before I sleep + + Revision 1.31 2004/07/22 22:37:03 reddawg + Caching is working now the FS is extremely fast but needs to be optimized to do 32bit copies over 8bit + + Revision 1.30 2004/07/22 19:01:59 flameshadow + chg: more directory and file caching + + Revision 1.29 2004/07/22 16:34:32 flameshadow + add: file and dir caching kinda work + + Revision 1.28 2004/07/21 22:07:18 flameshadow + chg: renamed caching functions (again) + + Revision 1.27 2004/07/21 21:08:05 flameshadow + add: added provisions for file caching + + Revision 1.26 2004/07/20 23:21:31 flameshadow + syncing + + Revision 1.25 2004/07/20 21:39:53 reddawg + ubixfs: does propper caching now problem was you did not seek realSector however the os starts but I am getting a segfault could be from anything haven't looked into it right quick + + Revision 1.24 2004/07/20 21:38:08 flameshadow + try now + + + Revision 1.23 2004/07/20 21:35:09 reddawg + Let me commit before we start to overlap + + Revision 1.22 2004/07/20 21:28:16 flameshadow + oops + + Revision 1.20 2004/07/20 19:36:49 reddawg + UBU Tags + + Revision 1.19 2004/07/20 18:09:37 flameshadow + add: directory caching related stuff + + Revision 1.18 2004/07/17 03:21:34 flameshadow + chg: cleaned up code; added assert() statements + + Revision 1.15 2004/07/14 12:21:49 reddawg + ubixfs: enableUbixFs to ubixfs_init + Changed Startup Routines + + Revision 1.14 2004/06/28 23:12:58 reddawg + file format now container:/path/to/file + + Revision 1.13 2004/06/28 18:12:44 reddawg + We need these files + + Revision 1.12 2004/06/28 11:57:58 reddawg + Fixing Up Filesystem + + Revision 1.10 2004/06/04 13:20:22 reddawg + ubixFSmkDir(): played with it a bit to see if it still worked + + Revision 1.9 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.8 2004/06/01 00:04:53 reddawg + Try now mark + + Revision 1.7 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.6 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.5 2004/04/29 15:45:19 reddawg + Fixed some bugs so now the automade images will work correctly + + Revision 1.4 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.3 2004/04/28 13:33:09 reddawg + Overhaul to ubixfs and boot loader and MBR to work well with our schema + now BAT and dir and file entries are all offset 64Sectors from the start of the partition + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:08 reddawg + UbixOS v1.0 + + Revision 1.31 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/ubixfsv2/Makefile b/ubixfsv2/Makefile new file mode 100644 index 0000000..d38158d --- /dev/null +++ b/ubixfsv2/Makefile @@ -0,0 +1,50 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +#Linker +LD = ld + +#Binary File Name +BINARY = ubixfs + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o vfs.o ubixfs.o btree.o ramdrive.o + +#Includes +INCLUDES = -I./include -I./ + +#CFLAGS + +CFLAGS = -O3 + +all: $(BINARY) + +# Link The Binary +$(BINARY) : $(OBJS) + $(CXX) $(CFLAGS) -o $@ $(OBJS) + +# Compile the source files +.cpp.o: + $(CXX) -ggdb -W -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -W -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -W -Wall $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -W -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -W -Wall $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) *.core diff --git a/ubixfsv2/btree.cpp b/ubixfsv2/btree.cpp new file mode 100644 index 0000000..114018d --- /dev/null +++ b/ubixfsv2/btree.cpp @@ -0,0 +1,767 @@ +// http://www.cs.msstate.edu/~cs2314/global/BTreeAnimation/algorithm.html +#include +#include +#include +#include +#include +#include +#include "btree.h" +#include "ubixfs.h" + +using namespace std; +#define VERIFY(x, y, z, n) if ((x) != (y)) { cout << "verify " << z << " failed" << endl; PrintWholeTree(); } + +bTree::bTree(UbixFS * filesystem, fileDescriptor * myfd) { + size_t result = 0; + + root = NULL; + tag = 0; + fs = filesystem; + fd = myfd; + header = new bTreeHeader; + assert(header); + memset(header, 0, sizeof(bTreeHeader)); + assert(fs); + result = fs->vfs_read(fd, header, 0, sizeof(bTreeHeader)); + assert(result == sizeof(bTreeHeader)); + + // If there are any files in this dir, load the first node of the b+tree + if (header->treeLeafCount != 0) { + assert(header->firstNodeOffset != 0); + root = new bNode; + assert(root); + result = fs->vfs_read(fd, root, header->firstNodeOffset, sizeof(bNode)); + assert(result == sizeof(bNode)); + } // if + +} // bTree::bTree + +bTree::bTree(const char * key, ubixfsInode * inode) { +/* once the FS and the bTree are interfaced, this should go away */ + root = NULL; + tag = 0; + header = new bTreeHeader; + assert(header); + memset(header, 0, sizeof(bTreeHeader)); + header->treeDepth = 1; + header->treeWidth = 0; + header->treeLeafCount = 0; + header->firstDeleted = -1; + header->firstNodeOffset = sizeof(bTreeHeader); + + if (inode == NULL) return; + root = allocEmptyNode(); + if (root == NULL) return; + root->used = 1; + root->parent.bPtr = NULL; + root->leaf = true; + root->childCount[1] = 1; + +// cout << "---Creating " << inode->name << "@" << inode << endl; + strncpy(root->keys[0], key, B_MAX_NAME_LENGTH); + // insert pointer to data page to the right of the data + root->head[1].iPtr = inode; + root->tail[1].iPtr = inode; + + root->present[1] = true; + if (inode != NULL) { + inode->next.bPtr = inode->prev.bPtr = NULL; + } // if + return; +} // bTree:bTree + +bool +bTree::Insert(const char * key, ubixfsInode * inode) { + bNode * bnode = root; + ubixfsInode * tmpInode = NULL; + unsigned int curSlot = 0; + + if (inode == NULL) return false; + + // note: this code is right out of the constructor + if (root == NULL) { + if (header == NULL) header = new bTreeHeader; + assert(header); + memset(header, 0, sizeof(bTreeHeader)); + header->treeDepth = 1; + header->treeWidth = 0; + header->treeLeafCount = 0; + header->firstDeleted = -1; + header->firstNodeOffset = sizeof(bTreeHeader); + + root = allocEmptyNode(); + assert(root); + if (root == NULL) return false; + + root->used = 1; + root->parent.bPtr = NULL; + root->leaf = true; + root->childCount[1] = 1; + + strncpy(root->keys[0], key, B_MAX_NAME_LENGTH); + // insert pointer to data page to the right of the data + root->head[1].iPtr = inode; + root->tail[1].iPtr = inode; + + root->present[1] = true; + inode->next.iPtr = inode->prev.iPtr = NULL; + return true; + } // if + + tmpInode = Find(key); + if (tmpInode != NULL) return false; +// PrintWholeTree(); +// cout << "Insert(" << key << ")" << endl; +//Info(bnode); + ++header->treeLeafCount; + /* + * Find the leaf node the inode goes into + */ + assert(bnode->used); +// cout << "---Inserting " << inode->name << " @ " << inode << endl; + while (bnode != NULL && !bnode->leaf) { + if (strcmp(key, bnode->keys[0]) < 0) { + bnode = bnode->head[0].bPtr; + } else { + if (strcmp(key, bnode->keys[bnode->used-1]) >= 0) { + bnode = bnode->head[bnode->used].bPtr; + } else { + for (unsigned int i = 1; i < bnode->used; i++) { + if (strcmp(key, bnode->keys[i]) < 0) { + bnode = bnode->head[i].bPtr; + break; + } // if + } // for i + } // else + } + } // while + + /* + * + */ + +assert(bnode); +if (bnode->leaf != true) cout << "leafnode!=true" << endl; +assert(inode); + + if (strcmp(key, bnode->keys[curSlot = 0]) < 0) + tmpInode = bnode->head[curSlot].iPtr; + else + if (strcmp(key, bnode->keys[(curSlot = bnode->used)-1]) >= 0) + tmpInode = bnode->head[bnode->used].iPtr; + else { + for (curSlot = 1; curSlot < bnode->used; curSlot++) { + if (strcmp(key, bnode->keys[curSlot]) < 0) { + tmpInode = bnode->head[curSlot].iPtr; + break; + } // if + } // for curSlot + tmpInode = bnode->head[curSlot].iPtr; + } // else + + + if (tmpInode == NULL) { + /* + * This is the first node in this leaf + */ + bnode->head[curSlot].iPtr = bnode->tail[curSlot].iPtr = inode; + bnode->present[curSlot] = true; + + if (curSlot == 0) { + + if (bnode->head[1].iPtr != NULL) { + ubixfsInode * iptr = bnode->head[1].iPtr; + inode->prev.iPtr = iptr->prev.iPtr; + inode->next.iPtr = iptr; + iptr->prev.iPtr = inode; + if (inode->prev.iPtr != NULL) + inode->prev.iPtr->next.iPtr = inode; + } else { + inode->next.iPtr = inode->prev.iPtr = NULL; + } // else + + } else { + ++bnode->used; + } // else + + } else { + /* + * Add node to leaf page. Scan through to find where it goes. + */ + if (strcmp(key, bnode->head[curSlot].iPtr->name) < 0) + { + + inode->next.iPtr = bnode->head[curSlot].iPtr; + inode->prev.iPtr = inode->next.iPtr->prev.iPtr; + inode->next.iPtr->prev.iPtr = inode; + if (inode->prev.iPtr != NULL) inode->prev.iPtr->next.iPtr = inode; + bnode->head[curSlot].iPtr = inode; + + } else { + + if (strcmp(key, bnode->tail[curSlot].iPtr->name) > 0) { + + inode->prev.iPtr = bnode->tail[curSlot].iPtr; + inode->next.iPtr = inode->prev.iPtr->next.iPtr; + inode->prev.iPtr->next.iPtr = inode; + + if (inode->next.iPtr != NULL) inode->next.iPtr->prev.iPtr = inode; + bnode->tail[curSlot].iPtr = inode; + + } else { + + + ubixfsInode * tmpInode = bnode->head[curSlot].iPtr; + for (unsigned int i = 0; i < bnode->childCount[curSlot]; i++) { + if (strcmp(key, tmpInode->name) < 0) { + inode->next.iPtr = tmpInode; + inode->prev.iPtr = tmpInode->prev.iPtr; + inode->next.iPtr->prev.iPtr = inode; + inode->prev.iPtr->next.iPtr = inode; + break; + } // if + tmpInode = tmpInode->next.iPtr; + } // for i + + } // else + + } // else + + } // else + + + + if (++bnode->childCount[curSlot] == B_MAX_CHILD_COUNT) { + +// cout << "---- before split ----" << endl; +// Info(bnode); + + if (curSlot != bnode->used) { + int shift = bnode->used - curSlot +1; + + memmove(&bnode->head[curSlot+1], + &bnode->head[curSlot], + sizeof(bnode->head[0]) * shift); + memmove(&bnode->tail[curSlot+1], + &bnode->tail[curSlot], + sizeof(bnode->tail[0]) * shift); + memmove(&bnode->present[curSlot+1], + &bnode->present[curSlot], + sizeof(bnode->present[0]) * shift); + memmove(&bnode->childCount[curSlot+1], + &bnode->childCount[curSlot], + sizeof(bnode->childCount[0]) * shift); + + memmove(&bnode->keys[curSlot+1], + &bnode->keys[curSlot], + sizeof(bnode->keys[0]) * (shift-1)); + memset(bnode->keys[curSlot], 0, B_MAX_NAME_LENGTH); + } else { + bnode->head[curSlot+1] = bnode->head[curSlot]; + bnode->tail[curSlot+1] = bnode->tail[curSlot]; + bnode->childCount[curSlot+1] = bnode->childCount[curSlot]; + bnode->present[curSlot+1] = bnode->present[curSlot]; + } // else + + ubixfsInode * tmpInode = bnode->head[curSlot].iPtr; + + for (unsigned int i = 0; i < (B_MAX_CHILD_COUNT+1) >> 1; i++) { + assert(tmpInode); + tmpInode = tmpInode->next.iPtr; + } // for i + + strncpy(bnode->keys[curSlot], tmpInode->name, B_MAX_NAME_LENGTH); + bnode->head[curSlot+1].iPtr = tmpInode; + bnode->tail[curSlot].iPtr = tmpInode->prev.iPtr; + bnode->childCount[curSlot] = (B_MAX_CHILD_COUNT+1) >> 1; + bnode->childCount[curSlot+1] -= bnode->childCount[curSlot]; + bnode->present[curSlot] = true; + ++header->treeWidth; + if (++bnode->used == B_MAX_KEYS) splitNode(bnode); + + } // if leaf is full +// Info(bnode); + return true; +} // bTree::Insert + +void +bTree::splitNode(bNode * oldNode) { + ubixfsInode * tmpInode = NULL; + assert(oldNode); + if (oldNode == NULL) return; + if (oldNode->used != B_MAX_KEYS) return; + + bNode * newNode = allocEmptyNode(); + if (newNode == NULL) return; + + unsigned int shift = B_MAX_KEYS >> 1; + unsigned int splitLoc = B_MAX_KEYS - shift; + ++ shift; +// cout << "oldNode before split: " << endl; +// Info(oldNode); +// cout << "splitLoc: " << splitLoc << endl; +// cout << "shift: " << shift << endl; + + newNode->used = oldNode->used = B_MAX_KEYS >> 1; + newNode->parent.bPtr = oldNode->parent.bPtr; + newNode->leaf = oldNode->leaf; + +// cout << "newNode->used: " << newNode->used << endl; +// cout << "oldNode->used: " << oldNode->used << endl; + + memcpy(&newNode->keys[0], + &oldNode->keys[splitLoc], + sizeof(newNode->keys[0]) * (shift-1)); + + memset(&oldNode->keys[splitLoc], 0, sizeof(newNode->keys[0]) * (shift-1)); + + memcpy(&newNode->present[0], + &oldNode->present[splitLoc], + sizeof(newNode->present[0]) * shift); + + memset(&oldNode->present[splitLoc], 0, sizeof(newNode->present[0]) * shift); + + memcpy(&newNode->head[0], + &oldNode->head[splitLoc], + sizeof(newNode->head[0]) * shift); + + memset(&oldNode->head[splitLoc], 0, + sizeof(newNode->head[0]) * shift); + + memcpy(&newNode->tail[0], + &oldNode->tail[splitLoc], + sizeof(newNode->tail[0]) * shift); + + memset(&oldNode->tail[splitLoc], 0, + sizeof(newNode->tail[0]) * shift); + + memcpy(&newNode->childCount[0], + &oldNode->childCount[splitLoc], + sizeof(newNode->childCount[0]) * shift); + + memset(&oldNode->childCount[splitLoc], 0, + sizeof(newNode->childCount[0]) * shift); + + if (!newNode->leaf) { + for (unsigned int i = 0; i <= newNode->used; i++) { + newNode->head[i].bPtr->parent.bPtr = newNode; + } // for i + } // if newNode isn't a leaf + + tmpInode = GetFirstNode(newNode); + assert(tmpInode); + + if (oldNode == root) { + // allocate a new root node + ++header->treeDepth; + root = allocEmptyNode(); + oldNode->parent.bPtr = root; + newNode->parent.bPtr = root; + // strncpy(root->keys[0], newNode->keys[0], B_MAX_NAME_LENGTH); + strncpy(root->keys[0], tmpInode->name, B_MAX_NAME_LENGTH); + root->head[0].bPtr = oldNode; + root->tail[0].bPtr = root->tail[1].bPtr = NULL; + root->head[1].bPtr = newNode; + root->used = 1; + root->leaf = false; + root->present[0] = root->present[1] = true; + root->childCount[0] = root->childCount[1] = 0; +// root->childCount[0] = oldNode->used; +// root->childCount[1] = newNode->used; + +// cout << "parent" << endl; +// Info(newNode->parent); +// cout << "oldNode" << endl; +// Info(oldNode); +// cout << "-----" << endl; +// cout << "newNode" << endl; +// Info(newNode); +// cout << "-----" << endl; + + } else { + insertNode(newNode->parent.bPtr, tmpInode->name, newNode); + // if (oldNode->parent->used == B_MAX_KEYS) splitNode(oldNode->parent); + } // else + return; +} // bTree::splitNode + +void +bTree::insertNode(bNode * node, const char * key, bNode * headPtr) { + unsigned int curSlot = 0; + if (node == NULL || key == NULL) return; + + if (strcmp(key, node->keys[node->used-1]) >= 0){ + curSlot = node->used; + memset(node->keys[curSlot], 0, B_MAX_NAME_LENGTH); + strncpy(node->keys[curSlot], key, B_MAX_NAME_LENGTH); + node->head[curSlot+1].bPtr = headPtr; + node->tail[curSlot+1].bPtr = NULL; + node->present[curSlot+1] = true; + node->childCount[node->used] = 0; // maybe? + + } else { + + for (curSlot = 0; curSlot < node->used; curSlot++) { + if (strcmp(key, node->keys[curSlot]) < 0) break; + } // for + + /* + * note that there is one more item for everything but keys + * So, make the shift count +1 and just subtract it from the key shift + * later + */ + int shift = node->used - curSlot +1; + + memmove(&node->head[curSlot+1], + &node->head[curSlot], + sizeof(node->head[0]) * shift); + memmove(&node->tail[curSlot+1], + &node->tail[curSlot], + sizeof(node->tail[0]) * shift); + memmove(&node->present[curSlot+1], + &node->present[curSlot], + sizeof(node->present[0]) * shift); + memmove(&node->childCount[curSlot+1], + &node->childCount[curSlot], + sizeof(node->childCount[0]) * shift); + + memmove(&node->keys[curSlot+1], + &node->keys[curSlot], + sizeof(node->keys[0]) * (shift-1)); + + memset(node->keys[curSlot], 0, B_MAX_NAME_LENGTH); + strncpy(node->keys[curSlot], key, B_MAX_NAME_LENGTH); + node->head[curSlot+1].bPtr = headPtr; + node->tail[curSlot+1].bPtr = NULL; + node->present[curSlot+1] = true; +// node->childCount[node->used] = ?; + } // else + if (++node->used == B_MAX_KEYS) splitNode(node); + return; +} // bTree::insertNode + +bNode * +bTree::allocEmptyNode(void) { + bNode * newNode = new bNode; + + memset(newNode, 0, sizeof(bNode)); + newNode->magic1 = B_NODE_MAGIC_1; + newNode->magic2 = B_NODE_MAGIC_2; + newNode->parent.bPtr = NULL; + newNode->tag = ++tag; // this will start at 1 (0 is the header node) + return newNode; +} // bTree::allocEmptyNode + +void +bTree::Info(const bNode * node) { + ubixfsInode * inode = NULL; + if (node == NULL || root == NULL) return; + cout << node << " | " << node->parent.bPtr << endl; + for (unsigned int i = 0; i <= node->used; i++) { + inode = node->head[i].iPtr; +// cout << "(" << node->childCount[i] << ")"; + for (unsigned int k = 0; k < node->childCount[i]; k++) { + cout << "[" << inode->name << "]"; + inode = inode->next.iPtr; + } // for k + if (i != node->used) cout << " {" << node->keys[i] << "} "; + } // for i + cout << endl; + return; +#if 0 + for (unsigned int i = 0; i < node->used; i++) { + cout << "keys[" << i << "]: " << node->keys[i] << " "; + } // for i + cout << endl; + cout << "node->used: " << node->used << endl; + cout << "leaf: " << node->leaf << endl; + for (unsigned int i = 0; i <= node->used; i++) { + inode = (ubixfsInode *)node->head[i]; +cout << "node->childCount["<childCount[i] << endl; + for (unsigned int j = 0; j < node->childCount[i]; j++) { + assert(inode); + cout << "[" << i << "].[" << j << "]->" << inode->name << endl; + inode = inode->next; + } // for j + } // for i +#endif +} // bTree::Info + +void +bTree::Info(void) { + ubixfsInode * inode = NULL; + + cout << "tree depth: " << header->treeDepth << endl; + cout << "tree width: " << header->treeWidth << endl; + cout << "tree leaf count: " << header->treeLeafCount << endl; + cout << "tag: " << tag << endl; + + if (root == NULL) return; + + for (unsigned int i = 0; i <= root->used; i++) { + cout << "CC[" << i << "]: " << root->childCount[i] << " "; + } // for i + + cout << endl; + for (unsigned int i = 0; i <= root->used; i++) { + cout << "CH[" << i << "]: " << root->head[i].bPtr << " "; + } // for i + + cout << endl; + for (unsigned int i = 0; i <=root->used; i++) { + cout << "CT[" << i << "]: " << root->tail[i].bPtr << " "; + } // for i + cout << endl; + for (unsigned int i = 0; i < root->used; i++) { + cout << "keys[" << i << "]: " << root->keys[i] << " "; + } // for i + cout << endl; + +cout << "root->used: " << root->used << endl; + for (unsigned int i = 0; i <= root->used; i++) { + inode = root->head[i].iPtr; +cout << "root->childCount["<childCount[i] << endl; + if (root->leaf) { +cout << "root contains leaf node" << endl; + for (unsigned int j = 0; j < root->childCount[i]; j++) { + assert(inode); + cout << "[" << i << "].[" << j << "]->" << inode->name << endl; + inode = inode->next.iPtr; + } // for j + } // if root->leaf + } // for i +} // bTree::Info + +void +bTree::Print(void) { + ubixfsInode * node = GetFirstNode(); + while (node != NULL) { + cout << node->name << endl; + node = node->next.iPtr; + } +} // bTree::Print + +ubixfsInode * +bTree::Find(const char * key) { +/* + ubixfsInode * tmp = GetFirstNode(); + while (tmp!=NULL) { + if (strcmp(tmp->name, key) == 0) return tmp; + tmp = tmp->next.iPtr; + } + return NULL; +*/ + return treeSearch(root, key); +} // bTree::Find + +ubixfsInode * +bTree::inodeSearch(ubixfsInode * inode, const char * key) { + if (inode == NULL || key == NULL) return NULL; + int result = strcmp(inode->name, key); + if (result == 0) return inode; + + if (result < 0) { + inode = inode->next.iPtr; + while (inode != NULL && ((result = strcmp(inode->name, key)) < 0)) { + inode = inode->next.iPtr; + } // while + } else { + inode = inode->prev.iPtr; + while (inode != NULL && ((result = strcmp(inode->name, key)) > 0)) { + inode = inode->prev.iPtr; + } // while + } // else + return (result == 0 ? inode : NULL); +} // bTree::inodeSearch + +ubixfsInode * +bTree::treeSearch(bNode * bnode, const char * key) { + + if (bnode == NULL || key == NULL || bnode->used == 0) return NULL; + + if (bnode->leaf) + return inodeSearch(GetFirstNode(bnode), key); + + if (strcmp(key, bnode->keys[0]) < 0) { + return treeSearch(bnode->head[0].bPtr, key); + } // if + + if (strcmp(key, bnode->keys[bnode->used-1]) >= 0) { + return treeSearch(bnode->head[bnode->used].bPtr, key); + } // if + + for (unsigned int i = 1; i < bnode->used; i++) { + if (strcmp(key, bnode->keys[i]) < 0) { + return treeSearch(bnode->head[i].bPtr, key); + } // if + } // for i + + return NULL; +} // bTree::treeSearch + +ubixfsInode * +bTree::GetFirstNode(void) { + return GetFirstNode(root); +} // bTree::GetFirstNode + +ubixfsInode * +bTree::GetFirstNode(bNode * node) { + bNode * tmpNode = node; + + if (tmpNode == NULL) return NULL; + + while (!tmpNode->leaf) { + for (unsigned int i = 0; i < tmpNode->used; i++) { + if (tmpNode->head[i].bPtr != NULL) { + tmpNode = tmpNode->head[i].bPtr; + break; + } // if + } // for i + } // while + + for (unsigned int i = 0; i < tmpNode->used; i++) { + if (tmpNode->head[i].iPtr != NULL) return tmpNode->head[i].iPtr; + } // for i + return NULL; +} // bTree::GetFirstNode + +bNode * +bTree::findLeafNode(bNode * node, const char * key) { + assert(node); + assert(key); + if (node == NULL || key == NULL) return NULL; + assert(node->used); + if (node->leaf) return node; + + if (strcmp(key, node->keys[0]) < 0) + return findLeafNode(node->head[0].bPtr, key); + + if (strcmp(key, node->keys[node->used-1]) >= 0) + return findLeafNode(node->head[node->used].bPtr, key); + + for (unsigned int i = 1; i < node->used; i++) { + if (strcmp(key, node->keys[i]) < 0) + return findLeafNode(node->head[i].bPtr, key); + } // for i + + return NULL; +} // bTree::findLeafNode + +void +bTree::saveNode(FILE * fd, bNode * node, void * tmpPtr) { + + bNode * ptr = (bNode *)tmpPtr; + assert(tmpPtr); + assert(fd); + assert(node); + cout << "writing tag: " << node->tag << endl; + + memcpy(tmpPtr, node, sizeof(bNode)); + + if (node->parent.bPtr != NULL) + ptr->parent.offset = node->parent.bPtr->tag * sizeof(bNode); + else + ptr->parent.offset = 0; + + for (unsigned int i = 0; i <= node->used; i++) { + bNode * bPtr = node->head[i].bPtr; + + if (bPtr != NULL) + ptr->head[i].offset = bPtr->tag * sizeof(bNode); + else + ptr->head[i].offset = ~0; + ptr->present[i] = false; + } // for i + + if (node->leaf) { + + for (unsigned int i = 0; i <= node->used; i++) { + // ubixfsInode * inode = node->head[i].iPtr; + // mji if (inode != NULL) tmp->head[i] = inode-> + } // for i + } else { + + for (unsigned int i = 0; i <= node->used; i++) { + + if (node->head[i].bPtr != NULL) saveNode(fd, node->head[i].bPtr, tmpPtr); + + } // for i + + } // else + + return; +} // bTree::saveNode + +bool +bTree::Save(const char * filename) { + ubixfsInode * uPtr = NULL; + if (filename == NULL) return false; + FILE * fd = NULL; + if ((fd = fopen(filename, "wb+")) == NULL) return false; + +cout << "tags: " << tag << endl; + lseek(fileno(fd), tag * sizeof(bNode), SEEK_END); + + header->firstNodeOffset = sizeof(bNode); + header->firstDeleted = -1; + void * tmpPtr = malloc(sizeof(bNode)); + assert(tmpPtr); + uPtr = (ubixfsInode *)tmpPtr; + memset(tmpPtr, 0, sizeof(bNode)); + fwrite(header, sizeof(bTreeHeader), 1, fd); + saveNode(fd, root, tmpPtr); + + fclose(fd); + free(tmpPtr); + return true; +} // bTree::Save + +bool +bTree::Load(const char * filename) { + if (filename == NULL) return false; + return true; +} // bTree::Load + +bool +bTree::Delete(const char * key) { + + if (key == NULL) return false; + return true; +} // bTree::Delete + +bool +bTree::Verify(void) { + ubixfsInode * node = GetFirstNode(); + if (node == NULL) return true; + + while (node != NULL) { + ubixfsInode * next = node->next.iPtr; + if (next != NULL) { + // cout << node->name << "::" << node->next->name << ":::" << strcmp(node->name, node->next->name) << endl; + if (strcmp(node->name, next->name) > 0) return false; + } + node = next; + } // while + return true; +} // bTree::Verify + +void +bTree::Print(bNode * node) { + if (node == NULL) return; + Info(node); + if (!node->leaf) + for (unsigned int i = 0; i <= node->used; i++) { + Print(node->head[i].bPtr); + } // for i +} // bTree::Print + +void +bTree::PrintWholeTree(void) { + Print(root); +} // bTree::PrintWholeTree; + +bTree::~bTree(void) { + cout << "tree depth: " << header->treeDepth << endl; + cout << "tree width: " << header->treeWidth << endl; + cout << "tree leaf count: " << header->treeLeafCount << endl; +} // bTree::~bTree diff --git a/ubixfsv2/btree.h b/ubixfsv2/btree.h new file mode 100644 index 0000000..edd28ee --- /dev/null +++ b/ubixfsv2/btree.h @@ -0,0 +1,70 @@ +#ifndef BTREE_H +#define BTREE_H + +#include + +#include "ubixfs.h" +#include "btreeheader.h" +#include "file.h" + +#define B_NODE_MAGIC_1 0xDEADBEEF +#define B_NODE_MAGIC_2 0x1900BABE + +#define B_MAX_KEYS 15 +#define B_MAX_NAME_LENGTH 240 +#define B_MAX_CHILD_COUNT 4 + +// if any of these structs change they have to be updated in the format +// utility too + +typedef struct bNode { + uInt32 magic1 __attribute__ ((packed)); + uInt32 used __attribute__ ((packed)); + uPtr parent __attribute__ ((packed)); + uInt64 tag __attribute__ ((packed)); + char keys[B_MAX_KEYS][B_MAX_NAME_LENGTH] __attribute__ ((packed)); + bool present[B_MAX_KEYS+1] __attribute__ ((packed)); + uPtr head[B_MAX_KEYS+1] __attribute__ ((packed)); + uPtr tail[B_MAX_KEYS+1] __attribute__ ((packed)); + uInt32 childCount[B_MAX_KEYS+1] __attribute__ ((packed)); + uInt32 magic2 __attribute__ ((packed)); + bool leaf __attribute__ ((packed)); + char reserved[131] __attribute__ ((packed)); +} bNode; // bNode + +struct ubixfsInode; + +class bTree { + protected: + bNode * root; + UbixFS * fs; + bTreeHeader * header; + fileDescriptor * fd; + uInt32 tag; + ubixfsInode * treeSearch(bNode *, const char *); + ubixfsInode * inodeSearch(ubixfsInode *, const char *); + void splitNode(bNode *); + bNode * allocEmptyNode(void); + void insertNode(bNode *, const char *, bNode *); + bNode * findLeafNode(bNode *, const char *); + void Print(bNode *); + void saveNode(FILE *, bNode *, void *); + public: + bTree(const char *, ubixfsInode *); + bTree(UbixFS *, fileDescriptor *); + ubixfsInode * Find(const char *); + ubixfsInode * GetFirstNode(void); + ubixfsInode * GetFirstNode(bNode *); + bool Delete(const char *); + void Info(void); + void Info(const bNode *); + bool Insert(const char *, ubixfsInode *); + bool Save(const char *); + bool Load(const char *); + void Print(void); + void PrintWholeTree(void); + bool Verify(void); + ~bTree(void); + friend class UbixFS; +}; // bTree +#endif // !BTREE_H diff --git a/ubixfsv2/btreeheader.h b/ubixfsv2/btreeheader.h new file mode 100644 index 0000000..be72012 --- /dev/null +++ b/ubixfsv2/btreeheader.h @@ -0,0 +1,13 @@ +#ifndef BTREEHEADER_H +#define BTREEHEADER_H + +typedef struct bTreeHeader { + uInt32 treeDepth; + uInt32 treeWidth; + uInt32 treeLeafCount; + off_t firstNodeOffset; // used when tree is on disk + off_t firstDeleted; // used to point to an empty node + char paddington[4068]; +} bTreeHeader; // bTreeHeader + +#endif /* !BTREEHEADER_H */ diff --git a/ubixfsv2/device.h b/ubixfsv2/device.h new file mode 100644 index 0000000..e4593f7 --- /dev/null +++ b/ubixfsv2/device.h @@ -0,0 +1,147 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +// #include +#include +#include "types.h" + +struct device_node { + struct device_node *prev; + struct device_node *next; + struct device_t *devInfo; + struct device_resource *devRec; + char type; + int minor; + }; + +struct device_resource { + uInt8 irq; + }; + +typedef struct device_t { + int major; + void *info; + uInt32 sectors; + int (*read)(device_t *, void *, off_t, size_t); + int (*write)(device_t *, void *, off_t, size_t); + int (*reset)(void *); + int (*init)(device_t *); + void (*ioctl)(void *); + void (*stop)(void *); + void (*start)(void *); + void (*standby)(void *); + }; + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:44 reddawg + no message + + Revision 1.4 2004/09/20 00:53:04 flameshadow + chg: UbixFS::vfs_read() now works for direct block extents + chg: UbixFS::vfs_read() returns ~0 on error, or the size read in on success + chg: UbixFS::root member is now a fileDescriptor + chg: UbixFS::vfs_init() creates a file descriptor for the root dir + chg: UbixFS::vfs_format() now sets all values in the bTreeHeader before writing + chg: UbixFS::vfs_format() sets the inode magic number + chg: device_t::read(device_t *, void *, off_t, size_t) + chg: device_t::write(device_t *, void *, off_t, size_t) + chg: vfs_abstract::vfs_read(fileDescriptor *, void *, off_t, size_t) + chg: vfs_abstract::vfs_write(fileDescriptor *, void *, off_t, size_t) + chg: ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length) + chg: ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length) + + Revision 1.3 2004/09/13 15:21:26 flameshadow + add: ramdrive.h + chg: renamed device_t.size to sectors + chg: made #define for size of ramdisk + chg: calculated sectors of ramdisk and stored in the device_t struct + + Revision 1.2 2004/09/11 22:05:59 flameshadow + chg: modified UbixFS::vfs_format() to properly init the device + chg: modified UbixFS::vfs_init() to verify that it's a ubixfs partition + add: added BAT blockRun in the superBlock + + Revision 1.1 2004/09/11 12:43:42 flameshadow + add: device.h, types.h. Temporarily moved custom ubix typedefs to types.h + ( supercedes this file when this code is included into + the kernel) + chg: changed dev_t to device_interface so as to not conflict with bsd/linux + definitions + chg: fixed up compiler warnings in btree.cpp + + Revision 1.14 2004/08/15 00:33:02 reddawg + Wow the ide driver works again + + Revision 1.13 2004/08/14 21:56:44 reddawg + Added initialized byte to the device system to make it easy to add child devices which use parent hardware. + + Revision 1.12 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + + Revision 1.11 2004/05/22 02:40:04 ionix + + + fixed typo in device.h and initialized previous in device.c :) + + Revision 1.10 2004/05/22 02:34:03 ionix + + + Added proto + + Revision 1.9 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ + diff --git a/ubixfsv2/file.h b/ubixfsv2/file.h new file mode 100644 index 0000000..7d8f1f3 --- /dev/null +++ b/ubixfsv2/file.h @@ -0,0 +1,14 @@ +#ifndef FILE_H +#define FILE_H + +#include "ubixfs.h" + +typedef struct fileDescriptor { + struct fileDescriptor * prev; + struct fileDescriptor * next; + void * inode; + off_t offset; + size_t size; +} fileDescriptor; + +#endif /* !FILE_H */ diff --git a/ubixfsv2/fsAbstract.h b/ubixfsv2/fsAbstract.h new file mode 100644 index 0000000..9658881 --- /dev/null +++ b/ubixfsv2/fsAbstract.h @@ -0,0 +1,46 @@ +#ifndef FSABSTRACT_H +#define FSABSTRACT_H + +#include +#include +#include +#include +#include "file.h" + +class vfs_abstract { + protected: + vfs_abstract * prev; + vfs_abstract * next; + device_t * device; + public: + /* File I/O */ + virtual int vfs_open(const char *, fileDescriptor *,int,...) { return -1; }; + virtual int vfs_close(fileDescriptor *) { return -1; }; + virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t) + { return 0; }; + virtual size_t vfs_write(fileDescriptor *, void *, off_t, size_t) + { return 0; }; + + /* Dir I/O */ + virtual int vfs_opendir(DIR *,const char *) { return -1; }; + virtual int vfs_closedir(DIR *) { return -1; }; + virtual int vfs_mkdir(const char *, mode_t) { return -1; }; + virtual int vfs_rmdir(const char *) { return -1; }; + virtual int vfs_readdir(DIR *,struct dirent *) { return -1; }; + + /* FS Functions */ + virtual int vfs_init(void) { return -1; }; + virtual int vfs_format(device_t *) { return -1; }; + virtual void * vfs_mknod(const char *, mode_t) { return NULL; }; + virtual int vfs_purge(void) { return -1; }; + virtual int vfs_stop(void) { return -1; }; + virtual int vfs_sync(void) { return -1; }; + + /* Misc Functions */ + virtual int vfs_unlink(const char *) { return -1; }; + virtual int vfs_rename(const char *,const char *) { return -1; }; + + virtual ~vfs_abstract(void) { }; +}; // vfs_FS + +#endif // !FSABSTRACT_H diff --git a/ubixfsv2/main.cpp b/ubixfsv2/main.cpp new file mode 100644 index 0000000..8bdff45 --- /dev/null +++ b/ubixfsv2/main.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include "vfs.h" +#include "btree.h" +#include "ubixfs.h" +#include "device.h" +#include "ramdrive.h" +using namespace std; + +int +main(void) { + + device_t * ramDrive = dev_ramDrive(); + UbixFS * fs = new UbixFS(ramDrive); + fs->vfs_format(ramDrive); + fs->vfs_init(); + fs->vfs_mkdir("/testdir", 0); + fs->vfs_stop(); + dev_ramDestroy(); + +#if 0 + int i = 0; + ubixfsInode * inode = (ubixfsInode *)malloc(sizeof(ubixfsInode)); + memset(inode, 0, sizeof(ubixfsInode)); + strcpy(inode -> name, "50"); + bTree * tree = new bTree(".", inode); + + for (i = 0; i < 100; i++) { +// while (tree->Verify()) { +// if (i%1000 == 0) cout << "-_- i = "<name[k] = (char)((random() % 26)+'a'); + } // for k +// tree->Insert(inode); + if (!tree->Insert(inode->name, inode)) cout << "Insert(" << inode->name << ") failed" << endl; +// ++i; + } // for i +// cout << "i made it to: " << i << endl; + + i = 0; + ubixfsInode * tmpInode = tmpInode = tree->GetFirstNode(); + if (tmpInode == NULL) cout << "GetFirstNode() returns null" << endl; + while (tmpInode != NULL) { + //cout << "node[" << i++ << "]: " << tmpInode->name << endl; + cout << tmpInode->name << endl; + tmpInode = tmpInode->next.iPtr; + } // while + + +// tree->Info(); + tree->Save("tree.dat"); + free(inode); + delete tree; +#endif + cout << "sizeof(bNode): " << sizeof(struct bNode) << endl; + cout << "sizeof(ubixfsInode): " << sizeof(struct ubixfsInode) << endl; + cout << "sizeof(diskSuperBlock): " << sizeof(struct diskSuperBlock) << endl; + cout << "sizeof(bTreeHeader): " << sizeof(struct bTreeHeader) << endl; + return 0; +} diff --git a/ubixfsv2/ramdrive.cpp b/ubixfsv2/ramdrive.cpp new file mode 100644 index 0000000..db9ce9c --- /dev/null +++ b/ubixfsv2/ramdrive.cpp @@ -0,0 +1,182 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include "device.h" + + +static char *ram_data = 0x0; + +#define RAM_DRIVE_SIZE 1024*1024*100 + +static +int +ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length) { + char *data = ram_data + (offset*512); + assert(ram_data); + assert(offset+length <= dev->sectors); + memcpy(ptr, data, length * 512); + + return(length); +} + +static +int +ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length) { + char *data = ram_data + (offset*512); + assert(ram_data); + + assert(offset+length <= dev->sectors); + + memcpy(data, ptr, length * 512); + + return(length); +} + +device_t * +dev_ramDrive(void) { + device_t *ramDrive = 0x0; + + FILE *ramDisk; + + ramDisk = fopen("./ram.dsk","rb"); + + ramDrive = (device_t *)malloc(sizeof(device_t)); + + ram_data = (char *)malloc(RAM_DRIVE_SIZE); + + if (ramDisk != 0x0) { + printf("Loaded Ram Disk\n"); + fread(ram_data,RAM_DRIVE_SIZE,1,ramDisk); + fclose(ramDisk); + } + + ramDrive->major = 0x1; + ramDrive->sectors = RAM_DRIVE_SIZE / 512; + + ramDrive->read = ramDrive_read; + ramDrive->write = ramDrive_write; + + printf("leaving dev_ramDrive()\n"); + return(ramDrive); + +} // dev_ramDrive + +int +dev_ramDestroy(void) { + printf("dev_ramDestroy()\n"); + FILE *ramDisk; + + ramDisk = fopen("./ram.dsk","wb"); + + fwrite(ram_data, RAM_DRIVE_SIZE ,1,ramDisk); + + fclose(ramDisk); + + printf("Saved Ram Disk\n"); + + return(0x0); +} // dev_ramDestroy + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:45 reddawg + no message + + Revision 1.5 2004/09/20 00:53:04 flameshadow + chg: UbixFS::vfs_read() now works for direct block extents + chg: UbixFS::vfs_read() returns ~0 on error, or the size read in on success + chg: UbixFS::root member is now a fileDescriptor + chg: UbixFS::vfs_init() creates a file descriptor for the root dir + chg: UbixFS::vfs_format() now sets all values in the bTreeHeader before writing + chg: UbixFS::vfs_format() sets the inode magic number + chg: device_t::read(device_t *, void *, off_t, size_t) + chg: device_t::write(device_t *, void *, off_t, size_t) + chg: vfs_abstract::vfs_read(fileDescriptor *, void *, off_t, size_t) + chg: vfs_abstract::vfs_write(fileDescriptor *, void *, off_t, size_t) + chg: ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length) + chg: ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length) + + Revision 1.4 2004/09/13 20:10:11 flameshadow + chg: UbixFS::vfs_format() works + chg: UbixFS::vfs_init() works + + Revision 1.3 2004/09/13 15:48:29 flameshadow + chg: oops, the ramDrive is 100MB, not 512MB + + Revision 1.2 2004/09/13 15:21:26 flameshadow + add: ramdrive.h + chg: renamed device_t.size to sectors + chg: made #define for size of ramdisk + chg: calculated sectors of ramdisk and stored in the device_t struct + + Revision 1.1 2004/09/13 14:37:49 flameshadow + add: ramdrive.cpp + chg: added ramdrive to the makefile + chg: finished root dir inode initialization and saving in UbixFS::format() + + Revision 1.8 2004/08/30 13:29:08 reddawg + Fixed ramdisk to write/read 512 blocks + + Revision 1.7 2004/08/13 22:06:54 reddawg + UbixFS: fixed the test shell + + Revision 1.6 2004/08/13 21:47:49 reddawg + Fixed + + Revision 1.5 2004/08/13 17:25:06 reddawg + Testing better + + Revision 1.4 2004/08/13 17:07:32 reddawg + Works + + Revision 1.3 2004/08/13 16:58:57 reddawg + test + + Revision 1.2 2004/08/13 16:54:14 reddawg + fixed + + Revision 1.1 2004/08/13 16:51:55 reddawg + Start of ubixfs shell + + END + ***/ + diff --git a/ubixfsv2/ramdrive.h b/ubixfsv2/ramdrive.h new file mode 100644 index 0000000..edcf041 --- /dev/null +++ b/ubixfsv2/ramdrive.h @@ -0,0 +1,65 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#ifndef __RAMDRIVE_H_ +#define __RAMDRIVE_H_ + +#include + +int dev_ramDestroy(); +device_t *dev_ramDrive(); + +#endif + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:54 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:15 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:45 reddawg + no message + + Revision 1.1 2004/09/13 15:21:26 flameshadow + add: ramdrive.h + chg: renamed device_t.size to sectors + chg: made #define for size of ramdisk + chg: calculated sectors of ramdisk and stored in the device_t struct + + Revision 1.1 2004/08/13 21:47:49 reddawg + Fixed + + END + ***/ + diff --git a/ubixfsv2/types.h b/ubixfsv2/types.h new file mode 100644 index 0000000..0cad845 --- /dev/null +++ b/ubixfsv2/types.h @@ -0,0 +1,11 @@ +#ifndef TYPES_H +#define TYPES_H + +typedef signed char int8; +typedef unsigned char uInt8; +typedef unsigned int uInt32; +typedef int int32; +typedef unsigned long long uInt64; +typedef signed long long int64; + +#endif /* !TYPES_H */ diff --git a/ubixfsv2/ubixfs.cpp b/ubixfsv2/ubixfs.cpp new file mode 100644 index 0000000..f938ddb --- /dev/null +++ b/ubixfsv2/ubixfs.cpp @@ -0,0 +1,989 @@ +#include +#include +#include +#include +#include +#include + +#include "ubixfs.h" +#include "btree.h" + +using namespace std; + +UbixFS::UbixFS(void) { + device = NULL; + freeBlockList = NULL; + superBlock = NULL; + root = NULL; +} // UbixFS::UbixFS + + +UbixFS::UbixFS(device_t * dev) { + device = dev; + freeBlockList = NULL; + superBlock = NULL; + root = NULL; +} // UbixFS::UbixFS + +void +UbixFS::printSuperBlock(void) { + printf("superBlock->name........... %s\n", superBlock->name); + printf("superBlock->magic1......... %X\n", superBlock->magic1); + printf("superBlock->fsByteOrder.... %d\n", superBlock->fsByteOrder); + printf("superBlock->blockSize...... %d\n", superBlock->blockSize); + printf("superBlock->blockShift..... %d\n", superBlock->blockShift); + printf("superBlock->numBlocks...... %lld\n", superBlock->numBlocks); + printf("superBlock->usedBlocks..... %lld\n", superBlock->usedBlocks); + printf("superBlock->batSectors..... %d\n", superBlock->batSectors); + printf("superBlock->inodeCount..... %d\n", superBlock->inodeCount); + printf("superBlock->magic2......... %X\n", superBlock->magic2); + printf("superBlock->blocksPerAG.... %d\n", superBlock->blocksPerAG); + printf("superBlock->AGShift........ %d\n", superBlock->AGShift); + printf("superBlock->numAGs......... %d\n", superBlock->numAGs); + printf("superBlock->lastUsedAG..... %d\n", superBlock->lastUsedAG); + printf("superBlock->flags.......... %X\n", superBlock->flags); + printf("superBlock->magic3......... %X\n", superBlock->magic3); + return; +} // UbixFS::printSuperBlock + +int +UbixFS::vfs_init(void) { +assert(device); + size_t result; + cout << "vfs_init()" << endl; + assert(device); + + if (device == NULL) return -1; + if (superBlock != NULL) delete superBlock; + superBlock = new diskSuperBlock; +assert(superBlock); + if (superBlock == NULL) return -1; + + // read in the superBlock. It's always the last block on the partition +cout << "reading in superBlock" << endl; + device->read(device, superBlock, device->sectors-1, 1); +cout << "done" << endl; + + assert(superBlock->magic1 == UBIXFS_MAGIC1); + assert(superBlock->magic2 == UBIXFS_MAGIC2); + assert(superBlock->magic3 == UBIXFS_MAGIC3); + assert(strcmp(superBlock->name, "UbixFS") == 0); + assert((1 << superBlock->blockShift) == superBlock->blockSize); + assert((unsigned)(1 << superBlock->AGShift) == superBlock->blocksPerAG); + assert(superBlock->flags == UBIXFS_CLEAN); + + if (freeBlockList != NULL) delete [] freeBlockList; + freeBlockList = new signed char[superBlock->batSectors*512]; +assert(freeBlockList); + memset(freeBlockList, 0, superBlock->batSectors*512); + + device->read(device, + freeBlockList, + device->sectors - superBlock->batSectors-1, + superBlock->batSectors + ); // device->read() + + root = new fileDescriptor; + assert(root); + memset(root, 0, sizeof(fileDescriptor)); +cout << "allocating root dir inode" << endl; + root->inode = new ubixfsInode; + memset(root->inode, 0, sizeof(ubixfsInode)); +cout << "root dir inode starting sector: " << + ((superBlock->rootDir.AG << superBlock->AGShift) + + superBlock->rootDir.start) * (superBlock->blockSize / 512) + << endl; + +cout << "reading in root dir inode" << endl; + + device->read(device, + root->inode, + ((superBlock->rootDir.AG << superBlock->AGShift) + + superBlock->rootDir.start) * (superBlock->blockSize / 512), + sizeof(ubixfsInode) / 512 + ); +cout << "done" << endl; + ubixfsInode * rootInode = static_cast(root->inode); + assert(rootInode); + + /* the bTree constructor now loads in the header */ + + rootInode->data.btPtr = new bTree(this, root); + rootInode->data.btPtr->Info(); + printSuperBlock(); + return 0; +} // UbixFS::init + +int +UbixFS::vfs_format(device_t * dev) { + cout << "vfs_format()" << endl; + char sector[512]; + uInt32 blocks, batSect, batSize; + if (dev == NULL) return -1; + + // zero out the sector + memset(§or, 0x0, sizeof(sector)); + + // fill the drive in with zeroed out sectors + cout << "dev->sectors: " << dev->sectors << endl; + cout << "clearing device..."; + + for (unsigned int i = 0; i < dev->sectors; i++) { + dev->write(dev, §or, i, 1); + } // for i + + cout << "done" << endl; + + // allocate a new superBlock and clear it + + diskSuperBlock *sb = new diskSuperBlock; + if (sb == NULL) return -1; + memset(sb, 0, sizeof(diskSuperBlock)); + + // dev->sectors is the number of 512 byte sectors + + blocks = (dev->sectors-1) / 8; // 4k blocks + batSize = (dev->sectors-1) % 8; // remainder + + // compute the BAT size + + while ((batSize * 4096) < blocks) { + batSize += 8; + --blocks; + } // while + + // batSize is in sectors + batSect = blocks * 8; + + strcpy(sb->name, "UbixFS"); + sb->magic1 = UBIXFS_MAGIC1; + sb->fsByteOrder = 0; + sb->blockSize = 4096; + sb->blockShift = 12; + sb->numBlocks = blocks; + sb->usedBlocks = 2; // root dir takes two blocks (inode + bTree header) + sb->inodeCount = 1; + sb->inodeSize = 4096; + sb->magic2 = UBIXFS_MAGIC2; + sb->blocksPerAG = 2048; + sb->AGShift = 11; + sb->numAGs = (sb->numBlocks+2047) / 2048; + sb->lastUsedAG = 0; + + // the BAT exists outside our official block count, so no + // entries in the BAT need to be set for it + sb->batSectors = batSize; + + sb->flags = 0x434C454E; // CLEN + sb->logBlocks.AG = 0; + sb->logBlocks.start = 0; + sb->logBlocks.len = 0; + sb->logStart = 0; + sb->logEnd = 0; + sb->magic3 = UBIXFS_MAGIC3; + sb->indicies.AG = 0; + sb->indicies.start = 0; + sb->indicies.len = 0; + + sb->rootDir.AG = 0; + sb->rootDir.start = 0; + sb->rootDir.len = 1; + + // write out the superBlock + + dev->write(dev, sb, dev->sectors-1, 1); + + // mark the first two 4k blocks used + memset(§or, 0, sizeof(sector)); + sector[0] = (1 << 7) | (1 << 6); + + // write out the first sector of the BAT + + dev->write(dev, §or, batSect, 1); + // clear the rest + sector[0] = 0; + + // write out the rest of the BAT + + for (unsigned int i = 1; i < batSize; i++) { + dev->write(dev, §or, (batSect)+i, 1); + } // for i + + /* allocate part of the root dir */ + + // sanity checks + assert(sb->blockSize); + assert((unsigned)sb->blockSize >= sizeof(bTreeHeader)); + + bTreeHeader * bth = new bTreeHeader; + assert(bth); + memset(bth, 0, sizeof(bTreeHeader)); + + bth->firstDeleted = -1; + bth->firstNodeOffset = -1; + bth->treeDepth = 1; + bth->treeWidth = 0; + bth->treeLeafCount = 0; + + /* create the root dir inode here */ + + ubixfsInode * inode = new ubixfsInode; + assert(inode); + if (inode == NULL) return -1; + memset(inode, 0, sizeof(ubixfsInode)); + + inode->magic1 = UBIXFS_INODE_MAGIC; + + // inodes point to themselves + inode->inodeNum.AG = 0; + inode->inodeNum.start = 0; + inode->inodeNum.len = 1; + + // root dir has no parent directory + inode->parent.iAddr.AG = 0; + inode->parent.iAddr.start = 0; + inode->parent.iAddr.len = 0; + + /* this is part of the root dir structure (the bTreeHeader) */ + inode->blocks.direct[0].AG = 0; + inode->blocks.direct[0].start = 1; + inode->blocks.direct[0].len = 1; + + inode->blocks.maxDirectRange = sizeof(bTreeHeader); + inode->blocks.size = sizeof(bTreeHeader); + + strcpy(inode->name, "/"); + inode->uid = getuid(); + inode->gid = getgid(); + // inode->mode + inode->flags = INODE_DIRECTORY; + // inode->createTime + // inode->lastModifiedTime + // inode->type + + inode->attributes.AG = 0; + inode->attributes.start = 0; + inode->attributes.len = 0; + + inode->inodeSize = sb->inodeSize; + + /* + * next and prev are used in memory to hold pointers to the next/prev + * inodes in this dir. On disk they may have another value, but for + * now they should be set to null. + */ + + inode->next.offset = 0; + inode->prev.offset = 0; + + // write out the "root" dir inode + + dev->write(dev, + inode, + ((inode->inodeNum.AG << sb->AGShift) + + inode->inodeNum.start) * (sb->blockSize / 512), + sb->inodeSize / 512 + ); // dev->write + + // write out the "root" dir + + dev->write(dev, + bth, + ((inode->blocks.direct[0].AG << sb->AGShift) + + inode->blocks.direct[0].start) * (sb->blockSize / 512), + sb->blockSize / 512 + ); // dev->write + + delete inode; + delete bth; + delete sb; + cout << "format complete" << endl; + return 0; +} // UbixFS::vfs_format + +void * +UbixFS::vfs_mknod(const char *path, mode_t mode) { + return mknod(path, 0, mode); // <- this probably isn't correct +} // UbixFS::vfs_mknod + +int +UbixFS::vfs_open(const char * filename, fileDescriptor * fd, int flags, ...) { + if (filename == NULL || fd == NULL) return -1; + flags = flags; + fd->inode = NULL; + fd->offset = 0; + fd->size = 0; + // look up the file here + return 0; +} // UbixFS::vfs_open + +size_t +UbixFS::vfs_read(fileDescriptor * fd, void * data, off_t offset, size_t size) { + + unsigned int i; + off_t sum, startingBlock; + size_t runSize, sectorCount, totalSize, bSize; // blockSize + ubixfsInode * inode = NULL; + + if (fd == NULL || data == NULL) return ~0; + + if (size == 0) return 0; // don't fail if size is 0? + + assert(device); + assert(superBlock); + + inode = static_cast(fd->inode); + + assert(inode); + + bSize = superBlock->blockSize; + + totalSize = sum = i = 0; + + while (size > 0) { + + /* + * place check here to see which set of blocks we're looking through + */ + + // scan through direct blocks + do { + if (offset >= sum && offset < sum + inode->blocks.direct[i].len * bSize) break; + + sum += inode->blocks.direct[i++].len * bSize; + + } while (i < NUM_DIRECT_BLOCKS); + + startingBlock = (inode->blocks.direct[i].AG << superBlock->AGShift) + + inode->blocks.direct[i].start + ((offset - sum) / bSize); + + runSize = inode->blocks.direct[i].len * bSize; + + // startingBlock is in 4k blocks + startingBlock *= (bSize / 512); + // startingBlock is now in sectors + + if (runSize >= size) { + runSize = size; + size = 0; + } else { + size -= runSize; + } // else + + sectorCount = runSize / 512; + + cout << "device->read(device, data, " << startingBlock << ", "; + cout << sectorCount << ");" << endl; + + device->read(device, data, startingBlock, sectorCount); + + (uInt8 *)data += runSize; + totalSize += runSize; + } // while + return totalSize; +} // UbixFS::vfs_read + +size_t +UbixFS::vfs_write(fileDescriptor * fd, void * data, off_t offset, size_t size) { + // char * sector[512]; // used to pad + unsigned int i, whichBlocks; + off_t sum, startingBlock, EORPos, maxRange; + size_t runSize, runRemainder, sectorCount, totalSize, bSize; // blockSize + ubixfsInode * inode = NULL; + blockRun br; + + if (fd == NULL || data == NULL) return ~0; + + if (size == 0) return 0; // don't fail if size is 0? + + assert(device); + assert(superBlock); + + inode = static_cast(fd->inode); + + assert(inode); + + bSize = superBlock->blockSize; + assert(bSize != 0); + + totalSize = sum = i = whichBlocks = 0; + + EORPos = offset + size; // compute End Of Run Position + maxRange = inode->blocks.maxDirectRange; + + if (inode->blocks.maxIndirectRange > maxRange) { + maxRange = inode->blocks.maxIndirectRange; + whichBlocks = 1; + } + + if (inode->blocks.maxDoubleIndirectRange > maxRange) { + maxRange = inode->blocks.maxDoubleIndirectRange; + whichBlocks = 2; + } + + if (EORPos > maxRange) { + /* + * The offset+size is greater than the size of the file, so we need to + * extend out the file. Scan through the direct blocks (FIX LATER) + * to find out where we need to extend + */ + switch (whichBlocks) { + case 0: + while (i < NUM_DIRECT_BLOCKS && inode->blocks.direct[i].len != 0) ++i; + // i holds which direct block we're going to add to + break; + case 1: + case 2: + assert(false); // UNFINISHED + break; + default: + assert(false); // sanity check + } // switch + + /* + * NOTE: it's possible that if we scan through to find where the + * run goes, we might be able to extend the previous block extent. + * This will require that we set up br.start to be where we'd like to + * start looking through the free block list, and then modifying + * getFreeBlock() to honour that. + */ + + br.AG = inode->inodeNum.AG; // request a sane allocation group + br.start = 0; // getFreeBlock() will ignore this + + /* + * The length that we need is determined by how much extra slack we + * already have in the pre-allocated blocks. + * e.g. (assumes 4k blocks) + * bSize = 4096 + * maxRange = 4096 + * size = 3000 + * offset = 3000 + * size = 4000 + * [--- data block ---][--- data block ---] <---- blocks on disk + * <-file data-> <---- actual file size + * <-----> <---- slack + * [ data block size ] <---- maxRange + * | <---- offset + * ***************** <---- new data + * + * In the above example, you'd need at least one more block to write + * out the data. + * ((offset + size) - maxRange + (bSize-1)) / bSize + * ((3000 + 4000) - 4096 + (4095)) / 4096 == 1 (rounded down) + * And then we expand it by a little extra so we don't have to keep + * looking for more blocks. Currently we use 32k of slack (or 8 blocks) + */ + + br.len = ((EORPos - maxRange + (bSize-1)) / bSize); + + if (br.len < 8) br.len = 8; // we allocate 32k if the file needs to grow + + br = getFreeBlock(br); + assert(br.len > 0); + switch (whichBlocks) { + case 0: + inode->blocks.direct[i] = br; + inode->blocks.maxDirectRange += br.len * bSize; + break; + case 1: + assert(false); // UNFINISHED + inode->blocks.maxIndirectRange += br.len * bSize; + break; + case 2: + assert(false); // UNFINISHED + inode->blocks.maxDoubleIndirectRange += br.len * bSize; + break; + default: + assert(false); // sanity check + } // switch + + inode->blocks.size = EORPos; + } // if + + + runRemainder = size % 512; + size -= runRemainder; + + totalSize = sum = i = 0; + + while (size > 0) { + + /* + * place check here to see which set of blocks we're looking through + */ + + // scan through direct blocks + do { + if (offset >= sum && offset < sum + inode->blocks.direct[i].len * bSize) + break; + + sum += inode->blocks.direct[i++].len * bSize; + + } while (i < NUM_DIRECT_BLOCKS); + + startingBlock = (inode->blocks.direct[i].AG << superBlock->AGShift) + + inode->blocks.direct[i].start + ((offset - sum) / bSize); + + runSize = inode->blocks.direct[i].len * bSize; + + // startingBlock is in 4k blocks + startingBlock *= (bSize / 512); + // startingBlock is now in sectors + + if (runSize >= size) { + runSize = size; + size = 0; + } else { + size -= runSize; + } // else + + sectorCount = runSize / 512; + + cout << "device->write(device, data, " << startingBlock << ", "; + cout << sectorCount << ");" << endl; + + device->write(device, data, startingBlock, sectorCount); + + (uInt8 *)data += runSize; + totalSize += runSize; + } // while + + assert(runRemainder != 0); // UNFINISHED + return totalSize; +} // UbixFS::vfs_write + +int +UbixFS::vfs_stop(void) { + if (vfs_sync() != 0) return -1; + + // you must delete the root dir first, in case it needs to + // still write anything out + + if (root != NULL) { + ubixfsInode * rootInode = static_cast(root->inode); + delete rootInode->data.btPtr; + delete rootInode; + root->inode = NULL; + + } // if + + delete root; + delete [] freeBlockList; + delete superBlock; + + freeBlockList = NULL; + superBlock = NULL; + root = NULL; + + /* + * The device isn't null at this point, allowing for people to restart + * the mount point. Or, alternatively, to blow things up. + */ + + return 0; +} // UbixFS::vfs_stop + +int +UbixFS::vfs_sync(void) { + if (device == NULL || superBlock == NULL || freeBlockList == NULL) return -1; + device->write(device, + freeBlockList, + device->sectors - superBlock->batSectors - 1, + superBlock->batSectors + ); + device->write(device, superBlock, device->sectors-1, 1); + return 0; +} // UbixFS::vfs_sync + +void +UbixFS::setFreeBlock(blockRun ibr) { + signed char * ptr; + + if (superBlock == NULL || freeBlockList == NULL) return; + if (ibr.len == 0) return; + ptr = freeBlockList + ((ibr.AG << superBlock->AGShift) >> 3); + ptr += ibr.start >> 3; + + if (ibr.start % 8 != 0) { + + ibr.len -= ibr.start % 8; + } // if + +} // UbixFS::setFreeBlock + +blockRun +UbixFS::getFreeBlock(blockRun ibr) { + signed char * ptr; + signed char * holdPtr; + int32 count, holdCount; + + blockRun obr = {0, 0, 0}; // output block run + + // Check to make sure none of these are null + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return obr; + + if (ibr.len == 0) return obr; + + if (ibr.len > superBlock->numBlocks) return obr; + + if (ibr.len == 1) return getFreeBlock(ibr.AG); + /* + * count is the block from the base of the list. + * Since we're given a specific AG to look through, we start the count at + * AG << AGShift, where AGShift is the shift value of the number of blocks + * in an AG + */ + + count = (ibr.AG << superBlock->AGShift); + + /* + * The freeBlockList is a bit map of the free/used blocks. + * Used = on bit + * Unused = off bit + * There are 8 bits per byte (hopefully) and so we have to divide the count + * by 8 to get our starting byte offset to look from + */ + + ptr = freeBlockList + (count >> 3); + +rescan: + // look for the first free 8 blocks (this may create holes) + while (*ptr != 0) { + ++ptr; + count += 8; + if (count+8 > superBlock->numBlocks) { + ptr = freeBlockList; + count = 0; + } // if + } // while *ptr != 0 + + holdPtr = ptr; + holdCount = count; + + for (unsigned short i = 0; i < ((ibr.len+7) / 8); i++) { + ++ptr; + count += 8; + if (count+8 > superBlock->numBlocks) { + ptr = freeBlockList; + count = 0; + goto rescan; + } // if + if (*ptr != 0) goto rescan; + } // for i + + // we have found a range of blocks that work for us + + obr.AG = holdCount / superBlock->blocksPerAG; + obr.start = holdCount % superBlock->blocksPerAG; + obr.len = ibr.len; + + for (unsigned short i = 0; i < (ibr.len / 8); i++) { + *holdPtr = -1; + ++holdPtr; + } // for + + if (ibr.len % 8 != 0) *holdPtr = (-1 << (8-(ibr.len % 8))); + + superBlock->usedBlocks += ibr.len; // increment the number of used blocks + return obr; +} // UbixFS::getFreeBlock + +blockRun +UbixFS::getFreeBlock(uInt32 AG) { + // AG == AllocationGroup + blockRun br; + signed char * ptr; + int32 count; + int32 subCount = 128; + + br.AG = 0; + br.start = 0; + br.len = 0; + // Check to make sure neither of these are null + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return br; + + // Are there any blocks available? + if (superBlock->numBlocks == superBlock->usedBlocks) return br; + + /* + * count is the block from the base of the list. + * Since we're given a specific AG to look through, we start the count at + * AG << AGShift, where AGShift is the shift value of the number of blocks + * in an AG + */ + + count = (AG << superBlock->AGShift); + + /* + * The freeBlockList is a bit map of the free/used blocks. + * Used = on bit + * Unused = off bit + * There are 8 bits per byte (hopefully) and so we have to divide the count + * by 8 to get our starting byte offset to look from + */ + + ptr = freeBlockList + (count >> 3); + + // Scan through the freeBlockList + +rescan: + while (*ptr == -1) { + ++ptr; + count += 8; + if (count+8 > superBlock->numBlocks) break; + } // while *ptr == -1 + + subCount = 128; + + do { + if ((*ptr & subCount) == 0) break; + subCount >>= 1; + ++count; + if (count == superBlock->numBlocks) { + count = 0; + ptr = freeBlockList; + goto rescan; + } // if + } while(subCount > 1); + + *ptr |= subCount; // mark this block as used + ++superBlock->usedBlocks; // increment the number of used blocks + + br.AG = count / superBlock->blocksPerAG; + br.start = count % superBlock->blocksPerAG; + br.len = 1; + return br; // return the allocated block number +} // Ubixfs::getFreeBlock + +uInt32 +UbixFS::getNextAG(void) { + + if (superBlock->lastUsedAG == superBlock->numAGs) + superBlock->lastUsedAG = 0; + else + superBlock->lastUsedAG++; + return superBlock->lastUsedAG; + +} // UbixFS::getNextAG + +/* + * UbixFS::getFreeBlock(void) + * upon success returns a free block based on the next AG after the lastUsedAG + * failure returns -1 + */ + +blockRun +UbixFS::getFreeBlock(void) { + return getFreeBlock(getNextAG()); +} // UbixFS::getFreeBlock + +blockRun +UbixFS::get8FreeBlocks(uInt32 AG) { + // AG == AllocationGroup + blockRun br; + signed char * ptr; + signed char * endPtr; + int32 count; + + br.AG = 0; + br.start = 0; + br.len = 0; + + if (device == NULL || freeBlockList == NULL || superBlock == NULL) return br; + + // Are there any blocks available? + if (superBlock->usedBlocks+8 > superBlock->numBlocks) return br; + + /* + * count is the block from the base of the list. + * Since we're given a specific AG to look through, we start the count at + * AG << AGShift, where AGShift is the shift value of the number of blocks + * in an AG + */ + + count = (AG << superBlock->AGShift); + + ptr = freeBlockList + (count >> 3); + + endPtr = freeBlockList + (superBlock->numBlocks >> 3); + + bool secondTime = false; + while (*ptr != 0) { + ++ptr; + count += 8; + if (ptr == endPtr) { + if (secondTime) + return br; + else + secondTime = true; + + count = 0; + ptr = freeBlockList; + } // if + } // while + + *ptr = -1; // mark 8 blocks as taken + + br.AG = count / superBlock->blocksPerAG; + br.start = count % superBlock->blocksPerAG; + br.len = 8; + return br; +} // UbixFS::get8FreeBlocks + +void * +UbixFS::mknod(const char *filename, ubixfsInode * parent, mode_t mode) { + ubixfsInode * inode = NULL; + + inode = new ubixfsInode; + assert(inode); + if (inode == NULL) return NULL; + memset(inode, 0, sizeof(ubixfsInode)); + + inode->magic1 = UBIXFS_INODE_MAGIC; + + /* + * in retrospect.. I'm not sure why parent would be null.. only the + * root directory would have a null parent, but that's manually allocated + * in vfs_format() + */ + + if (parent == NULL) { + inode->inodeNum = getFreeBlock(); + inode->parent.iAddr.AG = 0; + inode->parent.iAddr.start = 0; + inode->parent.iAddr.len = 0; + } else { + inode->inodeNum = getFreeBlock(parent->inodeNum.AG); + inode->parent.iAddr = parent->inodeNum; + } // else + + strncpy(inode->name, filename, MAX_FILENAME_LENGTH); + + inode->uid = getuid(); + inode->gid = getgid(); + // inode->mode + inode->flags = mode; + // inode->createTime + // inode->lastModifiedTime + inode->inodeSize = superBlock->inodeSize; + + inode->attributes.AG = 0; + inode->attributes.start = 0; + inode->attributes.len = 0; + + // inode->type + + /* + * next and prev are used in memory to hold pointers to the next/prev + * inodes in this dir. On disk they may have another value, but for + * now they should be set to null. + */ + + inode->next.offset = 0; + inode->prev.offset = 0; + inode->refCount = 0; + ++superBlock->inodeCount; + return inode; +} // UbixFS::mknod + +int +UbixFS::vfs_mkdir(const char * path, mode_t mode) { + char name[MAX_FILENAME_LENGTH]; + unsigned int start, end, len, nameStart; + ubixfsInode * dir = static_cast(root->inode); + ubixfsInode * inode = NULL; + + assert(path); // bad input: vfs_mkdir(NULL); + assert(*path); // bad input: vfs_mkdir(""); + + memset(&name, 0, sizeof(name)); + // find the dir name + len = strlen(path); + + assert(path[0] == '/'); // bad input: vfs isn't doing its job + assert(len > 1); // bad input: mkdir / + + // remove trailing "/" if present + if (path[len-1] == '/') --len; + + assert(len > 1); // bad input: mkdir // + + nameStart = len-1; + + assert(path[nameStart] != '/'); // bad input: mkdir /a// + + /* + * we're guaranteed by the assert() above that there is + * at least one "/" before our location. If you remove the assert + * you might need to make sure nameStart stays above 0 in the following + * while + */ + + while (path[nameStart] != '/') --nameStart; + ++nameStart; + assert(len - nameStart > 0); + + /* e.g. + * v--------------------- start + * v------------------ end + * v------ nameStart + * /usr/local/data/dirname/ <--- ignores trailing / + * <---------23----------> len + */ + + start = end = 1; // skip leading / + while (end < nameStart) { + do { ++end; } while(path[end] != '/'); + + assert(end-start+1 < sizeof(name)); + // this is probably wrong: + strncpy(name, &path[start], end-start+1); + cout << name << endl; + dir = dir->data.btPtr->Find(name); + assert(dir); + assert(dir->flags & INODE_DIRECTORY == INODE_DIRECTORY); + start = ++end; + } + + strncpy(name, &path[nameStart], len - nameStart); + inode = (ubixfsInode *)mknod(name, dir, mode | INODE_DIRECTORY); + + /* + * keep in mind that the reason for passing in the name is because + * we thought about allowing key names to be different from inode + * names. In retrospect, I don't think that's a good idea since a dir + * listing will print the actual dir name instead of . and .. + * Thus: the first parameter of btPtr->Insert() may go away. + */ + + assert(dir->data.btPtr->Insert(inode->name, inode)); + + return 0; +} // UbixFS::vfs_mkdir + +void +UbixFS::printFreeBlockList(uInt32 AG) { + unsigned int j; + if (superBlock == NULL || freeBlockList == NULL) return; + printf("AG = %d\n", AG); + for (unsigned int i = 0; i < superBlock->blocksPerAG / 8; i++) { + j = 128; + signed char foo = freeBlockList[(AG << superBlock->AGShift)+i]; + while (j > 0) { + if ((foo & j) == j) + printf("1"); + else + printf("0"); + j >>= 1; + + } + } // for i + printf("\n"); + return; +} // UbixFS::printFreeBlockList + +UbixFS::~UbixFS(void) { + delete [] freeBlockList; + return; +} diff --git a/ubixfsv2/ubixfs.h b/ubixfsv2/ubixfs.h new file mode 100644 index 0000000..595e6f4 --- /dev/null +++ b/ubixfsv2/ubixfs.h @@ -0,0 +1,163 @@ +#ifndef UBIXFS_H +#define UBIXFS_H + +#include +#include +#include "fsAbstract.h" +#include "types.h" +#include "file.h" + +#define INODE_IN_USE 0x00000001 +#define INODE_DIRECTORY 0x00000002 +#define ATTR_INODE 0x00000004 +#define INODE_LOGGED 0x00000008 +#define INODE_DELETED 0x00000010 +#define PERMANENT_FLAGS 0x0000ffff +#define INODE_NO_CACHE 0x00010000 +#define INODE_WAS_WRITTEN 0x00020000 +#define NO_TRANSACTION 0x00040000 + +#define NUM_DIRECT_BLOCKS 64 +#define MAX_FILENAME_LENGTH 256 + +#define UBIXFS_MAGIC1 0xA0A0A0A +#define UBIXFS_MAGIC2 0xB0B0B0B +#define UBIXFS_MAGIC3 0xC0C0C0C +#define UBIXFS_INODE_MAGIC 0x3bbe0ad9 + +/* befs magic numbers +#define SUPER_BLOCK_MAGIC1 0x42465331 // BFS1 +#define SUPER_BLOCK_MAGIC2 0xdd121031 +#define SUPER_BLOCK_MAGIC3 0x15b6830e + */ +#define UBIXFS_CLEAN 0x434C454E // CLEN +#define UBIXFS_DIRTY 0x44495254 // DIRT + + +typedef struct blockRun { + int AG __attribute__ ((packed)); + unsigned short start __attribute__ ((packed)); + unsigned short len __attribute__ ((packed)); +} inodeAddr; + +struct bNode; +struct ubixfsInode; +class bTree; + +typedef union uPtr { + inodeAddr iAddr; + bNode * bPtr; + bTree * btPtr; + ubixfsInode * iPtr; + void * vPtr; + off_t offset; +}; + +typedef struct diskSuperBlock { + char name[32] __attribute__ ((packed)); + int32 magic1 __attribute__ ((packed)); + int32 fsByteOrder __attribute__ ((packed)); + +// blockSize on disk (4096 for UbixFS v2) + int32 blockSize __attribute__ ((packed)); + +// number of bits needed to shift a block number to get a byte address + uInt32 blockShift __attribute__ ((packed)); + + off_t numBlocks __attribute__ ((packed)); + off_t usedBlocks __attribute__ ((packed)); + +// BlockAllocationTable + uInt32 batSectors __attribute__ ((packed)); + + uInt32 inodeCount __attribute__ ((packed)); + uInt32 inodeSize __attribute__ ((packed)); + uInt32 magic2 __attribute__ ((packed)); + uInt32 blocksPerAG __attribute__ ((packed)); + uInt32 AGShift __attribute__ ((packed)); + uInt32 numAGs __attribute__ ((packed)); + uInt32 lastUsedAG __attribute__ ((packed)); +// flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954) + int32 flags __attribute__ ((packed)); + +// journal information + blockRun logBlocks __attribute__ ((packed)); + off_t logStart __attribute__ ((packed)); + off_t logEnd __attribute__ ((packed)); + + int32 magic3 __attribute__ ((packed)); + +// root dir of the SYS container + inodeAddr rootDir __attribute__ ((packed)); + +// indicies + inodeAddr indicies __attribute__ ((packed)); + + char pad[368] __attribute__ ((packed)); + +} diskSuperBlock; + +typedef struct dataStream { + struct blockRun direct[NUM_DIRECT_BLOCKS] __attribute__ ((packed)); + off_t maxDirectRange __attribute__ ((packed)); + struct blockRun indirect __attribute__ ((packed)); + off_t maxIndirectRange __attribute__ ((packed)); + struct blockRun double_indirect __attribute__ ((packed)); + off_t maxDoubleIndirectRange __attribute__ ((packed)); + off_t size __attribute__ ((packed)); +} dataStream; + +typedef struct ubixfsInode { + int32 magic1 __attribute__ ((packed)); + inodeAddr inodeNum __attribute__ ((packed)); + char name[MAX_FILENAME_LENGTH] __attribute__ ((packed)); + uid_t uid __attribute__ ((packed)); + gid_t gid __attribute__ ((packed)); + int32 mode __attribute__ ((packed)); + int32 flags __attribute__ ((packed)); + // uInt64 createTime __attribute__ ((packed)); + // uInt64 lastModifiedTime __attribute__ (packed)); + inodeAddr attributes __attribute__ ((packed)); + uInt32 type __attribute__ ((packed)); + uInt32 inodeSize __attribute__ ((packed)); + uPtr parent __attribute__ ((packed)); + uPtr next __attribute__ ((packed)); + uPtr prev __attribute__ ((packed)); + uPtr data __attribute__ ((packed)); + dataStream blocks __attribute__ ((packed)); + uInt32 refCount __attribute__ ((packed)); + char smallData[3200] __attribute__ ((packed)); +} ubixfsInode; + +class UbixFS : public vfs_abstract { + protected: + signed char * freeBlockList; + diskSuperBlock * superBlock; + fileDescriptor * root; + + blockRun getFreeBlock(blockRun); + blockRun getFreeBlock(uInt32); + blockRun getFreeBlock(void); + blockRun get8FreeBlocks(uInt32); + uInt32 getNextAG(void); + void * mknod(const char *, ubixfsInode *, mode_t); + void printSuperBlock(void); + void printFreeBlockList(uInt32); + void setFreeBlock(blockRun); + public: + UbixFS(void); + UbixFS(device_t *); + virtual int vfs_init(void); + virtual int vfs_format(device_t *); + virtual void * vfs_mknod(const char *, mode_t); + virtual int vfs_mkdir(const char *, mode_t); + virtual int vfs_open(const char *, fileDescriptor *, int, ...); + virtual size_t vfs_read(fileDescriptor *, void *, off_t, size_t); + virtual size_t vfs_write(fileDescriptor *, void *, off_t, size_t); + virtual int vfs_sync(void); + virtual int vfs_stop(void); + virtual ~UbixFS(void); + friend class bTree; +}; // UbixFS + +#endif // !UBIXFS_H diff --git a/ubixfsv2/vfs.cpp b/ubixfsv2/vfs.cpp new file mode 100644 index 0000000..daa28a7 --- /dev/null +++ b/ubixfsv2/vfs.cpp @@ -0,0 +1,22 @@ +#include +#include "vfs.h" + +DiskFS::DiskFS(const char * filename) { + diskFile = fopen(filename, "r+"); +} // DiskFS::DiskFS + +int +DiskFS::write(const void * data, long offset, long size) { + if (diskFile == NULL) return 1; + fseek(diskFile, offset, SEEK_SET); + fwrite(data, size, 1, diskFile); + return 0; +} // DiskFS::write + +int +DiskFS::read(void * data, long offset, long size) { + if (diskFile == NULL) return 1; + fseek(diskFile, offset, SEEK_SET); + fread(data, size, 1, diskFile); + return 0; +} // DiskFS::read diff --git a/ubixfsv2/vfs.h b/ubixfsv2/vfs.h new file mode 100644 index 0000000..68548e9 --- /dev/null +++ b/ubixfsv2/vfs.h @@ -0,0 +1,25 @@ +#ifndef VFS_H +#define VFS_H + +#include +#include + +class FileSystemAbstract { + protected: + public: + virtual int read(char *, long, long) = 0; + virtual int write(char *, long, long) = 0; + virtual ~FileSystemAbstract(void) {}; +}; // FileSystemAbstract + +class DiskFS : public FileSystemAbstract { + protected: + FILE * diskFile; + public: + DiskFS(const char *); + virtual int write(const void *, long, long); + virtual int read(void *, long, long); + virtual ~DiskFS(void) { }; +}; // DiskFS + +#endif // !VFS_H diff --git a/ufs/Makefile b/ufs/Makefile new file mode 100644 index 0000000..caf1e5e --- /dev/null +++ b/ufs/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = ufs.o ffs.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/ufs/ffs.c b/ufs/ffs.c new file mode 100644 index 0000000..9f6aec0 --- /dev/null +++ b/ufs/ffs.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +int ffs_read(struct file *fd,char *data,uInt32 offset,long size) { + struct fs *fs; + struct ufs_obj *ufsObj = fd->fsObj; + + fs = (struct fs *)ufsObj->dmadat->sbbuf; + + if (offset < fd->size && offset >= fs->fs_maxfilesize) { + //return (EOVERFLOW); + return(-1); + } + + kprintf("Reading File w/ New Function [0x%X]\n",fs->fs_maxfilesize); + return(0x0); + } diff --git a/ufs/ufs.c b/ufs/ufs.c new file mode 100644 index 0000000..3b98fdc --- /dev/null +++ b/ufs/ufs.c @@ -0,0 +1,381 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define VBLKSHIFT 12 +#define VBLKSIZE (1 << VBLKSHIFT) +#define VBLKMASK (VBLKSIZE - 1) +#define DBPERVBLK (VBLKSIZE / DEV_BSIZE) +#define INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT)) +#define INOPB(fs) ((fs)->fs_inopb) +#define INO_TO_VBA(fs, ipervblk, x) \ + (fsbtodb(fs, cgimin(fs, ino_to_cg(fs, x))) + \ + (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK)) +#define INO_TO_VBO(ipervblk, x) ((x) % ipervblk) + + +static int dskread(void *buf, u_int64_t block,size_t count,struct file *fd) { + /* + kprintf("Buf: [0x%X]\n",buf); + kprintf("Block: [0x%X]\n",block); + kprintf("Count: [0x%X]\n",count); + kprintf("FD: [0x%X]\n",fd); + kprintf("MP: [0x%X]\n",fd->mp); + kprintf("Device: [0x%X]\n",fd->mp->device); + */ + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,buf,block,count); + return(0x0); + } + +//struct dmadat { +// char blkbuf[VBLKSIZE]; /* filesystem blocks */ +// char indbuf[VBLKSIZE]; /* indir blocks */ +// char sbbuf[SBLOCKSIZE]; /* superblock */ +// char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ +// }; +//static struct dmadat *dmadat; + +//static int ls,dsk_meta; + +static int sblock_try[] = SBLOCKSEARCH; + +#if defined(UFS2_ONLY) +#define DIP(field) dp2.field +#elif defined(UFS1_ONLY) +#define DIP(field) dp1.field +#else +#define DIP(field) fs->fs_magic == FS_UFS1_MAGIC ? dp1.field : dp2.field +#endif + + +static ssize_t fsread(ino_t inode, void *buf, size_t nbyte,struct file *fd) { + #ifndef UFS2_ONLY + static struct ufs1_dinode dp1; + #endif + #ifndef UFS1_ONLY + static struct ufs2_dinode dp2; + #endif + static ino_t inomap; + char *blkbuf; + void *indbuf; + struct fs *fs; + char *s; + size_t n, nb, size, off, vboff; + ufs_lbn_t lbn; + ufs2_daddr_t addr, vbaddr; + static ufs2_daddr_t blkmap, indmap; + u_int u; + struct ufs_obj *ufsObj = fd->fsObj; + + blkbuf = ufsObj->dmadat->blkbuf; + indbuf = ufsObj->dmadat->indbuf; + fs = (struct fs *)ufsObj->dmadat->sbbuf; + + #ifdef DEBUG + kprintf("fsread!\n"); + #endif + + if (!ufsObj->dsk_meta) { + inomap = 0; + for (n = 0; sblock_try[n] != -1; n++) { + if (dskread(fs, sblock_try[n] / DEV_BSIZE, 16,fd)) + return -1; + if (( + #if defined(UFS1_ONLY) + fs->fs_magic == FS_UFS1_MAGIC + #elif defined(UFS2_ONLY) + (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc == sblock_try[n]) + #else + fs->fs_magic == FS_UFS1_MAGIC || (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc == sblock_try[n]) + #endif + ) && fs->fs_bsize <= MAXBSIZE && fs->fs_bsize >= sizeof(struct fs)) + break; + } + if (sblock_try[n] == -1) { + kprintf("Not ufs\n"); + return -1; + } + ufsObj->dsk_meta++; + } + + if (!inode) { + #ifdef DEBUG + kprintf("!node\n"); + #endif + return(0x0); + } + + if (inomap != inode) { + #ifdef DEBUG + kprintf("inomap != inode\n"); + #endif + n = IPERVBLK(fs); + if (dskread(blkbuf, INO_TO_VBA(fs, n, inode), DBPERVBLK,fd)) + return -1; + n = INO_TO_VBO(n, inode); + #if defined(UFS1_ONLY) + dp1 = ((struct ufs1_dinode *)blkbuf)[n]; + #elif defined(UFS2_ONLY) + dp2 = ((struct ufs2_dinode *)blkbuf)[n]; + #else + if (fs->fs_magic == FS_UFS1_MAGIC) + dp1 = ((struct ufs1_dinode *)blkbuf)[n]; + else + dp2 = ((struct ufs2_dinode *)blkbuf)[n]; + #endif + + inomap = inode; + fd->offset = 0; + blkmap = indmap = 0; + } + + s = buf; + size = DIP(di_size); + fd->size = size; + n = size - fd->offset; + #ifdef VFSDEBUG + kprintf("n: [0x%X:0x%X:0x%X]\n",n,fd->offset,size); + #endif + if (n < 0) + return(0x0); + if (nbyte > n) + nbyte = n; + + nb = nbyte; + while (nb) { + lbn = lblkno(fs, fd->offset); + off = blkoff(fs, fd->offset); + if (lbn < NDADDR) { + addr = DIP(di_db[lbn]); + } + else if (lbn < NDADDR + NINDIR(fs)) { + n = INDIRPERVBLK(fs); + addr = DIP(di_ib[0]); + u = (u_int)(lbn - NDADDR) / (n * DBPERVBLK); + vbaddr = fsbtodb(fs, addr) + u; + if (indmap != vbaddr) { + if (dskread(indbuf, vbaddr, DBPERVBLK,fd)) + return -1; + indmap = vbaddr; + } + n = (lbn - NDADDR) & (n - 1); + #if defined(UFS1_ONLY) + addr = ((ufs1_daddr_t *)indbuf)[n]; + #elif defined(UFS2_ONLY) + addr = ((ufs2_daddr_t *)indbuf)[n]; + #else + if (fs->fs_magic == FS_UFS1_MAGIC) + addr = ((ufs1_daddr_t *)indbuf)[n]; + else + addr = ((ufs2_daddr_t *)indbuf)[n]; + #endif + } + else { + return -1; + } + vbaddr = fsbtodb(fs, addr) + (off >> VBLKSHIFT) * DBPERVBLK; + vboff = off & VBLKMASK; + n = sblksize(fs, size, lbn) - (off & ~VBLKMASK); + if (n > VBLKSIZE) + n = VBLKSIZE; + if (blkmap != vbaddr) { + if (dskread(blkbuf, vbaddr, n >> DEV_BSHIFT,fd)) + return -1; + blkmap = vbaddr; + } + n -= vboff; + if (n > nb) + n = nb; + memcpy(s, blkbuf + vboff, n); + s += n; + fd->offset += n; + nb -= n; + } + return nbyte; + } + + + + +static __inline int fsfind(const char *name, ino_t * ino,struct file *fd) { + char buf[DEV_BSIZE]; + struct dirent *d; + char *s; + ssize_t n; + + fd->offset = 0; + while ((n = fsread(*ino, buf, DEV_BSIZE,fd)) > 0) + for (s = buf; s < buf + DEV_BSIZE;) { + d = (void *)s; + if (!strcmp(name, d->d_name)) { + *ino = d->d_fileno; + return d->d_type; + } + s += d->d_reclen; + } + //if (n != -1 && ls) + //kprintf("\n"); + return 0; + } + + +static ino_t lookup(const char *path,struct file *fd) { + char name[MAXNAMLEN + 1]; + const char *s; + ino_t ino; + ssize_t n; + int dt; + + ino = ROOTINO; + dt = DT_DIR; + name[0] = '/'; + name[1] = '\0'; + for (;;) { + if (*path == '/') + path++; + if (!*path) + break; + for (s = path; *s && *s != '/'; s++); + if ((n = s - path) > MAXNAMLEN) + return 0; + //ls = *path == '?' && n == 1 && !*s; + memcpy(name, path, n); + name[n] = 0; + if (dt != DT_DIR) { + kprintf("%s: not a directory.\n", name); + return (0); + } + if ((dt = fsfind(name, &ino,fd)) <= 0) + break; + path = s; + } + + + return dt == DT_REG ? ino : 0; + } + + +static int ufs_openFile(const char *file,struct file *fd) { + char tmp[2]; + int ino = 0; + struct ufs_obj *ufsObj = 0x0; + + ufsObj = (struct ufs_obj *)kmalloc(sizeof(struct ufs_obj)); + fd->fsObj = ufsObj; + + ufsObj->dmadat = (struct dmadat *)kmalloc(sizeof(struct dmadat)); + ino = lookup(file,fd); + fd->offset = 0x0; + ufsObj->ino = ino; + if (ino == 0x0) { + return(-1); + } + + /* Quick Hack for file size */ + fsread(ufsObj->ino,&tmp,1,fd); + fd->offset = 0; + /* Return */ + fd->perms = 0x1; + return(0x1); + } + +int ufs_readFile(struct file *fd,char *data,uInt32 offset,long size) { + struct ufs_obj *ufsObj = fd->fsObj; + return(fsread(ufsObj->ino,data,size,fd)); + } + +int ufs_writeFile(fileDescriptor *fd, char *data,uInt32 offset,long size) { + kprintf("Writing :)\n"); + return(0x0); + } + +/***************************************************************************************** + +Function: int ufs_initialize() + +Description: This will initialize a mount point it loads the BAT and Caches the rootDir + +Notes: + +*****************************************************************************************/ +int ufs_initialize(struct vfs_mountPoint *mp) { + /* Return */ + return(0x1); + } + +static int ufs_closeFile(const char *file,struct file *fd) { + //kfree(fd->fsObj); + kprintf("Close file\n"); + return(0x0); + } + +static int ufs_dummy() { + kprintf("Dummy Func\n"); + } + +int ufs_init() { + /* Build our ufs struct */ + struct fileSystem ufs = { + NULL, /* prev */ + NULL, /* next */ + (void *)ufs_initialize, /* vfsInitFS */ + (void *)ufs_readFile, /* vfsRead */ + (void *)ufs_writeFile, /* vfsWrite */ + (void *)ufs_openFile, /* vfsOpenFile */ + (void *)ufs_closeFile, /* vfsCloseFile */ + (void *)ufs_dummy, /* vfsUnlink */ + (void *)ufs_dummy, /* vfsMakeDir */ + (void *)ufs_dummy, /* vfsRemDir */ + (void *)ufs_dummy, /* vfsSync */ + 0xAA, /* vfsType */ + }; /* UFS */ + + if (vfsRegisterFS(ufs) != 0x0) { + kpanic("Unable To Enable UFS"); + return(0x1); + } + + //dmadat = (struct dmadat *)kmalloc(sizeof(struct dmadat)); + /* Return */ + return(0x0); + } + +/*** + END + ***/ + diff --git a/vfs/Makefile b/vfs/Makefile new file mode 100644 index 0000000..5fbbef6 --- /dev/null +++ b/vfs/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = mount.o file.o vfs.o vfs_syscalls.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} ${INCLUDES} -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} ${INCLUDES} -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/vfs/file.c b/vfs/file.c new file mode 100644 index 0000000..9f86297 --- /dev/null +++ b/vfs/file.c @@ -0,0 +1,520 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static spinLock_t fdTable_lock = SPIN_LOCK_INITIALIZER; + + +fileDescriptor *fdTable = 0x0; + +/* USER */ + +void sysFwrite(char *ptr,int size,userFileDescriptor *userFd) { + if (userFd == 0x0) { + tty_print(ptr,_current->term); + } + else { + fwrite(ptr,size,1,userFd->fd); + } + return; + } + +void sysFgetc(int *ptr,userFileDescriptor *userFd) { + struct file *tmpFd = 0x0; + tmpFd = userFd->fd; + if (userFd->fd == 0x0) { + while (1) { + if (_current->term == tty_foreground) { + if ((*ptr = getch()) != 0x0) + return; + sched_yield(); + } + else { + sched_yield(); + } + /* + else { + kprintf("Waking Task: %i\n",tty_foreground->owner); + sched_setStatus(tty_foreground->owner,READY); + kprintf("Sleeping Task: %i\n",_current->id); + sched_setStatus(_current->id,WAIT); + sched_yield(); + } +*/ + } + } + else { + ptr[0] = (int) fgetc(tmpFd); + } + } + +void sysRmDir() { + return; + } + +void sysFseek(userFileDescriptor *userFd,long offset,int whence) { + // TODO : coredump? + if (userFd == NULL) + return; + if (userFd->fd == NULL) + return; + + userFd->fd->offset = offset+whence; + } + +void sysChDir(const char *path) { + if (strstr(path,":") == 0x0) { + sprintf(_current->oInfo.cwd,"%s%s",_current->oInfo.cwd,path); + } + else { + sprintf(_current->oInfo.cwd,path); + } + } + +void sysUnlink(const char *path,int *retVal) { + *retVal = unlink(path); + } + +/************************************************************************ + +Function: void sysFopen(); +Description: Opens A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFopen(const char *file,char *flags,userFileDescriptor *userFd) { + if (userFd == NULL) + kprintf("Error: userFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + userFd->fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(userFd->fd,file,flags); + if (userFd->fd != 0x0) { + userFd->fdSize = userFd->fd->size; + } + /* Return */ + return; + } + +/************************************************************************ + +Function: void sysFread(); +Description: Reads SIZE Bytes From The userFd Into DATA +Notes: + +************************************************************************/ +void sysFread(void *data,long size,userFileDescriptor *userFd) { + /* TODO : coredump? */ + if (userFd == NULL) + return; + if (userFd->fd == NULL) + return; + fread(data,size,1,userFd->fd); + return; + } + +/************************************************************************ + +Function: void sysFclse(); +Description: Closes A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFclose(userFileDescriptor *userFd,int *status) { + if (userFd == NULL ) + { + *status = -1; + return; + } + if (userFd->fd == NULL) + { + *status = -1; + return; + } + *status = fclose(userFd->fd); + /* Return */ + return; + } + + + +/* KERNEL */ + + +size_t fread(void *ptr,size_t size,size_t nmemb,struct file *fd) { + size_t i = 0x0; + + if (fd == 0x0) + return(0x0); + + if (nmemb == 0x0) + nmemb = 1; //Temp Fix + + assert(fd); + assert(fd->mp); + assert(fd->mp->fs); + + i = fd->mp->fs->vfsRead(fd,ptr,fd->offset,size * nmemb); + + return(i); + } + +size_t fwrite(void *ptr,int size,int nmemb,struct file *fd) { + if (fd != 0x0) { + fd->mp->fs->vfsWrite(fd,ptr,fd->offset,size * nmemb); + fd->offset += size * nmemb; + } + return(0x0); + } + +int fseek(struct file *tmpFd,long offset,int whence) { + #ifdef DEBUG + kprintf("FSEEK\n"); + #endif + tmpFd->offset = offset+whence; + return(tmpFd->offset); + } + +/************************************************************************ + +Function: int feof(fileDescriptor *fd) +Description: Check A File Descriptor For EOF And Return Result +Notes: + +************************************************************************/ +int feof(struct file *fd) { + if (fd->status == fdEof) { + return(-1); + } + return(0); + } + +/************************************************************************ + +Function: int fputc(int ch,fileDescriptor *fd) +Description: This Will Write Character To FD +Notes: + +************************************************************************/ +int fputc(int ch,struct file *fd) { + if (fd != 0x0) { + ch = fd->mp->fs->vfsWrite(fd,(char *)ch,fd->offset,1); + fd->offset++; + return(ch); + } + /* Return NULL If FD Is Not Found */ + return(0x0); + } + +/************************************************************************ + +Function: int fgetc(fileDescriptor *fd) +Description: This Will Return The Next Character In A FD Stream +Notes: + +************************************************************************/ +int fgetc(struct file *fd) { + int ch = 0x0; + /* If Found Return Next Char */ + if (fd != 0x0) { + fd->mp->fs->vfsRead(fd,(char *)&ch,fd->offset,1); + fd->offset++; + return(ch); + } + + /* Return NULL If FD Is Not Found */ + return(0x0); + } + +/************************************************************************ + +Function: fileDescriptor *fopen(const char *file,cont char *flags) +Description: This Will Open A File And Return A File Descriptor +Notes: + +08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well + +************************************************************************/ + +struct file *fopen(struct file *tmpFd,const char *file,const char *flags) { + int i = 0x0; + char *path = 0x0; + char *mountPoint = 0x0; + char fileName[1024]; + + /* Allocate Memory For File Descriptor */ + if(tmpFd == 0x0) { + kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + return(NULL); + } + + //tmpFd->fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + + strcpy(fileName,file); + + if (strstr(fileName,":")) { + mountPoint = (char *)strtok((char *)&fileName,":"); + path = strtok(NULL,"\n"); + } + else { + path = fileName; + } + + if (path[0] == '/') + strcpy(tmpFd->path, path); + else + sprintf(tmpFd->path,"/%s",path); + + /* Find our mount point or set default to sys */ + if (mountPoint == 0x0) + tmpFd->mp = vfs_findMount("sys"); + else + tmpFd->mp = vfs_findMount(mountPoint); + + if (tmpFd->mp == 0x0) { + kprintf("Mount Point Bad\n"); + return(0x0); + } + + /* This Will Set Up The Descriptor Modes */ + tmpFd->mode = 0; + for (i = 0; '\0' != flags[i] ;i++ ) { + switch(flags[i]) { + case 'w': + case 'W': + tmpFd->mode |= fileWrite; + break; + case 'r': + case 'R': + tmpFd->mode |= fileRead; + break; + case 'b': + case 'B': + tmpFd->mode |= fileBinary; + break; + case 'a': + case 'A': + tmpFd->mode |= fileAppend; + break; + default: + kprintf("Invalid mode '%c' for fopen\n", flags[i]); + break; + } + } + /* Search For The File */ + if (tmpFd->mp->fs->vfsOpenFile(tmpFd->path,tmpFd) == 0x1) { + /* If The File Is Found Then Set Up The Descriptor */ + + + /* in order to save resources we will allocate the buffer later when it is needed */ + + tmpFd->buffer = (char *)kmalloc(4096); + #ifdef VFSDEBUG + kprintf("meep meep [0x%X]\n",tmpFd->buffer); + #endif + if(tmpFd->buffer == 0x0) + { + kfree(tmpFd); + kprintf("Error: tmpFd->buffer == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + return(0x0); + } + /* Set Its Status To Open */ + tmpFd->status = fdOpen; + + /* Initial File Offset Is Zero */ + tmpFd->offset = 0x0; + //tmpFd->prev = 0x0; + + /* we do not want to be in a spinlock longer than we need to, so + it has been moved to here. */ + //spinLock(&fdTable_lock); + + /* Increment Number Of Open Files */ + systemVitals->openFiles++; + + //tmpFd->next = fdTable; + + //if (fdTable != 0x0) + //fdTable->prev = tmpFd; + + //fdTable = tmpFd; + + //spinUnlock(&fdTable_lock); + + /* Return The FD */ + return(tmpFd); + } + else { + kfree(tmpFd->buffer); + kfree(tmpFd); + //spinUnlock(&fdTable_lock); + #ifdef VFSDEBUG + kprintf("File Not Found? (%s)\n\n",file); + #endif + return (NULL); + } + + /* Return NULL */ + return(0x0); + } + +/************************************************************************ + +Function: int fclose(fileDescriptor *fd); +Description: This Will Close And Free A File Descriptor +Notes: + +************************************************************************/ +int fclose(struct file *fd) { + struct file *tmpFd = 0x0; + assert(fd); + + //BUG FCLOSE BROKEN!! + if ((fd->buffer != 0x0) || (fd->buffer != 0xBEBEBEBE)) + kfree(fd->buffer); + kfree(fd); +//BUG think i'm missing things +//K_PANIC("HMM?"); + + /* + spinLock(&fdTable_lock); + + for (tmpFd = fdTable;tmpFd != 0x0;tmpFd = tmpFd->next) { + if (tmpFd == fd) { + if (tmpFd->prev) + tmpFd->prev->next = tmpFd->next; + if (tmpFd->next) + tmpFd->next->prev = tmpFd->prev; + + if (tmpFd == fdTable) + fdTable = tmpFd->next; + + systemVitals->openFiles--; + spinUnlock(&fdTable_lock); + if(tmpFd->buffer != NULL) + kfree(tmpFd->buffer); + kfree(tmpFd); + return(0x0); + } + } + + spinUnlock(&fdTable_lock); + + */ + return(0x0); + } + +/* UBU */ + +/************************************************************************ + +Function: void sysMkDir(const char *path) +Description: This Will Create A New Directory +Notes: + +************************************************************************/ +void sysMkDir(const char *path) { + struct file *tmpFD = 0x0; + char tmpDir[1024]; + char rootPath[256]; + char *dir = 0x0;//UBU*mountPoint = 0x0; + char *tmp = 0x0; + rootPath[0] = '\0'; + dir = (char *)path; + + if (strstr(path,":") == 0x0) { + sprintf(tmpDir,"%s%s",_current->oInfo.cwd,path); + dir = (char *)&tmpDir; + } + while (strstr(dir,"/")) { + if (rootPath[0] == 0x0) + sprintf(rootPath,"%s/",strtok(dir,"/")); + else + sprintf(rootPath,"%s%s/",rootPath,strtok(dir,"/")); + tmp = strtok(NULL,"\n"); + dir = tmp; + } + + //kprintf("rootPath: [%s]\n",rootPath); + tmpFD = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + fopen(tmpFD,rootPath,"rb"); + + if (tmpFD->mp == 0x0) { + kprintf("Invalid Mount Point\n"); + } + tmpFD->mp->fs->vfsMakeDir(dir,tmpFD); + + fclose(tmpFD); + + return; + } + + +/************************************************************************ + +Function: int unlink(const char *node) +Description: This will unlink a file +Notes: + +************************************************************************/ + +int unlink(const char *node) { + char *path = 0x0,*mountPoint = 0x0; + struct vfs_mountPoint *mp = 0x0; + + path = (char *)strtok((char *)node,"@"); + mountPoint = strtok(NULL,"\n"); + if (mountPoint == 0x0) { + mp = vfs_findMount("sys"); /* _current->oInfo.container; */ + } + else { + mp = vfs_findMount(mountPoint); + } + if (mp == 0x0) { + //kpanic("Mount Point Bad"); + return(0x0); + } + mp->fs->vfsUnlink(path,mp); + return(0x0); + } + + +/*** + END + ***/ + diff --git a/vfs/mount.c b/vfs/mount.c new file mode 100644 index 0000000..c36977d --- /dev/null +++ b/vfs/mount.c @@ -0,0 +1,160 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/************************************************************************ + +Function: mount(int driveId,int partition,int fsType,char *mountPoint,char *perms) + +Description: mount adds a mount point and returns 0 if successful 1 if it fails + +Notes: + +************************************************************************/ +int vfs_mount(int major,int minor,int partition,int vfsType,char *mountPoint,char *perms) { + struct vfs_mountPoint *mp = 0x0; + struct device_node *device = 0x0; + + /* Allocate Memory For Mount Point */ + if ((mp = (struct vfs_mountPoint *)kmalloc(sizeof(struct vfs_mountPoint))) == NULL) + kprintf("vfs_mount: failed to allocate mp\n"); + + kprintf("DEBUG: MOUNT"); + + /* Copy Mount Point Into Buffer */ + sprintf(mp->mountPoint,mountPoint); + + /* Set Pointer To Physical Drive */ + device = device_find(major,minor); + + if (device == 0x0) { + kprintf("vfs_mount: failed invalid device\n"); + return(0x1); + } + + kprintf("DEBUG: [0x%X]\n",device); + + /* Set Up Mp Defaults */ + mp->device = device; + mp->fs = vfsFindFS(vfsType); + mp->partition = partition; + mp->perms = *perms; + + if (mp->fs == 0x0) { + /* sysErr(systemErr,"File System Type: %i Not Found\n",fsType); */ + kprintf("File System Type: %i Not Found\n",vfsType); + return(0x1); + } + + kprintf("DEBUG: mp->fs\n"); + + /*What is this for? 10/6/2006 */ +/* + if (device != 0x0) { + mp->diskLabel = (struct ubixDiskLabel *)kmalloc(512); + mp->device->devInfo->read(mp->device->devInfo->info,mp->diskLabel,1,1); + kprintf("READING SECTOR"); + } +*/ + + /* Add Mountpoint If It Fails Free And Return */ + if (vfs_addMount(mp) != 0x0) { + kfree(mp); + return(0x1); + } + + /* Initialize The File System If It Fails Return */ + if (mp->fs->vfsInitFS(mp) == 0x0) { + kfree(mp); + return(0x1); + } + kprintf("Got Here\n"); + /* Return */ + return(0x0); + } + +/************************************************************************ + +Function: vfs_addMount(struct vfs_mountPoint *mp) + +Description: This function adds a mount point to the system + +Notes: + +************************************************************************/ +int vfs_addMount(struct vfs_mountPoint *mp) { + + /* If There Are No Existing Mounts Make It The First */ + if (systemVitals->mountPoints == 0x0) { + mp->prev = 0x0; + mp->next = 0x0; + systemVitals->mountPoints = mp; + } + else { + mp->next = systemVitals->mountPoints; + systemVitals->mountPoints->prev = mp; + mp->prev = 0x0; + systemVitals->mountPoints = mp; + } + /* Return */ + return(0x0); + } + +/************************************************************************ + +Function: vfs_findMount(char *mountPoint) + +Description: This function finds a particular mount point + +Notes: + +************************************************************************/ +struct vfs_mountPoint *vfs_findMount(char *mountPoint) { + struct vfs_mountPoint *tmpMp = 0x0; + + for (tmpMp=systemVitals->mountPoints;tmpMp;tmpMp=tmpMp->next) { + if (strcmp(tmpMp->mountPoint,mountPoint) == 0x0) { + return(tmpMp); + } + } + /* Return NULL If Mount Point Not Found */ + return NULL; + } + +/*** + END + ***/ + diff --git a/vfs/vfs.c b/vfs/vfs.c new file mode 100644 index 0000000..8e3e940 --- /dev/null +++ b/vfs/vfs.c @@ -0,0 +1,159 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/************************************************************************ + +Function: void vfs_init(); + +Description: This Function Initializes The VFS Layer + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int vfs_init() { + /* Set up default fileSystems list */ + systemVitals->fileSystems = 0x0; + + /* Print information */ + kprintf("vfs0: loaded at address: [0x%X]\n",systemVitals->fileSystems); + + /* Return so we know things went well */ + return(0x0); + } + +struct fileSystem *vfsFindFS(int vfsType) { + struct fileSystem *tmp = 0x0; + + /* Search For File System */ + for (tmp=systemVitals->fileSystems;tmp;tmp=tmp->next) { + /* If Found Return File System */ + if (tmp->vfsType == vfsType) { + return(tmp); + } + } + + /* If FS Not Found Return NULL */ + return(0x0); + } + +/*! + * \brief register a file system + * + * This registers a new filesystem into the vfs which is referenced when trying to mount a device + * + * \param newFS pointer to fileSystem structure + */ +int vfsRegisterFS(struct fileSystem newFS) { +/* +int vfsType, +void *vfsInitFS, +void *vfsRead, +void *vfsWrite, +void *vfsOpenFile, +void *vfsUnlink, +void *vfsMakeDir, +void *vfsRemDir, +void *vfsSync) { + */ + struct fileSystem *tmpFs = 0x0; + + if (vfsFindFS(newFS.vfsType) != 0x0) { + kprintf("FS Is already Registered\n"); + return(0x1); + } + + /*! verify that we have all required methods */ + if ((newFS.vfsCloseFile == 0x0) || (newFS.vfsInitFS == 0x0) || (newFS.vfsMakeDir == 0x0) || (newFS.vfsOpenFile == 0x0) || (newFS.vfsRead == 0x0) || (newFS.vfsRemDir == 0x0) || (newFS.vfsSync == 0x0)) { + kprintf("Missing Methods\n"); + return(0x1); + } + + + /* Allocate Memory */ + tmpFs = (struct fileSystem *)kmalloc(sizeof(struct fileSystem)); + if (tmpFs == NULL) { + kprintf("vfsRegisterFS: memory allocation failed\n"); + /* Memory Allocation Failed */ + return(0x1); + } + + /* Set Up FS Defaults */ + +/* 2004 7-16-2004 mji + * Old method: + * tmpFs->vfsType = newFS.vfsType; + * tmpFs->vfsInitFS = newFS.vfsInitFS; + * tmpFs->vfsRead = newFS.vfsRead; + * tmpFs->vfsWrite = newFS.vfsWrite; + * tmpFs->vfsOpenFile = newFS.vfsOpenFile; + * tmpFs->vfsUnlink = newFS.vfsUnlink; + * tmpFs->vfsMakeDir = newFS.vfsMakeDir; + * tmpFs->vfsRemDir = newFS.vfsRemDir; + * tmpFs->vfsSync = newFS.vfsSync; + */ + /* new method: */ + + memcpy(tmpFs, &newFS, sizeof(struct fileSystem)); + if (!systemVitals->fileSystems) { + tmpFs->prev = 0x0; + tmpFs->next = 0x0; + systemVitals->fileSystems = tmpFs; + } + else { + tmpFs->prev = 0x0; + tmpFs->next = systemVitals->fileSystems; + systemVitals->fileSystems->prev = tmpFs; + systemVitals->fileSystems = tmpFs; + } + + return(0x0); + } + +/* HACK */ +int fstatfs(struct thread *td, struct fstatfs_args *uap) { + int error = 0x0; + uap->buf->f_mntonname[0] = '/'; + uap->buf->f_mntonname[1] = '\0'; + uap->buf->f_flags = 0x0; + return(error); + } + +/*** + END + ***/ + diff --git a/vfs/vfs_syscalls.c b/vfs/vfs_syscalls.c new file mode 100644 index 0000000..2c53c96 --- /dev/null +++ b/vfs/vfs_syscalls.c @@ -0,0 +1,244 @@ +/***************************************************************************************** + Copyright (c) 2007 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +/*! + * \brief entry point for lseek syscall + * + * \param *td pointer to callers thread + * \param *uap pointer to user space arguements for call + * + * \return new offset + */ +int lseek(struct thread *td, struct lseek_args *uap) { + int error = 0x0; + struct file *fd = 0x0; + + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + getfd(td,&fd,uap->fd); + switch (uap->whence) { + case SEEK_END: + K_PANIC("UNHANDLED WHENCE"); + break; + case SEEK_CUR: + fd->offset += uap->offset; + break; + case SEEK_SET: + fd->offset = uap->offset; + break; + default: + kprintf("offset: [%i], whence: [%i]\n",uap->offset,uap->whence); + K_PANIC("Invalid whence"); + break; + } + + td->td_retval[0] = fd->offset; + + return(error); + } /* end func */ + +/*! + * \brief entry point for read syscall + * + * \param *td pointer to callers thread + * \param *uap pointer to user space arguements for call + * + * \return bytes read + */ +int read(struct thread *td,struct read_args *uap) { + int error = 0x0; + int ch = 0x0; + int i = 0x0; + size_t count = 0x0; + struct file *fd = 0x0; + char *data = 0x0; + + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + if (uap->fd < 5) { + /* Special File Descriptors */ + switch (uap->fd) { + case 0: + data = uap->buf; + for (i = 0x0;i < uap->nbyte;i++) { + while ((ch = getch()) == 0x0); + data[i] = ch; + kprintf("%c",ch); + if (data[i] == '\n') + break; + } + //kprintf("Read: [%i]\n",i + 1); + count = i + 1; + break; + default: + kprintf("Invalid Descriptor\n"); + count = 0; + break; + } + } + else { + /* Standard File Descriptors */ + error = getfd(td,&fd,uap->fd); + + if (error) + return(error); + + count = fread(uap->buf,uap->nbyte,0x1,fd); + //fd->offset += count; + } + + #ifdef VFSDEBUG + kprintf("count(%i): %i - %i\n",fd->offset,count,uap->nbyte); + #endif + td->td_retval[0] = count; + return(error); + } /* end func */ + +/*! + * \brief entry point for write syscall + * + * \param *td pointer to callers thread + * \param *uap pointer to user space arguements for call + * + * \return bytes written + */ +int write(struct thread *td, struct write_args *uap) { + char *buffer = 0x0; + char *in = 0x0; + + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + if (uap->fd == 2) { + in = (char *)uap->buf; + if (uap->nbyte > 1) { + buffer = kmalloc(1024); + memcpy(buffer,uap->buf,uap->nbyte); + kprintf("STDERR: %s\n",buffer); + kfree(buffer); + } + td->td_retval[0] = uap->nbyte; + } + else if (uap->fd == 1) { + buffer = kmalloc(uap->nbyte); + memcpy(buffer,uap->buf,uap->nbyte); + kprint(buffer); + kfree(buffer); + td->td_retval[0] = uap->nbyte; + } + else { + kprintf("WUAP[%i]",uap->nbyte); + buffer = kmalloc(uap->nbyte); + memcpy(buffer,uap->buf,uap->nbyte); + //kprint(buffer); + kfree(buffer); + kprintf("(%i) [%s]",uap->fd,uap->buf); + td->td_retval[0] = uap->nbyte; + } + return(0x0); + } /* end func */ + +/*! + * \brief entry point for open syscall + * + * \param *td pointer to callers thread + * \param *uap pointer to user space arguements for call + * + * \return index to file descriptor + */ +int open(struct thread *td, struct open_args *uap) { + int error = 0x0; + int index = 0x0; + struct file *nfp = 0x0; + + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + error = falloc(td,&nfp,&index); + + if (error) + return(error); + + kprintf("opening: %s\n",uap->path); + + if (!strcmp(".",uap->path)) { + kprintf("GOTCHA!\n"); + strcpy(nfp->path,"/bin"); + } + else + strcpy(nfp->path,uap->path); + + if (uap->flags != 0x0) { + kprintf("BAD!\n"); + while (1); + } + if (fopen(nfp,nfp->path,"r") == 0x0) { + td->td_retval[0] = -1; + td->o_files[index] = 0x0; + } + else + td->td_retval[0] = index; + + return (error); + } /* end func open */ + +int close(struct thread *td,struct close_args *uap) { + struct file *fd = 0x0; + #ifdef VFSDEBUG + kprintf("[%s:%i:%s]",__FILE__,__LINE__,__FUNCTION__); + #endif + + getfd(td,&fd,uap->fd); + + //! Call the fs close function first + fd->mp->fs->vfsCloseFile(fd); + + if (fd->buffer != 0x0) + kfree(fd->buffer); + + kfree((void *)td->o_files[uap->fd]); + td->o_files[uap->fd] = 0x0; + td->td_retval[0] = 0x0; + return(0x0); + } /* end func close */ + +/*** + END + ***/ diff --git a/vmm/Makefile b/vmm/Makefile new file mode 100644 index 0000000..c02c625 --- /dev/null +++ b/vmm/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = page_fault.o pagefault.o setpageattributes.o unmappage.o getphysicaladdr.o getfreekernelpage.o vmm_memory.o paging.o vmm_init.o vmm_virtual.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/vmm/README b/vmm/README new file mode 100644 index 0000000..68fd016 --- /dev/null +++ b/vmm/README @@ -0,0 +1,2 @@ +UbixOS VMM (c) 2002-2004 UbixOS + diff --git a/vmm/getfreekernelpage.c b/vmm/getfreekernelpage.c new file mode 100644 index 0000000..8e98f15 --- /dev/null +++ b/vmm/getfreekernelpage.c @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002,2009 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER; + +/************************************************************************ + +Function: void *vmm_getFreeKernelPage(pidType pid); + +Description: Returns A Free Page Mapped To The VM Space + +Notes: + +02/13/09 - Renamed function to vmm_getFreeKernelPage +07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel + +************************************************************************/ +void *vmm_getFreeKernelPage(pidType pid) { + u_int16 x = 0x0, y = 0x0; + u_int32 *pageTableSrc = 0x0; + + spinLock(&vmmGFPlock); + + /* Lets Search For A Free Page */ + for (x = 768; x < 1024; x++) { + + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + for (y = 0x0; y < 1024; y++) { + /* Loop Through The Page Table Find An UnAllocated Page */ + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + /* Map A Physical Page To The Virtual Page */ + if ((vmm_remapPage(vmmFindFreePage(pid), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: vmm_getFreeKernelPage\n"); + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&vmmGFPlock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&vmmGFPlock); + return (0x0); +} + +/*** + END + ***/ diff --git a/vmm/getphysicaladdr.c b/vmm/getphysicaladdr.c new file mode 100644 index 0000000..1c42a54 --- /dev/null +++ b/vmm/getphysicaladdr.c @@ -0,0 +1,58 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +/*! + +Function: void *vmmGetPhysicalAddr(); +Description: Returns The Physical Address Of The Virtual Page +Notes: + +*/ + +u_int32_t vmm_getPhysicalAddr(uInt32 pageAddr) { + int pageDirectoryIndex = 0x0, pageTableIndex = 0x0; + uInt32 *pageTable = 0x0; + + //Calculate The Page Directory Index + pageDirectoryIndex = (pageAddr >> 22); + + //Calculate The Page Table Index + pageTableIndex = ((pageAddr >> 12) & 0x3FF); + + /* Set pageTable To The Virtual Address Of Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + /* Return The Physical Address Of The Page */ + return ((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); + } + +/*** + END + ***/ diff --git a/vmm/page_fault.S b/vmm/page_fault.S new file mode 100644 index 0000000..bc6b281 --- /dev/null +++ b/vmm/page_fault.S @@ -0,0 +1,60 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +/* + Page fault wrapper this will aquire some values we need for later use + */ + +.globl _vmm_pageFault +.text +.code32 +_vmm_pageFault: + xchgl %eax,(%esp) /* Save EAX */ + movl 4(%esp),%eax /* Move EIP into EAX to use later */ + pushl %ebx /* Save EBX */ + movl 20(%esp),%ebx /* Save ESP for ring 3 to use later */ + pushl %ecx /* Save ECX,EDX */ + pushl %edx + push %ebx /* Push ESP */ + push %eax /* Push EIP */ + movl %cr2,%eax /* Push the faulted address */ + pushl %eax + sti /* Turn interrupts back on we are now entrant safe */ + call vmm_pageFault /* Call our page fault handler */ + addl $0xC,%esp /* Adjust the stack to compensate for pushed values */ + popl %edx /* Restore EAX,EBX,ECX,EDX */ + popl %ecx + popl %ebx + popl %eax + iret /* Return from the interrupt */ + + +/*** + END + ***/ diff --git a/vmm/pagefault.c b/vmm/pagefault.c new file mode 100644 index 0000000..70dd2cd --- /dev/null +++ b/vmm/pagefault.c @@ -0,0 +1,223 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +static spinLock_t pageFaultSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: void vmm_pageFault(uInt32 memAddr,uInt32 eip,uInt32 esp); + Description: This is the page fault handler, it will handle COW and trap all other + exceptions and segfault the thread. + + Notes: + +07/30/02 - Fixed COW However I Need To Think Of A Way To Impliment + A Paging System Also Start To Add Security Levels + +07/27/04 - Added spin locking to ensure that we are thread safe. I know that spining a + cpu is a waste of resources but for now it prevents errors. + +*****************************************************************************************/ +void vmm_pageFault(uInt32 memAddr,uInt32 eip,uInt32 esp) { + uInt32 i = 0x0, pageTableIndex = 0x0,pageDirectoryIndex = 0x0; + uInt32 *pageDir = 0x0,*pageTable = 0x0; + uInt32 *src = 0x0,*dst = 0x0; + + /* Try to aquire lock otherwise spin till we do */ + spinLock(&pageFaultSpinLock); + + /* Set page dir pointer to the address of the visable page directory */ + pageDir = (uInt32 *)parentPageDirAddr; + + /* UBU - This is a temp panic for 0x0 read write later on I will handle this differently */ + if (memAddr == 0x0) { + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X]\n",memAddr,esp,_current->id,eip); + kpanic("Error We Wrote To 0x0\n"); + } + + /* Calculate The Page Directory Index */ + pageDirectoryIndex = (memAddr >> 22); + + /* Calculate The Page Table Index */ + pageTableIndex = ((memAddr >> 12) & 0x3FF); + + /* UBU - This is a temporary routine for handling access to a page of a non existant page table */ + if (pageDir[pageDirectoryIndex] == 0x0) { + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X], Not A Valid Page Table\n",memAddr,esp,_current->id,eip); + spinUnlock(&pageFaultSpinLock); + endTask(_current->id); + } + else { + /* Set pageTable To Point To Virtual Address Of Page Table */ + pageTable = (uInt32 *)(tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + + /* Test if this is a COW on page */ + if (((uInt32)pageTable[pageTableIndex] & PAGE_COW) == PAGE_COW) { + /* Set Src To Base Address Of Page To Copy */ + src = (uInt32 *)(memAddr & 0xFFFFF000); + /* Allocate A Free Page For Destination */ + /* USE vmInfo */ + dst = (uInt32 *) vmmGetFreeVirtualPage(_current->id,1,0x1); + /* Copy Memory */ + for (i=0;iid,eip); + spinUnlock(&pageFaultSpinLock); + endTask(_current->id); + } + else if (memAddr < (_current->td.vm_dsize + _current->td.vm_daddr)) { + pageTable[pageTableIndex] = (uInt32)vmmFindFreePage(_current->id) | PAGE_DEFAULT; + } + else { + spinUnlock(&pageFaultSpinLock); + /* Need To Create A Routine For Attempting To Access Non Mapped Memory */ + kprintf("Segfault At Address: [0x%X][0x%X][%i][0x%X] Non Mapped\n",memAddr,esp,_current->id,eip); + //kprintf("Out Of Stack Space: [0x%X]\n",memAddr & 0xFF0000); + spinUnlock(&pageFaultSpinLock); + endTask(_current->id); + } + } + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + + /* Release the spin lock */ + spinUnlock(&pageFaultSpinLock); + return; + } + +/*** + $Log$ + Revision 1.3 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + + Revision 1.2 2007/01/19 17:08:29 reddawg + Lots of fixes + + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.6 2006/12/05 14:10:21 reddawg + Workign Distro + + Revision 1.5 2006/12/01 05:12:35 reddawg + We're almost there... :) + + Revision 1.4 2006/11/21 13:25:49 reddawg + A handful of changes ;) + + Revision 1.3 2006/11/06 19:10:12 reddawg + Lots Of Updates... Still having issues with brk(); + + Revision 1.2 2006/10/31 20:44:19 reddawg + Lots of changes + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:52 reddawg + no message + + Revision 1.14 2004/08/25 22:02:41 reddawg + task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly + + Revision 1.13 2004/08/24 05:24:37 reddawg + TCA Is A BONER!!!! + + Revision 1.12 2004/08/14 11:23:03 reddawg + Changes + + Revision 1.11 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + Revision 1.10 2004/07/28 00:22:56 reddawg + bah + + Revision 1.9 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + + Revision 1.8 2004/07/27 07:09:38 reddawg + Put in a test for 0x0 + + Revision 1.7 2004/07/26 19:15:49 reddawg + test code, fixes and the like + + Revision 1.6 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + + Revision 1.5 2004/07/24 20:00:51 reddawg + Lots of changes to the vmm subsystem.... Page faults have been adjust to now be blocking on a per thread basis not system wide. This has resulted in no more deadlocks.. also the addition of per thread locking has removed segfaults as a result of COW in which two tasks fault the same COW page and try to modify it. + + Revision 1.4 2004/07/24 17:47:28 reddawg + vmm_pageFault: deadlock resolved thanks to a propper solution suggested by geist + + Revision 1.3 2004/07/19 02:05:26 reddawg + vmmPageFault: had a potential memory leak here for one page it was still using sysID on certain COW scenarios + + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:52 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/vmm/paging.c b/vmm/paging.c new file mode 100644 index 0000000..47b0f04 --- /dev/null +++ b/vmm/paging.c @@ -0,0 +1,576 @@ +/***************************************************************************************** + Copyright (c) 2002-2004,2005,2006,2007 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +u_int32_t *kernelPageDirectory = 0x0; + +static spinLock_t fkpSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t rmpSpinLock = SPIN_LOCK_INITIALIZER; + + +/***************************************************************************************** + Function: int vmm_pagingInit(); + + Description: This Function Will Initialize The Operating Systems Paging + Abilities. + + Notes: + 02/20/2004 - Looked Over Code And Have Approved Its Quality + 07/28/3004 - All pages are set for ring-0 only no more user accessable + +*****************************************************************************************/ + +int vmm_pagingInit() { + u_int32_t i = 0x0; + u_int32_t *pageTable = 0x0; + + /* Allocate A Page Of Memory For Kernels Page Directory */ + kernelPageDirectory = (uInt32 *) vmmFindFreePage(sysID); + if (kernelPageDirectory == 0x0) { + K_PANIC("Error: vmmFindFreePage Failed"); + return (0x1); + } /* end if */ + + /* Clear The Memory To Ensure There Is No Garbage */ + for (i = 0x0; i < pageEntries; i++) { + kernelPageDirectory[i] = (u_int32_t)0x0; + } /* end for */ + + /* Allocate a page for the first 4MB of memory */ + if ((pageTable = (u_int32_t *) vmmFindFreePage(sysID)) == 0x0) + K_PANIC("Error: vmmFindFreePage Failed"); + + kernelPageDirectory[0x0] = (u_int32_t) ((u_int32_t)pageTable | KERNEL_PAGE_DEFAULT); + + /* Make Sure The Page Table Is Clean */ + memset(pageTable,0x0,0x1000); + + /* + * Map the first 1MB of Memory to the kernel MM space because our kernel starts + * at 0x30000 + * Do not map page at address 0x0 this is reserved for null... + */ + for (i = 0x1; i < (pageEntries / 0x4); i++) { + pageTable[i] = (uInt32) ((i * 0x1000) | KERNEL_PAGE_DEFAULT); + } /* end for */ + + /* + * Create page tables for the top 1GB of VM space. This space is set aside + * for kernel space and will be shared with each process + */ + for (i = 768; i < pageEntries; i++) { + if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) + K_PANIC("Error: vmmFindFreePage Failed"); + + /* Make Sure The Page Table Is Clean */ + memset(pageTable,0x0,0x1000); + + /* Map In The Page Directory */ + kernelPageDirectory[i] = (uInt32) ((uInt32) (pageTable) | KERNEL_PAGE_DEFAULT); + } /* end for */ + + /* Set Up Memory To Be All The Allocated Page Directories */ + if ((pageTable = (uInt32 *) vmmFindFreePage(sysID)) == 0x0) + K_PANIC("Error: vmmFindFreePage Failed"); + + /* Clean Page Table */ + memset(pageTable,0x0,0x1000); + + kernelPageDirectory[767] = ((uInt32) pageTable | KERNEL_PAGE_DEFAULT); + + for (i = 0; i < pageEntries; i++) { + pageTable[i] = kernelPageDirectory[i]; + } /* end for */ + + /* Also Set Up Page Directory To Be The The First Page In 0xE0400000 */ + pageTable = (uInt32 *) (kernelPageDirectory[0] & 0xFFFFF000); + pageTable[256] = (uInt32) ((uInt32) (kernelPageDirectory) | KERNEL_PAGE_DEFAULT); + + + /* Now Lets Turn On Paging With This Initial Page Table */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + "movl %%cr0,%%eax \n" + "orl $0x80010000,%%eax \n" /* Turn on memory protection */ + "movl %%eax,%%cr0 \n" + : + : "d"((uInt32 *) (kernelPageDirectory)) + ); + + /* Remap The Memory List */ + for (i = 0x101000; i <= (0x101000 + (numPages * sizeof(mMap))); i += 0x1000) { + if ((vmm_remapPage(i, (vmmMemoryMapAddr + (i - 0x101000)),KERNEL_PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage failed\n"); + } /* end for */ + + /* Set New Address For Memory Map Since Its Relocation */ + vmmMemoryMap = (mMap *) vmmMemoryMapAddr; + + /* Print information on paging */ + kprintf("paging0 - Address: [0x%X], PagingISR Address: [0x%X]\n", kernelPageDirectory, &_vmm_pageFault); + + /* Return so we know everything went well */ + return (0x0); + } /* END func */ + +/***************************************************************************************** + Function: int vmmRemapPage(Physical Source,Virtual Destination) + + Description: This Function Will Remap A Physical Page Into Virtual Space + + Notes: + 07/29/02 - Rewrote This To Work With Our New Paging System + 07/30/02 - Changed Address Of Page Tables And Page Directory + 07/28/04 - If perms == 0x0 set to PAGE_DEFAULT + +*****************************************************************************************/ +int vmm_remapPage(uInt32 source,uInt32 dest,uInt16 perms) { + uInt16 destPageDirectoryIndex = 0x0, destPageTableIndex = 0x0; + uInt32 *pageDir = 0x0, *pageTable = 0x0; + short i = 0x0; + + if (source == 0x0) + K_PANIC("source == 0x0"); + + if (dest == 0x0) + K_PANIC("dest == 0x0"); + + spinLock(&rmpSpinLock); + + if (perms == 0x0) + perms = KERNEL_PAGE_DEFAULT; + + /* + * Set Pointer pageDirectory To Point To The Virtual Mapping Of The Page + * Directory + */ + + pageDir = (uInt32 *) parentPageDirAddr; + + /* Check To See If Page Table Exists */ + if (dest == 0x0) + return(0x0); + + /* Get Index Into The Page Directory */ + destPageDirectoryIndex = (dest / 0x400000); + + if ((pageDir[destPageDirectoryIndex] & PAGE_PRESENT) != PAGE_PRESENT) { + /* If Page Table Is Non Existant Then Set It Up */ + /* UBU Why does the page table need to be user writable? */ + pageDir[destPageDirectoryIndex] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; + + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTable = (uInt32 *) (tablesBaseAddress + 0x2FF000); + pageTable[destPageDirectoryIndex] = pageDir[destPageDirectoryIndex]; + + /* Reload Page Directory */ + asm volatile( + "push %eax \n" + "mov %cr3,%eax \n" + "mov %eax,%cr3 \n" + "pop %eax \n" + ); + + pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); + + for (i = 0x0;i < pageEntries;i++) + pageTable[i] = 0x0; + + } + + /* Set Address To Page Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * destPageDirectoryIndex)); + + /* Get The Index To The Page Table */ + destPageTableIndex = ((dest - (destPageDirectoryIndex * 0x400000)) / 0x1000); + + + /* If The Page Is Mapped In Free It Before We Remap */ + if ((pageTable[destPageTableIndex] & PAGE_PRESENT) == PAGE_PRESENT) { + if ((pageTable[destPageTableIndex] & PAGE_STACK) == PAGE_STACK) + kprintf("Stack Page: [0x%X]\n",dest); + + if ((pageTable[destPageTableIndex] & PAGE_COW) != PAGE_COW) { + kprintf("Page NOT COW\n"); + kprintf("Page Present: [0x%X][0x%X]",dest,pageTable[destPageTableIndex]); + source = 0x0; + goto rmDone; + } + + /* Clear The Page First For Security Reasons */ + freePage(((uInt32) pageTable[destPageTableIndex] & 0xFFFFF000)); + } + + /* Set The Source Address In The Destination */ + pageTable[destPageTableIndex] = (uInt32) (source | perms); + + /* Reload The Page Table; */ + asm volatile( + "push %eax \n" + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + "pop %eax \n" + ); + + rmDone: + + /* Return */ + spinUnlock(&rmpSpinLock); + return (source); + } /* end func */ + +/************************************************************************ + +Function: void *vmm_getFreeKernelPage(pidType pid); +Description: Returns A Free Page Mapped To The VM Space +Notes: + +07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel + +************************************************************************/ +void *vmm_getFreeKernelPage(pidType pid, uInt16 count) { + int x = 0, y = 0, c = 0; + uInt32 *pageTableSrc = 0x0; + + spinLock(&fkpSpinLock); + + /* Lets Search For A Free Page */ + for (x = 768; x < 1024; x++) { + + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * x)); + + for (y = 0; y < 1024; y++) { + + /* Loop Through The Page Table Find An UnAllocated Page */ + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + if (count > 1) { + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage failed: gfkp-1\n"); + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + + spinUnlock(&fkpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + else { + /* Map A Physical Page To The Virtual Page */ + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) + K_PANIC("vmmRemapPage failed: gfkp-2\n"); + + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&fkpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fkpSpinLock); + return (0x0); + } /* end func */ + + +/************************************************************************ + +Function: void vmmClearVirtualPage(uInt32 pageAddr); + +Description: This Will Null Out A Page Of Memory + +Notes: + +************************************************************************/ +int +vmmClearVirtualPage(uInt32 pageAddr) +{ + uInt32 *src = 0x0; + int counter = 0x0; + + /* Set Source Pointer To Virtual Page Address */ + src = (uInt32 *) pageAddr; + + /* Clear Out The Page */ + for (counter = 0x0; counter < pageEntries; counter++) { + src[counter] = 0x0; + } + + /* Return */ + return (0x0); +} + + +void *vmmMapFromTask(pidType pid,void *ptr,uInt32 size) { + kTask_t *child = 0x0; + uInt32 i = 0x0,x = 0x0,y = 0x0,count = ((size+4095)/0x1000),c = 0x0; + uInt16 dI = 0x0,tI = 0x0; + uInt32 baseAddr = 0x0,offset = 0x0; + uInt32 *childPageDir = (uInt32 *)0x5A00000; + uInt32 *childPageTable = 0x0; + uInt32 *pageTableSrc = 0x0; + offset = (uInt32)ptr & 0xFFF; + baseAddr = (uInt32)ptr & 0xFFFFF000; + child = schedFindTask(pid); + //Calculate The Page Table Index And Page Directory Index + dI = (baseAddr/(1024*4096)); + tI = ((baseAddr-(dI*(1024*4096)))/4096); + if (vmm_remapPage(child->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("vmmFailed"); + + for (i=0;i<0x1000;i++) { + if (vmm_remapPage(childPageDir[i],0x5A01000 + (i * 0x1000),KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("Returned NULL"); + } + for (x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++) { + pageTableSrc = (uInt32 *)(tablesBaseAddress + (4096*x)); + for (y=0;y<1024;y++) { + //Loop Through The Page Table Find An UnAllocated Page + if ((uInt32)pageTableSrc[y] == (uInt32)0x0) { + if (count > 1) { + for (c=0;((c= 0x1000) { + dI++; + tI = 0-c; + } + childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); + if (vmm_remapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096)),KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("remap == NULL"); + } + vmmUnmapPage(0x5A00000,1); + for (i=0;i<0x1000;i++) { + vmmUnmapPage((0x5A01000 + (i*0x1000)),1); + } + return((void *)((x*(1024*4096))+(y*4096)+offset)); + } + } + else { + //Map A Physical Page To The Virtual Page + childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); + if (vmm_remapPage(childPageTable[tI],((x*(1024*4096))+(y*4096)),KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("remap Failed"); + + //Return The Address Of The Mapped In Memory + vmmUnmapPage(0x5A00000,1); + for (i=0;i<0x1000;i++) { + vmmUnmapPage((0x5A01000 + (i*0x1000)),1); + } + return((void *)((x*(1024*4096))+(y*4096)+offset)); + } + } + } + } + return(0x0); + } + +void *vmm_getFreeMallocPage(uInt16 count) { + uInt16 x = 0x0, y = 0x0; + int c = 0x0; + uInt32 *pageTableSrc = 0x0; + + spinLock(&fkpSpinLock); + /* Lets Search For A Free Page */ + for (x = 960; x < 1024; x++) { + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + for (y = 0; y < 1024; y++) { + /* Loop Through The Page Table Find An UnAllocated Page */ + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + if (count > 1) { + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + if (vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("remap Failed"); + + vmmClearVirtualPage((uInt32) ((x * 0x400000) + ((y + c) * 0x1000))); + } + spinUnlock(&fkpSpinLock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } + else { + /* Map A Physical Page To The Virtual Page */ + if (vmm_remapPage((uInt32) vmmFindFreePage(sysID), ((x * 0x400000) + (y * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) + K_PANIC("Failed"); + + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * 0x400000) + (y * 0x1000))); + /* Return The Address Of The Newly Allocate Page */ + spinUnlock(&fkpSpinLock); + return ((void *)((x * 0x400000) + (y * 0x1000))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fkpSpinLock); + return (0x0); + } + +/*! + \brief sdf + */ +int mmap(struct thread *td,struct mmap_args *uap) { + vm_offset_t addr = 0x0; + char *tmp = 0x0; + struct file *fd = 0x0; + + addr = (vm_offset_t) uap->addr; + + #ifdef VMMDEBUG + if (uap->addr != 0x0) { + kprintf("Address hints are not supported yet.\n"); + } + kprintf("uap->flags: [0x%X]\n",uap->flags); + kprintf("uap->addr: [0x%X]\n",uap->addr); + kprintf("uap->len: [0x%X]\n",uap->len); + kprintf("uap->prot: [0x%X]\n",uap->prot); + kprintf("uap->fd: [%i]\n",uap->fd); + kprintf("uap->pad: [0x%X]\n",uap->pad); + kprintf("uap->pos: [0x%X]\n",uap->pos); + #endif + + if (uap->fd == -1) { + /* NEED ROUND PAGE */ + td->td_retval[0] = (int)vmmGetFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK); + } + else { + #ifdef VMMDEBUG + kprintf("uap->flags: [0x%X]\n",uap->flags); + kprintf("uap->addr: [0x%X]\n",uap->addr); + kprintf("uap->len: [0x%X]\n",uap->len); + kprintf("uap->prot: [0x%X]\n",uap->prot); + kprintf("uap->fd: [%i]\n",uap->fd); + kprintf("uap->pad: [0x%X]\n",uap->pad); + kprintf("uap->pos: [0x%X]\n",uap->pos); + #endif + getfd(td,&fd,uap->fd); + if (uap->addr == 0x0) + tmp = (char *)vmmGetFreeVirtualPage(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK); + else { + tmp = (char *)vmmGetFreeVirtualPage_new(_current->id,(uap->len + 0xFFF)/0x1000,VM_TASK,uap->addr); + } + + fd->offset = uap->pos; + fread(tmp,uap->len,0x1,fd); + + td->td_retval[0] = (int)tmp; + } + return(0x0); + } + +int obreak(struct thread *td,struct obreak_args *uap) { + u_int32_t i = 0x0; + vm_offset_t old = 0x0; + vm_offset_t base = 0x0; + vm_offset_t new = 0x0; + + #ifdef VMMDEBUG + kprintf("obreak\n"); + kprintf("vm_offset_t: [%i]\n",sizeof(vm_offset_t)); + kprintf("nsize: [0x%X]\n",uap->nsize); + kprintf("vm_daddr: [0x%X]\n",td->vm_daddr); + kprintf("vm_dsize: [0x%X]\n",td->vm_dsize); + kprintf("total: [0x%X]\n",td->vm_daddr + td->vm_dsize); + #endif + + new = round_page((vm_offset_t)uap->nsize); + + base = round_page((vm_offset_t)td->vm_daddr); + + old = base + ctob(td->vm_dsize); + + if (new < base) + K_PANIC("EINVAL"); + + if (new > old) { + for (i = old;i < new;i+= 0x1000) { + if (vmm_remapPage(vmmFindFreePage(_current->id),i,PAGE_DEFAULT) == 0x0) + K_PANIC("remap Failed"); + /* Clear Page */ + } + td->vm_dsize += btoc(new - old); + } + else if (new < old) { + kprintf("0x%X < 0x%X\n",new,old); + //K_PANIC("new < old"); + td->vm_dsize -= btoc(old - new); + } + + return(0x0); + } + +int munmap(struct thread *td,struct munmap_args *uap) { + /* HACK */ + //kprintf("munmap: [0x%X:0x%X]",uap->addr,uap->len); + return(0x0); + } + +/*** + END + ***/ + diff --git a/vmm/setpageattributes.c b/vmm/setpageattributes.c new file mode 100644 index 0000000..25bae0a --- /dev/null +++ b/vmm/setpageattributes.c @@ -0,0 +1,104 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software +without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +/************************************************************************ + +Function: void vmmSetPageAttributes(uInt32 pageAddr,int attributes; +Description: This Function Will Set The Page Attributes Such As + A Read Only Page, Stack Page, COW Page, ETC. +Notes: + +************************************************************************/ +int vmm_setPageAttributes(uInt32 memAddr,uInt16 attributes) { + uInt16 directoryIndex = 0x0, tableIndex = 0x0; + uInt32 *pageTable = 0x0; + + /* Calculate The Page Directory Index */ + directoryIndex = (memAddr >> 22); + + /* Calculate The Page Table Index */ + tableIndex = ((memAddr >> 12) & 0x3FF); + + /* Set Table Pointer */ + if ((pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * directoryIndex))) == 0x0) + kpanic("Error: pageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Set Attribute If Page Is Mapped */ + if (pageTable[tableIndex] != 0x0) + pageTable[tableIndex] = ((pageTable[tableIndex] & 0xFFFFF000) | attributes); + + /* Reload The Page Table; */ + asm volatile( + "push %eax \n" + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + "pop %eax \n" + ); + /* Return */ + return(0x0); + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:53 reddawg + no message + + Revision 1.4 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + + Revision 1.3 2004/07/20 22:29:55 reddawg + assert: remade assert + + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/vmm/unmappage.c b/vmm/unmappage.c new file mode 100644 index 0000000..938e3ff --- /dev/null +++ b/vmm/unmappage.c @@ -0,0 +1,146 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: void vmmUnmapPage(uInt32 pageAddr,int flags); +Description: This Function Will Unmap A Page From The Kernel VM Space + The Flags Variable Decides If Its To Free The Page Or Not + A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It +Notes: + +07/30/02 - I Have Decided That This Should Free The Physical Page There + Is No Reason To Keep It Marked As Not Available + +07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit + Even I Am Not Perfect Ok The Case Where You Wouldn't Want To + Free It Would Be On Something Like Where I Allocated A Page + To Create A New Virtual Space So Now It Has A Flag + +************************************************************************/ +void +vmmUnmapPage(uInt32 pageAddr, int flags) +{ + int pageDirectoryIndex = 0, pageTableIndex = 0; + uInt32 *pageTable = 0x0; + + /* Get The Index To The Page Directory */ + pageDirectoryIndex = (pageAddr >> 22); + + //Calculate The Page Table Index + pageTableIndex = ((pageAddr >> 12) & 0x3FF); + + /* Set pageTable To The Virtual Address Of Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * pageDirectoryIndex)); + /* Free The Physical Page If Flags Is 0 */ + if (flags == 0) { + + /* + * This is temp i think its still an issue clearVirtualPage(pageAddr); + * freePage((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); + */ + } + /* Unmap The Page */ + pageTable[pageTableIndex] = 0x0; + /* Rehash The Page Directory */ + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + /* Return */ + return; +} + + + +/************************************************************************ + +Function: void vmmUnmapPages(uInt32 pageAddr,int flags); +Description: This Function Will Unmap A Page From The Kernel VM Space + The Flags Variable Decides If Its To Free The Page Or Not + A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It +Notes: + +07/30/02 - I Have Decided That This Should Free The Physical Page There + Is No Reason To Keep It Marked As Not Available + +07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit + Even I Am Not Perfect Ok The Case Where You Wouldn't Want To + Free It Would Be On Something Like Where I Allocated A Page + To Create A New Virtual Space So Now It Has A Flag + +************************************************************************/ +void vmmUnmapPages(void *ptr,uInt32 size) { + uInt32 baseAddr = (uInt32)ptr & 0xFFFFF000; + uInt32 dI = 0x0,tI = 0x0; + uInt32 y = 0x0; + uInt32 *pageTable = 0x0; + + dI = (baseAddr/(1024*4096)); + tI = ((baseAddr-(dI*(1024*4096)))/4096); + pageTable = (uInt32 *)(tablesBaseAddress + (4096*dI)); + for (y=tI;y<(tI+((size+4095)/4096));y++) { + pageTable[y] = 0x0; + } + return; + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:54 reddawg + no message + + Revision 1.4 2004/07/26 19:15:49 reddawg + test code, fixes and the like + + Revision 1.3 2004/06/15 12:35:05 reddawg + Cleaned Up + + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.7 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/vmm/vmm_init.c b/vmm/vmm_init.c new file mode 100644 index 0000000..b6e8d37 --- /dev/null +++ b/vmm/vmm_init.c @@ -0,0 +1,54 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +/*! + Function: int vmm_init() + + Description: Initializes the vmm subsystem + + Notes: + +*/ +int vmm_init() { + if (vmmMemMapInit() != 0x0) + K_PANIC("Couldn't Initialize vmmMemMap"); + + if (vmm_pagingInit() != 0x0) + K_PANIC("Couldn't Initialize paging system"); + + return (0x0); + } + +/*** + END + ***/ + diff --git a/vmm/vmm_memory.c b/vmm/vmm_memory.c new file mode 100644 index 0000000..0952385 --- /dev/null +++ b/vmm/vmm_memory.c @@ -0,0 +1,419 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +static uInt32 freePages = 0; +static spinLock_t vmmSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t vmmCowSpinLock = SPIN_LOCK_INITIALIZER; + + +int numPages = 0x0; +mMap *vmmMemoryMap = (mMap *) 0x101000; + + +/************************************************************************ + + Function: void vmmMemMapInit(); + Description: This Function Initializes The Memory Map For the System + Notes: + + 02/20/2004 - Made It Report Real And Available Memory + +************************************************************************/ +int vmmMemMapInit() { + int i = 0x0; + int memStart = 0x0; + + /* Count System Memory */ + numPages = countMemory(); + + /* Set Memory Map To Point To First Physical Page That We Will Use */ + vmmMemoryMap = (mMap *) 0x101000; + + /* Initialize Map Make All Pages Not Available */ + for (i = 0x0; i < numPages; i++) { + vmmMemoryMap[i].cowCounter = 0x0; + vmmMemoryMap[i].status = memNotavail; + vmmMemoryMap[i].pid = vmmID; + vmmMemoryMap[i].pageAddr = i * 4096; + } + + /* Calculate Start Of Free Memory */ + memStart = (0x101000 / 0x1000); + memStart += (((sizeof(mMap) * numPages) + (sizeof(mMap) - 1)) / 0x1000); + + /* Initialize All Free Pages To Available */ + vmmMemoryMap[(0x100000 / 0x1000)].status = memAvail; + freePages++; + for (i = memStart; i < numPages; i++) { + vmmMemoryMap[i].status = memAvail; + freePages++; + } + + /* Print Out Amount Of Memory */ + kprintf("Real Memory: %iKB\n", numPages * 4); + kprintf("Available Memory: %iKB\n", freePages * 4); + + /* Return */ + return (0); + } + +/************************************************************************ + + Function: int countMemory(); + Description: This Function Counts The Systems Physical Memory + Notes: + + 02/20/2004 - Inspect For Quality And Approved + +************************************************************************/ +int countMemory() { + register uInt32 *mem = 0x0; + unsigned long memCount = -1, tempMemory = 0x0; + unsigned short memKb = 0; + unsigned char irq1State, irq2State; + unsigned long cr0 = 0x0; + + /* + * Save The States Of Both IRQ 1 And 2 So We Can Turn Them Off And Restore + * Them Later + */ + irq1State = inportByte(0x21); + irq2State = inportByte(0xA1); + + /* Turn Off IRQ 1 And 2 To Prevent Chances Of Faults While Examining Memory */ + outportByte(0x21, 0xFF); + outportByte(0xA1, 0xFF); + + /* Save The State Of Register CR0 */ + asm volatile ( + "movl %%cr0, %%ebx\n" + : "=a" (cr0) + : + : "ebx" + ); + + asm volatile ("wbinvd"); + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) + : "ebx" + ); + + while (memKb < 4096 && memCount != 0) { + memKb++; + if (memCount == -1) + memCount = 0; + memCount += 1024 * 1024; + mem = (uInt32 *)memCount; + tempMemory = *mem; + *mem = 0x55AA55AA; + asm("": : :"memory"); + if (*mem != 0x55AA55AA) { + memCount = 0; + } + else { + *mem = 0xAA55AA55; + asm("": : :"memory"); + if (*mem != 0xAA55AA55) { + memCount = 0; + } + } + asm("": : :"memory"); + *mem = tempMemory; + } + + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0) + : "ebx" + ); + + /* Restore States For Both IRQ 1 And 2 */ + outportByte(0x21, irq1State); + outportByte(0xA1, irq2State); + + /* Return Amount Of Memory In Pages */ + return ((memKb * 1024 * 1024) / 4096); + } + +/************************************************************************ + + Function: uInt32 vmmFindFreePage(pid_t pid); + + Description: This Returns A Free Physical Page Address Then Marks It + Not Available As Well As Setting The PID To The Proccess + Allocating This Page + Notes: + +************************************************************************/ +uInt32 vmmFindFreePage(pidType pid) { + int i = 0x0; + + /* Lets Look For A Free Page */ + if (pid < sysID) + kpanic("Error: invalid PID %i\n",pid); + + spinLock(&vmmSpinLock); + + for (i = 0; i <= numPages; i++) { + + /* + * If We Found A Free Page Set It To Not Available After That Set Its Own + * And Return The Address + */ + if ((vmmMemoryMap[i].status == memAvail) && (vmmMemoryMap[i].cowCounter == 0)) { + vmmMemoryMap[i].status = memNotavail; + vmmMemoryMap[i].pid = pid; + freePages--; + if (systemVitals) + systemVitals->freePages = freePages; + + spinUnlock(&vmmSpinLock); + return (vmmMemoryMap[i].pageAddr); + } + } + + /* If No Free Memory Is Found Return NULL */ + kpanic("Out Of Memory!!!!"); + return (0x0); + } + + +/************************************************************************ + + Function: int freePage(uInt32 pageAddr); + + Description: This Function Marks The Page As Free + + Notes: + +************************************************************************/ +int freePage(uInt32 pageAddr) { + int pageIndex = 0x0; + assert((pageAddr & 0xFFF) == 0x0); + spinLock(&vmmSpinLock); + + /* Find The Page Index To The Memory Map */ + pageIndex = (pageAddr / 4096); + + /* Check If Page COW Is Greater Then 0 If It Is Dec It If Not Free It */ + if (vmmMemoryMap[pageIndex].cowCounter == 0) { + /* Set Page As Avail So It Can Be Used Again */ + vmmMemoryMap[pageIndex].status = memAvail; + vmmMemoryMap[pageIndex].cowCounter = 0x0; + vmmMemoryMap[pageIndex].pid = -2; + freePages++; + systemVitals->freePages = freePages; + } + else { + /* Adjust The COW Counter */ + adjustCowCounter(((uInt32) vmmMemoryMap[pageIndex].pageAddr), -1); + } + spinUnlock(&vmmSpinLock); + /* Return */ + return (0); + } + +/************************************************************************ + + Function: int adjustCowCounter(uInt32 baseAddr,int adjustment); + + Description: This Adjust The COW Counter For Page At baseAddr It Will + Error If The Count Goes Below 0 + + Notes: + + 08/01/02 - I Think If Counter Gets To 0 I Should Free The Page + +************************************************************************/ +int adjustCowCounter(uInt32 baseAddr, int adjustment) { + int vmmMemoryMapIndex = (baseAddr / 4096); + assert((baseAddr & 0xFFF) == 0x0); + spinLock(&vmmCowSpinLock); + /* Adjust COW Counter */ + vmmMemoryMap[vmmMemoryMapIndex].cowCounter += adjustment; + + if (vmmMemoryMap[vmmMemoryMapIndex].cowCounter == 0) { + vmmMemoryMap[vmmMemoryMapIndex].cowCounter = 0x0; + vmmMemoryMap[vmmMemoryMapIndex].pid = vmmID; + vmmMemoryMap[vmmMemoryMapIndex].status = memAvail; + freePages++; + systemVitals->freePages = freePages; + } + spinUnlock(&vmmCowSpinLock); + /* Return */ + return (0); + } + +/************************************************************************ + + Function: void vmmFreeProcessPages(pid_t pid); + + Description: This Function Will Free Up Memory For The Exiting Process + + Notes: + + 08/04/02 - Added Checking For COW Pages First + +************************************************************************/ +void vmmFreeProcessPages(pidType pid) { + int i=0,x=0; + uInt32 *tmpPageTable = 0x0; + uInt32 *tmpPageDir = (uInt32 *)parentPageDirAddr; + spinLock(&vmmSpinLock); + /* Check Page Directory For An Avail Page Table */ + for (i=0;i<=0x300;i++) { + if (tmpPageDir[i] != 0) { + /* Set Up Page Table Pointer */ + tmpPageTable = (uInt32 *)(tablesBaseAddress + (i * 0x1000)); + /* Check The Page Table For COW Pages */ + for (x=0;xfreePages = freePages; + } + } + } + /* Return */ + spinUnlock(&vmmSpinLock); + return; + } + +/*** + $Log$ + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg + UbixOS + + Revision 1.1 2006/12/01 18:46:19 reddawg + renaming files + + Revision 1.2 2006/12/01 05:12:35 reddawg + We're almost there... :) + + Revision 1.1.1.1 2006/06/01 12:46:13 reddawg + ubix2 + + Revision 1.5 2006/06/01 12:42:09 reddawg + Getting back to the basics + + Revision 1.4 2006/06/01 04:15:32 reddawg + Woot + + Revision 1.3 2006/06/01 03:58:33 reddawg + wondering about this stuff here + + Revision 1.2 2005/10/12 00:13:38 reddawg + Removed + + Revision 1.1.1.1 2005/09/26 17:24:51 reddawg + no message + + Revision 1.15 2004/09/11 23:39:31 reddawg + ok time for bed + + Revision 1.14 2004/09/11 16:39:19 apwillia + Fix order in adjustCowCounter to prevent potential race condition + + Revision 1.13 2004/08/14 11:23:03 reddawg + Changes + + Revision 1.12 2004/08/01 20:51:33 reddawg + adjustCowCounter: we no longer need to debug unhandled adjustments they are normal situations now + + Revision 1.11 2004/07/28 00:17:05 reddawg + Major: + Disconnected page 0x0 from the system... Unfortunately this broke many things + all of which have been fixed. This was good because nothing deferences NULL + any more. + + Things affected: + malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file + + Revision 1.10 2004/07/26 19:15:49 reddawg + test code, fixes and the like + + Revision 1.9 2004/07/24 23:04:44 reddawg + Changes... mark let me know if you fault at pid 185 when you type stress + + Revision 1.8 2004/07/24 17:47:28 reddawg + vmm_pageFault: deadlock resolved thanks to a propper solution suggested by geist + + Revision 1.7 2004/07/19 02:04:32 reddawg + memory.c: added spinlocks to vmmFindFreePage and vmmFreePage to prevent two tasks from possibly allocating the same page + + Revision 1.6 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.5 2004/05/21 15:34:23 reddawg + Fixed a couple of typo + + Revision 1.4 2004/05/21 14:50:10 reddawg + Cleaned up + + Revision 1.3 2004/05/19 17:28:28 reddawg + Added the correct endTask Procedure + + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:06:52 reddawg + UbixOS v1.0 + + Revision 1.27 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + END + ***/ diff --git a/vmm/vmm_virtual.c b/vmm/vmm_virtual.c new file mode 100644 index 0000000..fbea4a9 --- /dev/null +++ b/vmm/vmm_virtual.c @@ -0,0 +1,607 @@ +/***************************************************************************************** + Copyright (c) 2002-2004,2005,2006,2007,2009 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int vmm_cleanVirtualSpace(u_int32_t addr) { + int x = 0x0; + int y = 0x0; + u_int32_t *pageTableSrc = 0x0; + u_int32_t *pageDir = 0x0; + + pageDir = (uInt32 *) parentPageDirAddr; + + #ifdef VMMDEBUG + kprintf("Called: vmm_cleanVirtualSpace(0x%X)\n",addr); + #endif + + /* Loop through the users virtual space flushing out COW pages */ + /* BUG memory leak this does not update COW counter on master page */ + for (x = (addr / (1024 * 4096)); x < 770; x++) { + if ((pageDir[x] & PAGE_PRESENT) == PAGE_PRESENT) { + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + for (y = 0;y < 1024;y++) { + if (pageTableSrc[y] != 0x0) { + if ((pageTableSrc[y] & PAGE_COW) == PAGE_COW) { + //kprintf("COWi*"); + pageTableSrc[y] = 0x0; + } + else if ((pageTableSrc[y] & PAGE_STACK) == PAGE_STACK) { + //pageTableSrc[y] = 0x0; + //kprintf("STACK: (%i:%i)",x,y); + } + else { + //kprintf("+"); + } + } + } + } + } + + /* we must now reload the page directory */ + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + + return(0x0); + } /* end func */ + +/************************************************************************ + +Function: void *vmmGetFreeVirtualPage(pidType pid,int count); +Description: Returns A Free Page Mapped To The VM Space +Notes: + +08/11/02 - This Will Return Next Avilable Free Page Of Tasks VM Space + +************************************************************************/ +static spinLock_t fvpSpinLock = SPIN_LOCK_INITIALIZER; + +void *vmmGetFreeVirtualPage(pidType pid, int count,int type) { + int x = 0, y = 0, c = 0; + uInt32 *pageTableSrc = 0x0; + uInt32 *pageDir = 0x0; + uInt32 start_page = 0x0; + + + spinLock(&fvpSpinLock); + + pageDir = (uInt32 *)PARENT_PAGEDIR_ADDR; + + /* Lets Search For A Free Page */ + if (_current->oInfo.vmStart <= 0x100000) + K_PANIC("Invalid vmStart\n"); + + + /* Set starting page based on page allocation type */ + if (type == VM_THRD) { + start_page = (u_int32_t)(_current->td.vm_daddr + ctob(_current->td.vm_dsize)); + #ifdef DEBUG + kprintf(".%i.",count); + #endif + //count--; + } + else if (type == VM_TASK) { + //kprintf("vmStart"); + start_page = _current->oInfo.vmStart; + } + else + K_PANIC("Invalid Type"); + + for (x = (start_page / (1024 * 4096)); x < 1024; x++) { + + /* Set Page Table Address */ + if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { + + /* If Page Table Is Non Existant Then Set It Up */ + pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; + + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTableSrc[x] = pageDir[x]; + y = 1; + + /* Reload Page Directory */ + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + + if (y != 0x0) { + for (y = 0x0;ytd.vm_dsize += btoc(0x1000); + /* BUG MEMORY LEAK */ + //pageTableSrc[y] = 0x0; + } + + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + + if (count > 0x1) { + + for (c = 0; c < count; c++) { + + if (y + c < 1024) { + + if ((pageTableSrc[y + c] & PAGE_COW) == PAGE_COW) { + #ifdef VMMDEBUG + kprintf("PAGE-COW-2"); + #endif + //_current->td.vm_dsize += btoc(0x1000); + /* BUG MEMORY LEAK */ + //pageTableSrc[y + c] = 0x0; + } + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + if (type == VM_THRD) + _current->td.vm_dsize += btoc(count * 0x1000); + spinUnlock(&fvpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + else { + /* Map A Physical Page To The Virtual Page */ + + /* + * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) + * ,pid); + */ + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); + + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + + /* Return The Address Of The Newly Allocate Page */ + if (type == VM_THRD) { + _current->td.vm_dsize += btoc(count * 0x1000); + #ifdef VMMDEBUG2 + kprintf("vm_dsize: [0x%X]][0x%X]\n",ctob(_current->td.vm_dsize),_current->td.vm_dsize); + #endif + } + //kprintf("(0x%X:0x%X)",_current->td.vm_dsize,vmm_getPhysicalAddr(((x * (1024 * 4096)) + (y * 4096)))); +// kprintf("(0x%X:0x%X)",_current->td.vm_dsize + _current->td.vm_daddr,((x * (1024 * 4096)) + (y * 4096))); + spinUnlock(&fvpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fvpSpinLock); + return (0x0); + } /* end func */ + +void *vmmGetFreeVirtualPage_new(pidType pid, int count,int type,u_int32_t start_addr) { + int x = 0, y = 0, c = 0; + uInt32 *pageTableSrc = 0x0; + uInt32 *pageDir = 0x0; + uInt32 start_page = 0x0; + + + spinLock(&fvpSpinLock); + + pageDir = (uInt32 *) parentPageDirAddr; + + /* Lets Search For A Free Page */ + if (_current->oInfo.vmStart <= 0x100000) + kpanic("Invalid vmStart\n"); + + if (type == VM_THRD) { + start_page = (u_int32_t)(_current->td.vm_daddr + ctob(_current->td.vm_dsize)); + } + else if (type == VM_TASK) { + //kprintf("vmStart"); + start_page = _current->oInfo.vmStart; + } + else + K_PANIC("Invalid Type"); + +start_page = start_addr; + + //for (x = ((_current->td.vm_daddr + _current->td.vm_dsize) / (1024 * 4096)); x < 1024; x++) { + for (x = (start_page / (1024 * 4096)); x < 1024; x++) { + /* Set Page Table Address */ + if ((pageDir[x] & PAGE_PRESENT) != PAGE_PRESENT) { + /* If Page Table Is Non Existant Then Set It Up */ + pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | PAGE_DEFAULT; + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTableSrc[x] = pageDir[x]; + y = 1; + /* Reload Page Directory */ + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + if (y != 0x0) { + for (y = 0x0;ytd.vm_dsize += btoc(0x1000); + /* HACK MEMORY LEAK */ + //pageTableSrc[y] = 0x0; + } + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + if (count > 0x1) { + for (c = 0; c < count; c++) { + if (y + c < 1024) { + if ((pageTableSrc[y + c] & PAGE_COW) == PAGE_COW) { + kprintf("PAGE-COW"); + //_current->td.vm_dsize += btoc(0x1000); + /* HACK MEMORY LEAK */ + //pageTableSrc[y + c] = 0x0; + } + + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-1: [0x%X]\n",((x * (1024 * 4096)) + ((y + c) * 4096))); + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + if (type == VM_THRD) + _current->td.vm_dsize += btoc(count * 0x1000); + spinUnlock(&fvpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } else { + /* Map A Physical Page To The Virtual Page */ + + /* + * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) + * ,pid); + */ + if ((vmm_remapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096)),PAGE_DEFAULT)) == 0x0) + kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); + + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + + /* Return The Address Of The Newly Allocate Page */ + if (type == VM_THRD) { + _current->td.vm_dsize += btoc(count * 0x1000); + #ifdef DEBUG + kprintf("vm_dsize: [0x%X]][0x%X]\n",ctob(_current->td.vm_dsize),_current->td.vm_dsize); + #endif + } + //kprintf("(0x%X:0x%X)",_current->td.vm_dsize,vmm_getPhysicalAddr(((x * (1024 * 4096)) + (y * 4096)))); +// kprintf("(0x%X:0x%X)",_current->td.vm_dsize + _current->td.vm_daddr,((x * (1024 * 4096)) + (y * 4096))); + spinUnlock(&fvpSpinLock); + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + spinUnlock(&fvpSpinLock); + return (0x0); +} + +/************************************************************************ + +Function: void *vmmCopyVirtualSpace(pidType pid); + +Description: Creates A Copy Of A Virtual Space And Set All NON Kernel + Space To COW For A Fork This Will Also Alter The Parents + VM Space To Make That COW As Well + +Notes: + +08/02/02 - Added Passing Of pidType pid So We Can Better Keep Track Of + Which Task Has Which Physical Pages + +************************************************************************/ +static spinLock_t cvsSpinLock = SPIN_LOCK_INITIALIZER; + +void *vmmCopyVirtualSpace(pidType pid) { + void *newPageDirectoryAddress = 0x0; + uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; + uInt32 *parentStackPage = 0x0, *newStackPage = 0x0; + uInt16 x = 0, i = 0, s = 0; + + spinLock(&cvsSpinLock); + + /* Set Address Of Parent Page Directory */ + parentPageDirectory = (uInt32 *) parentPageDirAddr; + /* Allocate A New Page For The New Page Directory */ + if ((newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); + + /* First Set Up A Flushed Page Directory */ + memset(newPageDirectory,0x0,0x1000); + + /* Map The Top 1GB Region Of The VM Space */ + for (x = 768; x < pageEntries; x++) { + newPageDirectory[x] = parentPageDirectory[x]; + } + + /* + * Now For The Fun Stuff For Page Tables 1-766 We Must Map These And Set + * The Permissions On Every Mapped Pages To COW This Will Conserve Memory + * Because The Two VM Spaces Will Be Sharing Some Pages + */ + for (x = 0x1; x <= 766; x++) { + /* If Page Table Exists Map It */ + if (parentPageDirectory[x] != 0) { + /* Set Parent To Propper Page Table */ + parentPageTable = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + /* Allocate A New Page Table */ + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Set Parent And New Pages To COW */ + for (i = 0; i < pageEntries; i++) { + + /* If Page Is Mapped */ + if ((parentPageTable[i] & 0xFFFFF000) != 0x0) { + /* Check To See If Its A Stack Page */ + if (((uInt32) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { + /* Alloc A New Page For This Stack Page */ + if ((newStackPage = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Set Pointer To Parents Stack Page */ + parentStackPage = (uInt32 *) (((1024 * 4096) * x) + (4096 * i)); + + /* Copy The Tack Byte For Byte (I Should Find A Faster Way) */ + for (s = 0x0; s < pageEntries; s++) { + newStackPage[s] = parentStackPage[s]; + } + /* Insert New Stack Into Page Table */ + newPageTable[i] = (vmm_getPhysicalAddr((uInt32) newStackPage) | PAGE_DEFAULT | PAGE_STACK); + /* Unmap From Kernel Space */ + vmmUnmapPage((uInt32) newStackPage, 1); + } + else { + /* Set Page To COW In Parent And Child Space */ + newPageTable[i] = (((uInt32) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); + /* Increment The COW Counter For This Page */ + if (((uInt32) parentPageTable[i] & PAGE_COW) == PAGE_COW) { + adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 1); + } + else { + adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 2); + parentPageTable[i] = newPageTable[i]; + } + } + } + else { + newPageTable[i] = (uInt32) 0x0; + } + } + + /* Put New Page Table Into New Page Directory */ + newPageDirectory[x] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ + vmmUnmapPage((uInt32) newPageTable, 1); + } else { + newPageDirectory[x] = (uInt32) 0x0; + } + } + /* + * Allocate A New Page For The The First Page Table Where We Will Map The + * Lower Region + */ + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + + /* Flush The Page From Garbage In Memory */ + memset(newPageTable,0x0,0x1000); + + /* Map This Into The Page Directory */ + newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + /* Set Address Of Parents Page Table */ + parentPageTable = (uInt32 *) tablesBaseAddress; + /* Map The First 1MB Worth Of Pages */ + for (x = 0; x < (pageEntries / 4); x++) { + newPageTable[x] = parentPageTable[x]; + } + /* Map The Next 3MB Worth Of Pages But Make Them COW */ + for (x = (pageEntries / 4) + 1; x < pageEntries; x++) { + /* If Page Is Avaiable Map It */ + if ((parentPageTable[x] & 0xFFFFF000) != 0x0) { + /* Set Pages To COW */ + newPageTable[x] = (((uInt32) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); + /* Increment The COW Counter For This Page */ + if (((uInt32) parentPageTable[x] & PAGE_COW) == PAGE_COW) { + adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 1); + } else { + adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 2); + parentPageTable[x] = newPageTable[x]; + } + } else { + newPageTable[x] = (uInt32) 0x0; + } + } + /* Set Virtual Mapping For Page Directory */ + newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); + + /* + * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have + * To Worry About Mapping Them In Later How Ever I'm Concerned This May + * Become A Security Issue + */ + /* First Lets Unmap The Previously Allocated Page Table */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Allocate A New Page Table */ + if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid,1)) == 0x0) + kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + /* First Set Our Page Directory To Contain This */ + newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; + /* Now Lets Build The Page Table */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = newPageDirectory[x]; + } + /* Now We Are Done So Lets Unmap This Page */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Now We Are Done With The Page Directory So Lets Unmap That Too */ + vmmUnmapPage((uInt32) newPageDirectory, 1); + + spinUnlock(&cvsSpinLock); + + /* Return Physical Address Of Page Directory */ + return (newPageDirectoryAddress); + } /* end func */ + +/************************************************************************ + +Function: void *vmmCreateVirtualSpace(pid_t); +Description: Creates A Virtual Space For A New Task +Notes: + +07/30/02 - This Is Going To Create A New VM Space However Its Going To + Share The Same Top 1GB Space With The Kernels VM And Lower + 1MB Of VM Space With The Kernel + +07/30/02 - Note This Is Going To Get The Top 1Gig And Lower 1MB Region + From The Currently Loaded Page Directory This Is Safe Because + All VM Spaces Will Share These Regions + +07/30/02 - Note I Realized A Mistake The First Page Table Will Need To Be + A Copy But The Page Tables For The Top 1GB Will Not Reason For + This Is That We Just Share The First 1MB In The First Page Table + So We Will Just Share Physical Pages. + +08/02/02 - Added Passing Of pid_t pid For Better Tracking Of Who Has Which + Set Of Pages + +************************************************************************/ +void *vmmCreateVirtualSpace(pid_t pid) { + void *newPageDirectoryAddress = 0x0; + uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; + int x = 0; + + /* Set Address Of Parent Page Directory */ + parentPageDirectory = (uInt32 *) parentPageDirAddr; + /* Allocate A New Page For The New Page Directory */ + newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid); + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ + newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory); + /* First Set Up A Flushed Page Directory */ + for (x = 0; x < pageEntries; x++) { + newPageDirectory[x] = 0x0; + } + /* Map The Top 1GB Region Of The VM Space */ + for (x = 768; x < pageEntries; x++) { + newPageDirectory[x] = parentPageDirectory[x]; + } + /* + * Allocate A New Page For The The First Page Table Where We Will Map The + * Lower Region + */ + newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid); + /* Flush The Page From Garbage In Memory */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = 0x0; + } + /* Map This Into The Page Directory */ + newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + /* Set Address Of Parents Page Table */ + parentPageTable = (uInt32 *) tablesBaseAddress; + /* Map The First 1MB Worth Of Pages */ + for (x = 0; x < (pageEntries / 4); x++) { + newPageTable[x] = parentPageTable[x]; + } + /* Set Virtual Mapping For Page Directory */ + newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT); + + /* + * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have + * To Worry About Mapping Them In Later How Ever I'm Concerned This May + * Become A Security Issue + */ + /* First Lets Unmap The Previously Allocated Page Table */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Allocate A New Page Table */ + newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid); + /* First Set Our Page Directory To Contain This */ + newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT; + /* Now Lets Build The Page Table */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = newPageDirectory[x]; + } + /* Now We Are Done So Lets Unmap This Page */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Now We Are Done With The Page Directory So Lets Unmap That Too */ + vmmUnmapPage((uInt32) newPageDirectory, 1); + /* Return Physical Address Of Page Directory */ + return (newPageDirectoryAddress); + } /* End Func */ + +/* + END + */