source: trunk/libs/newlib/src/libgloss/m68hc11/syscalls.c @ 532

Last change on this file since 532 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.7 KB
Line 
1/* pseudo system calls for M68HC11 & M68HC12.
2 * Copyright (C) 1999, 2000, 2001, 2002 Stephane Carrez (stcarrez@nerim.fr)     
3 *
4 * The authors hereby grant permission to use, copy, modify, distribute,
5 * and license this software and its documentation for any purpose, provided
6 * that existing copyright notices are retained in all copies and that this
7 * notice is included verbatim in any distributions. No written agreement,
8 * license, or royalty fee is required for any of the authorized uses.
9 * Modifications to this software may be copyrighted by their authors
10 * and need not follow the licensing terms described here, provided that
11 * the new terms are clearly indicated on the first page of each file where
12 * they apply.
13 */
14
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <unistd.h>
18
19extern void outbyte(char c);
20extern char inbyte(void);
21
22int
23read(int file, void *p, size_t nbytes)
24{
25  int i = 0;
26  char* buf = (char*) p;
27 
28  for (i = 0; i < nbytes; i++) {
29    *(buf + i) = inbyte();
30    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
31      i++;
32      break;
33    }
34  }
35  return (i);
36}
37
38int
39write(int file, const void *p, size_t len)
40{
41  const char *ptr = (const char*) p;
42  int todo;
43 
44  for (todo = len; todo; --todo)
45    {
46      outbyte (*ptr++);
47    }
48  return(len);
49}
50
51void *
52sbrk(ptrdiff_t incr)
53{
54  extern char _end;             /* Defined by the linker */
55  static char *heap_end;
56  char *prev_heap_end;
57
58  register char *stack_ptr asm ("sp");
59
60  if (heap_end == 0) 
61    {
62      heap_end = &_end;
63    }
64  prev_heap_end = heap_end;
65  if (heap_end + incr > stack_ptr)
66    {
67      write (1, "Heap and stack collision\n", 25);
68      abort ();
69    }
70  heap_end += incr;
71  return ((void*) prev_heap_end);
72}
73
74/* end of syscalls.c */
Note: See TracBrowser for help on using the repository browser.