Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | // Rom layout and bios assembler to C interface. |
| 2 | // |
Kevin O'Connor | f8e176c | 2009-05-06 23:33:32 -0400 | [diff] [blame] | 3 | // Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net> |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 4 | // Copyright (C) 2002 MandrakeSoft S.A. |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 7 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 8 | |
| 9 | /**************************************************************** |
| 10 | * Include of 16bit C code |
| 11 | ****************************************************************/ |
| 12 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 13 | .code16gcc |
Kevin O'Connor | 3dba4c2 | 2011-01-29 11:26:54 -0500 | [diff] [blame^] | 14 | #include "ccode.16.s" |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 15 | |
Kevin O'Connor | f8e176c | 2009-05-06 23:33:32 -0400 | [diff] [blame] | 16 | #include "config.h" // CONFIG_* |
| 17 | #include "ioport.h" // PORT_A20 |
| 18 | #include "bregs.h" // CR0_* |
| 19 | #include "cmos.h" // CMOS_RESET_CODE |
Kevin O'Connor | 3dba4c2 | 2011-01-29 11:26:54 -0500 | [diff] [blame^] | 20 | #include "asm-offsets.h" // BREGS_* |
Kevin O'Connor | f8e176c | 2009-05-06 23:33:32 -0400 | [diff] [blame] | 21 | #include "entryfuncs.S" // ENTRY_* |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 22 | |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 23 | |
| 24 | /**************************************************************** |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 25 | * Call trampolines |
| 26 | ****************************************************************/ |
| 27 | |
| 28 | // Place CPU into 32bit mode from 16bit mode. |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 29 | // %edx = return location (in 32bit mode) |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 30 | // Clobbers: ecx, flags, segment registers, cr0, idt/gdt |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 31 | DECLFUNC transition32 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 32 | transition32: |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 33 | movl %eax, %ecx |
Kevin O'Connor | 9caf786 | 2009-02-27 20:14:05 -0500 | [diff] [blame] | 34 | |
Kevin O'Connor | f094ba8 | 2009-04-13 19:30:27 -0400 | [diff] [blame] | 35 | // Disable irqs (and clear direction flag) |
| 36 | cli |
| 37 | cld |
| 38 | |
| 39 | // Disable nmi |
| 40 | movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax |
| 41 | outb %al, $PORT_CMOS_INDEX |
| 42 | inb $PORT_CMOS_DATA, %al |
| 43 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 44 | // enable a20 |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 45 | inb $PORT_A20, %al |
| 46 | orb $A20_ENABLE_BIT, %al |
| 47 | outb %al, $PORT_A20 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 48 | |
| 49 | // Set segment descriptors |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 50 | lidtw %cs:pmode_IDT_info |
| 51 | lgdtw %cs:rombios32_gdt_48 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 52 | |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 53 | // Enable protected mode |
| 54 | movl %cr0, %eax |
| 55 | orl $CR0_PE, %eax |
| 56 | movl %eax, %cr0 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 57 | |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 58 | // start 32bit protected mode code |
Kevin O'Connor | 1492708 | 2008-11-08 19:07:49 -0500 | [diff] [blame] | 59 | ljmpl $SEG32_MODE32_CS, $(BUILD_BIOS_ADDR + 1f) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 60 | |
| 61 | .code32 |
| 62 | 1: |
| 63 | // init data segments |
Kevin O'Connor | 1492708 | 2008-11-08 19:07:49 -0500 | [diff] [blame] | 64 | movl $SEG32_MODE32_DS, %eax |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 65 | movw %ax, %ds |
| 66 | movw %ax, %es |
| 67 | movw %ax, %ss |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 68 | movw %ax, %fs |
| 69 | movw %ax, %gs |
| 70 | |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 71 | movl %ecx, %eax |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 72 | jmpl *%edx |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 73 | |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 74 | // Place CPU into 16bit mode from 32bit mode. |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 75 | // %edx = return location (in 16bit mode) |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 76 | // Clobbers: ecx, flags, segment registers, cr0, idt/gdt |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 77 | DECLFUNC transition16 |
| 78 | .global transition16big |
| 79 | transition16: |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 80 | movl %eax, %ecx |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 81 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 82 | // restore data segment limits to 0xffff |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 83 | movl $SEG32_MODE16_DS, %eax |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 84 | movw %ax, %ds |
| 85 | movw %ax, %es |
| 86 | movw %ax, %ss |
| 87 | movw %ax, %fs |
| 88 | movw %ax, %gs |
| 89 | |
Kevin O'Connor | ffb81a4 | 2009-04-13 19:44:55 -0400 | [diff] [blame] | 90 | #if CONFIG_DISABLE_A20 |
Kevin O'Connor | 1a72e2e | 2008-11-11 22:03:55 -0500 | [diff] [blame] | 91 | // disable a20 |
Kevin O'Connor | d9a8b2d | 2008-11-16 09:17:02 -0500 | [diff] [blame] | 92 | inb $PORT_A20, %al |
| 93 | andb $~A20_ENABLE_BIT, %al |
| 94 | outb %al, $PORT_A20 |
Kevin O'Connor | ffb81a4 | 2009-04-13 19:44:55 -0400 | [diff] [blame] | 95 | #endif |
Kevin O'Connor | 1a72e2e | 2008-11-11 22:03:55 -0500 | [diff] [blame] | 96 | |
| 97 | // Jump to 16bit mode |
| 98 | ljmpw $SEG32_MODE16_CS, $1f |
| 99 | |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 100 | transition16big: |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 101 | movl %eax, %ecx |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 102 | |
| 103 | movl $SEG32_MODE16BIG_DS, %eax |
| 104 | movw %ax, %ds |
| 105 | movw %ax, %es |
| 106 | movw %ax, %ss |
| 107 | movw %ax, %fs |
| 108 | movw %ax, %gs |
| 109 | |
Kevin O'Connor | 0f78889 | 2010-07-25 14:04:01 -0400 | [diff] [blame] | 110 | ljmpw $SEG32_MODE16BIG_CS, $1f |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 111 | |
Kevin O'Connor | 1a72e2e | 2008-11-11 22:03:55 -0500 | [diff] [blame] | 112 | .code16gcc |
| 113 | 1: |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 114 | // Disable protected mode |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 115 | movl %cr0, %eax |
Kevin O'Connor | 3eac009 | 2008-11-16 09:59:32 -0500 | [diff] [blame] | 116 | andl $~CR0_PE, %eax |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 117 | movl %eax, %cr0 |
| 118 | |
| 119 | // far jump to flush CPU queue after transition to real mode |
Kevin O'Connor | e3677b1 | 2008-07-04 15:29:23 -0400 | [diff] [blame] | 120 | ljmpw $SEG_BIOS, $2f |
Kevin O'Connor | 21e930b | 2008-03-01 09:49:37 -0500 | [diff] [blame] | 121 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 122 | 2: |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 123 | // restore IDT to normal real-mode defaults |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 124 | lidtw %cs:rmode_IDT_info |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 125 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 126 | // Clear segment registers |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 127 | xorw %ax, %ax |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 128 | movw %ax, %fs |
| 129 | movw %ax, %gs |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 130 | movw %ax, %es |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 131 | movw %ax, %ds |
| 132 | movw %ax, %ss // Assume stack is in segment 0 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 133 | |
Kevin O'Connor | ad90159 | 2009-12-13 11:25:25 -0500 | [diff] [blame] | 134 | movl %ecx, %eax |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 135 | jmpl *%edx |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 136 | |
Kevin O'Connor | 21e930b | 2008-03-01 09:49:37 -0500 | [diff] [blame] | 137 | // Call a 16bit function from 16bit mode with a specified cpu register state |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 138 | // %eax = address of struct bregs |
Kevin O'Connor | 9caf786 | 2009-02-27 20:14:05 -0500 | [diff] [blame] | 139 | // Clobbers: %e[bcd]x, %e[ds]i, flags |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 140 | DECLFUNC __call16 |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 141 | __call16: |
Kevin O'Connor | 9caf786 | 2009-02-27 20:14:05 -0500 | [diff] [blame] | 142 | // Save %eax, %ebp |
| 143 | pushl %ebp |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 144 | pushl %eax |
| 145 | |
| 146 | // Setup for iretw call |
Kevin O'Connor | 273e8ae | 2009-01-19 19:56:07 -0500 | [diff] [blame] | 147 | pushw %cs |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 148 | pushw $1f // return point |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 149 | pushw BREGS_flags(%eax) // flags |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 150 | pushl BREGS_code(%eax) // CS:IP |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 151 | |
| 152 | // Load calling registers. |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 153 | movl BREGS_edi(%eax), %edi |
| 154 | movl BREGS_esi(%eax), %esi |
Kevin O'Connor | 7da210c | 2009-05-16 23:57:08 -0400 | [diff] [blame] | 155 | movl BREGS_ebp(%eax), %ebp |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 156 | movl BREGS_ebx(%eax), %ebx |
| 157 | movl BREGS_edx(%eax), %edx |
| 158 | movl BREGS_ecx(%eax), %ecx |
| 159 | movw BREGS_es(%eax), %es |
| 160 | movw BREGS_ds(%eax), %ds |
| 161 | movl %ss:BREGS_eax(%eax), %eax |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 162 | |
| 163 | // Invoke call |
| 164 | iretw // XXX - just do a lcalll |
| 165 | 1: |
| 166 | // Store flags, eax, ecx |
| 167 | pushfw |
| 168 | pushl %eax |
| 169 | movl 0x06(%esp), %eax |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 170 | movl %ecx, %ss:BREGS_ecx(%eax) |
| 171 | movw %ds, %ss:BREGS_ds(%eax) |
Kevin O'Connor | cbbb667 | 2008-03-08 13:04:10 -0500 | [diff] [blame] | 172 | movw %ss, %cx |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 173 | movw %cx, %ds // Restore %ds == %ss |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 174 | popl %ecx |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 175 | movl %ecx, BREGS_eax(%eax) |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 176 | popw %cx |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 177 | movw %cx, BREGS_flags(%eax) |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 178 | |
| 179 | // Store remaining registers |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 180 | movw %es, BREGS_es(%eax) |
| 181 | movl %edi, BREGS_edi(%eax) |
| 182 | movl %esi, BREGS_esi(%eax) |
Kevin O'Connor | 7da210c | 2009-05-16 23:57:08 -0400 | [diff] [blame] | 183 | movl %ebp, BREGS_ebp(%eax) |
Kevin O'Connor | 952974e | 2008-11-16 18:14:33 -0500 | [diff] [blame] | 184 | movl %ebx, BREGS_ebx(%eax) |
| 185 | movl %edx, BREGS_edx(%eax) |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 186 | |
Kevin O'Connor | 9caf786 | 2009-02-27 20:14:05 -0500 | [diff] [blame] | 187 | // Remove %eax, restore %ebp |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 188 | popl %eax |
Kevin O'Connor | 9caf786 | 2009-02-27 20:14:05 -0500 | [diff] [blame] | 189 | popl %ebp |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 190 | |
| 191 | retl |
| 192 | |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 193 | // Call a 16bit function from 32bit mode. |
| 194 | // %eax = address of struct bregs |
| 195 | // Clobbers: %e[bcd]x, %e[ds]i, flags, segment registers, idt/gdt |
| 196 | DECLFUNC __call16_from32 |
| 197 | .global __call16big_from32 |
| 198 | .code32 |
| 199 | __call16_from32: |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 200 | movl $1f, %edx |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 201 | jmp transition16 |
| 202 | __call16big_from32: |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 203 | movl $1f, %edx |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 204 | jmp transition16big |
| 205 | |
| 206 | // Make call. |
| 207 | .code16gcc |
| 208 | 1: calll __call16 |
| 209 | // Return via transition32 |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 210 | movl $(2f + BUILD_BIOS_ADDR), %edx |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 211 | jmp transition32 |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 212 | .code32 |
| 213 | 2: retl |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 214 | |
Kevin O'Connor | 4057f98 | 2010-11-25 08:52:50 -0500 | [diff] [blame] | 215 | .code16gcc |
Kevin O'Connor | 79dde65 | 2009-04-13 19:26:43 -0400 | [diff] [blame] | 216 | // IRQ trampolines |
| 217 | .macro IRQ_TRAMPOLINE num |
| 218 | DECLFUNC irq_trampoline_0x\num |
| 219 | irq_trampoline_0x\num : |
| 220 | int $0x\num |
| 221 | lretw |
| 222 | .endm |
| 223 | |
| 224 | IRQ_TRAMPOLINE 10 |
| 225 | IRQ_TRAMPOLINE 13 |
| 226 | IRQ_TRAMPOLINE 15 |
| 227 | IRQ_TRAMPOLINE 16 |
| 228 | IRQ_TRAMPOLINE 18 |
| 229 | IRQ_TRAMPOLINE 19 |
| 230 | |
| 231 | |
| 232 | /**************************************************************** |
| 233 | * POST entry point |
| 234 | ****************************************************************/ |
| 235 | |
| 236 | DECLFUNC entry_post |
| 237 | entry_post: |
| 238 | // Enable cache |
| 239 | movl %cr0, %eax |
| 240 | andl $~(CR0_CD|CR0_NW), %eax |
| 241 | movl %eax, %cr0 |
| 242 | |
| 243 | // Disable interrupts |
| 244 | cli |
| 245 | cld |
| 246 | |
| 247 | // Check for restart indicator. |
| 248 | movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax |
| 249 | outb %al, $PORT_CMOS_INDEX |
| 250 | inb $PORT_CMOS_DATA, %al |
| 251 | cmpb $0x0, %al |
| 252 | jnz 1f |
| 253 | |
| 254 | // Normal entry point |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 255 | ENTRY_INTO32 _cfunc32flat__start |
Kevin O'Connor | 79dde65 | 2009-04-13 19:26:43 -0400 | [diff] [blame] | 256 | |
| 257 | // Entry point when a post call looks like a resume. |
| 258 | 1: |
| 259 | // Save old shutdown status. |
| 260 | movl %eax, %ebx |
| 261 | |
| 262 | // Clear shutdown status register. |
| 263 | movl $CMOS_RESET_CODE|NMI_DISABLE_BIT, %eax |
| 264 | outb %al, $PORT_CMOS_INDEX |
| 265 | xorl %eax, %eax |
| 266 | outb %al, $PORT_CMOS_DATA |
| 267 | |
| 268 | // Use a stack in EBDA |
| 269 | movw $SEG_BDA, %ax |
| 270 | movw %ax, %ds |
| 271 | movw BDA_ebda_seg, %ax |
Kevin O'Connor | 49553a4 | 2009-05-17 10:31:34 -0400 | [diff] [blame] | 272 | |
| 273 | cmpw $EBDA_SEGMENT_START, %ax |
| 274 | jle 2f |
| 275 | // EBDA segment doesn't look valid - use startup value. |
| 276 | movw $EBDA_SEGMENT_START, %ax |
| 277 | |
| 278 | 2: movw %ax, %ds |
Kevin O'Connor | 79dde65 | 2009-04-13 19:26:43 -0400 | [diff] [blame] | 279 | movw %ax, %ss |
| 280 | movl $EBDA_OFFSET_TOP_STACK, %esp |
| 281 | |
| 282 | // Call handler. |
| 283 | movl %ebx, %eax |
| 284 | jmp handle_resume |
| 285 | |
| 286 | |
| 287 | /**************************************************************** |
| 288 | * Misc. entry points. |
| 289 | ****************************************************************/ |
| 290 | |
Kevin O'Connor | e54ee38 | 2009-07-26 19:33:13 -0400 | [diff] [blame] | 291 | // PMM entry point |
| 292 | DECLFUNC entry_pmm |
| 293 | entry_pmm: |
| 294 | pushl %esp // Backup %esp, then clear high bits |
| 295 | movzwl %sp, %esp |
| 296 | pushfl // Save registers clobbered by C code |
| 297 | cli |
| 298 | cld |
| 299 | pushl %eax |
| 300 | pushl %ecx |
| 301 | pushl %edx |
| 302 | pushw %es |
| 303 | pushw %ds |
| 304 | movw %ss, %cx // Move %ss to %ds |
| 305 | movw %cx, %ds |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 306 | leal 28(%esp), %eax // %eax points to start of args |
Kevin O'Connor | e54ee38 | 2009-07-26 19:33:13 -0400 | [diff] [blame] | 307 | calll handle_pmm |
| 308 | movw %ax, 12(%esp) // Modify %ax:%dx to return %eax |
| 309 | shrl $16, %eax |
| 310 | movw %ax, 4(%esp) |
| 311 | popw %ds // Restore saved registers |
| 312 | popw %es |
| 313 | popl %edx |
| 314 | popl %ecx |
| 315 | popl %eax |
| 316 | popfl |
| 317 | popl %esp |
| 318 | lretw |
| 319 | |
Kevin O'Connor | 79dde65 | 2009-04-13 19:26:43 -0400 | [diff] [blame] | 320 | // PnP entry points |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 321 | DECLFUNC entry_pnp_real |
| 322 | .global entry_pnp_prot |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 323 | entry_pnp_prot: |
| 324 | pushl %esp |
| 325 | jmp 1f |
| 326 | entry_pnp_real: |
| 327 | pushl %esp // Backup %esp, then clear high bits |
| 328 | movzwl %sp, %esp |
| 329 | 1: |
| 330 | pushfl // Save registers clobbered by C code |
Kevin O'Connor | e54ee38 | 2009-07-26 19:33:13 -0400 | [diff] [blame] | 331 | cli |
| 332 | cld |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 333 | pushl %eax |
| 334 | pushl %ecx |
| 335 | pushl %edx |
| 336 | pushw %es |
| 337 | pushw %ds |
| 338 | movw %ss, %cx // Move %ss to %ds |
| 339 | movw %cx, %ds |
Kevin O'Connor | 752151b | 2009-12-10 21:16:07 -0500 | [diff] [blame] | 340 | leal 28(%esp), %eax // %eax points to start of u16 args |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 341 | calll handle_pnp |
| 342 | movw %ax, 12(%esp) // Modify %eax to return %ax |
| 343 | popw %ds |
| 344 | popw %es |
| 345 | popl %edx |
| 346 | popl %ecx |
| 347 | popl %eax |
| 348 | popfl |
| 349 | popl %esp |
| 350 | lretw |
| 351 | |
Kevin O'Connor | 79dde65 | 2009-04-13 19:26:43 -0400 | [diff] [blame] | 352 | // APM entry points |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 353 | DECLFUNC apm16protected_entry |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 354 | apm16protected_entry: |
| 355 | pushfw // save flags |
| 356 | pushl %eax // dummy |
Kevin O'Connor | c003148 | 2010-01-01 13:03:17 -0500 | [diff] [blame] | 357 | ENTRY_ARG handle_apm16 |
Kevin O'Connor | b3c28be | 2008-06-08 13:34:43 -0400 | [diff] [blame] | 358 | addw $4, %sp // pop dummy |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 359 | popfw // restore flags |
| 360 | lretw |
| 361 | |
| 362 | .code32 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 363 | DECLFUNC apm32protected_entry |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 364 | apm32protected_entry: |
Kevin O'Connor | c003148 | 2010-01-01 13:03:17 -0500 | [diff] [blame] | 365 | pushfl |
| 366 | pushl %gs |
| 367 | pushl %cs // Move second descriptor after %cs to %gs |
| 368 | addl $16, (%esp) |
| 369 | popl %gs |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 370 | ENTRY_ARG_ESP _cfunc32seg_handle_apm32 |
Kevin O'Connor | c003148 | 2010-01-01 13:03:17 -0500 | [diff] [blame] | 371 | popl %gs |
| 372 | popfl |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 373 | lretl |
Kevin O'Connor | ee4f9ff | 2008-07-05 21:19:10 -0400 | [diff] [blame] | 374 | |
Kevin O'Connor | 871e0a0 | 2009-12-30 12:14:53 -0500 | [diff] [blame] | 375 | // PCI-BIOS 32bit entry point |
| 376 | DECLFUNC pcibios32_entry |
| 377 | pcibios32_entry: |
| 378 | pushfl |
Kevin O'Connor | c003148 | 2010-01-01 13:03:17 -0500 | [diff] [blame] | 379 | pushl %gs // Backup %gs and set %gs=%ds |
| 380 | pushl %ds |
| 381 | popl %gs |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 382 | ENTRY_ARG_ESP _cfunc32seg_handle_pcibios32 |
Kevin O'Connor | 871e0a0 | 2009-12-30 12:14:53 -0500 | [diff] [blame] | 383 | popl %gs |
| 384 | popfl |
| 385 | lretl |
| 386 | |
| 387 | // BIOS32 support |
| 388 | EXPORTFUNC bios32_entry |
| 389 | bios32_entry: |
| 390 | pushfl |
| 391 | #if CONFIG_PCIBIOS |
| 392 | // Check for PCI-BIOS request |
| 393 | cmpl $0x49435024, %eax // $PCI |
| 394 | jne 1f |
| 395 | movl $BUILD_BIOS_ADDR, %ebx |
| 396 | movl $BUILD_BIOS_SIZE, %ecx |
| 397 | movl $pcibios32_entry, %edx |
| 398 | xorb %al, %al |
| 399 | jmp 2f |
| 400 | #endif |
| 401 | // Unknown request |
| 402 | 1: movb $0x80, %al |
| 403 | // Return to caller |
| 404 | 2: popfl |
| 405 | lretl |
| 406 | |
Kevin O'Connor | ee4f9ff | 2008-07-05 21:19:10 -0400 | [diff] [blame] | 407 | // 32bit elf entry point |
Kevin O'Connor | c069394 | 2009-06-10 21:56:01 -0400 | [diff] [blame] | 408 | EXPORTFUNC post32 |
Kevin O'Connor | ee4f9ff | 2008-07-05 21:19:10 -0400 | [diff] [blame] | 409 | post32: |
| 410 | cli |
| 411 | cld |
| 412 | lidtl (BUILD_BIOS_ADDR + pmode_IDT_info) |
| 413 | lgdtl (BUILD_BIOS_ADDR + rombios32_gdt_48) |
Kevin O'Connor | e0504b0 | 2009-04-13 19:32:51 -0400 | [diff] [blame] | 414 | movl $SEG32_MODE32_DS, %eax |
| 415 | movw %ax, %ds |
| 416 | movw %ax, %es |
| 417 | movw %ax, %fs |
| 418 | movw %ax, %gs |
| 419 | movw %ax, %ss |
Kevin O'Connor | ee4f9ff | 2008-07-05 21:19:10 -0400 | [diff] [blame] | 420 | movl $BUILD_STACK_ADDR, %esp |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 421 | ljmpl $SEG32_MODE32_CS, $_cfunc32flat__start |
Kevin O'Connor | ee4f9ff | 2008-07-05 21:19:10 -0400 | [diff] [blame] | 422 | |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 423 | .code16gcc |
Kevin O'Connor | 1d01951 | 2008-03-11 21:21:47 -0400 | [diff] [blame] | 424 | |
Kevin O'Connor | 38fcbfe | 2008-02-25 22:30:47 -0500 | [diff] [blame] | 425 | |
| 426 | /**************************************************************** |
Kevin O'Connor | c5b5036 | 2008-12-18 21:56:41 -0500 | [diff] [blame] | 427 | * Interrupt entry points |
| 428 | ****************************************************************/ |
| 429 | |
Kevin O'Connor | 9f193b9 | 2009-05-16 23:31:27 -0400 | [diff] [blame] | 430 | // Main entry point for interrupts without args |
| 431 | DECLFUNC irqentry |
| 432 | irqentry: |
| 433 | ENTRY_ST |
| 434 | iretw |
| 435 | |
| 436 | // Main entry point for interrupts with args |
Kevin O'Connor | eaec3c2 | 2009-05-30 03:40:22 -0400 | [diff] [blame] | 437 | DECLFUNC irqentryarg |
Kevin O'Connor | 9f193b9 | 2009-05-16 23:31:27 -0400 | [diff] [blame] | 438 | irqentryarg: |
| 439 | ENTRY_ARG_ST |
| 440 | iretw |
| 441 | |
Kevin O'Connor | 812478e | 2011-01-22 10:53:48 -0500 | [diff] [blame] | 442 | // Define an entry point for an interrupt (no args passed). |
| 443 | .macro IRQ_ENTRY num |
| 444 | .global entry_\num |
| 445 | entry_\num : |
| 446 | pushl $ handle_\num |
| 447 | jmp irqentry |
| 448 | .endm |
| 449 | |
| 450 | .macro DECL_IRQ_ENTRY num |
| 451 | DECLFUNC entry_\num |
| 452 | IRQ_ENTRY \num |
| 453 | .endm |
| 454 | |
| 455 | // Define an entry point for an interrupt (can read/modify args). |
| 456 | .macro IRQ_ENTRY_ARG num |
| 457 | .global entry_\num |
| 458 | entry_\num : |
| 459 | pushl $ handle_\num |
| 460 | jmp irqentryarg |
| 461 | .endm |
| 462 | |
| 463 | .macro DECL_IRQ_ENTRY_ARG num |
| 464 | DECLFUNC entry_\num |
| 465 | IRQ_ENTRY_ARG \num |
| 466 | .endm |
| 467 | |
| 468 | // Various entry points (that don't require a fixed location). |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 469 | DECL_IRQ_ENTRY_ARG 13 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 470 | DECL_IRQ_ENTRY 76 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 471 | DECL_IRQ_ENTRY 70 |
| 472 | DECL_IRQ_ENTRY 74 |
| 473 | DECL_IRQ_ENTRY 75 |
| 474 | DECL_IRQ_ENTRY hwpic1 |
| 475 | DECL_IRQ_ENTRY hwpic2 |
| 476 | |
Kevin O'Connor | 4ebc0b7 | 2009-03-01 12:31:57 -0500 | [diff] [blame] | 477 | // int 18/19 are special - they reset stack and call into 32bit mode. |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 478 | DECLFUNC entry_19 |
| 479 | entry_19: |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 480 | ENTRY_INTO32 _cfunc32flat_handle_19 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 481 | |
| 482 | DECLFUNC entry_18 |
| 483 | entry_18: |
Kevin O'Connor | f3fe3aa | 2010-12-05 12:38:33 -0500 | [diff] [blame] | 484 | ENTRY_INTO32 _cfunc32flat_handle_18 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 485 | |
| 486 | |
| 487 | /**************************************************************** |
| 488 | * Fixed position entry points |
| 489 | ****************************************************************/ |
| 490 | |
| 491 | // Specify a location in the fixed part of bios area. |
| 492 | .macro ORG addr |
| 493 | .section .fixedaddr.\addr |
| 494 | .endm |
| 495 | |
| 496 | ORG 0xe05b |
| 497 | entry_post_official: |
| 498 | jmp entry_post |
| 499 | |
Kevin O'Connor | c5b5036 | 2008-12-18 21:56:41 -0500 | [diff] [blame] | 500 | ORG 0xe2c3 |
Kevin O'Connor | 75f49b3 | 2009-03-07 00:07:24 -0500 | [diff] [blame] | 501 | IRQ_ENTRY 02 |
Kevin O'Connor | c5b5036 | 2008-12-18 21:56:41 -0500 | [diff] [blame] | 502 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 503 | ORG 0xe3fe |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 504 | .global entry_13_official |
| 505 | entry_13_official: |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 506 | jmp entry_13 |
| 507 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 508 | // 0xe401 - OldFDPT in disk.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 509 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 510 | ORG 0xe6f2 |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 511 | .global entry_19_official |
| 512 | entry_19_official: |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 513 | jmp entry_19 |
| 514 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 515 | // 0xe6f5 - BIOS_CONFIG_TABLE in misc.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 516 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 517 | // 0xe729 - BaudTable in serial.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 518 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 519 | ORG 0xe739 |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 520 | IRQ_ENTRY_ARG 14 |
| 521 | |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 522 | ORG 0xe82e |
| 523 | IRQ_ENTRY_ARG 16 |
| 524 | |
| 525 | ORG 0xe987 |
| 526 | IRQ_ENTRY 09 |
| 527 | |
| 528 | ORG 0xec59 |
| 529 | IRQ_ENTRY_ARG 40 |
| 530 | |
| 531 | ORG 0xef57 |
| 532 | IRQ_ENTRY 0e |
| 533 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 534 | // 0xefc7 - diskette_param_table in floppy.c |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 535 | |
| 536 | ORG 0xefd2 |
| 537 | IRQ_ENTRY_ARG 17 |
| 538 | |
| 539 | ORG 0xf045 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 540 | entry_10_0x0f: |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 541 | // XXX - INT 10 Functions 0-Fh Entry Point |
| 542 | iretw |
| 543 | |
| 544 | ORG 0xf065 |
| 545 | IRQ_ENTRY_ARG 10 |
| 546 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 547 | // 0xf0a4 - VideoParams in misc.c |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 548 | |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 549 | ORG 0xf841 |
Kevin O'Connor | 9f193b9 | 2009-05-16 23:31:27 -0400 | [diff] [blame] | 550 | IRQ_ENTRY_ARG 12 |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 551 | |
| 552 | ORG 0xf84d |
Kevin O'Connor | 9f193b9 | 2009-05-16 23:31:27 -0400 | [diff] [blame] | 553 | IRQ_ENTRY_ARG 11 |
Kevin O'Connor | b4f0e89 | 2008-12-13 18:33:05 -0500 | [diff] [blame] | 554 | |
| 555 | ORG 0xf859 |
| 556 | IRQ_ENTRY_ARG 15 |
| 557 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 558 | // 0xfa6e - vgafont8 in font.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 559 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 560 | ORG 0xfe6e |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 561 | IRQ_ENTRY_ARG 1a |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 562 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 563 | ORG 0xfea5 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 564 | IRQ_ENTRY 08 |
| 565 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 566 | // 0xfef3 - InitVectors in misc.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 567 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 568 | // 0xff00 - BiosCopyright in misc.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 569 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 570 | ORG 0xff53 |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 571 | .global entry_iret_official |
| 572 | entry_iret_official: |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 573 | iretw |
| 574 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 575 | ORG 0xff54 |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 576 | IRQ_ENTRY_ARG 05 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 577 | |
Kevin O'Connor | 7453453 | 2008-05-12 18:28:58 -0400 | [diff] [blame] | 578 | ORG 0xfff0 // Power-up Entry Point |
Kevin O'Connor | 3f168b6 | 2008-11-29 13:22:29 -0500 | [diff] [blame] | 579 | .global reset_vector |
| 580 | reset_vector: |
Kevin O'Connor | d67a703 | 2009-01-17 19:37:26 -0500 | [diff] [blame] | 581 | ljmpw $SEG_BIOS, $entry_post_official |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 582 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 583 | // 0xfff5 - BiosDate in misc.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 584 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 585 | // 0xfffe - BiosModelId in misc.c |
Kevin O'Connor | e3677b1 | 2008-07-04 15:29:23 -0400 | [diff] [blame] | 586 | |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 587 | // 0xffff - BiosChecksum in misc.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 588 | |
| 589 | .end |