void BTree::_in(Node* n) { if( n != NULL) { _in(n->left); _in(n->right); printNode(n); } }
void read_sector(unsigned int cylinder, unsigned int sector, unsigned char* buffer){ int secteur_size; int tmp, i; if( !seek_sector(cylinder, sector) ){ buffer = NULL; return; } /* Mettre dans MASTERBUFFER les donnees a cette emplacement */ _out(HDA_DATAREGS, 1); _out(HDA_CMDREG, CMD_READ); _sleep(HDA_IRQ); /* exploiter les donnees de MASTERBUFFER */ _out(HDA_CMDREG, CMD_DSKINFO); tmp = _in(HDA_DATAREGS+4); tmp = tmp<<8; secteur_size = tmp + _in(HDA_DATAREGS+5); for(i=0; i<secteur_size; i++){ buffer[i] = (unsigned char)MASTERBUFFER[i]; } buffer[++i] = EOF; }
void cpuInit() { int i; _loadgdt(); while(_in(0x64) & 2); // wait for input buffer empty _out(0x64, 0xd1); // want write to 8042 p2 port while(_in(0x64) & 2); // wait for input buffer empty _out(0x60, 0xDF); // enable A20 address line _out(0x20, 0x11); // program 8259 _out(0xA0, 0x11); // initialization sequence _out(0x21, 0x20); // start of hardware interrupt is 32 _out(0xA1, 0x28); // start of hardware interrupt is 40 _out(0x21, 0x4); // 8259-1 is master _out(0xA1, 0x2); // 8259-2 is slave _out(0x21, 0x1); // 8086 mode for both _out(0xA1, 0x1); _out(0x21, 0x0); // enable all irq source _out(0xA1, 0x0); _out(0x43, 0x36); // program 8253: binary, mode 3, LSB/MSB, ch 0 _out(0x40, 0x9b); // LSB _out(0x40, 0x2e); // MSB 1193180/100=11931=0x2e9b for(i=0;i<64;i++) // init idts { IDT_DATA[i].zero=0; IDT_DATA[i].selector=8; IDT_DATA[i].attrib=0x8f; IDT_DATA[i].offsethigh = ((uint32)dummyIsr) >> 16; IDT_DATA[i].offsetlow = ((uint32)dummyIsr) & 0xFFFF; } for(i=0;i<24;i++) // set exception gate attrib 0x8f { IDT_DATA[i].attrib=0x8f; IDT_DATA[i].offsethigh = (_ISREXP[i]) >> 16; IDT_DATA[i].offsetlow = (_ISREXP[i]) & 0xFFFF; } for(i=32;i<48;i++) // set interrupt gate attrib 0x8e { IDT_DATA[i].attrib=0x8e; IDT_DATA[i].offsethigh = (_ISRINT[i-32]) >> 16; IDT_DATA[i].offsetlow = (_ISRINT[i-32]) & 0xFFFF; } for(i=0;i<256;i++) _ISRVECT[i]=(uint32)generalprotectintr; // init interrupt table _loadidt(); }
// Set up a memory regions to access GPIO void setup_io() { _out(DDB0, DDRB); // CSN _out(DDB1, DDRB); // SCK _out(DDB2, DDRB); // MOSI _in(DDB3, DDRB); // MISO _out(DDB4, DDRB); // CE } // setup_io
void soundOn(){ char value; _out(43h,B6h); _out(42h,54); _out(42h,124); value = _in(61h); value = value | 3; /*(Turn on bits 1 and 2)*/ _out 61h, value; }
// Set up a memory regions to access GPIO void setup_io() { _out(SPI_CSN, DDRD); // CSN _out(SPI_CE, DDRD); // CE _out(DDB5, DDRB); // SCK _in(DDB4, DDRB); // MISO _out(DDB3, DDRB); // MOSI // SS pin of AVR must be configured as output. // If it is input and it happens to be ever low, the AVR SPI hardware will drop out of master mode into slave mode, // and it will not resume until you put it back into master mode. So basically you cannot use AVR SS pin as input when you want to be the SPI master. _out(DDB2, DDRB); // SS } // setup_io
int main(){ int nbSec,nbCyl,cylinder,secteur,i; if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); _out(HDA_CMDREG,CMD_DSKINFO); nbCyl=_in(HDA_DATAREGS)<<8; nbCyl+=_in(HDA_DATAREGS+1); nbSec=_in(HDA_DATAREGS+2)<<8; nbSec+=_in(HDA_DATAREGS+3); printf("Formatage du disque\n"); for(cylinder=0;cylinder<nbCyl;cylinder++) for(secteur=0;secteur<nbSec;secteur++) format_sector(cylinder,secteur,1,0); return 0; }
static void mmuhandler() { int fault = _in(MMU_FAULT_ADDR); struct tlb_entry_s tlb_entry; assert(fault >= (int)virtual_memory && fault <= (int)virtual_memory + VM_SIZE - 1); tlb_entry.tlbe_cfu = 0; tlb_entry.tlbe_x_access = 1; tlb_entry.tlbe_w_access = 1; tlb_entry.tlbe_r_access = 1; tlb_entry.tlbe_used = 1; if(vm_mapping[vpage_of_vaddr(fault)].mapped) { tlb_entry.tlbe_physical_page = vm_mapping[vpage_of_vaddr(fault)].ppage; tlb_entry.tlbe_virtual_page = vpage_of_vaddr(fault); _out(TLB_ADD_ENTRY, *((int*)&tlb_entry)); return; } if(pm_mapping[victime_rr].mapped) { store_to_swap(pm_mapping[victime_rr].vpage, victime_rr); pm_mapping[victime_rr].mapped = 0; vm_mapping[pm_mapping[victime_rr].vpage].mapped = 0; tlb_entry.tlbe_physical_page = victime_rr; _out(TLB_DEL_ENTRY, *((int*)&tlb_entry)); } fetch_from_swap(vpage_of_vaddr(fault), victime_rr); pm_mapping[victime_rr].mapped = 1; pm_mapping[victime_rr].vpage = vpage_of_vaddr(fault); vm_mapping[vpage_of_vaddr(fault)].mapped = 1; vm_mapping[vpage_of_vaddr(fault)].ppage = victime_rr; tlb_entry.tlbe_physical_page = victime_rr; tlb_entry.tlbe_virtual_page = vpage_of_vaddr(fault); _out(TLB_ADD_ENTRY, *((int*)&tlb_entry)); victime_rr = (victime_rr % 255) + 1; return; }
void init() { uint ncyl = 0, nsec = 0, sector_size = 0, status=0; uint i; char* hw_config; hw_config = getenv("HW_CONFIG"); hw_config = hw_config ? hw_config : DEFAULT_HW_CONFIG; /* Met le microprocesseur en mode maitre */ puts("Initialisation du matériel ..."); status = init_hardware(hw_config); if (!status) {printf("error in hardware initialization with %s\n", hw_config);} /*init_hardware("etc/hardware.ini");*/ /* Prépare les interruptions */ puts("Préparation des interruptions..."); for(i = 0; i < IRQ_VECTOR_SIZE; i++) { IRQVECTOR[i] = empty_it; } /* Vérifie la géométrie du disque */ puts("Vérification du disque ..."); /* Retourne la géométrie du disque dans HDA_DATAREGS */ _out(HDA_CMDREG, CMD_DSKINFO); /* Lit la géométrie du disque octet par octet */ ncyl = (_in(HDA_DATAREGS + 0) << 8) + _in(HDA_DATAREGS + 1); nsec = (_in(HDA_DATAREGS + 2) << 8) + _in(HDA_DATAREGS + 3); sector_size = (_in(HDA_DATAREGS + 4) << 8) + _in(HDA_DATAREGS + 5); if (HDA_MAXCYLINDER != ncyl) { puts("Nombre de cylindres invalide à l'initialisation"); exit(INVALID_GEOMETRY); } if (HDA_MAXSECTOR != nsec) { puts("Nombre de secteurs invalide à l'initialisation"); exit(INVALID_GEOMETRY); } if (HDA_SECTORSIZE != sector_size) { puts("Taille des secteurs invalide à l'initialisation"); exit(INVALID_GEOMETRY); } puts("Initialisation terminée\n"); }
/******************************************************************************** Functions ********************************************************************************/ void initGPIO() { _in(DDD2, DDRD); // INT0 input // GPIO Interrupt INT0 // The falling edge of INT0 generates an interrupt request. EICRA = (0<<ISC11)|(0<<ISC10)|(1<<ISC01)|(0<<ISC00); // Enable INT0 EIMSK = (1<<INT0); _out(DDD3, DDRD); // OC2B _out(DDD5, DDRD); // OC0B _out(DDD6, DDRD); // OC0A _on(PD3, PORTD); // OC2B _on(PD5, PORTD); // OC0B _on(PD6, PORTD); // OC0A }
/* Handler de INT 80h */ void int_80(int systemCall, int fd, char *buffer, int count) { int i, j; if (systemCall == WRITE) //write { if (fd == STDOUT) //PANTALL { setBytes(vidmem + videoPos, buffer, count); } else if (fd == PIC1) _out(0x20, buffer[0]); } else if (systemCall == READ) //read { if (fd == KEYBOARD) buffer[0] = _in(0x60); } }
void mmu_handler() { union tlb_entry_u union_entry; unsigned int vaddr = _in(MMU_FAULT_ADDR); int ppage = ppage_of_vaddr(current_process, vaddr); if(ppage < 0) exit(-1); union_entry.entry.ppage = ppage; union_entry.entry.vpage = vpage_of_vaddr(vaddr); union_entry.entry.access_x = 1; union_entry.entry.access_r = 1; union_entry.entry.access_w = 1; union_entry.entry.used = 1; _out(TLB_ADD_ENTRY, union_entry.asInt); }
void yield() { ctx_t *current; if (ctx == NULL) return; irq_disable(); //CORE LOCK current = find_next_iddle(); if (current == NULL) { //CORE UNLOCK irq_enable(); return; } switch_to_ctx(current, _in(CORE_ID)); clean_ctx(current); //CORE UNLOCK irq_enable(); }
/******************************************************************************** Main ********************************************************************************/ int main(void) { // initialize code usart_init(); // initialize input port for ir receiver _in(DDE4, DDRE); _on(PE4, PORTE); // initialize input port interrupt _on(ISC40, EICRB); _off(ISC41, EICRB); _on(INT4, EIMSK); // initialize 16 bit timer 1 TCCR1B = (0<<CS12)|(1<<CS11)|(1<<CS10); _on(TOIE1, TIMSK); // enable interrupts sei(); printf("INIT AFTER RESET"); // main loop while (true) { if (send_data_flag && ir_data_count > 0) { printf("START PACKET"); for (uint16_t i = 0; i < ir_data_count; i++) { usart_putchar(ir_data[i]); } printf("END PACKET"); ir_data_count = 0; send_data_flag = 0; } } }
// Change current context to new_ctx on core "core" void switch_to_ctx(ctx_t *new_ctx, int core) { // Sauvegarde du contexte d'execution courant asm ("movl %%esp, %0" :"=r"(ctx_main[core].esp) :); asm ("movl %%ebp, %0" :"=r"(ctx_main[core].ebp) :); ctx_current[core] = new_ctx; //Installation du nouveau contexte asm ("movl %0, %%esp" : :"r"(new_ctx->esp)); asm ("movl %0, %%ebp" : :"r"(new_ctx->ebp)); //CORE UNLOCK irq_enable(); // Si premier lancement on appelle f() if (ctx_current[_in(CORE_ID)]->state == CTX_START) { ctx_current[_in(CORE_ID)]->state = CTX_RUN; ctx_current[_in(CORE_ID)]->f(ctx_current[_in(CORE_ID)]->args); } else // Sinon on se contente de noter le contexte comme étant en cours d'éxécution { ctx_current[_in(CORE_ID)]->state = CTX_RUN; return; } irq_disable(); // Si le contexte a terminé son éxécution on restaure le contexte d'origine //CORE LOCK asm ("movl %0, %%esp" : :"r"(ctx_main[_in(CORE_ID)].esp)); asm ("movl %0, %%ebp" : :"r"(ctx_main[_in(CORE_ID)].ebp)); return; }
// 加密按钮 void CAesFileEncryptDlg::OnBnClickedFileEncrypt() { CString m_fileName, m_savePath, m_key; m_editBrowse1.GetWindowTextW(m_fileName); m_editBrowse2.GetWindowTextW(m_savePath); m_editCtrl.GetWindowTextW(m_key); if (m_fileName == "") MessageBox(_T("请选择待加密的文件!"), _T("提示"), MB_ICONINFORMATION); else if (m_savePath == "") MessageBox(_T("请选择加密文件的保存路径!"), _T("提示"), MB_ICONINFORMATION); else if (m_key == "") MessageBox(_T("请输入密钥!"), _T("提示"), MB_ICONINFORMATION); else // 加密 { if(m_key.GetLength() != 16) { MessageBox(_T("密钥需要16位!"), _T("提示"), MB_ICONINFORMATION); return; } CT2CA pszCAS_filename(m_fileName); string fileName(pszCAS_filename); ifstream _in(fileName.c_str(), ios::binary); if(!_in) // 如果不存在 MessageBox(_T("待加密的文件不存在!"), _T("提示"), MB_ICONINFORMATION); else { SetTimer(TIMER_ID, 1000, NULL); // 开始计时 GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); // 开辟子线程进行文件加密 arr[0] = m_fileName; arr[1] = m_savePath; arr[2] = m_key; hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadEncryptFunc, (void*)arr, 0, &threadID); } _in.close(); } }
// Keyboard handler void int_09() { krn++; char scancode; scancode = _in(0x60); // We check if the scancode is a char or a control key. int flag = scancode >= 0x02 && scancode <= 0x0d; flag = flag || (scancode >= 0x10 && scancode <= 0x1b); flag = flag || (scancode >= 0x1E && scancode <= 0x29); flag = flag || (scancode >= 0x2b && scancode <= 0x35); if (flag) { char sc = scanCodeToChar(scancode); if(sc != 0 && sc != EOF) { pushC(sc); //guarda un char en el stack } } else { controlKey(scancode); // Envia el scancode al analizador de control keys. } kernel_buffer[0] = KILL; krn--; }
static void check_hda() { int sectorSize, sectorMax, cylinderMax; _out(HDA_CMDREG, CMD_DSKINFO); sectorSize = _in(HDA_DATAREGS + 4); sectorSize = sectorSize << 8; sectorSize |= _in(HDA_DATAREGS + 5); assert(sectorSize == HDA_SECTORSIZE); sectorMax = _in(HDA_DATAREGS + 2); sectorMax = sectorMax << 8; sectorMax |= _in(HDA_DATAREGS + 3); assert(sectorMax == HDA_MAXSECTOR); cylinderMax = _in(HDA_DATAREGS); cylinderMax = cylinderMax << 8; cylinderMax |= _in(HDA_DATAREGS + 1); assert(cylinderMax == HDA_MAXCYLINDER); }
void vpins_in(char port) {Serial.print("OK!");_in(port);}
void BTree::inOrder() { _in(root); }
// Tells if the kernel is ready to the keyboard int kernel_ready() { _in(0x60); // Needed for not blcoking the keyboard on idleness return ready; }
void JSONTokenizer::executeAction(int production) try { if (d_token__ != _UNDETERMINED_) pushToken__(d_token__); // save an already available token // save default non-nested block $$ if (int size = s_productionInfo[production].d_size) d_val__ = d_vsp__[1 - size]; switch (production) { // $insert actioncases case 1: { d_scanner.result(muzzley::JSObject); } break; case 2: { d_scanner.result(muzzley::JSArray); } break; case 3: { d_scanner.finish(muzzley::JSObject); } break; case 4: d_val__ = d_vsp__[0]; { d_scanner.init(muzzley::JSObject); } break; case 5: { d_scanner.finish(muzzley::JSArray); } break; case 6: d_val__ = d_vsp__[0]; { d_scanner.init(muzzley::JSArray); } break; case 8: { } break; case 9: { d_scanner.add(); } break; case 10: d_val__ = d_vsp__[0]; { d_scanner.init(muzzley::JSObject, d_scanner.matched()); } break; case 11: { d_scanner.add(); } break; case 12: d_val__ = d_vsp__[-2]; { d_scanner.init(muzzley::JSObject, d_scanner.matched()); } break; case 14: { } break; case 15: { d_scanner.add(); } break; case 16: { d_scanner.add(); } break; case 17: { } break; case 18: { } break; case 19: { string _out(d_scanner.matched()); d_scanner.init(_out); } break; case 20: { bool _out; string _in(d_scanner.matched()); muzzley::fromstr(_in, &_out); d_scanner.init(_out); } break; case 21: { long long _out; string _in(d_scanner.matched()); muzzley::fromstr(_in, &_out); d_scanner.init(_out); } break; case 22: { double _out; string _in(d_scanner.matched()); muzzley::fromstr(_in, &_out); d_scanner.init(_out); } break; case 23: { d_scanner.init(); } break; } } catch (std::exception const &exc) { exceptionHandler__(exc); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); const char key[] = { 0x00, 0x09, 0x70, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x3f }; const char in[] = { 0x00, 0x11, 0x11, 0x11, 0x13, 0x12, 0x12, 0x12, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0xdb, 0xdc, 0xdd, 0xde, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x12, 0x12, 0x12, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x12, 0x12, 0x12, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, }; const char iv[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x23, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xfc }; QByteArray _key(key, 32); QByteArray _in(in, 28); QByteArray _iv(iv, 16); AES aes(_key, _iv); RC4 rc4(_key, _iv); Salsa20 salsa20(_key, _iv); qDebug() << "\nAES encryptor - CFB \n"; QByteArray encode_in = aes.update_CFB(_in, true); qDebug() << "AES encode " << encode_in << " :size: " << encode_in.size(); QByteArray decode_in = aes.update_CFB(encode_in, false); qDebug() << "RC4 decode " << decode_in << " :size: " << decode_in.size(); qDebug() << "\nRC4 encryptor \n"; QByteArray _encode_in = rc4.update(_in); qDebug() << "RC4 encode " << _encode_in << " :size: " << _encode_in.size(); QByteArray _decode_in = rc4.update(_encode_in); qDebug() << "RC4 decode " << _decode_in << " :size: " << _decode_in.size(); qDebug() << "\nSalsa20 encryptor \n"; QByteArray __encode_in = salsa20.update(_in); qDebug() << "RC4 encode " << __encode_in << " :size: " << __encode_in.size(); QByteArray __decode_in = salsa20.update(__encode_in); qDebug() << "RC4 decode " << __decode_in << " :size: " << __decode_in.size(); return a.exec(); }
bool parse_dimacs(std::istream & in, std::ostream& err, sat::solver & solver) { stream_buffer _in(in); return parse_dimacs_core(_in, err, solver); }