Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ HelenOS.config	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -554,7 +554,4 @@
 ! CONFIG_WRITE_CORE_FILES (n/y)
 
-% Include development files (headers, libraries)
-! [RDFMT=tmpfs|RDFMT=ext2fs] CONFIG_DEVEL_FILES (n/y)
-
 % Strip binaries
 ! CONFIG_STRIP_BINARIES (n/y)
@@ -565,10 +562,4 @@
 % Barebone build with essential binaries only 
 ! CONFIG_BAREBONE (n/y)
-
-% Build pcc binaries 
-! CONFIG_PCC (n/y)
-
-% Build binutils binaries 
-! CONFIG_BINUTILS (n/y)
 
 % Line debugging information
Index: Makefile
===================================================================
--- Makefile	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ Makefile	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -66,5 +66,8 @@
 # Autotool (detects compiler features)
 
-autotool $(COMMON_MAKEFILE) $(COMMON_HEADER): $(CONFIG_MAKEFILE)
+$(COMMON_MAKEFILE): autotool
+$(COMMON_HEADER): autotool
+
+autotool: $(CONFIG_MAKEFILE)
 	$(AUTOTOOL)
 	-[ -f $(COMMON_HEADER_PREV) ] && diff -q $(COMMON_HEADER_PREV) $(COMMON_HEADER) && mv -f $(COMMON_HEADER_PREV) $(COMMON_HEADER)
@@ -72,5 +75,8 @@
 # Build-time configuration
 
-config_default $(CONFIG_MAKEFILE) $(CONFIG_HEADER): $(CONFIG_RULES)
+$(CONFIG_MAKEFILE): config_default
+$(CONFIG_HEADER): config_default
+
+config_default: $(CONFIG_RULES)
 ifeq ($(HANDS_OFF),y)
 	$(CONFIG) $< hands-off $(PROFILE)
@@ -94,5 +100,4 @@
 distclean: clean
 	rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc release/HelenOS-*
-	cd ./uspace/app/binutils/; ./distclean.sh
 
 clean:
Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ boot/Makefile	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -61,9 +61,4 @@
 		cp "$$file" "$(DIST_PATH)/lib/" ; \
 	done
-ifeq ($(CONFIG_DEVEL_FILES), y)
-	mkdir "$(DIST_PATH)/inc/c/"
-	cp -r -L "$(USPACE_PATH)/lib/c/include/." "$(DIST_PATH)/inc/c/"
-	cat "$(USPACE_PATH)/lib/c/arch/$(UARCH)/_link.ld" | sed 's/^STARTUP(.*)$$//g' > "$(DIST_PATH)/inc/_link.ld"
-endif
 	for file in $(RD_APPS) ; do \
 		cp "$$file" "$(DIST_PATH)/app/" ; \
@@ -99,5 +94,4 @@
 	rm -rf $(USPACE_PATH)/dist/drv/*
 	rm -f $(USPACE_PATH)/dist/lib/*
-	rm -rf $(USPACE_PATH)/dist/inc/*
 	rm -f $(USPACE_PATH)/dist/app/*
 	rm -f $(USPACE_PATH)/dist/cfg/net/*
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ boot/Makefile.common	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -127,11 +127,4 @@
 RD_LIBS =
 
-ifeq ($(CONFIG_DEVEL_FILES), y)
-	RD_LIBS += \
-		$(USPACE_PATH)/lib/c/libc.a \
-		$(USPACE_PATH)/lib/softint/libsoftint.a \
-		$(USPACE_PATH)/lib/softfloat/libsoftfloat.a
-endif
-
 ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
 	RD_LIBS += \
@@ -150,4 +143,8 @@
 	$(USPACE_PATH)/app/blkdump/blkdump \
 	$(USPACE_PATH)/app/bnchmark/bnchmark \
+	$(USPACE_PATH)/app/cc/cc \
+	$(USPACE_PATH)/app/ccom/ccom \
+	$(USPACE_PATH)/app/ccom/mkext/cc_mkext \
+	$(USPACE_PATH)/app/cpp/cpp \
 	$(USPACE_PATH)/app/dltest/dltest \
 	$(USPACE_PATH)/app/dltest2/dltest2 \
@@ -178,18 +175,4 @@
 	$(USPACE_PATH)/app/websrv/websrv
 
-ifeq ($(CONFIG_PCC),y)
-RD_APPS_NON_ESSENTIAL += \
-	$(USPACE_PATH)/app/cc/cc \
-	$(USPACE_PATH)/app/ccom/ccom \
-	$(USPACE_PATH)/app/ccom/mkext/cc_mkext \
-	$(USPACE_PATH)/app/cpp/cpp
-endif
-
-ifeq ($(CONFIG_BINUTILS),y)
-RD_APPS_NON_ESSENTIAL += \
-	$(USPACE_PATH)/app/binutils/bin/as \
-	$(USPACE_PATH)/app/binutils/bin/ld
-endif
-
 ifneq ($(CONFIG_BAREBONE),y)
 NET_CFG = \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ uspace/Makefile	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -37,4 +37,8 @@
 	app/blkdump \
 	app/bnchmark \
+	app/cc \
+	app/ccom \
+	app/ccom/mkext \
+	app/cpp \
 	app/edit \
 	app/ext2info \
@@ -111,17 +115,4 @@
 	drv/bus/usb/vhc
 
-ifeq ($(CONFIG_PCC),y)
-DIRS += \
-	app/cc \
-	app/ccom \
-	app/ccom/mkext \
-	app/cpp
-endif
-
-ifeq ($(CONFIG_BINUTILS),y)
-DIRS += \
-	app/binutils
-endif
-
 ## Networking
 #
Index: uspace/app/bdsh/input.c
===================================================================
--- uspace/app/bdsh/input.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ uspace/app/bdsh/input.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -169,48 +169,6 @@
 		new_iostate.stdout = to;
 	}
-
-	if (str_cmp(actual_cmd[0], "batch") == 0 && actual_cmd[1] != NULL) {
-		FILE *batch = fopen(actual_cmd[1], "r");
-		if (batch == NULL) {
-			printf("Cannot open file %s\n", actual_cmd[1]);
-			rc = errno;
-		} else {
-			cliuser_t fusr;
-			fusr.name = usr->name;
-			fusr.cwd = usr->cwd;
-			fusr.prompt = usr->prompt;
-			fusr.line = malloc(INPUT_MAX + 1);
-			char *cur = fusr.line;
-			char *end = fusr.line + INPUT_MAX;
-			int c = fgetc(batch);
-			while (fusr.line != NULL) {
-				if (c == '\n' || c == EOF || cur == end) {
-					*cur = '\0';
-					if (cur == fusr.line) {
-						/* skip empty line */
-						rc = 0;
-						free(cur);
-					} else {
-						printf(">%s\n", fusr.line);
-						rc = process_input(&fusr);
-						/* fusr->line was freed by process_input() */
-					}
-					if (rc == 0 && c != EOF) {
-						fusr.line = malloc(INPUT_MAX + 1);
-						cur = fusr.line;
-						end = fusr.line + INPUT_MAX;
-					} else {
-						break;
-					}
-				} else {
-					*cur++ = c;
-				}
-				c = fgetc(batch);
-			}
-			fclose(batch);
-		}
-	} else {
-		rc = run_command(actual_cmd, usr, &new_iostate);
-	}	
+	
+	rc = run_command(actual_cmd, usr, &new_iostate);
 	
 finit_with_files:
Index: pace/app/binutils/Makefile
===================================================================
--- uspace/app/binutils/Makefile	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,234 +1,0 @@
-#
-# Copyright (c) 2011 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-nullstring =
-space = $(nullstring) # space
-
-# When redefined to 'y' on the command line, certain areas of this Makefile
-# behave slightly differently to simplify the maintenance of binutils port.
-MAINTAIN_BINUTILS=n
-
-# Information for obtaining specific binutils redistributable package.
-# Might be subject to change in the future.
-REDIST_VERSION = 2.21
-REDIST_NAME = binutils-$(REDIST_VERSION)
-REDIST_FILENAME = $(REDIST_NAME).tar.bz2
-REDIST_SOURCE = ftp://ftp.gnu.org/gnu/binutils/
-
-# Directory for the binutils source tree.
-REDIST_DIR = ./redist
-
-# File to detect the presence of binutils source tree.
-REDIST_DETECT = $(REDIST_DIR)/configure
-
-# Directory for resulting binutils binaries.
-BIN_DIR = ./bin
-
-# $USPACE_PREFIX have to be based on the absolute path,
-# because targets derived from it will be referenced from
-# other than the current directory.
-USPACE_PREFIX = $(subst $(space),\ ,$(shell pwd))/../..
-
-# Ensure static configuration of Makefile.common.
-STATIC_ONLY = y
-
-# Link with POSIX runtime library.
-POSIX_COMPAT = y
-
-# Makefile.common for native applications.
-COMMON_MAKEFILE_NATIVE = $(USPACE_PREFIX)/Makefile.common
-
-# Generated from native Makefile.common.
-COMMON_MAKEFILE_PATCHED = ./Makefile.common
-
-# AWK script which generates patched Makefile.common.
-MAKEFILE_PATCH = ./patch.awk
-
-# Compilers that can be used to build binutils.
-SUPPORTED_COMPILERS = gcc_cross gcc_native
-
-# Patched Makefile.common for ported user space applications.
--include $(COMMON_MAKEFILE_PATCHED)
-
-# Patch $PATH to intercept toolchain calls.
-PATH := $(shell pwd):$(PATH)
-export PATH
-
-# Shell script for false toolchain generation.
-TOOLCHAIN_SCRIPT = ./toolchain.sh
-
-# False toolchain.
-TOOLCHAIN = ./gcc ./as ./ar ./ranlib ./ld ./objdump ./objcopy ./strip
-
-# Stamp indicating whether the binutils source tree is patched.
-BINUTILS_PATCHED = ./done
-
-# Shell script for instrusive patches of binutils source tree.
-BINUTILS_PATCH = ./intrusive.sh
-
-# Detection whether the binutils are already configured.
-BINUTILS_CONFIGURED = $(REDIST_DIR)/Makefile
-
-# Generated source file for libposix function stubs without posix_ prefix.
-CONFOBJ_SOURCE = ./confobj.c
-
-# Dummy object file for libposix function stubs without posix_ prefix..
-# Required by binutils configure script tests that links against symbols
-# without including headers (which means that symbols are not prefixed).
-CONFOBJ_OBJECT = $(subst $(space),\ ,$(shell pwd))/confobj.o
-
-# Required by libposix on RISC platforms.
-BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
-
-# Map the HelenOS target to binutils target.
-ifeq ($(PLATFORM),amd64)
-TARGET = amd64-linux-gnu
-endif
-ifeq ($(PLATFORM),arm32)
-TARGET = arm-linux-gnu
-endif
-ifeq ($(PLATFORM),ia32)
-TARGET = i686-pc-linux-gnu
-endif
-ifeq ($(PLATFORM),ia64)
-TARGET = ia64-pc-linux-gnu
-endif
-ifeq ($(PLATFORM),mips32)
-TARGET = mipsel-linux-gnu
-endif
-ifeq ($(PLATFORM),mips32eb)
-TARGET = mips-linux-gnu
-endif
-ifeq ($(PLATFORM),mips64)
-TARGET = mips64el-linux-gnu
-endif
-ifeq ($(PLATFORM),ppc32)
-TARGET = ppc-linux-gnu
-endif
-ifeq ($(PLATFORM),ppc64)
-TARGET = ppc64-linux-gnu
-endif
-ifeq ($(PLATFORM),sparc64)
-TARGET = sparc64-linux-gnu
-endif
-
-# Binutils configure flags.
-CONF_FLAGS = --disable-nls --disable-shared --enable-static \
-	--with-zlib=no --with-ppl=no --with-cloog=no  \
-	--with-gmp=no --with-mpfr=no --with-mpc=no
-
-# Binutils make targets.
-MAKE_TARGETS = all-gas all-ld
-
-# Check presence of gcc compiler.
-# Make binutils.
-# Copy binaries.
-ifeq ($(COMPILER),$(findstring $(COMPILER),$(SUPPORTED_COMPILERS)))
-all: $(COMMON_MAKEFILE_PATCHED) all_ $(TOOLCHAIN) $(BINUTILS_PATCHED) \
-		$(CONFOBJ_OBJECT) $(BINUTILS_CONFIGURED) $(REDIST_DETECT)
-	make -C $(REDIST_DIR) $(MAKE_TARGETS)
-	cp -f $(REDIST_DIR)/gas/as-new $(BIN_DIR)/as
-	cp -f $(REDIST_DIR)/ld/ld-new $(BIN_DIR)/ld
-else
-all:
-	# Skipped: Cannot build binutils with unsupported compiler.
-endif
-
-# Create patched Makefile.common from native Makefile.common.
-$(COMMON_MAKEFILE_PATCHED): $(MAKEFILE_PATCH) $(COMMON_MAKEFILE_NATIVE)
-	awk -f $^ > $@
-
-# Download binutils redistributable package.
-$(REDIST_FILENAME):
-	wget -c $(REDIST_SOURCE)$(REDIST_FILENAME)
-
-# Extract binutils source tree.
-$(REDIST_DETECT): $(REDIST_FILENAME)
-	tar -x -j -f $<
-	mv -f -T $(REDIST_NAME) $(REDIST_DIR)
-	touch $@
-
-# Generate stubs for libposix functions without posix_ prefix.
-$(CONFOBJ_SOURCE):
-	echo '/* GENERATED FILE. DO NOT MODIFY. */' > $@; \
-	$(OBJDUMP) -t $(LIBPOSIX_PREFIX)/libposix.a | \
-	grep 'F .text' | grep -o -h -I -E 'posix_[^.]*$$' | sort -u | \
-	sed 's/posix_\([^ ]*\)/char \1() { return 0; }/g' >> $@
-
-# Compile dummy object for configure script tests.
-$(CONFOBJ_OBJECT): $(CONFOBJ_SOURCE) $(TOOLCHAIN)
-	./gcc -c -o $@ $<
-
-# Generate false toolchain scripts.
-$(TOOLCHAIN): $(TOOLCHAIN_SCRIPT)
-	./$< gcc $(CC) \
-		'$(CFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS) $(CONFOBJ_OBJECT)'
-	./$< as $(AS)
-	./$< ar $(AR)
-	./$< ranlib
-	./$< ld $(LD) \
-		'$(LFLAGS)' '$(LINKER_SCRIPT)' '$(LIBS) $(BASE_LIBS)'
-	./$< objdump $(OBJDUMP)
-	./$< objcopy $(OBJCOPY)
-	./$< strip $(STRIP)
-
-# Patch binutils source tree.
-$(BINUTILS_PATCHED): $(BINUTILS_PATCH) $(REDIST_DETECT)
-	./$< do $(REDIST_DIR)
-	touch $@
-
-# Configure binutils.
-# $LD variable have to exported to override configure script caching.
-$(BINUTILS_CONFIGURED): $(REDIST_DIR)/configure $(REDIST_DETECT)
-	export LD=ld; \
-	cd $(REDIST_DIR); \
-	./configure --target=$(TARGET) $(CONF_FLAGS)
-
-# Delete binaries.
-# Clean binutils.
-# Unpatch binutils.
-# Delete everything in redist folder.
-# Delete generated scripts.
-clean: $(BINUTILS_PATCH) clean_
-	rm -f $(BIN_DIR)/as $(BIN_DIR)/ld
-	rm -f $(CONFOBJ_SOURCE) $(CONFOBJ_OBJECT)
-ifeq ($(MAINTAIN_BINUTILS),y)
-	if [ -e $(REDIST_DIR)/Makefile ]; then \
-		make -C $(REDIST_DIR) distclean; \
-	fi
-	if [ -e $(BINUTILS_PATCHED) ]; then \
-		./intrusive.sh undo $(REDIST_DIR); \
-		rm -f $(BINUTILS_PATCHED); \
-	fi
-else
-	rm -r -f redist/*
-	rm -f $(BINUTILS_PATCHED)
-endif
-	rm -f $(TOOLCHAIN)
-	rm -f $(COMMON_MAKEFILE_PATCHED)
-
Index: pace/app/binutils/distclean.sh
===================================================================
--- uspace/app/binutils/distclean.sh	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,35 +1,0 @@
-#! /bin/bash
-
-#
-# Copyright (c) 2011 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-# Delete binutils redistributable package.
-rm -f *tar.bz2
-# Delete binutils source tree.
-rm -r -f redist/*
-
Index: pace/app/binutils/intrusive.sh
===================================================================
--- uspace/app/binutils/intrusive.sh	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,209 +1,0 @@
-#! /bin/bash
-
-#
-# Copyright (c) 2011 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-#
-# This shell script is reserved for intrusive patches (hacks) to binutils
-# that cannot be done in a clean and isolated way or for which doing so 
-# would require too much complexity.
-#
-# List of patch descriptions:
-#
-# Patch 1
-# Even though binutils build process supports cross compilation where
-# build and host platforms are different, it is not easily applicable
-# to HelenOS. It would be difficult to satisfy binutils expectations
-# of host headers, libraries and tools on a build system (at least
-# until these are developed/ported). Another issue would be the 
-# necessity to carry out time consuming full canadian cross compilation
-# (even in case when build, host and target hardware platforms are the
-# same). Instead of going into such trouble, it is easier to leverage
-# already  built HelenOS toolchain as a first stage of canadian cross
-# and trick binutils scripts to do a simple cross compilation while 
-# actually doing second stage of canadian cross. Because binutils
-# configure scripts try to compile and execute various testing code, it
-# have to be ensured that these tests are skipped. Such behaviour can
-# be acomplished by patching cross compilation flag while leaving host
-# and build parameters empty (i.e. configure script believes it is
-# not doing cross compilation while skipping some testing as in the case
-# of cross compilation).
-# 
-# Patch 2
-# Enabled cross compilation flag brings along some anomalies which
-# have to reverted. 
-#
-# Patch 3
-# Binutils plugin support is dependent on libdl.so library.
-# By default, the plugin support is switched off for all
-# configure scripts of binutils. The only exception is configure
-# script of ld 2.21 (and possibly above), where plugin support
-# became mandatory (although not really needed).
-#
-# Patch 4
-# Whereas most systems maps pid_t to signed int, HelenOS maps it
-# to 64-bit unsigned integer (which is further masked by libposix to
-# 64-bit signed integer). Because libiberty blindly expects pid_t to be
-# signed int, there is some type incompatibility in libiberty
-# files related to executing a subprocess. Since both as and ld are
-# not runtime dependent on this functionality, the simplest solution is
-# to patch libiberty to avoid compiler warnings.
-#
-# Patch 5
-# When host and target system is equal, libbfd wants to compile a support
-# for core files, which is dependent on non-standard headers sys/param.h
-# and sys/user.h. Since we are cross compiling even when host and target
-# are equal, variables related to core file support must be cleared.
-#
-# Patch 6
-# There is a few occurences in binutils where POSIX function is declared 
-# and called without first including the corresponding header. Such
-# declarations cause a problem to the linker, because all functions
-# from libposix are prefixed with the posix_ prefix.
-#
-# Patch 7
-# Implementation of fnmatch inside libiberty is not very friendly to the
-# non-GNU libc which implements its own native fnmatch. To resolve this 
-# incompatibility, libiberty fnmatch has to be manually hidden.
-#
-
-case "$1" in
-	"do")
-		# Backup original files.
-		cp -f "$2/configure" "$2/configure.backup"
-		cp -f "$2/bfd/configure" "$2/bfd/configure.backup"
-		cp -f "$2/gas/configure" "$2/gas/configure.backup"
-		cp -f "$2/intl/configure" "$2/intl/configure.backup"
-		cp -f "$2/ld/configure" "$2/ld/configure.backup"
-		cp -f "$2/libiberty/configure" "$2/libiberty/configure.backup"
-		cp -f "$2/libiberty/Makefile.in" "$2/libiberty/Makefile.in.backup"
-		cp -f "$2/include/fnmatch.h" "$2/include/fnmatch.h.backup"
-		cp -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch.c.backup"
-		cp -f "$2/libiberty/pex-common.h" "$2/libiberty/pex-common.h.backup"
-		cp -f "$2/libiberty/xstrerror.c" "$2/libiberty/xstrerror.c.backup"
-		cp -f "$2/opcodes/configure" "$2/opcodes/configure.backup"
-
-		# Patch main binutils configure script.
-		cat "$2/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
-		> "$2/configure"
-
-		# Patch bfd configure script.
-		cat "$2/bfd/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
-		# See Patch 5.
-		sed 's/COREFILE=".*"/COREFILE='\'\''/g' | \
-		sed 's/COREFILE=[^ ]*/COREFILE='\'\''/g' \
-		> "$2/bfd/configure"
-
-		# Patch gas configure script.
-		cat "$2/gas/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
-		> "$2/gas/configure"
-
-		# Patch intl configure script.
-		cat "$2/intl/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
-		> "$2/intl/configure"
-
-		# Patch ld configure script.
-		cat "$2/ld/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
-		# See Patch 3.
-		sed 's/^enable_plugins=yes/enable_plugins=no/g' \
-		> "$2/ld/configure"
-
-		# Patch libiberty configure script.
-		cat "$2/libiberty/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' \
-		> "$2/libiberty/configure"
-
-		# Hide libiberty fnmatch implementation.
-		# See Patch 7.
-		mv -f "$2/include/fnmatch.h" "$2/include/fnmatch_hide.h"
-		(
-		# Avoid compiler warning for empty compilation unit.
-		echo 'char __fnmatch_hide(void);'
-		echo 'char __fnmatch_hide(void) { return 0; }'
-		echo '#define __GNU_LIBRARY__'
-		cat "$2/libiberty/fnmatch.c.backup"
-		) > "$2/libiberty/fnmatch.c"
-		mv -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch_hide.c"
-		cat "$2/libiberty/Makefile.in.backup" | \
-		sed 's/fnmatch/fnmatch_hide/g' \
-		> "$2/libiberty/Makefile.in"
-
-		# Patch libiberty pex-common.h.
-		cat "$2/libiberty/pex-common.h.backup" | \
-		# See Patch 4.
-		sed 's/pid_t (\*wait)/int (*wait)/g' \
-		> "$2/libiberty/pex-common.h"
-
-		# Patch libiberty xstrerror.c.
-		# See Patch 6.
-		(
-		echo '#include <string.h>'
-		echo '#define DONT_DECLARE_STRERROR'
-		cat "$2/libiberty/xstrerror.c.backup"
-		) > "$2/libiberty/xstrerror.c"
-
-		# Patch opcodes configure script.
-		cat "$2/opcodes/configure.backup" | \
-		# See Patch 1.
-		sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
-		# See Patch 2.
-		sed 's/BUILD_LIBS=-liberty/BUILD_LIBS=..\/libiberty\/libiberty.a/g' \
-		> "$2/opcodes/configure"
-
-		;;
-	"undo")
-		# Restore original files.
-		mv -f "$2/configure.backup" "$2/configure"
-		mv -f "$2/bfd/configure.backup" "$2/bfd/configure"
-		mv -f "$2/gas/configure.backup" "$2/gas/configure"
-		mv -f "$2/intl/configure.backup" "$2/intl/configure"
-		mv -f "$2/ld/configure.backup" "$2/ld/configure"
-		mv -f "$2/libiberty/configure.backup" "$2/libiberty/configure"
-		mv -f "$2/libiberty/Makefile.in.backup" "$2/libiberty/Makefile.in"
-		rm -f "$2/include/fnmatch_hide.h" "$2/libiberty/fnmatch_hide.c"
-		mv -f "$2/include/fnmatch.h.backup" "$2/include/fnmatch.h"
-		mv -f "$2/libiberty/fnmatch.c.backup" "$2/libiberty/fnmatch.c"
-		mv -f "$2/libiberty/pex-common.h.backup" "$2/libiberty/pex-common.h"
-		mv -f "$2/libiberty/xstrerror.c.backup" "$2/libiberty/xstrerror.c"
-		mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
-		;;
-	*)
-		;;
-esac
-
Index: pace/app/binutils/patch.awk
===================================================================
--- uspace/app/binutils/patch.awk	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#! /bin/awk -f
-
-#
-# Copyright (c) 2011 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-#
-# This script is reserved for transformation of native
-# uspace/Makefile.common so it would be compatible with ported
-# application and its operations could be intercepted.
-#
-
-# Rename 'all' target so it can be hijacked.
-/^all/ {
-	$1 = "all_:"
-}
-
-# Rename 'clean' target so it can be hijacked.
-/^clean/ {
-	$1 = "clean_:"
-}
-
-# Print rest of the lines unaltered.
-{
-	print
-}
-
Index: pace/app/binutils/toolchain.sh
===================================================================
--- uspace/app/binutils/toolchain.sh	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,167 +1,0 @@
-#! /bin/bash
-
-#
-# Copyright (c) 2011 Petr Koupy
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-# 
-# This script is intended to be called indirectly from the Makefile.
-# Given information from Makefile.common (e.g. CFLAGS), this shell
-# script generates false toolchain consisting of a short shell script
-# for each tool. Therefore, generated false tool already contains some
-# filtered information from the HelenOS side. When the actual call is
-# intercepted, information passed from the binutils side is filtered
-# and stored. Information from both sides is then joined together
-# and passed to the real tool.
-#
-# Basic idea behind filtering the information is that binutils is
-# dominant provider for the compilation, whereas HelenOS is dominant
-# for the linkage. In that way, the compilation command from binutils
-# is left untouched and only extended with a couple of flags that are
-# specific for HelenOS (i.e. include directories, preprocessor 
-# directives, preprocessor flags, standard libc exclusion). Similarly,
-# the linkage command is taken from HelenOS and extended with the
-# filtered information from binutils (i.e. output binary, objects,
-# binutils libraries).
-#
-# Most of the false tools are straightforward. However, gcc needs a 
-# special approach because binutils use it for both compilation and
-# linkage. In case the linking usage is detected, the call is redirected
-# to the linker. There is also special case for configure script tests
-# that require compiler link step.
-#
-
-case "$1" in
-	"gcc")
-		(
-		echo '#! /bin/bash'
-		echo 'AS_LINK="`echo \"$*\" | grep '\'as-new\''`"'
-		echo 'LD_LINK="`echo \"$*\" | grep '\'ld-new\''`"'
-		echo 'LINK="`echo -n "$AS_LINK""$LD_LINK"`"'
-		echo 'if [ -n "$LINK" ]; then'
-		echo '	LD_ARGS="`echo \" $*\" | \'
-		echo '		sed '\'s/ -O[^ ]*//g\'' | \'
-		echo '		sed '\'s/ -W[^ ]*//g\'' | \'
-		echo '		sed '\'s/ -g//g\'' | \'
-		echo '		sed '\'s/ -l[^ ]*//g\'' | \'
-		echo '		sed '\'s/ [ ]*/ /g\''`"'
-		echo '	ld $LD_ARGS'
-		echo 'else'
-		CFLAGS="`echo " $3" | \
-			sed 's/ -O[^ ]*//g' | \
-			sed 's/ -W[^ ]*//g' | \
-			sed 's/ -pipe//g' | \
-			sed 's/ -g//g' | \
-			sed 's/ [ ]*/ /g'`"
-		echo '	CONFTEST="`echo \"$*\" | grep '\' conftest \''`"'
-		echo '	if [ -n "$CONFTEST" ]; then'
-		echo '		LFLAGS="-Xlinker -z -Xlinker muldefs"'
-		echo '		echo' \'"$2"\' '"$@"' \'"$CFLAGS -T $4"\' '"$LFLAGS"' \'"$5"\'
-		echo "		$2" '$@' "$CFLAGS -T $4" '$LFLAGS' "$5"
-		echo '	else'
-					# Remove flags:
-					# -Werror
-					#		Avoid build failure due to some harmless bugs
-					#		(e.g. unused parameter) in the HelenOS.
-					# -Wc++-compat
-					#		Required just for gold linker.
-		echo '		GCC_ARGS="`echo \" $*\" | \'
-		echo '			sed '\'s/ -Werror//g\'' | \'
-		echo '			sed '\'s/ -Wc++-compat//g\'' | \'
-		echo '			sed '\'s/ [ ]*/ /g\''`"'
-					# Add flags:
-					# -Wno-shadow
-					#		Silents the warning caused by 
-					#		harmless bug in ld/ldlang.h and ld/ldlex.c.
-#		echo '		GCC_ARGS="$GCC_ARGS -Wno-shadow"'
-		echo '		echo' \'"$2"\' '"$GCC_ARGS"' \'"$CFLAGS"\'
-		echo "		$2" '$GCC_ARGS' "$CFLAGS"
-		echo '	fi'
-		echo 'fi'
-		) > 'gcc'
-		chmod a+x 'gcc'
-		;;
-	"as")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2"\' '"$@"'
-		echo "$2" '$@'
-		) > 'as'
-		chmod a+x 'as'
-		;;
-	"ar")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2"\' '"$@"'
-		echo "$2" '$@'
-		) > 'ar'
-		chmod a+x 'ar'
-		;;
-	"ranlib")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' 'ar -s' '"$@"'
-		echo 'ar -s' '$@'
-		) > 'ranlib'
-		chmod a+x 'ranlib'
-		;;
-	"ld")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2 -n $3 -T $4"\' '"$@"' \'"$5"\'
-		echo "$2 -n $3 -T $4" '$@' "$5"
-		) > 'ld'
-		chmod a+x 'ld'
-		;;
-	"objdump")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2"\' '"$@"'
-		echo "$2" '$@'
-		) > 'objdump'
-		chmod a+x 'objdump'
-		;;
-	"objcopy")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2"\' '"$@"'
-		echo "$2" '$@'
-		) > 'objcopy'
-		chmod a+x 'objcopy'
-		;;
-	"strip")
-		(
-		echo '#! /bin/bash'
-		echo 'echo' \'"$2"\' '"$@"'
-		echo "$2" '$@'
-		) > 'strip'
-		chmod a+x 'strip'
-		;;
-	*)
-		;;
-esac
-
Index: uspace/app/tetris/tetris.c
===================================================================
--- uspace/app/tetris/tetris.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ uspace/app/tetris/tetris.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -291,5 +291,5 @@
 		for (j = i + 1; j <= 5; j++) {
 			if (keys[i] == keys[j])
-				errx(1, "%s", "duplicate command keys specified.");
+				errx(1, "duplicate command keys specified.");
 		}
 		
Index: pace/dist/src/c/demos/hello/build
===================================================================
--- uspace/dist/src/c/demos/hello/build	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,4 +1,0 @@
-cc -E -o hello.i hello.c
-cc -S -o hello.s hello.i
-as -o hello.o hello.s
-ld -T /inc/_link.ld -o hello hello.o /lib/libc.a /lib/libsoftint.a
Index: pace/dist/src/c/demos/hello/clean
===================================================================
--- uspace/dist/src/c/demos/hello/clean	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,4 +1,0 @@
-rm hello
-rm hello.o
-rm hello.s
-rm hello.i
Index: pace/dist/src/c/demos/hello/hello.c
===================================================================
--- uspace/dist/src/c/demos/hello/hello.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,16 +1,0 @@
-extern int putchar(char);
-
-#define TERMINATOR '!'
-
-int main(void) {
-	/* Prints "hello" to the standard output. */
-	putchar('h');
-	putchar('e');
-	putchar('l');
-	putchar('l');
-	putchar('o');
-	putchar(TERMINATOR);
-	putchar('\n');
-	return 0;
-}
-
Index: pace/dist/src/c/demos/tetris/build
===================================================================
--- uspace/dist/src/c/demos/tetris/build	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,16 +1,0 @@
-cc -I/inc/c -E -o scores.i scores.c
-cc -I/inc/c -E -o screen.i screen.c
-cc -I/inc/c -E -o shapes.i shapes.c
-cc -I/inc/c -E -o tetris.i tetris.c
-
-cc -S -o scores.s scores.i
-cc -S -o screen.s screen.i
-cc -S -o shapes.s shapes.i
-cc -S -o tetris.s tetris.i
-
-as -o scores.o scores.s
-as -o screen.o screen.s
-as -o shapes.o shapes.s
-as -o tetris.o tetris.s
-
-ld -T /inc/_link.ld -o tetris_ scores.o screen.o shapes.o tetris.o /lib/libc.a /lib/libsoftint.a
Index: pace/dist/src/c/demos/tetris/clean
===================================================================
--- uspace/dist/src/c/demos/tetris/clean	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,16 +1,0 @@
-rm tetris_
-
-rm scores.o
-rm screen.o
-rm shapes.o
-rm tetris.o
-
-rm scores.s
-rm screen.s
-rm shapes.s
-rm tetris.s
-
-rm scores.i
-rm screen.i
-rm shapes.i
-rm tetris.i
Index: pace/dist/src/c/demos/tetris/scores.c
===================================================================
--- uspace/dist/src/c/demos/tetris/scores.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,240 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * scores.c 8.1 (Berkeley) 5/31/93
- * NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd
- * OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * Score code for Tetris, by Darren Provine (kilroy@gboro.glassboro.edu)
- * modified 22 January 1992, to limit the number of entries any one
- * person has.
- *
- * Major whacks since then.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <str.h>
-#include <io/console.h>
-#include <io/keycode.h>
-#include <vfs/vfs.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <err.h>
-#include <time.h>
-#include "screen.h"
-#include "tetris.h"
-#include "scores.h"
-
-/*
- * Within this code, we can hang onto one extra "high score", leaving
- * room for our current score (whether or not it is high).
- *
- * We also sometimes keep tabs on the "highest" score on each level.
- * As long as the scores are kept sorted, this is simply the first one at
- * that level.
- */
-
-#define NUMSPOTS  (MAXHISCORES + 1)
-#define NLEVELS   (MAXLEVEL + 1)
-
-static struct highscore scores[NUMSPOTS];
-
-/** Copy from hiscore table score with index src to dest
- *
- */
-static void copyhiscore(int dest, int src)
-{
-	str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1,
-	    scores[src].hs_name);
-	scores[dest].hs_score = scores[src].hs_score;
-	scores[dest].hs_level = scores[src].hs_level;
-}
-
-void showscores(int firstgame)
-{
-	int i;
-	
-	clear_screen();
-	moveto(10, 0);
-	printf("\tRank \tLevel \tName\t                     points\n");
-	printf("\t========================================================\n");
-	
-	for (i = 0; i < NUMSPOTS - 1; i++)
-		printf("\t%6d %6d %-16s %20d\n",
-		    i + 1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score);
-	
-	if (!firstgame) {
-		printf("\t========================================================\n");
-		printf("\t  Last %6d %-16s %20d\n",
-		    scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score);
-	}
-	
-	printf("\n\n\n\n\tPress any key to return to main menu.");
-	getchar();
-}
-
-void insertscore(int score, int level)
-{
-	int i;
-	int j;
-	size_t off;
-	kbd_event_t ev;
-	
-	clear_screen();
-	moveto(10, 10);
-	puts("Insert your name: ");
-	str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1,
-	    "Player");
-	i = 6;
-	off = 6;
-	
-	moveto(10 , 28);
-	printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME-i,
-	    "........................................");
-	
-	while (1) {
-		console_flush(console);
-		if (!console_get_kbd_event(console, &ev))
-			exit(1);
-		
-		if (ev.type == KEY_RELEASE)
-			continue;
-		
-		if (ev.key == KC_ENTER || ev.key == KC_NENTER)
-			break;
-		
-		if (ev.key == KC_BACKSPACE) {
-			if (i > 0) {
-				wchar_t uc;
-				
-				--i;
-				while (off > 0) {
-					--off;
-					size_t otmp = off;
-					uc = str_decode(scores[NUMSPOTS - 1].hs_name,
-					    &otmp, STR_BOUNDS(MAXLOGNAME) + 1);
-					if (uc != U_SPECIAL)
-						break;
-				}
-				
-				scores[NUMSPOTS - 1].hs_name[off] = '\0';
-			}
-		} else if (ev.c != '\0') {
-			if (i < (MAXLOGNAME - 1)) {
-				if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name,
-				    &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) {
-					++i;
-				}
-				scores[NUMSPOTS - 1].hs_name[off] = '\0';
-			}
-		}
-		
-		moveto(10, 28);
-		printf("%s%.*s", scores[NUMSPOTS - 1].hs_name, MAXLOGNAME - i,
-		    "........................................");
-	}
-	
-	scores[NUMSPOTS - 1].hs_score = score;
-	scores[NUMSPOTS - 1].hs_level = level;
-	
-	i = NUMSPOTS - 1;
-	while ((i > 0) && (scores[i - 1].hs_score < score))
-		i--;
-	
-	for (j = NUMSPOTS - 2; j > i; j--)
-		copyhiscore(j, j-1);
-	
-	copyhiscore(i, NUMSPOTS - 1);
-}
-
-void initscores(void)
-{
-	int i;
-	for (i = 0; i < NUMSPOTS; i++) {
-		str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team");
-		scores[i].hs_score = (NUMSPOTS - i) * 200;
-		scores[i].hs_level = (i + 1 > MAXLEVEL ? MAXLEVEL : i + 1);
-	}
-}
-
-int loadscores(void)
-{
-	FILE *f;
-	size_t cnt;
-	int rc;
-
-	f = fopen("/data/tetris.sco", "rb");
-	if (f == NULL)
-		return ENOENT;
-
-	cnt = fread(scores, sizeof(struct highscore), NUMSPOTS, f);
-	rc = fclose(f);
-
-	if (cnt != NUMSPOTS || rc != 0)
-		return EIO;
-
-	return EOK;
-}
-
-void savescores(void)
-{
-	FILE *f;
-	size_t cnt;
-	int rc;
-
-	f = fopen("/data/tetris.sco", "wb");
-	cnt = fwrite(scores, sizeof(struct highscore), NUMSPOTS, f);
-	rc = fclose(f);
-
-	if (cnt != NUMSPOTS || rc != 0)
-		printf("Error saving score table\n");
-}
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/scores.h
===================================================================
--- uspace/dist/src/c/demos/tetris/scores.h	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * scores.h 8.1 (Berkeley) 5/31/93
- * NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd
- * OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * Tetris scores.
- */
-
-#include <sys/time.h>
-#include <str.h>
-
-#define MAXLOGNAME   16
-#define MAXHISCORES  10
-#define MAXSCORES    9  /* maximum high score entries per person */
-#define EXPIRATION   (5L * 365 * 24 * 60 * 60)
-
-struct highscore {
-	char hs_name[STR_BOUNDS(MAXLOGNAME) + 1];  /* login name */
-	int hs_score;                              /* raw score */
-	int hs_level;                              /* play level */
-	time_t hs_time;                            /* time at game end */
-};
-
-extern void showscores(int);
-extern void initscores(void);
-extern void insertscore(int score, int level);
-extern int loadscores(void);
-extern void savescores(void);
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/screen.c
===================================================================
--- uspace/dist/src/c/demos/tetris/screen.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,413 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * screen.c 8.1 (Berkeley) 5/31/93
- * NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft
- * OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * Tetris screen control.
- */
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <str.h>
-#include <unistd.h>
-#include <vfs/vfs.h>
-#include <async.h>
-#include <bool.h>
-#include <io/console.h>
-#include <io/style.h>
-#include "screen.h"
-#include "tetris.h"
-
-#define STOP  (B_COLS - 3)
-
-static cell curscreen[B_SIZE];  /* non-zero => standout (or otherwise marked) */
-static int curscore;
-static int isset;               /* true => terminal is in game mode */
-
-static bool use_color;          /* true => use colors */
-
-static const struct shape *lastshape;
-
-static suseconds_t timeleft = 0;
-
-console_ctrl_t *console;
-
-
-/*
- * putstr() is for unpadded strings (either as in termcap(5) or
- * simply literal strings);
- */
-static inline void putstr(const char *s)
-{
-	while (*s)
-		putchar(*(s++));
-}
-
-static void start_standout(uint32_t color)
-{
-	console_flush(console);
-	console_set_rgb_color(console, 0xffffff,
-	    use_color ? color : 0x000000);
-}
-
-static void resume_normal(void)
-{
-	console_flush(console);
-	console_set_style(console, STYLE_NORMAL);
-}
-
-void clear_screen(void)
-{
-	console_clear(console);
-	moveto(0, 0);
-}
-
-/*
- * Clear the screen, forgetting the current contents in the process.
- */
-void scr_clear(void)
-{
-	resume_normal();
-	console_clear(console);
-	curscore = -1;
-	memset(curscreen, 0, sizeof(curscreen));
-}
-
-/*
- * Set up screen
- */
-void scr_init(void)
-{
-	console_cursor_visibility(console, 0);
-	resume_normal();
-	scr_clear();
-}
-
-void moveto(sysarg_t r, sysarg_t c)
-{
-	console_flush(console);
-	console_set_pos(console, c, r);
-}
-
-winsize_t winsize;
-
-static int get_display_size(winsize_t *ws)
-{
-	return console_get_size(console, &ws->ws_col, &ws->ws_row);
-}
-
-static bool get_display_color_sup(void)
-{
-	sysarg_t ccap;
-	int rc = console_get_color_cap(console, &ccap);
-	
-	if (rc != 0)
-		return false;
-	
-	return (ccap >= CONSOLE_CCAP_RGB);
-}
-
-/*
- * Set up screen mode.
- */
-void scr_set(void)
-{
-	winsize_t ws;
-	
-	Rows = 0;
-	Cols = 0;
-	
-	if (get_display_size(&ws) == 0) {
-		Rows = ws.ws_row;
-		Cols = ws.ws_col;
-	}
-
-	use_color = get_display_color_sup();
-	
-	if ((Rows < MINROWS) || (Cols < MINCOLS)) {
-		char smallscr[55];
-		
-		snprintf(smallscr, sizeof(smallscr),
-		    "the screen is too small (must be at least %dx%d)",
-		    MINROWS, MINCOLS);
-		stop(smallscr);
-	}
-	isset = 1;
-	
-	scr_clear();
-}
-
-/*
- * End screen mode.
- */
-void scr_end(void)
-{
-	console_cursor_visibility(console, 1);
-}
-
-void stop(const char *why)
-{
-	if (isset)
-		scr_end();
-	
-	errx(1, "aborting: %s", why);
-}
-
-/*
- * Update the screen.
- */
-void scr_update(void)
-{
-	cell *bp;
-	cell *sp;
-	cell so;
-	cell cur_so = 0;
-	int i;
-	int j;
-	int ccol;
-	
-	/* Always leave cursor after last displayed point */
-	curscreen[D_LAST * B_COLS - 1] = -1;
-	
-	if (score != curscore) {
-		moveto(0, 0);
-		printf("Score: %d", score);
-		curscore = score;
-	}
-	
-	/* Draw preview of next pattern */
-	if ((showpreview) && (nextshape != lastshape)) {
-		int i;
-		static int r = 5, c = 2;
-		int tr, tc, t;
-		
-		lastshape = nextshape;
-		
-		/* Clean */
-		resume_normal();
-		moveto(r - 1, c - 1);
-		putstr("          ");
-		moveto(r, c - 1);
-		putstr("          ");
-		moveto(r + 1, c - 1);
-		putstr("          ");
-		moveto(r + 2, c - 1);
-		putstr("          ");
-		
-		moveto(r - 3, c - 2);
-		putstr("Next shape:");
-		
-		/* Draw */
-		start_standout(nextshape->color);
-		moveto(r, 2 * c);
-		putstr("  ");
-		for (i = 0; i < 3; i++) {
-			t = c + r * B_COLS;
-			t += nextshape->off[i];
-			
-			tr = t / B_COLS;
-			tc = t % B_COLS;
-			
-			moveto(tr, 2*tc);
-			putstr("  ");
-		}
-		resume_normal();
-	}
-	
-	bp = &board[D_FIRST * B_COLS];
-	sp = &curscreen[D_FIRST * B_COLS];
-	for (j = D_FIRST; j < D_LAST; j++) {
-		ccol = -1;
-		for (i = 0; i < B_COLS; bp++, sp++, i++) {
-			if (*sp == (so = *bp))
-				continue;
-			
-			*sp = so;
-			if (i != ccol) {
-				if (cur_so) {
-					resume_normal();
-					cur_so = 0;
-				}
-				moveto(RTOD(j), CTOD(i));
-			}
-			
-			if (so != cur_so) {
-				if (so)
-					start_standout(so);
-				else
-					resume_normal();
-				cur_so = so;
-			}
-			putstr("  ");
-			
-			ccol = i + 1;
-			/*
-			 * Look ahead a bit, to avoid extra motion if
-			 * we will be redrawing the cell after the next.
-			 * Motion probably takes four or more characters,
-			 * so we save even if we rewrite two cells
-			 * `unnecessarily'.  Skip it all, though, if
-			 * the next cell is a different color.
-			 */
-			
-			if ((i > STOP) || (sp[1] != bp[1]) || (so != bp[1]))
-				continue;
-			
-			if (sp[2] != bp[2])
-				sp[1] = -1;
-			else if ((i < STOP) && (so == bp[2]) && (sp[3] != bp[3])) {
-				sp[2] = -1;
-				sp[1] = -1;
-			}
-		}
-	}
-	
-	if (cur_so)
-		resume_normal();
-	
-	console_flush(console);
-}
-
-/*
- * Write a message (set != 0), or clear the same message (set == 0).
- * (We need its length in case we have to overwrite with blanks.)
- */
-void scr_msg(char *s, bool set)
-{
-	int l = str_size(s);
-	
-	moveto(Rows - 2, ((Cols - l) >> 1) - 1);
-	
-	if (set)
-		putstr(s);
-	else
-		while (--l >= 0)
-			(void) putchar(' ');
-}
-
-/** Sleep for the current turn time
- *
- * Eat any input that might be available.
- *
- */
-void tsleep(void)
-{
-	suseconds_t timeout = fallrate;
-	
-	while (timeout > 0) {
-		kbd_event_t event;
-		
-		if (!console_get_kbd_event_timeout(console, &event, &timeout))
-			break;
-	}
-}
-
-/** Get char with timeout
- *
- */
-int tgetchar(void)
-{
-	/*
-	 * Reset timeleft to fallrate whenever it is not positive
-	 * and increase speed.
-	 */
-	
-	if (timeleft <= 0) {
-		faster();
-		timeleft = fallrate;
-	}
-	
-	/*
-	 * Wait to see if there is any input. If so, take it and
-	 * update timeleft so that the next call to tgetchar()
-	 * will not wait as long. If there is no input,
-	 * make timeleft zero and return -1.
-	 */
-	
-	wchar_t c = 0;
-	
-	while (c == 0) {
-		kbd_event_t event;
-		
-		if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
-			timeleft = 0;
-			return -1;
-		}
-		
-		if (event.type == KEY_PRESS)
-			c = event.c;
-	}
-	
-	return (int) c;
-}
-
-/** Get char without timeout
- *
- */
-int twait(void)
-{
-	wchar_t c = 0;
-	
-	while (c == 0) {
-		kbd_event_t event;
-		
-		if (!console_get_kbd_event(console, &event))
-			return -1;
-		
-		if (event.type == KEY_PRESS)
-			c = event.c;
-	}
-	
-	return (int) c;
-}
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/screen.h
===================================================================
--- uspace/dist/src/c/demos/tetris/screen.h	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,86 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * screen.h 8.1 (Berkeley) 5/31/93
- * NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd
- * OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * putpad() is for padded strings with count = 1.
- */
-#define putpad(s)  tputs(s, 1, put)
-
-#include <sys/types.h>
-#include <io/console.h>
-#include <async.h>
-#include <bool.h>
-
-typedef struct {
-	sysarg_t ws_row;
-	sysarg_t ws_col;
-} winsize_t;
-
-extern console_ctrl_t *console;
-extern winsize_t winsize;
-
-extern void moveto(sysarg_t r, sysarg_t c);
-extern void clear_screen(void);
-
-extern int put(int);
-extern void scr_clear(void);
-extern void scr_end(void);
-extern void scr_init(void);
-extern void scr_msg(char *, bool);
-extern void scr_set(void);
-extern void scr_update(void);
-
-extern void tsleep(void);
-extern int tgetchar(void);
-extern int twait(void);
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/shapes.c
===================================================================
--- uspace/dist/src/c/demos/tetris/shapes.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * shapes.c 8.1 (Berkeley) 5/31/93
- * NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd
- * OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * Tetris shapes and related routines.
- *
- * Note that the first 7 are `well known'.
- */
-
-#include <unistd.h>
-#include "tetris.h"
-
-#define TL  (-B_COLS - 1)  /* top left */
-#define TC  (-B_COLS)      /* top center */
-#define TR  (-B_COLS + 1)  /* top right */
-#define ML  -1             /* middle left */
-#define MR  1              /* middle right */
-#define BL  (B_COLS - 1)   /* bottom left */
-#define BC  B_COLS         /* bottom center */
-#define BR  (B_COLS + 1)   /* bottom right */
-
-const struct shape shapes[] = {
-	/*  0 */  {  7,  7, { TL, TC, MR }, 0xff042d},
-	/*  1 */  {  8,  8, { TC, TR, ML }, 0xff9304},
-	/*  2 */  {  9, 11, { ML, MR, BC }, 0xbeff04},
-	/*  3 */  {  3,  3, { TL, TC, ML }, 0x63ff04},
-	/*  4 */  { 12, 14, { ML, BL, MR }, 0xce04ff},
-	/*  5 */  { 15, 17, { ML, BR, MR }, 0xff04cf},
-	/*  6 */  { 18, 18, { ML, MR, 2  }, 0x7604ff},  /* sticks out */
-	/*  7 */  {  0,  0, { TC, ML, BL }, 0xff042d},
-	/*  8 */  {  1,  1, { TC, MR, BR }, 0xff9304},
-	/*  9 */  { 10,  2, { TC, MR, BC }, 0xbeff04},
-	/* 10 */  { 11,  9, { TC, ML, MR }, 0xbeff04},
-	/* 11 */  {  2, 10, { TC, ML, BC }, 0xbeff04},
-	/* 12 */  { 13,  4, { TC, BC, BR }, 0xce04ff},
-	/* 13 */  { 14, 12, { TR, ML, MR }, 0xce04ff},
-	/* 14 */  {  4, 13, { TL, TC, BC }, 0xce04ff},
-	/* 15 */  { 16,  5, { TR, TC, BC }, 0xff04cf},
-	/* 16 */  { 17, 15, { TL, MR, ML }, 0xff04cf},
-	/* 17 */  {  5, 16, { TC, BC, BL }, 0xff04cf},
-	/* 18 */  {  6,  6, { TC, BC, 2 * B_COLS }, 0x7604ff}  /* sticks out */
-};
-
-/*
- * Return true iff the given shape fits in the given position,
- * taking the current board into account.
- */
-int fits_in(const struct shape *shape, int pos)
-{
-	const int *o = shape->off;
-	
-	if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) ||
-	    (board[pos + *o]))
-		return 0;
-	
-	return 1;
-}
-
-/*
- * Write the given shape into the current board, turning it on
- * if `onoff' is 1, and off if `onoff' is 0.
- */
-void place(const struct shape *shape, int pos, int onoff)
-{
-	const int *o = shape->off;
-	
-	board[pos] = onoff ? shape->color : 0x000000;
-	board[pos + *o++] = onoff ? shape->color : 0x000000;
-	board[pos + *o++] = onoff ? shape->color : 0x000000;
-	board[pos + *o] = onoff ? shape->color : 0x000000;
-}
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/tetris.c
===================================================================
--- uspace/dist/src/c/demos/tetris/tetris.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,450 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * tetris.c 8.1 (Berkeley) 5/31/93
- * NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd
- * OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris Tetris
- * @brief Tetris ported from OpenBSD
- * @{
- */
-/** @file
- */
-
-static const char copyright[] =
-	"@(#) Copyright (c) 1992, 1993\n"
-	"\tThe Regents of the University of California.  All rights reserved.\n";
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <str.h>
-#include <unistd.h>
-#include <getopt.h>
-#include "scores.h"
-#include "screen.h"
-#include "tetris.h"
-
-cell board[B_SIZE];
-
-int Rows;
-int Cols;
-
-const struct shape *curshape;
-const struct shape *nextshape;
-
-long fallrate;
-int score;
-char key_msg[100];
-int showpreview;
-int classic;
-
-static void elide(void);
-static void setup_board(void);
-static const struct shape *randshape(void);
-
-static void usage(void);
-
-static int firstgame = 1;
-
-/*
- * Set up the initial board. The bottom display row is completely set,
- * along with another (hidden) row underneath that. Also, the left and
- * right edges are set.
- */
-static void setup_board(void)
-{
-	int i;
-	cell *p = board;
-	
-	for (i = B_SIZE; i; i--)
-		*p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000;
-}
-
-/*
- * Elide any full active rows.
- */
-static void elide(void)
-{
-	int rows = 0;
-	int i;
-	int j;
-	int base;
-	cell *p;
-	
-	for (i = A_FIRST; i < A_LAST; i++) {
-		base = i * B_COLS + 1;
-		p = &board[base];
-		for (j = B_COLS - 2; *p++ != 0;) {
-			if (--j <= 0) {
-				/* This row is to be elided */
-				rows++;
-				memset(&board[base], 0, sizeof(cell) * (B_COLS - 2));
-				
-				scr_update();
-				tsleep();
-				
-				while (--base != 0)
-					board[base + B_COLS] = board[base];
-				
-				scr_update();
-				tsleep();
-				
-				break;
-			}
-		}
-	}
-	
-	switch (rows) {
-	case 1:
-		score += 10;
-		break;
-	case 2:
-		score += 30;
-		break;
-	case 3:
-		score += 70;
-		break;
-	case 4:
-		score += 150;
-		break;
-	default:
-		break;
-	}
-}
-
-const struct shape *randshape(void)
-{
-	const struct shape *tmp = &shapes[random() % 7];
-	int i;
-	int j = random() % 4;
-	
-	for (i = 0; i < j; i++)
-		tmp = &shapes[classic ? tmp->rotc : tmp->rot];
-	
-	return (tmp);
-}
-
-static void srandomdev(void)
-{
-	struct timeval tv;
-	
-	gettimeofday(&tv, NULL);
-	srandom(tv.tv_sec + tv.tv_usec / 100000);
-}
-
-static void tetris_menu_draw(int level) 
-{
-	clear_screen();
-	moveto(5, 10);
-	puts("Tetris\n\n");
-	
-	moveto(8, 10);
-	printf("Level = %d (press keys 1 - 9 to change)", level);
-	moveto(9, 10);
-	printf("Preview is %s (press 'p' to change)", (showpreview ? "on ": "off"));
-	moveto(12, 10);
-	printf("Press 'h' to show hiscore table.");
-	moveto(13, 10);
-	printf("Press 's' to start game.");
-	moveto(14, 10);
-	printf("Press 'q' to quit game.");
-	moveto(20, 10);
-	printf("In game controls:");
-	moveto(21, 0);
-	puts(key_msg);
-}
-
-static int tetris_menu(int *level)
-{
-	tetris_menu_draw(*level);
-	while (1) {
-		int i = getchar();
-		
-		switch(i) {
-			case 'p':
-				showpreview = !showpreview;
-				moveto(9, 21);
-				if (showpreview)
-					printf("on ");
-				else
-					printf("off");
-				break;
-			case 'h':
-				loadscores();
-				showscores(firstgame);
-				tetris_menu_draw(*level);
-				break;
-			case 's':
-				firstgame = 0;
-				return 1;
-			case 'q':
-				return 0;
-			case '1':
-			case '2':
-			case '3':
-			case '4':
-			case '5':
-			case '6':
-			case '7':
-			case '8':
-			case '9':
-				*level = i - '0';
-				moveto(8, 18);
-				printf("%d", *level);
-				break;
-		}
-	}
-}
-
-int main(int argc, char *argv[])
-{
-	int pos;
-	int c;
-	const char *keys;
-	int level = 2;
-	char key_write[6][10];
-	int i;
-	int j;
-	int ch;
-	
-	console = console_init(stdin, stdout);
-	
-	keys = "jkl pq";
-	
-	classic = 0;
-	showpreview = 1;
-	
-	while ((ch = getopt(argc, argv, "ck:ps")) != -1)
-		switch(ch) {
-		case 'c':
-			/*
-			 * this means:
-			 *  - rotate the other way
-			 *  - no reverse video
-			 */
-			classic = 1;
-			break;
-		case 'k':
-			if (str_size(keys = optarg) != 6)
-				usage();
-			break;
-		case 'p':
-			showpreview = 1;
-			break;
-		case 's':
-			showscores(0);
-			exit(0);
-		default:
-			usage();
-		}
-	
-	argc -= optind;
-	argv += optind;
-	
-	if (argc)
-		usage();
-	
-	for (i = 0; i <= 5; i++) {
-		for (j = i + 1; j <= 5; j++) {
-			if (keys[i] == keys[j])
-				errx(1, "%s", "duplicate command keys specified.");
-		}
-		
-		if (keys[i] == ' ')
-			str_cpy(key_write[i], sizeof(key_write[i]), "<space>");
-		else {
-			key_write[i][0] = keys[i];
-			key_write[i][1] = '\0';
-		}
-	}
-	
-	snprintf(key_msg, sizeof(key_msg),
-	    "%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
-	    key_write[0], key_write[1], key_write[2], key_write[3],
-	    key_write[4], key_write[5]);
-	
-	scr_init();
-	if (loadscores() != EOK)
-		initscores();
-
-	while (tetris_menu(&level)) {
-		fallrate = 1000000 / level;
-		
-		scr_clear();
-		setup_board();
-		
-		srandomdev();
-		scr_set();
-		
-		pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
-		nextshape = randshape();
-		curshape = randshape();
-		
-		scr_msg(key_msg, 1);
-		
-		while (1) {
-			place(curshape, pos, 1);
-			scr_update();
-			place(curshape, pos, 0);
-			c = tgetchar();
-			if (c < 0) {
-				/*
-				 * Timeout.  Move down if possible.
-				 */
-				if (fits_in(curshape, pos + B_COLS)) {
-					pos += B_COLS;
-					continue;
-				}
-				
-				/*
-				 * Put up the current shape `permanently',
-				 * bump score, and elide any full rows.
-				 */
-				place(curshape, pos, 1);
-				score++;
-				elide();
-				
-				/*
-				 * Choose a new shape.  If it does not fit,
-				 * the game is over.
-				 */
-				curshape = nextshape;
-				nextshape = randshape();
-				pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
-				
-				if (!fits_in(curshape, pos))
-					break;
-				
-				continue;
-			}
-			
-			/*
-			 * Handle command keys.
-			 */
-			if (c == keys[5]) {
-				/* quit */
-				break;
-			}
-			
-			if (c == keys[4]) {
-				static char msg[] =
-				    "paused - press RETURN to continue";
-				
-				place(curshape, pos, 1);
-				do {
-					scr_update();
-					scr_msg(key_msg, 0);
-					scr_msg(msg, 1);
-					console_flush(console);
-				} while (!twait());
-				
-				scr_msg(msg, 0);
-				scr_msg(key_msg, 1);
-				place(curshape, pos, 0);
-				continue;
-			}
-			
-			if (c == keys[0]) {
-				/* move left */
-				if (fits_in(curshape, pos - 1))
-					pos--;
-				continue;
-			}
-			
-			if (c == keys[1]) {
-				/* turn */
-				const struct shape *new =
-				    &shapes[classic ? curshape->rotc : curshape->rot];
-				
-				if (fits_in(new, pos))
-					curshape = new;
-				continue;
-			}
-			
-			if (c == keys[2]) {
-				/* move right */
-				if (fits_in(curshape, pos + 1))
-					pos++;
-				continue;
-			}
-			
-			if (c == keys[3]) {
-				/* move to bottom */
-				while (fits_in(curshape, pos + B_COLS)) {
-					pos += B_COLS;
-					score++;
-				}
-				continue;
-			}
-			
-			if (c == '\f') {
-				scr_clear();
-				scr_msg(key_msg, 1);
-			}
-		}
-		
-		scr_clear();
-		loadscores();
-		insertscore(score, level);
-		savescores();
-		score = 0;
-	}
-	
-	scr_clear();
-	printf("\nGame over.\n");
-	scr_end();
-	
-	return 0;
-}
-
-void usage(void)
-{
-	fprintf(stderr, "usage: tetris [-ps] [-k keys]\n");
-	exit(1);
-}
-
-/** @}
- */
Index: pace/dist/src/c/demos/tetris/tetris.h
===================================================================
--- uspace/dist/src/c/demos/tetris/tetris.h	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ 	(revision )
@@ -1,199 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** Attributations
- *
- * tetris.h 8.1 (Berkeley) 5/31/93
- * NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd
- * OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert
- *
- * Based upon BSD Tetris
- *
- * Copyright (c) 1992, 1993
- *      The Regents of the University of California.
- *      Distributed under BSD license.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek and Darren F. Provine.
- *
- */
-
-/** @addtogroup tetris
- * @{
- */
-/** @file
- */
-
-/*
- * Definitions for Tetris.
- */
-
-/*
- * The display (`board') is composed of 23 rows of 12 columns of characters
- * (numbered 0..22 and 0..11), stored in a single array for convenience.
- * Columns 1 to 10 of rows 1 to 20 are the actual playing area, where
- * shapes appear.  Columns 0 and 11 are always occupied, as are all
- * columns of rows 21 and 22.  Rows 0 and 22 exist as boundary areas
- * so that regions `outside' the visible area can be examined without
- * worrying about addressing problems.
- */
-
-/* The board */
-#define B_COLS  12
-#define B_ROWS  23
-#define B_SIZE  (B_ROWS * B_COLS)
-
-typedef uint32_t cell;
-
-extern cell board[B_SIZE];  /* 1 => occupied, 0 => empty */
-
-/* The displayed area (rows) */
-#define D_FIRST  1
-#define D_LAST   22
-
-/* The active area (rows) */
-#define A_FIRST  1
-#define A_LAST   21
-
-/*
- * Minimum display size.
- */
-#define MINROWS  23
-#define MINCOLS  40
-
-/* Current screen size */
-extern int Rows;
-extern int Cols;
-
-/*
- * Translations from board coordinates to display coordinates.
- * As with board coordinates, display coordiates are zero origin.
- */
-#define RTOD(x)  ((x) - 1)
-#define CTOD(x)  ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1))
-
-/*
- * A `shape' is the fundamental thing that makes up the game.  There
- * are 7 basic shapes, each consisting of four `blots':
- *
- *      X.X       X.X           X.X
- *        X.X   X.X     X.X.X   X.X     X.X.X   X.X.X   X.X.X.X
- *                        X             X           X
- *
- *          0     1       2       3       4       5       6
- *
- * Except for 3 and 6, the center of each shape is one of the blots.
- * This blot is designated (0, 0).  The other three blots can then be
- * described as offsets from the center.  Shape 3 is the same under
- * rotation, so its center is effectively irrelevant; it has been chosen
- * so that it `sticks out' upward and leftward.  Except for shape 6,
- * all the blots are contained in a box going from (-1, -1) to (+1, +1);
- * shape 6's center `wobbles' as it rotates, so that while it `sticks out'
- * rightward, its rotation---a vertical line---`sticks out' downward.
- * The containment box has to include the offset (2, 0), making the overall
- * containment box range from offset (-1, -1) to (+2, +1).  (This is why
- * there is only one row above, but two rows below, the display area.)
- *
- * The game works by choosing one of these shapes at random and putting
- * its center at the middle of the first display row (row 1, column 5).
- * The shape is moved steadily downward until it collides with something:
- * either  another shape, or the bottom of the board.  When the shape can
- * no longer be moved downwards, it is merged into the current board.
- * At this time, any completely filled rows are elided, and blots above
- * these rows move down to make more room.  A new random shape is again
- * introduced at the top of the board, and the whole process repeats.
- * The game ends when the new shape will not fit at (1, 5).
- *
- * While the shapes are falling, the user can rotate them counterclockwise
- * 90 degrees (in addition to moving them left or right), provided that the
- * rotation puts the blots in empty spaces.  The table of shapes is set up
- * so that each shape contains the index of the new shape obtained by
- * rotating the current shape.  Due to symmetry, each shape has exactly
- * 1, 2, or 4 rotations total; the first 7 entries in the table represent
- * the primary shapes, and the remaining 12 represent their various
- * rotated forms.
- */
-struct shape {
-	int rot;     /* index of rotated version of this shape */
-	int rotc;    /* -- " -- in classic version  */
-	int off[3];  /* offsets to other blots if center is at (0,0) */
-	uint32_t color;
-};
-
-extern const struct shape shapes[];
-
-extern const struct shape *curshape;
-extern const struct shape *nextshape;
-
-/*
- * Shapes fall at a rate faster than once per second.
- *
- * The initial rate is determined by dividing 1 million microseconds
- * by the game `level'.  (This is at most 1 million, or one second.)
- * Each time the fall-rate is used, it is decreased a little bit,
- * depending on its current value, via the `faster' macro below.
- * The value eventually reaches a limit, and things stop going faster,
- * but by then the game is utterly impossible.
- */
-extern long fallrate;  /* less than 1 million; smaller => faster */
-
-#define faster()  (fallrate -= fallrate / 3000)
-
-/*
- * Game level must be between 1 and 9.  This controls the initial fall rate
- * and affects scoring.
- */
-#define MINLEVEL  1
-#define MAXLEVEL  9
-
-/*
- * Scoring is as follows:
- *
- * When the shape comes to rest, and is integrated into the board,
- * we score one point.  If the shape is high up (at a low-numbered row),
- * and the user hits the space bar, the shape plummets all the way down,
- * and we score a point for each row it falls (plus one more as soon as
- * we find that it is at rest and integrate it---until then, it can
- * still be moved or rotated).
- *
- * If previewing has been turned on, the score is multiplied by PRE_PENALTY.
- */
-#define PRE_PENALTY  0.75
-
-extern int score;  /* The obvious thing */
-
-extern char key_msg[100];
-extern int showpreview;
-extern int classic;
-
-extern int fits_in(const struct shape *, int);
-extern void place(const struct shape *, int, int);
-extern void stop(const char *);
-
-/** @}
- */
Index: uspace/drv/bus/usb/usbhid/kbd.h
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/drv/bus/usb/usbhid/kbd.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,5 @@
+/*
+ * Dummy file because of shared layout sources.
+ *
+ * Do not delete.
+ */
Index: uspace/drv/bus/usb/usbhid/kbd/layout.h
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd/layout.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/drv/bus/usb/usbhid/kbd/layout.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,1 @@
+../layout.h
Index: uspace/drv/bus/usb/usbhid/kbd/main.c
===================================================================
--- uspace/drv/bus/usb/usbhid/kbd/main.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/drv/bus/usb/usbhid/kbd/main.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * Main routines of USB KBD driver.
+ */
+
+#include <ddf/driver.h>
+#include <usb/debug.h>
+#include <errno.h>
+#include <str_error.h>
+
+#include <usb/dev/driver.h>
+
+#include "kbddev.h"
+#include "kbdrepeat.h"
+
+/*----------------------------------------------------------------------------*/
+
+#define NAME "usbkbd"
+
+/**
+ * Function for adding a new device of type USB/HID/keyboard.
+ *
+ * This functions initializes required structures from the device's descriptors
+ * and starts new fibril for polling the keyboard for events and another one for
+ * handling auto-repeat of keys.
+ *
+ * During initialization, the keyboard is switched into boot protocol, the idle
+ * rate is set to 0 (infinity), resulting in the keyboard only reporting event
+ * when a key is pressed or released. Finally, the LED lights are turned on 
+ * according to the default setup of lock keys.
+ *
+ * @note By default, the keyboards is initialized with Num Lock turned on and 
+ *       other locks turned off.
+ * @note Currently supports only boot-protocol keyboards.
+ *
+ * @param dev Device to add.
+ *
+ * @retval EOK if successful.
+ * @retval ENOMEM if there
+ * @return Other error code inherited from one of functions usb_kbd_init(),
+ *         ddf_fun_bind() and ddf_fun_add_to_class().
+ *
+ * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril()
+ */
+static int usb_kbd_try_add_device(usb_device_t *dev)
+{
+	/* Create the function exposed under /dev/devices. */
+	ddf_fun_t *kbd_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, 
+	    "keyboard");
+	if (kbd_fun == NULL) {
+		usb_log_error("Could not create DDF function node.\n");
+		return ENOMEM;
+	}
+	
+	/* 
+	 * Initialize device (get and process descriptors, get address, etc.)
+	 */
+	usb_log_debug("Initializing USB/HID KBD device...\n");
+	
+	usb_kbd_t *kbd_dev = usb_kbd_new();
+	if (kbd_dev == NULL) {
+		usb_log_error("Error while creating USB/HID KBD device "
+		    "structure.\n");
+		ddf_fun_destroy(kbd_fun);
+		return ENOMEM;  // TODO: some other code??
+	}
+	
+	int rc = usb_kbd_init(kbd_dev, dev);
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize USB/HID KBD device.\n");
+		ddf_fun_destroy(kbd_fun);
+		usb_kbd_free(&kbd_dev);
+		return rc;
+	}	
+	
+	usb_log_debug("USB/HID KBD device structure initialized.\n");
+	
+	/*
+	 * Store the initialized keyboard device and keyboard ops
+	 * to the DDF function.
+	 */
+	kbd_fun->driver_data = kbd_dev;
+	kbd_fun->ops = &keyboard_ops;
+
+	rc = ddf_fun_bind(kbd_fun);
+	if (rc != EOK) {
+		usb_log_error("Could not bind DDF function: %s.\n",
+		    str_error(rc));
+		// TODO: Can / should I destroy the DDF function?
+		ddf_fun_destroy(kbd_fun);
+		usb_kbd_free(&kbd_dev);
+		return rc;
+	}
+	
+	rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
+	if (rc != EOK) {
+		usb_log_error(
+		    "Could not add DDF function to class 'keyboard': %s.\n",
+		    str_error(rc));
+		ddf_fun_destroy(kbd_fun);
+		usb_kbd_free(&kbd_dev);
+		return rc;
+	}
+	
+	/* Start automated polling function.
+	 * This will create a separate fibril that will query the device
+	 * for the data continuously 
+	 */
+       rc = usb_device_auto_poll(dev,
+	   /* Index of the polling pipe. */
+	   USB_KBD_POLL_EP_NO,
+	   /* Callback when data arrives. */
+	   usb_kbd_polling_callback,
+	   /* How much data to request. */
+	   dev->pipes[USB_KBD_POLL_EP_NO].pipe->max_packet_size,
+	   /* Callback when the polling ends. */
+	   usb_kbd_polling_ended_callback,
+	   /* Custom argument. */
+	   kbd_dev);
+	
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to start polling fibril for `%s'.\n",
+		    dev->ddf_dev->name);
+		return rc;
+	}
+	
+	/*
+	 * Create new fibril for auto-repeat
+	 */
+	fid_t fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
+	if (fid == 0) {
+		usb_log_error("Failed to start fibril for KBD auto-repeat");
+		return ENOMEM;
+	}
+	fibril_add_ready(fid);
+
+	(void)keyboard_ops;
+
+	/*
+	 * Hurrah, device is initialized.
+	 */
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Callback for passing a new device to the driver.
+ *
+ * @note Currently, only boot-protocol keyboards are supported by this driver.
+ *
+ * @param dev Structure representing the new device.
+ *
+ * @retval EOK if successful. 
+ * @retval EREFUSED if the device is not supported.
+ */
+static int usb_kbd_add_device(usb_device_t *dev)
+{
+	usb_log_debug("usb_kbd_add_device()\n");
+	
+	if (dev->interface_no < 0) {
+		usb_log_warning("Device is not a supported keyboard.\n");
+		usb_log_error("Failed to add USB KBD device: endpoint not "
+		    "found.\n");
+		return ENOTSUP;
+	}
+	
+	int rc = usb_kbd_try_add_device(dev);
+	
+	if (rc != EOK) {
+		usb_log_warning("Device is not a supported keyboard.\n");
+		usb_log_error("Failed to add KBD device: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	usb_log_info("Keyboard `%s' ready to use.\n", dev->ddf_dev->name);
+
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+/* Currently, the framework supports only device adding. Once the framework
+ * supports unplug, more callbacks will be added. */
+static usb_driver_ops_t usb_kbd_driver_ops = {
+        .add_device = usb_kbd_add_device,
+};
+
+
+/* The driver itself. */
+static usb_driver_t usb_kbd_driver = {
+        .name = NAME,
+        .ops = &usb_kbd_driver_ops,
+        .endpoints = usb_kbd_endpoints
+};
+
+/*----------------------------------------------------------------------------*/
+
+int main(int argc, char *argv[])
+{
+	printf(NAME ": HelenOS USB KBD driver.\n");
+
+	usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
+
+	return usb_driver_main(&usb_kbd_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/usbhid/layout.h
===================================================================
--- uspace/drv/bus/usb/usbhid/layout.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/drv/bus/usb/usbhid/layout.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2011 Lubos Slovak 
+ * (copied from /uspace/srv/hid/kbd/include/layout.h)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * Keyboard layout.
+ */
+
+#ifndef USB_HID_LAYOUT_H_
+#define USB_HID_LAYOUT_H_
+
+#include <sys/types.h>
+#include <io/console.h>
+
+typedef struct {
+	void (*reset)(void);
+	wchar_t (*parse_ev)(kbd_event_t *);
+} layout_op_t;
+
+extern layout_op_t us_qwerty_op;
+extern layout_op_t us_dvorak_op;
+extern layout_op_t cz_op;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/bus/usb/usbmast/scsi.h
===================================================================
--- uspace/drv/bus/usb/usbmast/scsi.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/drv/bus/usb/usbmast/scsi.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 Vojtech Horky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup drvusbmast
+ * @{
+ */
+/** @file
+ * SCSI related structures.
+ */
+
+#ifndef USB_USBMAST_SCSI_H_
+#define USB_USBMAST_SCSI_H_
+
+#include <sys/types.h>
+#include <usb/usb.h>
+
+typedef struct {
+	uint8_t op_code;
+	uint8_t lun_evpd;
+	uint8_t page_code;
+	uint16_t alloc_length;
+	uint8_t ctrl;
+} __attribute__((packed)) scsi_cmd_inquiry_t;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/c/arch/ia32/include/atomic.h
===================================================================
--- uspace/lib/c/arch/ia32/include/atomic.h	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ uspace/lib/c/arch/ia32/include/atomic.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -43,6 +43,6 @@
 {
 	asm volatile (
-		"lock incl %0\n"
-		: "+m" (val->count)
+		"lock incl %[count]\n"
+		: [count] "+m" (val->count)
 	);
 }
@@ -51,6 +51,6 @@
 {
 	asm volatile (
-		"lock decl %0\n"
-		: "+m" (val->count)
+		"lock decl %[count]\n"
+		: [count] "+m" (val->count)
 	);
 }
@@ -61,7 +61,7 @@
 	
 	asm volatile (
-		"lock xaddl %1, %0\n"
-		: "+m" (val->count),
-		  "+r" (r)
+		"lock xaddl %[r], %[count]\n"
+		: [count] "+m" (val->count),
+		  [r] "+r" (r)
 	);
 	
@@ -74,7 +74,7 @@
 	
 	asm volatile (
-		"lock xaddl %1, %0\n"
-		: "+m" (val->count),
-		  "+r" (r)
+		"lock xaddl %[r], %[count]\n"
+		: [count] "+m" (val->count),
+		  [r] "+r" (r)
 	);
 	
Index: uspace/lib/c/arch/ia32/include/ddi.h
===================================================================
--- uspace/lib/c/arch/ia32/include/ddi.h	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
+++ uspace/lib/c/arch/ia32/include/ddi.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -44,7 +44,7 @@
 	
 	asm volatile (
-		"inb %w1, %b0\n"
-		: "=a" (val)
-		: "d" (port)
+		"inb %w[port], %b[val]\n"
+		: [val] "=a" (val)
+		: [port] "d" (port)
 	);
 	
@@ -57,7 +57,7 @@
 	
 	asm volatile (
-		"inw %w1, %w0\n"
-		: "=a" (val)
-		: "d" (port)
+		"inw %w[port], %w[val]\n"
+		: [val] "=a" (val)
+		: [port] "d" (port)
 	);
 	
@@ -70,7 +70,7 @@
 	
 	asm volatile (
-		"inl %w1, %0\n"
-		: "=a" (val)
-		: "d" (port)
+		"inl %w[port], %[val]\n"
+		: [val] "=a" (val)
+		: [port] "d" (port)
 	);
 	
@@ -81,6 +81,6 @@
 {
 	asm volatile (
-		"outb %b0, %w1\n"
-		:: "a" (val), "d" (port)
+		"outb %b[val], %w[port]\n"
+		:: [val] "a" (val), [port] "d" (port)
 	);
 }
@@ -89,6 +89,6 @@
 {
 	asm volatile (
-		"outw %w0, %w1\n"
-		:: "a" (val), "d" (port)
+		"outw %w[val], %w[port]\n"
+		:: [val] "a" (val), [port] "d" (port)
 	);
 }
@@ -97,6 +97,6 @@
 {
 	asm volatile (
-		"outl %0, %w1\n"
-		:: "a" (val), "d" (port)
+		"outl %[val], %w[port]\n"
+		:: [val] "a" (val), [port] "d" (port)
 	);
 }
Index: uspace/srv/hid/input/include/sun.h
===================================================================
--- uspace/srv/hid/input/include/sun.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/srv/hid/input/include/sun.h	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2009 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup kbdgen generic
+ * @brief Sun keyboard virtual port driver.
+ * @ingroup kbd
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KBD_SUN_H_
+#define KBD_SUN_H_
+
+extern int ns16550_port_init(void);
+extern int z8530_port_init(void);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/srv/hid/input/port/dummy.c
===================================================================
--- uspace/srv/hid/input/port/dummy.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/srv/hid/input/port/dummy.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup kbd_port
+ * @brief	Dummy keyboard port driver.
+ * @ingroup  kbd
+ * @{
+ */ 
+/** @file
+ */
+
+#include <kbd_port.h>
+#include <kbd.h>
+
+int kbd_port_init(void)
+{
+	return 0;
+}
+
+void kbd_port_yield(void)
+{
+}
+
+void kbd_port_reclaim(void)
+{
+}
+
+void kbd_port_write(uint8_t data)
+{
+	(void) data;
+}
+
+/** @}
+*/
Index: uspace/srv/hid/input/port/sgcn.c
===================================================================
--- uspace/srv/hid/input/port/sgcn.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/srv/hid/input/port/sgcn.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2008 Pavel Rimsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup kbd_port
+ * @ingroup  kbd
+ * @{
+ */
+/** @file
+ * @brief SGCN (Serengeti Console) keyboard port driver.
+ */
+
+#include <as.h>
+#include <ddi.h>
+#include <async.h>
+#include <kbd.h>
+#include <kbd_port.h>
+#include <sysinfo.h>
+#include <stdio.h>
+#include <thread.h>
+#include <bool.h>
+#include <errno.h>
+
+#define POLL_INTERVAL  10000
+
+/**
+ * SGCN buffer header. It is placed at the very beginning of the SGCN
+ * buffer.
+ */
+typedef struct {
+	/** hard-wired to "CON" */
+	char magic[4];
+	
+	/** we don't need this */
+	char unused[8];
+	
+	/** offset within the SGCN buffer of the input buffer start */
+	uint32_t in_begin;
+	
+	/** offset within the SGCN buffer of the input buffer end */
+	uint32_t in_end;
+	
+	/** offset within the SGCN buffer of the input buffer read pointer */
+	uint32_t in_rdptr;
+	
+	/** offset within the SGCN buffer of the input buffer write pointer */
+	uint32_t in_wrptr;
+} __attribute__ ((packed)) sgcn_buffer_header_t;
+
+/*
+ * Returns a pointer to the object of a given type which is placed at the given
+ * offset from the console buffer beginning.
+ */
+#define SGCN_BUFFER(type, offset) \
+		((type *) (sram_virt_addr + sram_buffer_offset + (offset)))
+
+/** Returns a pointer to the console buffer header. */
+#define SGCN_BUFFER_HEADER	(SGCN_BUFFER(sgcn_buffer_header_t, 0))
+
+/**
+ * Virtual address mapped to SRAM.
+ */
+static uintptr_t sram_virt_addr;
+
+/**
+ * SGCN buffer offset within SGCN.
+ */
+static uintptr_t sram_buffer_offset;
+
+/* polling thread */
+static void sgcn_thread_impl(void *arg);
+
+static volatile bool polling_disabled = false;
+
+/**
+ * Initializes the SGCN driver.
+ * Maps the physical memory (SRAM) and creates the polling thread. 
+ */
+int kbd_port_init(void)
+{
+	sysarg_t sram_paddr;
+	if (sysinfo_get_value("sram.address.physical", &sram_paddr) != EOK)
+		return -1;
+	
+	sysarg_t sram_size;
+	if (sysinfo_get_value("sram.area.size", &sram_size) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("sram.buffer.offset", &sram_buffer_offset) != EOK)
+		sram_buffer_offset = 0;
+	
+	sram_virt_addr = (uintptr_t) as_get_mappable_page(sram_size);
+	
+	if (physmem_map((void *) sram_paddr, (void *) sram_virt_addr,
+	    sram_size / PAGE_SIZE, AS_AREA_READ | AS_AREA_WRITE) != 0) {
+		printf("SGCN: uspace driver could not map physical memory.");
+		return -1;
+	}
+	
+	thread_id_t tid;
+	int rc = thread_create(sgcn_thread_impl, NULL, "kbd_poll", &tid);
+	if (rc != 0)
+		return rc;
+	
+	return 0;
+}
+
+void kbd_port_yield(void)
+{
+	polling_disabled = true;
+}
+
+void kbd_port_reclaim(void)
+{
+	polling_disabled = false;
+}
+
+void kbd_port_write(uint8_t data)
+{
+	(void) data;
+}
+
+/**
+ * Handler of the "key pressed" event. Reads codes of all the pressed keys from
+ * the buffer. 
+ */
+static void sgcn_key_pressed(void)
+{
+	char c;
+	
+	uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
+	uint32_t end = SGCN_BUFFER_HEADER->in_end;
+	uint32_t size = end - begin;
+	
+	volatile char *buf_ptr = (volatile char *)
+		SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
+	volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr);
+	volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr);
+	
+	while (*in_rdptr_ptr != *in_wrptr_ptr) {
+		c = *buf_ptr;
+		*in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
+		buf_ptr = (volatile char *)
+			SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
+		kbd_push_scancode(c);
+	}
+}
+
+/**
+ * Thread to poll SGCN for keypresses.
+ */
+static void sgcn_thread_impl(void *arg)
+{
+	(void) arg;
+
+	while (1) {
+		if (polling_disabled == false)
+			sgcn_key_pressed();
+		usleep(POLL_INTERVAL);
+	}
+}
+
+/** @}
+ */
Index: uspace/srv/hid/input/port/sun.c
===================================================================
--- uspace/srv/hid/input/port/sun.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/srv/hid/input/port/sun.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2009 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup kbd_port
+ * @ingroup  kbd
+ * @{
+ */
+/** @file
+ * @brief Sun keyboard virtual port driver.
+ */
+
+#include <kbd.h>
+#include <kbd_port.h>
+#include <sun.h>
+#include <sysinfo.h>
+#include <errno.h>
+#include <bool.h>
+
+/** Sun keyboard virtual port driver.
+ *
+ * This is a virtual port driver which can use
+ * both ns16550_port_init and z8530_port_init
+ * according to the information passed from the
+ * kernel. This is just a temporal hack.
+ *
+ */
+int kbd_port_init(void)
+{
+	sysarg_t z8530;
+	if (sysinfo_get_value("kbd.type.z8530", &z8530) != EOK)
+		z8530 = false;
+	
+	sysarg_t ns16550;
+	if (sysinfo_get_value("kbd.type.ns16550", &ns16550) != EOK)
+		ns16550 = false;
+	
+	if (z8530) {
+		if (z8530_port_init() == 0)
+			return 0;
+	}
+	
+	if (ns16550) {
+		if (ns16550_port_init() == 0)
+			return 0;
+	}
+	
+	return -1;
+}
+
+void kbd_port_yield(void)
+{
+}
+
+void kbd_port_reclaim(void)
+{
+}
+
+void kbd_port_write(uint8_t data)
+{
+	(void) data;
+}
+
+/** @}
+*/
Index: uspace/srv/hid/input/port/z8530.c
===================================================================
--- uspace/srv/hid/input/port/z8530.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
+++ uspace/srv/hid/input/port/z8530.c	(revision b6759f49ea55957bdd9cb4159bd68f0b2df41b1a)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup kbd_port
+ * @ingroup  kbd
+ * @{
+ */
+/** @file
+ * @brief Z8530 keyboard port driver.
+ */
+
+#include <ipc/irc.h>
+#include <async.h>
+#include <async_obsolete.h>
+#include <sysinfo.h>
+#include <kbd.h>
+#include <kbd_port.h>
+#include <sun.h>
+#include <sys/types.h>
+#include <ddi.h>
+#include <errno.h>
+
+#define CHAN_A_STATUS  4
+#define CHAN_A_DATA    6
+
+#define RR0_RCA  1
+
+static irq_cmd_t z8530_cmds[] = {
+	{
+		.cmd = CMD_PIO_READ_8,
+		.addr = (void *) 0,     /* Will be patched in run-time */
+		.dstarg = 1
+	},
+	{
+		.cmd = CMD_BTEST,
+		.value = RR0_RCA,
+		.srcarg = 1,
+		.dstarg = 3
+	},
+	{
+		.cmd = CMD_PREDICATE,
+		.value = 2,
+		.srcarg = 3
+	},
+	{
+		.cmd = CMD_PIO_READ_8,
+		.addr = (void *) 0,     /* Will be patched in run-time */
+		.dstarg = 2
+	},
+	{
+		.cmd = CMD_ACCEPT
+	}
+};
+	
+irq_code_t z8530_kbd = {
+	sizeof(z8530_cmds) / sizeof(irq_cmd_t),
+	z8530_cmds
+};
+
+static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call);
+
+int z8530_port_init(void)
+{
+	sysarg_t kaddr;
+	if (sysinfo_get_value("kbd.address.kernel", &kaddr) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
+	z8530_cmds[0].addr = (void *) kaddr + CHAN_A_STATUS;
+	z8530_cmds[3].addr = (void *) kaddr + CHAN_A_DATA;
+	
+	async_set_interrupt_received(z8530_irq_handler);
+	register_irq(inr, device_assign_devno(), inr, &z8530_kbd);
+	
+	return 0;
+}
+
+static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call)
+{
+	int scan_code = IPC_GET_ARG2(*call);
+	kbd_push_scancode(scan_code);
+	
+	if (irc_service)
+		async_obsolete_msg_1(irc_phone, IRC_CLEAR_INTERRUPT,
+		    IPC_GET_IMETHOD(*call));
+}
+
+/** @}
+ */
