Skip to content

Commit 61a3db3

Browse files
heiherchenx97
authored andcommitted
mips64: Add support for 64-bit MIPS.
1 parent 6015952 commit 61a3db3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1664
-30
lines changed

configure.ac

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ case "$target_cpu" in
109109
i[[3456]]86) target_cpu=i386 ;;
110110
amd64) target_cpu=x86_64 ;;
111111
sparc) target_cpu=sparc64 ;;
112-
mipsel|mips64el)
112+
mips64el)
113+
target_cpu=mips64el
114+
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS64EL=1"
115+
;;
116+
mipsel)
113117
target_cpu=mipsel
114118
machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1"
115119
;;
@@ -140,6 +144,7 @@ if test "x$with_platform" = x; then
140144
powerpc64-*) platform=ieee1275 ;;
141145
powerpc64le-*) platform=ieee1275 ;;
142146
sparc64-*) platform=ieee1275 ;;
147+
mips64el-*) platform=efi;;
143148
mipsel-*) platform=loongson ;;
144149
mips-*) platform=arc ;;
145150
ia64-*) platform=efi ;;
@@ -192,6 +197,7 @@ case "$target_cpu"-"$platform" in
192197
mipsel-yeeloong) platform=loongson ;;
193198
mipsel-fuloong) platform=loongson ;;
194199
mipsel-loongson) ;;
200+
mips64el-efi) ;;
195201
arm-uboot) ;;
196202
arm-coreboot) ;;
197203
arm-efi) ;;
@@ -1390,10 +1396,15 @@ grub_CHECK_PIC
13901396
# movk's which aren't representable.
13911397
# Since default varies across dictributions use either -fPIC or -fno-PIC
13921398
# explicitly.
1393-
if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel || test x$target_cpu = xarm64 ) && test "x$grub_cv_cc_target_clang" = xyes ; then
1399+
if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel || test x$target_cpu = xarm64 || test x$target_cpu = xmips64el ) && test "x$grub_cv_cc_target_clang" = xyes ; then
13941400
TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
13951401
elif [ x"$pic_possible" = xyes ]; then
13961402
TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
1403+
fi
1404+
# Don't generate SVR4-style position-independent code for MIPS64.
1405+
if test x$target_cpu = xmips64el ; then
1406+
TARGET_CFLAGS="$TARGET_CFLAGS -mno-abicalls"
1407+
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-abicalls"
13971408
fi]
13981409

13991410
CFLAGS="$TARGET_CFLAGS"
@@ -2143,6 +2154,8 @@ AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen]
21432154
AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh])
21442155
AM_CONDITIONAL([COND_loongarch64], [test x$target_cpu = xloongarch64])
21452156
AM_CONDITIONAL([COND_loongarch64_efi], [test x$target_cpu = xloongarch64 -a x$platform = xefi])
2157+
AM_CONDITIONAL([COND_mips64el], [test x$target_cpu = xmips64el])
2158+
AM_CONDITIONAL([COND_mips64_efi], [test x$target_cpu = xmips64el -a x$platform = xefi])
21462159
AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
21472160
AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xarc])
21482161
AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
@@ -2208,7 +2221,9 @@ AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
22082221
# Output files.
22092222
if test "$platform" != none; then
22102223
cpudir="${target_cpu}"
2211-
if test x${cpudir} = xmipsel; then
2224+
if test x${cpudir} = xmips64el; then
2225+
cpudir=mips64;
2226+
elif test x${cpudir} = xmipsel; then
22122227
cpudir=mips;
22132228
fi
22142229
grub_CHECK_LINK_DIR

gentpl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
3030
"i386_multiboot", "i386_ieee1275", "x86_64_efi",
3131
"i386_xen", "x86_64_xen", "i386_xen_pvh",
32-
"mips_loongson", "sparc64_ieee1275",
32+
"mips_loongson", "mips64_efi", "sparc64_ieee1275",
3333
"powerpc_ieee1275", "mips_arc", "ia64_efi",
3434
"mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
3535
"arm_coreboot", "loongarch64_efi", "riscv32_efi", "riscv64_efi" ]
@@ -43,6 +43,7 @@
4343
GROUPS["x86_64"] = [ "x86_64_efi" ]
4444
GROUPS["x86"] = GROUPS["i386"] + GROUPS["x86_64"]
4545
GROUPS["mips"] = [ "mips_loongson", "mips_qemu_mips", "mips_arc" ]
46+
GROUPS["mips64"] = [ "mips64_efi" ]
4647
GROUPS["sparc64"] = [ "sparc64_ieee1275" ]
4748
GROUPS["powerpc"] = [ "powerpc_ieee1275" ]
4849
GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
@@ -52,7 +53,7 @@
5253
GROUPS["riscv64"] = [ "riscv64_efi" ]
5354

5455
# Groups based on firmware
55-
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi",
56+
GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", "mips64_efi",
5657
"loongarch64_efi", "riscv32_efi", "riscv64_efi" ]
5758
GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
5859
GROUPS["uboot"] = [ "arm_uboot" ]

grub-core/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
239239
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
240240
endif
241241

242+
if COND_mips64_efi
243+
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
244+
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
245+
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
246+
endif
247+
242248
if COND_powerpc_ieee1275
243249
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
244250
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/alloc.h

grub-core/Makefile.core.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ kernel = {
113113
arm_coreboot_ldflags = '-Wl,-r';
114114
arm_coreboot_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version';
115115

116+
mips64_efi_ldflags = '-Wl,-r,-d';
117+
mips64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame -R .MIPS.abiflags';
118+
116119
i386_pc_startup = kern/i386/pc/startup.S;
117120
i386_efi_startup = kern/i386/efi/startup.S;
118121
x86_64_efi_startup = kern/x86_64/efi/startup.S;
@@ -124,6 +127,7 @@ kernel = {
124127
i386_coreboot_startup = kern/i386/coreboot/startup.S;
125128
i386_multiboot_startup = kern/i386/coreboot/startup.S;
126129
mips_startup = kern/mips/startup.S;
130+
mips64_efi_startup = kern/mips64/efi/startup.S;
127131
sparc64_ieee1275_startup = kern/sparc64/ieee1275/crt0.S;
128132
powerpc_ieee1275_startup = kern/powerpc/ieee1275/startup.S;
129133
arm_uboot_startup = kern/arm/startup.S;
@@ -328,6 +332,12 @@ kernel = {
328332
extra_dist = video/sis315_init.c;
329333
mips_loongson = commands/keylayouts.c;
330334

335+
mips64 = kern/mips64/init.c;
336+
mips64 = kern/mips64/dl.c;
337+
mips64 = kern/mips64/cache.S;
338+
mips64 = kern/generic/rtc_get_time_ms.c;
339+
mips64_efi = kern/mips64/efi/init.c;
340+
331341
powerpc_ieee1275 = kern/powerpc/cache.S;
332342
powerpc_ieee1275 = kern/powerpc/dl.c;
333343
powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
@@ -850,6 +860,7 @@ module = {
850860
enable = sparc64_ieee1275;
851861
enable = powerpc_ieee1275;
852862
enable = mips_arc;
863+
enable = mips64_efi;
853864
enable = ia64_efi;
854865
enable = arm_efi;
855866
enable = arm64_efi;
@@ -1711,6 +1722,8 @@ module = {
17111722
efi = lib/efi/relocator.c;
17121723
mips = lib/mips/relocator_asm.S;
17131724
mips = lib/mips/relocator.c;
1725+
mips64 = lib/mips64/relocator_asm.S;
1726+
mips64 = lib/mips64/relocator.c;
17141727
powerpc = lib/powerpc/relocator_asm.S;
17151728
powerpc = lib/powerpc/relocator.c;
17161729
xen = lib/xen/relocator.c;
@@ -1723,6 +1736,7 @@ module = {
17231736
extra_dist = kern/powerpc/cache_flush.S;
17241737

17251738
enable = mips;
1739+
enable = mips64;
17261740
enable = powerpc;
17271741
enable = x86;
17281742
enable = i386_xen_pvh;
@@ -1854,6 +1868,7 @@ module = {
18541868
i386_pc = lib/i386/pc/vesa_modes_table.c;
18551869
i386_xen_pvh = lib/i386/pc/vesa_modes_table.c;
18561870
mips = loader/mips/linux.c;
1871+
mips64 = loader/mips64/linux.c;
18571872
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
18581873
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
18591874
ia64_efi = loader/ia64/efi/linux.c;
@@ -1964,6 +1979,7 @@ module = {
19641979
enable = riscv32_efi;
19651980
enable = riscv64_efi;
19661981
enable = mips;
1982+
enable = mips64_efi;
19671983
};
19681984

19691985
module = {

grub-core/kern/mips64/cache.S

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* GRUB -- GRand Unified Bootloader
3+
* Copyright (C) 2009,2017 Free Software Foundation, Inc.
4+
*
5+
* GRUB is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* GRUB is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include <grub/symbol.h>
20+
21+
FUNCTION (grub_arch_sync_caches)
22+
jr.hb $ra

grub-core/kern/mips64/dl.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* dl-mips64.c - arch-dependent part of loadable module support */
2+
/*
3+
* GRUB -- GRand Unified Bootloader
4+
* Copyright (C) 2002,2005,2007,2009,2017 Free Software Foundation, Inc.
5+
*
6+
* GRUB is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* GRUB is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <grub/dl.h>
21+
#include <grub/elf.h>
22+
#include <grub/misc.h>
23+
#include <grub/err.h>
24+
#include <grub/cpu/types.h>
25+
#include <grub/mm.h>
26+
#include <grub/i18n.h>
27+
28+
/* Check if EHDR is a valid ELF header. */
29+
grub_err_t
30+
grub_arch_dl_check_header (void *ehdr)
31+
{
32+
Elf_Ehdr *e = ehdr;
33+
34+
/* Check the magic numbers. */
35+
#ifdef GRUB_CPU_WORDS_BIGENDIAN
36+
if (e->e_ident[EI_CLASS] != ELFCLASS64
37+
|| e->e_ident[EI_DATA] != ELFDATA2MSB
38+
|| e->e_machine != EM_MIPS)
39+
#else
40+
if (e->e_ident[EI_CLASS] != ELFCLASS64
41+
|| e->e_ident[EI_DATA] != ELFDATA2LSB
42+
|| e->e_machine != EM_MIPS)
43+
#endif
44+
return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic"));
45+
46+
return GRUB_ERR_NONE;
47+
}
48+
49+
#pragma GCC diagnostic ignored "-Wcast-align"
50+
51+
grub_err_t
52+
grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
53+
grub_size_t *tramp, grub_size_t *got)
54+
{
55+
*tramp = 0;
56+
*got = 0;
57+
return GRUB_ERR_NONE;
58+
}
59+
60+
/* Relocate symbols. */
61+
grub_err_t
62+
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
63+
Elf_Shdr *s, grub_dl_segment_t seg)
64+
{
65+
Elf_Ehdr *e = ehdr;
66+
Elf_Rel *rel, *max;
67+
68+
for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
69+
max = (Elf_Rel *) ((char *) rel + s->sh_size);
70+
rel < max;
71+
rel = (Elf_Rel *) ((char *) rel + s->sh_entsize))
72+
{
73+
grub_uint8_t *addr;
74+
Elf_Sym *sym;
75+
Elf_Addr r_info;
76+
grub_uint64_t sym_value;
77+
78+
if (seg->size < rel->r_offset)
79+
return grub_error (GRUB_ERR_BAD_MODULE,
80+
"reloc offset is out of the segment");
81+
82+
r_info = ((grub_uint64_t) rel->r_info << 32) |
83+
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
84+
85+
addr = (grub_uint8_t *) ((char *) seg->addr + rel->r_offset);
86+
sym = (Elf_Sym *) ((char *) mod->symtab
87+
+ mod->symsize * ELF_R_SYM (r_info));
88+
sym_value = sym->st_value;
89+
if (s->sh_type == SHT_RELA)
90+
{
91+
sym_value += ((Elf_Rela *) rel)->r_addend;
92+
}
93+
switch (ELF_R_TYPE (r_info))
94+
{
95+
case R_MIPS_64:
96+
*(grub_uint64_t *) addr += sym_value;
97+
break;
98+
case R_MIPS_32:
99+
*(grub_uint32_t *) addr += sym_value;
100+
break;
101+
case R_MIPS_26:
102+
{
103+
grub_uint32_t value;
104+
grub_uint32_t raw;
105+
raw = (*(grub_uint32_t *) addr) & 0x3ffffff;
106+
value = raw << 2;
107+
value += sym_value;
108+
raw = (value >> 2) & 0x3ffffff;
109+
110+
*(grub_uint32_t *) addr =
111+
raw | ((*(grub_uint32_t *) addr) & 0xfc000000);
112+
}
113+
break;
114+
case R_MIPS_LO16:
115+
#ifdef GRUB_CPU_WORDS_BIGENDIAN
116+
addr += 2;
117+
#endif
118+
*(grub_uint16_t *) addr = (grub_int16_t) sym_value;
119+
break;
120+
case R_MIPS_HI16:
121+
#ifdef GRUB_CPU_WORDS_BIGENDIAN
122+
addr += 2;
123+
#endif
124+
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x8000UL) >> 16);
125+
break;
126+
case R_MIPS_HIGHER:
127+
#ifdef GRUB_CPU_WORDS_BIGENDIAN
128+
addr += 2;
129+
#endif
130+
*(grub_uint16_t *) addr = (grub_int16_t) ((sym_value + 0x80008000UL) >> 32);
131+
break;
132+
case R_MIPS_HIGHEST:
133+
#ifdef GRUB_CPU_WORDS_BIGENDIAN
134+
addr += 2;
135+
#endif
136+
*(grub_uint16_t *) addr = (grub_uint16_t) ((sym_value + 0x800080008000UL) >> 48);
137+
break;
138+
default:
139+
{
140+
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
141+
N_("relocation 0x%x is not implemented yet"),
142+
ELF_R_TYPE (r_info));
143+
}
144+
break;
145+
}
146+
}
147+
148+
return GRUB_ERR_NONE;
149+
}

grub-core/kern/mips64/efi/init.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* init.c - initialize an arm-based EFI system */
2+
/*
3+
* GRUB -- GRand Unified Bootloader
4+
* Copyright (C) 2013 Free Software Foundation, Inc.
5+
*
6+
* GRUB is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* GRUB is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <grub/env.h>
21+
#include <grub/kernel.h>
22+
#include <grub/misc.h>
23+
#include <grub/mm.h>
24+
#include <grub/cpu/time.h>
25+
#include <grub/efi/efi.h>
26+
#include <grub/loader.h>
27+
28+
void
29+
grub_machine_init (void)
30+
{
31+
grub_efi_init ();
32+
33+
/* FIXME: Get cpuclock from EFI. */
34+
grub_timer_init (1000000000U);
35+
}
36+
37+
void
38+
grub_machine_fini (int flags)
39+
{
40+
if (!(flags & GRUB_LOADER_FLAG_NORETURN))
41+
return;
42+
43+
grub_efi_fini ();
44+
}

0 commit comments

Comments
 (0)