Initial snapshot

This commit is contained in:
Mercier Pierre-Olivier 2013-02-11 22:04:30 +01:00
commit fee4dd4e6d
373 changed files with 62144 additions and 0 deletions

50
tool/Makefile Normal file
View file

@ -0,0 +1,50 @@
#
# ---------- header -----------------------------------------------------------
#
# project kaneton
#
# license kaneton
#
# file /home/mycure/kaneton/export/output/kaneton/tool/Makefile
#
# created julien quintard [fri nov 28 16:24:37 2008]
# updated julien quintard [sat feb 5 12:11:38 2011]
#
#
# ---------- dependencies -----------------------------------------------------
#
include ../environment/env.mk
#
# ---------- directives -------------------------------------------------------
#
.PHONY: main clear prototypes headers
#
# ---------- variables --------------------------------------------------------
#
SUBDIRS :=
#
# ---------- rules ------------------------------------------------------------
#
main:
for d in $(SUBDIRS) ; do \
$(call env_launch,$${d}/Makefile,,) ; \
done
clear:
for d in $(SUBDIRS) ; do \
$(call env_launch,$${d}/Makefile,clear,) ; \
done
$(call env_purge,)
prototypes:
headers:

Binary file not shown.

284
tool/mbl/grub/grub.py Normal file
View file

@ -0,0 +1,284 @@
#
# ---------- header -----------------------------------------------------------
#
# project kaneton
#
# license kaneton
#
# file /home/mycure/kaneton/tool/mbl/grub/grub.py
#
# created julien quintard [tue jun 26 11:33:57 2007]
# updated julien quintard [sat mar 5 09:19:34 2011]
#
#
# ---------- information ------------------------------------------------------
#
# this script is used to build and install the kaneton microkernel boot
# device.
#
#
# ---------- imports ----------------------------------------------------------
#
import env
import sys
import re
#
# ---------- globals ----------------------------------------------------------
#
g_image="data/kaneton.img"
g_menu = None
g_components = None
g_action = None
#
# ---------- functions --------------------------------------------------------
#
#
# usage()
#
# this function displays the usage.
#
def usage():
env.display(env.HEADER_ERROR, "usage: grub.py [action]", env.OPTION_NONE)
env.display(env.HEADER_NONE, "", env.OPTION_NONE)
env.display(env.HEADER_ERROR, "actions:", env.OPTION_NONE)
env.display(env.HEADER_ERROR, " build", env.OPTION_NONE)
env.display(env.HEADER_ERROR, " install", env.OPTION_NONE)
#
# warning()
#
# this function warns the user about its configuration.
#
def warning():
env.display(env.HEADER_OK, "configuration:", env.OPTION_NONE)
env.display(env.HEADER_OK,
" bootmode: " + env._BOOT_MODE_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" address: " + env._ADDRESS_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" tftp address: " + env._TFTP_ADDRESS_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" tftp directory: " + env._TFTP_DIRECTORY_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" UNIX device: " + env._UDEVICE_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" mtool device: " + env._MDEVICE_,
env.OPTION_NONE)
env.display(env.HEADER_OK,
" image path: " + env._IMAGE_,
env.OPTION_NONE)
#
# menu()
#
# this function generates the grub menu file.
#
def menu():
global g_components
global g_menu
content = None
component = None
# initialize the file content.
content = "timeout 0\n" + \
"title kaneton\n"
# add information about how to boot.
if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "image"):
if env._BOOT_DEVICE_ == "floppy":
content += "root (fd0)\n"
elif env._BOOT_DEVICE_ == "hard-drive":
content += "root (hd0)\n"
else:
env.display(env.HEADER_ERROR,
"unknown boot device '" + env._BOOT_DEVICE_ + "'",
env.OPTION_NONE)
sys.exit(42)
elif env._BOOT_MODE_ == "network":
content += "ifconfig --address=" + env._ADDRESS_ + " --server=" + \
env._TFTP_ADDRESS_ + "\n" + \
"root (nd)\n"
else:
env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ +
"'", env.OPTION_NONE)
sys.exit(42)
# retrieve the grub modules from the _COMPONENTS_ environment variables.
g_components = re.split("[ \t]+", env._COMPONENTS_.strip())
# set the first component as the grub kernel.
content += re.sub("^.*\/", "kernel /modules/", g_components[0]) + "\n"
# set the other components as grub modules.
for component in g_components[1:]:
content += re.sub("^.*\/", "module /modules/", component) + "\n"
# create the temporary file and fill it.
g_menu = env.temporary(env.OPTION_FILE)
env.push(g_menu, content, env.OPTION_NONE)
#
# install()
#
# this function installs the kaneton binaries onto the boot device.
#
def install():
component = None
# warn the user before performing any action.
warning()
# display some stuff.
env.display(env.HEADER_NONE, "", env.OPTION_NONE)
env.display(env.HEADER_OK,
"installing kaneton binaries on the boot device",
env.OPTION_NONE)
# generates the grub menu file.
menu()
# depending on the boot mode and boot device, install the kaneton binaries
# and the grub menu file.
if env._BOOT_MODE_ == "peripheral":
if env.load(g_menu, env._MDEVICE_, "/boot/grub/menu.lst",
env.OPTION_DEVICE) != 0:
env.display(env.HEADER_ERROR,
"unable to load the menu.lst file",
env.OPTION_NONE)
sys.exit(42)
for component in g_components:
if not env.path(component, env.OPTION_EXIST):
env.display(env.HEADER_ERROR, " " + component, env.OPTION_NONE)
else:
if env.load(component, env._MDEVICE_, "/modules/",
env.OPTION_DEVICE) != 0:
env.display(env.HEADER_ERROR,
"unable to load the component '" + component + "'",
env.OPTION_NONE)
sys.exit(42)
env.display(env.HEADER_OK, " " + component, env.OPTION_NONE)
elif env._BOOT_MODE_ == "network":
if env.load(g_menu, env._MDEVICE_, "/boot/grub/menu.lst",
env.OPTION_DEVICE) != 0:
env.display(env.HEADER_ERROR,
"unable to load the menu.lst file",
env.OPTION_NONE)
sys.exit(42)
for component in g_components:
if not env.path(component, env.OPTION_EXIST):
env.display(env.HEADER_ERROR, " " + component, env.OPTION_NONE)
else:
env.copy(component, env._TFTP_DIRECTORY_, env.OPTION_NONE)
env.display(env.HEADER_OK, " " + component, env.OPTION_NONE)
elif env._BOOT_MODE_ == "image":
if env.load(g_menu, env._IMAGE_, "/boot/grub/menu.lst",
env.OPTION_IMAGE) != 0:
env.display(env.HEADER_ERROR,
"unable to load the menu.lst file",
env.OPTION_NONE)
sys.exit(42)
for component in g_components:
if not env.path(component, env.OPTION_EXIST):
env.display(env.HEADER_ERROR, " " + component, env.OPTION_NONE)
else:
if env.load(component, env._IMAGE_, "/modules/",
env.OPTION_IMAGE) != 0:
env.display(env.HEADER_ERROR,
"unable to load the component '" + component + "'",
env.OPTION_NONE)
sys.exit(42)
env.display(env.HEADER_OK, " " + component, env.OPTION_NONE)
else:
env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ +
"'", env.OPTION_NONE)
sys.exit(42)
#
# build()
#
# this function builds, initializes the boot device.
#
def build():
# warn the user before performing any action.
warning()
# display some stuff.
env.display(env.HEADER_NONE, "", env.OPTION_NONE)
env.display(env.HEADER_OK, "initializing the boot device", env.OPTION_NONE)
# for each boot mode, initialize the boot device.
if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "network"):
env.push(env._UDEVICE_,
env.pull(g_image, env.OPTION_NONE),
env.OPTION_NONE)
elif env._BOOT_MODE_ == "image":
env.copy(g_image, env._IMAGE_, env.OPTION_NONE)
else:
env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ +
"'", env.OPTION_NONE)
sys.exit(42)
#
# main()
#
# this function performs the main work.
#
def main():
global g_action
# check the number of arguments.
if len(sys.argv) != 2:
usage()
sys.exit(42)
# set the action.
g_action = sys.argv[1]
# act according to the action argument.
if g_action == "build":
build()
elif g_action == "install":
install()
else:
env.display(env.HEADER_ERROR, "unknown action \'" + g_action + "'",
env.OPTION_NONE)
usage()
sys.exit(42)
#
# ---------- entry point ------------------------------------------------------
#
if __name__ == "__main__":
main()

239
tool/mkp/mkp.py Normal file
View file

@ -0,0 +1,239 @@
#
# Makeprotos / mkp.py
# Made by pwipwi <pwipwi@lse.epita.fr>
# This python script was created to
# 1) Give me an opportunity to practice python a bit :)
# 2) Replace old mkp.pl, which was sufficient, but a bit unreadable.
#
# usage:
# ./mkp.py header1 header2 ...
#
# For this script to work efficiently, you have a few things to do :
# * Code with the Epita CSS, at least in function declaration.
# This little script is far from being a C parser, so it will
# exclusively recognize Epita CSS' functions declarations
# * You have to end your prototypes section by a
# /*
# * eop
# */
# statement
# * Last but not least, you need to have a VALID prototypes secion.
# it looks like that
# /*
# * ---------- prototypes --------------------
# *
# * ./relative/path/to/file/1
# * ./relative/path/to/file/2
# *
# * ./et/caetera
# */
# Be sure to respect the spacing, as the script is especially not
# tolerant with them (especially before the *).
# You can have as much spaces as you want between the * and the file
# names, though.
#
# That should do the trick. If you ever encounter a problem which is most
# likely a bug in that script, please send me a mail.
#
# System module
import sys
# OS specific module
import os
# Regular Expression module
import re
## --------- Classes ----------------------------------------------------------
class cl_functions:
""" cl_functions : functions definitions
This class is the one that shall hold all the function definitions
we will have found in the diverse files.
"""
def __init__(self):
self.di_files = {} # initialize file dictionnary
self.beginning = []
self.ending = []
self.filenames = []
def add_filename(self, str_filename):
self.di_files[str_filename] = []
def add_function(self, str_filename, li_functiondecl):
self.di_files[str_filename].append(li_functiondecl)
def purge(self):
self.di_files = {}
## --------- functions ---------------------------------------------------------
##
## error
##
def fn_error(string, code):
"""Throw an Error
Print an error and exit the program with the corresponding code
"""
print(sys.argv[0] + ':' + string)
sys.exit(code)
##
## readprotosfiles
##
def fn_readprotosfiles(fp, functions):
"""Readprotos files
Read the file names of the files that shall be processed
"""
filelist = []
line = fp.readline()
while line != '' and not re.match(' \* -+ prototypes -+', line):
functions.beginning.append(line)
line = fp.readline()
if line == '':
fn_error('this file doesn\'t contain a valid prototype section', 3)
# iterate until the end of the prototypes section
endre = re.compile('.*\*/')
filere = re.compile('\s*\*+\s+[./_a-zA-Z0-9]+')
filenamere = re.compile('[-./_a-zA-Z0-9]+')
eopre = re.compile('\s*\*+\s+eop')
while line != '' and not endre.match(line):
functions.beginning.append(line)
if filere.match(line):
line = filenamere.search(line).group()
filelist.append(line)
line = fp.readline()
functions.beginning.append(line)
while line != '' and not eopre.match(line):
line = fp.readline()
while line != '' and not endre.match(line):
line = fp.readline()
if line == '':
fn_error("no eop in" + fp.filename, 3)
while line != '':
line = fp.readline()
functions.ending.append(line)
del filere
del endre
del filenamere
return filelist
##
## processfile
##
def fn_processfile(filename, functions):
"""Process files
returns a function list from the given file
"""
inside_funcion = 0
inside_comment = 0
currentlist = []
try:
fp = open(filename, 'r')
except IOError:
fn_error("unable to open" + filename, 4)
functionre = re.compile('^[a-zA-Z0-9_](([\*\w]*)\s+\**)+\w+\(') # function declaration
commentre = re.compile('/\*') # comment start
endcomre = re.compile('\*/') # comment end
staticre = re.compile('static') # static keyword
for line in fp.readlines():
matched = functionre.search(line)
commatched = commentre.search(line)
endcommatched = endcomre.search(line)
if commatched:
inside_comment = inside_comment + 1
if endcommatched:
inside_comment = inside_comment - 1
if matched and not inside_comment:
inside_funcion = 1
if inside_funcion:
static_match = staticre.search(line)
if re.search('\)\n', line) and not static_match:
line = re.match("(.*)$", line).group(0)
line = line + ';\n'
currentlist.append(line)
functions.add_function(filename, currentlist)
currentlist = []
inside_funcion = 0
continue
else:
if not static_match:
currentlist.append(line)
else:
inside_funcion = 0
continue
fp.close()
##
##
##
def fn_write_header(functions, filename):
"""Write the header
Write the function declarations to the header files
"""
try:
fp = open(filename, 'w')
except IOError:
fn_error(filename + " is not writeable")
fp.writelines(functions.beginning)
for file in functions.filenames:
fp.write('\n/*\n * ' + file + '\n */\n\n')
for func in functions.di_files[file]:
fp.writelines(func)
fp.write('\n')
fp.write('\n/*\n * eop\n */\n')
fp.writelines(functions.ending)
fp.close()
##
## mkprotos
##
def fn_mkprotos(path):
""" Make protos
This function calls all the others. It proceeds in that order:
first, it calls fn_readprotos to get a list of the files to parse
and recover prototypes.
then, for each of those files, it calls fn_processfile, which
parses the file and gets the prototypes.
finally, it calls fn_write_header to actually write the header
"""
functions = cl_functions()
currentpwd = os.getcwd()
filename = ''
if (path.count('/') >= 1): # is it
filename = re.sub('.*/', '', path) # splits the filename from the path
dirname = re.sub('/[^/]*$', '', path) # splits the directory name from the path
try:
os.chdir(dirname)
except OSError:
fn_error(dirname + ', no such file or directory !', 1)
else:
filename = path
try:
fp = open(filename, 'r')
except IOError:
fn_error(filename + ', no such file', 2)
functions.filenames = fn_readprotosfiles(fp, functions)
for file in functions.filenames:
functions.add_filename(file)
fn_processfile(file, functions)
fp.close()
fn_write_header(functions, filename)
os.chdir(currentpwd)
return functions
##
## \o/ Main function \o/
##
args = sys.argv[1:]
if len(args) == 0:
fn_error('Give at least 1 argument, you silly man !', 3)
for file in args:
functions = fn_mkprotos(file)