Beispiel #1
0
static int pic_get_ilevel(void)
{
    int local_pic_ilevel, old_ilevel;
    int int_req = (pic_irr & ~(pic_isr | pic_imr));
    if (!int_req)
	return -1;
    local_pic_ilevel = find_bit(int_req);    /* find out what it is  */
    old_ilevel = find_bit(pic_isr);
    if (local_pic_ilevel >= old_ilevel + pic_smm)  /* priority check */
	return -1;
    return local_pic_ilevel;
}
Beispiel #2
0
void *buddy_allocation(info_p handle, long n_bytes){
  if(n_bytes > handle->n_bytes){
    printf("Buddy Alloc Error: Request Size too large\n");
    return NULL;
  }
  long size = find_smallest_block(n_bytes);
  if(size < (long)power(2,handle->parm1)){
    size = (long)power(2,handle->parm1);
  }
  printf("Looking for block size: %lu\n", size);

  int bitmap[handle->overhead * 8];
  encode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap);

  int indx = find_bit(bitmap, 1, handle->n_bytes, size, (long)power(2,handle->parm1));
  indx -= 50; //Decode the encoded index
  if(indx < 0){
    printf("Bitmap: Could not find free space\n");
    return NULL;
  }
  printf("Bitmap: Index Found: %d\n", indx);
  void *returnptr = find_memory(indx, handle);

  decode_bitmap(handle->memptr-handle->overhead, handle->overhead, bitmap);

  printf("Buddy Alloc: Allocated Space at %p\n", returnptr);

  return returnptr;
}
Beispiel #3
0
void write_pic1(ioport_t port, Bit8u value)
{
/* if port == 0 this must be either an ICW1, OCW2, or OCW3 */
/* if port == 1 this must be either ICW2, ICW3, ICW4, or load IMR */
static char /* icw_state, */     /* !=0 => port 1 does icw 2,3,(4) */
               icw_max_state;    /* number of icws expected        */
int ilevel;			  /* level to reset on outb 0x20  */

port -= 0xa0;
ilevel = 32;
if (pic_isr)
  ilevel=find_bit(pic_isr);
if (ilevel != 32 && !test_bit(ilevel, &pic_irqall)) {
  /* this is a fake IRQ, don't allow to reset its ISR bit */
  pic_print(1, "Protecting ISR bit for lvl ", ilevel, " from spurious EOI");
  ilevel = 32;
}

if (in_dpmi_pm())
  dpmi_return_request();	/* we have to leave the signal context */

if(!port){                            /* icw1, ocw2, ocw3 */
  if(value&0x10){                     /* icw1 */
    icw_max_state = (value & 1) + 1;
    if(value&2) ++icw_max_state;
    pic1_icw_state = 1;
    pic1_cmd=1;
    }
  else if (value&0x08) {                /* ocw3 */
    if(value&2) pic1_isr_requested = value&1;
    if(value&64)pic_smm = value&32; /* must be either 0 or 32, conveniently */
    pic1_cmd=3;
    }
  else if((value&0xb8) == 0x20) {    /* ocw2 */
    /* irqs on pic1 require an outb20 to each pic. we settle for any 2 */
     if(!clear_bit(ilevel,&pic1_isr)) {
       clear_bit(ilevel,&pic_isr);  /* the famous outb20 */
       pic_print(1,"EOI resetting bit ",ilevel, " on pic0");
       }
     else
       pic_print(1,"EOI resetting bit ",ilevel, " on pic1");
     pic0_cmd=2;
     }
  }
else                         /* icw2, icw3, icw4, or mask register */
  switch(pic1_icw_state){
     case 0:                    /* mask register */
       set_pic1_imr(value);
       pic_print(1, "Set mask to ", value, " on pic1");
       break;
     case 1:                    /* icw 2         */
       set_pic1_base(value);
     default:                   /* icw 2,3 and 4 */
       if(pic1_icw_state++ >= icw_max_state) pic1_icw_state=0;
  }
}
Beispiel #4
0
static int out_equ(ea_t ea)
{
  char buf[MAXSTR];
  char *const end = buf + sizeof(buf);
  segment_t *s = getseg(ea);
  if ( s != NULL && s->type == SEG_IMEM && ash.a_equ != NULL)
  {
    char nbuf[MAXSTR];
    char *name = get_name(BADADDR, ea, nbuf, sizeof(nbuf));
    if ( name != NULL
      && ((ash.uflag & UAS_PBYTNODEF) == 0 || !IsPredefined(name)) )
    {
      get_colored_name(BADADDR, ea, buf, sizeof(buf));
      uchar off = uchar(ea - get_segm_base(s));
      do_out_equ(buf, ash.a_equ, off);
      if ( (ash.uflag & UAS_AUBIT) == 0 && (off & 0xF8) == off )
      {
        char *ptr = tag_on(tail(buf), end, COLOR_SYMBOL);
        APPCHAR(ptr, end, ash.uflag & UAS_NOBIT ? '_' : '.');
        APPCHAR(ptr, end, '0');
        tag_off(ptr, end, COLOR_SYMBOL);
        for ( int i=0; i < 8; i++ )
        {
          const ioport_bit_t *b = find_bit(off, i);
          char *p2 = ptr;
          if ( b == NULL || b->name == NULL )
            ptr[-1] = '0' + i;
          else
            p2 = tag_addstr(ptr-1, end, COLOR_HIDNAME, b->name);
          tag_off(p2, end, COLOR_SYMBOL);
          do_out_equ(buf, ash.a_equ, off+i);
        }
        MakeNull();
      }
    }
    else
    {
      gl_name = 0;
      MakeLine("");
    }
    return 1;
  }
  if ( ash.uflag & UAS_NODS )
  {
    if ( !isLoaded(ea) && s->type == SEG_CODE )
    {
      adiff_t org = ea - get_segm_base(s) + get_item_size(ea);
      btoa(buf, sizeof(buf), org);
      printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf);
      return 1;
    }
  }
  return 0;
}
Beispiel #5
0
static void p_pic_print(char *s1, int v1, char *s2)
{
  static int oldi=0, header_count=0;
  int pic_ilevel=find_bit(pic_isr);
  char ci;

  if (pic_ilevel > oldi) ci='+';
  else if(pic_ilevel < oldi) ci='-';
  else ci=' ';
  oldi = pic_ilevel;
  if (!header_count++)
    log_printf(1, "PIC: cnt lvl pic_isr  pic_imr  pic_irr (column headers)\n");
  if(header_count>15) header_count=0;

  if(s2)
  log_printf(1, "PIC: %c%2d %08lx %08lx %08lx %s%02d%s\n",
     ci, pic_ilevel, pic_isr, pic_imr, pic_irr, s1, v1, s2);
  else
  log_printf(1, "PIC: %c%2d %08lx %08lx %08lx %s\n",
     ci, pic_ilevel, pic_isr, pic_imr, pic_irr, s1);

}
Beispiel #6
0
/* DANG_BEGIN_FUNCTION write_pic0,write_pic1
 *
 * write_pic_0() and write_pic1() implement dos writes to the pic ports.
 * They are called by the code that emulates inb and outb instructions.
 * Each function implements both ports for the pic:  pic0 is on ports
 * 0x20 and 0x21; pic1 is on ports 0xa0 and 0xa1.  These functions take
 * two arguments: a port number (0 or 1) and a value to be written.
 *
 * DANG_END_FUNCTION
 */
void write_pic0(ioport_t port, Bit8u value)
{

/* if port == 0 this must be either an ICW1, OCW2, or OCW3
 * if port == 1 this must be either ICW2, ICW3, ICW4, or load IMR
 */

#if 0
static char  icw_state,              /* !=0 => port 1 does icw 2,3,(4) */
#endif
static char                icw_max_state;          /* number of icws expected        */
int ilevel;			  /* level to reset on outb 0x20  */

port -= 0x20;
ilevel = 32;
if (pic_isr)
  ilevel=find_bit(pic_isr);
if (ilevel != 32 && !test_bit(ilevel, &pic_irqall)) {
  /* this is a fake IRQ, don't allow to reset its ISR bit */
  pic_print(1, "Protecting ISR bit for lvl ", ilevel, " from spurious EOI");
  ilevel = 32;
}

if (in_dpmi_pm())
  dpmi_return_request();	/* we have to leave the signal context */

if(!port){                          /* icw1, ocw2, ocw3 */
  if(value&0x10){                   /* icw1 */
    icw_max_state = (value & 1) + 1;
    if(value&2) ++icw_max_state;
    pic0_icw_state = 1;
    pic0_cmd=1;
    }

  else if (value&0x08){              /* ocw3 */
    if(value&2) pic0_isr_requested = value&1;
    if(value&64)pic_smm = value&32; /* must be either 0 or 32, conveniently */
    pic0_cmd=3;
    }
  else if((value&0xb8) == 0x20) {    /* ocw2 */
    /* irqs on pic1 require an outb20 to each pic. we settle for any 2 */
     if(!clear_bit(ilevel,&pic1_isr)) {
       clear_bit(ilevel,&pic_isr);  /* the famous outb20 */
       pic_print(1,"EOI resetting bit ",ilevel, " on pic0");
#if 1
	/* XXX hack: to avoid timer interrupt re-entrancy,
	 * we try to disable interrupts in a hope IRET will re-enable
	 * them. This fixes Tetris Classic problem:
	 * https://github.com/stsp/dosemu2/issues/99
	 * Need to check also IMR because DPMI uses another hack
	 * that masks the IRQs. */
       if (ilevel == PIC_IRQ0 && isset_IF() && !(pic_imr & (1 << ilevel))) {
         r_printf("PIC: disabling interrupts to avoid reentrancy\n");
         clear_IF_timed();
       }
#endif
       }
     else
       pic_print(1,"EOI resetting bit ",ilevel, " on pic1");
     pic0_cmd=2;
      }
   }
else                              /* icw2, icw3, icw4, or mask register */
    switch(pic0_icw_state){
     case 0:                        /* mask register */
       set_pic0_imr(value);
       pic_print(1, "Set mask to ", value, " on pic0");
       break;
     case 1:                        /* icw2          */
       set_pic0_base(value);
     default:                       /* icw2, 3, and 4*/
       if(pic0_icw_state++ >= icw_max_state) pic0_icw_state=0;
  }
}
Beispiel #7
0
//----------------------------------------------------------------------
static void attach_bit_comment(ea_t addr, int bit)
{
  const ioport_bit_t *predef = find_bit(addr, bit);
  if ( predef != NULL && get_cmt(cmd.ea, false, NULL, 0) <= 0 )
    set_cmt(cmd.ea, predef->cmt, false);
}
Beispiel #8
0
//----------------------------------------------------------------------
bool outop(op_t &x)
{
  switch ( x.type )
  {

    case o_void:
      return 0;

    case o_reg:
      if ( ram != BADADDR )
      {
        char buf[MAXSTR];
        const char *name = get_name(cmd.ea, ram+x.reg, buf, sizeof(buf));
        if ( name != NULL )
        {
          out_register(name);
          break;
        }
      }
      out_register(ph.regNames[x.reg]);
      break;

    case o_imm:
      if ( cmd.itype == AVR_cbi
        || cmd.itype == AVR_sbic
        || cmd.itype == AVR_sbi
        || cmd.itype == AVR_sbis )
      {
        const char *bit = find_bit(cmd.Op1.addr, (size_t)x.value);
        if ( bit != NULL )
        {
          out_line(bit, COLOR_REG);
          break;
        }
      }
      if ( x.specflag1 && isOff1(uFlag) && !is_invsign(cmd.ea, uFlag, 1) )
      {
        out_symbol('-');
      }
      OutValue(x, OOFS_IFSIGN|OOF_SIGNED|OOFW_8);
      break;

    case o_near:
      {
        ea_t ea = toEA(cmd.cs, x.addr);
        if ( !out_name_expr(x, ea, x.addr) )
          out_bad_address(x.addr);
      }
      break;

    case o_mem:
      {
        ea_t ea = toEA(dataSeg(), x.addr);
        if ( !out_name_expr(x, ea, x.addr) )
          out_bad_address(x.addr);
      }
      break;

    case o_phrase:
      out_phrase(x.phrase);
      break;

    case o_displ:
      out_phrase(x.phrase);
      OutValue(x,OOF_ADDR|OOFS_NEEDSIGN|OOFW_IMM);
      break;

    case o_port:
      {
        const char *pname = find_port(x.addr);
        if ( pname == NULL )
          out_bad_address(x.addr);
        else
          out_register(pname);
      }
      break;

    default:
      warning("out: %a: bad optype %d", cmd.ea, x.type);
      break;
  }
  return 1;
}
Beispiel #9
0
bool outop(op_t &x)
{
  uval_t v;
  int dir, bit;
  char buf[MAXSTR];
  switch ( x.type )
  {
    case o_reg:
      OutReg(x.reg);
      break;

    case o_phrase:
      if ( x.phrase == fRi )
      {
        out_symbol('@');
        OutReg(x.indreg);
        break;
      }
      out_colored_register_line(phrases[x.phrase]);
      break;

    case o_displ:
      out_symbol('@');
      OutReg(x.reg);
      out_symbol('+');
      OutValue(x, OOF_ADDR | OOFS_IFSIGN | OOFW_16);
      break;

    case o_imm:
      out_symbol('#');
      if ( cmd.auxpref & aux_0ext ) out_symbol('0');
      if ( cmd.auxpref & aux_1ext ) out_symbol('1');
      OutValue(x, OOFS_IFSIGN | OOFW_IMM);
      break;

    case o_mem:
    case o_near:
      v = map_addr(x.addr, x.n, x.type==o_mem);
      if ( get_name_expr(cmd.ea+x.offb, x.n, v, x.addr, buf, sizeof(buf)) <= 0 )
      {
/*        int nbit;
        if ( cmd.itype == I51_ecall || cmd.itype == I51_ejmp )
          nbit = OOFW_32;
        else
          nbit = OOFW_16;*/
        OutValue(x, OOF_ADDR | OOF_NUMBER | OOFS_NOSIGN | OOFW_32);
        QueueMark(Q_noName, cmd.ea);
        break;
      }

      // we want to output SFR register names always in COLOR_REG,
      // so remove the color tags and output it manually:

      if ( x.type == o_mem && x.addr >= 0x80 )
      {
        tag_remove(buf, buf, sizeof(buf));
        out_register(buf);
        break;
      }
      OutLine(buf);
      break;

    case o_void:
      return false;

    case o_bit251:
      if ( x.b251_bitneg ) out_symbol('/');
      dir = x.addr;
      bit = x.b251_bit;
      goto OUTBIT;

    case o_bitnot:
      out_symbol('/');
    case o_bit:
      dir = (x.reg & 0xF8);
      bit = x.reg & 7;
      if ( (dir & 0x80) == 0 ) dir = dir/8 + 0x20;
OUTBIT:
      if(ash.uflag & UAS_PBIT)
      {
        const ioport_bit_t *predef = find_bit( dir, bit);
        if ( predef != NULL )
        {
          out_line(predef->name, COLOR_REG);
          break;
        }
      }
      {
        v = map_addr(dir, x.n, true);
        ssize_t len = get_name_expr(cmd.ea+x.offb, x.n, v, dir, buf, sizeof(buf));
        if ( len > 0 && strchr(buf, '+') == NULL )
        {

      // we want to output the bit names always in COLOR_REG,
      // so remove the color tags and output it manually:

          if ( dir < 0x80 )
          {
            OutLine(buf);
          }
          else
          {
            tag_remove(buf, buf, sizeof(buf));
            out_register(buf);
          }
        }
        else
        {
          out_long(dir, 16);
        }
        out_symbol(ash.uflag & UAS_NOBIT ? '_' : '.');
        out_symbol('0'+bit);
      }
      break;

     default:
       warning("out: %a: bad optype",cmd.ea,x.type);
       break;
  }
  return true;
}