Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit b09f52a

Browse files
committed
Add terminal output
1 parent 9dae3d3 commit b09f52a

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

software/src/e2/main.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,101 @@ struct RootAS {
1818
AddressSpace as;
1919
Segment rom_seg;
2020
Segment ram_seg;
21+
Segment sia1;
22+
};
23+
24+
25+
uint8_t
26+
sia1_fetch_byte(AddressSpace *as, uint64_t addr) {
27+
/* Emulator has no read registers yet. */
28+
return 0xCC;
29+
}
30+
31+
uint16_t
32+
sia1_fetch_hword(AddressSpace *as, uint64_t addr) {
33+
if(addr & 1) {
34+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
35+
return 0xCCCC;
36+
}
37+
return (
38+
(uint8_t)(sia1_fetch_byte(as, addr))
39+
| (uint8_t)(sia1_fetch_byte(as, addr+1) << 8)
40+
);
41+
}
42+
43+
uint32_t
44+
sia1_fetch_word(AddressSpace *as, uint64_t addr) {
45+
if(addr & 3) {
46+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
47+
return 0xCCCCCCCC;
48+
}
49+
return (
50+
(uint32_t)(sia1_fetch_hword(as, addr))
51+
| (uint32_t)(sia1_fetch_hword(as, addr+2) << 16)
52+
);
53+
}
54+
55+
uint64_t
56+
sia1_fetch_dword(AddressSpace *as, uint64_t addr) {
57+
if(addr & 7) {
58+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
59+
return 0xCCCCCCCCCCCCCCCC;
60+
}
61+
return (
62+
(uint64_t)(sia1_fetch_word(as, addr))
63+
| ((uint64_t)(sia1_fetch_word(as, addr+4)) << 32)
64+
);
65+
}
66+
67+
void
68+
sia1_store_byte(AddressSpace *as, uint64_t addr, uint8_t datum) {
69+
if(addr == 0) {
70+
fprintf(stdout, "%c", datum);
71+
}
72+
}
73+
74+
void
75+
sia1_store_hword(AddressSpace *as, uint64_t addr, uint16_t datum) {
76+
if(addr & 1) {
77+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
78+
return;
79+
}
80+
81+
sia1_store_byte(as, addr, (uint16_t)datum);
82+
sia1_store_byte(as, addr+1, (uint16_t)datum >> 8);
83+
}
84+
85+
void
86+
sia1_store_word(AddressSpace *as, uint64_t addr, uint32_t datum) {
87+
if(addr & 3) {
88+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
89+
return;
90+
}
91+
92+
sia1_store_hword(as, addr, (uint16_t)datum);
93+
sia1_store_hword(as, addr+2, (uint16_t)datum >> 16);
94+
}
95+
96+
void
97+
sia1_store_dword(AddressSpace *as, uint64_t addr, uint64_t datum) {
98+
if(addr & 7) {
99+
fprintf(stderr, "TODO: raise a misalignment trap to the processor\n");
100+
return;
101+
}
102+
103+
sia1_store_word(as, addr, (uint32_t)datum);
104+
sia1_store_word(as, addr+4, (uint32_t)(datum >> 32));
105+
}
106+
107+
struct IAddressSpace sia1_interface = {
108+
.fetch_dword = sia1_fetch_dword,
109+
.fetch_word = sia1_fetch_word,
110+
.fetch_hword = sia1_fetch_hword,
111+
.fetch_byte = sia1_fetch_byte,
112+
.store_dword = sia1_store_dword,
113+
.store_word = sia1_store_word,
114+
.store_hword = sia1_store_hword,
115+
.store_byte = sia1_store_byte,
21116
};
22117

23118

@@ -404,6 +499,10 @@ new_root_address_space(void) {
404499
dispose_root_address_space(ras);
405500
return NULL;
406501
}
502+
503+
ras->sia1.as.i = &sia1_interface;
504+
ras->sia1.bottom = 0xFFFFFFFFFFFFF000;
505+
ras->sia1.top = 0xFFFFFFFFFFFFF001;
407506
}
408507
return ras;
409508
}

0 commit comments

Comments
 (0)