diff --git a/src/sys/deviceman/bus_resources_portio.c b/src/sys/deviceman/bus_resources_portio.c new file mode 100755 index 0000000..d77534e --- /dev/null +++ b/src/sys/deviceman/bus_resources_portio.c @@ -0,0 +1,77 @@ +/* + "bus_resources_portio.c" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + purpose: for port IO resource management + + $Id$ +*/ + +#include "gsdefines.h" +#include "misc_bit_array.h" + +/* checks a range of port addresses + returns: + - 1 if the range is comptetely empty + - 0 otherwise */ +int BUS_PORTIO_CheckRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ) +{ + BIT_ARRAY_RANGE_PARAMS rp; + BIT_ARRAY_MAKERANGEPARAMS( rp, p_bpp->a_addrs, baseaddr, overaddr ); + return BIT_ARRAY_IsRangeEmpty( &rp ); +} + +/* allocates a range of port addresses + returns: + - 1 on success + - 0 on failure */ +int BUS_PORTIO_AllocateRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ) +{ + BIT_ARRAY_RANGE_PARAMS rp; + BIT_ARRAY_MAKERANGEPARAMS( rp, p_bpp->a_addrs, baseaddr, overaddr ); + + /* check if this port range is free */ + if( BIT_ARRAY_IsRangeEmpty( &rp ) ) + { + /* allocate it */ + BIT_ARRAY_SetRange( &rp ); + + /* success */ + return 1; + } + + /* fail */ + return 0; +} + +/* frees a range of port addresses + returns: + - 1 if any port addresses in the range were allocated + - 0 otherwise */ +int BUS_PORTIO_FreeRange( BUS_PORTIO_POOL * p_bpp, + DWORDg baseaddr, + DWORDg overaddr ) +{ + BIT_ARRAY_RANGE_PARAMS rp; + BIT_ARRAY_MAKERANGEPARAMS( rp, p_bpp->a_addrs, baseaddr, overaddr ); + + /* check if this port range is free */ + if( !BIT_ARRAY_IsRangeEmpty( &rp ) ) + { + /* free it */ + BIT_ARRAY_ResetRange( &rp ); + + /* success */ + return 1; + } + + /* fail */ + return 0; +} \ No newline at end of file diff --git a/src/sys/include/misc/kernel_string_pool.h b/src/sys/include/misc/kernel_string_pool.h new file mode 100755 index 0000000..8a09ec3 --- /dev/null +++ b/src/sys/include/misc/kernel_string_pool.h @@ -0,0 +1,102 @@ +/* + "kernel_string_pool.h" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 11, 2002 + + purpose: to provide a mechanism for maintaining a pool of strings + for use by the kernel without unnecessary waste of memory + + NOTEs: + - for now only ASCII is supported + - done quickly, pretty hacky + + TODO: + - expand to support unicode + - use huffman encoding instead + + $Id$ +*/ + +#ifndef _KERNEL_STRING_POOL_H +#define _KERNEL_STRING_POOL_H + +/* memory FORMAT of a 'KRNSTR': (quick and dirty for now) + + an 'ID' is used to indicate a string within the pool + ---------------------------------------------------- + + 'ID' - [DWORD]: + - 'num-words' - bits [0,7] + - number of 'KRNWORD's in the string is 'num-words' + 1 + - bits [8,32] BYTE offset inside pool where the 'KRNSTR' + (kernel string) is stored + + 'KRNSTR's (kernel strings) are specified as an array of continuous BYTEs + ------------------------------------------------------------------------ + + 'KRNSTR': + - [KRNWORD] x 'num-words' (given by ID) + + 'KRNWORD': + - [BYTE] 'key1' + + - if key1 == [0,254]: + - key1 is the index of the 'sub-string' in the pool + + - otherwise key1 is an escape sequence and implies: + - [BYTE] 'key2' + - [BYTE] 'key3' + - the index of the 'sub-string' in the pool is key2*256 + key3 + 255 + + - NOTE: the reason for using two extra 8-bit keys instead of a 16-bit + value is in case we port to platform with data alignment exceptions + and this stuff is left dormant and never changed + + - NOTE: a 'space' (0x20) is implied between each 'KRNWORD', therefore + it is not currently possible to break encode string AB into substrings + A & B if AB does not contain any spaces + + - a 'sub-string' is found by using the the index of the + 'sub-string' in the pool to get an offset into an array + of continuous BYTEs via lookup + + 'sub-string's are specified as an array of continuous BYTEs + ----------------------------------------------------------- + + - a 'sub-string' is as follows: + + - [BYTE] 'numchars' [0,255] -> [1,256] + - [BYTE] x 'numchars' (the chars themselves) + + - WARNING: empty 'sub-string's are not allowed + +*/ + +/* WARNING: it is *assumed* any 'ID' given to a kernel + string pool function will be valid!! */ + +/* structure for kernel string pool */ +typedef struct tagKSTR_POOL +{ + /* pointer to where the kernel strings are stored */ + const BYTEg * p_krnstrs; + + /* pointer to where the sub strings are stored */ + const BYTEg * p_substrs; + + /* lookup table for substring offsets */ + const unsigned int * p_substr_off; +} +KSTR_POOL; + +/* the reason for this structure format is so that a tool + can be written which can generate a 'KSTR_POOL' from a configuration + file and place it into a 'C' source and header file pair as static data */ + +// gets the substring indicated by 'id' from the pool 'p_ksp' into 'p_dst' +// - returns pointer to 'p_dst' +char * KSTR_POOL_GetString( KSTR_POOL * p_ksp, char * p_dst, DWORDg id ); + +#endif /* _KERNEL_STRING_POOL_H */ \ No newline at end of file diff --git a/src/sys/misc/kernel_string_pool.c b/src/sys/misc/kernel_string_pool.c index e85dfe7..79c732a 100755 --- a/src/sys/misc/kernel_string_pool.c +++ b/src/sys/misc/kernel_string_pool.c @@ -15,6 +15,8 @@ TODO: - expand to support unicode - use huffman encoding instead + + $Id$ */ #include "gsdefines.h" diff --git a/src/sys/misc/misc_bit_array.c b/src/sys/misc/misc_bit_array.c new file mode 100755 index 0000000..9271d12 --- /dev/null +++ b/src/sys/misc/misc_bit_array.c @@ -0,0 +1,93 @@ +/* + "misc_bit_array.c" + + created by: grayspace aka J. Leveille + for: UbixOS Project + date: May 12, 2002 + + purpose: functions for dealing with bit arrays + + $Id$ +*/ + +#include "gsdefines.h" +#include "misc_bit_array.h" +#include "bus_resources_portio.h" + +int BIT_ARRAY_IsRangeEmpty( BIT_ARRAY_RANGE_PARAMS * p_rp ) +{ + p_rp->p_curdw = p_rp->p_firstdw; + + if( !(p_rp->premask & *(p_rp->p_curdw) ) + { + if( p_rp->premask ) + { + p_rp->p_curdw++; + } + + while( p_rp->p_curdw < p_rp->p_overdw + && !( *(p_rp->p_curdw) ) ) + { + p_rp->p_curdw++; + } + + if( p_rp->p_curdw == p_rp->p_overdw ) + { + if( p_rp->postmask ) + { + if( p_rp->postmask & *(p_rp->p_overdw) ) + { + return 0; + } + } + + return 1; + } + } + + return 0; +} + +void BIT_ARRAY_SetRange( BIT_ARRAY_RANGE_PARAMS * p_rp ) +{ + p_rp->p_curdw = p_rp->p_firstdw; + + if( p_rp->premask ) + { + *(p_rp->p_curdw) |= p_rp->premask; + p_rp->p_curdw++; + } + + while( p_rp->p_curdw < p_rp->p_overdw ) + { + *(p_rp->p_curdw) = 0xFFFFFFFF; + p_rp->p_curdw++; + } + + if( p_rp->postmask ) + { + *(p_rp->p_curdw) |= p_rp->postmask; + } +} + +void BIT_ARRAY_ResetRange( BIT_ARRAY_RANGE_PARAMS * p_rp ) +{ + p_rp->p_curdw = p_rp->p_firstdw; + + if( p_rp->premask ) + { + *(p_rp->p_curdw) &= ~(p_rp->premask); + p_rp->p_curdw++; + } + + while( p_rp->p_curdw < p_rp->p_overdw ) + { + *(p_rp->p_curdw) = 0; + p_rp->p_curdw++; + } + + if( p_rp->postmask ) + { + *(p_rp->p_curdw) &= ~(p_rp->postmask); + } +}