Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1286 vkos 1
/***************************************************************************************************
2
 *  Copyright (C) Vasiliy Kosenko (vkos), 2009                                                     *
3
 *  This program is free software: you can redistribute it and/or modify it under the terms of the *
4
 *  GNU General Public License as published by the Free Software Foundation, either version 3      *
5
 *  of the License, or (at your option) any later version.                                         *
6
 *                                                                                                 *
7
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;      *
8
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See  *
9
 *  the GNU General Public License for more details.                                               *
10
 *                                                                                                 *
11
 *  You should have received a copy of the GNU General Public License along with this program.     *
12
 *  If not, see .                                                    *
13
 ***************************************************************************************************/
14
 
15
/***************************************************************************************************
16
 *  kolibri.c - KolibriOS system functions                                                         *
17
 ***************************************************************************************************/
18
 
19
#include "kolibri.h"
20
#include "malloc.h"
21
 
22
/*
23
 * Other process/thread functions
24
 */
25
 
26
int kolibri_get_my_tid(){
27
	kolibri_process_info_t *info = malloc(0x400);
28
	int tid;
29
 
30
	kolibri_get_process_info(info, -1);
31
	tid = info->tid;
32
	free(info);
33
 
34
	return tid;
35
}
36
 
37
int kolibri_get_process_info(kolibri_process_info_t *info, int slot){
38
	int max_slot;
39
 
40
	asm("int $0x40":"=a"(max_slot):"a"(9),"b"(info),"c"(slot));
41
 
42
	return max_slot;
43
}
44
 
45
/*
46
 * Memory functions
47
 */
48
 
49
kolibri_memarea_t kolibri_new_named_memory(char *name, int size, int flags){
50
	kolibri_memarea_t area;
51
 
52
	asm("pushl %%esi\nmovl %6, %%esi\nint $0x40\npopl %%esi":"=a"(area.addr),"=d"(area.error):"a"(68),"b"(22),"c"(name),"d"(size),"g"(flags));
53
 
54
	return area;
55
}
56
 
57
int kolibri_heap_init(){
58
	int size;
59
 
60
	asm("int $0x40":"=a"(size):"a"(68),"b"(11));
61
 
62
	return size;
63
}
64
 
65
void *kolibri_malloc(int nbytes){
66
	void *addr;
67
 
68
	asm("int $0x40":"=a"(addr):"a"(68),"b"(12),"c"(nbytes));
69
 
70
	return addr;
71
}
72
 
73
/*
74
 * Events functions
75
 */
76
 
77
int kolibri_event_mask;
78
 
79
int kolibri_event_set_mask(int mask){
80
	kolibri_event_mask = mask;
81
	asm("int $0x40"::"a"(40),"b"(kolibri_event_mask));
82
	return 0;
83
}
84
 
85
int kolibri_event_get_mask(int mask){
86
	return kolibri_event_mask;
87
}
88
 
89
void kolibri_event_add_mask(int amask){
90
	kolibri_event_set_mask(kolibri_event_mask | amask);
91
}
92
 
93
void kolibri_event_sub_mask(int amask){
94
	kolibri_event_set_mask(kolibri_event_mask & ~amask);
95
}
96
 
97
int kolibri_event_wait(int time){
98
	int event;
99
	if (!time) {
100
		asm("int $0x40":"=a"(event):"a"(11));
101
	} else if (time == -1) {
102
		asm("int $0x40":"=a"(event):"a"(10));
103
	} else {
104
		asm("int $0x40":"=a"(event):"a"(23),"b"(time));
105
	}
106
	return event;
107
}