source: mainline/uspace/app/msim/helenos.c@ 90f067d9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 90f067d9 was 90f067d9, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Add filtering of ANSI escape sequences to msim

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2012 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup msim
30 * @{
31 */
32/** @file HelenOS specific functions for MSIM simulator.
33 */
34#include "io/input.h"
35#include "io/output.h"
36#include "device/dprinter.h"
37#include "debug/gdb.h"
38#include "cmd.h"
39#include "fault.h"
40#include "device/machine.h"
41#include <str.h>
42#include <malloc.h>
43#include <ctype.h>
44#include <stdio.h>
45
46/* Define when the dprinter device shall try to filter
47 * out ANSI escape sequences.
48 */
49#define IGNORE_ANSI_ESCAPE_SEQUENCES
50
51extern char *input_helenos_get_next_command(void);
52
53void interactive_control(void)
54{
55 tobreak = false;
56
57 if (reenter) {
58 mprintf("\n");
59 reenter = false;
60 }
61
62 stepping = 0;
63
64 while (interactive) {
65 char *commline = input_helenos_get_next_command();
66 if (commline == NULL) {
67 mprintf("Quit\n");
68 input_back();
69 exit(1);
70 }
71
72 /* Check for empty input. */
73 if (str_cmp(commline, "") == 0) {
74 interpret("step");
75 } else {
76 interpret(commline);
77 }
78
79 free(commline);
80 }
81}
82
83bool gdb_remote_init(void)
84{
85 return false;
86}
87
88void gdb_session(void)
89{
90}
91
92void gdb_handle_event(gdb_event_t event)
93{
94}
95
96
97char *input_helenos_get_next_command(void);
98
99static void (*original_printer_write)(cpu_t *, device_s *, ptr_t, uint32_t);
100static void helenos_printer_write(cpu_t *cpu, device_s *dev, ptr_t addr, uint32_t val)
101{
102#ifdef IGNORE_ANSI_ESCAPE_SEQUENCES
103 static bool inside_ansi_escape = false;
104 static bool just_ended_ansi_escape = false;
105
106 if (inside_ansi_escape) {
107 fprintf(stderr, "%02" PRIx32 "'%c' ", val, val >= 32 ? val : '?');
108 if (isalpha((int) val)) {
109 just_ended_ansi_escape = true;
110 inside_ansi_escape = false;
111 fprintf(stderr, " [END]\n");
112 }
113
114 return;
115 }
116
117 if (val == 0x1B) {
118 inside_ansi_escape = true;
119
120 if (!just_ended_ansi_escape) {
121 fprintf(stderr, "\n");
122 }
123 fprintf(stderr, "ESC sequence: ");
124
125 return;
126 }
127
128 just_ended_ansi_escape = false;
129#endif
130
131 (*original_printer_write)(cpu, dev, addr, val);
132}
133
134void helenos_dprinter_init(void)
135{
136 original_printer_write = dprinter.write;
137 dprinter.write = helenos_printer_write;
138}
139
140
Note: See TracBrowser for help on using the repository browser.