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
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <errno.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <limits.h>
36 #include <unistd.h>
37 #include <dirent.h>
38 #include <macros.h>
39 #include <sys/systeminfo.h>
40 #include <sys/queue.h>
41 #include <sys/mnttab.h>
42 #include "ficl.h"
43
44 /* Commands and return values; nonzero return sets command_errmsg != NULL */
45 typedef int (bootblk_cmd_t)(int argc, char *argv[]);
46 #define CMD_OK 0
47 #define CMD_ERROR 1
48
49 /*
50 * Support for commands
51 */
52 struct bootblk_command
53 {
54 const char *c_name;
55 const char *c_desc;
56 bootblk_cmd_t *c_fn;
57 STAILQ_ENTRY(bootblk_command) next;
58 };
59
60 #define MDIR_REMOVED 0x0001
61 #define MDIR_NOHINTS 0x0002
85 extern int pager_file(const char *);
86 static int page_file(char *);
87 static int include(const char *);
88
89 static int command_help(int argc, char *argv[]);
90 static int command_commandlist(int argc, char *argv[]);
91 static int command_show(int argc, char *argv[]);
92 static int command_set(int argc, char *argv[]);
93 static int command_setprop(int argc, char *argv[]);
94 static int command_unset(int argc, char *argv[]);
95 static int command_echo(int argc, char *argv[]);
96 static int command_read(int argc, char *argv[]);
97 static int command_more(int argc, char *argv[]);
98 static int command_ls(int argc, char *argv[]);
99 static int command_include(int argc, char *argv[]);
100 static int command_autoboot(int argc, char *argv[]);
101 static int command_boot(int argc, char *argv[]);
102 static int command_unload(int argc, char *argv[]);
103 static int command_load(int argc, char *argv[]);
104 static int command_reboot(int argc, char *argv[]);
105
106 #define BF_PARSE 100
107 #define BF_DICTSIZE 30000
108
109 /* update when loader version will change */
110 static const char bootprog_rev[] = "1.1";
111 STAILQ_HEAD(cmdh, bootblk_command) commands;
112
113 /*
114 * BootForth Interface to Ficl Forth interpreter.
115 */
116
117 ficlSystem *bf_sys;
118 ficlVm *bf_vm;
119
120 /*
121 * Redistribution and use in source and binary forms, with or without
122 * modification, are permitted provided that the following conditions
123 * are met:
124 * 1. Redistributions of source code must retain the above copyright
733 COMMAND_SET(cmdp, "read", "read input from the terminal", command_read);
734 STAILQ_INSERT_TAIL(&commands, cmdp, next);
735 COMMAND_SET(cmdp, "more", "show contents of a file", command_more);
736 STAILQ_INSERT_TAIL(&commands, cmdp, next);
737 COMMAND_SET(cmdp, "ls", "list files", command_ls);
738 STAILQ_INSERT_TAIL(&commands, cmdp, next);
739 COMMAND_SET(cmdp, "include", "read commands from a file",
740 command_include);
741 STAILQ_INSERT_TAIL(&commands, cmdp, next);
742 COMMAND_SET(cmdp, "boot", "boot a file or loaded kernel", command_boot);
743 STAILQ_INSERT_TAIL(&commands, cmdp, next);
744 COMMAND_SET(cmdp, "autoboot", "boot automatically after a delay",
745 command_autoboot);
746 STAILQ_INSERT_TAIL(&commands, cmdp, next);
747 COMMAND_SET(cmdp, "load", "load a kernel or module", command_load);
748 STAILQ_INSERT_TAIL(&commands, cmdp, next);
749 COMMAND_SET(cmdp, "unload", "unload all modules", command_unload);
750 STAILQ_INSERT_TAIL(&commands, cmdp, next);
751 COMMAND_SET(cmdp, "reboot", "reboot the system", command_reboot);
752 STAILQ_INSERT_TAIL(&commands, cmdp, next);
753
754 fsi = malloc(sizeof (ficlSystemInformation));
755 ficlSystemInformationInitialize(fsi);
756 fsi->textOut = out;
757 fsi->dictionarySize = BF_DICTSIZE;
758
759 bf_sys = ficlSystemCreate(fsi);
760 free(fsi);
761 ficlSystemCompileExtras(bf_sys);
762 bf_vm = ficlSystemCreateVm(bf_sys);
763
764 buf = isadir();
765 if (buf == NULL || strcmp(buf, "amd64") != 0) {
766 (void) setenv("ISADIR", "", 1);
767 } else {
768 (void) setenv("ISADIR", buf, 1);
769 }
770 if (buf != NULL)
771 free(buf);
772 buf = get_currdev();
819
820 /*
821 * Export some version numbers so that code can detect the
822 * loader/host version
823 */
824 env = ficlSystemGetEnvironment(bf_sys);
825 ficlDictionarySetConstant(env, "loader_version",
826 (bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0'));
827
828 /* try to load and run init file if present */
829 if (rc == NULL)
830 rc = "/boot/forth/boot.4th";
831 if (*rc != '\0') {
832 fd = open(rc, O_RDONLY);
833 if (fd != -1) {
834 (void) ficlExecFD(bf_vm, fd);
835 close(fd);
836 }
837 }
838
839 return (bf_vm);
840 }
841
842 void
843 bf_fini(void)
844 {
845 ficlSystemDestroy(bf_sys);
846 }
847
848 /*
849 * Feed a line of user input to the Forth interpreter
850 */
851 int
852 bf_run(char *line)
853 {
854 int result;
855 ficlString s;
856
857 FICL_STRING_SET_FROM_CSTRING(s, line);
858 result = ficlVmExecuteString(bf_vm, s);
859
860 switch (result) {
861 case FICL_VM_STATUS_OUT_OF_TEXT:
862 case FICL_VM_STATUS_ABORTQ:
863 case FICL_VM_STATUS_QUIT:
864 case FICL_VM_STATUS_ERROR_EXIT:
865 break;
1954 return (CMD_ERROR);
1955 }
1956 setenv("kernelname", filename, 1);
1957
1958 return (CMD_OK);
1959 }
1960
1961 static int
1962 command_unload(int argc, char *argv[])
1963 {
1964 unsetenv("kernelname");
1965 return (CMD_OK);
1966 }
1967
1968 static int
1969 command_reboot(int argc, char *argv[])
1970 {
1971 exit(0);
1972 return (CMD_OK);
1973 }
|
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
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <errno.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <limits.h>
36 #include <unistd.h>
37 #include <dirent.h>
38 #include <macros.h>
39 #include <sys/systeminfo.h>
40 #include <sys/queue.h>
41 #include <sys/mnttab.h>
42 #include "gfx_fb.h"
43 #include "ficl.h"
44
45 /* Commands and return values; nonzero return sets command_errmsg != NULL */
46 typedef int (bootblk_cmd_t)(int argc, char *argv[]);
47 #define CMD_OK 0
48 #define CMD_ERROR 1
49
50 /*
51 * Support for commands
52 */
53 struct bootblk_command
54 {
55 const char *c_name;
56 const char *c_desc;
57 bootblk_cmd_t *c_fn;
58 STAILQ_ENTRY(bootblk_command) next;
59 };
60
61 #define MDIR_REMOVED 0x0001
62 #define MDIR_NOHINTS 0x0002
86 extern int pager_file(const char *);
87 static int page_file(char *);
88 static int include(const char *);
89
90 static int command_help(int argc, char *argv[]);
91 static int command_commandlist(int argc, char *argv[]);
92 static int command_show(int argc, char *argv[]);
93 static int command_set(int argc, char *argv[]);
94 static int command_setprop(int argc, char *argv[]);
95 static int command_unset(int argc, char *argv[]);
96 static int command_echo(int argc, char *argv[]);
97 static int command_read(int argc, char *argv[]);
98 static int command_more(int argc, char *argv[]);
99 static int command_ls(int argc, char *argv[]);
100 static int command_include(int argc, char *argv[]);
101 static int command_autoboot(int argc, char *argv[]);
102 static int command_boot(int argc, char *argv[]);
103 static int command_unload(int argc, char *argv[]);
104 static int command_load(int argc, char *argv[]);
105 static int command_reboot(int argc, char *argv[]);
106 static int command_framebuffer(int argc, char *argv[]);
107
108 #define BF_PARSE 100
109 #define BF_DICTSIZE 30000
110
111 /* update when loader version will change */
112 static const char bootprog_rev[] = "1.1";
113 STAILQ_HEAD(cmdh, bootblk_command) commands;
114
115 /*
116 * BootForth Interface to Ficl Forth interpreter.
117 */
118
119 ficlSystem *bf_sys;
120 ficlVm *bf_vm;
121
122 /*
123 * Redistribution and use in source and binary forms, with or without
124 * modification, are permitted provided that the following conditions
125 * are met:
126 * 1. Redistributions of source code must retain the above copyright
735 COMMAND_SET(cmdp, "read", "read input from the terminal", command_read);
736 STAILQ_INSERT_TAIL(&commands, cmdp, next);
737 COMMAND_SET(cmdp, "more", "show contents of a file", command_more);
738 STAILQ_INSERT_TAIL(&commands, cmdp, next);
739 COMMAND_SET(cmdp, "ls", "list files", command_ls);
740 STAILQ_INSERT_TAIL(&commands, cmdp, next);
741 COMMAND_SET(cmdp, "include", "read commands from a file",
742 command_include);
743 STAILQ_INSERT_TAIL(&commands, cmdp, next);
744 COMMAND_SET(cmdp, "boot", "boot a file or loaded kernel", command_boot);
745 STAILQ_INSERT_TAIL(&commands, cmdp, next);
746 COMMAND_SET(cmdp, "autoboot", "boot automatically after a delay",
747 command_autoboot);
748 STAILQ_INSERT_TAIL(&commands, cmdp, next);
749 COMMAND_SET(cmdp, "load", "load a kernel or module", command_load);
750 STAILQ_INSERT_TAIL(&commands, cmdp, next);
751 COMMAND_SET(cmdp, "unload", "unload all modules", command_unload);
752 STAILQ_INSERT_TAIL(&commands, cmdp, next);
753 COMMAND_SET(cmdp, "reboot", "reboot the system", command_reboot);
754 STAILQ_INSERT_TAIL(&commands, cmdp, next);
755 COMMAND_SET(cmdp, "framebuffer", "framebuffer mode management",
756 command_framebuffer);
757 STAILQ_INSERT_TAIL(&commands, cmdp, next);
758
759 fsi = malloc(sizeof (ficlSystemInformation));
760 ficlSystemInformationInitialize(fsi);
761 fsi->textOut = out;
762 fsi->dictionarySize = BF_DICTSIZE;
763
764 bf_sys = ficlSystemCreate(fsi);
765 free(fsi);
766 ficlSystemCompileExtras(bf_sys);
767 bf_vm = ficlSystemCreateVm(bf_sys);
768
769 buf = isadir();
770 if (buf == NULL || strcmp(buf, "amd64") != 0) {
771 (void) setenv("ISADIR", "", 1);
772 } else {
773 (void) setenv("ISADIR", buf, 1);
774 }
775 if (buf != NULL)
776 free(buf);
777 buf = get_currdev();
824
825 /*
826 * Export some version numbers so that code can detect the
827 * loader/host version
828 */
829 env = ficlSystemGetEnvironment(bf_sys);
830 ficlDictionarySetConstant(env, "loader_version",
831 (bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0'));
832
833 /* try to load and run init file if present */
834 if (rc == NULL)
835 rc = "/boot/forth/boot.4th";
836 if (*rc != '\0') {
837 fd = open(rc, O_RDONLY);
838 if (fd != -1) {
839 (void) ficlExecFD(bf_vm, fd);
840 close(fd);
841 }
842 }
843
844 gfx_framework_init();
845 return (bf_vm);
846 }
847
848 void
849 bf_fini(void)
850 {
851 ficlSystemDestroy(bf_sys);
852 gfx_framework_fini();
853 }
854
855 /*
856 * Feed a line of user input to the Forth interpreter
857 */
858 int
859 bf_run(char *line)
860 {
861 int result;
862 ficlString s;
863
864 FICL_STRING_SET_FROM_CSTRING(s, line);
865 result = ficlVmExecuteString(bf_vm, s);
866
867 switch (result) {
868 case FICL_VM_STATUS_OUT_OF_TEXT:
869 case FICL_VM_STATUS_ABORTQ:
870 case FICL_VM_STATUS_QUIT:
871 case FICL_VM_STATUS_ERROR_EXIT:
872 break;
1961 return (CMD_ERROR);
1962 }
1963 setenv("kernelname", filename, 1);
1964
1965 return (CMD_OK);
1966 }
1967
1968 static int
1969 command_unload(int argc, char *argv[])
1970 {
1971 unsetenv("kernelname");
1972 return (CMD_OK);
1973 }
1974
1975 static int
1976 command_reboot(int argc, char *argv[])
1977 {
1978 exit(0);
1979 return (CMD_OK);
1980 }
1981
1982 /* Only implement get, ignore other arguments */
1983 static int
1984 command_framebuffer(int argc, char *argv[])
1985 {
1986 if (fb.fd < 0) {
1987 printf("Framebuffer is not available.\n");
1988 return (CMD_OK);
1989 }
1990
1991 if (argc == 2 && strcmp(argv[1], "get") == 0) {
1992 printf("\nSystem frame buffer: %s\n", fb.ident.name);
1993 printf("%dx%dx%d, stride=%d\n", fb.fb_width, fb.fb_height,
1994 fb.fb_depth, (fb.fb_pitch << 3) / fb.fb_depth);
1995 return (CMD_OK);
1996 }
1997 if (argc == 2 && strcmp(argv[1], "list") == 0) {
1998 printf("0: %dx%dx%d\n", fb.fb_width, fb.fb_height, fb.fb_depth);
1999 return (CMD_OK);
2000 }
2001 return (CMD_OK);
2002 }
|