:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / apps / 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 <ddk/ntddk.h>
49 #include <debug.h>
50
51 #include "precomp.h"
52 #include "serial.h"
53
54 ////////////////////////////////////////////////////
55 // GLOBALS
56 ////
57
58 BOOLEAN bDeviceAlreadyOpen = FALSE;
59
60 char tempPICE[1024];
61
62 ////////////////////////////////////////////////////
63 // FUNCTIONS
64 ////
65
66 //*************************************************************************
67 // pice_open()
68 //
69 //*************************************************************************
70
71 NTSTATUS STDCALL pice_open(PDEVICE_OBJECT DeviceObject, PIRP Irp)
72 {
73     DPRINT((0,"pice_open\n"));
74
75     /* We don't want to talk to two processes at the
76     * same time */
77     if (bDeviceAlreadyOpen){
78                 IoCompleteRequest (Irp, IO_NO_INCREMENT);
79                 return STATUS_UNSUCCESSFUL;     /* is there a more descriptive status code for this case? */
80         }
81
82     bDeviceAlreadyOpen = TRUE;
83         IoCompleteRequest (Irp, IO_NO_INCREMENT);
84         return STATUS_SUCCESS;
85 }
86
87 //*************************************************************************
88 // pice_close()
89 //
90 //*************************************************************************
91 NTSTATUS STDCALL pice_close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
92 {
93     DPRINT((0,"pice_close\n"));
94
95         CleanUpPICE();                      // used to be in cleanup_module
96
97         /* We're now ready for our next caller */
98     bDeviceAlreadyOpen = FALSE;
99         IoCompleteRequest (Irp, IO_NO_INCREMENT);
100
101         return STATUS_SUCCESS;
102 }
103
104
105 //*************************************************************************
106 // pice_ioctl()
107 //
108 //*************************************************************************
109
110 NTSTATUS STDCALL pice_ioctl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
111 {
112 //      char* pFilename = (char*) ioctl_param;
113
114         PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation( Irp );
115
116         ULONG Code = IoStack->Parameters.DeviceIoControl.IoControlCode;
117
118         switch(Code)
119         {
120                 case PICE_IOCTL_LOAD:
121             break;
122                 case PICE_IOCTL_RELOAD:
123             if(!ReloadSymbols())
124             {
125                             PICE_sprintf(tempPICE,"pICE: not able to reload symbols\n");
126                             Print(OUTPUT_WINDOW,tempPICE);
127             }
128                         break;
129                 case PICE_IOCTL_UNLOAD:
130             UnloadSymbols();
131                         break;
132                 case PICE_IOCTL_BREAK:
133                         PICE_sprintf(tempPICE,"pICE: forcible break\n");
134                         Print(OUTPUT_WINDOW,tempPICE);
135             __asm__ __volatile("int $3");
136             break;
137                 case PICE_IOCTL_STATUS:
138             {
139                 PDEBUGGER_STATUS_BLOCK ustatus_block_p;
140                 DEBUGGER_STATUS_BLOCK kstatus_block;
141
142                                 ULONG OutLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
143                                 if( OutLength < sizeof( DEBUGGER_STATUS_BLOCK ) ){
144                                         return STATUS_INVALID_PARAMETER;
145                                 }
146
147                                 ustatus_block_p = (PDEBUGGER_STATUS_BLOCK)Irp->AssociatedIrp.SystemBuffer;
148
149                 //kstatus_block.Test = 0x12345678;
150                 RtlCopyMemory(ustatus_block_p, &kstatus_block, sizeof(DEBUGGER_STATUS_BLOCK) );
151             }
152             break;
153         default:
154                         IoCompleteRequest (Irp, IO_NO_INCREMENT);
155                         return STATUS_INVALID_PARAMETER;
156         }
157         IoCompleteRequest (Irp, IO_NO_INCREMENT);
158     return STATUS_SUCCESS;
159 }
160
161
162 NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT DriverObject,
163                              PUNICODE_STRING RegistryPath)
164 /*
165  * FUNCTION: Module entry point
166  */
167 {
168    PDEVICE_OBJECT DeviceObject;
169    UNICODE_STRING DeviceName;
170    UNICODE_STRING SymlinkName;
171
172    DPRINT((0,"PICE Debugger\n"));
173
174 #if 0                                   // don't enable before completely ported
175 #ifdef DEBUG
176     // first we enable output of debug strings to COM port
177     DebugSetupSerial(1,115200);
178 #endif // DEBUG
179 #endif
180
181    if(InitPICE()){
182                 DriverObject->MajorFunction[IRP_MJ_CREATE] = pice_open;
183                 //ei unimplemented DriverObject->MajorFunction[IRP_MJ_CLOSE] = pice_close;
184                 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = pice_ioctl;
185
186                 RtlInitUnicodeStringFromLiteral(&DeviceName, L"\\Device\\Pice");
187                 IoCreateDevice(DriverObject,
188                                 0,
189                                 &DeviceName,
190                                 PICE_DEVICE_DEBUGGER,
191                                 0,
192                                 TRUE,
193                                 &DeviceObject);
194                 DeviceObject->Flags = DeviceObject->Flags | DO_BUFFERED_IO;
195
196                 RtlInitUnicodeStringFromLiteral(&SymlinkName, L"\\??\\Pice");
197                 IoCreateSymbolicLink(&SymlinkName, &DeviceName);
198
199                 return(STATUS_SUCCESS);
200    }
201 }
202