Improve support for old 16bit resume handlers.
[seabios.git] / src / resume.c
1 // Code for handling calls to "post" that are resume related.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU GPLv3 license.
6
7 #include "util.h" // dprintf
8 #include "ioport.h" // outb
9 #include "pic.h" // eoi_pic2
10 #include "biosvar.h" // struct bios_data_area_s
11
12 // Reset DMA controller
13 void
14 init_dma()
15 {
16     // first reset the DMA controllers
17     outb(0, PORT_DMA1_MASTER_CLEAR);
18     outb(0, PORT_DMA2_MASTER_CLEAR);
19
20     // then initialize the DMA controllers
21     outb(0xc0, PORT_DMA2_MODE_REG);
22     outb(0x00, PORT_DMA2_MASK_REG);
23 }
24
25 // Handler for post calls that look like a resume.
26 void VISIBLE16
27 handle_resume(u8 status)
28 {
29     init_dma();
30
31     debug_serial_setup();
32     dprintf(1, "In resume (status=%d)\n", status);
33
34     switch (status) {
35     case 0x00:
36     case 0x09:
37     case 0x0d ... 0xff:
38         // Normal post - now that status has been cleared a reset will
39         // run regular boot code..
40         reset_vector();
41         break;
42
43     case 0x05:
44         // flush keyboard (issue EOI) and jump via 40h:0067h
45         eoi_pic2();
46         // NO BREAK
47     case 0x0a:
48         // resume execution by jump via 40h:0067h
49 #define bda ((struct bios_data_area_s *)0)
50         asm volatile(
51             "movw %%ax, %%ds\n"
52             "ljmpw *%0\n"
53             : : "m"(bda->jump_ip), "a"(SEG_BDA)
54             );
55         break;
56
57     case 0x0b:
58         // resume execution via IRET via 40h:0067h
59         asm volatile(
60             "movw %%ax, %%ds\n"
61             "movw %0, %%sp\n"
62             "movw %1, %%ss\n"
63             "iretw\n"
64             : : "m"(bda->jump_ip), "m"(bda->jump_cs), "a"(SEG_BDA)
65             );
66         break;
67
68     case 0x0c:
69         // resume execution via RETF via 40h:0067h
70         asm volatile(
71             "movw %%ax, %%ds\n"
72             "movw %0, %%sp\n"
73             "movw %1, %%ss\n"
74             "lretw\n"
75             : : "m"(bda->jump_ip), "m"(bda->jump_cs), "a"(SEG_BDA)
76             );
77         break;
78     }
79
80     BX_PANIC("Unimplemented shutdown status: %02x\n", status);
81 }