Adding menuetlibc back to its place in /programs/develop/libraries

This version of menuetlibc was taken from revision 4743, right before I made any changes

git-svn-id: svn://kolibrios.org@4973 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
right-hearted
2014-06-12 10:43:21 +00:00
parent 989f9f99a2
commit 6496d04506
1183 changed files with 107270 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
OUTFILE = $(MENUETDEV)/lib/libipc.a
OBJS = hdr.o send.o recv.o
CFLAGS = -O2 -fomit-frame-pointer
include $(MENUETDEV)/makefiles/Makefile_for_lib

View File

@@ -0,0 +1,21 @@
#include"ipc.h"
#include<stdlib.h>
ipc_hdr_t * create_ipc(unsigned long size)
{
ipc_hdr_t * hdr=(ipc_hdr_t *)malloc(size+sizeof(ipc_hdr_t));
if(!hdr) return NULL;
hdr->lock=0;
hdr->free_ptr=8;
return hdr;
}
void register_ipc_mem(ipc_hdr_t * hdr)
{
int d0,d1,d2;
__asm__ __volatile__(
"int $0x40"
:"=a"(d0),"=b"(d1),"=c"(d2)
:"0"(60),"1"(1),"2"(hdr)
:"memory");
}

View File

@@ -0,0 +1,21 @@
#ifndef __MENUETOS_IPC_H
#define __MENUETOS_IPC_H
typedef struct {
volatile unsigned long lock;
unsigned long free_ptr;
char __mem[0];
} ipc_hdr_t;
typedef struct {
unsigned long sender_pid;
unsigned long msg_length;
char message[0];
} ipc_msg_t;
ipc_hdr_t * create_ipc(unsigned long size);
void register_ipc_mem(ipc_hdr_t * hdr);
void ipc_send_message(int dst_pid,ipc_msg_t * msg);
extern inline int ipc_messages_avail(ipc_hdr_t * hdr);
#endif

View File

@@ -0,0 +1,58 @@
#include"ipc.h"
#include<stdlib.h>
#include<string.h>
inline int ipc_messages_avail(ipc_hdr_t * hdr)
{
return hdr->free_ptr!=8;
}
static inline void lock_msg_queue(ipc_hdr_t * hdr)
{
int d0;
__asm__ __volatile__(
"2:\t"
"movb $1,%%al\n\t"
"xchgb %%al,%0\n\t"
"andb %%al,%%al\n\t"
"jnz 2b\n\t"
"incb %0"
:"=m"(hdr->lock),"=a"(d0)
:"m"(hdr->lock)
:"memory");
}
static inline void unlock_msg_queue(ipc_hdr_t * hdr)
{
__asm__ __volatile__(
"movl $0,%0"
:"=m"(hdr->lock)
:"m"(hdr->lock)
:"memory");
}
ipc_msg_t * ipc_receive_msg(ipc_hdr_t * hdr)
{
ipc_msg_t * msg, * tmp;
lock_msg_queue(hdr);
if(!ipc_messages_avail(hdr))
{
unlock_msg_queue(hdr);
return NULL;
}
tmp=(ipc_msg_t *)hdr->__mem;
msg=(ipc_msg_t *)malloc(tmp->msg_length);
if(!msg)
{
unlock_msg_queue(hdr);
return NULL;
}
memcpy(msg,tmp,tmp->msg_length);
if(hdr->free_ptr>(8+tmp->msg_length))
{
memcpy(tmp,tmp+1,hdr->free_ptr-8-tmp->msg_length);
hdr->free_ptr-=tmp->msg_length;
}
unlock_msg_queue(hdr);
return msg;
}

View File

@@ -0,0 +1,13 @@
#include"ipc.h"
#include<stdlib.h>
void ipc_send_message(int dst_pid,ipc_msg_t * msg)
{
int d0,d1,d2,d3,d4;
__asm__ __volatile__(
"addl $4,%%edx\n\t"
"int $0x40"
:"=a"(d0),"=b"(d1),"=c"(d2),"=d"(d3),"=S"(d4)
:"0"(60),"1"(2),"2"(dst_pid),"3"(msg),"4"(msg->msg_length)
:"memory");
}