Various logic fixes. Fixed bug in c_getc() for C1700 and C3600.

master
Philippe Vachon 16 years ago
parent 26b4e834aa
commit b5ecd94191

@ -63,7 +63,7 @@ void load_elf32_uninitialized_memory(uint32_t address, uint32_t length)
* @param loader_addr address of the loader binary in memory * @param loader_addr address of the loader binary in memory
* @return * @return
*/ */
int load_elf32_file(struct file *fp, char *cmd_line) void load_elf32_file(struct file *fp, char *cmd_line)
{ {
struct elf32_header hdr; struct elf32_header hdr;
uint32_t mem_sz = 0; uint32_t mem_sz = 0;
@ -77,20 +77,20 @@ int load_elf32_file(struct file *fp, char *cmd_line)
{ {
printf("Bad ELF magic found. Found: %#2x %#2x %#2x %#2x.\n", printf("Bad ELF magic found. Found: %#2x %#2x %#2x %#2x.\n",
hdr.ident[0], hdr.ident[1], hdr.ident[2], hdr.ident[3]); hdr.ident[0], hdr.ident[1], hdr.ident[2], hdr.ident[3]);
return -1; return;
} }
/* check machine class: */ /* check machine class: */
if (!hdr.ident[ELF_INDEX_CLASS] == ELF_CLASS_32) if (!hdr.ident[ELF_INDEX_CLASS] == ELF_CLASS_32)
{ {
printf("Invalid ELF machine class found. Found: %2x.\n", printf("Invalid ELF machine class found. Found: %2x.\n",
hdr.ident[ELF_INDEX_CLASS]); hdr.ident[ELF_INDEX_CLASS]);
return -1; return;
} }
/* check endianess: */ /* check endianess: */
if (hdr.ident[ELF_INDEX_DATA] != ELF_DATA_MSB) { if (hdr.ident[ELF_INDEX_DATA] != ELF_DATA_MSB) {
printf("Non-big endian ELF file detected. Aborting load.\n"); printf("Non-big endian ELF file detected. Aborting load.\n");
return -1; return;
} }
if (hdr.ehsize != 52 /* bytes */) { if (hdr.ehsize != 52 /* bytes */) {
@ -100,7 +100,7 @@ int load_elf32_file(struct file *fp, char *cmd_line)
if (hdr.phnum == 0) { if (hdr.phnum == 0) {
printf("Found zero segments in ELF file. Aborting load.\n"); printf("Found zero segments in ELF file. Aborting load.\n");
return -1; return;
} }
int i; int i;
@ -142,8 +142,6 @@ int load_elf32_file(struct file *fp, char *cmd_line)
((void (*)(uint32_t mem_sz, char *cmd_line))(hdr.entry)) ((void (*)(uint32_t mem_sz, char *cmd_line))(hdr.entry))
(c_memsz(), cmd_line); (c_memsz(), cmd_line);
return -1; /* something failed, badly */
} }
/** /**
@ -187,7 +185,7 @@ void load_elf64_uninitialized_memory(uint64_t address, uint64_t length)
} }
} }
int load_elf64_file(struct file *fp, char *cmd_line) void load_elf64_file(struct file *fp, char *cmd_line)
{ {
struct elf64_hdr hdr; struct elf64_hdr hdr;
uint32_t mem_sz = 0; uint32_t mem_sz = 0;
@ -203,20 +201,20 @@ int load_elf64_file(struct file *fp, char *cmd_line)
{ {
printf("Bad ELF magic found. Found: %#2x %#2x %#2x %#2x.\n", printf("Bad ELF magic found. Found: %#2x %#2x %#2x %#2x.\n",
hdr.e_ident[0], hdr.e_ident[1], hdr.e_ident[2], hdr.e_ident[3]); hdr.e_ident[0], hdr.e_ident[1], hdr.e_ident[2], hdr.e_ident[3]);
return -1; return;
} }
/* check machine class: */ /* check machine class: */
if (!hdr.e_ident[ELF_INDEX_CLASS] == ELF_CLASS_64) if (!hdr.e_ident[ELF_INDEX_CLASS] == ELF_CLASS_64)
{ {
printf("Invalid ELF machine class found. Found: %2x.\n", printf("Invalid ELF machine class found. Found: %2x.\n",
hdr.e_ident[ELF_INDEX_CLASS]); hdr.e_ident[ELF_INDEX_CLASS]);
return -1; return;
} }
/* check endianess: */ /* check endianess: */
if (hdr.e_ident[ELF_INDEX_DATA] != ELF_DATA_MSB) { if (hdr.e_ident[ELF_INDEX_DATA] != ELF_DATA_MSB) {
printf("Non-big endian ELF file detected. Aborting load.\n"); printf("Non-big endian ELF file detected. Aborting load.\n");
return -1; return;
} }
if (hdr.e_ehsize != 52 /* bytes */) { if (hdr.e_ehsize != 52 /* bytes */) {
@ -226,7 +224,7 @@ int load_elf64_file(struct file *fp, char *cmd_line)
if (hdr.e_phnum == 0) { if (hdr.e_phnum == 0) {
printf("Found zero segments in ELF file. Aborting load.\n"); printf("Found zero segments in ELF file. Aborting load.\n");
return -1; return;
} }
cilo_seek(fp, hdr.e_phoff, SEEK_SET); cilo_seek(fp, hdr.e_phoff, SEEK_SET);
@ -249,5 +247,4 @@ int load_elf64_file(struct file *fp, char *cmd_line)
return -1;
} }

@ -4,9 +4,7 @@
#include <types.h> #include <types.h>
#include <ciloio.h> #include <ciloio.h>
void load_elf32_section(struct file *fp, uint32_t address, void load_elf32_file(struct file *fp, char *cmd_line);
uint32_t file_offset, uint32_t length); void load_elf64_file(struct file *fp, char *cmd_line);
void load_elf32_uninitialized_memory(uint32_t address, uint32_t length);
int load_elf32_file(struct file *fp, char *cmd_line);
#endif /* _ELF_LOADER_H */ #endif /* _ELF_LOADER_H */

@ -107,7 +107,7 @@ void load_lzma(struct file *fp, uint32_t load_address, char *cmd_line)
} }
/* kick into kernel: */ /* kick into kernel: */
printf("\nStarting kernel at 0x%016x.\n", load_address); printf("100\nStarting kernel at 0x%016x.\n\n", load_address);
((void (*)(uint32_t mem_sz, char *cmd_line))(load_address)) ((void (*)(uint32_t mem_sz, char *cmd_line))(load_address))
(c_memsz(), cmd_line); (c_memsz(), cmd_line);
} }

@ -80,8 +80,8 @@ int c_gets(char *b, int n)
if (b[i - 1] == '\n' || b[i-1] == '\r') { if (b[i - 1] == '\n' || b[i-1] == '\r') {
break; break;
} }
else if (b[i - 1] == 0x8) { else if (b[i - 1] == 0x8 || b[i - 1] == 0x7f) {
i--; i-=2;
} }
} while (i < n); } while (i < n);

@ -95,7 +95,7 @@ int c_gets(char *b, int n)
break; break;
} }
else if (b[i - 1] == 0x8 || b[i - 1] == 0x7f) { else if (b[i - 1] == 0x8 || b[i - 1] == 0x7f) {
i--; i-=2;
} }
} while (i < n); } while (i < n);

@ -15,30 +15,6 @@
#include <string.h> #include <string.h>
/**
* Dump 0x10 bytes of memory in canonical hexadecimal form
* @param addr Starting address to dump from
*/
void hex_dump(uint32_t addr)
{
uint8_t *rgn = (uint8_t *)addr;
int i;
/* print out the address of the 16 bytes of interest */
printf("%8x " , addr);
/* print out hex value for individual bytes */
for (i = 0; i < 16; i++) {
printf("%02x ", rgn[i]);
}
/* print out as chars */
for (i = 0; i < 16; i++) {
printf("%c", rgn[i] >= 32 && rgn[i] <= 126 ? rgn[i] : '.');
}
printf("\n");
}
/** /**
* Entry Point for CiscoLoad * Entry Point for CiscoLoad
*/ */
@ -83,7 +59,6 @@ enter_filename:
c_gets(buf, 128); c_gets(buf, 128);
int baud = c_baud(); /* get console baud rate */ int baud = c_baud(); /* get console baud rate */
printf("Boot console baud rate: %d\n", baud);
/* determine if a command line string has been appended to kernel name */ /* determine if a command line string has been appended to kernel name */
if ((cmd_line_append = strchr(buf, ' ')) != NULL) { if ((cmd_line_append = strchr(buf, ' ')) != NULL) {
@ -104,8 +79,6 @@ enter_filename:
sprintf(cmd_line, "console=ttyS0,%d", baud); sprintf(cmd_line, "console=ttyS0,%d", baud);
} }
printf("\n\nAttempting to load file %s\n", kernel);
struct file kernel_file = cilo_open(kernel); struct file kernel_file = cilo_open(kernel);
if (kernel_file.code == -1) { if (kernel_file.code == -1) {
@ -126,12 +99,14 @@ enter_filename:
cilo_seek(&kernel_file, 0, SEEK_SET); cilo_seek(&kernel_file, 0, SEEK_SET);
/* check if this is a 32-bit or 64-bit kernel image. */ /* check if this is a 32-bit or 64-bit kernel image. */
if (load_elf32_file(&kernel_file, cmd_line) if (hdr.ident[ELF_INDEX_CLASS] == ELF_CLASS_32) {
< 0) load_elf32_file(&kernel_file, cmd_line);
{ } else {
printf("Fatal error while loading kernel. Aborting.\n"); load_elf64_file(&kernel_file, cmd_line);
} }
} }
printf("Fatal error while loading kernel. Aborting.\n");
goto enter_filename; goto enter_filename;
} }

Loading…
Cancel
Save