forked from KolibriOS/kolibrios
947f48e392
git-svn-id: svn://kolibrios.org@817 a494cfbc-eb01-0410-851d-a64ba20cac60
207 lines
4.9 KiB
C
207 lines
4.9 KiB
C
|
|
#define OS_BASE 0x80000000
|
|
|
|
#include "xmd.h"
|
|
|
|
#define NULL (void*)(0)
|
|
|
|
#define FALSE 0
|
|
#define TRUE 1
|
|
|
|
typedef void *pointer;
|
|
|
|
typedef unsigned int Bool;
|
|
|
|
typedef unsigned char u8;
|
|
typedef unsigned short u16;
|
|
typedef unsigned int u32;
|
|
|
|
typedef unsigned char u8_t;
|
|
typedef unsigned short u16_t;
|
|
typedef unsigned int u32_t;
|
|
|
|
typedef unsigned int memType;
|
|
typedef unsigned int size_t;
|
|
|
|
typedef struct { float hi, lo; } range;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
unsigned handle;
|
|
unsigned io_code;
|
|
void *input;
|
|
int inp_size;
|
|
void *output;
|
|
int out_size;
|
|
}ioctl_t;
|
|
|
|
typedef int (_stdcall *srv_proc_t)(ioctl_t *);
|
|
|
|
#define ERR_OK 0
|
|
#define ERR_PARAM -1
|
|
|
|
|
|
u32_t __stdcall drvEntry(int)__asm__("_drvEntry");
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
|
|
#define IMPORT __attribute__ ((dllimport))
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define PG_SW 0x003
|
|
#define PG_NOCACHE 0x018
|
|
|
|
void* STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
|
|
void* STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
|
|
void* STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
|
|
|
|
int KernelFree(void *);
|
|
|
|
void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer");
|
|
|
|
u32 STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
|
|
|
|
//void *CreateObject(u32 pid, size_t size);
|
|
//void *DestroyObject(void *obj);
|
|
|
|
CARD32 STDCALL MapIoMem(CARD32 Base,CARD32 size,CARD32 flags)__asm__("MapIoMem");
|
|
|
|
static inline u32_t GetPgAddr(void *mem)
|
|
{
|
|
u32_t retval;
|
|
|
|
asm volatile (
|
|
"call *__imp__GetPgAddr \n\t"
|
|
:"=eax" (retval)
|
|
:"a" (mem)
|
|
);
|
|
return retval;
|
|
}
|
|
|
|
static inline void CommitPages(void *mem, u32_t page, u32_t size)
|
|
{
|
|
size = (size+4095) & ~4095;
|
|
asm volatile (
|
|
"call *__imp__CommitPages"
|
|
:
|
|
:"a" (page), "b"(mem),"c"(size>>12)
|
|
:"edx"
|
|
);
|
|
|
|
|
|
}
|
|
static inline void UnmapPages(void *mem, size_t size)
|
|
{
|
|
size = (size+4095) & ~4095;
|
|
asm volatile (
|
|
"call *__imp__UnmapPages"
|
|
:
|
|
:"a" (mem), "c"(size>>12)
|
|
:"eax","ecx", "edx"
|
|
);
|
|
}
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
u32 PciApi(int cmd);
|
|
|
|
u8 STDCALL PciRead8 (u32 bus, u32 devfn, u32 reg)__asm__("PciRead8");
|
|
u16 STDCALL PciRead16(u32 bus, u32 devfn, u32 reg)__asm__("PciRead16");
|
|
u32 STDCALL PciRead32(u32 bus, u32 devfn, u32 reg)__asm__("PciRead32");
|
|
|
|
u32 STDCALL PciWrite8 (u32 bus, u32 devfn, u32 reg,u8 val) __asm__("PciWrite8");
|
|
u32 STDCALL PciWrite16(u32 bus, u32 devfn, u32 reg,u16 val)__asm__("PciWrite16");
|
|
u32 STDCALL PciWrite32(u32 bus, u32 devfn, u32 reg,u32 val)__asm__("PciWrite32");
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define SysMsgBoardStr __SysMsgBoardStr
|
|
#define PciApi __PciApi
|
|
//#define RegService __RegService
|
|
#define CreateObject __CreateObject
|
|
#define DestroyObject __DestroyObject
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void *malloc(size_t);
|
|
void *calloc( size_t num, size_t size );
|
|
void *realloc(void*, size_t);
|
|
void free(void*);
|
|
|
|
#define kmalloc malloc
|
|
#define kfree free
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n);
|
|
void * memcpy(void * _dest, const void *_src, size_t _n);
|
|
char * strcpy(char *to, const char *from);
|
|
char * strcat(char *s, const char *append);
|
|
int strcmp(const char *s1, const char *s2);
|
|
size_t strlen(const char *str);
|
|
char * strdup(const char *_s);
|
|
char * strchr(const char *s, int c);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int snprintf(char *s, size_t n, const char *format, ...);
|
|
int printf(const char* format, ...);
|
|
int dbg_open(char *path);
|
|
int dbgprintf(const char* format, ...);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
void usleep(u32 delay);
|
|
|
|
static int __attribute__ ((always_inline))
|
|
abs (int i)
|
|
{
|
|
return i < 0 ? -i : i;
|
|
};
|
|
|
|
static void __attribute__ ((always_inline))
|
|
__clear (void * dst, unsigned len)
|
|
{ u32 tmp;
|
|
asm __volatile__
|
|
(
|
|
"xorl %%eax, %%eax \n\t"
|
|
"cld \n\t"
|
|
"rep stosb \n"
|
|
:"=c"(tmp),"=D"(tmp)
|
|
:"c"(len),"D"(dst)
|
|
:"memory","eax","cc"
|
|
);
|
|
};
|
|
|
|
|
|
static inline u32 safe_cli(void)
|
|
{
|
|
u32 tmp;
|
|
asm volatile (
|
|
"pushf\n\t"
|
|
"popl %0\n\t"
|
|
"cli\n"
|
|
: "=r" (tmp)
|
|
);
|
|
return tmp;
|
|
}
|
|
|
|
static inline void safe_sti(u32 ipl)
|
|
{
|
|
asm volatile (
|
|
"pushl %0\n\t"
|
|
"popf\n"
|
|
: : "r" (ipl)
|
|
);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int _stdcall srv_cursor(ioctl_t *io);
|
|
int _stdcall srv_2d(ioctl_t *io);
|
|
|
|
|