Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1238 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
 * IPC functions & data
24
 */
25
 
26
kolibri_IPC_area_t *kolibri_IPC_area;
27
 
28
int kolibri_IPC_set_area(void *area, int size){
29
	int result;
30
 
31
	asm("int $0x40":"=a"(result):"a"(60),"b"(1),"c"(area),"d"(size));
32
 
33
	return result;
34
}
35
 
36
int kolibri_IPC_send(int tid, void *msg, int length){
37
	int result;
38
 
39
	asm("movl %5, %%esi\nint $0x40":"=a"(result):"a"(60),"b"(2),"c"(tid),"d"(msg),"g"(length));
40
 
41
	return result;
42
}
43
 
44
void kolibri_IPC_unlock(){
45
	kolibri_IPC_area->lock = 0;
46
}
47
 
48
void kolibri_IPC_lock(){
49
	kolibri_IPC_area->lock = 1;
50
}
51
 
52
int kolibri_IPC_init(void *area, int size){
53
	kolibri_IPC_area = (kolibri_IPC_area_t *)area;
54
	kolibri_IPC_area->size = 8;
55
 
56
	return kolibri_IPC_set_area(area, size);
57
}
58
 
59
kolibri_IPC_message_t *kolibri_IPC_get_next_message(){
60
	kolibri_IPC_lock();
61
	return (kolibri_IPC_message_t *)((char *)kolibri_IPC_area+sizeof(kolibri_IPC_area_t));
62
}
63
 
64
void kolibri_IPC_clear_buff(){
65
	kolibri_IPC_area->size = 8;
66
	kolibri_IPC_unlock();
67
}
68
 
69
/*
70
 * Other process/thread functions
71
 */
72
 
73
int kolibri_get_my_tid(){
74
	kolibri_process_info_t *info = malloc(0x400);
75
	int tid;
76
 
77
	kolibri_get_process_info(info, -1);
78
	tid = info->tid;
79
	free(info);
80
 
81
	return tid;
82
}
83
 
84
int kolibri_get_process_info(kolibri_process_info_t *info, int slot){
85
	int max_slot;
86
 
87
	asm("int $0x40":"=a"(max_slot):"a"(9),"b"(info),"c"(slot));
88
 
89
	return max_slot;
90
}
91
 
92
/*
93
 * Memory functions
94
 */
95
 
96
kolibri_memarea_t kolibri_new_named_memory(char *name, int size, int flags){
97
	kolibri_memarea_t area;
98
 
99
	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));
100
 
101
	return area;
102
}
103
 
104
int kolibri_heap_init(){
105
	int size;
106
 
107
	asm("int $0x40":"=a"(size):"a"(68),"b"(11));
108
 
109
	return size;
110
}
111
 
112
void *kolibri_malloc(int nbytes){
113
	void *addr;
114
 
115
	asm("int $0x40":"=a"(addr):"a"(68),"b"(12),"c"(nbytes));
116
 
117
	return addr;
118
}
119
 
120
/*
121
 * Events functions
122
 */
123
void kolibri_set_event_mask(int mask){
124
	asm("int $0x40"::"a"(40),"b"(mask));
125
}
126
 
127
int kolibri_event_wait(){
128
	int event;
129
	asm("int $0x40":"=a"(event):"a"(10));
130
	return event;
131
}