125 |
127 |
126 # Device class properties |
128 # Device class properties |
127 regions = [qemu.ioregion(0x1000, readl=read_reg, writel=write_reg)] |
129 regions = [qemu.ioregion(0x1000, readl=read_reg, writel=write_reg)] |
128 irqs = 1 |
130 irqs = 1 |
129 name = "syborg,serial" |
131 name = "syborg,serial" |
130 properties = {"fifo-size":16, "chardev":None} |
132 properties = {"fifo-size":16, "chardev":None, "target": ""} |
131 |
133 |
132 qemu.register_device(syborg_serial) |
134 qemu.register_device(syborg_serial) |
|
135 |
|
136 class syborg_modem(syborg_serial): |
|
137 |
|
138 def create(self): |
|
139 syborg_serial.create(self) |
|
140 |
|
141 # Find the path of the emulator executable |
|
142 path = os.path.dirname(sys.executable) |
|
143 executable = os.getenv("SVP_MODEM_EXECUTABLE") |
|
144 if None == executable: |
|
145 executable = self.modem_executable |
|
146 |
|
147 executable_name = executable |
|
148 fq_executable = os.path.join(path, executable_name) |
|
149 print(fq_executable) |
|
150 |
|
151 if not os.path.exists(fq_executable): |
|
152 executable_name = executable + ".exe" |
|
153 fq_executable = os.path.join(path, executable_name) |
|
154 |
|
155 if not os.path.exists(fq_executable): |
|
156 sys.exit("Could not locate modem executable '" + executable + "' in '" + path + "'!\n") |
|
157 |
|
158 # Attempt to find the correct port from the target spec |
|
159 target = self.properties["target"] |
|
160 |
|
161 if not(target.startswith("tcp:") or target.startswith("udp:")): |
|
162 sys.exit("Modem device is not accessed via an acceptable socket.") |
|
163 |
|
164 target = target[4:] |
|
165 port_start_idx = target.find(":"); |
|
166 port_end_idx = target.find(",") |
|
167 if -1 == port_start_idx: |
|
168 sys.exit("Could not extract port number from modem target spec!") |
|
169 |
|
170 port = "" |
|
171 if -1 == port_end_idx: |
|
172 port = target[port_start_idx + 1:] |
|
173 else: |
|
174 port = target[port_start_idx + 1:port_end_idx] |
|
175 |
|
176 os.spawnl(os.P_NOWAIT, fq_executable, executable_name, "-p", port) |
|
177 self.chardev.handle_connect() |
|
178 |
|
179 # Name property override. |
|
180 name = "syborg,serial,modem" |
|
181 |
|
182 # Default modem executable |
|
183 modem_executable = "phonesim" |
|
184 |
|
185 qemu.register_device(syborg_modem) |