[142] | 1 | /* $Id: misc.c 200 2001-12-20 19:58:01Z sandervl $ */
|
---|
| 2 |
|
---|
| 3 | //******************************************************************************
|
---|
| 4 | // OS/2 implementation of misc. Linux kernel services
|
---|
| 5 | //
|
---|
| 6 | // Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
| 7 | //
|
---|
| 8 | // Parts based on Linux kernel code (set/clear_bit)
|
---|
| 9 | //
|
---|
| 10 | // This program is free software; you can redistribute it and/or
|
---|
| 11 | // modify it under the terms of the GNU General Public License as
|
---|
| 12 | // published by the Free Software Foundation; either version 2 of
|
---|
| 13 | // the License, or (at your option) any later version.
|
---|
| 14 | //
|
---|
| 15 | // This program is distributed in the hope that it will be useful,
|
---|
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | // GNU General Public License for more details.
|
---|
| 19 | //
|
---|
| 20 | // You should have received a copy of the GNU General Public
|
---|
| 21 | // License along with this program; if not, write to the Free
|
---|
| 22 | // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
| 23 | // USA.
|
---|
| 24 | //
|
---|
| 25 | //******************************************************************************
|
---|
| 26 | #include "hwaccess.h"
|
---|
| 27 | #include <linux/init.h>
|
---|
| 28 | #include <linux/poll.h>
|
---|
| 29 | #include <asm/uaccess.h>
|
---|
| 30 | #include <asm/hardirq.h>
|
---|
| 31 | #include <linux\ioport.h>
|
---|
| 32 | #include <linux\utsname.h>
|
---|
| 33 |
|
---|
| 34 | struct new_utsname system_utsname = {0};
|
---|
| 35 | struct resource ioport_resource = {0};
|
---|
| 36 | mem_map_t *mem_map = 0;
|
---|
| 37 |
|
---|
| 38 | void set_bit(int nr, volatile void * addr)
|
---|
| 39 | {
|
---|
| 40 | volatile unsigned long *pAddr = (volatile unsigned long *)addr;
|
---|
| 41 |
|
---|
| 42 | *pAddr = (*pAddr) | (1 << nr);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | void clear_bit(int nr, volatile void * addr)
|
---|
| 46 | {
|
---|
| 47 | volatile unsigned long *pAddr = (volatile unsigned long *)addr;
|
---|
| 48 |
|
---|
| 49 | *pAddr = (*pAddr) & ~(1 << nr);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[151] | 52 | #define CR 0x0d
|
---|
| 53 | #define LF 0x0a
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | #define LEADING_ZEROES 0x8000
|
---|
| 57 | #define SIGNIFICANT_FIELD 0x0007
|
---|
| 58 |
|
---|
| 59 | char *HexLongToASCII(char *StrPtr, unsigned long wHexVal, unsigned short Option);
|
---|
| 60 | char *DecLongToASCII(char *StrPtr, unsigned long lDecVal, unsigned short Option);
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | //SvL: Not safe to use in non-KEE driver
|
---|
[142] | 64 | int sprintf (char *buffer, const char *format, ...)
|
---|
| 65 | {
|
---|
[151] | 66 | char *BuildPtr=buffer;
|
---|
| 67 | char *pStr = (char *) format;
|
---|
| 68 | char *SubStr;
|
---|
| 69 | union {
|
---|
| 70 | void *VoidPtr;
|
---|
| 71 | unsigned short *WordPtr;
|
---|
| 72 | unsigned long *LongPtr;
|
---|
| 73 | #ifdef KEE
|
---|
| 74 | unsigned long *StringPtr;
|
---|
| 75 | #else
|
---|
| 76 | double *StringPtr;
|
---|
| 77 | #endif
|
---|
| 78 | } Parm;
|
---|
| 79 | int wBuildOption;
|
---|
| 80 |
|
---|
| 81 | Parm.VoidPtr=(void *) &format;
|
---|
| 82 | Parm.StringPtr++; // skip size of string pointer
|
---|
| 83 |
|
---|
| 84 | while (*pStr)
|
---|
| 85 | {
|
---|
| 86 | switch (*pStr)
|
---|
| 87 | {
|
---|
| 88 | case '%':
|
---|
| 89 | wBuildOption=0;
|
---|
| 90 | pStr++;
|
---|
| 91 | if (*pStr=='0')
|
---|
| 92 | {
|
---|
| 93 | wBuildOption|=LEADING_ZEROES;
|
---|
| 94 | pStr++;
|
---|
| 95 | }
|
---|
| 96 | if (*pStr=='u') // always unsigned
|
---|
| 97 | pStr++;
|
---|
| 98 |
|
---|
| 99 | switch(*pStr)
|
---|
| 100 | {
|
---|
| 101 | case 'x':
|
---|
| 102 | case 'X':
|
---|
| 103 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
| 104 | pStr++;
|
---|
| 105 | continue;
|
---|
| 106 |
|
---|
| 107 | case 'd':
|
---|
| 108 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
| 109 | pStr++;
|
---|
| 110 | continue;
|
---|
| 111 |
|
---|
| 112 | #ifdef KEE
|
---|
| 113 | case 's':
|
---|
| 114 | SubStr=(char *)*Parm.StringPtr;
|
---|
| 115 | while (*BuildPtr++ = *SubStr++);
|
---|
| 116 | Parm.StringPtr++;
|
---|
| 117 | BuildPtr--; // remove the \0
|
---|
| 118 | pStr++;
|
---|
| 119 | continue;
|
---|
| 120 | #endif
|
---|
| 121 | case 'l':
|
---|
| 122 | pStr++;
|
---|
| 123 | switch (*pStr)
|
---|
| 124 | {
|
---|
| 125 | case 'x':
|
---|
| 126 | case 'X':
|
---|
| 127 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
| 128 | pStr++;
|
---|
| 129 | continue;
|
---|
| 130 |
|
---|
| 131 | case 'd':
|
---|
| 132 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
| 133 | pStr++;
|
---|
| 134 | continue;
|
---|
| 135 | } // end switch
|
---|
| 136 | continue; // dunno what he wants
|
---|
| 137 |
|
---|
| 138 | case 0:
|
---|
| 139 | continue;
|
---|
| 140 | } // end switch
|
---|
| 141 | break;
|
---|
| 142 |
|
---|
| 143 | case '\\':
|
---|
| 144 | pStr++;
|
---|
| 145 | switch (*pStr)
|
---|
| 146 | {
|
---|
| 147 | case 'n':
|
---|
| 148 | *BuildPtr++=LF;
|
---|
| 149 | pStr++;
|
---|
| 150 | continue;
|
---|
| 151 |
|
---|
| 152 | case 'r':
|
---|
| 153 | *BuildPtr++=CR;
|
---|
| 154 | pStr++;
|
---|
| 155 | continue;
|
---|
| 156 |
|
---|
| 157 | case 0:
|
---|
| 158 | continue;
|
---|
| 159 | break;
|
---|
| 160 | } // end switch
|
---|
| 161 |
|
---|
| 162 | break;
|
---|
| 163 | } // end switch
|
---|
| 164 |
|
---|
| 165 | *BuildPtr++=*pStr++;
|
---|
| 166 | } // end while
|
---|
| 167 |
|
---|
| 168 | *BuildPtr=0; // cauterize the string
|
---|
| 169 | return 1; //not correct
|
---|
[142] | 170 | }
|
---|
| 171 |
|
---|
| 172 | int printk(const char * fmt, ...)
|
---|
| 173 | {
|
---|
| 174 | return 0;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | void schedule(void)
|
---|
| 178 | {
|
---|
| 179 |
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
|
---|
| 183 | {
|
---|
| 184 |
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | int __check_region(struct resource *a, unsigned long b, unsigned long c)
|
---|
| 189 | {
|
---|
| 190 | return 0;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | void __release_region(struct resource *a, unsigned long b, unsigned long c)
|
---|
| 194 | {
|
---|
| 195 |
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | struct resource * __request_region(struct resource *a, unsigned long start, unsigned long n, const char *name)
|
---|
| 199 | {
|
---|
| 200 | return a;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void iodelay32(unsigned long);
|
---|
[200] | 204 | #pragma aux iodelay32 parm nomemory [ecx] modify nomemory exact [eax ecx];
|
---|
[142] | 205 |
|
---|
| 206 | void __udelay(unsigned long usecs)
|
---|
| 207 | {
|
---|
| 208 | iodelay32(usecs*2);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
[153] | 212 | /* --------------------------------------------------------------------- */
|
---|
| 213 | /*
|
---|
| 214 | * hweightN: returns the hamming weight (i.e. the number
|
---|
| 215 | * of bits set) of a N-bit word
|
---|
| 216 | */
|
---|
| 217 |
|
---|
| 218 | #ifdef hweight32
|
---|
| 219 | #undef hweight32
|
---|
| 220 | #endif
|
---|
| 221 |
|
---|
| 222 | unsigned int hweight32(unsigned int w)
|
---|
| 223 | {
|
---|
| 224 | unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
|
---|
| 225 | res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
|
---|
| 226 | res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
|
---|
| 227 | res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
|
---|
| 228 | return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
|
---|
| 229 | }
|
---|