2 * Minimal Alpha system boot code.
4 * Copyright Linaro Ltd 2019
12 .macro load_pci_io reg
13 /* For typhoon, this is
14 * 0xfffffc0000000000 -- kseg identity map
15 * + 0x10000000000 -- typhoon pio base
16 * + 0x1fc000000 -- typhoon pchip0 pci base
17 * = 0xfffffd01fc000000
19 ldah \reg, -3 /* ff..fd0000 */
20 lda \reg, 0x1fc(\reg) /* ff..fd01fc */
46 ldah $gp, 0($gp) !gpdisp!1
47 lda $gp, 0($gp) !gpdisp!1
49 ldah $sp, $stack_end($gp) !gprelhigh
50 lda $sp, $stack_end($sp) !gprellow
52 /* Install kernel gp for exception handlers. */
56 /* Install exception handlers. */
57 ldah $16, entInt($gp) !gprelhigh
58 lda $16, entInt($16) !gprellow
62 ldah $16, entArith($gp) !gprelhigh
63 lda $16, entArith($16) !gprellow
67 ldah $16, entMM($gp) !gprelhigh
68 lda $16, entMM($16) !gprellow
72 ldah $16, entIF($gp) !gprelhigh
73 lda $16, entIF($16) !gprellow
77 ldah $16, entUna($gp) !gprelhigh
78 lda $16, entUna($16) !gprellow
82 ldah $16, entSys($gp) !gprelhigh
83 lda $16, entSys($16) !gprellow
91 lda $2, 0x87 /* outb(0x87, com1Lcr); */
93 stb $31, com1Dlm($1) /* outb(0, com1Dlm); */
94 lda $2, 3 /* baudconst 3 => 56000 */
95 stb $2, com1Dll($1) /* outb(baudconst, com1Dll); */
97 stb $2, com1Lcr($1) /* outb(0x07, com1Lcr) */
99 stb $2, com1Mcr($1) /* outb(0x0f, com1Mcr) */
101 bsr $26, main !samegp
103 /* fall through to _exit */
109 .frame $sp, 0, $26, 0
112 /* We cannot return an error code. */
117 * We have received an exception that we don't handle. Log and exit.
127 ldah $16, $errormsg($gp) !gprelhigh
128 lda $16, $errormsg($16) !gprellow
129 bsr $26, __sys_outs !samegp
130 bsr $26, _exit !samegp
135 .string "Terminated by exception.\n"
142 /* Output a single character to serial port */
146 .frame $sp, 0, $26, 0
152 * while ((inb(com1Lsr) & 0x20) == 0)
155 1: ldbu $0, com1Lsr($1)
159 /* outb(c, com1Thr); */
164 /* Output a nul-terminated string to serial port */
168 .frame $sp, 0, $26, 0
177 * while ((inb(com1Lsr) & 0x20) == 0)
180 1: ldbu $0, com1Lsr($1)
184 /* outb(c, com1Thr); */
195 * Division routines that are normally in libc.
197 * These do not follow the C calling convention. Arguments are in $24+$25,
198 * the result is in $27. Register $28 may be clobbered; everything else
201 * We store the remainder in $28, so that we can share code.
203 * We do not signal divide by zero.
207 * Unsigned 64-bit division.
236 /* Shift left until divisor >= modulus. */
237 1: cmpult divisor, modulus, compare
239 addq divisor, divisor, divisor
240 addq mask, mask, mask
243 2: addq quotient, mask, tmp2
245 cmpule divisor, modulus, compare
246 subq modulus, divisor, tmp1
247 cmovne compare, tmp2, quotient
248 srl divisor, 1, divisor
249 cmovne compare, tmp1, modulus
271 * Unsigned 64-bit remainder.
272 * Note that __divqu above leaves the result in $28.
292 * Signed 64-bit division.
300 /* Common case: both arguments are positive. */
304 /* At least one argument is negative. */
310 /* Compute absolute values. */
321 /* -a / b = a / -b = -(a / b) */
332 * Signed 64-bit remainder.
340 /* Common case: both arguments are positive. */
344 /* At least one argument is negative. */
350 /* Compute absolute values. */
362 /* -a % b = -(a % b); a % -b = a % b. */
371 * Unsigned 32-bit division.
384 /* Zero extend and use the 64-bit routine. */
398 * Unsigned 32-bit remainder.
411 /* Zero extend and use the 64-bit routine. */
416 /* Recall that the remainder is returned in $28. */
426 * Signed 32-bit division.
443 /* Compute absolute values. */
454 /* Negate the unsigned result, if necessary. */
467 * Signed 32-bit remainder.
484 /* Compute absolute values. */
496 /* Negate the unsigned result, if necessary. */
511 .size stack, . - stack