Page 1 of 1

Reading of DVD-ROM/CD-ROM in AHCI MODE

Posted: Mon Jun 30, 2008 1:34 pm
by Wawan
Goal:
Reading of DVD-ROM/CD-ROM in AHCI MODE,
Programm written to be working in DOS.
TESTS Rightnow: Sending commands to open the CD-ROM (also EJECT command)

Code: Select all

typedef	struct _ComandHead
{
	word CFL:5;
	word A:1;
	word W:1;
	word P:1;
	word R:1;
	word B:1;
	word C:1;
	word RR:1;
	word PMP:4;
	word PRDT_Length:16;
	dword PRD_Byte_Count;
	dword CTBALo;
	dword CTBAHi;
	dword dw4;
	dword dw5;
	dword dw6;
	dword dw7;
}	ComandHead;


typedef struct _PRDT
{
	dword Base_addressLo;
	dword Base_addressHi;
	dword r;		
	word Byte_CountLo;
	word Byte_CountHi:6;
	word r1:9;		
	word Interrupt:1;	
} PRDT;


typedef struct _Command_Table
{
	byte CFIS[64];		
	byte ACMD[16];		
	byte Reserv[0x30];
	PRDT prdt[1];	
} Command_Table;


int cdrom( void )
{
	void *			CommandTableOrig;
	Command_Table *		CommandTable;
	void *			ComandListOrig;
	ComandHead *		ComandList;
	void *			FISOrig;
	void *			FIS;
	dword			t;

	GetPciList();
	DiskInfo();
	ToUnrealMode();
	FindCDroms();

	ComandListOrig		=	malloc( sizeof( ComandHead ) * 32 + 1023 );
	ComandList		=	(void*)( ( (dword)ComandListOrig + 1023 ) & ( ~(dword)1023 ) );

	CommandTableOrig	=	malloc( sizeof( Command_Table ) + 127 );
	CommandTable		=	(void*)( ( (dword)CommandTableOrig + 127 ) & ( ~(dword)127 ) );

	FISOrig			=	malloc( 256 + 4095 );
	FIS			=	(void*)( ( (dword)FISOrig + 4095 ) & ( ~(dword)4095 ) );

	memset( ComandList, 0, sizeof( ComandHead ) * 32 );
	memset( CommandTable, 0, sizeof( Command_Table ) );
	memset( FIS, 0, 256 );

	ComandList[ 0 ].PRDT_Length	=	1;
	ComandList[ 0 ].CTBALo		=	(dword)CommandTable;

	CommandTable->ACMD[ 0 ]		=	0x1B;
	CommandTable->ACMD[ 4 ]		=	0x02; // 2 - open, 3 - close

	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x18, 0x0104000D );
	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x2C, 1 );

	sleep( 1 );

	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x18, 0x0104000E );

	sleep( 1 );

	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x00, (dword)ComandList );
	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x04, 0 );
	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x08, (dword)FIS );
	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x0C, 0 );

	sleep( 1 );

	memWrite4( g_ABAR[ 0 ] + 0x100 + 0 * 0x80 + 0x38, 0x00000001 );

	sleep( 1 );

	return	g_CDCount;
}
Problem: No reaction from CD-ROM

Please help me to figur-out where is mistake or bug, AHCI & Atapi specifications i have, and research for serval weeks already, till now no any succeed.

I need a small example of working in AHCI mode.
Sources of Linux, OpenSolaris and BSD i got, but too much source there,
difficult to figur out what is going on there, so i would nee to try with smaller code to be able to figurout how does it work

Re: Reading of DVD-ROM/CD-ROM in AHCI MODE

Posted: Mon Jun 30, 2008 5:12 pm
by ChazZeromus
Did you take a look at the intel specification for AHCI?
Usually, specifications tell alot :)
http://download.intel.com/technology/se ... rev1_2.pdf

Re: Reading of DVD-ROM/CD-ROM in AHCI MODE

Posted: Mon Jun 30, 2008 11:01 pm
by Dex
I have not done any AHCI mode programming, but do you not have to take control off the BIOS (handoff), first ?.