source: trunk/libs/newlib/src/libgloss/mips/cygmon.c @ 444

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

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

File size: 2.1 KB
Line 
1/* cygmon.c -- Glue code for linking apps to run on top of Cygmon.
2 *
3 * Copyright (c) 1998, 1999, 2000 Red Hat, Inc.
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15
16#include "syscall.h"
17
18int
19write ( int file,
20        char *buf,
21        int nbytes)
22{
23  return sysCall(SYS_write, file, (unsigned long)buf, nbytes);
24}
25
26int
27read (int file,
28      char *buf,
29      int nbytes)
30{
31  return sysCall(SYS_read, file, (unsigned long)buf, nbytes);
32}
33
34int
35outbyte (unsigned char c)
36{
37  return sysCall(SYS_write, 0, (unsigned long)&c, 1);
38}
39
40unsigned char
41inbyte (void)
42{
43  char c;
44  sysCall(SYS_read, 0, (unsigned long)&c, 1);
45  return c;
46}
47
48
49/* Structure filled in by get_mem_info.  Only the size field is
50   actually used (by sbrk), so the others aren't even filled in.  */
51struct s_mem
52{
53  unsigned int size;
54  unsigned int icsize;
55  unsigned int dcsize;
56};
57
58// Perform a system call.
59// Unused parameters should be set to 0.
60int sysCall(unsigned long func, unsigned long p1, unsigned long p2, unsigned long p3)
61{
62  int ret = 0;
63  asm volatile ( "              \n\
64          move $4, %1           \n\
65          move $5, %2           \n\
66          move $6, %3           \n\
67          move $7, %4           \n\
68          syscall               \n\
69          nop                   \n\
70          move %0, $2" : "=r"(ret) : "r"(func), "r"(p1), "r"(p2), "r"(p3));
71  return ret;
72}
73
74// These need to be kept in sync with the definitions in Cygmon.
75#define SYS_meminfo     1001
76
77void *
78get_mem_info (mem)
79     struct s_mem *mem;
80{
81  unsigned long totmem = 0, topmem = 0;
82  int numbanks;
83
84  numbanks = sysCall(SYS_meminfo, (unsigned long)&totmem, (unsigned long)&topmem, 0);
85  mem->size = totmem;
86  return (void*)topmem;
87}
Note: See TracBrowser for help on using the repository browser.