Deleted Added
full compact
trap.c (306738) trap.c (329114)
1/*-
2 * Copyright (c) 2016 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Konstantin Belousov under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2016 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Konstantin Belousov under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/11/sys/boot/efi/loader/arch/amd64/trap.c 306738 2016-10-05 22:04:22Z kib $");
31__FBSDID("$FreeBSD: stable/11/sys/boot/efi/loader/arch/amd64/trap.c 329114 2018-02-11 02:27:50Z kevans $");
32
33#include <stand.h>
34#include <string.h>
35#include <sys/param.h>
36#include <machine/cpufunc.h>
37#include <machine/psl.h>
38#include <machine/segments.h>
39#include <machine/frame.h>

--- 39 unchanged lines hidden (view full) ---

79static struct region_descriptor fw_gdt; /* Descriptor of pristine GDT */
80static EFI_PHYSICAL_ADDRESS loader_gdt_pa; /* Address of loader shadow GDT */
81
82void report_exc(struct trapframe *tf);
83void
84report_exc(struct trapframe *tf)
85{
86
32
33#include <stand.h>
34#include <string.h>
35#include <sys/param.h>
36#include <machine/cpufunc.h>
37#include <machine/psl.h>
38#include <machine/segments.h>
39#include <machine/frame.h>

--- 39 unchanged lines hidden (view full) ---

79static struct region_descriptor fw_gdt; /* Descriptor of pristine GDT */
80static EFI_PHYSICAL_ADDRESS loader_gdt_pa; /* Address of loader shadow GDT */
81
82void report_exc(struct trapframe *tf);
83void
84report_exc(struct trapframe *tf)
85{
86
87 /* XXX using printf */
87 /*
88 * printf() depends on loader runtime and UEFI firmware health
89 * to produce the console output, in case of exception, the
90 * loader or firmware runtime may fail to support the printf().
91 */
88 printf("===================================================="
89 "============================\n");
90 printf("Exception %u\n", tf->tf_trapno);
91 printf("ss 0x%04hx cs 0x%04hx ds 0x%04hx es 0x%04hx fs 0x%04hx "
92 "gs 0x%04hx\n",
93 (uint16_t)tf->tf_ss, (uint16_t)tf->tf_cs, (uint16_t)tf->tf_ds,
94 (uint16_t)tf->tf_es, (uint16_t)tf->tf_fs, (uint16_t)tf->tf_gs);
95 printf("err 0x%08x rfl 0x%08x addr 0x%016lx\n"

--- 21 unchanged lines hidden (view full) ---

117 fw_idt_e = &((struct gate_descriptor *)fw_idt.rd_base)[idx];
118 loader_idt_e = &((struct gate_descriptor *)loader_idt.rd_base)[idx];
119 fw_intr_handlers[idx] = fw_idt_e->gd_looffset +
120 (fw_idt_e->gd_hioffset << 16);
121 intercepted[idx] = 1;
122 ist_use_table[fw_idt_e->gd_ist]++;
123 loader_idt_e->gd_looffset = my_handler;
124 loader_idt_e->gd_hioffset = my_handler >> 16;
92 printf("===================================================="
93 "============================\n");
94 printf("Exception %u\n", tf->tf_trapno);
95 printf("ss 0x%04hx cs 0x%04hx ds 0x%04hx es 0x%04hx fs 0x%04hx "
96 "gs 0x%04hx\n",
97 (uint16_t)tf->tf_ss, (uint16_t)tf->tf_cs, (uint16_t)tf->tf_ds,
98 (uint16_t)tf->tf_es, (uint16_t)tf->tf_fs, (uint16_t)tf->tf_gs);
99 printf("err 0x%08x rfl 0x%08x addr 0x%016lx\n"

--- 21 unchanged lines hidden (view full) ---

121 fw_idt_e = &((struct gate_descriptor *)fw_idt.rd_base)[idx];
122 loader_idt_e = &((struct gate_descriptor *)loader_idt.rd_base)[idx];
123 fw_intr_handlers[idx] = fw_idt_e->gd_looffset +
124 (fw_idt_e->gd_hioffset << 16);
125 intercepted[idx] = 1;
126 ist_use_table[fw_idt_e->gd_ist]++;
127 loader_idt_e->gd_looffset = my_handler;
128 loader_idt_e->gd_hioffset = my_handler >> 16;
125 loader_idt_e->gd_selector = fw_idt_e->gd_selector; /* XXX */
129 /*
130 * We reuse uefi selector for the code segment for the exception
131 * handler code, while the reason for the fault might be the
132 * corruption of that gdt entry. On the other hand, allocating
133 * our own descriptor might be not much better, if gdt is corrupted.
134 */
135 loader_idt_e->gd_selector = fw_idt_e->gd_selector;
126 loader_idt_e->gd_ist = 0;
127 loader_idt_e->gd_type = SDT_SYSIGT;
128 loader_idt_e->gd_dpl = 0;
129 loader_idt_e->gd_p = 1;
130 loader_idt_e->gd_xx = 0;
131 loader_idt_e->sd_xx1 = 0;
132}
133#define PREPARE_EXCEPTION(N) \

--- 265 unchanged lines hidden ---
136 loader_idt_e->gd_ist = 0;
137 loader_idt_e->gd_type = SDT_SYSIGT;
138 loader_idt_e->gd_dpl = 0;
139 loader_idt_e->gd_p = 1;
140 loader_idt_e->gd_xx = 0;
141 loader_idt_e->sd_xx1 = 0;
142}
143#define PREPARE_EXCEPTION(N) \

--- 265 unchanged lines hidden ---