This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] X86_64-elf port (part 3)


Index: newlib/libc/machine/x86_64/setjmp.S
===================================================================
/*
 * Based on the i386 setjump.S by DJ Delorie
 *
 * Copyright (C) 2007 Hans Kester
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms is permitted
 * provided that the above copyright notice and following paragraph are
 * duplicated in all such forms.
 *
 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

 /*
 **  jmp_buf:
 **   rax rbx rcx rdx rsi rdi rbp rsp rip
 **   0   8   16  24  32  40  48  56  64
 */

      #include "x86_64mach.h"

      .global SYM (setjmp)
      .global SYM (longjmp)
      SOTYPE_FUNCTION(setjmp)
      SOTYPE_FUNCTION(longjmp)

SYM (setjmp):

 pushq   rbp
 movq    rsp, rbp

 pushq   rdi
 movq    16 (rbp),rdi

 movq    rax,  0 (rdi)
 movq    rbx,  8 (rdi)
 movq    rcx, 16 (rdi)
 movq    rdx, 24 (rdi)
 movq    rsi, 32 (rdi)

 movq    -8 (rbp), rax
 movq    rax, 40 (rdi)

 movq    0 (rbp), rax
 movq    rax, 48 (rdi)

 movq    rsp, rax
 addq    $24, rax
 movq    rax, 56 (rdi)

 movq    8 (rbp), rax
 movq    rax, 64 (rdi)

 popq    rdi
 movq    $0, rax
 leave
 ret

SYM (longjmp):
 pushq   rbp
 movq    rsp, rbp

 movq    16(rbp), rdi  /* get jmp_buf */
 movq    24(rbp), rax  /* store retval in j->rax */
 movq    rax, 0(rdi)

 movq    48(rdi), rbp

      __CLI
 movq    56(rdi), rsp

 pushq   64(rdi)

 movq     0(rdi), rax
 movq     8(rdi), rbx
 movq    16(rdi), rcx
 movq    24(rdi), rdx
 movq    32(rdi), rsi
 movq    40(rdi), rdi
      __STI

 ret



Index: newlib/libc/machine/x86_64/x86_64mach.h
===================================================================
/*
 ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
 ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifndef __USER_LABEL_PREFIX__
#define __USER_LABEL_PREFIX__ _
#endif

#define __REG_PREFIX__ %

/* ANSI concatenation macros.  */

#define CONCAT1(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a##b

/* Use the right prefix for global labels.  */

#define SYM(x) CONCAT1(__USER_LABEL_PREFIX__, x)

/* Use the right prefix for registers.  */

#define REG(x) CONCAT1(__REG_PREFIX__, x)

#define rax REG(rax)
#define rbx REG(rbx)
#define rcx REG(rcx)
#define rdx REG(rdx)
#define rsi REG(rsi)
#define rdi REG(rdi)
#define rbp REG(rbp)
#define rsp REG(rsp)

#define eax REG(eax)
#define ebx REG(ebx)
#define ecx REG(ecx)
#define edx REG(edx)
#define esi REG(esi)
#define edi REG(edi)
#define ebp REG(ebp)
#define esp REG(esp)

#define st0 REG(st)
#define st1 REG(st(1))
#define st2 REG(st(2))
#define st3 REG(st(3))
#define st4 REG(st(4))
#define st5 REG(st(5))
#define st6 REG(st(6))
#define st7 REG(st(7))

#define ax REG(ax)
#define bx REG(bx)
#define cx REG(cx)
#define dx REG(dx)

#define ah REG(ah)
#define bh REG(bh)
#define ch REG(ch)
#define dh REG(dh)

#define al REG(al)
#define bl REG(bl)
#define cl REG(cl)
#define dl REG(dl)

#define mm1 REG(mm1)
#define mm2 REG(mm2)
#define mm3 REG(mm3)
#define mm4 REG(mm4)
#define mm5 REG(mm5)
#define mm6 REG(mm6)
#define mm7 REG(mm7)

#ifdef _I386MACH_NEED_SOTYPE_FUNCTION
#define SOTYPE_FUNCTION(sym) .type SYM(sym),@function
#else
#define SOTYPE_FUNCTION(sym)
#endif

#ifdef _I386MACH_ALLOW_HW_INTERRUPTS
#define        __CLI
#define        __STI
#else
#define __CLI  cli
#define __STI  sti
#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]