From 74eea126f472abc82268d937a26d7367e75e9369 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 18 Jan 2011 15:28:44 +0100 Subject: [PATCH] fuloong support --- grub-core/boot/mips/yeeloong/fwstart.S | 3 ++ grub-core/kern/mips/startup.S | 3 ++ grub-core/kern/mips/yeeloong/init.c | 7 +++-- grub-core/loader/mips/linux.c | 40 +++++++++++++++----------- grub-core/term/serial.c | 16 ++++++++--- include/grub/mips/yeeloong/kernel.h | 5 ++++ include/grub/mips/yeeloong/serial.h | 9 ++++-- include/grub/term.h | 16 +++++++++++ 8 files changed, 74 insertions(+), 25 deletions(-) diff --git a/grub-core/boot/mips/yeeloong/fwstart.S b/grub-core/boot/mips/yeeloong/fwstart.S index 425458401..4c2fe5543 100644 --- a/grub-core/boot/mips/yeeloong/fwstart.S +++ b/grub-core/boot/mips/yeeloong/fwstart.S @@ -25,6 +25,9 @@ #include #include +#define GRUB_MACHINE_SERIAL_PORT GRUB_MACHINE_SERIAL_PORT0 +#define GRUB_MACHINE_SERIAL_DIVISOR_115200 GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 + .set noreorder .set noat .set nomacro diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S index ae0e0b187..4bf4c1762 100644 --- a/grub-core/kern/mips/startup.S +++ b/grub-core/kern/mips/startup.S @@ -20,6 +20,7 @@ #include #include #include +#include #include #define BASE_ADDR 8 @@ -59,6 +60,8 @@ VARIABLE (grub_arch_memsize) .long 0 VARIABLE (grub_arch_highmemsize) .long 0 +VARIABLE (grub_arch_machine) + .long GRUB_ARCH_MACHINE_FULOONG #endif cont: /* Save our base. */ diff --git a/grub-core/kern/mips/yeeloong/init.c b/grub-core/kern/mips/yeeloong/init.c index f42c9696d..6787a205d 100644 --- a/grub-core/kern/mips/yeeloong/init.c +++ b/grub-core/kern/mips/yeeloong/init.c @@ -208,8 +208,11 @@ grub_machine_init (void) grub_font_init (); grub_gfxterm_init (); - grub_keylayouts_init (); - grub_at_keyboard_init (); + if (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) + { + grub_keylayouts_init (); + grub_at_keyboard_init (); + } grub_terminfo_init (); grub_serial_init (); diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 6ae2a9321..244d2b8a3 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -33,11 +33,13 @@ #include #ifdef GRUB_MACHINE_MIPS_YEELOONG -/* This can be detected on runtime from PMON, but: - a) it wouldn't work when GRUB is the firmware - and - b) for now we only support Yeeloong anyway. */ -#define LOONGSON_MACHTYPE "machtype=lemote-yeeloong-2f-8.9inches" +#include + +const char loongson_machtypes[][60] = + { + [GRUB_ARCH_MACHINE_YEELOONG] = "machtype=lemote-yeeloong-2f-8.9inches", + [GRUB_ARCH_MACHINE_FULOONG] = "machtype=lemote-fuloong-2f-unknown" + }; #endif static grub_dl_t my_mod; @@ -222,7 +224,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* For arguments. */ linux_argc = argc; -#ifdef LOONGSON_MACHTYPE +#ifdef GRUB_MACHINE_MIPS_YEELOONG linux_argc++; #endif /* Main arguments. */ @@ -237,8 +239,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), /* Normal arguments. */ for (i = 1; i < argc; i++) size += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); -#ifdef LOONGSON_MACHTYPE - size += ALIGN_UP (sizeof (LOONGSON_MACHTYPE), 4); +#ifdef GRUB_MACHINE_MIPS_YEELOONG + size += ALIGN_UP (sizeof (loongson_machtypes[0]), 4); #endif /* rd arguments. */ @@ -277,14 +279,20 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_argv++; linux_args += ALIGN_UP (sizeof ("a0"), 4); -#ifdef LOONGSON_MACHTYPE - /* In Loongson platform, it is the responsibility of the bootloader/firmware - to supply the OS kernel with machine type information. */ - grub_memcpy (linux_args, LOONGSON_MACHTYPE, sizeof (LOONGSON_MACHTYPE)); - *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground - + target_addr; - linux_argv++; - linux_args += ALIGN_UP (sizeof (LOONGSON_MACHTYPE), 4); +#ifdef GRUB_MACHINE_MIPS_YEELOONG + { + unsigned mtype = grub_arch_machine; + if (mtype >= ARRAY_SIZE (loongson_machtypes)) + mtype = 0; + /* In Loongson platform, it is the responsibility of the bootloader/firmware + to supply the OS kernel with machine type information. */ + grub_memcpy (linux_args, loongson_machtypes[mtype], + sizeof (loongson_machtypes[mtype])); + *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground + + target_addr; + linux_argv++; + linux_args += ALIGN_UP (sizeof (loongson_machtypes[mtype]), 4); + } #endif for (i = 1; i < argc; i++) diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index e672a89d6..aca5769fd 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -26,6 +26,9 @@ #include #include #include +#ifdef GRUB_MACHINE_MIPS_YEELOONG +#include +#endif #define FOR_SERIAL_PORTS(var) FOR_LIST_ELEMENTS((var), (grub_serial_ports)) @@ -296,17 +299,22 @@ grub_serial_register (struct grub_serial_port *port) port->term_out = out; grub_terminfo_output_register (out, "vt100"); #ifdef GRUB_MACHINE_MIPS_YEELOONG - if (grub_strcmp (port->name, "com0") == 0) + if (grub_strcmp (port->name, + (grub_arch_machine == GRUB_ARCH_MACHINE_YEELOONG) + ? "com0" : "com2") == 0) { grub_term_register_input_active ("serial_*", in); grub_term_register_output_active ("serial_*", out); } else -#endif { - grub_term_register_input ("serial_*", in); - grub_term_register_output ("serial_*", out); + grub_term_register_input_inactive ("serial_*", in); + grub_term_register_output_inactive ("serial_*", out); } +#else + grub_term_register_input ("serial_*", in); + grub_term_register_output ("serial_*", out); +#endif return GRUB_ERR_NONE; } diff --git a/include/grub/mips/yeeloong/kernel.h b/include/grub/mips/yeeloong/kernel.h index 15cf9f9fd..857b37a15 100644 --- a/include/grub/mips/yeeloong/kernel.h +++ b/include/grub/mips/yeeloong/kernel.h @@ -21,11 +21,16 @@ #include +#define GRUB_ARCH_MACHINE_YEELOONG 0 +#define GRUB_ARCH_MACHINE_FULOONG 1 + #ifndef ASM_FILE void EXPORT_FUNC (grub_reboot) (void) __attribute__ ((noreturn)); void EXPORT_FUNC (grub_halt) (void) __attribute__ ((noreturn)); +extern grub_uint32_t EXPORT_VAR (grub_arch_machine); + #endif #endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/mips/yeeloong/serial.h b/include/grub/mips/yeeloong/serial.h index ebe3638a1..45e6d8457 100644 --- a/include/grub/mips/yeeloong/serial.h +++ b/include/grub/mips/yeeloong/serial.h @@ -19,11 +19,14 @@ #ifndef GRUB_MACHINE_SERIAL_HEADER #define GRUB_MACHINE_SERIAL_HEADER 1 -#define GRUB_MACHINE_SERIAL_DIVISOR_115200 2 -#define GRUB_MACHINE_SERIAL_PORT 0xbff003f8 +#define GRUB_MACHINE_SERIAL_PORT0_DIVISOR_115200 2 +#define GRUB_MACHINE_SERIAL_PORT2_DIVISOR_115200 1 +#define GRUB_MACHINE_SERIAL_PORT0 0xbff003f8 +#define GRUB_MACHINE_SERIAL_PORT1 0xbfd003f8 +#define GRUB_MACHINE_SERIAL_PORT2 0xbfd002f8 #ifndef ASM_FILE -#define GRUB_MACHINE_SERIAL_PORTS { GRUB_MACHINE_SERIAL_PORT } +#define GRUB_MACHINE_SERIAL_PORTS { GRUB_MACHINE_SERIAL_PORT0, GRUB_MACHINE_SERIAL_PORT1, GRUB_MACHINE_SERIAL_PORT2 } #else #endif diff --git a/include/grub/term.h b/include/grub/term.h index dbcb2f52c..e9efc3f84 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -251,6 +251,14 @@ grub_term_register_input (const char *name __attribute__ ((unused)), } } +static inline void +grub_term_register_input_inactive (const char *name __attribute__ ((unused)), + grub_term_input_t term) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled), + GRUB_AS_LIST (term)); +} + static inline void grub_term_register_input_active (const char *name __attribute__ ((unused)), grub_term_input_t term) @@ -275,6 +283,14 @@ grub_term_register_output (const char *name __attribute__ ((unused)), } } +static inline void +grub_term_register_output_inactive (const char *name __attribute__ ((unused)), + grub_term_output_t term) +{ + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled), + GRUB_AS_LIST (term)); +} + static inline void grub_term_register_output_active (const char *name __attribute__ ((unused)), grub_term_output_t term)