22 #include "modules/system/vfs/Pipe.h" 24 #define MACHINE_FORWARD_DECL_ONLY 25 #include "pedigree/kernel/machine/Display.h" 26 #include "pedigree/kernel/machine/Framebuffer.h" 27 #include "pedigree/kernel/machine/InputManager.h" 28 #include "pedigree/kernel/machine/Machine.h" 29 #include "pedigree/kernel/machine/Vga.h" 31 #include "modules/system/console/Console.h" 32 #include "pedigree/kernel/utilities/assert.h" 34 #include "pedigree/kernel/ServiceManager.h" 35 #include "pedigree/kernel/graphics/Graphics.h" 36 #include "pedigree/kernel/graphics/GraphicsService.h" 38 #include "pedigree/kernel/utilities/utility.h" 43 #define ALT_KEY (1ULL << 60) 44 #define SHIFT_KEY (1ULL << 61) 45 #define CTRL_KEY (1ULL << 62) 46 #define SPECIAL_KEY (1ULL << 63) 60 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
64 size_t realSize = size;
66 if (size <
sizeof(uint64_t))
68 uint64_t val = random_next();
69 char *pBuffer =
reinterpret_cast<char *
>(buffer);
72 *pBuffer++ = val & 0xFF;
79 char *pBuffer =
reinterpret_cast<char *
>(buffer);
82 uint64_t align = random_next();
85 *pBuffer++ = align & 0xFF;
91 uint64_t *pBuffer64 =
reinterpret_cast<uint64_t *
>(buffer);
94 *pBuffer64++ = random_next();
99 return realSize - size;
103 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
109 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
115 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
123 :
File(str, 0, 0, 0, inode, pParentFS, 0, pParent), m_Terminals(),
124 m_pPtsDirectory(ptsDirectory)
127 FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
132 PtmxFile::~PtmxFile()
134 delete m_pPtsDirectory;
138 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
144 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
152 size_t terminal = m_Terminals.getFirstClear();
153 m_Terminals.set(terminal);
156 String masterName, slaveName;
157 masterName.Format(
"pty%d", terminal);
158 slaveName.Format(
"%d", terminal);
161 terminal, masterName, m_pPtsDirectory->getFilesystem());
163 terminal, slaveName, m_pPtsDirectory->getFilesystem());
165 pMaster->setOther(pSlave);
166 pSlave->setOther(pMaster);
168 m_pPtsDirectory->addEntry(slaveName, pSlave);
177 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
179 ByteSet(reinterpret_cast<void *>(buffer), 0, size);
184 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
190 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
196 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
211 NOTICE(
"RtcFile: command " <<
Hex << command <<
" with buffer " << buffer);
215 FramebufferFile::FramebufferFile(
217 :
File(str, 0, 0, 0, inode, pParentFS, 0, pParentNode),
218 m_pGraphicsParameters(0), m_bTextMode(
false), m_nDepth(0)
226 FramebufferFile::~FramebufferFile()
228 delete m_pGraphicsParameters;
231 bool FramebufferFile::initialise()
242 m_pGraphicsParameters->wantTextMode =
false;
243 if (!pService->
serve(
245 sizeof(*m_pGraphicsParameters)))
247 delete m_pGraphicsParameters;
248 m_pGraphicsParameters = 0;
256 m_pGraphicsParameters->providerResult.pFramebuffer
258 m_pGraphicsParameters->providerResult.pFramebuffer
259 ->getBytesPerLine());
264 return pFeatures && pService;
269 if (!m_pGraphicsParameters)
272 if (location > getSize())
274 ERROR(
"FramebufferFile::readBlock with location > size: " << location);
279 return reinterpret_cast<uintptr_t
>(m_pGraphicsParameters->providerResult
280 .pFramebuffer->getRawBuffer()) +
286 return (PEDIGREE_FB_CMD_MIN <= command) && (command <= PEDIGREE_FB_CMD_MAX);
291 if (!m_pGraphicsParameters)
293 ERROR(
"FramebufferFile::command called on an invalid FramebufferFile");
297 Display *pDisplay = m_pGraphicsParameters->providerResult.pDisplay;
299 m_pGraphicsParameters->providerResult.pFramebuffer;
303 case PEDIGREE_FB_SETMODE:
307 size_t desiredWidth = arg->width;
308 size_t desiredHeight = arg->height;
309 size_t desiredDepth = arg->depth;
312 if (!(desiredWidth && desiredHeight && desiredDepth))
314 bool bSuccess =
false;
315 if (!m_pGraphicsParameters->providerResult.bTextModes)
322 if (Machine::instance().getNumVga())
325 Vga *pVga = Machine::instance().
getVga(0);
339 NOTICE(
"FramebufferFile: set text mode");
349 while (desiredDepth > 8)
352 desiredWidth, desiredHeight, desiredDepth))
355 "FramebufferFile: set mode " 356 <<
Dec << desiredWidth <<
"x" << desiredHeight <<
"x" 357 << desiredDepth <<
Hex <<
".");
366 m_nDepth = desiredDepth;
369 pFramebuffer->getHeight() *
370 pFramebuffer->getBytesPerLine());
372 if (m_pGraphicsParameters->providerResult.bTextModes &&
379 Vga *pVga = Machine::instance().
getVga(0);
387 return bSet ? 0 : -1;
389 case PEDIGREE_FB_GETMODE:
395 ByteSet(arg, 0,
sizeof(*arg));
399 arg->width = pFramebuffer->getWidth();
400 arg->height = pFramebuffer->getHeight();
401 arg->depth = m_nDepth;
402 arg->bytes_per_pixel = pFramebuffer->getBytesPerPixel();
403 arg->format = pFramebuffer->getFormat();
408 case PEDIGREE_FB_REDRAW:
416 0, 0, pFramebuffer->getWidth(), pFramebuffer->getHeight(),
421 pFramebuffer->
redraw(arg->x, arg->y, arg->w, arg->h,
true);
434 :
File(str, 0, 0, 0, inode, pParentFS, 0, pParent), m_pDevFs(devfs)
437 FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
442 Tty0File::~Tty0File()
447 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
453 uint64_t location, uint64_t size, uintptr_t buffer,
bool bCanBlock)
461 return m_pDevFs->getTerminalManager().getCurrentTerminalFile();
467 NOTICE(
"MemFile: giving matching physical page for offset " <<
Hex << offset);
471 return offset & ~0xFFF;
479 DevFsDirectory::~DevFsDirectory() =
default;
505 m_pRoot->setPermissions(
506 FILE_UR | FILE_UW | FILE_UX | FILE_GR | FILE_GW | FILE_GX | FILE_OR |
514 m_pRoot->addEntry(pNull->
getName(), pNull);
515 m_pRoot->addEntry(pZero->
getName(), pZero);
519 m_pRoot->addEntry(pMem->
getName(), pMem);
523 String(
"pts"), 0, 0, 0, getNextInode(),
this, 0, m_pRoot);
524 pPts->setPermissions(
525 FILE_UR | FILE_UW | FILE_UX | FILE_GR | FILE_GX | FILE_OR | FILE_OX);
526 m_pRoot->addEntry(pPts->
getName(), pPts);
530 new PtmxFile(
String(
"ptmx"), getNextInode(),
this, m_pRoot, pPts);
531 m_pRoot->addEntry(pPtmx->
getName(), pPtmx);
536 m_pRoot->addEntry(pUrandom->
getName(), pUrandom);
541 m_pRoot->addEntry(pRandom->
getName(), pRandom);
546 if (pFb->initialise())
547 m_pRoot->addEntry(pFb->
getName(), pFb);
550 WARNING(
"POSIX: no /dev/fb - framebuffer failed to initialise.");
556 if (!m_VtManager->initialise())
558 WARNING(
"POSIX: no /dev/tty - VT manager failed to initialise");
560 m_VtManager =
nullptr;
565 new Tty0File(
String(
"tty0"), getNextInode(),
this, m_pRoot,
this);
566 m_pRoot->addEntry(pTty0->
getName(), pTty0);
570 new Tty0File(
String(
"console"), getNextInode(),
this, m_pRoot,
this);
571 m_pRoot->addEntry(pConsole->
getName(), pConsole);
575 m_pTty =
new TextIO(
String(
"textui"), getNextInode(),
this, m_pRoot);
576 m_pTty->markPrimary();
577 if (m_pTty->initialise(
false))
579 m_pRoot->addEntry(m_pTty->getName(), m_pTty);
583 WARNING(
"POSIX: no /dev/tty - TextIO failed to initialise.");
591 new Tty0File(
String(
"tty0"), getNextInode(),
this, m_pRoot,
this);
592 m_pRoot->addEntry(pTty0->
getName(), pTty0);
596 new Tty0File(
String(
"console"), getNextInode(),
this, m_pRoot,
this);
597 m_pRoot->addEntry(pConsole->
getName(), pConsole);
604 m_pRoot->addEntry(pTty1->
getName(), pTty1);
607 m_pTtyFiles[0] = pTty1;
611 for (
size_t i = 1; i < DEVFS_NUMTTYS; ++i)
614 ttyname.Format(
"tty%u", i + 1);
616 TextIO *tio =
new TextIO(ttyname, getNextInode(),
this, m_pRoot);
621 m_pRoot->addEntry(tio->
getName(), file);
624 m_pTtyFiles[i] = file;
634 WARNING(
"POSIX: failed to create " << ttyname);
638 m_pTtys[i] =
nullptr;
639 m_pTtyFiles[i] =
nullptr;
645 new Pipe(
String(
"initctl"), 0, 0, 0, getNextInode(),
this, 0, m_pRoot);
646 m_pRoot->addEntry(initctl->
getName(), initctl);
650 m_pRoot->addEntry(rtc->
getName(), rtc);
654 if (pPsAux->initialise())
656 m_pRoot->addEntry(pPsAux->
getName(), pPsAux);
657 m_pPsAuxFile = pPsAux;
673 size_t DevFs::getNextInode()
675 return m_NextInode++;
678 void DevFs::revertInode()
685 uint64_t c = in.data.key.key;
688 uint32_t k = c & 0xFFFFFFFFUL;
689 char *s =
reinterpret_cast<char *
>(&k);
692 if (!StringCompareN(s,
"f1", 3))
696 else if (!StringCompareN(s,
"f2", 3))
700 else if (!StringCompareN(s,
"f3", 3))
704 else if (!StringCompareN(s,
"f4", 3))
708 else if (!StringCompareN(s,
"f5", 3))
712 else if (!StringCompareN(s,
"f6", 3))
721 m_VtManager->activate(newTty);
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual int command(const size_t command, void *buffer)
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual void restoreMode()=0
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual int command(const size_t command, void *buffer)
virtual physical_uintptr_t getPhysicalPage(size_t offset)
void setUidOnly(size_t uid)
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual int command(const size_t command, void *buffer)
virtual void rememberMode()=0
virtual bool initialise(Disk *pDisk)
All zeroes = 'revert to text mode'.
virtual bool provides(Type service)
virtual Vga * getVga(size_t n)=0
virtual bool setMode(int mode)=0
void setPermissionsOnly(uint32_t perms)
virtual uintptr_t readBlock(uint64_t location)
void redraw(size_t x=~0UL, size_t y=~0UL, size_t w=~0UL, size_t h=~0UL, bool bChild=false)
bool initialise(bool bClear=true)
virtual bool supports(const size_t command) const
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
void setGidOnly(size_t gid)
virtual bool supports(const size_t command) const
Abstracts the system's framebuffer offering.
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual void returnPhysicalPage(size_t offset)
virtual size_t getNumVga()=0
Service * getService(const String &serviceName)
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual bool serve(ServiceFeatures::Type type, void *pData, size_t dataLen)=0
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
virtual bool setLargestTextMode()=0
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
ServiceFeatures * enumerateOperations(const String &serviceName)
virtual bool setScreenMode(ScreenMode sm)
virtual uint64_t write(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final