Merge in Windows port using mingw and make.
This commit is contained in:
@ -1,10 +1,6 @@
|
||||
ROOT=..
|
||||
include ../Make.config
|
||||
LIB=libkern.a
|
||||
CC=gcc
|
||||
CFLAGS=-I../include -I. -c -ggdb -D_THREAD_SAFE -pthread
|
||||
O=o
|
||||
#CC=cl
|
||||
#CFLAGS=-c -nologo -W3 -YX -Zi -MT -Zl -I../include -DWINDOWS
|
||||
#O=obj
|
||||
|
||||
OFILES=\
|
||||
allocb.$O\
|
||||
@ -14,9 +10,9 @@ OFILES=\
|
||||
dev.$O\
|
||||
devcons.$O\
|
||||
devdraw.$O\
|
||||
devfs.$O\
|
||||
devfs-$(OS).$O\
|
||||
devip.$O\
|
||||
devip-posix.$O\
|
||||
devip-$(OS).$O\
|
||||
devmnt.$O\
|
||||
devmouse.$O\
|
||||
devpipe.$O\
|
||||
@ -26,7 +22,6 @@ OFILES=\
|
||||
error.$O\
|
||||
parse.$O\
|
||||
pgrp.$O\
|
||||
posix.$O\
|
||||
procinit.$O\
|
||||
rwlock.$O\
|
||||
sleep.$O\
|
||||
@ -39,11 +34,12 @@ OFILES=\
|
||||
term.$O\
|
||||
todo.$O\
|
||||
uart.$O\
|
||||
waserror.$O
|
||||
waserror.$O\
|
||||
$(OS).$O
|
||||
|
||||
$(LIB): $(OFILES)
|
||||
ar r $(LIB) $(OFILES)
|
||||
ranlib $(LIB)
|
||||
$(AR) r $(LIB) $(OFILES)
|
||||
$(RANLIB) $(LIB)
|
||||
|
||||
%.$O: %.c
|
||||
$(CC) $(CFLAGS) $*.c
|
||||
|
@ -445,12 +445,12 @@ kbdputc(Queue *q, int c)
|
||||
if(c == Kalt){
|
||||
collecting = 1;
|
||||
nk = 0;
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!collecting){
|
||||
_kbdputc(c);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
kc[nk++] = c;
|
||||
@ -1034,8 +1034,7 @@ rand(void)
|
||||
return randn;
|
||||
}
|
||||
|
||||
/* static uvlong uvorder = 0x0001020304050607ULL; */
|
||||
static uvlong uvorder = (uvlong)0x0001020304050607;
|
||||
static uvlong uvorder = (uvlong) 0x0001020304050607ULL;
|
||||
|
||||
static uchar*
|
||||
le2vlong(vlong *to, uchar *f)
|
||||
|
@ -575,7 +575,7 @@ fsdirread(Chan *c, uchar *va, int count, ulong offset)
|
||||
memset(&stbuf, 0, sizeof stbuf);
|
||||
|
||||
if(stat(path, &stbuf) < 0) {
|
||||
print("dir: bad path %s\n", path);
|
||||
/* fprint(2, "dir: bad path %s\n", path); */
|
||||
/* but continue... probably a bad symlink */
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ lastelem(Chan *c)
|
||||
}
|
||||
|
||||
static Chan*
|
||||
fsattach(void *spec)
|
||||
fsattach(char *spec)
|
||||
{
|
||||
Chan *c;
|
||||
struct stat stbuf;
|
||||
@ -340,7 +340,7 @@ fsclose(Chan *c)
|
||||
}
|
||||
|
||||
static long
|
||||
fsread(Chan *c, void *va, long n, ulong offset)
|
||||
fsread(Chan *c, void *va, long n, vlong offset)
|
||||
{
|
||||
int fd, r;
|
||||
Ufsinfo *uif;
|
||||
@ -375,7 +375,7 @@ fsread(Chan *c, void *va, long n, ulong offset)
|
||||
}
|
||||
|
||||
static long
|
||||
fswrite(Chan *c, void *va, long n, ulong offset)
|
||||
fswrite(Chan *c, void *va, long n, vlong offset)
|
||||
{
|
||||
int fd, r;
|
||||
Ufsinfo *uif;
|
@ -1,5 +1,4 @@
|
||||
#include <windows.h>
|
||||
#include "winduhz.h"
|
||||
#include "u.h"
|
||||
#include "lib.h"
|
||||
#include "dat.h"
|
@ -477,8 +477,10 @@ mntstat(Chan *c, uchar *dp, int n)
|
||||
r->request.fid = c->fid;
|
||||
mountrpc(m, r);
|
||||
|
||||
if(r->reply.nstat >= 1<<(8*BIT16SZ))
|
||||
/* r->reply.nstat is 16 bits
|
||||
if(r->reply.nstat >= 1<<16)
|
||||
error("returned stat buffer count too large");
|
||||
*/
|
||||
|
||||
if(r->reply.nstat > n){
|
||||
/*
|
||||
|
@ -1025,7 +1025,7 @@ Encalg encrypttab[] =
|
||||
{ "rc4_40", 1, RC4, initRC4key_40, },
|
||||
{ 0 }
|
||||
};
|
||||
#endif NOSPOOKS
|
||||
#endif /* NOSPOOKS */
|
||||
|
||||
static int
|
||||
parseencryptalg(char *p, Dstate *s)
|
||||
|
@ -196,6 +196,7 @@ int notify(Ureg*);
|
||||
int nrand(int);
|
||||
int okaddr(ulong, ulong, int);
|
||||
int openmode(ulong);
|
||||
void oserrstr(void);
|
||||
Block* packblock(Block*);
|
||||
Block* padblock(Block*, int);
|
||||
void pagechainhead(Page*);
|
||||
|
47
kern/mkfile
47
kern/mkfile
@ -1,47 +0,0 @@
|
||||
<$DSRC/mkfile-$CONF
|
||||
TARG=libkern.$L
|
||||
|
||||
OFILES=\
|
||||
allocb.$O\
|
||||
cache.$O\
|
||||
chan.$O\
|
||||
data.$O\
|
||||
dev.$O\
|
||||
devcons.$O\
|
||||
devdraw.$O\
|
||||
devip.$O\
|
||||
devmnt.$O\
|
||||
devmouse.$O\
|
||||
devpipe.$O\
|
||||
devroot.$O\
|
||||
devssl.$O\
|
||||
devtab.$O\
|
||||
error.$O\
|
||||
parse.$O\
|
||||
pgrp.$O\
|
||||
procinit.$O\
|
||||
rwlock.$O\
|
||||
sleep.$O\
|
||||
smalloc.$O\
|
||||
stub.$O\
|
||||
sysfile.$O\
|
||||
sysproc.$O\
|
||||
qio.$O\
|
||||
qlock.$O\
|
||||
term.$O\
|
||||
todo.$O\
|
||||
uart.$O\
|
||||
waserror.$O\
|
||||
$DEVIP.$O\
|
||||
$OSHOOKS.$O\
|
||||
$DEVFS.$O
|
||||
|
||||
HFILE=\
|
||||
dat.h\
|
||||
devip.h\
|
||||
error.h\
|
||||
fns.h\
|
||||
netif.h\
|
||||
screen.h
|
||||
|
||||
<$DSRC/mklib-$CONF
|
@ -1,184 +0,0 @@
|
||||
#include <windows.h>
|
||||
#include "u.h"
|
||||
#include "lib.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
typedef struct Oproc Oproc;
|
||||
struct Oproc {
|
||||
int tid;
|
||||
HANDLE *sema;
|
||||
};
|
||||
|
||||
char *argv0;
|
||||
_declspec(thread) Proc *CT;
|
||||
|
||||
Proc*
|
||||
_getproc(void)
|
||||
{
|
||||
return CT;
|
||||
}
|
||||
|
||||
void
|
||||
_setproc(Proc *p)
|
||||
{
|
||||
CT = p;
|
||||
}
|
||||
|
||||
void
|
||||
oserrstr(void)
|
||||
{
|
||||
char *p;
|
||||
char buf[ERRMAX];
|
||||
|
||||
if((p = strerror(errno)) != nil)
|
||||
strecpy(up->errstr, up->errstr+ERRMAX, p);
|
||||
else
|
||||
snprint(up->errstr, ERRMAX, "unix error %d", errno);
|
||||
}
|
||||
|
||||
void
|
||||
oserror(void)
|
||||
{
|
||||
oserrstr();
|
||||
nexterror();
|
||||
}
|
||||
|
||||
void
|
||||
osinit(void)
|
||||
{
|
||||
Oproc *t;
|
||||
static Proc firstprocCTstore;
|
||||
|
||||
CT = &firstprocCTstore;
|
||||
t = (Oproc*) CT->oproc;
|
||||
assert(t != 0);
|
||||
|
||||
t->tid = GetCurrentThreadId();
|
||||
t->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if(t->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
osnewproc(Proc *p)
|
||||
{
|
||||
Oproc *op;
|
||||
|
||||
op = (Oproc*)p->oproc;
|
||||
op->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if (op->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
osmsleep(int ms)
|
||||
{
|
||||
Sleep((DWORD) ms);
|
||||
}
|
||||
|
||||
void
|
||||
osyield(void)
|
||||
{
|
||||
Sleep(0);
|
||||
}
|
||||
|
||||
static DWORD WINAPI tramp(LPVOID vp);
|
||||
|
||||
void
|
||||
osproc(Proc *p)
|
||||
{
|
||||
int tid;
|
||||
|
||||
if(CreateThread(0, 0, tramp, p, 0, &tid) == 0) {
|
||||
oserror();
|
||||
fatal("osproc: %r");
|
||||
}
|
||||
|
||||
Sleep(0);
|
||||
}
|
||||
|
||||
static DWORD WINAPI
|
||||
tramp(LPVOID vp)
|
||||
{
|
||||
Proc *p = (Proc *) vp;
|
||||
Oproc *op = (Oproc*) p->oproc;
|
||||
|
||||
CT = p;
|
||||
op->tid = GetCurrentThreadId();
|
||||
op->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if(op->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
|
||||
(*p->fn)(p->arg);
|
||||
ExitThread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
procsleep(void)
|
||||
{
|
||||
Proc *p;
|
||||
Oproc *op;
|
||||
|
||||
p = up;
|
||||
op = (Oproc*)p->oproc;
|
||||
WaitForSingleObject(op->sema, INFINITE);}
|
||||
|
||||
void
|
||||
procwakeup(Proc *p)
|
||||
{
|
||||
Oproc *op;
|
||||
|
||||
op = (Oproc*)p->oproc;
|
||||
ReleaseSemaphore(op->sema, 1, 0);
|
||||
}
|
||||
|
||||
void
|
||||
randominit(void)
|
||||
{
|
||||
srand(seconds());
|
||||
}
|
||||
|
||||
ulong
|
||||
randomread(void *v, ulong n)
|
||||
{
|
||||
int m, i, *r;
|
||||
|
||||
m = (n / sizeof(int)) * sizeof(int);
|
||||
for (i = 0, r = (int*)v; i < m; i += sizeof(int)) {
|
||||
*r = rand();
|
||||
r += sizeof(int);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
long
|
||||
seconds(void)
|
||||
{
|
||||
return time(0);
|
||||
}
|
||||
|
||||
int
|
||||
ticks(void)
|
||||
{
|
||||
return GetTickCount();
|
||||
}
|
||||
|
||||
extern int main(int, char*[]);
|
||||
static int args(char *argv[], int n, char *p);
|
||||
|
||||
int PASCAL
|
||||
WinMain(HANDLE hInst, HANDLE hPrev, LPSTR arg, int nshow)
|
||||
{
|
||||
main(__argc, __argv);
|
||||
ExitThread(0);
|
||||
return 0;
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
void
|
||||
uartputs(char *s, int n)
|
||||
{
|
||||
write(1, s, n);
|
||||
// write(1, s, n);
|
||||
}
|
||||
|
||||
|
||||
|
284
kern/win32.c
Normal file
284
kern/win32.c
Normal file
@ -0,0 +1,284 @@
|
||||
#include <windows.h>
|
||||
#include "u.h"
|
||||
#include "lib.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
typedef struct Oproc Oproc;
|
||||
struct Oproc {
|
||||
int tid;
|
||||
HANDLE *sema;
|
||||
};
|
||||
|
||||
static int tlsx = TLS_OUT_OF_INDEXES;
|
||||
|
||||
char *argv0;
|
||||
|
||||
Proc*
|
||||
_getproc(void)
|
||||
{
|
||||
if(tlsx == TLS_OUT_OF_INDEXES)
|
||||
return nil;
|
||||
return TlsGetValue(tlsx);
|
||||
}
|
||||
|
||||
void
|
||||
_setproc(Proc *p)
|
||||
{
|
||||
if(tlsx == TLS_OUT_OF_INDEXES){
|
||||
tlsx = TlsAlloc();
|
||||
if(tlsx == TLS_OUT_OF_INDEXES)
|
||||
panic("out of indexes");
|
||||
}
|
||||
TlsSetValue(tlsx, p);
|
||||
}
|
||||
|
||||
void
|
||||
oserror(void)
|
||||
{
|
||||
oserrstr();
|
||||
nexterror();
|
||||
}
|
||||
|
||||
void
|
||||
osinit(void)
|
||||
{
|
||||
Oproc *t;
|
||||
static Proc firstprocCTstore;
|
||||
|
||||
_setproc(&firstprocCTstore);
|
||||
t = (Oproc*)firstprocCTstore.oproc;
|
||||
assert(t != 0);
|
||||
|
||||
t->tid = GetCurrentThreadId();
|
||||
t->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if(t->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
osnewproc(Proc *p)
|
||||
{
|
||||
Oproc *op;
|
||||
|
||||
op = (Oproc*)p->oproc;
|
||||
op->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if (op->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
osmsleep(int ms)
|
||||
{
|
||||
Sleep((DWORD) ms);
|
||||
}
|
||||
|
||||
void
|
||||
osyield(void)
|
||||
{
|
||||
Sleep(0);
|
||||
}
|
||||
|
||||
static DWORD WINAPI tramp(LPVOID vp);
|
||||
|
||||
void
|
||||
osproc(Proc *p)
|
||||
{
|
||||
DWORD tid;
|
||||
|
||||
if(CreateThread(0, 0, tramp, p, 0, &tid) == 0) {
|
||||
oserror();
|
||||
fatal("osproc: %r");
|
||||
}
|
||||
|
||||
Sleep(0);
|
||||
}
|
||||
|
||||
static DWORD WINAPI
|
||||
tramp(LPVOID vp)
|
||||
{
|
||||
Proc *p = (Proc *) vp;
|
||||
Oproc *op = (Oproc*) p->oproc;
|
||||
|
||||
_setproc(p);
|
||||
op->tid = GetCurrentThreadId();
|
||||
op->sema = CreateSemaphore(0, 0, 1000, 0);
|
||||
if(op->sema == 0) {
|
||||
oserror();
|
||||
fatal("could not create semaphore: %r");
|
||||
}
|
||||
|
||||
(*p->fn)(p->arg);
|
||||
ExitThread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
procsleep(void)
|
||||
{
|
||||
Proc *p;
|
||||
Oproc *op;
|
||||
|
||||
p = up;
|
||||
op = (Oproc*)p->oproc;
|
||||
WaitForSingleObject(op->sema, INFINITE);}
|
||||
|
||||
void
|
||||
procwakeup(Proc *p)
|
||||
{
|
||||
Oproc *op;
|
||||
|
||||
op = (Oproc*)p->oproc;
|
||||
ReleaseSemaphore(op->sema, 1, 0);
|
||||
}
|
||||
|
||||
void
|
||||
randominit(void)
|
||||
{
|
||||
srand(seconds());
|
||||
}
|
||||
|
||||
ulong
|
||||
randomread(void *v, ulong n)
|
||||
{
|
||||
int m, i, *r;
|
||||
|
||||
m = (n / sizeof(int)) * sizeof(int);
|
||||
for (i = 0, r = (int*)v; i < m; i += sizeof(int)) {
|
||||
*r = rand();
|
||||
r += sizeof(int);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
long
|
||||
seconds(void)
|
||||
{
|
||||
return time(0);
|
||||
}
|
||||
|
||||
int
|
||||
ticks(void)
|
||||
{
|
||||
return GetTickCount();
|
||||
}
|
||||
|
||||
#if 0
|
||||
uvlong
|
||||
fastticks(uvlong *v)
|
||||
{
|
||||
uvlong n;
|
||||
|
||||
n = GetTickCount() * 1000 * 1000;
|
||||
if(v)
|
||||
*v = n;
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int main(int, char*[]);
|
||||
static int args(char *argv[], int n, char *p);
|
||||
|
||||
int APIENTRY
|
||||
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR arg, int nshow)
|
||||
{
|
||||
main(__argc, __argv);
|
||||
ExitThread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Windows socket error messages
|
||||
* There must be a way to get these strings out of the library.
|
||||
* This table is derived from the MSDN online help.
|
||||
*/
|
||||
static struct {
|
||||
int e;
|
||||
char *s;
|
||||
} tab[] = {
|
||||
{ 10004, "interrupted function call" },
|
||||
{ 10013, "permission denied" },
|
||||
{ 10014, "bad address" },
|
||||
{ 10022, "invalid argument" },
|
||||
{ 10024, "too many open files" },
|
||||
{ 10035, "resource temporarily unavailable" },
|
||||
{ 10036, "operation now in progress" },
|
||||
{ 10037, "operation already in progress" },
|
||||
{ 10038, "socket operation on nonsocket" },
|
||||
{ 10039, "destination address required" },
|
||||
{ 10040, "message too long" },
|
||||
{ 10041, "protocol wrong type for socket" },
|
||||
{ 10042, "bad protocol option" },
|
||||
{ 10043, "protocol not supported" },
|
||||
{ 10044, "socket type not supported" },
|
||||
{ 10045, "operation not supported" },
|
||||
{ 10046, "protocol family not supported" },
|
||||
{ 10047, "address family not supported by protocol family" },
|
||||
{ 10048, "address already in use" },
|
||||
{ 10049, "cannot assign requested address" },
|
||||
{ 10050, "network is down" },
|
||||
{ 10051, "network is unreachable" },
|
||||
{ 10052, "network dropped connection on reset" },
|
||||
{ 10053, "software caused connection abort" },
|
||||
{ 10054, "connection reset by peer" },
|
||||
{ 10055, "no buffer space available" },
|
||||
{ 10056, "socket is already connected" },
|
||||
{ 10057, "socket is not connected" },
|
||||
{ 10058, "cannot send after socket shutdown" },
|
||||
{ 10060, "connection timed out" },
|
||||
{ 10061, "connection refused" },
|
||||
{ 10064, "host is down" },
|
||||
{ 10065, "no route to host" },
|
||||
{ 10067, "too many processes" },
|
||||
{ 10091, "network subsystem is unavailable" },
|
||||
{ 10092, "winsock.dll version out of range" },
|
||||
{ 10093, "wsastartup not called" },
|
||||
{ 10101, "graceful shutdown in progress" },
|
||||
{ 10109, "class type not found" },
|
||||
{ 11001, "host name not found" },
|
||||
{ 11002, "host not found (non-authoritative)" },
|
||||
{ 11003, "nonrecoverable error" },
|
||||
{ 11004, "valid name, but no data record of requested type" },
|
||||
};
|
||||
|
||||
void
|
||||
osrerrstr(char *buf, uint nbuf)
|
||||
{
|
||||
char *p, *q;
|
||||
int e, i, r;
|
||||
|
||||
e = GetLastError();
|
||||
r = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0, e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
buf, nbuf, 0);
|
||||
if(r == 0){
|
||||
for(i=0; i<nelem(tab); i++)
|
||||
if(tab[i].e == e){
|
||||
strecpy(buf, buf+nbuf, tab[i].s);
|
||||
break;
|
||||
}
|
||||
if(i==nelem(tab))
|
||||
snprint(buf, nbuf, "windows error %d", e);
|
||||
}
|
||||
|
||||
for(p=q=buf; *p; p++) {
|
||||
if(*p == '\r')
|
||||
continue;
|
||||
if(*p == '\n')
|
||||
*q++ = ' ';
|
||||
else
|
||||
*q++ = *p;
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
oserrstr(void)
|
||||
{
|
||||
osrerrstr(up->errstr, ERRMAX);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <setjmp.h>
|
||||
#include <direct.h>
|
||||
#include <process.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* disable various silly warnings */
|
||||
#pragma warning( disable : 4245 4305 4244 4102 4761 4090 4028 4024)
|
||||
|
||||
typedef __int64 p9_vlong;
|
||||
typedef unsigned __int64 p9_uvlong;
|
Reference in New Issue
Block a user