MushOS  0.1
A UNIX-like OS prototype, written from scratch
Loading...
Searching...
No Matches
modules.c
1#include "modules.h"
2
3#include "../../lib/base/stdio.h"
4#include "../../lib/base/heap.h"
5
6#include "../kernel/interruption_tables.h"
7
8
9u_dword modules_placement = 0x30000;
10
11
12extern boolean read_disk(void* address, boolean slave_drive, u_word length, u_word offset, void* buffer);
13
14void init_module_loading_driver() {
15 silence_interrupt(46);
16}
17
18void* place_module(u_dword size) {
19 u_dword tmp = modules_placement;
20 modules_placement += size;
21 return (void*) tmp;
22}
23
24void* load_module(u_word offset, u_word length) {
25 if (length == 0) ; // TODO: throw error: module shouldn't be empty
26 if (length % 2 != 0) ; // TODO: throw error: module should be 2 bytes aligned
27 if (offset % 2 != 0) ; // TODO: throw error: module should be 2 bytes aligned
28 void* place = ralloc(length);
29 info("Loading module at offset %d, length %d to memory address: %h\n", offset, length, place)
30 boolean res = read_disk((void*) (offset / 512), false, length, offset, (u_word*) place);
31 info("Reading result: %d\n", res)
32 return place;
33}
void * ralloc(u_dword size)
u_dword size(void *structure)
Definition: lib/base/heap.c:65