1;; ----------------------------------------------------------------------- 2;; 3;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved 4;; Copyright 2009-2010 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 extern pm_api_vector 21 22; 23; Load a COM32 image. A COM32 image is the 32-bit analogue to a DOS 24; .com file. A COM32 image is loaded at address 0x101000, with %esp 25; set to the high end of usable memory. 26; 27; A COM32 image should begin with the magic bytes: 28; B8 FF 4C CD 21, which is "mov eax,0x21cd4cff" in 32-bit mode and 29; "mov ax,0x4cff; int 0x21" in 16-bit mode. This will abort the 30; program with an error if run in 16-bit mode. 31; 32com32_entry equ free_high_memory 33 34 section .text16 35is_com32_image: 36 push si ; Save file handle 37 push eax ; Save file length 38 39 call make_plain_cmdline 40 ; Copy the command line into the low cmdline buffer 41 mov ax,real_mode_seg 42 mov fs,ax 43 mov si,cmd_line_here 44 mov di,command_line 45 mov cx,[CmdLinePtr] 46 inc cx ; Include final null 47 sub cx,si 48 fs rep movsb 49 50 mov si,KernelName 51 mov di,Com32Name 52 call strcpy 53 54 call comboot_setup_api ; Set up the COMBOOT-style API 55 56 mov edi,com32_entry ; Load address 57 pop eax ; File length 58 pop si ; File handle 59 xor dx,dx ; No padding 60 mov bx,abort_check ; Don't print dots, but allow abort 61 call load_high 62 63 mov esi,com32_entry 64 mov edi,trackbuf 65 mov ecx,5 66 call bcopy 67 cmp dword [trackbuf],0xcd4cfeb8 68 jne not_com32r 69 cmp byte [trackbuf+4],0x21 70 jne not_com32r 71 72com32_start: 73 ; 74 ; Point the stack to the end of (permitted) high memory 75 ; 76 mov eax,[HighMemRsvd] 77 xor ax,ax ; Align to a 64K boundary 78 mov [PMESP],eax 79 mov ebx,.pm ; Where to go in PM 80 jmp enter_pm 81 82; 83; This is invoked right before the actually starting the COM32 84; progam, in 32-bit mode... 85; 86 bits 32 87 section .text 88.pm: 89 ; Set up the calling stack frame 90 91 push dword pm_api_vector 92 push dword Com32Name ; Module filename 93 push dword [HighMemSize] ; Memory managed by Syslinux 94 push dword core_cfarcall ; Cfarcall entry point 95 push dword core_farcall ; Farcall entry point 96 push dword (1 << 16) ; 64K bounce buffer 97 push dword core_real_mode ; Bounce buffer address 98 push dword core_intcall ; Intcall entry point 99 push dword command_line ; Command line pointer 100 push dword 9 ; Argument count 101 sti ; Interrupts OK now 102 call com32_entry ; Run the program... 103 ; ... on return, fall through to com32_exit ... 104com32_exit: 105 mov bx,comboot_return 106 jmp enter_rm 107 108 bits 16 109 section .text16 110not_com32r: 111 mov si,KernelName 112 call writestr 113 mov si,not_com32r_msg 114 call writestr 115 jmp enter_command 116 117 section .data16 118not_com32r_msg db ': not a COM32R image', CR, LF, 0 119 120 ; Ersatz com32 invocation structure, to make libcom32 121 ; code run the same if linked to the core. This is in 122 ; the .data16 segment so HighMemSize can live here. 123 ; 124 ; Danger, Will Robinson: it's not clear the use of 125 ; core_xfer_buf is safe here. 126 global __entry_esp, __com32 127 alignz 4 128__entry_esp: 129 dd 0 ; Dummy to avoid _exit issues 130__com32: 131 dd 9 ; Argument count 132 dd 0 ; No command line 133 dd core_intcall ; Intcall entry point 134 dd 0 ; Bounce buffer address 135 dd 0 ; 64K bounce buffer 136 dd core_farcall ; Farcall entry point 137 dd core_cfarcall ; Cfarcall entry point 138HighMemSize dd 0 ; End of memory pointer (bytes) 139 dd 0 ; No module name 140 dd pm_api_vector ; Protected mode functions 141 142 section .uibss 143Com32Name resb FILENAME_MAX 144 145 section .text16 146

