diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/runtime/linux/386 | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-upstream/2011.01.12.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/runtime/linux/386')
-rw-r--r-- | src/pkg/runtime/linux/386/defs.h | 1 | ||||
-rw-r--r-- | src/pkg/runtime/linux/386/rt0.s | 10 | ||||
-rw-r--r-- | src/pkg/runtime/linux/386/signal.c | 108 | ||||
-rw-r--r-- | src/pkg/runtime/linux/386/sys.s | 55 |
4 files changed, 98 insertions, 76 deletions
diff --git a/src/pkg/runtime/linux/386/defs.h b/src/pkg/runtime/linux/386/defs.h index ef8ef05d0..c1f58b2a0 100644 --- a/src/pkg/runtime/linux/386/defs.h +++ b/src/pkg/runtime/linux/386/defs.h @@ -10,6 +10,7 @@ enum { PROT_EXEC = 0x4, MAP_ANON = 0x20, MAP_PRIVATE = 0x2, + MAP_FIXED = 0x10, SA_RESTART = 0x10000000, SA_ONSTACK = 0x8000000, SA_RESTORER = 0x4000000, diff --git a/src/pkg/runtime/linux/386/rt0.s b/src/pkg/runtime/linux/386/rt0.s index 4d2345d8c..0f82d6a1c 100644 --- a/src/pkg/runtime/linux/386/rt0.s +++ b/src/pkg/runtime/linux/386/rt0.s @@ -4,6 +4,14 @@ // Darwin and Linux use the same linkage to main -TEXT _rt0_386_linux(SB),7,$0 +TEXT _rt0_386_linux(SB),7,$0 + // Linux starts the FPU in extended double precision. + // Other operating systems use double precision. + // Change to double precision to match them, + // and to match other hardware that only has double. + PUSHL $0x27F + FLDCW 0(SP) + POPL AX + JMP _rt0_386(SB) diff --git a/src/pkg/runtime/linux/386/signal.c b/src/pkg/runtime/linux/386/signal.c index 6bc95d0d7..0dbfcf9ff 100644 --- a/src/pkg/runtime/linux/386/signal.c +++ b/src/pkg/runtime/linux/386/signal.c @@ -8,41 +8,41 @@ #include "os.h" void -dumpregs(Sigcontext *r) +runtime·dumpregs(Sigcontext *r) { - printf("eax %x\n", r->eax); - printf("ebx %x\n", r->ebx); - printf("ecx %x\n", r->ecx); - printf("edx %x\n", r->edx); - printf("edi %x\n", r->edi); - printf("esi %x\n", r->esi); - printf("ebp %x\n", r->ebp); - printf("esp %x\n", r->esp); - printf("eip %x\n", r->eip); - printf("eflags %x\n", r->eflags); - printf("cs %x\n", r->cs); - printf("fs %x\n", r->fs); - printf("gs %x\n", r->gs); + runtime·printf("eax %x\n", r->eax); + runtime·printf("ebx %x\n", r->ebx); + runtime·printf("ecx %x\n", r->ecx); + runtime·printf("edx %x\n", r->edx); + runtime·printf("edi %x\n", r->edi); + runtime·printf("esi %x\n", r->esi); + runtime·printf("ebp %x\n", r->ebp); + runtime·printf("esp %x\n", r->esp); + runtime·printf("eip %x\n", r->eip); + runtime·printf("eflags %x\n", r->eflags); + runtime·printf("cs %x\n", r->cs); + runtime·printf("fs %x\n", r->fs); + runtime·printf("gs %x\n", r->gs); } /* * This assembler routine takes the args from registers, puts them on the stack, * and calls sighandler(). */ -extern void sigtramp(void); -extern void sigignore(void); // just returns -extern void sigreturn(void); // calls sigreturn +extern void runtime·sigtramp(void); +extern void runtime·sigignore(void); // just returns +extern void runtime·sigreturn(void); // calls runtime·sigreturn String -signame(int32 sig) +runtime·signame(int32 sig) { if(sig < 0 || sig >= NSIG) - return emptystring; - return gostringnocopy((byte*)sigtab[sig].name); + return runtime·emptystring; + return runtime·gostringnocopy((byte*)runtime·sigtab[sig].name); } void -sighandler(int32 sig, Siginfo* info, void* context) +runtime·sighandler(int32 sig, Siginfo* info, void* context) { Ucontext *uc; Sigcontext *r; @@ -52,7 +52,7 @@ sighandler(int32 sig, Siginfo* info, void* context) uc = context; r = &uc->uc_mcontext; - if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { + if((gp = m->curg) != nil && (runtime·sigtab[sig].flags & SigPanic)) { // Make it look like a call to the signal func. // Have to pass arguments out of band since // augmenting the stack frame would break @@ -61,84 +61,84 @@ sighandler(int32 sig, Siginfo* info, void* context) gp->sigcode0 = info->si_code; gp->sigcode1 = ((uintptr*)info)[3]; - // Only push sigpanic if r->eip != 0. + // Only push runtime·sigpanic if r->eip != 0. // If r->eip == 0, probably panicked because of a // call to a nil func. Not pushing that onto sp will - // make the trace look like a call to sigpanic instead. - // (Otherwise the trace will end at sigpanic and we + // make the trace look like a call to runtime·sigpanic instead. + // (Otherwise the trace will end at runtime·sigpanic and we // won't get to see who faulted.) if(r->eip != 0) { sp = (uintptr*)r->esp; *--sp = r->eip; r->esp = (uintptr)sp; } - r->eip = (uintptr)sigpanic; + r->eip = (uintptr)runtime·sigpanic; return; } - if(sigtab[sig].flags & SigQueue) { - if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) + if(runtime·sigtab[sig].flags & SigQueue) { + if(runtime·sigsend(sig) || (runtime·sigtab[sig].flags & SigIgnore)) return; - exit(2); // SIGINT, SIGTERM, etc + runtime·exit(2); // SIGINT, SIGTERM, etc } - if(panicking) // traceback already printed - exit(2); - panicking = 1; + if(runtime·panicking) // traceback already printed + runtime·exit(2); + runtime·panicking = 1; if(sig < 0 || sig >= NSIG) - printf("Signal %d\n", sig); + runtime·printf("Signal %d\n", sig); else - printf("%s\n", sigtab[sig].name); + runtime·printf("%s\n", runtime·sigtab[sig].name); - printf("PC=%X\n", r->eip); - printf("\n"); + runtime·printf("PC=%X\n", r->eip); + runtime·printf("\n"); - if(gotraceback()){ - traceback((void*)r->eip, (void*)r->esp, 0, m->curg); - tracebackothers(m->curg); - dumpregs(r); + if(runtime·gotraceback()){ + runtime·traceback((void*)r->eip, (void*)r->esp, 0, m->curg); + runtime·tracebackothers(m->curg); + runtime·dumpregs(r); } - breakpoint(); - exit(2); + runtime·breakpoint(); + runtime·exit(2); } void -signalstack(byte *p, int32 n) +runtime·signalstack(byte *p, int32 n) { Sigaltstack st; st.ss_sp = p; st.ss_size = n; st.ss_flags = 0; - sigaltstack(&st, nil); + runtime·sigaltstack(&st, nil); } void -initsig(int32 queue) +runtime·initsig(int32 queue) { static Sigaction sa; - siginit(); + runtime·siginit(); int32 i; sa.sa_flags = SA_ONSTACK | SA_SIGINFO | SA_RESTORER; sa.sa_mask = 0xFFFFFFFFFFFFFFFFULL; - sa.sa_restorer = (void*)sigreturn; + sa.sa_restorer = (void*)runtime·sigreturn; for(i = 0; i<NSIG; i++) { - if(sigtab[i].flags) { - if((sigtab[i].flags & SigQueue) != queue) + if(runtime·sigtab[i].flags) { + if((runtime·sigtab[i].flags & SigQueue) != queue) continue; - if(sigtab[i].flags & (SigCatch | SigQueue)) - sa.k_sa_handler = (void*)sigtramp; + if(runtime·sigtab[i].flags & (SigCatch | SigQueue)) + sa.k_sa_handler = (void*)runtime·sigtramp; else - sa.k_sa_handler = (void*)sigignore; - if(sigtab[i].flags & SigRestart) + sa.k_sa_handler = (void*)runtime·sigignore; + if(runtime·sigtab[i].flags & SigRestart) sa.sa_flags |= SA_RESTART; else sa.sa_flags &= ~SA_RESTART; - rt_sigaction(i, &sa, nil, 8); + runtime·rt_sigaction(i, &sa, nil, 8); } } } diff --git a/src/pkg/runtime/linux/386/sys.s b/src/pkg/runtime/linux/386/sys.s index 57ffc4aa4..a1505b0b0 100644 --- a/src/pkg/runtime/linux/386/sys.s +++ b/src/pkg/runtime/linux/386/sys.s @@ -8,21 +8,21 @@ #include "386/asm.h" -TEXT exit(SB),7,$0 +TEXT runtime·exit(SB),7,$0 MOVL $252, AX // syscall number MOVL 4(SP), BX INT $0x80 INT $3 // not reached RET -TEXT exit1(SB),7,$0 +TEXT runtime·exit1(SB),7,$0 MOVL $1, AX // exit - exit the current os thread MOVL 4(SP), BX INT $0x80 INT $3 // not reached RET -TEXT write(SB),7,$0 +TEXT runtime·write(SB),7,$0 MOVL $4, AX // syscall - write MOVL 4(SP), BX MOVL 8(SP), CX @@ -30,7 +30,7 @@ TEXT write(SB),7,$0 INT $0x80 RET -TEXT gettime(SB), 7, $32 +TEXT runtime·gettime(SB), 7, $32 MOVL $78, AX // syscall - gettimeofday LEAL 8(SP), BX MOVL $0, CX @@ -47,7 +47,7 @@ TEXT gettime(SB), 7, $32 MOVL BX, (DI) RET -TEXT rt_sigaction(SB),7,$0 +TEXT runtime·rt_sigaction(SB),7,$0 MOVL $174, AX // syscall - rt_sigaction MOVL 4(SP), BX MOVL 8(SP), CX @@ -56,7 +56,7 @@ TEXT rt_sigaction(SB),7,$0 INT $0x80 RET -TEXT sigtramp(SB),7,$40 +TEXT runtime·sigtramp(SB),7,$40 get_tls(CX) // save g @@ -76,7 +76,7 @@ TEXT sigtramp(SB),7,$40 MOVL context+8(FP), BX MOVL BX, 8(SP) - CALL sighandler(SB) + CALL runtime·sighandler(SB) // restore g get_tls(CX) @@ -85,16 +85,16 @@ TEXT sigtramp(SB),7,$40 RET -TEXT sigignore(SB),7,$0 +TEXT runtime·sigignore(SB),7,$0 RET -TEXT sigreturn(SB),7,$0 +TEXT runtime·sigreturn(SB),7,$0 MOVL $173, AX // rt_sigreturn INT $0x80 INT $3 // not reached RET -TEXT ·mmap(SB),7,$0 +TEXT runtime·mmap(SB),7,$0 MOVL $192, AX // mmap2 MOVL 4(SP), BX MOVL 8(SP), CX @@ -110,9 +110,19 @@ TEXT ·mmap(SB),7,$0 INCL AX RET +TEXT runtime·munmap(SB),7,$0 + MOVL $91, AX // munmap + MOVL 4(SP), BX + MOVL 8(SP), CX + INT $0x80 + CMPL AX, $0xfffff001 + JLS 2(PC) + INT $3 + RET + // int32 futex(int32 *uaddr, int32 op, int32 val, // struct timespec *timeout, int32 *uaddr2, int32 val2); -TEXT futex(SB),7,$0 +TEXT runtime·futex(SB),7,$0 MOVL $240, AX // futex MOVL 4(SP), BX MOVL 8(SP), CX @@ -124,7 +134,7 @@ TEXT futex(SB),7,$0 RET // int32 clone(int32 flags, void *stack, M *m, G *g, void (*fn)(void)); -TEXT clone(SB),7,$0 +TEXT runtime·clone(SB),7,$0 MOVL $120, AX // clone MOVL flags+4(SP), BX MOVL stack+8(SP), CX @@ -161,12 +171,12 @@ TEXT clone(SB),7,$0 // In child on new stack. Reload registers (paranoia). MOVL 0(SP), BX // m MOVL 4(SP), DX // g - MOVL 8(SP), CX // fn + MOVL 8(SP), SI // fn MOVL AX, m_procid(BX) // save tid as m->procid // set up ldt 7+id to point at m->tls. - // m->tls is at m+40. newosproc left the id in tls[0]. + // newosproc left the id in tls[0]. LEAL m_tls(BX), BP MOVL 0(BP), DI ADDL $7, DI // m0 is LDT#7. count up. @@ -175,7 +185,7 @@ TEXT clone(SB),7,$0 PUSHL $32 // sizeof tls PUSHL BP // &tls PUSHL DI // tls # - CALL setldt(SB) + CALL runtime·setldt(SB) POPL AX POPL AX POPL AX @@ -186,21 +196,21 @@ TEXT clone(SB),7,$0 MOVL DX, g(AX) MOVL BX, m(AX) - CALL stackcheck(SB) // smashes AX + CALL runtime·stackcheck(SB) // smashes AX, CX MOVL 0(DX), DX // paranoia; check they are not nil MOVL 0(BX), BX // more paranoia; check that stack splitting code works PUSHAL - CALL emptyfunc(SB) + CALL runtime·emptyfunc(SB) POPAL - CALL CX // fn() - CALL exit1(SB) + CALL SI // fn() + CALL runtime·exit1(SB) MOVL $0x1234, 0x1005 RET -TEXT sigaltstack(SB),7,$-8 +TEXT runtime·sigaltstack(SB),7,$-8 MOVL $186, AX // sigaltstack MOVL new+4(SP), BX MOVL old+8(SP), CX @@ -233,7 +243,7 @@ TEXT sigaltstack(SB),7,$-8 #define USEABLE 0x40 // setldt(int entry, int address, int limit) -TEXT setldt(SB),7,$32 +TEXT runtime·setldt(SB),7,$32 MOVL entry+0(FP), BX // entry MOVL address+4(FP), CX // base address @@ -247,8 +257,11 @@ TEXT setldt(SB),7,$32 * To accommodate that rewrite, we translate * the address here and bump the limit to 0xffffffff (no limit) * so that -8(GS) maps to 0(address). + * Also, the final 0(GS) (current 8(CX)) has to point + * to itself, to mimic ELF. */ ADDL $0x8, CX // address + MOVL CX, 0(CX) // set up user_desc LEAL 16(SP), AX // struct user_desc |