loader.c (158466) | loader.c (253172) |
---|---|
1/*- 2 * Copyright (c) 2000 Daniel Capo Sobral 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2000 Daniel Capo Sobral 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/boot/ficl/loader.c 158466 2006-05-12 04:07:42Z jhb $ | 26 * $FreeBSD: head/sys/boot/ficl/loader.c 253172 2013-07-10 21:37:50Z marcel $ |
27 */ 28 29/******************************************************************* 30** l o a d e r . c 31** Additional FICL words designed for FreeBSD's loader 32** 33*******************************************************************/ 34 --- 364 unchanged lines hidden (view full) --- 399 vmCheckStack(pVM, 1, 0); 400#endif 401 c = stackPop(pVM->pStack); 402 ltoa((c).i, pVM->pad, pVM->base); 403 vmTextOut(pVM, pVM->pad, 0); 404 return; 405} 406 | 27 */ 28 29/******************************************************************* 30** l o a d e r . c 31** Additional FICL words designed for FreeBSD's loader 32** 33*******************************************************************/ 34 --- 364 unchanged lines hidden (view full) --- 399 vmCheckStack(pVM, 1, 0); 400#endif 401 c = stackPop(pVM->pStack); 402 ltoa((c).i, pVM->pad, pVM->base); 403 vmTextOut(pVM, pVM->pad, 0); 404 return; 405} 406 |
407/* isdir? - Return whether an fd corresponds to a directory. 408 * 409 * isdir? ( fd -- bool ) 410 */ 411static void isdirQuestion(FICL_VM *pVM) 412{ 413 struct stat sb; 414 FICL_INT flag; 415 int fd; 416 417#if FICL_ROBUST > 1 418 vmCheckStack(pVM, 1, 1); 419#endif 420 421 fd = stackPopINT(pVM->pStack); 422 flag = FICL_FALSE; 423 do { 424 if (fd < 0) 425 break; 426 if (fstat(fd, &sb) < 0) 427 break; 428 if (!S_ISDIR(sb.st_mode)) 429 break; 430 flag = FICL_TRUE; 431 } while (0); 432 stackPushINT(pVM->pStack, flag); 433} 434 |
|
407/* fopen - open a file and return new fd on stack. 408 * 409 * fopen ( ptr count mode -- fd ) 410 */ 411static void pfopen(FICL_VM *pVM) 412{ 413 int mode, fd, count; 414 char *ptr, *name; --- 57 unchanged lines hidden (view full) --- 472 fd = stackPopINT(pVM->pStack); /* get fd */ 473 if (len > 0 && buf && fd != -1) 474 stackPushINT(pVM->pStack, read(fd, buf, len)); 475 else 476 stackPushINT(pVM->pStack, -1); 477 return; 478} 479 | 435/* fopen - open a file and return new fd on stack. 436 * 437 * fopen ( ptr count mode -- fd ) 438 */ 439static void pfopen(FICL_VM *pVM) 440{ 441 int mode, fd, count; 442 char *ptr, *name; --- 57 unchanged lines hidden (view full) --- 500 fd = stackPopINT(pVM->pStack); /* get fd */ 501 if (len > 0 && buf && fd != -1) 502 stackPushINT(pVM->pStack, read(fd, buf, len)); 503 else 504 stackPushINT(pVM->pStack, -1); 505 return; 506} 507 |
508/* freaddir - read directory contents 509 * 510 * freaddir ( fd -- ptr len TRUE | FALSE ) 511 */ 512static void pfreaddir(FICL_VM *pVM) 513{ 514 struct dirent *d; 515 int fd; 516 517#if FICL_ROBUST > 1 518 vmCheckStack(pVM, 1, 3); 519#endif 520 521 fd = stackPopINT(pVM->pStack); 522 d = readdirfd(fd); 523 if (d != NULL) { 524 stackPushPtr(pVM->pStack, d->d_name); 525 stackPushINT(pVM->pStack, strlen(d->d_name)); 526 stackPushINT(pVM->pStack, FICL_TRUE); 527 } else { 528 stackPushINT(pVM->pStack, FICL_FALSE); 529 } 530} 531 |
|
480/* fload - interpret file contents 481 * 482 * fload ( fd -- ) 483 */ 484static void pfload(FICL_VM *pVM) 485{ 486 int fd; 487 --- 160 unchanged lines hidden (view full) --- 648** Build FreeBSD platform extensions into the system dictionary 649**************************************************************************/ 650void ficlCompilePlatform(FICL_SYSTEM *pSys) 651{ 652 FICL_DICT *dp = pSys->dp; 653 assert (dp); 654 655 dictAppendWord(dp, ".#", displayCellNoPad, FW_DEFAULT); | 532/* fload - interpret file contents 533 * 534 * fload ( fd -- ) 535 */ 536static void pfload(FICL_VM *pVM) 537{ 538 int fd; 539 --- 160 unchanged lines hidden (view full) --- 700** Build FreeBSD platform extensions into the system dictionary 701**************************************************************************/ 702void ficlCompilePlatform(FICL_SYSTEM *pSys) 703{ 704 FICL_DICT *dp = pSys->dp; 705 assert (dp); 706 707 dictAppendWord(dp, ".#", displayCellNoPad, FW_DEFAULT); |
708 dictAppendWord(dp, "isdir?", isdirQuestion, FW_DEFAULT); |
|
656 dictAppendWord(dp, "fopen", pfopen, FW_DEFAULT); 657 dictAppendWord(dp, "fclose", pfclose, FW_DEFAULT); 658 dictAppendWord(dp, "fread", pfread, FW_DEFAULT); | 709 dictAppendWord(dp, "fopen", pfopen, FW_DEFAULT); 710 dictAppendWord(dp, "fclose", pfclose, FW_DEFAULT); 711 dictAppendWord(dp, "fread", pfread, FW_DEFAULT); |
712 dictAppendWord(dp, "freaddir", pfreaddir, FW_DEFAULT); |
|
659 dictAppendWord(dp, "fload", pfload, FW_DEFAULT); 660 dictAppendWord(dp, "fkey", fkey, FW_DEFAULT); 661 dictAppendWord(dp, "fseek", pfseek, FW_DEFAULT); 662 dictAppendWord(dp, "fwrite", pfwrite, FW_DEFAULT); 663 dictAppendWord(dp, "key", key, FW_DEFAULT); 664 dictAppendWord(dp, "key?", keyQuestion, FW_DEFAULT); 665 dictAppendWord(dp, "ms", ms, FW_DEFAULT); 666 dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT); --- 42 unchanged lines hidden --- | 713 dictAppendWord(dp, "fload", pfload, FW_DEFAULT); 714 dictAppendWord(dp, "fkey", fkey, FW_DEFAULT); 715 dictAppendWord(dp, "fseek", pfseek, FW_DEFAULT); 716 dictAppendWord(dp, "fwrite", pfwrite, FW_DEFAULT); 717 dictAppendWord(dp, "key", key, FW_DEFAULT); 718 dictAppendWord(dp, "key?", keyQuestion, FW_DEFAULT); 719 dictAppendWord(dp, "ms", ms, FW_DEFAULT); 720 dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT); --- 42 unchanged lines hidden --- |