blob: 98544488f9ad420ba24801719b2d43186e6c04e1 [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
Kevin O'Connor36feea92012-02-11 10:49:45 -050018 .code16gcc
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
43
44/****************************************************************
45 * Entry points
46 ****************************************************************/
47
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050048 // This macro is the same as ENTRY_ARG except the "calll"
49 // instruction is avoided to work around known issues in the
50 // emulation of some versions of x86emu.
51 .macro ENTRY_ARG_VGA cfunc
52 cli
53 cld
54 PUSHBREGS
55 movw %ss, %ax // Move %ss to %ds
56 movw %ax, %ds
57 movl %esp, %ebx // Backup %esp, then zero high bits
58 movzwl %sp, %esp
59 movl %esp, %eax // First arg is pointer to struct bregs
60 pushw %ax ; callw \cfunc
61 movl %ebx, %esp // Restore %esp (including high bits)
62 POPBREGS
63 .endm
64
Kevin O'Connor9961f992012-01-21 11:53:44 -050065 DECLFUNC entry_104f05
66entry_104f05:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050067 ENTRY_ARG_VGA vbe_104f05
Kevin O'Connor9961f992012-01-21 11:53:44 -050068 lretw
69
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040070 DECLFUNC _optionrom_entry
71_optionrom_entry:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050072 ENTRY_ARG_VGA vga_post
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040073 lretw
74
Kevin O'Connor9f193b92009-05-16 23:31:27 -040075 DECLFUNC entry_10
76entry_10:
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050077 ENTRY_ARG_VGA handle_10
Kevin O'Connor9f193b92009-05-16 23:31:27 -040078 iretw
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -050079
80 // Entry point using extra stack
81 DECLFUNC entry_10_extrastack
82entry_10_extrastack:
83 cli
84 cld
85 pushw %ds // Set %ds:%eax to space on ExtraStack
86 pushl %eax
Kevin O'Connorfeb02842013-12-09 20:30:30 -050087 movw %cs:ExtraStackSeg, %ds
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -050088 movl $(CONFIG_VGA_EXTRA_STACK_SIZE-BREGS_size-8), %eax
89 popl BREGS_eax(%eax) // Backup registers
90 popw BREGS_ds(%eax)
91 movl %edi, BREGS_edi(%eax)
92 movl %esi, BREGS_esi(%eax)
93 movl %ebp, BREGS_ebp(%eax)
94 movl %ebx, BREGS_ebx(%eax)
95 movl %edx, BREGS_edx(%eax)
96 movl %ecx, BREGS_ecx(%eax)
97 movw %es, BREGS_es(%eax)
98 movl %esp, BREGS_size+0(%eax)
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -050099 movw %ss, BREGS_size+4(%eax)
Kevin O'Connor41c60612013-12-09 17:27:54 -0500100 popl BREGS_code(%eax)
101 popw BREGS_flags(%eax)
Kevin O'Connor4a8b58c2013-11-30 19:16:15 -0500102
103 movw %ds, %dx // Setup %ss/%esp and call function
104 movw %dx, %ss
105 movl %eax, %esp
106 pushw %ax ; callw handle_10
107
108 movl %esp, %eax // Restore registers and return
109 movw BREGS_size+4(%eax), %ss
110 movl BREGS_size+0(%eax), %esp
111 popl %edx
112 popw %dx
113 pushw BREGS_flags(%eax)
114 pushl BREGS_code(%eax)
115 movl BREGS_edi(%eax), %edi
116 movl BREGS_esi(%eax), %esi
117 movl BREGS_ebp(%eax), %ebp
118 movl BREGS_ebx(%eax), %ebx
119 movl BREGS_edx(%eax), %edx
120 movl BREGS_ecx(%eax), %ecx
121 movw BREGS_es(%eax), %es
122 pushw BREGS_ds(%eax)
123 pushl BREGS_eax(%eax)
124 popl %eax
125 popw %ds
126 iretw