source: trunk/libs/newlib/src/libgloss/mips/pmon.S @ 468

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

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

File size: 4.6 KB
Line 
1/*
2 * pmon.S -- low-level entry points into PMON monitor.
3 *
4 * Copyright (c) 1996, 1997, 2002 Cygnus Support
5 *
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
15 */
16
17#ifdef __mips16
18/* This file contains 32 bit assembly code.  */
19        .set nomips16
20#endif
21
22#if !defined(__mips64)
23  /* This machine does not support 64-bit operations.  */
24  #define ADDU addu
25  #define SUBU subu
26#else
27  /* This machine supports 64-bit operations.  */
28  #define ADDU daddu
29  #define SUBU dsubu
30#endif
31
32#include "regs.S"
33
34        .text
35        .align  2
36
37#ifdef LSI
38  #define PMON_VECTOR 0xffffffffbfc00200
39#else
40  #define PMON_VECTOR 0xffffffffbfc00500
41#endif
42
43#ifndef __mips_eabi
44/* Provide named functions for entry into the monitor: */
45#define INDIRECT(name,index)                            \
46        .globl  name;                                   \
47        .ent    name;                                   \
48        .set    noreorder;                              \
49name:   la      $2,+(PMON_VECTOR+((index)*4));          \
50        lw      $2,0($2);                               \
51        j       $2;                                     \
52        nop;                                            \
53        .set    reorder;                                \
54        .end    name
55
56#else
57#define INDIRECT(name,index)                            \
58        .globl  name;                                   \
59        .ent    name;                                   \
60        .set    noreorder;                              \
61name:   la      $2,+(PMON_VECTOR+((index)*4));          \
62        lw      $2,0($2);                               \
63        SUBU    sp,sp,0x40;                             \
64        sd      ra,0x38(sp);                            \
65        sd      fp,0x30(sp);                            \
66        jal     $2;                                     \
67        move    fp,sp;                                  \
68        ld      ra,0x38(sp);                            \
69        ld      fp,0x30(sp);                            \
70        j       ra;                                     \
71        ADDU    sp,sp,0x40;                             \
72        .set    reorder;                                \
73        .end    name
74#endif
75
76
77/* The following magic numbers are for the slots into the PMON monitor */
78/* The first are used as the lo-level library run-time: */
79INDIRECT(read,0)
80INDIRECT(write,1)
81INDIRECT(open,2)
82INDIRECT(close,3)
83/* The following are useful monitor routines: */
84INDIRECT(mon_ioctl,4)
85INDIRECT(mon_printf,5)
86INDIRECT(mon_vsprintf,6)
87INDIRECT(mon_ttctl,7)
88INDIRECT(mon_cliexit,8)
89INDIRECT(mon_getenv,9)
90INDIRECT(mon_onintr,10)
91INDIRECT(mon_flush_cache,11)
92INDIRECT(_flush_cache,11)
93INDIRECT(mon_exception,12)
94
95/* The following routine is required by the "print()" function: */
96        .globl  outbyte
97        .ent    outbyte
98        .set    noreorder
99outbyte:
100        subu    sp,sp,0x20      /* allocate stack space for string */
101        sd      ra,0x18(sp)     /* stack return address */
102        sd      fp,0x10(sp)     /* stack frame-pointer */
103        move    fp,sp           /* take a copy of the stack pointer */
104        /* We leave so much space on the stack for the string (16
105           characters), since the call to mon_printf seems to corrupt
106           the 8bytes at offset 8 into the string/stack. */
107        sb      a0,0x00(sp)     /* character to print */
108        sb      z0,0x01(sp)     /* NUL terminator */
109        jal     mon_printf      /* and output the string */
110        move    a0,sp           /* take a copy of the string pointer {DELAY SLOT} */
111
112        move    sp,fp           /* recover stack pointer */
113        ld      ra,0x18(sp)     /* recover return address */
114        ld      fp,0x10(sp)     /* recover frame-pointer */
115        j       ra              /* return to the caller */
116        addu    sp,sp,0x20      /* dump the stack space {DELAY SLOT} */
117        .set    reorder
118        .end    outbyte
119
120/* The following routine is required by the "sbrk()" function: */
121        .globl  get_mem_info
122        .ent    get_mem_info
123        .set    noreorder
124get_mem_info:
125        # in:  a0 = pointer to 3 word structure
126        # out: void
127        subu    sp,sp,0x18      /* create some stack space */
128        sd      ra,0x00(sp)     /* stack return address */
129        sd      fp,0x08(sp)     /* stack frame-pointer */
130        sd      a0,0x10(sp)     /* stack structure pointer */
131        move    fp,sp           /* take a copy of the stack pointer */
132
133        # The monitor has already sized memory, but unfortunately we
134        # do not have access to the data location containing the
135        # memory size.
136
137        jal     __sizemem
138        nop
139
140        ld      a0,0x10(sp)     # recover structure pointer
141        sw      v0,0(a0)        # amount of memory available
142
143        # Deal with getting the cache size information:
144        mfc0    a1, C0_CONFIG
145        nop
146        nop
147        andi    a2,a1,0x7 << 9  # bits 11..9 for instruction cache size
148        sll     a2,a2,12 - 8
149        sw      a2,4(a0)
150        andi    a2,a1,0x7 << 6  # bits 8..6 for data cache size
151        sll     a2,a2,12 - 5
152        sw      a2,8(a0)        # data cache size
153        #
154        move    sp,fp           /* recover stack pointer */
155        ld      ra,0x00(sp)     /* recover return address */
156        ld      fp,0x08(sp)     /* recover frame-pointer */
157        j       ra              /* return to the caller */
158        addu    sp,sp,0x18      /* restore stack pointer {DELAY SLOT} */
159        .set    reorder
160        .end    get_mem_info
161
162#ifdef LSI
163
164# For the LSI MiniRISC board, we can safely assume that we have
165# at least one megabyte of RAM.
166
167        .globl  __sizemem
168        .ent    __sizemem
169__sizemem:
170        li      v0,0x100000
171        j       ra
172        .end    __sizemem
173#else
174
175
176#endif
177/* EOF pmon.S */
Note: See TracBrowser for help on using the repository browser.