Welcome to mirror list, hosted at ThFree Co, Russian Federation.

trapmon0.c « m32r « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20a2fcbfe55e320e9598786893596fd9bce468fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Mon2000 Trap handler (syscall interface).
 *
 * This trap handler is linked into the mon2000 libgloss (libmon).
 */
#include <reent.h>
#include "syscall.h"

int __trap0 (int function, int p1, int p2, int p3, struct _reent *r)
{
  int rc = 0;

  switch (function) {
  case SYS_exit:
    /* loop so GDB can't go past system exit call */
    while (1) {
      asm volatile (
          "ldi	  r0, #0						\n"
          "trap    #15        ; return control to Mon2000");
    }
    break;

  case SYS_write:
  {
    int i;

    for( i=0; i<p3; i++ ) {
      asm volatile (
          "ldi   r0, #2							\n"
          "ldi   r1, #15      ; load Ctrl-O (ASCII 15)			\n"
          "trap  #15          ; write Ctrl-O for quoting purposes" );

      asm volatile (
          "ldi   r0, #2							\n"
          "ldb   r1, %0							\n"
          "trap  #15          ; write character to console" 
          : /* no outputs */
          : "m" (((char*)p2)[i]));
    }

    rc = p3;                 /* return number of chars written */
    break;
  }

  default:
    rc = 0;
    break;
  }

  return rc;
}