Example #1
0
ssize_t
Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize)
{
	if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED)
		return of_write(fHandle, buffer, bufferSize);

	return B_ERROR;
}
Example #2
0
static int
cimod_write(char *buffer, int len)
{
    int ret;

    ret = of_write(myself, buffer, len);
    dprintf("cimod write returned: %i!\n", ret);

    return ret;
}
Example #3
0
ssize_t
ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,
	size_t bufferSize)
{
	const char *string = (const char *)buffer;

	// If the frame buffer is enabled, don't write to the chosen stdout.
	// On Apple's OpenFirmware this would overwrite parts of the frame buffer.
	if (gKernelArgs.frame_buffer.enabled)
		return bufferSize;

	// be nice to our audience and replace single "\n" with "\r\n"

	while (bufferSize > 0) {
		bool newLine = false;
		size_t length = 0;

		for (; length < bufferSize; length++) {
			if (string[length] == '\r' && length + 1 < bufferSize) {
				length += 2;
			} else if (string[length] == '\n') {
				newLine = true;
				break;
			}
		}

		if (length > 0) {
			of_write(fHandle, string, length);
			string += length;
			bufferSize -= length;
		}

		if (newLine) {
			// this code replaces a single '\n' with '\r\n', so it
			// bumps the string/bufferSize only a single character
			of_write(fHandle, "\r\n", 2);
			string++;
			bufferSize--;
		}
	}

	return string - (char *)buffer;
}
Example #4
0
int new_mm(int from)
{
	struct proc_mm_op copy;
	int n, fd;

	fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
	if(fd < 0)
		return(fd);

	if(from != -1){
		copy = ((struct proc_mm_op) { .op 	= MM_COPY_SEGMENTS,
					      .u 	=
					      { .copy_segments	= from } } );
Example #5
0
int new_mm(unsigned long stack)
{
	int fd;

	fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
	if(fd < 0)
		return(fd);

	if(skas_needs_stub)
		map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);

	return(fd);
}
Example #6
0
int os_file_mode(char *file, struct openflags *mode_out)
{
	*mode_out = OPENFLAGS();

	if(!access(file, W_OK)) *mode_out = of_write(*mode_out);
	else if(errno != EACCES) 
		return(-errno);

	if(!access(file, R_OK)) *mode_out = of_read(*mode_out);
	else if(errno != EACCES) 
		return(-errno);

	return(0);
}
Example #7
0
int new_mm(unsigned long stack)
{
    int fd, err;

    fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
    if (fd < 0)
        return fd;

    if (skas_needs_stub) {
        err = map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
        if (err) {
            os_close_file(fd);
            return err;
        }
    }

    return fd;
}
Example #8
0
snk_module_t *
cimod_check_and_install(void)
{
    uint8_t tmpbuf[8];

    dprintf("entered cimod_check_and_install!\n");

    myself = of_interpret_1("my-parent", tmpbuf);
    dprintf("cimod: myself=%lx\n", myself);

    /* Check whether "read" and "write" functions are provided by the
     * device tree node: */
    if (of_read(myself, tmpbuf, 0) == -1
            || of_write(myself, tmpbuf, 0) == -1) {
        dprintf("cimod: missing read or write!\n");
        return NULL;
    }

    return &ci_module;
}
Example #9
0
void gen_basic_array(CONTEXT *c) {
   NODE *cf,*hf;
   char *ots,*maybe_space;
   int i;
   NODE *k,*v;
   CONTEXT *ctx;
   
   /* check:  can we proceed? */
   if ((c->am.first_key!=NULL) && (c->am.first_key->type==nt_int) &&
       (c->am.last_key!=NULL) && (c->am.last_key->type==nt_int))
     c->generator=gen_basic_array;
   else {
      c->generator=NULL;
      return;
   }
   
   cf=open_output_file(c->c_file);
   hf=open_output_file(c->h_file);
   
   k=node_new();
   k->type=nt_int;
   
   if (c->value_c_type==NULL)
     ots="int";
   else
     ots=c->value_c_type;
   maybe_space=(ots[strlen(ots)-1]=='*')?"":" ";

   of_write(hf,"/* basic array lookup for map \"%s\" */\n\n",
	    c->id);
   of_write(hf,"extern %s%s__icemap_%s_array[];\n",
	    ots,maybe_space,c->id);
   if (c->am.first_key->x==0)
     of_write(hf,"#define %s_lookup(idx) \\\n"
	      "  (__icemap_%s_array[(idx)])\n\n",
	      c->id,c->id);
   else
     of_write(hf,"#define %s_lookup(idx) \\\n"
	      "  (__icemap_%s_array[(idx)-%d])\n\n",
	      c->id,c->id,c->am.first_key->x);

   of_write(cf,"/* basic array lookup for map \"%s\" */\n\n",
	    c->id);
   of_write(cf,"%s%s__icemap_%s_array[%d]={\n",
	    ots,maybe_space,c->id,c->am.last_key->x-c->am.first_key->x+1);
   of_indent(cf,2);

   for (i=c->am.first_key->x;i<=c->am.last_key->x;i++) {
      k->x=i;
      v=arrow_map_lookup(&(c->am),k);
      if (v==NULL)
	of_write_wrapped(cf,"0 /* missing key */,");
      else if (v->type==nt_int)
	of_write_wrapped(cf,"0x%X,",v->x);
      else
	of_write_wrapped(cf,"\"%s\",",v->cp);
   }

   of_unindent(cf,2);
   of_write(cf,"\n};\n\n");

   node_delete(k);

   for (ctx=context_stack->parent;ctx;ctx=ctx->parent)
     ctx->leaves++;
}
Example #10
0
void putchar(char c)
{
	if(of_output_handle != 0)
		of_write(of_output_handle, &c, 1);

}
Example #11
0
void gen_basic_array(CONTEXT *c) {
   NODE *cf,*hf;
   char *ots,*maybe_space;
   int i;
   NODE *k,*v;
   CONTEXT *ctx;
   
   /* check:  can we proceed? */
   if ((c->am.first_key!=NULL) && (c->am.first_key->type==nt_int) &&
       (c->am.last_key!=NULL) && (c->am.last_key->type==nt_int))
     c->generator=gen_basic_array;
   else {
      c->generator=NULL;
      return;
   }
   
   cf=open_output_file(c->c_file);
   hf=open_output_file(c->h_file);
   
   k=node_new();
   k->type=nt_int;
   
   if (c->value_c_type==NULL)
     ots="int";
   else
     ots=c->value_c_type;
   maybe_space=(ots[strlen(ots)-1]=='*')?"":" ";

   of_write(hf,"/* basic array lookup for map \"%s\" */\n\n",
	    c->id);
   of_write(hf,"extern %s%s__icemap_%s_array[];\n",
	    ots,maybe_space,c->id);
   of_write(hf,"#define %s_lookup(idx) \\\n  (",c->id);
   if (c->default_policy!=dp_fail) {
      of_write(hf,"(((idx)<%d)||((idx)>%d))?",
	       c->am.first_key->x,c->am.last_key->x);
      switch (c->default_policy) {
       case dp_value:
	 if (c->return_pointer)
	   of_write(hf,"(&(__icemap_%s_array[%d])):(",c->id,
		    c->am.last_key->x-c->am.first_key->x+1);
	 else {
	    of_write(hf,"(");
	    write_c_value(hf,c,c->default_value,"");
	    of_write(hf,"):(");
	 }
	 break;

       case dp_any:
	 if (c->return_pointer)
	   of_write(hf,"(&(__icemap_%s_array[0])):(",c->id);
	 else
	   of_write(hf,"(__icemap_%s_array[0]):(",c->id);
	 break;

       case dp_null:
       default:
	   of_write(hf,"NULL:(");
	 break;
      }
   }
   if (c->return_pointer) of_write(hf,"&(");
   if (c->am.first_key->x==0)
     of_write(hf,"__icemap_%s_array[(idx)]",c->id);
   else
     of_write(hf,"__icemap_%s_array[(idx)-%d]",c->id,c->am.first_key->x);
   if (c->return_pointer) of_write(hf,")");
   if (c->default_policy!=dp_fail) of_write(hf,")");
   of_write(hf,")\n");

   of_write(hf,"#define %s_count (%d)\n\n",c->id,c->am.num_arrows);

   of_write(cf,"/* basic array lookup for map \"%s\" */\n\n",
	    c->id);
   if ((c->default_policy==dp_value) && c->return_pointer)
     of_write(cf,"%s%s__icemap_%s_array[%d]={\n",
	      ots,maybe_space,c->id,c->am.last_key->x-c->am.first_key->x+2);
   else
     of_write(cf,"%s%s__icemap_%s_array[%d]={\n",
	      ots,maybe_space,c->id,c->am.last_key->x-c->am.first_key->x+1);
   of_indent(cf,2);

   for (i=c->am.first_key->x;i<=c->am.last_key->x;i++) {
      k->x=i;
      v=arrow_map_lookup(&(c->am),k);
      write_c_value(cf,c,v,",");
   }
   if ((c->default_policy==dp_value) && c->return_pointer)
     write_c_value(cf,c,c->default_value,",");

   of_unindent(cf,2);
   of_write(cf,"\n};\n\n");

   node_delete(k);

   for (ctx=context_stack->parent;ctx;ctx=ctx->parent)
     ctx->leaves++;
}