1a7e926abSLuca Barbieri/* 2a7e926abSLuca Barbieri * atomic64_t for 386/486 3a7e926abSLuca Barbieri * 4a7e926abSLuca Barbieri * Copyright © 2010 Luca Barbieri 5a7e926abSLuca Barbieri * 6a7e926abSLuca Barbieri * This program is free software; you can redistribute it and/or modify 7a7e926abSLuca Barbieri * it under the terms of the GNU General Public License as published by 8a7e926abSLuca Barbieri * the Free Software Foundation; either version 2 of the License, or 9a7e926abSLuca Barbieri * (at your option) any later version. 10a7e926abSLuca Barbieri */ 11a7e926abSLuca Barbieri 12a7e926abSLuca Barbieri#include <linux/linkage.h> 13a7e926abSLuca Barbieri#include <asm/alternative-asm.h> 14a7e926abSLuca Barbieri#include <asm/dwarf2.h> 15a7e926abSLuca Barbieri 16a7e926abSLuca Barbieri/* if you want SMP support, implement these with real spinlocks */ 17a7e926abSLuca Barbieri.macro LOCK reg 18a7e926abSLuca Barbieri pushfl 19a7e926abSLuca Barbieri CFI_ADJUST_CFA_OFFSET 4 20a7e926abSLuca Barbieri cli 21a7e926abSLuca Barbieri.endm 22a7e926abSLuca Barbieri 23a7e926abSLuca Barbieri.macro UNLOCK reg 24a7e926abSLuca Barbieri popfl 25a7e926abSLuca Barbieri CFI_ADJUST_CFA_OFFSET -4 26a7e926abSLuca Barbieri.endm 27a7e926abSLuca Barbieri 2830246557SLuca Barbieri#define BEGIN(op) \ 29*417484d4SLuca Barbieri.macro endp; \ 3030246557SLuca Barbieri CFI_ENDPROC; \ 3130246557SLuca BarbieriENDPROC(atomic64_##op##_386); \ 32*417484d4SLuca Barbieri.purgem endp; \ 3330246557SLuca Barbieri.endm; \ 3430246557SLuca BarbieriENTRY(atomic64_##op##_386); \ 3530246557SLuca Barbieri CFI_STARTPROC; \ 3630246557SLuca Barbieri LOCK v; 37a7e926abSLuca Barbieri 38*417484d4SLuca Barbieri#define ENDP endp 39*417484d4SLuca Barbieri 4030246557SLuca Barbieri#define RET \ 4130246557SLuca Barbieri UNLOCK v; \ 42a7e926abSLuca Barbieri ret 43a7e926abSLuca Barbieri 44*417484d4SLuca Barbieri#define RET_ENDP \ 4530246557SLuca Barbieri RET; \ 46*417484d4SLuca Barbieri ENDP 47a7e926abSLuca Barbieri 4830246557SLuca Barbieri#define v %ecx 4930246557SLuca BarbieriBEGIN(read) 5030246557SLuca Barbieri movl (v), %eax 5130246557SLuca Barbieri movl 4(v), %edx 52*417484d4SLuca BarbieriRET_ENDP 5330246557SLuca Barbieri#undef v 54a7e926abSLuca Barbieri 5530246557SLuca Barbieri#define v %esi 5630246557SLuca BarbieriBEGIN(set) 5730246557SLuca Barbieri movl %ebx, (v) 5830246557SLuca Barbieri movl %ecx, 4(v) 59*417484d4SLuca BarbieriRET_ENDP 6030246557SLuca Barbieri#undef v 61a7e926abSLuca Barbieri 6230246557SLuca Barbieri#define v %esi 6330246557SLuca BarbieriBEGIN(xchg) 6430246557SLuca Barbieri movl (v), %eax 6530246557SLuca Barbieri movl 4(v), %edx 6630246557SLuca Barbieri movl %ebx, (v) 6730246557SLuca Barbieri movl %ecx, 4(v) 68*417484d4SLuca BarbieriRET_ENDP 6930246557SLuca Barbieri#undef v 70a7e926abSLuca Barbieri 7130246557SLuca Barbieri#define v %ecx 7230246557SLuca BarbieriBEGIN(add) 7330246557SLuca Barbieri addl %eax, (v) 7430246557SLuca Barbieri adcl %edx, 4(v) 75*417484d4SLuca BarbieriRET_ENDP 7630246557SLuca Barbieri#undef v 77a7e926abSLuca Barbieri 7830246557SLuca Barbieri#define v %ecx 7930246557SLuca BarbieriBEGIN(add_return) 8030246557SLuca Barbieri addl (v), %eax 8130246557SLuca Barbieri adcl 4(v), %edx 8230246557SLuca Barbieri movl %eax, (v) 8330246557SLuca Barbieri movl %edx, 4(v) 84*417484d4SLuca BarbieriRET_ENDP 8530246557SLuca Barbieri#undef v 86a7e926abSLuca Barbieri 8730246557SLuca Barbieri#define v %ecx 8830246557SLuca BarbieriBEGIN(sub) 8930246557SLuca Barbieri subl %eax, (v) 9030246557SLuca Barbieri sbbl %edx, 4(v) 91*417484d4SLuca BarbieriRET_ENDP 9230246557SLuca Barbieri#undef v 9330246557SLuca Barbieri 9430246557SLuca Barbieri#define v %ecx 9530246557SLuca BarbieriBEGIN(sub_return) 96a7e926abSLuca Barbieri negl %edx 97a7e926abSLuca Barbieri negl %eax 98a7e926abSLuca Barbieri sbbl $0, %edx 9930246557SLuca Barbieri addl (v), %eax 10030246557SLuca Barbieri adcl 4(v), %edx 10130246557SLuca Barbieri movl %eax, (v) 10230246557SLuca Barbieri movl %edx, 4(v) 103*417484d4SLuca BarbieriRET_ENDP 10430246557SLuca Barbieri#undef v 105a7e926abSLuca Barbieri 10630246557SLuca Barbieri#define v %esi 10730246557SLuca BarbieriBEGIN(inc) 10830246557SLuca Barbieri addl $1, (v) 10930246557SLuca Barbieri adcl $0, 4(v) 110*417484d4SLuca BarbieriRET_ENDP 11130246557SLuca Barbieri#undef v 112a7e926abSLuca Barbieri 11330246557SLuca Barbieri#define v %esi 11430246557SLuca BarbieriBEGIN(inc_return) 11530246557SLuca Barbieri movl (v), %eax 11630246557SLuca Barbieri movl 4(v), %edx 117a7e926abSLuca Barbieri addl $1, %eax 118a7e926abSLuca Barbieri adcl $0, %edx 11930246557SLuca Barbieri movl %eax, (v) 12030246557SLuca Barbieri movl %edx, 4(v) 121*417484d4SLuca BarbieriRET_ENDP 12230246557SLuca Barbieri#undef v 123a7e926abSLuca Barbieri 12430246557SLuca Barbieri#define v %esi 12530246557SLuca BarbieriBEGIN(dec) 12630246557SLuca Barbieri subl $1, (v) 12730246557SLuca Barbieri sbbl $0, 4(v) 128*417484d4SLuca BarbieriRET_ENDP 12930246557SLuca Barbieri#undef v 130a7e926abSLuca Barbieri 13130246557SLuca Barbieri#define v %esi 13230246557SLuca BarbieriBEGIN(dec_return) 13330246557SLuca Barbieri movl (v), %eax 13430246557SLuca Barbieri movl 4(v), %edx 135a7e926abSLuca Barbieri subl $1, %eax 136a7e926abSLuca Barbieri sbbl $0, %edx 13730246557SLuca Barbieri movl %eax, (v) 13830246557SLuca Barbieri movl %edx, 4(v) 139*417484d4SLuca BarbieriRET_ENDP 14030246557SLuca Barbieri#undef v 141a7e926abSLuca Barbieri 14230246557SLuca Barbieri#define v %ecx 14330246557SLuca BarbieriBEGIN(add_unless) 144a7e926abSLuca Barbieri addl %eax, %esi 145a7e926abSLuca Barbieri adcl %edx, %edi 14630246557SLuca Barbieri addl (v), %eax 14730246557SLuca Barbieri adcl 4(v), %edx 148a7e926abSLuca Barbieri cmpl %eax, %esi 149a7e926abSLuca Barbieri je 3f 150a7e926abSLuca Barbieri1: 15130246557SLuca Barbieri movl %eax, (v) 15230246557SLuca Barbieri movl %edx, 4(v) 1536e6104feSLuca Barbieri movl $1, %eax 154a7e926abSLuca Barbieri2: 15530246557SLuca Barbieri RET 156a7e926abSLuca Barbieri3: 157a7e926abSLuca Barbieri cmpl %edx, %edi 158a7e926abSLuca Barbieri jne 1b 1596e6104feSLuca Barbieri xorl %eax, %eax 160a7e926abSLuca Barbieri jmp 2b 161*417484d4SLuca BarbieriENDP 16230246557SLuca Barbieri#undef v 163a7e926abSLuca Barbieri 16430246557SLuca Barbieri#define v %esi 16530246557SLuca BarbieriBEGIN(inc_not_zero) 16630246557SLuca Barbieri movl (v), %eax 16730246557SLuca Barbieri movl 4(v), %edx 168a7e926abSLuca Barbieri testl %eax, %eax 169a7e926abSLuca Barbieri je 3f 170a7e926abSLuca Barbieri1: 171a7e926abSLuca Barbieri addl $1, %eax 172a7e926abSLuca Barbieri adcl $0, %edx 17330246557SLuca Barbieri movl %eax, (v) 17430246557SLuca Barbieri movl %edx, 4(v) 175f3e83131SLuca Barbieri movl $1, %eax 176a7e926abSLuca Barbieri2: 17730246557SLuca Barbieri RET 178a7e926abSLuca Barbieri3: 179a7e926abSLuca Barbieri testl %edx, %edx 180a7e926abSLuca Barbieri jne 1b 181a7e926abSLuca Barbieri jmp 2b 182*417484d4SLuca BarbieriENDP 18330246557SLuca Barbieri#undef v 184a7e926abSLuca Barbieri 18530246557SLuca Barbieri#define v %esi 18630246557SLuca BarbieriBEGIN(dec_if_positive) 18730246557SLuca Barbieri movl (v), %eax 18830246557SLuca Barbieri movl 4(v), %edx 189a7e926abSLuca Barbieri subl $1, %eax 190a7e926abSLuca Barbieri sbbl $0, %edx 191a7e926abSLuca Barbieri js 1f 19230246557SLuca Barbieri movl %eax, (v) 19330246557SLuca Barbieri movl %edx, 4(v) 194a7e926abSLuca Barbieri1: 195*417484d4SLuca BarbieriRET_ENDP 19630246557SLuca Barbieri#undef v 197