Newly tracked file
emulator/processor/cpu/mmap_std.go
created.
emulator/processor/cpu/cpu.go
changed.
Other files ignored by Codecov
1 | + | // +build !fastmem |
|
2 | + | ||
3 | + | /* |
|
4 | + | Copyright (c) 2019-2021 Andreas T Jonsson |
|
5 | + | ||
6 | + | This software is provided 'as-is', without any express or implied |
|
7 | + | warranty. In no event will the authors be held liable for any damages |
|
8 | + | arising from the use of this software. |
|
9 | + | ||
10 | + | Permission is granted to anyone to use this software for any purpose, |
|
11 | + | including commercial applications, and to alter it and redistribute it |
|
12 | + | freely, subject to the following restrictions: |
|
13 | + | ||
14 | + | 1. The origin of this software must not be misrepresented; you must not |
|
15 | + | claim that you wrote the original software. If you use this software |
|
16 | + | in a product, an acknowledgment in the product documentation would be |
|
17 | + | appreciated but is not required. |
|
18 | + | 2. Altered source versions must be plainly marked as such, and must not be |
|
19 | + | misrepresented as being the original software. |
|
20 | + | 3. This notice may not be removed or altered from any source distribution. |
|
21 | + | */ |
|
22 | + | ||
23 | + | package cpu |
|
24 | + | ||
25 | + | import ( |
|
26 | + | "errors" |
|
27 | + | ||
28 | + | "github.com/andreas-jonsson/virtualxt/emulator/memory" |
|
29 | + | "github.com/andreas-jonsson/virtualxt/emulator/peripheral" |
|
30 | + | ) |
|
31 | + | ||
32 | + | type memMapLookup struct { |
|
33 | + | mmap [0x100000]byte |
|
34 | + | memPeripherals [MaxPeripherals]memory.Memory |
|
35 | + | } |
|
36 | + | ||
37 | + | func (m *memMapLookup) initializeMemMap(peripherals []peripheral.Peripheral) error { |
|
38 | + | dummyMem := &memory.DummyMemory{} |
|
39 | + | for i := range m.memPeripherals[:] { |
|
40 | + | m.memPeripherals[i] = dummyMem |
|
41 | + | } |
|
42 | + | ||
43 | + | for i := 1; i <= len(peripherals); i++ { |
|
44 | + | if dev, ok := peripherals[i-1].(memory.Memory); ok { |
|
45 | + | m.memPeripherals[i] = dev |
|
46 | + | } |
|
47 | + | } |
|
48 | + | return nil |
|
49 | + | } |
|
50 | + | ||
51 | + | func (m *memMapLookup) GetMappedMemoryDevice(addr memory.Pointer) memory.Memory { |
|
52 | + | return m.memPeripherals[m.mmap[addr]] |
|
53 | + | } |
|
54 | + | ||
55 | + | func (m *memMapLookup) InstallMemoryDevice(device memory.Memory, from, to memory.Pointer) error { |
|
56 | + | for i, d := range m.memPeripherals[:] { |
|
57 | + | if d == device { |
|
58 | + | for from <= to { |
|
59 | + | m.mmap[from] = byte(i) |
|
60 | + | from++ |
|
61 | + | } |
|
62 | + | return nil |
|
63 | + | } |
|
64 | + | } |
|
65 | + | return errors.New("could not find peripheral") |
|
66 | + | } |
35 | 35 | type CPU struct { |
|
36 | 36 | processor.Registers |
|
37 | 37 | instructionState |
|
38 | + | memMapLookup |
|
38 | 39 | ||
39 | 40 | isV20, trap bool |
|
40 | 41 |
45 | 46 | ||
46 | 47 | iomap [0x10000]byte |
|
47 | 48 | ioPeripherals [MaxPeripherals]memory.IO |
|
48 | - | ||
49 | - | mmap [0x100000]byte |
|
50 | - | memPeripherals [MaxPeripherals]memory.Memory |
|
51 | 49 | } |
|
52 | 50 | ||
53 | 51 | func NewCPU(peripherals []peripheral.Peripheral) (*CPU, []error) { |
58 | 56 | p.ioPeripherals[i] = dummyIO |
|
59 | 57 | } |
|
60 | 58 | ||
61 | - | dummyMem := &memory.DummyMemory{} |
|
62 | - | for i := range p.memPeripherals[:] { |
|
63 | - | p.memPeripherals[i] = dummyMem |
|
64 | - | } |
|
65 | - | ||
66 | 59 | for i := 1; i <= len(peripherals); i++ { |
|
67 | 60 | if dev, ok := peripherals[i-1].(memory.IO); ok { |
|
68 | 61 | p.ioPeripherals[i] = dev |
|
69 | 62 | } |
|
70 | - | if dev, ok := peripherals[i-1].(memory.Memory); ok { |
|
71 | - | p.memPeripherals[i] = dev |
|
72 | - | } |
|
73 | 63 | } |
|
74 | 64 | return p, p.installPeripherals() |
|
75 | 65 | } |
80 | 70 | ||
81 | 71 | func (p *CPU) installPeripherals() []error { |
|
82 | 72 | var errs []error |
|
73 | + | if err := p.initializeMemMap(p.peripherals); err != nil { |
|
74 | + | errs = append(errs, err) |
|
75 | + | } |
|
83 | 76 | ||
84 | 77 | log.Print("\nPeripherals") |
|
85 | 78 | for _, d := range p.peripherals { |
140 | 133 | } |
|
141 | 134 | } |
|
142 | 135 | ||
143 | - | func (p *CPU) GetMappedMemoryDevice(addr memory.Pointer) memory.Memory { |
|
144 | - | return p.memPeripherals[p.mmap[addr]] |
|
145 | - | } |
|
146 | - | ||
147 | 136 | func (p *CPU) GetMappedIODevice(port uint16) memory.IO { |
|
148 | 137 | return p.ioPeripherals[p.iomap[port]] |
|
149 | 138 | } |
205 | 194 | return nil |
|
206 | 195 | } |
|
207 | 196 | ||
208 | - | func (p *CPU) InstallMemoryDevice(device memory.Memory, from, to memory.Pointer) error { |
|
209 | - | for i, d := range p.memPeripherals[:] { |
|
210 | - | if d == device { |
|
211 | - | for from <= to { |
|
212 | - | p.mmap[from] = byte(i) |
|
213 | - | from++ |
|
214 | - | } |
|
215 | - | return nil |
|
216 | - | } |
|
217 | - | } |
|
218 | - | return errors.New("could not find peripheral") |
|
219 | - | } |
|
220 | - | ||
221 | - | func (p *CPU) InstallMemoryDeviceAt(device memory.Memory, addr ...memory.Pointer) error { |
|
222 | - | for _, a := range addr { |
|
223 | - | if err := p.InstallMemoryDevice(device, a, a); err != nil { |
|
224 | - | return err |
|
225 | - | } |
|
226 | - | } |
|
227 | - | return nil |
|
228 | - | } |
|
229 | - | ||
230 | 197 | func (p *CPU) InstallIODevice(device memory.IO, from, to uint16) error { |
|
231 | 198 | for i, d := range p.ioPeripherals[:] { |
|
232 | 199 | if d == device { |
248 | 215 | } |
|
249 | 216 | return nil |
|
250 | 217 | } |
|
218 | + | ||
219 | + | func (p *CPU) InstallMemoryDeviceAt(device memory.Memory, addr ...memory.Pointer) error { |
|
220 | + | for _, a := range addr { |
|
221 | + | if err := p.InstallMemoryDevice(device, a, a); err != nil { |
|
222 | + | return err |
|
223 | + | } |
|
224 | + | } |
|
225 | + | return nil |
|
226 | + | } |
Files | Coverage |
---|---|
emulator/processor/cpu | 80.87% |
platform | 0.00% |
Project Totals (9 files) | 72.48% |
TRAVIS_OS_NAME=windows 1.15.x=.15.x
TRAVIS_OS_NAME=linux 1.15.x=.15.x
TRAVIS_OS_NAME=osx 1.15.x=.15.x