1 // Copyright 2017-2019 VMware, Inc.
2 // SPDX-License-Identifier: BSD-2-Clause
3 //
4 // The BSD-2 license (the License) set forth below applies to all parts of the
5 // Cascade project.  You may not use this file except in compliance with the
6 // License.
7 //
8 // BSD-2 License
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice, this
14 // list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the following disclaimer in the documentation
18 // and/or other materials provided with the distribution.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #include "target/core/avmm/de10/de10_logic.h"
32 #include "target/core/avmm/de10/io.h"
33 
34 namespace cascade::avmm {
35 
De10Logic(Interface * interface,ModuleDeclaration * md,size_t slot,volatile uint8_t * addr)36 De10Logic::De10Logic(Interface* interface, ModuleDeclaration* md, size_t slot, volatile uint8_t* addr) : AvmmLogic<12,uint16_t,uint32_t>(interface, md, slot) {
37   get_table()->set_read([addr](uint16_t index) {
38     auto* maddr = reinterpret_cast<volatile uint8_t*>(addr + (index << 2));
39     return DE10_READ(maddr);
40   });
41   get_table()->set_write([addr](uint16_t index, uint32_t val) {
42     auto* maddr = reinterpret_cast<volatile uint8_t*>(addr + (index << 2));
43     DE10_WRITE(maddr, val);
44   });
45 }
46 
47 } // namespace cascade::avmm
48