From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,263934f9c388e24c X-Google-Attributes: gidfee84,public From: werme@alingo.zk3.dec.com (Eric Werme) Subject: Re: How the Alpha/OSF1 system call work ??? Date: 1997/09/19 Message-ID: #1/1 X-Deja-AN: 273828253 References: <341F5374.99AB3D30@cwb.gov.tw> Organization: Digital Equipment Corporation Reply-To: werme@zk3.dec.com Newsgroups: comp.unix.osf.osf1 Chung-min Hung writes: >Could you tell me how the Alpha/OSF1 open() system call work ? >1. How the Alpha/OSF1 system pass the arguments to the kernel open() >routine ? >2. How the kernel open() routine get the "filename" argument ? All the system calls you call from C actually go to small assembly language routines in libc. For open(2), the code calls: >*[__open, 0x120030100] addq r31, 0x2d, r0 [__open, 0x120030104] call_pal callsys [__open, 0x120030108] beq r19, 0x120030120 [__open, 0x12003010c] br gp, 0x120030110 [__open, 0x120030110] ldah gp, 8190(gp) [__open, 0x120030114] lda gp, -16192(gp) [__open, 0x120030118] ldq r28, -26736(gp) [__open, 0x12003011c] bsr r31, _cerror [__open, 0x120030120] ret r31, (r26), 1 This code is created from the SYSCALL macro in /usr/include/alpha/asm.s. All it does is load the system call number (see /usr/include/syscall.h) in R0 and traps to the kernel. When you called open(), the arguments were loaded in R16, R17, and R18. The PAL code callsys instruction switches to the kernel stack and jumps to the system call handler (see the Alpha Architecture manual). That saves R16-R19 in a local vector and dispatches to a kernel routine named "open" (oddly enough). Each system call generally casts the argument vector to a structure specific for the system call. Routines, (like open), which take arguments that point in user's memory access that memory through special bcopy-like routines that catch bogus addresses and return EFAULT. When the system call exits, R19 is zero on success. On error, the error code is in R0 and cerror() stores it in errno. This is typically how all Unixes handle system calls, Linux might be a little different since it isn't derived from the classic sources. Note - if think you need to know these details to write user level code, you don't. Even libc and kernel programmers rarely look at these code paths. -- <> Eric (Ric) Werme <> DEC's back! (As an officially approved <> <> <> nickname, we're really still DIGITAL.) <>