forked from KolibriOS/kolibrios
initial import of metcc project
git-svn-id: svn://kolibrios.org@145 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
118
programs/develop/metcc/trunk/libc/compile.js
Normal file
118
programs/develop/metcc/trunk/libc/compile.js
Normal file
@@ -0,0 +1,118 @@
|
||||
var fso=new ActiveXObject("Scripting.FileSystemObject");
|
||||
var wsh=WScript.CreateObject("WScript.Shell");
|
||||
var curpath=".";
|
||||
var gccpath="c:\\program files\\MinGW\\MinGW\\bin\\";
|
||||
//var gccpath="cmd.exe /c ";
|
||||
var gccexe="\""+gccpath+"cc1.exe"+"\" ";
|
||||
var asexe="\""+gccpath+"as.exe"+"\" ";
|
||||
var objcopyexe="\""+gccpath+"objcopy.exe"+"\" ";
|
||||
//var gccexe=gccpath+"cc1.exe" ;
|
||||
//var asexe=gccpath+"as.exe";
|
||||
var scriptline="CREATE melibc.a\r\n";
|
||||
|
||||
curpath=".\\string\\";
|
||||
compileasm("memmove");
|
||||
compileasm("memset");
|
||||
curpath=".\\mesys\\";
|
||||
compileasm("backgr");
|
||||
compileasm("button");
|
||||
compileasm("clock");
|
||||
compileasm("date");
|
||||
compileasm("debug_board");
|
||||
compileasm("delay");
|
||||
compileasm("dga");
|
||||
compileasm("draw_bar");
|
||||
compileasm("draw_image");
|
||||
compileasm("draw_window");
|
||||
compileasm("event");
|
||||
compileasm("exit");
|
||||
compileasm("file_58");
|
||||
compileasm("ipc");
|
||||
compileasm("irq");
|
||||
compileasm("keyboard");
|
||||
compileasm("line");
|
||||
compileasm("midi");
|
||||
compileasm("pci");
|
||||
compileasm("pixel");
|
||||
compileasm("process");
|
||||
compileasm("screen");
|
||||
compileasm("sound");
|
||||
compileasm("thread");
|
||||
compileasm("window_redraw");
|
||||
compileasm("write_text");
|
||||
curpath=".\\mem\\";
|
||||
compileasm("memalloc");
|
||||
curpath=".\\mesys\\";
|
||||
compilec("debug_board_");
|
||||
curpath=".\\string\\";
|
||||
compilec("memchr");
|
||||
compilec("memcmp");
|
||||
compilec("strcat");
|
||||
compilec("strchr");
|
||||
compilec("strcmp");
|
||||
compilec("strcoll");
|
||||
compilec("strcpy");
|
||||
compilec("strcspn");
|
||||
compilec("strdup");
|
||||
compilec("strerror");
|
||||
compilec("strlen");
|
||||
compilec("strnbrk");
|
||||
compilec("strncat");
|
||||
compilec("strncmp");
|
||||
compilec("strncpy");
|
||||
compilec("strrchr");
|
||||
compilec("strspn");
|
||||
compilec("strstr");
|
||||
compilec("strtok");
|
||||
compilec("strxfrm");
|
||||
curpath=".\\file\\";
|
||||
compilec("fclose");
|
||||
compilec("fopen");
|
||||
compilec("feof");
|
||||
compilec("fflush");
|
||||
compilec("fgetc");
|
||||
compilec("fgetpos");
|
||||
compilec("fsetpos");
|
||||
compilec("fputc");
|
||||
compilec("fread");
|
||||
compilec("fwrite");
|
||||
compilec("fseek");
|
||||
compilec("ftell");
|
||||
compilec("rewind");
|
||||
compilec("fprintf");
|
||||
compilec("fscanf");
|
||||
compilec("ungetc");
|
||||
curpath=".\\start\\";
|
||||
compileasm("start");
|
||||
//linking
|
||||
scriptline+="SAVE\r\n";
|
||||
linko();
|
||||
function compileasm(filename)
|
||||
{
|
||||
wsh.Run("fasm.exe "+quote(curpath+filename+".asm")+
|
||||
" "+quote(curpath+filename+".o"),0,true);
|
||||
addo(filename);
|
||||
}
|
||||
function compilec(filename)
|
||||
{
|
||||
wsh.Run(gccexe+"-nostdinc -I .\\include -DGNUC " + quote(curpath + filename + ".c")+
|
||||
" -o " + quote(curpath + filename + ".s"),0,true);
|
||||
wsh.Run(asexe+quote(curpath+filename+".s")+" -o "+quote(curpath+filename+".o"),0,true);
|
||||
wsh.Run(objcopyexe+" -O elf32-i386 --remove-leading-char "+quote(curpath+filename+".o"),0,true);
|
||||
addo(filename);
|
||||
}
|
||||
function addo(filename)
|
||||
{
|
||||
scriptline+="ADDMOD "+curpath+filename+".o\r\n";
|
||||
}
|
||||
function linko()
|
||||
{
|
||||
//fso.DeleteFile(".\\melibc.a");
|
||||
var file=fso.OpenTextFile("./script.txt",2,true);
|
||||
file.Write(scriptline);
|
||||
wsh.Run("cmd.exe /c ar.exe -M < ./script.txt",4,true);
|
||||
}
|
||||
function quote(name)
|
||||
{
|
||||
return "\""+name+"\"";
|
||||
}
|
10
programs/develop/metcc/trunk/libc/file/fclose.c
Normal file
10
programs/develop/metcc/trunk/libc/file/fclose.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
int fclose(FILE* file)
|
||||
{
|
||||
int res;
|
||||
res=_msys_write_file(file->filename,file->filesize,file->buffer);
|
||||
free(file->buffer);
|
||||
free(file);
|
||||
return res;
|
||||
}
|
5
programs/develop/metcc/trunk/libc/file/feof.c
Normal file
5
programs/develop/metcc/trunk/libc/file/feof.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "stdio.h"
|
||||
int feof(FILE* file)
|
||||
{
|
||||
return file->filepos>=file->filesize;
|
||||
}
|
7
programs/develop/metcc/trunk/libc/file/fflush.c
Normal file
7
programs/develop/metcc/trunk/libc/file/fflush.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "stdio.h"
|
||||
int fflush(FILE* file)
|
||||
{
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
return 0;
|
||||
return _msys_file_write(file->filename,file->filesize,file->buffer) ? EOF : 0;
|
||||
}
|
12
programs/develop/metcc/trunk/libc/file/fgetc.c
Normal file
12
programs/develop/metcc/trunk/libc/file/fgetc.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "stdio.h"
|
||||
int fgetc(FILE* file)
|
||||
{
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
return EOF;
|
||||
if (file->filepos>=file->filesize)
|
||||
return EOF;
|
||||
else
|
||||
{
|
||||
return (int)file->buffer[file->filepos++];
|
||||
}
|
||||
}
|
6
programs/develop/metcc/trunk/libc/file/fgetpos.c
Normal file
6
programs/develop/metcc/trunk/libc/file/fgetpos.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "stdio.h"
|
||||
int fgetpos(FILE* file,fpos_t* pos)
|
||||
{
|
||||
*pos=file->filepos;
|
||||
return 0;
|
||||
}
|
89
programs/develop/metcc/trunk/libc/file/fopen.c
Normal file
89
programs/develop/metcc/trunk/libc/file/fopen.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
FILE* fopen(const char* filename, const char *mode)
|
||||
{
|
||||
FILE* res;
|
||||
int imode;
|
||||
imode=0;
|
||||
if (*mode=='r')
|
||||
{
|
||||
imode=FILE_OPEN_READ;
|
||||
mode++;
|
||||
}else if (*mode=='w')
|
||||
{
|
||||
imode=FILE_OPEN_WRITE;
|
||||
mode++;
|
||||
}else if (*mode=='a')
|
||||
{
|
||||
imode=FILE_OPEN_APPEND;
|
||||
mode++;
|
||||
}else
|
||||
return 0;
|
||||
if (*mode=='t')
|
||||
{
|
||||
imode|=FILE_OPEN_TEXT;
|
||||
mode++;
|
||||
}else if (*mode=='b')
|
||||
mode++;
|
||||
if (*mode=='+')
|
||||
{
|
||||
imode|=FILE_OPEN_PLUS;
|
||||
mode++;
|
||||
}
|
||||
if (*mode!=0)
|
||||
return 0;
|
||||
res=malloc(sizeof(FILE));
|
||||
res->buffer=0;
|
||||
res->buffersize=0;
|
||||
res->filesize=0;
|
||||
res->filepos=0;
|
||||
res->filename=0;
|
||||
res->mode=imode;
|
||||
//check if file exists
|
||||
res=_msys_read_file(filename,0,0,0,&res->filesize);
|
||||
if (res==5)
|
||||
{
|
||||
if ((imode & 3) == FILE_OPEN_READ)
|
||||
{
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
res=_msys_write_file(filename,0,0);
|
||||
if (res!=0)
|
||||
{
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
res->filesize=0;
|
||||
}
|
||||
if (imode & 3==FILE_OPEN_WRITE)
|
||||
{
|
||||
res->buffersize=512;
|
||||
res->buffer=malloc(res->buffersize);
|
||||
if (res->buffer=0)
|
||||
{
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
res->filesize=0;
|
||||
}else
|
||||
{
|
||||
res->buffersize=(res->filesize & (~511))+512;
|
||||
res->buffer=malloc(res->buffersize);
|
||||
if (res->buffer==0)
|
||||
{
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
res=_msys_read_file(filename,0,res->filesize,res->buffer,0);
|
||||
if (res!=0)
|
||||
{
|
||||
free(res->buffer);
|
||||
free(res);
|
||||
}
|
||||
if (imode & 3==FILE_OPEN_APPEND)
|
||||
res->filepos=res->filesize;
|
||||
}
|
||||
res->filename=strdup(filename);
|
||||
return res;
|
||||
}
|
216
programs/develop/metcc/trunk/libc/file/fprintf.c
Normal file
216
programs/develop/metcc/trunk/libc/file/fprintf.c
Normal file
@@ -0,0 +1,216 @@
|
||||
#include "stdio.h"
|
||||
const char xdigs_lower[16]="0123456789abcdef";
|
||||
const char xdigs_upper[16]="0123456789ABCDEF";
|
||||
int fprintf(FILE* file, const char* format, ...)
|
||||
{
|
||||
void* arg;
|
||||
int ispoint;
|
||||
int beforepoint;
|
||||
int afterpoint;
|
||||
int longflag;
|
||||
int contflag;
|
||||
int i;
|
||||
long long number;
|
||||
char buffer[50];
|
||||
char* str;
|
||||
arg=&format;
|
||||
arg+=sizeof(const char*);
|
||||
while (*format!='\0')
|
||||
{
|
||||
if (*format!='%')
|
||||
{
|
||||
fputc(*format,file);
|
||||
format++;
|
||||
continue;
|
||||
}
|
||||
ispoint=0;
|
||||
beforepoint=0;
|
||||
afterpoint=0;
|
||||
longflag=0;
|
||||
contflag=1;
|
||||
format++;
|
||||
while (*format && contflag)
|
||||
{
|
||||
switch (*format)
|
||||
{
|
||||
case '.':
|
||||
ispoint=1;
|
||||
format++;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (ispoint)
|
||||
afterpoint=afterpoint*10+(*format)-'0';
|
||||
else
|
||||
beforepoint=beforepoint*10+(*format)-'0';
|
||||
format++;
|
||||
break;
|
||||
case 'l':
|
||||
if (longflag==0)
|
||||
longflag=1;
|
||||
else
|
||||
longflag=2;
|
||||
format++;
|
||||
break;
|
||||
case 'L':
|
||||
longflag=2;
|
||||
format++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'd':
|
||||
case 'x':
|
||||
case 'X':
|
||||
case 'c':
|
||||
case 's':
|
||||
case '%':
|
||||
contflag=0;
|
||||
break;
|
||||
default:
|
||||
contflag=0;
|
||||
}
|
||||
}
|
||||
if (contflag)
|
||||
break;
|
||||
switch (*format)
|
||||
{
|
||||
case '%':
|
||||
fpuc('%',file);
|
||||
break;
|
||||
case 'd':
|
||||
if (longflag==2)
|
||||
{
|
||||
number=*((long long *)arg);
|
||||
arg+=sizeof(long long);
|
||||
}else
|
||||
{
|
||||
number=*((int*)arg);
|
||||
arg+=sizeof(int);
|
||||
}
|
||||
if (number<0)
|
||||
{
|
||||
beforepoint--;
|
||||
fputc('-',file);
|
||||
number=-number;
|
||||
}
|
||||
i=0;
|
||||
while (number>0)
|
||||
{
|
||||
buffer[i]='0'+number%10;
|
||||
number=number/10;
|
||||
i++;
|
||||
}
|
||||
while (i<beforepoint)
|
||||
{
|
||||
fputc(' ',file);
|
||||
beforepoint--;
|
||||
}
|
||||
while (i>0)
|
||||
{
|
||||
i--;
|
||||
fputc(buffer[i],file);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
fputc(*(char*)arg,file);
|
||||
arg+=sizeof(char);
|
||||
break;
|
||||
case 's':
|
||||
str=*(char**)arg;
|
||||
arg+=sizeof(char*);
|
||||
if (beforepoint==0)
|
||||
beforepoint--;
|
||||
while (*str && beforepoint)
|
||||
{
|
||||
fputc(*str,file);
|
||||
beforepoint--;
|
||||
str++;
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
if (longflag==2)
|
||||
{
|
||||
number=*((long long *)arg);
|
||||
arg+=sizeof(long long);
|
||||
}else
|
||||
{
|
||||
number=*((int*)arg);
|
||||
arg+=sizeof(int);
|
||||
}
|
||||
if (number<0)
|
||||
{
|
||||
beforepoint--;
|
||||
fputc('-',file);
|
||||
number=-number;
|
||||
}
|
||||
i=0;
|
||||
while (number>0)
|
||||
{
|
||||
buffer[i]=xdigs_lower[number & 15];
|
||||
number=number>>4;
|
||||
i++;
|
||||
}
|
||||
while (i<beforepoint)
|
||||
{
|
||||
fputc(' ',file);
|
||||
beforepoint--;
|
||||
}
|
||||
while (i>0)
|
||||
{
|
||||
i--;
|
||||
fputc(buffer[i],file);
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
if (longflag==2)
|
||||
{
|
||||
number=*((long long *)arg);
|
||||
arg+=sizeof(long long);
|
||||
}else
|
||||
{
|
||||
number=*((int*)arg);
|
||||
arg+=sizeof(int);
|
||||
}
|
||||
if (number<0)
|
||||
{
|
||||
beforepoint--;
|
||||
fputc('-',file);
|
||||
number=-number;
|
||||
}
|
||||
i=0;
|
||||
while (number>0)
|
||||
{
|
||||
buffer[i]=xdigs_upper[number & 15];
|
||||
number=number>>4;
|
||||
i++;
|
||||
}
|
||||
while (i<beforepoint)
|
||||
{
|
||||
fputc(' ',file);
|
||||
beforepoint--;
|
||||
}
|
||||
while (i>0)
|
||||
{
|
||||
i--;
|
||||
fputc(buffer[i],file);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
if (longflag==2)
|
||||
arg+=10;
|
||||
else if (longflag==1)
|
||||
arg+=8;
|
||||
else
|
||||
arg+=4;
|
||||
break;
|
||||
}
|
||||
format++;
|
||||
}
|
||||
}
|
24
programs/develop/metcc/trunk/libc/file/fputc.c
Normal file
24
programs/develop/metcc/trunk/libc/file/fputc.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "stdio.h"
|
||||
int fputc(int c,FILE* file)
|
||||
{
|
||||
void* p;
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
return EOF;
|
||||
if ((file->mode & 3)==FILE_OPEN_APPEND)
|
||||
file->filepos=file->filesize;
|
||||
if (file->filepos==file->filesize)
|
||||
{
|
||||
file->filesize++;
|
||||
if (file->filesize>file->buffersize)
|
||||
{
|
||||
p=realloc(file->buffer,file->filesize+file->filesize<<1);
|
||||
if (p==0)
|
||||
return EOF;
|
||||
file->buffersize=file->filesize+file->filesize<<1;
|
||||
file->buffer=p;
|
||||
}
|
||||
}
|
||||
file->buffer[file->filepos]=(char)c;
|
||||
file->filepos++;
|
||||
return 0;
|
||||
}
|
12
programs/develop/metcc/trunk/libc/file/fread.c
Normal file
12
programs/develop/metcc/trunk/libc/file/fread.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "stdio.h"
|
||||
int fread(void* buffer,int size,int count,FILE* file)
|
||||
{
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
return 0;
|
||||
count=count*size;
|
||||
if (count+file->filepos>file->filesize)
|
||||
count=file->filesize-file->filepos;
|
||||
memcpy(buffer,file->buffer+file->filepos,count);
|
||||
file->filepos+=count;
|
||||
return count/size;
|
||||
}
|
188
programs/develop/metcc/trunk/libc/file/fscanf.c
Normal file
188
programs/develop/metcc/trunk/libc/file/fscanf.c
Normal file
@@ -0,0 +1,188 @@
|
||||
#include "stdio.h"
|
||||
void skipspaces(FILE* file)
|
||||
{
|
||||
int c;
|
||||
while(1)
|
||||
{
|
||||
c=getc(file);
|
||||
if (c!=' ' && c!='\r' && c!='\n')
|
||||
{
|
||||
ungetc(c,file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
int fscanf(FILE* file,const char* format, ...)
|
||||
{
|
||||
int res;
|
||||
void* arg;
|
||||
int i;
|
||||
int c;
|
||||
int contflag;
|
||||
int longflag;
|
||||
int sign;
|
||||
long long number;
|
||||
long double rnumber;
|
||||
char* str;
|
||||
res=0;
|
||||
arg=&format;
|
||||
arg+=sizeof(const char*);
|
||||
while (*format!='\0')
|
||||
{
|
||||
if (*format!='%')
|
||||
{
|
||||
c=fgetc(file);
|
||||
if (c!=*format)
|
||||
{
|
||||
fungetc(c,file);
|
||||
return -1;
|
||||
}
|
||||
format++;
|
||||
continue;
|
||||
}
|
||||
contflag=1;
|
||||
longflag=0;
|
||||
while (*format && contflag)
|
||||
{
|
||||
switch(*format)
|
||||
{
|
||||
case '.':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
format++;
|
||||
continue;
|
||||
break;
|
||||
case 'l':
|
||||
if (longflag==0)
|
||||
longflag=1;
|
||||
else
|
||||
longflag=2;
|
||||
format++;
|
||||
break;
|
||||
case 'L':
|
||||
longflag=2;
|
||||
format++;
|
||||
break;
|
||||
case 'f':
|
||||
case 'd':
|
||||
case 'c':
|
||||
case 's':
|
||||
case '%':
|
||||
contflag=0;
|
||||
break;
|
||||
default:
|
||||
contflag=0;
|
||||
}
|
||||
}
|
||||
if (contflag)
|
||||
break;
|
||||
switch(*format)
|
||||
{
|
||||
case '%':
|
||||
c=fgetc(file);
|
||||
if (c!='%')
|
||||
{
|
||||
ungetc(c,file);
|
||||
return -1;
|
||||
}
|
||||
res--;
|
||||
break;
|
||||
case 'd':
|
||||
number=0;
|
||||
sign=1;
|
||||
skipspaces(file);
|
||||
c=fgetc(file);
|
||||
if (c=='-')
|
||||
{
|
||||
sign=-1;
|
||||
}else if (c!='+')
|
||||
ungetc(c,file);
|
||||
contflag=0;
|
||||
while(1)
|
||||
{
|
||||
c=fgetc(file);
|
||||
if (c>='0' && c<='9')
|
||||
{
|
||||
contflag++;
|
||||
number=number*10+(c-'0');
|
||||
}else
|
||||
break;
|
||||
}
|
||||
ungetc(c,file);
|
||||
if (!contflag)
|
||||
return res;
|
||||
if (longflag<=1)
|
||||
{
|
||||
*((int*)arg)=number;
|
||||
arg+=sizeof(int);
|
||||
}else
|
||||
{
|
||||
*((long long*)arg)=number;
|
||||
arg+=sizeof(long long);
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
c=fgetc(file);
|
||||
if (c==EOF)
|
||||
return res;
|
||||
*((char*)arg)=c;
|
||||
arg+=sizeof(char);
|
||||
break;
|
||||
case 's':
|
||||
skipspaces(file);
|
||||
contflag=0;
|
||||
str=*((char**)arg);
|
||||
arg+=sizeof(char*);
|
||||
while(1)
|
||||
{
|
||||
c=fgetc(file);
|
||||
if (c==EOF || c==' ' || c=='\n' || c=='\r')
|
||||
{
|
||||
ungetc(c,file);
|
||||
break;
|
||||
}
|
||||
*str=c;
|
||||
str++;
|
||||
contflag++;
|
||||
}
|
||||
if (!contflag)
|
||||
return res;
|
||||
break;
|
||||
case 'f':
|
||||
skipspaces(file);
|
||||
// TODO: read real numbers
|
||||
rnumber=0;
|
||||
switch (longflag)
|
||||
{
|
||||
case 0:
|
||||
*((float*)arg)=rnumber;
|
||||
arg+=sizeof(float);
|
||||
break;
|
||||
case 1:
|
||||
*((double*)arg)=rnumber;
|
||||
arg+=sizeof(double);
|
||||
break;
|
||||
case 2:
|
||||
*((long double*)arg)=rnumber;
|
||||
arg+=sizeof(long double);
|
||||
break;
|
||||
default:
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
format++;
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
11
programs/develop/metcc/trunk/libc/file/fseek.c
Normal file
11
programs/develop/metcc/trunk/libc/file/fseek.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "stdio.h"
|
||||
int fseek(FILE* file,long offset,int origin)
|
||||
{
|
||||
if (origin==SEEK_CUR)
|
||||
offset+=file->filepos;
|
||||
else if (origin==SEEK_END)
|
||||
offset+=file->filesize;
|
||||
else if (origin!=SEEK_SET)
|
||||
return EOF;
|
||||
return fsetpos(file,offset);
|
||||
}
|
11
programs/develop/metcc/trunk/libc/file/fsetpos.c
Normal file
11
programs/develop/metcc/trunk/libc/file/fsetpos.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "stdio.h"
|
||||
int fsetpos(FILE* file,const fpos_t * pos)
|
||||
{
|
||||
if (*pos>=0)
|
||||
{
|
||||
file->filepos=*pos;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return EOF;
|
||||
}
|
5
programs/develop/metcc/trunk/libc/file/ftell.c
Normal file
5
programs/develop/metcc/trunk/libc/file/ftell.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "stdio.h"
|
||||
long ftell(FILE* file)
|
||||
{
|
||||
return file->filepos;
|
||||
}
|
23
programs/develop/metcc/trunk/libc/file/fwrite.c
Normal file
23
programs/develop/metcc/trunk/libc/file/fwrite.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "stdio.h"
|
||||
int fwrite(const void* buffer,int size,int count,FILE* file)
|
||||
{
|
||||
void* p;
|
||||
if ((file->mode & 3==FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
return 0;
|
||||
if (file->mode & 3==FILE_OPEN_APPEND)
|
||||
file->filepos=file->filesize;
|
||||
count=count*size;
|
||||
if (file->buffersize<file->filepos+count)
|
||||
{
|
||||
p=realloc(file->buffer,(file->filepos+count)+(file->filepos+count)<<1);
|
||||
if (p==0)
|
||||
return 0;
|
||||
file->buffer=p;
|
||||
file->buffersize=(file->filepos+count)+(file->filepos+count)<<1;
|
||||
}
|
||||
if (file->filesize<file->filepos+count)
|
||||
file->filesize=file->filepos+count;
|
||||
memcpy(file->buffer+file->filepos,buffer,count);
|
||||
file->filepos+=count;
|
||||
return count;
|
||||
}
|
5
programs/develop/metcc/trunk/libc/file/rewind.c
Normal file
5
programs/develop/metcc/trunk/libc/file/rewind.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "stdio.h"
|
||||
void rewind(FILE* file)
|
||||
{
|
||||
file->filepos=0;
|
||||
}
|
11
programs/develop/metcc/trunk/libc/file/ungetc.c
Normal file
11
programs/develop/metcc/trunk/libc/file/ungetc.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "stdio.h"
|
||||
int ungetc(int c,FILE* file)
|
||||
{
|
||||
if (c==EOF)
|
||||
return EOF;
|
||||
if (file->filepos<=0 || file->filepos>file->filesize)
|
||||
return EOF;
|
||||
file->filepos--;
|
||||
file->buffer[file->filepos]=(char)c;
|
||||
return c;
|
||||
}
|
88
programs/develop/metcc/trunk/libc/include/mesys.h
Normal file
88
programs/develop/metcc/trunk/libc/include/mesys.h
Normal file
@@ -0,0 +1,88 @@
|
||||
#ifndef mesys_h
|
||||
#define mesys_h
|
||||
#ifdef GNUC
|
||||
#define stdcall __stdcall
|
||||
#else
|
||||
#define stdcall __attribute__ ((__stdcall))
|
||||
#endif
|
||||
extern void stdcall _msys_draw_window(int xcoord,int ycoord, int xsize,
|
||||
int ysize,int workcolor,int type,
|
||||
int captioncolor,int windowtype,int bordercolor);
|
||||
extern int stdcall _msys_read_file(char* filename,int fileoffset,int size,void* data,
|
||||
int* filesize);
|
||||
extern int stdcall _msys_write_file(char* filename,int size,void* data);
|
||||
extern void stdcall _msys_run_program(char* filename,char* parameters);
|
||||
extern void stdcall _msys_debug_out(int c);
|
||||
extern void debug_out_str(char* str);
|
||||
extern void stdcall _msys_set_background_size(int xsize,int ysize);
|
||||
extern void stdcall _msys_write_background_mem(int pos,int color);
|
||||
extern void stdcall _msys_draw_background(void);
|
||||
extern void stdcall _msys_set_background_draw_type(int type);
|
||||
extern void stdcall _msys_background_blockmove(void* src,int bgr_pos, int count);
|
||||
extern void stdcall _msys_draw_bar(int x, int y, int xsize, int ysize, int color);
|
||||
extern void stdcall _msys_make_button(int x, int y, int xsize, int ysize, int id, int color);
|
||||
extern int stdcall _msys_get_button_id(void);
|
||||
extern int stdcall _msys_get_system_clock(void);
|
||||
extern int stdcall _msys_get_date(void);
|
||||
extern void stdcall _msys_delay(int m);
|
||||
extern void stdcall _msys_dga_get_resolution(int* xres, int* yres, int* bpp, int* bpscan);
|
||||
extern int stdcall _msys_wait_for_event_infinite(void);
|
||||
extern int stdcall _msys_check_for_event(void);
|
||||
extern int stdcall _msys_wait_for_event(int time);
|
||||
extern void stdcall _msys_set_wanted_events(int ev);
|
||||
extern void stdcall _msys_exit(void);
|
||||
extern void stdcall _msys_putimage(int x, int y, int xsize, int ysize, void* image);
|
||||
extern void stdcall _msys_send_message(int pid, void* msg, int size);
|
||||
extern void stdcall _msys_define_receive_area(void* area, int size);
|
||||
extern int stdcall _msys_get_irq_owner(int irq);
|
||||
extern int stdcall _msys_get_data_read_by_irq(int irq, int* size, void* data);
|
||||
extern int stdcall _msys_send_data_to_device(int port, unsigned char val);
|
||||
extern int stdcall _msys_receive_data_from_device(int port,unsigned char* data);
|
||||
extern void stdcall _msys_program_irq(void* intrtable, int irq);
|
||||
extern void stdcall _msys_reserve_irq(int irq);
|
||||
extern void stdcall _msys_free_irq(int irq);
|
||||
extern int stdcall _msys_reserve_port_area(int start,int end);
|
||||
extern int stdcall _msys_free_port_area(int start,int end);
|
||||
extern int stdcall _msys_get_key(void);
|
||||
extern void stdcall _msys_set_keyboard_mode(int mode);
|
||||
extern void stdcall _msys_line(int x1,int y1,int x2,int y2,int color);
|
||||
extern void stdcall _msys_midi_reset(void);
|
||||
extern void stdcall _msys_midi_send(int data);
|
||||
extern int stdcall _msys_get_pci_version(void);
|
||||
extern int stdcall _msys_get_last_pci_bus(void);
|
||||
extern int stdcall _msys_get_pci_access_mechanism(void);
|
||||
extern int stdcall _msys_pci_read_config_byte(int bus,int dev,int fn,int reg);
|
||||
extern int stdcall _msys_pci_read_config_word(int bus,int dev,int fn,int reg);
|
||||
extern int stdcall _msys_pci_read_config_dword(int bus,int dev,int fn,int reg);
|
||||
extern int stdcall _msys_pci_write_config_byte(int bus,int dev,int fn,int reg,int value);
|
||||
extern int stdcall _msys_pci_write_config_word(int bus,int dev,int fn,int reg,int value);
|
||||
extern int stdcall _msys_pci_write_config_value(int bus,int dev,int fn,int reg,int value);
|
||||
extern int stdcall _msys_putpixel(int x,int y,int color);
|
||||
typedef struct {
|
||||
int cpu_usage;
|
||||
int window_pos_info;
|
||||
char name[12];
|
||||
int memstart;
|
||||
int memused;
|
||||
int pid;
|
||||
int winx_start;
|
||||
int winy_start;
|
||||
int winx_size;
|
||||
int winy_size;
|
||||
int slot_info;
|
||||
} process_table_entry;
|
||||
extern int stdcall _msys_get_process_table(process_table_entry* proctab,int pid);
|
||||
extern int stdcall _msys_get_screen_size(int* x,int* y);
|
||||
extern void stdcall _msys_sound_load_block(void* blockptr);
|
||||
extern void stdcall _msys_sound_play_block(void);
|
||||
extern void stdcall _msys_sound_set_channels(int channels);
|
||||
extern void stdcall _msys_sound_set_data_size(int size);
|
||||
extern void stdcall _msys_sound_set_frequency(int frequency);
|
||||
extern void stdcall _msys_sound_speaker_play(void* data);
|
||||
extern void stdcall _msys_write_text(int x,int y,int color,char* text,int len);
|
||||
extern void* stdcall _msys_start_thread(void (* func_ptr)(void),int stack_size,int* pid);
|
||||
extern void stdcall _msys_window_redraw(int status);
|
||||
extern void* stdcall malloc(int);
|
||||
extern void stdcall free(void*);
|
||||
extern void* stdcall realloc(void*,int);
|
||||
#endif
|
38
programs/develop/metcc/trunk/libc/include/stdio.h
Normal file
38
programs/develop/metcc/trunk/libc/include/stdio.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef stdio_h
|
||||
#define stdio_h
|
||||
#include "mesys.h"
|
||||
typedef struct {
|
||||
char* buffer;
|
||||
int buffersize;
|
||||
int filesize;
|
||||
int filepos;
|
||||
char* filename;
|
||||
int mode;
|
||||
} FILE;
|
||||
#define FILE_OPEN_READ 0
|
||||
#define FILE_OPEN_WRITE 1
|
||||
#define FILE_OPEN_APPEND 2
|
||||
#define FILE_OPEN_TEXT 4
|
||||
#define FILE_OPEN_PLUS 8
|
||||
#define EOF -1
|
||||
extern FILE* fopen(const char* filename, const char *mode);
|
||||
extern int fclose(FILE* file);
|
||||
extern int feof(FILE* file);
|
||||
extern int fflush(FILE* file);
|
||||
extern int fgetc(FILE* file);
|
||||
typedef int fpos_t;
|
||||
extern int fgetpos(FILE* file,fpos_t* pos);
|
||||
extern int fsetpos(FILE* file,const fpos_t* pos);
|
||||
extern int fputc(int c,FILE* file);
|
||||
extern int fread(void* buffer,int size,int count,FILE* file);
|
||||
extern int fwrite(const void* buffer,int size,int count,FILE* file);
|
||||
extern long ftell(FILE* file);
|
||||
#define SEEK_CUR 0
|
||||
#define SEEK_END 1
|
||||
#define SEEK_SET 2
|
||||
extern int fseek(FILE* file,long offset,int origin);
|
||||
extern void rewind(FILE* file);
|
||||
extern int fprintf(FILE* file, const char* format, ...);
|
||||
extern int fscanf(FILE* file,const char* format, ...);
|
||||
extern int ungetc(int c,FILE* file);
|
||||
#endif
|
25
programs/develop/metcc/trunk/libc/include/string.h
Normal file
25
programs/develop/metcc/trunk/libc/include/string.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef string_h
|
||||
#define string_h
|
||||
extern void* memchr(const void*,int,int);
|
||||
extern int memcmp(const void*,const void*,int);
|
||||
extern void* memcpy(void*,const void*,int);
|
||||
extern void* memmove(void*,const void*,int);
|
||||
extern void* memset(void*,int,int);
|
||||
extern char* strcat(char*,const char*);
|
||||
extern char* strchr(const char*,int);
|
||||
extern int strcmp(const char*,const char*);
|
||||
extern int strcoll(const char*,const char*);
|
||||
extern char* strcpy(char*,const char*);
|
||||
extern int strcspn(const char*,const char*);
|
||||
extern int strlen(const char*);
|
||||
extern char* strncat(char*,const char*,int);
|
||||
extern int strncmp(const char*,const char*,int);
|
||||
extern char* strncpy(char*,const char*,int);
|
||||
extern char* strpbrk(const char*,const char*);
|
||||
extern char* strrchr(const char*,int);
|
||||
extern int strspn(const char*,const char*);
|
||||
extern char* strstr(const char*,const char*);
|
||||
extern char* strtok(char*,const char*);
|
||||
extern int strxfrm(char*,const char*,int);
|
||||
extern char* strdup(const char*);
|
||||
#endif
|
536
programs/develop/metcc/trunk/libc/mem/memalloc.asm
Normal file
536
programs/develop/metcc/trunk/libc/mem/memalloc.asm
Normal file
@@ -0,0 +1,536 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public malloc
|
||||
public free
|
||||
public realloc
|
||||
public mf_init
|
||||
;multithread: ;uncomment this for thread-safe version
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Memory allocator for MenuetOS ;;
|
||||
;; Halyavin Andrey halyavin@land.ru, 2006 ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; allocated mem block structure ;;
|
||||
;; +0: bit 0 - used flag ;;
|
||||
;; bits 31..1 - block size ;;
|
||||
;; +4: address of prev block ;;
|
||||
;; +8 .. +(blocksize) - allocated memory ;;
|
||||
;; +(blocksize) - next block ;;
|
||||
;; ;;
|
||||
;; free mem block structure ;;
|
||||
;; +0: bit 0 - used flag ;;
|
||||
;; bits 31..1 - block size ;;
|
||||
;; +4: address of prev block ;;
|
||||
;; +8: prev free block ;;
|
||||
;; +12: next free block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
memblock.size=0
|
||||
memblock.prevblock=4
|
||||
memblock.prevfreeblock=8
|
||||
memblock.nextfreeblock=12
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; mf_init ;;
|
||||
;; Initialize memory map for dynamic use ;;
|
||||
;; input: eax: starting address or 0 ;;
|
||||
;; output: none ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mf_init:
|
||||
push ebx
|
||||
push ecx
|
||||
test eax,eax
|
||||
jnz .noautodet
|
||||
sub esp,1024
|
||||
mov ebx,esp
|
||||
mov ecx,-1
|
||||
mov eax,9
|
||||
int 0x40
|
||||
mov eax,[esp+26]
|
||||
add esp,1024
|
||||
.noautodet:
|
||||
add eax,15
|
||||
and eax,not 15
|
||||
mov [heapsmallblocks],eax
|
||||
add eax,2048
|
||||
mov [heapstart],eax
|
||||
mov [heapfreelist],eax
|
||||
mov [heaplastblock],eax
|
||||
|
||||
mov ecx,eax
|
||||
if defined heapstartsize
|
||||
add ecx,heapstartsize
|
||||
else
|
||||
add ecx,4096
|
||||
end if
|
||||
add ecx,4095
|
||||
and ecx,not 4095
|
||||
push eax
|
||||
mov eax,64
|
||||
mov ebx,1
|
||||
int 0x40
|
||||
pop eax
|
||||
mov [eax+memblock.prevblock],dword 0
|
||||
mov [heapend],ecx
|
||||
mov [eax+memblock.size],ecx
|
||||
sub [eax+memblock.size],eax
|
||||
xor ebx,ebx
|
||||
mov dword [eax+memblock.prevfreeblock],heapfreelist-memblock.nextfreeblock
|
||||
mov [eax+memblock.nextfreeblock],ebx
|
||||
mov [heapmutex],ebx
|
||||
push edi
|
||||
mov edi,[heapsmallblocks]
|
||||
mov ecx,512
|
||||
xor eax,eax
|
||||
rep stosd
|
||||
pop edi
|
||||
pop ecx
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
if defined multithread
|
||||
heaplock:
|
||||
push eax
|
||||
push ebx
|
||||
push ecx
|
||||
mov eax,68
|
||||
mov ebx,1
|
||||
.loop:
|
||||
xchg ecx,[heapmutex]
|
||||
test ecx,ecx
|
||||
jz .endloop
|
||||
int 0x40 ;change task
|
||||
jmp .loop
|
||||
.endloop:
|
||||
pop ecx
|
||||
pop ebx
|
||||
pop eax
|
||||
ret
|
||||
|
||||
heapunlock:
|
||||
mov [heapmutex],dword 0
|
||||
ret
|
||||
end if
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_split_block ;;
|
||||
;; Split free block to allocated block and free one. ;;
|
||||
;; input: ;;
|
||||
;; eax - size of allocated block ;;
|
||||
;; ebx - block ;;
|
||||
;; output: ;;
|
||||
;; eax - real size of allocated block ;;
|
||||
;; ebx - pointer to new block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_split_block:
|
||||
push ecx
|
||||
mov ecx,[ebx+memblock.size]
|
||||
sub ecx,16
|
||||
cmp ecx,eax
|
||||
jge .norm
|
||||
inc dword [ebx+memblock.size]
|
||||
mov eax,ecx
|
||||
xor ebx,ebx
|
||||
pop ecx
|
||||
ret
|
||||
.norm:
|
||||
add ecx,16
|
||||
mov [ebx+memblock.size],eax
|
||||
inc dword [ebx+memblock.size]
|
||||
mov [ebx+eax+memblock.prevblock],ebx
|
||||
add ebx,eax
|
||||
sub ecx,eax
|
||||
mov [ebx+memblock.size],ecx
|
||||
mov ecx,eax
|
||||
mov eax,ebx
|
||||
call heap_fix_right
|
||||
mov eax,ecx
|
||||
pop ecx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_add_free_block ;;
|
||||
;; Add free block to one of free block lists. ;;
|
||||
;; input: ;;
|
||||
;; eax - address of free block ;;
|
||||
;; output: ;;
|
||||
;; none ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_add_free_block:
|
||||
cmp dword [eax+memblock.size],4096
|
||||
push ebx
|
||||
jge .bigblock
|
||||
mov ebx,[eax+memblock.size]
|
||||
shr ebx,1
|
||||
add ebx,[heapsmallblocks]
|
||||
push dword [ebx]
|
||||
pop dword [eax+memblock.nextfreeblock]
|
||||
mov [ebx],eax
|
||||
mov dword [eax+memblock.prevfreeblock],ebx
|
||||
sub dword [eax+memblock.prevfreeblock],memblock.nextfreeblock
|
||||
mov ebx,[eax+memblock.nextfreeblock]
|
||||
test ebx,ebx
|
||||
jz .no_next_block
|
||||
mov [ebx+memblock.prevfreeblock],eax
|
||||
.no_next_block:
|
||||
pop ebx
|
||||
ret
|
||||
.bigblock:
|
||||
mov ebx,[heapfreelist]
|
||||
mov [eax+memblock.nextfreeblock],ebx
|
||||
mov [heapfreelist],eax
|
||||
mov dword [eax+memblock.prevfreeblock],heapfreelist-memblock.nextfreeblock
|
||||
; mov ebx,[eax+memblock.nextfreeblock]
|
||||
test ebx,ebx
|
||||
jz .no_next_big_block
|
||||
mov [ebx+memblock.prevfreeblock],eax
|
||||
.no_next_big_block:
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_remove_block ;;
|
||||
;; Remove free block from the list of free blocks. ;;
|
||||
;; input: ;;
|
||||
;; eax - free block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_remove_block:
|
||||
push ebx
|
||||
push ecx
|
||||
mov ecx,[eax+memblock.prevfreeblock]
|
||||
mov ebx,[eax+memblock.nextfreeblock]
|
||||
mov [ecx+memblock.nextfreeblock],ebx
|
||||
test ebx,ebx
|
||||
jz .no_next_block
|
||||
mov [ebx+memblock.prevfreeblock],ecx
|
||||
.no_next_block:
|
||||
pop ecx
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; mf_alloc
|
||||
;; allocates a block of memory in heap
|
||||
;; intput: eax: size of block
|
||||
;; output: eax: address of allocated memory block or 0 if there's no mem.
|
||||
;; allocator will not create new nodes that contain less that 8b of space,
|
||||
;; and minimal allocation is actually 16 bytes - 8 for node and 8 for user.
|
||||
;; allocator will never create non-aligned memory blocks.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mf_alloc:
|
||||
test eax,eax
|
||||
jg .not_null ; test that we are not allocating null size block
|
||||
xor eax,eax
|
||||
ret
|
||||
.not_null:
|
||||
if defined multithread
|
||||
call heaplock
|
||||
end if
|
||||
push edi
|
||||
; push edx
|
||||
push ecx
|
||||
push ebx
|
||||
add eax,7
|
||||
and eax,not 7 ; make sure that block size is aligned
|
||||
|
||||
lea edi,[eax+8] ; desired block size
|
||||
cmp edi,4096
|
||||
jge .general_cycle
|
||||
|
||||
mov ebx,[heapsmallblocks]
|
||||
xor ecx,ecx
|
||||
shr edi,1
|
||||
|
||||
.smallloop:
|
||||
cmp [ebx+edi],ecx
|
||||
jnz .smallblockfound
|
||||
add edi,4
|
||||
cmp edi,2048
|
||||
jl .smallloop
|
||||
lea edi,[eax+8]
|
||||
jmp .general_cycle
|
||||
|
||||
.smallblockfound:
|
||||
lea ecx,[eax+8]
|
||||
mov eax,[ebx+edi]
|
||||
call heap_remove_block
|
||||
mov ebx,eax
|
||||
xchg eax,ecx
|
||||
call heap_split_block
|
||||
test ebx,ebx
|
||||
jz .perfect_small_block
|
||||
mov eax,ebx
|
||||
call heap_add_free_block
|
||||
.perfect_small_block:
|
||||
lea eax,[ecx+8]
|
||||
jmp .ret
|
||||
|
||||
.general_cycle:
|
||||
;edi - size needed
|
||||
mov eax,[heapfreelist]
|
||||
|
||||
.loop:
|
||||
test eax,eax
|
||||
jz .new_mem
|
||||
cmp [eax+memblock.size],edi
|
||||
jge .blockfound
|
||||
mov eax,[eax+memblock.nextfreeblock]
|
||||
jmp .loop
|
||||
|
||||
.blockfound:
|
||||
call heap_remove_block
|
||||
mov ebx,eax
|
||||
mov ecx,eax
|
||||
mov eax,edi
|
||||
call heap_split_block
|
||||
test ebx,ebx
|
||||
jz .perfect_block
|
||||
mov eax,ebx
|
||||
call heap_add_free_block
|
||||
.perfect_block:
|
||||
lea eax,[ecx+8]
|
||||
.ret:
|
||||
if defined multithread
|
||||
call heapunlock
|
||||
end if
|
||||
pop ebx
|
||||
pop ecx
|
||||
; pop edx
|
||||
pop edi
|
||||
ret
|
||||
|
||||
.new_mem:
|
||||
mov eax,edi
|
||||
add eax,4095
|
||||
and eax,not 4095
|
||||
mov ecx,[heapend]
|
||||
add [heapend],eax
|
||||
push eax
|
||||
mov eax,64
|
||||
push ebx
|
||||
push ecx
|
||||
mov ecx,[heapend]
|
||||
mov ebx,1
|
||||
int 0x40
|
||||
pop ecx
|
||||
pop ebx
|
||||
pop eax
|
||||
mov [ecx+memblock.size],eax
|
||||
mov eax,[heaplastblock]
|
||||
mov [ecx+memblock.prevblock],eax
|
||||
mov [heaplastblock],ecx
|
||||
mov eax,ecx
|
||||
call heap_add_free_block
|
||||
jmp .general_cycle
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_fix_right ;;
|
||||
;; input: ;;
|
||||
;; eax - pointer to free block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_fix_right:
|
||||
push ebx
|
||||
mov ebx,eax
|
||||
add ebx,[eax+memblock.size]
|
||||
cmp ebx,[heapend]
|
||||
jz .endblock
|
||||
mov [ebx+memblock.prevblock],eax
|
||||
pop ebx
|
||||
ret
|
||||
.endblock:
|
||||
mov [heaplastblock],eax
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_merge_left ;;
|
||||
;; input: ;;
|
||||
;; eax - pointer to free block ;;
|
||||
;; output: ;;
|
||||
;; eax - pointer to merged block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_merge_left:
|
||||
push ebx
|
||||
mov ebx,[eax+memblock.prevblock]
|
||||
test ebx,ebx
|
||||
jz .ret
|
||||
test byte [ebx+memblock.size],1
|
||||
jnz .ret
|
||||
xchg eax,ebx
|
||||
call heap_remove_block
|
||||
mov ebx,[ebx+memblock.size]
|
||||
add [eax+memblock.size],ebx
|
||||
call heap_fix_right
|
||||
.ret:
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_merge_right ;;
|
||||
;; input: ;;
|
||||
;; eax - pointer to free block ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_merge_right:
|
||||
push ebx
|
||||
mov ebx,eax
|
||||
add ebx,[eax+memblock.size]
|
||||
cmp ebx,[heapend]
|
||||
jz .ret
|
||||
test byte [ebx+memblock.size],1
|
||||
jnz .ret
|
||||
xchg eax,ebx
|
||||
call heap_remove_block
|
||||
xchg eax,ebx
|
||||
mov ebx,[ebx+memblock.size]
|
||||
add [eax+memblock.size],ebx
|
||||
call heap_fix_right
|
||||
.ret:
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; mf_free ;;
|
||||
;; input: ;;
|
||||
;; eax - pointer ;;
|
||||
;; output: ;;
|
||||
;; eax=1 - ok ;;
|
||||
;; eax=0 - failed ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mf_free:
|
||||
test eax,eax
|
||||
jnz .no_null
|
||||
inc eax
|
||||
ret
|
||||
.no_null:
|
||||
if defined multithread
|
||||
call heaplock
|
||||
end if
|
||||
sub eax,8
|
||||
dec dword [eax+memblock.size]
|
||||
call heap_merge_left
|
||||
call heap_merge_right
|
||||
call heap_add_free_block
|
||||
.ret:
|
||||
if defined multithread
|
||||
call heapunlock
|
||||
end if
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; heap_try_reloc
|
||||
;; input:
|
||||
;; eax - address
|
||||
;; ebx - new size
|
||||
;; output:
|
||||
;; ebx=1 - ok
|
||||
;; ebx=0 - failed
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
heap_try_reloc:
|
||||
push eax
|
||||
sub eax,8
|
||||
add ebx,15
|
||||
dec dword [eax+memblock.size]
|
||||
and ebx,not 7
|
||||
cmp [eax+memblock.size],ebx
|
||||
jge .truncate
|
||||
push ebx
|
||||
mov ebx,eax
|
||||
add ebx,[eax+memblock.size]
|
||||
cmp ebx,[heapend]
|
||||
jz .fail ;todo: we can allocate new mem here
|
||||
test [ebx+memblock.size],byte 1
|
||||
jnz .fail
|
||||
xchg eax,ebx
|
||||
call heap_remove_block
|
||||
mov eax,[eax+memblock.size]
|
||||
add [ebx+memblock.size],eax
|
||||
mov eax,ebx
|
||||
call heap_fix_right
|
||||
pop ebx
|
||||
.truncate:
|
||||
xchg eax,ebx
|
||||
call heap_split_block
|
||||
test ebx,ebx
|
||||
jz .no_last_block
|
||||
mov eax,ebx
|
||||
call heap_add_free_block
|
||||
call heap_merge_right
|
||||
.no_last_block:
|
||||
xor ebx,ebx
|
||||
pop eax
|
||||
inc ebx
|
||||
ret
|
||||
.fail:
|
||||
pop ebx
|
||||
xor ebx,ebx
|
||||
pop eax
|
||||
inc dword [eax-8+memblock.size]
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; mf_realloc
|
||||
;; input:
|
||||
;; eax - pointer
|
||||
;; ebx - new size
|
||||
;; output:
|
||||
;; eax - new pointer
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mf_realloc:
|
||||
push ebx
|
||||
if defined multithread
|
||||
call heaplock
|
||||
end if
|
||||
call heap_try_reloc
|
||||
test ebx,ebx
|
||||
jnz .ret
|
||||
;allocate new memory
|
||||
push eax
|
||||
mov eax,[esp+4]
|
||||
call mf_alloc
|
||||
test eax,eax
|
||||
jz .fail
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
mov edi,eax
|
||||
mov esi,[esp+12]
|
||||
mov ecx,[esi-8+memblock.size]
|
||||
shr ecx,2
|
||||
rep movsd
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
xchg eax,[esp]
|
||||
call mf_free
|
||||
.fail:
|
||||
pop eax
|
||||
.ret:
|
||||
if defined multithread
|
||||
call heapunlock
|
||||
end if
|
||||
pop ebx
|
||||
ret
|
||||
;C entries
|
||||
malloc:
|
||||
mov eax,[esp+4]
|
||||
call mf_alloc
|
||||
ret
|
||||
free:
|
||||
mov eax,[esp+4]
|
||||
call mf_free
|
||||
ret
|
||||
realloc:
|
||||
mov edx,ebx
|
||||
mov eax,[esp+4]
|
||||
mov ebx,[esp+8]
|
||||
call mf_realloc
|
||||
mov ebx,edx
|
||||
ret
|
||||
section '.bss' writeable
|
||||
heapsmallblocks rd 1
|
||||
heapstart rd 1
|
||||
heapend rd 1
|
||||
heapfreelist rd 1
|
||||
heapmutex rd 1
|
||||
heaplastblock rd 1
|
58
programs/develop/metcc/trunk/libc/mesys/backgr.asm
Normal file
58
programs/develop/metcc/trunk/libc/mesys/backgr.asm
Normal file
@@ -0,0 +1,58 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_set_background_size
|
||||
_msys_set_background_size:
|
||||
;arg1 - xsize
|
||||
;arg2 - ysize
|
||||
push ebx
|
||||
mov ecx,[esp+8]
|
||||
mov edx,[esp+12]
|
||||
mov eax,15
|
||||
mov ebx,1
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 8
|
||||
public _msys_write_background_mem
|
||||
_msys_write_background_mem:
|
||||
;arg1 - pos
|
||||
;arg2 - color
|
||||
push ebx
|
||||
mov eax,15
|
||||
mov ebx,2
|
||||
mov ecx,[esp+8]
|
||||
mov edx,[esp+12]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 8
|
||||
public _msys_draw_background
|
||||
_msys_draw_background:
|
||||
mov edx,ebx
|
||||
mov eax,15
|
||||
mov ebx,3
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret
|
||||
public _msys_set_background_draw_type
|
||||
_msys_set_background_draw_type:
|
||||
;arg1 - type
|
||||
mov edx,ebx
|
||||
mov eax,15
|
||||
mov ebx,4
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
public _msys_background_blockmove
|
||||
_msys_background_blockmove:
|
||||
;arg1 - source
|
||||
;arg2 - position in dest
|
||||
;arg3 - size
|
||||
push ebx esi
|
||||
mov eax,15
|
||||
mov ebx,5
|
||||
mov ecx,[esp+12]
|
||||
mov edx,[esp+16]
|
||||
mov esi,[esp+20]
|
||||
int 0x40
|
||||
pop esi ebx
|
||||
ret 12
|
36
programs/develop/metcc/trunk/libc/mesys/button.asm
Normal file
36
programs/develop/metcc/trunk/libc/mesys/button.asm
Normal file
@@ -0,0 +1,36 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_make_button
|
||||
_msys_make_button:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
;arg3 - xsize
|
||||
;arg4 - ysize
|
||||
;arg5 - id
|
||||
;arg6 - color
|
||||
push ebx esi
|
||||
mov ebx,[esp+12]
|
||||
shl ebx,16
|
||||
mov bx,[esp+20]
|
||||
mov ecx,[esp+16]
|
||||
shl ecx,16
|
||||
mov cx,[esp+24]
|
||||
mov edx,[esp+28]
|
||||
mov esi,[esp+32]
|
||||
mov eax,8
|
||||
int 0x40
|
||||
pop esi ebx
|
||||
ret 24
|
||||
|
||||
public _msys_get_button_id
|
||||
_msys_get_button_id:
|
||||
mov eax,17
|
||||
int 0x40
|
||||
test al,al
|
||||
jnz .no_button
|
||||
shr eax,8
|
||||
ret
|
||||
.no_button:
|
||||
xor eax,eax
|
||||
dec eax
|
||||
ret
|
7
programs/develop/metcc/trunk/libc/mesys/clock.asm
Normal file
7
programs/develop/metcc/trunk/libc/mesys/clock.asm
Normal file
@@ -0,0 +1,7 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_system_clock
|
||||
_msys_get_system_clock:
|
||||
mov eax,3
|
||||
int 0x40
|
||||
ret
|
7
programs/develop/metcc/trunk/libc/mesys/date.asm
Normal file
7
programs/develop/metcc/trunk/libc/mesys/date.asm
Normal file
@@ -0,0 +1,7 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_date
|
||||
_msys_get_date:
|
||||
mov eax,29
|
||||
int 0x40
|
||||
ret
|
13
programs/develop/metcc/trunk/libc/mesys/debug_board.asm
Normal file
13
programs/develop/metcc/trunk/libc/mesys/debug_board.asm
Normal file
@@ -0,0 +1,13 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
|
||||
public _msys_debug_out
|
||||
_msys_debug_out:
|
||||
;arg1 - char to out
|
||||
push ebx
|
||||
mov ecx,[esp+8]
|
||||
mov ebx,1
|
||||
mov eax,63
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 4
|
9
programs/develop/metcc/trunk/libc/mesys/debug_board_.c
Normal file
9
programs/develop/metcc/trunk/libc/mesys/debug_board_.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "mesys.h"
|
||||
void debug_out_str(char* str)
|
||||
{
|
||||
while (*str!='\0')
|
||||
{
|
||||
_msys_debug_out(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
11
programs/develop/metcc/trunk/libc/mesys/delay.asm
Normal file
11
programs/develop/metcc/trunk/libc/mesys/delay.asm
Normal file
@@ -0,0 +1,11 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_delay
|
||||
_msys_delay:
|
||||
;arg1 - time
|
||||
mov edx,ebx
|
||||
mov eax,5
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
34
programs/develop/metcc/trunk/libc/mesys/dga.asm
Normal file
34
programs/develop/metcc/trunk/libc/mesys/dga.asm
Normal file
@@ -0,0 +1,34 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_dga_get_resolution
|
||||
_msys_dga_get_resolution:
|
||||
;arg1 - *xres
|
||||
;arg2 - *yres
|
||||
;arg3 - *bpp
|
||||
;arg4 - *bpscan
|
||||
mov edx,ebx
|
||||
|
||||
mov eax,61
|
||||
mov ebx,1
|
||||
int 0x40
|
||||
mov ebx,[esp+8]
|
||||
mov [ebx],ax
|
||||
mov word [ebx+2],0
|
||||
shr eax,16
|
||||
mov ebx,[esp+4]
|
||||
mov [ebx],eax
|
||||
|
||||
mov eax,61
|
||||
mov ebx,2
|
||||
int 0x40
|
||||
mov ebx,[esp+12]
|
||||
mov [ebx],eax
|
||||
|
||||
mov eax,61
|
||||
mov ebx,3
|
||||
int 0x40
|
||||
mov ebx,[esp+16]
|
||||
mov [ebx],eax
|
||||
|
||||
mov ebx,edx
|
||||
ret 16
|
21
programs/develop/metcc/trunk/libc/mesys/draw_bar.asm
Normal file
21
programs/develop/metcc/trunk/libc/mesys/draw_bar.asm
Normal file
@@ -0,0 +1,21 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_draw_bar
|
||||
_msys_draw_bar:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
;arg3 - xsize
|
||||
;arg4 - ysize
|
||||
;arg5 - color
|
||||
push ebx
|
||||
mov eax,13
|
||||
mov ebx,[esp+8]
|
||||
shl ebx,16
|
||||
mov bx,[esp+16]
|
||||
mov ecx,[esp+12]
|
||||
shl ecx,16
|
||||
mov cx,[esp+20]
|
||||
mov edx,[esp+24]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
21
programs/develop/metcc/trunk/libc/mesys/draw_image.asm
Normal file
21
programs/develop/metcc/trunk/libc/mesys/draw_image.asm
Normal file
@@ -0,0 +1,21 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_putimage
|
||||
_msys_putimage:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
;arg3 - xsize
|
||||
;arg4 - ysize
|
||||
;arg5 - image
|
||||
push ebx
|
||||
mov ebx,[esp+24]
|
||||
mov ecx,[esp+16]
|
||||
shl ecx,16
|
||||
mov ecx,[esp+20]
|
||||
mov ebx,[esp+8]
|
||||
shl ebx,16
|
||||
mov ebx,[esp+12]
|
||||
mov eax,7
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
35
programs/develop/metcc/trunk/libc/mesys/draw_window.asm
Normal file
35
programs/develop/metcc/trunk/libc/mesys/draw_window.asm
Normal file
@@ -0,0 +1,35 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
|
||||
public _msys_draw_window
|
||||
_msys_draw_window:
|
||||
;arg1 - xcoord
|
||||
;arg2 - ycoord
|
||||
;arg3 - xsize
|
||||
;arg4 - ysize
|
||||
;arg5 - workcolor
|
||||
;arg6 - type
|
||||
;arg7 - captioncolor
|
||||
;arg8 - windowtype
|
||||
;arg9 - bordercolor
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push ebx esi edi
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov bx,[ebp+16]
|
||||
mov ecx,[ebp+12]
|
||||
shl ecx,16
|
||||
mov cx,[ebp+20]
|
||||
mov edx,[ebp+28]
|
||||
shl edx,24
|
||||
add edx,[ebp+24]
|
||||
mov esi,[ebp+36]
|
||||
shl esi,24
|
||||
add esi,[ebp+32]
|
||||
mov edi,[ebp+40]
|
||||
xor eax,eax
|
||||
int 0x40
|
||||
pop edi esi ebx
|
||||
pop ebp
|
||||
ret 36
|
33
programs/develop/metcc/trunk/libc/mesys/event.asm
Normal file
33
programs/develop/metcc/trunk/libc/mesys/event.asm
Normal file
@@ -0,0 +1,33 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_wait_for_event_infinite
|
||||
_msys_wait_for_event_infinite:
|
||||
mov eax,10
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
public _msys_check_for_event
|
||||
_msys_check_for_event:
|
||||
mov eax,11
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
public _msys_wait_for_event
|
||||
_msys_wait_for_event:
|
||||
;arg1 - time
|
||||
mov edx,ebx
|
||||
mov eax,23
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
|
||||
public _msys_set_wanted_events
|
||||
_msys_set_wanted_events:
|
||||
;arg1 - flags
|
||||
mov edx,ebx
|
||||
mov eax,40
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
8
programs/develop/metcc/trunk/libc/mesys/exit.asm
Normal file
8
programs/develop/metcc/trunk/libc/mesys/exit.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_exit
|
||||
_msys_exit:
|
||||
xor eax,eax
|
||||
dec eax
|
||||
int 0x40
|
||||
; ret
|
110
programs/develop/metcc/trunk/libc/mesys/file_58.asm
Normal file
110
programs/develop/metcc/trunk/libc/mesys/file_58.asm
Normal file
@@ -0,0 +1,110 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_read_file
|
||||
_msys_read_file:
|
||||
;arg1 - file name
|
||||
;arg2 - file offset
|
||||
;arg3 - size to read
|
||||
;arg4 - data
|
||||
;arg5 - file size
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
xor eax,eax
|
||||
mov [file_struct.operation],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.offset],eax
|
||||
mov eax,[ebp+16]
|
||||
mov [file_struct.offset],eax
|
||||
mov eax,[ebp+20]
|
||||
mov [file_struct.offset],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov ebx,file_struct
|
||||
mov eax,58
|
||||
int 0x40
|
||||
mov ecx,[ebp+24]
|
||||
test ecx,ecx
|
||||
jz .no_file_size
|
||||
mov [ecx],ebx
|
||||
.no_file_size:
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret 20
|
||||
|
||||
copy_file_name:
|
||||
push esi edi
|
||||
cld
|
||||
mov edi,edx
|
||||
xor eax,eax
|
||||
xor ecx,ecx
|
||||
dec ecx
|
||||
repnz scasb
|
||||
not ecx
|
||||
mov edi,file_struct.path
|
||||
mov esi,edx
|
||||
rep movsb
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
public _msys_write_file
|
||||
_msys_write_file:
|
||||
;arg1 - file name
|
||||
;arg2 - size
|
||||
;arg3 - data
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
xor eax,eax
|
||||
mov [file_struct.offset],eax
|
||||
inc eax
|
||||
mov [file_struct.operation],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.size],eax
|
||||
mov eax,[ebp+16]
|
||||
mov [file_struct.data],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov eax,58
|
||||
mov ebx,file_struct
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret 12
|
||||
|
||||
public _msys_run_program
|
||||
_msys_run_program:
|
||||
;arg1 - program name
|
||||
;arg2 - parameters
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov [file_struct.operation],16
|
||||
xor eax,eax
|
||||
mov [file_struct.offset],eax
|
||||
mov [file_struct.data],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.param],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer;
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov eax,58
|
||||
mov ebx,file_struct
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret 8
|
||||
section '.bss' writeable
|
||||
file_struct:
|
||||
.operation rd 1
|
||||
.offset rd 1
|
||||
.param:
|
||||
.size rd 1
|
||||
.data rd 1
|
||||
.temp_buffer rd 1
|
||||
.path rb 1024
|
||||
temp_buffer rb 4096
|
||||
|
||||
|
29
programs/develop/metcc/trunk/libc/mesys/ipc.asm
Normal file
29
programs/develop/metcc/trunk/libc/mesys/ipc.asm
Normal file
@@ -0,0 +1,29 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_send_message
|
||||
_msys_send_message:
|
||||
;arg1 - pid
|
||||
;arg2 - msg
|
||||
;arg3 - size
|
||||
push ebx esi
|
||||
mov eax,60
|
||||
mov ebx,2
|
||||
mov ecx,[esp+12]
|
||||
mov edx,[esp+16]
|
||||
mov esi,[esp+20]
|
||||
int 0x40
|
||||
pop esi ebx
|
||||
ret 12
|
||||
|
||||
public _msys_define_receive_area
|
||||
_msys_define_receive_area:
|
||||
;arg1 - area
|
||||
;arg2 - size
|
||||
push ebx
|
||||
mov eax,60
|
||||
mov ebx,1
|
||||
mov ecx,[esp+8]
|
||||
mov edx,[esp+12]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 8
|
127
programs/develop/metcc/trunk/libc/mesys/irq.asm
Normal file
127
programs/develop/metcc/trunk/libc/mesys/irq.asm
Normal file
@@ -0,0 +1,127 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_irq_owner
|
||||
_msys_get_irq_owner:
|
||||
;arg1 - irq
|
||||
mov edx,ebx
|
||||
mov eax,41
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
|
||||
public _msys_get_data_read_by_irq
|
||||
_msys_get_data_read_by_irq:
|
||||
;arg1 - irq
|
||||
;arg2 - *size
|
||||
;arg3 - data
|
||||
mov edx,ebx
|
||||
mov eax,42
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
cmp ecx,2
|
||||
jz .not_an_owner
|
||||
push ecx
|
||||
mov ecx,[esp+16]
|
||||
test ecx,ecx
|
||||
jz .ignore_data
|
||||
mov [ecx],bl
|
||||
.ignore_data:
|
||||
mov ecx,[esp+12]
|
||||
mov [ecx],eax
|
||||
pop eax
|
||||
mov ebx,edx
|
||||
ret 12
|
||||
.not_an_owner:
|
||||
mov eax,2
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_send_data_to_device
|
||||
_msys_send_data_to_device:
|
||||
;arg1 - port
|
||||
;arg2 - data
|
||||
mov edx,ebx
|
||||
mov eax,63
|
||||
mov ebx,[esp+8]
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 8
|
||||
|
||||
public _msys_receive_data_from_device
|
||||
_msys_receive_data_from_device:
|
||||
;arg1 - port
|
||||
;arg2 - data
|
||||
mov edx,ebx
|
||||
mov eax,43
|
||||
mov ecx,[esp+4]
|
||||
add ecx,0x80000000
|
||||
int 0x40
|
||||
mov ecx,[esp+8]
|
||||
mov [ecx],bl
|
||||
mov ebx,edx
|
||||
ret 8
|
||||
|
||||
public _msys_program_irq
|
||||
_msys_program_irq:
|
||||
;arg1 - intrtable
|
||||
;arg2 - irq
|
||||
mov edx,ebx
|
||||
mov eax,44
|
||||
mov ebx,[esp+4]
|
||||
mov ecx,[esp+8]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 8
|
||||
|
||||
public _msys_reserve_irq
|
||||
_msys_reserve_irq:
|
||||
;arg1 - irq
|
||||
mov edx,ebx
|
||||
mov eax,45
|
||||
xor ebx,ebx
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
|
||||
public _msys_free_irq
|
||||
_msys_free_irq:
|
||||
;arg1 - irq
|
||||
mov edx,ebx
|
||||
mov eax,45
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
|
||||
public _msys_reserve_port_area
|
||||
_msys_reserve_port_area:
|
||||
;arg1 - start
|
||||
;arg2 - end
|
||||
push ebx
|
||||
mov eax,46
|
||||
xor ebx,ebx
|
||||
mov ecx,[esp+8]
|
||||
mov edx,[esp+12]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 8
|
||||
|
||||
public _msys_free_port_area
|
||||
_msys_free_port_area:
|
||||
;arg1 - start
|
||||
;arg2 - end
|
||||
push ebx
|
||||
mov eax,46
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
mov ecx,[esp+8]
|
||||
mov edx,[esp+12]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 8
|
||||
|
18
programs/develop/metcc/trunk/libc/mesys/keyboard.asm
Normal file
18
programs/develop/metcc/trunk/libc/mesys/keyboard.asm
Normal file
@@ -0,0 +1,18 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_key
|
||||
_msys_get_key:
|
||||
mov eax,2
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
public _msys_set_keyboard_mode
|
||||
_msys_set_keyboard_mode:
|
||||
;arg1 - mode
|
||||
mov edx,ebx
|
||||
mov eax,66
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
mov ecx,[esp+4]
|
||||
mov ebx,edx
|
||||
ret 4
|
21
programs/develop/metcc/trunk/libc/mesys/line.asm
Normal file
21
programs/develop/metcc/trunk/libc/mesys/line.asm
Normal file
@@ -0,0 +1,21 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_line
|
||||
_msys_line:
|
||||
;arg1 - x1
|
||||
;arg2 - y1
|
||||
;arg3 - x2
|
||||
;arg4 - y2
|
||||
;arg5 - color
|
||||
push ebx
|
||||
mov ebx,[esp+8]
|
||||
shl ebx,16
|
||||
mov bx,[esp+16]
|
||||
mov ecx,[esp+12]
|
||||
shl ecx,16
|
||||
mov cx,[esp+20]
|
||||
mov edx,[esp+24]
|
||||
mov eax,38
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
22
programs/develop/metcc/trunk/libc/mesys/midi.asm
Normal file
22
programs/develop/metcc/trunk/libc/mesys/midi.asm
Normal file
@@ -0,0 +1,22 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_midi_reset
|
||||
_msys_midi_reset:
|
||||
mov edx,ebx
|
||||
mov eax,20
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_midi_send
|
||||
_msys_midi_send:
|
||||
;arg1 - data
|
||||
mov edx,ebx
|
||||
mov eax,20
|
||||
mov ebx,2
|
||||
xor ecx,ecx
|
||||
mov cl,[esp+4]
|
||||
mov ebx,edx
|
||||
ret 4
|
146
programs/develop/metcc/trunk/libc/mesys/pci.asm
Normal file
146
programs/develop/metcc/trunk/libc/mesys/pci.asm
Normal file
@@ -0,0 +1,146 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_pci_version
|
||||
_msys_get_pci_version:
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
xor ebx,ebx
|
||||
int 0x40
|
||||
movzx eax,ax
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_get_last_pci_bus
|
||||
_msys_get_last_pci_bus:
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
int 0x40
|
||||
movzx eax,al
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_get_pci_access_mechanism
|
||||
_msys_get_pci_access_mechanism:
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
mov ebx,2
|
||||
int 0x40
|
||||
movzx eax,al
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_pci_read_config_byte
|
||||
_msys_pci_read_config_byte:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
mov bl,4
|
||||
mov bh,[esp+4]
|
||||
mov ch,[esp+8]
|
||||
shl ch,3
|
||||
add ch,[esp+12]
|
||||
mov cl,[esp+16]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 16
|
||||
|
||||
public _msys_pci_read_config_word
|
||||
_msys_pci_read_config_word:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
mov bl,5
|
||||
mov bh,[esp+4]
|
||||
mov ch,[esp+8]
|
||||
shl ch,3
|
||||
add ch,[esp+12]
|
||||
mov cl,[esp+16]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 16
|
||||
|
||||
public _msys_pci_read_config_dword
|
||||
_msys_pci_read_config_dword:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
mov edx,ebx
|
||||
mov eax,62
|
||||
mov bl,6
|
||||
mov bh,[esp+4]
|
||||
mov ch,[esp+8]
|
||||
shl ch,3
|
||||
add ch,[esp+12]
|
||||
mov cl,[esp+16]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 16
|
||||
|
||||
public _msys_pci_write_config_byte
|
||||
_msys_pci_write_config_byte:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
;arg5 - value
|
||||
push ebx
|
||||
mov eax,62
|
||||
mov bl,8
|
||||
mov bh,[esp+8]
|
||||
mov ch,[esp+12]
|
||||
shl ch,3
|
||||
mov ch,[esp+16]
|
||||
mov cl,[esp+20]
|
||||
movzx edx,byte [esp+24]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
||||
|
||||
public _msys_pci_write_config_word
|
||||
_msys_pci_write_config_word:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
;arg5 - value
|
||||
push ebx
|
||||
mov eax,62
|
||||
mov bl,9
|
||||
mov bh,[esp+8]
|
||||
mov ch,[esp+12]
|
||||
shl ch,3
|
||||
mov ch,[esp+16]
|
||||
mov cl,[esp+20]
|
||||
movzx edx,word [esp+24]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
||||
|
||||
public _msys_pci_write_config_dword
|
||||
_msys_pci_write_config_dword:
|
||||
;arg1 - bus
|
||||
;arg2 - dev
|
||||
;arg3 - fn
|
||||
;arg4 - reg
|
||||
;arg5 - value
|
||||
push ebx
|
||||
mov eax,62
|
||||
mov bl,10
|
||||
mov bh,[esp+8]
|
||||
mov ch,[esp+12]
|
||||
shl ch,3
|
||||
mov ch,[esp+16]
|
||||
mov cl,[esp+20]
|
||||
mov edx,[esp+24]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 20
|
16
programs/develop/metcc/trunk/libc/mesys/pixel.asm
Normal file
16
programs/develop/metcc/trunk/libc/mesys/pixel.asm
Normal file
@@ -0,0 +1,16 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_putpixel
|
||||
_msys_putpixel:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
;arg3 - color
|
||||
push ebx
|
||||
xor eax,eax
|
||||
mov ebx,[esp+8]
|
||||
inc eax
|
||||
mov ecx,[esp+12]
|
||||
mov edx,[esp+16]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 12
|
13
programs/develop/metcc/trunk/libc/mesys/process.asm
Normal file
13
programs/develop/metcc/trunk/libc/mesys/process.asm
Normal file
@@ -0,0 +1,13 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_process_table
|
||||
_msys_get_process_table:
|
||||
;arg1 - pointer to information
|
||||
;arg2 - pid
|
||||
mov edx,ebx
|
||||
mov eax,9
|
||||
mov ebx,[esp+4]
|
||||
mov ecx,[esp+8]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 8
|
15
programs/develop/metcc/trunk/libc/mesys/screen.asm
Normal file
15
programs/develop/metcc/trunk/libc/mesys/screen.asm
Normal file
@@ -0,0 +1,15 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_get_screen_size
|
||||
_msys_get_screen_size:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
mov eax,14
|
||||
int 0x40
|
||||
mov ecx,[esp+8]
|
||||
mov [ecx],ax
|
||||
mov word [ecx+2],0
|
||||
shr eax,16
|
||||
mov ecx,[esp+4]
|
||||
mov [ecx],eax
|
||||
ret 8
|
70
programs/develop/metcc/trunk/libc/mesys/sound.asm
Normal file
70
programs/develop/metcc/trunk/libc/mesys/sound.asm
Normal file
@@ -0,0 +1,70 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_sound_load_block
|
||||
_msys_sound_load_block:
|
||||
;arg1 - blockptr
|
||||
mov edx,ebx
|
||||
mov eax,55
|
||||
xor ebx,ebx
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
||||
|
||||
public _msys_sound_play_block
|
||||
_msys_sound_play_block:
|
||||
mov edx,ebx
|
||||
mov eax,55
|
||||
xor ebx,ebx
|
||||
inc ebx
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret
|
||||
|
||||
public _msys_sound_set_channels
|
||||
_msys_sound_set_channels:
|
||||
;arg1 - channels
|
||||
push ebx
|
||||
mov eax,55
|
||||
mov ebx,2
|
||||
xor ecx,ecx
|
||||
mov edx,[esp+8]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 4
|
||||
|
||||
public _msys_sound_set_data_size
|
||||
_msys_sound_set_data_size:
|
||||
;arg1 - data size
|
||||
push ebx
|
||||
mov eax,55
|
||||
mov ebx,2
|
||||
xor ecx,ecx
|
||||
inc ecx
|
||||
mov edx,[esp+8]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 4
|
||||
|
||||
public _msys_sound_set_frequency
|
||||
_msys_sound_set_frequency:
|
||||
;arg1 - frequency
|
||||
push ebx
|
||||
mov eax,55
|
||||
mov ebx,2
|
||||
mov ecx,2
|
||||
mov edx,[esp+8]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret 4
|
||||
|
||||
public _msys_sound_speaker_play
|
||||
_msys_sound_speaker_play:
|
||||
;arg1 - data
|
||||
mov edx,ebx
|
||||
mov eax,55
|
||||
mov ebx,55
|
||||
mov ecx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
33
programs/develop/metcc/trunk/libc/mesys/thread.asm
Normal file
33
programs/develop/metcc/trunk/libc/mesys/thread.asm
Normal file
@@ -0,0 +1,33 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
extrn malloc
|
||||
public _msys_start_thread
|
||||
_msys_start_thread:
|
||||
;arg1 - proc
|
||||
;arg2 - stacksize
|
||||
;arg3 - pid
|
||||
push dword [esp+8]
|
||||
call malloc
|
||||
test eax,eax
|
||||
jz .no_mem
|
||||
push ebx
|
||||
mov edx,eax
|
||||
add edx,[esp+12]
|
||||
mov [edx-4],dword 0
|
||||
mov ecx,[esp+8]
|
||||
mov ebx,1
|
||||
mov eax,51
|
||||
int 0x40
|
||||
mov ebx,[esp+16]
|
||||
test ebx,ebx
|
||||
jz .no_val
|
||||
mov [ebx],eax
|
||||
.no_val:
|
||||
mov eax,edx
|
||||
sub eax,[esp+12]
|
||||
pop ebx
|
||||
ret 12
|
||||
.no_mem:
|
||||
mov ecx,[esp+12]
|
||||
mov [ecx],eax
|
||||
ret 12
|
11
programs/develop/metcc/trunk/libc/mesys/window_redraw.asm
Normal file
11
programs/develop/metcc/trunk/libc/mesys/window_redraw.asm
Normal file
@@ -0,0 +1,11 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_window_redraw
|
||||
_msys_window_redraw:
|
||||
;arg1 - status
|
||||
mov edx,ebx
|
||||
mov eax,12
|
||||
mov ebx,[esp+4]
|
||||
int 0x40
|
||||
mov ebx,edx
|
||||
ret 4
|
20
programs/develop/metcc/trunk/libc/mesys/write_text.asm
Normal file
20
programs/develop/metcc/trunk/libc/mesys/write_text.asm
Normal file
@@ -0,0 +1,20 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public _msys_write_text
|
||||
_msys_write_text:
|
||||
;arg1 - x
|
||||
;arg2 - y
|
||||
;arg3 - color
|
||||
;arg4 - text
|
||||
;arg5 - len
|
||||
push ebx esi
|
||||
mov eax,4
|
||||
mov ebx,[esp+12]
|
||||
shl ebx,16
|
||||
mov bx,[esp+16]
|
||||
mov ecx,[esp+20]
|
||||
mov edx,[esp+24]
|
||||
mov esi,[esp+28]
|
||||
int 0x40
|
||||
pop esi ebx
|
||||
ret 20
|
130
programs/develop/metcc/trunk/libc/start/start.asm
Normal file
130
programs/develop/metcc/trunk/libc/start/start.asm
Normal file
@@ -0,0 +1,130 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public start
|
||||
extrn mf_init
|
||||
extrn main
|
||||
;include 'debug2.inc'
|
||||
__DEBUG__=0
|
||||
virtual at 0
|
||||
db 'MENUET01' ; 1. Magic number (8 bytes)
|
||||
dd 0x01 ; 2. Version of executable file
|
||||
dd 0x0 ; 3. Start address
|
||||
dd 0x0 ; 4. Size of image
|
||||
dd 0x100000 ; 5. Size of needed memory
|
||||
dd 0x100000 ; 6. Pointer to stack
|
||||
hparams dd 0x0 ; 7. Pointer to program arguments
|
||||
hpath dd 0x0 ; 8. Pointer to program path
|
||||
end virtual
|
||||
start:
|
||||
;DEBUGF 'Start programm\n'
|
||||
xor eax,eax
|
||||
call mf_init
|
||||
;DEBUGF ' path "%s"\n params "%s"\n', .path, .params
|
||||
; check for overflow
|
||||
mov al, [path+buf_len-1]
|
||||
or al, [params+buf_len-1]
|
||||
jnz .crash
|
||||
; check if path written by OS
|
||||
mov eax, [hparams]
|
||||
test eax, eax
|
||||
jz .without_path
|
||||
mov eax, path
|
||||
.without_path:
|
||||
mov esi, eax
|
||||
call push_param
|
||||
; retrieving parameters
|
||||
mov esi, params
|
||||
xor edx, edx ; dl - <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(1) <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0)
|
||||
; dh - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
mov ecx, 1 ; cl = 1
|
||||
; ch = 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
.parse:
|
||||
lodsb
|
||||
test al, al
|
||||
jz .run
|
||||
test dl, dl
|
||||
jnz .findendparam
|
||||
;{<7B><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
cmp al, ' '
|
||||
jz .parse ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
mov dl, cl ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
cmp al, '"'
|
||||
jz @f ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
mov dh, ch ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
dec esi
|
||||
call push_param
|
||||
inc esi
|
||||
jmp .parse
|
||||
|
||||
@@:
|
||||
mov dh, cl ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
call push_param ;<3B><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
jmp .parse ;<3B><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>}
|
||||
|
||||
.findendparam:
|
||||
test dh, dh
|
||||
jz @f ; <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
cmp al, '"'
|
||||
jz .clear
|
||||
jmp .parse
|
||||
@@:
|
||||
cmp al, ' '
|
||||
jnz .parse
|
||||
|
||||
.clear:
|
||||
lea ebx, [esi - 1]
|
||||
mov [ebx], ch
|
||||
mov dl, ch
|
||||
jmp .parse
|
||||
|
||||
.run:
|
||||
;DEBUGF 'call main(%x, %x) with params:\n', [argc], argv
|
||||
if __DEBUG__ = 1
|
||||
mov ecx, [argc]
|
||||
@@:
|
||||
lea esi, [ecx * 4 + argv-4]
|
||||
DEBUGF '0x%x) "%s"\n', cx, [esi]
|
||||
loop @b
|
||||
end if
|
||||
push [argc]
|
||||
push argv
|
||||
call main
|
||||
.exit:
|
||||
;DEBUGF 'Exit from prog\n';
|
||||
xor eax,eax
|
||||
dec eax
|
||||
int 0x40
|
||||
dd -1
|
||||
.crash:
|
||||
;DEBUGF 'E:buffer overflowed\n'
|
||||
jmp .exit
|
||||
;============================
|
||||
push_param:
|
||||
;============================
|
||||
;parameters
|
||||
; esi - pointer
|
||||
;description
|
||||
; procedure increase argc
|
||||
; and add pointer to array argv
|
||||
; procedure changes ebx
|
||||
mov ebx, [argc]
|
||||
cmp ebx, max_parameters
|
||||
jae .dont_add
|
||||
mov [argv+4*ebx], esi
|
||||
inc [argc]
|
||||
.dont_add:
|
||||
ret
|
||||
;==============================
|
||||
public params as '__argv'
|
||||
public path as '__path'
|
||||
|
||||
section '.bss'
|
||||
buf_len = 0x400
|
||||
max_parameters=0x20
|
||||
argc rd 1
|
||||
argv rd max_parameters
|
||||
path rb buf_len
|
||||
params rb buf_len
|
||||
|
||||
;section '.data'
|
||||
;include_debug_strings ; ALWAYS present in data section
|
156
programs/develop/metcc/trunk/libc/string/_mesys.asm
Normal file
156
programs/develop/metcc/trunk/libc/string/_mesys.asm
Normal file
@@ -0,0 +1,156 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
|
||||
public _msys_draw_window
|
||||
_msys_draw_window:
|
||||
;arg1 - xcoord
|
||||
;arg2 - ycoord
|
||||
;arg3 - xsize
|
||||
;arg4 - ysize
|
||||
;arg5 - workcolor
|
||||
;arg6 - type
|
||||
;arg7 - captioncolor
|
||||
;arg8 - windowtype
|
||||
;arg9 - bordercolor
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push ebx esi edi
|
||||
mov ebx,[ebp+8]
|
||||
shl ebx,16
|
||||
mov bx,[ebp+16]
|
||||
mov ecx,[ebp+12]
|
||||
shl ecx,16
|
||||
mov cx,[ebp+20]
|
||||
mov edx,[ebp+28]
|
||||
shl edx,24
|
||||
add edx,[ebp+24]
|
||||
mov esi,[ebp+36]
|
||||
shl esi,24
|
||||
add esi,[ebp+32]
|
||||
mov edi,[ebp+40]
|
||||
xor eax,eax
|
||||
int 0x40
|
||||
pop edi esi ebx
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
public _msys_read_file
|
||||
_msys_read_file:
|
||||
;arg1 - file name
|
||||
;arg2 - file offset
|
||||
;arg3 - size to read
|
||||
;arg4 - data
|
||||
;arg5 - temp buffer
|
||||
;arg6 - file size
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
xor eax,eax
|
||||
mov [file_struct.operation],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.offset],eax
|
||||
mov eax,[ebp+16]
|
||||
mov [file_struct.offset],eax
|
||||
mov eax,[ebp+20]
|
||||
mov [file_struct.offset],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov ebx,file_struct
|
||||
mov eax,58
|
||||
int 0x40
|
||||
mov ecx,[ebp+28]
|
||||
test ecx,ecx
|
||||
jz .no_file_size
|
||||
mov [ecx],ebx
|
||||
.no_file_size:
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
copy_file_name:
|
||||
push esi edi
|
||||
cld
|
||||
mov edi,edx
|
||||
xor eax,eax
|
||||
xor ecx,ecx
|
||||
dec ecx
|
||||
repnz scasb
|
||||
not ecx
|
||||
mov edi,file_struct.path
|
||||
mov esi,edx
|
||||
rep movsb
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
public _msys_write_file
|
||||
_msys_write_file:
|
||||
;arg1 - file name
|
||||
;arg2 - size
|
||||
;arg3 - data
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
xor eax,eax
|
||||
mov [file_struct.offset],eax
|
||||
inc eax
|
||||
mov [file_struct.operation],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.size],eax
|
||||
mov eax,[ebp+16]
|
||||
mov [file_struct.data],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov eax,58
|
||||
mov ebx,file_struct
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
public _msys_run_program
|
||||
_msys_run_program:
|
||||
;arg1 - program name
|
||||
;arg2 - parameters
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
mov [file_struct.operation],16
|
||||
xor eax,eax
|
||||
mov [file_struct.offset],eax
|
||||
mov [file_struct.data],eax
|
||||
mov eax,[ebp+12]
|
||||
mov [file_struct.param],eax
|
||||
mov [file_struct.temp_buffer],temp_buffer;
|
||||
mov edx,[ebp+8]
|
||||
call copy_file_name
|
||||
push ebx
|
||||
mov eax,58
|
||||
mov ebx,file_struct
|
||||
int 0x40
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
public _msys_debug_out
|
||||
_msys_debug_out:
|
||||
;arg1 - char to out
|
||||
push ebx
|
||||
mov ecx,[esp+8]
|
||||
mov ebx,1
|
||||
mov eax,63
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret
|
||||
section '.data' writeable
|
||||
section '.bss' writeable
|
||||
file_struct:
|
||||
.operation rd 1
|
||||
.offset rd 1
|
||||
.param:
|
||||
.size rd 1
|
||||
.data rd 1
|
||||
.temp_buffer rd 1
|
||||
.path rb 1024
|
||||
temp_buffer rb 4096
|
||||
|
10
programs/develop/metcc/trunk/libc/string/memchr.c
Normal file
10
programs/develop/metcc/trunk/libc/string/memchr.c
Normal file
@@ -0,0 +1,10 @@
|
||||
void* memchr(const void* buf,int c,int count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
if (*(char*)buf==c)
|
||||
return (void*)buf;
|
||||
else
|
||||
buf++;
|
||||
return (void*)0;
|
||||
}
|
13
programs/develop/metcc/trunk/libc/string/memcmp.c
Normal file
13
programs/develop/metcc/trunk/libc/string/memcmp.c
Normal file
@@ -0,0 +1,13 @@
|
||||
typedef unsigned char uc;
|
||||
int memcmp(const void* buf1,const void* buf2,int count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
if (*(uc*)buf1<*(uc*)buf2)
|
||||
return -1;
|
||||
if (*(uc*)buf1>*(uc*)buf2)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
16
programs/develop/metcc/trunk/libc/string/memmove.asm
Normal file
16
programs/develop/metcc/trunk/libc/string/memmove.asm
Normal file
@@ -0,0 +1,16 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public memcpy
|
||||
public memmove
|
||||
memcpy:
|
||||
memmove:
|
||||
push esi edi
|
||||
mov edi,[esp+12]
|
||||
mov esi,[esp+16]
|
||||
mov ecx,[esp+20]
|
||||
jecxz .no_copy
|
||||
cld
|
||||
rep movsb
|
||||
.no_copy:
|
||||
pop edi esi
|
||||
ret
|
15
programs/develop/metcc/trunk/libc/string/memset.asm
Normal file
15
programs/develop/metcc/trunk/libc/string/memset.asm
Normal file
@@ -0,0 +1,15 @@
|
||||
format ELF
|
||||
section '.text' executable
|
||||
public memset
|
||||
memset:
|
||||
push edi
|
||||
mov edi,[esp+8]
|
||||
mov eax,[esp+12]
|
||||
mov ecx,[esp+16]
|
||||
jecxz .no_set
|
||||
cld
|
||||
rep stosb
|
||||
.no_set:
|
||||
pop edi
|
||||
ret
|
||||
|
13
programs/develop/metcc/trunk/libc/string/strcat.c
Normal file
13
programs/develop/metcc/trunk/libc/string/strcat.c
Normal file
@@ -0,0 +1,13 @@
|
||||
char* strcat(char* strDest, const char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest!='\0') strDest++;
|
||||
while (*strSource!='\0')
|
||||
{
|
||||
*strDest=*strSource;
|
||||
strDest++;
|
||||
strSource++;
|
||||
}
|
||||
return res;
|
||||
}
|
10
programs/develop/metcc/trunk/libc/string/strchr.c
Normal file
10
programs/develop/metcc/trunk/libc/string/strchr.c
Normal file
@@ -0,0 +1,10 @@
|
||||
char* strchr(const char* string, int c)
|
||||
{
|
||||
while (*string!='\0')
|
||||
{
|
||||
if (*string==c)
|
||||
return (char*)string;
|
||||
string++;
|
||||
}
|
||||
return (char*)0;
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strcmp.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strcmp.c
Normal file
@@ -0,0 +1,14 @@
|
||||
int strcmp(const char* string1, const char* string2)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (*string1<*string2)
|
||||
return -1;
|
||||
if (*string1>*string2)
|
||||
return 1;
|
||||
if (*string1=='\0')
|
||||
return 0;
|
||||
string1++;
|
||||
string2++;
|
||||
}
|
||||
}
|
4
programs/develop/metcc/trunk/libc/string/strcoll.c
Normal file
4
programs/develop/metcc/trunk/libc/string/strcoll.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int strcoll(const char* string1,const char* string2)
|
||||
{
|
||||
return strcmp(string1,string2);
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strcpy.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strcpy.c
Normal file
@@ -0,0 +1,14 @@
|
||||
char* strcpy(char* strDest,char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while(1)
|
||||
{
|
||||
*strDest=*strSource;
|
||||
if (*strSource=='\0')
|
||||
break;
|
||||
strDest++;
|
||||
strSource++;
|
||||
}
|
||||
return res;
|
||||
}
|
17
programs/develop/metcc/trunk/libc/string/strcspn.c
Normal file
17
programs/develop/metcc/trunk/libc/string/strcspn.c
Normal file
@@ -0,0 +1,17 @@
|
||||
int strcspn(const char* string, const char* strCharSet)
|
||||
{
|
||||
const char* temp;
|
||||
int i;
|
||||
i=0;
|
||||
while(1)
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (*temp!='\0')
|
||||
{
|
||||
if (*string==*temp)
|
||||
return i;
|
||||
temp++;
|
||||
}
|
||||
i++;string++;
|
||||
}
|
||||
}
|
9
programs/develop/metcc/trunk/libc/string/strdup.c
Normal file
9
programs/develop/metcc/trunk/libc/string/strdup.c
Normal file
@@ -0,0 +1,9 @@
|
||||
char* strdup(char* str)
|
||||
{
|
||||
char* res;
|
||||
int len;
|
||||
len=strlen(str)+1;
|
||||
res=malloc(len);
|
||||
memcpy(res,str,len);
|
||||
return res;
|
||||
}
|
4
programs/develop/metcc/trunk/libc/string/strerror.c
Normal file
4
programs/develop/metcc/trunk/libc/string/strerror.c
Normal file
@@ -0,0 +1,4 @@
|
||||
char* strerror(int err)
|
||||
{
|
||||
return (char*)0;
|
||||
}
|
11
programs/develop/metcc/trunk/libc/string/strlen.c
Normal file
11
programs/develop/metcc/trunk/libc/string/strlen.c
Normal file
@@ -0,0 +1,11 @@
|
||||
int strlen(const char* string)
|
||||
{
|
||||
int i;
|
||||
i=0;
|
||||
while (*string!='\0')
|
||||
{
|
||||
i++;
|
||||
string++;
|
||||
}
|
||||
return i;
|
||||
}
|
16
programs/develop/metcc/trunk/libc/string/strnbrk.c
Normal file
16
programs/develop/metcc/trunk/libc/string/strnbrk.c
Normal file
@@ -0,0 +1,16 @@
|
||||
char* strpbrk(const char* string, const char* strCharSet)
|
||||
{
|
||||
char* temp;
|
||||
while (*string!='\0')
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (*temp!='\0')
|
||||
{
|
||||
if (*string==*temp)
|
||||
return string;
|
||||
temp++;
|
||||
}
|
||||
string++;
|
||||
}
|
||||
return (char*)0;
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strncat.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strncat.c
Normal file
@@ -0,0 +1,14 @@
|
||||
char* strncat(char* strDest,const char* strSource,int count)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest!='\0') strDest++;
|
||||
while (count>0 && *strSource!='\0')
|
||||
{
|
||||
*strDest=*strSource;
|
||||
count--;
|
||||
strDest++;
|
||||
strSource++;
|
||||
}
|
||||
return res;
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strncmp.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strncmp.c
Normal file
@@ -0,0 +1,14 @@
|
||||
int strncmp(const char* string1, const char* string2, int count)
|
||||
{
|
||||
while(count>0)
|
||||
{
|
||||
if (*string1<*string2)
|
||||
return -1;
|
||||
if (*string1>*string2)
|
||||
return 1;
|
||||
if (*string1=='\0')
|
||||
return 0;
|
||||
count--;
|
||||
}
|
||||
return 0;
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strncpy.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strncpy.c
Normal file
@@ -0,0 +1,14 @@
|
||||
char* strncpy(char* strDest,const char* strSource,int count)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (count>0)
|
||||
{
|
||||
*strDest=*strSource;
|
||||
if (*strSource!='\0')
|
||||
strSource++;
|
||||
strDest++;
|
||||
count--;
|
||||
}
|
||||
return res;
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strrchr.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strrchr.c
Normal file
@@ -0,0 +1,14 @@
|
||||
char* strrchr(const char* s,int c)
|
||||
{
|
||||
char* res;
|
||||
res=(char*)0;
|
||||
while (1)
|
||||
{
|
||||
if (*s==(char)c)
|
||||
res=(char*)s;
|
||||
if (*s=='\0')
|
||||
break;
|
||||
s++;
|
||||
}
|
||||
return res;
|
||||
}
|
20
programs/develop/metcc/trunk/libc/string/strspn.c
Normal file
20
programs/develop/metcc/trunk/libc/string/strspn.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int strspn(const char* string,const char* strCharSet)
|
||||
{
|
||||
int i;
|
||||
const char* temp;
|
||||
i=0;
|
||||
while (*string!='\0')
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (temp!='\0')
|
||||
{
|
||||
if (*temp==*string)
|
||||
break;
|
||||
}
|
||||
if (temp=='\0')
|
||||
break;
|
||||
*string++;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
13
programs/develop/metcc/trunk/libc/string/strstr.c
Normal file
13
programs/develop/metcc/trunk/libc/string/strstr.c
Normal file
@@ -0,0 +1,13 @@
|
||||
extern int strncmp(char* s1,char* s2,int len);
|
||||
char* strstr(const char* s, const char* find)
|
||||
{
|
||||
int len;
|
||||
len=strlen(find);
|
||||
while (1)
|
||||
{
|
||||
if (strncmp(s,find,len)==0) return s;
|
||||
if (*s=='\0')
|
||||
return (char*) 0;
|
||||
s++;
|
||||
}
|
||||
}
|
14
programs/develop/metcc/trunk/libc/string/strtok.c
Normal file
14
programs/develop/metcc/trunk/libc/string/strtok.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "string.h"
|
||||
char* strtok(char* s,const char* delim)
|
||||
{
|
||||
char* res;
|
||||
if (*s=='\0')
|
||||
return (char*)0;
|
||||
s+=strspn(s,delim);
|
||||
if (*s=='\0')
|
||||
return (char*)0;
|
||||
res=s;
|
||||
s+=strcspn(s,delim);
|
||||
*s=='\0';
|
||||
return res;
|
||||
}
|
4
programs/develop/metcc/trunk/libc/string/strxfrm.c
Normal file
4
programs/develop/metcc/trunk/libc/string/strxfrm.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int strxfrm(char* strDest, const char* strSource, int count)
|
||||
{
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user