iplleord_diskid.c 3.99 KB
/*
 *  F i l e N a m e  :  i p l l e o r d _ d i s k i d . c
 *
 ****************************************************************************
 *               (C) Copyright ALPS Electric Co., Ltd. 1995-1996
 ****************************************************************************
 *  Version
 *
 *  ver     Date
 *  ----  --------
 *  1.01  '96-11-22  Add _ERRCHK definition to be enable to return code in 
 *                   cdb for sense-code.
 *  1.00  '96-08-26  Initial revision .
 ****************************************************************************
*/
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "iplleomacro.h"
#include "leoappli.h"

/**************************************/
/* PROTOTYPE DEFINITIONS              */
/**************************************/
u8 leoiplReadDiskId(void);

/**************************************/
/* EXTERNALY DEFINED FUNCTIONS        */
/**************************************/
extern void leoiplRead_zone0(void);

/**************************************/
/* RAM LOCATIONS                      */
/**************************************/

/**************************************/
/* EXTERNALY DEFINED RAM LOCATIONS    */
/**************************************/
extern OSMesg      LeoIPLcur_command;
extern u16 LeoIPLrw_flags;
extern u8 LeoIPL_c2temp[((SEC_SIZE_ZONE0 + 16)/16)*16];
extern union leo_sys_form LeoIPL_sys_data;

/*************************************/
/*  MACRO DEFINITIONS                */
/*************************************/
#define iplreadid_cmd   ((LEOCmdReadDiskId *)LeoIPLcur_command)

/**********************************************************
* Function : leoiplReadDiskID
* ---------------------------------------------------------
* Description : read disk ID parameter .
* IN  : non
* OUT : non
**********************************************************/
const static LEOCmdRead read_id_cmd =
      { { LEO_COMMAND_READ,           /* COMMAND        */
          0x00,                       /* RESERVE1       */
          0x00,                       /* CONTROL        */
          0x00,                       /* RESERVE3       */
          0x00,                       /* STATUS         */
          0x00,                       /* SENSE          */
          0x00,                       /* RESERVE6       */
          0x00,                       /* RESERVE7       */
          NULL                        /* POST QUEUE     */
        },
          DISK_ID_LBA1,               /* LBA            */
          0x01,                       /* BLOCKS         */
          (u64*)LeoIPL_c2temp,        /* BUFFER POINTER */
          0x00                        /* READ BYTES     */
        };

const static u8 iplleo_disk_id_lba[2] = {DISK_ID_LBA1,DISK_ID_LBA2};

u8 leoiplReadDiskId(void)
{
    LEOCmdRead dummy_cmd;
    u8  *temp_pointer;
    u32   cntr;

    /* back up current command */
    temp_pointer = (u8*)LeoIPLcur_command;
    /* read ID data  */
    LeoIPLcur_command = (OSMesg)&dummy_cmd;
    cntr = 0;

    LeoIPL_sys_data.param.defect_num[0] = 0;
    do
    {
        LeoIPLrw_flags = SECTOR_READ;
        dummy_cmd = read_id_cmd;
        dummy_cmd.lba = iplleo_disk_id_lba[cntr];
#ifdef _ERRCHK
        dummy_cmd.header.reserve1 = ((LEOCmdReadDiskId *)temp_pointer)->header.reserve1;
        dummy_cmd.header.reserve3 = ((LEOCmdReadDiskId *)temp_pointer)->header.reserve3;
#endif
        leoiplRead_zone0();
        if (dummy_cmd.header.sense != LEO_SENSE_UNRECOVERED_READ_ERROR)
            break;
    } while (++cntr < 2);
#ifdef _ERRCHK
    ((LEOCmdReadDiskId *)temp_pointer)->header.reserve7 = dummy_cmd.header.reserve7;
#endif

    /* restore current command */
    LeoIPLcur_command = (OSMesg)temp_pointer;
    /* copy 32bytes ID data to buffer */
    temp_pointer = (u8*)iplreadid_cmd->buffer_pointer;
    for (cntr = 0; cntr < 32; cntr += sizeof(int))
    {
        *(int*)temp_pointer = *((int*)&LeoIPL_c2temp[cntr]);
        temp_pointer += sizeof(int);
    }
    /* end of command */
    return (iplreadid_cmd->header.sense  = dummy_cmd.header.sense );

}