Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | // 16bit system callbacks |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2002 MandrakeSoft S.A. |
| 5 | // |
| 6 | // This file may be distributed under the terms of the GNU GPLv3 license. |
| 7 | |
| 8 | #include "util.h" // irq_restore |
Kevin O'Connor | 2ad3744 | 2008-05-06 19:49:01 -0400 | [diff] [blame] | 9 | #include "biosvar.h" // BIOS_CONFIG_TABLE |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 10 | #include "ioport.h" // inb |
Kevin O'Connor | c781293 | 2008-06-08 23:08:12 -0400 | [diff] [blame] | 11 | #include "memmap.h" // E820_RAM |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 12 | #include "pic.h" // eoi_pic2 |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 13 | #include "bregs.h" // struct bregs |
Kevin O'Connor | e2e5f01 | 2008-03-08 10:27:39 -0500 | [diff] [blame] | 14 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 15 | // Use PS2 System Control port A to set A20 enable |
| 16 | static inline u8 |
| 17 | set_a20(u8 cond) |
| 18 | { |
| 19 | // get current setting first |
| 20 | u8 newval, oldval = inb(PORT_A20); |
| 21 | if (cond) |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 22 | newval = oldval | A20_ENABLE_BIT; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 23 | else |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 24 | newval = oldval & ~A20_ENABLE_BIT; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 25 | outb(newval, PORT_A20); |
| 26 | |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 27 | return (oldval & A20_ENABLE_BIT) != 0; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 28 | } |
| 29 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 30 | static void |
| 31 | handle_152400(struct bregs *regs) |
| 32 | { |
| 33 | set_a20(0); |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 34 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static void |
| 38 | handle_152401(struct bregs *regs) |
| 39 | { |
| 40 | set_a20(1); |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 41 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void |
| 45 | handle_152402(struct bregs *regs) |
| 46 | { |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 47 | regs->al = (inb(PORT_A20) & A20_ENABLE_BIT) != 0; |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 48 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void |
| 52 | handle_152403(struct bregs *regs) |
| 53 | { |
| 54 | regs->bx = 3; |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 55 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void |
| 59 | handle_1524XX(struct bregs *regs) |
| 60 | { |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 61 | set_code_fail(regs, RET_EUNSUPPORTED); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Kevin O'Connor | adb6b37 | 2008-03-01 13:38:38 -0500 | [diff] [blame] | 64 | static void |
| 65 | handle_1524(struct bregs *regs) |
| 66 | { |
| 67 | switch (regs->al) { |
| 68 | case 0x00: handle_152400(regs); break; |
| 69 | case 0x01: handle_152401(regs); break; |
| 70 | case 0x02: handle_152402(regs); break; |
| 71 | case 0x03: handle_152403(regs); break; |
| 72 | default: handle_1524XX(regs); break; |
| 73 | } |
| 74 | } |
| 75 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 76 | // removable media eject |
| 77 | static void |
| 78 | handle_1552(struct bregs *regs) |
| 79 | { |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 80 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 83 | static void |
| 84 | handle_1587(struct bregs *regs) |
| 85 | { |
| 86 | // +++ should probably have descriptor checks |
| 87 | // +++ should have exception handlers |
| 88 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 89 | u8 prev_a20_enable = set_a20(1); // enable A20 line |
| 90 | |
| 91 | // 128K max of transfer on 386+ ??? |
| 92 | // source == destination ??? |
| 93 | |
| 94 | // ES:SI points to descriptor table |
| 95 | // offset use initially comments |
| 96 | // ============================================== |
| 97 | // 00..07 Unused zeros Null descriptor |
| 98 | // 08..0f GDT zeros filled in by BIOS |
| 99 | // 10..17 source ssssssss source of data |
| 100 | // 18..1f dest dddddddd destination of data |
| 101 | // 20..27 CS zeros filled in by BIOS |
| 102 | // 28..2f SS zeros filled in by BIOS |
| 103 | |
| 104 | //es:si |
| 105 | //eeee0 |
| 106 | //0ssss |
| 107 | //----- |
| 108 | |
| 109 | // check for access rights of source & dest here |
| 110 | |
| 111 | // Initialize GDT descriptor |
Kevin O'Connor | 67c00dd | 2008-03-09 16:10:19 -0400 | [diff] [blame] | 112 | SET_SEG(ES, regs->es); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 113 | u16 si = regs->si; |
| 114 | u16 base15_00 = (regs->es << 4) + si; |
| 115 | u16 base23_16 = regs->es >> 12; |
Kevin O'Connor | 67c00dd | 2008-03-09 16:10:19 -0400 | [diff] [blame] | 116 | if (base15_00 < (u16)(regs->es<<4)) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 117 | base23_16++; |
| 118 | SET_VAR(ES, *(u16*)(si+0x08+0), 47); // limit 15:00 = 6 * 8bytes/descriptor |
| 119 | SET_VAR(ES, *(u16*)(si+0x08+2), base15_00);// base 15:00 |
| 120 | SET_VAR(ES, *(u8 *)(si+0x08+4), base23_16);// base 23:16 |
| 121 | SET_VAR(ES, *(u8 *)(si+0x08+5), 0x93); // access |
| 122 | SET_VAR(ES, *(u16*)(si+0x08+6), 0x0000); // base 31:24/reserved/limit 19:16 |
| 123 | |
| 124 | // Initialize CS descriptor |
| 125 | SET_VAR(ES, *(u16*)(si+0x20+0), 0xffff);// limit 15:00 = normal 64K limit |
| 126 | SET_VAR(ES, *(u16*)(si+0x20+2), 0x0000);// base 15:00 |
| 127 | SET_VAR(ES, *(u8 *)(si+0x20+4), 0x000f);// base 23:16 |
| 128 | SET_VAR(ES, *(u8 *)(si+0x20+5), 0x9b); // access |
| 129 | SET_VAR(ES, *(u16*)(si+0x20+6), 0x0000);// base 31:24/reserved/limit 19:16 |
| 130 | |
| 131 | // Initialize SS descriptor |
| 132 | u16 ss = GET_SEG(SS); |
| 133 | base15_00 = ss << 4; |
| 134 | base23_16 = ss >> 12; |
| 135 | SET_VAR(ES, *(u16*)(si+0x28+0), 0xffff); // limit 15:00 = normal 64K limit |
| 136 | SET_VAR(ES, *(u16*)(si+0x28+2), base15_00);// base 15:00 |
| 137 | SET_VAR(ES, *(u8 *)(si+0x28+4), base23_16);// base 23:16 |
| 138 | SET_VAR(ES, *(u8 *)(si+0x28+5), 0x93); // access |
| 139 | SET_VAR(ES, *(u16*)(si+0x28+6), 0x0000); // base 31:24/reserved/limit 19:16 |
| 140 | |
Kevin O'Connor | 2cdd8b6 | 2008-03-09 23:37:04 -0400 | [diff] [blame] | 141 | u16 count = regs->cx; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 142 | asm volatile( |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 143 | // Load new descriptor tables |
Kevin O'Connor | 67c00dd | 2008-03-09 16:10:19 -0400 | [diff] [blame] | 144 | "lgdtw %%es:0x8(%%si)\n" |
| 145 | "lidtw %%cs:pmode_IDT_info\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 146 | |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 147 | // Enable protected mode |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 148 | "movl %%cr0, %%eax\n" |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 149 | "orl $" __stringify(CR0_PE) ", %%eax\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 150 | "movl %%eax, %%cr0\n" |
| 151 | |
| 152 | // far jump to flush CPU queue after transition to protected mode |
Kevin O'Connor | adb6b37 | 2008-03-01 13:38:38 -0500 | [diff] [blame] | 153 | "ljmpw $0x0020, $1f\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 154 | "1:\n" |
| 155 | |
| 156 | // GDT points to valid descriptor table, now load DS, ES |
| 157 | "movw $0x10, %%ax\n" // 010 000 = 2nd descriptor in table, TI=GDT, RPL=00 |
| 158 | "movw %%ax, %%ds\n" |
| 159 | "movw $0x18, %%ax\n" // 011 000 = 3rd descriptor in table, TI=GDT, RPL=00 |
| 160 | "movw %%ax, %%es\n" |
| 161 | |
| 162 | // move CX words from DS:SI to ES:DI |
| 163 | "xorw %%si, %%si\n" |
| 164 | "xorw %%di, %%di\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 165 | "rep movsw\n" |
| 166 | |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 167 | // Disable protected mode |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 168 | "movl %%cr0, %%eax\n" |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 169 | "andl $~" __stringify(CR0_PE) ", %%eax\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 170 | "movl %%eax, %%cr0\n" |
| 171 | |
| 172 | // far jump to flush CPU queue after transition to real mode |
Kevin O'Connor | e3677b1 | 2008-07-04 15:29:23 -0400 | [diff] [blame] | 173 | "ljmpw $" __stringify(SEG_BIOS) ", $2f\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 174 | "2:\n" |
| 175 | |
| 176 | // restore IDT to normal real-mode defaults |
Kevin O'Connor | 9649a96 | 2008-12-10 20:53:35 -0500 | [diff] [blame] | 177 | "lidtw %%cs:rmode_IDT_info\n" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 178 | |
Kevin O'Connor | e20ed9f | 2008-03-01 14:25:44 -0500 | [diff] [blame] | 179 | // Restore %ds (from %ss) |
| 180 | "movw %%ss, %%ax\n" |
| 181 | "movw %%ax, %%ds\n" |
Kevin O'Connor | 2cdd8b6 | 2008-03-09 23:37:04 -0400 | [diff] [blame] | 182 | : "+c"(count), "+S"(si) |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 183 | : : "eax", "di", "cc"); // XXX - also clobbers %es |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 184 | |
| 185 | set_a20(prev_a20_enable); |
| 186 | |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 187 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Get the amount of extended memory (above 1M) |
| 191 | static void |
| 192 | handle_1588(struct bregs *regs) |
| 193 | { |
Kevin O'Connor | e791636 | 2008-12-28 22:03:17 -0500 | [diff] [blame] | 194 | u32 rs = GET_GLOBAL(RamSize); |
Kevin O'Connor | 9571ac2 | 2008-05-17 22:20:27 -0400 | [diff] [blame] | 195 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 196 | // According to Ralf Brown's interrupt the limit should be 15M, |
| 197 | // but real machines mostly return max. 63M. |
Kevin O'Connor | 9571ac2 | 2008-05-17 22:20:27 -0400 | [diff] [blame] | 198 | if (rs > 64*1024*1024) |
| 199 | regs->ax = 63 * 1024; |
| 200 | else |
| 201 | regs->ax = (rs - 1*1024*1024) / 1024; |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 202 | set_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // Device busy interrupt. Called by Int 16h when no key available |
| 206 | static void |
| 207 | handle_1590(struct bregs *regs) |
| 208 | { |
| 209 | } |
| 210 | |
| 211 | // Interrupt complete. Called by Int 16h when key becomes available |
| 212 | static void |
| 213 | handle_1591(struct bregs *regs) |
| 214 | { |
| 215 | } |
| 216 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 217 | // keyboard intercept |
| 218 | static void |
| 219 | handle_154f(struct bregs *regs) |
| 220 | { |
Kevin O'Connor | db9e65e | 2008-06-07 14:41:21 -0400 | [diff] [blame] | 221 | set_fail_silent(regs); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 224 | static void |
| 225 | handle_15c0(struct bregs *regs) |
| 226 | { |
| 227 | regs->es = SEG_BIOS; |
Kevin O'Connor | 117fc21 | 2008-04-13 18:17:02 -0400 | [diff] [blame] | 228 | regs->bx = (u32)&BIOS_CONFIG_TABLE; |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 229 | set_code_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void |
| 233 | handle_15c1(struct bregs *regs) |
| 234 | { |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 235 | regs->es = get_ebda_seg(); |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 236 | set_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static void |
| 240 | handle_15e801(struct bregs *regs) |
| 241 | { |
| 242 | // my real system sets ax and bx to 0 |
| 243 | // this is confirmed by Ralph Brown list |
| 244 | // but syslinux v1.48 is known to behave |
| 245 | // strangely if ax is set to 0 |
| 246 | // regs.u.r16.ax = 0; |
| 247 | // regs.u.r16.bx = 0; |
| 248 | |
Kevin O'Connor | e791636 | 2008-12-28 22:03:17 -0500 | [diff] [blame] | 249 | u32 rs = GET_GLOBAL(RamSize); |
Kevin O'Connor | 9571ac2 | 2008-05-17 22:20:27 -0400 | [diff] [blame] | 250 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 251 | // Get the amount of extended memory (above 1M) |
Kevin O'Connor | 9571ac2 | 2008-05-17 22:20:27 -0400 | [diff] [blame] | 252 | if (rs > 16*1024*1024) { |
| 253 | // limit to 15M |
| 254 | regs->cx = 15*1024; |
| 255 | // Get the amount of extended memory above 16M in 64k blocks |
| 256 | regs->dx = (rs - 16*1024*1024) / (64*1024); |
| 257 | } else { |
| 258 | regs->cx = (rs - 1*1024*1024) / 1024; |
| 259 | regs->dx = 0; |
| 260 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 261 | |
| 262 | // Set configured memory equal to extended memory |
| 263 | regs->ax = regs->cx; |
| 264 | regs->bx = regs->dx; |
| 265 | |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 266 | set_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Kevin O'Connor | d995b3d | 2008-11-08 13:05:27 -0500 | [diff] [blame] | 269 | // Info on e820 map location and size. |
Kevin O'Connor | 92f95b0 | 2008-12-29 20:42:40 -0500 | [diff] [blame] | 270 | struct e820entry *e820_list VAR16_32; |
| 271 | int e820_count VAR16_32; |
Kevin O'Connor | e791636 | 2008-12-28 22:03:17 -0500 | [diff] [blame] | 272 | // Amount of continuous ram under 4Gig |
Kevin O'Connor | 92f95b0 | 2008-12-29 20:42:40 -0500 | [diff] [blame] | 273 | u32 RamSize VAR16_32; |
Kevin O'Connor | e791636 | 2008-12-28 22:03:17 -0500 | [diff] [blame] | 274 | // Amount of continuous ram >4Gig |
Kevin O'Connor | 92f95b0 | 2008-12-29 20:42:40 -0500 | [diff] [blame] | 275 | u64 RamSizeOver4G; |
Kevin O'Connor | d995b3d | 2008-11-08 13:05:27 -0500 | [diff] [blame] | 276 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 277 | static void |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 278 | handle_15e820(struct bregs *regs) |
| 279 | { |
Kevin O'Connor | 15157a3 | 2008-12-13 11:10:37 -0500 | [diff] [blame] | 280 | int count = GET_GLOBAL(e820_count); |
Kevin O'Connor | c781293 | 2008-06-08 23:08:12 -0400 | [diff] [blame] | 281 | if (regs->edx != 0x534D4150 || regs->bx >= count) { |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 282 | set_code_fail(regs, RET_EUNSUPPORTED); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | |
Kevin O'Connor | 15157a3 | 2008-12-13 11:10:37 -0500 | [diff] [blame] | 286 | struct e820entry *l = GET_GLOBAL(e820_list); |
Kevin O'Connor | d995b3d | 2008-11-08 13:05:27 -0500 | [diff] [blame] | 287 | memcpy_far(MAKE_FARPTR(regs->es, regs->di), &l[regs->bx], sizeof(l[0])); |
Kevin O'Connor | c781293 | 2008-06-08 23:08:12 -0400 | [diff] [blame] | 288 | if (regs->bx == count-1) |
| 289 | regs->ebx = 0; |
| 290 | else |
| 291 | regs->ebx++; |
| 292 | regs->eax = 0x534D4150; |
Kevin O'Connor | d995b3d | 2008-11-08 13:05:27 -0500 | [diff] [blame] | 293 | regs->ecx = sizeof(l[0]); |
Kevin O'Connor | c781293 | 2008-06-08 23:08:12 -0400 | [diff] [blame] | 294 | set_success(regs); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void |
| 298 | handle_15e8XX(struct bregs *regs) |
| 299 | { |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 300 | set_code_fail(regs, RET_EUNSUPPORTED); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void |
Kevin O'Connor | adb6b37 | 2008-03-01 13:38:38 -0500 | [diff] [blame] | 304 | handle_15e8(struct bregs *regs) |
| 305 | { |
| 306 | switch (regs->al) { |
| 307 | case 0x01: handle_15e801(regs); break; |
| 308 | case 0x20: handle_15e820(regs); break; |
| 309 | default: handle_15e8XX(regs); break; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | static void |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 314 | handle_15XX(struct bregs *regs) |
| 315 | { |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 316 | set_code_fail(regs, RET_EUNSUPPORTED); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // INT 15h System Services Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 320 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 321 | handle_15(struct bregs *regs) |
| 322 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 323 | debug_enter(regs, DEBUG_HDL_15); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 324 | switch (regs->ah) { |
Kevin O'Connor | adb6b37 | 2008-03-01 13:38:38 -0500 | [diff] [blame] | 325 | case 0x24: handle_1524(regs); break; |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 326 | case 0x4f: handle_154f(regs); break; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 327 | case 0x52: handle_1552(regs); break; |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 328 | case 0x53: handle_1553(regs); break; |
Kevin O'Connor | cbffa8e | 2008-08-17 11:11:07 -0400 | [diff] [blame] | 329 | case 0x5f: handle_155f(regs); break; |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 330 | case 0x83: handle_1583(regs); break; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 331 | case 0x86: handle_1586(regs); break; |
| 332 | case 0x87: handle_1587(regs); break; |
| 333 | case 0x88: handle_1588(regs); break; |
| 334 | case 0x90: handle_1590(regs); break; |
| 335 | case 0x91: handle_1591(regs); break; |
| 336 | case 0xc0: handle_15c0(regs); break; |
| 337 | case 0xc1: handle_15c1(regs); break; |
| 338 | case 0xc2: handle_15c2(regs); break; |
Kevin O'Connor | adb6b37 | 2008-03-01 13:38:38 -0500 | [diff] [blame] | 339 | case 0xe8: handle_15e8(regs); break; |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 340 | default: handle_15XX(regs); break; |
| 341 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | // INT 12h Memory Size Service Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 345 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 346 | handle_12(struct bregs *regs) |
| 347 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 348 | debug_enter(regs, DEBUG_HDL_12); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 349 | regs->ax = GET_BDA(mem_size_kb); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | // INT 11h Equipment List Service Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 353 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 354 | handle_11(struct bregs *regs) |
| 355 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 356 | debug_enter(regs, DEBUG_HDL_11); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 357 | regs->ax = GET_BDA(equipment_list_flags); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | // INT 05h Print Screen Service Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 361 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 362 | handle_05(struct bregs *regs) |
| 363 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 364 | debug_enter(regs, DEBUG_HDL_05); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // INT 10h Video Support Service Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 368 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 369 | handle_10(struct bregs *regs) |
| 370 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 371 | debug_enter(regs, DEBUG_HDL_10); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 372 | // dont do anything, since the VGA BIOS handles int10h requests |
| 373 | } |
| 374 | |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 375 | void VISIBLE16 |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 376 | handle_nmi() |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 377 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 378 | debug_isr(DEBUG_ISR_nmi); |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 379 | BX_PANIC("NMI Handler called\n"); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 380 | } |
| 381 | |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 382 | void |
| 383 | mathcp_setup() |
| 384 | { |
| 385 | dprintf(3, "math cp init\n"); |
| 386 | // 80x87 coprocessor installed |
| 387 | SETBITS_BDA(equipment_list_flags, 0x02); |
Kevin O'Connor | d21c089 | 2008-11-26 17:02:43 -0500 | [diff] [blame] | 388 | enable_hwirq(13, entry_75); |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 389 | } |
| 390 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 391 | // INT 75 - IRQ13 - MATH COPROCESSOR EXCEPTION |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 392 | void VISIBLE16 |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 393 | handle_75() |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 394 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 395 | debug_isr(DEBUG_ISR_75); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 396 | |
| 397 | // clear irq13 |
| 398 | outb(0, PORT_MATH_CLEAR); |
| 399 | // clear interrupt |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 400 | eoi_pic2(); |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 401 | // legacy nmi call |
Kevin O'Connor | a83ff55 | 2009-01-01 21:00:59 -0500 | [diff] [blame^] | 402 | u32 eax=0, flags; |
| 403 | call16_simpint(0x02, &eax, &flags); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 404 | } |