summaryrefslogtreecommitdiffstats
path: root/sys/boot/common
diff options
context:
space:
mode:
Diffstat (limited to 'sys/boot/common')
-rw-r--r--sys/boot/common/bcache.c31
-rw-r--r--sys/boot/common/boot.c19
-rw-r--r--sys/boot/common/bootstrap.h92
-rw-r--r--sys/boot/common/interp.c36
-rw-r--r--sys/boot/common/interp_backslash.c1
-rw-r--r--sys/boot/common/interp_forth.c2
-rw-r--r--sys/boot/common/interp_parse.c18
-rw-r--r--sys/boot/common/isapnp.c27
-rw-r--r--sys/boot/common/load_aout.c21
-rw-r--r--sys/boot/common/load_elf.c44
-rw-r--r--sys/boot/common/module.c4
-rw-r--r--sys/boot/common/pnp.c2
12 files changed, 135 insertions, 162 deletions
diff --git a/sys/boot/common/bcache.c b/sys/boot/common/bcache.c
index efdcbe0..e99a677 100644
--- a/sys/boot/common/bcache.c
+++ b/sys/boot/common/bcache.c
@@ -57,11 +57,11 @@ struct bcachectl
static struct bcachectl *bcache_ctl;
static caddr_t bcache_data;
static bitstr_t *bcache_miss;
-static int bcache_nblks;
-static int bcache_blksize;
-static int bcache_hits, bcache_misses, bcache_ops, bcache_bypasses;
-static int bcache_flushes;
-static int bcache_bcount;
+static u_int bcache_nblks;
+static u_int bcache_blksize;
+static u_int bcache_hits, bcache_misses, bcache_ops, bcache_bypasses;
+static u_int bcache_flushes;
+static u_int bcache_bcount;
static void bcache_insert(caddr_t buf, daddr_t blkno);
static int bcache_lookup(caddr_t buf, daddr_t blkno);
@@ -70,7 +70,7 @@ static int bcache_lookup(caddr_t buf, daddr_t blkno);
* Initialise the cache for (nblks) of (bsize).
*/
int
-bcache_init(int nblks, size_t bsize)
+bcache_init(u_int nblks, size_t bsize)
{
/* discard any old contents */
if (bcache_data != NULL) {
@@ -103,9 +103,9 @@ bcache_init(int nblks, size_t bsize)
* Flush the cache
*/
void
-bcache_flush()
+bcache_flush(void)
{
- int i;
+ u_int i;
bcache_flushes++;
@@ -125,14 +125,14 @@ bcache_flush()
* directly to the disk. XXX tune this.
*/
int
-bcache_strategy(void *devdata, int unit, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize)
+bcache_strategy(void *devdata, int unit, int rw, daddr_t blk, size_t size,
+ char *buf, size_t *rsize)
{
static int bcache_unit = -1;
struct bcache_devdata *dd = (struct bcache_devdata *)devdata;
- int nblk, p_size;
- daddr_t p_blk;
+ int p_size, result;
+ daddr_t p_blk, i, j, nblk;
caddr_t p_buf;
- int i, j, result;
bcache_ops++;
@@ -211,7 +211,8 @@ static void
bcache_insert(caddr_t buf, daddr_t blkno)
{
time_t now;
- int i, cand, ocount;
+ int cand, ocount;
+ u_int i;
time(&now);
cand = 0; /* assume the first block */
@@ -246,7 +247,7 @@ static int
bcache_lookup(caddr_t buf, daddr_t blkno)
{
time_t now;
- int i;
+ u_int i;
time(&now);
@@ -265,7 +266,7 @@ COMMAND_SET(bcachestat, "bcachestat", "get disk block cache stats", command_bcac
static int
command_bcache(int argc, char *argv[])
{
- int i;
+ u_int i;
for (i = 0; i < bcache_nblks; i++) {
printf("%08x %04x %04x|", bcache_ctl[i].bc_blkno, (unsigned int)bcache_ctl[i].bc_stamp & 0xffff, bcache_ctl[i].bc_count & 0xffff);
diff --git a/sys/boot/common/boot.c b/sys/boot/common/boot.c
index 7c02e56..ae3cb77 100644
--- a/sys/boot/common/boot.c
+++ b/sys/boot/common/boot.c
@@ -38,7 +38,7 @@
static char *getbootfile(int try);
/* List of kernel names to try (may be overwritten by boot.config) XXX should move from here? */
-static char *default_bootfiles = "kernel;kernel.old";
+static const char *default_bootfiles = "kernel;kernel.old";
static int autoboot_tried;
@@ -53,7 +53,6 @@ command_boot(int argc, char *argv[])
struct preloaded_file *fp;
char *cp;
int try;
- int i;
/*
* See if the user has specified an explicit kernel to boot.
@@ -164,7 +163,7 @@ autoboot_maybe()
}
int
-autoboot(int delay, char *prompt)
+autoboot(int timeout, char *prompt)
{
time_t when, otime, ntime;
int c, yes;
@@ -172,19 +171,19 @@ autoboot(int delay, char *prompt)
autoboot_tried = 1;
- if (delay == -1) {
+ if (timeout == -1) {
/* try to get a delay from the environment */
if ((cp = getenv("autoboot_delay"))) {
- delay = strtol(cp, &ep, 0);
+ timeout = strtol(cp, &ep, 0);
if (cp == ep)
- delay = -1;
+ timeout = -1;
}
}
- if (delay == -1) /* all else fails */
- delay = 10;
+ if (timeout == -1) /* all else fails */
+ timeout = 10;
otime = time(NULL);
- when = otime + delay; /* when to boot */
+ when = otime + timeout; /* when to boot */
yes = 0;
/* XXX could try to work out what we might boot */
@@ -228,7 +227,7 @@ getbootfile(int try)
{
static char *name = NULL;
char *spec, *ep;
- int len;
+ size_t len;
/* we use dynamic storage */
if (name != NULL) {
diff --git a/sys/boot/common/bootstrap.h b/sys/boot/common/bootstrap.h
index 67ca502..31ac87a 100644
--- a/sys/boot/common/bootstrap.h
+++ b/sys/boot/common/bootstrap.h
@@ -29,10 +29,6 @@
#include <sys/types.h>
#include <sys/queue.h>
-/* XXX debugging */
-extern struct console vidconsole;
-#define MARK(s, c) {vidconsole.c_out(s); vidconsole.c_out(c); while (!vidconsole.c_ready()) ; vidconsole.c_in();}
-
/*
* Generic device specifier; architecture-dependant
* versions may be larger, but should be allowed to
@@ -55,37 +51,42 @@ extern char command_errbuf[]; /* XXX blah, length */
#define CMD_ERROR 1
/* interp.c */
-extern void interact(void);
-extern int include(char *filename);
+void interact(void);
+int include(const char *filename);
+
+/* interp_backslash.c */
+char *backslash(char *str);
/* interp_parse.c */
-extern int parse(int *argc, char ***argv, char *str);
+int parse(int *argc, char ***argv, char *str);
/* interp_forth.c */
-extern void bf_init(void);
-extern int bf_run(char *line);
+void bf_init(void);
+int bf_run(char *line);
/* boot.c */
-extern int autoboot(int delay, char *prompt);
-extern void autoboot_maybe(void);
-extern int getrootmount(char *rootdev);
+int autoboot(int timeout, char *prompt);
+void autoboot_maybe(void);
+int getrootmount(char *rootdev);
/* misc.c */
-extern char *unargv(int argc, char *argv[]);
-extern void hexdump(caddr_t region, size_t len);
-extern size_t strlenout(vm_offset_t str);
-extern char *strdupout(vm_offset_t str);
+char *unargv(int argc, char *argv[]);
+void hexdump(caddr_t region, size_t len);
+size_t strlenout(vm_offset_t str);
+char *strdupout(vm_offset_t str);
/* bcache.c */
-extern int bcache_init(int nblks, size_t bsize);
-extern void bcache_flush();
+int bcache_init(u_int nblks, size_t bsize);
+void bcache_flush(void);
+int bcache_strategy(void *devdata, int unit, int rw, daddr_t blk,
+ size_t size, char *buf, size_t *rsize);
/*
* Disk block cache
*/
struct bcache_devdata
{
- int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, void *buf, size_t *rsize);
+ int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, char *buf, size_t *rsize);
void *dv_devdata;
};
@@ -94,8 +95,8 @@ struct bcache_devdata
*/
struct console
{
- char *c_name;
- char *c_desc;
+ const char *c_name;
+ const char *c_desc;
int c_flags;
#define C_PRESENTIN (1<<0)
#define C_PRESENTOUT (1<<1)
@@ -108,14 +109,14 @@ struct console
int (* c_ready)(void); /* return nonzer if input waiting */
};
extern struct console *consoles[];
-extern void cons_probe(void);
+void cons_probe(void);
/*
* Plug-and-play enumerator/configurator interface.
*/
struct pnphandler
{
- char *pp_name; /* handler/bus name */
+ const char *pp_name; /* handler/bus name */
void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
};
@@ -139,11 +140,11 @@ struct pnpinfo
extern struct pnphandler *pnphandlers[]; /* provided by MD code */
-extern void pnp_addident(struct pnpinfo *pi, char *ident);
-extern struct pnpinfo *pnp_allocinfo(void);
-extern void pnp_freeinfo(struct pnpinfo *pi);
-extern void pnp_addinfo(struct pnpinfo *pi);
-extern char *pnp_eisaformat(u_int8_t *data);
+void pnp_addident(struct pnpinfo *pi, char *ident);
+struct pnpinfo *pnp_allocinfo(void);
+void pnp_freeinfo(struct pnpinfo *pi);
+void pnp_addinfo(struct pnpinfo *pi);
+char *pnp_eisaformat(u_int8_t *data);
/*
* < 0 - No ISA in system
@@ -163,7 +164,7 @@ struct file_metadata
size_t md_size;
u_int16_t md_type;
struct file_metadata *md_next;
- char md_data[0]; /* data are immediately appended */
+ char md_data[1]; /* data are immediately appended */
};
struct preloaded_file;
@@ -209,8 +210,8 @@ struct file_format
extern struct file_format *file_formats[]; /* supplied by consumer */
extern struct preloaded_file *preloaded_files;
-extern int mod_load(char *name, int argc, char *argv[]);
-extern int mod_loadobj(char *type, char *name);
+int mod_load(char *name, int argc, char *argv[]);
+int mod_loadobj(char *type, char *name);
struct preloaded_file *file_alloc(void);
struct preloaded_file *file_findfile(char *name, char *type);
@@ -222,10 +223,10 @@ int file_addmodule(struct preloaded_file *fp, char *modname,
/* MI module loaders */
-extern int aout_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
-extern vm_offset_t aout_findsym(char *name, struct preloaded_file *fp);
+int aout_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
+vm_offset_t aout_findsym(char *name, struct preloaded_file *fp);
-extern int elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
+int elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result);
#ifndef NEW_LINKER_SET
#include <sys/linker_set.h>
@@ -284,7 +285,7 @@ struct bootblk_command
#define COMMAND_SET(tag, key, desc, func) \
static bootblk_cmd_t func; \
static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
- DATA_SET(Xcommand_set, _cmd_ ## tag);
+ DATA_SET(Xcommand_set, _cmd_ ## tag)
extern struct linker_set Xcommand_set;
@@ -297,22 +298,25 @@ extern struct linker_set Xcommand_set;
struct arch_switch
{
/* Automatically load modules as required by detected hardware */
- int (* arch_autoload)();
+ int (*arch_autoload)(void);
/* Locate the device for (name), return pointer to tail in (*path) */
- int (*arch_getdev)(void **dev, const char *name, const char **path);
+ int (*arch_getdev)(void **dev, const char *name, const char **path);
/* Copy from local address space to module address space, similar to bcopy() */
- int (*arch_copyin)(void *src, vm_offset_t dest, size_t len);
+ ssize_t (*arch_copyin)(const void *src, vm_offset_t dest,
+ const size_t len);
/* Copy to local address space from module address space, similar to bcopy() */
- int (*arch_copyout)(vm_offset_t src, void *dest, size_t len);
+ ssize_t (*arch_copyout)(const vm_offset_t src, void *dest,
+ const size_t len);
/* Read from file to module address space, same semantics as read() */
- int (*arch_readin)(int fd, vm_offset_t dest, size_t len);
+ ssize_t (*arch_readin)(const int fd, vm_offset_t dest,
+ const size_t len);
/* Perform ISA byte port I/O (only for systems with ISA) */
- int (*arch_isainb)(int port);
- void (*arch_isaoutb)(int port, int value);
+ int (*arch_isainb)(int port);
+ void (*arch_isaoutb)(int port, int value);
};
extern struct arch_switch archsw;
/* This must be provided by the MD code, but should it be in the archsw? */
-extern void delay(int delay);
+void delay(int delay);
-extern void dev_cleanup(void);
+void dev_cleanup(void);
diff --git a/sys/boot/common/interp.c b/sys/boot/common/interp.c
index ab0cf25..4349920 100644
--- a/sys/boot/common/interp.c
+++ b/sys/boot/common/interp.c
@@ -49,38 +49,6 @@ extern FICL_VM *bf_vm;
static void prompt(void);
/*
- * Perform the command
- */
-int
-perform(int argc, char *argv[])
-{
- int result;
- struct bootblk_command **cmdp;
- bootblk_cmd_t *cmd;
-
- if (argc < 1)
- return(CMD_OK);
-
- /* set return defaults; a successful command will override these */
- command_errmsg = command_errbuf;
- strcpy(command_errbuf, "no error message");
- cmd = NULL;
- result = CMD_ERROR;
-
- /* search the command set for the command */
- SET_FOREACH(cmdp, Xcommand_set) {
- if (((*cmdp)->c_name != NULL) && !strcmp(argv[0], (*cmdp)->c_name))
- cmd = (*cmdp)->c_fn;
- }
- if (cmd != NULL) {
- result = (cmd)(argc, argv);
- } else {
- command_errmsg = "unknown command";
- }
- RETURN(result);
-}
-
-/*
* Interactive mode
*/
void
@@ -157,7 +125,7 @@ command_include(int argc, char *argv[])
/*
* Since argv is static, we need to save it here.
*/
- argvbuf = (char**) calloc(argc, sizeof(char*));
+ argvbuf = (char**) calloc((u_int)argc, sizeof(char*));
for (i = 0; i < argc; i++)
argvbuf[i] = strdup(argv[i]);
@@ -183,7 +151,7 @@ struct includeline
};
int
-include(char *filename)
+include(const char *filename)
{
struct includeline *script, *se, *sp;
char input[256]; /* big enough? */
diff --git a/sys/boot/common/interp_backslash.c b/sys/boot/common/interp_backslash.c
index 6325e4e..8bbeb34 100644
--- a/sys/boot/common/interp_backslash.c
+++ b/sys/boot/common/interp_backslash.c
@@ -18,6 +18,7 @@
#include <stand.h>
#include <string.h>
+#include "bootstrap.h"
#define DIGIT(x) (isdigit(x) ? (x) - '0' : islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')
diff --git a/sys/boot/common/interp_forth.c b/sys/boot/common/interp_forth.c
index 251caf1..a77fb6c 100644
--- a/sys/boot/common/interp_forth.c
+++ b/sys/boot/common/interp_forth.c
@@ -64,7 +64,7 @@ static void
bf_command(FICL_VM *vm)
{
char *name, *line, *tail, *cp;
- int len;
+ size_t len;
struct bootblk_command **cmdp;
bootblk_cmd_t *cmd;
int nstrings, i;
diff --git a/sys/boot/common/interp_parse.c b/sys/boot/common/interp_parse.c
index 0f83c43..c57001a 100644
--- a/sys/boot/common/interp_parse.c
+++ b/sys/boot/common/interp_parse.c
@@ -18,13 +18,11 @@
#include <stand.h>
#include <string.h>
+#include "bootstrap.h"
-/* Forward decls */
-extern char *backslash(char *str);
-
-static void clean(void);
-static int insert(int *argcp, char *buf);
-static char *variable_lookup(char *name);
+static void clean(void);
+static int insert(int *argcp, char *buf);
+static char *variable_lookup(char *name);
#define PARSE_BUFSIZE 1024 /* maximum size of one element */
#define MAXARGS 20 /* maximum number of elements */
@@ -61,7 +59,7 @@ if (expr) { \
/* Accept the usual delimiters for a variable, returning counterpart */
static char
-isdelim(char ch)
+isdelim(int ch)
{
if (ch == '{')
return '}';
@@ -71,7 +69,7 @@ isdelim(char ch)
}
static int
-isquote(char ch)
+isquote(int ch)
{
return (ch == '\'' || ch == '"');
}
@@ -81,7 +79,7 @@ parse(int *argc, char ***argv, char *str)
{
int ac;
char *val, *p, *q, *copy = NULL;
- int i = 0;
+ size_t i = 0;
char token, tmp, quote, *buf;
enum { STR, VAR, WHITE } state;
@@ -147,7 +145,7 @@ parse(int *argc, char ***argv, char *str)
tmp = *q;
*q = '\0';
if ((val = variable_lookup(p)) != NULL) {
- int len = strlen(val);
+ size_t len = strlen(val);
strncpy(buf + i, val, PARSE_BUFSIZE - (i + 1));
i += min(len, PARSE_BUFSIZE - 1);
diff --git a/sys/boot/common/isapnp.c b/sys/boot/common/isapnp.c
index 1941706..0c5646d 100644
--- a/sys/boot/common/isapnp.c
+++ b/sys/boot/common/isapnp.c
@@ -39,9 +39,8 @@
#define inb(x) (archsw.arch_isainb((x)))
#define outb(x,y) (archsw.arch_isaoutb((x),(y)))
-static void isapnp_write(int d, u_char r);
-static u_char isapnp_read(int d);
-static void isapnp_send_Initiation_LFSR();
+static void isapnp_write(int d, int r);
+static void isapnp_send_Initiation_LFSR(void);
static int isapnp_get_serial(u_int8_t *p);
static int isapnp_isolation_protocol(void);
static void isapnp_enumerate(void);
@@ -58,25 +57,18 @@ struct pnphandler isapnphandler =
};
static void
-isapnp_write(int d, u_char r)
+isapnp_write(int d, int r)
{
outb (_PNP_ADDRESS, d);
outb (_PNP_WRITE_DATA, r);
}
-static u_char
-isapnp_read(int d)
-{
- outb (_PNP_ADDRESS, d);
- return (inb(isapnp_readport));
-}
-
/*
* Send Initiation LFSR as described in "Plug and Play ISA Specification",
* Intel May 94.
*/
static void
-isapnp_send_Initiation_LFSR()
+isapnp_send_Initiation_LFSR(void)
{
int cur, i;
@@ -167,8 +159,9 @@ static int
isapnp_scan_resdata(struct pnpinfo *pi)
{
u_char tag, resinfo[8];
- int large_len, limit;
- char *str;
+ u_int limit;
+ size_t large_len;
+ u_char *str;
limit = 1000;
while ((limit-- > 0) && !isapnp_get_resource_info(&tag, 1)) {
@@ -204,13 +197,13 @@ isapnp_scan_resdata(struct pnpinfo *pi)
case ID_STRING_ANSI:
str = malloc(large_len + 1);
- if (isapnp_get_resource_info(str, large_len)) {
+ if (isapnp_get_resource_info(str, (ssize_t)large_len)) {
free(str);
return(1);
}
str[large_len] = 0;
if (pi->pi_desc == NULL) {
- pi->pi_desc = str;
+ pi->pi_desc = (char *)str;
} else {
free(str);
}
@@ -218,7 +211,7 @@ isapnp_scan_resdata(struct pnpinfo *pi)
default:
/* Large resource, skip it */
- if (isapnp_get_resource_info(NULL, large_len))
+ if (isapnp_get_resource_info(NULL, (ssize_t)large_len))
return(1);
}
}
diff --git a/sys/boot/common/load_aout.c b/sys/boot/common/load_aout.c
index c36cfac..8867815 100644
--- a/sys/boot/common/load_aout.c
+++ b/sys/boot/common/load_aout.c
@@ -47,8 +47,8 @@ static vm_offset_t aout_findkldident(struct preloaded_file *fp, struct exec *ehd
static int aout_fixupkldmod(struct preloaded_file *fp, struct exec *ehdr);
#endif
-char *aout_kerneltype = "a.out kernel";
-char *aout_moduletype = "a.out module";
+const char *aout_kerneltype = "a.out kernel";
+const char *aout_moduletype = "a.out module";
/*
* Attempt to load the file (file) as an a.out module. It will be stored at
@@ -191,21 +191,24 @@ aout_loadimage(struct preloaded_file *fp, int fd, vm_offset_t loadaddr, struct e
{
u_int pad;
vm_offset_t addr;
- int ss;
+ size_t ss;
+ ssize_t result;
vm_offset_t ssym, esym;
addr = loadaddr;
- lseek(fd, N_TXTOFF(*ehdr), SEEK_SET);
+ lseek(fd, (off_t)N_TXTOFF(*ehdr), SEEK_SET);
/* text segment */
printf(" text=0x%lx ", ehdr->a_text);
- if (archsw.arch_readin(fd, addr, ehdr->a_text) != ehdr->a_text)
+ result = archsw.arch_readin(fd, addr, ehdr->a_text);
+ if (result < 0 || (size_t)result != ehdr->a_text)
return(0);
addr += ehdr->a_text;
/* data segment */
printf("data=0x%lx ", ehdr->a_data);
- if (archsw.arch_readin(fd, addr, ehdr->a_data) != ehdr->a_data)
+ result = archsw.arch_readin(fd, addr, ehdr->a_data);
+ if (result < 0 || (size_t)result != ehdr->a_data)
return(0);
addr += ehdr->a_data;
@@ -228,7 +231,8 @@ aout_loadimage(struct preloaded_file *fp, int fd, vm_offset_t loadaddr, struct e
/* symbol table */
printf("symbols=[0x%lx+0x%lx", (long)sizeof(ehdr->a_syms),ehdr->a_syms);
- if (archsw.arch_readin(fd, addr, ehdr->a_syms) != ehdr->a_syms)
+ result = archsw.arch_readin(fd, addr, ehdr->a_syms);
+ if (result < 0 || (size_t)result != ehdr->a_syms)
return(0);
addr += ehdr->a_syms;
@@ -238,7 +242,8 @@ aout_loadimage(struct preloaded_file *fp, int fd, vm_offset_t loadaddr, struct e
addr += sizeof(ss);
ss -= sizeof(ss);
printf("+0x%lx+0x%x]", (long)sizeof(ss), ss);
- if (archsw.arch_readin(fd, addr, ss) != ss)
+ result = archsw.arch_readin(fd, addr, ss);
+ if (result < 0 || (size_t)result != ss)
return(0);
addr += ss;
esym = addr;
diff --git a/sys/boot/common/load_elf.c b/sys/boot/common/load_elf.c
index 40a15fd..388d5a1 100644
--- a/sys/boot/common/load_elf.c
+++ b/sys/boot/common/load_elf.c
@@ -57,7 +57,7 @@ typedef struct elf_file {
size_t strsz;
int fd;
caddr_t firstpage;
- int firstlen;
+ size_t firstlen;
int kernel;
vm_offset_t off;
} *elf_file_t;
@@ -65,9 +65,10 @@ typedef struct elf_file {
static int elf_loadimage(struct preloaded_file *mp, elf_file_t ef, vm_offset_t loadaddr);
static int elf_lookup_symbol(struct preloaded_file *mp, elf_file_t ef, const char* name, Elf_Sym* sym);
static int elf_parse_modmetadata(struct preloaded_file *mp, elf_file_t ef);
+static char *fake_modname(const char *name);
-char *elf_kerneltype = "elf kernel";
-char *elf_moduletype = "elf module";
+const char *elf_kerneltype = "elf kernel";
+const char *elf_moduletype = "elf module";
/*
* Attempt to load the file (file) as an ELF module. It will be stored at
@@ -83,6 +84,7 @@ elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result)
int err;
u_int pad;
char *s;
+ ssize_t bytes_read;
fp = NULL;
bzero(&ef, sizeof(struct elf_file));
@@ -99,8 +101,9 @@ elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result)
close(ef.fd);
return(ENOMEM);
}
- ef.firstlen = read(ef.fd, ef.firstpage, PAGE_SIZE);
- if (ef.firstlen <= sizeof(Elf_Ehdr)) {
+ bytes_read = read(ef.fd, ef.firstpage, PAGE_SIZE);
+ ef.firstlen = (size_t)bytes_read;
+ if (bytes_read < 0 || ef.firstlen <= sizeof(Elf_Ehdr)) {
err = EFTYPE; /* could be EIO, but may be small file */
goto oerr;
}
@@ -224,7 +227,8 @@ elf_loadfile(char *filename, vm_offset_t dest, struct preloaded_file **result)
static int
elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
{
- int i, j;
+ int i;
+ u_int j;
Elf_Ehdr *ehdr;
Elf_Phdr *phdr, *php;
Elf_Shdr *shdr;
@@ -233,6 +237,7 @@ elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
vm_offset_t lastaddr;
void *buf;
size_t resid, chunk;
+ ssize_t result;
vm_offset_t dest;
vm_offset_t ssym, esym;
Elf_Dyn *dp;
@@ -241,7 +246,7 @@ elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
int symstrindex;
int symtabindex;
long size;
- int fpcopy;
+ u_int fpcopy;
dp = NULL;
shdr = NULL;
@@ -290,12 +295,13 @@ elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
phdr[i].p_vaddr + off, fpcopy);
}
if (phdr[i].p_filesz > fpcopy) {
- if (lseek(ef->fd, phdr[i].p_offset + fpcopy, SEEK_SET) == -1) {
+ if (lseek(ef->fd, (off_t)(phdr[i].p_offset + fpcopy),
+ SEEK_SET) == -1) {
printf("\nelf_loadexec: cannot seek\n");
goto out;
}
if (archsw.arch_readin(ef->fd, phdr[i].p_vaddr + off + fpcopy,
- phdr[i].p_filesz - fpcopy) != phdr[i].p_filesz - fpcopy) {
+ phdr[i].p_filesz - fpcopy) != (ssize_t)(phdr[i].p_filesz - fpcopy)) {
printf("\nelf_loadexec: archsw.readin failed\n");
goto out;
}
@@ -348,11 +354,12 @@ elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
shdr = malloc(chunk);
if (shdr == NULL)
goto nosyms;
- if (lseek(ef->fd, ehdr->e_shoff, SEEK_SET) == -1) {
+ if (lseek(ef->fd, (off_t)ehdr->e_shoff, SEEK_SET) == -1) {
printf("\nelf_loadimage: cannot lseek() to section headers");
goto nosyms;
}
- if (read(ef->fd, shdr, chunk) != chunk) {
+ result = read(ef->fd, shdr, chunk);
+ if (result < 0 || (size_t)result != chunk) {
printf("\nelf_loadimage: read section headers failed");
goto nosyms;
}
@@ -417,14 +424,14 @@ elf_loadimage(struct preloaded_file *fp, elf_file_t ef, vm_offset_t off)
printf("0x%lx+0x%lx", (long)sizeof(size), size);
#endif
- if (lseek(ef->fd, shdr[i].sh_offset, SEEK_SET) == -1) {
+ if (lseek(ef->fd, (off_t)shdr[i].sh_offset, SEEK_SET) == -1) {
printf("\nelf_loadimage: could not seek for symbols - skipped!");
lastaddr = ssym;
ssym = 0;
goto nosyms;
}
- if (archsw.arch_readin(ef->fd, lastaddr, shdr[i].sh_size) !=
- shdr[i].sh_size) {
+ result = archsw.arch_readin(ef->fd, lastaddr, shdr[i].sh_size);
+ if (result < 0 || (size_t)result != shdr[i].sh_size) {
printf("\nelf_loadimage: could not read symbols - skipped!");
lastaddr = ssym;
ssym = 0;
@@ -531,9 +538,9 @@ out:
static char invalid_name[] = "bad";
char *
-fake_modname(char *name) {
+fake_modname(const char *name) {
char *sp, *ep;
- int len;
+ size_t len;
sp = strrchr(name, '/');
if (sp)
@@ -561,8 +568,7 @@ int
elf_parse_modmetadata(struct preloaded_file *fp, elf_file_t ef) {
struct mod_metadata md;
Elf_Sym sym;
- void **p, *v;
- char *s;
+ char *s, *v, **p;
long entries;
int modcnt;
@@ -571,7 +577,7 @@ elf_parse_modmetadata(struct preloaded_file *fp, elf_file_t ef) {
COPYOUT(sym.st_value + ef->off, &entries, sizeof(entries));
modcnt = 0;
- p = (void*)(sym.st_value + ef->off + sizeof(entries));
+ p = (char **)(sym.st_value + ef->off + sizeof(entries));
while (entries--) {
COPYOUT(p++, &v, sizeof(v));
COPYOUT(v + ef->off, &md, sizeof(md));
diff --git a/sys/boot/common/module.c b/sys/boot/common/module.c
index 8ad0dc0..effb848 100644
--- a/sys/boot/common/module.c
+++ b/sys/boot/common/module.c
@@ -49,7 +49,7 @@ struct file_metadata* metadata_next(struct file_metadata *base_mp, int type);
/* load address should be tweaked by first module loaded (kernel) */
static vm_offset_t loadaddr = 0;
-static char *default_searchpath ="/;/boot;/modules";
+static const char *default_searchpath ="/;/boot;/modules";
struct preloaded_file *preloaded_files = NULL;
@@ -434,7 +434,7 @@ file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p)
{
struct file_metadata *md;
- md = malloc(sizeof(struct file_metadata) + size);
+ md = malloc(sizeof(struct file_metadata) - sizeof(md->md_data) + size);
md->md_size = size;
md->md_type = type;
bcopy(p, md->md_data, size);
diff --git a/sys/boot/common/pnp.c b/sys/boot/common/pnp.c
index bb3695b..b859529 100644
--- a/sys/boot/common/pnp.c
+++ b/sys/boot/common/pnp.c
@@ -19,8 +19,6 @@ STAILQ_HEAD(,pnpinfo) pnp_devices;
static int pnp_devices_initted = 0;
static void pnp_discard(void);
-static int pnp_readconf(char *path);
-static int pnp_scankernel(void);
/*
* Perform complete enumeration sweep
OpenPOWER on IntegriCloud