I changed virtcode so that it works like a minishell. Does nothing
else reading commands and try to execute them. As examples are help
and halt implemented. It's far away from being comfortable, but
it works ;) If there's a need it can be extended (more commands,
more comfort), perhaps someone want to build in a kernel debugger.
Patch (only against freemware/guest/virtcode) is attached.
>This is what I do: before I start coding, I always get the latest CVS
>tree. I then do cp -R freemware freemware-old, and edit the freemware tree.
>Then, diff -Nur freemware-old freemware only gives the "real" changes.
But if CVS tree changes while you are coding you make diffs against old
CVS states. You have to be _very fast_ or hope that CVS doesn't change.
jens
-----------------------------------
diff -Nur freemware/guest/virtcode/CVS/Entries
freemware-jens/guest/virtcode/CVS/Entries
--- freemware/guest/virtcode/CVS/Entries Mon Jan 17 14:41:37 2000
+++ freemware-jens/guest/virtcode/CVS/Entries Tue Jan 18 12:03:09 2000
@@ -1,4 +1,4 @@
-/.cvsignore/1.2/Mon Jan 10 10:37:07 2000//
-/Makefile.in/1.4/Mon Jan 10 10:37:07 2000//
-/virtcode.c/1.2/Mon Jan 17 13:41:37 2000//
+/.cvsignore/1.2/Mon Jan 10 10:42:04 2000//
+/Makefile.in/1.4/Mon Jan 10 10:42:04 2000//
+/virtcode.c/1.2/Mon Jan 17 19:46:23 2000//
D
diff -Nur freemware/guest/virtcode/Makefile.in
freemware-jens/guest/virtcode/Makefile.in
--- freemware/guest/virtcode/Makefile.in Mon Jan 10 11:37:07 2000
+++ freemware-jens/guest/virtcode/Makefile.in Tue Jan 18 15:43:29 2000
@@ -21,14 +21,16 @@
srcdir = @srcdir@
VPATH = @srcdir@
+SRC = virtcode.c keyboard.c minishell.c helper.c
+OBJ = $(SRC:.c=.o);
ALL: virtcode
.c.o:
$(CC) $(CFLAGS) -c $<
-virtcode: virtcode.o
- $(CC) -g -o virtcode -Wl,-Ttext,0x10000 -nostartfiles -nostdlib virtcode.o
+virtcode: $(OBJ)
+ $(CC) -g -o virtcode -Wl,-Ttext,0x10000 -nostartfiles -nostdlib $(OBJ)
clean:
/bin/rm -f *.o virtcode
diff -Nur freemware/guest/virtcode/helper.c freemware-jens/guest/virtcode/helper.c
--- freemware/guest/virtcode/helper.c Thu Jan 1 01:00:00 1970
+++ freemware-jens/guest/virtcode/helper.c Tue Jan 18 15:56:57 2000
@@ -0,0 +1,105 @@
+/*
+ * FreeMWare: run multiple x86 operating systems concurrently
+ * Copyright (C) 1999 - 2000 The FreeMWare Team
+ *
+ * virtcode.c: This file contains the test code to run in the VM
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+short *vidmem = (short *) 0xb8000;
+int cursor = 0;
+
+
+void
+printstr(char *text)
+{
+ int i = 0;
+
+ while(text[i])
+ {
+ if(text[i] == '\n')
+ {
+ cursor = (cursor / 80 + 1) * 80;
+ i++;
+ continue;
+ }
+ vidmem[cursor++] = text[i++] | 0x0700; // 0x0f00 for bold
+ cursor %= 80*25;
+ }
+
+ return;
+}
+
+void
+printchar(char c)
+{
+ if(c==0xd)
+ {
+ cursor = (cursor / 80 + 1) * 80;
+ return;
+ }
+ vidmem[cursor++] = c | 0x0700; // 0x0f00 for bold;
+ cursor %= 80*25;
+ return;
+}
+
+void
+printint(int i)
+{
+ char s[9];
+ const char map[ ] = "0123456789abcdef";
+ int j = 0;
+
+ if(i&0xf0000000) s[j++] = map[(i>>28)&0xf];
+ if(i&0xff000000) s[j++] = map[(i>>24)&0xf];
+ if(i&0xfff00000) s[j++] = map[(i>>20)&0xf];
+ if(i&0xffff0000) s[j++] = map[(i>>16)&0xf];
+ if(i&0xfffff000) s[j++] = map[(i>>12)&0xf];
+ if(i&0xffffff00) s[j++] = map[(i>>8)&0xf];
+ if(i&0xfffffff0) s[j++] = map[(i>>4)&0xf];
+ s[j++] = map[(i>>00)&0xf];
+ s[j] = '\0';
+
+ printstr(s);
+
+ return;
+}
+
+void
+clear_screen() {
+ int i;
+
+ /* clear the screen */
+
+ for(i=0; i<80*25; i++) vidmem[i] = 0;
+}
+
+int
+cmpstr(char *s1, char *s2)
+ /* compare two \0 terminated strings
+ * return 1 if equal, or 0 if not
+ */
+{
+ int i = 0;
+ while(s1[i]) {
+ if(s1[i]!=s2[i]) return 0;
+ i++;
+ }
+ if(s2[i]==0)
+ return 1;
+ return 0;
+}
diff -Nur freemware/guest/virtcode/keyboard.c freemware-jens/guest/virtcode/keyboard.c
--- freemware/guest/virtcode/keyboard.c Thu Jan 1 01:00:00 1970
+++ freemware-jens/guest/virtcode/keyboard.c Tue Jan 18 15:31:28 2000
@@ -0,0 +1,120 @@
+/*
+ * FreeMWare: run multiple x86 operating systems concurrently
+ * Copyright (C) 1999 - 2000 The FreeMWare Team
+ *
+ * virtcode.c: This file contains the test code to run in the VM
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define BREAK_MASK 0x80
+#define SCANCODE_MASK 0x7f
+#define SHIFT 42
+#define SHIFT2 0x36
+
+unsigned char
+shift_map[128] = {0,'1','!','"','�','$','%','&','/','(',')','=','?',};
+
+unsigned char
+normal_map[128] =
+{0, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '�', '\'', 0x8,
+ 0x9, 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', '�', '+', 0xd,
+ 0,
+ 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '�', '�', '^', 0, '#',
+ 'y', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-',0,0,0,' ',};
+
+int shift_state;
+
+char
+get_key_code(int scancode)
+{
+ int make = !(scancode & BREAK_MASK);
+ unsigned char *keymap;
+
+ scancode &= SCANCODE_MASK;
+
+ if ((scancode != SHIFT) && (scancode != SHIFT2)) {
+ if (!shift_state)
+ keymap = normal_map;
+ else
+ keymap = shift_map;
+ if (make) {
+ return keymap[scancode];
+ }
+ }
+ else {
+ if (make) {
+ shift_state = 1;
+ }
+ else {
+ shift_state = 0;
+ }
+ }
+ return 0;
+}
+
+int
+getkey(void)
+{
+ int i;
+
+ asm (
+ " xorl %%eax, %%eax \n"
+ " inb $0x64, %%al \n"
+ " andb $0x01, %%al \n"
+ " jz 2f \n"
+ " inb $0x60, %%al \n"
+ " movl %%eax, %0 \n"
+ " inb $0x61, %%al \n"
+ " movb %%al, %%ah \n"
+ " orb $0x80, %%al \n"
+ " outb %%al, $0x61 \n"
+ " movb %%ah, %%al \n"
+ " outb %%al, $0x61 \n"
+ " jmp 3f \n"
+ "2: movl $-1, %0 \n"
+ "3: \n"
+ : "=g" (i)
+ :
+ : "%eax"
+ );
+
+ return i;
+}
+
+int
+init_keyboard() {
+ int i;
+
+ /* keyboard self test */
+
+ while(getkey() != -1);
+ asm (
+ "xorl %%eax,%%eax \n"
+ "movb $0xaa, %%al \n"
+ "outb %%al, $0x64 \n"
+ "inb $0x60, %%al \n"
+ "movl %%eax, %0 \n"
+ : "=g" (i)
+ :
+ : "%eax"
+ );
+
+ if(i != 0x55) {
+ printstr("Error: keyboard self-test failed. Aborting...\n");
+ return -1;
+ }
+ return 0;
+}
diff -Nur freemware/guest/virtcode/minishell.c
freemware-jens/guest/virtcode/minishell.c
--- freemware/guest/virtcode/minishell.c Thu Jan 1 01:00:00 1970
+++ freemware-jens/guest/virtcode/minishell.c Tue Jan 18 16:07:12 2000
@@ -0,0 +1,89 @@
+/*
+ * FreeMWare: run multiple x86 operating systems concurrently
+ * Copyright (C) 1999 - 2000 The FreeMWare Team
+ *
+ * virtcode.c: This file contains the test code to run in the VM
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* todo
+ * correct history_index
+ */
+
+#define PROMPT "$ "
+
+char history[200];
+int history_index;
+
+int
+get_command() {
+ int i,h1;
+ char c;
+
+ h1 = history_index;
+ do {
+ while((i=getkey())==-1);
+
+#ifdef SHOW_SCANCODE
+ printstr("Received scancode: ");
+ printint(i);
+ printstr("\n");
+#endif
+
+ c = get_key_code(i);
+ if(c) {
+ history[history_index++]=c;
+ printchar(c);
+ }
+ }
+ while(c!=0xd);
+ history[history_index-1]=0;
+ return h1;
+}
+
+void
+print_help() {
+ printstr("Minishell help\n\n");
+ printstr("halt ... shut down virtual machine\n");
+
+ return;
+}
+
+int
+execute_command(int h1) {
+
+
+ if(cmpstr(&history[h1],"help"))
+ print_help();
+ else if(cmpstr(&history[h1],"halt"))
+ /* execute hlt shuts down vm */
+ asm("hlt\n");
+ else
+ printstr(&history[h1]);
+ return 0;
+}
+
+int
+minishell() {
+
+ history_index=0;
+
+ while (1) {
+ printstr(PROMPT);
+ execute_command(get_command());
+ }
+
+}
diff -Nur freemware/guest/virtcode/virtcode.c freemware-jens/guest/virtcode/virtcode.c
--- freemware/guest/virtcode/virtcode.c Mon Jan 17 14:41:37 2000
+++ freemware-jens/guest/virtcode/virtcode.c Tue Jan 18 15:44:30 2000
@@ -19,12 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/*
- * For now, we have this CPL3 task which doesn't do anything.
- * Just testing the interrupt redirection handling, and
- * host<-->monitor context switching mechanisms.
- */
-
asm (
".text; .globl _start \n"
"_start: \n"
@@ -38,117 +32,17 @@
);
-short *vidmem = (short *) 0xb8000;
-
-void
-printstr(char *text)
-{
- static int cursor = 0;
- int i = 0;
-
- while(text[i])
- {
- if(text[i] == '\n')
- {
- cursor = (cursor / 80 + 1) * 80;
- i++;
- continue;
- }
- vidmem[cursor++] = text[i++] | 0x0700; // 0x0f00 for bold
- cursor %= 80*25;
- }
-
- return;
-}
-
-void
-printint(int i)
-{
- char s[9];
- const char map[ ] = "0123456789abcdef";
- int j = 0;
-
- if(i&0xf0000000) s[j++] = map[(i>>28)&0xf];
- if(i&0xff000000) s[j++] = map[(i>>24)&0xf];
- if(i&0xfff00000) s[j++] = map[(i>>20)&0xf];
- if(i&0xffff0000) s[j++] = map[(i>>16)&0xf];
- if(i&0xfffff000) s[j++] = map[(i>>12)&0xf];
- if(i&0xffffff00) s[j++] = map[(i>>8)&0xf];
- if(i&0xfffffff0) s[j++] = map[(i>>4)&0xf];
- s[j++] = map[(i>>00)&0xf];
- s[j] = '\0';
-
- printstr(s);
-
- return;
-}
-
-int
-getkey(void)
-{
- int i;
-
- asm (
- " xorl %%eax, %%eax \n"
- " inb $0x64, %%al \n"
- " andb $0x01, %%al \n"
- " jz 2f \n"
- " inb $0x60, %%al \n"
- " movl %%eax, %0 \n"
- " inb $0x61, %%al \n"
- " movb %%al, %%ah \n"
- " orb $0x80, %%al \n"
- " outb %%al, $0x61 \n"
- " movb %%ah, %%al \n"
- " outb %%al, $0x61 \n"
- " jmp 3f \n"
- "2: movl $-1, %0 \n"
- "3: \n"
- : "=g" (i)
- :
- : "%eax"
- );
-
- return i;
-}
-
void
do_nothing(void)
{
int i;
- /* clear the screen */
-
- for(i=0; i<80*25; i++) vidmem[i] = 0;
-
- /* keyboard self test */
-
- while(getkey() != -1);
- asm (
- "xorl %%eax,%%eax \n"
- "movb $0xaa, %%al \n"
- "outb %%al, $0x64 \n"
- "inb $0x60, %%al \n"
- "movl %%eax, %0 \n"
- : "=g" (i)
- :
- : "%eax"
- );
-
- if(i != 0x55) {
- printstr("Error: keyboard self-test failed. Aborting...\n");
- return;
- }
-
+ if(init_keyboard()<0) return;
+ clear_screen();
/* we're go !! */
-
printstr("Hello, world !!\n\n");
printstr("Try pressing some keys...\n");
- while (1) {
- while((i=getkey())==-1);
- printstr("Received scancode: ");
- printint(i);
- printstr("\n");
- }
+ /* execute minishell; should never return */
+ minishell();
}