cp: make con_printf non-fatal no-op
[hvf.git] / loader / loader_asm.s
blob08210fd39681760e317d5e0f929a706c63f54991
2 # Copyright (c) 2007 Josef 'Jeff' Sipek
5 #include "loader.h"
7 .text
8 .align 4
9 .globl __do_io
10 .type __do_io, @function
11 __do_io:
13 # r4 = 0x80000000
15 XGR %r4, %r4
16 LHI %r4, 0x8
17 SLL %r4, 20
19 # r14 = r14 & 0x7fffffff don't ask, it's strangely retarded
21 L %r1,ADDRMASK(%r4)
22 NR %r14, %r1 # mask out the bit
24 # set up the interrupt handler
25 MVC 0x1f0(16),IOPSW(%r4) # SET NEW IO PSW
26 LA %r1,IOHANDLER(%r4) # GET HANDLER ADDRESS
27 STG %r1,0x1f0+8 # SAVE IN NEW PSW
29 L %r1, 0xb8 # load subsystem ID
31 SSCH ORB(%r4) # issue IO
33 # Load Control Register 6 with I/O interrupt subclass mask
34 STCTG 6,6,TMPVAR(%r4) # GET CR6
35 OI TMPVAR+4(%r4),0xFF # enable all
36 LCTLG 6,6,TMPVAR(%r4) # RELOAD MODIFIED CR6
39 7) Enable the PSW for I/O interrupts and go into wait state (you need bits 6, 12 & 14 set to 1 in the PSW : X'020A000000000000' is a good example)
41 LPSWE WAITPSW(%r4)
44 # The IO interrupt handler
46 .globl IOHANDLER
47 IOHANDLER:
48 # is this for us?
49 L %r1, MAGICVAL(%r4)
50 C %r1, 0xbc
51 BNE IONOTDONE(%r4)
53 # it is!
55 L %r1, 0xb8 # load subsystem ID
57 TSCH IRB(%r4)
60 FIXME: we should do more checking!
62 11) If Unit check or Channel Status|=0 : An I/O error occurred and act accordingly
63 12) If unit exception : End of media (for tape & cards) and act accordingly
64 13) If device end : I/O Completed.. Perform post I/O stuff (like advancing your pointers) and back to step 3
67 # unit check? (end of media?)
68 L %r1,IRB+5(%r4)
69 LA %r0,0x02
70 NR %r0,%r1
71 LA %r2,1 # return 1 - end of medium
72 BCR 4,%r14 # unit chk => return
74 # check the SCSW.. If CE Only : LPSW Old I/O PSW
75 LA %r0,0x04
76 NR %r0,%r1
77 LA %r2,0 # means IO done
78 BCR 4,%r14 # device end => return
80 IONOTDONE:
81 LPSWE 0x170
84 # The PGM interrupt handler
86 .globl PGMHANDLER
87 PGMHANDLER:
88 STMG %r1,%r3,0x200
90 # r3 = 0x80000000
91 XGR %r3, %r3
92 LHI %r3, 0x8
93 SLL %r3, 20
95 # is ILC == 3?
96 LGH %r2,0x8C
97 CGHI %r2,0x0006
98 BNE ERR
100 # grab the old PSW address, subtract length of TPROT, and compare it
101 # with the TPROT opcode (0xe501)
102 LG %r1,0x158
103 AGHI %r1,-6
104 LLGH %r2,TPROTOP(%r3)
105 LLGH %r1,0(%r1)
106 CGR %r2,%r1
107 BNE ERR(%r3)
109 # set CC=3
110 OI 0x152,0x30
112 LMG %r1,%r3,0x200
114 LPSWE 0x150
116 ERR:
117 .byte 0x00, 0x00
121 # Useful data
123 .data
124 .globl TPROTOP
125 TPROTOP:
126 .byte 0xe5, 0x01
128 .align 8
129 .globl IOPSW
130 IOPSW:
131 .byte 0x00
132 # bits value name desc
133 # 0 0 <zero>
134 # 1 0 PER Mask (R) disabled
135 # 2-4 0 <zero>
136 # 5 0 DAT Mode (T) disabled
137 # 6 0 I/O Mask (IO) enabled
138 # 7 0 External Mask (EX) disabled
140 .byte 0x00
141 # bits value name desc
142 # 8-11 0 Key
143 # 12 0 <one>
144 # 13 0 Machine-Check Mask (M) disabled
145 # 14 0 Wait State (W) executing
146 # 15 0 Problem State (P) supervisor state
148 .byte 0x00
149 # bits value name desc
150 # 16-17 0 Address-Space Control (AS) disabled
151 # 18-19 0 Condition Code (CC)
152 # 20-23 0 Program Mask exceptions disabled
154 .byte 0x01
155 # bits value name desc
156 # 24-30 0 <zero>
157 # 31 1 Extended Addressing (EA) EA + BA = 64 mode
159 .byte 0x80
160 .byte 0x00
161 .byte 0x00
162 .byte 0x00
163 .byte 0x00
164 .byte 0x00
165 .byte 0x00
166 .byte 0x00
167 .byte 0x00
168 .byte 0x00
169 .byte 0x00
170 .byte 0x00
171 # bits value name desc
172 # 32 1 Basic Addressing (BA) BA = 31, !BA = 24
173 # 33-63 0 <zero>
174 # 64-127 addr Instruction Address Address to exec
176 .globl WAITPSW
177 WAITPSW:
178 .byte 0x02
179 # bits value name desc
180 # 0 0 <zero>
181 # 1 0 PER Mask (R) disabled
182 # 2-4 0 <zero>
183 # 5 0 DAT Mode (T) disabled
184 # 6 1 I/O Mask (IO) enabled
185 # 7 0 External Mask (EX) disabled
187 .byte 0x02
188 # bits value name desc
189 # 8-11 0 Key
190 # 12 0 <zero>
191 # 13 0 Machine-Check Mask (M) disabled
192 # 14 1 Wait State (W) not executing
193 # 15 0 Problem State (P) supervisor state
195 .byte 0x00
196 # bits value name desc
197 # 16-17 0 Address-Space Control (AS) disabled
198 # 18-19 0 Condition Code (CC)
199 # 20-23 0 Program Mask exceptions disabled
201 .byte 0x01
202 # bits value name desc
203 # 24-30 0 <zero>
204 # 31 1 Extended Addressing (EA) EA + BA = 64 mode
206 .byte 0x80
207 .byte 0x00
208 .byte 0x00
209 .byte 0x00
210 .byte 0x00
211 .byte 0x00
212 .byte 0x00
213 .byte 0x00
214 .byte 0x00
215 .byte 0x00
216 .byte 0x00
217 .byte 0x00
218 # bits value name desc
219 # 32 1 Basic Addressing (BA) BA = 31, !BA = 24
220 # 33-63 0 <zero>
221 # 64-127 addr Instruction Address Address to exec
223 .globl TMPVAR
224 TMPVAR:
225 .8byte 0x0
227 .globl ADDRMASK
228 ADDRMASK:
229 .4byte 0x7fffffff
231 .globl MAGICVAL
232 MAGICVAL:
233 .4byte 0x12345678
235 .globl IRB
236 IRB:
237 .8byte 0x00
238 .8byte 0x00
239 .8byte 0x00
240 .8byte 0x00
241 .8byte 0x00
242 .8byte 0x00
243 .8byte 0x00
244 .8byte 0x00
245 .8byte 0x00
246 .8byte 0x00
247 .8byte 0x00
248 .8byte 0x00