blob: 17777aec5a6673d324fb46d63b8f1162f1219508 [file] [log] [blame]
Richard Henderson9ecefc82013-10-03 14:51:24 -05001/*
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
23#ifdef CONFIG_SOFTMMU
Richard Henderson9ecefc82013-10-03 14:51:24 -050024
25typedef struct TCGLabelQemuLdst {
Richard Henderson9c538892014-09-02 13:59:47 -070026 bool is_ld; /* qemu_ld: true, qemu_st: false */
Richard Henderson3972ef62015-05-13 09:10:33 -070027 TCGMemOpIdx oi;
Richard Henderson9c538892014-09-02 13:59:47 -070028 TCGType type; /* result type of a load */
Richard Henderson9ecefc82013-10-03 14:51:24 -050029 TCGReg addrlo_reg; /* reg index for low word of guest virtual addr */
30 TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */
31 TCGReg datalo_reg; /* reg index for low word to be loaded or stored */
32 TCGReg datahi_reg; /* reg index for high word to be loaded or stored */
Richard Henderson1813e172014-03-28 12:56:22 -070033 tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */
34 tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */
Richard Henderson686461c2014-09-30 07:18:06 -070035 struct TCGLabelQemuLdst *next;
Richard Henderson9ecefc82013-10-03 14:51:24 -050036} TCGLabelQemuLdst;
37
38typedef struct TCGBackendData {
Richard Henderson686461c2014-09-30 07:18:06 -070039 TCGLabelQemuLdst *labels;
Richard Henderson9ecefc82013-10-03 14:51:24 -050040} TCGBackendData;
41
42
43/*
44 * Initialize TB backend data at the beginning of the TB.
45 */
46
47static inline void tcg_out_tb_init(TCGContext *s)
48{
Richard Henderson686461c2014-09-30 07:18:06 -070049 s->be->labels = NULL;
Richard Henderson9ecefc82013-10-03 14:51:24 -050050}
51
52/*
53 * Generate TB finalization at the end of block
54 */
55
56static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l);
57static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l);
58
Richard Henderson23dceda2015-12-02 13:59:59 -080059static bool tcg_out_tb_finalize(TCGContext *s)
Richard Henderson9ecefc82013-10-03 14:51:24 -050060{
Richard Henderson686461c2014-09-30 07:18:06 -070061 TCGLabelQemuLdst *lb;
Richard Henderson9ecefc82013-10-03 14:51:24 -050062
63 /* qemu_ld/st slow paths */
Richard Henderson686461c2014-09-30 07:18:06 -070064 for (lb = s->be->labels; lb != NULL; lb = lb->next) {
65 if (lb->is_ld) {
66 tcg_out_qemu_ld_slow_path(s, lb);
Richard Henderson9ecefc82013-10-03 14:51:24 -050067 } else {
Richard Henderson686461c2014-09-30 07:18:06 -070068 tcg_out_qemu_st_slow_path(s, lb);
Richard Henderson9ecefc82013-10-03 14:51:24 -050069 }
Richard Henderson23dceda2015-12-02 13:59:59 -080070
71 /* Test for (pending) buffer overflow. The assumption is that any
72 one operation beginning below the high water mark cannot overrun
73 the buffer completely. Thus we can test for overflow after
74 generating code without having to check during generation. */
75 if (unlikely((void *)s->code_ptr > s->code_gen_highwater)) {
76 return false;
77 }
Richard Henderson9ecefc82013-10-03 14:51:24 -050078 }
Richard Henderson23dceda2015-12-02 13:59:59 -080079 return true;
Richard Henderson9ecefc82013-10-03 14:51:24 -050080}
81
82/*
83 * Allocate a new TCGLabelQemuLdst entry.
84 */
85
86static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s)
87{
88 TCGBackendData *be = s->be;
Richard Henderson686461c2014-09-30 07:18:06 -070089 TCGLabelQemuLdst *l = tcg_malloc(sizeof(*l));
Richard Henderson9ecefc82013-10-03 14:51:24 -050090
Richard Henderson686461c2014-09-30 07:18:06 -070091 l->next = be->labels;
92 be->labels = l;
93 return l;
Richard Henderson9ecefc82013-10-03 14:51:24 -050094}
95#else
96#include "tcg-be-null.h"
97#endif /* CONFIG_SOFTMMU */