Merge branch 'master' into core32
[profile/ivi/syslinux.git] / core / com32.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;;   Copyright 2009 Intel Corporation; author: H. Peter Anvin
5 ;;
6 ;;   This program is free software; you can redistribute it and/or modify
7 ;;   it under the terms of the GNU General Public License as published by
8 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;;   (at your option) any later version; incorporated herein by reference.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;;
15 ;; com32.inc
16 ;;
17 ;; Common code for running a COM32 image
18 ;;
19
20 ;
21 ; Load a COM32 image.  A COM32 image is the 32-bit analogue to a DOS
22 ; .com file.  A COM32 image is loaded at address 0x101000, with %esp
23 ; set to the high end of usable memory.
24 ;
25 ; A COM32 image should begin with the magic bytes:
26 ; B8 FF 4C CD 21, which is "mov eax,0x21cd4cff" in 32-bit mode and
27 ; "mov ax,0x4cff; int 0x21" in 16-bit mode.  This will abort the
28 ; program with an error if run in 16-bit mode.
29 ;
30 com32_entry     equ     free_high_memory
31
32                 section .text16
33 is_com32_image:
34                 push si                 ; Save file handle
35                 push eax                ; Save file length
36
37                 call make_plain_cmdline
38                 ; Copy the command line into the low cmdline buffer
39                 mov ax,real_mode_seg
40                 mov fs,ax
41                 mov si,cmd_line_here
42                 mov di,command_line
43                 mov cx,[CmdLinePtr]
44                 inc cx                  ; Include final null
45                 sub cx,si
46                 fs rep movsb
47
48                 call comboot_setup_api  ; Set up the COMBOOT-style API
49
50                 mov edi,com32_entry     ; Load address
51                 pop eax                 ; File length
52                 pop si                  ; File handle
53                 xor dx,dx               ; No padding
54                 mov bx,abort_check      ; Don't print dots, but allow abort
55                 call load_high
56
57                 mov esi,com32_entry
58                 mov edi,trackbuf
59                 mov ecx,5
60                 call bcopy
61                 cmp dword [trackbuf],0xcd4cfeb8
62                 jne not_com32r
63                 cmp byte [trackbuf+4],0x21
64                 jne not_com32r
65
66 com32_start:
67                 ;
68                 ; Point the stack to the end of (permitted) high memory
69                 ;
70                 mov eax,[HighMemRsvd]
71                 xor ax,ax                       ; Align to a 64K boundary
72                 mov [PMESP],eax
73                 mov ebx,.pm                     ; Where to go in PM
74                 jmp enter_pm
75
76 ;
77 ; This is invoked right before the actually starting the COM32
78 ; progam, in 32-bit mode...
79 ;
80                 bits 32
81                 section .text
82 .pm:
83                 ; Set up the calling stack frame
84
85                 push dword [HighMemSize]        ; Memory managed by Syslinux
86                 push dword core_cfarcall        ; Cfarcall entry point
87                 push dword core_farcall         ; Farcall entry point
88                 push dword (1 << 16)            ; 64K bounce buffer
89                 push dword (xfer_buf_seg << 4)  ; Bounce buffer address
90                 push dword core_intcall         ; Intcall entry point
91                 push dword command_line         ; Command line pointer
92                 push dword 7                    ; Argument count
93                 sti                             ; Interrupts OK now
94                 call com32_entry                ; Run the program...
95                 ; ... on return, fall through to com32_exit ...
96 com32_exit:
97                 mov bx,.rm
98                 jmp enter_rm
99
100                 bits 16
101                 section .text16
102 .rm:
103                 mov dword [PMESP],__stack_end   ; Stop use of COM32 stack
104                 sti
105                 jmp enter_command
106
107 not_com32r:
108                 mov si,KernelCName
109                 call writestr
110                 mov si,not_com32r_msg
111                 call writestr
112                 jmp enter_command
113
114                 section .data16
115 not_com32r_msg  db ': not a COM32R image', CR, LF, 0