3 Copyright (C) 2007-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <libkernel/kernel.h>
20 #include <libkernel/syscall.h>
21 #include <libkernel/arch/syscall.h>
23 #include <libkernel/type_noprefix.h>
25 /*! External functions
26 *\note Defined in libkernel/$arch/syscall.S */
27 extern void _LIBKERNEL_thread_entry();
29 void _LIBKERNEL_kernel_version(syscall_param_t
*major
,
30 syscall_param_t
*minor
)
32 _LIBKERNEL_SYSCALL0_2(_LIBKERNEL_SYSCALL_GET_KERNEL_VERSION
,
37 void *_LIBKERNEL_extend_heap(syscall_param_t size
)
40 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_HEAPALLOC
,
46 void _LIBKERNEL_get_memory_info(syscall_param_t
*total
,
47 syscall_param_t
*free
)
49 _LIBKERNEL_SYSCALL0_2(_LIBKERNEL_SYSCALL_GET_MEMORY_INFO
,
54 _LIBKERNEL_syscall_param_t
_LIBKERNEL_get_commandline_length()
56 _LIBKERNEL_syscall_param_t length
;
57 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_GET_COMMANDLINE
,
63 void _LIBKERNEL_get_commandline(char *cmdline
)
65 _LIBKERNEL_SYSCALL1_0(_LIBKERNEL_SYSCALL_GET_COMMANDLINE
,
69 void _LIBKERNEL_get_time(syscall_param_t
*hour
,
70 syscall_param_t
*minute
,
71 syscall_param_t
*second
)
73 _LIBKERNEL_SYSCALL0_3(_LIBKERNEL_SYSCALL_GET_TIME
,
79 void _LIBKERNEL_get_date(syscall_param_t
*dayofweek
,
80 syscall_param_t
*dayofmonth
,
81 syscall_param_t
*month
,
82 syscall_param_t
*year
,
83 syscall_param_t
*summertime
)
85 _LIBKERNEL_SYSCALL0_5(_LIBKERNEL_SYSCALL_GET_DATE
,
97 port_id_t
_LIBKERNEL_create_port()
100 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_CREATE_PORT
,
105 void _LIBKERNEL_destroy_port(port_id_t id
)
107 _LIBKERNEL_SYSCALL1_0(_LIBKERNEL_SYSCALL_DESTROY_PORT
,
111 port_id_t
_LIBKERNEL_create_specific_port(port_id_t id
)
113 syscall_param_t result
;
114 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_CREATE_SPECIFIC_PORT
,
122 syscall_param_t
_LIBKERNEL_peek_message(port_id_t id
,
125 syscall_param_t result
;
126 _LIBKERNEL_SYSCALL1_6(_LIBKERNEL_SYSCALL_PEEK_MESSAGE
,
137 syscall_param_t
_LIBKERNEL_get_message(port_id_t id
,
140 syscall_param_t result
;
141 _LIBKERNEL_SYSCALL1_6(_LIBKERNEL_SYSCALL_GET_MESSAGE
,
149 return (result
== id
);
152 port_id_t
_LIBKERNEL_wait_message(message_t
*msg
)
154 _LIBKERNEL_port_id_t result
;
156 result
= _LIBKERNEL_syscall_wait(_LIBKERNEL_SYSCALL_WAIT_MESSAGE
, msg
);
159 _LIBKERNEL_SYSCALL0_6(_LIBKERNEL_SYSCALL_WAIT_MESSAGE
,
170 syscall_param_t
_LIBKERNEL_transfer_port(port_id_t port
,
173 syscall_param_t result
;
174 _LIBKERNEL_SYSCALL2_1(_LIBKERNEL_SYSCALL_TRANSFER_PORT
,
181 syscall_param_t
_LIBKERNEL_add_wait_message(port_id_t id
,
182 const message_t
*msg
)
184 syscall_param_t result
;
186 result
= _LIBKERNEL_syscall_add_wait(_LIBKERNEL_SYSCALL_ADD_WAIT_MESSAGE
,
191 _LIBKERNEL_SYSCALL6_1(_LIBKERNEL_SYSCALL_ADD_WAIT_MESSAGE
,
203 syscall_param_t
_LIBKERNEL_send_message(port_id_t id
,
204 const message_t
*msg
)
206 syscall_param_t result
;
208 result
= _LIBKERNEL_syscall_send(_LIBKERNEL_SYSCALL_SEND_MESSAGE
,
217 _LIBKERNEL_SYSCALL6_1(_LIBKERNEL_SYSCALL_SEND_MESSAGE
,
229 void _LIBKERNEL_get_port_info(port_id_t id
,
233 syscall_param_t result
;
234 _LIBKERNEL_SYSCALL1_3(_LIBKERNEL_SYSCALL_PORT_INFO
,
241 syscall_param_t
_LIBKERNEL_set_standard_port(process_id_t pid
,
246 syscall_param_t result
;
247 _LIBKERNEL_SYSCALL5_1(_LIBKERNEL_SYSCALL_STANDARD_PORT
,
257 void _LIBKERNEL_get_standard_port(process_id_t pid
,
262 _LIBKERNEL_SYSCALL3_2(_LIBKERNEL_SYSCALL_STANDARD_PORT
,
270 syscall_param_t
_LIBKERNEL_register_event(port_id_t id
,
271 syscall_param_t type
,
272 syscall_param_t param1
,
273 syscall_param_t param2
)
275 syscall_param_t result
;
276 _LIBKERNEL_SYSCALL4_1(_LIBKERNEL_SYSCALL_REGISTER_EVENT
,
285 void _LIBKERNEL_acknoledge_event(port_id_t id
,
286 syscall_param_t type
,
287 syscall_param_t param
)
289 _LIBKERNEL_SYSCALL3_0(_LIBKERNEL_SYSCALL_ACKNOLEDGE_EVENT
,
295 syscall_param_t
_LIBKERNEL_unregister_event(port_id_t id
,
296 syscall_param_t type
)
298 syscall_param_t result
;
299 _LIBKERNEL_SYSCALL2_1(_LIBKERNEL_SYSCALL_UNREGISTER_EVENT
,
306 syscall_param_t
_LIBKERNEL_get_tick_count()
308 syscall_param_t count
;
309 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_GET_TICK_COUNT
,
314 shared_memory_t
_LIBKERNEL_create_shared_memory(syscall_param_t size
)
318 _LIBKERNEL_SYSCALL1_2(_LIBKERNEL_SYSCALL_CREATE_SHARED_MEMORY
,
325 void _LIBKERNEL_destroy_shared_memory(shared_memory_t
*shm
)
329 _LIBKERNEL_SYSCALL1_0(_LIBKERNEL_SYSCALL_DESTROY_SHARED_MEMORY
,
337 thread_id_t
_LIBKERNEL_create_thread(void (*thread_entry
)(_LIBKERNEL_syscall_param_t
),
338 syscall_param_t parameter
,
339 syscall_param_t flags
)
342 _LIBKERNEL_SYSCALL4_1(_LIBKERNEL_SYSCALL_CREATE_THREAD
,
343 _LIBKERNEL_thread_entry
,
351 syscall_param_t
_LIBKERNEL_suspend_thread(thread_id_t id
)
353 syscall_param_t result
;
354 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_SUSPEND_THREAD
,
360 syscall_param_t
_LIBKERNEL_resume_thread(thread_id_t id
)
362 syscall_param_t result
;
363 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_RESUME_THREAD
,
369 syscall_param_t
_LIBKERNEL_destroy_thread(thread_id_t id
)
371 syscall_param_t result
;
372 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_DESTROY_THREAD
,
378 syscall_param_t
_LIBKERNEL_destroy_process(process_id_t id
)
380 syscall_param_t result
;
381 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_DESTROY_PROCESS
,
387 process_id_t
_LIBKERNEL_get_process_id()
390 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_GET_PROCESSID
,
395 thread_id_t
_LIBKERNEL_get_thread_id()
398 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_GET_THREADID
,
403 syscall_param_t
_LIBKERNEL_get_process_count()
405 syscall_param_t count
;
406 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_GET_PROCESS_COUNT
,
411 process_id_t
_LIBKERNEL_enum_processes(syscall_param_t i
)
414 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_GET_PROCESS_LIST
,
420 syscall_param_t
_LIBKERNEL_get_process_name_length(process_id_t id
)
422 syscall_param_t length
;
423 _LIBKERNEL_SYSCALL3_1(_LIBKERNEL_SYSCALL_GET_PROCESS_INFO
,
431 void _LIBKERNEL_get_process_name(process_id_t id
,
434 _LIBKERNEL_SYSCALL3_0(_LIBKERNEL_SYSCALL_GET_PROCESS_INFO
,
440 syscall_param_t
_LIBKERNEL_get_process_memory_usage(process_id_t id
)
442 syscall_param_t mem_usage
;
443 _LIBKERNEL_SYSCALL2_1(_LIBKERNEL_SYSCALL_GET_PROCESS_INFO
,
450 syscall_param_t
_LIBKERNEL_range_allocator_count(syscall_param_t
*capacity
)
452 syscall_param_t count
;
453 _LIBKERNEL_SYSCALL0_2(_LIBKERNEL_SYSCALL_RANGE_ALLOCATOR_COUNT
,
459 void _LIBKERNEL_enum_range_allocator(syscall_param_t index
,
460 syscall_param_t
*address
,
461 syscall_param_t
*size
)
463 _LIBKERNEL_SYSCALL1_2(_LIBKERNEL_SYSCALL_ENUM_RANGE_ALLOCATOR
,
473 void _LIBKERNEL_vbe_get_version(syscall_param_t
*major
,
474 syscall_param_t
*minor
)
476 _LIBKERNEL_SYSCALL0_2(_LIBKERNEL_SYSCALL_VBE_GET_VERSION
,
481 syscall_param_t
_LIBKERNEL_vbe_get_mode_count()
483 syscall_param_t count
;
484 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_VBE_GET_MODE_COUNT
,
489 void _LIBKERNEL_vbe_enumerate_mode(syscall_param_t index
,
490 syscall_param_t
*width
,
491 syscall_param_t
*height
,
492 syscall_param_t
*bpp
)
494 _LIBKERNEL_SYSCALL1_3(_LIBKERNEL_SYSCALL_VBE_GET_MODE
,
501 void *_LIBKERNEL_vbe_set_mode(syscall_param_t index
)
504 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_VBE_SET_MODE
,
510 syscall_param_t
_LIBKERNEL_allocate_io_port_range(syscall_param_t port
,
511 syscall_param_t count
)
513 // NOTE TODO FIXME HACK
514 syscall_param_t result
;
515 _LIBKERNEL_SYSCALL0_1( _LIBKERNEL_SYSCALL_REQUEST_IO
,
520 void _LIBKERNEL_free_io_port_range(syscall_param_t port
,
521 syscall_param_t count
)
523 // NOTE TODO FIXME HACK
530 syscall_param_t
_LIBKERNEL_setup_dma_channel(syscall_param_t channel
,
532 syscall_param_t count
,
533 syscall_param_t mode
)
535 syscall_param_t result
;
536 _LIBKERNEL_SYSCALL4_1(_LIBKERNEL_SYSCALL_DMA
,
549 process_id_t
_LIBKERNEL_execute(const void *data
,
550 syscall_param_t size
,
552 syscall_param_t flags
,
556 _LIBKERNEL_SYSCALL5_1(_LIBKERNEL_SYSCALL_EXECUTE
,
561 (syscall_param_t
)libName
,
567 // Physical memory-management
570 void *_LIBKERNEL_get_physical_address(const void *address
)
573 _LIBKERNEL_SYSCALL1_1(_LIBKERNEL_SYSCALL_GET_PHYSICAL_ADDRESS
,
579 void *_LIBKERNEL_allocate_memory_region(syscall_param_t size
,
580 syscall_param_t type
,
584 _LIBKERNEL_SYSCALL3_1(_LIBKERNEL_SYSCALL_ALLOCATE_REGION
,
592 void _LIBKERNEL_free_memory_region(void *address
)
594 _LIBKERNEL_SYSCALL1_0(_LIBKERNEL_SYSCALL_FREE_REGION
,
599 // System configuration
602 void _LIBKERNEL_get_system_configuration(system_config_t
*config
)
604 syscall_param_t ret
[3];
605 _LIBKERNEL_SYSCALL0_3(_LIBKERNEL_SYSCALL_GET_SYSTEM_CONFIGURATION
,
609 config
->serial
[0] = ret
[0] & 0xFFFF;
610 config
->serial
[1] = (ret
[0] >> 16) & 0xFFFF;
611 config
->serial
[2] = ret
[1] & 0xFFFF;
612 config
->serial
[3] = (ret
[1] >> 16) & 0xFFFF;
613 config
->kernel_serial
= ret
[2] & 0xFFFF;
620 syscall_param_t
_LIBKERNEL_get_library_count()
622 syscall_param_t count
;
623 _LIBKERNEL_SYSCALL0_1(_LIBKERNEL_SYSCALL_GET_LIBRARY_COUNT
,
628 syscall_param_t
_LIBKERNEL_get_library_name_length(syscall_param_t index
)
630 syscall_param_t address
, size
, length
;
631 _LIBKERNEL_SYSCALL2_3(_LIBKERNEL_SYSCALL_GET_LIBRARY_INFO
,
640 void _LIBKERNEL_get_library_info(syscall_param_t index
,
642 syscall_param_t length
,
643 syscall_param_t
*address
,
644 syscall_param_t
*size
)
646 _LIBKERNEL_SYSCALL2_3(_LIBKERNEL_SYSCALL_GET_LIBRARY_INFO
,
658 void _LIBKERNEL_set_signal_handler(void (*func
)(int))
660 _LIBKERNEL_SYSCALL1_0(_LIBKERNEL_SYSCALL_SIGNAL_HANDLER
,
664 void _LIBKERNEL_signal_handler_end()
666 _LIBKERNEL_SYSCALL0_0(_LIBKERNEL_SYSCALL_SIGNAL_END
);
669 int _LIBKERNEL_signal(process_id_t pid
,
672 syscall_param_t result
;
673 _LIBKERNEL_SYSCALL2_1(_LIBKERNEL_SYSCALL_SIGNAL
,
682 syscall_param_t
_LIBKERNEL_get_log_entry(syscall_param_t index
,
683 syscall_param_t size
,
685 enum _LIBKERNEL_log_level
* level
)
687 syscall_param_t real_size
;
688 _LIBKERNEL_SYSCALL3_2(_LIBKERNEL_SYSCALL_GET_LOG_ENTRY
,