blob: f9624fce2ed9c570d6283b2905f46db52d842599 [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// Rom layout and bios assembler to C interface.
2//
Kevin O'Connordab0a742013-12-03 11:50:49 -05003// Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04004//
5// This file may be distributed under the terms of the GNU LGPLv3 license.
6
7
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -05008#include "asm-offsets.h" // BREGS_*
Julian Pidancet7c6509c2011-12-19 05:07:55 +00009#include "config.h" // CONFIG_*
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040010#include "entryfuncs.S" // ENTRY_*
11
12
13/****************************************************************
14 * Rom Header
15 ****************************************************************/
16
17 .section .rom.header
David Woodhouse67fd42c2014-06-03 17:28:58 +010018 .code16
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040019 .global _rom_header, _rom_header_size, _rom_header_checksum
20_rom_header:
21 .word 0xaa55
22_rom_header_size:
23 .byte 0
24_rom_header_entry:
25 jmp _optionrom_entry
26_rom_header_checksum:
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -050027 .byte 0
28_rom_header_other:
Julian Pidancet7c6509c2011-12-19 05:07:55 +000029 .space 17
30_rom_header_pcidata:
31#if CONFIG_VGA_PCI == 1
32 .word rom_pci_data
33#else
34 .word 0
35#endif
36_rom_header_pnpdata:
37 .word 0
Kevin O'Connor72b5e452011-12-23 23:01:48 -050038_rom_header_other2:
39 .word 0
40_rom_header_signature:
41 .asciz "IBM"
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040042
Gerd Hoffmannf4c6e4c2019-03-08 11:42:25 +010043#if CONFIG_VGA_ATI
44#include "ati-tables.S"
45#endif
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040046
47/****************************************************************
48 * Entry points
49 ****************************************************************/
50
Kevin O'Connor8032b8a2014-02-05 22:47:29 -050051 // This macro implements a call while avoiding instructions
52 // that old versions of x86emu have problems with.
53 .macro VGA_CALLL cfunc
Kevin O'Connor799b20b2015-04-09 17:15:23 -040054#if CONFIG_VGA_FIXUP_ASM
Kevin O'Connor0b2165d2015-04-09 17:20:16 -040055 pushw %ax
Kevin O'Connor8032b8a2014-02-05 22:47:29 -050056 callw \cfunc
Kevin O'Connor799b20b2015-04-09 17:15:23 -040057#else
58 calll \cfunc
59#endif
Kevin O'Connor8032b8a2014-02-05 22:47:29 -050060 .endm
61
62 // This macro is the same as ENTRY_ARG except VGA_CALLL is used.
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050063 .macro ENTRY_ARG_VGA cfunc
64 cli
65 cld
66 PUSHBREGS
67 movw %ss, %ax // Move %ss to %ds
68 movw %ax, %ds
69 movl %esp, %ebx // Backup %esp, then zero high bits
70 movzwl %sp, %esp
71 movl %esp, %eax // First arg is pointer to struct bregs
Kevin O'Connor8032b8a2014-02-05 22:47:29 -050072 VGA_CALLL \cfunc
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050073 movl %ebx, %esp // Restore %esp (including high bits)
74 POPBREGS
75 .endm
76
Kevin O'Connor9961f992012-01-21 11:53:44 -050077 DECLFUNC entry_104f05
78entry_104f05:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050079 ENTRY_ARG_VGA vbe_104f05
Kevin O'Connor9961f992012-01-21 11:53:44 -050080 lretw
81
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040082 DECLFUNC _optionrom_entry
83_optionrom_entry:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050084 ENTRY_ARG_VGA vga_post
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040085 lretw
86
Kevin O'Connor9f193b92009-05-16 23:31:27 -040087 DECLFUNC entry_10
88entry_10:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050089 ENTRY_ARG_VGA handle_10
Kevin O'Connor9f193b92009-05-16 23:31:27 -040090 iretw
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -050091
Kevin O'Connor251e2632015-03-17 11:37:25 -040092#define VGA_CUSTOM_BDA_FLAGS 0xb9
93#define BF_EXTRA_STACK 0x40
94
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -050095 // Entry point using extra stack
96 DECLFUNC entry_10_extrastack
97entry_10_extrastack:
98 cli
99 cld
Kevin O'Connor251e2632015-03-17 11:37:25 -0400100 pushw %ds
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500101 pushl %eax
Kevin O'Connor251e2632015-03-17 11:37:25 -0400102
103 movw $SEG_BDA, %ax // Check if extra stack is enabled
104 movw %ax, %ds
105 testb $BF_EXTRA_STACK, VGA_CUSTOM_BDA_FLAGS
106 jz 1f
107
108 movw %cs:ExtraStackSeg, %ds // Set %ds:%eax to space on ExtraStack
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500109 movl $(CONFIG_VGA_EXTRA_STACK_SIZE-PUSHBREGS_size-16), %eax
Kevin O'Connor46000f52014-10-21 02:23:02 -0400110 SAVEBREGS_POP_DSEAX // Save registers on extra stack
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500111 movl %esp, PUSHBREGS_size+8(%eax)
112 movw %ss, PUSHBREGS_size+12(%eax)
Kevin O'Connor41c60612013-12-09 17:27:54 -0500113 popl BREGS_code(%eax)
114 popw BREGS_flags(%eax)
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500115
116 movw %ds, %dx // Setup %ss/%esp and call function
117 movw %dx, %ss
118 movl %eax, %esp
Kevin O'Connor8032b8a2014-02-05 22:47:29 -0500119 VGA_CALLL handle_10
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500120
121 movl %esp, %eax // Restore registers and return
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500122 movw PUSHBREGS_size+12(%eax), %ss
123 movl PUSHBREGS_size+8(%eax), %esp
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500124 popl %edx
125 popw %dx
126 pushw BREGS_flags(%eax)
127 pushl BREGS_code(%eax)
Kevin O'Connor46000f52014-10-21 02:23:02 -0400128 RESTOREBREGS_DSEAX
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500129 iretw
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400130
Kevin O'Connor251e2632015-03-17 11:37:25 -04001311: // Use regular entry point if the extra stack is disabled
132 popl %eax
133 popw %ds
134 jmp entry_10
135
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400136 // Timer irq handling
137 DECLFUNC entry_timer_hook
138entry_timer_hook:
139 ENTRY handle_timer_hook
140 ljmpw *%cs:Timer_Hook_Resume
141
142 // Timer irq handling on extra stack
143 DECLFUNC entry_timer_hook_extrastack
144entry_timer_hook_extrastack:
145 cli
146 cld
147 pushw %ds // Set %ds:%eax to space on ExtraStack
148 pushl %eax
149 movw %cs:ExtraStackSeg, %ds
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500150 movl $(CONFIG_VGA_EXTRA_STACK_SIZE-PUSHBREGS_size-8), %eax
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400151 SAVEBREGS_POP_DSEAX
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500152 movl %esp, PUSHBREGS_size(%eax)
153 movw %ss, PUSHBREGS_size+4(%eax)
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400154
155 movw %ds, %dx // Setup %ss/%esp and call function
156 movw %dx, %ss
157 movl %eax, %esp
158 calll handle_timer_hook
159
160 movl %esp, %eax // Restore registers and return
Kevin O'Connoraa66d652014-11-05 09:05:36 -0500161 movw PUSHBREGS_size+4(%eax), %ss
162 movl PUSHBREGS_size(%eax), %esp
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400163 RESTOREBREGS_DSEAX
164 ljmpw *%cs:Timer_Hook_Resume