Example #1
0
int
privsep_recv(struct io *io, struct msg *msg, struct msgbuf *msgbuf)
{
	char	*tmpbuf;

	if (msgbuf != NULL) {
		msgbuf->buf = NULL;
		msgbuf->len = 0;
	}

	if (io_wait(io, sizeof *msg, INFTIM, NULL) != 0)
		return (-1);
	if (io_read2(io, msg, sizeof *msg) != 0)
		return (-1);

	if (msg->size == 0)
		return (0);

	if (io_wait(io, msg->size, INFTIM, NULL) != 0)
		return (-1);
	if (msgbuf == NULL) {
		if ((tmpbuf = io_read(io, msg->size)) == NULL)
			return (-1);
		xfree(tmpbuf);
	} else {
		if ((msgbuf->buf = io_read(io, msg->size)) == NULL)
			return (-1);
		msgbuf->len = msg->size;
	}

	return (0);
}
Example #2
0
static void remap_pic(void)
{
  u8 mask[2];

  mask[0] = inb(0x21);
  mask[1] = inb(0xa1);

  outb(0x20, 0x11);
  outb(0xa0, 0x11);
  io_wait();

  outb(0x21, 0x20); // map to interrupt range 0x20-0x27
  outb(0xa1, 0x28); // map to interrupt range 0x28-0x2f
  io_wait();

  outb(0x21, 4);    // have slave at IRQ2
  outb(0xa1, 2);    // ping master through IRQ2
  io_wait();

  outb(0x21, 1);    // 8086 mode
  outb(0xa1, 1);    // ditto
  io_wait();

  outb(0x21, mask[0]);
  outb(0xa1, mask[1]);
  io_wait();
}
Example #3
0
void irq_handler(const interrupt_info_t info)
{
    if (info.id >= INTERRUPT_IRQ_CMOS_CLOCK)
    {
        io_write_ui8(PIC_SLAVE_COMMAND, PIC_OCW2_EOI);
        io_wait();
    }

    io_write_ui8(PIC_MASTER_COMMAND, PIC_OCW2_EOI);
    io_wait();

    // Just handle stuff in the ISR handler.
    isr_handler(info);
}
Example #4
0
void pic_remap(int offset1, int offset2) {
    unsigned char a1, a2;
 
    a1 = inb(PIC1_DATA);                        // save masks
    a2 = inb(PIC2_DATA);
 
    outb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);  // starts the initialization sequence (in cascade mode)
    io_wait();
    outb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
    io_wait();
    outb(PIC1_DATA, offset1);                 // ICW2: Master PIC vector offset
    io_wait();
    outb(PIC2_DATA, offset2);                 // ICW2: Slave PIC vector offset
    io_wait();
    outb(PIC1_DATA, 4);                       // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
    io_wait();
    outb(PIC2_DATA, 2);                       // ICW3: tell Slave PIC its cascade identity (0000 0010)
    io_wait();
 
    outb(PIC1_DATA, ICW4_8086);
    io_wait();
    outb(PIC2_DATA, ICW4_8086);
    io_wait();
 
    outb(PIC1_DATA, a1);   // restore saved masks.
    outb(PIC2_DATA, a2);
}
Example #5
0
void pic_remap(int offset1, int offset2)
{
        unsigned char a1, a2;

        /* Save masks */
        a1 = inportb(PIC1_DATA);
        a2 = inportb(PIC2_DATA);

        /* Start the init sequence in cascade mode */
        outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);
        io_wait();
        outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
        io_wait();
        /* ICW2: Master/Slave vector offsets */
        outportb(PIC1_DATA, offset1);
        io_wait();
        outportb(PIC2_DATA, offset2);
        io_wait();
        /* ICW3: Inform Master of slave at IRQ2 */
        outportb(PIC1_DATA, 4);
        io_wait();
        /* ICW3: Tell slave its cascade identity */
        outportb(PIC2_DATA, 2);
        io_wait();

        outportb(PIC1_DATA, ICW4_8086);
        io_wait();
        outportb(PIC2_DATA, ICW4_8086);
        io_wait();

        /* Restore saved masks */
        outportb(PIC1_DATA, a1);
        outportb(PIC2_DATA, a2);
}
Example #6
0
File: irq.c Project: naegi/apropOS
void PIC_remap(uint8_t offset1,uint8_t offset2){

    unsigned char a1, a2;

    a1 = inb(PIC_MASTER_DATA_PORT);                        // save masks
    a2 = inb(PIC_SLAVE_DATA_PORT);

    outb(PIC_MASTER_CONTROL_PORT, ICW1_INIT+ICW1_ICW4);  // starts the initialization sequence (in cascade mode)
    io_wait();
    outb(PIC_SLAVE_CONTROL_PORT, ICW1_INIT+ICW1_ICW4);
    io_wait();
    outb(PIC_MASTER_DATA_PORT, offset1);                 // ICW2: Master PIC vector offset
    io_wait();
    outb(PIC_SLAVE_DATA_PORT, offset2);                 // ICW2: Slave PIC vector offset
    io_wait();
    outb(PIC_MASTER_DATA_PORT, 4);                       // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
    io_wait();
    outb(PIC_SLAVE_DATA_PORT, 2);                       // ICW3: tell Slave PIC its cascade identity (0000 0010)
    io_wait();

    outb(PIC_MASTER_DATA_PORT, ICW4_8086);
    io_wait();
    outb(PIC_SLAVE_DATA_PORT, ICW4_8086);
    io_wait();

    outb(PIC_MASTER_DATA_PORT, a1);   // restore saved masks.
    outb(PIC_SLAVE_DATA_PORT, a2);
}
Example #7
0
/*
 * arguments:
 * 				offset1 - vector offset for master PIC
 * 									vectors on the master become offset1...offset1+7
 * 				offset2 - same for slave PIC: offset2...offset2+7
 */
void PIC_remap(uint8_t master_offset, uint8_t slave_offset)
{
	uint8_t master_mask;
	uint8_t slave_mask;

	master_mask = inb(PIC_MASTER_DATA);/* If no command was send the Data Port can be use to get the interrupt masks */
	slave_mask  = inb(PIC_SLAVE_DATA);

	outb(PIC_MASTER_COMMAND, ICW1_INIT+ICW1_ICW4); /* starts the initialization sequence (in cascade mode) */
	io_wait();
	outb(PIC_SLAVE_COMMAND,  ICW1_INIT+ICW1_ICW4);
	io_wait();
	outb(PIC_MASTER_DATA, master_offset); /* Set the offset of the master PIC */
	io_wait();
	outb(PIC_SLAVE_DATA,  slave_offset);  /* The same for the slave */
	io_wait();
	outb(PIC_MASTER_DATA, 4);             /* Tell master PIC that there is a slave PIC at IQ2 (0000 0100) */
	io_wait();
	outb(PIC_SLAVE_DATA, 2);              /* Tell slave  PIC it's cascade identity (0000 0010) */
	io_wait();
	outb(PIC_MASTER_DATA, ICW4_8086);
	io_wait();
	outb(PIC_SLAVE_DATA,  ICW4_8086);
	io_wait();

	outb(PIC_MASTER_DATA, master_mask); /* Restore the saved masks */
	outb(PIC_SLAVE_DATA,  slave_mask );
}
Example #8
0
void
pic_remap_irq_vector (int offset1, int offset2)
{
  unsigned char a1, a2;

  a1 = inportb (PIC1_DATA);                        // save masks
  a2 = inportb (PIC2_DATA);
  
  outportb (PIC1_COMMAND, ICW1_INIT + ICW1_ICW4);
  io_wait ();
  outportb (PIC2_COMMAND, ICW1_INIT + ICW1_ICW4);
  io_wait ();
  outportb (PIC1_DATA, offset1);
  io_wait ();
  outportb (PIC2_DATA, offset2);
  io_wait ();
  outportb (PIC1_DATA, 4);
  io_wait ();
  outportb (PIC2_DATA, 2);
  io_wait ();
  outportb (PIC1_DATA, ICW4_8086);
  io_wait ();
  outportb (PIC2_DATA, ICW4_8086);
  io_wait ();
  /* Mask all irqs */
  outportb (PIC1_DATA, 0xff);
  outportb (PIC2_DATA, 0xff);
  
  outportb (PIC1_DATA, a1);   // restore saved masks.
  outportb (PIC2_DATA, a2);
}
Example #9
0
void pic_init()
{
	u8 a1, a2;

	a1 = inb(0x21);		// Save masks
	a2 = inb(0xa1);

	outb(0x20, 0x11);	// Start the initialization sequence
	io_wait();
	outb(0xa0, 0x11);
	io_wait();
	outb(0x21, 0x20);	// IRQ 0..7 -> INTR 0x20..0x27
	io_wait();
	outb(0xa1, 0x28);	// IRG 8..15 -> INTR 0x28..0x2f
	io_wait();
	outb(0x21, 4);
	io_wait();
	outb(0xa1, 2);
	io_wait();
	outb(0x21, 1);
	io_wait();
	outb(0xa1, 1);
	io_wait();

	outb(0x21, a1); 	// Restore masks
	outb(0x21, a2);
}
Example #10
0
void pit_init(unsigned int freq)
{
  unsigned int divisor = 1193180 / freq;

  set_interrupt_handler(0x20, irq0);

  outb(0x43, 0x36); // repeat mode
  io_wait();

  outb(0x40, divisor & 255);
  io_wait();

  outb(0x40, divisor >> 8);
  io_wait();
}
Example #11
0
static PyObject*
read_fields(drizzle_con_st *con, drizzle_result_st *result)
{
    int status = 1;    
    size_t offset = 0, size = 0, total = 0;
    drizzle_return_t ret;
    drizzle_field_t field;
    
    while(status){
        field = drizzle_field_read(result, &offset, &size, &total, &ret);
        if (ret == DRIZZLE_RETURN_ROW_END) {
            break;
        }
        status = io_wait(con, ret);
        if (status == -1){
            goto error;
        }
    }
    
    if (field == NULL) {
        Py_RETURN_NONE;
    } else if (offset > 0) {

    } else {

    }
    if (field) {
        drizzle_field_free(field);
    }
    
    Py_RETURN_NONE;
error:

    return NULL;
}
Example #12
0
int main(int argc, char **argv)
{
	io_poller poller;
	
	// clear poller_type because init_poller uses it to see if the poller has been initialized.
	poller.poller_type = IO_POLLER_NONE;
	
	// Process the command line arguments
	// This causes an appropriate poller to be created, mock tests to be installed, etc.
	process_args(&poller, argc, argv);
	if(poller.poller_type == IO_POLLER_NONE) {
		// poller was not initialized probably because no arguments were specified.
		fprintf(stderr, "You must specify --client, --server or --mock.\n");
		exit(1);
	}

	// Run the main event loop.
	for(;;) {
		if(io_wait(&poller, INT_MAX) < 0) {
			perror("io_wait");
		}
		io_dispatch(&poller);
	}

	io_poller_dispose(&poller);
	return 0;
}
Example #13
0
int main()
{
  int64 r;

  if (!io_fd(0)) return 111;
  if (!io_fd(1)) return 111;

  for (;;) {
    if (flageof && writepos >= readpos) return 0;

    if (!flageof && readpos < sizeof buf) io_wantread(0);
    if (writepos < readpos) io_wantwrite(1);
    io_wait();
    if (!flageof && readpos < sizeof buf) io_dontwantread(0);
    if (writepos < readpos) io_dontwantwrite(1);

    if (!flageof && readpos < sizeof buf) {
      r = io_tryread(0,buf + readpos,sizeof buf - readpos);
      if (r <= -2) return 111; /* read error other than EAGAIN */
      if (r == 0) flageof = 1;
      if (r > 0) readpos += r;
    }

    if (writepos < readpos) {
      r = io_trywrite(1,buf + writepos,readpos - writepos);
      if (r <= -2) return 111; /* write error other than EAGAIN */
      if (r > 0) {
	writepos += r;
	if (writepos == readpos) readpos = writepos = 0;
	/* if writepos is big, might want to left-shift buffer here */
      }
    }
  }
}
Example #14
0
static struct io_plan *r_done(struct io_conn *conn, struct data *d)
{
	d->state++;
	if (d->state == 3)
		return io_close(conn);
	return io_wait(conn, NULL, io_never, NULL);
}
Example #15
0
static PyObject*
ConnectionObject_autocommit(ConnectionObject *self, PyObject *args)
{
    int flag, status = 1;
    char query[256];

    drizzle_return_t ret;
    drizzle_result_st result;

    if (!PyArg_ParseTuple(args, "i", &flag)) {
        return NULL;
    }

    DEBUG("autocommit %d", flag);
    snprintf(query, 256, "SET AUTOCOMMIT=%d;", flag);
    BDEBUG("query %s", query);
    
    while(status){
        (void)drizzle_query(self->con, &result, query, 256, &ret);
        status = io_wait(self->con, ret);
        if (status == -1){
            goto error;
        }
    }

    drizzle_result_free(&result);
    Py_RETURN_NONE;
error:
    drizzle_result_free(&result);
    PyErr_SetString(PyExc_IOError, drizzle_error(drizzle));
    return NULL;
}
Example #16
0
static PyObject* 
get_desc(result_t *r, drizzle_con_st *con, drizzle_result_st *result)
{
    int status = 1, desclen = 0;
    uint16_t size = 0;
    drizzle_return_t ret;
    drizzle_column_st column;
    drizzle_column_st *c;
    PyObject *c_info = NULL;
    PyObject *desc = NULL;
    drizzle_column_type_t *types = NULL;
    
    size = drizzle_result_column_count(result);
    DEBUG("column count:%d" , size);
    
    r->column_count = size;
    types = PyMem_Malloc(sizeof(drizzle_column_type_t) * size);
    if (types == NULL) {
        return NULL;
    }
    r->types = types;

    desc = PyTuple_New(size);
    if (desc == NULL) {
        return NULL;
    }

    while (1) {
        c = drizzle_column_read(result, &column, &ret);
        status = io_wait(con, ret);
        if (status == -1) {
            goto error;
        }
        if (c == NULL) {
            break;
        } else {
            c_info = get_column_desc(desclen, types, &column);
            if (c_info == NULL) {
                goto error;
            }
            PyTuple_SetItem(desc, desclen, c_info);
            c_info = NULL;
            drizzle_column_free(c);
            desclen++;
        }
    }
    return desc;
error:
    if (c) {
        drizzle_column_free(c);
    }
    if (c_info) {
        Py_DECREF(c_info);
    }
    if (desc) {
        Py_DECREF(desc);
    }
    return NULL;
}
Example #17
0
File: iotest.c Project: aurora/rzh
int main(int argc, char **argv)
{
	int sd;
	struct sockaddr_in sin;

	io_init();

	printf("Opening listening socket...\n");

	if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket");
		exit(1);
	}

	if(set_nonblock(sd) < 0) {
		perror("setnonblocking");
		close(sd);
		exit(1);
	}

	memset(&sin, 0, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(PORT);
	sin.sin_addr.s_addr = htonl(INADDR_ANY);

	if(bind(sd, (struct sockaddr*)&sin, sizeof(sin)) < 0) {
		perror("bind");
		close(sd);
		exit(1);
	}

	if (listen(sd, STD_LISTEN_SIZE) == -1) {
		perror("listen");
		close(sd);
		exit(1);
	}

	g_accepter.fd = sd;
	g_accepter.proc = accept_proc;

	if(io_add(&g_accepter, IO_READ) < 0) {
		perror("io_add_main");
		close(sd);
		exit(1);
	}

	printf("Listening on port %d, fd %d.\n", PORT, g_accepter.fd);

	for(;;) {
		io_wait(MAXINT);
	}

	io_exit();

	return 0;
}
Example #18
0
static struct io_plan *read_json(struct io_conn *conn,
				 struct json_connection *jcon)
{
	jsmntok_t *toks;
	bool valid;

	log_io(jcon->log, true, jcon->buffer + jcon->used, jcon->len_read);

	/* Resize larger if we're full. */
	jcon->used += jcon->len_read;
	if (jcon->used == tal_count(jcon->buffer))
		tal_resize(&jcon->buffer, jcon->used * 2);

again:
	toks = json_parse_input(jcon->buffer, jcon->used, &valid);
	if (!toks) {
		if (!valid) {
			log_unusual(jcon->dstate->base_log,
				    "Invalid token in json input: '%.*s'",
				    (int)jcon->used, jcon->buffer);
			return io_close(conn);
		}
		/* We need more. */
		goto read_more;
	}

	/* Empty buffer? (eg. just whitespace). */
	if (tal_count(toks) == 1) {
		jcon->used = 0;
		goto read_more;
	}

	parse_request(jcon, toks);

	/* Remove first {}. */
	memmove(jcon->buffer, jcon->buffer + toks[0].end,
		tal_count(jcon->buffer) - toks[0].end);
	jcon->used -= toks[0].end;
	tal_free(toks);

	/* Need to wait for command to finish? */
	if (jcon->current) {
		jcon->len_read = 0;
		return io_wait(conn, jcon, read_json, jcon);
	}

	/* See if we can parse the rest. */
	goto again;

read_more:
	tal_free(toks);
	return io_read_partial(conn, jcon->buffer + jcon->used,
			       tal_count(jcon->buffer) - jcon->used,
			       &jcon->len_read, read_json, jcon);
}
//-------------------------------------------------------------------------------------------------------------------------------
//
//  读取硬盘分区信息函数
//
//-------------------------------------------------------------------------------------------------------------------------------
int ReadPartition(void)
{
	int i = 0;
	int sector, head, cylinder;
	unsigned char buffer[512];
	struct partition* p;

#ifndef HD_BOOT_SECTOR
#define HD_BOOT_SECTOR 0
#endif

  ConsolePrintf("Check the hard disk partition\n");

	sector = HD_BOOT_SECTOR &0xff;
	cylinder = (HD_BOOT_SECTOR &0xffff00)>>8;
	head = (HD_BOOT_SECTOR &0xf000000)>>24;
  
	while(inb(HD_STATUS) & 0x80);
	io_wait();
	outb(0,HD_CMD);
	outb(1,0x1f2);                   ///////////读写的扇区数.这个端口应该是:0X1F2,下面开始增加一
	outb(HD_BOOT_SECTOR,0x1f3);      ////////开始扇区
	outb(cylinder,0x1f4);            ///////开始柱面
	outb(cylinder>>8,0x1f5);         ///////开始柱面高位
	outb(0xE0|(0 <<4)|head,0x1f6);   /////主磁盘
	outb(0x20,0x1F7);                ////read命令
  while(inb(HD_STATUS) & 0x80);
	insw(0x1F0, buffer, 256);

	if (buffer[510] != (unsigned char) 0x55 || buffer[511] != (unsigned char) 0xAA){
		ConsolePrintFault();
		ConsoleWarning("  read_partition(): Can't Read Harddisk(IDE) partition data\n");
		return -1;
	}
  
	ConsolePrintOK();
	for (i=1;i<5;i++)
	{

	   p = (struct partition*)&buffer[0x1be + (i-1)*0x10]; //partition table offset after 446 byte.
		 hd[i].start_sect = p->start_sec;  	                 // 从0算起的绝对扇区(分区表的起始扇区,不是FAT表的)
		 hd[i].start_head=p->start_head;
		 hd[i].start_cyl=p->start_cyl;
		 hd[i].nr_sects = p->size;                           // 分区扇区总数 
		 hd[i].flag = p->type;
		 hd[i].lowsec = p->lowsec;
		 hd[i].type = GetPartitionName( p->type);
	   hd[i].name = 0x42+i;
	   FindActivePartition(p, i);
	}

	ReadIDEInfo();

	return 0;
}
Example #20
0
void irq_clear_mask(uint8_t irq){
  uint16_t port;
  if(irq < 8){
    port = MPIC_DAT_ADDR;
  } else {
    port = SPIC_DAT_ADDR;
    irq -= 8;
  }

  uint8_t value = inb(port) & ~(1 << irq);
  outb(port, value);
  io_wait();
}
Example #21
0
bool Keyboard::waitForBuffer(uint8_t buffer, bool state)
{
	int counter = 0;
	uint8_t status = 0x00;
	do
	{
		status = inb(0x64);
		io_wait();
		counter++;
		if(counter > 16)
			return false;
	} while((status & buffer) != (state ? buffer : 0));
	return true;
}
Example #22
0
void init_PIC()
{
    //PIC1 Command: 0x20	data: 0x21
    //PIC2 Command: 0xA0	data: 0xA1
    //Send a 0x20 to the Command Port for EOI
    //
    //0x11 = initialize command
    //	makes PIC wait for 3 more words
    //	fist: vector offset
    //	second: how it is wired to slave/master
    //	third: environment info



    //Save the PIC masks
    unsigned char mask1, mask2;
    mask1 = inportb(PIC1_DATA);
    mask2 = inportb(PIC2_DATA);

    //initialize the PICs
    outportb(PIC1_COMMAND, PIC_INIT);
    io_wait();
    outportb(PIC2_COMMAND, PIC_INIT);
    io_wait();
    //set vector table offset!!
    outportb(PIC1_DATA, 32);
    io_wait();
    outportb(PIC2_DATA, 40);
    io_wait();
    //tell master there is a slave at irq2
    outportb(PIC1_DATA, 4);
    io_wait();
    //tell slave its cascade identity??
    outportb(PIC2_DATA, 2);
    io_wait();
    //put PICs into 8086 mode
    outportb(PIC1_DATA, 0x01);
    io_wait();
    outportb(PIC2_DATA, 0x01);
    io_wait();
    //restore the saved masks
    outportb(PIC1_DATA, mask1);
    outportb(PIC2_DATA, mask2);


}
Example #23
0
/* rimappa i PIC (programmable input controller)
 * offset_1: offset riferito alla IDT delle interruzioni per il primo PIC
 * offset_2: offset riferito alla IDT delle interruzioni per il PIC slave
 */
void irq_remap(unsigned int offset_1, unsigned int offset_2) {
  /*
   * PIC_P e' il PIC primario o "master"
   * PIC_S e' il PIC secondario o "slave"
   *
   * Quando si manifesta un IRQ che riguarda il PIC secondario,
   * il PIC primario riceve IRQ 2
   *
   * ICW = initialization command word
   * OCW = operation command word
   */

  /* Inizializzazione                                */
  /* 0x10 significa che si sta' inizializzando       */
  /* 0x01 significa che si deve arrivare fino a ICW4 */
  sendICW(0x11, 0x11, 0);
  io_wait();

  /* ICW2: PIC_P a partire da "offset_1" */
  /*       PIC_S a partire da "offset_2" */
  sendICW(offset_1, offset_2, 1);
  io_wait();

  /* ICW3: PIC_P: IRQ2 per pilotare PIC_S    */
  /*       PIC_S: pilotato con IRQ2 da PIC_P */
  sendICW(0x04, 0x02, 1);
  io_wait();

  /* ICW4: si precisa la modalita' del microprocessore; 0x01 = 8086 */
  sendICW(0x01, 0x01, 1);
  io_wait();

  /* OCW1: azzera la maschera in modo da abilitare tutti i numeri IRQ */
  sendICW(0x00, 0x00, 1);
  io_wait();
}
Example #24
0
static void init_conn(int fd, struct data *d)
{
	int fd2;

	ok1(d->state == 0);
	d->state++;
	idler = io_new_conn(fd, io_wait(d, read_buf, d));
	io_set_finish(idler, finish_idle, d);

	/* This will wake us up, as read will fail. */
	fd2 = open("/dev/null", O_RDONLY);
	ok1(fd2 >= 0);
	io_set_finish(io_new_conn(fd2, io_read(idler, 1, never, NULL)),
		      finish_waker, d);
}
Example #25
0
static struct io_plan *init_idle(struct io_conn *conn, struct data *d)
{
	int fd2;

	ok1(d->state == 0);
	d->state++;
	idler = conn;
	io_set_finish(conn, finish_idle, d);

	/* This will wake us up, as read will fail. */
	fd2 = open("/dev/null", O_RDONLY);
	ok1(fd2 >= 0);
	io_set_finish(io_new_conn(NULL, fd2, init_waker, d), finish_waker, d);

	return io_wait(conn, d, read_buf, d);
}
Example #26
0
/**
 * Main event loop for OpenVPN in client mode, where only one VPN tunnel
 * is active.
 * @ingroup eventloop
 *
 * @param c - The context structure of the single active VPN tunnel.
 */
static void
tunnel_point_to_point(struct context *c)
{
    context_clear_2(c);

    /* set point-to-point mode */
    c->mode = CM_P2P;

    /* initialize tunnel instance */
    init_instance_handle_signals(c, c->es, CC_HARD_USR1_TO_HUP);
    if (IS_SIG(c))
    {
        return;
    }

    /* main event loop */
    while (true)
    {
        perf_push(PERF_EVENT_LOOP);

        /* process timers, TLS, etc. */
        pre_select(c);
        P2P_CHECK_SIG();

        /* set up and do the I/O wait */
        io_wait(c, p2p_iow_flags(c));
        P2P_CHECK_SIG();

        /* timeout? */
        if (c->c2.event_set_status == ES_TIMEOUT)
        {
            perf_pop();
            continue;
        }

        /* process the I/O which triggered select */
        process_io(c);
        P2P_CHECK_SIG();

        perf_pop();
    }

    uninit_management_callback();

    /* tear down tunnel instance (unless --persist-tun) */
    close_instance(c);
}
//-------------------------------------------------------------------------------------------------------------------------------
//
//  硬盘读写处理函数
//
//-------------------------------------------------------------------------------------------------------------------------------
void HardDiskRW(int RW, unsigned long sectors, void* buffer)
{
  unsigned __eflag;
	int sector, head, cylinder;

  save_eflags(&__eflag);

	sector   = sectors &0xff;
	cylinder = (sectors &0xffff00)>>8;
	head     = (sectors &0xf000000)>>24;

	while(inb(HD_STATUS) & 0x80);
	io_wait();
	outb(0,HD_CMD);

	outb(1,0x1f2);                 ///////////读写的扇区数.这个端口应该是:0X1F2,下面开始增加一
	outb(sector,0x1f3);            ////////开始扇区
	outb(cylinder,0x1f4);          ///////开始柱面
	outb(cylinder>>8,0x1f5);       ///////开始柱面高位
	outb(0xE0|(0 <<4)|head,0x1f6); /////主磁盘

	if (RW == READ)
	{                              ////read命令
	    outb(0x20,0x1F7);         
        while(inb(HD_STATUS) & 0x80);
	    insw(0x1F0, buffer, 256);
	}
	else if (RW == WRITE)
	{                             ////write命令

	if (inb(HD_STATUS & 0x01)) {
		ConsoleWarning("  issue write_command command error !\n");
		return;
	}

		 outb(0x30,0x1F7);   
	   while((inb(HD_STATUS) & 0x08) == 0);       //DRQ
	     outsw(0x1F0, buffer, 256);
     }
	else {
		ConsoleWarning("  Panic:bad command:you only can read or write on harddisk!");
	}
	restore_eflags(__eflag);
	return;
}
Example #28
0
static struct io_plan do_send_tx(struct io_conn *conn, struct generator *gen)
{
	struct pending_update *u;

	assert(conn == gen->update);

	u = list_top(&gen->updates, struct pending_update, list);
	if (u) {
		log_debug(gen->log,
			  "Sending transaction update shard %u off %u",
			  u->update.shard, u->update.txoff);

		return io_write(&u->update, sizeof(u->update), tx_sent, gen);
	}

	log_debug(gen->log, "Sending transactions going idle %p", gen);
	return io_wait(gen, do_send_tx, gen);
}
Example #29
0
ATADEV_TYPE DISK::detect_device_type()
{
	soft_reset();
	if (m_master) outportb(m_bus + ATA_REG_HDDEVSEL, 0xA0);
	else outportb(m_bus + ATA_REG_HDDEVSEL, 0xB0);
	io_wait();

	unsigned char cl = inportb(m_bus + ATA_REG_LBA1); /* CYL_LO */
	unsigned char ch = inportb(m_bus + ATA_REG_LBA2); /* CYL_HI */

	printf("ATA device type %02X%02X\n",ch,cl);
													  /* differentiate ATA, ATAPI, SATA and SATAPI */
	if (cl == 0x14 && ch == 0xEB) return ATADEV_PATAPI;
	if (cl == 0x69 && ch == 0x96) return ATADEV_SATAPI;
	if (cl == 0 && ch == 0) return ATADEV_PATA;
	if (cl == 0x3c && ch == 0xc3) return ATADEV_SATA;
	return ATADEV_UNKNOWN;
}
Example #30
0
static void server_mainloop( ) {
  static time_t ot_last_clean_time;
  time_t        next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL;
  struct        iovec *iovector;
  int           iovec_entries;

  for( ; ; ) {
    int64 i;

    io_wait();

    while( ( i = io_canread( ) ) != -1 ) {
      const void *cookie = io_getcookie( i );
      if( cookie == FLAG_TCP )
        handle_accept( i );
      else if( cookie == FLAG_UDP )
        handle_udp4( i );
      else
        handle_read( i );
    }

    while( ( i = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 )
      http_sendiovecdata( i, iovec_entries, iovector );

    while( ( i = io_canwrite( ) ) != -1 )
      handle_write( i );

    if( g_now > next_timeout_check ) {
      while( ( i = io_timeouted() ) != -1 )
        handle_dead( i );
      next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL;
    }

    /* See if we need to move our pools */
    if( NOW != ot_last_clean_time ) {
      ot_last_clean_time = NOW;
      clean_all_torrents();
    }

    /* Enforce setting the clock */
    signal_handler( SIGALRM );
  }
}