Example #1
0
int DiskCreate() {
  char *filename = NULL;
  int fsfd = -1;
  disk_block b;
  int i;

  // Check that you remembered to rename the filename for your group
  filename = DISK_FILENAME;
  if (filename[11] == 'X') {
    printf("DiskCreate: you didn't change the filesystem filename in include/os/disk.h.  Cowardly refusing to do anything.\n");
    GracefulExit();
  }
  // Open the hard disk file
  if ((fsfd = FsOpen(DISK_FILENAME, FS_MODE_WRITE)) < 0) {
    printf ("DiskCreate: File system %s cannot be opened!\n", DISK_FILENAME);
    return DISK_FAIL;
  }

  // Write all zeros to the hard disk file to make sure it is the right size.
  // You need to do this because the writeblock/readblock operations are allowed in
  // random order.
  bzero(b.data, DISK_BLOCKSIZE);
  for(i=0; i<DISK_NUMBLOCKS; i++) {
    FsWrite(fsfd, b.data, DISK_BLOCKSIZE);
  }
  
  // Close the hard disk file
  if (FsClose(fsfd) < 0) {
    printf("DiskCreate: unable to close open file!\n");
    return DISK_FAIL;
  }
  return DISK_SUCCESS;
}
Example #2
0
File: test.c Project: 1tgr/mobius
void testCharDeviceIo(const wchar_t *name)
{
	handle_t file;
	fileop_t op;
	uint32_t key;
	
	file = FsOpen(name, FILE_READ);
	if (file == NULL)
		wprintf(L"Failed to open %s\n", name);
	else
	{
		op.event = EvtCreate(false);
		op.bytes = 0;
		wprintf(L"op = %p op.event = %u sig = %u\n", 
			&op,
			op.event, 
			EvtIsSignalled(op.event));
		if (op.event != NULL)
		{
			while (true)
			{
				status_t ret;

				ret = FsReadAsync(file, &key, 0, sizeof(key), &op);
				if (ret > 0)
					break;
				else if (ret == SIOPENDING)
				{
					DbgWrite(L"Wait start\n", 11);
					/*while (EvtIsSignalled(op.event))*/
						ThrWaitHandle(op.event);
					DbgWrite(L"Wait end\n", 9);
					ret = op.result;
				}

				/*wprintf(L"op.result = %d op.bytes = %u\n",
					op.result, op.bytes);*/
				if (ret == SIOPENDING)
					wprintf(L"op.result is still SIOPENDING\n");
				else
				{
					if (ret > 0 ||
						op.bytes == 0)
						break;
					wprintf(L"%c", (wchar_t) key);
					if (key == 27)
						break;
				}
				op.bytes = 0;
			}

			DbgWrite(L"Finished\n", 9);
			wprintf(L"Finished: op.result = %d, op.bytes = %u\n",
				op.result, op.bytes);
			HndClose(op.event);
		}
	}

	HndClose(file);
}
Example #3
0
//==============================================================
void *_MmFileLoadB(const char *file, int area)
//--------------------------------------------------------------
// malloc して読み込む
// ※ブロックタイプ
//--------------------------------------------------------------
// in:	file = ファイル名
//		area = 読み込みエリア
//--------------------------------------------------------------
// out:	読み込みアドレス
//==============================================================
{
	sFILE *fp;
	size_t len;
	void *p;

	fp = FsOpen(file);
	ASSERT(fp);
	len = FsGetSizeOrig(fp);
	p = MemMalloc(area, len, GetFileBaseName(file));
	ASSERT(p);
	FsRead(fp, p, len);
	FsClose(fp);

	mn_read_size = len;							// FIXME:実ファイルサイズを返すべきか?

//	PRINTF("File '%s' Loaded.(%d bytes)\n", file, len);

	return p;
}
Example #4
0
//==============================================================
void *MmTextFileLoad(const char *file)
//--------------------------------------------------------------
// テキストファイルを読み込む
// ※データ終端に '\0' を付加します
//--------------------------------------------------------------
// in:	file = ファイル名
//--------------------------------------------------------------
// out:	読み込みアドレス
//==============================================================
{
	sFILE *fp;
	size_t len;
	char *p;

	fp = FsOpen(file);
	ASSERT(fp);
	len = FsGetSizeOrig(fp);
	p = (char *)fsMalloc(len + 1, "text data");
	ASSERT(p);
	FsRead(fp, p, len);
	FsClose(fp);

	*(p + len) = '\0';

	return p;
}
Example #5
0
//==============================================================
void MakeBackupFile(const char *fname)
//--------------------------------------------------------------
// PATH_BACKUP にバックアップをとる
//--------------------------------------------------------------
// in:	file = バックアップを取るファイル名
//--------------------------------------------------------------
// out:	なし
//==============================================================
{
	char d_name[FNAME_MAXLEN];
	void *tmp_buf;
	sFILE *fd_src, *fd_dst;
	size_t len, size;

	// オリジナルのファイルを開く
	//----------------------------
	fd_src = FsOpen(fname);
	if(!fd_src)
	{
		return;
	}

	// バックアップファイルの作成
	//----------------------------
	sprintf(d_name, PATH_BACKUP"/%s.%s", GetFileBaseName(fname), StrMakeUniqueName());
	fd_dst = FsCreate(d_name);
	if (!fd_dst)
	{
		FsClose(fd_src);
		return;
	}

	// 作業バッファを確保
	//--------------------
	tmp_buf = devMalloc(TMPBUF_LEN, "MakeBackupFile");

	len = FsGetSizeOrig(fd_src);
	while(len)
	{
		size = (len >= TMPBUF_LEN) ? TMPBUF_LEN : len;
		FsRead(fd_src, tmp_buf, size);
		FsWrite(fd_dst, tmp_buf, size);

		len -= size;
	}

	FsClose(fd_src);
	FsClose(fd_dst);

	Free(tmp_buf);

//	SYSINFODSP("Make Backup file");
//	SYSINFODSP("%s", MSG_FILE(d_name));
//	SYSINFO("Make Backup file");
//	SYSINFO("%s", MSG_FILE(d_name));
//	SYSINFOCNS("Make Backup file");
//	SYSINFOCNS("%s", MSG_FILE(d_name));
}
Example #6
0
bool GmgrInit(void)
{
    params_vid_t params;
    handle_t device;

    LmuxInit(&gmgr_draw);
    LmuxInit(&gmgr_mux_gfxs);
    atexit(GmgrCleanup);

    device = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE);
    if (device == NULL)
    {
        _wdprintf(SYS_DEVICES L"/Classes/video0" L": %s\n", _wcserror(errno));
        goto error0;
    }

    memset(&params.vid_setmode, 0, sizeof(params.vid_setmode));
    if (!FsRequestSync(device, VID_SETMODE, &params, sizeof(params), NULL))
    {
        _wdprintf(L"VID_SETMODE: %s\n", _wcserror(errno));
        goto error1;
    }

    gmgr_screen = GmgrCreateDeviceSurface(device, &params.vid_setmode);
    if (gmgr_screen == NULL)
    {
        _wdprintf(L"GmgrCreateDeviceSurface: %s\n", _wcserror(errno));
        goto error1;
    }

    gmgr_font = FontLoad(L"/Mobius/veramono.ttf", 12 * 64, 
        gmgr_screen->mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH);
    if (gmgr_font == NULL)
    {
        _wdprintf(L"/Mobius/veramono.ttf: %s\n", _wcserror(errno));
        goto error2;
    }

    if (!GmgrInitCursor())
        goto error3;

    return true;

error3:
    FontDelete(gmgr_font);
    gmgr_font = NULL;
error2:
    GmgrCloseSurface(gmgr_screen);
    gmgr_screen = NULL;
error1:
    HndClose(device);
error0:
    return false;
}
Example #7
0
File: test.c Project: 1tgr/mobius
void testFileIo(const wchar_t *name)
{
	handle_t file;
	unsigned i;
	size_t len;
	fileop_t op;
	uint64_t offset;
	
	file = FsOpen(name, FILE_READ);
	if (file == NULL)
	{
		wprintf(L"Failed to open %s\n", name);
		return;
	}

	op.event = EvtCreate(false);
	for (i = 0; i < 16; i++)
	{
		offset = 0;
		wprintf(L"\x1b[%um", (i % 8) + 30);
		while (true)
		{
			status_t ret;

			ret = FsReadAsync(file, key, offset, sizeof(key), &op);
			if (ret > 0)
				break;
			else if (ret == SIOPENDING)
			{
				ThrWaitHandle(op.event);
				ret = op.result;
			}
			len = op.bytes;
			if (len == 0)
				break;
			
			if (len < sizeof(key))
				key[len] = '\0';
			len = mbstowcs(str, key, _countof(key) - 1);
			if (len == -1)
				wprintf(L"invalid multibyte sequence\n");
			else
				_cputws(str, len);

			offset += op.bytes;
		}

		ThrSleep(5000);
	}

	HndClose(op.event);
	HndClose(file);
}
Example #8
0
File: test.c Project: 1tgr/mobius
void testBlockDeviceIo(const wchar_t *name)
{
	handle_t file;
	unsigned i, j;
	fileop_t op;
	wchar_t *ch;

	file = FsOpen(name, FILE_READ);
	if (file == NULL)
		wprintf(L"Failed to open %s\n", name);
	else
	{
		op.event = EvtCreate(false);
		for (j = 0; j < 1; j++)
		{
			status_t ret;

			wprintf(/*L"\x1b[2J"*/ L"\x1b[%um", (j % 8) + 30);

			ret = FsReadAsync(file, key, 9 * 512, sizeof(key), &op);
			if (ret > 0)
				break;
			else if (ret == SIOPENDING)
			{
				ThrWaitHandle(op.event);
				ret = op.result;
			}
			
			if (ret == SIOPENDING)
				wprintf(L"op.result is still SIOPENDING\n");
			else if (ret == 0 && op.bytes > 0)
			{
				wprintf(L"Read %u bytes\n", op.bytes);
				ch = str;
				for (i = 0; i < op.bytes; i++)
				{
					swprintf(ch, L"%02X", key[i]);
					ch += 2;
				}
				_cputws(str, op.bytes * 2);
				/*for (i = 0; i < op.bytes; i++)
					wprintf(L"%02X", key[i]);*/
			}
			else
				break;
		}
		DbgWrite(L"Finished\n", 9);
		wprintf(L"Finished: op.result = %d, op.bytes = %u\n",
			op.result, op.bytes);
		HndClose(op.event);
	}
	HndClose(file);
}
Example #9
0
//==============================================================
BOOL MmFileCheck(const char *file)
//--------------------------------------------------------------
// ファイルが存在するかチェック
//--------------------------------------------------------------
// in:	file = ファイル名
//--------------------------------------------------------------
// out:	TRUE = 存在する
//==============================================================
{
	sFILE *fp;

	fp = FsOpen(file);
	if(fp)	FsClose(fp);

	return fp ? TRUE : FALSE;
}
Example #10
0
File: cdfs.c Project: 1tgr/mobius
static vnode_id_t CdfsAllocNode(cdfs_t *cdfs, 
								vnode_id_t parent, 
								unsigned index_within_parent, 
								const entry_t *entry,
								const wchar_t *name)
{
    vnode_id_t id;
    cdnode_t *cdnode;

	id = CdfsGenerateNodeId(cdfs, parent, index_within_parent);

    cdnode = CdfsGetNode(cdfs, id);
	if (cdnode != VNODE_NONE)
	{
		CdfsReleaseNode(cdfs, cdnode);
		return id;
	}

	cdnode = malloc(sizeof(*cdnode));
	if (cdnode == NULL)
		return VNODE_NONE;

    cdnode->id = id;
    cdnode->locks = 0;
    cdnode->parent = parent;
    cdnode->entry = *entry;
	cdnode->name = _wcsdup(name);
	cdnode->directory = NULL;
	cdnode->next = cdfs->nodes[cdnode->id % _countof(cdfs->nodes)];
	cdfs->nodes[id % _countof(cdfs->nodes)] = cdnode;

	if (cdnode->entry.flags & DIR_FLAG_DIRECTORY)
	{
		vnode_t vnode_this = { &cdfs->fsd, id };

		cdnode->directory = FsOpen(&vnode_this, L"/", FILE_READ);
		if (cdnode->directory == NULL)
			wprintf(L"CdfsAllocVnode: failed to open %x as a directory\n", id);
	}

    return id;
}
Example #11
0
int DiskWriteBlock (uint32 blocknum, disk_block *b) {
  int fsfd = -1;
  uint32 intrvals = 0;
  char *filename = NULL;

  if (blocknum >= DISK_NUMBLOCKS) {
    printf("DiskWriteBlock: cannot write to block larger than filesystem size\n");
    return DISK_FAIL;
  }

  // Check that you remembered to rename the filename for your group
  filename = DISK_FILENAME;
  if (filename[11] == 'X') {
    printf("DiskWriteBlock: you didn't change the filesystem filename in include/os/disk.h.  Cowardly refusing to do anything.\n");
    GracefulExit();
  }

  intrvals = DisableIntrs();

  // Open the hard disk file
  if ((fsfd = FsOpen(DISK_FILENAME, FS_MODE_RW)) < 0) {
    printf ("DiskWriteBlock: File system %s cannot be opened!\n", DISK_FILENAME);
    return DISK_FAIL;
  }

  /* printf("DiskWriteBlock: fsfd = %d\n", fsfd); */

  // Write data to virtual disk
  FsSeek(fsfd, blocknum * DISK_BLOCKSIZE, FS_SEEK_SET);
  if (FsWrite(fsfd, b->data, DISK_BLOCKSIZE) != DISK_BLOCKSIZE) {
    printf ("DiskWriteBlock: Block %d could not be written!\n", blocknum);
    FsClose (fsfd);
    return DISK_FAIL;
  }

  // Close the hard disk file
  FsClose (fsfd);

  RestoreIntrs(intrvals);
  return DISK_BLOCKSIZE;
}
Example #12
0
//----------------------------------------------------------------------
//
//	ProcessGetCodeSizes
//
//	Get the code sizes (stack & data) for a file.  A file descriptor
//	for the named file is returned.  This descriptor MUST be closed
//	(presumably by the caller) at some point.
//
//----------------------------------------------------------------------
int
ProcessGetCodeInfo (const char *file, uint32 *startAddr,
		    uint32 *codeStart, uint32 *codeSize,
		     uint32 *dataStart, uint32 *dataSize)
{
  int		fd;
  int		totalsize;
  char		buf[100];
  char		*pos;

  // Open the file for reading.  If it returns a negative number, the open
  // didn't work.
  if ((fd = FsOpen (file, FS_MODE_READ)) < 0) {
    dbprintf ('f', "ProcessGetCodeInfo: open of %s failed (%d).\n",
	      file, fd);
    return (-1);
  }
  dbprintf ('f', "File descriptor is now %d.\n", fd);
  if ((totalsize = FsRead (fd, buf, sizeof (buf))) != sizeof (buf)) {
    dbprintf ('f', "ProcessGetCodeInfo: read got %d (not %d) bytes from %s\n",
	      totalsize, (int)sizeof (buf), file);
    FsClose (fd);
    return (-1);
  }
  if (dstrstr (buf, "start:") == NULL) {
    dbprintf ('f', "ProcessGetCodeInfo: %s missing start line (not a DLX executable?)\n", file);
    return (-1);
  }
  pos = (char *)dindex (buf, ':') + 1;
  // Get the start address and overall size
  *startAddr = dstrtol (pos, &pos, 16);
  totalsize = dstrtol (pos, &pos, 16);
  // Get code & data section start & sizes
  *codeStart = dstrtol (pos, &pos, 16);
  *codeSize = dstrtol (pos, &pos, 16);
  *dataStart = dstrtol (pos, &pos, 16);
  *dataSize = dstrtol (pos, &pos, 16);
  // Seek to start of first real line
  FsSeek (fd, 1 + dindex (buf, '\n') - buf, 0);
  return (fd);
}
Example #13
0
File: test.c Project: 1tgr/mobius
wchar_t _wgetch(void)
{
	static handle_t keyb, keyb_event;
	fileop_t op;
	uint32_t key;

	if (keyb == NULL)
	{
		keyb = FsOpen(SYS_DEVICES L"/keyboard", FILE_READ);
		if (keyb == NULL)
			return (wchar_t) -1;
	}

	if (keyb_event == NULL)
	{
		keyb_event = EvtCreate(false);
		if (keyb_event == NULL)
			return (wchar_t) -1;
	}
	
	op.event = keyb_event;
	do
	{
		status_t ret;
		
		ret = FsReadAsync(keyb, &key, 0, sizeof(key), &op);
		if (ret > 0)
			return false;
		else if (ret == SIOPENDING)
		{
			ThrWaitHandle(op.event);
			ret = op.result;
		}

		if (ret != 0 || op.bytes == 0)
			return -1;
	} while ((wchar_t) key == 0);

	return (wchar_t) key;
}
Example #14
0
File: wfopen.c Project: 1tgr/mobius
FILE *
_wfopen(const wchar_t *file, const wchar_t *mode)
{
    FILE *f;
    int fd, rw, oflags = 0;
    /*char tbchar;*/

    if (file == 0)
        return 0;
    if (mode == 0)
        return 0;

    rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));

    switch (*mode)
    {
    case 'a':
        oflags = FILE_CREATE_OPEN | (rw ? FILE_READ | FILE_WRITE : FILE_WRITE);
        break;
    case 'r':
        oflags = FILE_FORCE_OPEN | (rw ? FILE_READ | FILE_WRITE : FILE_READ);
        break;
    case 'w':
        oflags = FILE_FORCE_CREATE | (rw ? FILE_READ | FILE_WRITE : FILE_READ);
        break;
    default:
        return (NULL);
    }
    
    /* xxx - text/binary distinction ignored for Mobius */
    /*if (mode[1] == '+')
        tbchar = mode[2];
    else
        tbchar = mode[1];

    if (tbchar == 't')
        oflags |= O_TEXT;
    else if (tbchar == 'b')
        oflags |= O_BINARY;
    else
        oflags |= (_fmode & (O_TEXT|O_BINARY));*/

    fd = FsOpen(file, oflags);
    if (fd == NULL)
        return NULL;

    f = __alloc_file();
    if (f == NULL)
        return NULL;

    if (*mode != 'a' ||
		!FsGetFileLength(fileno(f), &f->_offset))
        f->_offset = 0;

    f->_cnt = 0;
    f->_file = fd;
    f->_bufsiz = 0;
    f->_flag = oflags;

    f->_base = f->_ptr = NULL;
    return f;
}
Example #15
0
//----------------------------------------------------------------------
//
//	main
//
//	This routine is called when the OS starts up.  It allocates a
//	PCB for the first process - the one corresponding to the initial
//	thread of execution.  Note that the stack pointer is already
//	set correctly by _osinit (assembly language code) to point
//	to the stack for the 0th process.  This stack isn't very big,
//	though, so it should be replaced by the system stack of the
//	currently running process.
//
//----------------------------------------------------------------------
main (int argc, char *argv[])
{
  int		i, j;
  int		n;
  char	buf[120];
  char		*userprog = (char *)0;
  static PCB	temppcb;
  uint32	addr;
  extern void	SysprocCreateProcesses ();
  char *param[12]={NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  	 	   NULL, NULL, NULL, NULL};
  int base;

  debugstr[0] = '\0';
  MyFuncRetZero();
  printf ("Got %d arguments.\n", argc);
  printf ("Available memory: 0x%x -> 0x%x.\n", lastosaddress,
	  MemoryGetSize ());
  printf ("Argument count is %d.\n", argc);
  for (i = 0; i < argc; i++) {
    printf ("Argument %d is %s.\n", i, argv[i]);
  }
//  *((int *)0xfff00100) = 't';
  FsModuleInit ();
  for (i = 0; i < argc; i++)
  {
    if (argv[i][0] == '-')
    {
      switch (argv[i][1])
      {
      case 'D':
	dstrcpy (debugstr, argv[++i]);
	break;
      case 'i':
	n = dstrtol (argv[++i], (void *)0, 0);
	ditoa (n, buf);
	printf ("Converted %s to %d=%s\n", argv[i], n, buf);
	break;
      case 'f':
      {
	int	start, codeS, codeL, dataS, dataL, fd, j;
	int	addr = 0;
	static unsigned char buf[200];
	fd = ProcessGetCodeInfo (argv[++i], &start, &codeS, &codeL, &dataS,
				 &dataL);
	printf ("File %s -> start=0x%08x\n", argv[i], start);
	printf ("File %s -> code @ 0x%08x (size=0x%08x)\n", argv[i], codeS,
		codeL);
	printf ("File %s -> data @ 0x%08x (size=0x%08x)\n", argv[i], dataS,
		dataL);
	while ((n = ProcessGetFromFile (fd, buf, &addr, sizeof (buf))) > 0)
	{
	  for (j = 0; j < n; j += 4)
	  {
	    printf ("%08x: %02x%02x%02x%02x\n", addr + j - n, buf[j], buf[j+1],
		    buf[j+2], buf[j+3]);
	  }
	}
	close (fd);
	break;
      }
      case 'u':
	userprog = argv[++i];
        base = i;
	break;
      default:
	printf ("Option %s not recognized.\n", argv[i]);
	break;
      }
      if(userprog)
        break;
    }
  }
  dbprintf ('i', "About to initialize queues.\n");
  QueueModuleInit ();
  dbprintf ('i', "After initializing queues.\n");
  MemoryModuleInit ();
  dbprintf ('i', "After initializing memory.\n");

  ProcessModuleInit ();
  dbprintf ('i', "After initializing processes.\n");
  ShareModuleInit ();
  dbprintf ('i', "After initializing shared memory.\n");
  SynchModuleInit ();
  dbprintf ('i', "After initializing synchronization tools.\n");
  KbdModuleInit ();
  dbprintf ('i', "After initializing keyboard.\n");
  for (i = 0; i < 100; i++) {
    buf[i] = 'a';
  }
  i = FsOpen ("vm", FS_MODE_WRITE);
  dbprintf ('i', "VM Descriptor is %d\n", i);
  FsSeek (i, 0, FS_SEEK_SET);
  FsWrite (i, buf, 80);
  FsClose (i);
  if (userprog != (char *)0) {
      for(i=base;i<argc&&i-base<11; i++)
      {
        param[i-base] = argv[i];
      }
      process_create(0,0,param[0], param[1], param[2], param[3], param[4],
      		     param[5], param[6], param[7], param[8], param[9],
		     param[10], param[11]);
//    ProcessFork (0, (uint32)"Help Me man!", userprog, 1);
  }
  SysprocCreateProcesses ();
  dbprintf ('i', "Created processes - about to set timer quantum.\n");
  TimerSet (processQuantum);
  dbprintf ('i', "Set timer quantum to %d, about to run first process.\n",
	    processQuantum);
  intrreturn ();
  // Should never be called because the scheduler exits when there
  // are no runnable processes left.
  exitsim();	// NEVER RETURNS!
}
Example #16
0
int mainCRTStartup(void)
{
    handle_t server, client;
    unsigned i;
    params_vid_t params;
    font_t *font;

    vid = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE);
    if (vid == NULL)
    {
        _wdprintf(L"console: " SYS_DEVICES L"/Classes/video0: %s\n", _wcserror(errno));
        return errno;
    }

    memset(&mode, 0, sizeof(mode));
    params.vid_setmode = mode;
    if (!FsRequestSync(vid, VID_SETMODE, &params, sizeof(params), NULL))
    {
        _wdprintf(L"console: failed to set video mode: %s\n", _wcserror(errno));
        HndClose(vid);
        return errno;
    }

    mode = params.vid_setmode;

    if (mode.flags & VIDEO_MODE_TEXT)
    {
        _wdprintf(L"console: text mode not supported\n");
        return 0;
    }

    if (mode.bitsPerPixel == 4)
    {
        vidmem = NULL;
        if (!AccelCreateSurface(&mode, vid, &surf))
        {
            _wdprintf(L"console: AccelCreateSurface failed\n");
            return errno;
        }
    }
    else
    {
        handle_t handle_vidmem;

        handle_vidmem = HndOpen(mode.framebuffer);
        if (handle_vidmem == 0)
        {
            _wdprintf(L"console: unable to open framebuffer %s\n", mode.framebuffer);
            return errno;
        }

        vidmem = VmmMapSharedArea(handle_vidmem, 0, 
            VM_MEM_USER | VM_MEM_READ | VM_MEM_WRITE);
        HndClose(handle_vidmem);

        if (!FramebufCreateSurface(&mode, vidmem, &surf))
        {
            _wdprintf(L"console: video mode not supported: %u bits per pixel\n", mode.bitsPerPixel);
            return errno;
        }
    }

    FontInit();
    font = FontLoad(font_name, 10 * 64, 
        mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH);
    if (font == NULL)
    {
        _wdprintf(L"console: failed to load font %s\n", font_name);
        return errno;
    }

    cookies[0] = (void*) 0x12345678;

    num_buffers = 1;

    LmuxInit(&lmux_consoles);
    for (i = 0; i < _countof(consoles); i++)
    {
        LmuxInit(&consoles[i].lmux);
        consoles[i].width = consoles[i].height = 0;
        consoles[i].fg_colour = consoles[i].default_fg_colour = 0xc0c0c0;
        consoles[i].bg_colour = consoles[i].default_bg_colour = 0x000000;
        consoles[i].cookie = cookies[0];
        consoles[i].buf_chars = NULL;
        consoles[i].font = font;
        FontGetMaxSize(consoles[i].font, 
            &consoles[i].char_width, &consoles[i].char_height);
    }

    num_consoles = _countof(consoles);
    ConTileBuffer(0);
    num_consoles = 0;

    current = consoles;

    for (i = 0; i < _countof(consoles); i++)
        ConClear(consoles + i);

    server = FsCreate(server_name, 0);

    ThrCreateThread(ConKeyboardThread, NULL, 16, L"ConKeyboardThread");
    ThrCreateThread(ConCursorThread, NULL, 16, L"ConCursorThread");

    ConDisplaySignonMessage();

    while ((client = PortAccept(server, FILE_READ | FILE_WRITE)))
    {
        if (num_consoles < _countof(consoles))
        {
            consoles[num_consoles].client = client;
            ThrCreateThread(ConClientThread, consoles + num_consoles, 15, L"ConClientThread");
            num_consoles++;
        }
        else
            HndClose(client);
    }

    for (i = 0; i < _countof(consoles); i++)
    {
        LmuxDelete(&consoles[i].lmux);
        free(consoles[i].buf_chars);
    }

    LmuxDelete(&lmux_consoles);
    FontDelete(font);
    HndClose(server);
    if (vidmem != NULL)
        VmmFree(vidmem);
    HndClose(vid);
    return EXIT_SUCCESS;
}
Example #17
0
File: v86.c Project: 1tgr/mobius
void ShCmdV86(const wchar_t *cmd, wchar_t *params)
{
    uint8_t *code;
    psp_t *psp;
    FARPTR fp_code, fp_stackend;
    handle_t thr, file;
    dirent_standard_t di;
    bool doWait;
    wchar_t **names, **values;

    ShParseParams(params, &names, &values, &params);
    params = ShPrompt(L" .COM file? ", params);
    if (*params == '\0')
        return;

    doWait = true;
    if (ShHasParam(names, L"nowait"))
        doWait = false;
    
    free(names);
    free(values);

    /*if (!FsQueryFile(params, FILE_QUERY_STANDARD, &di, sizeof(di)))
    {
        _pwerror(params);
        return;
    }*/
    di.length = 0x10000;

    file = FsOpen(params, FILE_READ);
    if (file == NULL)
    {
        wprintf(L"FsOpen: ");
        _pwerror(params);
        return;
    }

    code = aligned_alloc(di.length + 0x100);
    psp = (psp_t*) code;
    memset(psp, 0, sizeof(*psp));
    psp->int20 = 0x20cd;

    if (!FsRead(file, code + 0x100, 0, di.length, NULL))
    {
        wprintf(L"FsRead: ");
        _pwerror(params);
        HndClose(file);
        return;
    }

    HndClose(file);

    fp_code = i386LinearToFp(code);
    fp_code = MK_FP(FP_SEG(fp_code), FP_OFF(fp_code) + 0x100);
        
    if (sh_v86stack == NULL)
        sh_v86stack = aligned_alloc(65536);

    fp_stackend = i386LinearToFp(sh_v86stack);
    memset(sh_v86stack, 0, 65536);
    
    thr = ThrCreateV86Thread(fp_code, fp_stackend, 15, ShV86Handler, params);
    if (doWait)
        ThrWaitHandle(thr);

    /* xxx - need to clean up HndClose() implementation before we can use this */
    /*HndClose(thr);*/
}
Example #18
0
static void ShDumpFile(const wchar_t *name, void (*fn)(const void*, addr_t, size_t))
{
    static char buf[16 + 1];

    handle_t file;
    size_t len;
    addr_t origin;
    dirent_standard_t di;
    char *ptr, *dyn;

    di.length = 0;
    if (!FsQueryFile(name, FILE_QUERY_STANDARD, &di, sizeof(di)) ||
        di.length == 0)
    {
        di.length = sizeof(buf) - 1;
        ptr = buf;
        dyn = NULL;
    }
    else
    {
        dyn = malloc(di.length);
        ptr = dyn;
    }

    printf("ShDumpFile(%S): reading in chunks of %lu\n", name, (uint32_t) di.length);
    file = FsOpen(name, FILE_READ);
    if (file == NULL)
    {
        _pwerror(name);
        return;
    }

    origin = 0;
    do
    {
        //KeLeakBegin();

        //printf("[b]");
		if (!FsRead(file, ptr, origin, di.length, &len))
		{
			_pwerror(name);
			break;
		}

		//KeLeakEnd();

        if (len == 0)
        {
            printf("FSD read zero bytes but didn't report an error\n");
            break;
        }

        if (len < di.length)
            ptr[len] = '\0';
        /*printf("%u", len);*/
        fn(ptr, origin, len);

        origin += len;
        if (len < di.length)
        {
            printf("FSD hit the end of the file: successful but only %u bytes read\n", len);
            break;
        }

        //printf("[e]");
        fflush(stdout);
    } while (true);

    free(dyn);
    HndClose(file);
}
Example #19
0
//----------------------------------------------------------------------
//
//	main
//
//	This routine is called when the OS starts up.  It allocates a
//	PCB for the first process - the one corresponding to the initial
//	thread of execution.  Note that the stack pointer is already
//	set correctly by _osinit (assembly language code) to point
//	to the stack for the 0th process.  This stack isn't very big,
//	though, so it should be replaced by the system stack of the
//	currently running process.
//
//----------------------------------------------------------------------
void main (int argc, char *argv[])
{
  int		i,j;
  int		n;
  char	buf[120];
  char		*userprog = (char *)0;
  int base=0;
  int numargs=0;
  char allargs[SIZE_ARG_BUFF];
  int allargs_offset = 0;
  
  debugstr[0] = '\0';

  printf ("Got %d arguments.\n", argc);
  printf ("Available memory: 0x%x -> 0x%x.\n", (int)lastosaddress, MemoryGetSize ());
  printf ("Argument count is %d.\n", argc);
  for (i = 0; i < argc; i++) {
    printf ("Argument %d is %s.\n", i, argv[i]);
  }

  FsModuleInit ();
  for (i = 0; i < argc; i++) 
  {
    if (argv[i][0] == '-') 
    {
      switch (argv[i][1]) 
      {
      case 'D':
	dstrcpy (debugstr, argv[++i]);
	break;
      case 'i':
	n = dstrtol (argv[++i], (void *)0, 0);
	ditoa (n, buf);
	printf ("Converted %s to %d=%s\n", argv[i], n, buf);
	break;
      case 'f':
      {
	int	start, codeS, codeL, dataS, dataL, fd, j;
	int	addr = 0;
	static unsigned char buf[200];
	fd = ProcessGetCodeInfo (argv[++i], &start, &codeS, &codeL, &dataS,
				 &dataL);
	printf ("File %s -> start=0x%08x\n", argv[i], start);
	printf ("File %s -> code @ 0x%08x (size=0x%08x)\n", argv[i], codeS,
		codeL);
	printf ("File %s -> data @ 0x%08x (size=0x%08x)\n", argv[i], dataS,
		dataL);
	while ((n = ProcessGetFromFile (fd, buf, &addr, sizeof (buf))) > 0) 
	{
	  for (j = 0; j < n; j += 4) 
	  {
	    printf ("%08x: %02x%02x%02x%02x\n", addr + j - n, buf[j], buf[j+1],
		    buf[j+2], buf[j+3]);
	  }
	}
	close (fd);
	break;
      }
      case 'u':
	userprog = argv[++i];
        base = i; // Save the location of the user program's name 
	break;
      default:
	printf ("Option %s not recognized.\n", argv[i]);
	break;
      }
      if(userprog)
        break;
    }
  }
  dbprintf ('i', "About to initialize queues.\n");
  AQueueModuleInit ();
  dbprintf ('i', "After initializing queues.\n");
  MemoryModuleInit ();
  dbprintf ('i', "After initializing memory.\n");

  ProcessModuleInit ();
  dbprintf ('i', "After initializing processes.\n");
  SynchModuleInit ();
  dbprintf ('i', "After initializing synchronization tools.\n");
  KbdModuleInit ();
  dbprintf ('i', "After initializing keyboard.\n");
  ClkModuleInit ();
  dbprintf ('i', "After initializing clock.\n");
  for (i = 0; i < 100; i++) {
    buf[i] = 'a';
  }
  i = FsOpen ("vm", FS_MODE_WRITE);
  dbprintf ('i', "VM Descriptor is %d\n", i);
  FsSeek (i, 0, FS_SEEK_SET);
  FsWrite (i, buf, 80);
  FsClose (i);

  // Setup command line arguments
  if (userprog != (char *)0) {
    numargs=0;
    allargs_offset = 0;
    // Move through each of the argv addresses
    for(i=0; i<argc-base; i++) {
      // At each argv address, copy the string into allargs, including the '\0'
      for(j=0; allargs_offset < SIZE_ARG_BUFF; j++) {
        allargs[allargs_offset++] = argv[i+base][j];
        if (argv[i+base][j] == '\0') break; // end of this string
      }
      numargs++;
    }
    allargs[SIZE_ARG_BUFF-1] = '\0'; // set last char to NULL for safety
    ProcessFork(0, (uint32)allargs, userprog, 1);
  } else {
    dbprintf('i', "No user program passed!\n");
  }
  ClkStart();
  dbprintf ('i', "Set timer quantum to %d, about to run first process.\n",
	    processQuantum);
  intrreturn ();
  // Should never be called because the scheduler exits when there
  // are no runnable processes left.
  exitsim();	// NEVER RETURNS!
}
Example #20
0
int ConKeyboardThread(void *param)
{
    uint32_t ch, code;
    handle_t keyboard;
    //void *old_buffer;
    //unsigned i;

    keyboard = FsOpen(SYS_DEVICES L"/keyboard", FILE_READ);
    while (FsRead(keyboard, &ch, 0, sizeof(ch), NULL))
    {
        code = ch & ~KBD_BUCKY_ANY;
        if ((ch & KBD_BUCKY_ALT) != 0 &&
            code >= KEY_F1 && 
            code <= KEY_F12)
        {
            /*LmuxAcquire(&lmux_consoles);
            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, false);

            old_buffer = current->cookie;
            current = consoles + code - KEY_F1;

            if (old_buffer != current->buffer)
                for (i = 0; i < num_consoles; i++)
                    if (consoles[i].buffer == current->buffer)
                        ConRedraw(consoles + i);

            ConDrawCursor(current, true);
            LmuxRelease(&current->lmux);
            LmuxRelease(&lmux_consoles);*/
        }
        else if (ch == (KBD_BUCKY_CTRL | KBD_BUCKY_ALT | KEY_DEL))
            SysShutdown(SHUTDOWN_REBOOT);
        else if (ch == (KBD_BUCKY_ALT | '\t') || 
            ch == (KBD_BUCKY_ALT | KBD_BUCKY_SHIFT | '\t'))
        {
            LmuxAcquire(&lmux_consoles);

            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, false);
            LmuxRelease(&current->lmux);

            if (ch & KBD_BUCKY_SHIFT)
            {
                if (current - consoles - 1 < 0)
                    current = consoles + num_consoles - 1;
                else
                    current--;
            }
            else
            {
                if (current - consoles + 1 >= num_consoles)
                    current = consoles;
                else
                    current++;
            }

            LmuxAcquire(&current->lmux);
            ConDrawCursor(current, true);
            LmuxRelease(&current->lmux);

            LmuxRelease(&lmux_consoles);
        }
        else
        {
            LmuxAcquire(&lmux_consoles);
            if (current != NULL && current->client != NULL)
                FsWrite(current->client, &ch, 0, sizeof(ch), NULL);
            LmuxRelease(&lmux_consoles);
        }
    }

    _wdprintf(L"console(keyboard): FsRead failed, %s\n", _wcserror(errno));
    return errno;
}