3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 void module_display ()
32 printf ("Module\t\tSize\n");
34 for (kmod
= module_list
.next
; kmod
!= &module_list
; kmod
= kmod
->next
)
36 printf ("%s\t\t%u\n", kmod
->name
, kmod
->mem_usage
/1024);
38 printf ("?\t\t%u\n", kmod
->mem_usage
/1024);
41 module_t
*module_find (task_t
*task
)
44 for (kmod
= module_list
.next
; kmod
!= &module_list
; kmod
= kmod
->next
) {
45 if (kmod
->task
== task
)
52 module_t
*module_load (char *modname
)
54 int f
= open (modname
, O_RDONLY
);
59 fd_t
*fd
= fd_get (f
);
64 module_t
*kmod
= (module_t
*) kmalloc (sizeof (module_t
));
69 kmod
->mem_usage
= fd
->e
+ sizeof (module_t
) + 1;
71 kmod
->image
= (char *) kmalloc (sizeof (char) * fd
->e
+ 1);
76 read (f
, kmod
->image
, fd
->e
);
80 unsigned data
, data_off
, bss
;
81 int err
= exec_elf (kmod
->image
, &entry
, &data
, &data_off
, &bss
);
84 printf ("ERROR -> invalid module %s\n", modname
);
91 task_t
*task
= (task_t
*) task_create (modname
, entry
, KMOD_MODULE_PRIORITY
);
94 printf ("ERROR -> invalid module task\n");
103 unsigned l
= strlen (modname
);
104 kmod
->name
= (char *) kmalloc (sizeof (char) * l
+ 1);
114 memcpy (kmod
->name
, modname
, l
);
115 kmod
->name
[l
] = '\0';
118 kmod
->next
= &module_list
;
119 kmod
->prev
= module_list
.prev
;
120 kmod
->prev
->next
= kmod
;
121 kmod
->next
->prev
= kmod
;
126 unsigned int init_module (void)
128 module_list
.next
= &module_list
;
129 module_list
.prev
= &module_list
;