/* * Boot a specified local disk. AX specifies the BIOS disk number; or * -1 in case we should execute INT 18h ("next device.") */ __export void local_boot(int16_t ax) { com32sys_t ireg, oreg; int i; memset(&ireg, 0, sizeof(ireg)); syslinux_force_text_mode(); writestr(LOCALBOOT_MSG); crlf(); cleanup_hardware(); if (ax == -1) { /* Hope this does the right thing */ __intcall(0x18, &zero_regs, NULL); /* If we returned, oh boy... */ kaboom(); } /* * Load boot sector from the specified BIOS device and jump to * it. */ memset(&ireg, 0, sizeof ireg); ireg.edx.b[0] = ax & 0xff; ireg.eax.w[0] = 0; /* Reset drive */ __intcall(0x13, &ireg, NULL); memset(&ireg, 0, sizeof(ireg)); ireg.eax.w[0] = 0x0201; /* Read one sector */ ireg.ecx.w[0] = 0x0001; /* C/H/S = 0/0/1 (first sector) */ ireg.ebx.w[0] = OFFS(trackbuf); ireg.es = SEG(trackbuf); for (i = 0; i < retry_count; i++) { __intcall(0x13, &ireg, &oreg); if (!(oreg.eflags.l & EFLAGS_CF)) break; } if (i == retry_count) kaboom(); cli(); /* Abandon hope, ye who enter here */ memcpy((void *)0x07C00, trackbuf, 512); ireg.esi.w[0] = OFFS(trackbuf); ireg.edi.w[0] = 0x07C00; ireg.edx.w[0] = ax; call16(local_boot16, &ireg, NULL); }
/* * Initialize pxe fs * */ static int pxe_fs_init(struct fs_info *fs) { (void)fs; /* drop the compile warning message */ /* Prepare for handling pxe interrupts */ pxe_init_isr(); /* This block size is actually arbitrary... */ fs->sector_shift = fs->block_shift = TFTP_BLOCKSIZE_LG2; fs->sector_size = fs->block_size = 1 << TFTP_BLOCKSIZE_LG2; /* Find the PXE stack */ if (pxe_init(false)) kaboom(); /* See if we also have a gPXE stack */ gpxe_init(); /* Network-specific initialization */ network_init(); /* Initialize network-card-specific idle handling */ pxe_idle_init(); /* Our name for the root */ strcpy(fs->cwd_name, "::"); return 0; }
/** * Get a fresh packet from a gPXE socket * @param: inode -> Inode pointer * */ static void gpxe_get_packet(struct inode *inode) { struct pxe_pvt_inode *socket = PVT(inode); static __lowmem struct s_PXENV_FILE_READ file_read; int err; while (1) { file_read.FileHandle = socket->tftp_remoteport; file_read.Buffer = FAR_PTR(packet_buf); file_read.BufferSize = PKTBUF_SIZE; err = pxe_call(PXENV_FILE_READ, &file_read); if (!err) /* successed */ break; if (file_read.Status != PXENV_STATUS_TFTP_OPEN) kaboom(); } memcpy(socket->tftp_pktbuf, packet_buf, file_read.BufferSize); socket->tftp_dataptr = socket->tftp_pktbuf; socket->tftp_bytesleft = file_read.BufferSize; socket->tftp_filepos += file_read.BufferSize; if (socket->tftp_bytesleft == 0) inode->size = socket->tftp_filepos; /* if we're done here, close the file */ if (inode->size > socket->tftp_filepos) return; /* Got EOF, close it */ socket->tftp_goteof = 1; gpxe_close_file(inode); }
/* Load the config file, return -1 if failed, or 0 */ static int pxe_open_config(struct com32_filedata *filedata) { const char *cfgprefix = "pxelinux.cfg/"; const char *default_str = "default"; char *config_file; char *last; int tries = 8; chdir(path_prefix); if (DHCPMagic & 0x02) { /* We got a DHCP option, try it first */ if (open_file(ConfigName, O_RDONLY, filedata) >= 0) return 0; } /* * Have to guess config file name ... */ config_file = stpcpy(ConfigName, cfgprefix); /* Try loading by UUID */ if (sysappend_strings[SYSAPPEND_SYSUUID]) { strcpy(config_file, sysappend_strings[SYSAPPEND_SYSUUID]+8); if (open_file(ConfigName, O_RDONLY, filedata) >= 0) return 0; } /* Try loading by MAC address */ strcpy(config_file, sysappend_strings[SYSAPPEND_BOOTIF]+7); if (open_file(ConfigName, O_RDONLY, filedata) >= 0) return 0; /* Nope, try hexadecimal IP prefixes... */ sprintf(config_file, "%08X", ntohl(IPInfo.myip)); last = &config_file[8]; while (tries) { *last = '\0'; /* Zero-terminate string */ if (open_file(ConfigName, O_RDONLY, filedata) >= 0) return 0; last--; /* Drop one character */ tries--; }; /* Final attempt: "default" string */ strcpy(config_file, default_str); if (open_file(ConfigName, O_RDONLY, filedata) >= 0) return 0; ddprintf("%-68s\n", "Unable to locate configuration file"); kaboom(); }
int main() { std::cout << "Hello, world" << std::endl; std::cout << "The answer is: " << get_answer_to_the_question_of_life_universe_and_everything() << std::endl; try { kaboom(); } catch (std::exception &e) { std::cout << "I just saved the world!" << std::endl; std::cout << "Error was: " << e.what() << std::endl; } return 0; }
/* * Get a fresh packet if the buffer is drained, and we haven't hit * EOF yet. The buffer should be filled immediately after draining! */ static void tftp_get_packet(struct inode *inode) { uint16_t last_pkt; const uint8_t *timeout_ptr; uint8_t timeout; uint16_t buffersize; uint16_t serial; jiffies_t oldtime; struct tftp_packet *pkt = NULL; uint16_t buf_len; struct pxe_pvt_inode *socket = PVT(inode); uint16_t src_port; uint32_t src_ip; int err; /* * Start by ACKing the previous packet; this should cause * the next packet to be sent. */ timeout_ptr = TimeoutTable; timeout = *timeout_ptr++; oldtime = jiffies(); ack_again: ack_packet(inode, socket->tftp_lastpkt); while (timeout) { buf_len = socket->tftp_blksize + 4; err = core_udp_recv(socket, socket->tftp_pktbuf, &buf_len, &src_ip, &src_port); if (err) { jiffies_t now = jiffies(); if (now-oldtime >= timeout) { oldtime = now; timeout = *timeout_ptr++; if (!timeout) break; goto ack_again; } continue; } if (buf_len < 4) /* Bad size for a DATA packet */ continue; pkt = (struct tftp_packet *)(socket->tftp_pktbuf); if (pkt->opcode != TFTP_DATA) /* Not a data packet */ continue; /* If goes here, recevie OK, break */ break; } /* time runs out */ if (timeout == 0) kaboom(); last_pkt = socket->tftp_lastpkt; last_pkt++; serial = ntohs(pkt->serial); if (serial != last_pkt) { /* * Wrong packet, ACK the packet and try again. * This is presumably because the ACK got lost, * so the server just resent the previous packet. */ #if 0 printf("Wrong packet, wanted %04x, got %04x\n", \ htons(last_pkt), htons(*(uint16_t *)(data+2))); #endif goto ack_again; } /* It's the packet we want. We're also EOF if the size < blocksize */ socket->tftp_lastpkt = last_pkt; /* Update last packet number */ buffersize = buf_len - 4; /* Skip TFTP header */ socket->tftp_dataptr = socket->tftp_pktbuf + 4; socket->tftp_filepos += buffersize; socket->tftp_bytesleft = buffersize; if (buffersize < socket->tftp_blksize) { /* it's the last block, ACK packet immediately */ ack_packet(inode, serial); /* Make sure we know we are at end of file */ inode->size = socket->tftp_filepos; socket->tftp_goteof = 1; tftp_close_file(inode); } }
int detonate(struct nukstr *np, coord x, coord y, int airburst) { int nuketype = np->nuk_type; struct nchrstr *ncp; struct plnstr plane; struct sctstr sect; struct shpstr ship; struct lndstr land; struct nukstr nuke; natid own; int type; int damage; int fallout; int rad; struct nstr_sect ns; struct nstr_item ni; int changed = 0; pr("Releasing RV's for %s detonation...\n", airburst ? "airburst" : "groundburst"); getsect(x, y, §); ncp = &nchr[nuketype]; kaboom(x, y, ncp->n_blast); rad = ncp->n_blast; if (!airburst) rad = rad * 2 / 3; if (sect.sct_type == SCT_WATER) rad = 0; /* Nukes falling on water affect only 1 sector */ np->nuk_effic = 0; putnuke(np->nuk_uid, np); snxtsct_dist(&ns, x, y, rad); while (nxtsct(&ns, §)) { own = sect.sct_own; type = sect.sct_type; if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0) continue; if (type == SCT_SANCT) { pr("bounced off %s\n", xyas(ns.x, ns.y, player->cnum)); mpr(own, "%s nuclear device bounced off %s\n", cname(player->cnum), xyas(ns.x, ns.y, own)); nreport(player->cnum, N_NUKE, own, 1); continue; } sect_damage(§, damage); if (opt_FALLOUT) { fallout = sect.sct_fallout; if (ncp->n_flags & N_NEUT) fallout += damage * 30; else fallout += damage * 3; sect.sct_fallout = MIN(fallout, FALLOUT_MAX); } if (damage > 100) { sect.sct_oldown = 0; sect.sct_own = 0; if (type == SCT_WATER || type == SCT_BSPAN || type == SCT_BTOWER) { if (type != SCT_WATER) { pr("left nothing but water in %s\n", xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device left nothing but water in %s\n", cname(player->cnum), xyas(ns.x, ns.y, own)); sect.sct_newtype = SCT_WATER; sect.sct_type = SCT_WATER; } } else { sect.sct_newtype = SCT_WASTE; sect.sct_type = SCT_WASTE; pr("turned %s into a radioactive wasteland\n", xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device turned %s into a radioactive wasteland\n", cname(player->cnum), xyas(ns.x, ns.y, own)); } changed |= map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[sect.sct_type].d_mnem, 0); } else { pr("did %d%% damage in %s\n", damage, xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device did %d%% damage in %s\n", cname(player->cnum), damage, xyas(ns.x, ns.y, own)); } (void)putsect(§); if (type != SCT_WATER) nreport(player->cnum, N_NUKE, own, 1); } if (changed) writebmap(player->cnum); snxtitem_dist(&ni, EF_PLANE, x, y, rad); while (nxtitem(&ni, &plane)) { if ((own = plane.pln_own) == 0) continue; if (plane.pln_flags & PLN_LAUNCHED) continue; damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden; if (damage <= 0) continue; if (plane.pln_ship >= 0) { /* Are we on a sub? */ getship(plane.pln_ship, &ship); if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } } planedamage(&plane, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prplane(&plane), xyas(plane.pln_x, plane.pln_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prplane(&plane), xyas(plane.pln_x, plane.pln_y, own)); } putplane(ni.cur, &plane); } snxtitem_dist(&ni, EF_LAND, x, y, rad); while (nxtitem(&ni, &land)) { if ((own = land.lnd_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (land.lnd_ship >= 0) { /* Are we on a sub? */ getship(land.lnd_ship, &ship); if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } } land_damage(&land, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prland(&land), xyas(land.lnd_x, land.lnd_y, own)); } putland(land.lnd_uid, &land); } snxtitem_dist(&ni, EF_SHIP, x, y, rad); while (nxtitem(&ni, &ship)) { if ((own = ship.shp_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } ship_damage(&ship, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prship(&ship), xyas(ship.shp_x, ship.shp_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prship(&ship), xyas(ship.shp_x, ship.shp_y, own)); } putship(ship.shp_uid, &ship); } snxtitem_dist(&ni, EF_NUKE, x, y, rad); while (nxtitem(&ni, &nuke)) { if ((own = nuke.nuk_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (!pct_chance(damage)) continue; nuke.nuk_effic = 0; if (own == player->cnum) { pr("%s at %s destroyed\n", prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, player->cnum)); } else { mpr(own, "%s nuclear device destroyed %s at %s\n", cname(player->cnum), prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own)); } putnuke(ni.cur, &nuke); } return nukedamage(ncp, 0, airburst); }
__export __noreturn __bad_SEG(const volatile void *p) { dprintf("SEG() passed an invalid pointer: %p\n", p); kaboom(); }
int game( int nlevel ){ LSDB lsdb; lsdb.lives = 3; lsdb.bombs = 0; lsdb.score = 0; lsdb.diamonds = 0; int die; gps player; int count = 0; int new_bomb = 0; int level = nlevel; int level_score = 0; int new_bomb_x, new_bomb_y; char map[MAP_HSIZE][MAP_WSIZE]; erase(); load_level( map, level, &player, &lsdb.diamonds ); draw_all( map, HZ, lsdb ); nodelay( stdscr, TRUE ); int run = 1; while( run ){ count++; die = 0; switch( tolower( getch() ) ){ case KEY_UP : if( move_player( map, &player, UP , &lsdb) == -1 ) die = 1; break; case KEY_DOWN : if( move_player( map, &player, DOWN , &lsdb) == -1 ) die = 1; break; case KEY_LEFT : if( move_player( map, &player, LEFT , &lsdb) == -1 ) die = 1; break; case KEY_RIGHT: if( move_player( map, &player, RIGHT, &lsdb) == -1 ) die = 1; break; case 'k' : die = 1; break; case 'h' : help() ; break; case 27 : run = false ; break; case 'q' : if(msgbox("Quit game == 'q' ? yes : no ")== 'q') run = false; break; case 'b' : if( lsdb.bombs ){ if( new_bomb == 0 ){ lsdb.bombs--; new_bomb = 1; new_bomb_y = player.y; new_bomb_x = player.x; } } break; case 't' : if( new_bomb ){ new_bomb = 0; die = 1; } else if( kaboom( map ) ) die = 1; break; default : break; } // switch( ch ) if( new_bomb ){ if( player.y != new_bomb_y || player.x != new_bomb_x ){ new_bomb = 0; map[new_bomb_y][new_bomb_x] = BOMB; } } if( count >= 4 ){ if( do_the_monster_dance( map, player ) ) die = 1; count = 0; } if( gravity( map, &new_bomb ) ) die = 1; if( die ){ kill_player(map, player ); lsdb.lives--; lsdb.bombs = 0; new_bomb = 0; if( lsdb.lives == 0 ){ if( msgbox( "continue == 'q' ? no : yes " ) != 'q' ) return level; else return 0 ; } lsdb.score = level_score; load_level( map, level, &player, &lsdb.diamonds ); } if( lsdb.diamonds <= 0 ){ level_score = lsdb.score; load_level( map, ++level, &player, &lsdb.diamonds ); } draw_all( map, HZ, lsdb ); } // while( run ) nodelay( stdscr, FALSE ); return 0; }