aboutsummaryrefslogtreecommitdiffstats
path: root/ice40/chip.h
diff options
context:
space:
mode:
Diffstat (limited to 'ice40/chip.h')
-rw-r--r--ice40/chip.h84
1 files changed, 47 insertions, 37 deletions
diff --git a/ice40/chip.h b/ice40/chip.h
index 5eeca5e9..9f15bf60 100644
--- a/ice40/chip.h
+++ b/ice40/chip.h
@@ -72,31 +72,38 @@ PortPin portPinFromId(IdString id);
// -----------------------------------------------------------------------
-#if 0
+/**** Everything in this section must be kept in sync with chipdb.py ****/
+
template <typename T>
struct RelPtr {
- int offset;
+ int32_t offset;
- // RelPtr(T *ptr) : offset(reinterpret_cast<const char*>(ptr) -
- // reinterpret_cast<const char*>(this)) {}
+ // void set(const T *ptr) {
+ // offset = reinterpret_cast<const char*>(ptr) - reinterpret_cast<const char*>(this);
+ // }
+
+ const T*get() const {
+ return reinterpret_cast<const T*>(reinterpret_cast<const char*>(this) + offset);
+ }
- T&operator*() {
- return *reinterpret_cast<T*>(reinterpret_cast<char*>(this) + offset);
+ const T&operator[](size_t index) const {
+ return get()[index];
}
- T*operator->() {
- return reinterpret_cast<T*>(reinterpret_cast<char*>(this) + offset);
+ const T&operator*() const {
+ return *(get());
+ }
+
+ const T*operator->() const {
+ return get();
}
};
-#else
-template <typename T> using RelPtr = T *;
-#endif
struct BelWirePOD
{
int32_t wire_index;
PortPin port;
-};
+} __attribute__((packed));
struct BelInfoPOD
{
@@ -105,13 +112,14 @@ struct BelInfoPOD
int32_t num_bel_wires;
RelPtr<BelWirePOD> bel_wires;
int8_t x, y, z;
-};
+ int8_t padding_0;
+} __attribute__((packed));
struct BelPortPOD
{
int32_t bel_index;
PortPin port;
-};
+} __attribute__((packed));
struct PipInfoPOD
{
@@ -120,7 +128,7 @@ struct PipInfoPOD
int8_t x, y;
int16_t switch_mask;
int32_t switch_index;
-};
+} __attribute__((packed));
struct WireInfoPOD
{
@@ -132,21 +140,21 @@ struct WireInfoPOD
BelPortPOD bel_uphill;
RelPtr<BelPortPOD> bels_downhill;
- int8_t x, y;
-};
+ int16_t x, y;
+} __attribute__((packed));
struct PackagePinPOD
{
- const char *name;
+ RelPtr<char> name;
int32_t bel_index;
-};
+} __attribute__((packed));
struct PackageInfoPOD
{
const char *name;
int num_pins;
PackagePinPOD *pins;
-};
+} __attribute__((packed));
enum TileType
{
@@ -160,21 +168,21 @@ enum TileType
struct ConfigBitPOD
{
int8_t row, col;
-};
+} __attribute__((packed));
struct ConfigEntryPOD
{
- const char *name;
- int num_bits;
- ConfigBitPOD *bits;
-};
+ RelPtr<char> name;
+ int32_t num_bits;
+ RelPtr<ConfigBitPOD> bits;
+} __attribute__((packed));
struct TileInfoPOD
{
int8_t cols, rows;
int num_config_entries;
ConfigEntryPOD *entries;
-};
+} __attribute__((packed));
static const int max_switch_bits = 5;
@@ -183,13 +191,13 @@ struct SwitchInfoPOD
int8_t x, y;
int num_bits;
ConfigBitPOD cbits[max_switch_bits];
-};
+} __attribute__((packed));
struct IerenInfoPOD
{
int8_t iox, ioy, ioz;
int8_t ierx, iery, ierz;
-};
+} __attribute__((packed));
struct BitstreamInfoPOD
{
@@ -197,7 +205,7 @@ struct BitstreamInfoPOD
TileInfoPOD *tiles_nonrouting;
SwitchInfoPOD *switches;
IerenInfoPOD *ierens;
-};
+} __attribute__((packed));
struct ChipInfoPOD
{
@@ -210,13 +218,15 @@ struct ChipInfoPOD
TileType *tile_grid;
BitstreamInfoPOD *bits_info;
PackageInfoPOD *packages_data;
-};
+} __attribute__((packed));
extern ChipInfoPOD chip_info_384;
extern ChipInfoPOD chip_info_1k;
extern ChipInfoPOD chip_info_5k;
extern ChipInfoPOD chip_info_8k;
+/************************ End of chipdb section. ************************/
+
// -----------------------------------------------------------------------
struct BelId
@@ -329,7 +339,7 @@ struct BelRange
struct BelPinIterator
{
- BelPortPOD *ptr = nullptr;
+ const BelPortPOD *ptr = nullptr;
void operator++() { ptr++; }
bool operator!=(const BelPinIterator &other) const
@@ -411,7 +421,7 @@ struct AllPipRange
struct PipIterator
{
- int *cursor = nullptr;
+ const int *cursor = nullptr;
void operator++() { cursor++; }
bool operator!=(const PipIterator &other) const
@@ -476,7 +486,7 @@ struct Chip
IdString getBelName(BelId bel) const
{
assert(bel != BelId());
- return chip_info.bel_data[bel.index].name;
+ return chip_info.bel_data[bel.index].name.get();
}
void bindBel(BelId bel, IdString cell)
@@ -555,7 +565,7 @@ struct Chip
{
BelPinRange range;
assert(wire != WireId());
- range.b.ptr = chip_info.wire_data[wire.index].bels_downhill;
+ range.b.ptr = chip_info.wire_data[wire.index].bels_downhill.get();
range.e.ptr =
range.b.ptr + chip_info.wire_data[wire.index].num_bels_downhill;
return range;
@@ -568,7 +578,7 @@ struct Chip
IdString getWireName(WireId wire) const
{
assert(wire != WireId());
- return chip_info.wire_data[wire.index].name;
+ return chip_info.wire_data[wire.index].name.get();
}
void bindWire(WireId wire, IdString net)
@@ -687,7 +697,7 @@ struct Chip
{
PipRange range;
assert(wire != WireId());
- range.b.cursor = chip_info.wire_data[wire.index].pips_downhill;
+ range.b.cursor = chip_info.wire_data[wire.index].pips_downhill.get();
range.e.cursor =
range.b.cursor + chip_info.wire_data[wire.index].num_downhill;
return range;
@@ -697,7 +707,7 @@ struct Chip
{
PipRange range;
assert(wire != WireId());
- range.b.cursor = chip_info.wire_data[wire.index].pips_uphill;
+ range.b.cursor = chip_info.wire_data[wire.index].pips_uphill.get();
range.e.cursor =
range.b.cursor + chip_info.wire_data[wire.index].num_uphill;
return range;