leord_diskid.c 3.77 KB
/*
 *  F i l e N a m e  :  l e o r d _ d i s k i d . c
 *
 ****************************************************************************
 *               (C) Copyright ALPS Electric Co., Ltd. 1995-1996
 ****************************************************************************
 *  Version
 *
 *  ver     Date
 *  ----  --------
 *  1.00  '96-08-26  Initial revision .
 ****************************************************************************
*/
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leomacro.h"
#include "leoappli.h"

/**************************************/
/* PROTOTYPE DEFINITIONS              */
/**************************************/
void leoReadDiskId(void);

/**************************************/
/* EXTERNALY DEFINED FUNCTIONS        */
/**************************************/
extern void leoRead_common(unsigned int);

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

/**************************************/
/* EXTERNALY DEFINED RAM LOCATIONS    */
/**************************************/
extern OSMesg      LEOcur_command;
extern u16 LEOrw_flags;
extern u8 LEO_TempBuffer[((SEC_SIZE_ZONE0 + 16)/16)*16];

/*************************************/
/*  MACRO DEFINITIONS                */
/*************************************/
#define readid_cmd   ((LEOCmdReadDiskId *)LEOcur_command)

/**********************************************************
* Function : leoRead
* ---------------------------------------------------------
* Description : read
* IN  : non
* OUT : non
**********************************************************/
const static LEOCmdRead read_id_cmd =
      { { LEO_COMMAND_READ,           /* COMMAND        */
          0x00,                       /* RESERVE        */
          0x00,                       /* CONTROL        */
          0x00,                       /* RESERVE        */
          0x00,                       /* STATUS         */
          0x00,                       /* SENSE          */
          0x00,                       /* RESERVE        */
          0x00,                       /* RESERVE        */
          NULL                        /* POST QUEUE     */
        },
          DISK_ID_LBA1,               /* LBA            */
          0x01,                       /* BLOCKS         */
          (u64*)LEO_TempBuffer,       /* BUFFER POINTER */
          0x00                        /* READ BYTES     */
      };

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

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

    /* back up current command */
    temp_pointer = (u8*)LEOcur_command;
    /* read ID data  */
    LEOcur_command = (OSMesg)&dummy_cmd;
    cntr = 0;
    do
    {
        LEOrw_flags = SECTOR_READ;
        dummy_cmd = read_id_cmd;
        dummy_cmd.lba = leo_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
        leoRead_common(0);
        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 */
    LEOcur_command = (OSMesg)temp_pointer;
    /* copy 32bytes ID data to buffer */
    temp_pointer = (u8*)readid_cmd->buffer_pointer;
    for (cntr = 0; cntr < 32; cntr += sizeof(int))
    {
        *(int*)temp_pointer = *((int*)&LEO_TempBuffer[cntr]);
        temp_pointer += sizeof(int);
    }
    /* end of command */
    readid_cmd->header.sense  = dummy_cmd.header.sense;
    readid_cmd->header.status = dummy_cmd.header.status;
}