Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision a92f13d72ceb92e4f0db78669f2f2592d7016727)
+++ HelenOS.config	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -573,4 +573,7 @@
 ! CONFIG_BINUTILS (n/y)
 
+% Build MSIM binary
+! CONFIG_MSIM (n/y)
+
 % Line debugging information
 ! [CONFIG_STRIP_BINARIES!=y] CONFIG_LINE_DEBUG (n/y)
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision a92f13d72ceb92e4f0db78669f2f2592d7016727)
+++ boot/Makefile.common	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -203,4 +203,9 @@
 endif
 
+ifeq ($(CONFIG_MSIM),y)
+RD_APPS_NON_ESSENTIAL += \
+	$(USPACE_PATH)/app/msim/msim
+endif
+
 ifneq ($(CONFIG_BAREBONE),y)
 NET_CFG = \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision a92f13d72ceb92e4f0db78669f2f2592d7016727)
+++ uspace/Makefile	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -140,4 +140,9 @@
 endif
 
+ifeq ($(CONFIG_MSIM),y)
+DIRS += \
+	app/msim
+endif
+
 ## Platform-specific hardware support
 #
Index: uspace/app/msim/Makefile
===================================================================
--- uspace/app/msim/Makefile	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
+++ uspace/app/msim/Makefile	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -0,0 +1,75 @@
+#
+# Copyright (c) 2012 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.
+#
+
+USPACE_PREFIX = ../..
+BINARY = msim
+
+MSIM_VERSION = 1.3.8.1
+MSIM_DIST = msim-$(MSIM_VERSION)
+MSIM_TARBALL = $(MSIM_DIST).tar.bz2
+MSIM_MIRROR = http://d3s.mff.cuni.cz/~holub/sw/msim/
+
+MSIM_HELENOS_MAKEFILE = Makefile.msim.src
+MSIM_HELENOS_PLATFORM_FILES = helenos.c helenos_input.c
+MSIM_PATCHED_FILES = \
+	$(MSIM_DIST)/config.h \
+	$(MSIM_DIST)/src/$(MSIM_HELENOS_MAKEFILE) \
+	$(MSIM_DIST)/src/helenos.c \
+	$(MSIM_DIST)/src/helenos_input.c
+
+CP = /bin/cp -f
+
+all: $(BINARY)
+
+# FIXME - better parallelization
+
+$(BINARY):
+# Download it
+	wget "$(MSIM_MIRROR)$(MSIM_TARBALL)" -O $(MSIM_TARBALL)
+# Unpack it
+	tar xjf $(MSIM_TARBALL)
+# Extract sources
+	cd $(MSIM_DIST)/src; ( \
+		echo 'all__:'; \
+		echo -e '\t@echo SOURCES = $$(SOURCES)'; cat Makefile.in \
+	) | make -f - | grep 'SOURCES' >Makefile.sources
+# Patch it
+	sed \
+		-e 's:io/input.c:$(MSIM_HELENOS_PLATFORM_FILES):' \
+		-e 's:debug/gdb.c::' \
+		-e 's:arch/posix/stdin.c::' \
+		-i $(MSIM_DIST)/src/Makefile.sources
+	$(CP) config.h.msim $(MSIM_DIST)/config.h
+	$(CP) $(MSIM_HELENOS_MAKEFILE) $(MSIM_HELENOS_PLATFORM_FILES) $(MSIM_DIST)/src/
+# Build it
+	cd $(MSIM_DIST)/src; make -f $(MSIM_HELENOS_MAKEFILE) USPACE_PREFIX=../../$(USPACE_PREFIX)
+	$(CP) $(MSIM_DIST)/src/msim $@
+
+clean:
+	rm -rf msim Makefile.depend* *.map *.disasm $(MSIM_TARBALL) $(MSIM_DIST)
+
Index: uspace/app/msim/Makefile.msim.src
===================================================================
--- uspace/app/msim/Makefile.msim.src	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
+++ uspace/app/msim/Makefile.msim.src	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2012 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.
+#
+
+
+BINARY = msim
+LIBS = $(LIBCLUI_PREFIX)/libclui.a
+POSIX_COMPAT = y
+# Needed because MSIM is not that strict as HelenOS
+EXTRA_CFLAGS = -Wno-error -I$(LIBCLUI_PREFIX)
+
+include Makefile.sources
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/msim/config.h.msim
===================================================================
--- uspace/app/msim/config.h.msim	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
+++ uspace/app/msim/config.h.msim	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -0,0 +1,108 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#define HAVE_CTYPE_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+#define HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `readline' library (-lreadline). */
+#define HAVE_LIBREADLINE 1
+
+/* Define to 1 if you have the `wsock32' library (-lwsock32). */
+/* #undef HAVE_LIBWSOCK32 */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#define HAVE_READLINE_HISTORY_H 1
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#define HAVE_READLINE_READLINE_H 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#define HAVE_SIGNAL_H 1
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#define HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stdbool.h> header file. */
+#define HAVE_STDBOOL_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Name of package */
+#define PACKAGE "msim"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME ""
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING ""
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION ""
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "1.3.8.1"
+
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
Index: uspace/app/msim/helenos.c
===================================================================
--- uspace/app/msim/helenos.c	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
+++ uspace/app/msim/helenos.c	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2012 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 msim
+ * @{
+ */
+/** @file HelenOS specific functions for MSIM simulator.
+ */
+#include "io/input.h"
+#include "io/output.h"
+#include "debug/gdb.h"
+#include "cmd.h"
+#include "fault.h"
+#include "device/machine.h"
+#include <str.h>
+#include <malloc.h>
+
+extern char *input_helenos_get_next_command(void);
+
+void interactive_control(void)
+{
+	tobreak = false;
+
+	if (reenter) {
+		mprintf("\n");
+		reenter = false;
+	}
+
+	stepping = 0;
+
+	while (interactive) {
+		char *commline = input_helenos_get_next_command();
+		if (commline == NULL) {
+			mprintf("Quit\n");
+			input_back();
+			exit(1);
+		}
+
+		/* Check for empty input. */
+		if (str_cmp(commline, "") == 0) {
+			interpret("step");
+		} else {
+			interpret(commline);
+		}
+
+		free(commline);
+	}
+}
+
+bool gdb_remote_init(void)
+{
+	return false;
+}
+
+void gdb_session(void)
+{
+}
+
+void gdb_handle_event(gdb_event_t event)
+{
+}
+
+bool stdin_poll(char *key)
+{
+	// TODO: implement reading from keyboard
+	return false;
+}
+
Index: uspace/app/msim/helenos_input.c
===================================================================
--- uspace/app/msim/helenos_input.c	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
+++ uspace/app/msim/helenos_input.c	(revision 3f0ea0e27dd8fd035057f2c75afa2a0b24875fd3)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2012 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 msim
+ * @{
+ */
+/** @file HelenOS specific functions for MSIM simulator.
+ */
+#include "io/input.h"
+#include "io/output.h"
+#include "fault.h"
+#include <tinput.h>
+#include <errno.h>
+
+static tinput_t *input_prompt;
+
+char *input_helenos_get_next_command(void);
+
+/** Terminal and readline initialization
+ *
+ */
+void input_init(void)
+{
+	input_prompt = tinput_new();
+	if (input_prompt == NULL) {
+		die(1, "Failed to intialize input.");
+	}
+}
+
+void input_inter(void)
+{
+}
+
+void input_shadow( void)
+{
+}
+
+void input_back( void)
+{
+}
+
+char *input_helenos_get_next_command(void)
+{
+	tinput_set_prompt(input_prompt, "[msim] ");
+
+	char *commline = NULL;
+	int rc = tinput_read(input_prompt, &commline);
+
+	if (rc == ENOENT) {
+		rc = asprintf(&commline, "quit");
+		mprintf("Quit\n");
+		if (rc != EOK) {
+			exit(1);
+		}
+	}
+
+	/* On error, it remains NULL. */
+	return commline;
+}
+
