CN115934213A - Controller stack calling method, device, equipment and storage medium - Google Patents

Controller stack calling method, device, equipment and storage medium Download PDF

Info

Publication number
CN115934213A
CN115934213A CN202211693888.2A CN202211693888A CN115934213A CN 115934213 A CN115934213 A CN 115934213A CN 202211693888 A CN202211693888 A CN 202211693888A CN 115934213 A CN115934213 A CN 115934213A
Authority
CN
China
Prior art keywords
target
function
stack
address
read
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211693888.2A
Other languages
Chinese (zh)
Inventor
宋维
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Hollysys Automation Co Ltd
Original Assignee
Hangzhou Hollysys Automation Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Hollysys Automation Co Ltd filed Critical Hangzhou Hollysys Automation Co Ltd
Priority to CN202211693888.2A priority Critical patent/CN115934213A/en
Publication of CN115934213A publication Critical patent/CN115934213A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Stored Programmes (AREA)

Abstract

The application discloses a controller stack calling method, a controller stack calling device and a storage medium, which relate to the field of industrial control and comprise the following steps: writing preset type function data of a current execution function into a target stack space of an industrial controller, writing target function parameters into a reserved stack space in a read-only segment of a preset executable program, compiling to generate a machine code, and linking to generate a corresponding executable file; determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file; and reading the target function parameters through the loading address, and operating the current execution function by using the read target function parameters and preset type function data so as to execute corresponding industrial control operation. According to the method and the device, the function parameters are put into the read-only section during compiling, and the read-only section data is accessed through repositioning, so that the problem that the controller cannot operate when the parameters occupying space larger than stack space are transmitted is solved.

Description

Controller stack calling method, device, equipment and storage medium
Technical Field
The present invention relates to the field of industrial control, and in particular, to a method, an apparatus, a device, and a storage medium for calling a controller stack.
Background
The engineering program run by the controller in the industrial public duty system is from configuration software of an upper computer, wherein common function parameter transfer in the configuration program needs to occupy a program stack, the function stack used for simple data type parameter transfer is small, but the parameter sizes of a structure type and a data group type are unpredictable, so that the function stack can be occupied by parameters used by one function.
The controller in the industrial control system belongs to an embedded device, the internal resources are limited, and the program stack is very small, but as the control program is more and more complex, more and more complex data transmission is required. In the prior art, the number of parameters of the function and the calling depth of the function are limited to prevent the function stack from exceeding the maximum value; or the function stack is enlarged by upgrading the existing hardware, and the capability of supporting parameter transfer is increased, so that the controller operates normally, which causes the performance of the controller to be limited and increases the use cost, therefore, how to handle the problem of the function stack for parameter transfer in the parameter transfer process of the structure and the array type, and how to realize the complex data transfer requirement becomes an urgent problem to be solved in the field of industrial control.
Disclosure of Invention
In view of this, an object of the present invention is to provide a method, an apparatus, a device, and a storage medium for calling a controller stack, which can put a function stack into a read-only segment of an executable program during a compilation process, access a data area of the read-only segment in a relocation manner to replace occupation of the function stack, solve a problem of stack data transfer at a compilation level, and ensure normal operation of a control system. The specific scheme is as follows:
in a first aspect, the present application provides a controller stack calling method, which is applied to an industrial controller, and includes:
writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain a target executable program;
compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code;
determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file;
and reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space so as to execute corresponding industrial control operation.
Optionally, before writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program, the method further includes:
determining the occupied space of the function parameter corresponding to the current execution function;
judging whether the occupied space exceeds a preset threshold value, if so, screening target function parameters exceeding the preset threshold value from the function parameters; and the preset threshold is set according to the stack out-of-range condition of the target stack space.
Optionally, the writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program includes:
and writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program in a mode of modifying a compiler code of the preset executable program.
Optionally, the compiling the target executable program to generate a machine code includes:
and updating a preset object file according to the target function parameter written into the reserved stack space to obtain a target object file, and compiling the target executable program based on the target object file to generate a machine code.
Optionally, the process of linking the machine code to generate a corresponding executable file includes:
and reading the target object file, and generating a repositioning code corresponding to the target function parameter based on the target object file.
Optionally, the linking the machine code to generate a corresponding executable file includes:
and setting a tracking process stack instruction in a preset link script at the initial address of a read-only segment in the machine code and linking to generate a corresponding executable file.
Optionally, the address of the target function parameter in the reserved stack space is the first address of the reserved stack space;
correspondingly, the determining the address of the target function parameter in the reserved stack space as the load address of the target executable program includes:
and determining the initial address of the reserved stack space as the loading address of the target executable program, and updating the address of the read-only segment in the executable file to be the loading address according to the tracking process stack instruction.
In a second aspect, the present application provides a controller stack calling apparatus, applied to an industrial controller, including:
the data writing module is used for writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain the target executable program;
the program compiling module is used for compiling the target executable program to generate a machine code and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code;
an address determining module, configured to determine, according to the relocation code in the executable file, an address of the target function parameter in the reserved stack space as a load address of the target executable program;
and the function running module is used for reading the target function parameters in the reserved stack space through the loading address and running the current execution function by using the read target function parameters and the preset type function data in the target stack space so as to execute corresponding industrial control operation.
In a third aspect, the present application provides an electronic device comprising a processor and a memory; wherein the memory is configured to store a computer program that is loaded and executed by the processor to implement the aforementioned controller stack call method.
In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program which, when executed by a processor, implements the aforementioned controller stack call method.
In the application, writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain the target executable program; compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code; determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file; and reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space to execute corresponding industrial control operation. Therefore, the function stack is placed in the read-only section of the executable program in the compiling process, the data area of the read-only section is accessed in a repositioning mode to replace the occupation of the function stack, the limitation of parameter specification limitation on the configuration flexibility of the control system is avoided, the problem of equipment cost increase caused by hardware upgrading is solved, the problem of stack data transmission is solved in the compiling level, the normal operation of the control system is ensured, meanwhile, a small amount of stack space can be used for running the program, and flexible configuration is supported.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of a controller stack calling method provided in the present application;
FIG. 2 is a flow chart of a controller stack call provided herein;
FIG. 3 is a specific controller stack call flow diagram provided herein;
FIG. 4 is a flow chart of controller code execution provided herein;
FIG. 5 is a flowchart of a specific controller stack invocation method provided herein;
FIG. 6 is a flow chart of a specific controller code execution provided herein;
fig. 7 is a schematic diagram illustrating a controller stack relocation process according to the present application;
fig. 8 is a schematic structural diagram of a controller stack call apparatus provided in the present application;
fig. 9 is a block diagram of an electronic device provided in the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In an industrial control system, as a control program becomes complicated, more complicated data transfer is required, but the stack size of a controller is determined, and thus as a data occupation space gradually increases, the operation of the controller gradually becomes unstable. The parameter specification limitation in the prior art can ensure the normal operation of the program, but limits the configuration flexibility, and the cost is increased due to hardware upgrade. According to the method and the device, the function stack is placed in the read-only section of the executable program in the compiling process, the data area of the read-only section is accessed in a repositioning mode to replace the occupation of the function stack, the problem of stack data transmission is solved in the compiling layer, and a small amount of stack space can be used for program operation.
Referring to fig. 1, an embodiment of the present invention discloses a controller stack calling method, which is applied to an industrial controller, and includes:
and S11, writing preset type function data corresponding to the current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain the target executable program.
It can be understood that, during the running process of the program in the controller, the parameter and the return value of each running function and the local variable occupy the stack space of the system, and the stack size of the controller is determined, and the maximum value of the program stack inside the industrial controller, i.e. the controller in the industrial control system, is small, and the parameter of the function is changed according to the logic of the program configuration, so the maximum value of the stack space of the controller can be easily and quickly reached in the configuration. For example, if the size of the stack space corresponding to the control code of the controller is 64K, a function parameter of 64K being passed through at this time may cause the controller to fail to operate normally. As shown in fig. 2, if there is a function call chain a (·) and B (·) and C (·), and the currently executed function is C, the controller may operate normally only if the parameter that function B delivers to C is guaranteed to be less than 64K, but it is usually difficult to do in practical situations.
Therefore, in this embodiment, the preset type function data corresponding to the current execution function may be written into the target stack space of the industrial controller, and the target function parameter corresponding to the current execution function may be written into the reserved stack space in the read-only segment of the preset executable program by modifying the compiler code of the preset executable program, so as to obtain the target executable program. It is understood that the preset type function data may be preset by a programmer, i.e. a type of function parameter which usually occupies a small space, such as the local variable of the function and the return value of the function in fig. 3. And writing the function parameters transferred between the functions into a reserved stack space in a read-only section of the preset executable program. It should be noted that, before writing the function parameter into the reserved stack space in the read-only segment of the preset executable program, the occupied space of the function parameter corresponding to the currently executed function may be determined first; then judging whether the occupied space of the function parameters exceeds a preset threshold value or not, and if so, screening target function parameters exceeding the preset threshold value from the function parameters; the preset threshold value can be set according to a stack out-of-bounds condition of the target stack space. It can be understood that, on this basis, the occupied space of the preset type function data may also be judged, and the specific parameter type for judgment may be set according to different function operating conditions, which is not discussed in detail in this embodiment. By writing the target function parameter with the occupied space exceeding the preset threshold into the reserved stack space in the read-only section of the preset executable program, the problem that the controller cannot normally operate when the function parameter with the occupied space exceeding the stack space is transmitted can be avoided, the type of the function parameter written into the reserved stack space in the read-only section of the executable program can be flexibly controlled, and the function parameter can be more flexibly stored.
S12, compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code.
In this embodiment, as shown in fig. 4, when a code is to be changed into an executable program and complete execution, it is necessary to compile to generate a machine code, then link the machine code into an executable file, and load the executable file into a memory by a loader for execution. In this embodiment, after the target stack used by the currently executed function is placed in the read-only section of the executable program in the compiling process, the relocation code is generated from the information to be relocated, that is, the target function parameter written in the reserved stack space in the read-only section of the preset executable program, in the linking process, and the linking of the machine code is completed on the basis. And generating relocation codes so as to determine the addresses of the parameters of the target function through the relocation codes in the subsequent loading phase to execute program operation.
And S13, determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file.
In this embodiment, as shown in fig. 3, the address of the target function parameter stored in the reserved stack space is determined as the load address of the target executable program according to the relocation code.
And S14, reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space to execute corresponding industrial control operation.
In this embodiment, the target function parameter in the reserved stack space is read according to the loading address determined in the above steps, for example, as shown in fig. 3, when the function a finishes running, the parameter to be transferred to the function B is obtained, at this time, the parameter to be transferred is not directly stored in the target stack, but the parameter to be transferred, that is, the target function parameter is stored in the reserved stack space, and the stored corresponding address is determined as the loading address of the target executable program, so that after the function B receives the address transferred by the function a, the target function parameter is read according to the received address to finish running. By transferring the corresponding addresses of the function parameters among the functions instead of directly transferring the function parameters, the space use of a target stack is effectively reduced, the brute force expansion of the stack space is reduced, and the normal operation of the controller when the function parameters occupying a larger space are transferred can be ensured.
Therefore, in the embodiment, the preset type function data corresponding to the current execution function is written into the target stack space of the industrial controller, and the target function parameter corresponding to the current execution function is written into the reserved stack space in the read-only segment of the preset executable program, so that the target executable program is obtained; compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code; determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file; and reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space to execute corresponding industrial control operation. By the technical scheme, the stack space of the service code can be compressed in a controllable specification range, the size of the used stack space is controlled according to the specification of the program, the read-only segment is placed in the internal memory of the service code, which belongs to the stack space, so that the program can be prevented from being tampered, and the brute force expansion of the service stack is limited by the specification.
Based on the previous embodiment, the target function parameter corresponding to the current execution function can be written into the reserved stack space in the read-only segment of the preset executable program to reduce the consumption of the target stack space, and next, the specific method for reading the function parameter in the reserved stack space will be described in detail in this embodiment. Referring to fig. 5, an embodiment of the present application discloses a controller stack calling method, including:
and S21, writing preset type function data corresponding to the current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain the target executable program.
And S22, updating a preset object file according to the target function parameter written into the reserved stack space to obtain a target object file, and compiling the target executable program based on the target object file to generate a machine code.
In this embodiment, if a function parameter in a reserved stack space is to be read, data of a target function parameter of a read-only segment needs to be modified into a load address of an executable program in a relocation stage, as shown in fig. 6, information that needs to be relocated, that is, the target function parameter written into the reserved stack space is put into a preset object file in a compilation stage of the program, and it can be understood that the preset object file, that is, an o file, is to write the target function parameter into a text segment and a data segment in fig. 6, and the target executable program is compiled based on the target object file to generate a machine code, so that a relocation code is generated based on the information that needs to be relocated in a linking process.
Step S23, reading the target object file in the machine code, generating a relocation code corresponding to the target function parameter based on the target object file, and setting a tracking process stack instruction in a preset link script at a start address of a read-only segment in the machine code and linking the tracking process stack instruction to generate a corresponding executable file.
In this embodiment, a relocation code corresponding to the target function parameter is generated based on the target object file, then a start address of a read-only segment of a process stack instruction in the machine code is tracked in a linking process, as shown in fig. 7, a start address of a g _ pStack instruction in the read-only segment is specified in a linking script, and a corresponding executable file is generated, so that a program is executed by specifying a loading address as a first address of a reserved stack space through the g _ pStack instruction.
Step S24, according to the relocation code in the executable file, determining the first address of the reserved stack space as the loading address of the target executable program, and updating the address of the read-only segment in the executable file to be the loading address according to the tracking process stack instruction.
In this embodiment, the address of the target function parameter in the reserved stack space is the first address of the reserved stack space. Therefore, in the relocation process before the target executable program runs, the function can run normally by modifying the address of the read-only segment into the first address of the reserved stack space based on the g _ pStack instruction.
And S25, reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space to execute corresponding industrial control operation.
In this embodiment, for more specific processing procedures of the steps S21 and S25, reference may be made to corresponding contents disclosed in the foregoing embodiments, and details are not repeated here.
Therefore, in this embodiment, the preset type function data corresponding to the current execution function is written into the target stack space, and the target function parameter is written into the reserved stack space in the read-only segment of the preset executable program, so as to obtain the target executable program. And updating the preset object file according to the target function parameters to obtain a target object file, and compiling based on the target object file to generate a machine code. Reading a target object file in the machine code, generating a relocation code, and setting a tracking process stack instruction in a starting address of a read-only segment in the machine code in a preset link script to generate a corresponding executable file. And according to the relocation code in the executable file, determining the first address of the reserved stack space as a loading address of the target executable program, and updating the address of the read-only segment in the executable file into the loading address according to the tracking process stack instruction. And reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and preset type function data in the target stack space to execute corresponding industrial control operation. The method changes the parameter transmission mode into the pointer transmission mode in the compiling process, stores the function parameters to the designated position, namely, the reserved stack space stored by the read-only memory is used for storing the target function parameters, and then the program loading address is set by tracking the process stack instruction to complete the function execution, so that the normal operation of the controller can be completed by using a small amount of stack space, and the flexible configuration of the controller is realized.
Referring to fig. 8, an embodiment of the present application further discloses a controller stack calling apparatus, which is applied to an industrial controller, and includes:
the data writing module 11 is configured to write preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and write target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program, so as to obtain a target executable program;
a program compiling module 12, configured to compile the target executable program to generate a machine code, and link the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code;
an address determining module 13, configured to determine, according to the relocation code in the executable file, an address of the target function parameter in the reserved stack space as a loading address of the target executable program;
and the function running module 14 is configured to read the target function parameter in the reserved stack space through the load address, and run the current execution function by using the read target function parameter and the preset type function data in the target stack space, so as to execute a corresponding industrial control operation.
In this embodiment, writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain a target executable program; compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code; determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file; and reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space so as to execute corresponding industrial control operation. Therefore, by the technical scheme, the function stack can be placed in the read-only section of the executable program in the compiling process, the data area of the read-only section is accessed to replace the occupation of the function stack in a repositioning mode, the problem of stack data transmission is solved in the compiling layer, the normal operation of a control system is ensured, a small amount of stack space can be used, and flexible configuration is supported.
In some embodiments, the data writing module 11 further includes:
the space determining unit is used for determining the occupied space of the function parameter corresponding to the current execution function;
the space judgment unit is used for judging whether the occupied space exceeds a preset threshold value or not, and if so, screening target function parameters exceeding the preset threshold value from the function parameters; and the preset threshold is set according to the stack out-of-bounds condition of the target stack space.
In some embodiments, the data writing module 11 specifically includes:
and the parameter writing unit is used for writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program in a mode of modifying a compiler code of the preset executable program.
In some embodiments, the program compiling module 12 specifically includes:
and the file updating unit is used for updating a preset object file according to the target function parameter written into the reserved stack space to obtain a target object file, and compiling the target executable program based on the target object file to generate a machine code.
In some embodiments, the program compiling module 12 specifically includes:
and the code generation module is used for reading the target object file and generating a relocation code corresponding to the target function parameter based on the target object file.
In some embodiments, the program compiling module 12 specifically includes:
and the instruction setting unit is used for setting the tracking process stack instruction in the starting address of the read-only segment in the machine code in a preset link script and linking the tracking process stack instruction to generate a corresponding executable file.
In some specific embodiments, the address determining module 13 specifically includes:
and the address determining unit is used for determining the first address of the reserved stack space as the loading address of the target executable program, and updating the address of the read-only segment in the executable file to be the loading address according to the tracking process stack instruction.
Further, an electronic device is disclosed in the embodiments of the present application, and fig. 9 is a block diagram of an electronic device 20 according to an exemplary embodiment, which should not be construed as limiting the scope of the application.
Fig. 9 is a schematic structural diagram of an electronic device 20 according to an embodiment of the present disclosure. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input output interface 25, and a communication bus 26. Wherein, the memory 22 is used for storing a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the controller stack calling method disclosed in any of the foregoing embodiments. In addition, the electronic device 20 in the present embodiment may be specifically an electronic computer.
In this embodiment, the power supply 23 is configured to provide a working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and an external device, and a communication protocol followed by the communication interface is any communication protocol applicable to the technical solution of the present application, and is not specifically limited herein; the input/output interface 25 is configured to obtain external input data or output data to the outside, and a specific interface type thereof may be selected according to specific application requirements, which is not specifically limited herein.
In addition, the storage 22 is used as a carrier for storing resources, and may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage manner may be a transient storage manner or a permanent storage manner.
The operating system 221 is used for managing and controlling each hardware device on the electronic device 20 and the computer program 222, and may be Windows Server, netware, unix, linux, or the like. The computer programs 222 may further include computer programs that can be used to perform other specific tasks in addition to the computer programs that can be used to perform the controller stack calling methods disclosed by any of the foregoing embodiments and executed by the electronic device 20.
Further, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program when executed by a processor implements the controller stack call method disclosed above. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the foregoing embodiments, which are not described herein again.
In the present specification, the embodiments are described in a progressive manner, and each embodiment focuses on differences from other embodiments, and the same or similar parts between the embodiments are referred to each other. The device disclosed in the embodiment corresponds to the method disclosed in the embodiment, so that the description is simple, and the relevant points can be referred to the description of the method part.
Those of skill would further appreciate that the various illustrative components and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the components and steps of the various examples have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The technical solutions provided by the present application are introduced in detail above, and specific examples are applied in the present application to explain the principles and embodiments of the present application, and the descriptions of the above examples are only used to help understanding the method and the core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A controller stack calling method is applied to an industrial controller and comprises the following steps:
writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain a target executable program;
compiling the target executable program to generate a machine code, and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code;
determining the address of the target function parameter in the reserved stack space as the loading address of the target executable program according to the relocation code in the executable file;
and reading the target function parameters in the reserved stack space through the loading address, and operating the current execution function by using the read target function parameters and the preset type function data in the target stack space so as to execute corresponding industrial control operation.
2. The controller stack call method according to claim 1, wherein before writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program, the method further comprises:
determining the occupied space of the function parameter corresponding to the current execution function;
judging whether the occupied space exceeds a preset threshold value, if so, screening target function parameters exceeding the preset threshold value from the function parameters; and the preset threshold is set according to the stack out-of-range condition of the target stack space.
3. The controller stack call method according to claim 1, wherein writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program includes:
and writing the target function parameter corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program in a mode of modifying a compiler code of the preset executable program.
4. The controller stack call method as recited in claim 1, wherein said compiling the target executable to generate machine code comprises:
and updating a preset object file according to the target function parameter written into the reserved stack space to obtain a target object file, and compiling the target executable program based on the target object file to generate a machine code.
5. The method according to claim 4, wherein the linking the machine code to generate the corresponding executable file comprises:
and reading the target object file, and generating a repositioning code corresponding to the target function parameter based on the target object file.
6. The controller stack call method of any of claims 1 to 5, wherein said linking the machine code to generate a corresponding executable file comprises:
and setting a tracking process stack instruction in a preset link script at the initial address of a read-only segment in the machine code and linking to generate a corresponding executable file.
7. The controller stack call method according to claim 6, wherein the address of the target function parameter in the reserved stack space is a head address of the reserved stack space;
correspondingly, the determining the address of the target function parameter in the reserved stack space as the load address of the target executable program includes:
and determining the initial address of the reserved stack space as the loading address of the target executable program, and updating the address of the read-only segment in the executable file to be the loading address according to the tracking process stack instruction.
8. A controller stack calling device applied to an industrial controller comprises:
the data writing module is used for writing preset type function data corresponding to a current execution function into a target stack space of the industrial controller, and writing target function parameters corresponding to the current execution function into a reserved stack space in a read-only segment of a preset executable program to obtain the target executable program;
the program compiling module is used for compiling the target executable program to generate a machine code and linking the machine code to generate a corresponding executable file; the executable file comprises relocation code generated based on the target function parameters in the machine code;
an address determining module, configured to determine, according to the relocation code in the executable file, an address of the target function parameter in the reserved stack space as a load address of the target executable program;
and the function running module is used for reading the target function parameters in the reserved stack space through the loading address and running the current execution function by using the read target function parameters and the preset type function data in the target stack space so as to execute corresponding industrial control operation.
9. An electronic device, comprising a processor and a memory; wherein the memory is for storing a computer program that is loaded and executed by the processor to implement the controller stack call method of any of claims 1 to 7.
10. A computer-readable storage medium for storing a computer program which, when executed by a processor, implements the controller stack call method of any one of claims 1 to 7.
CN202211693888.2A 2022-12-28 2022-12-28 Controller stack calling method, device, equipment and storage medium Pending CN115934213A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211693888.2A CN115934213A (en) 2022-12-28 2022-12-28 Controller stack calling method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211693888.2A CN115934213A (en) 2022-12-28 2022-12-28 Controller stack calling method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115934213A true CN115934213A (en) 2023-04-07

Family

ID=86697735

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211693888.2A Pending CN115934213A (en) 2022-12-28 2022-12-28 Controller stack calling method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115934213A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116521576A (en) * 2023-05-11 2023-08-01 上海合见工业软件集团有限公司 EDA software data processing system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116521576A (en) * 2023-05-11 2023-08-01 上海合见工业软件集团有限公司 EDA software data processing system
CN116521576B (en) * 2023-05-11 2024-03-08 上海合见工业软件集团有限公司 EDA software data processing system

Similar Documents

Publication Publication Date Title
US7657886B1 (en) Mobile device with a MMU for faster firmware updates in a wireless network
US7246346B2 (en) System and method for persisting dynamically generated code in a directly addressable and executable storage medium
JP2005509194A (en) Method and apparatus for creating and using pre-internalized program files
CN103810416A (en) Software installation or uninstallation method and device
JP2004530201A (en) Methods for loading and running applications in embedded environments
CN111427596B (en) Software upgrading method and device and terminal equipment
KR20070057666A (en) System and method for providing monolithic image for use in a wireless device
US6665671B2 (en) System and method for optimization of shared data
CN115934213A (en) Controller stack calling method, device, equipment and storage medium
CN104731622A (en) Application program loading method and device and mobile terminal
CN104699503A (en) Method and device for replacing function execution logic in Android system
US8099724B2 (en) Fast patch-based method calls
CN112199109B (en) Firmware upgrading method, device, equipment and medium
JP2007510211A (en) Mapping dynamic link libraries on computer equipment
CN109254787A (en) Service logic variation, device, storage medium and electronic equipment
US20070016744A1 (en) Memory management in a portable data carrier
KR100745256B1 (en) Code overlay method in the embedded system
CN108958795B (en) BootLoader code reuse method and development board in embedded system
CN110990018B (en) Compiling method and compiling system of embedded system
KR100478463B1 (en) Dynamic Linking Method for Application Program
CN110162311A (en) It is a kind of using installation method, the generation method of application installation package
CN103645925A (en) Method and device for running webpage applications in mobile terminal operating system
KR100727627B1 (en) Method for supporting application using dynamic linking library and system using the method
CN111221535B (en) Thread allocation method, server and computer readable storage medium
CN112486570B (en) Glibc compatible method for CPUs of different types

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination