📄 lx.c
字号:
/*
Copyright 1994-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <dos.h>
#include "langext.h"
#include "defines.h"
#include "types.h"
#include "subs.h"
#include "globals.h"
/*+-------------------------------------------------------------------------+
| |
| enter_lx_Fixup |
| |
+-------------------------------------------------------------------------+*/
void enter_lx_fixup(bit_32 target, bit_32 address, loc_type location)
BeginDeclarations
bit_32 target_object = 0 ;
bit_32 i ;
EndDeclarations
BeginCode
If lxfile.val IsTrue OrIf lefile.val IsTrue
Then
If location IsNotEqualTo offset32_location AndIf location IsNotEqualTo secondary_offset32_location
Then
linker_error(4,"LX Fixup error:\n"
" Error: segment-relative fixups in LX files must be 32 bits\n");
return ;
EndIf ;
If n_lx_fixups IsEqualTo max_lx_fixups
Then
max_lx_fixups += 20 ;
lx_fixup_array = (lx_fixup_hold_ptr_array)reallocate_memory(lx_fixup_array, max_lx_fixups*sizeof(lx_fixup_hold_ptr)) ;
EndIf ;
For i=1; i < n_lx_sections; i++
BeginFor
If target GreaterThanOrEqualTo lx_outList[i]->base
Then
target_object++ ;
Else
ExitLoop ;
EndIf
EndFor ;
lx_fixup_array[n_lx_fixups] = (lx_fixup_hold_ptr)allocate_memory(sizeof(lx_fixup_hold_type));
lx_fixup_array[n_lx_fixups]->offset = address ;
lx_fixup_array[n_lx_fixups]->target = target ;
lx_fixup_array[n_lx_fixups]->target_object = target_object ;
lx_fixup_array[n_lx_fixups++]->type = LX_FM_OFFSET32 ;
EndIf ;
EndCode
/*+-------------------------------------------------------------------------+
| |
| SortFixups |
| |
+-------------------------------------------------------------------------+*/
static void SortLXFixups(void)
BeginDeclarations
bit_32 i,j;
lx_fixup_hold_ptr temp ;
EndDeclarations
BeginCode
For i=0 ; i < n_lx_fixups; i++
BeginFor
For j=i+1; j < n_lx_fixups; j++
BeginFor
If lx_fixup_array[i]->offset > lx_fixup_array[j]->offset
Then
temp = lx_fixup_array[i] ;
lx_fixup_array[i] = lx_fixup_array[j] ;
lx_fixup_array[j] = temp ;
EndIf ;
EndFor ;
EndFor ;
EndCode
/*+-------------------------------------------------------------------------+
| |
| createLXOutputSection |
| |
+-------------------------------------------------------------------------+*/
bit_32 createLXOutputSection(bit_32 flags)
BeginDeclarations
bit_32 rv = n_lx_sections++ ;
EndDeclarations
BeginCode
lx_outList = (lx_section_ptr_array)reallocate_memory(lx_outList,sizeof(lx_section_ptr) * n_lx_sections) ;
lx_outList[rv] = (lx_section_ptr)allocate_memory(sizeof(lx_section_type)) ;
lx_outList[rv]->Flags = flags ;
return rv ;
EndCode
/*+-------------------------------------------------------------------------+
| |
| WriteLXImage |
| |
+-------------------------------------------------------------------------+*/
void write_lx_image(void)
BeginDeclarations
bit_32 i,j,k,l ;
lx_header_ptr lxhead ;
#define LXHead (*lxhead)
lx_object_ptr lxobject ;
#define LXObject (*lxobject)
lx_object_page_ptr lxobjectPage,p ;
#define LXObjectPage (*lxobjectPage)
le_object_page_ptr leobjectPage ;
#define LEObjectPage (*leobjectPage)
lx_fixup_page_ptr lxfixupPage ;
byte_ptr lxfixupRecord =0 ;
byte_ptr headbuf ;
bit_32 stubSize;
byte_ptr stubData;
bit_32 headerStart ;
bit_32 headerSize ;
bit_32 objpagestart ;
bit_32 fixuppagestart ;
bit_32 currentPage = 0 ;
bit_32 size ;
bit_32 xsize ;
bit_32 asize ;
bit_32 current_section = -1 ;
byte fixupbuf[32] ;
bit_32 fixuplen ;
public_entry_ptr import ;
string_ptr stubname ;
segment_entry_ptr seg;
lseg_ptr lseg ;
#define Seg (*seg )
#define Lseg (*lseg)
char buf[260] ;
FILE *fil;
EndDeclarations
BeginCode
ReturnIf (!n_lx_sections) ;
// So we don't write the BSS to the file
If PE_bss_seg IsNotZero
Then
lx_outList[PE_bss_seg]->initlength = 0 ;
EndIf ;
/* create a stack object */
If lx_stack_seg IsZero
Then
i = createLXOutputSection(LX_OF_READABLE | LX_OF_WRITEABLE | LX_OF_ZEROFILL | LX_OF_BIGDEFAULT ) ;
lx_outList[i]->length = stackSize.val ;
next_available_address +=
lx_outList[i]->virtualSize = (stackSize.val + lx_page_size.val -1) & ~(lx_page_size.val -1);
lx_outList[i]->base = first_pe_section_address ;
Else
i = lx_stack_seg ;
EndIf
lx_outList[i]->initlength = 0 ;
first_pe_section_address = next_available_address =
(next_available_address + lx_page_size.val - 1) & ~(lx_page_size.val -1) ;
// LXHead.stack_size = stackSize.val ;
/* load stub32a.exe or whatever they specified */
If stub_file_list.first IsNull
Then
stubname = allocate_string(260) ;
copy_string(stubname, default_lx_stub_string) ;
If lib_directory.val IsNotNull
Then
strcpy(buf,String(stubname)) ;
fil = SearchPath(buf, String(lib_directory.val),"r") ;
If fil IsNotNull
Then
fclose(fil) ;
strcpy(String(stubname),buf) ;
Length(stubname) = strlen(buf) ;
EndIf
EndIf
process_filename(stubname) ;
add_files_to_list(&stub_file_list, stubname);
EndIf ;
load_stub(&stubData,&stubSize);
/* create the basic header */
headerStart = stubSize ;
headerStart+=0x0f;
headerStart&=0xfffffff0; /* align lx header to 8 byte boundary */
headerSize=sizeof(lx_header_type)+n_lx_sections*sizeof(lx_object_type)+headerStart;
headbuf=allocate_memory(headerSize);
memset(headbuf,0,headerSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -