Subversion Repositories HelenOS

Rev

Rev 4605 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4605 Rev 4616
Line 501... Line 501...
501
 
501
 
502
    *buffer = data_buffer;
502
    *buffer = data_buffer;
503
    return 0;
503
    return 0;
504
}
504
}
505
 
505
 
-
 
506
int udebug_thread_get_thread_struct(thread_t *t, void **buffer)
-
 
507
{
-
 
508
    ipl_t ipl = interrupts_disable();
-
 
509
 
-
 
510
    void *data_buffer = (void *)malloc(sizeof(thread_t), 0);
-
 
511
 
-
 
512
    memcpy(data_buffer, (void *)t, sizeof(thread_t));
-
 
513
 
-
 
514
    *buffer = data_buffer;
-
 
515
 
-
 
516
    interrupts_restore(ipl);
-
 
517
 
-
 
518
    return (0);
-
 
519
}
-
 
520
 
-
 
521
int udebug_task_get_memory_areas(void **buffer, size_t buf_size, size_t *n)
-
 
522
{
-
 
523
    link_t *cur;
-
 
524
    ipl_t ipl;
-
 
525
    unative_t *areas_buffer;
-
 
526
    size_t max_index;
-
 
527
 
-
 
528
    as_print(TASK->as);
-
 
529
   
-
 
530
    areas_buffer = malloc(buf_size, 0);
-
 
531
 
-
 
532
    mutex_lock(&TASK->udebug.lock);
-
 
533
 
-
 
534
    /* Verify task state */
-
 
535
    if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
-
 
536
        mutex_unlock(&TASK->udebug.lock);
-
 
537
        return EINVAL;
-
 
538
    }
-
 
539
 
-
 
540
    ipl = interrupts_disable();
-
 
541
    spinlock_lock(&TASK->lock);
-
 
542
 
-
 
543
    max_index = buf_size / sizeof(unative_t);
-
 
544
    as_t *as = TASK->as;
-
 
545
   
-
 
546
    mutex_lock(&as->lock);
-
 
547
   
-
 
548
    /* print out info about address space areas */
-
 
549
    unsigned int index = 0;
-
 
550
    for (cur = as->as_area_btree.leaf_head.next;
-
 
551
        cur != &as->as_area_btree.leaf_head; cur = cur->next) {
-
 
552
        btree_node_t *node;
-
 
553
       
-
 
554
        node = list_get_instance(cur, btree_node_t, leaf_link);
-
 
555
       
-
 
556
        unsigned int i;
-
 
557
        for (i = 0; i < node->keys; i++) {
-
 
558
            if (index >= max_index)
-
 
559
                break;
-
 
560
 
-
 
561
            as_area_t *area = node->value[i];
-
 
562
       
-
 
563
            mutex_lock(&area->lock);
-
 
564
            areas_buffer[index++] = area->base;
-
 
565
            areas_buffer[index++] = area->base + FRAMES2SIZE(area->pages);
-
 
566
            mutex_unlock(&area->lock);
-
 
567
        }
-
 
568
    }
-
 
569
   
-
 
570
    mutex_unlock(&as->lock);
-
 
571
 
-
 
572
    spinlock_unlock(&TASK->lock);
-
 
573
    interrupts_restore(ipl);
-
 
574
 
-
 
575
    mutex_unlock(&TASK->udebug.lock);
-
 
576
 
-
 
577
    *buffer = areas_buffer;
-
 
578
    *n = (index) * sizeof(unative_t);
-
 
579
 
-
 
580
    return 0;
-
 
581
 
-
 
582
}
-
 
583
 
-
 
584
int udebug_copy_kstack(void *kstack, void **buffer, size_t n)
-
 
585
{
-
 
586
    ipl_t ipl = interrupts_disable();
-
 
587
 
-
 
588
    void *data_buffer = malloc(n, 0);
-
 
589
 
-
 
590
    memcpy(data_buffer, (void *)kstack, n);
-
 
591
 
-
 
592
    *buffer = data_buffer;
-
 
593
 
-
 
594
    interrupts_restore(ipl);
-
 
595
 
-
 
596
    return 0;
-
 
597
}
-
 
598
 
-
 
599
int udebug_restore_thread_struct(void *buffer, thread_t *t_old)
-
 
600
{
-
 
601
    ipl_t ipl = interrupts_disable();
-
 
602
 
-
 
603
    thread_t *t_new = (thread_t *)buffer;
-
 
604
 
-
 
605
    t_old->thread_code = t_new->thread_code;
-
 
606
 
-
 
607
    printf("old sp: %p, new sp: %p\n", t_old->saved_context.sp, t_new->saved_context.sp);
-
 
608
    printf("old kstack: %p, new kstack: %p\n", t_old->kstack, t_new->kstack);
-
 
609
 
-
 
610
    t_old->saved_context = t_new->saved_context;
-
 
611
    t_old->saved_context.sp = (uintptr_t)t_old->kstack + ((uintptr_t)t_new->saved_context.sp - (uintptr_t)t_new->kstack);
-
 
612
 
-
 
613
    t_old->sleep_timeout_context = t_new->sleep_timeout_context;
-
 
614
    t_old->sleep_timeout = t_new->sleep_timeout;
-
 
615
    t_old->timeout_pending = t_new->timeout_pending;
-
 
616
   
-
 
617
    t_old->in_copy_from_uspace = t_new->in_copy_from_uspace;
-
 
618
    t_old->in_copy_to_uspace = t_new->in_copy_to_uspace;
-
 
619
 
-
 
620
    t_old->interrupted = t_new->interrupted;
-
 
621
 
-
 
622
    t_old->call_me = t_new->call_me;
-
 
623
    t_old->call_me_with = t_new->call_me_with;
-
 
624
 
-
 
625
    t_old->udebug.go_call = t_new->udebug.go_call;
-
 
626
 
-
 
627
    interrupts_restore(ipl);
-
 
628
   
-
 
629
    return (0);
-
 
630
}
-
 
631
 
-
 
632
int udebug_mem_write(void *buffer, void *start, size_t n)
-
 
633
{
-
 
634
    ipl_t ipl = interrupts_disable();
-
 
635
 
-
 
636
    if (((unsigned) start & 0x80000000) == 0)
-
 
637
        copy_to_uspace(start, buffer, n);
-
 
638
 
-
 
639
    interrupts_restore(ipl);
-
 
640
 
-
 
641
    return (0);
-
 
642
}
-
 
643
 
-
 
644
int udebug_restore_kstack(void *buffer, size_t size, thread_t *t)
-
 
645
{
-
 
646
    ipl_t ipl = interrupts_disable();
-
 
647
 
-
 
648
    memcpy(t->kstack + sizeof(the_t), buffer + sizeof(the_t), size - sizeof(the_t));
-
 
649
 
-
 
650
    interrupts_restore(ipl);
-
 
651
 
-
 
652
    return (0);
-
 
653
}
-
 
654
 
-
 
655
 
506
/** @}
656
/** @}
507
 */
657
 */