unsigned char * generate(treenode * root) { unsigned char * program = (unsigned char *)malloc(MAX_PROGRAM); int pc = 0; // header pc += 8; // static variables program[2] = hibyte(pc); program[3] = lobyte(pc); pc = generate_static_variables(program, pc); // program program[4] = hibyte(pc); program[5] = lobyte(pc); pc = generateBLOCK(program, pc, root); program[pc++] = OPCODE_EXIT; // stack program[6] = hibyte(pc); program[7] = lobyte(pc); pc += STACK_SIZE; // fix up header's size member program[0] = hibyte(pc); program[1] = lobyte(pc); return program; }
// Send data from LCD to PC via RS-232 using the XMODEM protocol static inline void SendBMP(void) { uint8_t rx,data,Packet=1, n=0,i,j; uint16_t crc=0; // First Block send(SOH); send(Packet); // Send Packet number send(255-Packet); // Send Packet number 1's complement // Send BMP Header for(i=0; i<62; i++) { n++; data = pgm_read_byte_near(BMP+i); crc=_crc_xmodem_update(crc,data); send(data); } // Send LCD data, 64 lines for(i=63; i!=255; i--) { // Each LCD line consists of 16 bytes for(j=0; j<16; j++) { data=transpose(j*8,i); crc=_crc_xmodem_update(crc,data); send(data); n++; if(n==128) { // end of 128byte block n=0; send(hibyte(crc)); send(lobyte(crc)); // Wait for ACK rx = read(); if(rx!=ACK) return; // Error -> cancel transmission Packet++; send(SOH); send(Packet); send(255-Packet); crc=0; } } } // End of last block for(; n<128; n++) { // send remainder of block data= 0x1A; // pad with 0x1A which marks the end of file crc=_crc_xmodem_update(crc,data); send(data); } send(hibyte(crc)); send(lobyte(crc)); rx = read(); if(rx!=ACK) return; send(EOT); rx = read(); if(rx!=NAK) return; send(EOT); rx = read(); if(rx!=ACK) return; }
int generateIF(unsigned char * program, int pc, treenode * root) { int temppc, calcpc; //Go process the boolean operator first J. Brooks treenode * child = firstchild(root); pc = generateOPERATOR(program, pc, child); //Pop the exteraneous push first program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; //Jump around the the false parameter load if bool is true (True cmp val is already loaded by Operator processing) program[pc++] = OPCODE_JEq; program[pc++] = hibyte(4); program[pc++] = lobyte(4); //Load for false process jmp program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(0); program[pc++] = lobyte(0); program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G2; program[pc++] = hibyte(0); program[pc++] = lobyte(0); program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; //jmp around block if test was false program[pc++] = OPCODE_JEq; temppc = pc; //Reserve jump relative param spots program[pc++] = hibyte(0); program[pc++] = lobyte(0); //Process the block child = nextchild(root,child); pc = generateBLOCK(program, pc, child); //calc the block size calcpc = pc - temppc - 2; //fix up the jump relative program[temppc++] = hibyte(calcpc); program[temppc++] = lobyte(calcpc); return pc; }
/*-#+func---------------------------------------------------------- FUNCTION: inet_ntoa() PURPOSE: Convert an internet address (in host byte order) to a dotted decimal ascii string, e.g., 255.255.255.255\0 SYNTAX: DESCRIPTION: RETURNS: HISTORY: --#-func----------------------------------------------------------*/ char *inet_ntoa(int32 a) { static char buf[25]; sprintf(buf,"%u.%u.%u.%u", hibyte(hiword(a)), lobyte(hiword(a)), hibyte(loword(a)), lobyte(loword(a)) ); return buf; }
/* Print a buffer up to 16 bytes long in formatted hex with ascii * translation, e.g., * 0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>? */ static void fmtline( FILE *fp, uint addr, uint8 *buf, uint len) { char line[80]; char *aptr,*cptr; uint8 c; memset(line,' ',sizeof(line)); ctohex(line,(uint)hibyte(addr)); ctohex(line+2,(uint)lobyte(addr)); aptr = &line[6]; cptr = &line[55]; while(len-- != 0){ c = *buf++; ctohex(aptr,(uint)c); aptr += 3; *cptr++ = isprint(c) ? c : '.'; } *cptr++ = '\n'; fwrite(line,1,(unsigned)(cptr-line),fp); }
void UIDropMsg::on_okButton_clicked() { djDebug()<<"UIDropMsg::on_okButton_clicked"; QString broadcastMsg = lineEdit->text(); QByteArray utf8 = broadcastMsg.toUtf8(); QByteArray buf(sizeof(DJGameProtocol)+sizeof(ChatContent) + utf8.size() + 1,0); DJGameProtocol *protocol = reinterpret_cast<DJGameProtocol *>(buf.data()); protocol->chTotalLen = buf.size(); protocol->chType = DJGAME_PROTOCOL_TYPE_CHAT; protocol->chLanguage = m_gameController->language(); ChatContent *chat = reinterpret_cast<ChatContent *>(protocol->chBuf); setle4( &chat->userid_speaker, m_gameController->selfUserId() ); setle4( &chat->userid_listener, DJGAME_PLAYER_BROADCAST ); chat->chGameClass = hibyte(m_gameController->gameId()); chat->chGame = lobyte(m_gameController->gameId()); qstrcpy( chat->szSentence, utf8.data() ); DJClientRequest request( buf ); m_gameController->sendRequest( request ); close(); }
void PAS_SetSampleRateTimer ( void ) { int LoByte; int HiByte; int data; unsigned flags; flags = DisableInterrupts(); // Disable the Sample Rate Timer data = PAS_State->audiofilt; data &= ~SampleRateTimerGateFlag; PAS_Write( AudioFilterControl, data ); PAS_State->audiofilt = data; // Select the Sample Rate Timer data = SelectSampleRateTimer; PAS_Write( LocalTimerControl, data ); PAS_State->tmrctlr = data; LoByte = lobyte( PAS_TimeInterval ); HiByte = hibyte( PAS_TimeInterval ); // Program the Sample Rate Timer PAS_Write( SampleRateTimer, LoByte ); PAS_Write( SampleRateTimer, HiByte ); PAS_State->samplerate = PAS_TimeInterval; RestoreInterrupts( flags ); }
void _jsr(void) { word addr; push(hibyte(cpu.pc + 3)); push(lobyte(cpu.pc + 3)); addr = fetch_word((word)(cpu.pc + 1)); cpu.pc = addr; }
void _brk(void) { push(hibyte(cpu.pc + sizeof(word))); push(lobyte(cpu.pc + sizeof(word))); push(cpu.sr); set_brk_flag(); set_int_disable_flag(); cpu.pc = fetch_word(IRQ_VECTOR); }
VOID outab(b) { if (pass == 2) { out_lb(b,0); if (oflag) { outchk(1, 0); *txtp++ = lobyte(b); } } ++dot.s_addr; }
int generateNUMBER(unsigned char * program, int pc, treenode * root) { // LOAD_R G1 value program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(root->attribute.value); program[pc++] = lobyte(root->attribute.value); // PUSH_R G1 program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; return pc; }
int generateCOLOR_NAME(unsigned char * program, int pc, treenode * root) { //Push a value representing a color (0-15) on the stack J. Brooks program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(root->attribute.color); program[pc++] = lobyte(root->attribute.color); // PUSH_R G1 program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; return pc; }
/* *------------------------------------------------------------------------ * clkinit - initialize the clock and sleep queue (called at startup) *------------------------------------------------------------------------ */ void clkinit() { preempt = QUANTUM; /* initial time quantum */ countTick = TICK; /* TICKs of a sec. counter */ clmutex = screate(1); /* semaphore for tod clock */ clktime = 0L; /* initially a low number */ ctr100 = 0L; /* timer (relative) */ slnempty = FALSE; /* initially, no process asleep */ clkdiff = 0; /* zero deferred ticks */ defclk = FALSE; /* clock is not deferred */ clkruns = 1; clockq = newqueue(); /* Initialize timer 3 (System Clock) */ /* 100 Hz clock 16000000/256/(1+624) */ /* OCR3A set to 624 for CTC mode */ OCR3AH = hibyte(624); /* 0-624 => divide by 625 */ OCR3AL = lobyte(624); /* write high byte first! */ TCNT3L = 0x00; TCNT3H = 0x00; TCCR3A = 0x00; /* normal port operation, WGM31=0 WGM30=0 */ TCCR3B = (1<<CS32) | (0<<CS31) | (0<<CS30); /* (clock source/256) for 62500Hz */ TCCR3B |= (1 << WGM32); /* normal mode 4: CTC w/OCR3A */ TCCR3C = 0x00; TIMSK3 |= (1<<OCF3A); /* Clear overflow flag bit */ TIMSK3 |= (1<<OCIE3A); /* Output Compare A Match Interrupt Enable */ /* Initialize timer 2 (RTC) */ TIMSK2 &= ~((1<<TOIE2)|(1<<OCIE2A)|(1<<OCIE2B)); //Disable TC2 interrupt ASSR |= (1<<AS2); //set Timer/Counter2 to be asynchronous from the CPU clock //with a second external clock(32.768kHz)driving it. TCNT2 = 0x00; TCCR2A = 0x00; //normal mode 0 TCCR2B = 0x05; //prescale the timer to be clock source / 128 // //TIMER2 quit working on me 12/21/2013 -- change rtc & MAC Symbol counter!!!!!!!!!!!!!!!!!! // // while(ASSR&0x1F) // while(ASSR&( (1<<TCR2BUB)|(1<<OCR2BUB)|(1<<TCN2UB) )) // ; //Wait until TC0 is updated // TIFR2 |= (1<<TOV2); //Clear overflow flag bit // TIMSK2 |= (1<<TOIE2); //set 8-bit Timer/Counter0 Overflow Interrupt Enable }
bool Crypt(const wxString &sText, wxString &sCryptText) { sCryptText.Clear(); const wxString sPass(PASSWD); size_t pos(0); for(size_t i = 0; i < sText.Len(); ++i) { if(pos == sPass.Len()) pos = 0; wxUint32 val1 = sText[i]; wxUint32 val2 = sPass[pos]; wxUint32 Symbol = val1 ^ val2; char SymbolHi = hibyte(Symbol); char SymbolLo = lobyte(Symbol);//(Symbol >> 4) & 0xff; sCryptText += wxDecToHex(SymbolHi); sCryptText += wxDecToHex(SymbolLo); pos++; } return true; }
int yhy632_send_command(int fd, unsigned short command, unsigned char * data, int data_len) { unsigned short length = 2 + 2 + 1 + data_len; unsigned char header0 = YHY632_HEADER_FIRST; unsigned char header1 = YHY632_HEADER_SECOND; unsigned char zero = 0; unsigned char checksum = 0x00; unsigned char * payload; do_write(fd, &header0, 1); do_write(fd, &header1, 1); do_write(fd, &length, 2); do_write(fd, &zero, 1); do_write(fd, &zero, 1); checksum ^= 0; do_write(fd, &command, 2); checksum ^= hibyte(command); checksum ^= lobyte(command); int i ; for (i = 0; i < data_len; i++) { do_write(fd, data + i, 1); checksum ^= data[i]; if (data[i] == 0xAA) { do_write(fd, &zero, 1); } } do_write(fd, &checksum, 1); fdatasync(fd); }
int generateREPEAT(unsigned char * program, int pc, treenode * root) { int temppc, temppc2, calcpc; //printf("Entering generateREAPET with root type %i and attribute %i\n",root->type,root->attribute.func); //Repeat build. First get the repeat count treenode * child = firstchild(root); pc = generate_expression(program, pc, child); program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; //Bump loop count for pre decrement program[pc++] = OPCODE_INC_R; program[pc++] = REGISTER_G1; //Push loop count program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; //Jump to pre decrement processing program[pc++] = OPCODE_JMPRe; temppc = pc; program[pc++] = hibyte(0); program[pc++] = lobyte(0); child = nextchild(root,child); //Process the block temppc2 = pc; pc = generateBLOCK(program, pc, child); //Fix up the jump calcpc = pc - temppc-2; program[temppc++] = hibyte(calcpc); program[temppc++] = lobyte(calcpc); //Decr and compare loop count program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_DEC_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G2; program[pc++] = hibyte(0); program[pc++] = lobyte(0); program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; //Loop done jump to finish program[pc++] = OPCODE_JEq; program[pc++] = hibyte(3); program[pc++] = lobyte(3); //Continue more repeat jump back to top of block program[pc++] = OPCODE_JMPRe; calcpc = temppc2 - pc - 2; program[pc++] = hibyte(calcpc); program[pc++] = lobyte(calcpc); //Clean the stack program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; return pc; }
// returns count bytes recieved, -1 otherwise int yhy632_recieve_data(int fd, unsigned short expected_cmd, unsigned char * status, char * data) { unsigned char prev_byte = 0; unsigned char current_byte = 0; unsigned short cmd; while ( 1 ) { //expected_cmd != cmd while (1) { if (synchronous_read(fd, ¤t_byte, 1, YHY632_TIMEOUT) >= 0) { if (( prev_byte == YHY632_HEADER_FIRST ) && ( current_byte == YHY632_HEADER_SECOND )) { // header found, stop if (verbose) fprintf(logfd, "header found stop\n"); break; } prev_byte = current_byte; } else { fprintf(logfd, "failed to get header!\n"); return -2; } } unsigned short length; unsigned short reserved; unsigned char checksum = 0; unsigned char original_checksum; if ( synchronous_read(fd, &length, 2, YHY632_TIMEOUT) < 1) return -2; if (verbose) fprintf(logfd, "length: %d\n", length); if (length == 0x000a && expected_cmd == 0x0212) { length = 0x0d; } if ( synchronous_read(fd, &reserved, 2, YHY632_TIMEOUT) < 1) return -2; checksum ^= hibyte(reserved); checksum ^= lobyte(reserved); if ( synchronous_read(fd, &cmd, 2, YHY632_TIMEOUT) < 1) return -2; if (cmd != expected_cmd) continue ; checksum ^= lobyte(cmd); checksum ^= hibyte(cmd); if ( synchronous_read(fd, status, 1, YHY632_TIMEOUT) < 1) return -2; checksum ^= *status; int i; //reading data if ( synchronous_read(fd, data, length - 6, YHY632_TIMEOUT) < length - 6) return -2; for (i=0; i < length -6; i++ ) { checksum ^= data[i]; } synchronous_read(fd, &original_checksum, 1, YHY632_TIMEOUT); if (original_checksum == checksum) { return length - 6; } else { if (*status == 0) { fprintf(logfd, "checksum %d should be %d\n", original_checksum, checksum); } return -1; } } }
int do_pseudo (int op) { char fccdelim; int fill; int tmp, tmp2; struct nlist *np, *index, *val; char ctemp[80], ctemp1[80]; char *ptr; if (op != EQU && *Label) { install (Label, Pc); } P_force++; switch (op) { case RMB: /* reserve memory bytes */ if (eval ()) { Pc += Result; if (strncmp ("ds.w", Op, 4) == 0) Pc += Result; /* double it if talking words */ if (strncmp ("rmw", Op, 4) == 0) Pc += Result; /* double it if talking words */ f_record (); /* flush out bytes */ } else error ("Undefined operand in RMB pseudo-op."); break; case ZMB: /* zero memory bytes */ if (eval ()) while (Result--) emit (0); else { error ("Undefined operand for ZMB pseudo-op."); } break; case FILL: /* fill memory with constant */ eval (); fill = Result; if (*Optr++ != ',') error ("Comma missing in FILL pseudo-op."); else { Optr = skip_white (Optr); eval (); while (Result--) emit (fill); } break; case FCB: /* form constant byte(s) */ do { Optr = skip_white (Optr); eval (); if (Result > 0xFF) { if (!Force_byte) warn ("Value too large and has been masked to 0xFF"); Result = lobyte (Result); } emit (Result); } while (*Optr++ == ','); break; case FDB: /* form double byte(s) */ do { Optr = skip_white (Optr); eval (); eword (Result); } while (*Optr++ == ','); break; case FCC: /* form constant characters */ if (*Operand == NULL) break; fccdelim = *Optr++; while (*Optr != NULL && *Optr != fccdelim) emit (*Optr++); if (*Optr == fccdelim) Optr++; else error ("Missing delimiter in FCC pseudo-op."); break; case ORG: /* origin */ if (eval ()) { Old_pc = Pc = Result; f_record (); /* flush out any bytes */ } else error ("Undefined operand for ORG pseudo-op."); break; case EQU: /* equate */ if (*Label == NULL) { error ("Missing or bad label for EQU pseudo-op."); break; } if (eval ()) { if (Pass == 1) { install (Label, Result); } else { np = lookup (Label); np->def = Result; } Old_pc = Result; /* override normal */ } else error ("Undefined operand for EQU pseudo-op."); break; case REDEF: ptr = ctemp; tmp = 0; Optr = Operand; /* while ((!delim(*Optr)) && (*Optr!=NULL)) { */ while ((!delim (*Optr)) && (*Optr != 0)) { if (*Optr == ',') { tmp++; } Optr++; } Optr = Operand; while (alphan (*Optr)) *ptr++ = *Optr++; /* *ptr = NULL; */ *ptr = 0; Optr++; np = lookup (ctemp); if (np == NULL) { error ("Cannot redefine an undefined label."); } else { if (tmp > 1) { Optr = Operand; while (alphan (*Optr)) Optr++; Optr++; /* go past the comma */ ptr = ctemp; while (alphan (*Optr)) *ptr++ = *Optr++; /* collect the next label into ctemp */ *ptr = 0; if (*Optr == ',') { Optr++; /* go past the next comma */ ptr = ctemp1; while (alphan (*Optr)) *ptr++ = *Optr++; /* collect the next label into ctemp1 */ *ptr = 0; index = lookup (ctemp1); /* now I have the address of the index variable */ if (index == NULL) { error ("Index variable in REDEF pseudo-op is undefined."); return 0; } if (*Optr == ',') { Optr++; /* go past next comma */ eval (); /* gets the limit for the increment */ index->def = index->def + 1; if (index->def > Result) { index->def = 0; } sprintf (ctemp1, "%s%03d", ctemp, index->def); val = lookup (ctemp1); if (val == NULL) { error ("Internal error in REDEF pseudo-op; val == NULL."); return 0; } np->def = val->def; } else { error ("Missing arguments in REDEF pseudo-op."); return 0; } } else { error ("Missing arguments in REDEF pseudo-op."); return 0; } } else { eval (); np->def = Result; Old_pc = Result; /* override normal */ } } break; case LOC: /* equate */ Optr = Operand; if (alphan (*Optr)) { eval (); LocLab = Result; } P_force = 0; tmp = tmp2 = LocLab / 100; Loc_Lab[0] = hexstr2[tmp]; tmp = (LocLab - (tmp2 * 100)) / 10; Loc_Lab[1] = hexstr2[tmp]; tmp = LocLab - ((tmp2 * 100) + (tmp * 10)); Loc_Lab[2] = hexstr2[tmp]; Loc_Lab[3] = 0; strcpy (Operand, Loc_Lab); LocLab++; break; case OPT: /* assembler option */ P_force = 0; do { if (Pass == 2) { Optr = skip_white (Optr); if (head (Optr, "l")) { Lflag = 1; Optr++; } else if (head (Optr, "nol")) { Lflag = 0; Optr += 3; } else if (head (Optr, "c")) { Cflag = 1; Ctotal = 0; Optr++; } else if (head (Optr, "noc")) { Cflag = 0; Optr += 3; } else if (head (Optr, "contc")) { Cflag = 1; Optr += 5; } else { sprintf (errbuf, "Unknown option %s in OPT pseudo-op; must be L, NOL, C, NOC, CONTC.", Optr); error (errbuf); } } } while (*Optr++ == ','); break; case NULL_OP: /* ignored psuedo ops */ P_force = 0; break; default: fatal ("Pseudo-op error, could not find a pseudo-op to match."); } return 0; // added to keep the BC compiler happy }
int generateIFELSE(unsigned char * program, int pc, treenode * root) { int temppc, calcpc; //Similar to if processing, except a true block and a false block treenode * child = firstchild(root); pc = generateOPERATOR(program, pc, child); program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_JEq; program[pc++] = hibyte(4); program[pc++] = lobyte(4); program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(0); program[pc++] = lobyte(0); program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G2; program[pc++] = hibyte(0); program[pc++] = lobyte(0); program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; program[pc++] = OPCODE_JEq; //Setup to jump the true block temppc = pc; program[pc++] = hibyte(0); program[pc++] = lobyte(0); //Make the true block child = nextchild(root,child); pc = generateBLOCK(program, pc, child); //Size the true block calcpc = pc - temppc + 1; program[temppc++] = hibyte(calcpc); program[temppc++] = lobyte(calcpc); //Setup to jump the false block program[pc++] = OPCODE_JMPRe; temppc = pc; program[pc++] = hibyte(0); program[pc++] = lobyte(0); //Make the false block child = nextchild(root,child); pc = generateBLOCK(program, pc, child); //Size the false block calcpc = pc - temppc-2; program[temppc++] = hibyte(calcpc); program[temppc++] = lobyte(calcpc); return pc; }
Boolean_t util_create_guid(char **guid) { eui_16_t eui; /* * We only have room for 32bits of data in the GUID. The hiword/loword * macros will not work on 64bit variables. The work, but produce * invalid results on Big Endian based machines. */ uint32_t tval = (uint_t)time((time_t *)0); size_t guid_size; int i, fd; if ((mac_len == 0) && (if_find_mac(NULL) == False)) { /* * By default strict GUID generation is enforced. This can * be disabled by using the correct XML tag in the configuration * file. */ if (enforce_strict_guid == True) return (False); /* * There's no MAC address available and we've even tried * a second time to get one. So fallback to using a random * number for the MAC address. */ if ((fd = open("/dev/random", O_RDONLY)) < 0) return (False); if (read(fd, &eui, sizeof (eui)) != sizeof (eui)) return (False); (void) close(fd); eui.e_vers = SUN_EUI_16_VERS; eui.e_company_id[0] = 0; eui.e_company_id[1] = 0; eui.e_company_id[2] = SUN_EN; } else { bzero(&eui, sizeof (eui)); eui.e_vers = SUN_EUI_16_VERS; /* ---- [0] & [1] are zero for Sun's IEEE identifier ---- */ eui.e_company_id[2] = SUN_EN; eui.e_timestamp[0] = hibyte(hiword(tval)); eui.e_timestamp[1] = lobyte(hiword(tval)); eui.e_timestamp[2] = hibyte(loword(tval)); eui.e_timestamp[3] = lobyte(loword(tval)); for (i = 0; i < min(mac_len, sizeof (eui.e_mac)); i++) { eui.e_mac[i] = mac_addr[i]; } /* * To prevent duplicate GUIDs we need to sleep for one * second here since part of the GUID is a time stamp with * a one second resolution. */ sleep(1); } if (tgt_xml_encode((uint8_t *)&eui, sizeof (eui), guid, &guid_size) == False) { return (False); } else return (True); }
int generateOPERATOR(unsigned char * program, int pc, treenode * root) { //Math and boolean operators are handeled here J. Brooks //Get values for left and right values out of the tree J. Brooks // generate code for each child treenode * child = firstchild(root); while (child != NULL) { pc = generate_expression(program, pc, child); child = nextchild(root, child); } // POP_R G2 program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G2; // POP_R G1 program[pc++] = OPCODE_POP_R; program[pc++] = REGISTER_G1; //Process math functions J. Brooks if (root->attribute.op == OT_PLUS) { // ADD_R G1 G2 program[pc++] = OPCODE_ADD_R; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; } if (root->attribute.op == OT_MINUS) { // Sub_R G1 G2 program[pc++] = OPCODE_SUB_R; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; } if (root->attribute.op == OT_TIMES) { // Mul_R G1 G2 program[pc++] = OPCODE_MUL_R; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; } if (root->attribute.op == OT_DIVIDE) { // Divide_R G1 G2 program[pc++] = OPCODE_DIV_R; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; } //Process boolean functions J. Brooks //Flags are set by the compares for the jumps done by the caller (if/ifelse) if (root->attribute.op == OT_EQUALS) { // Compare G1 G2 program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(1); program[pc++] = lobyte(1); } if (root->attribute.op == OT_LESSTHAN) { // Compare G1 G2 program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(1); program[pc++] = lobyte(1); } if (root->attribute.op == OT_GREATERTHAN) { // Compare G1 G2 program[pc++] = OPCODE_CMP_RR; program[pc++] = REGISTER_G1; program[pc++] = REGISTER_G2; program[pc++] = OPCODE_LOAD_R; program[pc++] = REGISTER_G1; program[pc++] = hibyte(1); program[pc++] = lobyte(1); } // PUSH_R G1 program[pc++] = OPCODE_PUSH_R; program[pc++] = REGISTER_G1; return pc; }
(void) close(fd); eui.e_vers = SUN_EUI_16_VERS; eui.e_company_id[0] = (SUN_EN >> 16) & 0xff; eui.e_company_id[1] = (SUN_EN >> 8) & 0xff; eui.e_company_id[2] = SUN_EN & 0xff; } else { bzero(&eui, sizeof (eui)); eui.e_vers = SUN_EUI_16_VERS; eui.e_company_id[0] = (SUN_EN >> 16) & 0xff; eui.e_company_id[1] = (SUN_EN >> 8) & 0xff; eui.e_company_id[2] = SUN_EN & 0xff; eui.e_timestamp[0] = hibyte(hiword(tval)); eui.e_timestamp[1] = lobyte(hiword(tval)); eui.e_timestamp[2] = hibyte(loword(tval)); eui.e_timestamp[3] = lobyte(loword(tval)); for (i = 0; i < min(mac_len, sizeof (eui.e_mac)); i++) { eui.e_mac[i] = mac_addr[i]; } /* * To prevent duplicate GUIDs we need to sleep for one * second here since part of the GUID is a time stamp with * a one second resolution. */ (void) sleep(1); } if (tgt_xml_encode((uint8_t *)&eui, sizeof (eui), guid,
/*------------------------------------------------------------------------ * sysinit -- initialize all Xinu data structeres and devices *------------------------------------------------------------------------ */ LOCAL sysinit() { int i,j,len; struct pentry *pptr; /* null process entry */ struct sentry *sptr; struct mblock *volatile mptr; numproc = 0; /* initialize system variables */ nextproc = NPROC-1; nextsem = NSEM-1; nextqueue = NPROC; /* q[0..NPROC-1] are processes */ memlist.mnext = mptr = /* initialize free memory list */ (struct mblock *volatile) roundmb(__malloc_heap_start); mptr->mnext = (struct mblock *)NULL; mptr->mlen = len = (int) truncmb(RAMEND - NULLSTK - (unsigned)&__bss_end); __malloc_heap_start = (char *)mptr; __malloc_heap_end = __malloc_heap_start + len; kprintf_P(PSTR("Heap: %p of length %d\n"), mptr, len); for (i=0 ; i<NPROC ; i++) /* initialize process table */ proctab[i].pstate = PRFREE; /* initialize null process entry */ pptr = &proctab[NULLPROC]; pptr->pstate = PRCURR; for (j=0; j<6; j++) pptr->pname[j] = "nullp"[j]; pptr->plimit = (unsigned char *)(RAMEND + 1) - NULLSTK; pptr->pbase = (unsigned char *) RAMEND; *pptr->pbase = (unsigned char)MAGIC; /* clobbers return, but proc 0 doesn't return */ pptr->paddr = (int *) main; pptr->pargs = 0; pptr->pprio = 0; pptr->pregs[SSP_L] = lobyte((unsigned int)pptr->plimit); /* for error checking */ pptr->pregs[SSP_H] = hibyte((unsigned int)pptr->plimit); /* for error checking */ currpid = NULLPROC; for (i=0 ; i<NSEM ; i++) { /* initialize semaphores */ (sptr = &semaph[i])->sstate = SFREE; sptr->sqtail = 1 + (sptr->sqhead = newqueue()); } rdytail = 1 + (rdyhead=newqueue()); /* initialize ready list */ #ifdef MEMMARK kprintf("Memory marking\n"); _mkinit(); /* initialize memory marking */ #else kprintf("Pool init\n"); poolinit(); /* explicitly */ pinit(MAXMSGS); #endif #ifdef RTCLOCK kprintf("init RTC\n"); clkinit(); /* initialize r.t.clock */ #endif #ifdef NDEVS for ( i=0 ; i<NDEVS ; i++ ) { if (i>0) kprintf("init dev %d\n", i); init(i); } #endif #ifdef NNETS // kprintf("net init\n"); netinit(); #endif return (OK); }
static long K_ttynum; /* which device is the console */ static int Console; static char z8530Btabl[] = { R(9), 0xC0, /* force hardware reset */ R(4), 0x44, /* x16 clock, 1 stop, no parity */ R(3), 0xC0, /* RCV: 8 bits/char */ R(5), 0x60, /* XMT: 8 bits/char */ R(1), 0x53, /* no WAIT/DMA REQ, R-IRQ, T-IRQ */ R(10), 0x00, /* NRZ mode */ R(11), 0x50, /* RXC+TXC = BRG output */ R(12), lobyte(OSPEED), R(13), hibyte(OSPEED), R(15), 0x00, /* external interrupts disabled */ R(14), 0x07, /* BRG = PCLK */ R(2), 0x40, /* interrupt vector (couldn't get it to work) */ R(5), 0x6A, /* XMT: 8 bits/char, TXD enabled, DTR=L */ R(3), 0xC1, /* RCV: 8 bits/char, RXD enabled */ R(9), 0x00, /* interrupts disabled */ 0, 0 }; static char z8530Atabl[] = { R(4), 0x44, /* x16 clock, 1 stop, no parity */ R(3), 0xC0, /* RCV: 8 bits/char */ R(5), 0x60, /* XMT: 8 bits/char */
SYSCALL create(int (*procaddr)(), int ssize, int priority, char *name, int nargs, ...) { STATWORD ps; int pid; /* stores new process id */ struct pentry *pptr; /* pointer to proc. table entry */ int i; unsigned char *saddr; /* stack address */ int INITRET(); va_list ap; disable(ps); ssize = (int) roundmb(ssize); if ( (saddr = (unsigned char *)getstk(ssize)) == (unsigned char *)SYSERR ) { restore(ps); return (SYSERR); } if ( ssize < MINSTK || (pid=newpid()) == SYSERR || priority < 1 ) { freestk((unsigned)saddr, (unsigned)ssize); restore(ps); return(SYSERR); } numproc++; pptr = &proctab[pid]; /* stderr set to &kprint_out (see kprintf.c and initialize.c) */ pptr->fildes[0] = fdopen(CONSOLE, "r"); /* stdin set to console */ pptr->fildes[1] = fdopen(CONSOLE, "w"); /* stdout set to console */ pptr->fildes[2] = &kprint_out; /* stderr set to &kprint_out */ for (i=2; i < _NFILE; i++) /* others set to unused */ pptr->fildes[i] = (FILE *)FDFREE; pptr->pstate = PRSUSP; for (i=0 ; i<PNMLEN && (int)(pptr->pname[i]=name[i])!=0 ; i++) ; pptr->pprio = priority; pptr->pbase = saddr; pptr->pstklen = ssize; pptr->psem = 0; pptr->phasmsg = FALSE; pptr->plimit = pptr->pbase - ssize + sizeof (WORD); *saddr-- = (char)MAGIC; /* Bottom of stack */ pptr->pargs = nargs; for (i=0 ; i<PNREGS ; i++) pptr->pregs[i] = INITREG; pptr->paddr = (int *)procaddr; pptr->pregs[SPC_L] = lobyte((unsigned) procaddr); pptr->pregs[SPC_H] = hibyte((unsigned) procaddr); pptr->pregs[SSREG] = INITPS; pptr->pnxtkin = BADPID; pptr->pdevs[0] = pptr->pdevs[1] = BADDEV; va_start(ap,nargs); for (i=0 ; i < nargs; i++) { pptr->parg[i] = va_arg(ap, unsigned int); } va_end(ap); pptr->parg[nargs] = 0; /* machine/compiler dependent pass arguments to created process */ pptr->pregs[24] = lobyte((unsigned)pptr->pargs); /*r24*/ pptr->pregs[25] = hibyte((unsigned)pptr->pargs); pptr->pregs[22] = lobyte((unsigned)&pptr->parg[0]); /*r22*/ pptr->pregs[23] = hibyte((unsigned)&pptr->parg[0]); *saddr-- = lobyte((unsigned)INITRET); /* push on initial return address*/ *saddr-- = hibyte((unsigned)INITRET); // *saddr-- = 0; /* 256Kb memory device */ /*TODO make conditional*/ *saddr-- = lobyte((unsigned)procaddr); /* push on procedure address */ *saddr-- = hibyte((unsigned)procaddr); // *saddr-- = 0; /* 256Kb memory device */ /*TODO make conditional*/ pptr->pregs[SSP_L] = lobyte((unsigned) saddr); pptr->pregs[SSP_H] = hibyte((unsigned) saddr); restore(ps); return(pid); }
PAS_State->audiofilt = data; // Select the Sample Buffer Count data = SelectSampleBufferCount; PAS_Write( LocalTimerControl, data ); PAS_State->tmrctlr = data; count = PAS_TransferLength; // Check if we're using a 16-bit DMA channel if ( PAS_DMAChannel > 3 ) { count >>= 1; } LoByte = lobyte( count ); HiByte = hibyte( count ); // Program the Sample Buffer Count PAS_Write( SampleBufferCount, LoByte ); PAS_Write( SampleBufferCount, HiByte ); PAS_State->samplecnt = count; RestoreInterrupts( flags ); } /*--------------------------------------------------------------------- Function: PAS_SetPlaybackRate Sets the rate at which the digitized sound will be played in