void bagelsinit(){ int sendrc; static unsigned char hdr1[]="HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" "<html><body><span style=\"color:#0000A0\">\r\n" "<center><h1>Olduino 1802 BAGELS Server</h1></center>"; static unsigned char Inst1[]= "I AM THINKING OF A 3 DIGIT NUMBER.<BR>TRY TO GUESS " //50 "MY NUMBER AND I WILL GIVE YOU CLUES AS FOLLOWS:<BR>" "...PICO - ONE DIGIT IS IN THE WRONG PLACE<BR>" "...FERMI - ONE DIGIT IS IN THE CORRECT PLACE<BR>" "...BAGELS - NO DIGIT IS CORRECT<P>"; static unsigned char gform[]="<p><form method=\"GET\">\r\n" "<input type=\"text\" name=\"G\">" "<input type=\"submit\" value=\"Enter Your Guess\">\r\n" "</form>"; static unsigned char trlr[]="</body></html>\r\n\r\n"; int x=sizeof(trlr); sendconst(hdr1); // Now Send the HTTP Response first part printf("I.\n"); //sendconst(Inst1); // Now Send the instructions send0(Inst1,sizeof(Inst1)-1); // Now Send the instructions printf(".I\n"); sendconst(gform); // Now Send the rest of the page sendlit("<a href=\"http://goo.gl/p4C0Cg\">Olduino</a>: An Arduino for the First of Us<p>"); sendconst(trlr); // Now Send the rest of the page thisip.l=getip(); thisipslot=getipslot(thisip);//finds or assigns a slot for the ip setsecret(); strcpy((char*)secrets[thisipslot],(char*)secret); printf("IP: %d.%d.%d.%d,slot %d,secret %s\n",thisip.c[0],thisip.c[1],thisip.c[2],thisip.c[3],thisipslot,secrets[thisipslot]); }
void simple_irb(static_context_t *this_context, object_t *self) { printf("Simple Irb (aka lots-of-temporary-files-creator)\n"); char buf[1024]; /* please don't crash me... */ printf(">> "); fflush(stdout); // context_t *context = context_new(0); context_new_stack(0); static_context_t ctx; this_context->context = context; ctx.file = (char *)__FILE__; ctx.method = (char *)__FUNCTION__; ctx.line = __LINE__; ctx.parent = this_context; ctx.block = 0; while (fgets(buf, 1023, stdin)) { object_t *argv[] = { string_new_cstr(buf) }; jump_begin(JUMP_RESCUE) object_t *result = kernel_eval(&ctx, self, 1, argv); printf("=> "); p(result); jump_rescue object_t *cls = send0(exc, s_class); printf("%s: %s\n", ((symbol_t *)((class_t *)cls)->name)->string, ((string_t *)((exception_t *)exc)->message)->bytes); array_t *array = (array_t *)((exception_t *)exc)->backtrace; int i; for (i = 0; i < array->used; i++) printf("\tfrom %s\n", ((string_t *)array->values[i])->bytes); jump_ensure jump_end printf(">> "); fflush(stdout); } }
// another proper message. Triggers a local operation, // triggers sending of dval, and triggers a trigger out. static void proc( const Conn* c ) { void* data = c->data(); LookupTestClass* tc = static_cast< LookupTestClass* >( data ); tc->dval = 0.0; map< string, double >::iterator i; for ( i = tc->dmap.begin(); i != tc->dmap.end(); i++ ) tc->dval += i->second; // This sends the double value out to a target send1< double >( c->target(), sumSlot, tc->dval ); // This just sends a trigger to the remote object. send0( c->target(), procSlot ); }
void sendByte(char data) { char temp; for(int i=0;i<8;i++) { temp = data & 0x01; if(temp & (1<<0)) { send1(); } else { send0(); } data >>= 1; } return; }
int main(int argc, char *argv[]) { init(); init2(); static_context_t ctx; ctx.file = (char *)__FILE__; ctx.method = (char *)__FUNCTION__; ctx.line = __LINE__; ctx.parent = 0; ctx.block = 0; static_context_t *this_context = &ctx; /* awesome hardcoding work here */ load_path = array_new(); array_push(this_context, load_path, string_new_cstr(".")); array_push(this_context, load_path, string_new_cstr("./mspec/lib")); jump_begin(JUMP_RESCUE) send3(Kernel, s_define_method, intern("load"), kernel_load, 1); send3(Kernel, s_define_method, intern("require"), kernel_require, 1); send3(Kernel, s_define_method, intern("eval"), kernel_eval, -1); Init_hash(this_context); Init_regexp(this_context); init_core(&ctx, g_main); if (argc > 1) { set_argv(this_context, argc - 2, argv + 2); kernel_load(this_context, g_main, string_new_cstr(argv[1])); } else { set_argv(this_context, 0, 0); simple_irb(this_context, g_main); } jump_rescue object_t *cls = send0(exc, s_class); printf("%s: %s\n", ((symbol_t *)((class_t *)cls)->name)->string, ((string_t *)((exception_t *)exc)->message)->bytes); array_t *array = (array_t *)((exception_t *)exc)->backtrace; int i; for (i = 0; i < array->used; i++) printf("\tfrom %s\n", ((string_t *)array->values[i])->bytes); jump_ensure jump_end exit(0); return 0; }
void bagelsinit(){ int sendrc; unsigned int secretnum; char strtemp[8]; static unsigned char hdr1[]="HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" "<html><body><span style=\"color:#0000A0\">\r\n" "<center><h1>Olduino 1802 BAGELS Server</h1></center>"; static unsigned char Inst1[]= "I AM THINKING OF A 3 DIGIT NUMBER.<BR>TRY TO GUESS " //50 "MY NUMBER AND I WILL GIVE YOU CLUES AS FOLLOWS:<BR>" "...PICO - ONE DIGIT IS IN THE WRONG PLACE<BR>" "...FERMI - ONE DIGIT IS IN THE CORRECT PLACE<BR>" "...BAGELS - NO DIGIT IS CORRECT<P>"; static unsigned char gform[]="<p><form method=\"GET\">\r\n" "<input type=\"text\" name=\"G\">" "<input type=\"submit\" value=\"Enter Your Guess\">\r\n" "</form>"; static unsigned char postform[]="<p><form method=\"POST\">\r\n" //"<p>\r\n" "<input type=\"submit\" value=\"Secret Test\">\r\n" "<input type=\"text\" name=\"S\" value=\"xyz\">" "</form>"; static unsigned char trlr[]="</body></html>\r\n\r\n"; int x=sizeof(trlr); sendconst(hdr1); // Now Send the HTTP Response first part printf("I.\n"); //sendconst(Inst1); // Now Send the instructions send0(Inst1,sizeof(Inst1)-1); // Now Send the instructions printf(".I\n"); sendconst(gform); // Now Send the rest of the page sendconst(postform); // Now Send the rest of the page sendlit("<a href=\"http://goo.gl/p4C0Cg\">Olduino</a>: An Arduino for the First of Us<p>"); sendconst(trlr); // Now Send the rest of the page // send0(trlr,sizeof(trlr)-1); // Now Send the rest of the page setsecret(); printf("%s\n",secret); }
void lookupFinfoTest() { cout << "\nTesting lookupFinfo set and get"; const Ftype* f1a = LookupFtype< double, string >::global(); const Ftype* f1d = ValueFtype1< double >::global(); const Ftype* f0 = Ftype0::global(); static Finfo* requestValShared[] = { new SrcFinfo( "procout", f0 ), new DestFinfo( "dsum", f1d, RFCAST( &LookupTestClass::dsum ) ), }; static Finfo* testFinfos[] = { new LookupFinfo( "dmap", f1a, reinterpret_cast< GetFunc >( &LookupTestClass::getDmap ), reinterpret_cast< RecvFunc >( &LookupTestClass::setDmap ) ), new ValueFinfo( "dval", f1d, LookupTestClass::getDval, reinterpret_cast< RecvFunc >( &LookupTestClass::setDval ) ), new SharedFinfo( "requestVal", requestValShared, sizeof( requestValShared ) / sizeof( Finfo* ) ), new SrcFinfo( "dsumout", f1d ), new SrcFinfo( "procout", f0 ), new DestFinfo( "dsum", f1d, RFCAST( &LookupTestClass::dsum ) ), new DestFinfo( "proc", f0, &LookupTestClass::proc ), }; Cinfo lookuptestclass( "lookuptestclass", "Upi", "Lookup Test class", initNeutralCinfo(), testFinfos, sizeof( testFinfos ) / sizeof( Finfo*), ValueFtype1< LookupTestClass >::global() ); FuncVec::sortFuncVec(); sumSlot = lookuptestclass.getSlot( "dsumout" ); procSlot = lookuptestclass.getSlot( "procout" ); requestSlot = lookuptestclass.getSlot( "requestVal.procout" ); Element* a1 = lookuptestclass.create( Id::scratchId(), "a1" ); double dret = 0; get< double >( a1, "dval", dret ); ASSERT( dret == 2.2202, "test get1"); set< double >( a1, "dval", 555.5 ); dret = 0; get< double >( a1, "dval", dret ); ASSERT( dret == 555.5, "test set1"); vector< Finfo* > flist; unsigned int ndyn = a1->listLocalFinfos( flist ); ASSERT( ndyn == 0, "Counting DynFinfos" ); // Here we have the crucial functions for the LookupFinfo: // the ability to lookup the data using the lookupGet/Set functions // where the index is provided in the function itself, rather // than in the name of the field. lookupGet< double, string >( a1, "dmap", dret, "0" ); ASSERT( dret == 0.1, "test lookupGet0"); lookupSet< double, string >( a1, "dmap", 1111.1, "0" ); dret = 0; lookupGet< double, string >( a1, "dmap", dret, "0" ); ASSERT( dret == 1111.1, "test lookupSet0"); // Note that the match function will treat the indices as // strings. // First we confirm that the zeroth entry is the same as touched // by the lookupSet previously. get< double >( a1, "dmap[0]", dret ); ASSERT( dret == 1111.1, "test get0"); set< double >( a1, "dmap[0]", 1.1 ); dret = 0; get< double >( a1, "dmap[0]", dret ); ASSERT( dret == 1.1, "test set0"); // Check that there is only one DynamicFinfo set up when looking at // the same lookup index. ASSERT( a1->listLocalFinfos( flist ) == 1, "Counting DynFinfos" ); get< double >( a1, a1->findFinfo( "dmap[1]" ), dret ); ASSERT( dret == 0.2, "test get1"); set< double >( a1, a1->findFinfo( "dmap[1]" ), 2.2 ); dret = 0; get< double >( a1, a1->findFinfo( "dmap[1]" ), dret ); ASSERT( dret == 2.2, "test set1"); // Check that there is only one DynamicFinfo set up when looking at // the same lookup index. ASSERT( a1->listLocalFinfos( flist ) == 1, "Counting DynFinfos" ); get< double >( a1, a1->findFinfo( "dmap[3]" ), dret ); ASSERT( dret == 0.4, "test get3"); set< double >( a1, a1->findFinfo( "dmap[3]" ), 3.3 ); dret = 1234.567; get< double >( a1, a1->findFinfo( "dmap[3]" ), dret ); ASSERT( dret == 3.3, "test set3"); // Check that the system reuses the DynamicFinfo. ASSERT( a1->listLocalFinfos( flist ) == 1, "Counting DynFinfos" ); //////////////////////////////////////////////////////////////// // Check string set and get. //////////////////////////////////////////////////////////////// string sret = ""; bool bret = 0; bret = a1->findFinfo( "dmap[3]" )->strSet( a1, "-2.3" ); ASSERT( bret, "strSet" ); get< double >( a1, a1->findFinfo( "dmap[3]" ), dret ); ASSERT( dret == -2.3, "test strSet"); bret = a1->findFinfo( "dmap[3]" )->strGet( a1, sret ); ASSERT( bret, "strSet" ); ASSERT( sret == "-2.3", "test strSet"); bret = a1->findFinfo( "dmap[2]" )->strSet( a1, "-0.03" ); ASSERT( bret, "strSet" ); bret = get< double >( a1, a1->findFinfo( "dmap[2]" ), dret ); ASSERT( bret, "strGet" ); ASSERT( dret == -0.03, "test strGet"); //////////////////////////////////////////////////////////////// // Now we start testing messages between LookupFinfo fields. //////////////////////////////////////////////////////////////// cout << "\nTesting lookupFinfo messaging"; Element* a2 = lookuptestclass.create( Id::scratchId(), "a2" ); // We will follow a1 messages to call proc on a2. Check a2->dval. // // proc on a2 will send this value of dval to a1->dmap[0]. Check it. // // a1 trigger message will call send on a2->dmap[1]. This goes // to a1->dval. Check it. // // a1 trigger message will call send on a2->dmap[2]. This goes // to a1->dmap[2]. The trigger is created first. Check it. // // a1 trigger message will call send on a2->dmap[3]. This goes // to a1->dmap[3]. The send is created first. Check it. // 1. We will follow a1 messages to call proc on a2. Check a2->dval. const Finfo *f1 = a1->findFinfo( "procout" ); const Finfo *f2 = a2->findFinfo( "proc" ); bret = f1->add( a1, a2, f2, ConnTainer::Default ); ASSERT( bret, "adding procout to proc"); // 2. proc on a2 will send this value of dval to a1->dmap[0]. f1 = a2->findFinfo( "dsumout" ); f2 = a1->findFinfo( "dmap[0]" ); bret = f1->add( a2, a1, f2, ConnTainer::Default ); ASSERT( bret, "Adding dsumout to dval"); // We have already made a finfo for a1->dmap[0]. Check that this // is the one that is used for the messaging. ASSERT( a1->listLocalFinfos( flist ) == 1, "Counting DynFinfos" ); // 3. a1 trigger message will call request on a2->dmap[1]. The // value comes back to a1, and is added to dval. f1 = a1->findFinfo( "requestVal" ); f2 = a2->findFinfo( "dmap[1]" ); bret = f1->add( a1, a2, f2, ConnTainer::Default ); ASSERT( bret, "Adding requestVal to dmap[1]"); // Here we made a new DynamicFinfo for the regular ValueFinfo. ASSERT( a2->listLocalFinfos( flist ) == 1, "Counting DynFinfos" ); // 4. a2 trigger message will call request on a1->dmap[2]. This // is set up using reverse Shared messaging calls. The // value comes back to a2 and is added to dval. f1 = a1->findFinfo( "dmap[2]" ); f2 = a2->findFinfo( "requestVal" ); bret = f1->add( a1, a2, f2, ConnTainer::Default ); ASSERT( bret, "Adding a1.dmap[2] to a2.requestVal"); // We have not made a finfo for a1->dmap[2]. Check that this // new one is used for the messaging. ASSERT( a1->listLocalFinfos( flist ) == 2, "Counting DynFinfos" ); /////////////////////////////////////////////////////////////////// // Now setup is done, let's start sending info around. /////////////////////////////////////////////////////////////////// bret = set< double >( a1, "dval", 4321.0 ); bret &= set< double >( a2, "dval", 1234.0 ); bret &= set< double >( a1, "dmap[0]", 10.0 ); bret &= set< double >( a1, "dmap[1]", 20.0 ); bret &= set< double >( a1, "dmap[2]", 30.0 ); bret &= set< double >( a1, "dmap[3]", 40.0 ); bret &= set< double >( a2, "dmap[0]", 1.0 ); bret &= set< double >( a2, "dmap[1]", 2.0 ); bret &= set< double >( a2, "dmap[2]", 3.0 ); bret &= set< double >( a2, "dmap[3]", 4.0 ); ASSERT( bret, "assignment"); bret = get< double >( a1, a1->findFinfo( "dmap[2]" ), dret ); ASSERT( bret, "test assignment"); ASSERT( dret == 30.0, "test assignment"); send0( a1, procSlot ); // procout // Here a2->dval should simply become the sum of its lookup entries. // As this has just been initialized, the sum should be 10.0. // Bad Upi: should never test for equality of doubles. get< double >( a2, a2->findFinfo( "dval" ), dret ); ASSERT( dret == 10.0, "test msg1"); // proc on a2 will send this value of dval to a1->dmap[0]. Check it. dret = 0.0; get< double >( a1, a1->findFinfo( "dmap[0]" ), dret ); ASSERT( dret == 10.0, "test msg2"); ////////////////////////////////////////////////////////////////////// // a1 trigger message will call send on a2->dmap[1], which currently // holds the value 2. The value is added to a1->dval, which is 4321 send0( a1, requestSlot ); // procout dret = 0.0; get< double >( a1, a1->findFinfo( "dval" ), dret ); ASSERT( dret == 4323.0, "test msg3"); // 4. a2 trigger message will call request on a1->dmap[2]. This // is set up using reverse Shared messaging calls. The // value ( 30 ) comes back to a2 and is added to dval (10). bret = get< double >( a2, a2->findFinfo( "dval" ), dret ); ASSERT( bret, "test msg4"); ASSERT( dret == 10.0, "test msg4"); dret = 0; bret = get< double >( a1, a1->findFinfo( "dmap[2]" ), dret ); ASSERT( bret, "test msg4"); ASSERT( dret == 30.0, "test msg4"); send0( a2, requestSlot ); // procout dret = 0.0; get< double >( a2, a2->findFinfo( "dval" ), dret ); ASSERT( dret == 40, "test msg4"); // Check that there are no strange things happening with the // Finfos when the messaging is actually used. // Note that we set all of a1.dmap[], only 2 of which were already used // Note that we set all of a2.dmap[], only 1 of which was already used // Since the system reuses when it can, the net increment in each is 1. ASSERT( a1->listLocalFinfos( flist ) == 3, "Counting DynFinfos" ); ASSERT( a2->listLocalFinfos( flist ) == 2, "Counting DynFinfos" ); }
int send0s(char* what){ //printf(">>%s\n",what); return send0((unsigned char *)what,strlen(what)); }
void sendack(){ int sendrc; static unsigned char ack[]="HTTP/1.0 200 OK\r\n\r\n"; sendrc=send0(ack,strlen((char *)ack)); // Now Send the HTTP Response }
void start() { ACPI_STATUS status = AE_OK; printf("acpica: starting...\n"); // NB! Must be at least as large as physical memory - the ACPI tables could // be anywhere. (Could be handled by AcpiOsMapMemory though.) map(0, MAP_PHYS | PROT_READ | PROT_WRITE | PROT_NO_CACHE, (void*)ACPI_PHYS_BASE, 0, USER_MAP_MAX - ACPI_PHYS_BASE); __default_section_init(); AcpiDbgLayer = 0; AcpiDbgLevel = ACPI_LV_REPAIR | ACPI_LV_INTERRUPTS; status = InitializeFullAcpi (); CHECK_STATUS("InitializeFullAcpi"); int pic_mode = 0; // Default is PIC mode if something fails status = PrintAPICTable(); CHECK_STATUS("PrintAPICTable"); status = FindIOAPICs(&pic_mode); CHECK_STATUS("Find IOAPIC"); status = ExecuteOSI(pic_mode); CHECK_STATUS("ExecuteOSI"); // Tables we get in Bochs: // * DSDT: All the AML code // * FACS // * FACP // * APIC (= MADT) // * SSDT: Secondary System Description Table // Contains more AML code loaded automatically by ACPICA // More tables on qemu: // * Another SSDT (Loaded by ACPICA) // * HPET table // PrintFACSTable(); // PrintFACPTable(); // TODO Iterate through and disable all pci interrupt link devices (call // _DIS). Then we'll enable the ones we actually intend to use. EnumeratePCI(); AcpiWriteBitRegister(ACPI_BITREG_SCI_ENABLE, 1); //AcpiWriteBitRegister(ACPI_BITREG_POWER_BUTTON_ENABLE, 1); AcpiInstallGlobalEventHandler(GlobalEventHandler, NULL); AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, 0); for (;;) { ipc_dest_t rcpt = 0x100; ipc_arg_t arg = 0; ipc_arg_t arg2 = 0; ipc_msg_t msg = recv2(&rcpt, &arg, &arg2); //printf("acpica: Received %#lx from %#lx: %#lx %#lx\n", msg, rcpt, arg, arg2); if (msg == MSG_PULSE) { if (AcpiOsCheckInterrupt(rcpt, arg)) { continue; } else { printf("acpica: Unhandled pulse: %#x from %#lx\n", arg, rcpt); } } switch (msg & 0xff) { case MSG_ACPI_FIND_PCI: MsgFindPci(rcpt, arg); break; case MSG_ACPI_CLAIM_PCI: MsgClaimPci(rcpt, arg, arg2); break; // This feels a bit wrong, but as long as we use PIO access to PCI // configuration space, we need to serialize all accesses. case MSG_ACPI_READ_PCI: arg = PciReadWord((arg & 0x7ffffffc) | 0x80000000); send1(MSG_ACPI_READ_PCI, rcpt, arg); break; case MSG_ACPI_DEBUGGER_INIT: debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_INIT, rcpt); break; case MSG_ACPI_DEBUGGER_BUFFER: assert(debugger_buffer_pos < ACPI_DB_LINE_BUFFER_SIZE); AcpiGbl_DbLineBuf[debugger_buffer_pos++] = arg; send0(MSG_ACPI_DEBUGGER_BUFFER, rcpt); break; case MSG_ACPI_DEBUGGER_CMD: assert(debugger_buffer_pos < ACPI_DB_LINE_BUFFER_SIZE); AcpiGbl_DbLineBuf[debugger_buffer_pos++] = 0; putchar('\n'); AcpiDbCommandDispatch(AcpiGbl_DbLineBuf, NULL, NULL); debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_CMD, rcpt); break; case MSG_ACPI_DEBUGGER_CLR_BUFFER: debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_CLR_BUFFER, rcpt); break; case MSG_REG_IRQ: RegIRQ(rcpt, arg); continue; case MSG_IRQ_ACK: AckIRQ(rcpt); continue; } // TODO Handle other stuff. if (rcpt == 0x100) { hmod(rcpt, 0, 0); } } __builtin_unreachable(); failed: printf("ACPI failed :( (status %x)\n", status); abort(); }