summaryrefslogtreecommitdiffstats
path: root/src/devices/pic/base/pic_protection.h
blob: 75d0032396f755bcb81804aa8be822fd2011f239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org>             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#ifndef PIC_PROTECTION_H
#define PIC_PROTECTION_H

#include "pic.h"

namespace Pic
{
class Data;

//----------------------------------------------------------------------------
class Protection
{
public:
  enum { MAX_NB_BLOCKS = 8 };
  enum Family { NoProtection = 0, BasicProtection, BlockProtection, CodeGuard, Nb_Families };
  enum Type { ProgramProtected = 0, WriteProtected, ReadProtected,
              StandardSecurity, HighSecurity, Nb_Types };

public:
  Protection(const Pic::Data &data, const Config &config) : _data(data), _config(config) {}
  Family family() const;
  TQString securityValueName(Type type) const;
  bool hasBootBlock() const;
  TQString bootSizeMaskName() const;
  TQString bootMaskName(Type ptype) const;
  TQString bootLabel() const;
  uint nbBlocks() const;
  TQString blockSizeMaskName(uint i) const;
  TQString blockMaskName(Type ptype, uint i) const;
  TQString blockLabel(uint i) const;
  AddressRangeVector extractRanges(const TQString &name, MemoryRangeType type) const;
  bool checkRange(const TQString &mask, const TQString &name) const;
  TQString maskName(Type type, MemoryRangeType mtype) const;
  bool isAllProtectedValueName(const TQString &valueName) const;
  bool isNoneProtectedValueName(const TQString &valueName) const;

private:
  const Pic::Data &_data;
  const Config    &_config;

  enum SegmentType { BootSegment = 0, SecureSegment, GeneralSegment, Nb_SegmentTypes };
  static bool extractRanges(const TQString &name, TQValueVector<Address> &starts, Address &end, bool &ok);
  class ProtectedRange {
  public:
    TQValueVector<Address> starts, ends;
  };
  ProtectedRange extractRange(const TQString &mask, const TQString &name, bool &ok) const;
};

} //namespace

#endif