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