* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: prom_file.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* Copyright (c) 2001-2003 Sun Microsystems, Inc.
* Use is subject to license terms.
#pragma ident "@(#)prom_file.c 1.1 01/04/19 SMI"
#include <sys/promimpl.h>
typedef struct DEBLOCK_T
{
uchar_t buffer
[BLOCKSIZE
];
* this counts on the fact that the standalone program was boot disked rather
* than boot netted. (ufs-file-system package is already loaded)
* By the way, isn't ufs-file-system redundant?
loadfile(ihandle_t instance
, uint32_t addr
)
ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
ci
[1] = (cell_t
)3; /* #argument cells */
ci
[2] = (cell_t
)2; /* #result cells */
ci
[3] = p1275_ptr2cell("load"); /* Arg1: method name */
ci
[4] = p1275_ihandle2cell(instance
); /* Arg2:SA1:dev-node ihandle */
ci
[5] = p1275_int2cell(addr
); /* Arg3: SA2: load-addr */
retval
= p1275_cif_handler(&ci
);
if (ci
[6] != 0) /* Res1: Catch result */
return ((void *)ci
[7]); /* Res2: virt addr */
filesize(ihandle_t instance
)
ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
ci
[1] = (cell_t
)2; /* #argument cells */
ci
[2] = (cell_t
)3; /* #result cells */
ci
[3] = p1275_ptr2cell("size"); /* Arg1: method name */
ci
[4] = p1275_ihandle2cell(instance
); /* Arg2:SA1:dev-node ihandle */
retval
= p1275_cif_handler(&ci
);
if (ci
[5] != 0) /* Res1: Catch result */
return ((long)ci
[7]); /* Res3: file size */
fileseek(ihandle_t instance
, int32_t offset
)
* Note that the order of the args passed in (after the ihandle)
* is being reversed so that when they are popped onto the forth
* stack they will be in the correct order for seeking
* ( offset whence -- error? )
ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
ci
[1] = (cell_t
)4; /* #argument cells */
ci
[2] = (cell_t
)2; /* #result cells */
ci
[3] = p1275_ptr2cell("seek"); /* Arg1: method name */
ci
[4] = p1275_ihandle2cell(instance
); /* Arg2:SA1:dev-node ihandle */
ci
[5] = p1275_int2cell(0); /* Arg3: SA3: whence */
ci
[6] = p1275_int2cell(offset
); /* Arg4: SA2: offset */
retval
= p1275_cif_handler(&ci
);
if (ci
[7] != 0) /* Res1: Catch result */
return (ci
[8]); /* Res2: error? */
fileread(ihandle_t instance
, uchar_t
*addr
, int32_t len
)
* Note that the order of the args passed in (after the ihandle)
* is being reversed so that when they are popped onto the forth
* stack they will be in the correct order for reading
* ( addr len -- act-len )
ci
[0] = p1275_ptr2cell("call-method"); /* Service name */
ci
[1] = (cell_t
)4; /* #argument cells */
ci
[2] = (cell_t
)2; /* #result cells */
ci
[3] = p1275_ptr2cell("read"); /* Arg1: method name */
ci
[4] = p1275_ihandle2cell(instance
); /* Arg2:SA1:dev-node ihandle */
ci
[5] = p1275_int2cell(len
); /* Arg3: SA3: length */
ci
[6] = p1275_int2cell(addr
); /* Arg4: SA2: addr */
retval
= p1275_cif_handler(&ci
);
if (ci
[7] != 0) /* Res1: Catch result */
return (ci
[8]); /* Res2: actual len */
/* it's always read/write */
fopen(char const *filename
, char const *mode
)
prom_strcpy(ext_filename
, "disk:,");
filename
= "|platform|platforms.di";
prom_strcat(ext_filename
, (caddr_t
)filename
);
if ((ihandle
= prom_open(ext_filename
)) == NULL
)
prom_printf("thisfile %x\n", thisfile
);
prom_printf("ihandle %x\n", ihandle
);
thisfile
.size
= filesize(ihandle
);
thisfile
.ihandle
= ihandle
;
thisfile
.deblock
.start
= -1; /* nothing read */
printf("filesize = %i\n", thisfile
.size
);
return (prom_close(stream
->ihandle
));
fseek(FILE *stream
, long offset
, int32_t whence
)
stream
->currentpos
= 0 + offset
;
stream
->currentpos
+= offset
;
/* Unix allows going off the end of a stream! */
stream
->currentpos
= stream
->size
+ offset
;
return (fileseek(stream
->ihandle
, stream
->currentpos
));
return (stream
->currentpos
);
min(int32_t a
, int32_t b
)
/* I should buffer this */
long file_end
= stream
->size
;
long position
= stream
->currentpos
;
long size
= min((stream
->size
- position
), BLOCKSIZE
);
uchar_t
*buffer
= stream
->deblock
.buffer
;
if (position
>= file_end
)
if ((position
< stream
->deblock
.start
) ||
(position
>= stream
->deblock
.start
+ stream
->deblock
.blocksize
) ||
(stream
->deblock
.start
== -1)) {
stream
->deblock
.start
= position
;
stream
->deblock
.blocksize
= size
;
if ((fileread(stream
->ihandle
, buffer
, size
)) != size
)
return ((int32_t)buffer
[stream
->currentpos
++ - stream
->deblock
.start
]);