efi: PE file size differ from in-memory size
[syslinux.git] / dos / crt0.S
blob66b52c063e7e8b2871624dee941591e407ee440f
1         .code16
3 #ifndef REGPARM
4 # error "This file assumes -mregparm=3 -DREGPARM=3"
5 #endif
7         .section ".text","ax"
8         .globl _start
9         .type _start,@function
10 _start:
11         # Align the stack and make sure the high half is zero
12         andl $0xfffc,%esp
14         # DS, ES points to the PSP at this point
15         pushw %es               # Save PSP pointer
16         movw %cs,%ax
17         movw %ax,%ds
18         movw %ax,%es
20         # Clear the .bss
21         cld
22         xorl %eax,%eax
23         movw $__bss_start,%di
24         movw $__bss_end+3,%cx
25         subw %di,%cx
26         shrw $2,%cx
27         rep ; stosl
29         # Copy the PSP into our own segment
30         popw %fs                # FS -> PSP
31         movw $_PSP,%di
32         xorw %si,%si
33         movw $0x40,%cx
34         fs ; rep ; movsl
36         # Verify that this is a supportable DOS version
37         movw $0x3001,%ax
38         int $0x21
39         xchgb %ah,%al
40         movw %ax,dos_version
41         cmpw $0x0314,%ax        # DOS >= 3.20?
42         jae 1f                  # If so, okay
43         movw $bad_dos,%dx       # Print error message
44         movb $0x09,%ah
45         int $0x21
46         int $0x20               # Die
49         # Compute argc and argv (assumes REGPARM)
50         pushl %eax              # Make space for argv
51         movl %esp,%eax
52         calll __parse_argv
53         pushl %eax              # argc
55         # Initialize malloc
56         calll __init_memory_arena
58         # Now call main
59         popl %eax               # argc
60         popl %edx               # argv
61         calll main
63         # Here %eax is the exit code, fall through into exit
65         .size _start,.-_start
67         .globl exit
68         .type exit,@function
69 exit:
70         # Exit code already in %eax
71         movb $0x4c,%ah          # Terminate program
72         int $0x21
73 1:      hlt
74         jmp 1b
75         .size exit,.-exit
77         .section ".rodata","a"
78 bad_dos:
79         .ascii "Unsupported DOS version\r\n$"
80         .size bad_dos,.-bad_dos
82         .section ".bss","aw"
83         .balign 16
84         .globl _PSP
85 _PSP:
86         .space 256
87         .size _PSP, .-_PSP
89         /* Purely for sanity */
90         .section ".null","a"
91         .long 0,0,0,0