From owner-freebsd-current Thu Dec 2 4: 5:19 1999 Delivered-To: freebsd-current@freebsd.org Received: from ns.demophon.com (ns.demophon.com [193.65.70.13]) by hub.freebsd.org (Postfix) with SMTP id 554B814F44 for ; Thu, 2 Dec 1999 04:05:15 -0800 (PST) (envelope-from will@ns.demophon.com) Received: (qmail 4621 invoked by uid 1003); 2 Dec 1999 12:02:12 -0000 Date: 2 Dec 1999 12:02:12 -0000 Message-ID: <19991202120212.4618.qmail@ns.demophon.com> From: Ville-Pertti Keinonen To: marcel@scc.nl Cc: current@freebsd.org, dillon@apollo.backplane.com, bde@zeta.org.au In-reply-to: <384657E7.B3E461D5@scc.nl> (message from Marcel Moolenaar on Thu, 02 Dec 1999 12:28:39 +0100) Subject: Re: kernel: -mpreferred-stack-boundary=2 ?? Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > AFAICT, it's enough to just align the stack before doing anything else. > In this case it means aligning the stack somewhere before > (exit(main(...)). gcc maintains proper alignment on an aligned stack. I wouldn't rely on that, gcc is free to assume that it can address local variables relative to the stack. In practice, it uses %ebp unless you use -fomit-frame-pointer, but I don't think that manipulating the stack pointer without gcc knowing about it is guaranteed to be safe (alloca is a special case, gcc detects that it is used internally). Future improvements in code generation would also be likely to break things. However, an easy alternative would be to make the _start entry point an assembly language stub that calls a C function: That would look something like this if done in crt1.c: asm(".text; .globl _start; _start:;" "lea 4(%esp),%eax;" "andl $~15,%esp;" "subl $4,%esp;" "pushl %eax;" "call c_start"); static void c_start(char **argv) { etc... This of course assumes that static symbols have naming conventions identical to global symbols. (It can easily be made more predictable by assigning the function a specific symbol) > Maybe alignment can even be done in the kernel... It gets messy, it has to be done before putting the env and argv pointers in place... On program entry, (%esp) is argc, %esp + 4 is the beginning of the argv array and env array is located immediately after the argv array. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message