vm86.c

00001 /***************************************************************************
00002                           vm86.c  -  description
00003                              -------------------
00004     begin                : Tue Feb 10 2004
00005     copyright            : (C) 2004 by Dynacube Team
00006     email                : 
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "core/vm86.h"
00019  #include "proc/proc.h"
00020  #include "gui/svga.h"
00021  #include "common/ds/queue.h"
00022 
00023   PROC vm86_bk;
00024   VBEINFO *VbeInfoBlock;
00025   VBE_ModeInfo vbe_mode;
00026  
00027   void svgainit() //Task that would be copied to < 1Mb space
00028   {
00029     asm("int $0x10"::"a"(0x4F01),"c"(0x114),"D"(0x1000));
00030     asm("int $0x10"::"a"(0x4F02),"b"(0x4114),"c"(0x0));
00031     asm("int $0xFF");
00032   }
00033 
00034   void handleVM86(REGS *regs)
00035   {
00036     DD i;
00037     DB opcode, opr1, opr2, opr3;
00038     DD stck_ret, vid_modes;
00039     DD temp;
00040 
00041         DW *vid = (DW *)0xA0000;
00042     
00043     memcpy((void *)&vm86_bk,(void *)&_proc[cur_pid],sizeof(PROC));
00044     
00045     VM86REGS *vmregs = (VM86REGS *) regs;
00046     DD phy;
00047 
00048     printf("\nInside handleVM86");
00049     printRegs(regs);
00050     printf("\nVMREGS cs %x ds %x es %x \n fs %x gs %x",vmregs->cs,vmregs->_ds,vmregs->_es,vmregs->_fs,vmregs->_gs);
00051     _proc[cur_pid].ds = vmregs->_ds;
00052     _proc[cur_pid].es = vmregs->_es;
00053     _proc[cur_pid].fs = vmregs->_fs;
00054     _proc[cur_pid].gs = vmregs->_gs;
00055     phy = ((vmregs->cs)<<4) + vmregs->eip;
00056     printf("\n phy_val(%x) %x",phy,*(DD *)phy);
00057 
00058     opcode = *(DB *)phy;
00059     opr1    = *(DB *)(phy+1);
00060     opr2    = *(DB *)(phy+2);
00061     opr3    = *(DB *)(phy+3);
00062     
00063                 printf("\nEAX %x EBX %x ECX %x  DI %x",regs->eax,regs->ebx,regs->ecx,regs->edi);
00064 
00065     switch(opcode)
00066     {
00067       case 0xCD:
00068               if(opr1 == 0xFF)
00069                {
00070                  remove(&ready_q,cur_pid);
00071                  do_exit(cur_pid);
00072                  post_vm86();
00073                }
00074               else
00075               { 
00076                 printf("\nInterrupt %x",opr1);
00077                 printf("\ncs %x ip %x",*(DW*)((opr1*4)+2),*(DW*)opr1*4);
00078                 _proc[cur_pid].cs = (*(DW*)((opr1*4)+2)) & 0xFFFF;
00079                 _proc[cur_pid].eip = (*(DW*)(opr1*4)) & 0xFFFF;
00080 
00081                 //Backup needed for IRET
00082                 push(vmregs->eflags);
00083                 push(vmregs->cs);
00084                 push(vmregs->eip+2); //For 0xCDxx
00085                 printStack();                            
00086               }
00087               break;
00088       case 0xFA: //CLI
00089             printf("\nCLI called");
00090             _proc[cur_pid].eflags &= ~(1<<9); //IFlag
00091             _proc[cur_pid].eip += 2;
00092             break;
00093 
00094       case 0xFB: //STI
00095             printf("\nSTI called");
00096             _proc[cur_pid].eflags |= (1<<9); //IFlag
00097             _proc[cur_pid].eip += 2;            
00098             break;
00099             
00100       case 0xCF: //IRET      
00101             printf("\nIRET called");
00102             stck_ret = pop();
00103             _proc[cur_pid].eip = (stck_ret > 0)?stck_ret:0;
00104             stck_ret = pop();
00105             _proc[cur_pid].cs = (stck_ret > 0)?stck_ret:0x9000;
00106             stck_ret = pop();
00107             _proc[cur_pid].eflags = (stck_ret > 0)?stck_ret:0;
00108 
00109             printf("\ncs %x eip %x eflags %x",_proc[cur_pid].cs,_proc[cur_pid].eip,_proc[cur_pid].eflags);
00110 
00111 
00112             if(vbe_mode.PhysBasePtr == 0)
00113               vbe_mode = *((VBE_ModeInfo *) (0x91000));
00114 
00115             printf("\nPhys addr: %x xRes %d yRes %d bpp %d",vbe_mode.PhysBasePtr,vbe_mode.XResolution,vbe_mode.YResolution,vbe_mode.BitsPerPixel);
00116             printf("\nModeAttributes : %x",vbe_mode.ModeAttributes);
00117             break;
00118             
00119       default:
00120             printf("\nDefault %x",opcode);
00121             break;
00122     }
00123 
00124   }
00125 
00126   

Generated on Thu Jul 27 23:52:28 2006 for Dynacube by  doxygen 1.4.7