1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872 |
- /* This file is part of the program psim.
- Copyright (C) 1996-1998, Andrew Cagney <cagney@highland.com.au>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef _EMUL_UNIX_C_
- #define _EMUL_UNIX_C_
- /* Note: this module is called via a table. There is no benefit in
- making it inline */
- #include "defs.h"
- #include <string.h>
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/stat.h>
- #else
- #undef HAVE_STAT
- #undef HAVE_LSTAT
- #undef HAVE_FSTAT
- #endif
- #include <stdio.h>
- #include <signal.h>
- #include <errno.h>
- #ifdef HAVE_FCNTL_H
- #include <fcntl.h>
- #endif
- #ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
- #endif
- #include <sys/time.h>
- #ifndef HAVE_TERMIOS_STRUCTURE
- #undef HAVE_SYS_TERMIOS_H
- #undef HAVE_TCGETATTR
- #else
- #ifndef HAVE_SYS_TERMIOS_H
- #undef HAVE_TERMIOS_STRUCTURE
- #endif
- #endif
- #ifdef HAVE_TERMIOS_STRUCTURE
- #include <sys/termios.h>
- /* If we have TERMIOS, use that for the termio structure, since some systems
- don't like including both sys/termios.h and sys/termio.h at the same
- time. */
- #undef HAVE_TERMIO_STRUCTURE
- #undef TCGETA
- #undef termio
- #define termio termios
- #endif
- #ifndef HAVE_TERMIO_STRUCTURE
- #undef HAVE_SYS_TERMIO_H
- #else
- #ifndef HAVE_SYS_TERMIO_H
- #undef HAVE_TERMIO_STRUCTURE
- #endif
- #endif
- #ifdef HAVE_TERMIO_STRUCTURE
- #include <sys/termio.h>
- #endif
- #ifdef HAVE_GETRUSAGE
- #ifndef HAVE_SYS_RESOURCE_H
- #undef HAVE_GETRUSAGE
- #endif
- #endif
- #ifdef HAVE_GETRUSAGE
- #include <sys/resource.h>
- int getrusage();
- #endif
- #if HAVE_DIRENT_H
- # include <dirent.h>
- # define NAMLEN(dirent) strlen((dirent)->d_name)
- #else
- # define dirent direct
- # define NAMLEN(dirent) (dirent)->d_namlen
- # if HAVE_SYS_NDIR_H
- # include <sys/ndir.h>
- # endif
- # if HAVE_SYS_DIR_H
- # include <sys/dir.h>
- # endif
- # if HAVE_NDIR_H
- # include <ndir.h>
- # endif
- #endif
- #ifdef HAVE_UNISTD_H
- #undef MAXPATHLEN /* sys/param.h might define this also */
- #include <unistd.h>
- #endif
- #include <stdlib.h>
- #include <time.h>
- #include "emul_generic.h"
- #include "emul_unix.h"
- #ifndef STATIC_INLINE_EMUL_UNIX
- #define STATIC_INLINE_EMUL_UNIX STATIC_INLINE
- #endif
- #ifndef PATH_MAX
- #define PATH_MAX 1024
- #endif
- #ifndef EINVAL
- #define EINVAL -1
- #endif
- /* UNIX's idea of what is needed to implement emulations */
- struct _os_emul_data {
- device *vm;
- emul_syscall *syscalls;
- };
- /* Emulation of simple UNIX system calls that are common on all systems. */
- /* Structures that are common agmonst the UNIX varients */
- struct unix_timeval {
- int32_t tv_sec; /* seconds */
- int32_t tv_usec; /* microseconds */
- };
- struct unix_timezone {
- int32_t tz_minuteswest; /* minutes west of Greenwich */
- int32_t tz_dsttime; /* type of dst correction */
- };
- #define UNIX_RUSAGE_SELF 0
- #define UNIX_RUSAGE_CHILDREN (-1)
- #define UNIX_RUSAGE_BOTH (-2) /* sys_wait4() uses this */
- struct unix_rusage {
- struct unix_timeval ru_utime; /* user time used */
- struct unix_timeval ru_stime; /* system time used */
- int32_t ru_maxrss; /* maximum resident set size */
- int32_t ru_ixrss; /* integral shared memory size */
- int32_t ru_idrss; /* integral unshared data size */
- int32_t ru_isrss; /* integral unshared stack size */
- int32_t ru_minflt; /* any page faults not requiring I/O */
- int32_t ru_majflt; /* any page faults requiring I/O */
- int32_t ru_nswap; /* swaps */
- int32_t ru_inblock; /* block input operations */
- int32_t ru_oublock; /* block output operations */
- int32_t ru_msgsnd; /* messages sent */
- int32_t ru_msgrcv; /* messages received */
- int32_t ru_nsignals; /* signals received */
- int32_t ru_nvcsw; /* voluntary context switches */
- int32_t ru_nivcsw; /* involuntary " */
- };
- /* File descriptors 0, 1, and 2 should not be closed. fd_closed[]
- tracks whether these descriptors have been closed in do_close()
- below. */
- static int fd_closed[3];
- /* Check for some occurrences of bad file descriptors. We only check
- whether fd 0, 1, or 2 are "closed". By "closed" we mean that these
- descriptors aren't actually closed, but are considered to be closed
- by this layer.
- Other checks are performed by the underlying OS call. */
- static int
- fdbad (int fd)
- {
- if (fd >=0 && fd <= 2 && fd_closed[fd])
- {
- errno = EBADF;
- return -1;
- }
- return 0;
- }
- static void
- do_unix_exit(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int status = (int)cpu_registers(processor)->gpr[arg0];
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d)\n", status);
- cpu_halt(processor, cia, was_exited, status);
- }
- static void
- do_unix_read(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- void *scratch_buffer;
- int d = (int)cpu_registers(processor)->gpr[arg0];
- unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
- int nbytes = cpu_registers(processor)->gpr[arg0+2];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
- /* get a tempoary bufer */
- scratch_buffer = zalloc(nbytes);
- /* check if buffer exists by reading it */
- emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia);
- status = fdbad (d);
- /* read */
- if (status == 0)
- status = read (d, scratch_buffer, nbytes);
- emul_write_status(processor, status, errno);
- if (status > 0)
- emul_write_buffer(scratch_buffer, buf, status, processor, cia);
- free(scratch_buffer);
- }
- static void
- do_unix_write(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- void *scratch_buffer = NULL;
- int d = (int)cpu_registers(processor)->gpr[arg0];
- unsigned_word buf = cpu_registers(processor)->gpr[arg0+1];
- int nbytes = cpu_registers(processor)->gpr[arg0+2];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes);
- /* get a tempoary bufer */
- scratch_buffer = zalloc(nbytes); /* FIXME - nbytes == 0 */
- /* copy in */
- emul_read_buffer(scratch_buffer, buf, nbytes,
- processor, cia);
- status = fdbad (d);
- /* write */
- if (status == 0)
- status = write(d, scratch_buffer, nbytes);
- emul_write_status(processor, status, errno);
- free(scratch_buffer);
- flush_stdoutput();
- }
- static void
- do_unix_open(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int flags = (int)cpu_registers(processor)->gpr[arg0+1];
- int mode = (int)cpu_registers(processor)->gpr[arg0+2];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%x, 0x%x", (long)path_addr, path, flags, mode);
- status = open(path, flags, mode);
- emul_write_status(processor, status, errno);
- }
- static void
- do_unix_close(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int d = (int)cpu_registers(processor)->gpr[arg0];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d", d);
- status = fdbad (d);
- if (status == 0)
- {
- /* Do not close stdin, stdout, or stderr. GDB may still need access to
- these descriptors. */
- if (d == 0 || d == 1 || d == 2)
- {
- fd_closed[d] = 1;
- status = 0;
- }
- else
- status = close(d);
- }
- emul_write_status(processor, status, errno);
- }
- static void
- do_unix_break(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- /* just pass this onto the `vm' device */
- unsigned_word new_break = cpu_registers(processor)->gpr[arg0];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx", (long)cpu_registers(processor)->gpr[arg0]);
- status = device_ioctl(emul->vm,
- processor,
- cia,
- device_ioctl_break,
- new_break); /*ioctl-data*/
- emul_write_status(processor, 0, status);
- }
- #ifndef HAVE_ACCESS
- #define do_unix_access 0
- #else
- static void
- do_unix_access(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int mode = (int)cpu_registers(processor)->gpr[arg0+1];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%x [0%o]", (long)path_addr, path, mode, mode);
- status = access(path, mode);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_GETPID
- #define do_unix_getpid 0
- #else
- static void
- do_unix_getpid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- pid_t status = getpid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #ifndef HAVE_GETPPID
- #define do_unix_getppid 0
- #else
- static void
- do_unix_getppid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- pid_t status = getppid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #if !defined(HAVE_GETPID) || !defined(HAVE_GETPPID)
- #define do_unix_getpid2 0
- #else
- static void
- do_unix_getpid2(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int pid = (int)getpid();
- int ppid = (int)getppid();
- emul_write2_status(processor, pid, ppid, errno);
- }
- #endif
- #if !defined(HAVE_GETUID) || !defined(HAVE_GETEUID)
- #define do_unix_getuid2 0
- #else
- static void
- do_unix_getuid2(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- uid_t uid = getuid();
- uid_t euid = geteuid();
- emul_write2_status(processor, (int)uid, (int)euid, errno);
- }
- #endif
- #ifndef HAVE_GETUID
- #define do_unix_getuid 0
- #else
- static void
- do_unix_getuid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- uid_t status = getuid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #ifndef HAVE_GETEUID
- #define do_unix_geteuid 0
- #else
- static void
- do_unix_geteuid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- uid_t status = geteuid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #if 0
- #ifndef HAVE_KILL
- #define do_unix_kill 0
- #else
- static void
- do_unix_kill(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- pid_t pid = cpu_registers(processor)->gpr[arg0];
- int sig = cpu_registers(processor)->gpr[arg0+1];
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, %d", (int)pid, sig);
- printf_filtered("SYS_kill at 0x%lx - more to this than just being killed\n",
- (long)cia);
- cpu_halt(processor, cia, was_signalled, sig);
- }
- #endif
- #endif
- #ifndef HAVE_DUP
- #define do_unix_dup 0
- #else
- static void
- do_unix_dup(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int oldd = cpu_registers(processor)->gpr[arg0];
- int status = (fdbad (oldd) < 0) ? -1 : dup(oldd);
- int err = errno;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d", oldd);
- emul_write_status(processor, status, err);
- }
- #endif
- #ifndef HAVE_DUP2
- #define do_unix_dup2 0
- #else
- static void
- do_unix_dup2(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int oldd = cpu_registers(processor)->gpr[arg0];
- int newd = cpu_registers(processor)->gpr[arg0+1];
- int status = (fdbad (oldd) < 0) ? -1 : dup2(oldd, newd);
- int err = errno;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, %d", oldd, newd);
- emul_write_status(processor, status, err);
- }
- #endif
- #ifndef HAVE_LSEEK
- #define do_unix_lseek 0
- #else
- static void
- do_unix_lseek(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int fildes = (int)cpu_registers(processor)->gpr[arg0];
- off_t offset = (off_t)cpu_registers(processor)->gpr[arg0+1];
- int whence = (int)cpu_registers(processor)->gpr[arg0+2];
- off_t status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d %ld %d", fildes, (long)offset, whence);
- status = fdbad (fildes);
- if (status == 0)
- status = lseek(fildes, offset, whence);
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #if !defined(HAVE_GETGID) || !defined(HAVE_GETEGID)
- #define do_unix_getgid2 0
- #else
- static void
- do_unix_getgid2(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- gid_t gid = getgid();
- gid_t egid = getegid();
- emul_write2_status(processor, (int)gid, (int)egid, errno);
- }
- #endif
- #ifndef HAVE_GETGID
- #define do_unix_getgid 0
- #else
- static void
- do_unix_getgid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- gid_t status = getgid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #ifndef HAVE_GETEGID
- #define do_unix_getegid 0
- #else
- static void
- do_unix_getegid(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- gid_t status = getegid();
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #ifndef HAVE_UMASK
- #define do_unix_umask 0
- #else
- static void
- do_unix_umask(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- mode_t mask = (mode_t)cpu_registers(processor)->gpr[arg0];
- int status = umask(mask);
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0%o", (unsigned int)mask);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_CHDIR
- #define do_unix_chdir 0
- #else
- static void
- do_unix_chdir(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s]", (long)path_addr, path);
- status = chdir(path);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_LINK
- #define do_unix_link 0
- #else
- static void
- do_unix_link(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
- char path1_buf[PATH_MAX];
- char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
- unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
- char path2_buf[PATH_MAX];
- char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
- status = link(path1, path2);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_SYMLINK
- #define do_unix_symlink 0
- #else
- static void
- do_unix_symlink(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path1_addr = cpu_registers(processor)->gpr[arg0];
- char path1_buf[PATH_MAX];
- char *path1 = emul_read_string(path1_buf, path1_addr, PATH_MAX, processor, cia);
- unsigned_word path2_addr = cpu_registers(processor)->gpr[arg0+1];
- char path2_buf[PATH_MAX];
- char *path2 = emul_read_string(path2_buf, path2_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx [%s]", (long)path1_addr, path1, (long)path2_addr, path2);
- status = symlink(path1, path2);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_UNLINK
- #define do_unix_unlink 0
- #else
- static void
- do_unix_unlink(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s]", (long)path_addr, path);
- status = unlink(path);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_MKDIR
- #define do_unix_mkdir 0
- #else
- static void
- do_unix_mkdir(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int mode = (int)cpu_registers(processor)->gpr[arg0+1];
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0%3o", (long)path_addr, path, mode);
- #ifdef USE_WIN32API
- status = mkdir(path);
- #else
- status = mkdir(path, mode);
- #endif
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_RMDIR
- #define do_unix_rmdir 0
- #else
- static void
- do_unix_rmdir(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- char path_buf[PATH_MAX];
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s]", (long)path_addr, path);
- status = rmdir(path);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_TIME
- #define do_unix_time 0
- #else
- static void
- do_unix_time(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word tp = cpu_registers(processor)->gpr[arg0];
- time_t now = time ((time_t *)0);
- unsigned_word status = H2T_4(now);
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx", (long)tp);
- emul_write_status(processor, (int)status, errno);
- if (tp)
- emul_write_buffer(&status, tp, sizeof(status), processor, cia);
- }
- #endif
- #if !defined(HAVE_GETTIMEOFDAY)
- #define do_unix_gettimeofday 0
- #else
- static void
- do_unix_gettimeofday(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word tv = cpu_registers(processor)->gpr[arg0];
- unsigned_word tz = cpu_registers(processor)->gpr[arg0+1];
- struct unix_timeval target_timeval;
- struct timeval host_timeval;
- struct unix_timezone target_timezone;
- struct timezone host_timezone;
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx, 0x%lx", (long)tv, (long)tz);
- /* Just in case the system doesn't set the timezone structure */
- host_timezone.tz_minuteswest = 0;
- host_timezone.tz_dsttime = 0;
- status = gettimeofday(&host_timeval, &host_timezone);
- if (status >= 0) {
- if (tv) {
- target_timeval.tv_sec = H2T_4(host_timeval.tv_sec);
- target_timeval.tv_usec = H2T_4(host_timeval.tv_usec);
- emul_write_buffer((void *) &target_timeval, tv, sizeof(target_timeval), processor, cia);
- }
- if (tz) {
- target_timezone.tz_minuteswest = H2T_4(host_timezone.tz_minuteswest);
- target_timezone.tz_dsttime = H2T_4(host_timezone.tz_dsttime);
- emul_write_buffer((void *) &target_timezone, tv, sizeof(target_timezone), processor, cia);
- }
- }
-
- emul_write_status(processor, (int)status, errno);
- }
- #endif
- #ifndef HAVE_GETRUSAGE
- #define do_unix_getrusage 0
- #else
- static void
- do_unix_getrusage(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- signed_word who = (signed_word)cpu_registers(processor)->gpr[arg0];
- unsigned_word usage = cpu_registers(processor)->gpr[arg0+1];
- struct rusage host_rusage, host_rusage2;
- struct unix_rusage target_rusage;
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%ld, 0x%lx", (long)who, (long)usage);
- switch (who) {
- default:
- status = -1;
- errno = EINVAL;
- break;
- case UNIX_RUSAGE_SELF:
- status = getrusage(RUSAGE_SELF, &host_rusage);
- break;
- case UNIX_RUSAGE_CHILDREN:
- status = getrusage(RUSAGE_CHILDREN, &host_rusage);
- break;
- case UNIX_RUSAGE_BOTH:
- status = getrusage(RUSAGE_SELF, &host_rusage);
- if (status >= 0) {
- status = getrusage(RUSAGE_CHILDREN, &host_rusage2);
- if (status >= 0) {
- host_rusage.ru_utime.tv_sec += host_rusage2.ru_utime.tv_sec;
- host_rusage.ru_utime.tv_usec += host_rusage2.ru_utime.tv_usec;
- host_rusage.ru_stime.tv_sec += host_rusage2.ru_stime.tv_sec;
- host_rusage.ru_stime.tv_usec += host_rusage2.ru_stime.tv_usec;
- host_rusage.ru_maxrss += host_rusage2.ru_maxrss;
- host_rusage.ru_ixrss += host_rusage2.ru_ixrss;
- host_rusage.ru_idrss += host_rusage2.ru_idrss;
- host_rusage.ru_isrss += host_rusage2.ru_isrss;
- host_rusage.ru_minflt += host_rusage2.ru_minflt;
- host_rusage.ru_majflt += host_rusage2.ru_majflt;
- host_rusage.ru_nswap += host_rusage2.ru_nswap;
- host_rusage.ru_inblock += host_rusage2.ru_inblock;
- host_rusage.ru_oublock += host_rusage2.ru_oublock;
- host_rusage.ru_msgsnd += host_rusage2.ru_msgsnd;
- host_rusage.ru_msgrcv += host_rusage2.ru_msgrcv;
- host_rusage.ru_nsignals += host_rusage2.ru_nsignals;
- host_rusage.ru_nvcsw += host_rusage2.ru_nvcsw;
- host_rusage.ru_nivcsw += host_rusage2.ru_nivcsw;
- }
- }
- }
- if (status >= 0) {
- target_rusage.ru_utime.tv_sec = H2T_4(host_rusage2.ru_utime.tv_sec);
- target_rusage.ru_utime.tv_usec = H2T_4(host_rusage2.ru_utime.tv_usec);
- target_rusage.ru_stime.tv_sec = H2T_4(host_rusage2.ru_stime.tv_sec);
- target_rusage.ru_stime.tv_usec = H2T_4(host_rusage2.ru_stime.tv_usec);
- target_rusage.ru_maxrss = H2T_4(host_rusage2.ru_maxrss);
- target_rusage.ru_ixrss = H2T_4(host_rusage2.ru_ixrss);
- target_rusage.ru_idrss = H2T_4(host_rusage2.ru_idrss);
- target_rusage.ru_isrss = H2T_4(host_rusage2.ru_isrss);
- target_rusage.ru_minflt = H2T_4(host_rusage2.ru_minflt);
- target_rusage.ru_majflt = H2T_4(host_rusage2.ru_majflt);
- target_rusage.ru_nswap = H2T_4(host_rusage2.ru_nswap);
- target_rusage.ru_inblock = H2T_4(host_rusage2.ru_inblock);
- target_rusage.ru_oublock = H2T_4(host_rusage2.ru_oublock);
- target_rusage.ru_msgsnd = H2T_4(host_rusage2.ru_msgsnd);
- target_rusage.ru_msgrcv = H2T_4(host_rusage2.ru_msgrcv);
- target_rusage.ru_nsignals = H2T_4(host_rusage2.ru_nsignals);
- target_rusage.ru_nvcsw = H2T_4(host_rusage2.ru_nvcsw);
- target_rusage.ru_nivcsw = H2T_4(host_rusage2.ru_nivcsw);
- emul_write_buffer((void *) &target_rusage, usage, sizeof(target_rusage), processor, cia);
- }
-
- emul_write_status(processor, status, errno);
- }
- #endif
- static void
- do_unix_nop(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
- (long)cpu_registers(processor)->gpr[arg0],
- (long)cpu_registers(processor)->gpr[arg0+1],
- (long)cpu_registers(processor)->gpr[arg0+2],
- (long)cpu_registers(processor)->gpr[arg0+3],
- (long)cpu_registers(processor)->gpr[arg0+4],
- (long)cpu_registers(processor)->gpr[arg0+5]);
- emul_write_status(processor, 0, errno);
- }
- /* Common code for initializing the system call stuff */
- static os_emul_data *
- emul_unix_create(device *root,
- bfd *image,
- const char *name,
- emul_syscall *syscall)
- {
- unsigned_word top_of_stack;
- unsigned stack_size;
- int elf_binary;
- os_emul_data *data;
- device *vm;
- char *filename;
- /* merge any emulation specific entries into the device tree */
- /* establish a few defaults */
- if (image->xvec->flavour == bfd_target_elf_flavour) {
- elf_binary = 1;
- top_of_stack = 0xe0000000;
- stack_size = 0x00100000;
- }
- else {
- elf_binary = 0;
- top_of_stack = 0x20000000;
- stack_size = 0x00100000;
- }
- /* options */
- emul_add_tree_options(root, image, name,
- (WITH_ENVIRONMENT == USER_ENVIRONMENT
- ? "user" : "virtual"),
- 0 /*oea-interrupt-prefix*/);
- /* virtual memory - handles growth of stack/heap */
- vm = tree_parse(root, "/openprom/vm@0x%lx",
- (unsigned long)(top_of_stack - stack_size));
- tree_parse(vm, "./stack-base 0x%lx",
- (unsigned long)(top_of_stack - stack_size));
- tree_parse(vm, "./nr-bytes 0x%x", stack_size);
- filename = tree_quote_property (bfd_get_filename(image));
- tree_parse(root, "/openprom/vm/map-binary/file-name %s",
- filename);
- free (filename);
- /* finish the init */
- tree_parse(root, "/openprom/init/register/pc 0x%lx",
- (unsigned long)bfd_get_start_address(image));
- tree_parse(root, "/openprom/init/register/sp 0x%lx",
- (unsigned long)top_of_stack);
- tree_parse(root, "/openprom/init/register/msr 0x%x",
- ((tree_find_boolean_property(root, "/options/little-endian?")
- ? msr_little_endian_mode
- : 0)
- | (tree_find_boolean_property(root, "/openprom/options/floating-point?")
- ? (msr_floating_point_available
- | msr_floating_point_exception_mode_0
- | msr_floating_point_exception_mode_1)
- : 0)));
- tree_parse(root, "/openprom/init/stack/stack-type %s",
- (elf_binary ? "ppc-elf" : "ppc-xcoff"));
- /* finally our emulation data */
- data = ZALLOC(os_emul_data);
- data->vm = vm;
- data->syscalls = syscall;
- return data;
- }
- /* EMULATION
- Solaris - Emulation of user programs for Solaris/PPC
- DESCRIPTION
- */
- /* Solaris specific implementation */
- typedef int32_t solaris_uid_t;
- typedef int32_t solaris_gid_t;
- typedef int32_t solaris_off_t;
- typedef int32_t solaris_pid_t;
- typedef int32_t solaris_time_t;
- typedef uint32_t solaris_dev_t;
- typedef uint32_t solaris_ino_t;
- typedef uint32_t solaris_mode_t;
- typedef uint32_t solaris_nlink_t;
- #ifdef HAVE_SYS_STAT_H
- #define SOLARIS_ST_FSTYPSZ 16 /* array size for file system type name */
- /* AIX 7.1 defines st_pad[123] to st_[amc]tim.tv_pad, respectively */
- #undef st_pad1
- #undef st_pad2
- #undef st_pad3
- struct solaris_stat {
- solaris_dev_t st_dev;
- int32_t st_pad1[3]; /* reserved for network id */
- solaris_ino_t st_ino;
- solaris_mode_t st_mode;
- solaris_nlink_t st_nlink;
- solaris_uid_t st_uid;
- solaris_gid_t st_gid;
- solaris_dev_t st_rdev;
- int32_t st_pad2[2];
- solaris_off_t st_size;
- int32_t st_pad3; /* future off_t expansion */
- struct unix_timeval st_atim;
- struct unix_timeval st_mtim;
- struct unix_timeval st_ctim;
- int32_t st_blksize;
- int32_t st_blocks;
- char st_fstype[SOLARIS_ST_FSTYPSZ];
- int32_t st_pad4[8]; /* expansion area */
- };
- /* Convert from host stat structure to solaris stat structure */
- STATIC_INLINE_EMUL_UNIX void
- convert_to_solaris_stat(unsigned_word addr,
- struct stat *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct solaris_stat target;
- int i;
- target.st_dev = H2T_4(host->st_dev);
- target.st_ino = H2T_4(host->st_ino);
- target.st_mode = H2T_4(host->st_mode);
- target.st_nlink = H2T_4(host->st_nlink);
- target.st_uid = H2T_4(host->st_uid);
- target.st_gid = H2T_4(host->st_gid);
- target.st_size = H2T_4(host->st_size);
- #ifdef HAVE_ST_RDEV
- target.st_rdev = H2T_4(host->st_rdev);
- #else
- target.st_rdev = 0;
- #endif
- #ifdef HAVE_ST_BLKSIZE
- target.st_blksize = H2T_4(host->st_blksize);
- #else
- target.st_blksize = 0;
- #endif
- #ifdef HAVE_ST_BLOCKS
- target.st_blocks = H2T_4(host->st_blocks);
- #else
- target.st_blocks = 0;
- #endif
- target.st_atim.tv_sec = H2T_4(host->st_atime);
- target.st_atim.tv_usec = 0;
- target.st_ctim.tv_sec = H2T_4(host->st_ctime);
- target.st_ctim.tv_usec = 0;
- target.st_mtim.tv_sec = H2T_4(host->st_mtime);
- target.st_mtim.tv_usec = 0;
- for (i = 0; i < ARRAY_SIZE (target.st_pad1); i++)
- target.st_pad1[i] = 0;
- for (i = 0; i < ARRAY_SIZE (target.st_pad2); i++)
- target.st_pad2[i] = 0;
- target.st_pad3 = 0;
- for (i = 0; i < ARRAY_SIZE (target.st_pad4); i++)
- target.st_pad4[i] = 0;
- /* For now, just punt and always say it is a ufs file */
- strcpy (target.st_fstype, "ufs");
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_SYS_STAT_H */
- #ifndef HAVE_STAT
- #define do_solaris_stat 0
- #else
- static void
- do_solaris_stat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- char path_buf[PATH_MAX];
- struct stat buf;
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
- status = stat (path, &buf);
- if (status == 0)
- convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_LSTAT
- #define do_solaris_lstat 0
- #else
- static void
- do_solaris_lstat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- char path_buf[PATH_MAX];
- struct stat buf;
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
- status = lstat (path, &buf);
- if (status == 0)
- convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_FSTAT
- #define do_solaris_fstat 0
- #else
- static void
- do_solaris_fstat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int fildes = (int)cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- struct stat buf;
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
- status = fdbad (fildes);
- if (status == 0)
- status = fstat (fildes, &buf);
- if (status == 0)
- convert_to_solaris_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- #define SOLARIS_TIOC ('T'<<8)
- #define SOLARIS_NCC 8
- #define SOLARIS_NCCS 19
- #define SOLARIS_VINTR 0
- #define SOLARIS_VQUIT 1
- #define SOLARIS_VERASE 2
- #define SOLARIS_VKILL 3
- #define SOLARIS_VEOF 4
- #define SOLARIS_VEOL 5
- #define SOLARIS_VEOL2 6
- #define SOLARIS_VSWTCH 7
- #define SOLARIS_VSTART 8
- #define SOLARIS_VSTOP 9
- #define SOLARIS_VSUSP 10
- #define SOLARIS_VDSUSP 11
- #define SOLARIS_VREPRINT 12
- #define SOLARIS_VDISCARD 13
- #define SOLARIS_VWERASE 14
- #define SOLARIS_VLNEXT 15
- #endif
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- /* Convert to/from host termio structure */
- struct solaris_termio {
- uint16_t c_iflag; /* input modes */
- uint16_t c_oflag; /* output modes */
- uint16_t c_cflag; /* control modes */
- uint16_t c_lflag; /* line discipline modes */
- uint8_t c_line; /* line discipline */
- uint8_t c_cc[SOLARIS_NCC]; /* control chars */
- };
- STATIC_INLINE_EMUL_UNIX void
- convert_to_solaris_termio(unsigned_word addr,
- struct termio *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct solaris_termio target;
- int i;
- target.c_iflag = H2T_2 (host->c_iflag);
- target.c_oflag = H2T_2 (host->c_oflag);
- target.c_cflag = H2T_2 (host->c_cflag);
- target.c_lflag = H2T_2 (host->c_lflag);
- #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
- target.c_line = host->c_line;
- #else
- target.c_line = 0;
- #endif
- for (i = 0; i < SOLARIS_NCC; i++)
- target.c_cc[i] = 0;
- #ifdef VINTR
- target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
- #endif
- #ifdef VQUIT
- target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
- #endif
- #ifdef VERASE
- target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
- #endif
- #ifdef VKILL
- target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
- #endif
- #ifdef VEOF
- target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
- #endif
- #ifdef VEOL
- target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
- #endif
- #ifdef VEOL2
- target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
- #endif
- #ifdef VSWTCH
- target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
- #else
- #ifdef VSWTC
- target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
- #endif
- #endif
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_TERMIO_STRUCTURE || HAVE_TERMIOS_STRUCTURE */
- #ifdef HAVE_TERMIOS_STRUCTURE
- /* Convert to/from host termios structure */
- typedef uint32_t solaris_tcflag_t;
- typedef uint8_t solaris_cc_t;
- typedef uint32_t solaris_speed_t;
- struct solaris_termios {
- solaris_tcflag_t c_iflag;
- solaris_tcflag_t c_oflag;
- solaris_tcflag_t c_cflag;
- solaris_tcflag_t c_lflag;
- solaris_cc_t c_cc[SOLARIS_NCCS];
- };
- STATIC_INLINE_EMUL_UNIX void
- convert_to_solaris_termios(unsigned_word addr,
- struct termios *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct solaris_termios target;
- int i;
- target.c_iflag = H2T_4 (host->c_iflag);
- target.c_oflag = H2T_4 (host->c_oflag);
- target.c_cflag = H2T_4 (host->c_cflag);
- target.c_lflag = H2T_4 (host->c_lflag);
- for (i = 0; i < SOLARIS_NCCS; i++)
- target.c_cc[i] = 0;
- #ifdef VINTR
- target.c_cc[SOLARIS_VINTR] = host->c_cc[VINTR];
- #endif
- #ifdef VQUIT
- target.c_cc[SOLARIS_VQUIT] = host->c_cc[VQUIT];
- #endif
- #ifdef VERASE
- target.c_cc[SOLARIS_VERASE] = host->c_cc[VERASE];
- #endif
- #ifdef VKILL
- target.c_cc[SOLARIS_VKILL] = host->c_cc[VKILL];
- #endif
- #ifdef VEOF
- target.c_cc[SOLARIS_VEOF] = host->c_cc[VEOF];
- #endif
- #ifdef VEOL
- target.c_cc[SOLARIS_VEOL] = host->c_cc[VEOL];
- #endif
- #ifdef VEOL2
- target.c_cc[SOLARIS_VEOL2] = host->c_cc[VEOL2];
- #endif
- #ifdef VSWTCH
- target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTCH];
- #else
- #ifdef VSWTC
- target.c_cc[SOLARIS_VSWTCH] = host->c_cc[VSWTC];
- #endif
- #endif
- #ifdef VSTART
- target.c_cc[SOLARIS_VSTART] = host->c_cc[VSTART];
- #endif
- #ifdef VSTOP
- target.c_cc[SOLARIS_VSTOP] = host->c_cc[VSTOP];
- #endif
- #ifdef VSUSP
- target.c_cc[SOLARIS_VSUSP] = host->c_cc[VSUSP];
- #endif
- #ifdef VDSUSP
- target.c_cc[SOLARIS_VDSUSP] = host->c_cc[VDSUSP];
- #endif
- #ifdef VREPRINT
- target.c_cc[SOLARIS_VREPRINT] = host->c_cc[VREPRINT];
- #endif
- #ifdef VDISCARD
- target.c_cc[SOLARIS_VDISCARD] = host->c_cc[VDISCARD];
- #endif
- #ifdef VWERASE
- target.c_cc[SOLARIS_VWERASE] = host->c_cc[VWERASE];
- #endif
- #ifdef VLNEXT
- target.c_cc[SOLARIS_VLNEXT] = host->c_cc[VLNEXT];
- #endif
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_TERMIOS_STRUCTURE */
- #ifndef HAVE_IOCTL
- #define do_solaris_ioctl 0
- #else
- static void
- do_solaris_ioctl(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int fildes = cpu_registers(processor)->gpr[arg0];
- unsigned request = cpu_registers(processor)->gpr[arg0+1];
- unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
- int status = 0;
- const char *name = "<unknown>";
- #ifdef HAVE_TERMIOS_STRUCTURE
- struct termios host_termio;
- #else
- #ifdef HAVE_TERMIO_STRUCTURE
- struct termio host_termio;
- #endif
- #endif
- status = fdbad (fildes);
- if (status != 0)
- goto done;
- switch (request)
- {
- case 0: /* make sure we have at least one case */
- default:
- status = -1;
- errno = EINVAL;
- break;
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
- case SOLARIS_TIOC | 1: /* TCGETA */
- name = "TCGETA";
- #ifdef HAVE_TCGETATTR
- status = tcgetattr(fildes, &host_termio);
- #elif defined(TCGETS)
- status = ioctl (fildes, TCGETS, &host_termio);
- #else
- status = ioctl (fildes, TCGETA, &host_termio);
- #endif
- if (status == 0)
- convert_to_solaris_termio (argp_addr, &host_termio, processor, cia);
- break;
- #endif /* TCGETA */
- #endif /* HAVE_TERMIO_STRUCTURE */
- #ifdef HAVE_TERMIOS_STRUCTURE
- #if defined(TCGETS) || defined(HAVE_TCGETATTR)
- case SOLARIS_TIOC | 13: /* TCGETS */
- name = "TCGETS";
- #ifdef HAVE_TCGETATTR
- status = tcgetattr(fildes, &host_termio);
- #else
- status = ioctl (fildes, TCGETS, &host_termio);
- #endif
- if (status == 0)
- convert_to_solaris_termios (argp_addr, &host_termio, processor, cia);
- break;
- #endif /* TCGETS */
- #endif /* HAVE_TERMIOS_STRUCTURE */
- }
- done:
- emul_write_status(processor, status, errno);
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
- }
- #endif /* HAVE_IOCTL */
- static emul_syscall_descriptor solaris_descriptors[] = {
- /* 0 */ { 0, "syscall" },
- /* 1 */ { do_unix_exit, "exit" },
- /* 2 */ { 0, "fork" },
- /* 3 */ { do_unix_read, "read" },
- /* 4 */ { do_unix_write, "write" },
- /* 5 */ { do_unix_open, "open" },
- /* 6 */ { do_unix_close, "close" },
- /* 7 */ { 0, "wait" },
- /* 8 */ { 0, "creat" },
- /* 9 */ { do_unix_link, "link" },
- /* 10 */ { do_unix_unlink, "unlink" },
- /* 11 */ { 0, "exec" },
- /* 12 */ { do_unix_chdir, "chdir" },
- /* 13 */ { do_unix_time, "time" },
- /* 14 */ { 0, "mknod" },
- /* 15 */ { 0, "chmod" },
- /* 16 */ { 0, "chown" },
- /* 17 */ { do_unix_break, "brk" },
- /* 18 */ { do_solaris_stat, "stat" },
- /* 19 */ { do_unix_lseek, "lseek" },
- /* 20 */ { do_unix_getpid2, "getpid" },
- /* 21 */ { 0, "mount" },
- /* 22 */ { 0, "umount" },
- /* 23 */ { 0, "setuid" },
- /* 24 */ { do_unix_getuid2, "getuid" },
- /* 25 */ { 0, "stime" },
- /* 26 */ { 0, "ptrace" },
- /* 27 */ { 0, "alarm" },
- /* 28 */ { do_solaris_fstat, "fstat" },
- /* 29 */ { 0, "pause" },
- /* 30 */ { 0, "utime" },
- /* 31 */ { 0, "stty" },
- /* 32 */ { 0, "gtty" },
- /* 33 */ { do_unix_access, "access" },
- /* 34 */ { 0, "nice" },
- /* 35 */ { 0, "statfs" },
- /* 36 */ { 0, "sync" },
- /* 37 */ { 0, "kill" },
- /* 38 */ { 0, "fstatfs" },
- /* 39 */ { 0, "pgrpsys" },
- /* 40 */ { 0, "xenix" },
- /* 41 */ { do_unix_dup, "dup" },
- /* 42 */ { 0, "pipe" },
- /* 43 */ { 0, "times" },
- /* 44 */ { 0, "profil" },
- /* 45 */ { 0, "plock" },
- /* 46 */ { 0, "setgid" },
- /* 47 */ { do_unix_getgid2, "getgid" },
- /* 48 */ { 0, "signal" },
- /* 49 */ { 0, "msgsys" },
- /* 50 */ { 0, "syssun" },
- /* 51 */ { 0, "acct" },
- /* 52 */ { 0, "shmsys" },
- /* 53 */ { 0, "semsys" },
- /* 54 */ { do_solaris_ioctl, "ioctl" },
- /* 55 */ { 0, "uadmin" },
- /* 56 */ { 0, 0 /* reserved for exch */ },
- /* 57 */ { 0, "utssys" },
- /* 58 */ { 0, "fdsync" },
- /* 59 */ { 0, "execve" },
- /* 60 */ { do_unix_umask, "umask" },
- /* 61 */ { 0, "chroot" },
- /* 62 */ { 0, "fcntl" },
- /* 63 */ { 0, "ulimit" },
- /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 64 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 65 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 66 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 67 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 68 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 69 */ { 0, 0 /* reserved for UNIX PC */ },
- /* 70 */ { 0, 0 /* was advfs */ },
- /* 71 */ { 0, 0 /* was unadvfs */ },
- /* 72 */ { 0, 0 /* was rmount */ },
- /* 73 */ { 0, 0 /* was rumount */ },
- /* 74 */ { 0, 0 /* was rfstart */ },
- /* 75 */ { 0, 0 /* was sigret */ },
- /* 76 */ { 0, 0 /* was rdebug */ },
- /* 77 */ { 0, 0 /* was rfstop */ },
- /* 78 */ { 0, 0 /* was rfsys */ },
- /* 79 */ { do_unix_rmdir, "rmdir" },
- /* 80 */ { do_unix_mkdir, "mkdir" },
- /* 81 */ { 0, "getdents" },
- /* 82 */ { 0, 0 /* was libattach */ },
- /* 83 */ { 0, 0 /* was libdetach */ },
- /* 84 */ { 0, "sysfs" },
- /* 85 */ { 0, "getmsg" },
- /* 86 */ { 0, "putmsg" },
- /* 87 */ { 0, "poll" },
- /* 88 */ { do_solaris_lstat, "lstat" },
- /* 89 */ { do_unix_symlink, "symlink" },
- /* 90 */ { 0, "readlink" },
- /* 91 */ { 0, "setgroups" },
- /* 92 */ { 0, "getgroups" },
- /* 93 */ { 0, "fchmod" },
- /* 94 */ { 0, "fchown" },
- /* 95 */ { 0, "sigprocmask" },
- /* 96 */ { 0, "sigsuspend" },
- /* 97 */ { do_unix_nop, "sigaltstack" },
- /* 98 */ { do_unix_nop, "sigaction" },
- /* 99 */ { 0, "sigpending" },
- /* 100 */ { 0, "context" },
- /* 101 */ { 0, "evsys" },
- /* 102 */ { 0, "evtrapret" },
- /* 103 */ { 0, "statvfs" },
- /* 104 */ { 0, "fstatvfs" },
- /* 105 */ { 0, 0 /* reserved */ },
- /* 106 */ { 0, "nfssys" },
- /* 107 */ { 0, "waitsys" },
- /* 108 */ { 0, "sigsendsys" },
- /* 109 */ { 0, "hrtsys" },
- /* 110 */ { 0, "acancel" },
- /* 111 */ { 0, "async" },
- /* 112 */ { 0, "priocntlsys" },
- /* 113 */ { 0, "pathconf" },
- /* 114 */ { 0, "mincore" },
- /* 115 */ { 0, "mmap" },
- /* 116 */ { 0, "mprotect" },
- /* 117 */ { 0, "munmap" },
- /* 118 */ { 0, "fpathconf" },
- /* 119 */ { 0, "vfork" },
- /* 120 */ { 0, "fchdir" },
- /* 121 */ { 0, "readv" },
- /* 122 */ { 0, "writev" },
- /* 123 */ { 0, "xstat" },
- /* 124 */ { 0, "lxstat" },
- /* 125 */ { 0, "fxstat" },
- /* 126 */ { 0, "xmknod" },
- /* 127 */ { 0, "clocal" },
- /* 128 */ { 0, "setrlimit" },
- /* 129 */ { 0, "getrlimit" },
- /* 130 */ { 0, "lchown" },
- /* 131 */ { 0, "memcntl" },
- /* 132 */ { 0, "getpmsg" },
- /* 133 */ { 0, "putpmsg" },
- /* 134 */ { 0, "rename" },
- /* 135 */ { 0, "uname" },
- /* 136 */ { 0, "setegid" },
- /* 137 */ { 0, "sysconfig" },
- /* 138 */ { 0, "adjtime" },
- /* 139 */ { 0, "systeminfo" },
- /* 140 */ { 0, 0 /* reserved */ },
- /* 141 */ { 0, "seteuid" },
- /* 142 */ { 0, "vtrace" },
- /* 143 */ { 0, "fork1" },
- /* 144 */ { 0, "sigtimedwait" },
- /* 145 */ { 0, "lwp_info" },
- /* 146 */ { 0, "yield" },
- /* 147 */ { 0, "lwp_sema_wait" },
- /* 148 */ { 0, "lwp_sema_post" },
- /* 149 */ { 0, 0 /* reserved */ },
- /* 150 */ { 0, 0 /* reserved */ },
- /* 151 */ { 0, 0 /* reserved */ },
- /* 152 */ { 0, "modctl" },
- /* 153 */ { 0, "fchroot" },
- /* 154 */ { 0, "utimes" },
- /* 155 */ { 0, "vhangup" },
- /* 156 */ { do_unix_gettimeofday, "gettimeofday" },
- /* 157 */ { 0, "getitimer" },
- /* 158 */ { 0, "setitimer" },
- /* 159 */ { 0, "lwp_create" },
- /* 160 */ { 0, "lwp_exit" },
- /* 161 */ { 0, "lwp_suspend" },
- /* 162 */ { 0, "lwp_continue" },
- /* 163 */ { 0, "lwp_kill" },
- /* 164 */ { 0, "lwp_self" },
- /* 165 */ { 0, "lwp_setprivate" },
- /* 166 */ { 0, "lwp_getprivate" },
- /* 167 */ { 0, "lwp_wait" },
- /* 168 */ { 0, "lwp_mutex_unlock" },
- /* 169 */ { 0, "lwp_mutex_lock" },
- /* 170 */ { 0, "lwp_cond_wait" },
- /* 171 */ { 0, "lwp_cond_signal" },
- /* 172 */ { 0, "lwp_cond_broadcast" },
- /* 173 */ { 0, "pread" },
- /* 174 */ { 0, "pwrite" },
- /* 175 */ { 0, "llseek" },
- /* 176 */ { 0, "inst_sync" },
- /* 177 */ { 0, 0 /* reserved */ },
- /* 178 */ { 0, "kaio" },
- /* 179 */ { 0, 0 /* reserved */ },
- /* 180 */ { 0, 0 /* reserved */ },
- /* 181 */ { 0, 0 /* reserved */ },
- /* 182 */ { 0, 0 /* reserved */ },
- /* 183 */ { 0, 0 /* reserved */ },
- /* 184 */ { 0, "tsolsys" },
- /* 185 */ { 0, "acl" },
- /* 186 */ { 0, "auditsys" },
- /* 187 */ { 0, "processor_bind" },
- /* 188 */ { 0, "processor_info" },
- /* 189 */ { 0, "p_online" },
- /* 190 */ { 0, "sigqueue" },
- /* 191 */ { 0, "clock_gettime" },
- /* 192 */ { 0, "clock_settime" },
- /* 193 */ { 0, "clock_getres" },
- /* 194 */ { 0, "timer_create" },
- /* 195 */ { 0, "timer_delete" },
- /* 196 */ { 0, "timer_settime" },
- /* 197 */ { 0, "timer_gettime" },
- /* 198 */ { 0, "timer_getoverrun" },
- /* 199 */ { 0, "nanosleep" },
- /* 200 */ { 0, "facl" },
- /* 201 */ { 0, "door" },
- /* 202 */ { 0, "setreuid" },
- /* 203 */ { 0, "setregid" },
- /* 204 */ { 0, "install_utrap" },
- /* 205 */ { 0, 0 /* reserved */ },
- /* 206 */ { 0, 0 /* reserved */ },
- /* 207 */ { 0, 0 /* reserved */ },
- /* 208 */ { 0, 0 /* reserved */ },
- /* 209 */ { 0, 0 /* reserved */ },
- /* 210 */ { 0, "signotifywait" },
- /* 211 */ { 0, "lwp_sigredirect" },
- /* 212 */ { 0, "lwp_alarm" },
- };
- static char *(solaris_error_names[]) = {
- /* 0 */ "ESUCCESS",
- /* 1 */ "EPERM",
- /* 2 */ "ENOENT",
- /* 3 */ "ESRCH",
- /* 4 */ "EINTR",
- /* 5 */ "EIO",
- /* 6 */ "ENXIO",
- /* 7 */ "E2BIG",
- /* 8 */ "ENOEXEC",
- /* 9 */ "EBADF",
- /* 10 */ "ECHILD",
- /* 11 */ "EAGAIN",
- /* 12 */ "ENOMEM",
- /* 13 */ "EACCES",
- /* 14 */ "EFAULT",
- /* 15 */ "ENOTBLK",
- /* 16 */ "EBUSY",
- /* 17 */ "EEXIST",
- /* 18 */ "EXDEV",
- /* 19 */ "ENODEV",
- /* 20 */ "ENOTDIR",
- /* 21 */ "EISDIR",
- /* 22 */ "EINVAL",
- /* 23 */ "ENFILE",
- /* 24 */ "EMFILE",
- /* 25 */ "ENOTTY",
- /* 26 */ "ETXTBSY",
- /* 27 */ "EFBIG",
- /* 28 */ "ENOSPC",
- /* 29 */ "ESPIPE",
- /* 30 */ "EROFS",
- /* 31 */ "EMLINK",
- /* 32 */ "EPIPE",
- /* 33 */ "EDOM",
- /* 34 */ "ERANGE",
- /* 35 */ "ENOMSG",
- /* 36 */ "EIDRM",
- /* 37 */ "ECHRNG",
- /* 38 */ "EL2NSYNC",
- /* 39 */ "EL3HLT",
- /* 40 */ "EL3RST",
- /* 41 */ "ELNRNG",
- /* 42 */ "EUNATCH",
- /* 43 */ "ENOCSI",
- /* 44 */ "EL2HLT",
- /* 45 */ "EDEADLK",
- /* 46 */ "ENOLCK",
- /* 47 */ "ECANCELED",
- /* 48 */ "ENOTSUP",
- /* 49 */ "EDQUOT",
- /* 50 */ "EBADE",
- /* 51 */ "EBADR",
- /* 52 */ "EXFULL",
- /* 53 */ "ENOANO",
- /* 54 */ "EBADRQC",
- /* 55 */ "EBADSLT",
- /* 56 */ "EDEADLOCK",
- /* 57 */ "EBFONT",
- /* 58 */ "Error code 58",
- /* 59 */ "Error code 59",
- /* 60 */ "ENOSTR",
- /* 61 */ "ENODATA",
- /* 62 */ "ETIME",
- /* 63 */ "ENOSR",
- /* 64 */ "ENONET",
- /* 65 */ "ENOPKG",
- /* 66 */ "EREMOTE",
- /* 67 */ "ENOLINK",
- /* 68 */ "EADV",
- /* 69 */ "ESRMNT",
- /* 70 */ "ECOMM",
- /* 71 */ "EPROTO",
- /* 72 */ "Error code 72",
- /* 73 */ "Error code 73",
- /* 74 */ "EMULTIHOP",
- /* 75 */ "Error code 75",
- /* 76 */ "Error code 76",
- /* 77 */ "EBADMSG",
- /* 78 */ "ENAMETOOLONG",
- /* 79 */ "EOVERFLOW",
- /* 80 */ "ENOTUNIQ",
- /* 81 */ "EBADFD",
- /* 82 */ "EREMCHG",
- /* 83 */ "ELIBACC",
- /* 84 */ "ELIBBAD",
- /* 85 */ "ELIBSCN",
- /* 86 */ "ELIBMAX",
- /* 87 */ "ELIBEXEC",
- /* 88 */ "EILSEQ",
- /* 89 */ "ENOSYS",
- /* 90 */ "ELOOP",
- /* 91 */ "ERESTART",
- /* 92 */ "ESTRPIPE",
- /* 93 */ "ENOTEMPTY",
- /* 94 */ "EUSERS",
- /* 95 */ "ENOTSOCK",
- /* 96 */ "EDESTADDRREQ",
- /* 97 */ "EMSGSIZE",
- /* 98 */ "EPROTOTYPE",
- /* 99 */ "ENOPROTOOPT",
- /* 100 */ "Error code 100",
- /* 101 */ "Error code 101",
- /* 102 */ "Error code 102",
- /* 103 */ "Error code 103",
- /* 104 */ "Error code 104",
- /* 105 */ "Error code 105",
- /* 106 */ "Error code 106",
- /* 107 */ "Error code 107",
- /* 108 */ "Error code 108",
- /* 109 */ "Error code 109",
- /* 110 */ "Error code 110",
- /* 111 */ "Error code 111",
- /* 112 */ "Error code 112",
- /* 113 */ "Error code 113",
- /* 114 */ "Error code 114",
- /* 115 */ "Error code 115",
- /* 116 */ "Error code 116",
- /* 117 */ "Error code 117",
- /* 118 */ "Error code 118",
- /* 119 */ "Error code 119",
- /* 120 */ "EPROTONOSUPPORT",
- /* 121 */ "ESOCKTNOSUPPORT",
- /* 122 */ "EOPNOTSUPP",
- /* 123 */ "EPFNOSUPPORT",
- /* 124 */ "EAFNOSUPPORT",
- /* 125 */ "EADDRINUSE",
- /* 126 */ "EADDRNOTAVAIL",
- /* 127 */ "ENETDOWN",
- /* 128 */ "ENETUNREACH",
- /* 129 */ "ENETRESET",
- /* 130 */ "ECONNABORTED",
- /* 131 */ "ECONNRESET",
- /* 132 */ "ENOBUFS",
- /* 133 */ "EISCONN",
- /* 134 */ "ENOTCONN",
- /* 135 */ "Error code 135", /* XENIX has 135 - 142 */
- /* 136 */ "Error code 136",
- /* 137 */ "Error code 137",
- /* 138 */ "Error code 138",
- /* 139 */ "Error code 139",
- /* 140 */ "Error code 140",
- /* 141 */ "Error code 141",
- /* 142 */ "Error code 142",
- /* 143 */ "ESHUTDOWN",
- /* 144 */ "ETOOMANYREFS",
- /* 145 */ "ETIMEDOUT",
- /* 146 */ "ECONNREFUSED",
- /* 147 */ "EHOSTDOWN",
- /* 148 */ "EHOSTUNREACH",
- /* 149 */ "EALREADY",
- /* 150 */ "EINPROGRESS",
- /* 151 */ "ESTALE",
- };
- static char *(solaris_signal_names[]) = {
- /* 0 */ 0,
- /* 1 */ "SIGHUP",
- /* 2 */ "SIGINT",
- /* 3 */ "SIGQUIT",
- /* 4 */ "SIGILL",
- /* 5 */ "SIGTRAP",
- /* 6 */ "SIGABRT",
- /* 7 */ "SIGEMT",
- /* 8 */ "SIGFPE",
- /* 9 */ "SIGKILL",
- /* 10 */ "SIGBUS",
- /* 11 */ "SIGSEGV",
- /* 12 */ "SIGSYS",
- /* 13 */ "SIGPIPE",
- /* 14 */ "SIGALRM",
- /* 15 */ "SIGTERM",
- /* 16 */ "SIGUSR1",
- /* 17 */ "SIGUSR2",
- /* 18 */ "SIGCHLD",
- /* 19 */ "SIGPWR",
- /* 20 */ "SIGWINCH",
- /* 21 */ "SIGURG",
- /* 22 */ "SIGPOLL",
- /* 23 */ "SIGSTOP",
- /* 24 */ "SIGTSTP",
- /* 25 */ "SIGCONT",
- /* 26 */ "SIGTTIN",
- /* 27 */ "SIGTTOU",
- /* 28 */ "SIGVTALRM",
- /* 29 */ "SIGPROF",
- /* 30 */ "SIGXCPU",
- /* 31 */ "SIGXFSZ",
- /* 32 */ "SIGWAITING",
- /* 33 */ "SIGLWP",
- /* 34 */ "SIGFREEZE",
- /* 35 */ "SIGTHAW",
- /* 36 */ "SIGCANCEL",
- };
- static emul_syscall emul_solaris_syscalls = {
- solaris_descriptors,
- ARRAY_SIZE (solaris_descriptors),
- solaris_error_names,
- ARRAY_SIZE (solaris_error_names),
- solaris_signal_names,
- ARRAY_SIZE (solaris_signal_names),
- };
- /* Solaris's os_emul interface, most are just passed on to the generic
- syscall stuff */
- static os_emul_data *
- emul_solaris_create(device *root,
- bfd *image,
- const char *name)
- {
- /* check that this emulation is really for us */
- if (name != NULL && strcmp(name, "solaris") != 0)
- return NULL;
- if (image == NULL)
- return NULL;
- return emul_unix_create(root, image, "solaris", &emul_solaris_syscalls);
- }
-
- static void
- emul_solaris_init(os_emul_data *emul_data,
- int nr_cpus)
- {
- fd_closed[0] = 0;
- fd_closed[1] = 0;
- fd_closed[2] = 0;
- }
- static void
- emul_solaris_system_call(cpu *processor,
- unsigned_word cia,
- os_emul_data *emul_data)
- {
- emul_do_system_call(emul_data,
- emul_data->syscalls,
- cpu_registers(processor)->gpr[0],
- 3, /*r3 contains arg0*/
- processor,
- cia);
- }
- const os_emul emul_solaris = {
- "solaris",
- emul_solaris_create,
- emul_solaris_init,
- emul_solaris_system_call,
- 0, /*instruction_call*/
- 0 /*data*/
- };
- /* EMULATION
- Linux - Emulation of user programs for Linux/PPC
- DESCRIPTION
- */
- /* Linux specific implementation */
- typedef uint32_t linux_dev_t;
- typedef uint32_t linux_ino_t;
- typedef uint32_t linux_mode_t;
- typedef uint16_t linux_nlink_t;
- typedef int32_t linux_off_t;
- typedef int32_t linux_pid_t;
- typedef uint32_t linux_uid_t;
- typedef uint32_t linux_gid_t;
- typedef uint32_t linux_size_t;
- typedef int32_t linux_ssize_t;
- typedef int32_t linux_ptrdiff_t;
- typedef int32_t linux_time_t;
- typedef int32_t linux_clock_t;
- typedef int32_t linux_daddr_t;
- #ifdef HAVE_SYS_STAT_H
- /* For the PowerPC, don't both with the 'old' stat structure, since there
- should be no extant binaries with that structure. */
- struct linux_stat {
- linux_dev_t st_dev;
- linux_ino_t st_ino;
- linux_mode_t st_mode;
- linux_nlink_t st_nlink;
- linux_uid_t st_uid;
- linux_gid_t st_gid;
- linux_dev_t st_rdev;
- linux_off_t st_size;
- uint32_t st_blksize;
- uint32_t st_blocks;
- uint32_t st_atimx; /* don't use st_{a,c,m}time, that might a macro */
- uint32_t __unused1; /* defined by the host's stat.h */
- uint32_t st_mtimx;
- uint32_t __unused2;
- uint32_t st_ctimx;
- uint32_t __unused3;
- uint32_t __unused4;
- uint32_t __unused5;
- };
- /* Convert from host stat structure to solaris stat structure */
- STATIC_INLINE_EMUL_UNIX void
- convert_to_linux_stat(unsigned_word addr,
- struct stat *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct linux_stat target;
- target.st_dev = H2T_4(host->st_dev);
- target.st_ino = H2T_4(host->st_ino);
- target.st_mode = H2T_4(host->st_mode);
- target.st_nlink = H2T_2(host->st_nlink);
- target.st_uid = H2T_4(host->st_uid);
- target.st_gid = H2T_4(host->st_gid);
- target.st_size = H2T_4(host->st_size);
- #ifdef HAVE_ST_RDEV
- target.st_rdev = H2T_4(host->st_rdev);
- #else
- target.st_rdev = 0;
- #endif
- #ifdef HAVE_ST_BLKSIZE
- target.st_blksize = H2T_4(host->st_blksize);
- #else
- target.st_blksize = 0;
- #endif
- #ifdef HAVE_ST_BLOCKS
- target.st_blocks = H2T_4(host->st_blocks);
- #else
- target.st_blocks = 0;
- #endif
- target.st_atimx = H2T_4(host->st_atime);
- target.st_ctimx = H2T_4(host->st_ctime);
- target.st_mtimx = H2T_4(host->st_mtime);
- target.__unused1 = 0;
- target.__unused2 = 0;
- target.__unused3 = 0;
- target.__unused4 = 0;
- target.__unused5 = 0;
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_SYS_STAT_H */
- #ifndef HAVE_STAT
- #define do_linux_stat 0
- #else
- static void
- do_linux_stat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- char path_buf[PATH_MAX];
- struct stat buf;
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
- status = stat (path, &buf);
- if (status == 0)
- convert_to_linux_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_LSTAT
- #define do_linux_lstat 0
- #else
- static void
- do_linux_lstat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- unsigned_word path_addr = cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- char path_buf[PATH_MAX];
- struct stat buf;
- char *path = emul_read_string(path_buf, path_addr, PATH_MAX, processor, cia);
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("0x%lx [%s], 0x%lx", (long)path_addr, path, (long)stat_pkt);
- status = lstat (path, &buf);
- if (status == 0)
- convert_to_linux_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #ifndef HAVE_FSTAT
- #define do_linux_fstat 0
- #else
- static void
- do_linux_fstat(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int fildes = (int)cpu_registers(processor)->gpr[arg0];
- unsigned_word stat_pkt = cpu_registers(processor)->gpr[arg0+1];
- struct stat buf;
- int status;
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%lx", fildes, (long)stat_pkt);
- status = fdbad (fildes);
- if (status == 0)
- status = fstat (fildes, &buf);
- if (status == 0)
- convert_to_linux_stat (stat_pkt, &buf, processor, cia);
- emul_write_status(processor, status, errno);
- }
- #endif
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- #define LINUX_NCC 10
- #define LINUX_NCCS 19
-
- #define LINUX_VINTR 0
- #define LINUX_VQUIT 1
- #define LINUX_VERASE 2
- #define LINUX_VKILL 3
- #define LINUX_VEOF 4
- #define LINUX_VMIN 5
- #define LINUX_VEOL 6
- #define LINUX_VTIME 7
- #define LINUX_VEOL2 8
- #define LINUX_VSWTC 9
- #define LINUX_VWERASE 10
- #define LINUX_VREPRINT 11
- #define LINUX_VSUSP 12
- #define LINUX_VSTART 13
- #define LINUX_VSTOP 14
- #define LINUX_VLNEXT 15
- #define LINUX_VDISCARD 16
-
- #define LINUX_IOC_NRBITS 8
- #define LINUX_IOC_TYPEBITS 8
- #define LINUX_IOC_SIZEBITS 13
- #define LINUX_IOC_DIRBITS 3
- #define LINUX_IOC_NRMASK ((1 << LINUX_IOC_NRBITS)-1)
- #define LINUX_IOC_TYPEMASK ((1 << LINUX_IOC_TYPEBITS)-1)
- #define LINUX_IOC_SIZEMASK ((1 << LINUX_IOC_SIZEBITS)-1)
- #define LINUX_IOC_DIRMASK ((1 << LINUX_IOC_DIRBITS)-1)
- #define LINUX_IOC_NRSHIFT 0
- #define LINUX_IOC_TYPESHIFT (LINUX_IOC_NRSHIFT+LINUX_IOC_NRBITS)
- #define LINUX_IOC_SIZESHIFT (LINUX_IOC_TYPESHIFT+LINUX_IOC_TYPEBITS)
- #define LINUX_IOC_DIRSHIFT (LINUX_IOC_SIZESHIFT+LINUX_IOC_SIZEBITS)
- /*
- * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
- * And this turns out useful to catch old ioctl numbers in header
- * files for us.
- */
- #define LINUX_IOC_NONE 1U
- #define LINUX_IOC_READ 2U
- #define LINUX_IOC_WRITE 4U
- #define LINUX_IOC(dir,type,nr,size) \
- (((dir) << LINUX_IOC_DIRSHIFT) | \
- ((type) << LINUX_IOC_TYPESHIFT) | \
- ((nr) << LINUX_IOC_NRSHIFT) | \
- ((size) << LINUX_IOC_SIZESHIFT))
- /* used to create numbers */
- #define LINUX_IO(type,nr) LINUX_IOC(LINUX_IOC_NONE,(type),(nr),0)
- #define LINUX_IOR(type,nr,size) LINUX_IOC(LINUX_IOC_READ,(type),(nr),sizeof(size))
- #define LINUX_IOW(type,nr,size) LINUX_IOC(LINUX_IOC_WRITE,(type),(nr),sizeof(size))
- #define LINUX_IOWR(type,nr,size) LINUX_IOC(LINUX_IOC_READ|LINUX_IOC_WRITE,(type),(nr),sizeof(size))
- #endif
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- /* Convert to/from host termio structure */
- struct linux_termio {
- uint16_t c_iflag; /* input modes */
- uint16_t c_oflag; /* output modes */
- uint16_t c_cflag; /* control modes */
- uint16_t c_lflag; /* line discipline modes */
- uint8_t c_line; /* line discipline */
- uint8_t c_cc[LINUX_NCC]; /* control chars */
- };
- STATIC_INLINE_EMUL_UNIX void
- convert_to_linux_termio(unsigned_word addr,
- struct termio *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct linux_termio target;
- int i;
- target.c_iflag = H2T_2 (host->c_iflag);
- target.c_oflag = H2T_2 (host->c_oflag);
- target.c_cflag = H2T_2 (host->c_cflag);
- target.c_lflag = H2T_2 (host->c_lflag);
- #if defined(HAVE_TERMIO_CLINE) || defined(HAVE_TERMIOS_CLINE)
- target.c_line = host->c_line;
- #else
- target.c_line = 0;
- #endif
- for (i = 0; i < LINUX_NCC; i++)
- target.c_cc[i] = 0;
- #ifdef VINTR
- target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
- #endif
- #ifdef VQUIT
- target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
- #endif
- #ifdef VERASE
- target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
- #endif
- #ifdef VKILL
- target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
- #endif
- #ifdef VEOF
- target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
- #endif
- #ifdef VMIN
- target.c_cc[LINUX_VMIN] = host->c_cc[VMIN];
- #endif
- #ifdef VEOL
- target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
- #endif
- #ifdef VTIME
- target.c_cc[LINUX_VTIME] = host->c_cc[VTIME];
- #endif
- #ifdef VEOL2
- target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
- #endif
- #ifdef VSWTC
- target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTC];
- #endif
- #ifdef VSWTCH
- target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
- #endif
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_TERMIO_STRUCTURE */
- #ifdef HAVE_TERMIOS_STRUCTURE
- /* Convert to/from host termios structure */
- typedef uint32_t linux_tcflag_t;
- typedef uint8_t linux_cc_t;
- typedef uint32_t linux_speed_t;
- struct linux_termios {
- linux_tcflag_t c_iflag;
- linux_tcflag_t c_oflag;
- linux_tcflag_t c_cflag;
- linux_tcflag_t c_lflag;
- linux_cc_t c_cc[LINUX_NCCS];
- linux_cc_t c_line;
- int32_t c_ispeed;
- int32_t c_ospeed;
- };
- STATIC_INLINE_EMUL_UNIX void
- convert_to_linux_termios(unsigned_word addr,
- struct termios *host,
- cpu *processor,
- unsigned_word cia)
- {
- struct linux_termios target;
- int i;
- target.c_iflag = H2T_4 (host->c_iflag);
- target.c_oflag = H2T_4 (host->c_oflag);
- target.c_cflag = H2T_4 (host->c_cflag);
- target.c_lflag = H2T_4 (host->c_lflag);
- for (i = 0; i < LINUX_NCCS; i++)
- target.c_cc[i] = 0;
- #ifdef VINTR
- target.c_cc[LINUX_VINTR] = host->c_cc[VINTR];
- #endif
- #ifdef VQUIT
- target.c_cc[LINUX_VQUIT] = host->c_cc[VQUIT];
- #endif
- #ifdef VERASE
- target.c_cc[LINUX_VERASE] = host->c_cc[VERASE];
- #endif
- #ifdef VKILL
- target.c_cc[LINUX_VKILL] = host->c_cc[VKILL];
- #endif
- #ifdef VEOF
- target.c_cc[LINUX_VEOF] = host->c_cc[VEOF];
- #endif
- #ifdef VEOL
- target.c_cc[LINUX_VEOL] = host->c_cc[VEOL];
- #endif
- #ifdef VEOL2
- target.c_cc[LINUX_VEOL2] = host->c_cc[VEOL2];
- #endif
- #ifdef VSWTCH
- target.c_cc[LINUX_VSWTC] = host->c_cc[VSWTCH];
- #endif
- #ifdef HAVE_TERMIOS_CLINE
- target.c_line = host->c_line;
- #else
- target.c_line = 0;
- #endif
- #ifdef HAVE_CFGETISPEED
- target.c_ispeed = cfgetispeed (host);
- #else
- target.c_ispeed = 0;
- #endif
- #ifdef HAVE_CFGETOSPEED
- target.c_ospeed = cfgetospeed (host);
- #else
- target.c_ospeed = 0;
- #endif
- emul_write_buffer(&target, addr, sizeof(target), processor, cia);
- }
- #endif /* HAVE_TERMIOS_STRUCTURE */
- #ifndef HAVE_IOCTL
- #define do_linux_ioctl 0
- #else
- static void
- do_linux_ioctl(os_emul_data *emul,
- unsigned call,
- const int arg0,
- cpu *processor,
- unsigned_word cia)
- {
- int fildes = cpu_registers(processor)->gpr[arg0];
- unsigned request = cpu_registers(processor)->gpr[arg0+1];
- unsigned_word argp_addr = cpu_registers(processor)->gpr[arg0+2];
- int status = 0;
- const char *name = "<unknown>";
- #ifdef HAVE_TERMIOS_STRUCTURE
- struct termios host_termio;
- #else
- #ifdef HAVE_TERMIO_STRUCTURE
- struct termio host_termio;
- #endif
- #endif
- status = fdbad (fildes);
- if (status != 0)
- goto done;
- switch (request)
- {
- case 0: /* make sure we have at least one case */
- default:
- status = -1;
- errno = EINVAL;
- break;
- #if defined(HAVE_TERMIO_STRUCTURE) || defined(HAVE_TERMIOS_STRUCTURE)
- #if defined(TCGETA) || defined(TCGETS) || defined(HAVE_TCGETATTR)
- case LINUX_IOR('t', 23, struct linux_termio): /* TCGETA */
- name = "TCGETA";
- #ifdef HAVE_TCGETATTR
- status = tcgetattr(fildes, &host_termio);
- #elif defined(TCGETS)
- status = ioctl (fildes, TCGETS, &host_termio);
- #else
- status = ioctl (fildes, TCGETA, &host_termio);
- #endif
- if (status == 0)
- convert_to_linux_termio (argp_addr, &host_termio, processor, cia);
- break;
- #endif /* TCGETA */
- #endif /* HAVE_TERMIO_STRUCTURE */
- #ifdef HAVE_TERMIOS_STRUCTURE
- #if defined(TCGETS) || defined(HAVE_TCGETATTR)
- case LINUX_IOR('t', 19, struct linux_termios): /* TCGETS */
- name = "TCGETS";
- #ifdef HAVE_TCGETATTR
- status = tcgetattr(fildes, &host_termio);
- #else
- status = ioctl (fildes, TCGETS, &host_termio);
- #endif
- if (status == 0)
- convert_to_linux_termios (argp_addr, &host_termio, processor, cia);
- break;
- #endif /* TCGETS */
- #endif /* HAVE_TERMIOS_STRUCTURE */
- }
- done:
- emul_write_status(processor, status, errno);
- if (WITH_TRACE && ppc_trace[trace_os_emul])
- printf_filtered ("%d, 0x%x [%s], 0x%lx", fildes, request, name, (long)argp_addr);
- }
- #endif /* HAVE_IOCTL */
- static emul_syscall_descriptor linux_descriptors[] = {
- /* 0 */ { 0, "setup" },
- /* 1 */ { do_unix_exit, "exit" },
- /* 2 */ { 0, "fork" },
- /* 3 */ { do_unix_read, "read" },
- /* 4 */ { do_unix_write, "write" },
- /* 5 */ { do_unix_open, "open" },
- /* 6 */ { do_unix_close, "close" },
- /* 7 */ { 0, "waitpid" },
- /* 8 */ { 0, "creat" },
- /* 9 */ { do_unix_link, "link" },
- /* 10 */ { do_unix_unlink, "unlink" },
- /* 11 */ { 0, "execve" },
- /* 12 */ { do_unix_chdir, "chdir" },
- /* 13 */ { do_unix_time, "time" },
- /* 14 */ { 0, "mknod" },
- /* 15 */ { 0, "chmod" },
- /* 16 */ { 0, "chown" },
- /* 17 */ { 0, "break" },
- /* 18 */ { 0, "stat" },
- /* 19 */ { do_unix_lseek, "lseek" },
- /* 20 */ { do_unix_getpid, "getpid" },
- /* 21 */ { 0, "mount" },
- /* 22 */ { 0, "umount" },
- /* 23 */ { 0, "setuid" },
- /* 24 */ { do_unix_getuid, "getuid" },
- /* 25 */ { 0, "stime" },
- /* 26 */ { 0, "ptrace" },
- /* 27 */ { 0, "alarm" },
- /* 28 */ { 0, "fstat" },
- /* 29 */ { 0, "pause" },
- /* 30 */ { 0, "utime" },
- /* 31 */ { 0, "stty" },
- /* 32 */ { 0, "gtty" },
- /* 33 */ { do_unix_access, "access" },
- /* 34 */ { 0, "nice" },
- /* 35 */ { 0, "ftime" },
- /* 36 */ { 0, "sync" },
- /* 37 */ { 0, "kill" },
- /* 38 */ { 0, "rename" },
- /* 39 */ { do_unix_mkdir, "mkdir" },
- /* 40 */ { do_unix_rmdir, "rmdir" },
- /* 41 */ { do_unix_dup, "dup" },
- /* 42 */ { 0, "pipe" },
- /* 43 */ { 0, "times" },
- /* 44 */ { 0, "prof" },
- /* 45 */ { do_unix_break, "brk" },
- /* 46 */ { 0, "setgid" },
- /* 47 */ { do_unix_getgid, "getgid" },
- /* 48 */ { 0, "signal" },
- /* 49 */ { do_unix_geteuid, "geteuid" },
- /* 50 */ { do_unix_getegid, "getegid" },
- /* 51 */ { 0, "acct" },
- /* 52 */ { 0, "phys" },
- /* 53 */ { 0, "lock" },
- /* 54 */ { do_linux_ioctl, "ioctl" },
- /* 55 */ { 0, "fcntl" },
- /* 56 */ { 0, "mpx" },
- /* 57 */ { 0, "setpgid" },
- /* 58 */ { 0, "ulimit" },
- /* 59 */ { 0, "olduname" },
- /* 60 */ { do_unix_umask, "umask" },
- /* 61 */ { 0, "chroot" },
- /* 62 */ { 0, "ustat" },
- /* 63 */ { do_unix_dup2, "dup2" },
- /* 64 */ { do_unix_getppid, "getppid" },
- /* 65 */ { 0, "getpgrp" },
- /* 66 */ { 0, "setsid" },
- /* 67 */ { 0, "sigaction" },
- /* 68 */ { 0, "sgetmask" },
- /* 69 */ { 0, "ssetmask" },
- /* 70 */ { 0, "setreuid" },
- /* 71 */ { 0, "setregid" },
- /* 72 */ { 0, "sigsuspend" },
- /* 73 */ { 0, "sigpending" },
- /* 74 */ { 0, "sethostname" },
- /* 75 */ { 0, "setrlimit" },
- /* 76 */ { 0, "getrlimit" },
- /* 77 */ { do_unix_getrusage, "getrusage" },
- /* 78 */ { do_unix_gettimeofday, "gettimeofday" },
- /* 79 */ { 0, "settimeofday" },
- /* 80 */ { 0, "getgroups" },
- /* 81 */ { 0, "setgroups" },
- /* 82 */ { 0, "select" },
- /* 83 */ { do_unix_symlink, "symlink" },
- /* 84 */ { 0, "lstat" },
- /* 85 */ { 0, "readlink" },
- /* 86 */ { 0, "uselib" },
- /* 87 */ { 0, "swapon" },
- /* 88 */ { 0, "reboot" },
- /* 89 */ { 0, "readdir" },
- /* 90 */ { 0, "mmap" },
- /* 91 */ { 0, "munmap" },
- /* 92 */ { 0, "truncate" },
- /* 93 */ { 0, "ftruncate" },
- /* 94 */ { 0, "fchmod" },
- /* 95 */ { 0, "fchown" },
- /* 96 */ { 0, "getpriority" },
- /* 97 */ { 0, "setpriority" },
- /* 98 */ { 0, "profil" },
- /* 99 */ { 0, "statfs" },
- /* 100 */ { 0, "fstatfs" },
- /* 101 */ { 0, "ioperm" },
- /* 102 */ { 0, "socketcall" },
- /* 103 */ { 0, "syslog" },
- /* 104 */ { 0, "setitimer" },
- /* 105 */ { 0, "getitimer" },
- /* 106 */ { do_linux_stat, "newstat" },
- /* 107 */ { do_linux_lstat, "newlstat" },
- /* 108 */ { do_linux_fstat, "newfstat" },
- /* 109 */ { 0, "uname" },
- /* 110 */ { 0, "iopl" },
- /* 111 */ { 0, "vhangup" },
- /* 112 */ { 0, "idle" },
- /* 113 */ { 0, "vm86" },
- /* 114 */ { 0, "wait4" },
- /* 115 */ { 0, "swapoff" },
- /* 116 */ { 0, "sysinfo" },
- /* 117 */ { 0, "ipc" },
- /* 118 */ { 0, "fsync" },
- /* 119 */ { 0, "sigreturn" },
- /* 120 */ { 0, "clone" },
- /* 121 */ { 0, "setdomainname" },
- /* 122 */ { 0, "newuname" },
- /* 123 */ { 0, "modify_ldt" },
- /* 124 */ { 0, "adjtimex" },
- /* 125 */ { 0, "mprotect" },
- /* 126 */ { 0, "sigprocmask" },
- /* 127 */ { 0, "create_module" },
- /* 128 */ { 0, "init_module" },
- /* 129 */ { 0, "delete_module" },
- /* 130 */ { 0, "get_kernel_syms" },
- /* 131 */ { 0, "quotactl" },
- /* 132 */ { 0, "getpgid" },
- /* 133 */ { 0, "fchdir" },
- /* 134 */ { 0, "bdflush" },
- /* 135 */ { 0, "sysfs" },
- /* 136 */ { 0, "personality" },
- /* 137 */ { 0, "afs_syscall" },
- /* 138 */ { 0, "setfsuid" },
- /* 139 */ { 0, "setfsgid" },
- /* 140 */ { 0, "llseek" },
- /* 141 */ { 0, "getdents" },
- /* 142 */ { 0, "newselect" },
- /* 143 */ { 0, "flock" },
- /* 144 */ { 0, "msync" },
- /* 145 */ { 0, "readv" },
- /* 146 */ { 0, "writev" },
- /* 147 */ { 0, "getsid" },
- /* 148 */ { 0, "fdatasync" },
- /* 149 */ { 0, "sysctl" },
- /* 150 */ { 0, "mlock" },
- /* 151 */ { 0, "munlock" },
- /* 152 */ { 0, "mlockall" },
- /* 153 */ { 0, "munlockall" },
- /* 154 */ { 0, "sched_setparam" },
- /* 155 */ { 0, "sched_getparam" },
- /* 156 */ { 0, "sched_setscheduler" },
- /* 157 */ { 0, "sched_getscheduler" },
- /* 158 */ { 0, "sched_yield" },
- /* 159 */ { 0, "sched_get_priority_max" },
- /* 160 */ { 0, "sched_get_priority_min" },
- /* 161 */ { 0, "sched_rr_get_interval" },
- };
- static char *(linux_error_names[]) = {
- /* 0 */ "ESUCCESS",
- /* 1 */ "EPERM",
- /* 2 */ "ENOENT",
- /* 3 */ "ESRCH",
- /* 4 */ "EINTR",
- /* 5 */ "EIO",
- /* 6 */ "ENXIO",
- /* 7 */ "E2BIG",
- /* 8 */ "ENOEXEC",
- /* 9 */ "EBADF",
- /* 10 */ "ECHILD",
- /* 11 */ "EAGAIN",
- /* 12 */ "ENOMEM",
- /* 13 */ "EACCES",
- /* 14 */ "EFAULT",
- /* 15 */ "ENOTBLK",
- /* 16 */ "EBUSY",
- /* 17 */ "EEXIST",
- /* 18 */ "EXDEV",
- /* 19 */ "ENODEV",
- /* 20 */ "ENOTDIR",
- /* 21 */ "EISDIR",
- /* 22 */ "EINVAL",
- /* 23 */ "ENFILE",
- /* 24 */ "EMFILE",
- /* 25 */ "ENOTTY",
- /* 26 */ "ETXTBSY",
- /* 27 */ "EFBIG",
- /* 28 */ "ENOSPC",
- /* 29 */ "ESPIPE",
- /* 30 */ "EROFS",
- /* 31 */ "EMLINK",
- /* 32 */ "EPIPE",
- /* 33 */ "EDOM",
- /* 34 */ "ERANGE",
- /* 35 */ "EDEADLK",
- /* 36 */ "ENAMETOOLONG",
- /* 37 */ "ENOLCK",
- /* 38 */ "ENOSYS",
- /* 39 */ "ENOTEMPTY",
- /* 40 */ "ELOOP",
- /* 41 */ 0,
- /* 42 */ "ENOMSG",
- /* 43 */ "EIDRM",
- /* 44 */ "ECHRNG",
- /* 45 */ "EL2NSYNC",
- /* 46 */ "EL3HLT",
- /* 47 */ "EL3RST",
- /* 48 */ "ELNRNG",
- /* 49 */ "EUNATCH",
- /* 50 */ "ENOCSI",
- /* 51 */ "EL2HLT",
- /* 52 */ "EBADE",
- /* 53 */ "EBADR",
- /* 54 */ "EXFULL",
- /* 55 */ "ENOANO",
- /* 56 */ "EBADRQC",
- /* 57 */ "EBADSLT",
- /* 58 */ "EDEADLOCK",
- /* 59 */ "EBFONT",
- /* 60 */ "ENOSTR",
- /* 61 */ "ENODATA",
- /* 62 */ "ETIME",
- /* 63 */ "ENOSR",
- /* 64 */ "ENONET",
- /* 65 */ "ENOPKG",
- /* 66 */ "EREMOTE",
- /* 67 */ "ENOLINK",
- /* 68 */ "EADV",
- /* 69 */ "ESRMNT",
- /* 70 */ "ECOMM",
- /* 71 */ "EPROTO",
- /* 72 */ "EMULTIHOP",
- /* 73 */ "EDOTDOT",
- /* 74 */ "EBADMSG",
- /* 75 */ "EOVERFLOW",
- /* 76 */ "ENOTUNIQ",
- /* 77 */ "EBADFD",
- /* 78 */ "EREMCHG",
- /* 79 */ "ELIBACC",
- /* 80 */ "ELIBBAD",
- /* 81 */ "ELIBSCN",
- /* 82 */ "ELIBMAX",
- /* 83 */ "ELIBEXEC",
- /* 84 */ "EILSEQ",
- /* 85 */ "ERESTART",
- /* 86 */ "ESTRPIPE",
- /* 87 */ "EUSERS",
- /* 88 */ "ENOTSOCK",
- /* 89 */ "EDESTADDRREQ",
- /* 90 */ "EMSGSIZE",
- /* 91 */ "EPROTOTYPE",
- /* 92 */ "ENOPROTOOPT",
- /* 93 */ "EPROTONOSUPPORT",
- /* 94 */ "ESOCKTNOSUPPORT",
- /* 95 */ "EOPNOTSUPP",
- /* 96 */ "EPFNOSUPPORT",
- /* 97 */ "EAFNOSUPPORT",
- /* 98 */ "EADDRINUSE",
- /* 99 */ "EADDRNOTAVAIL",
- /* 100 */ "ENETDOWN",
- /* 101 */ "ENETUNREACH",
- /* 102 */ "ENETRESET",
- /* 103 */ "ECONNABORTED",
- /* 104 */ "ECONNRESET",
- /* 105 */ "ENOBUFS",
- /* 106 */ "EISCONN",
- /* 107 */ "ENOTCONN",
- /* 108 */ "ESHUTDOWN",
- /* 109 */ "ETOOMANYREFS",
- /* 110 */ "ETIMEDOUT",
- /* 111 */ "ECONNREFUSED",
- /* 112 */ "EHOSTDOWN",
- /* 113 */ "EHOSTUNREACH",
- /* 114 */ "EALREADY",
- /* 115 */ "EINPROGRESS",
- /* 116 */ "ESTALE",
- /* 117 */ "EUCLEAN",
- /* 118 */ "ENOTNAM",
- /* 119 */ "ENAVAIL",
- /* 120 */ "EISNAM",
- /* 121 */ "EREMOTEIO",
- /* 122 */ "EDQUOT",
- };
- static char *(linux_signal_names[]) = {
- /* 0 */ 0,
- /* 1 */ "SIGHUP",
- /* 2 */ "SIGINT",
- /* 3 */ "SIGQUIT",
- /* 4 */ "SIGILL",
- /* 5 */ "SIGTRAP",
- /* 6 */ "SIGABRT",
- /* 6 */ "SIGIOT",
- /* 7 */ "SIGBUS",
- /* 8 */ "SIGFPE",
- /* 9 */ "SIGKILL",
- /* 10 */ "SIGUSR1",
- /* 11 */ "SIGSEGV",
- /* 12 */ "SIGUSR2",
- /* 13 */ "SIGPIPE",
- /* 14 */ "SIGALRM",
- /* 15 */ "SIGTERM",
- /* 16 */ "SIGSTKFLT",
- /* 17 */ "SIGCHLD",
- /* 18 */ "SIGCONT",
- /* 19 */ "SIGSTOP",
- /* 20 */ "SIGTSTP",
- /* 21 */ "SIGTTIN",
- /* 22 */ "SIGTTOU",
- /* 23 */ "SIGURG",
- /* 24 */ "SIGXCPU",
- /* 25 */ "SIGXFSZ",
- /* 26 */ "SIGVTALRM",
- /* 27 */ "SIGPROF",
- /* 28 */ "SIGWINCH",
- /* 29 */ "SIGIO",
- /* 30 */ "SIGPWR",
- /* 31 */ "SIGUNUSED",
- };
- static emul_syscall emul_linux_syscalls = {
- linux_descriptors,
- ARRAY_SIZE (linux_descriptors),
- linux_error_names,
- ARRAY_SIZE (linux_error_names),
- linux_signal_names,
- ARRAY_SIZE (linux_signal_names),
- };
- /* Linux's os_emul interface, most are just passed on to the generic
- syscall stuff */
- static os_emul_data *
- emul_linux_create(device *root,
- bfd *image,
- const char *name)
- {
- /* check that this emulation is really for us */
- if (name != NULL && strcmp(name, "linux") != 0)
- return NULL;
- if (image == NULL)
- return NULL;
- return emul_unix_create(root, image, "linux", &emul_linux_syscalls);
- }
- static void
- emul_linux_init(os_emul_data *emul_data,
- int nr_cpus)
- {
- fd_closed[0] = 0;
- fd_closed[1] = 0;
- fd_closed[2] = 0;
- }
- static void
- emul_linux_system_call(cpu *processor,
- unsigned_word cia,
- os_emul_data *emul_data)
- {
- emul_do_system_call(emul_data,
- emul_data->syscalls,
- cpu_registers(processor)->gpr[0],
- 3, /*r3 contains arg0*/
- processor,
- cia);
- }
- const os_emul emul_linux = {
- "linux",
- emul_linux_create,
- emul_linux_init,
- emul_linux_system_call,
- 0, /*instruction_call*/
- 0 /*data*/
- };
- #endif /* _EMUL_UNIX_C_ */
|