- Implemented execp*.
[planlOS.git] / system / kernel / sys / serial.c
blob1eba2b49a7d52f017afd20c07d3d202d18f2809d
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #include "sys/serial.h"
23 #include "ke/ports.h"
24 #include "fs/devfs.h"
25 #include "fs/request.h"
27 #define SERIAL 0x3f8
29 static void sysSerialPrintChar(char c)
31 // Serial output
32 while ((inb(SERIAL + 5) & 0x20) == 0);
33 outb(SERIAL, c);
36 static int sysTerminalRequest(struct FsDeviceFile *file, FsRequest *request)
38 switch (request->type)
40 case FS_REQUEST_READ:
41 request->return_value = 0;
42 fsFinishRequest(request);
43 break;
44 case FS_REQUEST_WRITE:
46 uint32_t i;
47 for (i = 0; i < request->bufferlength; i++)
49 sysSerialPrintChar(((char*)request->buffer)[i]);
51 request->return_value = request->bufferlength;
52 fsFinishRequest(request);
54 break;
55 case FS_REQUEST_IOCTL:
56 request->return_value = -1;
57 fsFinishRequest(request);
58 break;
59 default:
60 request->return_value = -1;
61 fsFinishRequest(request);
63 return 0;
66 static FsDeviceFile serialfile;
68 void sysInitSerial(void)
70 serialfile.path = "serial";
71 serialfile.query_request = sysTerminalRequest;
72 fsCreateDeviceFile(&serialfile);