3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 void module_display ()
30 printf ("Module\t\tSize\n");
32 for (kmod
= module_list
.next
; kmod
!= &module_list
; kmod
= kmod
->next
)
34 printf ("%s\t\t%u\n", kmod
->name
, kmod
->mem_usage
/1024);
36 printf ("?\t\t%u\n", kmod
->mem_usage
/1024);
39 module_t
*module_find (task_t
*task
)
42 for (kmod
= module_list
.next
; kmod
!= &module_list
; kmod
= kmod
->next
) {
43 if (kmod
->task
== task
)
50 module_t
*module_load (char *modname
)
52 FILE *f
= fopen (modname
, "r");
57 module_t
*kmod
= (module_t
*) kmalloc (sizeof (module_t
));
62 kmod
->mem_usage
= f
->e
+ sizeof (module_t
) +1;
64 kmod
->image
= (char *) kmalloc (sizeof (char) * f
->e
+ 1);
69 fgets (kmod
->image
, f
->e
, f
);
73 unsigned data
, data_off
, bss
;
74 int err
= exec_elf (kmod
->image
, &entry
, &data
, &data_off
, &bss
);
77 printf ("ERROR -> invalid module %s\n", modname
);
81 task_t
*task
= (task_t
*) task_create (modname
, entry
, KMOD_MODULE_PRIORITY
);
84 printf ("ERROR -> invalid module task\n");
90 unsigned l
= strlen (modname
);
91 kmod
->name
= (char *) kmalloc (sizeof (char) * l
+ 1);
94 memcpy (kmod
->name
, modname
, l
);
99 kmod
->next
= &module_list
;
100 kmod
->prev
= module_list
.prev
;
101 kmod
->prev
->next
= kmod
;
102 kmod
->next
->prev
= kmod
;
104 //fclose (f); // FIXME: uninitialized pointer of FILE *f in free () ??
109 unsigned int init_module (void)
111 module_list
.next
= &module_list
;
112 module_list
.prev
= &module_list
;