xref: /openbsd-src/sys/arch/landisk/stand/boot/devs.c (revision a4f11372d5ec16405c3947a49e9200b89358d82d)
1 /*	$OpenBSD: devs.c,v 1.13 2023/02/23 19:48:22 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
16  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <sys/param.h>
21 #include <libsa.h>
22 #include <lib/libsa/loadfile.h>
23 
24 int sector;
25 
26 void
machdep(void)27 machdep(void)
28 {
29 	tick_init();
30 	cninit();
31 }
32 
33 int
devopen(struct open_file * f,const char * fname,char ** file)34 devopen(struct open_file *f, const char *fname, char **file)
35 {
36 	if (fname[0] != 'c' || fname[1] != 'f' || fname[2] != ':')
37 		return EINVAL;
38 
39 	*file = (char *)fname + 3;
40 	f->f_flags |= F_NODEV;
41 	f->f_dev = &devsw[0];
42 	return (0);
43 }
44 
45 void
devboot(dev_t bootdev,char * p)46 devboot(dev_t bootdev, char *p)
47 {
48 	sector = bootdev;	/* passed from pbr */
49 	p[0] = 'c';
50 	p[1] = 'f';
51 	p[2] = '\0';
52 }
53 
54 void
run_loadfile(uint64_t * marks,int howto)55 run_loadfile(uint64_t *marks, int howto)
56 {
57 	u_long entry;
58 
59 	entry = marks[MARK_ENTRY];
60 	cache_flush();
61 	cache_disable();
62 
63 	(*(void (*)(int,int,int))entry)(howto, marks[MARK_END], 0);
64 }
65 
66 int
blkdevopen(struct open_file * f,...)67 blkdevopen(struct open_file *f, ...)
68 {
69 	return 0;
70 }
71 
72 int
blkdevstrategy(void * v,int flag,daddr_t dblk,size_t size,void * buf,size_t * rsize)73 blkdevstrategy(void *v, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize)
74 {
75 
76 	if (flag != F_READ)
77 		return EROFS;
78 
79 	if (size & (DEV_BSIZE - 1))
80 		return EINVAL;
81 
82 	if (rsize)
83 		*rsize = size;
84 
85 	if (size != 0 && readsects(0x40, sector + dblk, buf,
86 	    size / DEV_BSIZE) != 0)
87 		return EIO;
88 
89 	return 0;
90 }
91 
92 int
blkdevclose(struct open_file * f)93 blkdevclose(struct open_file *f)
94 {
95 	return 0;
96 }
97