Пример #1
0
int main(int argc, char* argv[])
{
    int i, j, loops;

    // -=# monitoring code start #=-
    ferret_ulist_local_t * l1 = NULL;
    int ret;

    l4_sleep(1000);
    // create sensor and configure it to an element size of 64 with
    // 1000 list entries
    ret = ferret_create(12, 2, 0, FERRET_ULIST,
                        FERRET_SUPERPAGES, "64:1000", l1, &malloc);
    if (ret)
    {
        LOG("Error creating sensor: ret = %d", ret);
        exit(1);
    }
    // -=# monitoring code end #=-

    j = 0;
    while (1)
    {
        // -=# monitoring code start #=-
        ferret_ulist_post_1w(l1, 1, 2, 3, 0xabcd1234);
        // -=# monitoring code end #=-

        // do some work
        loops = 10000 + l4util_rand();
        for (i = 0; i < loops; i++)
            asm volatile ("": : : "memory");

        // -=# monitoring code start #=-
        ferret_ulist_post_1w(l1, 1, 2, 3, 0xabcd5678);
        // -=# monitoring code end #=-

        l4_sleep(100);
        j++;
    }

    // -=# monitoring code start #=-
    /* will never be reached due to the infinite loop above, but
     * demonstrates cleanup.
     *
     * The sensor will be freed after all parties released it, that
     * is, the creator and all monitors.
     */
    ret = ferret_free_sensor(12, 2, 0, l1, &free);
    if (ret)
    {
        LOG("Error freeing sensor: ret = %d", ret);
        exit(1);
    }
    // -=# monitoring code end #=-

    return 0;
}
Пример #2
0
static void alien_thread(void)
{
  volatile l4_msgtag_t x;
  while (1) {
    x = l4_ipc_call(0x1234 << L4_CAP_SHIFT, l4_utcb(), l4_msgtag(0, 0, 0, 0), L4_IPC_NEVER);
#ifdef MEASURE
    l4_sleep(0);
#else
    l4_sleep(1000);
    outstring("An int3 -- you should see this\n");
    outnstring("345", 3);
#endif
  }

}
Пример #3
0
 void enterExclusive() const {
     l4_utcb_t * utcb = l4_utcb();
     _lock.enter();
     while(!_locked.empty() && _locked.find(utcb) == _locked.end()){
        _lock.leave();
         l4_sleep(0);
         _lock.enter();
     }
     ++_locked[utcb];
     while(!_measuring.empty()){
        _lock.leave();
         l4_sleep(0);
         _lock.enter();
     }
    _lock.leave();
 }
Пример #4
0
/* Lock the spin lock object LOCK.  If the lock is held by another
   thread spin until it becomes available.  */
int
_pthread_spin_lock (__pthread_spinlock_t *lock)
{
  int i;

#ifdef USE_L4
  /* Start with a small timeout of 2 microseconds, then back off
     exponentially.  */
  l4_time_t timeout;
  timeout = l4_time_period (2);
#else
# warning Do not know how to sleep on this platform.
#endif

  while (1)
    {
      for (i = 0; i < __pthread_spin_count; i++)
	{
	  if (__pthread_spin_trylock (lock) == 0)
	    return 0;
	}

#ifdef USE_L4
      l4_sleep (timeout);

      timeout = l4_time_mul2 (timeout);
      if (timeout == L4_NEVER)
	timeout = L4_TIME_PERIOD_MAX;
#endif
    }
}
Пример #5
0
int main(void)
{
  l4_uint32_t value;

  if (l4rtc_get_offset_to_realtime(&value))
    printf("Error: l4rtc_get_offset_to_realtime\n");
  else
    printf("offset-to-realtime: %d\n", value);

  if (l4rtc_get_linux_tsc_scaler(&value))
    printf("Error: l4rtc_get_linux_tsc_scaler\n");
  else
    printf("linux-tsc-scaler: %d\n", value);

  while (1)
    {
      if (l4rtc_get_seconds_since_1970(&value))
        printf("Error: l4rtc_get_seconds_since_1970\n");
      else
        printf("time: %d\n", value);
      l4_sleep(400);
    }

  return 0;
}
Пример #6
0
int main(void)
{
  const int seconds = 5;
  l4irq_t *irqdesc;

  if (!(irqdesc = l4irq_request(IRQ_NO, isr_handler, 0, 0xff, 0)))
    {
      printf("Requesting IRQ %d failed\n", IRQ_NO);
      return 1;
    }

  printf("Attached to key IRQ %d\nPress keys now, will terminate in %d seconds\n",
         IRQ_NO, seconds);

  l4_sleep(seconds * 1000);

  if (l4irq_release(irqdesc))
    {
      printf("Failed to release IRQ\n");
      return 1;
    }

  printf("Bye\n");
  return 0;
}
Пример #7
0
int
main(void)
{
  for (;;)
    {
      puts("hey");
      l4_sleep(200);
    }
}
Пример #8
0
int main(void)
{
    l4_sleep(6000);

    test1();
    test2();

    return 0;
}
Пример #9
0
void
halt (void)
{
#ifdef _L4_TEST_ENVIRONMENT
  abort ();
#else
  l4_sleep (L4_NEVER);
#endif
}
Пример #10
0
/* The thread to be created. For illustration it will print out its
 * register set.
 */
static void L4_STICKY(thread_func(l4_umword_t *d))
{
  while (1)
    {
      printf("hey, I'm a thread\n");
      printf("got register values: %ld %ld %ld %ld %ld %ld %ld\n",
             d[7], d[6], d[5], d[4], d[2], d[1], d[0]);
      l4_sleep(800);
    }
}
Пример #11
0
 void enterMeasurement() const{
     l4_utcb_t * utcb = l4_utcb();
     _lock.enter();
     while(!_locked.empty() && (_measuring.find(utcb) == _measuring.end())){
        _lock.leave();
         l4_sleep(0);
         _lock.enter();
     }
     ++_measuring[utcb];
    _lock.leave();
 }
Пример #12
0
/* UDELAY */
void udelay(unsigned long usecs)
{
#ifdef ARCH_arm
  l4_sleep(usecs/1000); // XXX
#elif defined(ARCH_mips)
#warning KYMA ARCH_mips l4_busy_wait_us() not implemented, using l4_usleep instead.
  // this gives up control of cpu; it's not always what's wanted...
  l4_usleep(usecs);
#else
  l4_busy_wait_us(usecs);
#endif
}
Пример #13
0
int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
{
    unsigned long timeout;

    /*
     * set synchronisation state between this boot processor
     * and the secondary one
     */
    spin_lock(&boot_lock);

    /*
     * The secondary processor is waiting to be released from
     * the holding pen - release it, then wait for it to flag
     * that it has been released by resetting pen_release.
     *
     * Note that "pen_release" is the hardware CPU ID, whereas
     * "cpu" is Linux's internal ID.
     */
    write_pen_release(cpu);

    /*
     * Send the secondary CPU a soft interrupt, thereby causing
     * the boot monitor to read the system wide flags register,
     * and branch to the address found there.
     */
    //l4/smp_cross_call(cpumask_of(cpu), 1);
    l4x_cpu_release(cpu);

    timeout = jiffies + (1 * HZ);
    while (time_before(jiffies, timeout)) {
        smp_rmb();
        if (pen_release == -1)
            break;

        //udelay(10);
        {
            L4XV_V(f);
            L4XV_L(f);
            l4_sleep(10);
            L4XV_U(f);
        }
    }

    /*
     * now the secondary core is starting up let it run its
     * calibrations, then wait for it to finish
     */
    spin_unlock(&boot_lock);

    return 0; //pen_release != -1 ? -ENOSYS : 0;
}
Пример #14
0
/******************************************************************************
 * logo                                                                       *
 *                                                                            *
 * show logo on screen using pSLIM SET                                        *
 ******************************************************************************/
int logo()
{
  int ret = 0, i;
  char buffer[30];

  static l4_int16_t xy_idx[][2] = 
    {
	{ 170,  10}, { 300, 100}, 
	{   0, 360}, { 470, 280},
	{ -50, 200}, { 280, 290},
	{ 540, 400}, { 300, 300},
	{ 330, 350}, { 400,-100}
    };

  l4con_pslim_rect_t rect;
  CORBA_Environment _env = dice_default_environment;

  /* setup initial vfb area info */
  rect.x = 0; rect.y = 0;
  rect.w = 160; rect.h = 120;

  for (i=0; i<=10; i++) 
    {
      ret = con_vc_pslim_set_call(&vc_l4id, 
			     &rect,
	      		     (l4_uint8_t*)pmap_buf, 
			     38400,
			     &_env);
      if (ret) 
	{
	  ret2ecodestr(ret, buffer);
	  LOG("pslim_set returned %s error", buffer);
	  return -1;
	}
      if (DICE_HAS_EXCEPTION(&_env))
	{
	  LOG("pslim_set returned ipc error: 0x%02x", DICE_IPC_ERROR(&_env));
	  CORBA_exception_free(&_env);
	}

      /* setup new vfb area info */
      rect.x = xy_idx[i][0]; rect.y = xy_idx[i][1];

      l4_sleep(800);
    }

  return 0;
}
Пример #15
0
static void
uxScreenUpdate(int x, int y, int w, int h)
{
  (void)x; (void)y; (void)w; (void)h;
  if (!waiting)
    {
      lx_kill(ux_con_pid, LX_SIGUSR1);
      waiting = 1;
      while (l4_ipc_error(l4_ipc_send(updater_id, l4_utcb(),
                                      l4_msgtag(0, 0, 0, 0),
                                      L4_IPC_BOTH_TIMEOUT_0), l4_utcb()))
        {
          l4_sleep(1);
        }
    }
}
Пример #16
0
static void *thread_producer(void *d)
{
  (void)d;
  l4shmc_chunk_t p_one;
  l4shmc_signal_t s_one, s_done;
  l4shmc_area_t shmarea;

  l4_debugger_set_object_name(pthread_getl4cap(pthread_self()), "prod");

  // attach this thread to the shm object
  CHK(l4shmc_attach("testshm", &shmarea));

  // add a chunk
  CHK(l4shmc_add_chunk(&shmarea, "one", 1024, &p_one));

  // add a signal
  CHK(l4shmc_add_signal(&shmarea, "prod", &s_one));

  // connect chunk and signal
  CHK(l4shmc_connect_chunk_signal(&p_one, &s_one));

  CHK(l4shmc_attach_signal_to(&shmarea, "done",
                              pthread_getl4cap(pthread_self()), 10000, &s_done));

  printf("PRODUCER: ready\n");

  while (1)
    {
      while (l4shmc_chunk_try_to_take(&p_one))
        printf("Uh, should not happen!\n"); //l4_thread_yield();

      set_some_data();

      memcpy(l4shmc_chunk_ptr(&p_one), some_data, sizeof(some_data));

      CHK(l4shmc_chunk_ready_sig(&p_one, sizeof(some_data)));

      printf("PRODUCER: Sent data %s\n", some_data);

      CHK(l4shmc_wait_signal(&s_done));

      l4_sleep(5000);
    }

  l4_sleep_forever();
  return NULL;
}
Пример #17
0
static void *updater_thread(void *data)
{
  l4_umword_t l;
  (void)data;

  l4_thread_control_start();
  l4_thread_control_ux_host_syscall(1);
  l4_thread_control_commit(pthread_getl4cap(pthread_self()));

  while (1)
    {
      if (l4_ipc_error(l4_ipc_wait(l4_utcb(), &l, L4_IPC_NEVER), l4_utcb()))
        printf("updater_thread: l4_ipc_wait failed\n");
      l4_sleep(30);
      lx_kill(ux_con_pid, LX_SIGUSR1);
      waiting = 0;
    }
  return NULL;
}
Пример #18
0
int main(void)
{
	printf("starting Hello (C version)\n");

	void *ebuf = (void*)0xB0000000;
	
	unsigned i = 0;
	for ( ; i < 5; ++i) {

		struct GenericEvent *ev = evbuf_next(ebuf);
		ev->header.tsc = evbuf_get_time(ebuf, 1);
		ev->header.vcpu = 0x1234;
		ev->header.type = 4;

		printf("HELLO..\n");

		l4_sleep(1000);
	}
	return 0;
}
Пример #19
0
/* Lock the spin lock object LOCK.  If the lock is held by another
   thread spin until it becomes available.  */
int
_pthread_spin_lock (__pthread_spinlock_t *lock)
{
  l4_time_t timeout;
  int i;

  /* Start with a small timeout of 2 microseconds, then back off
     exponentially.  */
  timeout = l4_time_period (2);

  while (1)
    {
      for (i = 0; i < __pthread_spin_count; i++)
	{
	  if (__pthread_spin_trylock (lock) == 0)
	    return 0;
	}
      l4_sleep (timeout);

      timeout = l4_time_mul2 (timeout);
      if (timeout == L4_NEVER)
	timeout = L4_TIME_PERIOD_MAX;
    }
}
Пример #20
0
void
shutdown_machine (void)
{
  if (shutdown_reset)
    {
      l4_time_t timespec = l4_time_period (SLEEP_TIME * 1000UL * 1000UL);

      l4_sleep (timespec);
      reset ();
    }
  else
    halt ();

  /* Never reached.  */
  if (shutdown_reset)
    {
      printf ("Unable to reset this machine.\n");
      halt ();
    }

  printf ("Unable to halt this machine.\n");
  while (1)
    ;
}
Пример #21
0
int main(int argc, char **argv)
{
	if (l4ankh_init())
	  return 1;

	l4_cap_idx_t c = pthread_getl4cap(pthread_self());
	cfg.send_thread = c;

	static struct option long_opts[] = {
		{"bufsize", 1, 0, BUF_SIZE },
		{"shm", 1, 0, SHM_NAME },
		GETOPT_LIST_END
	};

	while (1) {
		int optind = 0;
		int opt = getopt_long(argc, argv, "b:s:", long_opts, &optind);
		printf("getopt: %d\n", opt);

		if (opt == -1)
			break;

		switch(opt) {
			case BUF_SIZE:
				printf("buf size: %d\n", atoi(optarg));
				cfg.bufsize = atoi(optarg);
				break;
			case SHM_NAME:
				printf("shm name: %s\n", optarg);
				snprintf(cfg.shm_name, CFG_SHM_NAME_SIZE, "%s", optarg);
				break;
			default:
				break;
		}
	}

	// Start the TCP/IP thread & init stuff
	tcpip_init(NULL, NULL);
	struct netif *n = netif_add(&my_netif,
	                            &ipaddr, &netmask, &gw,
	                            &cfg, // configuration state
	                            ankhif_init, ethernet_input);

	printf("netif_add: %p (%p)\n", n, &my_netif);
	assert(n == &my_netif);

	printf("dhcp_start()\n");
	dhcp_start(&my_netif);
	printf("dhcp started\n");

	while (!netif_is_up(&my_netif))
		l4_sleep(1000);
	printf("Network interface is up.\n");

	printf("IP: "); lwip_util_print_ip(&my_netif.ip_addr); printf("\n");
	printf("GW: "); lwip_util_print_ip(&my_netif.gw); printf("\n");

	dns_test();
	server();

	return 0;
}
Пример #22
0
int main(int argc, char* argv[])
{
    /* 1. startup
     * 2. poll to open all relevant sensors (0:0:0, 1:0:0)
     * 3. in loop get new events and reorder according to time
     * 4. if between atomic begin and atomic end other scheduling
     *    event in same task -> flag error
     */

    int ret;
    ferret_list_moni_t * list = NULL;
    ferret_tbuf_moni_t * tbuf = NULL;
    l4_tracebuffer_entry_t     tbuf_e;   // native tracebuffer entry
    ferret_list_entry_common_t list_e;   // list entry for other sensors
    ferret_list_entry_kernel_t list_te;  // list entry for converted tbuf entry

    printf("History buffer and position addresses: %p, %p\n",
           &history, &history_position);

    if (parse_args(argc, argv))
        return 1;

    // open relevant sensors
    while ((ret = ferret_att(FERRET_TBUF_MAJOR, FERRET_TBUF_MINOR,
                             FERRET_TBUF_INSTANCE, tbuf)))
    {
        printf("Could not attach to %hd:%hd:%hd, retrying soon ...\n",
            FERRET_TBUF_MAJOR, FERRET_TBUF_MINOR, FERRET_TBUF_INSTANCE);
        l4_sleep(1000);
    }
    printf("Attached to %hd:%hd:%hd.\n",
        FERRET_TBUF_MAJOR, FERRET_TBUF_MINOR, FERRET_TBUF_INSTANCE);

    while ((ret = ferret_att(FERRET_L4LX_MAJOR, FERRET_L4LX_LIST_MINOR,
                             1, list)))
    {
        printf("Could not attach to %hd:%hd:%hd, retrying soon ...\n",
            FERRET_L4LX_MAJOR, FERRET_L4LX_LIST_MINOR, 1);
        l4_sleep(1000);
    }
    printf("Attached to %hd:%hd:%hd.\n",
        FERRET_L4LX_MAJOR, FERRET_L4LX_LIST_MINOR, 1);

    // at first, fill the reorder buffers with one element from each sensor
    while (1)
    {
        ret = ferret_tbuf_get(tbuf, &tbuf_e);
        if (ret == -1)
        {
            //LOG("Waiting for element in tbuf ...");
            l4_sleep(1000);
            continue;
        }
        else if (ret < -1)
        {
            printf("Something wrong with tbuf: %d\n", ret);
            exit(1);
        }
        ferret_util_convert_k2c(&tbuf_e, &list_te);
        break;
    }


    while (1)
    {
        ret = ferret_list_get(list, (ferret_list_entry_t *)&list_e);
        if (ret == -1)
        {
            //LOG("Waiting for element in list ...");
            l4_sleep(1000);
            continue;
        }
        else if (ret < -1)
        {
            printf("Something wrong with list: %d\n", ret);
            exit(1);
        }
        break;
    }

    // periodically read from sensors
    while (1)
    {
        if (list_e.timestamp < list_te.timestamp)
        {  // list_e is older, we work with it and get a new one
            eval_event(&list_e);
            while (1)
            {
                ret = ferret_list_get(list, (ferret_list_entry_t *)&list_e);
                if (ret == -1)
                {
                    //LOG("Waiting for element in list ...");
                    l4_sleep(10);
                    continue;
                }
                else if (ret < -1)
                {
                    printf("Something wrong with list: %d\n", ret);
                    exit(1);
                }
                break;
            }
        }
        else
        {  // list_et is older, we work with it and get a new one
            eval_event((ferret_list_entry_common_t *)&list_te);
            while (1)
            {
                ret = ferret_tbuf_get(tbuf, &tbuf_e);
                if (ret == -1)
                {
                    //LOG("Waiting for element in tbuf ...");
                    l4_sleep(10);
                    continue;
                }
                else if (ret < -1)
                {
                    printf("Something wrong with tbuf: %d\n", ret);
                    exit(1);
                }
                ferret_util_convert_k2c(&tbuf_e, &list_te);
                break;
            }
        }
    }

    return 0;
}
Пример #23
0
/* Our main function */
int main(void)
{
  /* Get a capability slot for our new thread. */
  l4_cap_idx_t t1 = l4re_util_cap_alloc();
  l4_utcb_t *u = l4_utcb();
  l4_exc_regs_t *e = l4_utcb_exc_u(u);
  l4_msgtag_t tag;
  int err;

  printf("Example showing how to start a thread with an exception.\n");
  /* We do not want to implement a pager here, take the shortcut. */
  printf("Make sure to start this program with ldr-flags=eager_map\n");

  if (l4_is_invalid_cap(t1))
    return 1;

  /* Create the thread using our default factory */
  tag = l4_factory_create_thread(l4re_env()->factory, t1);
  if (l4_error(tag))
    return 1;

  /* Setup the thread by setting the pager and task. */
  l4_thread_control_start();
  l4_thread_control_pager(l4re_env()->main_thread);
  l4_thread_control_exc_handler(l4re_env()->main_thread);
  l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb,
                          L4RE_THIS_TASK_CAP);
  tag = l4_thread_control_commit(t1);
  if (l4_error(tag))
    return 2;

  /* Start the thread by finally setting instruction and stack pointer */
  tag = l4_thread_ex_regs(t1,
                          (l4_umword_t)thread,
                          (l4_umword_t)thread_stack + sizeof(thread_stack),
                          L4_THREAD_EX_REGS_TRIGGER_EXCEPTION);
  if (l4_error(tag))
    return 3;

  l4_sched_param_t sp = l4_sched_param(1, 0);
  tag = l4_scheduler_run_thread(l4re_env()->scheduler, t1, &sp);
  if (l4_error(tag))
    return 4;


  /* Receive initial exception from just started thread */
  tag = l4_ipc_receive(t1, u, L4_IPC_NEVER);
  if ((err = l4_ipc_error(tag, u)))
    {
      printf("Umm, ipc error: %x\n", err);
      return 1;
    }
  /* We expect an exception IPC */
  if (!l4_msgtag_is_exception(tag))
    {
      printf("PF?: %lx %lx (not prepared to handle this) %ld\n",
	     l4_utcb_mr_u(u)->mr[0], l4_utcb_mr_u(u)->mr[1], l4_msgtag_label(tag));
      return 1;
    }

  /* Fill out the complete register set of the new thread */
  e->sp = (l4_umword_t)(thread_stack + sizeof(thread_stack));
#ifdef ARCH_x86
  e->ip = (l4_umword_t)thread;
  e->eax = 1;
  e->ebx = 4;
  e->ecx = 2;
  e->edx = 3;
  e->esi = 6;
  e->edi = 7;
  e->ebp = 5;
#endif
#ifdef ARCH_arm
  e->pc = (l4_umword_t)thread;
  e->r[0] = 0;
  e->r[1] = 1;
  e->r[2] = 2;
  e->r[3] = 3;
  e->r[4] = 4;
  e->r[5] = 5;
  e->r[6] = 6;
  e->r[7] = 7;
#endif
  /* Send a complete exception */
  tag = l4_msgtag(0, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0);

  /* Send reply and start the thread with the defined CPU register set */
  tag = l4_ipc_send(t1, u, tag, L4_IPC_NEVER);
  if ((err = l4_ipc_error(tag, u)))
    printf("Error sending IPC: %x\n", err);

  /* Idle around */
  while (1)
    l4_sleep(10000);

  return 0;
}
Пример #24
0
/******************************************************************************
 * main                                                                       *
 *                                                                            *
 * Main function                                                              *
 ******************************************************************************/
int main(int argc, char *argv[])
{
  int error = 0, i=1;
  l4_threadid_t dummy_l4id = L4_NIL_ID, loader_id;
//  l4events_event_t event;
//  l4events_nr_t eventnr;

  CORBA_Environment _env = dice_default_environment;

  /* init */
  do_args(argc, argv);
  my_l4id = l4thread_l4_id( l4thread_myself() );

  LOG("Hello, I'm running as "l4util_idfmt, l4util_idstr(my_l4id));

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 50000) == 0) 
    {
      LOG("PANIC: %s not registered at names", CON_NAMES_STR);
      enter_kdebug("panic");
    }

  if (names_waitfor_name("LOADER", &loader_id, 50000) == 0)
    {
      LOG("PANIC: LOADER not registered at names");
      enter_kdebug("panic");
    }
  
  if (con_if_openqry_call(&con_l4id, MY_SBUF_SIZE, 0, 0,
		     L4THREAD_DEFAULT_PRIO,
		     &vc_l4id, 
	  	     CON_VFB, &_env))
    enter_kdebug("Ouch, open vc failed");
  
  if (con_vc_smode_call(&vc_l4id, CON_OUT, &dummy_l4id, &_env))
    enter_kdebug("Ouch, setup vc failed");

  if (con_vc_graph_gmode_call(&vc_l4id, &gmode, &xres, &yres,
			 &bits_per_pixel, &bytes_per_pixel,
			 &bytes_per_line, &accel_flags, 
			 &fn_x, &fn_y, &_env))
    enter_kdebug("Ouch, graph_gmode failed");

  if (bytes_per_pixel != 2)
    {
      printf("Graphics mode not 2 bytes/pixel, exiting\n");
      con_vc_close_call(&vc_l4id, &_env);
      exit(0);
    }

  if (create_logo())
    enter_kdebug("Ouch, logo creation failed");

  while (!error && (i>0)) 
    {
      if ((error = clear_screen()))
	enter_kdebug("Ouch, clear_screen failed");
      if ((error = logo()))
	enter_kdebug("Ouch, logo failed");
      l4_sleep(500);
      i--;
    }

  if (con_vc_close_call(&vc_l4id, &_env))
    enter_kdebug("Ouch, close vc failed?!");
  
  LOG("Finally closed vc");

  LOG("Going to bed ...");

  names_register("CON_DEMO1");
/*
  my_id = l4_myself();
  event.len=sizeof(l4_umword_t);
  *(l4_umword_t*)event.str=my_id.id.task;
  
  l4events_send(1, &event, &eventnr, L4EVENTS_SEND_ACK);
  l4events_get_ack(eventnr, L4_IPC_NEVER);
*/  
  return 0;
}
Пример #25
0
int main(int argc, char* argv[])
{
    int i, j, ret;
    long long ts[2];

    // -=# monitoring code start #=-
    ferret_dplist_t * dpl1 = NULL;
    ferret_list_local_t * l1 = NULL;

    ferret_list_moni_t * ml1 = NULL;
    ferret_dplist_moni_t * mdpl1 = NULL;

    ferret_list_entry_t * el = malloc(64);

    l4_sleep(1000);
    // create sensor and configure it to an element size of 64 with
    // 1024 list entries
    ret = ferret_create(2, 3, 4, FERRET_DPLIST, 0, "64:1024", dpl1, &malloc);
    if (ret)
    {
        LOG("Error creating sensor: ret = %d", ret);
        exit(1);
    }
    //LOG("DPList created with the following properties:"
    //    " count = %d, element_size = %d", dpl1->count, dpl1->element_size);

    // create sensor and configure it to an element size of 64 with
    // 1024 list entries
    ret = ferret_create(3, 3, 4, FERRET_LIST, 0, "64:1024", l1, &malloc);
    if (ret)
    {
        LOG("Error creating sensor: ret = %d", ret);
        exit(1);
    }

    // self attach to sensors to read stuff from them again
    ret = ferret_att(2, 3, 4, mdpl1);
    if (ret)
    {
        LOG("Could not attach to sensor 2:3:4");
        exit(1);
    }
    ret = ferret_att(3, 3, 4, ml1);
    if (ret)
    {
        LOG("Could not attach to sensor 3:3:4");
        exit(1);
    }
    // -=# monitoring code end #=-

    printf("Beginning tests, stay tuned ...\n");
    printf("Doing %d writes:\n", LOOPS);
    ts[0] = l4_rdtsc();
    for (i = 0; i < LOOPS; i++)
    {
        ferret_dplist_post_1w(dpl1, 2, 3, 4, i);
    }
    ts[1] = l4_rdtsc();
    printf("DPList: cycles per event = %g\n", (ts[1] - ts[0]) / (double)LOOPS);

    ts[0] = l4_rdtsc();
    for (i = 0; i < LOOPS; i++)
    {
        ferret_list_post_1w(l1, 2, 3, 4, i);
    }
    ts[1] = l4_rdtsc();
    printf("List:   cycles per event = %g\n", (ts[1] - ts[0]) / (double)LOOPS);

    printf("Doing %d write--read pairs %d times:\n",
           LOOPS_INNER, LOOPS / LOOPS_INNER);
    ts[0] = l4_rdtsc();
    for (j = 0; j < LOOPS / LOOPS_INNER; j++)
    {
        //printf("b lost %lld events\n", mdpl1->lost);
        for (i = 0; i < LOOPS_INNER; i++)
        {
            ferret_dplist_post_1w(dpl1, 2, 3, 4, i);
        }
        for (i = 0; i < LOOPS_INNER; i++)
        {
            ret = ferret_dplist_get(mdpl1, el);
            if (ret != 0)
            {
                printf("Error code from ferret_dplist_get(): %d\n", ret);
                printf("head = %lld, next_read = %lld, i = %d\n",
                       mdpl1->glob->head.value, mdpl1->next_read.value, i);
                exit(1);
            }
        }
        //printf("a lost %lld events\n", mdpl1->lost);
    }
    ts[1] = l4_rdtsc();
    printf("DPList: lost %lld events\n", mdpl1->lost);
    printf("DPList: cycles per event (write + read) = %g\n",
           (ts[1] - ts[0]) / (double)LOOPS);

    ts[0] = l4_rdtsc();
    for (j = 0; j < LOOPS / LOOPS_INNER; j++)
    {
        for (i = 0; i < LOOPS_INNER; i++)
        {
            ferret_list_post_1w(l1, 2, 3, 4, i);
        }
        for (i = 0; i < LOOPS_INNER; i++)
        {
            ret = ferret_list_get(ml1, el);
            if (ret != 0)
            {
                printf("Error code from ferret_dplist_get(): %d\n", ret);
                exit(1);
            }
        }
    }
    ts[1] = l4_rdtsc();
    printf("List:   lost %lld events\n", ml1->lost);
    printf("List:   cycles per event (write + read) = %g\n",
           (ts[1] - ts[0]) / (double)LOOPS);


#if 0
    j = 0;
    while (1)
    {
        // -=# monitoring code start #=-
        ferret_dplist_post_2w(dpl1, 2, 3, 4, j, 0);
        // -=# monitoring code end #=-

        // do some work
        loops = 10000 + l4util_rand();
        for (i = 0; i < loops; i++)
            asm volatile ("": : : "memory");  // memory barrier

        // -=# monitoring code start #=-
        ferret_dplist_post_2w(dpl1, 2, 3, 4, j, 1);
        // -=# monitoring code end #=-

        l4_sleep(100);
        j++;
        if (j % 10 == 0)
        {
            LOG(".");
        }
    }
#endif

    // -=# monitoring code start #=-
    /* Demonstrates cleanup.
     *
     * The sensor will be freed after all parties released it, that
     * is, the creator and all monitors.
     */
    ret = ferret_free_sensor(2, 3, 4, dpl1, &free);
    if (ret)
    {
        LOG("Error freeing sensor: ret = %d", ret);
        exit(1);
    }
    // -=# monitoring code end #=-

    return 0;
}
Пример #26
0
void
l4os3_exec(char *cmd, char *params, l4_taskid_t *taskid)
{
  #define MAX_TASK_ID 16
  CORBA_Environment env = dice_default_environment;
  //char name[] = "os2app.cfg";
  char parm[1024] = "";
  char cmd_buf[0x20];
  l4_taskid_t task_ids[MAX_TASK_ID];
  char error_msg[1024];
  char *ptr = error_msg;
  l4os3_ds_t ds = L4DM_INVALID_DATASPACE;
  l4_addr_t addr;
  int error;

  // If we use events server, pass this option
  // to other servers/apps too
  if (use_events)
  {
    io_log("using events\n");
    strcat(parm, " --events ");
  }

  strcat(parm, params);
  
  io_log("cmd=%s\n", cmd);
  io_log("parm=\"%s\"\n", parm);

  /* RPC call to DM_PHYS (create a dataspace) */
  //if (if_l4dm_mem_open_call(&dsm_id, 1024, 0, 0,
  //                            name, &ds, &env))
  if (l4os3_ds_allocate(&ds, 0, 1024))
    {
      io_log("Can't allocate a dataspace!\n");
      while (1) { l4_sleep(0.1); }
    }
  io_log("dataspace created\n");
      
  /* attach the dataspace to our own address space */
  attach_ds(&ds, L4DM_RW, &addr);
  io_log("dataspace attached\n");
      
  /* create a loader script */
  strcpy((char *)addr, "modpath \"/file/system\"\n\ntask \"");
  strcat((char *)addr, cmd);
  strcat((char *)addr, "\"  \"--stdin /dev/vc0 --stdout /dev/vc0 --stderr /dev/vc0 ");
  strcat((char *)addr, parm);
  strcat((char *)addr, "\"");
  strcat((char *)addr, "\n\n  priority 0xA0");

  /* detach dataspace */
  l4rm_detach((void *)addr);

  /* transfer dataspace to loader */
  l4dm_transfer(&ds,              // dataspace
                loader_id);       // taskid
  
  /* RPC to L4 loader to start OS/2 app L4 startup */
  if ((error = l4loader_app_open_call(&loader_id, &ds, cmd_buf,
                                        &fprov_id, 0, task_ids,
                                        &ptr, &env)))
    {
      if (error == -L4_ENOTFOUND)
        io_log("file %s not found!\n", cmd_buf);

      io_log("  Error %d (%s) loading application\n",
          error, l4os3_errtostr(error));

      if (*error_msg)
        io_log("  (Loader says:'%s')\n", error_msg);
 
      while (1) l4_sleep(0.1);
    }
  *taskid = task_ids[0];
}
Пример #27
0
int main(void)
{
	l4_cap_idx_t srv = lookup_sensordir();
    int i, j, loops;


    // -=# monitoring code start #=-
    ferret_list_local_t * l1 = NULL, * l2 = NULL, * l3 = NULL, * l4 = NULL;
    int ret;
    int index;
    ferret_utime_t t;

    ferret_list_entry_common_t * elc;
    ferret_list_entry_t * el;

    l4_sleep(1000);
    // create sensor and configure it to an element size of 8 bytes with
    // 100 list entries
    ret = ferret_create(srv, 12, 1, 0, FERRET_LIST,
                        0, "8:100", l1, &malloc);
    if (ret)
    {
        printf("Error creating sensor: ret = %d\n", ret);
        exit(1);
    }

    // create sensor and configure it to an element size of 64 bytes with
    // 1000 list entries
    ret = ferret_create(srv, 12, 2, 0, FERRET_LIST,
                        FERRET_SUPERPAGES, "64:1000", l2, &malloc);
    if (ret)
    {
        printf("Error creating sensor: ret = %d\n", ret);
        exit(1);
    }


    // testing reopen here
    ret = ferret_create(srv, 12, 2, 0, FERRET_LIST,
                        FERRET_SUPERPAGES, "64:1000", l3, &malloc);
    if (ret)
    {
        printf("Error creating sensor: ret = %d\n", ret);
        exit(1);
    }
    else
    {
        printf("Reopen worked.\n");
    }

    ret = ferret_create(srv, 12, 2, 0, FERRET_LIST,
                        FERRET_SUPERPAGES, "64:999", l4, &malloc);
    if (ret)
    {
        printf("Error creating sensor: ret = %d (as expected)\n", ret);
    }
    else
    {
        printf("Reopen worked (should not).\n");
        exit(1);
    }

    // -=# monitoring code end #=-

    j = 0;
    while (1)
    {
        // -=# monitoring code start #=-
        // this sensor has empty events, just timestamps are inserted
        // on commiting, so we don't have to insert other data
        //printf("X1: %p, %p, %p, %p\n", l1, l1->glob, l1->ind_buf, l1->out_buf);
        index = ferret_list_dequeue(l1);
        ferret_list_commit(l1, index);
        index = ferret_list_dequeue(l1);
        ferret_list_commit(l1, index);
        index = ferret_list_dequeue(l1);
        ferret_list_commit(l1, index);
        index = ferret_list_dequeue(l1);
        ferret_list_commit(l1, index);
        // -=# monitoring code end #=-

        // -=# monitoring code start #=-
        // this demonstrates to cast the received pointer to a certain
        // struct and fill it
        index = ferret_list_dequeue(l2);
        elc = (ferret_list_entry_common_t *)ferret_list_e4i(l2->glob, index);
        FERRET_GET_TIME(FERRET_TIME_REL_US, elc->data64[0]);
        elc->major     = 12;
        elc->minor     = 2;
        elc->instance  = 0;
        elc->cpu       = 0;
        elc->data32[2] = 1;  // start
        elc->data32[3] = j;
        ferret_list_commit(l2, index);
        // -=# monitoring code end #=-

        // do some work
        loops = 10000 + l4util_rand();
        for (i = 0; i < loops; i++)
            asm volatile ("": : : "memory");

        // -=# monitoring code start #=-
        // here, dynamic marshaling is demonstrated
        index = ferret_list_dequeue(l2);
        el = ferret_list_e4i(l2->glob, index);
        FERRET_GET_TIME(FERRET_TIME_REL_US, t);
        //printf("%lld, %p, %p\n", t, el, l2->glob);
        ret = ferret_util_pack("hhhbxqll", el->data, 12, 2, 0, 0, t, 2, j);
        ferret_list_commit(l2, index);
        // -=# monitoring code end #=-

        // -=# monitoring code start #=-
        // demonstrate use of convenience wrappers here
        ferret_list_post_c  (1, l3, 12, 2, 0);
        ferret_list_post_1wc(1, l3, 12, 2, 0, 1);
        ferret_list_post_2wc(1, l3, 12, 2, 0, 1, 2);
        ferret_list_post_3wc(1, l3, 12, 2, 0, 1, 2, 3);
        ferret_list_post_4wc(1, l3, 12, 2, 0, 1, 2, 3, 4);
        // -=# monitoring code end #=-

        l4_sleep(100);
        j++;
    }

    // -=# monitoring code start #=-
    /* will never be reached due to the infinite loop above, but
     * demonstrates cleanup.
     *
     * The sensor will be freed after all parties released it, that
     * is, the creator and all monitors.
     */
    ret = ferret_free_sensor(10, 1, 0, l1, &free);
    if (ret)
    {
        printf("Error freeing sensor: ret = %d\n", ret);
        exit(1);
    }

    ret = ferret_free_sensor(10, 2, 0, l2, &free);
    if (ret)
    {
        printf("Error freeing sensor: ret = %d\n", ret);
        exit(1);
    }
    // -=# monitoring code end #=-
    return 0;
}
Пример #28
0
/* Our main function */
int main(void)
{
  /* Get a capability slot for our new thread. */
  l4_cap_idx_t t1 = l4re_util_cap_alloc();
  l4_utcb_t *u = l4_utcb();
  l4_exc_regs_t *e = l4_utcb_exc_u(u);
  l4_msgtag_t tag;
  int err;
  extern char _start[], _end[], _etext[];

  if (l4_is_invalid_cap(t1))
    return 1;

  /* Prevent pagefaults of our new thread because we do not want to
   * implement a pager as well. */
  l4_touch_ro(_start, _end - _start + 1);
  l4_touch_rw(_etext, _end - _etext);

  /* Create the thread using our default factory */
  tag = l4_factory_create_thread(l4re_env()->factory, t1);
  if (l4_msgtag_has_error(tag))
    return 1;

  /* Setup the thread by setting the pager and task. */
  l4_thread_control_start();
  l4_thread_control_pager(l4re_env()->main_thread);
  l4_thread_control_exc_handler(l4re_env()->main_thread);
  l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb,
                          L4RE_THIS_TASK_CAP);
  tag = l4_thread_control_commit(t1);
  if (l4_msgtag_has_error(tag))
    return 2;

  /* Start the thread by finally setting instruction and stack pointer */
  tag = l4_thread_ex_regs(t1,
                          (l4_umword_t)thread,
                          (l4_umword_t)thread_stack + sizeof(thread_stack),
                          L4_THREAD_EX_REGS_TRIGGER_EXCEPTION);
  if (l4_msgtag_has_error(tag))
    return 3;

  /* Receive initial exception from just started thread */
  tag = l4_ipc_receive(t1, u, L4_IPC_NEVER);
  if ((err = l4_ipc_error(tag, u)))
    {
      printf("Umm, ipc error: %x\n", err);
      return 1;
    }
  /* We expect an exception IPC */
  if (!l4_msgtag_is_exception(tag))
    {
      printf("PF?: %lx %lx (not prepared to handle this) %ld\n",
	     l4_utcb_mr_u(u)->mr[0], l4_utcb_mr_u(u)->mr[1], l4_msgtag_label(tag));
      return 1;
    }

  /* Fill out the complete register set of the new thread */
  e->ip = (l4_umword_t)thread;
  e->sp = (l4_umword_t)(thread_stack + sizeof(thread_stack));
  e->eax = 1;
  e->ebx = 4;
  e->ecx = 2;
  e->edx = 3;
  e->esi = 6;
  e->edi = 7;
  e->ebp = 5;
  /* Send a complete exception */
  tag = l4_msgtag(0, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0);

  /* Send reply and start the thread with the defined CPU register set */
  tag = l4_ipc_send(t1, u, tag, L4_IPC_NEVER);
  if ((err = l4_ipc_error(tag, u)))
    printf("Error sending IPC: %x\n", err);

  /* Idle around */
  while (1)
    l4_sleep(10000);

  return 0;
}
Пример #29
0
/******************************************************************************
 * main                                                                       *
 *                                                                            *
 * Main function                                                              *
 ******************************************************************************/
int main(int argc, char *argv[])
{
  int error = 0;
  l4_threadid_t dummy_l4id = L4_NIL_ID;

  CORBA_Environment _env = dice_default_environment;

  /* init */
  do_args(argc, argv);
  my_l4id = l4thread_l4_id( l4thread_myself() );

  LOG("Hello, I'm running as "l4util_idfmt, l4util_idstr(my_l4id));

  /* ask for 'con' (timeout = 5000 ms) */
  if (names_waitfor_name(CON_NAMES_STR, &con_l4id, 50000) == 0) 
    {
      LOG("PANIC: %s not registered at names", CON_NAMES_STR);
      enter_kdebug("panic");
    }

  if (con_if_openqry_call(&con_l4id, MY_SBUF_SIZE, 0, 0,
		     L4THREAD_DEFAULT_PRIO,
		     &vc_l4id, 
	  	     CON_VFB, &_env))
    enter_kdebug("Ouch, open vc failed");
  
  if (con_vc_smode_call(&vc_l4id, CON_OUT, &dummy_l4id, &_env))
    enter_kdebug("Ouch, setup vc failed");

  if (con_vc_graph_gmode_call(&vc_l4id, &gmode, &xres, &yres,
			 &bits_per_pixel, &bytes_per_pixel,
			 &bytes_per_line, &accel_flags, 
			 &fn_x, &fn_y, &_env))
    enter_kdebug("Ouch, graph_gmode failed");

  if (bytes_per_pixel != 2)
    {
      printf("Graphics mode not 2 bytes/pixel, exiting\n");
      con_vc_close_call(&vc_l4id, &_env);
      exit(0);
    }

  if (create_logo())
    enter_kdebug("Ouch, logo creation failed");

  while (!error) 
    {
      if ((error = clear_screen()))
	enter_kdebug("Ouch, clear_screen failed");
      if ((error = logo()))
	enter_kdebug("Ouch, logo failed");
      l4_sleep(2000);
    }

  if (con_vc_close_call(&vc_l4id, &_env))
    enter_kdebug("Ouch, close vc failed?!");
  
  LOG("Finally closed vc");

  LOG("Going to bed ...");
  l4_sleep(-1);

  return 0;
}