Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
d16d2be1
Commit
d16d2be1
authored
Feb 16, 2015
by
Ley Foon Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nios2: add kgdb support
Signed-off-by:
Ley Foon Tan
<
lftan@altera.com
>
parent
08c283cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
277 additions
and
1 deletion
+277
-1
arch/nios2/Kconfig
arch/nios2/Kconfig
+1
-0
arch/nios2/include/asm/kgdb.h
arch/nios2/include/asm/kgdb.h
+93
-0
arch/nios2/kernel/Makefile
arch/nios2/kernel/Makefile
+1
-0
arch/nios2/kernel/entry.S
arch/nios2/kernel/entry.S
+11
-1
arch/nios2/kernel/kgdb.c
arch/nios2/kernel/kgdb.c
+171
-0
No files found.
arch/nios2/Kconfig
View file @
d16d2be1
...
@@ -8,6 +8,7 @@ config NIOS2
...
@@ -8,6 +8,7 @@ config NIOS2
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_IRQ_SHOW
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_KGDB
select IRQ_DOMAIN
select IRQ_DOMAIN
select MODULES_USE_ELF_RELA
select MODULES_USE_ELF_RELA
select OF
select OF
...
...
arch/nios2/include/asm/kgdb.h
0 → 100644
View file @
d16d2be1
/*
* Copyright (C) 2015 Altera Corporation
* Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
*
* Based on the code posted by Kazuyasu on the Altera Forum at:
* http://www.alteraforum.com/forum/showpost.php?p=77003&postcount=20
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _ASM_NIOS2_KGDB_H
#define _ASM_NIOS2_KGDB_H
#define CACHE_FLUSH_IS_SAFE 1
#define BUFMAX 2048
enum
regnames
{
GDB_R0
=
0
,
GDB_AT
,
GDB_R2
,
GDB_R3
,
GDB_R4
,
GDB_R5
,
GDB_R6
,
GDB_R7
,
GDB_R8
,
GDB_R9
,
GDB_R10
,
GDB_R11
,
GDB_R12
,
GDB_R13
,
GDB_R14
,
GDB_R15
,
GDB_R16
,
GDB_R17
,
GDB_R18
,
GDB_R19
,
GDB_R20
,
GDB_R21
,
GDB_R22
,
GDB_R23
,
GDB_ET
,
GDB_BT
,
GDB_GP
,
GDB_SP
,
GDB_FP
,
GDB_EA
,
GDB_BA
,
GDB_RA
,
GDB_PC
,
GDB_STATUS
,
GDB_ESTATUS
,
GDB_BSTATUS
,
GDB_IENABLE
,
GDB_IPENDING
,
GDB_CPUID
,
GDB_CTL6
,
GDB_EXCEPTION
,
GDB_PTEADDR
,
GDB_TLBACC
,
GDB_TLBMISC
,
GDB_ECCINJ
,
GDB_BADADDR
,
GDB_CONFIG
,
GDB_MPUBASE
,
GDB_MPUACC
,
/* do not change the last entry or anything below! */
GDB_NUMREGBYTES
/* number of registers */
};
#define GDB_SIZEOF_REG sizeof(u32)
#define DBG_MAX_REG_NUM (49)
#define NUMREGBYTES (DBG_MAX_REG_NUM * sizeof(GDB_SIZEOF_REG))
#define BREAK_INSTR_SIZE 4
static
inline
void
arch_kgdb_breakpoint
(
void
)
{
__asm__
__volatile__
(
"trap 30
\n
"
);
}
#endif
/* _ASM_NIOS2_KGDB_H */
arch/nios2/kernel/Makefile
View file @
d16d2be1
...
@@ -21,5 +21,6 @@ obj-y += time.o
...
@@ -21,5 +21,6 @@ obj-y += time.o
obj-y
+=
traps.o
obj-y
+=
traps.o
obj-$(CONFIG_EARLY_PRINTK)
+=
early_printk.o
obj-$(CONFIG_EARLY_PRINTK)
+=
early_printk.o
obj-$(CONFIG_KGDB)
+=
kgdb.o
obj-$(CONFIG_MODULES)
+=
module.o
obj-$(CONFIG_MODULES)
+=
module.o
obj-$(CONFIG_NIOS2_ALIGNMENT_TRAP)
+=
misaligned.o
obj-$(CONFIG_NIOS2_ALIGNMENT_TRAP)
+=
misaligned.o
arch/nios2/kernel/entry.S
View file @
d16d2be1
...
@@ -121,7 +121,11 @@ trap_table:
...
@@ -121,7 +121,11 @@ trap_table:
.
word
instruction_trap
/*
27
*/
.
word
instruction_trap
/*
27
*/
.
word
instruction_trap
/*
28
*/
.
word
instruction_trap
/*
28
*/
.
word
instruction_trap
/*
29
*/
.
word
instruction_trap
/*
29
*/
.
word
instruction_trap
/*
30
*/
#ifdef CONFIG_KGDB
.
word
handle_kgdb_breakpoint
/*
30
KGDB
breakpoint
*/
#else
.
word
instruction_trap
/*
30
*/
#endif
.
word
handle_breakpoint
/*
31
*/
.
word
handle_breakpoint
/*
31
*/
.
text
.
text
...
@@ -445,6 +449,12 @@ handle_diverror:
...
@@ -445,6 +449,12 @@ handle_diverror:
call
handle_diverror_c
call
handle_diverror_c
br
ret_from_exception
br
ret_from_exception
#ifdef CONFIG_KGDB
handle_kgdb_breakpoint
:
call
kgdb_breakpoint_c
br
ret_from_exception
#endif
/*
/*
*
Beware
-
when
entering
resume
,
prev
(
the
current
task
)
is
*
Beware
-
when
entering
resume
,
prev
(
the
current
task
)
is
*
in
r4
,
next
(
the
new
task
)
is
in
r5
,
don
't change these
*
in
r4
,
next
(
the
new
task
)
is
in
r5
,
don
't change these
...
...
arch/nios2/kernel/kgdb.c
0 → 100644
View file @
d16d2be1
/*
* Nios2 KGDB support
*
* Copyright (C) 2015 Altera Corporation
* Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
*
* Based on the code posted by Kazuyasu on the Altera Forum at:
* http://www.alteraforum.com/forum/showpost.php?p=77003&postcount=20
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <linux/ptrace.h>
#include <linux/kgdb.h>
#include <linux/kdebug.h>
#include <linux/io.h>
static
int
wait_for_remote_debugger
;
struct
dbg_reg_def_t
dbg_reg_def
[
DBG_MAX_REG_NUM
]
=
{
{
"zero"
,
GDB_SIZEOF_REG
,
-
1
},
{
"at"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r1
)
},
{
"r2"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r2
)
},
{
"r3"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r3
)
},
{
"r4"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r4
)
},
{
"r5"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r5
)
},
{
"r6"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r6
)
},
{
"r7"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r7
)
},
{
"r8"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r8
)
},
{
"r9"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r9
)
},
{
"r10"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r10
)
},
{
"r11"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r11
)
},
{
"r12"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r12
)
},
{
"r13"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r13
)
},
{
"r14"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r14
)
},
{
"r15"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
r15
)
},
{
"r16"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r17"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r18"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r19"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r20"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r21"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r22"
,
GDB_SIZEOF_REG
,
-
1
},
{
"r23"
,
GDB_SIZEOF_REG
,
-
1
},
{
"et"
,
GDB_SIZEOF_REG
,
-
1
},
{
"bt"
,
GDB_SIZEOF_REG
,
-
1
},
{
"gp"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
gp
)
},
{
"sp"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
sp
)
},
{
"fp"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
fp
)
},
{
"ea"
,
GDB_SIZEOF_REG
,
-
1
},
{
"ba"
,
GDB_SIZEOF_REG
,
-
1
},
{
"ra"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
ra
)
},
{
"pc"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
ea
)
},
{
"status"
,
GDB_SIZEOF_REG
,
-
1
},
{
"estatus"
,
GDB_SIZEOF_REG
,
offsetof
(
struct
pt_regs
,
estatus
)
},
{
"bstatus"
,
GDB_SIZEOF_REG
,
-
1
},
{
"ienable"
,
GDB_SIZEOF_REG
,
-
1
},
{
"ipending"
,
GDB_SIZEOF_REG
,
-
1
},
{
"cpuid"
,
GDB_SIZEOF_REG
,
-
1
},
{
"ctl6"
,
GDB_SIZEOF_REG
,
-
1
},
{
"exception"
,
GDB_SIZEOF_REG
,
-
1
},
{
"pteaddr"
,
GDB_SIZEOF_REG
,
-
1
},
{
"tlbacc"
,
GDB_SIZEOF_REG
,
-
1
},
{
"tlbmisc"
,
GDB_SIZEOF_REG
,
-
1
},
{
"eccinj"
,
GDB_SIZEOF_REG
,
-
1
},
{
"badaddr"
,
GDB_SIZEOF_REG
,
-
1
},
{
"config"
,
GDB_SIZEOF_REG
,
-
1
},
{
"mpubase"
,
GDB_SIZEOF_REG
,
-
1
},
{
"mpuacc"
,
GDB_SIZEOF_REG
,
-
1
},
};
char
*
dbg_get_reg
(
int
regno
,
void
*
mem
,
struct
pt_regs
*
regs
)
{
if
(
regno
>=
DBG_MAX_REG_NUM
||
regno
<
0
)
return
NULL
;
if
(
dbg_reg_def
[
regno
].
offset
!=
-
1
)
memcpy
(
mem
,
(
void
*
)
regs
+
dbg_reg_def
[
regno
].
offset
,
dbg_reg_def
[
regno
].
size
);
else
memset
(
mem
,
0
,
dbg_reg_def
[
regno
].
size
);
return
dbg_reg_def
[
regno
].
name
;
}
int
dbg_set_reg
(
int
regno
,
void
*
mem
,
struct
pt_regs
*
regs
)
{
if
(
regno
>=
DBG_MAX_REG_NUM
||
regno
<
0
)
return
-
EINVAL
;
if
(
dbg_reg_def
[
regno
].
offset
!=
-
1
)
memcpy
((
void
*
)
regs
+
dbg_reg_def
[
regno
].
offset
,
mem
,
dbg_reg_def
[
regno
].
size
);
return
0
;
}
void
sleeping_thread_to_gdb_regs
(
unsigned
long
*
gdb_regs
,
struct
task_struct
*
p
)
{
memset
((
char
*
)
gdb_regs
,
0
,
NUMREGBYTES
);
gdb_regs
[
GDB_SP
]
=
p
->
thread
.
kregs
->
sp
;
gdb_regs
[
GDB_PC
]
=
p
->
thread
.
kregs
->
ea
;
}
void
kgdb_arch_set_pc
(
struct
pt_regs
*
regs
,
unsigned
long
pc
)
{
regs
->
ea
=
pc
;
}
int
kgdb_arch_handle_exception
(
int
vector
,
int
signo
,
int
err_code
,
char
*
remcom_in_buffer
,
char
*
remcom_out_buffer
,
struct
pt_regs
*
regs
)
{
char
*
ptr
;
unsigned
long
addr
;
switch
(
remcom_in_buffer
[
0
])
{
case
's'
:
case
'c'
:
/* handle the optional parameters */
ptr
=
&
remcom_in_buffer
[
1
];
if
(
kgdb_hex2long
(
&
ptr
,
&
addr
))
regs
->
ea
=
addr
;
return
0
;
}
return
-
1
;
/* this means that we do not want to exit from the handler */
}
asmlinkage
void
kgdb_breakpoint_c
(
struct
pt_regs
*
regs
)
{
/*
* The breakpoint entry code has moved the PC on by 4 bytes, so we must
* move it back. This could be done on the host but we do it here
*/
if
(
!
wait_for_remote_debugger
)
regs
->
ea
-=
4
;
else
/* pass the first trap 30 code */
wait_for_remote_debugger
=
0
;
kgdb_handle_exception
(
30
,
SIGTRAP
,
0
,
regs
);
}
int
kgdb_arch_init
(
void
)
{
wait_for_remote_debugger
=
1
;
return
0
;
}
void
kgdb_arch_exit
(
void
)
{
/* Nothing to do */
}
struct
kgdb_arch
arch_kgdb_ops
=
{
/* Breakpoint instruction: trap 30 */
.
gdb_bpt_instr
=
{
0xba
,
0x6f
,
0x3b
,
0x00
},
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment