Subversion Repositories shark

Rev

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