Skip to content

Commit 35a2472

Browse files
Ming Wangk-hagio
Ming Wang
authored andcommitted
Add LoongArch64 framework code support
Mainly added some environment configurations, macro definitions, specific architecture structures and some function declarations supported by the LoongArch64 architecture. Co-developed-by: Youling Tang <[email protected]> Signed-off-by: Youling Tang <[email protected]> Signed-off-by: Ming Wang <[email protected]>
1 parent 28891d1 commit 35a2472

11 files changed

+13162
-10
lines changed

Diff for: Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
6565
kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
6666
printk.c \
6767
alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
68-
arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
68+
arm.c arm64.c mips.c mips64.c riscv64.c loongarch64.c sparc64.c \
6969
extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
7070
lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
7171
lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -85,7 +85,7 @@ OBJECT_FILES=main.o tools.o global_data.o memory.o filesys.o help.o task.o \
8585
build_data.o kernel.o test.o gdb_interface.o net.o dev.o bpf.o \
8686
printk.o \
8787
alpha.o x86.o ppc.o ia64.o s390.o s390x.o s390dbf.o ppc64.o x86_64.o \
88-
arm.o arm64.o mips.o mips64.o riscv64.o sparc64.o \
88+
arm.o arm64.o mips.o mips64.o riscv64.o loongarch64.o sparc64.o \
8989
extensions.o remote.o va_server.o va_server_v1.o symbols.o cmdline.o \
9090
lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \
9191
lkcd_fix_mem.o s390_dump.o netdump.o diskdump.o makedumpfile.o xendump.o \
@@ -445,6 +445,9 @@ riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
445445
sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
446446
${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
447447

448+
loongarch64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} loongarch64.c
449+
${CC} -c ${CRASH_CFLAGS} loongarch64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
450+
448451
s390.o: ${GENERIC_HFILES} ${IBM_HFILES} s390.c
449452
${CC} -c ${CRASH_CFLAGS} s390.c ${WARNING_OPTIONS} ${WARNING_ERROR}
450453

Diff for: configure.c

+42-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void add_extra_lib(char *);
108108
#undef SPARC64
109109
#undef MIPS64
110110
#undef RISCV64
111+
#undef LOONGARCH64
111112

112113
#define UNKNOWN 0
113114
#define X86 1
@@ -124,6 +125,7 @@ void add_extra_lib(char *);
124125
#define SPARC64 12
125126
#define MIPS64 13
126127
#define RISCV64 14
128+
#define LOONGARCH64 15
127129

128130
#define TARGET_X86 "TARGET=X86"
129131
#define TARGET_ALPHA "TARGET=ALPHA"
@@ -139,6 +141,7 @@ void add_extra_lib(char *);
139141
#define TARGET_MIPS64 "TARGET=MIPS64"
140142
#define TARGET_SPARC64 "TARGET=SPARC64"
141143
#define TARGET_RISCV64 "TARGET=RISCV64"
144+
#define TARGET_LOONGARCH64 "TARGET=LOONGARCH64"
142145

143146
#define TARGET_CFLAGS_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
144147
#define TARGET_CFLAGS_ALPHA "TARGET_CFLAGS="
@@ -163,6 +166,8 @@ void add_extra_lib(char *);
163166
#define TARGET_CFLAGS_SPARC64 "TARGET_CFLAGS="
164167
#define TARGET_CFLAGS_RISCV64 "TARGET_CFLAGS="
165168
#define TARGET_CFLAGS_RISCV64_ON_X86_64 "TARGET_CFLAGS="
169+
#define TARGET_CFLAGS_LOONGARCH64 "TARGET_CFLAGS="
170+
#define TARGET_CFLAGS_LOONGARCH64_ON_X86_64 "TARGET_CFLAGS="
166171

167172
#define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS="
168173
#define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -174,6 +179,7 @@ void add_extra_lib(char *);
174179
#define GDB_TARGET_MIPS_ON_X86 "GDB_CONF_FLAGS=--target=mipsel-elf-linux"
175180
#define GDB_TARGET_MIPS_ON_X86_64 "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32"
176181
#define GDB_TARGET_RISCV64_ON_X86_64 "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu"
182+
#define GDB_TARGET_LOONGARCH64_ON_X86_64 "GDB_CONF_FLAGS=--target=loongarch64-unknown-linux-gnu"
177183

178184
/*
179185
* The original plan was to allow the use of a particular version
@@ -413,6 +419,9 @@ get_current_configuration(struct supported_gdb_version *sp)
413419
#if defined(__riscv) && (__riscv_xlen == 64)
414420
target_data.target = RISCV64;
415421
#endif
422+
#ifdef __loongarch64
423+
target_data.target = LOONGARCH64;
424+
#endif
416425

417426
set_initial_target(sp);
418427

@@ -472,6 +481,12 @@ get_current_configuration(struct supported_gdb_version *sp)
472481
* Build an RISCV64 crash binary on an X86_64 host.
473482
*/
474483
target_data.target = RISCV64;
484+
} else if ((target_data.target == X86_64) &&
485+
(name_to_target((char *)target_data.target_as_param) == LOONGARCH64)) {
486+
/*
487+
* Build an LOONGARCH64 crash binary on an X86_64 host.
488+
*/
489+
target_data.target = LOONGARCH64;
475490
} else {
476491
fprintf(stderr,
477492
"\ntarget=%s is not supported on the %s host architecture\n\n",
@@ -512,6 +527,14 @@ get_current_configuration(struct supported_gdb_version *sp)
512527
(target_data.target != MIPS64))
513528
arch_mismatch(sp);
514529

530+
if ((target_data.initial_gdb_target == LOONGARCH64) &&
531+
(target_data.target != LOONGARCH64)) {
532+
if (target_data.target == X86_64)
533+
target_data.target = LOONGARCH64;
534+
else
535+
arch_mismatch(sp);
536+
}
537+
515538
if ((target_data.initial_gdb_target == RISCV64) &&
516539
(target_data.target != RISCV64)) {
517540
if (target_data.target == X86_64)
@@ -686,6 +709,9 @@ show_configuration(void)
686709
case RISCV64:
687710
printf("TARGET: RISCV64\n");
688711
break;
712+
case LOONGARCH64:
713+
printf("TARGET: LOONGARCH64\n");
714+
break;
689715
}
690716

691717
if (strlen(target_data.program)) {
@@ -811,6 +837,14 @@ build_configure(struct supported_gdb_version *sp)
811837
} else
812838
target_CFLAGS = TARGET_CFLAGS_RISCV64;
813839
break;
840+
case LOONGARCH64:
841+
target = TARGET_LOONGARCH64;
842+
if (target_data.host == X86_64) {
843+
target_CFLAGS = TARGET_CFLAGS_LOONGARCH64_ON_X86_64;
844+
gdb_conf_flags = GDB_TARGET_LOONGARCH64_ON_X86_64;
845+
} else
846+
target_CFLAGS = TARGET_CFLAGS_LOONGARCH64;
847+
break;
814848
}
815849

816850
ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1408,7 +1442,7 @@ make_spec_file(struct supported_gdb_version *sp)
14081442
printf("Vendor: Red Hat, Inc.\n");
14091443
printf("Packager: Dave Anderson <[email protected]>\n");
14101444
printf("ExclusiveOS: Linux\n");
1411-
printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
1445+
printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64 loongarch64\n");
14121446
printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
14131447
printf("BuildRequires: ncurses-devel zlib-devel bison\n");
14141448
printf("Requires: binutils\n");
@@ -1649,6 +1683,8 @@ set_initial_target(struct supported_gdb_version *sp)
16491683
target_data.initial_gdb_target = SPARC64;
16501684
else if (strncmp(buf, "RISCV64", strlen("RISCV64")) == 0)
16511685
target_data.initial_gdb_target = RISCV64;
1686+
else if (strncmp(buf, "LOONGARCH64", strlen("LOONGARCH64")) == 0)
1687+
target_data.initial_gdb_target = LOONGARCH64;
16521688
}
16531689

16541690
char *
@@ -1670,6 +1706,7 @@ target_to_name(int target)
16701706
case MIPS64: return("MIPS64");
16711707
case SPARC64: return("SPARC64");
16721708
case RISCV64: return("RISCV64");
1709+
case LOONGARCH64: return("LOONGARCH64");
16731710
}
16741711

16751712
return "UNKNOWN";
@@ -1738,6 +1775,10 @@ name_to_target(char *name)
17381775
return RISCV64;
17391776
else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
17401777
return RISCV64;
1778+
else if (strncmp(name, "loongarch64", strlen("loongarch64")) == 0)
1779+
return LOONGARCH64;
1780+
else if (strncmp(name, "LOONGARCH64", strlen("LOONGARCH64")) == 0)
1781+
return LOONGARCH64;
17411782

17421783
return UNKNOWN;
17431784
}

Diff for: defs.h

+161-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \
7777
!defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \
7878
!defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \
79-
!defined(RISCV64) && !defined(SPARC64)
79+
!defined(RISCV64) && !defined(LOONGARCH64) && !defined(SPARC64)
8080
#ifdef __alpha__
8181
#define ALPHA
8282
#endif
@@ -121,6 +121,9 @@
121121
#if defined(__riscv) && (__riscv_xlen == 64)
122122
#define RISCV64
123123
#endif
124+
#ifdef __loongarch64
125+
#define LOONGARCH64
126+
#endif
124127
#endif
125128

126129
#ifdef X86
@@ -165,6 +168,9 @@
165168
#ifdef RISCV64
166169
#define NR_CPUS (256)
167170
#endif
171+
#ifdef LOONGARCH64
172+
#define NR_CPUS (256)
173+
#endif
168174

169175
#define NR_DEVICE_DUMPS (64)
170176

@@ -3723,6 +3729,48 @@ typedef signed int s32;
37233729

37243730
#endif /* RISCV64 */
37253731

3732+
/* fix compilation errors due to elf.h version. */
3733+
#ifndef EM_LOONGARCH
3734+
#define EM_LOONGARCH 258
3735+
#endif
3736+
3737+
#ifdef LOONGARCH64
3738+
#define _64BIT_
3739+
#define MACHINE_TYPE "LOONGARCH64"
3740+
3741+
#define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask)
3742+
3743+
#define IS_XKPRANGE(X) (((X) >= 0x8000000000000000lu) && \
3744+
((X) < 0xc000000000000000lu))
3745+
3746+
#define PTOV(X) ((ulong)(X) + 0x9000000000000000lu)
3747+
#define VTOP(X) ((ulong)(X) & 0x0000fffffffffffflu)
3748+
3749+
#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start)
3750+
3751+
#define DEFAULT_MODULES_VADDR 0xffff800000000000lu
3752+
#define MODULES_VADDR (machdep->machspec->modules_vaddr)
3753+
#define MODULES_END (machdep->machspec->modules_end)
3754+
#define VMALLOC_START (machdep->machspec->vmalloc_start_addr)
3755+
#define VMALLOC_END (machdep->machspec->vmalloc_end)
3756+
3757+
#define __SWP_TYPE_SHIFT 16
3758+
#define __SWP_TYPE_BITS 8
3759+
#define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1)
3760+
#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
3761+
3762+
#define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
3763+
#define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT)
3764+
3765+
#define __swp_type(entry) SWP_TYPE(entry)
3766+
#define __swp_offset(entry) SWP_OFFSET(entry)
3767+
3768+
#define TIF_SIGPENDING (1)
3769+
3770+
#define _SECTION_SIZE_BITS 28
3771+
#define _MAX_PHYSMEM_BITS 48
3772+
#endif /* LOONGARCH64 */
3773+
37263774
#ifdef X86
37273775
#define _32BIT_
37283776
#define MACHINE_TYPE "X86"
@@ -4775,6 +4823,10 @@ struct machine_specific {
47754823
#define MAX_HEXADDR_STRLEN (16)
47764824
#define UVADDR_PRLEN (16)
47774825
#endif
4826+
#ifdef LOONGARCH64
4827+
#define MAX_HEXADDR_STRLEN (16)
4828+
#define UVADDR_PRLEN (16)
4829+
#endif
47784830

47794831
#define BADADDR ((ulong)(-1))
47804832
#define BADVAL ((ulong)(-1))
@@ -5396,6 +5448,9 @@ void dump_build_data(void);
53965448
#ifdef SPARC64
53975449
#define machdep_init(X) sparc64_init(X)
53985450
#endif
5451+
#ifdef LOONGARCH64
5452+
#define machdep_init(X) loongarch64_init(X)
5453+
#endif
53995454
int clean_exit(int);
54005455
int untrusted_file(FILE *, char *);
54015456
char *readmem_function_name(void);
@@ -5887,6 +5942,10 @@ void display_help_screen(char *);
58875942
#ifdef RISCV64
58885943
#define dump_machdep_table(X) riscv64_dump_machdep_table(X)
58895944
#endif
5945+
#ifdef LOONGARCH64
5946+
#define dump_machdep_table(X) loongarch64_dump_machdep_table(X)
5947+
#endif
5948+
58905949
extern char *help_pointer[];
58915950
extern char *help_alias[];
58925951
extern char *help_ascii[];
@@ -7109,6 +7168,107 @@ int sparc64_vmalloc_addr(ulong);
71097168
error(FATAL, "The -d option is not applicable to sparc64.\n")
71107169
#endif
71117170

7171+
/*
7172+
* loongarch64.c
7173+
*/
7174+
void loongarch64_display_regs_from_elf_notes(int, FILE *);
7175+
#ifdef LOONGARCH64
7176+
void loongarch64_init(int);
7177+
void loongarch64_dump_machdep_table(ulong);
7178+
7179+
#define display_idt_table() \
7180+
error(FATAL, "-d option is not applicable to LOONGARCH64 architecture\n")
7181+
7182+
7183+
#define KSYMS_START (0x1)
7184+
7185+
struct machine_specific {
7186+
ulong phys_base;
7187+
ulong vmalloc_start_addr;
7188+
ulong modules_vaddr;
7189+
ulong modules_end;
7190+
7191+
struct loongarch64_pt_regs *crash_task_regs;
7192+
};
7193+
7194+
/*
7195+
* Basic page table format:
7196+
*
7197+
* 63 62 61 PALEN-1 12 10 9 8 7 6 5 4 3 2 1 0
7198+
* +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+
7199+
* |RPLV|NX|NR| | PA[PALEN-1:12] | |SP|PN|W|P|G|MAT|PLV|D|V|
7200+
* +----+--+--+------+--------------------+----+--+--+-+-+-+---+---+-+-+
7201+
*
7202+
*
7203+
* Huge page table format:
7204+
*
7205+
* 63 62 61 PALEN-1 12 10 9 8 7 6 5 4 3 2 1 0
7206+
* +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+
7207+
* |RPLV|NX|NR| | PA[PALEN-1:12] | G| |SP|PN|W|P|H|MAT|PLV|D|V|
7208+
* +----+--+--+------+-----------------+--+----+--+--+-+-+-+---+---+-+-+
7209+
*
7210+
*/
7211+
/* from arch/loongarch/include/asm/pgtable-bits.h */
7212+
7213+
/* Page table bits */
7214+
#define _PAGE_VALID_SHIFT 0
7215+
#define _PAGE_ACCESSED_SHIFT 0 /* Reuse Valid for Accessed */
7216+
#define _PAGE_DIRTY_SHIFT 1
7217+
#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */
7218+
#define _CACHE_SHIFT 4 /* 4~5, two bits */
7219+
#define _PAGE_GLOBAL_SHIFT 6
7220+
#define _PAGE_HUGE_SHIFT 6 /* HUGE is a PMD bit */
7221+
#define _PAGE_PRESENT_SHIFT 7
7222+
#define _PAGE_WRITE_SHIFT 8
7223+
#define _PAGE_MODIFIED_SHIFT 9
7224+
#define _PAGE_PROTNONE_SHIFT 10
7225+
#define _PAGE_SPECIAL_SHIFT 11
7226+
#define _PAGE_HGLOBAL_SHIFT 12 /* HGlobal is a PMD bit */
7227+
#define _PAGE_PFN_SHIFT 12
7228+
#define _PAGE_SWP_EXCLUSIVE_SHIFT 23
7229+
#define _PAGE_PFN_END_SHIFT 48
7230+
#define _PAGE_PRESENT_INVALID_SHIFT 60
7231+
#define _PAGE_NO_READ_SHIFT 61
7232+
#define _PAGE_NO_EXEC_SHIFT 62
7233+
#define _PAGE_RPLV_SHIFT 63
7234+
7235+
#ifndef _ULCAST_
7236+
#define _ULCAST_ (unsigned long)
7237+
#endif
7238+
7239+
/* Used by software */
7240+
#define _PAGE_PRESENT (_ULCAST_(1) << _PAGE_PRESENT_SHIFT)
7241+
#define _PAGE_PRESENT_INVALID (_ULCAST_(1) << _PAGE_PRESENT_INVALID_SHIFT)
7242+
#define _PAGE_WRITE (_ULCAST_(1) << _PAGE_WRITE_SHIFT)
7243+
#define _PAGE_ACCESSED (_ULCAST_(1) << _PAGE_ACCESSED_SHIFT)
7244+
#define _PAGE_MODIFIED (_ULCAST_(1) << _PAGE_MODIFIED_SHIFT)
7245+
#define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT)
7246+
#define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT)
7247+
7248+
/* We borrow bit 23 to store the exclusive marker in swap PTEs. */
7249+
#define _PAGE_SWP_EXCLUSIVE (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT)
7250+
7251+
/* Used by TLB hardware (placed in EntryLo*) */
7252+
#define _PAGE_VALID (_ULCAST_(1) << _PAGE_VALID_SHIFT)
7253+
#define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT)
7254+
#define _PAGE_PLV (_ULCAST_(3) << _PAGE_PLV_SHIFT)
7255+
#define _PAGE_GLOBAL (_ULCAST_(1) << _PAGE_GLOBAL_SHIFT)
7256+
#define _PAGE_HUGE (_ULCAST_(1) << _PAGE_HUGE_SHIFT)
7257+
#define _PAGE_HGLOBAL (_ULCAST_(1) << _PAGE_HGLOBAL_SHIFT)
7258+
#define _PAGE_NO_READ (_ULCAST_(1) << _PAGE_NO_READ_SHIFT)
7259+
#define _PAGE_NO_EXEC (_ULCAST_(1) << _PAGE_NO_EXEC_SHIFT)
7260+
#define _PAGE_RPLV (_ULCAST_(1) << _PAGE_RPLV_SHIFT)
7261+
#define _CACHE_MASK (_ULCAST_(3) << _CACHE_SHIFT)
7262+
#define _PFN_SHIFT (PAGESHIFT() - 12 + _PAGE_PFN_SHIFT)
7263+
7264+
#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT)
7265+
#define _PAGE_KERN (PLV_KERN << _PAGE_PLV_SHIFT)
7266+
7267+
#define _PFN_MASK (~((_ULCAST_(1) << (_PFN_SHIFT)) - 1) & \
7268+
((_ULCAST_(1) << (_PAGE_PFN_END_SHIFT)) - 1))
7269+
7270+
#endif /* LOONGARCH64 */
7271+
71127272
/*
71137273
* netdump.c
71147274
*/

0 commit comments

Comments
 (0)