VirtualBox

Changeset 41708 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Jun 14, 2012 1:35:50 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78516
Message:

DevRTC.cpp: r=bird:

  • Changed cmos to cmos1.
  • Don't start internal functions with capital letters.
  • The prefix for the RTC module is RTC.
  • CMOSRTCInfo is too many capitalized letters to parse in a function name, so use CamelCase on acronyms.
  • Don't use uint16_t as a loop index, unsigned or int is better.
  • u16ByteCount is a bad name as the variable is an index, not a count. Indexes get the prefix 'i' or 'idx'.
  • Declare variables when you need them, unless the source is C89 (this is C++). It helps sorting out variable life time and initialization.
  • Don't initialize all variables to for instance 0 when declaring them, just to immediately assign some value to them further down. Besides making it hard to figure the code it also hides problems where you forgot to set the varable in some branch further down - the compiler will tell you if you don't initialize the variable, it cannot if you do.
  • Don't split strings over multiple lines, unless the are insanely long (>= column 130) or are split on new lines "\n".
  • Ending each iteration with a new line saves you a pfnPrintf call.
  • Long #ifdef XXXX shall have a comment on the #endif line indicating what closed. See VBox or GNU coding style guidelines for the fine details.
  • Leave empty lines alone.
  • Don't add trailing white space.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevRTC.cpp

    r41667 r41708  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4444*   Header Files                                                               *
    4545*******************************************************************************/
    46 #define LOG_GROUP LOG_GROUP_DEV_RTC 
     46#define LOG_GROUP LOG_GROUP_DEV_RTC
    4747#include <VBox/vmm/pdmdev.h>
    4848#include <VBox/log.h>
     
    5757
    5858#include "VBoxDD.h"
     59
    5960struct RTCState;
    6061typedef struct RTCState RTCState;
     
    110111#define REG_B_UIE 0x10
    111112
    112 #define CMOS_BANK_LOWER_LIMIT 0x0E
    113 #define CMOS_BANK_UPPER_LIMIT 0x7F
    114 #define CMOS_BANK2_LOWER_LIMIT 0x80
    115 #define CMOS_BANK2_UPPER_LIMIT 0xFF
     113#define CMOS_BANK_LOWER_LIMIT   0x0E
     114#define CMOS_BANK_UPPER_LIMIT   0x7F
     115#define CMOS_BANK2_LOWER_LIMIT  0x80
     116#define CMOS_BANK2_UPPER_LIMIT  0xFF
    116117
    117118/** The saved state version. */
     
    285286 *      Dumps the cmos Bank Info.}
    286287 */
    287 static DECLCALLBACK(void) CMOSBankInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     288static DECLCALLBACK(void) rtcCmosBankInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    288289{
    289290    RTCState *pThis = PDMINS_2_DATA(pDevIns, RTCState *);
    290     uint16_t u16ByteCount = 0;
    291 
    292     pHlp->pfnPrintf(pHlp, "First CMOS bank, offsets 0x0E - 0x7F");
    293     pHlp->pfnPrintf(pHlp, "\nOffset %02x : --- use 'info rtc' to show CMOS clock ---", 0);
    294     for (u16ByteCount = CMOS_BANK_LOWER_LIMIT; u16ByteCount <= CMOS_BANK_UPPER_LIMIT; u16ByteCount++)
    295     {
    296         if ((u16ByteCount & 15) == 0) {
    297             pHlp->pfnPrintf(pHlp, "\nOffset %02x : ", u16ByteCount);
    298         } else if ((u16ByteCount & 15) == 8) {
     291
     292    pHlp->pfnPrintf(pHlp, "First CMOS bank, offsets 0x0E - 0x7F\n"
     293                          "Offset %02x : --- use 'info rtc' to show CMOS clock ---\n", 0);
     294    for (unsigned iCmos = CMOS_BANK_LOWER_LIMIT; iCmos <= CMOS_BANK_UPPER_LIMIT; iCmos++)
     295    {
     296        if ((iCmos & 15) == 0)
     297            pHlp->pfnPrintf(pHlp, "Offset %02x : ", iCmos);
     298        else if ((iCmos & 15) == 8)
    299299            pHlp->pfnPrintf(pHlp, "-");
    300         } else {
     300        else
    301301            pHlp->pfnPrintf(pHlp, " ");
    302         }
    303         pHlp->pfnPrintf(pHlp, "%02x", pThis->cmos_data[u16ByteCount]);
    304     }
    305     pHlp->pfnPrintf(pHlp, "\n");
     302        pHlp->pfnPrintf(pHlp, "%02x\n", pThis->cmos_data[iCmos]);
     303    }
    306304}
    307305
     
    310308 *      Dumps the cmos Bank2 Info.}
    311309 */
    312 static DECLCALLBACK(void) CMOSBank2Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     310static DECLCALLBACK(void) rtcCmosBank2Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    313311{
    314312    RTCState *pThis = PDMINS_2_DATA(pDevIns, RTCState *);
    315     uint16_t u16ByteCount = 0;
    316 
    317     pHlp->pfnPrintf(pHlp, "Second CMOS bank, offsets 0x80 - 0xFF");
    318     for (u16ByteCount = CMOS_BANK2_LOWER_LIMIT; u16ByteCount <= CMOS_BANK2_UPPER_LIMIT; u16ByteCount++)
    319     {
    320         if ((u16ByteCount & 15) == 0) {
    321             pHlp->pfnPrintf(pHlp, "\nOffset %02x : ", u16ByteCount);
    322         } else if ((u16ByteCount & 15) == 8) {
     313
     314    pHlp->pfnPrintf(pHlp, "Second CMOS bank, offsets 0x80 - 0xFF\n");
     315    for (uint16_t iCmos = CMOS_BANK2_LOWER_LIMIT; iCmos <= CMOS_BANK2_UPPER_LIMIT; iCmos++)
     316    {
     317        if ((iCmos & 15) == 0)
     318            pHlp->pfnPrintf(pHlp, "Offset %02x : ", iCmos);
     319        else if ((iCmos & 15) == 8)
    323320            pHlp->pfnPrintf(pHlp, "-");
    324         } else {
     321        else
    325322            pHlp->pfnPrintf(pHlp, " ");
    326         }
    327         pHlp->pfnPrintf(pHlp, "%02x", pThis->cmos_data[u16ByteCount]);
    328     }
    329     pHlp->pfnPrintf(pHlp, "\n");
     323        pHlp->pfnPrintf(pHlp, "%02x\n", pThis->cmos_data[iCmos]);
     324    }
    330325}
    331326
     
    334329 *      Dumps the cmos RTC Info.}
    335330 */
    336 static DECLCALLBACK(void) CMOSRTCInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     331static DECLCALLBACK(void) rtcCmosClockInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    337332{
    338333    RTCState *pThis = PDMINS_2_DATA(pDevIns, RTCState *);
    339     uint8_t u8Sec = 0;
    340     uint8_t u8Min = 0;
    341     uint8_t u8Hr = 0;
    342     uint8_t u8Day = 0;
    343     uint8_t u8Month = 0;
    344     uint8_t u8Year = 0;
    345    
    346     u8Sec = from_bcd(pThis, pThis->cmos_data[RTC_SECONDS]);
    347     u8Min = from_bcd(pThis, pThis->cmos_data[RTC_MINUTES]);
    348     u8Hr = from_bcd(pThis, pThis->cmos_data[RTC_HOURS] & 0x7f);
     334    uint8_t u8Sec   = from_bcd(pThis, pThis->cmos_data[RTC_SECONDS]);
     335    uint8_t u8Min   = from_bcd(pThis, pThis->cmos_data[RTC_MINUTES]);
     336    uint8_t u8Hr    = from_bcd(pThis, pThis->cmos_data[RTC_HOURS] & 0x7f);
    349337    if (   !(pThis->cmos_data[RTC_REG_B] & 0x02)
    350338        && (pThis->cmos_data[RTC_HOURS] & 0x80))
    351339        u8Hr += 12;
    352     u8Day = from_bcd(pThis, pThis->cmos_data[RTC_DAY_OF_MONTH]);
    353     u8Month = from_bcd(pThis, pThis->cmos_data[RTC_MONTH]) ;
    354     u8Year = from_bcd(pThis, pThis->cmos_data[RTC_YEAR]);
     340    uint8_t u8Day  = from_bcd(pThis, pThis->cmos_data[RTC_DAY_OF_MONTH]);
     341    uint8_t u8Month = from_bcd(pThis, pThis->cmos_data[RTC_MONTH]) ;
     342    uint8_t u8Year = from_bcd(pThis, pThis->cmos_data[RTC_YEAR]);
    355343    pHlp->pfnPrintf(pHlp, "Time: Hr:%u Min:%u Sec:%u, Day:%u Month:%u Year:%u\n", u8Hr, u8Min, u8Sec, u8Day, u8Month, u8Year);
    356 }
    357 
    358 #endif
     344    /** @todo r=bird: missing REG A-D. */
     345}
     346
     347#endif /* IN_RING3 */
    359348
    360349
     
    12481237    /*
    12491238     * Register debugger info callback.
    1250     */
    1251     PDMDevHlpDBGFInfoRegister(pDevIns, "cmos", "Display CMOS Bank 1 Info.. "
    1252                               "'cmos'. No argument.", CMOSBankInfo);
    1253     PDMDevHlpDBGFInfoRegister(pDevIns, "cmos2", "Display CMOS Bank 2 Info.. "
    1254                               "'cmos2'. No argument", CMOSBank2Info);
    1255     PDMDevHlpDBGFInfoRegister(pDevIns, "rtc", "Display CMOS RTC info "
    1256                               "'rtc'. No argument", CMOSRTCInfo);
     1239     */
     1240    PDMDevHlpDBGFInfoRegister(pDevIns, "cmos1", "Display CMOS Bank 1 Info (0x0e-0x7f). No arguments. See also rtc.", rtcCmosBankInfo);
     1241    PDMDevHlpDBGFInfoRegister(pDevIns, "cmos2", "Display CMOS Bank 2 Info (0x0e-0x7f). No arguments.", rtcCmosBank2Info);
     1242    PDMDevHlpDBGFInfoRegister(pDevIns, "rtc",   "Display CMOS RTC (0x00-0x0d). No arguments. See also cmos1 & cmos2", rtcCmosClockInfo);
    12571243    return VINF_SUCCESS;
    12581244}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette