1 // Code for handling calls to "post" that are resume related.
3 // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "bregs.h" // struct bregs
8 #include "config.h" // CONFIG_*
9 #include "farptr.h" // FLATPTR_TO_SEGOFF
10 #include "hw/pci.h" // pci_reboot
11 #include "hw/pic.h" // pic_eoi2
12 #include "hw/ps2port.h" // i8042_reboot
13 #include "hw/rtc.h" // rtc_read
14 #include "output.h" // dprintf
15 #include "stacks.h" // farcall16big
16 #include "std/bda.h" // struct bios_data_area_s
17 #include "string.h" // memset
18 #include "util.h" // dma_setup
20 // Handler for post calls that look like a resume.
25 int status = rtc_read(CMOS_RESET_CODE);
26 rtc_write(CMOS_RESET_CODE, 0);
27 dprintf(1, "In resume (status=%d)\n", status);
34 panic("Unimplemented shutdown status: %02x\n", status);
37 // flush keyboard (issue EOI) and jump via 40h:0067h
41 #define BDA_JUMP (((struct bios_data_area_s *)0)->jump)
42 // resume execution by jump via 40h:0067h
46 : : "m"(BDA_JUMP), "r"(SEG_BDA)
51 // resume execution via IRET via 40h:0067h
56 : : "m"(BDA_JUMP), "r"(SEG_BDA)
61 // resume execution via RETF via 40h:0067h
66 : : "m"(BDA_JUMP), "r"(SEG_BDA)
74 // Not a 16bit resume - do remaining checks in 32bit mode
78 "movl $_cfunc32flat_handle_resume32, %%edx\n"
80 : : "i"(BUILD_S3RESUME_STACK_ADDR), "r"(0), "a"(status)
84 // Handle an S3 resume event
88 if (!CONFIG_S3_RESUME)
91 u32 s3_resume_vector = find_resume_vector();
92 if (!s3_resume_vector) {
93 dprintf(1, "No resume vector set!\n");
104 make_bios_readonly();
106 // Invoke the resume vector.
108 memset(&br, 0, sizeof(br));
109 dprintf(1, "Jump to resume vector (%x)\n", s3_resume_vector);
110 br.code = FLATPTR_TO_SEGOFF((void*)s3_resume_vector);
114 u8 HaveAttemptedReboot VARLOW;
116 // Attempt to invoke a hard-reboot.
120 if (HaveAttemptedReboot) {
121 // Hard reboot has failed - try to shutdown machine.
122 dprintf(1, "Unable to hard-reboot machine - attempting shutdown.\n");
125 HaveAttemptedReboot = 1;
127 dprintf(1, "Attempting a hard reboot\n");
129 // Setup for reset on qemu.
132 // Reboot using ACPI RESET_REG
135 // Try keyboard controller reboot.
138 // Try PCI 0xcf9 reboot
142 asm volatile("int3");
144 panic("Could not reboot");
148 handle_resume32(int status)
151 dprintf(1, "In 32bit resume\n");
156 // Must be a soft reboot - invoke a hard reboot.