int acpiEnable(void) { // check if acpi is enabled if ( (inw((unsigned int) PM1a_CNT) &SCI_EN) == 0 ) { // check if acpi can be enabled if (SMI_CMD != 0 && ACPI_ENABLE != 0) { outb((unsigned int) SMI_CMD, ACPI_ENABLE); // send acpi enable command // give 3 seconds time to enable acpi int i; for (i=0; i<300; i++ ) { if ( (inw((unsigned int) PM1a_CNT) &SCI_EN) == 1 ) break; sleep(10); } if (PM1b_CNT != 0) for (; i<300; i++ ) { if ( (inw((unsigned int) PM1b_CNT) &SCI_EN) == 1 ) break; sleep(10); } if (i<300) { wrstr("enabled acpi.\n"); return 0; } else { wrstr("couldn't enable acpi.\n"); return -1; } } else { wrstr("no known way to enable acpi.\n"); return -1; } } else { wrstr("acpi was already enabled.\n"); return 0; } }
/* Outputs a symbol table to file in a way that can be * read back usefully. Only writes declarations, types * and sub-namespaces. Captured variables are ommitted. */ static void wrstab(FILE *fd, Stab *val) { size_t n, i; void **keys; wrstr(fd, val->name); /* write decls */ keys = htkeys(val->dcl, &n); wrint(fd, n); for (i = 0; i < n; i++) wrsym(fd, getdcl(val, keys[i])); free(keys); /* write types */ keys = htkeys(val->ty, &n); wrint(fd, n); for (i = 0; i < n; i++) { pickle(fd, keys[i]); /* name */ wrtype(fd, gettype(val, keys[i])); /* type */ } free(keys); }
static void sendthem(char *str, int fn, char *phstr1, char *phstr2) { int sendcr = 1, echocheck = 0; char *sptr, *bptr; char buf[BUFSIZ]; struct termio ttybuf; /* should be EQUALS, but previous versions had BREAK n for integer n */ if (PREFIX("BREAK", str)) { /* send break */ CDEBUG(5, "BREAK\n%s", ""); (*genbrk)(fn); return; } if (EQUALS(str, "EOT")) { CDEBUG(5, "EOT\n%s", ""); (void) (*Write)(fn, EOTMSG, strlen(EOTMSG)); return; } if (EQUALS(str, "\"\"")) { CDEBUG(5, "\"\"\n%s", ""); str += 2; } bptr = buf; CDEBUG(5, "sendthem (%s", ""); for (sptr = str; *sptr; sptr++) { if (*sptr == '\\') { switch (*++sptr) { /* adjust switches */ case 'c': /* no CR after string */ FLUSH(); if (sptr[1] == NULLCHAR) { CDEBUG(5, "<NO CR>%s", ""); sendcr = 0; } else { /*EMPTY*/ CDEBUG(5, "<NO CR IGNORED>\n%s", ""); } continue; } /* stash in buf and continue */ switch (*sptr) { case 'D': /* raw phnum */ (void) strcpy(bptr, phstr1); bptr += strlen(bptr); continue; case 'T': /* translated phnum */ (void) strcpy(bptr, phstr2); bptr += strlen(bptr); continue; case 'N': /* null */ *bptr++ = 0; continue; case 's': /* space */ *bptr++ = ' '; continue; case '\\': /* backslash escapes itself */ *bptr++ = *sptr; continue; default: /* send the backslash */ *bptr++ = '\\'; *bptr++ = *sptr; continue; /* flush buf, perform action, and continue */ case 'E': /* echo check on */ FLUSH(); CDEBUG(5, "ECHO CHECK ON\n%s", ""); echocheck = 1; continue; case 'e': /* echo check off */ FLUSH(); CDEBUG(5, "ECHO CHECK OFF\n%s", ""); echocheck = 0; continue; case 'd': /* sleep briefly */ FLUSH(); CDEBUG(5, "DELAY\n%s", ""); (void) sleep(2); continue; case 'p': /* pause momentarily */ FLUSH(); CDEBUG(5, "PAUSE\n%s", ""); nap(HZ/4); /* approximately 1/4 second */ continue; case 'K': /* inline break */ FLUSH(); CDEBUG(5, "BREAK\n%s", ""); (*genbrk)(fn); continue; case 'M': /* modem control - set CLOCAL */ case 'm': /* no modem control - clear CLOCAL */ FLUSH(); CDEBUG(5, ")\n%s CLOCAL ", (*sptr == 'M' ? "set" : "clear")); if ((*Ioctl)(fn, TCGETA, &ttybuf) != 0) { /*EMPTY*/ CDEBUG(5, "ignored. TCGETA failed, errno %d", errno); } else { if (*sptr == 'M') ttybuf.c_cflag |= CLOCAL; else ttybuf.c_cflag &= ~CLOCAL; if ((*Ioctl)(fn, TCSETAW, &ttybuf) != 0) /*EMPTY*/ CDEBUG(5, "failed. TCSETAW failed, errno %d", errno); } CDEBUG(5, "\n%s", ""); continue; } } else *bptr++ = *sptr; } if (sendcr) *bptr++ = '\r'; if ((bptr - buf) > 0) (void) wrstr(fn, buf, bptr - buf, echocheck); err: CDEBUG(5, ")\n%s", ""); }
/* Usefile format: * U<pkgname> * L<liblist> * I<initlist> * T<pickled-type> * D<picled-decl> * G<pickled-decl><pickled-initializer> * Z */ void writeuse(FILE *f, Node *file) { Stab *st; void **k; Node *s, *u; size_t i, n; assert(file->type == Nfile); st = file->file.globls; /* usefile name */ wrbyte(f, 'U'); wrint(f, Abiversion); /* use version */ if (st->name) wrstr(f, st->name); else wrstr(f, NULL); /* library deps */ for (i = 0; i < file->file.nuses; i++) { u = file->file.uses[i]; if (!u->use.islocal) { wrbyte(f, 'L'); wrstr(f, u->use.name); } } for (i = 0; i < file->file.nlibdeps; i++) { wrbyte(f, 'L'); wrstr(f, file->file.libdeps[i]); } for (i = 0; i < file->file.nextlibs; i++) { wrbyte(f, 'X'); wrstr(f, file->file.extlibs[i]); } /* source file name */ wrbyte(f, 'F'); wrstr(f, file->file.files[0]); for (i = 0; i < ntypes; i++) { if (types[i]->vis == Visexport || types[i]->vis == Vishidden) { wrbyte(f, 'T'); wrint(f, types[i]->tid); typickle(f, types[i]); } } for (i = 0; i < ntraittab; i++) { if (traittab[i]->vis == Visexport || traittab[i]->vis == Vishidden) { wrbyte(f, 'R'); traitpickle(f, traittab[i]); } } k = htkeys(st->impl, &n); for (i = 0; i < n; i++) { /* merging during inference should remove all protos */ s = getimpl(st, k[i]); assert(!s->impl.isproto); if (s->impl.vis == Visexport || s->impl.vis == Vishidden) { wrbyte(f, 'I'); pickle(f, s); } } free(k); k = htkeys(st->dcl, &n); for (i = 0; i < n; i++) { s = getdcl(st, k[i]); assert(s != NULL); if (s->decl.vis == Visintern || s->decl.vis == Visbuiltin) continue; /* trait functions get written out with their traits */ if (s->decl.trait || s->decl.isinit) continue; else if (s->decl.isgeneric) wrbyte(f, 'G'); else wrbyte(f, 'D'); wrsym(f, s); } for (i = 0; i < file->file.ninit; i++) { wrbyte(f, 'S'); pickle(f, file->file.init[i]); } if (file->file.localinit) { wrbyte(f, 'S'); pickle(f, file->file.localinit->decl.name); } free(k); }
/* Pickles a node to a file. The format * is more or less equivalen to to * simplest serialization of the * in-memory representation. Minimal * checking is done, so a bad type can * crash the compiler */ static void pickle(FILE *fd, Node *n) { size_t i; if (!n) { wrbyte(fd, Nnone); return; } wrbyte(fd, n->type); wrint(fd, n->loc.line); switch (n->type) { case Nfile: wrstr(fd, n->file.files[0]); wrint(fd, n->file.nuses); for (i = 0; i < n->file.nuses; i++) pickle(fd, n->file.uses[i]); wrint(fd, n->file.nstmts); for (i = 0; i < n->file.nstmts; i++) pickle(fd, n->file.stmts[i]); wrstab(fd, n->file.globls); break; case Nexpr: wrbyte(fd, n->expr.op); wrtype(fd, n->expr.type); wrbool(fd, n->expr.isconst); pickle(fd, n->expr.idx); wrint(fd, n->expr.nargs); for (i = 0; i < n->expr.nargs; i++) pickle(fd, n->expr.args[i]); break; case Nname: wrbool(fd, n->name.ns != NULL); if (n->name.ns) { wrstr(fd, n->name.ns); } wrstr(fd, n->name.name); break; case Nuse: wrbool(fd, n->use.islocal); wrstr(fd, n->use.name); break; case Nlit: wrbyte(fd, n->lit.littype); wrtype(fd, n->lit.type); wrint(fd, n->lit.nelt); switch (n->lit.littype) { case Lchr: wrint(fd, n->lit.chrval); break; case Lint: wrint(fd, n->lit.intval); break; case Lflt: wrflt(fd, n->lit.fltval); break; case Lstr: wrlenstr(fd, n->lit.strval); break; case Llbl: wrstr(fd, n->lit.lblval); break; case Lbool: wrbool(fd, n->lit.boolval); break; case Lfunc: pickle(fd, n->lit.fnval); break; } break; case Nloopstmt: pickle(fd, n->loopstmt.init); pickle(fd, n->loopstmt.cond); pickle(fd, n->loopstmt.step); pickle(fd, n->loopstmt.body); break; case Niterstmt: pickle(fd, n->iterstmt.elt); pickle(fd, n->iterstmt.seq); pickle(fd, n->iterstmt.body); break; case Nmatchstmt: pickle(fd, n->matchstmt.val); wrint(fd, n->matchstmt.nmatches); for (i = 0; i < n->matchstmt.nmatches; i++) pickle(fd, n->matchstmt.matches[i]); break; case Nmatch: pickle(fd, n->match.pat); pickle(fd, n->match.block); break; case Nifstmt: pickle(fd, n->ifstmt.cond); pickle(fd, n->ifstmt.iftrue); pickle(fd, n->ifstmt.iffalse); break; case Nblock: wrstab(fd, n->block.scope); wrint(fd, n->block.nstmts); for (i = 0; i < n->block.nstmts; i++) pickle(fd, n->block.stmts[i]); break; case Ndecl: /* sym */ pickle(fd, n->decl.name); wrtype(fd, n->decl.type); /* symflags */ wrbool(fd, n->decl.isconst); wrbool(fd, n->decl.isgeneric); wrbool(fd, n->decl.isextern); wrbool(fd, n->decl.isnoret); wrbool(fd, n->decl.ispkglocal); /* init */ pickle(fd, n->decl.init); break; case Nfunc: wrtype(fd, n->func.type); wrstab(fd, n->func.scope); wrint(fd, n->func.nargs); for (i = 0; i < n->func.nargs; i++) pickle(fd, n->func.args[i]); pickle(fd, n->func.body); break; case Nimpl: pickle(fd, n->impl.traitname); wrint(fd, n->impl.trait->uid); wrtype(fd, n->impl.type); wrint(fd, n->impl.ndecls); for (i = 0; i < n->impl.ndecls; i++) wrsym(fd, n->impl.decls[i]); break; case Nnone: die("Nnone should not be seen as node type!"); break; } }
/* Writes types to a file. Errors on * internal only types like Tyvar that * will not be meaningful in another file*/ static void typickle(FILE *fd, Type *ty) { size_t i; if (!ty) { die("trying to pickle null type\n"); return; } wrbyte(fd, ty->type); wrbyte(fd, ty->vis); /* tid is generated; don't write */ /* FIXME: since we only support hardcoded traits, we just write * out the set of them. we should write out the trait list as * well */ if (!ty->traits) { wrint(fd, 0); } else { wrint(fd, bscount(ty->traits)); for (i = 0; bsiter(ty->traits, &i); i++) { if (i < Ntraits) wrint(fd, i | Builtinmask); else wrint(fd, i); } } wrint(fd, ty->nsub); switch (ty->type) { case Tyunres: pickle(fd, ty->name); break; case Typaram: wrstr(fd, ty->pname); break; case Tystruct: wrint(fd, ty->nmemb); for (i = 0; i < ty->nmemb; i++) pickle(fd, ty->sdecls[i]); break; case Tyunion: wrint(fd, ty->nmemb); for (i = 0; i < ty->nmemb; i++) wrucon(fd, ty->udecls[i]); break; case Tyarray: wrtype(fd, ty->sub[0]); pickle(fd, ty->asize); break; case Tyslice: wrtype(fd, ty->sub[0]); break; case Tyvar: die("Attempting to pickle %s. This will not work.\n", tystr(ty)); break; case Tyname: pickle(fd, ty->name); wrbool(fd, ty->issynth); wrint(fd, ty->narg); for (i = 0; i < ty->narg; i++) wrtype(fd, ty->arg[i]); wrtype(fd, ty->sub[0]); break; case Tygeneric: pickle(fd, ty->name); wrbool(fd, ty->issynth); wrint(fd, ty->ngparam); for (i = 0; i < ty->ngparam; i++) wrtype(fd, ty->gparam[i]); wrtype(fd, ty->sub[0]); break; default: for (i = 0; i < ty->nsub; i++) wrtype(fd, ty->sub[i]); break; } }
PUBLIC WORD parse(INT old_nesting) { int nesting = (int) old_nesting; int quoted; nextsym(); if( symb==s_eof ) return nesting; parse_depth++; if( ( quoted = (symb==s_quote) ) != 0 ) nextsym(); /* trace("Parse %squoted depth %d",quoted?"":"un",parse_depth); */ for(;;) { switch ( (int)symb ) { case s_builtin: if(!quoted) { builtin(); break; } case s_macro: if(!quoted) { eval(); break; } case s_hexvar: case s_var: if(!quoted) { evalvar(); break; } default: case s_token: if( toksize == 1 ) wrch(token[0]); else wrstr(token); break; case s_lbra: if( nesting++ > 0) wrch(c_lbra); break; case s_rbra: if( --nesting > 0 ) wrch(c_rbra); break; case s_eof: return nesting; case s_quote: if( quoted ) wrch(c_quote); pbchar(c_quote); nesting = (int) parse((WORD)nesting); break; case s_concat: if( quoted ) wrch(c_concat); break; } if ( nesting <= old_nesting ) break; nextsym(); } parse_depth--; return nesting; }
// // bytecode of the \_S5 object // ----------------------------------------- // | (optional) | | | | // NameOP | \ | _ | S | 5 | _ // 08 | 5A | 5F | 53 | 35 | 5F // // ----------------------------------------------------------------------------------------------------------- // | | | ( SLP_TYPa ) | ( SLP_TYPb ) | ( Reserved ) | (Reserved ) // PackageOP | PkgLength | NumElements | byteprefix Num | byteprefix Num | byteprefix Num | byteprefix Num // 12 | 0A | 04 | 0A 05 | 0A 05 | 0A 05 | 0A 05 // //----this-structure-was-also-seen---------------------- // PackageOP | PkgLength | NumElements | // 12 | 06 | 04 | 00 00 00 00 // // (Pkglength bit 6-7 encode additional PkgLength bytes [shouldn't be the case here]) // int initAcpi(void) { unsigned int *ptr = acpiGetRSDPtr(); // check if address is correct ( if acpi is available on this pc ) if (ptr != NULL && acpiCheckHeader(ptr, "RSDT") == 0) { // the RSDT contains an unknown number of pointers to acpi tables int entrys = *(ptr + 1); entrys = (entrys-36) /4; ptr += 36/4; // skip header information while (0<entrys--) { // check if the desired table is reached if (acpiCheckHeader((unsigned int *) *ptr, "FACP") == 0) { entrys = -2; struct FACP *facp = (struct FACP *) *ptr; if (acpiCheckHeader((unsigned int *) facp->DSDT, "DSDT") == 0) { // search the \_S5 package in the DSDT char *S5Addr = (char *) facp->DSDT +36; // skip header int dsdtLength = *(facp->DSDT+1) -36; while (0 < dsdtLength--) { if ( memcmp(S5Addr, "_S5_", 4) == 0) break; S5Addr++; } // check if \_S5 was found if (dsdtLength > 0) { // check for valid AML structure if ( ( *(S5Addr-1) == 0x08 || ( *(S5Addr-2) == 0x08 && *(S5Addr-1) == '\\') ) && *(S5Addr+4) == 0x12 ) { S5Addr += 5; S5Addr += ((*S5Addr &0xC0)>>6) +2; // calculate PkgLength size if (*S5Addr == 0x0A) S5Addr++; // skip byteprefix SLP_TYPa = *(S5Addr)<<10; S5Addr++; if (*S5Addr == 0x0A) S5Addr++; // skip byteprefix SLP_TYPb = *(S5Addr)<<10; SMI_CMD = facp->SMI_CMD; ACPI_ENABLE = facp->ACPI_ENABLE; ACPI_DISABLE = facp->ACPI_DISABLE; PM1a_CNT = facp->PM1a_CNT_BLK; PM1b_CNT = facp->PM1b_CNT_BLK; PM1_CNT_LEN = facp->PM1_CNT_LEN; SLP_EN = 1<<13; SCI_EN = 1; return 0; } else { wrstr("\\_S5 parse error.\n"); } } else {