summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager/V86/V86.ns.cpp
blob: f70728c1ac7ad34e1cfcf022f0b3a71ff7151b92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "V86.ns.h"
#include <TaskManager/Task.ns.h>

namespace V86 {

u16int seg = V86_ALLOC_START;

void run(v86_function_t& entry, v86_regs_t &regs) {
	v86_retval_t ret;
	ret.regs = &regs;
	new V86Thread(&entry, &ret);
	while (!ret.finished) Task::currThread()->sleep(10);
}

void biosInt(u8int int_no, v86_regs_t &regs) {
	v86_retval_t ret;
	ret.regs = &regs;
	new V86Thread(int_no, &ret);
	while (!ret.finished) Task::currThread()->sleep(10);
}

void map(Process* p) {
	if (p == 0) p = Task::currProcess();
	for (u32int i = 0x00000; i < 0xFFFFF; i += 0x1000) {
		p->getPagedir()->allocFrame(i, true, true);
	}
}

u16int allocSeg(u16int length) {
	if (length & 0xF) length = (length & 0xFFFF0) + 0x10;
	u16int segments = length / 16;
	if (seg < V86_ALLOC_START) seg = V86_ALLOC_START;
	if (seg + segments > V86_ALLOC_END) seg = V86_ALLOC_START;
	u16int ret = seg;
	seg += segments;

	return ret;
}

void* alloc(u16int length) {
	return FP_TO_LINEAR(allocSeg(length), 0);
}

}