Example #1
0
/* This function will return the current system date & time in the passed pointer parameters.

   Note : The year is only 2 digits and the RTC is Real Time Clock  and donot confuse it with the Y2K problem.

   The Day of week problem is still unsolved
*/
void GetLocalTime(SYSTEMTIME * lpSystemTime)
{
    /* Checking whether we can read the time now or not according to some documentation the MSB in Status A will remain 1 (invalid time) only a millisecond*/
    int TimeOut;

    OutPortByte( RTC_INDEX_REG, RTC_STATUS_A );    //check status - read access
    TimeOut = 1000;
    while ( InPortByte( RTC_VALUE_REG ) & 0x80 )
        if ( TimeOut < 0 )
            return;
        else
            TimeOut--;

    OutPortByte( RTC_INDEX_REG, RTC_DAY );         //get day value
    lpSystemTime->wDay = InPortByte( RTC_VALUE_REG );
    OutPortByte( RTC_INDEX_REG, RTC_MONTH );       //get month value
    lpSystemTime->wMonth = InPortByte( RTC_VALUE_REG );
    OutPortByte( RTC_INDEX_REG, RTC_YEAR );        //get year
    lpSystemTime->wYear = InPortByte( RTC_VALUE_REG );

    OutPortByte( RTC_INDEX_REG, RTC_DAY_OF_WEEK ); //get day of week - **** problem
    lpSystemTime->wDayOfWeek = InPortByte( RTC_VALUE_REG );

    OutPortByte( RTC_INDEX_REG, RTC_SECOND );
    lpSystemTime->wSecond = InPortByte( RTC_VALUE_REG );
    OutPortByte( RTC_INDEX_REG, RTC_MINUTE );
    lpSystemTime->wMinute = InPortByte( RTC_VALUE_REG );
    OutPortByte( RTC_INDEX_REG, RTC_HOUR );
    lpSystemTime->wHour = InPortByte( RTC_VALUE_REG );

    OutPortByte( RTC_INDEX_REG, RTC_STATUS_B );
    OutPortByte( RTC_VALUE_REG, 2 );

    return;
}
Example #2
0
/* Sets the Cursor Type
	0 to 15 is possible value to pass
	Returns - none.
	Example : Normal Cursor - (13,14)
		  Solid Cursor - (0,15)
		  No Cursor - (25,25) - beyond the cursor limit so it is invisible
*/
void Console::SetCursorType(unsigned char  Bottom, unsigned char  Top)
{
	OutPortByte(m_VideoCardType,VGA_CRT_CURSOR_START);
	OutPortByte(m_VideoCardType + 1,Top);
	OutPortByte(m_VideoCardType,VGA_CRT_CURSOR_END);
	OutPortByte(m_VideoCardType + 1,Bottom);
}
/* --------------------------------------------------------------------- */
void XGI_Newdebugcode( UCHAR code )
{
    OutPortByte ( 0x80 , code ) ;
#if 0
    OutPortByte ( 0x300 , code ) ;
    NewDelaySeconds( 0x3 ) ;
#endif
}
Example #4
0
/*
This function performs a Software Reset on the devices attached. You may
specifing only one or one portion of a hard disk but all harddisks and
entire space is subjected to sofware reset and the status is posted in the
Error Register.

1) Set the SRST bit to 1, wait for 400ns
2) Clear the SRST bit to 0
3) Wait for BSY bit cleared in the Status Register upto 31 seconds
4) Read the Error Register
Input  :
DeviceController Number
Output :
( Output == 0x1 )
Device 0 passed, Device 1 passed or not present
( Output == 0x0 || ( Output >=0x2 && Output <=0x7F ) )
Device 0 failed, Device 1 passed or not present
( Output == 0x81 )
Device 0 passed, Device 1 failed
( Output == 0x80 || ( Output >=0x82 && Output <=0xFF ) )
Device 0 failed, Device 1 failed

*/
BYTE HardDiskHandler::DoSoftwareReset(UINT16 DeviceController)
{
	BYTE DeviceControl = 4; //Setting SRST bit in the control register ( 2nd bit  (bit count 3) )
	OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CON_DEVICE_CONTROL, DeviceControl);
	DeviceControl = 0;      //Clearing the SRST bit in the control register ( 2nd bit)
	OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CON_DEVICE_CONTROL, DeviceControl);

	return InPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_ERROR);
}
Example #5
0
bool HalpInitSysTimer(BYTE timeoutPerSecond)
{
	WORD timeout = (WORD)(1193180 / timeoutPerSecond);

	OutPortByte(0x43, 0x34);
	OutPortByte(0x40, (UCHAR)(timeout & 0xff));
	OutPortByte(0x40, (UCHAR)(timeout >> 8));

	return TRUE;
}
Example #6
0
/* --------------------------------------------------------------------- */
void XGINew_SetReg1( USHORT port , USHORT index , USHORT data )
{
#ifdef LINUX_XF86
    OutPortByte( ( PUCHAR )(ULONG)port , index ) ;
    OutPortByte( ( PUCHAR )(ULONG)port + 1 , data ) ;
#else
    OutPortByte( ( PUCHAR )port , index ) ;
    OutPortByte( ( PUCHAR )port + 1 , data ) ;
#endif
}
Example #7
0
void Console::MoveCursor(unsigned int  X,unsigned int  Y)
{
	if(X > m_ScreenWidth)
		X = 0;
	unsigned short Offset = (unsigned short)((Y*m_ScreenWidth) + (X - 1));
	OutPortByte(m_VideoCardType,VGA_CRT_CURSOR_H_LOCATION);
	OutPortByte(m_VideoCardType+1,Offset>>8);
	OutPortByte(m_VideoCardType,VGA_CRT_CURSOR_L_LOCATION);
	OutPortByte(m_VideoCardType+1,(Offset<<8)>>8);
}
Example #8
0
/* --------------------------------------------------------------------- */
void XGINew_ClearDAC( PUCHAR port )
{
    int i ;

    OutPortByte( port , 0 ) ;
    port++ ;
    for( i = 0 ; i < 256 * 3 ; i++ )
    {
        OutPortByte( port , 0 ) ;
    }
}
Example #9
0
/* --------------------------------------------------------------------- */
UCHAR XGINew_GetReg1( USHORT port , USHORT index )
{
    UCHAR data ;

#ifdef LINUX_XF86
    OutPortByte( ( PUCHAR )(ULONG)port , index ) ;
    data = InPortByte( ( PUCHAR )(ULONG)port + 1 ) ;
#else
    OutPortByte( ( PUCHAR )port , index ) ;
    data = InPortByte( ( PUCHAR )port + 1 ) ;
#endif

    return( data ) ;
}
Example #10
0
bool HalpInitPIC(void)
{
	/* master 8259 */
	OutPortByte(0x20, 0x11); /* edge trig, cascade mode, ICW4 */
	OutPortByte(0x21, 0x20); /* start at INT vector 20h */
	OutPortByte(0x21, 0x04); /* #IR2 pin has a slave */
	OutPortByte(0x21, 0x01); /* not sp, nonbuffered mode, normal EOI, for x86 */
	OutPortByte(0x21, 0x00);

	/* slave 8259 */
	OutPortByte(0xa0, 0x11); /* edge trig, cascade mode, ICW4 */
	OutPortByte(0xa1, 0x28); /* start at INT vector 28h */
	OutPortByte(0xa1, 0x02); /* slave 8259 has been linked to master's #IR2 pin */
	OutPortByte(0xa1, 0x01); /* not sp, nonbuffered mode, normal EOI, for x86 */
	OutPortByte(0xa1, 0x00);

	return TRUE;
}
Example #11
0
/* --------------------------------------------------------------------- */
UCHAR XGINew_GetReg1( USHORT port , USHORT index )
{
    UCHAR data ;

    OutPortByte( ( ULONG )port , index ) ;
    data = InPortByte( ( ULONG )port + 1 ) ;

    return( data ) ;
}
Example #12
0
/* --------------------------------------------------------------------- */
void Newdebugcode( UCHAR code )
{
#ifndef LINUX_XF86
    ULONG ultemp ;
#endif

    OutPortByte ( 0x80 , code ) ;
    /* OutPortByte ( 0x300 , code ) ; */
    /* NewDelaySeconds( 0x3 ) ; */
}
Example #13
0
bool HalpEnableA20(void)
{
	int *test_1 = (int *)0x00000000, test_1_buf;
	int *test_2 = (int *)0x00100000, test_2_buf;
	UCHAR status, flag;

	/* read current falg */
	do { status = InPortByte(0x64); } while (status & 0x02);
	OutPortByte(0x64, 0xd0);
	do { status = InPortByte(0x64); } while (!(status & 0x01));
	flag = InPortByte(0x60);
	flag |= 0x02; /* enable a20 */

	/* write modified flag */
	do { status = InPortByte(0x64); } while (status & 0x02);
	OutPortByte(0x64, 0xd1);
	do { status = InPortByte(0x64); } while (status & 0x02);
	OutPortByte(0x60, flag); /* write new flag */

	/* wait until the new flag has adapted */
	do { status = InPortByte(0x64); } while (status & 0x02);

	/* test a20 line */
	test_1_buf = *test_1;
	test_2_buf = *test_2;
	*test_1 = 0xff00ccaa;
	*test_2 = 0x22cc11dd;
	if (*test_1 == *test_2) {
		*test_1 = test_1_buf;
		return false;
	}
	*test_1 = test_1_buf;
	*test_2 = test_2_buf;

	return true;
}
Example #14
0
/* --------------------------------------------------------------------- */
void XGINew_SetReg3( USHORT port , USHORT data )
{
    OutPortByte( port , data ) ;
}
Example #15
0
/* ----------------------PIO functions -------------------------------------
ReadSectors()
1) Get the HDDInfo object
2) Check whether Device is busy
3) Set the DEVICE BIT
4) Check whether the device ready accept Data commands
5) Set Head, Track etc informations
6) Issue READ command
7) Check whether the device ready to transfer data
8) Read the Data Register to get data
*/
BYTE HardDiskHandler::ReadSectors(BYTE * DPF, UINT16 StartCylinder, BYTE StartHead, BYTE StartSector, BYTE NoOfSectors, BYTE * Buffer, BOOLEAN WithRetry)
{
	__HDDInfo * HDD;
	BYTE DevHead, StartCylHigh = 0, StartCylLow = 0;

	HDD = HDDs.Item((char *)DPF);
	if (HDD == NULL)
	{
		LastError = HDD_NOT_FOUND;
		return HDD_NOT_FOUND;
	}

	if (HDD->DeviceNumber == 0)
		DevHead = StartHead | 0xA0;
	else
		DevHead = StartHead | 0xB0;

	if (IsDeviceControllerBusy(HDD->IORegisterIdx, 1 * 60))
	{
		LastError = HDD_CONTROLLER_BUSY;
		return HDD_CONTROLLER_BUSY;
	}

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_DEVICE_HEAD, DevHead);

	if (!IsDeviceDataReady(HDD->IORegisterIdx, 1 * 60, FALSE))
	{
		LastError = HDD_DATA_COMMAND_NOT_READY;
		return HDD_DATA_COMMAND_NOT_READY;
	}

	StartCylHigh = StartCylinder >> 8;
	StartCylLow = (StartCylinder << 8) >> 8;

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_CYLINDER_HIGH, StartCylHigh);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_CYLINDER_LOW, StartCylLow);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_SECTOR, StartSector);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_SECTOR_COUNT, NoOfSectors);

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_COMMAND, WithRetry ? IDE_COM_READ_SECTORS_W_RETRY : IDE_COM_READ_SECTORS);
	for (BYTE j = 0; j < NoOfSectors; j++)
	{
		if (!IsDeviceDataReady(HDD->IORegisterIdx, 1 * 60, TRUE))
		{
			LastError = HDD_DATA_NOT_READY;
			return HDD_DATA_NOT_READY;
		}

		for (UINT16 i = 0; i < (HDD->BytesPerSector) / 2; i++)
		{
			UINT16 w = 0;
			BYTE l, h;
			w = InPortWord(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_DATA);
			l = (w << 8) >> 8;
			h = w >> 8;
			Buffer[(j * (HDD->BytesPerSector)) + (i * 2)] = l;
			Buffer[(j * (HDD->BytesPerSector)) + (i * 2) + 1] = h;
		}
	}
	return HDD_NO_ERROR;
}
Example #16
0
void HardDiskHandler::Initialize()
{
	char strKey[3];
	strKey[0] = 'H'; //HDD type ID
	strKey[1] = '0';   //First HDD
	strKey[2] = 0;   //Null Character
	//SetIDT(32+14,_HDDInterruptHandler);
	//SetIDT(32+15,_HDDInterruptHandler);

	HDDs.Initialize();
	for (BYTE DeviceController = 0; DeviceController < IDE_MAX_CONTROLLER; DeviceController++)
	{
		DoSoftwareReset(DeviceController);
		if (IsDeviceControllerBusy(DeviceController)) //if device controller is busy then skipping
		{			
			DebugPrintf("\nController Busy");
			continue;
		}
		OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_COMMAND, IDE_COM_EXECUTE_DEVICE_DIAGNOSTIC);
		if (IsDeviceControllerBusy(DeviceController, 6))
		{			
			DebugPrintf("\nController busy after EXE");
			continue;
		}

		
		BYTE Result = InPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_ERROR);
		for (BYTE Device = 0; Device < 2; Device++)         // loop for master and slave disks
		{
			UINT16 DeviceID_Data[512], j;
			if (Device == 0 && !(Result & 1))
				continue;
			if (Device == 1 && (Result & 0x80))
				continue;
			if (Device == 1)
				OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_DEVICE_HEAD, 0x10); //Setting 4th bit(count 5) to set device as 1
			else
				OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_DEVICE_HEAD, 0x0);
			
			sleep(50);
			OutPortByte(IDE_Con_IOBases[DeviceController][0] + IDE_CB_COMMAND, IDE_COM_IDENTIFY_DEVICE);
			if (!IsDeviceDataReady(DeviceController, 600, TRUE))
			{
				DebugPrintf("\nData not ready %d", DeviceController);
				continue;
			}							
			/*Reading 512 bytes of information from the Device*/
			for (j = 0; j < 256; j++)
				DeviceID_Data[j] = InPortWord(IDE_Con_IOBases[DeviceController][0] + IDE_CB_DATA);
			/* Creating new HDD node for the Collection HDDs */
			
			//struct __HDDInfo * newHDD;
			__HDDInfo * newHDD=(__HDDInfo *)kmalloc(sizeof(__HDDInfo));
			if (newHDD == NULL)
			{
				DebugPrintf("\nHDD Initialize :: Allocation failed");
				return;
			}
			newHDD->IORegisterIdx = DeviceController;
			memcpy(newHDD->DeviceID, DeviceID_Data, 512);
			newHDD->DeviceNumber = Device;
			newHDD->LastError = 0;

			newHDD->BytesPerSector = 512; //-------------Modify Code

			newHDD->CHSCylinderCount = DeviceID_Data[1];
			newHDD->CHSHeadCount = DeviceID_Data[3];
			newHDD->CHSSectorCount = DeviceID_Data[6];
			if (DeviceID_Data[10] == 0)
				strcpy(newHDD->SerialNumber, "N/A");
			else
			for (j = 0; j < 20; j += 2)
			{
				newHDD->SerialNumber[j] = DeviceID_Data[10 + (j / 2)] >> 8;
				newHDD->SerialNumber[j + 1] = (DeviceID_Data[10 + (j / 2)] << 8) >> 8;
			}
			if (DeviceID_Data[23] == 0)
				strcpy(newHDD->FirmwareRevision, "N/A");
			else
			for (j = 0; j < 8; j += 2)
			{
				newHDD->FirmwareRevision[j] = DeviceID_Data[23 + (j / 2)] >> 8;
				newHDD->FirmwareRevision[j + 1] = (DeviceID_Data[23 + (j / 2)] << 8) >> 8;
			}

			if (DeviceID_Data[27] == 0)
				strcpy(newHDD->ModelNumber, "N/A");
			else
			for (j = 0; j < 20; j += 2)
			{
				newHDD->ModelNumber[j] = DeviceID_Data[27 + (j / 2)] >> 8;
				newHDD->ModelNumber[j + 1] = (DeviceID_Data[27 + (j / 2)] << 8) >> 8;
			}
			newHDD->LBASupported = DeviceID_Data[49] & 0x200;
			newHDD->DMASupported = DeviceID_Data[49] & 0x100;

			UINT32 LBASectors = DeviceID_Data[61];
			LBASectors = LBASectors << 16;
			LBASectors |= DeviceID_Data[60];

			newHDD->LBACount = LBASectors;
			HDDs.Add(newHDD, strKey);
			strKey[1]++;
		}
	}
}
Example #17
0
/* --------------------------------------------------------------------- */
void XGINew_SetReg1( USHORT port , USHORT index , USHORT data )
{
    OutPortByte( ( ULONG )port , index ) ;
    OutPortByte( ( ULONG )port + 1 , data ) ;
}
Example #18
0
BYTE HardDiskHandler::ReadSectors(BYTE * DPF, UINT32 StartLBASector, BYTE NoOfSectors, BYTE * Buffer, BOOLEAN WithRetry)
{
	__HDDInfo * HDD;
	BYTE LBA0_7, LBA8_15, LBA16_23, LBA24_27;

	HDD = HDDs.Item((char *)DPF);
	if (HDD == NULL)
	{
		LastError = HDD_NOT_FOUND;
		return HDD_NOT_FOUND;
	}
	LBA0_7 = (StartLBASector << 24) >> 24;
	LBA8_15 = (StartLBASector << 16) >> 24;
	LBA16_23 = (StartLBASector << 8) >> 24;
	LBA24_27 = (StartLBASector << 4) >> 28;

	if (HDD->DeviceNumber == 0)
		LBA24_27 = LBA24_27 | 0xE0;
	else
		LBA24_27 = LBA24_27 | 0xF0;

	if (IsDeviceControllerBusy(HDD->IORegisterIdx, 1 * 60))
	{
		LastError = HDD_CONTROLLER_BUSY;
		return HDD_CONTROLLER_BUSY;
	}

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_DEVICE_HEAD, LBA24_27);

	if (!IsDeviceDataReady(HDD->IORegisterIdx, 1 * 60, FALSE))
	{
		LastError = HDD_DATA_COMMAND_NOT_READY;
		return HDD_DATA_COMMAND_NOT_READY;
	}

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_LBA_16_23, LBA16_23);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_LBA_8_15, LBA8_15);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_LBA_0_7, LBA0_7);
	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_SECTOR_COUNT, NoOfSectors);

	OutPortByte(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_COMMAND, WithRetry ? IDE_COM_READ_SECTORS_W_RETRY : IDE_COM_READ_SECTORS);
	for (BYTE j = 0; j < NoOfSectors; j++)
	{
		if (!IsDeviceDataReady(HDD->IORegisterIdx, 1 * 60, TRUE))
		{
			LastError = HDD_DATA_NOT_READY;
			return HDD_DATA_NOT_READY;
		}

		for (UINT16 i = 0; i < (HDD->BytesPerSector) / 2; i++)
		{
			UINT16 w = 0;
			BYTE l, h;
			w = InPortWord(IDE_Con_IOBases[HDD->IORegisterIdx][0] + IDE_CB_DATA);
			l = (w << 8) >> 8;
			h = w >> 8;
			Buffer[(j * (HDD->BytesPerSector)) + (i * 2)] = l;
			Buffer[(j * (HDD->BytesPerSector)) + (i * 2) + 1] = h;
		}
	}
	return HDD_NO_ERROR;
}
Example #19
0
/* Returns 1 on success and 0 on failue */
BYTE SetLocalTime(SYSTEMTIME * lpSystemTime)
{
    /* Checking whether we can read the time now or not according to some documentation the MSB in Status A will   remain 1 (invalid time) only a millisecond*/
    int TimeOut;

    OutPortByte( RTC_INDEX_REG, RTC_STATUS_A );    //checking status -read access
    TimeOut = 1000;
    while ( InPortByte(RTC_VALUE_REG) & 0x80 )
        if ( TimeOut< 0 )
            return 0;
        else
            TimeOut--;

    OutPortByte( RTC_INDEX_REG, RTC_DAY );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wDay );
    OutPortByte( RTC_INDEX_REG, RTC_MONTH );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wMonth );
    OutPortByte( RTC_INDEX_REG, RTC_YEAR );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wYear );

    OutPortByte( RTC_INDEX_REG, RTC_SECOND );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wSecond );
    OutPortByte( RTC_INDEX_REG, RTC_MINUTE );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wMinute );
    OutPortByte( RTC_INDEX_REG, RTC_HOUR );
    OutPortByte( RTC_VALUE_REG, lpSystemTime->wHour );

    return 1;
}
Example #20
0
bool  Scheduler::DoSchedule(int tick, uint32_t registers)
{

	//DebugPrintf("\nScheduler");

	int entryPoint = 0;
	unsigned int procStack = 0;
	
	/* switch to process address space */

	if (systemOn == true)
	{
		Process* curProcess = ProcessManager::GetInstance()->g_pCurProcess;

		if (curProcess)
		{
			Thread* pCurThread = (Thread*)List_GetData(curProcess->pThreadQueue, "", 0);			
			pCurThread->curESP = (*(uint32_t*)(registers - 8));
			pCurThread->curFlags = (*(uint32_t*)(registers - 12));
			pCurThread->curCS = (*(uint32_t*)(registers - 16));
			pCurThread->curEip = (*(uint32_t*)(registers - 20));

			/*pCurThread->curgs = (*(uint16_t*)(registers - 24));
			pCurThread->curfs = (*(uint16_t*)(registers - 28));
			pCurThread->curEs = (*(uint16_t*)(registers - 32));
			pCurThread->curds = (*(uint16_t*)(registers - 36));*/

			pCurThread->frame.eax = (*(uint32_t*)(registers - 24));
			pCurThread->frame.ecx = (*(uint32_t*)(registers - 28));
			pCurThread->frame.edx = (*(uint32_t*)(registers - 32));
			pCurThread->frame.ebx = (*(uint32_t*)(registers - 36));
			pCurThread->frame.esp = (*(uint32_t*)(registers - 40));
			pCurThread->frame.ebp = (*(uint32_t*)(registers - 44));
			pCurThread->frame.esi = (*(uint32_t*)(registers - 48));
			pCurThread->frame.edi = (*(uint32_t*)(registers - 52));			

			LISTNODE *pProcessList = ProcessManager::GetInstance()->pProcessQueue;
			int processCount = List_Count(pProcessList);

			for (int index = 0; index < processCount; index++)
			{
				Process* pProcess = (Process*)List_GetData(pProcessList, "", index);

				if (curProcess == pProcess)
					continue;

						



				pProcess->dwTickCount++;
				if (pProcess->dwTickCount > 10)
				{
					
					pProcess->dwTickCount = 0;
					if (pProcess->dwProcessType == PROCESS_USER)
					{
						

						console.Print("Scheduler1 : %d\n", processCount);
						ProcessManager::GetInstance()->g_pCurProcess = pProcess;
						Thread* pThread = (Thread*)List_GetData(pProcess->pThreadQueue, "", 0);						


						entryPoint = pThread->curEip;
						procStack = pThread->curESP;
						uint32_t eflags = pThread->curFlags;
						
						console.Print("eip : %x\n", pThread->curEip);
						console.Print("CS : %x\n", pThread->curCS);
						console.Print("flags : %x\n", pThread->curFlags);
						console.Print("esp : %x\n", pThread->curESP);


						//entryPoint = pThread->frame.eip;						
						//procStack = pThread->frame.esp;						

						uint32_t regEax = pThread->frame.eax;
						uint32_t regEcx = pThread->frame.ecx;
						uint32_t regEdx = pThread->frame.edx;
						uint32_t regEbx = pThread->frame.ebx;
						uint32_t regEsp = pThread->frame.esp;
						uint32_t regEbp = pThread->frame.ebp;
						uint32_t regEsi = pThread->frame.esi;
						uint32_t regEdi = pThread->frame.edi;

						uint16_t regGs = pThread->curgs;
						uint16_t regFs = pThread->curfs;
						uint16_t regEs = pThread->curEs;
						uint16_t regDs = pThread->curds;

						
						pmmngr_load_PDBR((physical_addr)pProcess->pPageDirectory);						
						OutPortByte(0x20, 0x20);
						__asm {
							mov     ax, 0x23; user mode data selector is 0x20 (GDT entry 3).Also sets RPL to 3
								mov     ds, ax
								mov     es, ax
								mov     fs, ax
								mov     gs, ax

							
							; create stack frame
								;
							push   0x23; SS, notice it uses same selector as above
								push[procStack]; stack
								push[eflags]; EFLAGS
								push    0x1b; CS, user mode code selector is 0x18.With RPL 3 this is 0x1b
								push[entryPoint]; EIP

								mov eax, regEax
								mov ecx, regEcx
								mov edx, regEdx
								mov ebx, regEbx
								mov esp, regEsp
								mov ebp, regEbp
								mov esi, regEsi
								mov edi, regEdi

								iretd
						}

					}
					else
					{
						/*if (aa == 0)
						{
							aa = 1;
							DebugPrintf("\nasdasas : %x", registers);
							for (int i = 0; i < 20; i++)
								DebugPrintf("\nasdasas : %x", (*(uint32_t*)(registers - i * 4)));
							
							while (1);
						}*/

						console.Print("Scheduler2\n");
						ProcessManager::GetInstance()->g_pCurProcess = pProcess;
						Thread* pThread = (Thread*)List_GetData(pProcess->pThreadQueue, "", 0);
						entryPoint = pThread->frame.eip;
						procStack = pThread->frame.esp;
						//procStack = 0;

						pmmngr_load_PDBR((physical_addr)pProcess->pPageDirectory);
						OutPortByte(0x20, 0x20);
						__asm {
							mov     ax, 0x10;
								mov     ds, ax
								mov     es, ax
								mov     fs, ax
								mov     gs, ax
								;
							; create stack frame
								;
							push   0x10; SS, notice it uses same selector as above
								push[procStack]; stack
								push    0x200; EFLAGS
								push    0x08;
								push[entryPoint]; EIP
								iretd
						}
					}
				}