various fixes

This commit is contained in:
phcoder 2009-10-11 02:07:52 +02:00
parent 65e64ea4b1
commit ffa9860a86
10 changed files with 177 additions and 39 deletions

View file

@ -91,7 +91,7 @@ kernel_img_SOURCES = kern/mips/qemu-r4k/startup.S \
kern/rescue_parser.c kern/rescue_reader.c \ kern/rescue_parser.c kern/rescue_reader.c \
kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
kern/generic/millisleep.c kern/time.c \ kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c kern/time.c \
symlist.c kern/$(target_cpu)/cache.S symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
@ -122,4 +122,10 @@ lsmmap_mod_SOURCES = commands/lsmmap.c
lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For serial.mod.
pkglib_MODULES += serial.mod
serial_mod_SOURCES = term/serial.c
serial_mod_CFLAGS = $(COMMON_CFLAGS)
serial_mod_LDFLAGS = $(COMMON_LDFLAGS)
include $(srcdir)/conf/common.mk include $(srcdir)/conf/common.mk

View file

@ -280,8 +280,10 @@ grub_cpio_open (grub_file_t file, const char *name)
/* Compare NAME and FN by hand in order to cope with duplicate /* Compare NAME and FN by hand in order to cope with duplicate
slashes. */ slashes. */
i = 1; i = 0;
j = 0; j = 0;
while (name[i] == '/')
i++;
while (1) while (1)
{ {
if (name[i] != fn[j]) if (name[i] != fn[j])
@ -290,13 +292,16 @@ grub_cpio_open (grub_file_t file, const char *name)
if (name[i] == '\0') if (name[i] == '\0')
break; break;
if (name[i] == '/' && name[i+1] == '/') while (name[i] == '/' && name[i+1] == '/')
i++; i++;
i++; i++;
j++; j++;
} }
if (name[i] != fn[j])
goto no_match;
file->data = data; file->data = data;
file->size = data->size; file->size = data->size;
grub_free (fn); grub_free (fn);

View file

@ -319,6 +319,7 @@ MOSTLYCLEANFILES += #{deps_str}
#{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
$(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS) $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
$(STRIP) -R .rel.dyn -R .reginfo -R .note -R .comment $@
" + objs.collect_with_index do |obj, i| " + objs.collect_with_index do |obj, i|
src = sources[i] src = sources[i]
@ -330,6 +331,7 @@ MOSTLYCLEANFILES += #{deps_str}
"#{obj}: #{src} $(#{src}_DEPENDENCIES) "#{obj}: #{src} $(#{src}_DEPENDENCIES)
$(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $< $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
-include #{dep} -include #{dep}
" "

25
include/grub/mips/dl.h Normal file
View file

@ -0,0 +1,25 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_CPU_DL_H
#define GRUB_CPU_DL_H 1
/* Dummy __gnu_local_gp. Resolved by linker. */
char EXPORT_VAR (__gnu_local_gp);
#endif /* ! GRUB_CPU_DL_H */

62
include/grub/mips/io.h Normal file
View file

@ -0,0 +1,62 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_IO_H
#define GRUB_IO_H 1
#include <grub/types.h>
typedef grub_addr_t grub_port_t;
static __inline unsigned char
grub_inb (grub_port_t port)
{
return *(grub_uint8_t *) port;
}
static __inline unsigned short int
grub_inw (grub_port_t port)
{
return *(grub_uint16_t *) port;
}
static __inline unsigned int
grub_inl (grub_port_t port)
{
return *(grub_uint32_t *) port;
}
static __inline void
grub_outb (unsigned char value, grub_port_t port)
{
*(grub_uint8_t *) port = value;
}
static __inline void
grub_outw (unsigned short int value, grub_port_t port)
{
*(grub_uint16_t *) port = value;
}
static __inline void
grub_outl (unsigned int value, grub_port_t port)
{
*(grub_uint32_t *) port = value;
}
#endif /* _SYS_IO_H */

View file

@ -267,15 +267,12 @@ grub_disk_open (const char *name)
for (dev = grub_disk_dev_list; dev; dev = dev->next) for (dev = grub_disk_dev_list; dev; dev = dev->next)
{ {
grub_printf ("open: %p\n", dev->open);
grub_getkey ();
if ((dev->open) (raw, disk) == GRUB_ERR_NONE) if ((dev->open) (raw, disk) == GRUB_ERR_NONE)
break; break;
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE) else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
else else
goto fail; goto fail;
grub_printf ("survived\n");
} }
if (! dev) if (! dev)

View file

@ -57,6 +57,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
grub_size_t gp_size = 0; grub_size_t gp_size = 0;
/* FIXME: suboptimal. */ /* FIXME: suboptimal. */
grub_uint32_t *gp, *gpptr; grub_uint32_t *gp, *gpptr;
grub_uint32_t gp0;
/* Find a symbol table. */ /* Find a symbol table. */
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
@ -70,6 +71,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize; entsize = s->sh_entsize;
/* Find reginfo. */
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_MIPS_REGINFO)
break;
if (i == e->e_shnum)
return grub_error (GRUB_ERR_BAD_MODULE, "no reginfo found");
gp0 = ((grub_uint32_t *)((char *) e + s->sh_offset))[5];
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum; i < e->e_shnum;
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
@ -107,7 +120,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
gpptr = gp = grub_malloc (gp_size); gpptr = gp = grub_malloc (gp_size);
if (!gp) if (!gp)
return grub_errno; return grub_errno;
grub_printf ("gp=%p\n", gp);
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum; i < e->e_shnum;
@ -166,8 +178,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
*(grub_uint16_t *) addr += (sym->st_value) & 0xffff; *(grub_uint16_t *) addr += (sym->st_value) & 0xffff;
break; break;
case R_MIPS_32: case R_MIPS_32:
*(grub_uint32_t *) addr = sym->st_value; *(grub_uint32_t *) addr += sym->st_value;
break; break;
case R_MIPS_GPREL32:
*(grub_uint32_t *) addr = sym->st_value
+ *(grub_uint32_t *) addr + gp0 - (grub_uint32_t)gp;
break;
case R_MIPS_26: case R_MIPS_26:
{ {
grub_uint32_t value; grub_uint32_t value;
@ -189,16 +206,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
= sizeof (grub_uint32_t) * (gpptr - gp); = sizeof (grub_uint32_t) * (gpptr - gp);
gpptr++; gpptr++;
break; break;
case R_MIPS_GPREL32:
grub_printf ("gp32\n");
*gpptr = sym->st_value + *(grub_uint16_t *) addr;
*(grub_uint32_t *) addr
= sizeof (grub_uint32_t) * (gpptr - gp);
gpptr++;
break;
default: default:
grub_printf ("Unknown relocation type %d\n", {
grub_free (gp);
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unknown relocation type %d\n",
ELF_R_TYPE (rel->r_info)); ELF_R_TYPE (rel->r_info));
}
break; break;
} }
} }

View file

@ -5,6 +5,7 @@
#include <grub/types.h> #include <grub/types.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/time.h>
#include <grub/machine/kernel.h> #include <grub/machine/kernel.h>
#include <grub/machine/memory.h> #include <grub/machine/memory.h>
#include <grub/cpu/kernel.h> #include <grub/cpu/kernel.h>

View file

@ -48,9 +48,11 @@ struct grub_handler_class grub_term_output_class =
void void
grub_putcode (grub_uint32_t code) grub_putcode (grub_uint32_t code)
{ {
// int height = grub_getwh () & 255; int height = grub_getwh () & 255;
if (!grub_cur_term_output)
return;
#if 0
if (code == '\t' && grub_cur_term_output->getxy) if (code == '\t' && grub_cur_term_output->getxy)
{ {
int n; int n;
@ -61,15 +63,13 @@ grub_putcode (grub_uint32_t code)
return; return;
} }
#endif
// (grub_cur_term_output->putchar) (code); (grub_cur_term_output->putchar) (code);
*((grub_uint8_t *)0x140003f8) = code;
if (code == '\n') if (code == '\n')
{ {
grub_putcode ('\r'); grub_putcode ('\r');
#if 0
grub_more_lines++; grub_more_lines++;
if (grub_more && grub_more_lines == height - 1) if (grub_more && grub_more_lines == height - 1)
@ -96,7 +96,6 @@ grub_putcode (grub_uint32_t code)
else else
grub_more_lines = 0; grub_more_lines = 0;
} }
#endif
} }
} }
@ -129,54 +128,66 @@ grub_putchar (int c)
grub_ssize_t grub_ssize_t
grub_getcharwidth (grub_uint32_t code) grub_getcharwidth (grub_uint32_t code)
{ {
if (!grub_cur_term_output)
return 1;
return (grub_cur_term_output->getcharwidth) (code); return (grub_cur_term_output->getcharwidth) (code);
} }
int int
grub_getkey (void) grub_getkey (void)
{ {
while (!(*((grub_uint8_t *)0x140003f8+5) & 0x01)); int c;
return *((grub_uint8_t *)0x140003f8); if (!grub_cur_term_input)
// return (grub_cur_term_input->getkey) (); return 0;
return (grub_cur_term_input->getkey) ();
} }
int int
grub_checkkey (void) grub_checkkey (void)
{ {
return !!(*((grub_uint8_t *)0x140003f8+5) & 0x01); if (!grub_cur_term_input)
//return (grub_cur_term_input->checkkey) (); return 0;
return (grub_cur_term_input->checkkey) ();
} }
int int
grub_getkeystatus (void) grub_getkeystatus (void)
{ {
/* if (grub_cur_term_input->getkeystatus) if (grub_cur_term_input && grub_cur_term_input->getkeystatus)
return (grub_cur_term_input->getkeystatus) (); return (grub_cur_term_input->getkeystatus) ();
else*/ else
return 0; return 0;
} }
grub_uint16_t grub_uint16_t
grub_getxy (void) grub_getxy (void)
{ {
if (!grub_cur_term_output)
return 0;
return (grub_cur_term_output->getxy) (); return (grub_cur_term_output->getxy) ();
} }
grub_uint16_t grub_uint16_t
grub_getwh (void) grub_getwh (void)
{ {
if (!grub_cur_term_output)
return (80 << 8) | 25;
return (grub_cur_term_output->getwh) (); return (grub_cur_term_output->getwh) ();
} }
void void
grub_gotoxy (grub_uint8_t x, grub_uint8_t y) grub_gotoxy (grub_uint8_t x, grub_uint8_t y)
{ {
if (grub_cur_term_output && grub_cur_term_output->gotoxy)
(grub_cur_term_output->gotoxy) (x, y); (grub_cur_term_output->gotoxy) (x, y);
} }
void void
grub_cls (void) grub_cls (void)
{ {
if (!grub_cur_term_output)
return;
if ((grub_cur_term_output->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug"))) if ((grub_cur_term_output->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
{ {
grub_putchar ('\n'); grub_putchar ('\n');
@ -189,20 +200,29 @@ grub_cls (void)
void void
grub_setcolorstate (grub_term_color_state state) grub_setcolorstate (grub_term_color_state state)
{ {
if (grub_cur_term_output && grub_cur_term_output->setcolorstate) if (!grub_cur_term_output)
return;
if (grub_cur_term_output->setcolorstate)
(grub_cur_term_output->setcolorstate) (state); (grub_cur_term_output->setcolorstate) (state);
} }
void void
grub_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color) grub_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
{ {
if (grub_cur_term_output && grub_cur_term_output->setcolor) if (!grub_cur_term_output)
return;
if (grub_cur_term_output->setcolor)
(grub_cur_term_output->setcolor) (normal_color, highlight_color); (grub_cur_term_output->setcolor) (normal_color, highlight_color);
} }
void void
grub_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color) grub_getcolor (grub_uint8_t *normal_color, grub_uint8_t *highlight_color)
{ {
if (!grub_cur_term_output)
return;
if (grub_cur_term_output->getcolor) if (grub_cur_term_output->getcolor)
(grub_cur_term_output->getcolor) (normal_color, highlight_color); (grub_cur_term_output->getcolor) (normal_color, highlight_color);
} }
@ -212,7 +232,7 @@ grub_setcursor (int on)
{ {
int ret = cursor_state; int ret = cursor_state;
if (grub_cur_term_output->setcursor) if (grub_cur_term_output && grub_cur_term_output->setcursor)
{ {
(grub_cur_term_output->setcursor) (on); (grub_cur_term_output->setcursor) (on);
cursor_state = on; cursor_state = on;
@ -230,7 +250,7 @@ grub_getcursor (void)
void void
grub_refresh (void) grub_refresh (void)
{ {
if (grub_cur_term_output->refresh) if (grub_cur_term_output && grub_cur_term_output->refresh)
(grub_cur_term_output->refresh) (); (grub_cur_term_output->refresh) ();
} }

View file

@ -18,8 +18,8 @@
#include <grub/machine/machine.h> #include <grub/machine/machine.h>
#include <grub/machine/memory.h> #include <grub/machine/memory.h>
#include <grub/machine/serial.h> #include <grub/serial.h>
#include <grub/machine/console.h> //#include <grub/machine/console.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/types.h> #include <grub/types.h>
#include <grub/dl.h> #include <grub/dl.h>
@ -67,6 +67,9 @@ static struct serial_port serial_settings;
#ifdef GRUB_MACHINE_PCBIOS #ifdef GRUB_MACHINE_PCBIOS
static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR; static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
#define GRUB_SERIAL_PORT_NUM 4 #define GRUB_SERIAL_PORT_NUM 4
#elif defined (GRUB_MACHINE_MIPS_QEMU)
static const grub_port_t serial_hw_io_addr[] = { 0x140003f8 };
#define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr))
#else #else
static const grub_port_t serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; static const grub_port_t serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
#define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr)) #define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr))
@ -149,7 +152,7 @@ serial_translate_key_sequence (void)
if (input_buf[0] != '\e' || input_buf[1] != '[') if (input_buf[0] != '\e' || input_buf[1] != '[')
return; return;
for (i = 0; ARRAY_SIZE (three_code_table); i++) for (i = 0; i < ARRAY_SIZE (three_code_table); i++)
if (three_code_table[i].key == input_buf[2]) if (three_code_table[i].key == input_buf[2])
{ {
input_buf[0] = three_code_table[i].ascii; input_buf[0] = three_code_table[i].ascii;
@ -254,6 +257,9 @@ grub_serial_getkey (void)
; ;
c = input_buf[0]; c = input_buf[0];
if (c == 0x7f)
c = GRUB_TERM_BACKSPACE;
grub_memmove (input_buf, input_buf + 1, --npending); grub_memmove (input_buf, input_buf + 1, --npending);
return c; return c;