Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 * arch/ia64/hp/sim/boot/bootloader.c
  3 *
  4 * Loads an ELF kernel.
  5 *
  6 * Copyright (C) 1998-2003 Hewlett-Packard Co
  7 *	David Mosberger-Tang <davidm@hpl.hp.com>
  8 *	Stephane Eranian <eranian@hpl.hp.com>
  9 *
 10 * 01/07/99 S.Eranian modified to pass command line arguments to kernel
 11 */
 12struct task_struct;	/* forward declaration for elf.h */
 13
 14#include <linux/elf.h>
 15#include <linux/init.h>
 16#include <linux/kernel.h>
 17
 18#include <asm/elf.h>
 19#include <asm/intrinsics.h>
 20#include <asm/pal.h>
 21#include <asm/pgtable.h>
 22#include <asm/sal.h>
 23
 24#include "ssc.h"
 25
 26struct disk_req {
 27	unsigned long addr;
 28	unsigned len;
 29};
 30
 31struct disk_stat {
 32	int fd;
 33	unsigned count;
 34};
 35
 36extern void jmp_to_kernel (unsigned long bp, unsigned long e_entry);
 37extern struct ia64_boot_param *sys_fw_init (const char *args, int arglen);
 38extern void debug_break (void);
 39
 40static void
 41cons_write (const char *buf)
 42{
 43	unsigned long ch;
 44
 45	while ((ch = *buf++) != '\0') {
 46		ssc(ch, 0, 0, 0, SSC_PUTCHAR);
 47		if (ch == '\n')
 48		  ssc('\r', 0, 0, 0, SSC_PUTCHAR);
 49	}
 50}
 51
 52#define MAX_ARGS 32
 53
 54void
 55start_bootloader (void)
 56{
 57	static char mem[4096];
 58	static char buffer[1024];
 59	unsigned long off;
 60	int fd, i;
 61	struct disk_req req;
 62	struct disk_stat stat;
 63	struct elfhdr *elf;
 64	struct elf_phdr *elf_phdr;	/* program header */
 65	unsigned long e_entry, e_phoff, e_phnum;
 66	register struct ia64_boot_param *bp;
 67	char *kpath, *args;
 68	long arglen = 0;
 69
 70	ssc(0, 0, 0, 0, SSC_CONSOLE_INIT);
 71
 72	/*
 73	 * S.Eranian: extract the commandline argument from the simulator
 74	 *
 75	 * The expected format is as follows:
 76         *
 77	 *	kernelname args...
 78	 *
 79	 * Both are optional but you can't have the second one without the first.
 80	 */
 81	arglen = ssc((long) buffer, 0, 0, 0, SSC_GET_ARGS);
 82
 83	kpath = "vmlinux";
 84	args = buffer;
 85	if (arglen > 0) {
 86		kpath = buffer;
 87		while (*args != ' ' && *args != '\0')
 88			++args, --arglen;
 89		if (*args == ' ')
 90			*args++ = '\0', --arglen;
 91	}
 92
 93	if (arglen <= 0) {
 94		args = "";
 95		arglen = 1;
 96	}
 97
 98	fd = ssc((long) kpath, 1, 0, 0, SSC_OPEN);
 99
100	if (fd < 0) {
101		cons_write(kpath);
102		cons_write(": file not found, reboot now\n");
103		for(;;);
104	}
105	stat.fd = fd;
106	off = 0;
107
108	req.len = sizeof(mem);
109	req.addr = (long) mem;
110	ssc(fd, 1, (long) &req, off, SSC_READ);
111	ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
112
113	elf = (struct elfhdr *) mem;
114	if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) {
115		cons_write("not an ELF file\n");
116		return;
117	}
118	if (elf->e_type != ET_EXEC) {
119		cons_write("not an ELF executable\n");
120		return;
121	}
122	if (!elf_check_arch(elf)) {
123		cons_write("kernel not for this processor\n");
124		return;
125	}
126
127	e_entry = elf->e_entry;
128	e_phnum = elf->e_phnum;
129	e_phoff = elf->e_phoff;
130
131	cons_write("loading ");
132	cons_write(kpath);
133	cons_write("...\n");
134
135	for (i = 0; i < e_phnum; ++i) {
136		req.len = sizeof(*elf_phdr);
137		req.addr = (long) mem;
138		ssc(fd, 1, (long) &req, e_phoff, SSC_READ);
139		ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
140		if (stat.count != sizeof(*elf_phdr)) {
141			cons_write("failed to read phdr\n");
142			return;
143		}
144		e_phoff += sizeof(*elf_phdr);
145
146		elf_phdr = (struct elf_phdr *) mem;
147
148		if (elf_phdr->p_type != PT_LOAD)
149			continue;
150
151		req.len = elf_phdr->p_filesz;
152		req.addr = __pa(elf_phdr->p_paddr);
153		ssc(fd, 1, (long) &req, elf_phdr->p_offset, SSC_READ);
154		ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
155		memset((char *)__pa(elf_phdr->p_paddr) + elf_phdr->p_filesz, 0,
156		       elf_phdr->p_memsz - elf_phdr->p_filesz);
157	}
158	ssc(fd, 0, 0, 0, SSC_CLOSE);
159
160	cons_write("starting kernel...\n");
161
162	/* fake an I/O base address: */
163	ia64_setreg(_IA64_REG_AR_KR0, 0xffffc000000UL);
164
165	bp = sys_fw_init(args, arglen);
166
167	ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS);
168
169	debug_break();
170	jmp_to_kernel((unsigned long) bp, e_entry);
171
172	cons_write("kernel returned!\n");
173	ssc(-1, 0, 0, 0, SSC_EXIT);
174}
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * arch/ia64/hp/sim/boot/bootloader.c
  4 *
  5 * Loads an ELF kernel.
  6 *
  7 * Copyright (C) 1998-2003 Hewlett-Packard Co
  8 *	David Mosberger-Tang <davidm@hpl.hp.com>
  9 *	Stephane Eranian <eranian@hpl.hp.com>
 10 *
 11 * 01/07/99 S.Eranian modified to pass command line arguments to kernel
 12 */
 13struct task_struct;	/* forward declaration for elf.h */
 14
 15#include <linux/elf.h>
 16#include <linux/init.h>
 17#include <linux/kernel.h>
 18
 19#include <asm/elf.h>
 20#include <asm/intrinsics.h>
 21#include <asm/pal.h>
 22#include <asm/pgtable.h>
 23#include <asm/sal.h>
 24
 25#include "ssc.h"
 26
 27struct disk_req {
 28	unsigned long addr;
 29	unsigned len;
 30};
 31
 32struct disk_stat {
 33	int fd;
 34	unsigned count;
 35};
 36
 37extern void jmp_to_kernel (unsigned long bp, unsigned long e_entry);
 38extern struct ia64_boot_param *sys_fw_init (const char *args, int arglen);
 39extern void debug_break (void);
 40
 41static void
 42cons_write (const char *buf)
 43{
 44	unsigned long ch;
 45
 46	while ((ch = *buf++) != '\0') {
 47		ssc(ch, 0, 0, 0, SSC_PUTCHAR);
 48		if (ch == '\n')
 49		  ssc('\r', 0, 0, 0, SSC_PUTCHAR);
 50	}
 51}
 52
 53#define MAX_ARGS 32
 54
 55void
 56start_bootloader (void)
 57{
 58	static char mem[4096];
 59	static char buffer[1024];
 60	unsigned long off;
 61	int fd, i;
 62	struct disk_req req;
 63	struct disk_stat stat;
 64	struct elfhdr *elf;
 65	struct elf_phdr *elf_phdr;	/* program header */
 66	unsigned long e_entry, e_phoff, e_phnum;
 67	register struct ia64_boot_param *bp;
 68	char *kpath, *args;
 69	long arglen = 0;
 70
 71	ssc(0, 0, 0, 0, SSC_CONSOLE_INIT);
 72
 73	/*
 74	 * S.Eranian: extract the commandline argument from the simulator
 75	 *
 76	 * The expected format is as follows:
 77         *
 78	 *	kernelname args...
 79	 *
 80	 * Both are optional but you can't have the second one without the first.
 81	 */
 82	arglen = ssc((long) buffer, 0, 0, 0, SSC_GET_ARGS);
 83
 84	kpath = "vmlinux";
 85	args = buffer;
 86	if (arglen > 0) {
 87		kpath = buffer;
 88		while (*args != ' ' && *args != '\0')
 89			++args, --arglen;
 90		if (*args == ' ')
 91			*args++ = '\0', --arglen;
 92	}
 93
 94	if (arglen <= 0) {
 95		args = "";
 96		arglen = 1;
 97	}
 98
 99	fd = ssc((long) kpath, 1, 0, 0, SSC_OPEN);
100
101	if (fd < 0) {
102		cons_write(kpath);
103		cons_write(": file not found, reboot now\n");
104		for(;;);
105	}
106	stat.fd = fd;
107	off = 0;
108
109	req.len = sizeof(mem);
110	req.addr = (long) mem;
111	ssc(fd, 1, (long) &req, off, SSC_READ);
112	ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
113
114	elf = (struct elfhdr *) mem;
115	if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) != 0) {
116		cons_write("not an ELF file\n");
117		return;
118	}
119	if (elf->e_type != ET_EXEC) {
120		cons_write("not an ELF executable\n");
121		return;
122	}
123	if (!elf_check_arch(elf)) {
124		cons_write("kernel not for this processor\n");
125		return;
126	}
127
128	e_entry = elf->e_entry;
129	e_phnum = elf->e_phnum;
130	e_phoff = elf->e_phoff;
131
132	cons_write("loading ");
133	cons_write(kpath);
134	cons_write("...\n");
135
136	for (i = 0; i < e_phnum; ++i) {
137		req.len = sizeof(*elf_phdr);
138		req.addr = (long) mem;
139		ssc(fd, 1, (long) &req, e_phoff, SSC_READ);
140		ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
141		if (stat.count != sizeof(*elf_phdr)) {
142			cons_write("failed to read phdr\n");
143			return;
144		}
145		e_phoff += sizeof(*elf_phdr);
146
147		elf_phdr = (struct elf_phdr *) mem;
148
149		if (elf_phdr->p_type != PT_LOAD)
150			continue;
151
152		req.len = elf_phdr->p_filesz;
153		req.addr = __pa(elf_phdr->p_paddr);
154		ssc(fd, 1, (long) &req, elf_phdr->p_offset, SSC_READ);
155		ssc((long) &stat, 0, 0, 0, SSC_WAIT_COMPLETION);
156		memset((char *)__pa(elf_phdr->p_paddr) + elf_phdr->p_filesz, 0,
157		       elf_phdr->p_memsz - elf_phdr->p_filesz);
158	}
159	ssc(fd, 0, 0, 0, SSC_CLOSE);
160
161	cons_write("starting kernel...\n");
162
163	/* fake an I/O base address: */
164	ia64_setreg(_IA64_REG_AR_KR0, 0xffffc000000UL);
165
166	bp = sys_fw_init(args, arglen);
167
168	ssc(0, (long) kpath, 0, 0, SSC_LOAD_SYMBOLS);
169
170	debug_break();
171	jmp_to_kernel((unsigned long) bp, e_entry);
172
173	cons_write("kernel returned!\n");
174	ssc(-1, 0, 0, 0, SSC_EXIT);
175}