* sim/ucsim/cmd.src/newcmdposix.cc, sim/ucsim/cmd.src/newcmdposixcl.h,
[fw/sdcc] / sim / ucsim / cmd.src / bp.cc
index e2d6fd1312f062ade1579572800b6b8541ed036a..bc31d24bf20f36e2e9f4ef0cb77bdc8f46fc9b3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Simulator of microcontrollers (bp.cc)
+ * Simulator of microcontrollers (cmd.src/bp.cc)
  *
  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
  * 
@@ -36,46 +36,96 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 // cmd
 #include "cmdsetcl.h"
+#include "bpcl.h"
 
 
 /*
  * BREAK command
  */
 
-int
-cl_break_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_break_cmd::do_work(class cl_sim *sim,
+//                    class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_UC(cl_break_cmd)
 {
-  long addr;
-  int  hit= 1;
-  class cl_cmd_arg *params[2]= { cmdline->param(0),
-                                cmdline->param(1) };
-
-  if (params[0] == 0)
+  t_addr addr= 0;
+  int hit= 1;
+  char op;
+  class cl_address_space *mem;
+  class cl_cmd_arg *params[4]= { cmdline->param(0),
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3) };
+
+  if (cmdline->syntax_match(uc, ADDRESS)) {
+    addr= params[0]->value.address;
+    hit= 1;
+    do_fetch(uc, addr, hit, con);
+  }
+  else if (cmdline->syntax_match(uc, ADDRESS NUMBER)) {
+    addr= params[0]->value.address;
+    hit= params[1]->value.number;
+    do_fetch(uc, addr, hit, con);
+  }
+  else if (cmdline->syntax_match(uc, MEMORY STRING ADDRESS)) {
+    mem= params[0]->value.memory.address_space;
+    op= *(params[1]->get_svalue());
+    addr= params[2]->value.address;
+    hit= 1;
+    do_event(uc, mem, op, addr, hit, con);
+  }
+  else if (cmdline->syntax_match(uc, MEMORY STRING ADDRESS NUMBER)) {
+    mem= params[0]->value.memory.address_space;
+    op= *(params[1]->get_svalue());
+    addr= params[2]->value.address;
+    hit= params[3]->value.number;
+    do_event(uc, mem, op, addr, hit, con);
+  }
+  else
     {
-      con->printf("Address is missing.\n");
-      return(FALSE);
+      con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+      return(DD_FALSE);
     }
-  addr= (params[0])->get_address();
-  if (params[1])
-    hit= (params[1])->get_ivalue();
+  return(DD_FALSE);
+}
+
+void
+cl_break_cmd::do_fetch(class cl_uc *uc,
+                       t_addr addr, int hit, class cl_console_base *con)
+{
   if (hit > 99999)
     {
-      con->printf("Hit value %d is too big.\n", hit);
-      return(0);
+      con->dd_printf("Hit value %d is too big.\n", hit);
+      return;
     }
-  if (sim->uc->fbrk->bp_at(addr))
-    con->printf("Breakpoint at 0x%06x is already set.\n", addr);
+  if (uc->fbrk->bp_at(addr))
+    con->dd_printf("Breakpoint at 0x%06x is already set.\n", addr);
   else
     {
-      class cl_brk *b= new cl_fetch_brk(sim->uc->fbrk->make_new_nr(),
-                                       addr, perm, hit);
+      class cl_brk *b= new cl_fetch_brk(uc->address_space(MEM_ROM_ID),
+                                        uc->make_new_brknr(),
+                                        addr, perm, hit);
       b->init();
-      sim->uc->fbrk->add_bp(b);
-      char *s= sim->uc->disass(addr, NULL);
-      con->printf("Breakpoint %d at 0x%06x: %s\n", b->nr, addr, s);
+      uc->fbrk->add_bp(b);
+      char *s= uc->disass(addr, NULL);
+      con->dd_printf("Breakpoint %d at 0x%06x: %s\n", b->nr, addr, s);
       free(s);
     }
-  return(0);
+}
+
+void
+cl_break_cmd::do_event(class cl_uc *uc,
+                       class cl_address_space *mem,
+                       char op, t_addr addr, int hit,
+                       class cl_console_base *con)
+{
+  class cl_ev_brk *b= NULL;
+
+  b= uc->mk_ebrk(perm, mem, op, addr, hit);
+  if (b)
+    uc->ebrk->add_bp(b);
+  else
+    con->dd_printf("Couldn't make event breakpoint\n");
 }
 
 
@@ -83,21 +133,22 @@ cl_break_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
  * CLEAR address
  */
 
-int
-cl_clear_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_clear_cmd::do_work(class cl_sim *sim,
+//                    class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_UC(cl_clear_cmd)
 {
-  uint addr;
   int idx;
-  class cl_brk *brk= sim->uc->fbrk->get_bp(sim->uc->PC, &idx);
+  class cl_brk *brk= uc->fbrk->get_bp(uc->PC, &idx);
 
   if (cmdline->param(0) == 0)
     {
       if (!brk)
-       {
-         con->printf("No breakpoint at this address.\n");
-         return(0);
-       }
-      sim->uc->fbrk->del_bp(sim->uc->PC);
+        {
+          con->dd_printf("No breakpoint at this address.\n");
+          return(0);
+        }
+      uc->fbrk->del_bp(uc->PC);
       return(0);
     }
 
@@ -105,15 +156,50 @@ cl_clear_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
   class cl_cmd_arg *param;
   while ((param= cmdline->param(i++)))
     {
-      addr= param->get_ivalue();
-      if (sim->uc->fbrk->bp_at(addr) == 0)
-       sim->cmd->printf("No breakpoint at 0x%06x\n", addr);
+      t_addr addr;
+      if (!param->as_address(uc))
+        return(DD_FALSE);
+      addr= param->value.address;
+      if (uc->fbrk->bp_at(addr) == 0)
+        con->dd_printf("No breakpoint at 0x%06x\n", addr);
       else
-       sim->uc->fbrk->del_bp(addr);
+        uc->fbrk->del_bp(addr);
     }
 
-  return(0);
+  return(DD_FALSE);
+}
+
+
+/*
+ * DELETE nr nr ...
+ */
+
+//int
+//cl_delete_cmd::do_work(class cl_sim *sim,
+//                     class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_UC(cl_delete_cmd)
+{
+  if (cmdline->param(0) == 0)
+    {
+      // delete all
+      uc->remove_all_breaks();
+    }
+  else
+    {
+      int i= 0;
+      class cl_cmd_arg *param;
+      while ((param= cmdline->param(i++)))
+        {
+          long num;
+          if (param->get_ivalue(&num))
+            {
+              if (!uc->rm_brk(num))
+                con->dd_printf("Error\n");
+            }
+        }
+    }
+  return(DD_FALSE);
 }
 
 
-/* End of bp.cc */
+/* End of cmd.src/bp.cc */