Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * TCG Backend Data: load-store optimization only. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | * THE SOFTWARE. |
| 21 | */ |
| 22 | |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 23 | typedef struct TCGLabelQemuLdst { |
Richard Henderson | 9c53889 | 2014-09-02 13:59:47 -0700 | [diff] [blame] | 24 | bool is_ld; /* qemu_ld: true, qemu_st: false */ |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 25 | TCGMemOpIdx oi; |
Richard Henderson | 9c53889 | 2014-09-02 13:59:47 -0700 | [diff] [blame] | 26 | TCGType type; /* result type of a load */ |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 27 | TCGReg addrlo_reg; /* reg index for low word of guest virtual addr */ |
| 28 | TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */ |
| 29 | TCGReg datalo_reg; /* reg index for low word to be loaded or stored */ |
| 30 | TCGReg datahi_reg; /* reg index for high word to be loaded or stored */ |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 31 | tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */ |
| 32 | tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */ |
Laurent Vivier | 6001f77 | 2018-04-30 01:58:40 +0200 | [diff] [blame] | 33 | QSIMPLEQ_ENTRY(TCGLabelQemuLdst) next; |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 34 | } TCGLabelQemuLdst; |
| 35 | |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Generate TB finalization at the end of block |
| 39 | */ |
| 40 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 41 | static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l); |
| 42 | static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l); |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 43 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 44 | static int tcg_out_ldst_finalize(TCGContext *s) |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 45 | { |
Richard Henderson | 686461c | 2014-09-30 07:18:06 -0700 | [diff] [blame] | 46 | TCGLabelQemuLdst *lb; |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 47 | |
| 48 | /* qemu_ld/st slow paths */ |
Laurent Vivier | 6001f77 | 2018-04-30 01:58:40 +0200 | [diff] [blame] | 49 | QSIMPLEQ_FOREACH(lb, &s->ldst_labels, next) { |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 50 | if (lb->is_ld |
| 51 | ? !tcg_out_qemu_ld_slow_path(s, lb) |
| 52 | : !tcg_out_qemu_st_slow_path(s, lb)) { |
| 53 | return -2; |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 54 | } |
Richard Henderson | 23dceda | 2015-12-02 13:59:59 -0800 | [diff] [blame] | 55 | |
| 56 | /* Test for (pending) buffer overflow. The assumption is that any |
| 57 | one operation beginning below the high water mark cannot overrun |
| 58 | the buffer completely. Thus we can test for overflow after |
| 59 | generating code without having to check during generation. */ |
| 60 | if (unlikely((void *)s->code_ptr > s->code_gen_highwater)) { |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 61 | return -1; |
Richard Henderson | 23dceda | 2015-12-02 13:59:59 -0800 | [diff] [blame] | 62 | } |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 63 | } |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 64 | return 0; |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Allocate a new TCGLabelQemuLdst entry. |
| 69 | */ |
| 70 | |
| 71 | static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s) |
| 72 | { |
Richard Henderson | 686461c | 2014-09-30 07:18:06 -0700 | [diff] [blame] | 73 | TCGLabelQemuLdst *l = tcg_malloc(sizeof(*l)); |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 74 | |
Laurent Vivier | 6001f77 | 2018-04-30 01:58:40 +0200 | [diff] [blame] | 75 | QSIMPLEQ_INSERT_TAIL(&s->ldst_labels, l, next); |
| 76 | |
Richard Henderson | 686461c | 2014-09-30 07:18:06 -0700 | [diff] [blame] | 77 | return l; |
Richard Henderson | 9ecefc8 | 2013-10-03 14:51:24 -0500 | [diff] [blame] | 78 | } |