Example #1
0
TInt TestGetThreadContext(DThread* aThread,TDes8* aContext)
	{
	TArmRegSet context1;
	TArmRegSet context2;

	memclr(&context1,sizeof(context1));
	memclr(&context2,sizeof(context2));
	NKern::Lock();
	TUint32 unused;
	NKern::ThreadGetUserContext(&aThread->iNThread,&context1,unused);
	TInt r=GetThreadUserContext(&aThread->iNThread,context2);
	NKern::Unlock();
	DumpContext(context1,-1);
	DumpContext(context2,r);

	TInt len,maxLen;
	Kern::KUDesInfo(*aContext,len,maxLen);
	if(maxLen>KMaxThreadContext)
		maxLen = KMaxThreadContext;
	TPtr8 ptr((TUint8*)&context1,maxLen,maxLen);
	Kern::KUDesPut(*aContext,ptr);

	for(TUint i=0; i<sizeof(context1); i++)
		if(((TUint8*)&context1)[i]!=((TUint8*)&context2)[i])
			return KErrGeneral;
	return r;
	}
Example #2
0
void
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
{
    Sigaction sa;

    // If SIGHUP handler is SIG_IGN, assume running
    // under nohup and do not set explicit handler.
    if(i == SIGHUP) {
        runtime·memclr((byte*)&sa, sizeof sa);
        if(runtime·rt_sigaction(i, nil, &sa, sizeof(sa.sa_mask)) != 0)
            runtime·throw("rt_sigaction read failure");
        if(sa.sa_handler == SIG_IGN)
            return;
    }

    runtime·memclr((byte*)&sa, sizeof sa);
    sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER;
    if(restart)
        sa.sa_flags |= SA_RESTART;
    sa.sa_mask = ~0ULL;
    sa.sa_restorer = (void*)runtime·sigreturn;
    if(fn == runtime·sighandler)
        fn = (void*)runtime·sigtramp;
    sa.sa_handler = fn;
    if(runtime·rt_sigaction(i, &sa, nil, sizeof(sa.sa_mask)) != 0)
        runtime·throw("rt_sigaction failure");
}
Example #3
0
void
runtime·setsig(int32 i, void (*fn)(int32, Siginfo*, void*, G*), bool restart)
{
	Sigaction sa;

	// If SIGHUP handler is SIG_IGN, assume running
	// under nohup and do not set explicit handler.
	if(i == SIGHUP) {
		runtime·memclr((byte*)&sa, sizeof sa);
		runtime·sigaction(i, nil, &sa);
		if(sa._sa_u._sa_sigaction == SIG_IGN)
			return;
	}

	runtime·memclr((byte*)&sa, sizeof sa);
	sa.sa_flags = SA_SIGINFO|SA_ONSTACK;
	if(restart)
		sa.sa_flags |= SA_RESTART;
	sa.sa_mask[0] = ~0U;
	sa.sa_mask[1] = ~0U;
	sa.sa_mask[2] = ~0U;
	sa.sa_mask[3] = ~0U;
	if (fn == runtime·sighandler)
		fn = (void*)runtime·sigtramp;
	sa._sa_u._sa_sigaction = (void*)fn;
	runtime·sigaction(i, &sa, nil);
}
Example #4
0
void
runtime·exit(int32)
{
	int32 fd;
	uint8 buf[128];
	uint8 tmp[16];
	uint8 *p, *q;
	int32 pid;

	runtime·memclr(buf, sizeof buf);
	runtime·memclr(tmp, sizeof tmp);
	pid = _tos->pid;

	/* build path string /proc/pid/notepg */
	for(q=tmp; pid > 0;) {
		*q++ = '0' + (pid%10);
		pid = pid/10;
	}
	p = buf;
	runtime·memmove((void*)p, (void*)"/proc/", 6);
	p += 6;
	for(q--; q >= tmp;)
		*p++ = *q--;
	runtime·memmove((void*)p, (void*)"/notepg", 7);

	/* post interrupt note */
	fd = runtime·open(buf, OWRITE);
	runtime·write(fd, "interrupt", 9);
	runtime·exits(nil);
}
Example #5
0
void run_test_3 (cyg_bool polled)
{
    diag_printf ("Test 3 : Extended API test (polled = %d).\n", polled ? 1 : 0);
    memclr(rx_data1, sizeof(rx_data1));
    memclr(rx_data2, sizeof(rx_data1));

    cyg_spi_transaction_begin (&loopback_device);
    cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data1),
                                  (const cyg_uint8*) &tx_data1[0], (cyg_uint8*) &rx_data1[0], false);
    cyg_spi_transaction_transfer (&loopback_device, polled, sizeof (tx_data2),
                                  (const cyg_uint8*) &tx_data2[0], (cyg_uint8*) &rx_data2[0], true);
    cyg_spi_transaction_end (&loopback_device);
    diag_printf ("    Tx data 1 (%u Bytes): %s\n", sizeof(tx_data1), tx_data1);
    diag_printf ("    Rx data 31 : %s\n", rx_data1);
    diag_printf ("    Tx data 2 (%u Bytes): %s\n", sizeof(tx_data2), tx_data2);
    diag_printf ("    Rx data 32 : %s\n", rx_data2);

    if (memcmp (tx_data1, rx_data1, sizeof (tx_data1)) != 0) {
        errors++;
        diag_printf("Simple transfer loopback failed - mismatched data (transfer 1).\n");
    }
    if (memcmp (tx_data2, rx_data2, sizeof (tx_data2)) != 0) {
        errors++;
        diag_printf("Simple transfer loopback failed - mismatched data (transfer 2).\n");
    }
}
Example #6
0
void
initialize_registers (int context)
{
  reg_image_t &reg_image = reg_images[context];

  memclr (reg_image.FPR, FPR_LENGTH * sizeof (double));
  reg_image.FGR = (float *) reg_image.FPR;
  reg_image.FWR = (int *) reg_image.FPR;

  memclr (reg_image.R, R_LENGTH * sizeof (reg_word));
  reg_image.R[REG_SP] = STACK_TOP - BYTES_PER_WORD - 4096; /* Initialize $sp */
  reg_image.HI = reg_image.LO = 0;
  reg_image.PC = TEXT_BOT;

  CP0_BadVAddr(reg_image) = 0;
  CP0_Count(reg_image) = 0;
  CP0_Compare(reg_image) = 0;
  CP0_Status(reg_image) = (CP0_Status_CU & 0x30000000) | CP0_Status_IM | CP0_Status_UM;
  CP0_Cause(reg_image) = 0;
  CP0_EPC(reg_image) = 0;
#ifdef SPIM_BIGENDIAN
  CP0_Configreg_image() =  CP0_Config_BE;
#else
  CP0_Config(reg_image) = 0;
#endif

  FIR(reg_image) = FIR_W | FIR_D | FIR_S;	/* Word, double, & single implemented */
  FCSR(reg_image) = 0x0;
  FCCR(reg_image) = 0x0;
  FEXR(reg_image) = 0x0;
  FENR(reg_image) = 0x0;

  reg_image.RFE_cycle = 0;
}
Example #7
0
/**
 * Initialization code.
 */
void busInit(void) {
    BYTE i;
    
    //Initialize busInfo structure with configured values from EEPROM
    memclr(&busInfo, sizeof(busInfo));      //Clear busInfo structure
    busInfoInit();
    
    //Initialze serial buses
    serInit();
    #if defined(BRD_SBC65EC)
    ser2Init();
    #endif
    i2cBusInit();

    /*
    debugPutGenMsg(2);     //@mxd:2:%s
    debugPutRomStringXNull((ROM char*)"Bus Ser1 Txbuf = 0x");
    debugPutByteHex( (BYTE)(((WORD)busInfo.buf[BUSID_SER1].txBuf)>>8) );
    debugPutByteHex( (BYTE)busInfo.buf[BUSID_SER1].txBuf );
    debugPutByte(0);    //Null terminate string

    debugPutGenMsg(2);     //@mxd:2:%s
    debugPutRomStringXNull((ROM char*)"Bus Ser1 Rxbuf = 0x");
    debugPutByteHex( (BYTE)(((WORD)busInfo.buf[BUSID_SER1].rxBuf)>>8) );
    debugPutByteHex( (BYTE)busInfo.buf[BUSID_SER1].rxBuf );
    debugPutByte(0);    //Null terminate string
    */

    #if (DEBUG_BUS >= LOG_ERROR)
    debugPutMsg(1);     //@mxd:1:Initialized Serial Buses
    #endif
}
Example #8
0
/******************************************************************************
 * NSchedulable
 ******************************************************************************/
NSchedulable::NSchedulable()
	:	iSSpinLock(TSpinLock::EOrderThread)
	{
	iPriority = 0;
	iReady = 0;
	iCurrent = 0;
	iLastCpu = 0;
	iPauseCount = 0;
	iSuspended = 0;
	iACount = 0;
	iPreferredCpu = 0;
	iActiveState = 0;
	i_NSchedulable_Spare2 = 0;
	iTransientCpu = 0;
	iForcedCpu = 0;
	iLbState = ELbState_Inactive;
	iCpuChange = 0;
	iStopping = 0;
	iFreezeCpu = 0;
	iParent = (NSchedulable*)0xdeadbeef;
	iCpuAffinity = 0;
	new (i_IDfcMem) TDfc(&DeferredReadyIDfcFn, this);
	iEventState = 0;
	iRunCount.i64 = 0;
	iLastRunTime.i64 = 0;
	iTotalCpuTime.i64 = 0;
	iLastActivationTime.i64 = 0;
	iTotalActiveTime.i64 = 0;
	iSavedCpuTime.i64 = 0;
	iSavedActiveTime.i64 = 0;
	iLbLink.iNext = 0;
	memclr(&iLbInfo, EMaxLbInfoSize);
	}
Example #9
0
void
runtime·newosproc(M *mp, void *stk)
{
	ThrParam param;
	Sigset oset;

	if(0){
		runtime·printf("newosproc stk=%p m=%p g=%p id=%d/%d ostk=%p\n",
			stk, mp, mp->g0, mp->id, (int32)mp->tls[0], &mp);
	}

	runtime·sigprocmask(&sigset_all, &oset);
	runtime·memclr((byte*)&param, sizeof param);

	param.start_func = runtime·thr_start;
	param.arg = (byte*)mp;
	
	// NOTE(rsc): This code is confused. stackbase is the top of the stack
	// and is equal to stk. However, it's working, so I'm not changing it.
	param.stack_base = (void*)mp->g0->stackbase;
	param.stack_size = (byte*)stk - (byte*)mp->g0->stackbase;

	param.child_tid = (intptr*)&mp->procid;
	param.parent_tid = nil;
	param.tls_base = (void*)&mp->tls[0];
	param.tls_size = sizeof mp->tls;

	mp->tls[0] = mp->id;	// so 386 asm can find it

	runtime·thr_new(&param, sizeof param);
	runtime·sigprocmask(&oset, nil);
}
Example #10
0
void
runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
{
	ThrParam param;
	Sigset oset;

	USED(fn);	// thr_start assumes fn == mstart
	USED(gp);	// thr_start assumes gp == mp->g0

	if(0){
		runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
			stk, mp, gp, fn, mp->id, mp->tls[0], &mp);
	}

	runtime·sigprocmask(&sigset_all, &oset);
	runtime·memclr((byte*)&param, sizeof param);

	param.start_func = runtime·thr_start;
	param.arg = (byte*)mp;
	param.stack_base = (void*)gp->stackbase;
	param.stack_size = (byte*)stk - (byte*)gp->stackbase;
	param.child_tid = (intptr*)&mp->procid;
	param.parent_tid = nil;
	param.tls_base = (void*)&mp->tls[0];
	param.tls_size = sizeof mp->tls;

	mp->tls[0] = mp->id;	// so 386 asm can find it

	runtime·thr_new(&param, sizeof param);
	runtime·sigprocmask(&oset, nil);
}
Example #11
0
int32
runtime·postnote(int32 pid, int8* msg)
{
	int32 fd, len;
	uint8 buf[128];
	uint8 tmp[16];
	uint8 *p, *q;

	runtime·memclr(buf, sizeof buf);

	/* build path string /proc/pid/note */
	q = tmp;
	p = buf;
	runtime·itoa(pid, tmp, sizeof tmp);
	runtime·memmove((void*)p, (void*)"/proc/", 6);
	for(p += 6; *p++ = *q++; );
	p--;
	runtime·memmove((void*)p, (void*)"/note", 5);

	fd = runtime·open((int8*)buf, OWRITE, 0);
	if(fd < 0)
		return -1;

	len = runtime·findnull((byte*)msg);
	if(runtime·write(fd, msg, len) != len) {
		runtime·close(fd);
		return -1;
	}
	runtime·close(fd);
	return 0;
}
bool Adafruit_BluefruitLE_SPI::getResponse(void)
{
    // Blocking wait until IRQ is asserted
    while ( !digitalRead(m_irq_pin) ) {}

    // There is data from Bluefruit & enough room in the fifo
    while ( digitalRead(m_irq_pin) &&
            m_rx_fifo.remaining() >= SDEP_MAX_PACKETSIZE )
    {
        // Get a SDEP packet
        sdepMsgResponse_t msg_response;
        memclr(&msg_response, sizeof(sdepMsgResponse_t));

        if ( !getPacket(&msg_response) ) return false;

        // Write to fifo
        if ( msg_response.header.length > 0)
        {
            m_rx_fifo.write_n(msg_response.payload, msg_response.header.length);
        }

        // No more packet data
        if ( !msg_response.header.more_data ) break;

        // It takes a bit since all Data received to IRQ to get LOW
        // May need to delay a bit for it to be stable before the next try
        // delayMicroseconds(SPI_DEFAULT_DELAY_US);
    }

    return true;
}
Example #13
0
void TH__setup_threads(const TH_thread_funptr *thfptrs){
  debug((uint16_t) thfptrs[0].fptr);
  int16_t i, n;
  debug(F("Tset:"));
  assert(thfptrs);
  TH__thread_funptrs = (TH_thread_funptr *)thfptrs;
  i = get_len_fptrs();
  sdebug(F("len:")); edebug(i);
  assert(i <= MAX_THREADS);
  TH__threads = (pthread *)malloc(sizeof(pthread) * i);
  debug((uint16_t) TH__threads);
  memcheck(TH__threads);
  for(n = 0; n < i; n++){
    //PT_INIT(&TH__threads[n]);
    //set_thread_innactive(&TH__threads[n]);
    TH__threads[n].lc = PT_INNACTIVE;
    TH__threads[n].data = NULL;
  }
  TH__threads_len = i;
  debug(F("TsetD"));
  return;
error:
  memclr(TH__threads);
  return;
}
Example #14
0
/*
 ****************************************************************
 *	Obtém um RAW EP da lista livre				*
 ****************************************************************
 */
RAW_EP	*
get_raw_ep (void)
{
	register ITSCB	*ip = &itscb;
	register RAW_EP	*rp;

	SPINLOCK (&ip->it_rep_lock);

	if ((rp = ip->it_rep_free) == NO_RAW_EP)
		{ SPINFREE (&ip->it_rep_lock); return (NO_RAW_EP); }

	ip->it_rep_free = rp->rp_next;

	memclr (rp, sizeof (RAW_EP));

	rp->rp_next = ip->it_rep_busy;
	ip->it_rep_busy = rp;

	ip->it_rep_count++;

	SPINFREE (&ip->it_rep_lock);

	return (rp);

}	/* end get_raw_ep */
Example #15
0
/*
 ****************************************************************
 *	Obtém um TCP EP da lista livre				*
 ****************************************************************
 */
TCP_EP	*
get_tcp_ep (void)
{
	register ITSCB	*ip = &itscb;
	register TCP_EP	*tp;

	SPINLOCK (&ip->it_tep_lock);

	if ((tp = ip->it_tep_free) == NO_TCP_EP)
		{ SPINFREE (&ip->it_tep_lock); return (NO_TCP_EP); }

	ip->it_tep_free = tp->tp_next;

	memclr (tp, sizeof (TCP_EP));

	tp->tp_next = ip->it_tep_busy;
	ip->it_tep_busy = tp;

	ip->it_tep_count++;

	SPINFREE (&ip->it_tep_lock);

	return (tp);

}	/* end get_tcp_ep */
Example #16
0
/*
 ****************************************************************
 *	Obtém um UDP EP da lista livre				*
 ****************************************************************
 */
UDP_EP	*
get_udp_ep (void)
{
	register ITSCB	*ip = &itscb;
	register UDP_EP	*up;

	SPINLOCK (&ip->it_uep_lock);

	if ((up = ip->it_uep_free) == NO_UDP_EP)
		{ SPINFREE (&ip->it_uep_lock); return (NO_UDP_EP); }

	ip->it_uep_free = up->up_next;

	memclr (up, sizeof (UDP_EP));

	up->up_next = ip->it_uep_busy;
	ip->it_uep_busy = up;

	ip->it_uep_count++;

	SPINFREE (&ip->it_uep_lock);

	return (up);

}	/* end get_udp_ep */
Example #17
0
runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, bool large, bool needzero)
{
	MSpan *s;

	// Don't do any operations that lock the heap on the G stack.
	// It might trigger stack growth, and the stack growth code needs
	// to be able to allocate heap.
	if(g == g->m->g0) {
		s = mheap_alloc(h, npage, sizeclass, large);
	} else {
		g->m->ptrarg[0] = h;
		g->m->scalararg[0] = npage;
		g->m->scalararg[1] = sizeclass;
		g->m->scalararg[2] = large;
		runtime·mcall(mheap_alloc_m);
		s = g->m->ptrarg[0];
		g->m->ptrarg[0] = nil;
	}
	if(s != nil) {
		if(needzero && s->needzero)
			runtime·memclr((byte*)(s->start<<PageShift), s->npages<<PageShift);
		s->needzero = 0;
	}
	return s;
}
Example #18
0
runtime·getenv(int8 *s)
{
	int32 fd, n, r;
	intgo len;
	byte file[128];
	byte *p;

	len = runtime·findnull((byte*)s);
	if(len > sizeof file-6)
		return nil;

	runtime·memclr(file, sizeof file);
	runtime·memmove((void*)file, (void*)"/env/", 5);
	runtime·memmove((void*)(file+5), (void*)s, len);

	fd = runtime·open((int8*)file, OREAD, 0);
	if(fd < 0)
		return nil;
	n = runtime·seek(fd, 0, 2);
	p = runtime·malloc(n+1);
	r = runtime·pread(fd, p, n, 0);
	runtime·close(fd);
	if(r < 0)
		return nil;
	return p;
}
Example #19
0
/*
 * Free an agent control block
 */
INTERNAL void
agent_free(AGENT_REQ *areq) {
	areq->status = AGENTD_AGENT_FREE;
	areq->pid    = 0;
	memclr(areq, sizeof(AGENT_REQ));
	--Nagent;
}
Example #20
0
void run_test_1 (cyg_bool polled, const char* tx_data_p, cyg_uint32 count)
{
    diag_printf ("Test 1 : Simple transfer test polled = %d, count=%d\n",
                 polled ? 1 : 0, count);
    memclr(rx_data1, sizeof(rx_data1));
    memclr(rx_data2, sizeof(rx_data1));
    cyg_spi_transfer (&loopback_device, polled, count,
        (const cyg_uint8*) tx_data_p, (cyg_uint8*) &rx_data[0]);
    diag_printf ("    Tx data : %s\n", tx_data_p);
    diag_printf ("    Rx data : %s 0x%02x\n", rx_data, rx_data[0]);

    if (memcmp (tx_data_p, rx_data, count) != 0) {
        errors++;
        diag_printf("Simple transfer loopback failed - mismatched data.\n");
    }
}
Example #21
0
static void
resizefintab(Fintab *tab)
{
	Fintab newtab;
	void *k;
	int32 i;

	runtime·memclr((byte*)&newtab, sizeof newtab);
	newtab.max = tab->max;
	if(newtab.max == 0)
		newtab.max = 3*3*3;
	else if(tab->ndead < tab->nkey/2) {
		// grow table if not many dead values.
		// otherwise just rehash into table of same size.
		newtab.max *= 3;
	}
	
	newtab.key = runtime·mallocgc(newtab.max*sizeof newtab.key[0], FlagNoPointers, 0, 1);
	newtab.val = runtime·mallocgc(newtab.max*sizeof newtab.val[0], 0, 0, 1);
	
	for(i=0; i<tab->max; i++) {
		k = tab->key[i];
		if(k != nil && k != (void*)-1)
			addfintab(&newtab, k, tab->val[i].fn, tab->val[i].nret);
	}
	
	runtime·free(tab->key);
	runtime·free(tab->val);
	
	tab->key = newtab.key;
	tab->val = newtab.val;
	tab->nkey = newtab.nkey;
	tab->ndead = newtab.ndead;
	tab->max = newtab.max;
}
Example #22
0
void
runtime·itoa(int32 n, byte *p, uint32 len)
{
	byte *q, c;
	uint32 i;

	if(len <= 1)
		return;

	runtime·memclr(p, len);
	q = p;

	if(n==0) {
		*q++ = '0';
		USED(q);
		return;
	}
	if(n < 0) {
		*q++ = '-';
		p++;
		n = -n;
	}
	for(i=0; n > 0 && i < len; i++) {
		*q++ = '0' + (n%10);
		n = n/10;
	}
	for(q--; q >= p; ) {
		c = *p;
		*p++ = *q;
		*q-- = c;
	}
}
Example #23
0
int
main(void)
{
  uint8_t data[64];
  char string[(sizeof(data) * 2) + 1];

  memset(data, 0xab, sizeof(data));

  if (det_data_to_hex(string, sizeof(string), data, sizeof(data)) !=
      (sizeof(string) - 1))
  {
    det_derr_msg("Failed det_data_to_hex");
    return (EXIT_FAILURE);
  }

  uint8_t buf[sizeof(data)];

  memclr(buf, sizeof(buf));

  if (det_hex_to_data(buf, sizeof(buf), string) != sizeof(data))
  {
    det_derr_msg("Failed det_hex_to_data");
    return (EXIT_FAILURE);
  }

  if (memcmp(data, buf, sizeof(data)))
  {
    det_derr_msg("Failed memcmp");
    return (EXIT_FAILURE);
  }

  return (EXIT_SUCCESS);
} // main()
void vfs_generate_path(char *buf, size_t bytes, vfs_inode_t *parent) {
  size_t len = 0;
  
  vfs_inode_t *inode = parent;
  while(inode != vfs_root()) {
    len += strlen((char*)inode->name) + 1;
    inode = inode->parent;
  }
  
  if(len > bytes) {
    printf("Puffer zu klein!\n");
    return;
  }
  
  memclr(buf, bytes);
  if(len > 0) {
    buf += len+1;
    *--buf = '\0';
    
    inode = parent;
    while(inode != vfs_root()) {
      int len = strlen((char*)inode->name);
      buf -= len;
      memcpy(buf, inode->name, len);
      
      *--buf = '/';
      inode = inode->parent;
    }
  } else {
    strcpy(buf,"/");
  }
}
Example #25
0
File: module.c Project: UIKit0/TSOS
/*
 * Reads the file from the path into a temporary buffer, and then attempt to
 * load it as a kernel module.
 *
 * @param path Path to the kernel module
 * @param err Pointer to an integer in which to store a more detailed error
 * @return true if success, false if error.
 */
bool module_load_from_file(char *path, int *err) {
	// Attempt to open file
	fs_file_handle_t *module = hal_vfs_fopen(path, kFSFileModeReadOnly);
	if(module) {
		// Reject modules > 1MB in size
		fs_file_t *file = hal_vfs_handle_to_file(module);
		if(file->size > MODULE_MAX_SIZE) {
			KERROR("%s is %u bytes, max %u bytes", path, (unsigned int) file->size, MODULE_MAX_SIZE);
			return false;
		}

		// Get buffer and zero it
		void *buf = (void *) paging_module_buffer();
		memclr(buf, MODULE_MAX_SIZE);

		// Read entire file
		hal_vfs_fread(buf, file->size, module);

		// Clean up
		hal_vfs_fclose(module);

		// Perform module loading
		module_load(buf, file->i.name);
	} else {
		KERROR("Can't open '%s' for module read", path);
	}

	return false;
}
Example #26
0
runtime·malg(int32 stacksize)
{
	G *newg;
	byte *stk;

	if(StackTop < sizeof(Stktop)) {
		runtime·printf("runtime: SizeofStktop=%d, should be >=%d\n", (int32)StackTop, (int32)sizeof(Stktop));
		runtime·throw("runtime: bad stack.h");
	}

	newg = runtime·malloc(sizeof(G));
	if(stacksize >= 0) {
		if(g == m->g0) {
			// running on scheduler stack already.
			stk = runtime·stackalloc(StackSystem + stacksize);
		} else {
			// have to call stackalloc on scheduler stack.
			g->param = (void*)(StackSystem + stacksize);
			runtime·mcall(mstackalloc);
			stk = g->param;
			g->param = nil;
		}
		newg->stack0 = stk;
		newg->stackguard = stk + StackGuard;
		newg->stackbase = stk + StackSystem + stacksize - sizeof(Stktop);
		runtime·memclr(newg->stackbase, sizeof(Stktop));
	}
	return newg;
}
/**
  * Shifts the pixels in this Image a given number of pixels to downward.
  *
  * @param n The number of pixels to shift.
  *
  * @return MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER.
  *
  * @code
  * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; // a cute heart
  * MicroBitImage i(10,5,heart);
  * i.shiftDown(1);
  * @endcode
  */
int MicroBitImage::shiftDown(int16_t n)
{
    uint8_t *pOut, *pIn;

    if (n <= 0 )
        return MICROBIT_INVALID_PARAMETER;

    if(n >= getHeight())
    {
        clear();
        return MICROBIT_OK;
    }

    pOut = getBitmap() + getWidth()*(getHeight()-1);
    pIn = pOut - getWidth()*n;

    for (int y = 0; y < getHeight(); y++)
    {
        // Copy, and blank fill the leftmost column.
        if (y < getHeight()-n)
            memcpy(pOut, pIn, getWidth());
        else
            memclr(pOut, getWidth());

        pIn -= getWidth();
        pOut -= getWidth();
    }

    return MICROBIT_OK;
}
Example #28
0
runtime·MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed)
{
	MCacheList *l;
	MLink *v;

	// Allocate from list.
	l = &c->list[sizeclass];
	if(l->list == nil) {
		// Replenish using central lists.
		l->nlist = runtime·MCentral_AllocList(&runtime·mheap->central[sizeclass], &l->list);
		if(l->list == nil)
			runtime·throw("out of memory");
	}
	v = l->list;
	l->list = v->next;
	l->nlist--;

	// v is zeroed except for the link pointer
	// that we used above; zero that.
	v->next = nil;
	if(zeroed) {
		// block is zeroed iff second word is zero ...
		if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0)
			runtime·memclr((byte*)v, size);
	}
	c->local_cachealloc += size;
	c->local_objects++;
	return v;
}
Example #29
0
bool Context::Init(uint width, uint height)
{
	_width = width;
	_height = height;

#ifdef WIN32
	_instance = static_cast<HINSTANCE>(GetModuleHandle(nullptr));

#ifndef FINAL
	if(!CreateConsole())
	{
		LogErrorL("Failed to create console window");
		return false;
	}
#endif

	WNDCLASSEX wc;

	memclr(&wc, sizeof(wc));

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.lpfnWndProc   = WndProc;
    wc.hInstance     = _instance;
    wc.hIcon         = LoadIcon(nullptr, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(nullptr, IDC_ARROW);
    wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
    wc.lpszMenuName  = nullptr;
    wc.lpszClassName = "EngineClass";
    wc.hIconSm       = wc.hIcon;

    if(!RegisterClassEx(&wc))
    {
        LogErrorL("Failed to register class: %s", wc.lpszClassName);
        return false;
    }

	LPSTR window_title = "Engine";
    _window = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        wc.lpszClassName,
        window_title,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 1280, 720,
        nullptr, nullptr, _instance, nullptr);

    if(_window == nullptr)
    {
        LogErrorL("Failed to create window: %s", window_title);
        return false;
    }

	LogSuccessL("Created window: %s", window_title);

    ShowWindow(_window, SW_SHOWNORMAL);
    UpdateWindow(_window);
#endif

	return true;
}
Example #30
0
void
runtime·SysMap(void *v, uintptr n)
{
	void *p = v;
	
	mstats.sys += n;

	// On 64-bit, we don't actually have v reserved, so tread carefully.
	if(sizeof(void*) == 8) {
		runtime·mmap((void*)&p, n, MMAP_WRITE, 0, 0, 0);
		runtime·memclr(p, n);
		return;
	}

	runtime·mmap((void*)&p, n, MMAP_WRITE, 0, 0, 0);
	runtime·memclr(p, n);
}