Subversion Repositories shark

Rev

Rev 473 | Rev 500 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
432 giacomo 1
 
2
#include <ll/i386/hw-instr.h>
436 giacomo 3
#include <ll/i386/cons.h>
432 giacomo 4
 
5
#include <linuxcomp.h>
6
 
7
#include <linux/time.h>
8
#include <linux/sched.h>
436 giacomo 9
#include <linux/ioport.h>
437 giacomo 10
#include <linux/errno.h>
436 giacomo 11
#include <asm/io.h>
437 giacomo 12
#include <linux/ctype.h>
13
#include <linux/device.h>
462 giacomo 14
#include <linux/completion.h>
468 giacomo 15
#include <linux/tty.h>
16
#include <asm/setup.h>
432 giacomo 17
 
437 giacomo 18
unsigned char _ctype[] = {
19
_C,_C,_C,_C,_C,_C,_C,_C,                        /* 0-7 */
20
_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,         /* 8-15 */
21
_C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
22
_C,_C,_C,_C,_C,_C,_C,_C,                        /* 24-31 */
23
_S|_SP,_P,_P,_P,_P,_P,_P,_P,                    /* 32-39 */
24
_P,_P,_P,_P,_P,_P,_P,_P,                        /* 40-47 */
25
_D,_D,_D,_D,_D,_D,_D,_D,                        /* 48-55 */
26
_D,_D,_P,_P,_P,_P,_P,_P,                        /* 56-63 */
27
_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,      /* 64-71 */
28
_U,_U,_U,_U,_U,_U,_U,_U,                        /* 72-79 */
29
_U,_U,_U,_U,_U,_U,_U,_U,                        /* 80-87 */
30
_U,_U,_U,_P,_P,_P,_P,_P,                        /* 88-95 */
31
_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,      /* 96-103 */
32
_L,_L,_L,_L,_L,_L,_L,_L,                        /* 104-111 */
33
_L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
34
_L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
35
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 128-143 */
36
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 144-159 */
37
_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,   /* 160-175 */
38
_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,       /* 176-191 */
39
_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,       /* 192-207 */
40
_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,       /* 208-223 */
41
_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,       /* 224-239 */
42
_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};      /* 240-255 */
43
 
455 giacomo 44
__kernel_size_t strnlen(const char *s, __kernel_size_t count)
45
{
46
        const char *sc;
47
 
48
        for (sc = s; count-- && *sc != '\0'; ++sc)
49
                /* nothing */;
50
        return sc - s;
51
}
437 giacomo 52
 
432 giacomo 53
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
54
 
436 giacomo 55
struct resource ioport_resource = {
56
        .name   = "PCI IO",
57
        .start  = 0x0000,
58
        .end    = IO_SPACE_LIMIT,
59
        .flags  = IORESOURCE_IO,
60
};
61
 
62
struct resource iomem_resource = {
63
        .name   = "PCI mem",
64
        .start  = 0UL,
65
        .end    = ~0UL,
66
        .flags  = IORESOURCE_MEM,
67
};
68
 
437 giacomo 69
/* Return the conflict entry if you can't request it */
70
static struct resource * __request_resource(struct resource *root, struct resource *new)
71
{
72
        unsigned long start = new->start;
73
        unsigned long end = new->end;
74
        struct resource *tmp, **p;
436 giacomo 75
 
437 giacomo 76
        if (end < start)
77
                return root;
78
        if (start < root->start)
79
                return root;
80
        if (end > root->end)
81
                return root;
82
        p = &root->child;
83
        for (;;) {
84
                tmp = *p;
85
                if (!tmp || tmp->start > end) {
86
                        new->sibling = tmp;
87
                        *p = new;
88
                        new->parent = root;
89
                        return NULL;
90
                }
91
                p = &tmp->sibling;
92
                if (tmp->end < start)
93
                        continue;
94
                return tmp;
95
        }
436 giacomo 96
}
97
 
437 giacomo 98
static int __release_resource(struct resource *old)
99
{
100
        struct resource *tmp, **p;
101
 
102
        p = &old->parent->child;
103
        for (;;) {
104
                tmp = *p;
105
                if (!tmp)
106
                        break;
107
                if (tmp == old) {
108
                        *p = tmp->sibling;
109
                        old->parent = NULL;
110
                        return 0;
111
                }
112
                p = &tmp->sibling;
113
        }
114
        return -EINVAL;
115
}
116
 
117
int release_resource(struct resource *old)
118
{
119
        int retval;
120
 
121
        retval = __release_resource(old);
122
 
123
        return retval;
124
}
125
 
126
int request_resource(struct resource *root, struct resource *new)
127
{
128
        struct resource *conflict;
129
 
130
        conflict = __request_resource(root, new);
131
 
132
        return conflict ? -EBUSY : 0;
133
}
134
 
135
 
136
 
137
struct resource * __request_region(struct resource *parent, unsigned long start, unsigned long n, const char *name)
138
{
475 giacomo 139
        return (void *)(0xFFFFFFFF);
437 giacomo 140
}
141
 
142
void __release_region(struct resource *parent, unsigned long start, unsigned long n)
143
{
144
 
145
}
146
 
147
static int find_resource(struct resource *root, struct resource *new,
148
                         unsigned long size,
149
                         unsigned long min, unsigned long max,
150
                         unsigned long align,
151
                         void (*alignf)(void *, struct resource *,
152
                                        unsigned long, unsigned long),
153
                         void *alignf_data)
154
{
155
        struct resource *this = root->child;
156
 
157
        new->start = root->start;
158
        /*
159
         * Skip past an allocated resource that starts at 0, since the assignment
160
         * of this->start - 1 to new->end below would cause an underflow.
161
         */
162
        if (this && this->start == 0) {
163
                new->start = this->end + 1;
164
                this = this->sibling;
165
        }
166
        for(;;) {
167
                if (this)
168
                        new->end = this->start - 1;
169
                else
170
                        new->end = root->end;
171
                if (new->start < min)
172
                        new->start = min;
173
                if (new->end > max)
174
                        new->end = max;
175
                new->start = (new->start + align - 1) & ~(align - 1);
176
                if (alignf)
177
                        alignf(alignf_data, new, size, align);
178
                if (new->start < new->end && new->end - new->start + 1 >= size) {
179
                        new->end = new->start + size - 1;
180
                        return 0;
181
                }
182
                if (!this)
183
                        break;
184
                new->start = this->end + 1;
185
                this = this->sibling;
186
        }
187
        return -EBUSY;
188
}
189
 
190
int allocate_resource(struct resource *root, struct resource *new,
191
                      unsigned long size,
192
                      unsigned long min, unsigned long max,
193
                      unsigned long align,
194
                      void (*alignf)(void *, struct resource *,
195
                                     unsigned long, unsigned long),
196
                      void *alignf_data)
197
{
198
        int err;
199
 
200
 
201
        err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
202
        if (err >= 0 && __request_resource(root, new))
203
                err = -EBUSY;
204
 
205
        return err;
206
}
207
 
208
int remap_page_range(struct vm_area_struct *vma, unsigned long from, unsigned long phys_addr, unsigned long size, pgprot_t prot)
209
{ return 0; }
210
 
436 giacomo 211
void dump_stack(void) { }
212
 
213
void panic(const char * fmt, ...) {
214
 
215
  cprintf((char *)(fmt));
216
 
217
}
218
 
219
extern void * malloc(size_t size);
220
 
221
void *__kmalloc(size_t size, int flags) {
222
 
223
  return malloc(size);
224
 
225
}
226
 
227
extern void free(void *);
228
 
229
void kfree(const void *ptr) {
230
 
231
  free((void *)(ptr));
232
 
233
}
234
 
235
unsigned long pci_mem_start = 0x10000000;
236
 
432 giacomo 237
signed long schedule_timeout(signed long timeout) {
238
 
239
  SYS_FLAGS f;
240
  struct timespec t;
241
 
242
  f = ll_fsave();
243
  sti();
244
 
245
  jiffies_to_timespec(timeout, &t);
246
 
247
  nanosleep(&t,NULL);
248
 
249
  ll_frestore(f);
250
 
251
  return 0;
252
 
253
}
436 giacomo 254
 
255
void __const_udelay(unsigned long usecs) {
256
 
257
  SYS_FLAGS f;
258
  struct timespec t;
259
 
260
  f = ll_fsave();
261
  sti();
262
 
263
  t.tv_sec = 0;
264
  t.tv_nsec = usecs * 1000;
265
 
266
  nanosleep(&t,NULL);
267
 
268
  ll_frestore(f);
269
 
270
}
271
 
464 giacomo 272
void __udelay(unsigned long usecs) {
273
 
274
  SYS_FLAGS f;
275
  struct timespec t;
276
 
277
  f = ll_fsave();
278
  sti();
279
 
280
  t.tv_sec = 0;
281
  t.tv_nsec = usecs * 1000;
282
 
283
  nanosleep(&t,NULL);
284
 
285
  ll_frestore(f);
286
 
287
}
288
 
462 giacomo 289
void complete(struct completion *c) {
290
}
291
 
292
void wait_for_completion(struct completion *c) {
293
}
294
 
295
struct device legacy_bus = {
296
        .bus_id         = "legacy",
297
};
298
 
299
int register_chrdev(unsigned int a, const char *b, struct file_operations *c) {
300
        return 0;
301
}
302
 
303
int unregister_chrdev(unsigned int a, const char *b) {
304
        return 0;
305
}
468 giacomo 306
 
307
void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags) {
308
 
309
  return (void *)offset;
310
 
311
}
312
 
313
void iounmap(void *addr) {
314
 
315
}
316
 
317
void *vmalloc(unsigned long size) {
318
 
319
  return malloc(size);
320
 
321
}
322
 
323
void vfree(void *addr) {
324
 
325
  return free(addr);
326
 
327
}
328
 
329
/* TODO */
330
char * strsep(char **a,const char *b) {
331
 
332
  return NULL;
333
 
334
}
335
 
336
struct screen_info screen_info;
337
 
469 giacomo 338
int linuxcomp_setfd(struct inode *i, int i_rdev) {
339
 
340
  i->i_rdev = i_rdev;
341
 
342
  return 0;
343
 
344
}
345
 
468 giacomo 346
int linuxcomp_init(void) {
347
 
348
  return 0;
349
 
350
}