Rev 3042 | Rev 3425 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3042 | Rev 3424 | ||
---|---|---|---|
Line 49... | Line 49... | ||
49 | #include <proc/task.h> |
49 | #include <proc/task.h> |
50 | #include <memstr.h> |
50 | #include <memstr.h> |
51 | #include <debug.h> |
51 | #include <debug.h> |
52 | 52 | ||
53 | #include <print.h> |
53 | #include <print.h> |
54 | #include <console/klog.h> |
54 | #include <console/console.h> |
55 | #include <proc/thread.h> |
55 | #include <proc/thread.h> |
56 | #include <arch/interrupt.h> |
56 | #include <arch/interrupt.h> |
57 | #include <ipc/irq.h> |
57 | #include <ipc/irq.h> |
58 | 58 | ||
59 | /** Open channel that is assigned automatically to new tasks */ |
59 | /** Open channel that is assigned automatically to new tasks */ |
Line 65... | Line 65... | ||
65 | * |
65 | * |
66 | * @param call Call structure to be initialized. |
66 | * @param call Call structure to be initialized. |
67 | */ |
67 | */ |
68 | static void _ipc_call_init(call_t *call) |
68 | static void _ipc_call_init(call_t *call) |
69 | { |
69 | { |
70 | memsetb((uintptr_t) call, sizeof(*call), 0); |
70 | memsetb(call, sizeof(*call), 0); |
71 | call->callerbox = &TASK->answerbox; |
71 | call->callerbox = &TASK->answerbox; |
72 | call->sender = TASK; |
72 | call->sender = TASK; |
73 | call->buffer = NULL; |
73 | call->buffer = NULL; |
74 | } |
74 | } |
75 | 75 | ||
Line 514... | Line 514... | ||
514 | * wake up and terminate. |
514 | * wake up and terminate. |
515 | */ |
515 | */ |
516 | ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread); |
516 | ipc_answerbox_slam_phones(&TASK->kernel_box, have_kb_thread); |
517 | 517 | ||
518 | if (have_kb_thread) { |
518 | if (have_kb_thread) { |
519 | klog_printf("join kb_thread.."); |
519 | printf("join kb_thread..\n"); |
520 | thread_join(TASK->kb_thread); |
520 | thread_join(TASK->kb_thread); |
521 | thread_detach(TASK->kb_thread); |
521 | thread_detach(TASK->kb_thread); |
522 | klog_printf("join done"); |
522 | printf("join done\n"); |
523 | TASK->kb_thread = NULL; |
523 | TASK->kb_thread = NULL; |
524 | } |
524 | } |
525 | 525 | ||
526 | /* Answer all messages in 'calls' and 'dispatched_calls' queues */ |
526 | /* Answer all messages in 'calls' and 'dispatched_calls' queues */ |
527 | spinlock_lock(&TASK->kernel_box.lock); |
527 | spinlock_lock(&TASK->kernel_box.lock); |
Line 650... | Line 650... | ||
650 | task->phones[i].callee); |
650 | task->phones[i].callee); |
651 | break; |
651 | break; |
652 | default: |
652 | default: |
653 | break; |
653 | break; |
654 | } |
654 | } |
655 | printf("active: %d\n", |
655 | printf("active: %ld\n", |
656 | atomic_get(&task->phones[i].active_calls)); |
656 | atomic_get(&task->phones[i].active_calls)); |
657 | } |
657 | } |
658 | mutex_unlock(&task->phones[i].lock); |
658 | mutex_unlock(&task->phones[i].lock); |
659 | } |
659 | } |
660 | 660 | ||
Line 663... | Line 663... | ||
663 | spinlock_lock(&task->answerbox.lock); |
663 | spinlock_lock(&task->answerbox.lock); |
664 | printf("ABOX - CALLS:\n"); |
664 | printf("ABOX - CALLS:\n"); |
665 | for (tmp = task->answerbox.calls.next; tmp != &task->answerbox.calls; |
665 | for (tmp = task->answerbox.calls.next; tmp != &task->answerbox.calls; |
666 | tmp = tmp->next) { |
666 | tmp = tmp->next) { |
667 | call = list_get_instance(tmp, call_t, link); |
667 | call = list_get_instance(tmp, call_t, link); |
668 | printf("Callid: %p Srctask:%llu M:%d A1:%d A2:%d A3:%d " |
668 | printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun |
- | 669 | " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun |
|
669 | "A4:%d A5:%d Flags:%x\n", call, call->sender->taskid, |
670 | " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call, call->sender->taskid, |
670 | IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
671 | IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
671 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
672 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
672 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
673 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
673 | call->flags); |
674 | call->flags); |
674 | } |
675 | } |
675 | /* Print answerbox - calls */ |
676 | /* Print answerbox - calls */ |
676 | printf("ABOX - DISPATCHED CALLS:\n"); |
677 | printf("ABOX - DISPATCHED CALLS:\n"); |
677 | for (tmp = task->answerbox.dispatched_calls.next; |
678 | for (tmp = task->answerbox.dispatched_calls.next; |
678 | tmp != &task->answerbox.dispatched_calls; |
679 | tmp != &task->answerbox.dispatched_calls; |
679 | tmp = tmp->next) { |
680 | tmp = tmp->next) { |
680 | call = list_get_instance(tmp, call_t, link); |
681 | call = list_get_instance(tmp, call_t, link); |
681 | printf("Callid: %p Srctask:%llu M:%d A1:%d A2:%d A3:%d " |
682 | printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun |
- | 683 | " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun |
|
682 | "A4:%d A5:%d Flags:%x\n", call, call->sender->taskid, |
684 | " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call, call->sender->taskid, |
683 | IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
685 | IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
684 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
686 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
685 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
687 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
686 | call->flags); |
688 | call->flags); |
687 | } |
689 | } |
688 | /* Print answerbox - calls */ |
690 | /* Print answerbox - calls */ |
689 | printf("ABOX - ANSWERS:\n"); |
691 | printf("ABOX - ANSWERS:\n"); |
690 | for (tmp = task->answerbox.answers.next; tmp != &task->answerbox.answers; |
692 | for (tmp = task->answerbox.answers.next; tmp != &task->answerbox.answers; |
691 | tmp = tmp->next) { |
693 | tmp = tmp->next) { |
692 | call = list_get_instance(tmp, call_t, link); |
694 | call = list_get_instance(tmp, call_t, link); |
693 | printf("Callid:%p M:%d A1:%d A2:%d A3:%d A4:%d A5:%d Flags:%x\n", |
695 | printf("Callid:%p M:%" PRIun " A1:%" PRIun " A2:%" PRIun |
- | 696 | " A3:%" PRIun " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", |
|
694 | call, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
697 | call, IPC_GET_METHOD(call->data), IPC_GET_ARG1(call->data), |
695 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
698 | IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data), |
696 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
699 | IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data), |
697 | call->flags); |
700 | call->flags); |
698 | } |
701 | } |
Line 700... | Line 703... | ||
700 | spinlock_unlock(&task->answerbox.lock); |
703 | spinlock_unlock(&task->answerbox.lock); |
701 | spinlock_unlock(&task->lock); |
704 | spinlock_unlock(&task->lock); |
702 | } |
705 | } |
703 | 706 | ||
704 | #include <ipc/ipcrsc.h> |
707 | #include <ipc/ipcrsc.h> |
705 | #include <console/klog.h> |
708 | #include <print.h> |
706 | #include <udebug/udebug_ipc.h> |
709 | #include <udebug/udebug_ipc.h> |
707 | 710 | ||
708 | static void kbox_thread_proc(void *arg) |
711 | static void kbox_thread_proc(void *arg) |
709 | { |
712 | { |
710 | call_t *call; |
713 | call_t *call; |
711 | int method; |
714 | int method; |
712 | bool done; |
715 | bool done; |
713 | ipl_t ipl; |
716 | ipl_t ipl; |
714 | 717 | ||
715 | (void)arg; |
718 | (void)arg; |
716 | klog_printf("kbox_thread_proc()"); |
719 | printf("kbox_thread_proc()\n"); |
717 | done = false; |
720 | done = false; |
718 | 721 | ||
719 | while (!done) { |
722 | while (!done) { |
720 | //klog_printf("kbox: wait for call"); |
723 | //printf("kbox: wait for call\n"); |
721 | call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT, |
724 | call = ipc_wait_for_call(&TASK->kernel_box, SYNCH_NO_TIMEOUT, |
722 | SYNCH_FLAGS_NONE); |
725 | SYNCH_FLAGS_NONE); |
723 | 726 | ||
724 | if (call != NULL) { |
727 | if (call != NULL) { |
725 | method = IPC_GET_METHOD(call->data); |
728 | method = IPC_GET_METHOD(call->data); |
Line 727... | Line 730... | ||
727 | if (method == IPC_M_DEBUG_ALL) { |
730 | if (method == IPC_M_DEBUG_ALL) { |
728 | udebug_call_receive(call); |
731 | udebug_call_receive(call); |
729 | } |
732 | } |
730 | 733 | ||
731 | if (method == IPC_M_PHONE_HUNGUP) { |
734 | if (method == IPC_M_PHONE_HUNGUP) { |
732 | klog_printf("kbox: handle hangup message"); |
735 | printf("kbox: handle hangup message\n"); |
733 | 736 | ||
734 | /* Was it our debugger, who hung up? */ |
737 | /* Was it our debugger, who hung up? */ |
735 | if (call->sender == TASK->udebug.debugger) { |
738 | if (call->sender == TASK->udebug.debugger) { |
736 | /* Terminate debugging session (if any) */ |
739 | /* Terminate debugging session (if any) */ |
737 | klog_printf("kbox: terminate debug session"); |
740 | printf("kbox: terminate debug session\n"); |
738 | ipl = interrupts_disable(); |
741 | ipl = interrupts_disable(); |
739 | spinlock_lock(&TASK->lock); |
742 | spinlock_lock(&TASK->lock); |
740 | udebug_task_cleanup(TASK); |
743 | udebug_task_cleanup(TASK); |
741 | spinlock_unlock(&TASK->lock); |
744 | spinlock_unlock(&TASK->lock); |
742 | interrupts_restore(ipl); |
745 | interrupts_restore(ipl); |
743 | } else { |
746 | } else { |
744 | klog_printf("kbox: was not debugger"); |
747 | printf("kbox: was not debugger\n"); |
745 | } |
748 | } |
746 | 749 | ||
747 | klog_printf("kbox: continue with hangup message"); |
750 | printf("kbox: continue with hangup message\n"); |
748 | IPC_SET_RETVAL(call->data, 0); |
751 | IPC_SET_RETVAL(call->data, 0); |
749 | ipc_answer(&TASK->kernel_box, call); |
752 | ipc_answer(&TASK->kernel_box, call); |
750 | 753 | ||
751 | ipl = interrupts_disable(); |
754 | ipl = interrupts_disable(); |
752 | spinlock_lock(&TASK->lock); |
755 | spinlock_lock(&TASK->lock); |
753 | spinlock_lock(&TASK->answerbox.lock); |
756 | spinlock_lock(&TASK->answerbox.lock); |
754 | if (list_empty(&TASK->answerbox.connected_phones)) { |
757 | if (list_empty(&TASK->answerbox.connected_phones)) { |
755 | /* Last phone has been disconnected */ |
758 | /* Last phone has been disconnected */ |
756 | TASK->kb_thread = NULL; |
759 | TASK->kb_thread = NULL; |
757 | done = true; |
760 | done = true; |
758 | klog_printf("phone list is empty"); |
761 | printf("phone list is empty\n"); |
759 | } |
762 | } |
760 | spinlock_unlock(&TASK->answerbox.lock); |
763 | spinlock_unlock(&TASK->answerbox.lock); |
761 | spinlock_unlock(&TASK->lock); |
764 | spinlock_unlock(&TASK->lock); |
762 | interrupts_restore(ipl); |
765 | interrupts_restore(ipl); |
763 | } |
766 | } |
764 | } |
767 | } |
765 | } |
768 | } |
766 | 769 | ||
767 | klog_printf("kbox: finished"); |
770 | printf("kbox: finished\n"); |
768 | } |
771 | } |
769 | 772 | ||
770 | 773 | ||
771 | /** |
774 | /** |
772 | * Connect phone to a task kernel-box specified by id. |
775 | * Connect phone to a task kernel-box specified by id. |