void cmd_line_test(void)
{
    // Initialise modules
    uart0_init(115200,8,UART0_NO_PARITY,1);
    printf_init();

    // Enable global interrupts
    sei();    

    // Initialise command line parser and VT100 terminal helper
	vt100_init(&main_put_char);
    cmd_line_init(&main_put_char);

    cmd_line_add      (&cmd_line_led,                  "led",&cmd_line_handler_led,    "display status of led");
    cmd_line_add_child(&cmd_line_led,&cmd_line_led_on, "on", &cmd_line_handler_led_on, "switch led on"        );
    cmd_line_add_child(&cmd_line_led,&cmd_line_led_off,"off",&cmd_line_handler_led_off,"switch led off"       );

    PRINTF("\nCommand Line test\n\n");

    for(;;)
    {
        // Pass all received data to command line parser
        if(uart0_get_rx_byte(&data))
        {
            cmd_line_process(data);
        }        
    }
}
Esempio n. 2
0
void hdlc_test(void)
{
    u8_t data;

    // Enable RS-485 PIO for loopback operation
    BIT_SET_HI(PORT_RS485_TX_EN_O, BIT_RS485_TX_EN_O);
    BIT_SET_HI(DDR_RS485_TX_EN_O, BIT_RS485_TX_EN_O);

    BIT_SET_LO(PORT_RS485_RX_EN_O, BIT_RS485_RX_EN_O);
    BIT_SET_HI(DDR_RS485_RX_EN_O, BIT_RS485_RX_EN_O);

    // Initialise modules
    uart0_init();
    uart1_init();
    printf_init();
    hdlc_init(&hdlc_on_rx_frame);

    // Enable global interrupts
    sei();
        
    // Send an HDLC packet
    data = 0x55;
    hdlc_tx_frame(&data,1);

    // Process received data
    for(;;)
    {
        if(uart1_get_rx_byte(&data))
        {
            PRINTF("%02X ", data);
            // Feed received data to HDLC layer
            hdlc_on_rx_byte(data);
        }
    }
}
Esempio n. 3
0
int
main(int argc, char **argv)
{
	kern_return_t	rc;
	mach_port_t	security_port;
	mach_port_t	root_ledger_wired;
	mach_port_t	root_ledger_paged;

	if(argc > 1)
	{
		if(argv[1][0] == '-')
			if(argv[1][1] == 't')
			{
				tgdb_debug_flags = -1;
				debug_flag = 1;
			}
	}

	if (bootstrap_ports(bootstrap_port, &tgdb_host_priv,
			    &device_server_port, &root_ledger_wired,
			    &root_ledger_paged, &security_port))
		panic("bootstrap_ports");

	threads_init();
	printf_init(device_server_port);
	panic_init(tgdb_host_priv);

	tgdb_session_init();

	if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET,
			       &tgdb_wait_port_set) != KERN_SUCCESS) {
		printf("tgdb: can't allocate port set\n");
		return 1;
	}

	exc_thread = tgdb_thread_create((vm_offset_t) tgdb_thread);
	if(exc_thread == 0)
		printf("tgdb_thread_create failed\n");

	if((rc = thread_resume(exc_thread)) != KERN_SUCCESS) {
		printf("tgdb: thread_resume failed %x\n", rc);
	}

	/*
	 * Change our scheduling policy to round-robin, and boost our priority.
	 */
	tgdb_set_policy(tgdb_host_priv);

	tgdb_connect();

	return 1;	/* Only reached on error. */
}
Esempio n. 4
0
int			bootloader_cons_init(void)
{
  cons.line = 0;
  cons.column = 0;
  cons.attr = IBMPC_CONS_FRONT(IBMPC_CONS_WHITE) |
    IBMPC_CONS_BACK(IBMPC_CONS_BLACK) | IBMPC_CONS_INT;
  cons.vga = (char*)IBMPC_CONS_ADDR;

  bootloader_cons_clear();

  printf_init(bootloader_cons_print_char, bootloader_cons_attr);

  return (0);
}
Esempio n. 5
0
void main(void) {
    keyboard_init();
    printf_init();
    timer_init();
    system_enable_interrupts();

    while (1) {
        int key = keyboard_read_scancode(); 
        printf("%02x ", key );
	if (key != 0xf0 && key != 0xe0) {
            printf("\n");
	}
    }
}
Esempio n. 6
0
void DBG_vTest(void)
{
    u8_t counter;
 
    // Initialise modules
    uart0_init();
    printf_init();

    // Enable global interrupts
    sei();
  
    for(counter = 0; counter<16; counter++)
    {
        DBG_ASSERT(counter <= 7); // Counter may not exceed the value 7
        DBG_TRACE(DBG_PROG, "Counter = %d\n", counter);
    }
}
void at45db041b_test(void)
{
    u8_t  status;
    u16_t counter;

    // Initialise PIO
    BIT_SET_HI(PORT_SFLASH_CS_O, BIT_SFLASH_CS_O);
    BIT_SET_HI(DDR_SFLASH_CS_O,  BIT_SFLASH_CS_O);
 
    // Initialise modules
    spi_init();
    uart0_init();
    printf_init();
    at45db041b_init();

    // Enable global interrupts
    sei();
  
    // See if Serial FLASH is present
    status = at45db041b_get_status();
    if((status & AT45DB041B_DENSITY_MASK) != AT45DB041B_DENSITY)
    {
        PRINTF("Error! AT45DB041B not present. Status = 0x%02X\n", status);
        return;
    }

    // Write a page of Serial FLASH
    for(counter = 0; counter<AT45DB041B_PAGE_SIZE; counter++)
    {
        page[counter] = (u8_t)(counter&0xff);
    }
    at45db041b_write_page(AT45DB041B_PAGES-1, page);

    // Read a page of Serial FLASH
    at45db041b_read_page(AT45DB041B_PAGES-1, page);

    // Report content of page
    for(counter = 0; counter<AT45DB041B_PAGE_SIZE; counter++)
    {
        PRINTF("%02X ", page[counter]);
        if((counter&0x0F) == 0x0F)
        {
            PRINTF("\n");
        }
    }
}
Esempio n. 8
0
/** @brief preStart() is the function for the startup thread, which is the
 * one spawned by main().
 *
 * It does all the initialization that needs to happen after the
 * kernel is up and running, and then it calls the application start function.
 */
void pre_start(void)
{
    //TODO: this should somehow be auto-generated
#ifdef PLATFORM_LINUX
    mos_node_id_init();	// must be called before gevent_init ()
    gevent_init();

    serial_init();
    terminal_init();
    //udp_init();
    xmos_radio_init();	// gevent_init() must be called first
    xmos_flash_init();	// gevent_init() must be called first
    mos_thread_suspend(); //fixes threading issue with freebsd

#elif defined(ARCH_MICRO)
    uart_init();
    printf_init();
    plat_init();
    clock_init();
#if defined(PLATFORM_TELOSB)
    // clock_init() clobbers TimerA
    // re-initialize TimerA here as a kludge.
    kernel_timer_init();
#endif
    mos_node_id_init();

    //dev_loopback_init();
    //com_loopback_init();


    // seed the rng
    //srandom(mos_node_id_get());
#endif //if defined(ARCH_AVR)

#ifdef MOS_DEBUG
    mos_debug_post_init();
#endif

    start();
}
Esempio n. 9
0
void adc_test(void)
{
    u16_t adc_val;
 
    // Initialise modules
    adc_init();
    uart0_init();
    printf_init();

    // Enable global interrupts
    sei();
  
    // Select ADC0
    adc_sel_channel(0);
   
    // Sample channel
    adc_val = adc_get_sample();

    PRINTF("\nADC Value = %d -> Voltage = %2.2f V\n", 
           adc_val,
           ((float)adc_val)*(3.3/1024.0));
}
Esempio n. 10
0
void dbg_test(void)
{
    u8_t counter;
 
    // Initialise modules
    uart0_init(115200,8,UART0_NO_PARITY,1);
    printf_init();

    // Enable global interrupts
    sei();    

    DBG_TRACE("\nDBG Test\n\n");

    DBG_ERR("This is an error msg\n");
    DBG_WARN("This is a warning msg\n");
    DBG_PROG("This is a progress msg\n");

    for(counter = 0; counter<16; counter++)
    {
        DBG_ASSERT(counter <= 7); // Counter may not exceed the value 7
        DBG_LOG(DBG_LEVEL_PROG, "Counter = %d\n", counter);
    }
}
Esempio n. 11
0
/*
 *	Running in virtual memory, on the interrupt stack.
 *	Does not return.  Dispatches initial thread.
 *
 *	Assumes that master_cpu is set.
 */
void setup_main()
{
	thread_t		startup_thread;

	panic_init();
	printf_init();

	sched_init();
	vm_mem_bootstrap();
	ipc_bootstrap();
	vm_mem_init();
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	PMAP_ACTIVATE_KERNEL(master_cpu);

	init_timers();
	init_timeout();

#if	XPR_DEBUG
	xprbootstrap();
#endif	XPR_DEBUG

	timestamp_init();

	mapable_time_init();

	machine_init();

	machine_info.max_cpus = NCPUS;
	machine_info.memory_size = phys_last_addr - phys_first_addr; /* XXX mem_size */
	machine_info.avail_cpus = 0;
	machine_info.major_version = KERNEL_MAJOR_VERSION;
	machine_info.minor_version = KERNEL_MINOR_VERSION;

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
	task_init();
	thread_init();
	swapper_init();
#if	MACH_HOST
	pset_sys_init();
#endif	MACH_HOST

	/*
	 *	Kick off the time-out driven routines by calling
	 *	them the first time.
	 */
	recompute_priorities();
	compute_mach_factor();
	
	/*
	 *	Create a kernel thread to start the other kernel
	 *	threads.  Thread_resume (from kernel_thread) calls
	 *	thread_setrun, which may look at current thread;
	 *	we must avoid this, since there is no current thread.
	 */

	/*
	 * Create the thread, and point it at the routine.
	 */
	(void) thread_create(kernel_task, &startup_thread);
	thread_start(startup_thread, start_kernel_threads);

	/*
	 * Give it a kernel stack.
	 */
	thread_doswapin(startup_thread);

	/*
	 * Pretend it is already running, and resume it.
	 * Since it looks as if it is running, thread_resume
	 * will not try to put it on the run queues.
	 *
	 * We can do all of this without locking, because nothing
	 * else is running yet.
	 */
	startup_thread->state |= TH_RUN;
	(void) thread_resume(startup_thread);

	/*
	 * Start the thread.
	 */
	cpu_launch_first_thread(startup_thread);
	/*NOTREACHED*/
}
Esempio n. 12
0
void print_MipsCodes(char* output){
	fp = fopen(output,"w");
	if ( !fp )
	{
		perror(output);
		return ;
	}
        printf_init();
	MipsCodes p = Mips_head->next;assert(p->code!=NULL);
	while(p!=NULL){
		switch(p->code->kind){
			case MIP_LAB:
				print_MIP_LAB(p);
				break;
			case MIP_LI:
				print_MIP_LI(p);
				break;
			case MIP_LA:
				print_MIP_LA(p);
				break;
			case MIP_MOVE:
				print_MIP_MOVE(p);
				break;
			case MIP_ADDI:
				print_MIP_ADDI(p);
				break;
			case MIP_ADD:
				print_MIP_ADD(p);
				break;
			case MIP_SUB:
				print_MIP_SUB(p);
				break;
			case MIP_MUL:
				print_MIP_MUL(p);
				break;
			case MIP_DIV:
				print_MIP_DIV(p);
				break;
			case MIP_MFLO:
				print_MIP_MFLO(p); 
                break; 
            case MIP_LW:
				print_MIP_LW(p);
				break;
			case MIP_SW:
				print_MIP_SW(p);
				break;
			case MIP_J:
				print_MIP_J(p);
				break;
			case MIP_JAL:
				print_MIP_JAL(p);
				break;
			case MIP_JR:
				print_MIP_JR(p);
				break; 
			case MIP_BEQ: 
				print_MIP_BEQ(p);
				break;
			case MIP_BNE:
				print_MIP_BNE(p);
				break;
			case MIP_BGT:
				print_MIP_BGT(p);
				break;
			case MIP_BLT:
				print_MIP_BLT(p);
				break;
			case MIP_BGE:
				print_MIP_BGE(p);
				break;
			case MIP_BLE:
				print_MIP_BLE(p);
				break;
			case MIP_FUNC:
				print_MIP_FUNC(p);
				break;
			case MIP_READ:
				print_MIP_READ(p);
				break;
			case MIP_WRITE:
				print_MIP_WRITE(p);
				break;
			default:
				break;

		}
		//if(p->code->kind!=COND)
		fputs("\n",fp);
		p=p->next;
	}
	fclose(fp);
}
Esempio n. 13
0
/*
 *	Running in virtual memory, on the interrupt stack.
 *	Does not return.  Dispatches initial thread.
 *
 *	Assumes that master_cpu is set.
 */
void
setup_main(void)
{
	thread_t		startup_thread;

	printf_init();
	panic_init();

	sched_init();
	vm_mem_bootstrap();
	ipc_bootstrap();
	vm_mem_init();
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	PMAP_ACTIVATE_KERNEL(master_cpu);

	init_timers();
	timeout_init();

#if	CDLI > 0
	ns_init();	/* Initialize CDLI */
#endif	/* CDLI > 0 */

	dev_lookup_init();
	timeout_init();
	machine_init();

	machine_info.max_cpus = NCPUS;
	machine_info.memory_size = mem_size;
	machine_info.avail_cpus = 0;
	machine_info.major_version = KERNEL_MAJOR_VERSION;
	machine_info.minor_version = KERNEL_MINOR_VERSION;

#if	XPR_DEBUG
	xprbootstrap();
#endif	/* XPR_DEBUG */

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
	clock_init();
	utime_init();
        ledger_init();
#if	THREAD_SWAPPER
	thread_swapper_init();
#endif	/* THREAD_SWAPPER */
#if	TASK_SWAPPER
	task_swapper_init();
#endif	/* TASK_SWAPPER */
	task_init();
	act_init();
	thread_init();
	subsystem_init();
#if	TASK_SWAPPER
	task_swappable(&realhost, kernel_task, FALSE);
#endif	/* TASK_SWAPPER */
#if	MACH_HOST
	pset_sys_init();
#endif	/* MACH_HOST */

	/*
	 *	Kick off the time-out driven routines by calling
	 *	them the first time.
	 */
	recompute_priorities();
	compute_mach_factor();

	/*
	 *	Initialize the Event Trace Analysis Package.
	 * 	Dynamic Phase: 2 of 2
	 */
	etap_init_phase2();
	
	/*
	 *	Create a kernel thread to start the other kernel
	 *	threads.  Thread_resume (from kernel_thread) calls
	 *	thread_setrun, which may look at current thread;
	 *	we must avoid this, since there is no current thread.
	 */

	/*
	 * Create the thread, and point it at the routine.
	 */
	(void) thread_create_at(kernel_task, &startup_thread,
							start_kernel_threads);
#if	NCPUS > 1 && PARAGON860
	thread_bind(startup_thread, cpu_to_processor(master_cpu));
#endif
	/*
	 * Pretend it is already running, and resume it.
	 * Since it looks as if it is running, thread_resume
	 * will not try to put it on the run queues.
	 *
	 * We can do all of this without locking, because nothing
	 * else is running yet.
	 */
	startup_thread->state |= TH_RUN;
	(void) thread_resume(startup_thread->top_act);

	/*
	 * Start the thread.
	 */
	cpu_launch_first_thread(startup_thread);
	/*NOTREACHED*/
	panic("cpu_launch_first_thread returns!");
}
Esempio n. 14
0
int
main(
	int argc,
	char **argv)
{
	int			my_node;
	mach_port_t		master_device_port;
	mach_port_t		security_port;
	mach_port_t		root_ledger_wired;
	mach_port_t		root_ledger_paged;
	static char		here[] = "main";
	int			need_dp_init = 1;

	/*
	 * Use 4Kbyte cthread wait stacks.
	 */
	cthread_wait_stack_size = 4 * 1024;

	if (bootstrap_ports(bootstrap_port, &default_pager_host_port,
			    &master_device_port, &root_ledger_wired,
			    &root_ledger_paged, &security_port))
		Panic("privileged ports");

	printf_init(master_device_port);
	panic_init(default_pager_host_port);


	norma_mk = (norma_node_self(default_pager_host_port,
				    &my_node) == KERN_SUCCESS);
	printf("(default_pager): started%s\n",
	       norma_mk ? " on a NORMA kernel" : "");

	/*
	 * Process arguments:
	 *	list of attributes, list of device names.
	 * Must do device names after ports are initialised.
	 */
	while (--argc > 0) {
	    argv++;
	    if (!dp_parse_argument(*argv)) {
		if (need_dp_init) {
			/*
			 * Set up ports, port sets and thread counts.
			 */
			default_pager_initialize(default_pager_host_port);
			need_dp_init = 0;
		}
		if (!bs_add_device(*argv, master_device_port))
			printf("(default_pager): couldn't add device %s\n",
			       *argv);
		else
			printf("(default_pager): added device %s\n",
			       *argv);
	    }
	}
	if (need_dp_init) {
		default_pager_initialize(default_pager_host_port);
		need_dp_init = 0;
	}

	/*
	 * Change our scheduling policy to round-robin, and boost our priority.
	 */
	default_pager_set_policy(default_pager_host_port);

	/* Start threads and message processing.
	 */
	for (;;) {
		default_pager();
		/*NOTREACHED*/
	}
}
Esempio n. 15
0
int
main (int argc, char **argv)
{
  const task_t my_task = mach_task_self();
  error_t err;
  memory_object_t defpager;

  err = get_privileged_ports (&bootstrap_master_host_port,
			      &bootstrap_master_device_port);
  if (err)
    error (1, err, "cannot get privileged ports");

  defpager = MACH_PORT_NULL;
  err = vm_set_default_memory_manager (bootstrap_master_host_port, &defpager);
  if (err)
    error (1, err, "cannot check current default memory manager");
  if (MACH_PORT_VALID (defpager))
    error (2, 0, "Another default memory manager is already running");

  if (!(argc == 2 && !strcmp (argv[1], "-d")))
    {
      /* We don't use the `daemon' function because we might exit back to the
	 parent before the daemon has completed vm_set_default_memory_manager.
	 Instead, the parent waits for a SIGUSR1 from the child before
	 exitting, and the child sends that signal after it is set up.  */
      sigset_t set;
      signal (SIGUSR1, nohandler);
      sigemptyset (&set);
      sigaddset (&set, SIGUSR1);
      sigprocmask (SIG_BLOCK, &set, 0);
      switch (fork ())
	{
	case -1:
	  error (1, errno, "cannot become daemon");
	case 0:
	  setsid ();
	  chdir ("/");
	  close (0);
	  close (1);
	  close (2);
	  break;
	default:
	  sigemptyset (&set);
	  sigsuspend (&set);
	  _exit (0);
	}
    }

  /* Mark us as important.  */
  mach_port_t proc = getproc ();
  if (proc == MACH_PORT_NULL)
    error (3, err, "cannot get a handle to our process");

  err = proc_mark_important (proc);
  /* This might fail due to permissions or because the old proc server
     is still running, ignore any such errors.  */
  if (err && err != EPERM && err != EMIG_BAD_ID)
    error (3, err, "cannot mark us as important");

  mach_port_deallocate (mach_task_self (), proc);

  printf_init(bootstrap_master_device_port);

  /*
   * Set up the default pager.
   */
  partition_init();

  /*
   * task_set_exception_port and task_set_bootstrap_port
   * both require a send right.
   */
  (void) mach_port_insert_right(my_task, default_pager_exception_port,
				default_pager_exception_port,
				MACH_MSG_TYPE_MAKE_SEND);

  /*
   * Change our exception port.
   */
  if (!debug)
  (void) task_set_exception_port(my_task, default_pager_exception_port);

  default_pager_initialize (bootstrap_master_host_port);

  if (!(argc == 2 && !strcmp (argv[1], "-d")))
    kill (getppid (), SIGUSR1);

  /*
   * Become the default pager
   */
  default_pager();
  /*NOTREACHED*/
  return -1;
}
Esempio n. 16
0
void _doprnt(
	const char 	*fmt,
	va_list		argp,
					/* character output routine */
 	void		(*putc)( char, vm_offset_t),
	int		radix,		/* default radix - for '%r' */
	vm_offset_t	putc_arg)
{
	int		length;
	int		prec;
	boolean_t	ladjust;
	char		padc;
	long		n;
	unsigned long	u;
	int		plus_sign;
	int		sign_char;
	boolean_t	altfmt, truncate;
	int		base;
	char		c;

	printf_init();

#if 0
	/* Make sure that we get *some* printout, no matter what */
	simple_lock(&_doprnt_lock);
#else
	{
		int i = 0;
		while (i < 1*1024*1024) {
			if (simple_lock_try(&_doprnt_lock))
				break;
			i++;
		}
	}
#endif

	while ((c = *fmt) != '\0') {
	    if (c != '%') {
		(*putc)(c, putc_arg);
		fmt++;
		continue;
	    }

	    fmt++;

	    length = 0;
	    prec = -1;
	    ladjust = FALSE;
	    padc = ' ';
	    plus_sign = 0;
	    sign_char = 0;
	    altfmt = FALSE;

	    while (TRUE) {
		c = *fmt;
		if (c == '#') {
		    altfmt = TRUE;
		}
		else if (c == '-') {
		    ladjust = TRUE;
		}
		else if (c == '+') {
		    plus_sign = '+';
		}
		else if (c == ' ') {
		    if (plus_sign == 0)
			plus_sign = ' ';
		}
		else
		    break;
		fmt++;
	    }

	    if (c == '0') {
		padc = '0';
		c = *++fmt;
	    }

	    if (isdigit(c)) {
		while(isdigit(c)) {
		    length = 10 * length + Ctod(c);
		    c = *++fmt;
		}
	    }
	    else if (c == '*') {
		length = va_arg(argp, int);
		c = *++fmt;
		if (length < 0) {
		    ladjust = !ladjust;
		    length = -length;
		}
	    }

	    if (c == '.') {
		c = *++fmt;
		if (isdigit(c)) {
		    prec = 0;
		    while(isdigit(c)) {
			prec = 10 * prec + Ctod(c);
			c = *++fmt;
		    }
		}
		else if (c == '*') {
		    prec = va_arg(argp, int);
		    c = *++fmt;
		}
Esempio n. 17
0
/* =========================== */
int main(int argc,char *argv[])
{
   unsigned short       port;
   int                  result;
   int                  err;
   SOCKET               masterSock;
   SOCKET               clientSock;
   em_workspace_t       *wrk;
   struct sockaddr_in   servAddr;
   int                  i;
   WORD                 wVersionRequested;
   WSADATA              wsaData;
   int                  clientAddrLen;
   struct sockaddr      clientAddr;

   fprintf(stdout,"Embedded Web Server - Windows 95 : %s\n",__TIMESTAMP__);
   fprintf(stdout,"Copyright (c) 1995-1996 David M. Howard\n");

   port = w95t_server_port;

   /* initialize printf */
   printf_init();

   /* =============================================== */
   /* initialize winsock library                      */
   /* =============================================== */

   wVersionRequested = MAKEWORD(1, 1);

   err = WSAStartup(wVersionRequested, &wsaData);
   if (err != 0) {
      fprintf(stderr,"Can't initialize winsock lib\n");
      exit(1);
   }

   /* Confirm that the Windows Sockets DLL supports 1.1.*/
   /* Note that if the DLL supports versions greater */
   /* than 1.1 in addition to 1.1, it will still return */
   /* 1.1 in wVersion since that is the version we */
   /* requested. */

   if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1) {
      /* Tell the user that we couldn't find a useable */
      /* winsock.dll. */
      WSACleanup();
      fprintf(stderr,"Winsock doesn't support version 1.1\n");
      exit(1);
   }

   ews_printf("Winsock Initialized OK\n");

   /* =============================================== */
   /* The Windows Sockets DLL is acceptable. Proceed. */
   /* =============================================== */

   /* Create a socket and bind address, listen for incoming connections */
   masterSock = socket( PF_INET, SOCK_STREAM, 0 );
   if ( masterSock == INVALID_SOCKET ) {
      ews_printf("socket(..) failed\n");
      exit(1);
   }

   /*lint -e740 unusual pointer cast */
   memset((char *) &servAddr, 0, sizeof servAddr );
   servAddr.sin_family      = AF_INET;
   servAddr.sin_addr.s_addr = htonl( INADDR_ANY );
   servAddr.sin_port        = htons( port );
   result = bind( masterSock, ( struct sockaddr * ) &servAddr, sizeof servAddr );
   if ( result == -1 ) {
      ews_printf("bind(..) failed\n");
      exit(1);
   }

   /*lint _e740 */

   result = listen( masterSock, 3 );
   if ( result == -1 ) {
      ews_printf("listen(..) failed\n");
      exit(1);
   }

   ews_printf("masterSock listening on port %hu\n",port);

   /* ================================== */
   /* create the client connection queue */
   /* ================================== */
   thread_sockq = socket_qinit(NUMBER_OF_SERVER_TASKS);

   /* for each vrtx connection thread */
   for(i=0;i<NUMBER_OF_SERVER_TASKS;i++) {
      /* initialize a workspace  */
      wrk = &w95t_workspace[i];

      /* clear it to all 0's to start */
      memset(wrk,0,sizeof(em_workspace_t));

      /* SOCKET IO FUNCTIONS */
      wrk->system.p           = &w95t_dresp[i];
      wrk->system.read        = w95t_Read;
      wrk->system.write       = w95t_Write;
      wrk->system.open        = w95t_Open;
      wrk->system.close       = w95t_Close;
      wrk->system.exit        = w95t_Exit;
      wrk->system.gmt         = w95t_GMT;
      wrk->system.pagebin     = app_binurl;

      /* spawn the thread and pass it the workspace pointer */
      _beginthread(w95t_server_thread,0,wrk);
   }

   /* all threads are spawned */
   /* loop, waiting for connections */
   /* when a connection is received, enqueue it for the server threads */
   for(;;) {
      /* specify the max length of the address structure and accept the
      next connection.  clientAddrLen is passed as a pointer as it is
      updated by the accept call.
      retry accept until it works
      */
      ews_printf("Accept : masterSock = %ld\n",masterSock);

      clientAddrLen = sizeof (clientAddr);
      clientSock = accept( masterSock, &clientAddr, &clientAddrLen );


      /* if accept call fails */
      if ( clientSock == INVALID_SOCKET ) {
         /* get winsock error */
         err = WSAGetLastError();

         /* print it to error output */
         ews_printf("Accept failed : %d\n",err);

         /* quit */
         break;
      }

      ews_printf("Connect : clientSock = %ld\n",clientSock);

      /* client socket is accepted  */
      /* enqueue it for the servers */
      /* return (long)clientSock;   */
      socket_qsend(thread_sockq,clientSock);
   }

   return 0;
}