rsc | 0a61c07 | 2004-04-19 18:18:37 +0000 | [diff] [blame] | 1 | // runtime library definitions |
| 2 | if objtype=="mips2" then objtype="mips"; |
| 3 | |
| 4 | include("/sys/src/alef/lib/"+objtype+"/acid"); |
| 5 | |
| 6 | defn |
| 7 | pchan(addr) |
| 8 | { |
| 9 | local l, n; |
| 10 | |
| 11 | complex Chan addr; |
| 12 | |
| 13 | if addr.sva then |
| 14 | print("Sender waiting: buffer ", addr.sva, "\n"); |
| 15 | else |
| 16 | print("No sender\n"); |
| 17 | |
| 18 | if addr.rva then |
| 19 | print("Receiver waiting: buffer ", addr.rva, "\n"); |
| 20 | else |
| 21 | print("No receiver\n"); |
| 22 | |
| 23 | if addr.async then { |
| 24 | n = 0; |
| 25 | l = addr.qh; |
| 26 | while l do { |
| 27 | n = n+1; |
| 28 | l = l.next; |
| 29 | } |
| 30 | print("Async channel\n\t", n\D, " messsages queued\n\t"); |
| 31 | l = addr.free; |
| 32 | while l do { |
| 33 | n = n+1; |
| 34 | l = l.next; |
| 35 | } |
| 36 | print(n\D, " free buffers\n"); |
| 37 | } |
| 38 | |
| 39 | if addr.selt then { |
| 40 | l = "send"; |
| 41 | if addr.selt then |
| 42 | l = "receive"; |
| 43 | print("In select ", l, ": task ", addr.selt\X, "\n"); |
| 44 | labstk(addr.selt); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | defn |
| 49 | tdb() |
| 50 | { |
| 51 | local ta, tq; |
| 52 | |
| 53 | // Private proc tdb pointer |
| 54 | ta = *{ 0x7fffe000, |
| 55 | 0x0ffdf000, |
| 56 | 0xbfff5000 }[match(objtype, {"mips", "sparc", "386"})]; |
| 57 | |
| 58 | complex Tdb ta; |
| 59 | |
| 60 | print("tdb ", ta.ntask, " tasks:"); |
| 61 | if *ta then |
| 62 | print("locked\n"); |
| 63 | else |
| 64 | print("unlocked\n"); |
| 65 | |
| 66 | if ta.ctask then { |
| 67 | print("current task ", ta.ctask, "\n"); |
| 68 | Task(ta.ctask); |
| 69 | } |
| 70 | else |
| 71 | print("proc is idle\n"); |
| 72 | |
| 73 | tq = (Task)ta.runhd; |
| 74 | if tq == 0 then |
| 75 | return {}; |
| 76 | |
| 77 | print("Tasks ready to run:\n"); |
| 78 | while tq != 0 do { |
| 79 | print("Task(", tq, ")\n"); |
| 80 | tq = tq.link; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | defn |
| 85 | lselect(addr) |
| 86 | { |
| 87 | local c; |
| 88 | |
| 89 | complex Task addr; |
| 90 | complex Chan c; |
| 91 | |
| 92 | c = addr.slist; |
| 93 | if c == 0 then { |
| 94 | print("No select pending\n"); |
| 95 | return {}; |
| 96 | } |
| 97 | while c do { |
| 98 | print("pchan(", c\X, ")\n"); |
| 99 | c = c.sellink; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | defn |
| 104 | pqlock(addr) |
| 105 | { |
| 106 | local t; |
| 107 | |
| 108 | complex QLock addr; |
| 109 | |
| 110 | if *addr then |
| 111 | print("QLock is under modification\n"); |
| 112 | if addr.used == 0 then |
| 113 | return {}; |
| 114 | |
| 115 | print("QLock is held\n"); |
| 116 | t = addr.queue; |
| 117 | complex Task t; |
| 118 | if t == 0 then { |
| 119 | print("No tasks waiting\n"); |
| 120 | return {}; |
| 121 | } |
| 122 | print("Tasks waiting:\n"); |
| 123 | while t do { |
| 124 | print("Task(", t, ")\n"); |
| 125 | tq = tq.qlink; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | srcpath = { |
| 130 | "./", |
| 131 | "/sys/src/alef/lib/port/", |
| 132 | "/sys/src/alef/lib/p9/", |
| 133 | "/sys/src/alef/lib/"+objtype+"/" |
| 134 | }; |
| 135 | |
| 136 | defn labstk(l) |
| 137 | { |
| 138 | if objtype == "386" then |
| 139 | _stk(ALEF_switch, *l, linkreg(0), 0); |
| 140 | else |
| 141 | _stk(*(l+4), *l, linkreg(0), 0); |
| 142 | } |
| 143 | |
| 144 | print(acidfile); |
| 145 | |
| 146 | include("/sys/src/alef/lib/port/acid."+objtype); |
| 147 | include("/sys/src/alef/lib/p9/acid."+objtype); |