1 // m32r.cxx - Implementation of the M32R libgloss specifics. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
14 using namespace sidutil;
16 m32r_libgloss::m32r_libgloss()
18 register_attribute_names[-1] = "r0"; // result
19 register_attribute_names[-2] = "r0"; // error
20 register_attribute_names[0] = "r0"; // function code
21 register_attribute_names[1] = "r1"; // arg 1
22 register_attribute_names[2] = "r2"; // arg 2
23 register_attribute_names[3] = "r3"; // arg 3
27 m32r_libgloss::get_int_argument(unsigned index, int32& value)
30 string attrName = register_attribute_names[index];
31 assert (attrName != "");
33 string attrValue = cpu->attribute_value (attrName);
36 cerr << "Could not read attribute " << attrName
37 << " for ABI argument #" << index << endl;
41 host_int_4 value_number;
42 parse_attribute(attrValue, value_number);
48 m32r_libgloss::set_int_result(int32 value)
51 string attrName = register_attribute_names[-1];
52 assert (attrName != "");
54 host_int_4 value_number = value;
55 string attrValue = make_attribute(value_number);
57 cpu->set_attribute_value (attrName, attrValue);
58 return true; // XXX: check?
62 m32r_libgloss::set_error_result(int32 value)
65 string attrName = register_attribute_names[-2];
66 assert (attrName != "");
68 host_int_4 value_number = value;
69 string attrValue = make_attribute(value_number);
71 cpu->set_attribute_value (attrName, attrValue);
72 return true; // XXX: safe to assume success?
76 m32r_libgloss::syscall_trap_p()
78 // M32R system calls use TRAP 0.
79 return ((trap_type_ipin.sense() == sidutil::cpu_trap_software)
80 && (trap_code_pin.sense() == 0)); /* trap 0 */
84 m32r_libgloss::syscall_trap()
88 get_int_argument(0, syscall);
91 cerr << "M32R/libgloss system call number " << syscall << endl;
96 case libgloss::SYS_exit:
99 get_int_argument(1, value);
101 cerr << "*** exit(" << value << ")" << endl;
104 process_signal_pin.drive(newlib::sigQuit);
106 process_signal_pin.drive(newlib::sigAbrt);
110 case libgloss::SYS_write:
117 get_int_argument(1, fd);
118 get_int_argument(2, address);
119 get_int_argument(3, length);
123 if (! this->write (fd, address, length, len_written, errcode))
125 set_error_result(host_to_target_errno(errcode));
130 set_int_result(len_written);
134 case libgloss::SYS_read:
141 get_int_argument(1, fd);
142 get_int_argument(2, address);
143 get_int_argument(3, length);
147 if (! this->read (fd, address, length, len_read, errcode))
149 set_error_result(host_to_target_errno(errcode));
154 set_int_result(len_read);
161 cerr << "Unimplemented syscall " << syscall << endl;
164 set_error_result(newlib::eNoSys);
168 // Convert host errno value to target.
171 m32r_libgloss::host_to_target_errno (int host_errno)
173 return newlib::host_to_target_errno (host_errno);