mirror of https://git.ia64.cc/perso/cos2000v2.git
Nicolas Hordé
5 years ago
23 changed files with 588 additions and 79 deletions
@ -0,0 +1,181 @@
|
||||
#!/usr/bin/env python2.7 |
||||
# -*-coding:utf-8 -* |
||||
|
||||
import os, os.path, re, string, json |
||||
|
||||
def getfunction(syscall): |
||||
args="" |
||||
num=1 |
||||
for argument in syscall['ARGS']: |
||||
if num>1: |
||||
args=args+", " |
||||
args=args+argument['TYPE']+" "+argument['NAME'] |
||||
num=num+1 |
||||
if args=="": |
||||
args="void" |
||||
return str(syscall['RETURN'])+" "+str(syscall['NAME'])+"("+args+")" |
||||
|
||||
def getfunctioninternal(syscall): |
||||
args="" |
||||
argsname=["ebx","esi","edi","ebp"] |
||||
num=1 |
||||
for argument in syscall['ARGS']: |
||||
if num>1: |
||||
args=args+", " |
||||
args=args+"dump->"+argsname[num-1] |
||||
num=num+1 |
||||
if syscall.has_key('DUMP'): |
||||
if num>1: |
||||
args=args+", " |
||||
args=args+"dump" |
||||
return str(syscall['INTERNALNAME'])+"("+args+")" |
||||
|
||||
def get_duplicates(sorted_list): |
||||
duplicates = [] |
||||
last = sorted_list[0] |
||||
for x in sorted_list[1:]: |
||||
if x == last: |
||||
duplicates.append(x) |
||||
last = x |
||||
return set(duplicates) |
||||
|
||||
path = "./" |
||||
files = os.listdir(path) |
||||
pattern = r'\/\* SYSCALL.*END \*\/' |
||||
output_file = "syscalls.txt" |
||||
if os.path.exists(output_file): |
||||
os.remove(output_file) |
||||
fo = open(output_file, "a+") |
||||
fo.write("[") |
||||
print "*** Collecte des SYSCALL" |
||||
for root, dirs, files in os.walk(path): |
||||
for name in files: |
||||
if name.endswith((".c")): |
||||
if root=="./templates": |
||||
continue |
||||
input_file = os.path.join(root, name) |
||||
with open(input_file, "r") as fi : |
||||
content = fi.read() |
||||
results = re.findall(pattern, content, re.MULTILINE| re.DOTALL) |
||||
for result in results: |
||||
print("Fichier :"+os.path.join(root, name)) |
||||
new=string.replace(string.replace(result,"/* SYSCALL ",""),"END */","") |
||||
if fo.tell()>2: |
||||
new=","+new; |
||||
fo.write(new+"\r\n") |
||||
fo.write("]") |
||||
fo.seek(0) |
||||
alljson=json.load(fo); |
||||
print alljson |
||||
fo.close() |
||||
dup = get_duplicates([syscall['ID'] for syscall in alljson]); |
||||
if len(dup)>0: |
||||
print "ERREUR : deux fonctions possedent le meme numero de SYSCALL" |
||||
for error in dup: |
||||
for syscall in alljson: |
||||
if syscall['ID']==error: |
||||
print "librairie :"+syscall['LIBRARY']+" fonction: "+syscall['INTERNALNAME']+" id:"+str(syscall['ID']) |
||||
exit() |
||||
print "*** Mise en place de la documentation" |
||||
os.popen('cp ./templates/API.md ./API.md') |
||||
alllibs=set([syscall['LIBRARY'] for syscall in alljson]) |
||||
text="" |
||||
for lib in alllibs: |
||||
text=text+""" |
||||
### """+lib.upper()+""" |
||||
|
||||
All fonctions in the \""""+lib+"""\" library. |
||||
|
||||
""" |
||||
for syscall in alljson: |
||||
if syscall['LIBRARY']==lib: |
||||
textargs="" |
||||
num=1 |
||||
for argument in syscall['ARGS']: |
||||
textargs=textargs+"\n* * argument "+str(num)+" : **"+argument['TYPE']+" "+argument['NAME']+"** *"+argument['DESCRIPTION']+"*" |
||||
num=num+1 |
||||
dump="no" |
||||
if syscall.has_key('DUMP'): |
||||
dump="yes" |
||||
text=text+"""------ |
||||
|
||||
`"""+getfunction(syscall)+""";` |
||||
|
||||
*Description:"""+str(syscall['DESCRIPTION'])+"""* |
||||
|
||||
* syscall id : **"""+str(syscall['ID'])+"""** |
||||
* arguments : **"""+str(len(syscall['ARGS']))+"""**"""+textargs+""" |
||||
* results : **"""+str(syscall['RETURN'])+"""** |
||||
* dump of register cpu: **"""+dump+"""** |
||||
|
||||
""" |
||||
fo = open("./API.md", "r+") |
||||
content = fo.read() |
||||
content=content.replace("/* FOR INSERTING */",text) |
||||
##print content |
||||
fo.seek(0) |
||||
fo.write(content) |
||||
fo.close() |
||||
print "*** Mise en place des libraires (HEADERS)" |
||||
for lib in alllibs: |
||||
text="" |
||||
print "Librairie :"+lib |
||||
libname="./programs/include/"+lib+".h" |
||||
os.popen('cp ./templates/lib.h '+libname) |
||||
for syscall in alljson: |
||||
if syscall['LIBRARY']==lib: |
||||
text=text+getfunction(syscall)+";\n" |
||||
fo = open(libname, "r+") |
||||
content = fo.read() |
||||
content=content.replace("/* FOR INSERTING */",text) |
||||
##print content |
||||
fo.seek(0) |
||||
fo.write(content) |
||||
fo.close() |
||||
print "*** Mise en place des libraires (SOURCES)" |
||||
for lib in alllibs: |
||||
text="" |
||||
print "Librairie :"+lib |
||||
libname="./programs/lib/"+lib+".c" |
||||
os.popen('cp ./templates/lib.c '+libname) |
||||
for syscall in alljson: |
||||
if syscall['LIBRARY']==lib: |
||||
numargs=len(syscall['ARGS']) |
||||
textargs="syscall"+str(numargs)+"("+str(syscall['ID']) |
||||
for i in range(0,numargs): |
||||
if numargs>0: |
||||
textargs=textargs+"," |
||||
textargs=textargs+"(u32) "+syscall['ARGS'][i]['NAME'] |
||||
text=text+getfunction(syscall)+""" |
||||
{ |
||||
"""+textargs+"""); |
||||
} |
||||
|
||||
""" |
||||
fo = open(libname, "r+") |
||||
content = fo.read() |
||||
content=content.replace("/* FOR INSERTING */",text) |
||||
##print content |
||||
fo.seek(0) |
||||
fo.write(content) |
||||
fo.close() |
||||
print "*** Mise en place du fichier noyau SYSCALL" |
||||
text="" |
||||
libname="./lib/syscall.c" |
||||
os.popen('cp ./templates/syscall.c '+libname) |
||||
for syscall in alljson: |
||||
print "ID :"+str(syscall['ID']) |
||||
call="" |
||||
if syscall['RETURN']!='void': |
||||
call="dump->eax=(u32) " |
||||
call=call+getfunctioninternal(syscall) |
||||
text=text+""" case """+str(syscall['ID'])+""": |
||||
"""+call+"""; |
||||
break; |
||||
""" |
||||
fo = open(libname, "r+") |
||||
content = fo.read() |
||||
content=content.replace("/* FOR INSERTING */",text) |
||||
##print content |
||||
fo.seek(0) |
||||
fo.write(content) |
@ -0,0 +1,11 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "types.h"; |
||||
|
||||
u32 getticks(void); |
||||
void exit(u32 resultcode); |
||||
u8 waitkey(void); |
||||
u32 testapi(u32 arg1, u32 arg2, u32 arg3); |
||||
|
@ -1,8 +1,8 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "types.h"; |
||||
|
||||
u32 libc_testapi(void); |
||||
u32 libc_exit(u32 errorcode); |
||||
u32 print(u8* string); |
||||
|
@ -1,17 +0,0 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ |
||||
/* */ |
||||
|
||||
#include "libc.h"; |
||||
#include "syscall.h"; |
||||
#include "types.h"; |
||||
|
||||
u32 libc_testapi(void) |
||||
{ |
||||
syscall3(0x0, 0x1980, 0x2505, 0x4444); |
||||
} |
||||
|
||||
u32 libc_exit(u32 errorcode) |
||||
{ |
||||
syscall1(0x1, errorcode); |
||||
} |
@ -0,0 +1,29 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "libsys.h"; |
||||
#include "syscall.h"; |
||||
#include "types.h"; |
||||
|
||||
u32 getticks(void) |
||||
{ |
||||
syscall0(4); |
||||
} |
||||
|
||||
void exit(u32 resultcode) |
||||
{ |
||||
syscall1(5,(u32) resultcode); |
||||
} |
||||
|
||||
u8 waitkey(void) |
||||
{ |
||||
syscall0(1); |
||||
} |
||||
|
||||
u32 testapi(u32 arg1, u32 arg2, u32 arg3) |
||||
{ |
||||
syscall3(0,(u32) arg1,(u32) arg2,(u32) arg3); |
||||
} |
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "libsys.h"; |
||||
#include "syscall.h"; |
||||
#include "types.h"; |
||||
|
||||
u32 print(u8* string) |
||||
{ |
||||
syscall1(2,(u32) string); |
||||
} |
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
[ |
||||
{ |
||||
"ID":4, |
||||
"NAME":"getticks", |
||||
"LIBRARY":"libsys", |
||||
"INTERNALNAME":"gettimer", |
||||
"DESCRIPTION":"Return the internal value of the timer", |
||||
"ARGS": [], |
||||
"RETURN":"u32" |
||||
} |
||||
|
||||
, |
||||
{ |
||||
"ID":5, |
||||
"LIBRARY":"libsys", |
||||
"NAME":"exit", |
||||
"INTERNALNAME":"exit", |
||||
"DESCRIPTION":"End a task for user or kernel domain", |
||||
"ARGS": [ |
||||
{"TYPE":"u32","NAME":"resultcode","DESCRIPTION":"Code result of the execution"} |
||||
], |
||||
"RETURN":"void" |
||||
} |
||||
|
||||
, |
||||
{ |
||||
"ID":2, |
||||
"LIBRARY":"libvideo", |
||||
"NAME":"print", |
||||
"INTERNALNAME":"print", |
||||
"DESCRIPTION":"Show a string on the screen", |
||||
"ARGS": [ |
||||
{"TYPE":"u8*","NAME":"string","DESCRIPTION":"string to show in ascii format"} |
||||
], |
||||
"RETURN":"u32" |
||||
} |
||||
|
||||
, |
||||
{ |
||||
"ID":1, |
||||
"LIBRARY":"libsys", |
||||
"NAME":"waitkey", |
||||
"INTERNALNAME":"waitascii", |
||||
"DESCRIPTION":"Wait for user to press a key and return the ascii code pressed", |
||||
"ARGS": [], |
||||
"RETURN":"u8" |
||||
} |
||||
|
||||
, |
||||
{ |
||||
"ID":0, |
||||
"LIBRARY":"libsys", |
||||
"NAME":"testapi", |
||||
"INTERNALNAME":"testapi", |
||||
"DESCRIPTION":"Simple function to test if SYSCALL API is correctly running", |
||||
"ARGS": [ |
||||
{"TYPE":"u32","NAME":"arg1","DESCRIPTION":"first argument of your choice"}, |
||||
{"TYPE":"u32","NAME":"arg2","DESCRIPTION":"second argument of your choice"}, |
||||
{"TYPE":"u32","NAME":"arg3","DESCRIPTION":"third argument of your choice"} |
||||
], |
||||
"RETURN":"u32", |
||||
"DUMP":"yes" |
||||
} |
||||
|
||||
] |
@ -0,0 +1,5 @@
|
||||
## API List |
||||
|
||||
APIs given by COS2000 libraries |
||||
|
||||
/* FOR INSERTING */ |
@ -0,0 +1,9 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "libsys.h"; |
||||
#include "syscall.h"; |
||||
#include "types.h"; |
||||
|
||||
/* FOR INSERTING */ |
@ -0,0 +1,7 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
|
||||
#include "types.h"; |
||||
|
||||
/* FOR INSERTING */ |
@ -0,0 +1,80 @@
|
||||
/*******************************************************************************/ |
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Horde Nicolas */ |
||||
/* */ |
||||
#include <types.h> |
||||
#include <gdt.h> |
||||
#include <asm.h> |
||||
#include <memory.h> |
||||
#include <interrupts.h> |
||||
#include <syscall.h> |
||||
#include <process.h> |
||||
|
||||
/* 32bit SYSENTER instruction entry.
|
||||
* |
||||
* Arguments: |
||||
* %eax System call number. |
||||
* %ebx Arg1 |
||||
* %esi Arg2 |
||||
* %edi Arg3 |
||||
/*******************************************************************************/ |
||||
|
||||
/* Fonction permettant de tester le fonctionnement de SYSENTER */ |
||||
/* SYSCALL
|
||||
{ |
||||
"ID":0, |
||||
"LIBRARY":"libsys", |
||||
"NAME":"testapi", |
||||
"INTERNALNAME":"testapi", |
||||
"DESCRIPTION":"Simple function to test if SYSCALL API is correctly running", |
||||
"ARGS": [ |
||||
{"TYPE":"u32","NAME":"arg1","DESCRIPTION":"first argument of your choice"}, |
||||
{"TYPE":"u32","NAME":"arg2","DESCRIPTION":"second argument of your choice"}, |
||||
{"TYPE":"u32","NAME":"arg3","DESCRIPTION":"third argument of your choice"} |
||||
], |
||||
"RETURN":"u32", |
||||
"DUMP":"yes" |
||||
} |
||||
END */ |
||||
|
||||
u32 testapi(u32 arg1, u32 arg2, u32 arg3, regs* dump) |
||||
{ |
||||
printf("Appel syscall %u depuis %Y:%Y avec arguments => ARG1:%Y ARG2:%Y ARG3:%Y\r\n", dump->eax, (u32) dump->cs, dump->eip, arg1, arg2, arg3);
|
||||
return; |
||||
} |
||||
|
||||
/*******************************************************************************/ |
||||
|
||||
/* Initialise les appels système par SYSENTER/SYSEXIT */ |
||||
|
||||
void initsyscall(void) |
||||
{ |
||||
wrmsr(0x174, SEL_KERNEL_CODE, 0x0); |
||||
wrmsr(0x175, 0x60000, 0x0); |
||||
wrmsr(0x176, &sysenter_handler + 6, 0x0); |
||||
} |
||||
|
||||
/*******************************************************************************/ |
||||
|
||||
/* Entrée pour les appels système SYSENTER */ |
||||
|
||||
void sysenter_handler(void) |
||||
{ |
||||
cli(); |
||||
regs *dump; |
||||
dumpcpu(); |
||||
getESP(dump); |
||||
sti(); |
||||
switch (dump->eax) |
||||
{ |
||||
/* FOR INSERTING */ |
||||
default: |
||||
printf("Appel syscall vers fonction inexistante en %Y:%Y", dump->cs, dump->eip); |
||||
break; |
||||
} |
||||
restdebugcpu(); |
||||
sysexit(); |
||||
} |
||||
|
||||
/*******************************************************************************/ |
||||
|
||||
|
Loading…
Reference in new issue