1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Definitions of interfaces that provide services from the secondary
* boot program to its clients (primarily Solaris, krtld, kmdb and their
* successors.) This interface replaces the bootops (BOP) implementation
* as the interface to be called by boot clients.
*
*/
#include <sys/types.h>
#include <sys/reboot.h>
#include <sys/param.h>
#include <sys/varargs.h>
#include <sys/obpdefs.h>
#include <sys/promif.h>
#include <sys/bootconf.h>
#include <sys/bootstat.h>
/*
* Implementation of the "version" boot service.
* Return the compiled version number of this implementation.
*
* Note: An individual service can be tested for and versioned with
* bop_serviceavail();
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] Res0: returned version number
*/
uint_t
bop_getversion(struct bootops *bop)
{
return (bop->bsys_version);
}
/*
* Implementation of the "open" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] filename string
* args[4] flags
* args[5] Res0: returned result
*
*/
int
bop_open(struct bootops *bop, char *name, int flags)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("open");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(name);
args[4] = boot_int2cell(flags);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[5]));
}
/*
* Implementation of the "read" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] boot-opened file descriptor
* args[4] client's buffer
* args[5] size of read request
* args[6] Res0: returned result
*
*/
int
bop_read(struct bootops *bop, int fd, caddr_t buf, size_t size)
{
boot_cell_t args[7];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("read");
args[1] = 3;
args[2] = 1;
args[3] = boot_int2cell(fd);
args[4] = boot_ptr2cell(buf);
args[5] = boot_uint2cell(size);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[6]));
}
/*
* Implementation of the "seek" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] boot-opened file descriptor
* args[4] offset hi XXX just use one cell for offset?
* args[5] offset lo
* args[6] Res0: returned result
*/
int
bop_seek(struct bootops *bop, int fd, off_t hi, off_t lo)
{
boot_cell_t args[7];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("seek");
args[1] = 3;
args[2] = 1;
args[3] = boot_int2cell(fd);
args[4] = boot_offt2cell(hi);
args[5] = boot_offt2cell(lo);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[6]));
}
/*
* Implementation of the "close" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] boot-opened file descriptor
* args[4] Res0: returned result
*/
int
bop_close(struct bootops *bop, int fd)
{
boot_cell_t args[5];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("close");
args[1] = 1;
args[2] = 1;
args[3] = boot_int2cell(fd);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[4]));
}
/*
* Implementation of the "alloc" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] virtual hint
* args[4] size to allocate
* args[5] alignment
* args[6] Res0: returned result
*/
caddr_t
bop_alloc(struct bootops *bop, caddr_t virthint, size_t size, int align)
{
boot_cell_t args[7];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("alloc");
args[1] = 3;
args[2] = 1;
args[3] = boot_ptr2cell(virthint);
args[4] = boot_size2cell(size);
args[5] = boot_int2cell(align);
(void) (bsys_1275_call)(args);
return ((caddr_t)(uintptr_t)boot_ptr2cell((uintptr_t)args[6]));
}
/*
* Implementation of the "alloc_virt" boot service
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] virtual address
* args[4] size to allocate
* args[5] Resi: returned result
*/
caddr_t
bop_alloc_virt(struct bootops *bop, caddr_t virt, size_t size)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("alloc_virt");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(virt);
args[4] = boot_size2cell(size);
(void) (bsys_1275_call)(args);
return ((caddr_t)(uintptr_t)boot_ptr2cell((uintptr_t)args[5]));
}
/*
* Implementation of the "free" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] virtual hint
* args[4] size to free
* args[5] Res0: returned result
*/
/*ARGSUSED*/
void
bop_free(struct bootops *bop, caddr_t virt, size_t size)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("free");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(virt);
args[4] = boot_size2cell(size);
(void) (bsys_1275_call)(args);
}
/*
* Implementation of the "map" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] virtual address
* args[4] space of phys addr
* args[5] phys addr
* args[6] size
* args[7] Res0: returned result
*/
/*ARGSUSED*/
caddr_t
bop_map(struct bootops *bop, caddr_t virt, int space,
caddr_t phys, size_t size)
{
boot_cell_t args[8];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("map");
args[1] = 3;
args[2] = 1;
args[3] = boot_ptr2cell(virt);
args[4] = boot_int2cell(space);
args[5] = boot_ptr2cell(phys);
args[6] = boot_size2cell(size);
(void) (bsys_1275_call)(args);
return ((caddr_t)boot_cell2ptr(args[7]));
}
/*
* Implementation of the "unmap" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] virtual address
* args[4] size of chunk
* args[5] Res0: returned result
*/
/*ARGSUSED*/
void
bop_unmap(struct bootops *bop, caddr_t virt, size_t size)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("unmap");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(virt);
args[4] = boot_size2cell(size);
(void) (bsys_1275_call)(args);
}
/*
* Implementation of the "quiesce" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] Res0: returned result
*/
/*ARGSUSED*/
void
bop_quiesce_io(struct bootops *bop)
{
boot_cell_t args[4];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("quiesce");
args[1] = 0;
args[2] = 1;
(void) (bsys_1275_call)(args);
}
/*
* Implementation of the "getproplen" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] property name string
* args[4] Res0: returned result
*/
/*ARGSUSED*/
int
bop_getproplen(struct bootops *bop, char *name)
{
boot_cell_t args[7];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("getproplen");
args[1] = 1;
args[2] = 1;
args[3] = boot_ptr2cell(name);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[4]));
}
/*
* Implementation of the "getprop" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] property name string
* args[4] buffer pointer to hold value of the property
* args[5] Res0: returned result
*/
/*ARGSUSED*/
int
bop_getprop(struct bootops *bop, char *name, void *value)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("getprop");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(name);
args[4] = boot_ptr2cell(value);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[5]));
}
/*
* Implementation of the "nextprop" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] previous property name string
* args[4] Res0: returned result
*/
/*ARGSUSED*/
char *
bop_nextprop(struct bootops *bop, char *prevprop)
{
boot_cell_t args[5];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("nextprop");
args[1] = 1;
args[2] = 1;
args[3] = boot_ptr2cell(prevprop);
(void) (bsys_1275_call)(args);
return ((char *)boot_cell2ptr(args[4]));
}
/*
* Implementation of the "puts" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] string to print
*/
/*ARGSUSED*/
void
bop_puts(struct bootops *bop, char *string)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
void (*bsys_printf)(struct bootops *, char *, ...);
/* so new kernel, old boot can print a message before dying */
if (!BOOTOPS_ARE_1275(bop)) {
/* use uintptr_t to suppress the gcc warning */
bsys_printf = (void (*)(struct bootops *, char *, ...))
(uintptr_t)bop->bsys_printf;
(*bsys_printf)(bop, string);
return;
}
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("puts");
args[1] = 1;
args[2] = 0;
args[3] = boot_ptr2cell(string);
(void) (bsys_1275_call)(args);
}
/*
* Implementation of the "putsarg" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] string to print (with '%*' format)
* args[4] 64-bit thing to print
*/
/*ARGSUSED*/
void
bop_putsarg(struct bootops *bop, const char *string, ...)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
void (*bsys_printf)(struct bootops *, char *, ...);
va_list ap;
const char *fmt = string;
int ells = 0;
uint64_t arg;
/*
* We need to do the minimum printf-like stuff here to figure
* out the size of argument, if present.
*/
while (*fmt) {
if (*fmt++ != '%')
continue;
if (*fmt == '%') {
fmt++;
continue;
}
while (*fmt >= '0' && *fmt <= '9')
fmt++;
for (ells = 0; *fmt == 'l'; fmt++)
ells++;
va_start(ap, string);
switch (*fmt) {
case 's':
/* use uintptr_t to suppress the gcc warning */
arg = (uint64_t)(uintptr_t)va_arg(ap, char *);
break;
case 'p':
arg = (uint64_t)(uintptr_t)va_arg(ap, void *);
break;
case 'd':
case 'D':
case 'x':
case 'X':
case 'u':
case 'U':
case 'o':
case 'O':
if (ells == 0)
arg = (uint64_t)va_arg(ap, uint_t);
else if (ells == 1)
arg = (uint64_t)va_arg(ap, ulong_t);
else
arg = (uint64_t)va_arg(ap, uint64_t);
break;
default:
arg = (uint64_t)va_arg(ap, uint_t);
break;
}
va_end(ap);
break;
}
/* so new kernel, old boot can print a message before dying */
if (!BOOTOPS_ARE_1275(bop)) {
/* use uintptr_t to suppress the gcc warning */
bsys_printf = (void (*)(struct bootops *, char *, ...))
(uintptr_t)bop->bsys_printf;
(*bsys_printf)(bop, (char *)string, arg);
return;
}
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("putsarg");
args[1] = 2;
args[2] = 0;
args[3] = boot_ptr2cell(string);
args[4] = boot_uint642cell(arg);
(void) (bsys_1275_call)(args);
}
/*
* Implementation of the "mount" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] pathname string
* args[4] Res0: returned result
*/
/*ARGSUSED*/
int
bop_mountroot(struct bootops *bop, char *path)
{
boot_cell_t args[5];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("mountroot");
args[1] = 2;
args[2] = 1;
args[3] = boot_ptr2cell(path);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[4]));
}
/*
* Implementation of the "unmountroot" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] Res0: returned result
*/
/*ARGSUSED*/
int
bop_unmountroot(struct bootops *bop)
{
boot_cell_t args[4];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("unmountroot");
args[1] = 0;
args[2] = 1;
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[3]));
}
/*
* Implementation of the "serviceavail" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] name string of service to be tested for
* args[4] Res0: returned version number or 0
*/
/*ARGSUSED*/
int
bop_serviceavail(struct bootops *bop, char *name)
{
/* use uintptr_t to suppress the gcc warning */
boot_cell_t args[5];
int (*bsys_1275_call)(void *) =
(int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("serviceavail");
args[1] = 1;
args[2] = 1;
args[3] = boot_ptr2cell(name);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[4]));
}
/*
* Implementation of the "fstat" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells
* args[2] #result cells
* args[3] fd
* args[4] client's stat structure
*/
int
bop_fstat(struct bootops *bop, int fd, struct bootstat *st)
{
boot_cell_t args[6];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("fstat");
args[1] = 2;
args[2] = 1;
args[3] = boot_int2cell(fd);
args[4] = boot_ptr2cell(st);
(void) (bsys_1275_call)(args);
return (boot_cell2int(args[5]));
}
/*
* Implementation of the "enter_mon" boot service.
*
* Calling spec:
* args[0] Service name string
* args[1] #argument cells (0)
* args[2] #result cells (0)
*/
void
bop_enter_mon(struct bootops *bop)
{
boot_cell_t args[4];
int (*bsys_1275_call)(void *);
/* use uintptr_t to suppress the gcc warning */
bsys_1275_call = (int (*)(void *))(uintptr_t)bop->bsys_1275_call;
args[0] = boot_ptr2cell("enter_mon");
args[1] = 0;
args[2] = 0;
(void) (bsys_1275_call)(args);
}
|