Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 4389 → Rev 4390

/branches/tracing/kernel/arch/amd64/include/cpu.h
77,6 → 77,10
extern uint64_t read_efer_flag(void);
void cpu_setup_fpu(void);
 
#define DR6_BT (1<<15)
#define DR6_BS (1<<14)
#define DR6_BD (1<<13)
 
#endif /* __ASM__ */
 
#endif
/branches/tracing/kernel/arch/amd64/include/drivers
0,0 → 1,0
link ../../ia32/include/drivers
Property changes:
Added: svn:special
+*
\ No newline at end of property
/branches/tracing/kernel/arch/amd64/src/debugger.c
282,7 → 282,7
* The userspace thread has TF set and executed
* an instruction
*/
udebug_trap_event(istate->eip);
udebug_trap_event(getip(istate));
return;
}
}
/branches/tracing/uspace/app/debug/cmd.c
86,7 → 86,7
(void)argc;
addr = strtoul(argv[1], NULL, 0);
 
cons_printf("You requested a breakpoint at 0x%x\n", addr);
cons_printf("You requested a breakpoint at 0x%lx\n", addr);
// arch_breakpoint_add(addr);
breakpoint_add(addr);
}
109,7 → 109,7
if (dt->id == tid) {
cwt = dt;
cons_printf("changed working thread to: %d [hash 0x%x]\n",
cons_printf("changed working thread to: %d [hash 0x%lx]\n",
cwt->id, cwt->hash);
} else {
cons_printf("no such thread\n");
195,7 → 195,7
return;
}
 
cons_printf("0x%x:", addr);
cons_printf("0x%lx:", addr);
for (i = 0; i < to_read; ++i) {
cons_printf(" %02x", buf[i]);
}
263,7 → 263,7
dt = NULL;
for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
dt = list_get_instance(cur, dthread_t, link);
cons_printf("%d [hash 0x%x]\n", dt->id, dt->hash);
cons_printf("%d [hash 0x%lx]\n", dt->id, dt->hash);
}
}
 
/branches/tracing/uspace/app/debug/main.c
51,7 → 51,7
#include "include/arch.h"
#include "main.h"
 
void thread_debug_start(unsigned thread_hash);
void thread_debug_start(thash_t thread_hash);
 
#define IN_BUF_SIZE 64
static char in_buf[IN_BUF_SIZE];
321,7 → 321,7
cons_printf("thread hashes:");
 
for (i = 0; i < *n; ++i) {
cons_printf("0x%x\n", thash_buf[i]);
cons_printf("0x%lx\n", thash_buf[i]);
}
 
cons_printf("Total of %u threads\n", *n);
331,10 → 331,10
return 0;
}
 
static void event_thread_b(unsigned hash)
static void event_thread_b(thash_t hash)
{
async_serialize_start();
cons_printf("new thread, hash 0x%x\n", hash);
cons_printf("new thread, hash 0x%lx\n", hash);
async_serialize_end();
 
thread_debug_start(hash);
370,7 → 370,7
{
int rc;
udebug_event_t ev_type;
unsigned val0, val1;
sysarg_t val0, val1;
dthread_t *dt;
 
dt = (dthread_t *)dt_arg;
378,15 → 378,18
cons_printf("debug_loop(%d)\n", dt->id);
 
while (!abort_debug) {
 
/* Run thread until an event occurs */
rc = udebug_go(app_phone, dt->hash, &ev_type, &val0, &val1);
if (rc < 0) {
cons_printf("Failed resuming thread (%d).\n", rc);
return rc;
}
 
if (ev_type == UDEBUG_EVENT_FINISHED) {
cons_printf("thread %u debugging finished\n", dt->id);
break;
}
if (rc >= 0) debug_event(dt->hash, ev_type, val0);
debug_event(dt->hash, ev_type, val0);
}
 
cons_printf("debug_loop(%d) exiting\n", dt->id);
393,7 → 396,7
return 0;
}
 
void thread_debug_start(unsigned thash)
void thread_debug_start(thash_t thash)
{
fid_t fid;
dthread_t *dt;
/branches/tracing/uspace/app/debug/arch/amd64/include/types.h
0,0 → 1,71
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup debug
* @{
*/
/** @file
*/
 
#ifndef amd64_TYPES_H_
#define amd64_TYPES_H_
 
typedef struct {
unsigned char back;
} breakpoint_arch_t;
 
typedef struct {
int singlestep;
} dthread_arch_t;
 
typedef struct {
uint64_t rax;
uint64_t rcx;
uint64_t rdx;
uint64_t rsi;
uint64_t rdi;
uint64_t r8;
uint64_t r9;
uint64_t r10;
uint64_t r11;
uint64_t error_word;
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t stack[];
} istate_t;
 
static inline uint64_t istate_get_pc(istate_t *istate)
{
return istate->rip;
}
 
#endif
 
/** @}
*/
/branches/tracing/uspace/app/debug/arch/amd64/Makefile.inc
0,0 → 1,29
#
# Copyright (c) 2009 Jiri Svoboda
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
ARCH_SOURCES := arch/$(UARCH)/src/amd64.c
/branches/tracing/uspace/app/debug/arch/amd64/src/amd64.c
0,0 → 1,188
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup debug
* @{
*/
/** @file
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <bool.h>
#include <udebug.h>
 
#include <kernel/arch/context_offset.h>
 
#include "../../../cons.h"
#include "../../../main.h"
#include "../../../include/arch.h"
 
#define OPCODE_INT3 0xCC
 
void arch_dthread_initialize(dthread_t *dt)
{
dt->arch.singlestep = false;
}
 
static int _set_trap_flag(dthread_t *dt, bool enable)
{
static istate_t istate;
int rc;
 
rc = udebug_regs_read(app_phone, dt->hash, &istate);
if (rc < 0) { printf("regs read failed\n"); return -1; }
 
if (enable) istate.rflags |= 0x0100; /* trap flag */
else if (!active_bkpt) istate.rflags &= ~0x0100; /* trap flag */
 
rc = udebug_regs_write(app_phone, dt->hash, &istate);
if (rc < 0) { printf("regs write failed\n"); return -1; }
 
return 0;
}
 
int arch_breakpoint_set(breakpoint_t *b)
{
char brkp[1];
int rc;
 
rc = udebug_mem_read(app_phone, &b->arch.back, b->addr, 1);
cons_printf("udebug_mem_read() -> %d\n", rc);
if (rc < 0) return rc;
 
brkp[0] = OPCODE_INT3;
rc = udebug_mem_write(app_phone, brkp, b->addr, 1);
if (rc < 0) return rc;
 
cons_printf("udebug_mem_write() -> %d\n", rc);
return 0;
}
 
int arch_breakpoint_remove(breakpoint_t *b)
{
int rc;
 
if (b->active) {
active_bkpt = NULL;
} else {
rc = udebug_mem_write(app_phone, &b->arch.back, b->addr, 1);
if (rc < 0) {
cons_printf("error writing mem\n");
return rc;
}
}
 
return 0;
}
 
void arch_event_breakpoint(thash_t thread_hash)
{
static istate_t istate;
breakpoint_t *b;
int rc;
 
rc = udebug_regs_read(app_phone, thread_hash, &istate);
// cons_printf("udebug_regs_read -> %d\n", rc);
// cons_printf("RIP was 0x%08x\n", istate.rip);
int brk_addr = istate.rip - 1;
 
b = breakpoint_find_by_addr(brk_addr);
if (!b) {
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
return;
}
 
istate.rip = brk_addr;
istate.rflags |= 0x0100; /* trap flag */
 
rc = udebug_regs_write(app_phone, thread_hash, &istate);
if (rc < 0) { cons_printf("error writing regs\n"); return; }
rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 1);
if (rc < 0) { cons_printf("error writing mem\n"); return; }
// cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
 
b->active = true;
active_bkpt = b;
 
breakpoint_hit(b);
}
 
void arch_event_trap(dthread_t *dt)
{
breakpoint_t *b;
static istate_t istate;
unsigned char brkinstr[1];
int rc;
 
// cons_printf("trap event\n");
b = active_bkpt;
if (b) {
brkinstr[0] = OPCODE_INT3;
rc = udebug_mem_write(app_phone, brkinstr, b->addr, 1);
// cons_printf("restore breakpoint -> %d\n", rc);
active_bkpt = NULL;
}
 
rc = _set_trap_flag(dt, false);
dt->arch.singlestep = false;
 
singlestep_hit();
}
 
void arch_dump_regs(thash_t thash)
{
static istate_t istate;
int rc;
 
rc = udebug_regs_read(app_phone, thash, &istate);
if (rc < 0) { cons_printf("Error reading regs\n"); return; }
 
cons_printf(
"rip:%016x rflags:%016x rax:%016x rcx:%016x ecx:%016x "
"rdx:%016x\nrsi:%016x rdi:%016x r8:%016x r9:%016x "
"r10:%016x r11:%016x cs:%04x\n",
istate.rip, istate.rflags, istate.rax, istate.rcx,
istate.rdx, istate.rsi, istate.rdi, istate.r8, istate.r9,
istate.r10, istate.r11, istate.cs);
}
 
void arch_singlestep(dthread_t *dt)
{
int rc;
 
rc = _set_trap_flag(dt, true);
if (rc != 0) return;
 
dthread_resume(dt);
}
 
/** @}
*/
/branches/tracing/boot/arch/amd64/Makefile.inc
54,6 → 54,7
$(USPACEDIR)/app/trace/trace \
$(USPACEDIR)/app/tetris/tetris \
$(USPACEDIR)/app/tester/tester \
$(USPACEDIR)/app/debug/debug \
$(USPACEDIR)/app/klog/klog \
$(USPACEDIR)/app/bdsh/bdsh