Added libroot's os/ tree.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1385 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-10-05 17:07:03 +00:00
parent d98c8e6e59
commit 712ec3d786
13 changed files with 993 additions and 0 deletions

View File

@ -0,0 +1,16 @@
SubDir OBOS_TOP src kernel libroot os ;
KernelObjects
<$(SOURCE_GRIST)>area.c
<$(SOURCE_GRIST)>debug.c
<$(SOURCE_GRIST)>port.c
<$(SOURCE_GRIST)>sem.c
<$(SOURCE_GRIST)>systeminfo.c
<$(SOURCE_GRIST)>team.c
<$(SOURCE_GRIST)>thread.c
<$(SOURCE_GRIST)>time.c
:
-fPIC -DPIC
;
SubInclude OBOS_TOP src kernel libroot os arch ;

View File

@ -0,0 +1 @@
SubInclude OBOS_TOP src kernel libroot os arch $(OBOS_ARCH) ;

View File

@ -0,0 +1,3 @@
SubDir OBOS_TOP src kernel libroot os arch x86 ;
KernelObjects atomic.S ;

View File

@ -0,0 +1,109 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#define FUNCTION(x) .global x; .type x,@function; x
.text
/* int atomic_add(int *val, int incr) */
FUNCTION(atomic_add):
movl 4(%esp),%edx
movl 8(%esp),%eax
lock
xaddl %eax,(%edx)
ret
/* int atomic_and(int *val, int incr) */
FUNCTION(atomic_and):
movl 4(%esp),%edx
_atomic_and1:
movl 8(%esp),%ecx
movl (%edx),%eax
andl %eax,%ecx
lock
cmpxchgl %ecx,(%edx)
jnz _atomic_and1
ret
/* int atomic_or(int *val, int incr) */
FUNCTION(atomic_or):
movl 4(%esp),%edx
_atomic_or1:
movl 8(%esp),%ecx
movl (%edx),%eax
orl %eax,%ecx
lock
cmpxchgl %ecx,(%edx)
jnz _atomic_or1
ret
/* int atomic_set(int *val, int set_to) */
FUNCTION(atomic_set):
movl 4(%esp),%edx
movl 8(%esp),%eax
xchg %eax,(%edx)
ret
/* int test_and_set(int *val, int set_to, int test_val) */
FUNCTION(test_and_set):
movl 4(%esp),%edx
movl 8(%esp),%ecx
movl 12(%esp),%eax
lock
cmpxchgl %ecx,(%edx)
ret
/* saves the conversion factor needed for system_time */
cv_factor:
.word 0
FUNCTION(setup_system_time):
movl 4(%esp),%eax
movl %eax,cv_factor
ret
/* long long system_time(); */
FUNCTION(system_time):
/* load 64-bit factor into %eax (low), %edx (high) */
rdtsc /* time in %edx,%eax */
pushl %ebx
pushl %ecx
movl cv_factor, %ebx
movl %edx, %ecx /* save high half */
mull %ebx /* truncate %eax, but keep %edx */
movl %ecx, %eax
movl %edx, %ecx /* save high half of low */
mull %ebx /*, %eax*/
/* now compute [%edx, %eax] + [%ecx], propagating carry */
subl %ebx, %ebx /* need zero to propagate carry */
addl %ecx, %eax
adc %ebx, %edx
popl %ecx
popl %ebx
ret
/* void i386_switch_stack_and_call(addr stack, void (*func)(void *), void *arg); */
FUNCTION(i386_switch_stack_and_call):
movl 4(%esp),%eax // new stack
movl 8(%esp),%ecx // func
movl 12(%esp),%edx // args
movl %eax,%esp // switch the stack
pushl %edx // push the argument
call *%ecx // call the target function
_loop:
jmp _loop

View File

@ -0,0 +1,257 @@
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
** syscall interface works as such:
** eax has syscall #
** ecx has number of args (0-16)
** edx has pointer to buffer containing args from first to last
** each is verified to make sure someone doesnt try to clobber it
*/
#define SYSCALL0(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall0
#define SYSCALL1(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall1
#define SYSCALL2(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall2
#define SYSCALL3(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall3
#define SYSCALL4(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall4
#define SYSCALL5(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall5
#define SYSCALL6(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall6
#define SYSCALL7(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall7
#define SYSCALL8(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall8
#define SYSCALL9(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall9
#define SYSCALL10(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall10
#define SYSCALL11(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall11
#define SYSCALL12(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall12
#define SYSCALL13(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall13
#define SYSCALL14(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall14
#define SYSCALL15(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall15
#define SYSCALL16(name, n) \
.globl name; \
.type name,@function; \
.align 8; \
name: \
movl $n,%eax; \
jmp syscall16
/* we will optimize by just passing a ptr to the place where the caller
** would have dumped the args */
syscall0:
movl $0, %ecx
lea 4(%esp), %edx
int $99
ret
syscall1:
movl $1, %ecx
lea 4(%esp), %edx
int $99
ret
syscall2:
movl $2, %ecx
lea 4(%esp), %edx
int $99
ret
syscall3:
movl $3, %ecx
lea 4(%esp), %edx
int $99
ret
syscall4:
movl $4, %ecx
lea 4(%esp), %edx
int $99
ret
syscall5:
movl $5, %ecx
lea 4(%esp), %edx
int $99
ret
syscall6:
movl $6, %ecx
lea 4(%esp), %edx
int $99
ret
syscall7:
movl $7, %ecx
lea 4(%esp), %edx
int $99
ret
syscall8:
movl $8, %ecx
lea 4(%esp), %edx
int $99
ret
syscall9:
movl $9, %ecx
lea 4(%esp), %edx
int $99
ret
syscall10:
movl $10, %ecx
lea 4(%esp), %edx
int $99
ret
syscall11:
movl $11, %ecx
lea 4(%esp), %edx
int $99
ret
syscall12:
movl $12, %ecx
lea 4(%esp), %edx
int $99
ret
syscall13:
movl $13, %ecx
lea 4(%esp), %edx
int $99
ret
syscall14:
movl $14, %ecx
lea 4(%esp), %edx
int $99
ret
syscall15:
movl $15, %ecx
lea 4(%esp), %edx
int $99
ret
syscall16:
movl $16, %ecx
lea 4(%esp), %edx
int $99
ret

View File

@ -0,0 +1,87 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
area_id
create_area(const char *name, void **start_addr, uint32 addr_spec, size_t size,
uint32 lock, uint32 protection)
{
// ToDo: create_area: names don't match, but basic function does.
// Little work needed on addr_spec.
return sys_vm_create_anonymous_region(name, start_addr, addr_spec, size, lock, protection);
}
area_id
clone_area(const char *name, void **dest_addr, uint32 addr_spec,
uint32 protection, area_id source)
{
// ToDo: Not 100% sure about the REGION_PRIVATE_MAP
return sys_vm_clone_region(name, dest_addr, addr_spec, source, REGION_PRIVATE_MAP, protection);
}
area_id
find_area(const char *name)
{
return sys_find_region_by_name(name);
}
area_id
area_for(void *addr)
{
// ToDo: implement area_for()
return B_ERROR;
}
status_t
delete_area(area_id id)
{
return sys_vm_delete_region(id);
}
status_t
resize_area(area_id id, size_t newSize)
{
// ToDo: implement resize_area()
return B_ERROR;
}
status_t
set_area_protection(area_id id, uint32 protection)
{
// ToDo: implement set_area_protection()
return B_ERROR;
}
status_t
_get_area_info(area_id id, area_info *areaInfo, size_t size)
{
// size is not yet used, but may, if area_info changes
(void)size;
return sys_vm_get_region_info(id, (void *)areaInfo);
}
status_t
_get_next_area_info(team_id team, int32 *cookie, area_info *ainfo, size_t size)
{
// size is not yet used, but may, if area_info changes
(void)size;
// ToDo: implement _get_next_area_info()
return B_ERROR;
}

View File

@ -0,0 +1,24 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
void
debugger(const char *message)
{
// ToDo: implement debugger()
}
const int
disable_debugger(int state)
{
// ToDo: implement disable_debugger()
return 0;
}

View File

@ -0,0 +1,112 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
port_id
create_port(int32 capacity, const char *name)
{
return sys_port_create(capacity, name);
}
port_id
find_port(const char *name)
{
return sys_port_find(name);
}
status_t
write_port(port_id port, int32 code, const void *buffer, size_t bufferSize)
{
return sys_port_write(port, code, buffer, bufferSize);
}
status_t
read_port(port_id port, int32 *code, void *buffer, size_t bufferSize)
{
return sys_port_read(port, code, buffer, bufferSize);
}
status_t
write_port_etc(port_id port, int32 code, const void *buffer, size_t bufferSize,
uint32 flags, bigtime_t timeout)
{
return sys_port_write_etc(port, code, buffer, bufferSize, flags, timeout);
}
status_t
read_port_etc(port_id port, int32 *code, void *buffer, size_t bufferSize,
uint32 flags, bigtime_t timeout)
{
return sys_port_read_etc(port, code, buffer, bufferSize, flags, timeout);
}
ssize_t
port_buffer_size(port_id port)
{
return sys_port_buffer_size(port);
}
ssize_t
port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout)
{
return sys_port_buffer_size_etc(port, flags, timeout);
}
ssize_t
port_count(port_id port)
{
return sys_port_count(port);
}
status_t
set_port_owner(port_id port, team_id team)
{
return sys_port_set_owner(port, team);
}
status_t
close_port(port_id port)
{
return sys_port_close(port);
}
status_t
delete_port(port_id port)
{
return sys_port_delete(port);
}
status_t
_get_next_port_info(team_id team, int32 *cookie, port_info *info, size_t size)
{
// size is not yet used, but may, if port_info changes
(void)size;
return sys_port_get_next_port_info(team, cookie, info);
}
status_t
_get_port_info(port_id port, port_info *info, size_t size)
{
return sys_port_get_info(port, info);
}

View File

@ -0,0 +1,79 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
sem_id
create_sem(int32 count, const char *name)
{
return sys_create_sem(count, name);
}
status_t
delete_sem(sem_id id)
{
return sys_delete_sem(id);
}
status_t
acquire_sem(sem_id id)
{
return sys_acquire_sem(id);
}
status_t
acquire_sem_etc(sem_id id, int32 count, uint32 flags, bigtime_t timeout)
{
return sys_acquire_sem_etc(id, count, flags, timeout);
}
status_t
release_sem(sem_id id)
{
return sys_release_sem(id);
}
status_t
release_sem_etc(sem_id id, int32 count, uint32 flags)
{
return sys_release_sem_etc(id, count, flags);
}
status_t
get_sem_count(sem_id sem, int32 *count)
{
return sys_sem_get_count(sem, count);
}
status_t
set_sem_owner(sem_id sem, team_id team)
{
return sys_set_sem_owner(sem, team);
}
status_t
_get_sem_info(sem_id sem, sem_info *info, size_t size)
{
return sys_get_sem_info(sem, info, size);
}
status_t
_get_next_sem_info(team_id team, int32 *cookie, sem_info *info, size_t size)
{
return sys_get_next_sem_info(team, cookie, info, size);
}

View File

@ -0,0 +1,39 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
status_t
get_cpuid(cpuid_info *info, uint32 eax_register, uint32 cpu_num)
{
// ToDo: get_cpuid()
return B_ERROR;
}
status_t
_get_system_info(system_info *returned_info, size_t size)
{
// ToDo: _get_system_info()
return B_ERROR;
}
int32
is_computer_on(void)
{
return 1;
}
double
is_computer_on_fire(void)
{
return 0;
}

View File

@ -0,0 +1,47 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
status_t
_get_team_usage_info(team_id tmid, int32 who, team_usage_info *ti, size_t size)
{
// size is not yet used, but may if team_usage_info changes
(void)size;
// ToDo: implement _get_team_usage_info
return B_ERROR;
}
status_t
kill_team(team_id team)
{
return sys_kill_team(team);
}
status_t
_get_team_info(team_id team, team_info *info, size_t size)
{
// size is not yet used, but may if team_info changes
(void)size;
return sys_get_team_info(team, info);
}
status_t
_get_next_team_info(int32 *cookie, team_info *info, size_t size)
{
// size is not yet used, but may if team_info changes
(void)size;
return sys_get_next_team_info(cookie, info);
}

View File

@ -0,0 +1,164 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include <stdio.h>
#include "syscalls.h"
thread_id
spawn_thread(thread_func function, const char *name, int32 priority, void *data)
{
return sys_spawn_thread(function, name, priority, data);
}
status_t
kill_thread(thread_id thread)
{
return sys_kill_thread(thread);
}
status_t
resume_thread(thread_id thread)
{
return sys_resume_thread(thread);
}
status_t
suspend_thread(thread_id thread)
{
return sys_suspend_thread(thread);
}
thread_id
find_thread(const char *name)
{
// ToDo: fix find_thread()!
if (!name)
return sys_get_current_thread_id();
printf("find_thread(): Not yet implemented!!\n");
return B_ERROR;
}
#ifdef __INTEL__
// see OS.h for the reason why we need this
thread_id _kfind_thread_(const char *name);
thread_id
_kfind_thread_(const char *name)
{
// ToDo: _kfind_thread_()
printf("find_thread(): Not yet implemented!!\n");
return B_ERROR;
}
#endif
status_t
rename_thread(thread_id thread, const char *name)
{
// ToDo: rename_thread not implemented
return B_ERROR;
}
status_t
set_thread_priority(thread_id thread, int32 priority)
{
// ToDo: set_thread_priority not implemented
return B_ERROR;
}
void
exit_thread(status_t status)
{
// ToDo: exit_thread not implemented
}
status_t
wait_for_thread(thread_id thread, status_t *thread_return_value)
{
return sys_wait_on_thread(thread,thread_return_value);
}
status_t on_exit_thread(void (*callback)(void *), void *data)
{
// ToDo: on_exit_thread not implemented
return B_ERROR;
}
status_t
_get_thread_info(thread_id thread, thread_info *info, size_t size)
{
// size parameter is not yet used (but may, if the thread_info structure ever changes)
(void)size;
return sys_get_thread_info(thread, info);
}
status_t
_get_next_thread_info(team_id team, int32 *cookie, thread_info *info, size_t size)
{
// size parameter is not yet used (but may, if the thread_info structure ever changes)
(void)size;
return sys_get_next_thread_info(team, cookie, info);
}
/* ToDo: Those are currently defined in syscalls.S - we need some
* consistency here...
* send_data(), receive_data(), has_data()
status_t
send_data(thread_id thread, int32 code, const void *buffer, size_t bufferSize)
{
// ToDo: send_data()
return B_ERROR;
}
status_t
receive_data(thread_id *sender, void *buffer, size_t bufferSize)
{
// ToDo: receive_data()
return B_ERROR;
}
bool
has_data(thread_id thread)
{
// ToDo: has_data()
return false;
}
*/
status_t
snooze(bigtime_t microseconds)
{
// ToDo: snooze()
return B_ERROR;
}
status_t
snooze_until(bigtime_t time, int timeBase)
{
// ToDo: snooze_until()
return B_ERROR;
}

View File

@ -0,0 +1,55 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include "syscalls.h"
uint32
real_time_clock(void)
{
// ToDo: real_time_clock()
return 0;
}
void
set_real_time_clock(int32 secs)
{
// ToDo: set_real_time_clock()
}
bigtime_t
real_time_clock_usecs(void)
{
// ToDo: real_time_clock_usecs()
return 0;
}
status_t
set_timezone(char *timezone)
{
// ToDo: set_timezone()
return B_ERROR;
}
bigtime_t
system_time(void)
{
/* time since booting in microseconds */
return sys_system_time();
}
bigtime_t
set_alarm(bigtime_t when, uint32 flags)
{
// ToDo: set_alarm()
return B_ERROR;
}