ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
shorts-segment-manager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SHORTS_SEGMENT_MANAGER_H
23 #define SHORTS_SEGMENT_MANAGER_H
24 
25 #include "common/scummsys.h"
26 
27 #if defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) && defined(MIPS_TARGET)
28 
29 #include "backends/plugins/elf/elf32.h"
30 
31 #include "common/singleton.h"
32 #include "common/list.h"
33 
34 #define ShortsMan ShortSegmentManager::instance()
35 
51 class ShortSegmentManager : public Common::Singleton<ShortSegmentManager> {
52 private:
53  char *_shortsStart;
54  char *_shortsEnd;
55 
56 public:
57  char *getShortsStart() {
58  return _shortsStart;
59  }
60 
61  // Returns whether or not an absolute address is in the GP-relative section.
62  bool inGeneralSegment(char *addr) {
63  return (addr >= _shortsStart && addr < _shortsEnd);
64  }
65 
66  class Segment {
67  private:
68  friend class ShortSegmentManager;
69  Segment(char *start, uint32 size, char *origAddr) :
70  _startAddress(start),
71  _size(size),
72  _origAddress(origAddr) {
73  }
74 
75  virtual ~Segment() {
76  }
77 
78  char *_startAddress; // Start of shorts segment in memory
79  uint32 _size; // Size of shorts segment
80  char *_origAddress; // Original address this segment was supposed to be at
81 
82  public:
83  char *getStart() {
84  return _startAddress;
85  }
86 
87  char *getEnd() {
88  return (_startAddress + _size);
89  }
90 
91  Elf32_Addr getOffset() {
92  return (Elf32_Addr)(_startAddress - _origAddress);
93  }
94 
95  bool inSegment(char *addr) {
96  return (addr >= _startAddress && addr <= _startAddress + _size);
97  }
98  };
99 
100  Segment *newSegment(uint32 size, char *origAddr);
101  void deleteSegment(Segment *);
102 
103 private:
104  ShortSegmentManager();
105  friend class Common::Singleton<ShortSegmentManager>;
107  char *_highestAddress;
108 };
109 
110 #endif // defined(DYNAMIC_MODULES) && defined(USE_ELF_LOADER) && defined(MIPS_TARGET)
111 
112 #endif /* SHORTS_SEGMENT_MANAGER_H */
Definition: list.h:44
Definition: singleton.h:42