commit 7e7544a15a930fcf8b1b55a1636b591702178573
parent 93f19d3a17cd100e1f391b6f68aed8518213712f
Author: Luxferre <lux@ferre>
Date: Sun, 14 Aug 2022 16:15:44 +0300
Implemented some task control portio
Diffstat:
M | equi.c | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/equi.c b/equi.c
@@ -388,17 +388,45 @@ ushort persistOp(FILE *pfd, ushort maddr, ushort dataLen, ushort blk, uchar isWr
void portIO(ushort port, ushort p2, ushort p1) {
ushort r1 = 0, r2 = 0, status = 0;
switch(port) {
+ /* Echo port (for testing): r1 = p1, r2 = p2 */
case PORT_ECHO:
r1 = p1;
r2 = p2;
break;
+ /* Random number generator port: p1 = from, p2 = to, r1 and r2 = rand(from, to) */
case PORT_RANDOM:
r1 = (ushort) (p1 + (rand()%p2));
r2 = (ushort) (p1 + (rand()%p2));
break;
+ /* Checksum port: p1 = address, p2 = length, r1 = CRC-16-CCITT value */
case PORT_CHECKSUM:
r1 = crc16(&flatram[p1], p2);
break;
+ /* Task control port: p1 = task ID, p2 = operation code */
+ /* Operations: 0 - get status, 1 - set active status, 2 - unset active status, 3 - get privilege status */
+ /* Only privileged tasks can change status of other tasks, otherwise fail silently */
+ case PORT_TASKCTL:
+ if(p1 >= EQUI_TASKS_MAX) {
+ trapout(OUT_OF_BOUNDS_JUMP);
+ return;
+ }
+ switch(p2) {
+ case 0:
+ r1 = ram.tasks[p1].active;
+ break;
+ case 1:
+ if(curtask->privileged)
+ ram.tasks[p1].active = 1;
+ break;
+ case 2:
+ if(curtask->privileged)
+ ram.tasks[p1].active = 0;
+ break;
+ case 3:
+ r1 = ram.tasks[p1].privileged;
+ break;
+ }
+ break;
default:
fprintf(stderr, "[PORTIO] Unimplemented call to port 0x%X with P1=%X and P2=%X\n", port, p1, p2);
}