diff options
Diffstat (limited to 'ice40/chip.h')
-rw-r--r-- | ice40/chip.h | 183 |
1 files changed, 95 insertions, 88 deletions
diff --git a/ice40/chip.h b/ice40/chip.h index 5eeca5e9..e6bb0a08 100644 --- a/ice40/chip.h +++ b/ice40/chip.h @@ -72,31 +72,35 @@ PortPin portPinFromId(IdString id); // ----------------------------------------------------------------------- -#if 0 -template <typename T> -struct RelPtr { - int offset; +/**** Everything in this section must be kept in sync with chipdb.py ****/ - // RelPtr(T *ptr) : offset(reinterpret_cast<const char*>(ptr) - - // reinterpret_cast<const char*>(this)) {} +template <typename T> struct RelPtr +{ + int32_t offset; - T&operator*() { - return *reinterpret_cast<T*>(reinterpret_cast<char*>(this) + offset); - } + // void set(const T *ptr) { + // offset = reinterpret_cast<const char*>(ptr) - + // reinterpret_cast<const char*>(this); + // } - T*operator->() { - return reinterpret_cast<T*>(reinterpret_cast<char*>(this) + offset); + const T *get() const + { + return reinterpret_cast<const T *>( + reinterpret_cast<const char *>(this) + offset); } + + const T &operator[](size_t index) const { return get()[index]; } + + 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 +109,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 +125,7 @@ struct PipInfoPOD int8_t x, y; int16_t switch_mask; int32_t switch_index; -}; +} __attribute__((packed)); struct WireInfoPOD { @@ -132,23 +137,23 @@ 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; -}; + RelPtr<char> name; + int32_t num_pins; + RelPtr<PackagePinPOD> pins; +} __attribute__((packed)); -enum TileType +enum TileType : uint32_t { TILE_NONE = 0, TILE_LOGIC = 1, @@ -160,62 +165,64 @@ 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; -}; + int16_t num_config_entries; + RelPtr<ConfigEntryPOD> entries; +} __attribute__((packed)); static const int max_switch_bits = 5; struct SwitchInfoPOD { + int32_t num_bits; 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 { - int num_switches, num_ierens; - TileInfoPOD *tiles_nonrouting; - SwitchInfoPOD *switches; - IerenInfoPOD *ierens; -}; + int32_t num_switches, num_ierens; + RelPtr<TileInfoPOD> tiles_nonrouting; + RelPtr<SwitchInfoPOD> switches; + RelPtr<IerenInfoPOD> ierens; +} __attribute__((packed)); struct ChipInfoPOD { - int width, height; - int num_bels, num_wires, num_pips; - int num_switches, num_packages; - BelInfoPOD *bel_data; - WireInfoPOD *wire_data; - PipInfoPOD *pip_data; - TileType *tile_grid; - BitstreamInfoPOD *bits_info; - PackageInfoPOD *packages_data; -}; + int32_t width, height; + int32_t num_bels, num_wires, num_pips; + int32_t num_switches, num_packages; + RelPtr<BelInfoPOD> bel_data; + RelPtr<WireInfoPOD> wire_data; + RelPtr<PipInfoPOD> pip_data; + RelPtr<TileType> tile_grid; + RelPtr<BitstreamInfoPOD> bits_info; + RelPtr<PackageInfoPOD> packages_data; +} __attribute__((packed)); + +extern uint8_t chipdb_blob_384[]; +extern uint8_t chipdb_blob_1k[]; +extern uint8_t chipdb_blob_5k[]; +extern uint8_t chipdb_blob_8k[]; -extern ChipInfoPOD chip_info_384; -extern ChipInfoPOD chip_info_1k; -extern ChipInfoPOD chip_info_5k; -extern ChipInfoPOD chip_info_8k; +/************************ End of chipdb section. ************************/ // ----------------------------------------------------------------------- @@ -329,7 +336,7 @@ struct BelRange struct BelPinIterator { - BelPortPOD *ptr = nullptr; + const BelPortPOD *ptr = nullptr; void operator++() { ptr++; } bool operator!=(const BelPinIterator &other) const @@ -411,7 +418,7 @@ struct AllPipRange struct PipIterator { - int *cursor = nullptr; + const int *cursor = nullptr; void operator++() { cursor++; } bool operator!=(const PipIterator &other) const @@ -453,8 +460,8 @@ struct ChipArgs struct Chip { - ChipInfoPOD chip_info; - PackageInfoPOD *package_info; + const ChipInfoPOD *chip_info; + const PackageInfoPOD *package_info; mutable std::unordered_map<IdString, int> bel_by_name; mutable std::unordered_map<IdString, int> wire_by_name; @@ -476,7 +483,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) @@ -509,7 +516,7 @@ struct Chip { BelRange range; range.b.cursor = 0; - range.e.cursor = chip_info.num_bels; + range.e.cursor = chip_info->num_bels; return range; } @@ -532,7 +539,7 @@ struct Chip BelType getBelType(BelId bel) const { assert(bel != BelId()); - return chip_info.bel_data[bel.index].type; + return chip_info->bel_data[bel.index].type; } WireId getWireBelPin(BelId bel, PortPin pin) const; @@ -542,10 +549,10 @@ struct Chip BelPin ret; assert(wire != WireId()); - if (chip_info.wire_data[wire.index].bel_uphill.bel_index >= 0) { + if (chip_info->wire_data[wire.index].bel_uphill.bel_index >= 0) { ret.bel.index = - chip_info.wire_data[wire.index].bel_uphill.bel_index; - ret.pin = chip_info.wire_data[wire.index].bel_uphill.port; + chip_info->wire_data[wire.index].bel_uphill.bel_index; + ret.pin = chip_info->wire_data[wire.index].bel_uphill.port; } return ret; @@ -555,9 +562,9 @@ struct Chip { BelPinRange range; assert(wire != WireId()); - range.b.ptr = chip_info.wire_data[wire.index].bels_downhill; - range.e.ptr = - range.b.ptr + chip_info.wire_data[wire.index].num_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 +575,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) @@ -601,7 +608,7 @@ struct Chip { WireRange range; range.b.cursor = 0; - range.e.cursor = chip_info.num_wires; + range.e.cursor = chip_info->num_wires; return range; } @@ -614,20 +621,20 @@ struct Chip { assert(pip != PipId()); assert(pip_to_net[pip.index] == IdString()); - assert(switches_locked[chip_info.pip_data[pip.index].switch_index] == + assert(switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString()); pip_to_net[pip.index] = net; - switches_locked[chip_info.pip_data[pip.index].switch_index] = net; + switches_locked[chip_info->pip_data[pip.index].switch_index] = net; } void unbindPip(PipId pip) { assert(pip != PipId()); assert(pip_to_net[pip.index] != IdString()); - assert(switches_locked[chip_info.pip_data[pip.index].switch_index] != + assert(switches_locked[chip_info->pip_data[pip.index].switch_index] != IdString()); pip_to_net[pip.index] = IdString(); - switches_locked[chip_info.pip_data[pip.index].switch_index] = + switches_locked[chip_info->pip_data[pip.index].switch_index] = IdString(); } @@ -635,11 +642,11 @@ struct Chip { assert(pip != PipId()); if (args.type == ChipArgs::UP5K) { - int x = chip_info.pip_data[pip.index].x; - if (x == 0 || x == (chip_info.width - 1)) + int x = chip_info->pip_data[pip.index].x; + if (x == 0 || x == (chip_info->width - 1)) return false; } - return switches_locked[chip_info.pip_data[pip.index].switch_index] == + return switches_locked[chip_info->pip_data[pip.index].switch_index] == IdString(); } @@ -647,7 +654,7 @@ struct Chip { assert(pip != PipId()); if (conflicting) - return switches_locked[chip_info.pip_data[pip.index].switch_index]; + return switches_locked[chip_info->pip_data[pip.index].switch_index]; return pip_to_net[pip.index]; } @@ -655,7 +662,7 @@ struct Chip { AllPipRange range; range.b.cursor = 0; - range.e.cursor = chip_info.num_pips; + range.e.cursor = chip_info->num_pips; return range; } @@ -663,7 +670,7 @@ struct Chip { WireId wire; assert(pip != PipId()); - wire.index = chip_info.pip_data[pip.index].src; + wire.index = chip_info->pip_data[pip.index].src; return wire; } @@ -671,7 +678,7 @@ struct Chip { WireId wire; assert(pip != PipId()); - wire.index = chip_info.pip_data[pip.index].dst; + wire.index = chip_info->pip_data[pip.index].dst; return wire; } @@ -679,7 +686,7 @@ struct Chip { DelayInfo delay; assert(pip != PipId()); - delay.delay = chip_info.pip_data[pip.index].delay; + delay.delay = chip_info->pip_data[pip.index].delay; return delay; } @@ -687,9 +694,9 @@ 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; + range.b.cursor + chip_info->wire_data[wire.index].num_downhill; return range; } @@ -697,9 +704,9 @@ 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; + range.b.cursor + chip_info->wire_data[wire.index].num_uphill; return range; } |