Home | History | Annotate | Line # | Download | only in common
raw.c revision 1.2.70.1
      1  1.2.70.1  thorpej /*	$NetBSD: raw.c,v 1.2.70.1 2021/08/01 22:42:06 thorpej Exp $	*/
      2       1.1    pooka 
      3       1.1    pooka /*-
      4       1.1    pooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5       1.1    pooka  * All rights reserved.
      6       1.1    pooka  *
      7       1.1    pooka  * This code was written by Alessandro Forin and Neil Pittman
      8       1.1    pooka  * at Microsoft Research and contributed to The NetBSD Foundation
      9       1.1    pooka  * by Microsoft Corporation.
     10       1.1    pooka  *
     11       1.1    pooka  * Redistribution and use in source and binary forms, with or without
     12       1.1    pooka  * modification, are permitted provided that the following conditions
     13       1.1    pooka  * are met:
     14       1.1    pooka  * 1. Redistributions of source code must retain the above copyright
     15       1.1    pooka  *    notice, this list of conditions and the following disclaimer.
     16       1.1    pooka  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1    pooka  *    notice, this list of conditions and the following disclaimer in the
     18       1.1    pooka  *    documentation and/or other materials provided with the distribution.
     19       1.1    pooka  *
     20       1.1    pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21       1.1    pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22       1.1    pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23       1.1    pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24       1.1    pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25       1.1    pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26       1.1    pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27       1.1    pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28       1.1    pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29       1.1    pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.1    pooka  * POSSIBILITY OF SUCH DAMAGE.
     31       1.1    pooka  */
     32       1.1    pooka 
     33       1.1    pooka #include <lib/libsa/stand.h>
     34       1.1    pooka #include <lib/libkern/libkern.h>
     35       1.1    pooka #include <machine/emipsreg.h>
     36       1.1    pooka 
     37       1.1    pooka #include <sys/param.h>
     38       1.1    pooka #include <sys/disklabel.h>
     39       1.1    pooka #include <sys/endian.h>
     40       1.1    pooka 
     41       1.1    pooka #include "common.h"
     42       1.1    pooka #include "raw.h"
     43       1.1    pooka #include "ace.h"
     44       1.1    pooka 
     45       1.1    pooka /* Used to parse strings of the form "a0/99/badface" all hex
     46       1.1    pooka  */
     47       1.1    pooka 
     48       1.1    pooka static inline int hexnum(char c)
     49       1.1    pooka {
     50       1.1    pooka     if (c >= '0' && c <= '9')
     51       1.1    pooka         return c - '0';
     52       1.1    pooka     if (c >= 'a' && c <= 'f')
     53       1.1    pooka         return c - 'a';
     54       1.1    pooka     if (c >= 'A' && c <= 'F')
     55       1.1    pooka         return c - 'A';
     56       1.1    pooka     return -1;
     57       1.1    pooka }
     58       1.1    pooka 
     59       1.1    pooka static char *getxnum(char *s, uint32_t *dest)
     60       1.1    pooka {
     61       1.1    pooka     uint32_t u = 0;
     62       1.1    pooka     char c;
     63       1.1    pooka     int v = -1;
     64       1.1    pooka 
     65       1.1    pooka     if ((c = *s++) == '/')
     66       1.1    pooka         c = *s++;
     67       1.1    pooka     while (c && c != '/') {
     68       1.1    pooka         v = hexnum(c);
     69       1.1    pooka         if (v < 0)
     70       1.1    pooka             break;
     71       1.1    pooka         u = (u << 4) + v;
     72       1.1    pooka         c = *s++;
     73       1.1    pooka     }
     74       1.1    pooka     /* did we get any */
     75       1.1    pooka     if (v < 0)
     76       1.1    pooka         return NULL;
     77       1.1    pooka     *dest = u;
     78       1.1    pooka     return s-1;
     79       1.1    pooka }
     80       1.1    pooka 
     81       1.1    pooka /* rawopen("", ctlr, unit, part);
     82       1.1    pooka  */
     83       1.1    pooka int
     84       1.1    pooka rawopen(struct open_file *f, ...)
     85       1.1    pooka {
     86       1.1    pooka 	int ctlr, unit, part;
     87       1.1    pooka     char *file, *cp;
     88       1.1    pooka 	uint32_t start_sector, sector_count, load_address;
     89       1.1    pooka     int er;
     90       1.1    pooka 	size_t cnt;
     91       1.1    pooka 	va_list ap;
     92       1.1    pooka 
     93       1.1    pooka 	va_start(ap, f);
     94       1.1    pooka 
     95       1.1    pooka 	ctlr = va_arg(ap, int);
     96       1.1    pooka 	unit = va_arg(ap, int);
     97       1.1    pooka 	part = va_arg(ap, int);
     98       1.1    pooka     file = va_arg(ap, char *);
     99       1.1    pooka 	va_end(ap);
    100       1.1    pooka 
    101       1.1    pooka     /* See if we have that controller */
    102       1.1    pooka     er = aceopen(f,ctlr,unit,part);
    103       1.1    pooka     if (er != 0)
    104       1.1    pooka         return er;
    105       1.1    pooka 
    106       1.1    pooka     /* The string in FILE must tell us three things.. */
    107       1.1    pooka     cp = file;
    108       1.1    pooka     cp = getxnum(cp,&start_sector);
    109       1.1    pooka     if (cp == NULL) goto Bad;
    110       1.1    pooka     cp = getxnum(cp,&sector_count);
    111       1.1    pooka     if (cp == NULL) goto Bad;
    112       1.1    pooka     cp = getxnum(cp,&load_address);
    113       1.1    pooka     if (cp == NULL) goto Bad;
    114       1.1    pooka 
    115       1.1    pooka     //printf("%s -> %u %u %p\n", file, start_sector, sector_count, load_address);
    116       1.1    pooka 
    117       1.1    pooka     /* Read them sectors */
    118       1.1    pooka     er = acestrategy(f->f_devdata, F_READ, start_sector, DEV_BSIZE * sector_count,
    119       1.1    pooka                      (void *) load_address, &cnt);
    120       1.1    pooka #ifndef LIBSA_NO_DEV_CLOSE
    121       1.1    pooka     /* regardless, close the disk */
    122       1.1    pooka     aceclose(f);
    123       1.1    pooka #endif
    124       1.1    pooka     /* How did it go, are we still alive */
    125       1.1    pooka     if (er != 0)
    126       1.1    pooka         return er;
    127       1.1    pooka 
    128       1.1    pooka     /* Ok, say it and do it then. */
    129       1.1    pooka     printf("Read %u sectors from sector %u at %x, jumping to it..\n",
    130       1.1    pooka            sector_count, start_sector, load_address);
    131       1.1    pooka 
    132       1.1    pooka     call_kernel(load_address,"raw","",0,NULL);
    133       1.1    pooka 
    134       1.1    pooka  Bad:
    135       1.1    pooka #ifndef LIBSA_NO_DEV_CLOSE
    136       1.1    pooka     /* regardless, close it */
    137       1.1    pooka     aceclose(f);
    138       1.1    pooka #endif
    139       1.1    pooka     return (ENXIO);
    140       1.1    pooka }
    141       1.1    pooka 
    142       1.1    pooka #ifndef LIBSA_NO_DEV_CLOSE
    143       1.1    pooka int
    144       1.1    pooka rawclose(struct open_file *f)
    145       1.1    pooka {
    146       1.1    pooka     /* Never gets here */
    147       1.1    pooka 	return (0);
    148       1.1    pooka }
    149       1.1    pooka #endif
    150       1.1    pooka 
    151       1.1    pooka int
    152       1.1    pooka rawstrategy(
    153       1.1    pooka 	void *devdata,
    154       1.1    pooka 	int rw,
    155       1.1    pooka 	daddr_t bn,
    156       1.1    pooka 	size_t reqcnt,
    157       1.1    pooka 	void *addr,
    158  1.2.70.1  thorpej 	size_t *cnt)	/* out: number of bytes transferred */
    159       1.1    pooka {
    160       1.1    pooka     /* Never gets here */
    161       1.1    pooka     return (EIO);
    162       1.1    pooka }
    163       1.1    pooka 
    164