1 ----------------------------------------------------------------------
2 Patch name: patch.example-override-ask
4 Date: Mon Sep 23 13:00:53 EDT 2002
8 This patch shows how to create your own siminterface callback function.
9 It is not intended to be checked in anytime, only to serve as an example
10 of how to use the siminterface.
12 Patch updated for current CVS. (Volker Ruppert, Oct 16, 2005)
14 Patch was created with:
16 Apply patch to what version:
17 cvs checked out on DATE
19 To patch, go to main bochs directory.
20 Type "patch -p1 < THIS_PATCH_FILE".
21 ----------------------------------------------------------------------
22 --- bochs/config.h.in 2005-10-13 20:40:50.131262080 +0200
23 +++ bochs-overrideask/config.h.in 2005-10-13 20:44:40.841188840 +0200
26 #define BX_EXTERNAL_DEBUGGER 0
28 +// Override ask dialog (demo)
29 +#define BX_OVERRIDE_ASK_EXAMPLE 1
32 #define BX_MAGIC_BREAKPOINT 1
34 --- bochs/gui/textconfig.cc 2005-06-06 22:14:50.000000000 +0200
35 +++ bochs-overrideask/gui/textconfig.cc 2005-10-13 20:12:16.090835832 +0200
38 //fprintf (stderr, "textconfig.cc: start\n");
39 bx_config_interface_init ();
40 +#if BX_OVERRIDE_ASK_EXAMPLE
41 + extern void override_ask_init();
42 + override_ask_init ();
44 if (SIM->get_param_enum(BXP_BOCHS_START)->get () == BX_QUICK_START)
45 bx_config_interface (BX_CI_START_SIMULATION);
47 diff -urN bochs/Makefile.in bochs-overrideask/Makefile.in
48 --- bochs/Makefile.in 2005-07-30 17:02:40.000000000 +0200
49 +++ bochs-overrideask/Makefile.in 2005-10-13 20:04:06.137320088 +0200
57 EXTERN_ENVIRONMENT_OBJS = \
58 --- bochs/overrideask.cc 1970-01-01 01:00:00.000000000 +0100
59 +++ bochs-overrideask/overrideask.cc 2005-10-13 20:15:25.713008880 +0200
65 +#include "gui/siminterface.h"
67 +bxevent_handler old_callback = NULL;
68 +void *old_callback_arg = NULL;
71 +override_ask_callback (void *unused, BxEvent *event)
75 + fprintf (stderr, "override_ask_callback\n");
76 + event->retcode = -1;
77 + switch (event->type)
79 + case BX_SYNC_EVT_LOG_ASK:
80 + level = event->u.logmsg.level;
81 + fprintf (stderr, "============ override_ask_callback was called ==========================\n");
82 + fprintf (stderr, "Event type: %s\n", SIM->get_log_level_name (level));
83 + fprintf (stderr, "Device: %s\n", event->u.logmsg.prefix);
84 + fprintf (stderr, "Message: %s\n\n", event->u.logmsg.msg);
85 + // note: 4 only available if BX_DEBUGGER=1. ideally, don't show it
86 + fprintf (stderr, "What should I do? (0=continue, 1=alwayscont, 2=die, 3=abort, 4=debug) ");
87 + while (scanf ("%d", &n) != 1 || (n<0 && n>4)) {
88 + fprintf (stderr, "Enter 0-4 only.\n");
91 + fprintf (stderr, "============ override_ask_callback is done =============================\n");
93 + case BX_SYNC_EVT_TICK: // called periodically by siminterface.
94 + case BX_SYNC_EVT_ASK_PARAM: // called if simulator needs to know value of a param.
95 + case BX_ASYNC_EVT_REFRESH: // called when some bx_param_c parameters have changed.
96 + // fall into default case
98 + return (*old_callback)(old_callback_arg, event);
102 +// called from textconfig.cc
103 +void override_ask_init ()
105 + fprintf (stderr, "override_ask_init");
106 + // this should be called after the configuration interface has had a
107 + // chance to install its own callback. Otherwise, overrideask will not
108 + // override anything.
109 + SIM->get_notify_callback (&old_callback, &old_callback_arg);
110 + assert (old_callback != NULL);
111 + SIM->set_notify_callback (override_ask_callback, NULL);