OSDN Git Service

First Commit
authorVOSystems <vosystems@users.sourceforge.jp>
Sun, 12 Apr 2015 14:31:52 +0000 (23:31 +0900)
committerVOSystems <vosystems@users.sourceforge.jp>
Sun, 12 Apr 2015 14:31:52 +0000 (23:31 +0900)
99 files changed:
Makefile [new file with mode: 0644]
after_proc.sh [new file with mode: 0644]
bin/2015-03-12-23-30-00.vsb [new file with mode: 0644]
bin/2015-03-12-23-31-08.vsb [new file with mode: 0644]
bin/2015-03-13-22-20-21.vsb [new file with mode: 0644]
bin/2015-03-13-22-33-29.vsb [new file with mode: 0644]
bin/2015-03-13-22-48-33.vsb [new file with mode: 0644]
bin/2015-03-14-15-00-41.vsb [new file with mode: 0644]
bin/2015-03-14-15-43-45.vsb [new file with mode: 0644]
bin/2015-03-15-00-32-13.vsb [new file with mode: 0644]
bin/2015-03-15-22-20-47.vsb [new file with mode: 0644]
bin/2015-03-24-23-50-14.vsb [new file with mode: 0644]
bin/2015-03-25-14-23-17.vsb [new file with mode: 0644]
bin/2015-03-26-00-28-30.vsb [new file with mode: 0644]
bin/2015-03-26-11-57-07.vsb [new file with mode: 0644]
bin/2015-03-28-00-06-08.vsb [new file with mode: 0644]
bin/2015-03-28-12-46-35.vsb [new file with mode: 0644]
bin/2015-03-28-23-16-14.vsb [new file with mode: 0644]
bin/2015-03-29-22-17-11.vsb [new file with mode: 0644]
bin/2015-03-30-08-53-17.vsb [new file with mode: 0644]
bin/2015-03-30-08-54-35.vsb [new file with mode: 0644]
bin/2015-03-31-00-02-24.vsb [new file with mode: 0644]
bin/2015-03-31-23-19-12.vsb [new file with mode: 0644]
bin/2015-03-31-23-22-17.vsb [new file with mode: 0644]
bin/2015-04-01-23-29-00.vsb [new file with mode: 0644]
bin/2015-04-04-00-43-00.vsb [new file with mode: 0644]
bin/2015-04-04-23-29-51.vsb [new file with mode: 0644]
bin/2015-04-12-23-20-39.vsb [new file with mode: 0644]
bin/2015-04-12-23-23-51.vsb [new file with mode: 0644]
drivers/Makefile [new file with mode: 0644]
drivers/dma/Makefile [new file with mode: 0644]
drivers/dma/dma.S [new file with mode: 0644]
drivers/dma/dma.c [new file with mode: 0644]
drivers/keyboard/Makefile [new file with mode: 0644]
drivers/keyboard/int.c [new file with mode: 0644]
drivers/keyboard/keyboard.c [new file with mode: 0644]
drivers/keyboard/scancode.c [new file with mode: 0644]
drivers/ramfs/Makefile [new file with mode: 0644]
drivers/ramfs/front.c [new file with mode: 0644]
drivers/ramfs/init.c [new file with mode: 0644]
drivers/ramfs/sys.c [new file with mode: 0644]
drivers/vga/Makefile [new file with mode: 0644]
drivers/vga/cursol.c [new file with mode: 0644]
drivers/vga/vga.c [new file with mode: 0644]
include/Diverge.h [new file with mode: 0644]
include/Diverge/Account.h [new file with mode: 0644]
include/Diverge/BitMap.h [new file with mode: 0644]
include/Diverge/Cursol.h [new file with mode: 0644]
include/Diverge/DivergeAPI.h [new file with mode: 0644]
include/Diverge/DrFS.h [new file with mode: 0644]
include/Diverge/descriptor.h [new file with mode: 0644]
include/Diverge/diverge.h [new file with mode: 0644]
include/Diverge/dksh.h [new file with mode: 0644]
include/Diverge/dmsg.h [new file with mode: 0644]
include/Diverge/env_var.h [new file with mode: 0644]
include/Diverge/interrupt.h [new file with mode: 0644]
include/Diverge/keyboard.h [new file with mode: 0644]
include/Diverge/kstdio.h [new file with mode: 0644]
include/Diverge/memory.h [new file with mode: 0644]
include/Diverge/multiboot.h [new file with mode: 0644]
include/Diverge/paging.h [new file with mode: 0644]
include/Diverge/proc.h [new file with mode: 0644]
include/Diverge/scancode.h [new file with mode: 0644]
include/Diverge/string.h [new file with mode: 0644]
include/Diverge/types.h [new file with mode: 0644]
include/string.h [new file with mode: 0644]
include/time.h [new file with mode: 0644]
kernel/Account.c [new file with mode: 0644]
kernel/BitMap.c [new file with mode: 0644]
kernel/DKsh.c [new file with mode: 0644]
kernel/DLKB.c [new file with mode: 0644]
kernel/DivergeAPI.c [new file with mode: 0644]
kernel/Makefile [new file with mode: 0644]
kernel/cpuinfo.c [new file with mode: 0644]
kernel/dmsg.c [new file with mode: 0644]
kernel/env.c [new file with mode: 0644]
kernel/init.c [new file with mode: 0644]
kernel/interrupt.c [new file with mode: 0644]
kernel/interrupt_gate.S [new file with mode: 0644]
kernel/io_cpu.S [new file with mode: 0644]
kernel/kernel.c [new file with mode: 0644]
kernel/kstdio.c [new file with mode: 0644]
kernel/load.S [new file with mode: 0644]
kernel/mbootinfo.c [new file with mode: 0644]
kernel/memory_map_diverge.txt [new file with mode: 0644]
kernel/paging.c [new file with mode: 0644]
kernel/physicalmem.c [new file with mode: 0644]
kernel/proc.c [new file with mode: 0644]
kernel/string.c [new file with mode: 0644]
kernel/task.S [new file with mode: 0644]
kernel/time.c [new file with mode: 0644]
kernel/tss.c [new file with mode: 0644]
lib/dma.lib [new file with mode: 0644]
lib/keyboard.lib [new file with mode: 0644]
lib/libosdk.a [new file with mode: 0644]
lib/link.ls [new file with mode: 0644]
lib/ramfs.lib [new file with mode: 0644]
lib/string.c [new file with mode: 0644]
lib/vga.lib [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..2a5f8b2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+all:
+       cd drivers; make drivers
+       cd kernel; make kernel
+       @echo " Make All is Successfully!!"
+       
+rebuild:
+       cd kernel; make rebuild
+       cd drivers; make drivers
+       @echo " Make ReBuild is Successfully!!"
+       
+clean::
+       bash ./after_proc.sh
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~
+       cd drivers; make clean
+       cd kernel; make clean
+       @echo " Make Clean is Successfully!!"
+
+start:
+       git pull origin diverge4
\ No newline at end of file
diff --git a/after_proc.sh b/after_proc.sh
new file mode 100644 (file)
index 0000000..81d2202
--- /dev/null
@@ -0,0 +1,3 @@
+#! /bin/sh
+day=`date '+%Y-%m-%d-%H-%M-%S'`
+mv ./kernel/Kernel.vsb ./bin/${day}.vsb
diff --git a/bin/2015-03-12-23-30-00.vsb b/bin/2015-03-12-23-30-00.vsb
new file mode 100644 (file)
index 0000000..80ea520
Binary files /dev/null and b/bin/2015-03-12-23-30-00.vsb differ
diff --git a/bin/2015-03-12-23-31-08.vsb b/bin/2015-03-12-23-31-08.vsb
new file mode 100644 (file)
index 0000000..80ea520
Binary files /dev/null and b/bin/2015-03-12-23-31-08.vsb differ
diff --git a/bin/2015-03-13-22-20-21.vsb b/bin/2015-03-13-22-20-21.vsb
new file mode 100644 (file)
index 0000000..80ea520
Binary files /dev/null and b/bin/2015-03-13-22-20-21.vsb differ
diff --git a/bin/2015-03-13-22-33-29.vsb b/bin/2015-03-13-22-33-29.vsb
new file mode 100644 (file)
index 0000000..ae7d9bc
Binary files /dev/null and b/bin/2015-03-13-22-33-29.vsb differ
diff --git a/bin/2015-03-13-22-48-33.vsb b/bin/2015-03-13-22-48-33.vsb
new file mode 100644 (file)
index 0000000..952fbab
Binary files /dev/null and b/bin/2015-03-13-22-48-33.vsb differ
diff --git a/bin/2015-03-14-15-00-41.vsb b/bin/2015-03-14-15-00-41.vsb
new file mode 100644 (file)
index 0000000..9dcc490
Binary files /dev/null and b/bin/2015-03-14-15-00-41.vsb differ
diff --git a/bin/2015-03-14-15-43-45.vsb b/bin/2015-03-14-15-43-45.vsb
new file mode 100644 (file)
index 0000000..7758884
Binary files /dev/null and b/bin/2015-03-14-15-43-45.vsb differ
diff --git a/bin/2015-03-15-00-32-13.vsb b/bin/2015-03-15-00-32-13.vsb
new file mode 100644 (file)
index 0000000..b2c87f3
Binary files /dev/null and b/bin/2015-03-15-00-32-13.vsb differ
diff --git a/bin/2015-03-15-22-20-47.vsb b/bin/2015-03-15-22-20-47.vsb
new file mode 100644 (file)
index 0000000..8360865
Binary files /dev/null and b/bin/2015-03-15-22-20-47.vsb differ
diff --git a/bin/2015-03-24-23-50-14.vsb b/bin/2015-03-24-23-50-14.vsb
new file mode 100644 (file)
index 0000000..96f2d42
Binary files /dev/null and b/bin/2015-03-24-23-50-14.vsb differ
diff --git a/bin/2015-03-25-14-23-17.vsb b/bin/2015-03-25-14-23-17.vsb
new file mode 100644 (file)
index 0000000..fedf7b8
Binary files /dev/null and b/bin/2015-03-25-14-23-17.vsb differ
diff --git a/bin/2015-03-26-00-28-30.vsb b/bin/2015-03-26-00-28-30.vsb
new file mode 100644 (file)
index 0000000..028fdd6
Binary files /dev/null and b/bin/2015-03-26-00-28-30.vsb differ
diff --git a/bin/2015-03-26-11-57-07.vsb b/bin/2015-03-26-11-57-07.vsb
new file mode 100644 (file)
index 0000000..e6b3996
Binary files /dev/null and b/bin/2015-03-26-11-57-07.vsb differ
diff --git a/bin/2015-03-28-00-06-08.vsb b/bin/2015-03-28-00-06-08.vsb
new file mode 100644 (file)
index 0000000..24b43d7
Binary files /dev/null and b/bin/2015-03-28-00-06-08.vsb differ
diff --git a/bin/2015-03-28-12-46-35.vsb b/bin/2015-03-28-12-46-35.vsb
new file mode 100644 (file)
index 0000000..4f6f7ad
Binary files /dev/null and b/bin/2015-03-28-12-46-35.vsb differ
diff --git a/bin/2015-03-28-23-16-14.vsb b/bin/2015-03-28-23-16-14.vsb
new file mode 100644 (file)
index 0000000..1bb0613
Binary files /dev/null and b/bin/2015-03-28-23-16-14.vsb differ
diff --git a/bin/2015-03-29-22-17-11.vsb b/bin/2015-03-29-22-17-11.vsb
new file mode 100644 (file)
index 0000000..18fd9b5
Binary files /dev/null and b/bin/2015-03-29-22-17-11.vsb differ
diff --git a/bin/2015-03-30-08-53-17.vsb b/bin/2015-03-30-08-53-17.vsb
new file mode 100644 (file)
index 0000000..8498dcd
Binary files /dev/null and b/bin/2015-03-30-08-53-17.vsb differ
diff --git a/bin/2015-03-30-08-54-35.vsb b/bin/2015-03-30-08-54-35.vsb
new file mode 100644 (file)
index 0000000..6df7e7b
Binary files /dev/null and b/bin/2015-03-30-08-54-35.vsb differ
diff --git a/bin/2015-03-31-00-02-24.vsb b/bin/2015-03-31-00-02-24.vsb
new file mode 100644 (file)
index 0000000..7a1a565
Binary files /dev/null and b/bin/2015-03-31-00-02-24.vsb differ
diff --git a/bin/2015-03-31-23-19-12.vsb b/bin/2015-03-31-23-19-12.vsb
new file mode 100644 (file)
index 0000000..d84486e
Binary files /dev/null and b/bin/2015-03-31-23-19-12.vsb differ
diff --git a/bin/2015-03-31-23-22-17.vsb b/bin/2015-03-31-23-22-17.vsb
new file mode 100644 (file)
index 0000000..a4f343c
Binary files /dev/null and b/bin/2015-03-31-23-22-17.vsb differ
diff --git a/bin/2015-04-01-23-29-00.vsb b/bin/2015-04-01-23-29-00.vsb
new file mode 100644 (file)
index 0000000..6d52e12
Binary files /dev/null and b/bin/2015-04-01-23-29-00.vsb differ
diff --git a/bin/2015-04-04-00-43-00.vsb b/bin/2015-04-04-00-43-00.vsb
new file mode 100644 (file)
index 0000000..c825e6e
Binary files /dev/null and b/bin/2015-04-04-00-43-00.vsb differ
diff --git a/bin/2015-04-04-23-29-51.vsb b/bin/2015-04-04-23-29-51.vsb
new file mode 100644 (file)
index 0000000..ffca6d6
Binary files /dev/null and b/bin/2015-04-04-23-29-51.vsb differ
diff --git a/bin/2015-04-12-23-20-39.vsb b/bin/2015-04-12-23-20-39.vsb
new file mode 100644 (file)
index 0000000..f1c0235
Binary files /dev/null and b/bin/2015-04-12-23-20-39.vsb differ
diff --git a/bin/2015-04-12-23-23-51.vsb b/bin/2015-04-12-23-23-51.vsb
new file mode 100644 (file)
index 0000000..f1c0235
Binary files /dev/null and b/bin/2015-04-12-23-23-51.vsb differ
diff --git a/drivers/Makefile b/drivers/Makefile
new file mode 100644 (file)
index 0000000..05d1aca
--- /dev/null
@@ -0,0 +1,23 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} drivers
+
+drivers:
+       cd dma; make dma
+       cd keyboard; make keyboard
+       cd ramfs; make ramfs
+       cd vga; make vga
+       @echo "  Make Drivers Succcessfully!!"
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~
+       cd dma; make clean
+       cd keyboard; make clean
+       cd ramfs; make clean
+       cd vga; make clean
+       @echo "  Make Drivers Clean Succcessfully!!"
+       
\ No newline at end of file
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
new file mode 100644 (file)
index 0000000..b685a40
--- /dev/null
@@ -0,0 +1,56 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+
+#Target
+DMA_LIB        = ${LIBDIR}/dma.lib
+
+# Define
+RM     = /bin/rm
+CC     = gcc
+AS     = ${CC}
+LD     = ld
+OBJCOPY        = objcopy
+
+AR     = ar
+
+ARFLAG = rcs
+CFLAG  = -m32 -ffreestanding -fno-common -masm=intel -nostdlib -fno-builtin -fomit-frame-pointer -O2 -c
+AFLAG  = -m32 -ffreestanding -fno-common -fno-builtin -fomit-frame-pointer -O2 -c
+LFLAG  = -Ttext 0x100000 -melf_i386 --oformat elf32-i386 -o
+#-T link.ls -melf-i386 --oformat elf32-i386 -o
+
+INCLUDE        = -I${INCDIR}
+
+# Dir
+INCDIR = ../../include
+LIBDIR = ../../lib
+
+# Sufix
+.c.o:
+       ${CC} ${INCLUDE} ${CFLAG} $<
+       
+.S.o:
+       ${AS} ${INCLUDE} ${AFLAG} $<
+       
+# Sources_C
+DMA_C  = dma.c
+# Source_ASM
+DMA_S  = dma.S
+
+DMA_OBJ=${DMA_C:.c=.o} ${DMA_S:.S=.o}
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} dma
+
+dma:
+       ${MAKE} ${DMA_LIB}
+       @echo "  Make DMA Driver Succcessfully!!"
+       
+${DMA_LIB}:${DMA_OBJ}
+       ${AR} ${ARFLAG} ${DMA_LIB} ${DMA_OBJ}
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~ *.lib
diff --git a/drivers/dma/dma.S b/drivers/dma/dma.S
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/drivers/dma/dma.c b/drivers/dma/dma.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/drivers/keyboard/Makefile b/drivers/keyboard/Makefile
new file mode 100644 (file)
index 0000000..44d7a46
--- /dev/null
@@ -0,0 +1,57 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+
+#Target
+KBD_LIB        = ${LIBDIR}/keyboard.lib
+
+# Define
+RM     = /bin/rm
+CC     = gcc
+AS     = ${CC}
+LD     = ld
+OBJCOPY        = objcopy
+
+AR     = ar
+
+ARFLAG = rcs
+CFLAG  = -m32 -ffreestanding -fno-common -masm=intel -nostdlib -fno-builtin -fomit-frame-pointer -O2 -c
+AFLAG  = -m32 -ffreestanding -fno-common -fno-builtin -fomit-frame-pointer -O2 -c
+LFLAG  = -Ttext 0x100000 -melf_i386 --oformat elf32-i386 -o
+#-T link.ls -melf-i386 --oformat elf32-i386 -o
+
+INCLUDE        = -I${INCDIR}
+
+# Dir
+INCDIR = ../../include
+LIBDIR = ../../lib
+
+# Sufix
+.c.o:
+       ${CC} ${INCLUDE} ${CFLAG} $<
+       
+.S.o:
+       ${AS} ${INCLUDE} ${AFLAG} $<
+       
+# Sources_C
+INT_C  = int.c
+KBD_C  = keyboard.c
+SC_C   = scancode.c
+# Source_ASM
+
+KBD_OBJ=${INT_C:.c=.o} ${KBD_C:.c=.o} ${SC_C:.c=.o}
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} keyboard
+
+keyboard:
+       ${MAKE} ${KBD_LIB}
+       @echo "  Make Keyboard Driver Succcessfully!!"
+       
+${KBD_LIB}:${KBD_OBJ}
+       ${AR} ${ARFLAG} ${KBD_LIB} ${KBD_OBJ}
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~ *.lib
diff --git a/drivers/keyboard/int.c b/drivers/keyboard/int.c
new file mode 100644 (file)
index 0000000..3f01464
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+       int.c
+       Interrupt Handler C
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/interrupt.h>
+#include<Diverge/scancode.h>
+#include<Diverge/keyboard.h>
+#include<Diverge.h>
+
+extern DHANDLE kbdHandle;
+extern bool ex_keycode_flag;
+
+void keyboard_int_handler(void)
+{
+       unsigned char sc=readKbdEncBuffer();
+       
+       /*Make Shift*/
+       if(sc==SC_RIGHT_SHIFT || sc==SC_LEFT_SHIFT){
+               keyboard.shift=true;
+               
+       /*Make Ctrl*/
+       }else if(sc==SC_LEFT_CTRL){
+               keyboard.ctrl=true;
+               
+       /*Break Shift*/
+       }else if(sc==BREAK_NORMAL(SC_RIGHT_SHIFT) || sc==BREAK_NORMAL(SC_LEFT_SHIFT)){
+               keyboard.shift=false;
+               
+       /*Break Ctrl*/
+       }else if(sc==BREAK_NORMAL(SC_LEFT_CTRL)){
+               keyboard.ctrl=false;
+               
+       /*Num Lock*/
+       }else if(sc==SC_NUM_LOCK){
+               ChangeKeyboardState(2);
+               
+       /*Scroll Lock*/
+       }else if(sc==SC_SCR){
+               ChangeKeyboardState(1);
+               
+       /*Caps Lock*/
+       }else if(sc==SC_CAPS && keyboard.shift==true){
+               ChangeKeyboardState(0);
+               
+       /*Extension Flag*//*
+       }else if(sc==EX_FLAG || ex_keycode_flag==true){
+               ExKey(sc);
+               */
+       }else{
+               EnqDMsgQ(sc, kbdHandle);
+       }
+}
\ No newline at end of file
diff --git a/drivers/keyboard/keyboard.c b/drivers/keyboard/keyboard.c
new file mode 100644 (file)
index 0000000..1e13138
--- /dev/null
@@ -0,0 +1,272 @@
+/*
+       keyboard.c
+       Keyboard Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/keyboard.h>
+#include<Diverge/types.h>
+#include<Diverge/dmsg.h>
+#include<Diverge.h>
+
+KeyBoard_Status keyboard;
+int keyboard_disable;
+DHANDLE kbdHandle,exKeyHandle;
+bool ex_keycode_flag;
+
+void init_keyboard(void)
+{
+       keyboard.caps_lock=false;
+       keyboard.scr_lock=false;
+       keyboard.num_lock=false;
+       
+       keyboard.shift=false;
+       keyboard.insert=false;
+       keyboard.ctrl=false;
+       keyboard.alt=false;
+       keyboard.windows=false;
+       
+       keyboard.pgdn=false;
+       keyboard.pgup=false;
+       keyboard.end=false;
+       keyboard.home=false;
+       keyboard.del=false;
+       
+       keyboardSetLED(E_KBD_NONE_LED);
+       keyboardEnableKBD();
+       CreateDMsgQ(kbdHandle);
+       CreateDMsgQ(exKeyHandle);
+       
+       ex_keycode_flag=false;
+}
+
+void fin_keyboard(void)
+{
+       printTASK("Removing Scan Code Queue");LoadingPromptSec(1);
+       DestroyDMsgQ(kbdHandle);
+       printOK("Removing Scan Code Queue");
+       
+       printTASK("Removing Extension Key Code Queue");LoadingPromptSec(1);
+       DestroyDMsgQ(exKeyHandle);
+       printOK("Removing Extension Key Code Queue");
+}
+
+/*Key Board Status Change 0->Caps, 1->Scroll, 2->Num*/
+void ChangeKeyboardState(char ch)
+{
+       E_KBD_LED led=E_KBD_NONE_LED;
+       switch(ch){
+               case 0:
+                       if(keyboard.num_lock==true && keyboard.scr_lock==true){
+                               led=E_KBD_NUM_LOCK_LED | E_KBD_SCROLL_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==true && keyboard.scr_lock==false){
+                               led=E_KBD_NUM_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==false && keyboard.scr_lock==true){
+                               led=E_KBD_SCROLL_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==false && keyboard.scr_lock==false){
+                               led=E_KBD_NONE_LED;
+                               
+                       }
+                       
+                       if(keyboard.caps_lock==true){
+                               keyboard.caps_lock=false;
+                               
+                       }else{
+                               keyboard.caps_lock=true;
+                               led |= E_KBD_CAPS_LOCK_LED;
+                       }
+                       break;
+                       
+               case 1:
+                       if(keyboard.num_lock==true && keyboard.caps_lock==true){
+                               led=E_KBD_NUM_LOCK_LED | E_KBD_CAPS_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==true && keyboard.caps_lock==false){
+                               led=E_KBD_NUM_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==false && keyboard.caps_lock==true){
+                               led=E_KBD_CAPS_LOCK_LED;
+                               
+                       }else if(keyboard.num_lock==false && keyboard.caps_lock==false){
+                               led=E_KBD_NONE_LED;
+                               
+                       }
+                       
+                       if(keyboard.scr_lock==true){
+                               keyboard.scr_lock=false;
+                               
+                       }else{
+                               keyboard.scr_lock=true;
+                               led |= E_KBD_SCROLL_LOCK_LED;
+                       }
+                       break;
+                       
+               case 2:
+                       if(keyboard.caps_lock==true && keyboard.scr_lock==true){
+                               led=E_KBD_CAPS_LOCK_LED | E_KBD_SCROLL_LOCK_LED;
+                               
+                       }else if(keyboard.caps_lock==true && keyboard.scr_lock==false){
+                               led=E_KBD_CAPS_LOCK_LED;
+                               
+                       }else if(keyboard.caps_lock==false && keyboard.scr_lock==true){
+                               led=E_KBD_SCROLL_LOCK_LED;
+                               
+                       }else if(keyboard.caps_lock==false && keyboard.scr_lock==false){
+                               led=E_KBD_NONE_LED;
+                               
+                       }
+                       
+                       if(keyboard.num_lock==true){
+                               keyboard.num_lock=false;
+                               
+                       }else{
+                               keyboard.num_lock=true;
+                               led |= E_KBD_NUM_LOCK_LED;
+                       }
+                       break;
+       }
+       keyboardSetLED(led);
+       
+}
+
+unsigned char readKbdCtrlStatus(void)
+{
+       return(io_in8(PORT_KBD_CTRL_STATUS));
+}
+
+int writeKbdCtrlCommand(unsigned char command)
+{
+       int retry;
+       
+       for(retry=0;retry<MAX_RETRY;++retry)
+       {
+               if((readKbdCtrlStatus() & KBD_STS_IBF)==0)
+               {
+                       io_out8(PORT_KBD_CTRL_COMMAND,command);
+                       return KBD_OK;
+               }
+       }
+       return KBD_ERROR;
+}
+
+unsigned char readKbdEncBuffer(void)
+{
+       return(io_in8(PORT_KBD_ENC_BUFFER));
+}
+
+int writeKbdEncCommand(unsigned char command)
+{
+       int retry;
+       
+       for(retry=0;retry<MAX_RETRY;++retry)
+       {
+               if((readKbdCtrlStatus() & KBD_STS_IBF)==0)
+               {
+                       io_out8(PORT_KBD_ENC_COMMAND,command);
+                       return KBD_OK;
+               }
+       }
+       return KBD_ERROR;
+}
+
+int keyboardSetLED(E_KBD_LED led)
+{
+    unsigned char wirte_data;
+       int status;
+       
+       /*if designated leds are unknow*/
+       if((E_KBD_SCROLL_LOCK_LED | E_KBD_NUM_LOCK_LED | E_KBD_CAPS_LOCK_LED) < led)
+       {
+               return(KBD_ERROR);
+       }
+
+       status =  writeKbdEncCommand(KBD_ENC_COM_SETLED);
+       status |= writeKbdEncCommand((unsigned char)led);
+
+       return(status);
+}
+
+int keyboardSelfTest(void)
+{
+       unsigned char enc_buffer;
+       int status;
+    
+       /* execute self test*/
+       status = writeKbdCtrlCommand(KBD_CTRL_COM_SELF_TEST);
+
+       if(KBD_OK != status)
+       {
+               return(status);
+       }
+
+       /*wait*/
+       status = waitKbdOutputBufferFull();
+
+       if(KBD_OK != status)
+       {
+               return(status);
+       }
+
+       /*test result of self test*/
+       enc_buffer = readKbdEncBuffer();
+
+       if(enc_buffer==KBD_CTRL_STS_SELF_TEST_OK)
+       {
+               return(status);
+       }
+
+       return(KBD_ERROR);
+}
+
+int waitKbdOutputBufferFull(void)
+{
+       unsigned char kbd_status;
+       int retry;
+
+       for(retry=0; retry<MAX_RETRY; retry++)
+       {
+               kbd_status = readKbdCtrlStatus();
+
+               if((kbd_status & KBD_STS_OBF)==KBD_STS_OBF)
+               {
+                       return(KBD_OK);
+               }
+       }
+
+       return(KBD_ERROR);
+}
+
+int keyboardDisableKBD(void)
+{
+       /*disable a keyboard*/
+       int status = writeKbdCtrlCommand(KBD_CTRL_COM_DISABLE_KBD);
+
+       if(KBD_OK != status){
+               keyboard_disable = 0;
+               
+       }else{
+       keyboard_disable = 1;
+       
+       }
+
+       return(status);
+}
+
+int keyboardEnableKBD(void)
+{
+       /*enable a keyboard*/
+       int status = writeKbdCtrlCommand(KBD_CTRL_COM_ENABLE_KBD);
+
+       if(KBD_OK != status){
+               keyboard_disable = 1;
+               
+       }else{
+               keyboard_disable = 0;
+        
+       }
+
+       return(status);
+}
diff --git a/drivers/keyboard/scancode.c b/drivers/keyboard/scancode.c
new file mode 100644 (file)
index 0000000..583dcfe
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+       scancode.c
+       Scancode Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/scancode.h>
+#include<Diverge/keyboard.h>
+#include<Diverge/interrupt.h>
+#include<Diverge/dmsg.h>
+
+extern DHANDLE kbdHandle,exKeyHandle;
+extern bool ex_keycode_flag;
+
+unsigned char Generate_Scancode_To_ASCII_Code(void)
+{
+       unsigned char scode=DeqDMsgQ(kbdHandle);
+       static unsigned char un_shift_keytable[0x80]={
+               0,0,'1','2','3','4','5','6','7','8','9','0','-','^','\b','\t',
+               'q','w','e','r','t','y','u','i','o','p','@','[','\n',0,'a','s',
+               'd','f','g','h','j','k','l',';',':',0,0,']','z','x','c','v',
+               'b','n','m',',','.','/',0,'*',0,' ',0,0,0,0,0,0,
+               0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
+               '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+               '\\',0,0,0,0,0,0,0,0,0,'\\',0,0
+       };
+       static unsigned char shift_keytable[0x80]={
+               0,0,'!','\"','#','$','%','&','\'','(',')','~','=','~','\b','\t',
+               'Q','W','E','R','T','Y','U','I','O','P','`','{','\n',0,'A','S',
+               'D','F','G','H','J','K','L','+','*',0,0,'}','Z','X','C','V',
+               'B','N','M','<','>','?',0,'*',0,' ',0,0,0,0,0,0,
+               0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
+               '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+               '_',0,0,0,0,0,0,0,0,0,'|',0,0
+       };
+       
+       if(scode==0xe0){
+               ex_keycode_flag=true;
+               return 0;
+       }else if(ex_keycode_flag==true){
+               char ret=0;
+               switch(scode){
+                       case 0x1c:
+                               ret='\n';
+                               break;
+                       case 0x1d:
+                               keyboard.ctrl=true;
+                               break;
+                       case 0x35:
+                               ret='/';
+                               break;
+                       case 0x37:
+                               break;
+                       case 0x38:
+                               keyboard.alt=true;
+                               break;
+                       case 0x46:
+                       case 0x47:
+                       case 0x48:
+                       case 0x49:
+                       case 0x4b:
+                       case 0x4d:
+                       case 0x4f:
+                       case 0x50:
+                       case 0x51:
+                       case 0x52:
+                       case 0x53:
+                       case 0x5b:
+                               break;
+                       case 0x5c:
+                               keyboard.windows=true;
+                               break;
+                       case 0x5d:
+                       default:
+                               break;
+               }
+               ex_keycode_flag=false;
+               return ret;
+               
+       }else if(scode>0x80){
+               return 0;
+       }
+       
+       if(keyboard.shift==true){
+               if(keyboard.caps_lock==true){
+                       return un_shift_keytable[scode];
+                       
+               }else{
+                       return shift_keytable[scode];
+               }
+       }else{
+               if(keyboard.caps_lock==true){
+                       return shift_keytable[scode];
+                       
+               }else{
+                       return un_shift_keytable[scode];
+               }       
+       }
+}
diff --git a/drivers/ramfs/Makefile b/drivers/ramfs/Makefile
new file mode 100644 (file)
index 0000000..5a13963
--- /dev/null
@@ -0,0 +1,57 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+
+#Target
+RAMFS_LIB      = ${LIBDIR}/ramfs.lib
+
+# Define
+RM     = /bin/rm
+CC     = gcc
+AS     = ${CC}
+LD     = ld
+OBJCOPY        = objcopy
+
+AR     = ar
+
+ARFLAG = rcs
+CFLAG  = -m32 -ffreestanding -fno-common -masm=intel -nostdlib -fno-builtin -fomit-frame-pointer -O2 -c
+AFLAG  = -m32 -ffreestanding -fno-common -fno-builtin -fomit-frame-pointer -O2 -c
+LFLAG  = -Ttext 0x100000 -melf_i386 --oformat elf32-i386 -o
+#-T link.ls -melf-i386 --oformat elf32-i386 -o
+
+INCLUDE        = -I${INCDIR}
+
+# Dir
+INCDIR = ../../include
+LIBDIR = ../../lib
+
+# Sufix
+.c.o:
+       ${CC} ${INCLUDE} ${CFLAG} $<
+       
+.S.o:
+       ${AS} ${INCLUDE} ${AFLAG} $<
+       
+# Sources_C
+INIT_C = init.c
+FRONT_C        = front.c
+SYS_C  = sys.c
+# Source_ASM
+
+RAMFS_OBJ=${INIT_C:.c=.o} ${FRONT_C:.c=.o} ${SYS_C:.c=.o}
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} ramfs
+
+ramfs:
+       ${MAKE} ${RAMFS_LIB}
+       @echo "  Make RamFS Driver Succcessfully!!"
+       
+${RAMFS_LIB}:${RAMFS_OBJ}
+       ${AR} ${ARFLAG} ${RAMFS_LIB} ${RAMFS_OBJ}
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~ *.lib
diff --git a/drivers/ramfs/front.c b/drivers/ramfs/front.c
new file mode 100644 (file)
index 0000000..5cb57f8
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+       front.c
+       DrFS Front End
+       (C) 2015 VOSystems.
+*/
+
+#include<Diverge/DrFS.h>
+#include<Diverge/kstdio.h>
+#include<string.h>
+#include<Diverge/diverge.h>
+#include<Diverge/BitMap.h>
+#include<Diverge/dksh.h>
+
+extern struct fnode *cdir;
+extern struct DrFS_Prefix* drfs;
+extern unsigned long map[64];
+
+int ListFiles(int mode)
+{
+       FSDirPointer fsd=(FSDirPointer)cdir->tnp;
+       struct fnode* node;
+       struct faright right;
+       int C;
+       
+       if(cdir->level==0){
+               for(C=0; C<128; C++){
+                       if(fsd[C]==0)break;
+                       node=(struct fnode*)fsd[C];
+                       right=CheckObjectRight(node);
+                       if(right.hide!=true || mode==1){
+                               PrintFileList(right, node, mode);
+                       }
+               }
+       }else{
+               
+       }
+       return 0;
+}
+
+//0 ->正常, -1 ->異常
+int MakeFile(char* name, unsigned short ar, unsigned int uid, unsigned int gid, unsigned int pid)
+{
+       bool error;
+       
+       ar |= 0x40; //11111111
+       
+       struct fnode* node=MakeObject(name,ar,uid,gid,pid,&error);
+       if(error==true){
+               return -1;
+       }
+       
+       return 0;
+}
+
+int ktouch(const char* name)
+{
+       return MakeFile(name, cdir->attribute, cdir->uid, cdir->gid, cdir->id);
+}
+
+//0 ->正常, -1 ->異常
+int MakeDir(char* name, unsigned short ar, unsigned int uid, unsigned int gid, unsigned int pid)
+{
+       bool error;
+       
+       struct fnode* node=MakeObject(name,ar,uid,gid,pid,&error);
+       if(error==true){
+               return -1;
+       }
+       
+       FSDirPointer sec=(FSDirPointer)node->tnp;
+       sec[0]=(unsigned int)node;
+       sec[1]=(unsigned int)pid;
+       
+       return 0;
+}
+
+int kmkdir(char* name)
+{
+       return MakeDir(name, cdir->attribute, cdir->uid, cdir->gid, cdir->id);
+}
+
+
+int ShowFile(const char *name)
+{
+       bool error=false;
+       struct fnode* node=SearchObjectFromCDir(name, 1, &error);
+       if(error==true)return -1;
+       
+}
+
+int ChangeDir(char* name, char* current_dir, bool* error)
+{
+       struct fnode* node=cdir;
+       *error=false;
+       if(strcmp(name,"/")==0){
+               cdir=drfs->root_fnode_addr;
+               strcpy(current_dir,"/");
+               
+       }else if(strcmp(name,".")==0){
+               
+       }else if(strcmp(name,"..")==0){
+               cdir=cdir->pid;
+               StringBreak(current_dir,'/');
+               if(cdir->id==drfs->root_fnode_addr)StringConnect(current_dir,"/");
+               
+       }else{
+               int C=0;
+               do{
+                       cdir=SearchObjectFromCDir(name,0,error);
+                       C++;
+               }while(*error==true && C<0xff);
+               if(*error!=true){
+                       if(node->id!=drfs->root_fnode_addr)StringConnect(current_dir,"/");
+                       StringConnect(current_dir,cdir->name);
+               }
+       }
+       
+       if(*error==true){
+               cdir=node;
+               return -1;
+       }else{
+               return 0;
+       }
+}
\ No newline at end of file
diff --git a/drivers/ramfs/init.c b/drivers/ramfs/init.c
new file mode 100644 (file)
index 0000000..a5b5a76
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+       init.c
+       DrFS Init
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/DrFS.h>
+#include<Diverge/kstdio.h>
+#include<string.h>
+#include<Diverge/diverge.h>
+#include<Diverge/BitMap.h>
+#include<Diverge/dksh.h>
+
+struct fnode *cdir;
+struct DrFS_Prefix* drfs;
+unsigned long map[64];
+
+void init_DrFS(void)
+{
+       /*Prefix*/
+       printTASK("Unpacking DrFS");
+       drfs=(struct DrFS_Prefix*)FS_PREFIX_ADDR;
+       strcpy(drfs->sign, "DivergeRamFileSystem");
+       drfs->sector_size=512;
+       drfs->root_fnode_addr=NULL;
+       drfs->fs_size=(pc.mem.size-(FS_START_ADDR/(1024*1024)))*(4/5);
+       drfs->sector_count=64*32;
+       printOK("Unpacking DrFS");      
+       
+       unsigned int C;
+       for(C=0; C<64; C++){
+               map[C]=0;
+       }
+       
+       /*Root*/
+       printTASK("Setting Root Dir");
+       bool error;
+       struct fnode* node=(struct fnode*)SearchSectorPysicalMemory(&error);
+       if(error==true){
+               printFAIL("Setting Root Dir : Memory space was unable to get for Fnode.");
+               printFAIL("Unpackint DrFS is Fail");
+               return;
+       }
+       SectorCleanUp((unsigned int)node);
+       
+       error=false;
+       unsigned int sector=SearchSectorPysicalMemory(&error);
+       if(error==true){
+               printFAIL("Setting Root Dir : Memory space was unable to get for Sector.");
+               printFAIL("Unpackint DrFS is Fail");
+               return;
+       }
+       SectorCleanUp(sector);
+       
+       strcpy(node->name,"/");
+       node->attribute=0x2fc0;
+       node->uid=0;
+       node->gid=GID_ROOT;
+       node->pid=(unsigned int)node;
+       node->id=(unsigned int)node;
+       node->fsize=0;
+       node->level=0;
+       node->tnp=sector;
+       time_t now=time(NULL);
+       node->create=now;
+       node->rewrite=now;
+       node->access=now;
+       
+       FSDirPointer sec=(FSDirPointer)sector;
+       sec[0]=(unsigned int)node->id;
+       
+       drfs->root_fnode_addr=node->id;
+       printOK("Setting Root Dir");
+       
+       cdir=node;
+       
+       error=false;
+       
+       char cdir_tmp[0xff]={cdir->name};
+       
+       /*System Dir*/
+       printTASK("Setting Dir");
+       if(kmkdir("Diverge")==-1){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Config")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Programs")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Shell")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Device")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("home")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       
+       /*Diverge's Sub Dir*/
+       if(ChangeDir("Diverge",cdir_tmp,&error)==-1){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Kernel")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Divergence")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Log")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Tmp")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("DivPkg")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Config")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       
+       /*Diverge/Divergence's Sub Dir*/
+       if(ChangeDir("Divergence",cdir_tmp,&error)==-1){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("DShell")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       if(kmkdir("Cmd")!=0){
+               printFAIL("Setting Dir");
+               return;
+       }
+       
+       cdir=node;
+       
+       printOK("Setting Dir");
+}
\ No newline at end of file
diff --git a/drivers/ramfs/sys.c b/drivers/ramfs/sys.c
new file mode 100644 (file)
index 0000000..fac918d
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+       sys.c
+       DrFS System
+       (C) 2015 VOSystems.
+*/
+
+#include<Diverge/DrFS.h>
+#include<Diverge/kstdio.h>
+#include<string.h>
+#include<Diverge/diverge.h>
+#include<Diverge/BitMap.h>
+#include<Diverge/dksh.h>
+
+extern struct fnode *cdir;
+extern struct DrFS_Prefix* drfs;
+extern unsigned long map[64];
+
+/*セクタのクリーンアップ 引数:セクタのアドレス*/
+void SectorCleanUp(unsigned int sector)
+{
+       FSDirPointer fsd=(FSDirPointer)sector;
+       int C;
+       for(C=0; C<128; C++){
+               fsd[C]=0;
+       }
+       return;
+}
+
+unsigned int SearchObjectFromCDir(char* name, char mode, bool *error)
+{
+       *error=true;
+       unsigned int C,ret;
+       FSDirPointer dp=(FSDirPointer)cdir->tnp;
+       struct fnode* node;
+       
+       for(C=0; C<128; C++){
+               if(cdir->level==0){
+                       node=(struct fnode*)dp[C];
+                       if(strcmp(node->name,name)==0){
+                               struct faright right=CheckObjectRight(node);
+                               
+                               if(right.dir==mode){
+                                       ret=dp[C];
+                                       *error=false;
+                                       break;
+                               }
+                       }
+               }else{
+                       
+               }
+       }
+       return ret;
+}
+
+//正常->作成したオブジェクトのfnodeポインタ 異常->NULL & *error==true
+struct fnode* MakeObject(char* name, unsigned short ar, unsigned int uid, unsigned int gid, unsigned int pid, bool *error)
+{
+       *error=false;
+       struct fnode* node=(struct fnode*)SearchSectorPysicalMemory(error);
+       if(*error==true)return NULL;
+       SectorCleanUp((unsigned int)node);
+       
+       *error=false;
+       unsigned int sector=SearchSectorPysicalMemory(error);
+       if(*error==true)return NULL;
+       SectorCleanUp(sector);
+       
+       time_t timer=time(NULL);
+       
+       strcpy(node->name,name);
+       node->attribute=ar;
+       node->uid=uid;
+       node->gid=gid;
+       node->pid=pid;
+       node->id=(unsigned int)node;
+       node->fsize=0;
+       node->level=0;
+       node->tnp=sector;
+       node->create=timer;
+       node->rewrite=timer;
+       node->access=timer;
+       
+       struct fnode* parent=(struct fnode*)pid;
+       FSDirPointer sec=(FSDirPointer)parent->tnp;
+       int C;
+       
+       *error=false;
+       
+       if(parent->level==0){
+               *error=true;
+               for(C=0; C<128; C++){
+                       if(sec[C]==0){
+                               sec[C]=node->id;
+                               *error=false;
+                               break;
+                       }
+               }
+               if(*error==true)return NULL;
+       }else{
+               /*セクタ段数が0じゃない時の開いているセクタポインタを探すロジック、あとで実装する。*/
+       }
+       parent->fsize+=4;
+       
+       return node;
+}
+
+unsigned int SectorSearch(bool *error)
+{
+       unsigned int C,bit=0xffffffff;
+       *error=false;
+       
+       for(C=0; C<64; C++){
+               bit=SearchEmptyBit(&map[C]);
+               if(bit!=0xffffffff){
+                       break;
+               }
+       }
+       if(bit==0xffffffff){
+               *error=true;
+               return 0;
+       }
+       ReserveBit(&map[C], bit);
+       return (C*32)+bit;
+}
+
+struct faright CheckObjectRight(const struct fnode* node)
+{
+       struct faright right;
+       unsigned short ar=node->attribute;
+       
+       struct tm* temp=localtime(&node->create);
+       right.create_time=*temp;
+       
+       temp=localtime(&node->rewrite);
+       right.rewrite_time=*temp;
+       
+       temp=localtime(&node->access);
+       right.access_time=*temp;
+       
+       if((ar & 0x8000)==0){
+               right.dir=0;
+       }else{
+               right.dir=1;
+       }
+       
+       if((ar & 0x4000)!=0){
+               right.hide=true;
+       }else{
+               right.hide=false;
+       }
+       
+       if((ar & 0x2000)!=0){
+               right.sys=true;
+       }else{
+               right.sys=false;
+       }
+       
+       if((ar & 0x1000)!=0){
+               right.tmp=true;
+       }else{
+               right.tmp=false;
+       }
+       
+       if((ar & 0xc00)==0xc00){
+               right.user_right=3;
+       }else if((ar & 0xc00)==0x800){
+               right.user_right=2;
+       }else if((ar & 0xc00)==0x400){
+               right.user_right=1;
+       }else{
+               right.user_right=0;
+       }
+       
+       if((ar & 0x300)==0x300){
+               right.group_right=3;
+       }else if((ar & 0x300)==0x200){
+               right.group_right=2;
+       }else if((ar & 0x300)==0x100){
+               right.group_right=1;
+       }else{
+               right.group_right=0;
+       }
+       
+       if((ar & 0xc0)==0xc0){
+               right.others_right=3;
+       }else if((ar & 0xc0)==0x80){
+               right.others_right=2;
+       }else if((ar & 0xc0)==0x40){
+               right.others_right=1;
+       }else{
+               right.others_right=0;
+       }
+       
+       if(node->id==cdir->id){
+               right.flag=0;
+       }else if(node->id==cdir->pid){
+               right.flag=1;
+       }else{
+               right.flag=2;
+       }
+       
+       right.uid=node->uid;
+       switch(right.uid){
+               case 0:
+                       right.gid=GID_ROOT;
+                       break;
+               case 1:
+                       right.gid=GID_ADMIN;
+                       break;
+               case 2:
+                       right.gid=GID_USER;
+                       break;
+               default:
+                       right.gid=0xffffffff;
+       }
+       
+       return right;
+}
+
+unsigned int SearchSectorPysicalMemory(bool* error)
+{
+       unsigned int bit;
+       bit=SectorSearch(error);
+       if(*error==true)return NULL;
+       bit=(drfs->sector_size*bit)+FS_START_ADDR+1;
+       return bit;
+}
+
+void PrintFileList(struct faright right, struct fnode* node, int mode)
+{
+       switch(mode){
+               case 0:
+                       switch(right.flag){
+                               case 0:
+                                       kputs(".\n");
+                                       break;
+                               case 1:
+                                       kputs("..\n");
+                                       break;
+                               default:
+                                       kprintf("%s\n",node->name);
+                                       break;
+                       }
+                       break;
+               case 1:
+                       switch(right.dir){
+                               case 0:
+                                       kputs("d");
+                                       break;
+                               default:
+                                       kputs("f");
+                                       break;
+                       }
+                       switch(right.hide){
+                               case true:
+                                       kputs("h");
+                                       break;
+                               default:
+                                       kputs("-");
+                       }
+                       switch(right.sys){
+                               case true:
+                                       kputs("s");
+                                       break;
+                               default:
+                                       kputs("-");
+                                       break;
+                       }
+                       switch(right.tmp){
+                               case true:
+                                       kputs("t");
+                                       break;
+                               default:
+                                       kputs("-");
+                                       break;
+                       }
+                       switch(right.user_right){
+                               case 0:
+                                       kputs("-");
+                                       break;
+                               case 1:
+                                       kputs("r");
+                                       break;
+                               case 2:
+                                       kputs("w");
+                                       break;
+                               case 3:
+                                       kputs("a");
+                                       break;
+                               default:
+                                       kputs("?");
+                                       break;
+                       }
+                       switch(right.group_right){
+                               case 0:
+                                       kputs("-");
+                                       break;
+                               case 1:
+                                       kputs("r");
+                                       break;
+                               case 2:
+                                       kputs("w");
+                                       break;
+                               case 3:
+                                       kputs("a");
+                                       break;
+                               default:
+                                       kputs("?");
+                                       break;
+                       }
+                       switch(right.others_right){
+                               case 0:
+                                       kputs("-");
+                                       break;
+                               case 1:
+                                       kputs("r");
+                                       break;
+                               case 2:
+                                       kputs("w");
+                                       break;
+                               case 3:
+                                       kputs("a");
+                                       break;
+                               default:
+                                       kputs("?");
+                                       break;
+                       }
+                       switch(right.gid){
+                               case GID_ROOT:
+                                       kputs(" RootGroup  ");
+                                       break;
+                               case GID_ADMIN:
+                                       kputs(" AdminGroup ");
+                                       break;
+                               case GID_USER:
+                                       kputs(" UserGroup  ");
+                                       break;
+                               default:
+                                       kputs(" ?          ");
+                       }
+                       switch(right.uid){
+                               case GID_ROOT:
+                                       kputs("Root  ");
+                                       break;
+                               case GID_ADMIN:
+                                       kputs("Admin ");
+                                       break;
+                               case GID_USER:
+                                       kputs("User  ");
+                                       break;
+                               default:
+                                       kputs("?     ");
+                       }
+                       kprintf(" %d/%d/%d %d:%d:%d %dB",right.rewrite_time.tm_year+1970, right.rewrite_time.tm_mon, right.rewrite_time.tm_mday, right.rewrite_time.tm_hour, right.rewrite_time.tm_min, right.rewrite_time.tm_sec, node->fsize);
+                       switch(right.flag){
+                               case 0:
+                                       kputs(" .\n");
+                                       break;
+                               case 1:
+                                       kputs(" ..\n");
+                                       break;
+                               default:
+                                       kprintf(" %s\n",node->name);
+                                       break;
+                       }
+                       break;
+       }
+}
\ No newline at end of file
diff --git a/drivers/vga/Makefile b/drivers/vga/Makefile
new file mode 100644 (file)
index 0000000..63ff79e
--- /dev/null
@@ -0,0 +1,56 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+
+#Target
+VGA_LIB        = ${LIBDIR}/vga.lib
+
+# Define
+RM     = /bin/rm
+CC     = gcc
+AS     = ${CC}
+LD     = ld
+OBJCOPY        = objcopy
+
+AR     = ar
+
+ARFLAG = rcs
+CFLAG  = -m32 -ffreestanding -fno-common -masm=intel -nostdlib -fno-builtin -fomit-frame-pointer -O2 -c
+AFLAG  = -m32 -ffreestanding -fno-common -fno-builtin -fomit-frame-pointer -O2 -c
+LFLAG  = -Ttext 0x100000 -melf_i386 --oformat elf32-i386 -o
+#-T link.ls -melf-i386 --oformat elf32-i386 -o
+
+INCLUDE        = -I${INCDIR}
+
+# Dir
+INCDIR = ../../include
+LIBDIR = ../../lib
+
+# Sufix
+.c.o:
+       ${CC} ${INCLUDE} ${CFLAG} $<
+       
+.S.o:
+       ${AS} ${INCLUDE} ${AFLAG} $<
+       
+# Sources_C
+VGA_C  = vga.c
+CUR_C  = cursol.c
+# Source_ASM
+
+VGA_OBJ=${VGA_C:.c=.o} ${CUR_C:.c=.o}
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} vga
+
+vga:
+       ${MAKE} ${VGA_LIB}
+       @echo "  Make VGA Driver Succcessfully!!"
+       
+${VGA_LIB}:${VGA_OBJ}
+       ${AR} ${ARFLAG} ${VGA_LIB} ${VGA_OBJ}
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~ *.lib
diff --git a/drivers/vga/cursol.c b/drivers/vga/cursol.c
new file mode 100644 (file)
index 0000000..53c886b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+       cursol.c
+       Cursol Control
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/Cursol.h>
+
+static struct curinfo state;
+
+void init_Cursol(void)
+{
+       state.X=0;
+       state.Y=0;
+       state.pos=0;
+       MoveCursol();
+       //CursolHeight();
+}
+
+void CursolHeight(void)
+{
+       io_out8(CRTC_ADDR, CRTC_HEIGHT);
+       io_out8(CRTC_DATA, 0);
+}
+
+void ChangeCursolStatus(unsigned short X, unsigned short Y)
+{
+       state.X=X;
+       state.Y=Y;
+       CalcCursolPosition();
+}
+
+void CalcCursolPosition(void)
+{
+       state.pos=(state.Y*80)+state.X;
+}
+
+void MoveCursolCRTC(void)
+{
+       io_out8(CRTC_ADDR, CRTC_CURSOR_H);
+       io_out8(CRTC_DATA, state.pos >> 8);
+       io_out8(CRTC_ADDR, CRTC_CURSOR_L);
+       io_out8(CRTC_DATA, state.pos & 0xFF);
+}
+
+void MoveCursol(struct curinfo cursol)
+{
+       state.X=cursol.X;
+       state.Y=cursol.Y;
+       CalcCursolPosition();
+       
+       MoveCursolCRTC();
+}
+
+void AutoMoveCursol(unsigned short X, unsigned short Y)
+{
+       ChangeCursolStatus(X, Y);
+       MoveCursolCRTC();
+}
\ No newline at end of file
diff --git a/drivers/vga/vga.c b/drivers/vga/vga.c
new file mode 100644 (file)
index 0000000..ccec559
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+       vga.c
+       VGA Driver
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/kstdio.h>
+#include<Diverge/diverge.h>
+#include<Diverge/types.h>
+#include<Diverge/string.h>
+
+/*VGA Text Control*/
+static unsigned short *ch_vram;
+static unsigned short X,Y,pos;
+static unsigned char attr;
+#define SCREEN_START 0xb8000
+#define SCREEN_END   0xc0000
+/*
+enum VGA_PORTS{
+       CRTC_ADDR = 0x3D4,
+       CRTC_DATA = 0x3D5
+};
+
+enum CGTC_REGS{
+       CRTC_CURSOR_H = 0x0E,
+       CRTC_CURSOR_L = 0x0F
+};
+
+void vga_text_update_cursor(void)
+{
+       pos=(Y*80)+X;
+       io_out8(CRTC_ADDR, CRTC_CURSOR_H);
+       io_out8(CRTC_DATA, pos >> 8     );
+       io_out8(CRTC_ADDR, CRTC_CURSOR_L);
+       io_out8(CRTC_DATA, pos & 0xFF   );
+}
+*/
+void ClearScreen(void)
+{
+       ch_vram=(unsigned short*)0xb8000;
+       X=0;Y=0;
+       while(ch_vram<(unsigned short*)0xc0000)
+       {
+               *ch_vram++ =NULL;
+       }
+       ch_vram=(unsigned short*)0xb8000;
+       AutoMoveCursol(X, Y);
+       return;
+}
+
+void init_vga(void)
+{
+       strcpy(kstdout.sign,STDOUT_SIGN);
+       kstdout.fp                      = NULL;
+       kstdout.data_cnt        = NULL;
+       kstdout.buf_addr        = NULL;
+       kstdout.err_flag        = NULL;
+       kstdout.file_desc       = 1;
+       
+       strcpy(kstdin.sign,STDIN_SIGN);
+       kstdin.fp                       = NULL;
+       kstdin.data_cnt         = NULL;
+       kstdin.buf_addr         = NULL;
+       kstdin.err_flag         = NULL;
+       kstdin.file_desc        = 0;
+       
+       strcpy(kstderr.sign,STDERR_SIGN);
+       kstderr.fp                      = NULL;
+       kstderr.data_cnt        = NULL;
+       kstderr.buf_addr        = NULL;
+       kstderr.err_flag        = NULL;
+       kstderr.file_desc       = 2;
+       
+       fp_count=3;
+       
+       stdout  = &kstdout;
+       stdin   = &kstdin;
+       stderr  = &kstderr;
+       
+       DisplayColorChangeChar(White);
+       
+       init_flag=true;
+       ClearScreen();
+}
+
+void DisplayOutputChar(const char ch)
+{
+       if(ch=='\n'){
+               ch_vram+=(80-X);/*80 charactors * 2byte - X charactors * 2 byte*/
+               pos+=(80-X);
+               Y++;
+               X=0;
+               
+       }else if(ch=='\t'){
+               *ch_vram++ = (((attr)<<8) | ' ');
+               *ch_vram++ = (((attr)<<8) | ' ');
+               X+=2;
+               pos+=2;
+               
+       }else if(ch=='\r'){
+               while(X>0)
+               {
+                       *ch_vram-- = (unsigned short)NULL;
+                       X--;
+                       pos--;
+               }
+       
+       }else if(ch=='\b'){
+               ch_vram--;
+               *ch_vram = (unsigned short)NULL;
+               X--;
+               pos--;
+               
+       }else if(ch==0x7f){
+               /*Delete*/
+               
+       }else{
+               *ch_vram++ = (((attr)<<8) | ch);
+               X++;
+               pos++;
+               
+       }
+       
+       AutoMoveCursol(X, Y);
+       
+       if(X>=80){
+               X-=80;
+               Y++;
+       }
+       
+       if(Y==25){
+               ShiftDisplayChar(1);
+               Y--;
+               ch_vram-=(80-X);
+       }
+       
+       return;
+}
+
+void ShiftDisplayChar(unsigned int len)
+{
+       unsigned short *sc1,*sc2;
+       sc1=0xb8000;    sc2=0xb8000+(80*2);
+       while(sc2<=0xc0000)*sc1++ = *sc2++;
+       if(len>1){
+               len--;
+               ShiftDisplayChar(len);
+       }
+}
+
+void DisplayColorChangeChar(char att)
+{
+       attr = att;
+}
\ No newline at end of file
diff --git a/include/Diverge.h b/include/Diverge.h
new file mode 100644 (file)
index 0000000..e6a54af
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+       Diverge.h
+       Diverge Common
+       (C) 2015 VOSystems.
+*/
+
+#ifndef Diverge_Common_Header__
+#define Diverge_Common_Header__
+
+typedef void* DHANDLE;//Diverge Handle(オブジェクトに関するアドレス)
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/Account.h b/include/Diverge/Account.h
new file mode 100644 (file)
index 0000000..92921db
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+       Account.h
+       Diverge Account Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Diverge_Account
+#define Diverge_Account
+
+#define GID_ROOT       0//完全な管理者権限。1PCに対して1人のみ。
+#define GID_ADMIN      1//一般的管理者権限。システムへの直接的な影響を与える変更はできない。
+#define GID_USER       2//一般ユーザー。権限変更などの間接的な影響を与える変更もできない。
+
+struct user_info{
+       char name[256];
+       char pw[256];
+       unsigned int uid;
+       unsigned char gid;
+};
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/BitMap.h b/include/Diverge/BitMap.h
new file mode 100644 (file)
index 0000000..a43ecc6
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+       BitMap.c
+       Bit Map Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef BitMap_Diverge
+#define BitMap_Diverge
+
+#include<Diverge/types.h>
+
+void ReserveBit(unsigned long *map, unsigned long where);
+void RemoveBit(unsigned long *map, unsigned long where);
+bool CheckEmptyBit(unsigned int *map);
+unsigned int NumCountBit(unsigned int *map);
+bool ContainBit(unsigned long *map, unsigned int where);
+unsigned int SearchEmptyBit(unsigned long *map);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/Cursol.h b/include/Diverge/Cursol.h
new file mode 100644 (file)
index 0000000..f6adbaf
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+       cursol.c
+       Cursol Control
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Cursol_Ctrl_Diverge
+#define Cursol_Ctrl_Diverge
+
+struct curinfo{
+       unsigned short X,Y,pos;
+};
+
+enum VGA_PORTS{
+       CRTC_ADDR=0x3d4,
+       CRTC_DATA=0x3d5
+};
+
+enum CGTC_REGS{
+       CRTC_CURSOR_H=0x0e,
+       CRTC_CURSOR_L=0x0f,
+       CRTC_HEIGHT=0x0a
+};
+
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/DivergeAPI.h b/include/Diverge/DivergeAPI.h
new file mode 100644 (file)
index 0000000..8bc6a60
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+       DivergeAPI.h
+       Diverge API
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef DivergeAPI_for_Application_Driver_and_Kernel
+#define DivergeAPI_for_Application_Driver_and_Kernel
+
+typedef unsigned int DHANDLE;
+
+void InitCharArrey(char* arrey,size_t lengh);
+void Sleep(unsigned long milisec);
+char GetKeyBoardChar(void);
+int CharCountInStr(char* str, char cha);
+int StringCompare(const char* s1, const char* s2, const char separate);
+void LoadingPromptSec(unsigned int Sec);
+void LoadingPrompt(void);
+void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/DrFS.h b/include/Diverge/DrFS.h
new file mode 100644 (file)
index 0000000..53f47d6
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+       DrFS.h
+       Diverge RAM FS
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Diverge_RAM_FS_
+#define Diverge_RAM_FS_
+
+#include<Diverge/types.h>
+#include<time.h>
+
+#define FS_PREFIX_ADDR         0x01000000
+#define FS_START_ADDR          (FS_PREFIX_ADDR+sizeof(struct DrFS_Prefix))
+
+typedef struct{
+       unsigned int major;
+       unsigned int minor;
+       unsigned int revision;
+       unsigned int build;
+}VersionInfoStruct;
+
+struct DrFS_Prefix{
+       char sign[32];//シグネチャ
+       unsigned int sector_size;//セクタサイズ(Byte)
+       unsigned int root_fnode_addr;//ルートのfnodeアドレス
+       unsigned int fs_size;//FSのサイズ(MiB)
+       unsigned int sector_count;//セクタ数
+       VersionInfoStruct version;//バージョン
+       unsigned int space;
+};
+
+struct fnode{
+       char name[454];
+       unsigned short attribute;//属性 オブジェクトの種類(ディレクトリ->0,ファイル->1), 隠しファイル(1), システムファイル(1), テンポラリファイル(1), 所有者権限(リード, ライト), グループ権限(リード,ライト), その他の権限(リード,ライト)
+       unsigned int uid;//所有者UID
+       unsigned int gid;//所有者GID
+       unsigned int pid;//親オブジェクト識別子
+       unsigned int id;//識別子
+       unsigned long long fsize;//ファイルサイズ
+       unsigned int level;//ノードの深さ。何段でデータセクタに行き着くか(0->tnpが直接セクタを指している)
+       unsigned int tnp;//トップレベルノードポインタ
+       time_t create;
+       time_t rewrite;
+       time_t access;
+};
+
+struct faright{
+       bool dir;
+       bool hide;
+       bool sys;
+       bool tmp;
+       unsigned char user_right;
+       unsigned char group_right;
+       unsigned char others_right;
+       unsigned char flag;
+       unsigned int uid;
+       unsigned int gid;
+       struct tm create_time;
+       struct tm rewrite_time;
+       struct tm access_time;
+};
+
+typedef unsigned char* FSSector;
+typedef unsigned int* FSDirPointer;
+
+void init_DrFS(void);
+unsigned int SearchObjectFromCDir(char* name, char mode, bool* error);
+int ChangeDir(char* name, char* current_dir, bool* error);
+unsigned int SectorSearch(bool *error);
+unsigned int SearchSectorPysicalMemory(bool* error);
+int MakeDir(char* name, unsigned short ar, unsigned uid, unsigned int gid, unsigned int pid);
+int kmkdir(char* name);
+struct faright CheckObjectRight(const struct fnode* node);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/descriptor.h b/include/Diverge/descriptor.h
new file mode 100644 (file)
index 0000000..60d7c5b
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+       descriptor.h
+       Initation Descriptor Tables
+*/
+
+#ifndef Descriptor_Diverge_H__
+#define Descriptor_Diverge_H__
+
+#include<Diverge/proc.h>
+
+#define ADR_IDT                        0x00dff800
+#define LIMIT_IDT              0x000007ff
+
+#define ADR_TSS_DESC   (0x00dff799-(sizeof(tss)*MAX_TSS))
+
+#define ADR_GDT                        0x00e00000
+#define LIMIT_GDT              0x000fffff
+
+#define AR_DATA32_SYS_RW       0x4092//__KERNEL_DS
+#define AR_CODE32_SYS_ER       0x409a//__KERNEL_CS
+#define AR_DATA32_USR_RW       0x40fa//__USER_DS
+#define AR_CODE32_USR_ER       0x40f2//__USER_CS
+
+#define AR_LDT                 0x0082
+#define AR_TSS32               0x0089
+#define AR_INTGATE32   0x008e
+
+typedef struct{
+       unsigned short limit_low, base_low;
+       unsigned char base_mid, access_right;
+       unsigned char limit_high, base_high;
+}__attribute__ ((packed))Segment_Descriptor;
+
+typedef struct{
+       unsigned short offset_low, selector;
+       unsigned char dw_count, access_right;
+       unsigned short offset_high;
+}__attribute__((packed))Gate_Descriptor;
+
+/*PIC*/
+#define        PORT_MASTER_PIC_COMMAND 0x0020
+#define        PORT_MASTER_PIC_STATUS  0x0020
+#define        PORT_MASTER_PIC_DATA    0x0021
+#define        PORT_MASTER_PIC_IMR             0x0021
+#define        PORT_SLAVE_PIC_COMMAND  0x00A0
+#define        PORT_SLAVE_PIC_STATUS   0x00A0
+#define        PORT_SLAVE_PIC_DATA             0x00A1
+#define        PORT_SLAVE_PIC_IMR              0x00A1
+#define        PIC_ICW1                                0x11
+#define        PIC_MASTER_ICW2                 0x20
+#define        PIC_SLAVE_ICW2                  0x28
+#define        PIC_MASTER_ICW3                 0x04
+#define        PIC_SLAVE_ICW3                  0x02
+#define        PIC_MASTER_ICW4                 0x01
+#define        PIC_SLAVE_ICW4                  0x01
+
+/*IRQ*/
+#define        PIC_IMR_MASK_IRQ0               0x01
+#define        PIC_IMR_MASK_IRQ1               0x02
+#define        PIC_IMR_MASK_IRQ2               0x04
+#define        PIC_IMR_MASK_IRQ3               0x08
+#define        PIC_IMR_MASK_IRQ4               0x10
+#define        PIC_IMR_MASK_IRQ5               0x20
+#define        PIC_IMR_MASK_IRQ6               0x40
+#define        PIC_IMR_MASK_IRQ7               0x80
+#define        PIC_IMR_MASK_IRQ_ALL    0xFF
+
+/*PIT*/
+#define        PIT_REG_COUNTER0                0x0040
+#define        PIT_REG_COUNTER1                0x0041
+#define        PIT_REG_COUNTER2                0x0042
+#define        PIT_REG_CONTROL                 0x0043
+#define        PIT_CLOCK                               1193181.67      
+#define        PIT_COM_MASK_BINCOUNT   0x01
+#define        PIT_COM_MASK_MODE               0x0E
+#define        PIT_COM_MASK_RL                 0x30
+#define        PIT_COM_MASK_COUNTER    0xC0
+#define        PIT_COM_BINCOUNT_BIN    0x00
+#define        PIT_COM_BINCOUNT_BCD    0x01
+#define        PIT_COM_MODE_TERMINAL   0x00
+#define        PIT_COM_MODE_PROGONE    0x02
+#define        PIT_COM_MODE_RATEGEN    0x04
+#define        PIT_COM_MODE_SQUAREWAVE 0x06
+#define        PIT_COM_MODE_SOFTTRIG   0x08
+#define        PIT_COM_MODE_HARDTRIG   0x0A
+#define        PIT_COM_RL_LATCH                0x00
+#define        PIT_COM_RL_LSBONLY              0x10
+#define        PIT_COM_RL_MSBONLY              0x20
+#define        PIT_COM_RL_DATA                 0x30
+#define PIT_COM_COUNTER0               0x00
+#define        PIT_COM_COUNTER1                0x40
+#define        PIT_COM_COUNTER2                0x80
+
+/*IDT Vector*/
+#define DE 0x00//除算エラー
+#define DB 0x01//デバッグ、シングルステップ
+#define NMI 0x02//マスク不可能割り込み
+#define BP 0x03//デバッグ、ブレークポイント
+#define OF 0x04//オーバーフロー
+#define BR 0x05//バウンド範囲外
+#define UD 0x06//無効なオペコード
+#define NM 0x07//デバイス使用不可
+#define DF 0x08//ダブルフォルト
+#define COR 0x09//コプロセッサセグメントオーバーラン(本当はMF)
+#define TS 0x0a//無効なTSS
+#define NP 0x0b//セグメント不在
+#define SS 0x0c//スタックセグメントフォルト
+#define GP 0x0d//一般保護例外
+#define PF 0x0e//ページフォルト
+#define R15 0x0f//予約
+#define MF 0x10//浮動小数点エラー
+#define AC 0x11//アライメントチェック
+#define MC 0x12//マシンチェック
+#define XF 0x13//SIMD浮動小数点例外
+#define IRQ0 0x20//タイマー
+#define IRQ1 0x21//キーボード
+#define IRQ2 0x22//スレーブPIC
+#define IRQ3 0x23//シリアルポート2
+#define IRQ4 0x24//シリアルポート1
+#define IRQ5 0x25//AT:パラレルポート2、PS/2:予約
+#define IRQ6 0x26//FDD
+#define IRQ7 0x27//パラレルポート1
+#define IRQ8 0x28//CMOS RTC
+#define IRQ9 0x29//CGA垂直トレース
+#define IRQ10 0x2a//予約
+#define IRQ11 0x2b//予約
+#define IRQ12 0x2c//AT:予約、PS/2:AUXデバイス
+#define IRQ13 0x2d//FPU
+#define IRQ14 0x2e//HDD
+#define IRQ15 0x2f//予約
+#define APPSYSCALL     0x80//システムコールアプリケーション用
+#define DRVSYSCALL     0x90//システムコールドライバ用
+#define V86EXIT                0xa0//仮想86モード脱出用
+
+void init_PIC(void);
+int init_PIT(int freq, unsigned char counter, unsigned char mode);
+void Set_PIC_Mask(unsigned int mask);
+void init_GDT(void);
+void init_IDT(void);
+void Set_Segment_Descriptor(Segment_Descriptor *sd, unsigned int base, unsigned int limit, unsigned short ar);
+void Set_Gate_Descriptor(Gate_Descriptor *gd, int offset, int selector, int ar);
+
+#endif
diff --git a/include/Diverge/diverge.h b/include/Diverge/diverge.h
new file mode 100644 (file)
index 0000000..570ce43
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+       diverge.h
+       Diverge Low-Level Layer Library for Kernel Building
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Diverge_H__
+#define Diverge_H__
+
+#include<Diverge/types.h>
+#include<Diverge/multiboot.h>
+
+/*Diverge Low-Level Layer Library for Kernel Building (DLB)*/
+#define Black 0x00
+#define Blue 0x01
+#define Green 0x02
+#define Cian 0x03
+#define Red 0x04
+#define Masenta 0x05
+#define Brown 0x06
+#define LightGray 0x07
+#define DarkGray 0x08
+#define LightBlue 0x09
+#define LightGreen 0x0a
+#define LightCian 0x0b
+#define LightRed 0x0c
+#define LightMasenta 0x0d
+#define LightBrown 0x0e
+#define White 0x0f
+
+#define TYPE_SIZE(type) (sizeof(type))
+
+/*CPUID EAX Value*/
+#define CPUID_VENDOR   0x00
+#define CPUID_FUNCTION 0x01
+#define CPUID_TLB_INFO 0x02
+#define CPUID_EX_NUM   0x80000000
+#define CPUID_BRAND1   0x80000002
+#define CPUID_BRAND2   0x80000003
+#define CPUID_BRAND3   0x80000004
+struct general_registers{
+       unsigned int eax;
+       unsigned int ebx;
+       unsigned int ecx;
+       unsigned int edx;
+};
+
+/*FIFO*/
+typedef struct{
+       unsigned int start, max, end;
+       void* buf;
+       unsigned char mode;
+}FIFO;
+#define FIFO_MODE_UNINIT 0xff
+#define FIFO_MODE_UBYTE 0x01
+#define FIFO_MODE_UWORD 0x02
+#define FIFO_MODE_UDWORD 0x03
+#define FIFO_MODE_BYTE 0x11
+#define FIFO_MODE_WORD 0x12
+#define FIFO_MODE_DOWRD 0x13
+
+/*Multiboot Info*/
+extern struct pc_info pc;
+void MB_memory(multiboot_info_t* mbi,unsigned long magic);
+void MB_apm(multiboot_info_t* mbi);
+
+struct mem_info{
+       unsigned long size;//MB単位
+       unsigned long low_size;//KB単位
+       unsigned long up_size;//KB単位
+};
+/*
+struct boot_dev_info{
+       unsigned char drive;
+       unsigned char p1;
+       unsigned char p2;
+       unsigned char p3;
+};*/
+
+struct apm_info{
+       unsigned short version;
+       unsigned short cs32;
+       unsigned int offset;
+       unsigned short cs16;
+       unsigned short ds16;
+       unsigned short flag;
+       unsigned short cs32_size;
+       unsigned short cs16_size;
+       unsigned short ds_size;
+};
+
+struct pc_info{
+       struct mem_info mem;
+       //struct boot_dev_info dev;
+       char* cmd;
+       struct apm_info apm;
+};
+
+
+inline void InitCharArrey(char* arrey,size_t lengh);
+inline void Sleep(unsigned long milisec);
+
+void vga_text_update_cursor(void);
+void ClearScreen(void);
+void init_char_io(void);
+void DisplayOutputChar(const char ch);
+void ShiftDisplayChar(unsigned int len);
+void DisplayColorChangeChar(char att);
+void GetTimeFromRTC(unsigned char* t);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/dksh.h b/include/Diverge/dksh.h
new file mode 100644 (file)
index 0000000..8a6aae4
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+       DKsh.h
+       Diverge Kernel shell
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Diverge_Kernel_Shell
+#define Diverge_Kernel_Shell
+
+#include<Diverge/Account.h>
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/dmsg.h b/include/Diverge/dmsg.h
new file mode 100644 (file)
index 0000000..482489d
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+       dmsg.h
+       Diverge Message Queue
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Diverge_Messaging_
+#define Diverge_Messaging_
+
+#include<Diverge.h>
+
+#define DMSG_Q_MAX 0xff
+
+struct dmsg_q{
+       char dq[DMSG_Q_MAX];
+       unsigned int top, buttom;
+       unsigned char flag;
+       unsigned int free;
+};
+
+#define DQ_FLAG_UNINIT 0x00
+#define DQ_FLAG_CLEAN  0x01
+#define DQ_FLAG_UNUSE  0x02
+#define DQ_FLAG_RUN            0x03
+#define DQ_FLAG_CRASH  0xff
+
+/*Prototype*/
+void InitDMsgQ(DHANDLE handle);//キューの初期化
+void init_DMsgQ(void);//Diverge MsgQの初期化
+DHANDLE CreateDMsgQ(DHANDLE handle);//新しいキューの作成
+void DestroyDMsgQ(DHANDLE handle);//キューの破壊
+
+int EnqDMsgQ(char data, DHANDLE handle);//エンキュー
+char DeqDMsgQ(DHANDLE handle);//デキュー
+
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/env_var.h b/include/Diverge/env_var.h
new file mode 100644 (file)
index 0000000..c5efa9d
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+       env_var.h
+       Environment Var
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Env_Diverge_
+#define Env_Diverge_
+
+typedef struct _Diverge_Environment_Variable_Shell{
+       char name[32];
+       unsigned int major,minor,rev,build;
+}env_shell;
+
+typedef struct _Diverge_Environment_Variable{
+       env_shell shell;
+       char osname[32];
+       char oemname[32];
+       unsigned int major,minor,rev,build;
+}env;
+
+typedef struct _Diverge_Environment_PC_Info{
+       unsigned char vendor;/*Intel->0, AMD->1, Centaur Technology->2, Cyrix->3, Transmeta->4, NSC->5, NexGen->6, Rise Technology->7, SiS->8, UMC->9, VIA Technology->10*/
+       char brand[50];
+}env_pc_info;
+
+void version(void);
+void init_env(void);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/interrupt.h b/include/Diverge/interrupt.h
new file mode 100644 (file)
index 0000000..557c843
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+       interrupt.h
+       Interrupt Handlers
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Interrupt_H__
+#define Interrupt_H__
+
+struct keyboard_fifo{
+       unsigned char buf[0xff];
+       unsigned short top, buttom, max;
+};
+unsigned char kbd_fifo_read(void);
+
+void ignore_gate(void);
+void timer_int_gate(void);
+void keyboard_int_gate(void);
+void virtual86_exit_gate(void);
+void app_syscall_gate(void);
+void driver_syscall_gate(void);
+
+void init_interrupt_handler(void);
+void timer_int_handler(void);
+void keyboard_int_handler(void);
+int app_syscall(int eax, int ebx, int ecx, int edx, int esi, int edi);
+int driver_syscall(int eax, int ebx, int ecx, int edx, int esi, int edi);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/keyboard.h b/include/Diverge/keyboard.h
new file mode 100644 (file)
index 0000000..fb327fb
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+       keyboard.h
+       Keyboard Handler
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef KeyBoard_Ctrl
+#define KeyBoard_Ctrl
+
+#include<Diverge/types.h>
+
+typedef enum
+{
+    E_KBD_NONE_LED          = 0x00000000,
+    E_KBD_SCROLL_LOCK_LED   = 0x00000001,
+    E_KBD_NUM_LOCK_LED      = 0x00000002,
+    E_KBD_CAPS_LOCK_LED     = 0x00000004
+} E_KBD_LED;
+
+/*DESCRIPTION KEYBOARD ENCODE*/
+#define PORT_KBD_ENCODER 0x0060
+#define PORT_KBD_ENC_BUFFER PORT_KBD_ENCODER
+#define PORT_KBD_ENC_COMMAND PORT_KBD_ENCODER
+
+/*DESCRIPTION KEYBOARD CONTROLER*/
+#define PORT_KBD_CONTROLLER 0x0064
+#define PORT_KBD_CTRL_STATUS PORT_KBD_CONTROLLER
+#define PORT_KBD_CTRL_COMMAND PORT_KBD_CONTROLLER
+
+/*DEFINE STATUS REGISTOR*/
+#define KBD_STS_OBF 0x01
+#define KBD_STS_IBF 0x02
+#define KBD_STS_F0  0x04
+#define KBD_STS_F1  0x08
+#define KBD_STS_ST4 0x10
+#define KBD_STS_ST5 0x20
+#define KBD_STS_ST6 0x40
+#define KBD_STS_ST7 0x80
+
+/*Key Board Status*/
+#define KBD_OK 0
+#define KBD_ERROR (-1)
+#define MAX_RETRY 0x01000000
+
+/*Key Board Status*/
+#define        KBD_ENC_COM_SETLED              0xED
+#define        KBD_ENC_COM_ECHO                0xEE
+#define        KBD_ENC_COM_GETSET_SCANCODE     0xF0
+#define        KBD_ENC_COM_GET_KBD_ID          0xF2
+#define        KBD_ENC_COM_SET_TYPEMATIC       0xF3
+#define        KBD_ENC_COM_ENABLE_KBD          0xF4
+#define        KBD_ENC_COM_DISABLE_KBD         0xF5
+#define        KBD_ENC_COM_SET_DEFAULT         0xF6
+#define        KBD_ENC_COM_SET_ALL_REPEAT      0xF7
+#define        KBD_ENC_COM_SET_ALL_BREAK       0xF8
+#define        KBD_ENC_COM_CLEAR_ALL_REP_BRK   0xF9
+#define        KBD_ENC_COM_SET_ALL_REP_BRK     0xFA
+#define        KBD_ENC_COM_SET_REPEAT          0xFB
+#define        KBD_ENC_COM_SET_BREAK           0xFC
+#define        KBD_ENC_COM_CLEAR_REP_BRK       0xFD
+#define        KBD_ENC_COM_REQ_RESEND          0xFE
+#define        KBD_ENC_COM_RESET_SELFTEST      0xFF
+
+/* Standard Commands      */
+#define KBD_CTRL_COM_READ_CCB        0x20
+#define KBD_CTRL_COM_WRITE_CCB       0x60
+#define KBD_CTRL_COM_DISABLE_MOUSE   0xA7
+#define KBD_CTRL_COM_ENABLE_MOUSE    0xA8
+#define KBD_CTRL_COM_TEST_MOUSE      0xA9
+#define KBD_CTRL_COM_SELF_TEST       0xAA
+#define KBD_CTRL_COM_TEST_IF         0xAB
+#define KBD_CTRL_COM_DISABLE_KBD     0xAD
+#define KBD_CTRL_COM_ENABLE_KBD      0xAE
+#define KBD_CTRL_COM_READ_IN_PORT    0xC0
+#define KBD_CTRL_COM_READ_OUT_PORT   0xD0
+#define KBD_CTRL_COM_WRITE_OUT_PORT  0xD1
+#define KBD_CTRL_COM_WRITE_MOUSE     0xD4
+#define KBD_CTRL_COM_READ_TEST_PORT  0xE0
+#define KBD_CTRL_COM_SYSTEM_RESET    0xFE
+
+/* Vendo-Specific Commands  */
+#define KBD_CTRL_COM_READ_RAM_0x20   0x20
+#define KBD_CTRL_COM_READ_RAM_0x21   0x21
+#define KBD_CTRL_COM_READ_RAM_0x22   0x22
+#define KBD_CTRL_COM_READ_RAM_0x23   0x23
+#define KBD_CTRL_COM_READ_RAM_0x24   0x24
+#define KBD_CTRL_COM_READ_RAM_0x25   0x25
+#define KBD_CTRL_COM_READ_RAM_0x26   0x26
+#define KBD_CTRL_COM_READ_RAM_0x27   0x27
+#define KBD_CTRL_COM_READ_RAM_0x28   0x28
+#define KBD_CTRL_COM_READ_RAM_0x29   0x29
+#define KBD_CTRL_COM_READ_RAM_0x2A   0x2A
+#define KBD_CTRL_COM_READ_RAM_0x2B   0x2B
+#define KBD_CTRL_COM_READ_RAM_0x2C   0x2C
+#define KBD_CTRL_COM_READ_RAM_0x2D   0x2D
+#define KBD_CTRL_COM_READ_RAM_0x2E   0x2E
+#define KBD_CTRL_COM_READ_RAM_0x2F   0x2F
+#define KBD_CTRL_COM_READ_RAM_0x30   0x30
+#define KBD_CTRL_COM_READ_RAM_0x31   0x31
+#define KBD_CTRL_COM_READ_RAM_0x32   0x32
+#define KBD_CTRL_COM_READ_RAM_0x33   0x33
+#define KBD_CTRL_COM_READ_RAM_0x34   0x34
+#define KBD_CTRL_COM_READ_RAM_0x35   0x35
+#define KBD_CTRL_COM_READ_RAM_0x36   0x36
+#define KBD_CTRL_COM_READ_RAM_0x37   0x37
+#define KBD_CTRL_COM_READ_RAM_0x38   0x38
+#define KBD_CTRL_COM_READ_RAM_0x39   0x39
+#define KBD_CTRL_COM_READ_RAM_0x3A   0x3A
+#define KBD_CTRL_COM_READ_RAM_0x3B   0x3B
+#define KBD_CTRL_COM_READ_RAM_0x3C   0x3C
+#define KBD_CTRL_COM_READ_RAM_0x3D   0x3D
+#define KBD_CTRL_COM_READ_RAM_0x3E   0x3E
+#define KBD_CTRL_COM_READ_RAM_0x3F   0x3F
+
+#define KBD_CTRL_COM_WRITE_RAM_0x60  0x60
+#define KBD_CTRL_COM_WRITE_RAM_0x61  0x61
+#define KBD_CTRL_COM_WRITE_RAM_0x62  0x62
+#define KBD_CTRL_COM_WRITE_RAM_0x63  0x36
+#define KBD_CTRL_COM_WRITE_RAM_0x64  0x46
+#define KBD_CTRL_COM_WRITE_RAM_0x65  0x56
+#define KBD_CTRL_COM_WRITE_RAM_0x66  0x66
+#define KBD_CTRL_COM_WRITE_RAM_0x67  0x67
+#define KBD_CTRL_COM_WRITE_RAM_0x68  0x68
+#define KBD_CTRL_COM_WRITE_RAM_0x69  0x69
+#define KBD_CTRL_COM_WRITE_RAM_0x6A  0x6A
+#define KBD_CTRL_COM_WRITE_RAM_0x6B  0x6B
+#define KBD_CTRL_COM_WRITE_RAM_0x6C  0x6C
+#define KBD_CTRL_COM_WRITE_RAM_0x6D  0x6D
+#define KBD_CTRL_COM_WRITE_RAM_0x6E  0x6E
+#define KBD_CTRL_COM_WRITE_RAM_0x6F  0x6F
+#define KBD_CTRL_COM_WRITE_RAM_0x70  0x70
+#define KBD_CTRL_COM_WRITE_RAM_0x71  0x71
+#define KBD_CTRL_COM_WRITE_RAM_0x72  0x72
+#define KBD_CTRL_COM_WRITE_RAM_0x73  0x73
+#define KBD_CTRL_COM_WRITE_RAM_0x74  0x74
+#define KBD_CTRL_COM_WRITE_RAM_0x75  0x75
+#define KBD_CTRL_COM_WRITE_RAM_0x76  0x76
+#define KBD_CTRL_COM_WRITE_RAM_0x77  0x77
+#define KBD_CTRL_COM_WRITE_RAM_0x78  0x78
+#define KBD_CTRL_COM_WRITE_RAM_0x79  0x79
+#define KBD_CTRL_COM_WRITE_RAM_0x7A  0x7A
+#define KBD_CTRL_COM_WRITE_RAM_0x7B  0x7B
+#define KBD_CTRL_COM_WRITE_RAM_0x7C  0x7C
+#define KBD_CTRL_COM_WRITE_RAM_0x7D  0x7D
+#define KBD_CTRL_COM_WRITE_RAM_0x7E  0x7E
+#define KBD_CTRL_COM_WRITE_RAM_0x7F  0x7F
+
+/*Self Status Command*/
+#define KBD_CTRL_STS_SELF_TEST_OK    0x55
+#define KBD_CTRL_STS_SELF_TEST_NG    0xFC
+
+typedef struct{
+       bool caps_lock;
+       bool scr_lock;
+       bool num_lock;
+       bool shift;
+       bool insert;
+       bool ctrl;
+       bool alt;
+       bool windows;
+       bool home;
+       bool pgdn;
+       bool pgup;
+       bool end;
+       bool del;
+}KeyBoard_Status;
+
+extern bool ex_keycode_flag;
+
+void init_keyboard(void);
+void ChangeKeyboardState(char ch);
+unsigned char readKbdCtrlStatus(void);
+int writeKbdCtrlCommand(unsigned char command);
+unsigned char readKbdEncBuffer(void);
+int writeKbdEncCommand(unsigned char command);
+int keyboardSetLED(E_KBD_LED led);
+int keyboardSelfTest(void);
+int waitKbdOutputBufferFull(void);
+int keyboardDisableKBD(void);
+int keyboardEnableKBD(void);
+
+#endif
diff --git a/include/Diverge/kstdio.h b/include/Diverge/kstdio.h
new file mode 100644 (file)
index 0000000..969faf0
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+       kstdio.h
+       Kernel Standard Input/Output
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef kstdio_h_Diverge
+#define kstdio_h_Diverge
+
+#include<Diverge/types.h>
+
+#define STDOUT_SIGN    "Sys_stdout"
+#define STDIN_SIGN     "Sys_stdin"
+#define STDERR_SIGN    "Sys_stderr"
+#define SYSTEM_SIGN    "Sys_sys"
+#define USER_SIGN      "User_user"
+
+
+typedef struct{
+       char *sign;
+       char *fp;
+       int data_cnt;
+       char *buf_addr;
+       char err_flag;
+       char file_desc;
+}FILE;
+
+extern bool init_flag;
+extern unsigned int fp_count;
+extern FILE kstdout,kstdin,kstderr;
+extern FILE *stdout,*stdin,*stderr;
+
+void ksprintf(char* s,char* fmt, ...);
+
+char kgetchar(void);
+char kgetch(void);
+
+void printFAIL(const char* str);
+void printWARN(const char* str);
+void printINFO(const char* str);
+void printOK(const char* str);
+void printTASK(const char* str);
+
+int scan_num(unsigned int base);
+char scan_char(void);
+char* scan_str(char* in,size_t lengh);
+void kscanf(const char* fmt,...);
+
+#endif
diff --git a/include/Diverge/memory.h b/include/Diverge/memory.h
new file mode 100644 (file)
index 0000000..04b0fb9
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+       memory.h
+       Memory Info
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Memory_Diverge_H__
+#define Memory_Diverge_H__
+
+#include<Diverge/types.h>
+
+typedef        struct
+{
+    unsigned int    system_memory_size;      /* システムのメモリサイズ     */
+    unsigned int    system_memory_blocks;    /* システムのメモリブロック数 */
+    unsigned int    allocated_blocks;        /* 割り当て済みブロック数     */
+    unsigned int    free_blocks;             /* フリーブロック数           */
+    unsigned int*   memory_map;              /* ビットマップ               */
+    unsigned int    memory_map_size;         /* ビットマップのサイズ       */
+} PHYSICAL_MEMORY_INFO;
+
+#define MEM_KERNEL_START 0x00100000
+#define MEM_BITMAP_ADDR 0x00bfa799
+
+inline unsigned int getSystemMemoryBlocks(void);
+inline unsigned int getSystemMemorySize(void);
+void init_Physical_Memory(unsigned int memory_size);
+void initPhysicalMemoryManagement(unsigned int memory_size);
+inline void setBit(int bit_number);
+inline void clearBit(int bit_number);
+bool testBit( int bit_number );
+int findFirstFreeMemoryBlock(unsigned int *block_number);
+void initFreedMemoryRegion(void *base_address, uint32_t size);
+void initAllocatedMemoryRegion(void *base_address, uint32_t size );
+void *allocSingleMemoryBlock(void);
+void freeSingleMemoryBlock(void* physical_address );
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/multiboot.h b/include/Diverge/multiboot.h
new file mode 100644 (file)
index 0000000..29f133b
--- /dev/null
@@ -0,0 +1,205 @@
+#ifndef MULTIBOOT_HEADER
+#define MULTIBOOT_HEADER 1
+
+/* How many bytes from the start of the file we search for the header.  */
+#define MULTIBOOT_SEARCH                               8192
+
+/* The magic field should contain this.  */
+#define MULTIBOOT_HEADER_MAGIC                 0x1BADB002
+
+/* This should be in %eax.  */
+#define MULTIBOOT_BOOTLOADER_MAGIC             0x2BADB002
+
+/* The bits in the required part of flags field we don't support.  */
+#define MULTIBOOT_UNSUPPORTED                  0x0000fffc
+
+/* Alignment of multiboot modules.  */
+#define MULTIBOOT_MOD_ALIGN                    0x00001000
+
+/* Alignment of the multiboot info structure.  */
+#define MULTIBOOT_INFO_ALIGN                   0x00000004
+
+/* Flags set in the 'flags' member of the multiboot header.  */
+
+/* Align all boot modules on i386 page (4KB) boundaries.  */
+#define MULTIBOOT_PAGE_ALIGN                   0x00000001
+
+/* Must pass memory information to OS.  */
+#define MULTIBOOT_MEMORY_INFO                  0x00000002
+
+/* Must pass video information to OS.  */
+#define MULTIBOOT_VIDEO_MODE                   0x00000004
+
+/* This flag indicates the use of the address fields in the header.  */
+#define MULTIBOOT_AOUT_KLUDGE                  0x00010000
+
+/* Flags to be set in the 'flags' member of the multiboot info structure.  */
+
+/* is there basic lower/upper memory information? */
+#define MULTIBOOT_INFO_MEMORY                  0x00000001
+/* is there a boot device set? */
+#define MULTIBOOT_INFO_BOOTDEV                 0x00000002
+/* is the command-line defined? */
+#define MULTIBOOT_INFO_CMDLINE                 0x00000004
+/* are there modules to do something with? */
+#define MULTIBOOT_INFO_MODS                    0x00000008
+
+/* These next two are mutually exclusive */
+
+/* is there a symbol table loaded? */
+#define MULTIBOOT_INFO_AOUT_SYMS               0x00000010
+/* is there an ELF section header table? */
+#define MULTIBOOT_INFO_ELF_SHDR                        0X00000020
+
+/* is there a full memory map? */
+#define MULTIBOOT_INFO_MEM_MAP                 0x00000040
+
+/* Is there drive info?  */
+#define MULTIBOOT_INFO_DRIVE_INFO              0x00000080
+
+/* Is there a config table?  */
+#define MULTIBOOT_INFO_CONFIG_TABLE            0x00000100
+
+/* Is there a boot loader name?  */
+#define MULTIBOOT_INFO_BOOT_LOADER_NAME                0x00000200
+
+/* Is there a APM table?  */
+#define MULTIBOOT_INFO_APM_TABLE               0x00000400
+
+/* Is there video information?  */
+#define MULTIBOOT_INFO_VIDEO_INFO              0x00000800
+
+#define VESA_GRAPHIC   0x00000000
+#define EGA_TEXT               0x00000001
+
+#ifndef ASM_FILE
+
+typedef unsigned short         multiboot_uint16_t;
+typedef unsigned int           multiboot_uint32_t;
+typedef unsigned long long     multiboot_uint64_t;
+
+struct multiboot_header
+{
+  /* Must be MULTIBOOT_MAGIC - see above.  */
+  multiboot_uint32_t magic;
+
+  /* Feature flags.  */
+  multiboot_uint32_t flags;
+
+  /* The above fields plus this one must equal 0 mod 2^32. */
+  multiboot_uint32_t checksum;
+
+  /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set.  */
+  multiboot_uint32_t header_addr;
+  multiboot_uint32_t load_addr;
+  multiboot_uint32_t load_end_addr;
+  multiboot_uint32_t bss_end_addr;
+  multiboot_uint32_t entry_addr;
+
+  /* These are only valid if MULTIBOOT_VIDEO_MODE is set.  */
+  multiboot_uint32_t mode_type;
+  multiboot_uint32_t width;
+  multiboot_uint32_t height;
+  multiboot_uint32_t depth;
+};
+
+/* The symbol table for a.out.  */
+struct multiboot_aout_symbol_table
+{
+  multiboot_uint32_t tabsize;
+  multiboot_uint32_t strsize;
+  multiboot_uint32_t addr;
+  multiboot_uint32_t reserved;
+};
+typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
+
+/* The section header table for ELF.  */
+struct multiboot_elf_section_header_table
+{
+  multiboot_uint32_t num;
+  multiboot_uint32_t size;
+  multiboot_uint32_t addr;
+  multiboot_uint32_t shndx;
+};
+typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
+
+struct multiboot_info
+{
+  /* Multiboot info version number */
+  multiboot_uint32_t flags;
+
+  /* Available memory from BIOS */
+  multiboot_uint32_t mem_lower;
+  multiboot_uint32_t mem_upper;
+
+  /* "root" partition */
+  multiboot_uint32_t boot_device;
+
+  /* Kernel command line */
+  multiboot_uint32_t cmdline;
+
+  /* Boot-Module list */
+  multiboot_uint32_t mods_count;
+  multiboot_uint32_t mods_addr;
+
+  union
+  {
+    multiboot_aout_symbol_table_t aout_sym;
+    multiboot_elf_section_header_table_t elf_sec;
+  } u;
+
+  /* Memory Mapping buffer */
+  multiboot_uint32_t mmap_length;
+  multiboot_uint32_t mmap_addr;
+
+  /* Drive Info buffer */
+  multiboot_uint32_t drives_length;
+  multiboot_uint32_t drives_addr;
+
+  /* ROM configuration table */
+  multiboot_uint32_t config_table;
+
+  /* Boot Loader Name */
+  multiboot_uint32_t boot_loader_name;
+
+  /* APM table */
+  multiboot_uint32_t apm_table;
+
+  /* Video */
+  multiboot_uint32_t vbe_control_info;
+  multiboot_uint32_t vbe_mode_info;
+  multiboot_uint16_t vbe_mode;
+  multiboot_uint16_t vbe_interface_seg;
+  multiboot_uint16_t vbe_interface_off;
+  multiboot_uint16_t vbe_interface_len;
+};
+typedef struct multiboot_info multiboot_info_t;
+
+struct multiboot_mmap_entry
+{
+  multiboot_uint32_t size;
+  multiboot_uint64_t addr;
+  multiboot_uint64_t len;
+#define MULTIBOOT_MEMORY_AVAILABLE             1
+#define MULTIBOOT_MEMORY_RESERVED              2
+  multiboot_uint32_t type;
+} __attribute__((packed));
+typedef struct multiboot_mmap_entry multiboot_memory_map_t;
+
+struct multiboot_mod_list
+{
+  /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
+  multiboot_uint32_t mod_start;
+  multiboot_uint32_t mod_end;
+
+  /* Module command line */
+  multiboot_uint32_t cmdline;
+
+  /* padding to take it to 16 bytes (must be zero) */
+  multiboot_uint32_t pad;
+};
+typedef struct multiboot_mod_list multiboot_module_t;
+
+#endif /* ! ASM_FILE */
+
+#endif /* ! MULTIBOOT_HEADER */
diff --git a/include/Diverge/paging.h b/include/Diverge/paging.h
new file mode 100644 (file)
index 0000000..a571257
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+       paging.h
+       Paging
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Paging_Diverge_H__
+#define Paging_Diverge_H__
+
+#include<Diverge/types.h>
+
+/*Paging Common*/
+#define        MM_PAGE_SIZE            4096
+
+#define        MM_KERNEL_START         0x00010000
+
+#define        MM_PTE_INDEX_MASK       0x000003FF
+#define        MM_PTE_INDEX_SHIFT      12
+
+#define        MM_PDE_INDEX_MASK       0x000003FF
+#define        MM_PDE_INDEX_SHIFT      22
+
+#define        MM_NUM_PTE              1024
+#define        MM_PAGE_TABLE_SIZE      ( sizeof( PTE ) * MM_NUM_PTE )
+#define        MM_NUM_PDE              1024
+#define        MM_PAGE_DIRECTORY_SIZE  ( sizeof( PDE ) * MM_NUM_PDE )
+
+#define        MM_OK                   0
+#define        MM_ERROR                (-1)
+
+/*Page Table Entry*/
+typedef unsigned long PTE;
+typedef PTE    PAGE_TABLE;
+
+#define PTE_P                  0x00000001
+#define PTE_RW                 0x00000002
+#define PTE_US                 0x00000004
+#define PTE_PWT                        0x00000008
+#define PTE_PCD                        0x00000010
+#define PTE_A                  0x00000020
+#define PTE_D                  0x00000040
+#define PTE_PAT                        0x00000080
+#define PTE_G                  0x00000100
+#define PTE_AVAILABLE  0x00000e00
+#define PTE_ADDR               0xfffff000
+
+/*Page Dirctry Entry*/
+typedef unsigned long PDE;
+typedef PDE    PAGE_DIRECTORY;
+
+#define PDE_P                  0x00000001
+#define PDE_RW                 0x00000002
+#define PDE_US                 0x00000004
+#define PDE_PWT                        0x00000008
+#define PDE_PCD                        0x00000010
+#define PDE_A                  0x00000020
+#define PDE_D                  0x00000040
+#define PDE_PAT                        0x00000080
+#define PDE_G                  0x00000100
+#define PDE_AVAILABLE  0x00000e00
+#define PDE_ADDR               0xfffff000
+
+inline void set_PDE_flag(PDE* entry, unsigned long flags);
+inline void clear_PDE_flag(PDE* entry, unsigned long flags);
+void set_PDE_page_frame_addr(PDE* entry, unsigned long page_frame_addr);
+unsigned long get_PDE_frame_addr(PDE* entry);
+bool PDE_Present(PDE* entry);
+bool PDE_Write_Table(PDE* entry);
+
+inline void set_PTE_flag(PTE* entry, unsigned long flags);
+inline void clear_PTE_flag(PTE* entry, unsigned long flags);
+void set_PTE_page_frame_addr(PTE* entry, unsigned long page_frame_addr);
+unsigned long get_PTE_frame_addr(PTE* entry);
+bool PTE_Present(PTE* entry);
+bool PTE_Write_Table(PTE* entry);
+
+#endif
\ No newline at end of file
diff --git a/include/Diverge/proc.h b/include/Diverge/proc.h
new file mode 100644 (file)
index 0000000..df4351e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+       proc.h
+       Process Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Process_Diverge_H__
+#define Process_Diverge_H__
+
+#include<Diverge/types.h>
+
+#define MAX_TSS 3//Ring0, Ring3, Virtual 86
+#define MAX_PROC 0xffff
+
+/*TSS本体*/
+typedef struct{
+       unsigned int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3;//8
+       unsigned int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;//10
+       unsigned int es, cs, ss, ds, fs, gs;//6
+       unsigned int ldtr, iomap;//2
+}__attribute__((packed))tss;
+
+typedef struct{
+       unsigned int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
+       unsigned int es, cs, ss, ds, fs, gs;
+}__attribute__((packed))task_state;
+
+/*プロセスの状態を管理*/
+typedef struct{
+       unsigned char mode;
+       unsigned char state;
+       unsigned int time;
+       uint64_t count;
+       task_state regs;
+}process;
+//プロセスのモード(x86リングプロテクションに対応, デフォルトでKERNEL)
+#define KERNEL 0x00
+#define DRIVER 0x01
+#define SHELL 0x02
+#define USER 0x03
+//プロセスの状態
+#define NONE 0x00
+#define RUN 0x01
+#define SLEEP 0x02
+#define FAIL 0x03
+#define CLEAN 0x04
+#define WAIT 0x05
+//プロセスのオプション
+#define MAX_RUN_TIME 30//ミリ秒
+
+/*タスク関係のプロトタイプ宣言*/
+void tss_switch(unsigned int tss);
+void init_proc(void);
+unsigned int task_schedule(const unsigned int now);
+
+#endif
diff --git a/include/Diverge/scancode.h b/include/Diverge/scancode.h
new file mode 100644 (file)
index 0000000..5165cd8
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+       scancode.h
+       scancode
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef _SCANCODE_H_VANE_
+#define _SCANCODE_H_VANE_
+#include<Diverge/keyboard.h>
+extern KeyBoard_Status keyboard;
+
+unsigned char Generate_Scancode_To_ASCII_Code(void);
+
+/*Flag Code*/
+#define EX_FLAG 0xe0
+
+#define BREAK_NORMAL(make_code) (make_code + 0x80)
+/*Common*/
+#define SC_A   0x1e
+#define SC_B   0x30
+#define SC_C   0x2e
+#define SC_D   0x20
+#define SC_E   0x12
+#define SC_F   0x21
+#define SC_G   0x22
+#define SC_H   0x23
+#define SC_I   0x17
+#define SC_J   0x24
+#define SC_K   0x25
+#define SC_L   0x26
+#define SC_M   0x32
+#define SC_N   0x31
+#define SC_O   0x18
+#define SC_P   0x19
+#define SC_Q   0x10
+#define SC_R   0x13
+#define SC_S   0x1f
+#define SC_T   0x14
+#define SC_U   0x16
+#define SC_V   0x2f
+#define SC_W   0x11
+#define SC_X   0x2d
+#define SC_Y   0x15
+#define SC_Z   0x2c
+
+#define SC_0   0x0b
+#define SC_1   0x02
+#define SC_2   0x03
+#define SC_3   0x04
+#define SC_4   0x05
+#define SC_5   0x06
+#define SC_6   0x07
+#define SC_7   0x08
+#define SC_8   0x09
+#define SC_9   0x0a
+
+#define SC_ZEN_HAN_KAKU 0x29
+#define SC_ECOAL               0x0c
+#define SC_TILDA               0x0d
+#define SC_YEN                 0x7d
+#define SC_GAUS_RIGHT  0x2b
+#define SC_BS                  0x0e
+#define SC_SP                  0x39
+#define SC_TB                  0xof
+#define SC_CAPS                        0x3a
+#define SC_LEFT_SHIFT  0x2a
+#define SC_LEFT_CTRL   0x1d
+#define SC_LEFT_ALT            0x38
+#define SC_RIGHT_SHIFT 0x36
+
+#define SC_ENTER               0x1c
+#define SC_ESC                 0x01
+
+#define SC_F1  0x3b
+#define SC_F2  0x3c
+#define SC_F3  0x3d
+#define SC_F4  0x3e
+#define SC_F5  0x3f
+#define SC_F6  0x40
+#define SC_F7  0x41
+#define SC_F8  0x42
+#define SC_F9  0x43
+#define SC_F10 0x44
+#define SC_F11 0x57
+#define SC_F12 0x58
+
+#define SC_SCR         0x46
+#define SC_AT_MARK     0x9a
+
+#define SC_NUM_LOCK            0x45
+#define SC_NUM_KEY_AST 0x37
+#define SC_NUM_KEY_MINUS       0x4a
+#define SC_NUM_KEY_PLUS        0x79
+#define SC_NUM_KEY_PIRIOD      0x53
+#define SC_NUM_KEY_0           0x52
+#define SC_NUM_KEY_1           0x4f
+#define SC_NUM_KEY_2           0x50
+#define SC_NUM_KEY_3           0x51
+#define SC_NUM_KEY_4           0x4b
+#define SC_NUM_KEY_5           0x4c
+#define SC_NUM_KEY_6           0x4d
+#define SC_NUM_KEY_7           0x47
+#define SC_NUM_KEY_8           0x48
+#define SC_NUM_KEY_9           0x49
+
+#define SC_GAUS_LEFT                   0x1b
+#define SC_SEMI_COLON                  0x27
+#define SC_COMMA                               0x28
+#define SC_PILIOD                              0x33
+#define SC_SLASH                               0x34
+#define SC_MUHENNKANN                  0x35
+#define SC_HENNKANN                            0x7b
+#define SC_KATAKANA_HIRAGANA   0x79
+
+
+/*Break*/
+#define BREAK_LEFT_WIN         0xe0f01f
+#define BREAK_RIGHT_CTRL       0xe0f014
+#define BREAK_RIGHT_WIN                0xe0f027
+#define BREAK_RIGHT_ALT                0xe0f011
+#define BREAK_APP                      0xe0f02f
+
+#define BREAK_PRISC                                                    0xe0f012e0f07c
+#define BREAK_PAUSE                                                    0xe1f01477e1f0f014f077
+#define BREAK_INSERT                                           0xe0f070
+#define BREAK_HOME                                                     0xe0f06c
+#define BREAK_PAGE_UP                                          0xe0f07d
+#define BREAK_DEL                                                      0xe0f071
+#define BREAK_END                                                      0xe0cf
+#define BREAK_PAGE_DOWN                                                0xe0f07a
+#define BREAK_ARROW_UP                                         0xe0c8
+#define BREAK_ARROW_LEFT                                       0xe0f06b
+#define BREAK_ARROW_DOWN                                       0xe0f072
+#define BREAK_ARROW_RIGHT                                      0xe0f074
+
+#define BREAK_NUM_LOCK_AND_INS                         0xe0f070e0f012
+#define BREAK_NUM_LOCK_AND_HOME                                0xe0f006e0f012
+#define BREAK_NUM_LOCK_AND_PAGE_UP                     0xe0f07de0f012
+#define BREAK_NUM_LOCK_AND_DEL                         0xe0f071e0f012
+#define BREAK_NUM_LOCK_AND_END                         0xe0f069e0f012
+#define BREAK_NUM_LOCK_AND_PAGE_DOWN           0xe0f07ae0f012
+#define BREAK_NUM_LOCK_AND_ARROW_UP                    0xe0f075e0f012
+#define BREAK_NUM_LOCK_AND_ARROW_LEFT          0xe0f06be0f012
+#define BREAK_NUM_LOCK_AND_ARROW_DOWN          0xe0f072e0f012
+#define BREAK_NUM_LOCK_AND_ARROW_RIGHT         0xe0f074e0f012
+
+#define BREAK_LEFT_SHIFT_AND_INS                       0xe0f070e012
+#define BREAK_LEFT_SHIFT_AND_HOME                      0xe0f06ce012
+#define BREAK_LEFT_SHIFT_AND_PAGE_UP           0xe0f07de012
+#define BREAK_LEFT_SHIFT_AND_DEL                       0xe0f071e012
+#define BREAK_LEFT_SHIFT_AND_END                       0xe0f069e012
+#define BREAK_LEFT_SHIFT_AND_PAGE_DOWN         0xe0f07ae012
+#define BREAK_LEFT_SHIFT_AND_ARROW_UP          0xe0f075e012
+#define BREAK_LEFT_SHIFT_AND_ARROW_LEFT                0xe0f06be012
+#define BREAK_LEFT_SHIFT_AND_ARROW_DOWN                0xe0f072e012
+#define BREAK_LEFT_SHIFT_AND_ARROW_RIGHT       0xe0f074e012
+
+#define BREAK_RIGHT_SHIFT_AND_INS                      0xe0f070e059
+#define BREAK_RIGHT_SHIFT_AND_HOME                     0xe0f06ce059
+#define BREAK_RIGHT_SHIFT_AND_PAGE_UP          0xe0f07de059
+#define BREAK_RIGHT_SHIFT_AND_DEL                      0xe0f071e059
+#define BREAK_RIGHT_SHIFT_AND_END                      0xe0f069e059
+#define BREAK_RIGHT_SHIFT_AND_PAGE_DOWN                0xe0f07ae059
+#define BREAK_RIGHT_SHIFT_AND_ARROW_UP         0xe0f075e059
+#define BREAK_RIGHT_SHIFT_AND_ARROW_LEFT       0xe0f06be059
+#define BREAK_RIGHT_SHIFT_AND_ARROW_DOWN       0xe0f072e059
+#define BREAK_RIGHT_SHIFT_AND_ARROW_RIGHT      0xe0f074e059
+
+#define BREAK_LR_SHIFT_AND_INS                 0xe0f070e059e012
+#define BREAK_LR_SHIFT_AND_HOME                        0xe0f06ce059e012
+#define BREAK_LR_SHIFT_AND_PAGE_UP             0xe0f07de059e012
+#define BREAK_LR_SHIFT_AND_DEL                 0xe0f071e059e012
+#define BREAK_LR_SHIFT_AND_END                 0xe0f069e059e012
+#define BREAK_LR_SHIFT_AND_PAGE_DOWN   0xe0f07ae059e012
+#define BREAK_LR_SHIFT_AND_ARROW_UP            0xe0f075e059e012
+#define BREAK_LR_SHIFT_AND_ARROW_LEFT  0xe0f06be059e012
+#define BREAK_LR_SHIFT_AND_ARROW_DOWN  0xe0f072e059e012
+#define BREAK_LR_SHIFT_AND_ARROW_RIGHT 0xe0f074e059e012
+
+#define BREAK_NUM_KEY_SLASH            0xe0f04a
+#define BREAK_NUM_KEY_LEFT_SHIFT_AND_SLASH             0xe0f04ae012
+#define BREAK_NUM_KEY_RIGHT_SHIFT_AND_SLASH            0xe0f04ae059
+#define BREAK_NUM_KEY_LR_SHIFT_AND_SLASH               0xe0f04ae059e012
+
+
+/*Make*/
+#define MAKE_RIGHT_CTRL                0xe014
+#define MAKE_RIGHT_WIN         0xe027
+#define MAKE_RIGHT_ALT         0xe011
+#define MAKE_APP                       0xe02f
+
+#define MAKE_LEFT_WIN          0xe01f
+#define MAKE_PRISC                     0xe012e07c
+#define MAKE_PAUSE                     0xe11477e1f014f077
+#define MAKE_INSERT                    0xe070
+#define MAKE_HOME                      0xe06c
+#define MAKE_PAGE_UP           0xe07d
+#define MAKE_DEL                       0xe071
+#define MAKE_END                       0xe04f
+#define MAKE_PAGE_DOWN         0xe07a
+#define MAKE_ARROW_UP          0xe048
+#define MAKE_ARROW_LEFT                0xe06b
+#define MAKE_ARROW_DOWN                0xe072
+#define MAKE_ARROW_RIGHT       0xe074
+
+#define MAKE_NUM_LOCK_AND_INS                  0xe012e070
+#define MAKE_NUM_LOCK_AND_HOME                 0xe012e06c
+#define MAKE_NUM_LOCK_AND_PAGE_UP              0xe012e07d
+#define MAKE_NUM_LOCK_AND_DEL                  0xe012e071
+#define MAKE_NUM_LOCK_AND_END                  0xe012e069
+#define MAKE_NUM_LOCK_AND_PAGE_DOWN            0xe012e07a
+#define MAKE_NUM_LOCK_AND_ARROW_UP             0xe012e075
+#define MAKE_NUM_LOCK_AND_ARROW_LEFT   0xe012e06b
+#define MAKE_NUM_LOCK_AND_ARROW_DOWN   0xe012e072
+#define MAKE_NUM_LOCK_AND_ARROW_RIGHT  0xe012e074
+
+#define MAKE_LEFT_SHIFT_AND_INS                        0xe0f012e070
+#define MAKE_LEFT_SHIFT_AND_HOME               0xe0f012e06c
+#define MAKE_LEFT_SHIFT_AND_PAGE_UP            0xe0f012e07d
+#define MAKE_LEFT_SHIFT_AND_DEL                        0xe0f012e071
+#define MAKE_LEFT_SHIFT_AND_END                        0xe0f012e069
+#define MAKE_LEFT_SHIFT_AND_PAGE_DOWN  0xe0f012e07a
+#define MAKE_LEFT_SHIFT_AND_ARROW_UP   0xe0f012e075
+#define MAKE_LEFT_SHIFT_AND_ARROW_LEFT 0xe0f012e06b
+#define MAKE_LEFT_SHIFT_AND_ARROW_DOWN 0xe0f012e072
+#define MAKE_LEFT_SHIFT_AND_ARROW_RIGHT        0xe0f012e074
+
+#define MAKE_RIGHT_SHIFT_AND_INS                       0xe0f059e070
+#define MAKE_RIGHT_SHIFT_AND_HOME                      0xe0f059e06c
+#define MAKE_RIGHT_SHIFT_AND_PAGE_UP           0xe0f059e07d
+#define MAKE_RIGHT_SHIFT_AND_DEL                       0xe0f059e071
+#define MAKE_RIGHT_SHIFT_AND_END                       0xe0f059e069
+#define MAKE_RIGHT_SHIFT_AND_PAGE_DOWN         0xe0f059e07a
+#define MAKE_RIGHT_SHIFT_AND_ARROW_UP          0xe0f059e075
+#define MAKE_RIGHT_SHIFT_AND_ARROW_LEFT                0xe0f059e06b
+#define MAKE_RIGHT_SHIFT_AND_ARROW_DOWN                0xe0f059e072
+#define MAKE_RIGHT_SHIFT_AND_ARROW_RIGHT       0xe0f059e074
+
+#define MAKE_LR_SHIFT_AND_INS                  0xe0f012e0f059e070
+#define MAKE_LR_SHIFT_AND_HOME                 0xe0f012e0f059e06c
+#define MAKE_LR_SHIFT_AND_PAGE_UP              0xe0f012e0f059e07d
+#define MAKE_LR_SHIFT_AND_DEL                  0xe0f012e0f059e071
+#define MAKE_LR_SHIFT_AND_END                  0xe0f012e0f059e069
+#define MAKE_LR_SHIFT_AND_PAGE_DOWN            0xe0f012e0f059e07a
+#define MAKE_LR_SHIFT_AND_ARROW_UP             0xe0f012e0f059e075
+#define MAKE_LR_SHIFT_AND_ARROW_LEFT   0xe0f012e0f059e06b
+#define MAKE_LR_SHIFT_AND_ARROW_DOWN   0xe0f012e0f059e072
+#define MAKE_LR_SHIFT_AND_ARROW_RIGHT  0xe0f012e0f059e074
+#define MAKE_NUM_KEY_SLASH     0xe04a
+#define MAKE_NUM_KEY_LEFT_SHIFT_AND_SLASH      0xe0f012e04a
+#define MAKE_NUM_KEY_RIGHT_SHIFT_AND_SLASH     0xe0f059e04a
+#define MAKE_NUM_KEY_LR_SHIFT_AND_SLASH                0xe0f012e0f059e04a
+#define MAKE_NUM_KEY_ENTER     0xe05a
+
+
+#endif
diff --git a/include/Diverge/string.h b/include/Diverge/string.h
new file mode 100644 (file)
index 0000000..4e851eb
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+       string.h
+       C Standard Library
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef String_Diverge_C_Lib
+#define String_Diverge_C_Lib
+
+#include<Diverge/types.h>
+
+int strcmp(const char *s1, const char *s2);
+size_t strlen(const char *s);
+void *kmemset(void *s, int c, size_t n);
+char *strcpy(char *s1, const char *s2);
+
+#endif
diff --git a/include/Diverge/types.h b/include/Diverge/types.h
new file mode 100644 (file)
index 0000000..f6fc3bc
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+       types.h
+       type
+       (C) 2014-2015 VOSystems.
+*/
+
+#ifndef Type_Diverge_H__
+#define Type_Diverge_H__
+
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef char BYTE;
+typedef short WORD;
+typedef int DWORD;
+
+typedef unsigned int size_t;
+
+typedef unsigned char bool;
+#define true 1
+#define false 0
+
+#define NULL (0)
+
+/*
+#define CHAR_BIT       8
+#define SCHAR_MIN      (-128)
+#define SCHAR_MAX      127
+#define UCHAR_MAX      255
+#define CHAR_MIN       SCHAR_MIN
+#define CHAR_MAX       SCHAR_MAX
+#define SHRT_MIN       (-32768)
+#define SHRT_MAX       32767
+#define USHRT_MAX      65535
+#define INT_MIN        (-INT_MAX - 1)
+#define INT_MAX        2147483647
+#define UINT_MAX       4294967295U
+#define LONG_MAX       9223372036854775807L
+#define LONG_MAX       2147483647L
+#define ULONG_MAX      18446744073709551615UL
+#define ULONG_MAX      4294967295UL
+
+#define LLONG_MAX      9223372036854775807LL
+#define LLONG_MIN      (-LLONG_MAX - 1LL)
+
+#define ULLONG_MAX     18446744073709551615ULL
+*/
+#define UINT8_MAX      255
+#define UINT16_MAX     65535
+#define UINT32_MAX     4294967295U
+#define UINT64_MAX     18446744073709551615ULL
+
+#endif
\ No newline at end of file
diff --git a/include/string.h b/include/string.h
new file mode 100644 (file)
index 0000000..8f12aa0
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef String_Diverge_C_Lib
+#define String_Diverge_C_Lib
+
+#include<Diverge/types.h>
+
+int strcmp(const char *s1, const char *s2);
+size_t strlen(const char *s);
+void *kmemset(void *s, int c, size_t n);
+char *strcpy(char *s1, const char *s2);
+
+#endif
diff --git a/include/time.h b/include/time.h
new file mode 100644 (file)
index 0000000..77d49ef
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+       time.h
+       C standard Library
+       (C) 2015 VOSystems.
+*/
+
+#ifndef Diverge_C_Lib_
+#define Diverge_C_Lib_
+
+#include<Diverge/types.h>
+
+typedef uint64_t time_t;
+
+struct tm{
+       unsigned int tm_sec;
+       unsigned int tm_min;
+       unsigned int tm_hour;
+       unsigned int tm_mday;
+       unsigned int tm_mon;
+       unsigned int tm_year;
+       unsigned int tm_wday;
+       unsigned int tm_yday;
+       unsigned int tm_isdst;
+};
+
+#endif
\ No newline at end of file
diff --git a/kernel/Account.c b/kernel/Account.c
new file mode 100644 (file)
index 0000000..c8e62e4
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+       Account.c
+       Diverge Account Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/Account.h>
+
+#define MAX_USER_COUNT 0xff
+
+static struct user_info user[MAX_USER_COUNT];
+static struct user_info *current;
+static struct user_info *recentry;
+static struct user_info *admin,*root;
+
+static unsigned int uid_count;
+
+void init_Account(void)
+{
+       uid_count=0;
+       
+       strcpy(user[uid_count].name,"root");
+       strcpy(user[uid_count].pw,"toor");
+       user[uid_count].gid=GID_ROOT;
+       user[uid_count].uid=uid_count;
+       root=&user[uid_count];
+       uid_count++;
+       
+       strcpy(user[uid_count].name,"admin");
+       strcpy(user[uid_count].pw,"admin");
+       user[uid_count].gid=GID_ADMIN;
+       user[uid_count].uid=uid_count;
+       admin=&user[uid_count];
+       uid_count++;
+       
+       strcpy(user[uid_count].name,"Diverge");
+       strcpy(user[uid_count].pw,"diverge");
+       user[uid_count].gid=GID_USER;
+       user[uid_count].uid=uid_count;
+       uid_count++;
+       
+       current=&user[2];
+}
+
+char* GetUserNameFromUID(unsigned int uid)
+{
+       int C;
+       for(C=0; C<MAX_USER_COUNT; C++){
+               if(user[C].uid==uid)return user[C].name;
+       }
+       return 0;
+}
+
+unsigned int GetUIDFromName(const char* name)
+{
+       int C;
+       for(C=0; C<MAX_USER_COUNT; C++){
+               if(strcmp(user[C].name,name)==0)return user[C].uid;
+       }
+       return MAX_USER_COUNT;
+}
+
+unsigned int SetCurrentUserFromName(const char* name)
+{
+       int C;
+       for(C=0; C<MAX_USER_COUNT; C++){
+               if(strcmp(user[C].name,name)==0){
+                       current=&user[C];
+                       return current->uid;
+               }
+       }
+       return MAX_USER_COUNT;
+}
+
+char* GetCurrentUserName(void)
+{
+       return current->name;
+}
+
+unsigned int GetCurrentUserUID(void)
+{
+       return current->uid;
+}
+
+unsigned int GetCurrentUserGID(void)
+{
+       return current->gid;
+}
+
+struct user_info GetCurrentUserInfo(void)
+{
+       return *current;
+}
+
+void LogIn(void)
+{
+       char uname[256],pw[256];
+       kputs("Account Name : ");
+       kscanf("%s",&uname);
+       if(SetCurrentUserFromName(uname)==MAX_USER_COUNT){
+               printFAIL("Log In is Failure.");
+               LogIn();
+       }
+       
+       kputs("Password : ");
+       ScanPassword(pw);
+       if(strcmp(pw,current->pw)==0){
+               return;
+       }else{
+               printFAIL("Log In is Failure.");
+               LogIn();
+       }
+}
+
+int AdminUserDo(unsigned int fail_count)
+{
+       char pw[256];
+       if(current->gid==GID_ADMIN){
+               current=recentry;
+               return 0;
+       }
+       kputs("Admin's Password>");
+       ScanPassword(pw);
+       if(strcmp(pw,admin->pw)!=0){
+               if(fail_count>3){
+                       printFAIL("Failed to privilege change");
+                       return -1;
+               }else{
+                       fail_count++;
+                       AdminUserDo(fail_count);
+               }
+       }else{
+               recentry=current;
+               current=admin;
+       }
+       return 0;
+}
+
+int RootUserDo(unsigned int fail_count)
+{
+       char pw[256];
+       if(current->gid==GID_ROOT){
+               current=recentry;
+               return 0;
+       }
+       kputs("Root's Password>");
+       ScanPassword(pw);
+       if(strcmp(pw,root->pw)!=0){
+               if(fail_count>3){
+                       printFAIL("Failed to privilege change");
+                       return -1;
+               }else{
+                       fail_count++;
+                       RootUserDo(fail_count);
+               }
+       }else{
+               recentry=current;
+               current=root;
+       }
+       return 0;
+}
\ No newline at end of file
diff --git a/kernel/BitMap.c b/kernel/BitMap.c
new file mode 100644 (file)
index 0000000..0b2d53d
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+       BitMap.c
+       Bit Map Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/types.h>
+
+static bool is_valid(unsigned int where)
+{
+       if(where>=0 && where<4*8){
+               return true;
+       }else{
+               return false;
+       }
+}
+
+static unsigned long set_of(unsigned int where)
+{
+       return 1UL<<where;
+}
+
+void ReserveBit(unsigned long *map, unsigned int where)
+{
+       if(is_valid(where)){
+               *map |= set_of(where);
+       }
+}
+
+void RemoveBit(unsigned long *map, unsigned int where)
+{
+       if(is_valid(where)){
+               *map &= ~set_of(where);
+       }
+}
+
+bool CheckEmptyBit(unsigned long *map)
+{
+       if(*map==0)return true;
+       return false;
+}
+
+unsigned int SearchEmptyBit(unsigned long *map)
+{
+       unsigned int C;
+       int check=true;
+       for(C=0; C<32; C++){
+               check=ContainBit(map,C);
+               if(check==false){
+                       break;
+               }
+       }
+       if(check==true){
+               return 0xffffffff;
+       }
+       return C;
+}
+
+unsigned int NumCountBit(unsigned long *map)
+{
+       unsigned int count=0;
+       unsigned long x=*map;
+       while(x){
+               x &= x-1;
+               count++;
+       }
+       return count;
+}
+
+int ContainBit(unsigned long *map, unsigned int where)
+{
+       if(is_valid(where) && (*map & set_of(where))){
+               return true;
+       }else{
+               return false;
+       }
+}
\ No newline at end of file
diff --git a/kernel/DKsh.c b/kernel/DKsh.c
new file mode 100644 (file)
index 0000000..3d8bf7f
--- /dev/null
@@ -0,0 +1,344 @@
+/*
+       DKsh.c
+       Diverge Kernel shell
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/kstdio.h>
+#include<string.h>
+#include<Diverge/diverge.h>
+#include<Diverge/DrFS.h>
+#include<Diverge/dksh.h>
+#include<Diverge/DivergeAPI.h>
+
+static char current_dir[0xffff];
+static char buf[256][256];
+static short top,bottom;
+
+static struct user_info root;
+static struct user_info user;
+static struct user_info admin;
+static struct user_info *current;
+static struct user_info *recentry;
+
+static unsigned int uid_count;
+
+void init_DKsh(void)
+{
+       uid_count=0;
+       
+       strcpy(root.name,"root");
+       strcpy(root.pw,"toor");
+       root.gid=GID_ROOT;
+       root.uid=uid_count;
+       uid_count++;
+       
+       strcpy(admin.name,"admin");
+       strcpy(admin.pw,"admin");
+       admin.gid=GID_ADMIN;
+       admin.uid=uid_count;
+       uid_count++;
+       
+       strcpy(user.name,"Diverge");
+       strcpy(user.pw,"diverge");
+       user.gid=GID_USER;
+       user.uid=uid_count;
+       uid_count++;
+       
+       current=&user;
+       
+       strcpy(current_dir,"/");
+       
+       int C,i;
+       for(C=0; C<256; C++){
+               for(i=0; i<256; i++){
+                       buf[C][i]=0;
+               }
+       }
+       top=0;
+       bottom=0;
+}
+
+void DivergeKernelShell(void)
+{
+       char cmd[256]={0};
+       kputchar('\n');
+       LogIn();
+       kputchar('\n');
+       while(strcmp(cmd,"exit")){
+               ShowPrompt();
+               kscanf("%[A-Za-z0-9!\"$'()~=|-^@;:,./\\`+*?_ ]s",&cmd);
+               
+               if(strcmp(cmd,"time")==0){
+                       Dtime();
+                       
+               }else if(strcmp(cmd,"cls")==0 || strcmp(cmd,"clear")==0){
+                       ClearScreen();
+                       
+               }else if(strcmp(cmd,"apminfo")==0){
+                       DAPMInfo();
+                       
+               }else if(strcmp(cmd,"uname")==0 || strcmp(cmd,"dname")==0){
+                       Duname();
+                       
+               }else if(strcmp(cmd,"sudo")==0 || strcmp(cmd,"rodo")==0){
+                       RootUserDo(0);
+                       
+               }else if(strcmp(cmd,"audo")==0 || strcmp(cmd,"amdo")==0){
+                       AdminUserDo(0);
+                       
+               }else if(StringCompare(cmd,"cd", ' ')==0){
+                       Dcd(cmd);
+                       
+               }else if(StringCompare(cmd,"ls",' ')==0 || StringCompare(cmd,"dir",' ')==0){
+                       Dls(cmd);
+                       
+               }else if(StringCompare(cmd,"mkdir",' ')==0){
+                       Dmkdir(cmd);
+                       
+               }else if(StringCompare(cmd,"touch",' ')==0 || StringCompare(cmd,"mkfile",' ')==0){
+                       Dtouch(cmd);
+                       
+               }else if(strcmp(cmd,"exit")!=0){
+                       kprintf("DKsh: %s: Unknown Command.\n",cmd);
+               }
+       }
+}
+
+void PushHistory(char* cmd)
+{
+       strcpy(buf[bottom],cmd);
+       bottom++;
+       if(bottom==256){
+               bottom=0;
+       }
+}
+
+char* PopHistory(void)
+{
+       top++;
+       if(top==256){
+               top=0;
+       }
+       return buf[top];
+}
+
+void Dtime(void)
+{
+       unsigned char t[7];
+       GetTimeFromRTC(t);
+       kprintf("%x%x/%x/%x %x:%x:%x\n",t[6],t[5],t[4],t[3],t[2],t[1],t[0]);
+}
+
+void Duname(void)
+{
+       osversion();
+}
+
+void DAPMInfo(void)
+{
+       kprintf("APM Information\n");
+       kprintf("\tVersion            = %d\n",pc.apm.version);
+       kprintf("\t32bit Code Segment = %d\n",pc.apm.cs32);
+       kprintf("\tOffset             = %d\n",pc.apm.offset);
+       kprintf("\t16bit Code Segment = %d\n",pc.apm.cs16);
+       kprintf("\tflag               = %d\n",pc.apm.flag);
+       kprintf("\t32bit CS Size      = %d\n",pc.apm.cs32_size);
+       kprintf("\t16bit CS Size      = %d\n",pc.apm.cs16_size);
+       kprintf("\tData Segment Size  = %d\n",pc.apm.ds_size);
+}
+
+int Dcd(const char* cmd)
+{
+       bool error=false;
+       int C=3,i;
+       char tmp[500]={0};
+       
+       if(cmd[3]=='/'){
+               ChangeDir("/",current_dir,&error);
+               if(error==true)return -1;
+               C=4;
+               
+       }else if(cmd[3]=='.' && cmd[4]=='.'){
+               ChangeDir("..",current_dir,&error);
+               if(error==true)return -1;
+               C=5;
+               if(cmd[5]=='/')C++;
+               
+       }else if(cmd[3]=='.'){
+               ChangeDir(".",current_dir,&error);
+               if(error==true)return -1;
+               C=4;
+               
+       }
+       
+       while(cmd[C]!='\0'){
+               error=false;
+               for(i=0; C<500; C++, i++){
+                       if(cmd[C]=='/' || cmd[C]=='\0'){
+                               tmp[C]='\0';
+                               break;
+                       }
+                       tmp[i]=cmd[C];
+               }
+               C++;
+               ChangeDir(tmp,current_dir,&error);
+               if(error==true)return -2;
+       }
+}
+
+int Dls(const char* cmd)
+{
+       if(cmd[3]=='a' || cmd[4]=='a'){
+               ListFiles(1);
+       }else{
+               ListFiles(0);
+       }
+}
+
+int Dmkdir(const char* cmd)
+{
+       if(cmd[6]=='\0')return -1;
+       return kmkdir(&cmd[6]);
+}
+
+int Dtouch(const char* cmd)
+{
+       if(cmd[6]=='\0')return -1;
+       unsigned int start=6;
+       if(cmd[0]=='m')start++;
+       return ktouch(&cmd[start]);
+}
+
+void ShowPrompt(void)
+{
+       DisplayColorChangeChar(Green);
+       kputs(current->name);
+       kputchar('@');
+       kputs("Diverge-Alpha");
+       DisplayColorChangeChar(White);
+       kputchar(':');
+       DisplayColorChangeChar(Blue);
+       kputs(current_dir);
+       DisplayColorChangeChar(White);
+       
+       if(current->gid==GID_ROOT){
+               kputchar('#');
+       }else if(current->gid==GID_ADMIN){
+               kputchar('%');
+       }else{
+               kputchar('$');
+       }
+       kputchar(' ');
+}
+
+char* scan_pw(char* buf)
+{
+       char *p=buf;
+       char tmp=0;
+       unsigned int count=0;
+       
+       while(1){
+               tmp=kgetch();
+               if(tmp==' ' || tmp=='\n'){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+                       
+               }else if(tmp=='\b' && count>0){
+                       *p-- ='\0';
+                       count--;
+                       kputchar('\b');
+               }else{
+                       if(tmp!='\b'){
+                               *p++ =tmp;
+                               count++;
+                               kputchar('*');
+                       }else{
+                               if(count>0){
+                                       *p-- ='\0';
+                                       count--;
+                                       kputchar('\b');
+                               }
+                       }
+               }
+               if(count+1 > 256){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+                       
+               }
+       }
+       return buf;
+}
+
+void LogIn(void)
+{
+       char uname[256],pw[256];
+       kputs("Account Name : ");
+       kscanf("%s",&uname);
+       if(strcmp(uname,"root")==0){
+               current=&root;
+       }else if(strcmp(uname,"Diverge")==0){
+               current=&user;
+       }else{
+               printFAIL("Log In is Failure.");
+               LogIn();
+       }
+       kputs("Password : ");
+       scan_pw(pw);
+       if(strcmp(pw,current->pw)==0){
+               return;
+       }else{
+               printFAIL("Log In is Failure.");
+               LogIn();
+       }
+}
+
+int AdminUserDo(unsigned int fail_count)
+{
+       char pw[256];
+       if(current->gid==GID_ADMIN){
+               current=recentry;
+               return 0;
+       }
+       kputs("Admin's Password>");
+       scan_pw(pw);
+       if(strcmp(pw,admin.pw)!=0){
+               if(fail_count>3){
+                       printFAIL("Failed to privilege change");
+                       return -1;
+               }else{
+                       fail_count++;
+                       AdminUserDo(fail_count);
+               }
+       }else{
+               recentry=current;
+               current=&admin;
+       }
+       return 0;
+}
+
+int RootUserDo(unsigned int fail_count)
+{
+       char pw[256];
+       if(current->gid==GID_ROOT){
+               current=recentry;
+               return 0;
+       }
+       kputs("Root's Password>");
+       scan_pw(pw);
+       if(strcmp(pw,root.pw)!=0){
+               if(fail_count>3){
+                       printFAIL("Failed to privilege change");
+                       return -1;
+               }else{
+                       fail_count++;
+                       RootUserDo(fail_count);
+               }
+       }else{
+               recentry=current;
+               current=&root;
+       }
+       return 0;
+}
\ No newline at end of file
diff --git a/kernel/DLKB.c b/kernel/DLKB.c
new file mode 100644 (file)
index 0000000..b047faf
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+       DLKB.c
+       Diverge Low-Level Layer Library for Kernel Building
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/kstdio.h>
+#include<Diverge/diverge.h>
+#include<Diverge/types.h>
+#include<Diverge/string.h>
+
+
+void GetTimeFromRTC(unsigned char *t)
+{
+    char err;
+    static unsigned char adr[7]={0x00, 0x02, 0x04, 0x07, 0x08, 0x09, 0x32};
+    static unsigned char max[7]={0x60, 0x59, 0x23, 0x31, 0x12, 0x99, 0x99};
+    int i;
+    for (;;) { /* 読み込みが成功するまで繰り返す */
+        err = 0;
+        for (i = 0; i < 7; i++) {
+            io_out8(0x70, adr[i]);
+            t[i] = io_in8(0x71);
+        }
+        for (i = 0; i < 7; i++) {
+            io_out8(0x70, adr[i]);
+            if (t[i] != io_in8(0x71) || (t[i] & 0x0f) > 9 || t[i] > max[i]) {
+                err = 1;
+            }
+        }
+        if (err == 0) {
+            return;
+        }
+    }
+}
\ No newline at end of file
diff --git a/kernel/DivergeAPI.c b/kernel/DivergeAPI.c
new file mode 100644 (file)
index 0000000..8eff287
--- /dev/null
@@ -0,0 +1,260 @@
+/*
+       DivergeAPI.c
+       Diverge API
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/diverge.h>
+#include<Diverge/types.h>
+
+void InitCharArrey(char* arrey,size_t lengh)
+{
+       unsigned int i;
+       for(i=0;i<lengh;i++)*arrey++ =0;
+       return;
+}
+
+void Sleep(unsigned long milisec)
+{
+       unsigned long sec;
+       for(sec=0;sec<=milisec;sec+=10)io_hlt();
+}
+
+char GetKeyBoardChar(void)
+{
+       Generate_Scancode_To_ASCII_Code();
+}
+
+int CharCountInStr(char* str, char cha)
+{
+       int C,count=0;
+       for(C=0; str[C]!='\0'; C++){
+               if(str[C]==cha)count++;
+       }
+       return count;
+}
+
+void StringConnect(char* dest, const char* src)
+{
+       size_t dest_len=strlen(dest);
+       size_t C;
+       
+       for(C=0; src[C]!='\0'; dest_len++, C++){
+               dest[dest_len]=src[C];
+       }
+}
+
+void StringBreak(char* dest, const char separate)
+{
+       size_t len=strlen(dest);
+       
+       while(dest[len]!=separate){
+               dest[len]='\0';
+               len--;
+       }
+       dest[len]='\0';
+}
+
+int StringCompare(const char* s1, const char* s2, const char separate)
+{
+       while(*s1==*s2) {
+               if(*s1=='\0')return 0;
+               s1++;
+               s2++;
+               if(*s1==separate || *s2==separate)return 0;
+       }
+       return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+void LoadingPromptSec(unsigned int Sec)
+{
+       int C;
+       for(C=0; C<((Sec*1000)/(100*4)); C++){
+               LoadingPrompt();
+       }
+}
+
+void LoadingPrompt(void)
+{
+       kputchar('/');
+       Sleep(100);
+       kputchar('\b');
+       kputchar('-');
+       Sleep(100);
+       kputchar('\b');
+       kputchar('\\');
+       Sleep(100);
+       kputchar('\b');
+       kputchar('|');
+       Sleep(100);
+       kputchar('\b');
+}
+
+static void memswap(void *x, void *y, size_t n)
+{
+       unsigned char *a=(unsigned char*)x;
+       unsigned char *b=(unsigned char*)y;
+
+       for(; n--; a++, b++){
+               unsigned char c=*a;
+               *a=*b;
+               *b=c;
+       }
+}
+
+void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
+{
+       if(nmemb>0){
+               size_t pl=0;//左カーソル */
+               size_t pr=nmemb-1;//右カーソル
+               size_t pv=nmemb;//ピボット
+               size_t pt=(pl + pr)/2;//ピボットの更新値
+               char *v=(char *)base;//先頭要素へのポインタ
+               char *x;//ピボットへのポインタ
+
+               do{
+                       if (pv != pt) x = &v[(pv = pt) * size];
+
+                       while (compar((const void *)&v[pl * size], x) < 0) pl++;
+                       while (compar((const void *)&v[pr * size], x) > 0) pr--;
+                       if (pl <= pr) {
+                               pt = (pl == pv) ? pr : (pr == pv) ? pl : pv;
+                               memswap(&v[pl * size], &v[pr * size], size);
+                               pl++;
+                               if (pr == 0)    /* 符号無し整数0からのデクリメントを避ける */
+                               goto QuickRight;
+                               pr--;
+                       }
+               }while(pl<=pr);
+
+               if(0<pr)qsort(&v[0], pr+1, size, compar);
+QuickRight:
+               if(pl<nmemb-1)qsort(&v[pl*size], nmemb-pl, size, compar);
+       }
+}
+
+char* ScanPassword(char* buf)
+{
+       char *p=buf;
+       char tmp=0;
+       unsigned int count=0;
+       
+       while(1){
+               tmp=kgetch();
+               if(tmp==' ' || tmp=='\n'){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+                       
+               }else if(tmp=='\b' && count>0){
+                       *p-- ='\0';
+                       count--;
+                       kputchar('\b');
+               }else{
+                       if(tmp!='\b'){
+                               *p++ =tmp;
+                               count++;
+                               kputchar('*');
+                       }else{
+                               if(count>0){
+                                       *p-- ='\0';
+                                       count--;
+                                       kputchar('\b');
+                               }
+                       }
+               }
+               if(count+1 > 256){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+                       
+               }
+       }
+       return buf;
+}
+
+/* a/b = ans ... rem*/
+static int Divide16on32(unsigned int a, unsigned int b, unsigned int* ans, unsigned int* rem)
+{
+       if(b==0)return -1;
+       *ans=a/b;
+       *rem=a%b;
+       return 0;
+}
+
+unsigned long long DivideU64(unsigned long long a, unsigned int b)
+{
+       unsigned int a1, a2, a3, a4;
+       unsigned int b1, b2, b3, b4;
+       unsigned long long ans;
+       
+       a1=a>>48;
+       
+       a2=(a1<<16)^(a>>32);
+       
+       a3=((a1<<32)|(a2<<16))^(a>>16);
+       
+       a4=((a1<<48)|(a2<<32)|(a3<<16))^a;
+       
+       unsigned int ans1,rem1;
+       if(Divide16on32(a1,b,&ans1,&rem1)==-1)return 0;
+       a2 |= rem1<<17;
+       
+       unsigned int ans2,rem2;
+       if(Divide16on32(a2,b,&ans2,&rem2)==-1)return 0;
+       a3 |= rem2<<17;
+       
+       unsigned int ans3,rem3;
+       if(Divide16on32(a3,b,&ans3,&rem3)==-1)return 0;
+       a4 |= rem3<<17;
+       
+       unsigned int ans4,rem4;
+       if(Divide16on32(a4,b,&ans4,&rem4)==-1)return 0;
+       
+       ans=(ans1<<48)+(ans2<<32)+(ans3<<16)+ans4;
+       
+       return ans;
+}
+
+int hex2dec_bcd(int hex)
+{
+       int i,m,n=0;
+       m=hex/16;
+       if(0x0<=m && m<=0x9){
+               n+=m*10;
+       
+       }else{
+               n+=0;
+               
+       }
+       m=hex-(m*16);
+       if(0x0<=m && m<=0x9){
+               n+=m;
+       
+       }else{
+               n+=0;
+               
+       }
+       return n;
+}
+
+unsigned int DivideU64_2(unsigned long long a, unsigned long long b)    
+{
+       int i;
+       unsigned long long i_a = 0;
+       unsigned long long i_b = 0;
+       unsigned long long i_op1 = (unsigned long long)a;
+       unsigned long long i_op2 = (unsigned long long)b << 32;
+       for(i=1; i<=64; i++){
+               i_a <<= 1;
+               i_op1 <<= 1;          
+               i_b = i_op1 - i_op2;
+               if( i_b >= 0 ){
+                       i_a |= 0x01;
+                       i_op1 = i_b;
+               }
+       }
+       unsigned int ans = i_a >> 16;
+       
+       return ans;
+} 
\ No newline at end of file
diff --git a/kernel/Makefile b/kernel/Makefile
new file mode 100644 (file)
index 0000000..2bccd4e
--- /dev/null
@@ -0,0 +1,85 @@
+#Makefile(kernel)
+#Kernel Makefile
+#(C) 2014-2015 VOSystems.
+
+
+#Target
+KERNEL_BIN     = Kernel.vsb
+
+# Define
+RM     = /bin/rm
+CC     = gcc
+AS     = ${CC}
+LD     = ld
+OBJCOPY        = objcopy
+
+CFLAG  = -m32 -ffreestanding -fno-common -masm=intel -nostdlib -fno-builtin -fomit-frame-pointer -O2 -c
+AFLAG  = -m32 -ffreestanding -fno-common -fno-builtin -fomit-frame-pointer -O2 -c
+LFLAG  = -Ttext 0x100000 -melf_i386 --oformat elf32-i386 -o
+#-T link.ls -melf-i386 --oformat elf32-i386 -o
+
+INCLUDE        = -I${INCDIR}
+
+# Dir
+INCDIR = ../include
+BINDIR = ../bin
+LIBDIR = ../lib
+
+# Lib
+DMA_LIB        = ${LIBDIR}/dma.lib
+VGA_LIB        = ${LIBDIR}/vga.lib
+RFS_LIB        = ${LIBDIR}/ramfs.lib
+KBD_LIB        = ${LIBDIR}/keyboard.lib
+
+# Sufix
+.c.o:
+       ${CC} ${INCLUDE} ${CFLAG} $<
+       
+.S.o:
+       ${AS} ${INCLUDE} ${AFLAG} $<
+       
+# Sources_C
+KERNEL_C       = kernel.c
+INIT_C         = init.c
+PAGE_C         = paging.c
+PHYMEM_C       = physicalmem.c
+PROC_C         = proc.c
+TSS_C          = tss.c
+DIV_API_C      = DivergeAPI.c
+STRING_C       = string.c
+INT_C          = interrupt.c
+KSTDIO_C       = kstdio.c
+ENV_C          = env.c
+#KBD_C         = keyboard.c
+#SC_C          = scancode.c
+MBINFO_C       = mbootinfo.c
+DMSG_C         = dmsg.c
+DLKB_C         = DLKB.c
+DKSH_C         = DKsh.c
+CPUINFO_C      = cpuinfo.c
+#CURSOL_C      = cursol.c
+#DRFS_C                = DrFS.c
+BITMAP_C       = BitMap.c
+AC_C           = Account.c
+TIME_C         = time.c
+# Source_ASM
+LOAD_S         = load.S
+INT_S          = interrupt_gate.S
+CPU_S          = io_cpu.S
+TASK_S         = task.S
+
+KERNEL_OBJ=${LOAD_S:.S=.o} ${KERNEL_C:.c=.o} ${CPU_S:.S=.o} ${INT_S:.S=.o} ${INIT_C:.c=.o} ${PAGE_C:.c=.o} ${PHYMEM_C:.c=.o} ${PROC_C:.c=.o} ${TSS_C:.c=.o} ${DIV_API_C:.c=.o} ${STRING_C:.c=.o} ${INT_C:.c=.o} ${KSTDIO_C:.c=.o} ${ENV_C:.c=.o} ${MBINFO_C:.c=.o} ${DMSG_C:.c=.o} ${TASK_S:.S=.o} ${DLKB_C:.c=.o} ${DKSH_C:.c=.o} ${CPUINFO_C:.c=.o} ${BITMAP_C:.c=.o} ${TIME_C:.c=.o}
+#${AC_C:.c=.o} ${KBD_C:.c=.o} ${CURSOL_C:.c=.o} ${DRFS_C:.c=.o} ${SC_C:.c=.o}
+
+rebuild:
+       ${MAKE} clean
+       ${MAKE} kernel
+
+kernel:
+       ${MAKE} ${KERNEL_BIN}
+       @echo "  Make Kernel Succcessfully!!"
+${KERNEL_BIN}:${KERNEL_OBJ}
+       ${LD} ${LFLAG} ${KERNEL_BIN} ${KERNEL_OBJ} ${DMA_LIB} ${VGA_LIB} ${KBD_LIB} ${RFS_LIB}
+       
+clean::
+       -${RM} -f *.~ *.lo *.o make.log *.bak .a.out .core .*.core *.vsb *~
diff --git a/kernel/cpuinfo.c b/kernel/cpuinfo.c
new file mode 100644 (file)
index 0000000..0085edc
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+       cpuinfo.c
+       Input/Output
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/diverge.h>
+#include<Diverge/env_var.h>
+#include<Diverge/kstdio.h>
+
+env_pc_info pc_env;
+
+void init_CPUinfo(void)
+{
+       char vendor[80];
+       
+       printTASK("Get CPU Information");
+       CPUVendor();
+       printOK("Get CPU Information");
+       switch(pc_env.vendor){
+               case 0:
+                       printINFO("CPU Vendor = Intel"); 
+                       break;
+               case 1:
+                       printINFO("CPU Vendor = AMD");
+                       break;
+               case 2:
+                       printINFO("CPU Vendor = Centaur Technology");
+                       break;
+               case 3:
+                       printINFO("CPU Vendor = Cyrix");
+                       break;
+               case 4:
+                       printINFO("CPU Vendor = Transmeta");
+                       break;
+               case 5:
+                       printINFO("CPU Vendor = NSC");
+                       break;
+               case 6:
+                       printINFO("CPU Vendor = NexGen");
+                       break;
+               case 7:
+                       printINFO("CPU Vendor = Rise Technology");
+                       break;
+               case 8:
+                       printINFO("CPU Vendor = SiS");
+                       break;
+               case 9:
+                       printINFO("CPU Vendor = UMC");
+                       break;
+               case 10:
+                       printINFO("CPU Vendor = VIA Technology");
+                       break;  
+               default:
+                       printFAIL("Can't get CPU Vendor");
+                       break;
+       }
+       return;
+}
+
+inline void RunCPUID(struct general_registers *reg, unsigned int eax)
+{
+       __asm__ __volatile__(
+               "mov eax, %4    \n\t"
+               "cpuid                  \n\t"
+               "mov %0, eax    \n\t"
+               "mov %1, ebx    \n\t"
+               "mov %2, ecx    \n\t"
+               "mov %3, edx    \n\t"
+               :"=m"(reg->eax), "=m"(reg->ebx), "=m"(reg->ecx), "=m"(reg->edx)
+               :"m"(eax)
+       );
+}
+
+void CPUVendor(void)
+{
+       struct general_registers reg;
+       char id[15]={0};
+       RunCPUID(&reg, 0);
+       if(reg.ebx==0x756e6547 && reg.edx==0x49656e69){
+               /*Intel*/
+               pc_env.vendor=0;
+       }else if(reg.ebx==0x69444d41 || reg.ebx==0x68747541){
+               /*AMD*/
+               pc_env.vendor=1;
+       }else if(reg.ebx==0x746e6543){
+               /*Centaur*/
+               pc_env.vendor=2;
+       }else if(reg.ebx==0x69727943){
+               /*Cyrix*/
+               pc_env.vendor=3;
+       }else if(reg.ebx==0x756e6547 || reg.ebx==0x6e617254){
+               /*Transmeta*/
+               pc_env.vendor=4;
+       }else if(reg.ebx==0x646f6547){
+               /*NSC*/
+               pc_env.vendor=5;
+       }else if(reg.ebx==0x4778654e){
+               /*NexGen*/
+               pc_env.vendor=6;
+       }else if(reg.ebx==0x65736952){
+               /*Rise*/
+               pc_env.vendor=7;
+       }else if(reg.ebx==0x20536953){
+               /*SiS*/
+               pc_env.vendor=8;
+       }else if(reg.ebx==0x20434d55){
+               /*UMC*/
+               pc_env.vendor=9;
+       }else if(reg.ebx==0x20414956){
+               /*VIA*/
+               pc_env.vendor=10;
+       }else{
+               pc_env.vendor=0xff;
+       }
+}
\ No newline at end of file
diff --git a/kernel/dmsg.c b/kernel/dmsg.c
new file mode 100644 (file)
index 0000000..ea8d03f
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+       dmsg.c
+       Diverge Message Queue Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/dmsg.h>
+#include<string.h>
+#include<Diverge/types.h>
+#include<Diverge.h>
+
+#define DMSG_Q_NUM_MAX 32
+
+struct dmsg_q dmsg[DMSG_Q_NUM_MAX];
+
+void InitDMsgQ(DHANDLE handle);
+
+void init_DMsgQ(void)
+{
+       unsigned int C;
+       for(C=0; C<DMSG_Q_NUM_MAX; C++){
+               InitDMsgQ(&dmsg[C]);
+       }
+}
+
+DHANDLE CreateDMsgQ(DHANDLE handle)
+{
+       unsigned int C;
+       for(C=0; C<DMSG_Q_NUM_MAX; C++){
+               if(dmsg[C].flag == DQ_FLAG_UNUSE){
+                       dmsg[C].flag=DQ_FLAG_UNINIT;
+                       break;
+               }else{
+                       if(C>=DMSG_Q_NUM_MAX){
+                               return NULL;
+                       }
+               }
+       }
+       InitDMsgQ(&dmsg[C]);
+       dmsg[C].flag=DQ_FLAG_RUN;
+       handle=&dmsg[C];
+       return handle;
+}
+
+void DestroyDMsgQ(DHANDLE handle)
+{
+       struct dmsg_q* q=(struct dmsg_q*)handle;
+       
+       q->flag=DQ_FLAG_CLEAN;
+       InitDMsgQ(q);
+       q=NULL;
+}
+void InitDMsgQ(DHANDLE handle)
+{
+       struct dmsg_q* q=(struct dmsg_q*)handle;
+       
+       q->flag=DQ_FLAG_UNUSE;
+       int C;
+       for(C=0; C<DMSG_Q_MAX; C++){
+               q->dq[C]=0;
+       }
+       q->top=0;       q->buttom=0; q->free=DMSG_Q_MAX;
+}
+
+int EnqDMsgQ(char data, DHANDLE handle)
+{
+       struct dmsg_q* q=(struct dmsg_q*)handle;
+       
+       if(q->flag!=DQ_FLAG_RUN){
+               return -2;
+       }else if(q->free==0){
+               return -1;
+       }
+       
+       q->dq[q->buttom]=data;
+       q->buttom++;
+       
+       if(q->buttom==DMSG_Q_MAX-1){
+               q->buttom=0;
+       }
+       q->free--;
+       return 0;
+}
+
+char DeqDMsgQ(DHANDLE handle)
+{
+       struct dmsg_q* q=(struct dmsg_q*)handle;
+       
+       int data;
+       
+       if(q->flag!=DQ_FLAG_RUN){
+               return -2;
+       }else if(q->free==DMSG_Q_MAX){
+               return -1;
+       }
+       
+       data = q->dq[q->top];
+       q->dq[q->top]=0;
+       q->top++;
+       
+       if(q->top==DMSG_Q_MAX-1){
+               q->top=0;
+       }
+       
+       q->free++;
+       return data;
+}
diff --git a/kernel/env.c b/kernel/env.c
new file mode 100644 (file)
index 0000000..d055114
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+       env.c
+       Environment Var
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/env_var.h>
+
+env envv;
+
+void version(void)
+{
+       osversion();
+       shversion();
+}
+
+void shversion(void)
+{
+       kprintf("%s [Version %d.%d.%d.%d]\n",envv.shell.name, envv.shell.major, envv.shell.minor, envv.shell.rev, envv.shell.build);
+}
+
+void osversion(void)
+{
+       kprintf("%s %s [Version %d.%d.%d.%d]\n",envv.oemname, envv.osname, envv.major, envv.minor, envv.rev, envv.build);
+}
+
+void init_env(void)
+{
+       strcpy(envv.shell.name,"Divergence");
+       envv.shell.major=0;
+       envv.shell.minor=0;
+       envv.shell.rev=3;
+       envv.shell.build=29;
+       
+       strcpy(envv.oemname,"VOSystems");
+       strcpy(envv.osname,"Diverge Sts");
+       envv.major=0;
+       envv.minor=0;
+       envv.rev=1;
+       envv.build=56;
+}
diff --git a/kernel/init.c b/kernel/init.c
new file mode 100644 (file)
index 0000000..13fe756
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+       init.c
+       Initation PC
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/descriptor.h>
+#include<Diverge/interrupt.h>
+
+void init_PIC(void)
+{
+       io_out8(PORT_MASTER_PIC_COMMAND, PIC_ICW1);
+       io_out8(PORT_SLAVE_PIC_COMMAND, PIC_ICW1);
+
+       io_out8(PORT_MASTER_PIC_DATA, PIC_MASTER_ICW2);
+       io_out8(PORT_SLAVE_PIC_DATA, PIC_SLAVE_ICW2);
+
+       io_out8(PORT_MASTER_PIC_DATA, PIC_MASTER_ICW3);
+       io_out8(PORT_SLAVE_PIC_DATA, PIC_SLAVE_ICW3);
+
+       io_out8(PORT_MASTER_PIC_DATA, PIC_MASTER_ICW4);
+       io_out8(PORT_SLAVE_PIC_DATA, PIC_SLAVE_ICW4);
+       
+       io_out8(PORT_MASTER_PIC_IMR, (~PIC_IMR_MASK_IRQ0) & (~PIC_IMR_MASK_IRQ2));
+       io_out8(PORT_SLAVE_PIC_IMR, PIC_IMR_MASK_IRQ_ALL);
+       
+       io_out8(PORT_MASTER_PIC_IMR,
+                       (~PIC_IMR_MASK_IRQ0)
+                       & (~PIC_IMR_MASK_IRQ1)
+                       & (~PIC_IMR_MASK_IRQ2));
+    io_out8(PORT_SLAVE_PIC_IMR, PIC_IMR_MASK_IRQ_ALL);
+       return;
+}
+
+int init_PIT(int freq, unsigned char counter, unsigned char mode)
+{
+       unsigned short  count;
+       unsigned char   command;
+
+       count = (unsigned short)(PIT_CLOCK/freq);
+
+       command = mode | PIT_COM_RL_DATA | counter;
+
+       io_out8(PIT_REG_CONTROL, command);
+
+       io_out8(PIT_REG_COUNTER0, (unsigned char)(count & 0xFF));
+       io_out8(PIT_REG_COUNTER0, (unsigned char)((count >> 8) & 0xFF));
+}
+
+void Set_PIC_Mask(unsigned int mask)
+{
+       
+}
+
+void init_GDT(void)
+{
+       Segment_Descriptor* sd=(Segment_Descriptor*)ADR_GDT;
+       tss *tss_desc=(tss*)ADR_TSS_DESC;
+       int i;
+       
+       for(i=0; i<(LIMIT_GDT/sizeof(Segment_Descriptor)); i++){
+               Set_Segment_Descriptor(sd+i, 0, 0, 0);
+       }
+       Set_Segment_Descriptor(sd+1, 0x00000000, 0xffffffff,    AR_CODE32_SYS_ER);//Ring0
+       Set_Segment_Descriptor(sd+2, 0x00000000, 0xffffffff,    AR_DATA32_SYS_RW);//Ring0
+       Set_Segment_Descriptor(sd+3, 0x00000000, 0xffffffff,    AR_CODE32_USR_ER);//Ring3
+       Set_Segment_Descriptor(sd+4, 0x00000000, 0xffffffff,    AR_DATA32_USR_RW);//Ring3
+       Set_Segment_Descriptor(sd+5, tss_desc  , sizeof(tss),   AR_TSS32);//Ring0
+       Set_Segment_Descriptor(sd+6, tss_desc+1, sizeof(tss),   AR_TSS32);//Ring3
+       Set_Segment_Descriptor(sd+7, tss_desc+2, sizeof(tss),   AR_TSS32);//Virtual x86 Mode
+       
+       Set_Segment_Descriptor(sd+8, tss_desc  , sizeof(tss),   AR_TSS32);//Test
+       
+       load_gdtr(LIMIT_GDT, ADR_GDT);
+       
+       __asm__ __volatile__(
+               "mov eax,2*8    \n\t"
+               "mov ds,eax     \n\t"
+               "mov gs,eax     \n\t"
+               "mov fs,eax     \n\t"
+               "mov es,eax     \n\t"
+       );
+}
+
+void init_IDT(void)
+{
+       Gate_Descriptor* gd=(Gate_Descriptor*)ADR_IDT;
+       int i;
+       
+       for(i=0; i<(LIMIT_IDT/sizeof(Gate_Descriptor)); i++){
+               Set_Gate_Descriptor(gd+i, ignore_gate, 0, 0);
+       }
+       Set_Gate_Descriptor(gd+IRQ0,            timer_int_gate,                 1*8, AR_INTGATE32);
+       Set_Gate_Descriptor(gd+IRQ1,            keyboard_int_gate,              1*8, AR_INTGATE32);
+       Set_Gate_Descriptor(gd+V86EXIT,         virtual86_exit_gate,    1*8, AR_INTGATE32);
+       Set_Gate_Descriptor(gd+APPSYSCALL,      app_syscall_gate,               1*8, AR_INTGATE32);
+       Set_Gate_Descriptor(gd+DRVSYSCALL,      driver_syscall_gate,    1*8, AR_INTGATE32);
+       
+       load_idtr(LIMIT_IDT, ADR_IDT);
+}
+
+void Set_Segment_Descriptor(Segment_Descriptor *sd, unsigned int base, unsigned int limit, unsigned short ar)
+{
+       if (limit > 0xfffff) {
+               ar |= 0x8000; /* G_bit = 1 */
+               limit /= 0x1000;
+       }
+       sd->limit_low    = limit & 0xffff;
+       sd->base_low     = base & 0xffff;
+       sd->base_mid     = (base >> 16) & 0xff;
+       sd->access_right = ar & 0xff;
+       sd->limit_high   = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0);
+       sd->base_high    = (base >> 24) & 0xff;
+}
+
+void Set_Gate_Descriptor(Gate_Descriptor *gd, int offset, int selector, int ar)
+{
+       gd->offset_low   = offset & 0xffff;
+       gd->selector     = selector;
+       gd->dw_count     = (ar >> 8) & 0xff;
+       gd->access_right = ar & 0xff;
+       gd->offset_high  = (offset >> 16) & 0xffff;
+       return;
+}
diff --git a/kernel/interrupt.c b/kernel/interrupt.c
new file mode 100644 (file)
index 0000000..840f654
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+       interrrupt.c
+       Interrupt Handler C
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/interrupt.h>
+#include<Diverge/types.h>
+#include<Diverge/dmsg.h>
+
+volatile unsigned int clock;
+
+void init_interrupt_handler(void)
+{
+       clock=0;
+}
+
+void timer_int_handler(void)
+{
+       clock++;
+}
+
+int app_syscall(int eax, int ebx, int ecx, int edx, int esi, int edi)
+{
+       if(eax==1){
+               char* send;
+               send=(char*)ebx;
+               kputs(send);
+       }
+}
+
+int driver_syscall(int eax, int ebx, int ecx, int edx, int esi, int edi)
+{
+       
+}
diff --git a/kernel/interrupt_gate.S b/kernel/interrupt_gate.S
new file mode 100644 (file)
index 0000000..1b85a5c
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+       interrupt_gate.S
+       Interrupt Gate
+       (C) 2014-2015 VOSystems.
+*/
+
+.file "interrupt_gate.S"
+.intel_syntax noprefix
+.code32
+
+.global ignore_gate
+.global timer_int_gate, keyboard_int_gate
+.global virtual86_exit_gate, app_syscall_gate, driver_syscall_gate
+
+#存在しないゲート
+ignore_gate:
+       push es
+       push ds
+       pushad
+       
+       popad
+       pop ds
+       pop es
+       iret
+       
+#ここから例外
+de_ex_gate:
+       
+db_ex_gate:
+       
+nmi_ex_gate:
+       
+bp_ex_gate:
+       
+of_ex_gate:
+       
+br_ex_gate:
+       
+ud_ex_gate:
+       
+nm_ex_gate:
+       
+df_ex_gate:
+       
+cor_ex_gate:
+       
+ts_ex_gate:
+       
+np_ex_gate:
+       
+ss_ex_gate:
+       
+gp_ex_gate:
+       
+pf_ex_gate:
+       
+mf_ex_gate:
+       
+ac_ex_gate:
+       
+mc_ex_gate:
+       
+xf_ex_gate:
+       
+
+#ここから割り込みIRQ
+timer_int_gate:
+       push es
+       push ds
+       pushad
+       mov eax,esp
+       push eax
+       mov ax,ss
+       mov ds,ax
+       mov es,ax
+       call timer_int_handler
+       
+       mov al,0x20
+       out 0x20,al
+       
+       pop eax
+       popad
+       pop ds
+       pop es
+       iret
+       
+keyboard_int_gate:
+       push es
+       push ds
+       pushad
+       mov eax,esp
+       push eax
+       mov ax,ss
+       mov ds,ax
+       mov es,ax
+       call keyboard_int_handler
+       
+       mov al,0x20
+       out 0x20,al
+       
+       pop eax
+       popad
+       pop ds
+       pop es
+       iret
+
+#ここからシステムコール
+virtual86_exit_gate:#こいつだけ特殊用途(仮想86モード抜けるため)
+       push es
+       push ds
+       pushad
+       
+       jmp 5*8:0
+       
+       popad
+       pop ds
+       pop es
+       iret
+       
+app_syscall_gate:
+       push es
+       push ds
+       pushad
+       
+       push edi
+       push esi
+       push edx
+       push ecx
+       push ebx
+       push eax
+       call app_syscall
+       
+       popad
+       pop ds
+       pop es
+       iret
+       
+driver_syscall_gate:
+       push es
+       push ds
+       pushad
+       
+       push edi
+       push esi
+       push edx
+       push ecx
+       push ebx
+       push eax
+       call driver_syscall
+       
+       popad
+       pop ds
+       pop es
+       iret
+       
\ No newline at end of file
diff --git a/kernel/io_cpu.S b/kernel/io_cpu.S
new file mode 100644 (file)
index 0000000..c33f846
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+       io_cpu.S
+       Input/Output
+       (C) 2014-2015 VOSystems.
+*/
+
+.file "io_cpu.S"
+.code32
+.intel_syntax noprefix
+
+.global load_gdtr, load_idtr, io_cli, io_sti, io_hlt, load_tr
+.global io_in8, io_in16, io_in32, io_out8, io_out16, io_out32
+
+load_gdtr:
+       mov ax,[esp+4]
+       mov [esp+6],ax
+       lgdt [esp+6]
+       ret
+       
+load_idtr:
+       MOV     AX,[ESP+4]
+       MOV     [ESP+6],AX
+       LIDT [ESP+6]
+       RET
+       
+io_cli:
+       cli
+       ret
+       
+io_sti:
+       sti
+       ret
+       
+io_hlt:
+       hlt
+       ret
+       
+load_tr: # void load_tr(int tr);
+       LTR             [ESP+4] # tr
+       RET
+       
+io_in8:        # int io_in8(int port);
+       MOV     EDX,[ESP+4]             # port
+       MOV     EAX,0
+       IN      AL,DX
+       RET
+
+io_in16:       # int io_in16(int port);
+       MOV     EDX,[ESP+4]             # port
+       MOV     EAX,0
+       IN      AX,DX
+       RET
+
+io_in32:       # int io_in32(int port);
+       MOV     EDX,[ESP+4]             # port
+       IN      EAX,DX
+       RET
+
+io_out8:       # void io_out8(int port, int data);
+       MOV     EDX,[ESP+4]             # port
+       MOV     AL,[ESP+8]              # data
+       OUT     DX,AL
+       RET
+
+io_out16:      # void io_out16(int port, int data);
+       MOV     EDX,[ESP+4]             # port
+       MOV     EAX,[ESP+8]             # data
+       OUT     DX,AX
+       RET
+
+io_out32:      # void io_out32(int port, int data);
+       MOV     EDX,[ESP+4]             # port
+       MOV     EAX,[ESP+8]             # data
+       OUT     DX,EAX
+       RET
\ No newline at end of file
diff --git a/kernel/kernel.c b/kernel/kernel.c
new file mode 100644 (file)
index 0000000..3e00f36
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+       kernel.c
+       Kernel Start
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/diverge.h>
+#include<Diverge/types.h>
+#include<Diverge/interrupt.h>
+#include<Diverge/multiboot.h>
+#include<Diverge/proc.h>
+#include<Diverge/descriptor.h>
+
+void start_kernel(unsigned long magic, unsigned long addr)
+{
+       init_vga();
+       init_env();
+       version();
+       kputs("Copyright (C) 2014-2015 VOSystems. All rights reserved.\n\n");
+       
+       /*init*/
+       kputs("Starting Init\n");
+       
+       printTASK("Init VGA Cursol Manager");
+       init_Cursol();
+       printOK("Init VGA Cursol Manager");
+       
+       io_cli();
+       
+       printTASK("Setting GDT");
+       init_GDT();
+       printOK("Setting GDT");
+       
+       printTASK("Setting IDT");
+       init_IDT();
+       init_interrupt_handler();
+       printOK("Setting IDT");
+       
+       printTASK("Init Diverge Message Queue");
+       init_DMsgQ();
+       printOK("Init Diverge Message Queue");
+       
+       printTASK("Setting PIC");
+       init_PIC();
+       printOK("Setting PIC");
+       
+       printTASK("Setting PIT");
+       init_PIT(100, PIT_COM_COUNTER0, PIT_COM_MODE_SQUAREWAVE);
+       printOK("Setting PIT");
+       
+       printTASK("Init Keyboard");
+       init_keyboard();
+       printOK("Init Keyboard");
+       
+       io_sti();
+       printTASK("Init Process Manager");
+       init_proc();
+       printOK("Init Process Manager");
+       
+       printTASK("Init Task State Segment Manager");
+       init_tss();
+       printOK("Init Task State Segment Manager");
+       
+       init_MultiBoot(magic,addr);
+       
+       init_CPUinfo();
+       
+       init_DrFS();
+       
+       printTASK("Init Diverge Kernel Shell");
+       init_DKsh();
+       printOK("Init Diverge Kernel Shell");
+       
+       DivergeKernelShell();
+       
+       finDiverge();
+       
+       while(true)io_hlt();
+}
+
+void finDiverge(void)
+{
+       fin_keyboard();
+       ClearScreen();
+       
+       kputs("Press Power Key To Halt.");
+       DisplayColorChangeChar(LightGreen);
+       kputchar('\n');kputchar('\n');kputchar('\n');
+       kputs("  ________        *                                   ______                  \n");
+       kputs(" |        \\                           ____    |  /   /      \\|     ____     \n");
+       kputs(" |         \\      |   |         |    /    \\   | /   /        |    /    \\   \n");
+       kputs(" |         |      |    \\       /    /      \\  |/   /         |   /      \\  \n");
+       kputs(" |         |      |     |     |     --------  |    |        /|   --------     \n");
+       kputs(" |        /       |      \\   /      \\         |     \\      / |   \\         \n");
+       kputs(" |_______/        |       ---        \\____    |      \\____/  |    \\____     \n");
+       kputs("                                                             |                \n");
+       kputs("                                                             |                \n");
+       kputs("                                                    \\       /                \n");
+       kputs("                                                     \\_____/                 \n");
+       DisplayColorChangeChar(LightCian);
+       kputs("                    (C) 2014-2015 VOSystems.\n");
+       kputchar('\n');kputchar('\n');
+       kputs("                                       ");
+       
+       DisplayColorChangeChar(White);
+       while(true)LoadingPrompt();
+}
+
+void panic(unsigned int error)
+{
+       char cmd[256]={0};
+       ksprintf("Kernel has crashed. ECode=0x%X",error);
+       printFAIL(cmd);
+}
\ No newline at end of file
diff --git a/kernel/kstdio.c b/kernel/kstdio.c
new file mode 100644 (file)
index 0000000..8a2bb24
--- /dev/null
@@ -0,0 +1,548 @@
+/*
+       kstdio.c
+       Kernel Standard Input/Output
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/diverge.h>
+#include<Diverge/kstdio.h>
+
+bool init_flag=false;
+unsigned int fp_count;
+FILE kstdout,kstdin,kstderr;
+FILE *stdout,*stdin,*stderr;
+
+inline WriteFILE(unsigned char ch,FILE* fp)
+{
+               *fp->fp++ =ch;
+               fp->data_cnt--;
+}
+
+int kputc(unsigned char ch, FILE *fp)
+{
+       if((fp->file_desc==0) || (strcmp(fp->sign, STDOUT_SIGN)==0)){
+               DisplayOutputChar(ch);
+       
+       }else if((fp->file_desc==1) || (strcmp(fp->sign, STDIN_SIGN)==0)){
+               return -1;
+               
+       }else if((fp->file_desc==2) || (strcmp(fp->sign, STDERR_SIGN)==0)){
+               return -1;
+               
+       }else{
+               if(ch=='\n'){
+                       WriteFILE('\n',fp);
+                       
+               }else if(ch=='\r'){
+                       WriteFILE('\r',fp);
+                       
+               }else if(ch=='\t'){
+                       if(fp->data_cnt >= 2){
+                               WriteFILE(' ',fp);
+                               WriteFILE(' ',fp);
+                       }
+               
+               }else{
+                       WriteFILE(ch,fp);
+               
+               }
+       }
+       return (int)ch;
+}
+
+inline unsigned char kputchar(unsigned char ch)
+{
+       if(init_flag==false){
+               init_vga();
+       }
+       
+       kputc(ch, stdout);
+}
+
+char* uint_to_str_big_hex(char *buf, unsigned src, int base)
+{
+       char *p = buf;
+       char *p1, *p2;
+       
+       do{
+               *p++ = "0123456789ABCDEF"[src%base];
+       }while(src /= base);
+       
+       // Terminate BUF
+       *p = 0;
+       
+       // Reverse BUF
+       for(p1=buf, p2=p-1; p1 < p2; p1++, p2--){
+               char tmp = *p1;
+               *p1 = *p2;
+               *p2 = tmp;
+       }
+       
+       return buf;
+}
+
+char* uint_to_str_small_hex(char *buf, unsigned src, int base)
+{
+       char *p = buf;
+       char *p1, *p2;
+       
+       do{
+               *p++ = "0123456789abcdef"[src%base];
+       }while(src /= base);
+       
+       // Terminate BUF
+       *p = 0;
+       
+       // Reverse BUF
+       for(p1=buf, p2=p-1; p1 < p2; p1++, p2--) {
+               char tmp = *p1;
+               *p1 = *p2;
+               *p2 = tmp;
+       }
+       
+       return buf;
+}
+
+void ksprintf(char* s,char* fmt, ...)
+{
+       char **arg = (char **) &fmt;
+       char c;
+       arg++;
+
+       FILE str;
+       str.fp                  = s;
+       str.data_cnt    = 0xffff;
+       str.buf_addr    = s;
+       str.err_flag    = 0;
+       str.file_desc   = fp_count;
+       fp_count++;
+       
+       while((c = *fmt++) != 0) {
+               if(c != '%'){
+                       kputc(c,&str);
+                       
+               }else{
+                       char buf[64];
+                       char *p;
+                       c = *fmt++;
+                       
+                       if(c=='d'){
+                               // if value is minus, put '-' in the head
+                               if( 0 > *((int *) arg) ) {
+                                       kputc('-',&str);
+                                       *((int *) arg) *= -1;
+                               }
+                               p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 10);
+                               kfputs(p,&str);
+        
+                       }else if(c=='x'){
+                               p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 16);
+                               kfputs(p,&str);
+               
+               }else if(c=='X'){
+                       p = uint_to_str_big_hex(buf, *((unsigned *) arg++), 16);
+                               kfputs(p,&str);
+               
+                       }else if(c=='s'){
+                               p = *arg++;
+                               kfputs(p,&str);
+               }else if(c=='c'){
+                       p=*arg++;
+                       char send=*p;
+                       kputc(send,&str);
+                       }else{
+                               kputc(c,&str);
+               }       
+               }
+       }
+       fp_count--;
+}
+
+void kprintf(char* fmt, ...)
+{
+       char **arg = (char **) &fmt;
+       char c;
+       arg++;
+
+       while((c = *fmt++) != 0) {
+               if(c != '%'){
+                       kputchar(c);
+                       
+               }else{
+                       char buf[64];
+                       char *p;
+                       c = *fmt++;
+                       
+                       if(c=='d'){
+                               // if value is minus, put '-' in the head
+                               if( 0 > *((int *) arg) ) {
+                                       kputchar('-');
+                                       *((int *) arg) *= -1;
+                               }
+                               p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 10);
+                               kputs(p);
+        
+                       }else if(c=='x'){
+                               p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 16);
+                               kputs(p);
+               
+               }else if(c=='X'){
+                       p = uint_to_str_big_hex(buf, *((unsigned *) arg++), 16);
+                               kputs(p);
+               
+                       }else if(c=='o'){
+                       p = uint_to_str_big_hex(buf, *((unsigned *) arg++), 8);
+                               kputs(p);
+               
+                       }else if(c=='s'){
+                               p = *arg++;
+                               kputs(p);
+                               
+               }else if(c=='c'){
+                       p=*arg++;
+                       char send=*p;
+                       kputchar(send);
+                               
+                       }else{
+                               kputchar(c);
+               }       
+               }
+       }
+}
+
+void kputs(const char* msg)
+{
+       kfputs(msg,stdout);
+       return;
+}
+
+void kfputs(const char* msg,FILE* fp)
+{
+       char ch;
+       ch=*msg++;
+       
+       while(ch!='\0')
+       {
+               kputc(ch,fp);
+               ch=*msg++;
+       }
+       return;
+}
+
+char kfgetc(FILE* fp)
+{
+       if(fp->file_desc==1){
+               return kgetchar();
+               
+       }else if(fp->file_desc==0 || fp->file_desc==2){
+               return 0;
+       }else{
+               
+       }
+}
+
+char kgetchar(void)
+{
+       char code=kgetch();
+       kputchar(code);
+       return code;
+}
+
+char kgetch(void)
+{
+       char code=0;
+       while(code==0)
+       {
+               code=Generate_Scancode_To_ASCII_Code();
+       }
+       return code;
+}
+
+void printFAIL(const char* str)
+{
+       kputchar('\r');
+       kputchar('[');
+       DisplayColorChangeChar(Red);
+       kputs("fail");
+       DisplayColorChangeChar(White);
+       kprintf("] %s\n",str);
+}
+
+void printWARN(const char* str)
+{
+       kputchar('\r');
+       kputchar('[');
+       DisplayColorChangeChar(LightRed);
+       kputs("warn");
+       DisplayColorChangeChar(White);
+       kprintf("] %s\n",str);
+}
+
+void printINFO(const char* str)
+{
+       kputchar('\r');
+       kputchar('[');
+       DisplayColorChangeChar(LightBlue);
+       kputs("info");
+       DisplayColorChangeChar(White);
+       kprintf("] %s\n",str);
+}
+
+void printOK(const char* str)
+{
+       kputchar('\r');
+       kputchar('[');
+       DisplayColorChangeChar(Green);
+       kputs(" ok ");
+       DisplayColorChangeChar(White);
+       kprintf("] %s...done.\n",str);
+}
+
+void printTASK(const char* str)
+{
+       kprintf("\r[....] %s...",str);
+}
+
+int scan_num(unsigned int base)
+{
+       if(base==0)return 0;
+       
+       int scan=0;     char tmp=0;
+       unsigned int count=0;
+       
+       while(1){
+               tmp=kgetch();
+               
+               if(tmp=='0'){
+                       if(scan!=0){
+                               tmp*=base;
+                               count++;
+                               kputchar(tmp);
+                       }
+               }else if(tmp=='1'){
+                       scan+=1;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='2'){
+                       scan+=2;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='3'){
+                       scan+=3;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='4'){
+                       scan+=4;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='5'){
+                       scan+=5;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='6'){
+                       scan+=6;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='7'){
+                       scan+=7;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='8'){
+                       scan+=8;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='9'){
+                       scan+=9;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='a' || tmp=='A') && base>16){
+                       scan+=0xa;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='b' || tmp=='B') && base>16){
+                       scan+=0xb;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='c' || tmp=='C') && base>16){
+                       scan+=0xc;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='d' || tmp=='D') && base>16){
+                       scan+=0xd;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='e' || tmp=='E') && base>16){
+                       scan+=0xe;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if((tmp=='f' || tmp=='F') && base>16){
+                       scan+=0xf;
+                       scan*=base;
+                       count++;
+                       kputchar(tmp);
+                       
+               }else if(tmp=='\b' && count>0){
+                       scan/=base;
+                       count--;
+                       kputchar(tmp);
+                       
+               }else{
+                       scan/=base;
+                       break;
+               }
+       }
+       return scan;
+}
+
+char scan_char(void)
+{
+       char scan=0;
+       scan=kgetchar();
+       return scan;
+}
+
+char scan_limiter[100];
+
+char* scan_str(char* in,size_t lengh)
+{
+       char* p=in;
+       char tmp=0;
+       unsigned int count=0;
+       int C=0;
+       bool Limit_Flag=true;
+       
+       while(1){
+               tmp=kgetch();
+               for(C=0; scan_limiter[C]!='\0'; C++){
+                       if(tmp==scan_limiter[C]){
+                               Limit_Flag=false;
+                       }
+               }
+               
+               if(Limit_Flag==true || tmp=='\n'){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+               }
+               if(tmp=='\b' && count>0){
+                       *p-- ='\0';
+                       count--;
+                       kputchar('\b');
+               }else{
+                       if(tmp!='\b'){
+                               *p++ =tmp;
+                               count++;
+                               kputchar(tmp);
+                       }else{
+                               if(count>0){
+                                       *p-- ='\0';
+                                       count--;
+                                       kputchar('\b');
+                               }
+                       }
+               }
+               if(count+1 > lengh){
+                       kputchar('\n');
+                       *p='\0';
+                       break;
+                       
+               }
+       }
+       return in;
+}
+
+void kscanf(const char* fmt,...)
+{
+       char **arg = (char **) &fmt;
+       arg++;
+       char ch=*fmt++;
+       while(ch!='\0'){
+               if(ch=='%'){
+                       ch=*fmt++;
+                       if(ch=='d'){
+                               //int *p=*arg++;
+                               *arg++ =scan_num(10);
+                               
+                       }else if(ch=='x' || ch=='X'){
+                               //int *p=*arg++;
+                               *arg++ =scan_num(16);
+                               
+                       }else if(ch=='o'){
+                               //int *p=*arg++;
+                               *arg++ =scan_num(8);
+                               
+                       }else if(ch=='c'){
+                               //char* p=*arg++;
+                               *arg++ =scan_char();
+                               
+                       }else if(ch=='['){
+                               int C=0;
+                               ch=*fmt++;
+                               int limiter_point=0;
+                               const char strTable[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\0"};
+                               
+                               while(ch!=']'){
+                                       if(ch=='-'){
+                                               ch=*fmt++;
+                                               if((0x30<=ch && ch<=0x39) || (0x41<=ch && ch<=0x5a) || (0x61<=ch && ch<=0x7a)){
+                                                       for(C=0; strTable[C]!=scan_limiter[limiter_point-1] && C<(sizeof(strTable)/sizeof(strTable[0])); C++);
+                                                       int start=C;
+                                                       for(C=0; strTable[C]!=ch && C<(sizeof(strTable)/sizeof(strTable[0])); C++);
+                                                       int end=C;
+                                                       for(C=start; C<=end && limiter_point<100; C++){
+                                                               scan_limiter[limiter_point]=strTable[C];
+                                                               limiter_point++;
+                                                       }
+                                               }else{
+                                                       scan_limiter[limiter_point]=ch;
+                                                       limiter_point++;
+                                               }
+                                       }else{
+                                               scan_limiter[limiter_point]=ch;
+                                               limiter_point++;
+                                       }
+                                       ch=*fmt++;
+                               }
+                               ch=*fmt++;
+                               if(ch=='s'){
+                                       goto string_scan;
+                               }
+                       }else if(ch=='s'){
+                               strcpy(scan_limiter,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()~=|@[;:]`{+*},./\\<>?_^-");
+string_scan:
+                               *arg=scan_str(*arg,0xffff);
+                               InitCharArrey(scan_limiter,100);
+                               *arg++;
+                       }
+               }
+               ch=*fmt++;
+       }
+}
diff --git a/kernel/load.S b/kernel/load.S
new file mode 100644 (file)
index 0000000..0176472
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+       load.S
+       Load
+       (C) 2014-2015 VOSystems.
+*/
+
+#define ASM_FILE       1
+#include <Diverge/multiboot.h>
+
+/* C symbol format. HAVE_ASM_USCORE is defined by configure.  */
+#ifdef HAVE_ASM_USCORE
+# define EXT_C(sym)                    _ ## sym
+#else
+# define EXT_C(sym)                    sym
+#endif
+
+/* The size of our stack (16KB).  */
+#define STACK_SIZE                     0x4000
+
+/* The flags for the Multiboot header.  */
+#ifdef __ELF__
+# define MULTIBOOT_HEADER_FLAGS                0x00000003
+#else
+# define MULTIBOOT_HEADER_FLAGS                0x00010003
+#endif
+       
+       .text
+
+       .globl  start, _start
+start:
+_start:
+       jmp     multiboot_entry
+
+       /* Align 32 bits boundary.  */
+       .align  4
+
+       /* Multiboot header.  */
+multiboot_header:
+       /* magic */
+       .long   MULTIBOOT_HEADER_MAGIC
+       /* flags */
+       .long   MULTIBOOT_HEADER_FLAGS
+       /* checksum */
+       .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
+#ifndef __ELF__
+       /* header_addr */
+       .long   multiboot_header
+       /* load_addr */
+       .long   _start
+       /* load_end_addr */
+       .long   _edata
+       /* bss_end_addr */
+       .long   _end
+       /* entry_addr */
+       .long   multiboot_entry
+       /*Video Mode*/
+#endif /* ! __ELF__ */
+
+multiboot_entry:
+       /* Initialize the stack pointer.  */
+       movl    $(stack + STACK_SIZE), %esp
+
+       /* Reset EFLAGS.  */
+       pushl   $0
+       popf
+
+       /* Push the pointer to the Multiboot information structure.  */
+       pushl   %ebx
+       /* Push the magic value.  */
+       pushl   %eax
+
+       /* Now enter the C main function...  */
+       call    EXT_C(start_kernel)
+       RET
+       /* Halt.  */
+       pushl   $halt_message
+       call    EXT_C(kprintf)
+       
+loop:  hlt
+       jmp     loop
+
+halt_message:
+       .asciz  "Halted."
+
+       /* Our stack area.  */
+       .comm   stack, STACK_SIZE
diff --git a/kernel/mbootinfo.c b/kernel/mbootinfo.c
new file mode 100644 (file)
index 0000000..cec6c98
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+       mbootinfo.c
+       MultiBoot Info
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/multiboot.h>
+#include<Diverge/diverge.h>
+
+struct pc_info pc;
+
+void init_MultiBoot(unsigned long magic, unsigned long addr)
+{
+       multiboot_info_t *mbi = (multiboot_info_t *) addr;
+       
+       pc.cmd=mbi->cmdline;
+       MB_memory(mbi, magic);
+       MB_apm(mbi);
+}
+
+void MB_memory(multiboot_info_t* mbi,unsigned long magic)
+{
+       printTASK("Loading Memory Info");
+       if(magic!=MULTIBOOT_BOOTLOADER_MAGIC){
+               printFAIL("Loading Memory Info");
+               
+       }else{
+               char meminfo[100];
+               printOK("Loading Memory Info");
+               pc.mem.low_size=mbi->mem_lower;
+               pc.mem.up_size=mbi->mem_upper;
+               pc.mem.size=(pc.mem.low_size + pc.mem.up_size)/1024;
+               ksprintf(meminfo,"Total Memory = %d MiB",pc.mem.size);
+               printINFO(meminfo);
+       }
+}
+
+void MB_apm(multiboot_info_t* mbi)
+{
+       printTASK("Loading APM Info");
+       struct apm_info* apm=(struct apm_info*)mbi->apm_table;
+       pc.apm.version          = apm->version;
+       pc.apm.cs32                     = apm->cs32;
+       pc.apm.offset           = apm->offset;
+       pc.apm.cs16                     = apm->cs16;
+       pc.apm.ds16                     = apm->ds16;
+       pc.apm.flag                     = apm->flag;
+       pc.apm.cs32_size        = apm->cs32_size;
+       pc.apm.cs16_size        = apm->cs16_size;
+       pc.apm.ds_size          = apm->ds_size;
+       printOK("Loading APM Info");
+}
diff --git a/kernel/memory_map_diverge.txt b/kernel/memory_map_diverge.txt
new file mode 100644 (file)
index 0000000..414cf08
--- /dev/null
@@ -0,0 +1,4 @@
+Kernel                                 0x00100000-?                    10MiB
+Pysical Memory Bit Map 0x00bfa799-0x00bff799   20KiB
+IDT                                            0x00bff800-0x00bfffff   1 KiB
+GDT                                            0x00e00000-0x00efffff   1 KiB
\ No newline at end of file
diff --git a/kernel/paging.c b/kernel/paging.c
new file mode 100644 (file)
index 0000000..de7a70c
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+       paging.c
+       Paging Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/paging.h>
+#include<Diverge/types.h>
+
+/*PDE*/
+inline void set_PDE_flag(PDE* entry, unsigned long flags)
+{
+       *entry |= flags;
+}
+
+inline void clear_PDE_flag(PDE* entry, unsigned long flags)
+{
+       *entry &= ~flags;
+}
+
+void set_PDE_page_frame_addr(PDE* entry, unsigned long page_frame_addr)
+{
+       page_frame_addr &= PDE_ADDR;
+       *entry |= page_frame_addr;
+}
+
+unsigned long get_PDE_frame_addr(PDE* entry)
+{
+       return (*entry & PDE_ADDR);
+}
+
+bool PDE_Present(PDE* entry)
+{
+       return ((*entry & PDE_P)==PDE_P);
+}
+
+bool PDE_Write_Table(PDE* entry)
+{
+       return ((*entry & PDE_RW)==PDE_RW);
+}
+
+/*PTE*/
+PTE page_table[1024];
+
+inline void set_PTE_flag(PTE* entry, unsigned long flags)
+{
+       *entry |= flags;
+}
+
+inline void clear_PTE_flag(PTE* entry, unsigned long flags)
+{
+       *entry &= ~flags;
+}
+
+void set_PTE_page_frame_addr(PTE* entry, unsigned long page_frame_addr)
+{
+       page_frame_addr &= PTE_ADDR;
+       *entry |= page_frame_addr;
+}
+
+unsigned long get_PTE_frame_addr(PTE* entry)
+{
+       return (*entry & PTE_ADDR);
+}
+
+bool PTE_Present(PTE* entry)
+{
+       return ((*entry & PTE_P)==PTE_P);
+}
+
+bool PTE_Write_Table(PTE* entry)
+{
+       return ((*entry & PTE_RW)==PTE_RW);
+}
+
diff --git a/kernel/physicalmem.c b/kernel/physicalmem.c
new file mode 100644 (file)
index 0000000..81f7843
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+       pysicalmem.c
+       Pysical Memory Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/memory.h>
+#include<Diverge/diverge.h>
+#include<Diverge/types.h>
+
+PHYSICAL_MEMORY_INFO pm_info;
+#define DEF_MEMORY_KERNEL_START 0x00100000
+#define DEF_MEMORY_BLOCK_SIZE (4*1024)
+
+inline unsigned int getSystemMemoryBlocks(void)
+{
+       return (pm_info.system_memory_blocks);
+}
+
+inline unsigned int getSystemMemorySize(void)
+{
+       return (pm_info.system_memory_size);
+}
+
+void init_Physical_Memory(unsigned int memory_size)
+{
+       
+}
+
+void initPhysicalMemoryManagement(unsigned int memory_size)
+{
+       pm_info.system_memory_size              = memory_size;
+       pm_info.system_memory_blocks    = getSystemMemorySize()/DEF_MEMORY_BLOCK_SIZE;
+       pm_info.allocated_blocks                = getSystemMemoryBlocks();
+       pm_info.free_blocks                             = 0;
+       pm_info.memory_map                              = (unsigned int*)(MEM_BITMAP_ADDR);
+    pm_info.memory_map_size                    = getSystemMemoryBlocks()/32;
+
+    /* ------------------------------------------------------------------------ */
+    /*  all blocks are allocated at initialization                              */
+    /* ------------------------------------------------------------------------ */
+       kmemset((void*)pm_info.memory_map, 0xFF, pm_info.memory_map_size);
+}
+
+inline void setBit(int bit_number)
+{
+    pm_info.memory_map[ bit_number/32] |= (1 << (bit_number%32));
+}
+
+inline void clearBit(int bit_number)
+{
+    pm_info.memory_map[ bit_number/32] &= ~(1 << (bit_number%32));
+}
+
+bool testBit( int bit_number )
+{
+       unsigned int _test;
+
+       _test = pm_info.memory_map[ bit_number / 32 ] & ( 1 << ( bit_number % 32 ) );
+
+       return( _test > 0 );
+}
+
+int findFirstFreeMemoryBlock(unsigned int *block_number)
+{
+    unsigned int bitmap_index;
+    unsigned int bit_count;
+    unsigned int found;
+
+    /* ------------------------------------------------------------------------ */
+    /*  iterate each element of the bitmap                                      */
+    /* ------------------------------------------------------------------------ */
+    for(bitmap_index=0; bitmap_index<pm_info.memory_map_size; bitmap_index++)
+    {
+        /* -------------------------------------------------------------------- */
+        /*  if the element has candidate spaces                                 */
+        /* -------------------------------------------------------------------- */
+        if(pm_info.memory_map[bit_count] != 0xFFFFFFFF)
+        {
+            /* ---------------------------------------------------------------- */
+            /*  iterate each bit of the element                                 */
+            /* ---------------------------------------------------------------- */
+            for( bit_count = 0 ; bit_count < 32 ; bit_count++ )
+            {
+                if( false == testBit( bit_count ) )
+                {
+                    /* -------------------------------------------------------- */
+                    /*  return bitmap index number                              */
+                    /* -------------------------------------------------------- */
+                    *block_number
+                        = bitmap_index * sizeof( unsigned int ) * 8 + bit_count;
+
+                    return(1);
+                }
+            }
+        }
+    }
+    
+    return(-1);
+}
+
+void initFreedMemoryRegion(void *base_address, uint32_t size)
+{
+    uint32_t block_number;
+    int32_t block_size;
+    int32_t i;
+
+    block_number = (uint32_t)base_address / DEF_MEMORY_BLOCK_SIZE;
+    block_size   = size / DEF_MEMORY_BLOCK_SIZE;
+
+    /* ------------------------------------------------------------------------ */
+    /*  all blocks of the memory region are freed                               */
+    /* ------------------------------------------------------------------------ */
+    for( i = block_size ; 0 < i ; i-- )
+    {
+        clearBit( block_number );
+
+        block_number--;
+        pm_info.allocated_blocks--;
+        pm_info.free_blocks++;
+    }
+}
+
+void initAllocatedMemoryRegion(void *base_address, uint32_t size )
+{
+    uint32_t block_number;
+    int32_t block_size;
+    int32_t i;
+
+    block_number = (uint32_t)base_address / DEF_MEMORY_BLOCK_SIZE;
+    block_size   = size / DEF_MEMORY_BLOCK_SIZE;
+
+    /* ------------------------------------------------------------------------ */
+    /*  all blocks of the memory region are allocated                           */
+    /* ------------------------------------------------------------------------ */
+    for( i = block_size ; 0 <= i ; i-- )
+    {
+        setBit( block_number );
+
+        block_number--;
+        pm_info.allocated_blocks++;
+        pm_info.free_blocks--;
+    }
+}
+
+void *allocSingleMemoryBlock(void)
+{
+    unsigned int block_number;
+    void* physical_address;
+    int status;
+
+    /* ------------------------------------------------------------------------ */
+    /*  there is no free block                                                  */
+    /* ------------------------------------------------------------------------ */
+    if( pm_info.free_blocks <= 0 )
+    {
+        return(NULL);
+    }
+       
+    /* ------------------------------------------------------------------------ */
+    /*  get a free block number                                                 */
+    /* ------------------------------------------------------------------------ */
+    status = findFirstFreeMemoryBlock( &block_number );
+
+    if( status != 1 )
+    {
+        return(NULL);
+    }
+       
+    setBit( block_number );
+
+    physical_address = (void*)( block_number * DEF_MEMORY_BLOCK_SIZE );
+
+    pm_info.allocated_blocks++;
+    pm_info.free_blocks--;
+
+    return( physical_address );
+}
+
+void freeSingleMemoryBlock(void* physical_address )
+{
+    unsigned int block_number;
+
+    block_number = ( unsigned int )physical_address / DEF_MEMORY_BLOCK_SIZE;
+
+    clearBit( block_number );
+
+    pm_info.allocated_blocks--;
+    pm_info.free_blocks++;
+}
diff --git a/kernel/proc.c b/kernel/proc.c
new file mode 100644 (file)
index 0000000..4f6579f
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+       proc.c
+       Process Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/proc.h>
+#include<Diverge/descriptor.h>
+
+process proc[MAX_PROC];
+
+void init_proc(void)
+{
+       tss* tss_desc=(tss*)ADR_TSS_DESC;
+       int i;
+       for(i=0; i<MAX_PROC; i++){
+               proc[i].mode=USER;//USERにしておけば誤爆が防げるかな?ww
+               proc[i].state=NONE;
+               proc[i].time=0;
+       }
+}
+
+unsigned int task_schedule(const unsigned int now)
+{
+       unsigned int i;
+       unsigned int next,temp=0,tmp/*比較用*/;
+       
+       for(i=0; i<MAX_PROC; i++){
+               if(i+now>MAX_PROC){
+                       next=(i+now)-MAX_PROC;
+               }else{
+                       next=i+now;
+               }
+               if(proc[next].state==RUN && proc[next].count>temp){
+                       temp=proc[next].count;
+                       tmp=next;
+               }
+       }
+       next=tmp;
+       return next;
+}
diff --git a/kernel/string.c b/kernel/string.c
new file mode 100644 (file)
index 0000000..9bae874
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+       string.c
+       C Standard Library string.h
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/types.h>
+
+
+int strcmp(const char *s1, const char *s2)
+{
+       while(*s1==*s2) {
+               if(*s1=='\0')return 0;
+               s1++;
+               s2++;
+       }
+       return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+size_t strlen(const char *s)
+{
+       size_t len=0;
+
+       while(*s++)len++;
+       return len;
+}
+
+void *kmemset(void *s, int c, size_t n)
+{
+       const unsigned char uc=c;
+       unsigned char *p=(unsigned char *)s;
+
+       while(n-- >0)
+       *p++ =uc;
+
+       return s;
+}
+
+char *strcpy(char *s1, const char *s2)
+{
+       char *p=s1;
+       while(*s1++ =*s2++);
+       return p;
+}
+
+char *strchr(const char *s, int c)
+{
+       c=(char)c;
+       while(*s!=c){
+               if (*s=='\0')return NULL;
+               s++;
+       }
+       return (char *)s;
+}
+
+char *strstr(const char *s1, const char *s2)
+{
+       if(*s2=='\0')return (char *)s1;
+
+       for(; (s1=strchr(s1, *s2))!=NULL; ++s1){
+               const char *sc1=s1;
+               const char *sc2=s2;
+
+               do{
+                       if(*++sc2=='\0')return (char *)s1;
+               }while(*++sc1==sc2);
+       }
+
+       return NULL;
+}
+
+size_t strcspn(const char *s1, const char *s2)
+{
+       const char *p=s1;
+
+       for(; *s1; s1++){
+               const char *t;
+
+               for(t=s2; *t; t++)
+                       if(*t==*s1)return s1-p;
+       }
+       return s1-p;
+}
+
+char *strpbrk(const char *s1, const char *s2)
+{
+       for(; *s1; s1++){
+               const char *t=s2;
+               for(; *t; t++)
+                       if(*t==*s1)return (char *)s1;
+       }
+       return NULL;
+}
\ No newline at end of file
diff --git a/kernel/task.S b/kernel/task.S
new file mode 100644 (file)
index 0000000..cc6489e
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+       task.S
+       Task Manager
+       (C) 2014-2015 VOSystems.
+*/
+
+.file "task.S"
+.code32
+.intel_syntax noprefix
+
+.global tss_switch
+
+tss_switch:
+       jmp far [ESP+4] # eip, cs
+       ret
\ No newline at end of file
diff --git a/kernel/time.c b/kernel/time.c
new file mode 100644 (file)
index 0000000..a473a81
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+       time.c
+       C standard Library
+       (C) 2015 VOSystems.
+*/
+
+#include<time.h>
+
+struct tm ttime;
+
+time_t time(time_t* timer)
+{
+       if(timer!=NULL)
+       {
+               return *timer;
+       }
+       time_t ntime;
+       unsigned char gtime[7];
+       GetTimeFromRTC(gtime);
+       int time[7];
+       int i;
+       for(i=0;i<7;i++){
+               time[i]=hex2dec_bcd(gtime[i]);
+       }
+       int year=1970-time[6]*100+time[5];
+       
+       ntime+=time[0];//sec
+       ntime+=time[1]*60;//min
+       ntime+=time[2]*60*60;//hour
+       ntime+=time[3]*60*60*24;//day
+       ntime+=time[4]*60*60*24*30;//mon
+       ntime+=year*60*60*24*30*12;//year from 2010
+       return ntime;
+}
+
+struct tm* localtime(time_t* timer)
+{
+       
+       ttime.tm_year=DivideU64_2(*timer,(60*60*24*30*12));//year from 1970
+       timer-=ttime.tm_year*(60*60*24*30*12);
+       
+       ttime.tm_mon=DivideU64_2(*timer,(60*60*24*30));//mon
+       timer-=ttime.tm_mon*(60*60*24*30);
+       
+       ttime.tm_mday=DivideU64_2(*timer,(60*60*24));//day
+       timer-=ttime.tm_mday*(60*60*24);
+       
+       ttime.tm_hour=DivideU64_2(*timer,(60*60));//hour
+       timer-=ttime.tm_hour*(60*60);
+       
+       ttime.tm_min=DivideU64_2(*timer,60);//min
+       timer-=ttime.tm_min*(60);
+       
+       ttime.tm_sec=*timer;//sec
+       /*
+       ttime.tm_year=*timer/(60*60*24*30*12);//year from 1970
+       timer-=ttime.tm_year*(60*60*24*30*12);
+       
+       ttime.tm_mon=*timer/(60*60*24*30);//mon
+       timer-=ttime.tm_mon*(60*60*24*30);
+       
+       ttime.tm_mday=*timer/(60*60*24);//day
+       timer-=ttime.tm_mday*(60*60*24);
+       
+       ttime.tm_hour=*timer/(60*60);//hour
+       timer-=ttime.tm_hour*(60*60);
+       
+       ttime.tm_min=*timer/60;//min
+       timer-=ttime.tm_min*(60);
+       
+       ttime.tm_sec=*timer;//sec*/
+       return &ttime;
+}
\ No newline at end of file
diff --git a/kernel/tss.c b/kernel/tss.c
new file mode 100644 (file)
index 0000000..edd256c
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+       tss.c
+       Task State Segment Library
+       (C) 2014-2015 VOSystems.
+*/
+
+#include<Diverge/proc.h>
+#include<Diverge/descriptor.h>
+
+void InitTSS(tss* tss_desc, unsigned char ring);
+void ChangeProtect2V86(tss* tss_desc);
+
+void LoopTest(void)
+{
+       kputs("In Loop Test\n");
+       while(1);
+}
+
+void init_tss(void)
+{
+       tss* tss_desc=(tss*)ADR_TSS_DESC;
+       int C=0;
+       for(C=0; C<MAX_TSS; C++){
+               tss_desc[C].backlink=0;
+               tss_desc[C].esp0=0;
+               tss_desc[C].ss0=0;
+               tss_desc[C].esp1=0;
+               tss_desc[C].ss1=0;
+               tss_desc[C].esp2=0;
+               tss_desc[C].ss2=0;
+               tss_desc[C].cr3=0;
+               tss_desc[C].eip=0;
+               tss_desc[C].eflags=0x00000202;
+               tss_desc[C].eax=0;
+               tss_desc[C].ecx=0;
+               tss_desc[C].edx=0;
+               tss_desc[C].ebx=0;
+               tss_desc[C].esp=0;
+               tss_desc[C].ebp=0;
+               tss_desc[C].esi=0;
+               tss_desc[C].edi=0;
+               tss_desc[C].es=0;
+               tss_desc[C].cs=0;
+               tss_desc[C].ss=0;
+               tss_desc[C].ds=0;
+               tss_desc[C].fs=0;
+               tss_desc[C].gs=0;
+               tss_desc[C].ldtr=0;
+               tss_desc[C].iomap=0x40000000;
+       }
+       InitTSS(&tss_desc[0], 0);
+       InitTSS(&tss_desc[1], 3);
+       InitTSS(&tss_desc[2], 0);
+       InitTSS(&tss_desc[3], 0);
+       ChangeProtect2V86(&tss_desc[2]);
+       
+       ChangeEIP(&tss_desc[3], LoopTest);
+       
+       load_tr(5*8);
+}
+
+void InitTSS(tss* tss_desc, unsigned char ring)
+{
+       if(ring==3){
+               tss_desc->cs=3*8;
+               tss_desc->ds=4*8;
+               tss_desc->es=4*8;
+               tss_desc->fs=4*8;
+               tss_desc->gs=4*8;
+               tss_desc->eflags=0x00003202;
+       }else if(ring==0){
+               tss_desc->cs=1*8;
+               tss_desc->ds=2*8;
+               tss_desc->es=2*8;
+               tss_desc->fs=2*8;
+               tss_desc->gs=2*8;
+               tss_desc->eflags=0x00000202;
+       }
+}
+
+void ChangeProtect2V86(tss* tss_desc)
+{
+       tss_desc->eflags=0x00023202; 
+}
+
+void ChangeEIP(tss* tss_desc, unsigned int eip)
+{
+       tss_desc->eip=eip;
+}
+
diff --git a/lib/dma.lib b/lib/dma.lib
new file mode 100644 (file)
index 0000000..44d1681
Binary files /dev/null and b/lib/dma.lib differ
diff --git a/lib/keyboard.lib b/lib/keyboard.lib
new file mode 100644 (file)
index 0000000..30b7e20
Binary files /dev/null and b/lib/keyboard.lib differ
diff --git a/lib/libosdk.a b/lib/libosdk.a
new file mode 100644 (file)
index 0000000..7ee5bf3
Binary files /dev/null and b/lib/libosdk.a differ
diff --git a/lib/link.ls b/lib/link.ls
new file mode 100644 (file)
index 0000000..5f478ea
--- /dev/null
@@ -0,0 +1,26 @@
+OUTPUT_FORMAT("elf32")
+OUTPUT_ARCH("i386")
+
+SECTIONS
+{
+       .long(0x)
+    .text :
+    {
+        *(.text)
+    }
+
+    .rodata :
+    {
+        *(.rodata)
+    }
+
+    .data :
+    {
+        *(.data)
+    }
+
+    .bss :
+    {
+        *(.bss)
+    }
+}
\ No newline at end of file
diff --git a/lib/ramfs.lib b/lib/ramfs.lib
new file mode 100644 (file)
index 0000000..1649548
Binary files /dev/null and b/lib/ramfs.lib differ
diff --git a/lib/string.c b/lib/string.c
new file mode 100644 (file)
index 0000000..61bc5d0
--- /dev/null
@@ -0,0 +1,33 @@
+#include<types.h>
+
+
+int strcmp(const char *s1, const char *s2)
+{
+    while (*s1 == *s2) {
+        if (*s1 == '\0')            /* 等しい */
+            return (0);
+        s1++;
+        s2++;
+    }
+    return ((unsigned char)*s1 - (unsigned char)*s2);
+}
+
+size_t strlen(const char *s)
+{
+    size_t len = 0;
+
+    while (*s++)
+        len++;
+    return (len);
+}
+
+void *kmemset(void *s, int c, size_t n)
+{
+    const unsigned char uc = c;
+    unsigned char       *p = (unsigned char *)s;
+
+    while (n-- > 0)
+        *p++ = uc;
+
+    return (s);
+}
\ No newline at end of file
diff --git a/lib/vga.lib b/lib/vga.lib
new file mode 100644 (file)
index 0000000..1fde0c8
Binary files /dev/null and b/lib/vga.lib differ