blob: 642bbb1914799103ade99dac55bd00992d14d2a3 [file] [log] [blame]
Kevin O'Connor30853762009-01-17 18:49:20 -05001// Code for misc 16bit handlers and variables.
2//
Kevin O'Connor2929c352009-07-25 13:48:27 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor30853762009-01-17 18:49:20 -05004// Copyright (C) 2002 MandrakeSoft S.A.
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8#include "bregs.h" // struct bregs
9#include "biosvar.h" // GET_BDA
10#include "util.h" // debug_enter
Kevin O'Connor5d369d82013-09-02 20:48:46 -040011#include "hw/pic.h" // enable_hwirq
Kevin O'Connor3df600b2013-09-14 19:28:55 -040012#include "stacks.h" // call16_int
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040013#include "string.h" // memset
Kevin O'Connor30853762009-01-17 18:49:20 -050014
Kevin O'Connor30853762009-01-17 18:49:20 -050015
16/****************************************************************
17 * Misc 16bit ISRs
18 ****************************************************************/
19
20// INT 12h Memory Size Service Entry Point
21void VISIBLE16
22handle_12(struct bregs *regs)
23{
24 debug_enter(regs, DEBUG_HDL_12);
25 regs->ax = GET_BDA(mem_size_kb);
26}
27
28// INT 11h Equipment List Service Entry Point
29void VISIBLE16
30handle_11(struct bregs *regs)
31{
32 debug_enter(regs, DEBUG_HDL_11);
33 regs->ax = GET_BDA(equipment_list_flags);
34}
35
36// INT 05h Print Screen Service Entry Point
37void VISIBLE16
38handle_05(struct bregs *regs)
39{
40 debug_enter(regs, DEBUG_HDL_05);
41}
42
43// INT 10h Video Support Service Entry Point
44void VISIBLE16
45handle_10(struct bregs *regs)
46{
47 debug_enter(regs, DEBUG_HDL_10);
48 // dont do anything, since the VGA BIOS handles int10h requests
49}
50
Kevin O'Connor75f49b32009-03-07 00:07:24 -050051// NMI handler
Kevin O'Connor30853762009-01-17 18:49:20 -050052void VISIBLE16
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040053handle_02(void)
Kevin O'Connor30853762009-01-17 18:49:20 -050054{
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040055 debug_isr(DEBUG_ISR_02);
Kevin O'Connor30853762009-01-17 18:49:20 -050056}
57
58void
Kevin O'Connor3a735ba2013-02-10 00:35:01 -050059mathcp_setup(void)
Kevin O'Connor30853762009-01-17 18:49:20 -050060{
61 dprintf(3, "math cp init\n");
62 // 80x87 coprocessor installed
Kevin O'Connore51316d2012-06-10 09:09:22 -040063 set_equipment_flags(0x02, 0x02);
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040064 enable_hwirq(13, FUNC16(entry_75));
Kevin O'Connor30853762009-01-17 18:49:20 -050065}
66
67// INT 75 - IRQ13 - MATH COPROCESSOR EXCEPTION
68void VISIBLE16
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040069handle_75(void)
Kevin O'Connor30853762009-01-17 18:49:20 -050070{
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040071 debug_isr(DEBUG_ISR_75);
Kevin O'Connor30853762009-01-17 18:49:20 -050072
73 // clear irq13
74 outb(0, PORT_MATH_CLEAR);
75 // clear interrupt
Kevin O'Connoraa7c2342013-07-14 15:07:21 -040076 pic_eoi2();
Kevin O'Connor30853762009-01-17 18:49:20 -050077 // legacy nmi call
Kevin O'Connorecdc6552012-05-28 14:25:15 -040078 struct bregs br;
79 memset(&br, 0, sizeof(br));
80 br.flags = F_IF;
81 call16_int(0x02, &br);
Kevin O'Connor30853762009-01-17 18:49:20 -050082}
83
84
85/****************************************************************
86 * BIOS_CONFIG_TABLE
87 ****************************************************************/
88
89// DMA channel 3 used by hard disk BIOS
90#define CBT_F1_DMA3USED (1<<7)
91// 2nd interrupt controller (8259) installed
92#define CBT_F1_2NDPIC (1<<6)
93// Real-Time Clock installed
94#define CBT_F1_RTC (1<<5)
95// INT 15/AH=4Fh called upon INT 09h
96#define CBT_F1_INT154F (1<<4)
97// wait for external event (INT 15/AH=41h) supported
98#define CBT_F1_WAITEXT (1<<3)
99// extended BIOS area allocated (usually at top of RAM)
100#define CBT_F1_EBDA (1<<2)
101// bus is Micro Channel instead of ISA
102#define CBT_F1_MCA (1<<1)
103// system has dual bus (Micro Channel + ISA)
104#define CBT_F1_MCAISA (1<<0)
105
106// INT 16/AH=09h (keyboard functionality) supported
107#define CBT_F2_INT1609 (1<<6)
108
109struct bios_config_table_s BIOS_CONFIG_TABLE VAR16FIXED(0xe6f5) = {
110 .size = sizeof(BIOS_CONFIG_TABLE) - 2,
Kevin O'Connore52ad392013-02-20 23:48:22 -0500111 .model = BUILD_MODEL_ID,
112 .submodel = BUILD_SUBMODEL_ID,
113 .biosrev = BUILD_BIOS_REVISION,
Kevin O'Connor30853762009-01-17 18:49:20 -0500114 .feature1 = (
115 CBT_F1_2NDPIC | CBT_F1_RTC | CBT_F1_EBDA
116 | (CONFIG_KBD_CALL_INT15_4F ? CBT_F1_INT154F : 0)),
117 .feature2 = CBT_F2_INT1609,
118 .feature3 = 0,
119 .feature4 = 0,
120 .feature5 = 0,
121};
122
123
124/****************************************************************
125 * GDT and IDT tables
126 ****************************************************************/
127
Kevin O'Connor30853762009-01-17 18:49:20 -0500128// Real mode IDT descriptor
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500129struct descloc_s rmode_IDT_info VARFSEG = {
Kevin O'Connor30853762009-01-17 18:49:20 -0500130 .length = sizeof(struct rmode_IVT) - 1,
Kevin O'Connor35ae7262009-01-19 15:44:44 -0500131 .addr = (u32)MAKE_FLATPTR(SEG_IVT, 0),
Kevin O'Connor30853762009-01-17 18:49:20 -0500132};
133
134// Dummy IDT that forces a machine shutdown if an irq happens in
135// protected mode.
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500136u8 dummy_IDT VARFSEG;
Kevin O'Connor30853762009-01-17 18:49:20 -0500137
138// Protected mode IDT descriptor
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500139struct descloc_s pmode_IDT_info VARFSEG = {
Kevin O'Connor30853762009-01-17 18:49:20 -0500140 .length = sizeof(dummy_IDT) - 1,
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500141 .addr = (u32)&dummy_IDT,
Kevin O'Connor30853762009-01-17 18:49:20 -0500142};
143
144// GDT
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500145u64 rombios32_gdt[] VARFSEG __aligned(8) = {
Kevin O'Connor30853762009-01-17 18:49:20 -0500146 // First entry can't be used.
147 0x0000000000000000LL,
148 // 32 bit flat code segment (SEG32_MODE32_CS)
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400149 GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_B,
Kevin O'Connor30853762009-01-17 18:49:20 -0500150 // 32 bit flat data segment (SEG32_MODE32_DS)
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400151 GDT_GRANLIMIT(0xffffffff) | GDT_DATA | GDT_B,
Kevin O'Connor30853762009-01-17 18:49:20 -0500152 // 16 bit code segment base=0xf0000 limit=0xffff (SEG32_MODE16_CS)
Kevin O'Connor643062f2010-01-04 20:48:20 -0500153 GDT_LIMIT(BUILD_BIOS_SIZE-1) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR),
Kevin O'Connor30853762009-01-17 18:49:20 -0500154 // 16 bit data segment base=0x0 limit=0xffff (SEG32_MODE16_DS)
Kevin O'Connoreaa2e552009-08-10 00:03:04 -0400155 GDT_LIMIT(0x0ffff) | GDT_DATA,
Kevin O'Connor0f788892010-07-25 14:04:01 -0400156 // 16 bit code segment base=0xf0000 limit=0xffffffff (SEG32_MODE16BIG_CS)
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400157 GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR),
Kevin O'Connor30853762009-01-17 18:49:20 -0500158 // 16 bit data segment base=0 limit=0xffffffff (SEG32_MODE16BIG_DS)
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400159 GDT_GRANLIMIT(0xffffffff) | GDT_DATA,
Kevin O'Connor30853762009-01-17 18:49:20 -0500160};
161
162// GDT descriptor
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500163struct descloc_s rombios32_gdt_48 VARFSEG = {
Kevin O'Connor30853762009-01-17 18:49:20 -0500164 .length = sizeof(rombios32_gdt) - 1,
Kevin O'Connor89a2f962013-02-18 23:36:03 -0500165 .addr = (u32)rombios32_gdt,
Kevin O'Connor30853762009-01-17 18:49:20 -0500166};
167
168
169/****************************************************************
170 * Misc fixed vars
171 ****************************************************************/
172
173char BiosCopyright[] VAR16FIXED(0xff00) =
174 "(c) 2002 MandrakeSoft S.A. Written by Kevin Lawton & the Bochs team.";
175
176// BIOS build date
177char BiosDate[] VAR16FIXED(0xfff5) = "06/23/99";
178
Kevin O'Connore52ad392013-02-20 23:48:22 -0500179u8 BiosModelId VAR16FIXED(0xfffe) = BUILD_MODEL_ID;
Kevin O'Connor30853762009-01-17 18:49:20 -0500180
181u8 BiosChecksum VAR16FIXED(0xffff);
182
183// XXX - Initial Interrupt Vector Offsets Loaded by POST
184u8 InitVectors[13] VAR16FIXED(0xfef3);
185
186// XXX - INT 1D - SYSTEM DATA - VIDEO PARAMETER TABLES
187u8 VideoParams[88] VAR16FIXED(0xf0a4);