2 * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <mach/mach_types.h>
30 #include <mach/vm_param.h>
31 #include <sys/appleapiopts.h>
32 #include <kern/debug.h>
33 #include <uuid/uuid.h>
35 #include <kdp/kdp_internal.h>
36 #include <kdp/kdp_private.h>
37 #include <kdp/kdp_core.h>
39 #include <libsa/types.h>
40 #include <libkern/version.h>
42 #include <string.h> /* bcopy */
44 #include <kern/processor.h>
45 #include <kern/thread.h>
46 #include <kern/clock.h>
47 #include <vm/vm_map.h>
48 #include <vm/vm_kern.h>
49 #include <vm/vm_pageout.h>
50 #include <vm/vm_shared_region.h>
51 #include <libkern/OSKextLibPrivate.h>
53 #define DO_ALIGN 1 /* align all packet data accesses */
55 #define KDP_TEST_HARNESS 0
57 #define dprintf(x) kprintf x
63 dispatch_table
[KDP_INVALID_REQUEST
-KDP_CONNECT
] =
66 /* 1 */ kdp_disconnect
,
73 /* 8 */ kdp_writeregs
,
77 /* C */ kdp_resumecpus
,
80 /* F */ kdp_breakpoint_set
,
81 /*10 */ kdp_breakpoint_remove
,
85 /*14 */ kdp_readmem64
,
86 /*15 */ kdp_writemem64
,
87 /*16 */ kdp_breakpoint64_set
,
88 /*17 */ kdp_breakpoint64_remove
,
89 /*18 */ kdp_kernelversion
,
90 /*19 */ kdp_readphysmem64
,
91 /*1A */ kdp_writephysmem64
,
92 /*1B */ kdp_readioport
,
93 /*1C */ kdp_writeioport
,
94 /*1D */ kdp_readmsr64
,
95 /*1E */ kdp_writemsr64
,
101 #define MAX_BREAKPOINTS 100
104 * Version 11 of the KDP Protocol adds support for 64-bit wide memory
105 * addresses (read/write and breakpoints) as well as a dedicated
106 * kernelversion request. Version 12 adds read/writing of physical
107 * memory with 64-bit wide memory addresses.
109 #define KDP_VERSION 12
112 mach_vm_address_t address
;
114 uint8_t oldbytes
[MAX_BREAKINSN_BYTES
];
115 } kdp_breakpoint_record_t
;
117 static kdp_breakpoint_record_t breakpoint_list
[MAX_BREAKPOINTS
];
118 static unsigned int breakpoints_initialized
= 0;
120 int reattach_wait
= 0;
121 int noresume_on_disconnect
= 0;
124 kdp_set_breakpoint_internal(
125 mach_vm_address_t address
129 kdp_remove_breakpoint_internal(
130 mach_vm_address_t address
137 unsigned short *reply_port
140 static unsigned aligned_pkt
[1538/sizeof(unsigned)+1]; // max ether pkt
141 kdp_pkt_t
*rd
= (kdp_pkt_t
*)&aligned_pkt
;
147 if (plen
> sizeof(aligned_pkt
)) {
148 printf("kdp_packet bad len %lu\n", plen
);
151 bcopy((char *)pkt
, (char *)rd
, plen
);
153 rd
= (kdp_pkt_t
*)pkt
;
155 if (plen
< sizeof (rd
->hdr
) || rd
->hdr
.len
!= plen
) {
156 printf("kdp_packet bad len pkt %lu hdr %d\n", plen
, rd
->hdr
.len
);
161 if (rd
->hdr
.is_reply
) {
162 printf("kdp_packet reply recvd req %x seq %x\n",
163 rd
->hdr
.request
, rd
->hdr
.seq
);
168 req
= rd
->hdr
.request
;
169 if (req
>= KDP_INVALID_REQUEST
) {
170 printf("kdp_packet bad request %x len %d seq %x key %x\n",
171 rd
->hdr
.request
, rd
->hdr
.len
, rd
->hdr
.seq
, rd
->hdr
.key
);
176 ret
= ((*dispatch_table
[req
- KDP_CONNECT
])(rd
, len
, reply_port
));
178 bcopy((char *)rd
, (char *) pkt
, *len
);
187 __unused
unsigned short *reply_port
190 kdp_pkt_t
*rd
= (kdp_pkt_t
*)pkt
;
192 printf("kdp_unknown request %x len %d seq %x key %x\n",
193 rd
->hdr
.request
, rd
->hdr
.len
, rd
->hdr
.seq
, rd
->hdr
.key
);
202 unsigned short *reply_port
205 kdp_connect_req_t
*rq
= &pkt
->connect_req
;
207 kdp_connect_reply_t
*rp
= &pkt
->connect_reply
;
208 uint16_t rport
, eport
;
212 if (plen
< sizeof (*rq
))
215 dprintf(("kdp_connect seq %x greeting %s\n", rq
->hdr
.seq
, rq
->greeting
));
217 rport
= rq
->req_reply_port
;
218 eport
= rq
->exc_note_port
;
222 if ((seq
== kdp
.conn_seq
) && /* duplicate request */
223 (rport
== kdp
.reply_port
) &&
224 (eport
== kdp
.exception_port
) &&
225 (key
== kdp
.session_key
))
226 rp
->error
= KDPERR_NO_ERROR
;
228 rp
->error
= KDPERR_ALREADY_CONNECTED
;
231 kdp
.reply_port
= rport
;
232 kdp
.exception_port
= eport
;
235 kdp
.session_key
= key
;
237 rp
->error
= KDPERR_NO_ERROR
;
240 rp
->hdr
.is_reply
= 1;
241 rp
->hdr
.len
= sizeof (*rp
);
246 if (current_debugger
== KDP_CUR_DB
)
256 unsigned short *reply_port
259 kdp_disconnect_req_t
*rq
= &pkt
->disconnect_req
;
261 kdp_disconnect_reply_t
*rp
= &pkt
->disconnect_reply
;
263 if (plen
< sizeof (*rq
))
269 dprintf(("kdp_disconnect\n"));
271 *reply_port
= kdp
.reply_port
;
273 kdp
.reply_port
= kdp
.exception_port
= 0;
274 kdp
.is_halted
= kdp
.is_conn
= FALSE
;
275 kdp
.exception_seq
= kdp
.conn_seq
= 0;
278 if (debugger_panic_str
!= NULL
)
281 if (noresume_on_disconnect
== 1) {
283 noresume_on_disconnect
= 0;
286 rp
->hdr
.is_reply
= 1;
287 rp
->hdr
.len
= sizeof (*rp
);
291 if (current_debugger
== KDP_CUR_DB
)
301 unsigned short *reply_port
304 kdp_reattach_req_t
*rq
= &pkt
->reattach_req
;
307 kdp_disconnect(pkt
, len
, reply_port
);
308 *reply_port
= rq
->req_reply_port
;
317 unsigned short *reply_port
320 kdp_hostinfo_req_t
*rq
= &pkt
->hostinfo_req
;
322 kdp_hostinfo_reply_t
*rp
= &pkt
->hostinfo_reply
;
324 if (plen
< sizeof (*rq
))
327 dprintf(("kdp_hostinfo\n"));
329 rp
->hdr
.is_reply
= 1;
330 rp
->hdr
.len
= sizeof (*rp
);
332 kdp_machine_hostinfo(&rp
->hostinfo
);
334 *reply_port
= kdp
.reply_port
;
344 unsigned short *reply_port
347 kdp_kernelversion_req_t
*rq
= &pkt
->kernelversion_req
;
349 kdp_kernelversion_reply_t
*rp
= &pkt
->kernelversion_reply
;
352 if (plen
< sizeof (*rq
))
355 rp
->hdr
.is_reply
= 1;
356 rp
->hdr
.len
= sizeof (*rp
);
358 dprintf(("kdp_kernelversion\n"));
359 slen
= strlcpy(rp
->version
, kdp_kernelversion_string
, MAX_KDP_DATA_SIZE
);
361 rp
->hdr
.len
+= slen
+ 1; /* strlcpy returns the amount copied with NUL */
363 *reply_port
= kdp
.reply_port
;
373 unsigned short *reply_port
376 kdp_suspend_req_t
*rq
= &pkt
->suspend_req
;
378 kdp_suspend_reply_t
*rp
= &pkt
->suspend_reply
;
380 if (plen
< sizeof (*rq
))
383 rp
->hdr
.is_reply
= 1;
384 rp
->hdr
.len
= sizeof (*rp
);
386 dprintf(("kdp_suspend\n"));
388 kdp
.is_halted
= TRUE
;
390 *reply_port
= kdp
.reply_port
;
400 unsigned short *reply_port
403 kdp_resumecpus_req_t
*rq
= &pkt
->resumecpus_req
;
405 kdp_resumecpus_reply_t
*rp
= &pkt
->resumecpus_reply
;
407 if (plen
< sizeof (*rq
))
410 rp
->hdr
.is_reply
= 1;
411 rp
->hdr
.len
= sizeof (*rp
);
413 dprintf(("kdp_resumecpus %x\n", rq
->cpu_mask
));
415 kdp
.is_halted
= FALSE
;
417 *reply_port
= kdp
.reply_port
;
427 unsigned short *reply_port
430 kdp_writemem_req_t
*rq
= &pkt
->writemem_req
;
432 kdp_writemem_reply_t
*rp
= &pkt
->writemem_reply
;
435 if (plen
< sizeof (*rq
))
438 if (rq
->nbytes
> MAX_KDP_DATA_SIZE
)
439 rp
->error
= KDPERR_BAD_NBYTES
;
441 dprintf(("kdp_writemem addr %x size %d\n", rq
->address
, rq
->nbytes
));
442 cnt
= kdp_machine_vm_write((caddr_t
)rq
->data
, (mach_vm_address_t
)rq
->address
, rq
->nbytes
);
443 rp
->error
= KDPERR_ACCESS(rq
->nbytes
, cnt
);
444 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
447 rp
->hdr
.is_reply
= 1;
448 rp
->hdr
.len
= sizeof (*rp
);
450 *reply_port
= kdp
.reply_port
;
460 unsigned short *reply_port
463 kdp_writemem64_req_t
*rq
= &pkt
->writemem64_req
;
465 kdp_writemem64_reply_t
*rp
= &pkt
->writemem64_reply
;
468 if (plen
< sizeof (*rq
))
471 if (rq
->nbytes
> MAX_KDP_DATA_SIZE
)
472 rp
->error
= KDPERR_BAD_NBYTES
;
474 dprintf(("kdp_writemem64 addr %llx size %d\n", rq
->address
, rq
->nbytes
));
475 cnt
= kdp_machine_vm_write((caddr_t
)rq
->data
, (mach_vm_address_t
)rq
->address
, (mach_vm_size_t
)rq
->nbytes
);
476 rp
->error
= KDPERR_ACCESS(rq
->nbytes
, cnt
);
477 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
480 rp
->hdr
.is_reply
= 1;
481 rp
->hdr
.len
= sizeof (*rp
);
483 *reply_port
= kdp
.reply_port
;
493 unsigned short *reply_port
496 kdp_writephysmem64_req_t
*rq
= &pkt
->writephysmem64_req
;
498 kdp_writephysmem64_reply_t
*rp
= &pkt
->writephysmem64_reply
;
502 if (plen
< sizeof (*rq
))
506 if (size
> MAX_KDP_DATA_SIZE
)
507 rp
->error
= KDPERR_BAD_NBYTES
;
509 dprintf(("kdp_writephysmem64 addr %llx size %d\n", rq
->address
, size
));
510 cnt
= kdp_machine_phys_write(rq
, rq
->data
, rq
->lcpu
);
511 rp
->error
= KDPERR_ACCESS(size
, cnt
);
512 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
515 rp
->hdr
.is_reply
= 1;
516 rp
->hdr
.len
= sizeof (*rp
);
518 *reply_port
= kdp
.reply_port
;
528 unsigned short *reply_port
531 kdp_readmem_req_t
*rq
= &pkt
->readmem_req
;
533 kdp_readmem_reply_t
*rp
= &pkt
->readmem_reply
;
537 if (plen
< sizeof (*rq
))
540 rp
->hdr
.is_reply
= 1;
541 rp
->hdr
.len
= sizeof (*rp
);
544 if (size
> MAX_KDP_DATA_SIZE
)
545 rp
->error
= KDPERR_BAD_NBYTES
;
547 dprintf(("kdp_readmem addr %x size %d\n", rq
->address
, size
));
548 cnt
= kdp_machine_vm_read((mach_vm_address_t
)rq
->address
, (caddr_t
)rp
->data
, rq
->nbytes
);
549 rp
->error
= KDPERR_ACCESS(size
, cnt
);
550 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
555 *reply_port
= kdp
.reply_port
;
565 unsigned short *reply_port
568 kdp_readmem64_req_t
*rq
= &pkt
->readmem64_req
;
570 kdp_readmem64_reply_t
*rp
= &pkt
->readmem64_reply
;
574 if (plen
< sizeof (*rq
))
577 rp
->hdr
.is_reply
= 1;
578 rp
->hdr
.len
= sizeof (*rp
);
581 if (size
> MAX_KDP_DATA_SIZE
)
582 rp
->error
= KDPERR_BAD_NBYTES
;
584 dprintf(("kdp_readmem64 addr %llx size %d\n", rq
->address
, size
));
585 cnt
= kdp_machine_vm_read((mach_vm_address_t
)rq
->address
, (caddr_t
)rp
->data
, rq
->nbytes
);
586 rp
->error
= KDPERR_ACCESS(size
, cnt
);
587 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
592 *reply_port
= kdp
.reply_port
;
602 unsigned short *reply_port
605 kdp_readphysmem64_req_t
*rq
= &pkt
->readphysmem64_req
;
607 kdp_readphysmem64_reply_t
*rp
= &pkt
->readphysmem64_reply
;
611 if (plen
< sizeof (*rq
))
614 rp
->hdr
.is_reply
= 1;
615 rp
->hdr
.len
= sizeof (*rp
);
618 if (size
> MAX_KDP_DATA_SIZE
)
619 rp
->error
= KDPERR_BAD_NBYTES
;
621 dprintf(("kdp_readphysmem64 addr %llx size %d\n", rq
->address
, size
));
622 cnt
= kdp_machine_phys_read(rq
, rp
->data
, rq
->lcpu
);
623 rp
->error
= KDPERR_ACCESS(size
, cnt
);
624 dprintf((" cnt %lld error %d\n", cnt
, rp
->error
));
629 *reply_port
= kdp
.reply_port
;
639 unsigned short *reply_port
642 kdp_maxbytes_req_t
*rq
= &pkt
->maxbytes_req
;
644 kdp_maxbytes_reply_t
*rp
= &pkt
->maxbytes_reply
;
646 if (plen
< sizeof (*rq
))
649 rp
->hdr
.is_reply
= 1;
650 rp
->hdr
.len
= sizeof (*rp
);
652 dprintf(("kdp_maxbytes\n"));
654 rp
->max_bytes
= MAX_KDP_DATA_SIZE
;
656 *reply_port
= kdp
.reply_port
;
666 unsigned short *reply_port
669 kdp_version_req_t
*rq
= &pkt
->version_req
;
671 kdp_version_reply_t
*rp
= &pkt
->version_reply
;
673 if (plen
< sizeof (*rq
))
676 rp
->hdr
.is_reply
= 1;
677 rp
->hdr
.len
= sizeof (*rp
);
679 dprintf(("kdp_version\n"));
681 rp
->version
= KDP_VERSION
;
682 if (!(kdp_flag
& KDP_BP_DIS
))
683 rp
->feature
= KDP_FEATURE_BP
;
687 *reply_port
= kdp
.reply_port
;
697 unsigned short *reply_port
700 kdp_regions_req_t
*rq
= &pkt
->regions_req
;
702 kdp_regions_reply_t
*rp
= &pkt
->regions_reply
;
705 if (plen
< sizeof (*rq
))
708 rp
->hdr
.is_reply
= 1;
709 rp
->hdr
.len
= sizeof (*rp
);
711 dprintf(("kdp_regions\n"));
717 r
->nbytes
= 0xffffffff;
719 r
->protection
= VM_PROT_ALL
; r
++; rp
->nregions
++;
721 rp
->hdr
.len
+= rp
->nregions
* sizeof (kdp_region_t
);
723 *reply_port
= kdp
.reply_port
;
733 unsigned short *reply_port
736 kdp_writeregs_req_t
*rq
= &pkt
->writeregs_req
;
739 kdp_writeregs_reply_t
*rp
= &pkt
->writeregs_reply
;
741 if (plen
< sizeof (*rq
))
744 size
= rq
->hdr
.len
- (unsigned)sizeof(kdp_hdr_t
) - (unsigned)sizeof(unsigned int);
745 rp
->error
= kdp_machine_write_regs(rq
->cpu
, rq
->flavor
, rq
->data
, &size
);
747 rp
->hdr
.is_reply
= 1;
748 rp
->hdr
.len
= sizeof (*rp
);
750 *reply_port
= kdp
.reply_port
;
760 unsigned short *reply_port
763 kdp_readregs_req_t
*rq
= &pkt
->readregs_req
;
765 kdp_readregs_reply_t
*rp
= &pkt
->readregs_reply
;
768 if (plen
< sizeof (*rq
))
771 rp
->hdr
.is_reply
= 1;
772 rp
->hdr
.len
= sizeof (*rp
);
774 rp
->error
= kdp_machine_read_regs(rq
->cpu
, rq
->flavor
, rp
->data
, &size
);
777 *reply_port
= kdp
.reply_port
;
788 unsigned short *reply_port
791 kdp_breakpoint_req_t
*rq
= &pkt
->breakpoint_req
;
792 kdp_breakpoint_reply_t
*rp
= &pkt
->breakpoint_reply
;
796 if (plen
< sizeof (*rq
))
799 dprintf(("kdp_breakpoint_set %x\n", rq
->address
));
801 kerr
= kdp_set_breakpoint_internal((mach_vm_address_t
)rq
->address
);
805 rp
->hdr
.is_reply
= 1;
806 rp
->hdr
.len
= sizeof (*rp
);
807 *reply_port
= kdp
.reply_port
;
814 kdp_breakpoint64_set(
817 unsigned short *reply_port
820 kdp_breakpoint64_req_t
*rq
= &pkt
->breakpoint64_req
;
821 kdp_breakpoint64_reply_t
*rp
= &pkt
->breakpoint64_reply
;
825 if (plen
< sizeof (*rq
))
828 dprintf(("kdp_breakpoint64_set %llx\n", rq
->address
));
830 kerr
= kdp_set_breakpoint_internal((mach_vm_address_t
)rq
->address
);
834 rp
->hdr
.is_reply
= 1;
835 rp
->hdr
.len
= sizeof (*rp
);
836 *reply_port
= kdp
.reply_port
;
843 kdp_breakpoint_remove(
846 unsigned short *reply_port
849 kdp_breakpoint_req_t
*rq
= &pkt
->breakpoint_req
;
850 kdp_breakpoint_reply_t
*rp
= &pkt
->breakpoint_reply
;
853 if (plen
< sizeof (*rq
))
856 dprintf(("kdp_breakpoint_remove %x\n", rq
->address
));
858 kerr
= kdp_remove_breakpoint_internal((mach_vm_address_t
)rq
->address
);
862 rp
->hdr
.is_reply
= 1;
863 rp
->hdr
.len
= sizeof (*rp
);
864 *reply_port
= kdp
.reply_port
;
871 kdp_breakpoint64_remove(
874 unsigned short *reply_port
877 kdp_breakpoint64_req_t
*rq
= &pkt
->breakpoint64_req
;
878 kdp_breakpoint64_reply_t
*rp
= &pkt
->breakpoint64_reply
;
882 if (plen
< sizeof (*rq
))
885 dprintf(("kdp_breakpoint64_remove %llx\n", rq
->address
));
887 kerr
= kdp_remove_breakpoint_internal((mach_vm_address_t
)rq
->address
);
891 rp
->hdr
.is_reply
= 1;
892 rp
->hdr
.len
= sizeof (*rp
);
893 *reply_port
= kdp
.reply_port
;
901 kdp_set_breakpoint_internal(
902 mach_vm_address_t address
906 uint8_t breakinstr
[MAX_BREAKINSN_BYTES
], oldinstr
[MAX_BREAKINSN_BYTES
];
907 uint32_t breakinstrsize
= sizeof(breakinstr
);
911 kdp_machine_get_breakinsn(breakinstr
, &breakinstrsize
);
913 if(breakpoints_initialized
== 0)
915 for(i
=0;(i
< MAX_BREAKPOINTS
); breakpoint_list
[i
].address
=0, i
++);
916 breakpoints_initialized
++;
919 cnt
= kdp_machine_vm_read(address
, (caddr_t
)&oldinstr
, (mach_vm_size_t
)breakinstrsize
);
921 if (0 == memcmp(oldinstr
, breakinstr
, breakinstrsize
)) {
922 printf("A trap was already set at that address, not setting new breakpoint\n");
924 return KDPERR_BREAKPOINT_ALREADY_SET
;
927 for(i
=0;(i
< MAX_BREAKPOINTS
) && (breakpoint_list
[i
].address
!= 0); i
++);
929 if (i
== MAX_BREAKPOINTS
) {
930 return KDPERR_MAX_BREAKPOINTS
;
933 breakpoint_list
[i
].address
= address
;
934 memcpy(breakpoint_list
[i
].oldbytes
, oldinstr
, breakinstrsize
);
935 breakpoint_list
[i
].bytesused
= breakinstrsize
;
937 cnt
= kdp_machine_vm_write((caddr_t
)&breakinstr
, address
, breakinstrsize
);
939 return KDPERR_NO_ERROR
;
943 kdp_remove_breakpoint_internal(
944 mach_vm_address_t address
950 for(i
=0;(i
< MAX_BREAKPOINTS
) && (breakpoint_list
[i
].address
!= address
); i
++);
952 if (i
== MAX_BREAKPOINTS
)
954 return KDPERR_BREAKPOINT_NOT_FOUND
;
957 breakpoint_list
[i
].address
= 0;
958 cnt
= kdp_machine_vm_write((caddr_t
)&breakpoint_list
[i
].oldbytes
, address
, breakpoint_list
[i
].bytesused
);
960 return KDPERR_NO_ERROR
;
964 kdp_remove_all_breakpoints(void)
967 boolean_t breakpoint_found
= FALSE
;
969 if (breakpoints_initialized
)
971 for(i
=0;i
< MAX_BREAKPOINTS
; i
++)
973 if (breakpoint_list
[i
].address
)
975 kdp_machine_vm_write((caddr_t
)&(breakpoint_list
[i
].oldbytes
), (mach_vm_address_t
)breakpoint_list
[i
].address
, (mach_vm_size_t
)breakpoint_list
[i
].bytesused
);
976 breakpoint_found
= TRUE
;
977 breakpoint_list
[i
].address
= 0;
981 if (breakpoint_found
)
982 printf("kdp_remove_all_breakpoints: found extant breakpoints, removing them.\n");
984 return breakpoint_found
;
989 __unused kdp_pkt_t
*pkt
,
991 __unused
unsigned short *reply_port
994 dprintf(("kdp_reboot\n"));
996 kdp_machine_reboot();
998 return (TRUE
); // no, not really, we won't return
1005 unsigned short *reply_port
1008 kdp_readioport_req_t
*rq
= &pkt
->readioport_req
;
1009 kdp_readioport_reply_t
*rp
= &pkt
->readioport_reply
;
1012 if (plen
< sizeof (*rq
))
1015 rp
->hdr
.is_reply
= 1;
1016 rp
->hdr
.len
= sizeof (*rp
);
1018 if (rq
->nbytes
> MAX_KDP_DATA_SIZE
)
1019 rp
->error
= KDPERR_BAD_NBYTES
;
1021 #if KDP_TEST_HARNESS
1022 uint16_t addr
= rq
->address
;
1024 uint16_t size
= rq
->nbytes
;
1025 dprintf(("kdp_readioport addr %x size %d\n", addr
, size
));
1027 rp
->error
= kdp_machine_ioport_read(rq
, rp
->data
, rq
->lcpu
);
1028 if (rp
->error
== KDPERR_NO_ERROR
)
1029 rp
->hdr
.len
+= size
;
1032 *reply_port
= kdp
.reply_port
;
1042 unsigned short *reply_port
1045 kdp_writeioport_req_t
*rq
= &pkt
->writeioport_req
;
1046 kdp_writeioport_reply_t
*rp
= &pkt
->writeioport_reply
;
1049 if (plen
< sizeof (*rq
))
1052 if (rq
->nbytes
> MAX_KDP_DATA_SIZE
)
1053 rp
->error
= KDPERR_BAD_NBYTES
;
1055 dprintf(("kdp_writeioport addr %x size %d\n", rq
->address
,
1058 rp
->error
= kdp_machine_ioport_write(rq
, rq
->data
, rq
->lcpu
);
1061 rp
->hdr
.is_reply
= 1;
1062 rp
->hdr
.len
= sizeof (*rp
);
1064 *reply_port
= kdp
.reply_port
;
1074 unsigned short *reply_port
1077 kdp_readmsr64_req_t
*rq
= &pkt
->readmsr64_req
;
1078 kdp_readmsr64_reply_t
*rp
= &pkt
->readmsr64_reply
;
1081 if (plen
< sizeof (*rq
))
1084 rp
->hdr
.is_reply
= 1;
1085 rp
->hdr
.len
= sizeof (*rp
);
1087 dprintf(("kdp_readmsr64 lcpu %x addr %x\n", rq
->lcpu
, rq
->address
));
1088 rp
->error
= kdp_machine_msr64_read(rq
, rp
->data
, rq
->lcpu
);
1089 if (rp
->error
== KDPERR_NO_ERROR
)
1090 rp
->hdr
.len
+= sizeof(uint64_t);
1092 *reply_port
= kdp
.reply_port
;
1102 unsigned short *reply_port
1105 kdp_writemsr64_req_t
*rq
= &pkt
->writemsr64_req
;
1106 kdp_writemsr64_reply_t
*rp
= &pkt
->writemsr64_reply
;
1109 if (plen
< sizeof (*rq
))
1112 dprintf(("kdp_writemsr64 lcpu %x addr %x\n", rq
->lcpu
, rq
->address
));
1113 rp
->error
= kdp_machine_msr64_write(rq
, rq
->data
, rq
->lcpu
);
1115 rp
->hdr
.is_reply
= 1;
1116 rp
->hdr
.len
= sizeof (*rp
);
1118 *reply_port
= kdp
.reply_port
;
1128 unsigned short *reply_port
1131 kdp_dumpinfo_req_t
*rq
= &pkt
->dumpinfo_req
;
1132 kdp_dumpinfo_reply_t
*rp
= &pkt
->dumpinfo_reply
;
1135 if (plen
< sizeof (*rq
))
1138 dprintf(("kdp_dumpinfo file=%s destip=%s routerip=%s\n", rq
->name
, rq
->destip
, rq
->routerip
));
1139 rp
->hdr
.is_reply
= 1;
1140 rp
->hdr
.len
= sizeof (*rp
);
1142 if ((rq
->type
& KDP_DUMPINFO_MASK
) != KDP_DUMPINFO_GETINFO
) {
1143 kdp_set_dump_info(rq
->type
, rq
->name
, rq
->destip
, rq
->routerip
,
1147 /* gather some stats for reply */
1148 kdp_get_dump_info(rp
);
1150 *reply_port
= kdp
.reply_port
;