123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811 |
-
-
- FILE_LICENCE ( GPL2_OR_LATER )
-
- #include <config/general.h>
-
- #define PNP_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
- #define PMM_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'M' << 16 ) + ( 'M' << 24 ) )
- #define PCI_SIGNATURE ( 'P' + ( 'C' << 8 ) + ( 'I' << 16 ) + ( ' ' << 24 ) )
- #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
- #define PMM_ALLOCATE 0x0000
- #define PMM_FIND 0x0001
- #define PMM_HANDLE_BASE ( ( ( 'F' - 'A' + 1 ) << 26 ) + \
- ( ( 'E' - 'A' + 1 ) << 21 ) + \
- ( ( 'N' - 'A' + 1 ) << 16 ) )
- #define PMM_HANDLE_BASE_IMAGE_SOURCE \
- ( PMM_HANDLE_BASE | 0x00001000 )
- #define PMM_HANDLE_BASE_DECOMPRESS_TO \
- ( PMM_HANDLE_BASE | 0x00002000 )
-
-
- #define ROM_BANNER_TIMEOUT ( 2 * ( 18 * BANNER_TIMEOUT ) / 10 )
-
-
- #if ROMPREFIX_EXCLUDE_PAYLOAD
- #define ZINFO_TYPE_ADxB "ADHB"
- #define ZINFO_TYPE_ADxW "ADHW"
- #else
- #define ZINFO_TYPE_ADxB "ADDB"
- #define ZINFO_TYPE_ADxW "ADDW"
- #endif
-
- .text
- .code16
- .arch i386
- .section ".prefix", "ax", @progbits
- .globl start
- start:
-
- .org 0x00
- romheader:
- .word 0xAA55
- romheader_size: .byte 0
- jmp init
- checksum:
- .byte 0
- .org 0x16
- .word undiheader
- .org 0x18
- .word pciheader
- .org 0x1a
- .word pnpheader
- .size romheader, . - romheader
-
- .section ".zinfo.fixup", "a", @progbits
- .ascii ZINFO_TYPE_ADxB
- .long romheader_size
- .long 512
- .long 0
- .previous
-
- build_id:
- .long _build_id
-
- pciheader:
- .ascii "PCIR"
- .word pci_vendor_id
- .word pci_device_id
- .word 0x0000
- .word pciheader_len
- .byte 0x03
- .byte 0x02, 0x00, 0x00
- pciheader_image_length:
- .word 0
- .word 0x0001
- .byte 0x00
- .byte 0x80
- pciheader_runtime_length:
- .word 0
- .word 0x0000
- .word 0x0000
- .equ pciheader_len, . - pciheader
- .size pciheader, . - pciheader
-
- .section ".zinfo.fixup", "a", @progbits
- .ascii ZINFO_TYPE_ADxW
- .long pciheader_image_length
- .long 512
- .long 0
- .ascii ZINFO_TYPE_ADxW
- .long pciheader_runtime_length
- .long 512
- .long 0
- .previous
-
- pnpheader:
- .ascii "$PnP"
- .byte 0x01
- .byte ( pnpheader_len / 16 )
- .word 0x0000
- .byte 0x00
- .byte 0x00
- .long 0x00000000
- .word mfgstr
- .word prodstr
- .byte 0x02
- .byte 0x00
- .byte 0x00
- .byte 0xf4
- .word 0x0000
- .word 0x0000
- .word bev_entry
- .word 0x0000
- .word 0x0000
- .equ pnpheader_len, . - pnpheader
- .size pnpheader, . - pnpheader
-
-
- mfgstr:
- .asciz "http://ipxe.org"
- .size mfgstr, . - mfgstr
-
-
- prodstr:
- .ascii PRODUCT_SHORT_NAME
- prodstr_separator:
- .byte 0
- .ascii "(PCI "
- prodstr_pci_id:
- .asciz "xx:xx.x)"
- .size prodstr, . - prodstr
-
- .globl undiheader
- .weak undiloader
- undiheader:
- .ascii "UNDI"
- .byte undiheader_len
- .byte 0
- .byte 0
- .byte 0,1,2
- .word undiloader
- .word _data16_memsz
- .word _data16_memsz
- .word _text16_memsz
- .ascii "PCIR"
- .equ undiheader_len, . - undiheader
- .size undiheader, . - undiheader
-
-
- init:
-
- pushaw
- pushw %ds
- pushw %es
- pushw %fs
- pushw %gs
- cld
- pushw %cs
- popw %ds
-
-
-
- movw %bx, %gs
- movw %di, %bx
-
-
- movw %ax, init_pci_busdevfn
-
-
- movw $init_message, %si
- xorw %di, %di
- call print_message
- call print_pci_busdevfn
-
-
- movw $prodstr_pci_id, %di
- call print_pci_busdevfn
- movb $( ' ' ), prodstr_separator
-
-
- movb $( ' ' ), %al
- xorw %di, %di
- call print_character
- movw %cs, %ax
- call print_hex_word
-
-
- pushl %ebx
- pushl %edx
- pushl %edi
- stc
- movw $0xb101, %ax
- int $0x1a
- jc no_pci3
- cmpl $PCI_SIGNATURE, %edx
- jne no_pci3
- testb %ah, %ah
- jnz no_pci3
- movw $init_message_pci, %si
- xorw %di, %di
- call print_message
- movb %bh, %al
- call print_hex_nibble
- movb $( '.' ), %al
- call print_character
- movb %bl, %al
- call print_hex_byte
- cmpb $3, %bh
- jb no_pci3
-
- movw %gs, %ax
- cmpw $0xa000, %ax
- jb pci3_insane
- movw %cs, %bx
- cmpw %bx, %ax
- je 1f
- movzbw romheader_size, %cx
- shlw $5, %cx
- addw %cx, %bx
- cmpw %bx, %ax
- jae 1f
- movw %cs, %bx
- addw %cx, %ax
- cmpw %bx, %ax
- jbe 1f
- pci3_insane:
- movb $( '!' ), %al
- call print_character
- movw %gs, %ax
- call print_hex_word
- no_pci3:
-
- pushw %cs
- popw %gs
- 1: popl %edi
- popl %edx
- popl %ebx
-
-
-
- movw $( 0xf000 - 1 ), %bx
- pnp_scan:
- incw %bx
- jz no_pnp
- movw %bx, %es
- cmpl $PNP_SIGNATURE, %es:0
- jne pnp_scan
- xorw %dx, %dx
- xorw %si, %si
- movzbw %es:5, %cx
- 1: es lodsb
- addb %al, %dl
- loop 1b
- jnz pnp_scan
-
- movw $init_message_pnp, %si
- xorw %di, %di
- call print_message
- jmp pnp_done
- no_pnp:
- movw $init_message_int19, %si
- xorw %di, %di
- call print_message
- xorw %ax, %ax
- movw %ax, %es
- pushl %es:( 0x19 * 4 )
- popl orig_int19
- pushw %gs
- pushw $int19_entry
- popl %es:( 0x19 * 4 )
- pnp_done:
-
-
- movw $( 0xe000 - 1 ), %bx
- pmm_scan:
- incw %bx
- jz no_pmm
- movw %bx, %es
- cmpl $PMM_SIGNATURE, %es:0
- jne pmm_scan
- xorw %dx, %dx
- xorw %si, %si
- movzbw %es:5, %cx
- 1: es lodsb
- addb %al, %dl
- loop 1b
- jnz pmm_scan
-
- movw $init_message_pmm, %si
- xorw %di, %di
- call print_message
-
- pushal
-
- movzwl image_source_len_pgh, %ecx
- movl $PMM_HANDLE_BASE_IMAGE_SOURCE, %ebx
- movw $get_pmm_image_source, %bp
- call get_pmm
- movl %esi, image_source
- jc 1f
-
- pushw %es
- xorw %ax, %ax
- movw %ax, %es
- movl %esi, %edi
- xorl %esi, %esi
- movzbl romheader_size, %ecx
- shll $9, %ecx
- addr32 rep movsb
- popw %es
-
- movb shrunk_rom_size, %al
- movb %al, romheader_size
- 1:
-
- movl $_textdata_memsz_pgh, %ecx
- addl $0x00001fff, %ecx
- andl $0xffffe000, %ecx
- movl %ecx, %ebx
- shrw $12, %bx
- orl $PMM_HANDLE_BASE_DECOMPRESS_TO, %ebx
- movw $get_pmm_decompress_to, %bp
- call get_pmm
- movl %esi, decompress_to
-
- popal
- no_pmm:
-
-
- xorw %bx, %bx
- xorw %si, %si
- movzbw romheader_size, %cx
- shlw $9, %cx
- 1: lodsb
- addb %al, %bl
- loop 1b
- subb %bl, checksum
-
-
-
- movb $( ' ' ), %al
- xorw %di, %di
- call print_character
- movw %gs, %ax
- call print_hex_word
- movzbw romheader_size, %cx
- shlw $9, %cx
- movw %ax, %es
- xorw %si, %si
- xorw %di, %di
- cs rep movsb
-
-
- movw $init_message_prompt, %si
- xorw %di, %di
- call print_message
- movw $prodstr, %si
- call print_message
- movw $init_message_dots, %si
- call print_message
-
- movw $0xff02, %bx
- call wait_for_key
-
- pushf
- xorw %di, %di
- call print_kill_line
- movw $init_message_done, %si
- call print_message
- popf
- jnz 2f
-
-
- stc
- pushw %cs
- call exec
- 2:
-
- popw %gs
- popw %fs
- popw %es
- popw %ds
- popaw
-
-
- movw $0x20, %ax
- lret
- .size init, . - init
-
-
- get_pmm:
-
- pushl %eax
- pushw %di
- movw $' ', %di
- get_pmm_find:
-
- pushl %ebx
- pushw $PMM_FIND
- lcall *%es:7
- addw $6, %sp
- pushw %dx
- pushw %ax
- popl %esi
- testl %esi, %esi
- jz get_pmm_allocate
-
- call *%bp
- jnc get_pmm_done
-
- incl %ebx
- jmp get_pmm_find
- get_pmm_allocate:
-
- pushw $0x0002
- pushl %ebx
- pushl %ecx
- pushw $PMM_ALLOCATE
- lcall *%es:7
- addw $12, %sp
- pushw %dx
- pushw %ax
- popl %esi
- movw $'+', %di
- testl %esi, %esi
- jnz get_pmm_done
- stc
- get_pmm_done:
-
- pushfw
- movw %di, %ax
- xorw %di, %di
- call print_character
- movl %esi, %eax
- call print_hex_dword
- popfw
-
- popw %di
- popl %eax
- ret
- .size get_pmm, . - get_pmm
-
-
- get_pmm_image_source:
- pushw %es
- xorw %ax, %ax
- movw %ax, %es
- movl build_id, %eax
- addr32 cmpl %es:build_id(%esi), %eax
- je 1f
- stc
- 1: popw %es
- ret
- .size get_pmm_image_source, . - get_pmm_image_source
-
-
- get_pmm_decompress_to:
- clc
- ret
- .size get_pmm_decompress_to, . - get_pmm_decompress_to
-
-
- init_message:
- .ascii "\n"
- .ascii PRODUCT_NAME
- .ascii "\n"
- .asciz "iPXE (http://ipxe.org) "
- .size init_message, . - init_message
- init_message_pci:
- .asciz " PCI"
- .size init_message_pci, . - init_message_pci
- init_message_pnp:
- .asciz " PnP"
- .size init_message_pnp, . - init_message_pnp
- init_message_pmm:
- .asciz " PMM"
- .size init_message_pmm, . - init_message_pmm
- init_message_int19:
- .asciz " INT19"
- .size init_message_int19, . - init_message_int19
- init_message_prompt:
- .asciz "\nPress Ctrl-B to configure "
- .size init_message_prompt, . - init_message_prompt
- init_message_dots:
- .asciz "..."
- .size init_message_dots, . - init_message_dots
- init_message_done:
- .asciz "\n\n"
- .size init_message_done, . - init_message_done
-
-
- init_pci_busdevfn:
- .word 0xffff
- .size init_pci_busdevfn, . - init_pci_busdevfn
-
-
- .globl image_source
- image_source:
- .long 0
- .size image_source, . - image_source
-
-
- image_source_len_pgh:
- .word 0
- .size image_source_len_pgh, . - image_source_len_pgh
- .section ".zinfo.fixup", "a", @progbits
- .ascii "ADDW"
- .long image_source_len_pgh
- .long 16
- .long 0
- .previous
-
-
- shrunk_rom_size:
- .byte 0
- .size shrunk_rom_size, . - shrunk_rom_size
- .section ".zinfo.fixup", "a", @progbits
- .ascii "ADHB"
- .long shrunk_rom_size
- .long 512
- .long 0
- .previous
-
-
- .globl decompress_to
- decompress_to:
- .long 0
- .size decompress_to, . - decompress_to
-
-
- bev_entry:
- clc
- pushw %cs
- call exec
- lret
- .size bev_entry, . - bev_entry
-
-
- int19_entry:
- pushw %cs
- popw %ds
-
- movw $int19_message_prompt, %si
- xorw %di, %di
- call print_message
- movw $prodstr, %si
- call print_message
- movw $int19_message_dots, %si
- call print_message
- movw $0xdf4e, %bx
- call wait_for_key
- pushf
- xorw %di, %di
- call print_kill_line
- movw $int19_message_done, %si
- call print_message
- popf
- jz 1f
-
-
- clc
- pushw %cs
- call exec
- 1:
- movl %cs:orig_int19, %eax
- testl %eax, %eax
- je 2f
- ljmp *%cs:orig_int19
- 2:
- int $0x18
- .size int19_entry, . - int19_entry
- orig_int19:
- .long 0
- .size orig_int19, . - orig_int19
-
- int19_message_prompt:
- .asciz "Press N to skip booting from "
- .size int19_message_prompt, . - int19_message_prompt
- int19_message_dots:
- .asciz "..."
- .size int19_message_dots, . - int19_message_dots
- int19_message_done:
- .asciz "\n\n"
- .size int19_message_done, . - int19_message_done
-
-
- exec:
- pushw %cs
- popw %ds
-
-
- lahf
-
-
- movw $prodstr, %si
- xorw %di, %di
- call print_message
- movw $exec_message_pre_install, %si
- call print_message
-
-
- pushl $STACK_MAGIC
- movw %ss, %dx
- movw %sp, %bp
-
-
- xorw %bx, %bx
- movw %bx, %ss
- movw $0x7c00, %sp
-
-
- sahf
- pushfw
- call alloc_basemem
- popfw
- movl image_source, %esi
- movl decompress_to, %edi
- call install_prealloc
-
-
- movw $exec_message_post_install, %si
- xorw %di, %di
- call print_message
-
-
- movw %bx, %ss
- movw $_estack16, %sp
-
-
- pushw %ax
- pushw $1f
- lret
- .section ".text16", "awx", @progbits
- 1:
- pushl $main
- pushw %cs
- call prot_call
- popl %ecx
-
-
- call uninstall
-
-
- movw %dx, %ss
- movw %bp, %sp
-
-
- popl %eax
- cmpl $STACK_MAGIC, %eax
- jne 1f
-
- lret
- 1:
- int $0x18
- .previous
-
- exec_message_pre_install:
- .asciz " starting execution..."
- .size exec_message_pre_install, . - exec_message_pre_install
- exec_message_post_install:
- .asciz "ok\n"
- .size exec_message_post_install, . - exec_message_post_install
-
-
- wait_for_key:
-
- pushw %cx
- pushw %ax
- 1:
- movb $0x01, %ah
- int $0x16
- jz 2f
- xorw %ax, %ax
- int $0x16
- jmp 1b
- 2:
- movw $ROM_BANNER_TIMEOUT, %cx
- 3: decw %cx
- js 99f
-
- call wait_for_tick
-
- movb $0x01, %ah
- int $0x16
- jz 3b
-
- andb %bh, %al
- cmpb %al, %bl
- je 99f
-
- pushfw
- xorw %ax, %ax
- int $0x16
- popfw
- 99:
- popw %ax
- popw %cx
- ret
- .size wait_for_key, . - wait_for_key
-
-
- wait_for_tick:
- pushl %eax
- pushw %fs
- movw $0x40, %ax
- movw %ax, %fs
- movl %fs:(0x6c), %eax
- 1: pushf
- sti
- hlt
- popf
- cmpl %fs:(0x6c), %eax
- je 1b
- popw %fs
- popl %eax
- ret
- .size wait_for_tick, . - wait_for_tick
|