Changes in kernel/generic/src/console/cmd.c [059a8e4:2f33fbc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/cmd.c
r059a8e4 r2f33fbc 56 56 #include <cpu.h> 57 57 #include <mm/tlb.h> 58 #include <mm/km.h> 58 59 #include <arch/mm/tlb.h> 59 60 #include <mm/frame.h> … … 81 82 .func = cmd_help, 82 83 .argc = 0 84 }; 85 86 /* Data and methods for pio_read_8 command */ 87 static int cmd_pio_read_8(cmd_arg_t *argv); 88 static cmd_arg_t pio_read_8_argv[] = { { .type = ARG_TYPE_INT } }; 89 static cmd_info_t pio_read_8_info = { 90 .name = "pio_read_8", 91 .description = "pio_read_8 <address> Read 1 byte from memory (or port).", 92 .func = cmd_pio_read_8, 93 .argc = 1, 94 .argv = pio_read_8_argv 95 }; 96 97 /* Data and methods for pio_read_16 command */ 98 static int cmd_pio_read_16(cmd_arg_t *argv); 99 static cmd_arg_t pio_read_16_argv[] = { { .type = ARG_TYPE_INT } }; 100 static cmd_info_t pio_read_16_info = { 101 .name = "pio_read_16", 102 .description = "pio_read_16 <address> Read 2 bytes from memory (or port).", 103 .func = cmd_pio_read_16, 104 .argc = 1, 105 .argv = pio_read_16_argv 106 }; 107 108 /* Data and methods for pio_read_32 command */ 109 static int cmd_pio_read_32(cmd_arg_t *argv); 110 static cmd_arg_t pio_read_32_argv[] = { { .type = ARG_TYPE_INT } }; 111 static cmd_info_t pio_read_32_info = { 112 .name = "pio_read_32", 113 .description = "pio_read_32 <address> Read 4 bytes from memory (or port).", 114 .func = cmd_pio_read_32, 115 .argc = 1, 116 .argv = pio_read_32_argv 117 }; 118 119 /* Data and methods for pio_write_8 command */ 120 static int cmd_pio_write_8(cmd_arg_t *argv); 121 static cmd_arg_t pio_write_8_argv[] = { 122 { .type = ARG_TYPE_INT }, 123 { .type = ARG_TYPE_INT } 124 }; 125 static cmd_info_t pio_write_8_info = { 126 .name = "pio_write_8", 127 .description = "pio_write_8 <address> <value> Write 1 byte to memory (or port).", 128 .func = cmd_pio_write_8, 129 .argc = 2, 130 .argv = pio_write_8_argv 131 }; 132 133 /* Data and methods for pio_write_16 command */ 134 static int cmd_pio_write_16(cmd_arg_t *argv); 135 static cmd_arg_t pio_write_16_argv[] = { 136 { .type = ARG_TYPE_INT }, 137 { .type = ARG_TYPE_INT } 138 }; 139 static cmd_info_t pio_write_16_info = { 140 .name = "pio_write_16", 141 .description = "pio_write_16 <address> <value> Write 2 bytes to memory (or port).", 142 .func = cmd_pio_write_16, 143 .argc = 2, 144 .argv = pio_write_16_argv 145 }; 146 147 /* Data and methods for pio_write_32 command */ 148 static int cmd_pio_write_32(cmd_arg_t *argv); 149 static cmd_arg_t pio_write_32_argv[] = { 150 { .type = ARG_TYPE_INT }, 151 { .type = ARG_TYPE_INT } 152 }; 153 static cmd_info_t pio_write_32_info = { 154 .name = "pio_write_32", 155 .description = "pio_write_32 <address> <value> Write 4 bytes to memory (or port).", 156 .func = cmd_pio_write_32, 157 .argc = 2, 158 .argv = pio_write_32_argv 83 159 }; 84 160 … … 531 607 &btrace_info, 532 608 #endif 609 &pio_read_8_info, 610 &pio_read_16_info, 611 &pio_read_32_info, 612 &pio_write_8_info, 613 &pio_write_16_info, 614 &pio_write_32_info, 533 615 NULL 534 616 }; … … 601 683 spinlock_unlock(&cmd_lock); 602 684 685 return 1; 686 } 687 688 /** Read 1 byte from phys memory or io port. 689 * 690 * @param argv Argument vector. 691 * 692 * @return 0 on failure, 1 on success. 693 */ 694 static int cmd_pio_read_8(cmd_arg_t *argv) 695 { 696 uint8_t *ptr = NULL; 697 698 #ifdef IO_SPACE_BOUNDARY 699 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 700 ptr = (void *) argv[0].intval; 701 else 702 #endif 703 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t), 704 PAGE_NOT_CACHEABLE); 705 706 const uint8_t val = pio_read_8(ptr); 707 printf("read %" PRIxn ": %" PRIx8 "\n", argv[0].intval, val); 708 709 #ifdef IO_SPACE_BOUNDARY 710 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 711 return 1; 712 #endif 713 714 km_unmap((uintptr_t) ptr, sizeof(uint8_t)); 715 return 1; 716 } 717 718 /** Read 2 bytes from phys memory or io port. 719 * 720 * @param argv Argument vector. 721 * 722 * @return 0 on failure, 1 on success. 723 */ 724 static int cmd_pio_read_16(cmd_arg_t *argv) 725 { 726 uint16_t *ptr = NULL; 727 728 #ifdef IO_SPACE_BOUNDARY 729 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 730 ptr = (void *) argv[0].intval; 731 else 732 #endif 733 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t), 734 PAGE_NOT_CACHEABLE); 735 736 const uint16_t val = pio_read_16(ptr); 737 printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val); 738 739 #ifdef IO_SPACE_BOUNDARY 740 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 741 return 1; 742 #endif 743 744 km_unmap((uintptr_t) ptr, sizeof(uint16_t)); 745 return 1; 746 } 747 748 /** Read 4 bytes from phys memory or io port. 749 * 750 * @param argv Argument vector. 751 * 752 * @return 0 on failure, 1 on success. 753 */ 754 static int cmd_pio_read_32(cmd_arg_t *argv) 755 { 756 uint32_t *ptr = NULL; 757 758 #ifdef IO_SPACE_BOUNDARY 759 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 760 ptr = (void *) argv[0].intval; 761 else 762 #endif 763 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t), 764 PAGE_NOT_CACHEABLE); 765 766 const uint32_t val = pio_read_32(ptr); 767 printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val); 768 769 #ifdef IO_SPACE_BOUNDARY 770 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 771 return 1; 772 #endif 773 774 km_unmap((uintptr_t) ptr, sizeof(uint32_t)); 775 return 1; 776 } 777 778 /** Write 1 byte to phys memory or io port. 779 * 780 * @param argv Argument vector. 781 * 782 * @return 0 on failure, 1 on success. 783 */ 784 static int cmd_pio_write_8(cmd_arg_t *argv) 785 { 786 uint8_t *ptr = NULL; 787 788 #ifdef IO_SPACE_BOUNDARY 789 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 790 ptr = (void *) argv[0].intval; 791 else 792 #endif 793 ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t), 794 PAGE_NOT_CACHEABLE); 795 796 printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval, 797 (uint8_t) argv[1].intval); 798 pio_write_8(ptr, (uint8_t) argv[1].intval); 799 800 #ifdef IO_SPACE_BOUNDARY 801 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 802 return 1; 803 #endif 804 805 km_unmap((uintptr_t) ptr, sizeof(uint8_t)); 806 return 1; 807 } 808 809 /** Write 2 bytes to phys memory or io port. 810 * 811 * @param argv Argument vector. 812 * 813 * @return 0 on failure, 1 on success. 814 */ 815 static int cmd_pio_write_16(cmd_arg_t *argv) 816 { 817 uint16_t *ptr = NULL; 818 819 #ifdef IO_SPACE_BOUNDARY 820 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 821 ptr = (void *) argv[0].intval; 822 else 823 #endif 824 ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t), 825 PAGE_NOT_CACHEABLE); 826 827 printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval, 828 (uint16_t) argv[1].intval); 829 pio_write_16(ptr, (uint16_t) argv[1].intval); 830 831 #ifdef IO_SPACE_BOUNDARY 832 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 833 return 1; 834 #endif 835 836 km_unmap((uintptr_t) ptr, sizeof(uint16_t)); 837 return 1; 838 } 839 840 /** Write 4 bytes to phys memory or io port. 841 * 842 * @param argv Argument vector. 843 * 844 * @return 0 on failure, 1 on success. 845 */ 846 static int cmd_pio_write_32(cmd_arg_t *argv) 847 { 848 uint32_t *ptr = NULL; 849 850 #ifdef IO_SPACE_BOUNDARY 851 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 852 ptr = (void *) argv[0].intval; 853 else 854 #endif 855 ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t), 856 PAGE_NOT_CACHEABLE); 857 858 printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval, 859 (uint32_t) argv[1].intval); 860 pio_write_32(ptr, (uint32_t) argv[1].intval); 861 862 #ifdef IO_SPACE_BOUNDARY 863 if ((void *) argv->intval < IO_SPACE_BOUNDARY) 864 return 1; 865 #endif 866 867 km_unmap((uintptr_t) ptr, sizeof(uint32_t)); 603 868 return 1; 604 869 } … … 724 989 thread_t *thread; 725 990 if ((thread = thread_create((void (*)(void *)) cmd_call0, 726 (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { 727 irq_spinlock_lock(&thread->lock, true); 728 thread->cpu = &cpus[i]; 729 irq_spinlock_unlock(&thread->lock, true); 730 991 (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) { 731 992 printf("cpu%u: ", i); 732 993 thread_wire(thread, &cpus[i]); 733 994 thread_ready(thread); 734 995 thread_join(thread);
Note:
See TracChangeset
for help on using the changeset viewer.