- Start rosapps rearrange and cleanup process.
[reactos.git] / rosapps / applications / sysutils / utils / pice / module / privateice.c
1 /*++
2
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4
5 Module Name:
6
7 privateice.c
8
9 Abstract:
10
11 Environment:
12
13 Author:
14
15 Klaus P. Gerlicher
16
17 reactos port by:
18 Eugene Ingerman
19
20 Revision History:
21
22 16-Jul-1998: created
23 15-Nov-2000: general cleanup of source files
24 19-Jan-2001: renamed to privateice.c
25
26 10/20/2001: porting to reactos begins
27
28 Copyright notice:
29
30 This file may be distributed under the terms of the GNU Public License.
31
32 --*/
33
34 ////////////////////////////////////////////////////
35 // INCLUDES
36 ////
37 /*
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <asm/uaccess.h>
41 #include <linux/fs.h>
42 #include <linux/config.h>
43 #include <linux/sched.h>
44 #include <asm/unistd.h>
45 #include <linux/string.h>
46 */
47
48 #include <ntddk.h>
49 #include <debug.h>
50 #include <rosrtl/string.h>
51
52 #include "precomp.h"
53 #include "serial.h"
54
55 ////////////////////////////////////////////////////
56 // GLOBALS
57 ////
58
59 BOOLEAN bDeviceAlreadyOpen = FALSE;
60
61 char tempPICE[1024];
62
63 ////////////////////////////////////////////////////
64 // FUNCTIONS
65 ////
66
67 //*************************************************************************
68 // pice_open()
69 //
70 //*************************************************************************
71
72 NTSTATUS STDCALL pice_open(PDEVICE_OBJECT DeviceObject, PIRP Irp)
73 {
74 DPRINT((0,"pice_open\n"));
75
76 /* We don't want to talk to two processes at the
77 * same time */
78 if (bDeviceAlreadyOpen){
79 IoCompleteRequest (Irp, IO_NO_INCREMENT);
80 return STATUS_UNSUCCESSFUL; /* is there a more descriptive status code for this case? */
81 }
82
83 bDeviceAlreadyOpen = TRUE;
84 IoCompleteRequest (Irp, IO_NO_INCREMENT);
85 return STATUS_SUCCESS;
86 }
87
88 //*************************************************************************
89 // pice_close()
90 //
91 //*************************************************************************
92 NTSTATUS STDCALL pice_close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
93 {
94 DPRINT((0,"pice_close\n"));
95
96 CleanUpPICE(); // used to be in cleanup_module
97
98 /* We're now ready for our next caller */
99 bDeviceAlreadyOpen = FALSE;
100 IoCompleteRequest (Irp, IO_NO_INCREMENT);
101
102 return STATUS_SUCCESS;
103 }
104
105
106 //*************************************************************************
107 // pice_ioctl()
108 //
109 //*************************************************************************
110
111 NTSTATUS STDCALL pice_ioctl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
112 {
113 // char* pFilename = (char*) ioctl_param;
114
115 PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation( Irp );
116
117 ULONG Code = IoStack->Parameters.DeviceIoControl.IoControlCode;
118
119 switch(Code)
120 {
121 case PICE_IOCTL_LOAD:
122 break;
123 case PICE_IOCTL_RELOAD:
124 if(!ReloadSymbols())
125 {
126 PICE_sprintf(tempPICE,"pICE: not able to reload symbols\n");
127 Print(OUTPUT_WINDOW,tempPICE);
128 }
129 break;
130 case PICE_IOCTL_UNLOAD:
131 UnloadSymbols();
132 break;
133 case PICE_IOCTL_BREAK:
134 PICE_sprintf(tempPICE,"pICE: forcible break\n");
135 Print(OUTPUT_WINDOW,tempPICE);
136 __asm__ __volatile("int $3");
137 break;
138 case PICE_IOCTL_STATUS:
139 {
140 PDEBUGGER_STATUS_BLOCK ustatus_block_p;
141 DEBUGGER_STATUS_BLOCK kstatus_block;
142
143 ULONG OutLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
144 if( OutLength < sizeof( DEBUGGER_STATUS_BLOCK ) ){
145 return STATUS_INVALID_PARAMETER;
146 }
147
148 ustatus_block_p = (PDEBUGGER_STATUS_BLOCK)Irp->AssociatedIrp.SystemBuffer;
149
150 //kstatus_block.Test = 0x12345678;
151 RtlCopyMemory(ustatus_block_p, &kstatus_block, sizeof(DEBUGGER_STATUS_BLOCK) );
152 }
153 break;
154 default:
155 IoCompleteRequest (Irp, IO_NO_INCREMENT);
156 return STATUS_INVALID_PARAMETER;
157 }
158 IoCompleteRequest (Irp, IO_NO_INCREMENT);
159 return STATUS_SUCCESS;
160 }
161
162
163 NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT DriverObject,
164 PUNICODE_STRING RegistryPath)
165 /*
166 * FUNCTION: Module entry point
167 */
168 {
169 PDEVICE_OBJECT DeviceObject;
170 UNICODE_STRING DeviceName;
171 UNICODE_STRING SymlinkName;
172
173 DPRINT((0,"PICE Debugger\n"));
174
175 #if 0 // don't enable before completely ported
176 #ifdef DEBUG
177 // first we enable output of debug strings to COM port
178 DebugSetupSerial(1,115200);
179 #endif // DEBUG
180 #endif
181
182 if(InitPICE()){
183 DriverObject->MajorFunction[IRP_MJ_CREATE] = pice_open;
184 //ei unimplemented DriverObject->MajorFunction[IRP_MJ_CLOSE] = pice_close;
185 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = pice_ioctl;
186
187 RtlRosInitUnicodeStringFromLiteral(&DeviceName, L"\\Device\\Pice");
188 IoCreateDevice(DriverObject,
189 0,
190 &DeviceName,
191 PICE_DEVICE_DEBUGGER,
192 0,
193 TRUE,
194 &DeviceObject);
195 DeviceObject->Flags = DeviceObject->Flags | DO_BUFFERED_IO;
196
197 RtlRosInitUnicodeStringFromLiteral(&SymlinkName, L"\\??\\Pice");
198 IoCreateSymbolicLink(&SymlinkName, &DeviceName);
199
200 return(STATUS_SUCCESS);
201 }
202 }
203