VxWorks startup code Romstart () function analysis

Source: Internet
Author: User
Tags uncompress

VxWorks startup code Romstart () function Analysis

Daniellee_ustb 2013-6-14

qq:382899443

For several days did not learn vxworks, really a little remorse. Often for a variety of reasons to stop the dream runway, the road to work is really full of fetters. Fortunately, the serial server and the completion of critical verification, temporarily, continue to concentrate on learning. Today go to a multiplexer company to understand their products, think they do very well, you can see that no years of accumulation is impossible to achieve such a high level of technology. Personal also, on the road of long-distance running you lazy, slow down, do not want to run, then nothing can be achieved, only adhere to do think of the matter, just do not regret.

To begin with, we began to study the function of Romstart () in bootinit.c.

When Rominit.s executes to the LDR pc, L$_rstrtinrom, it jumps to this location to execute:

L$_rstrtinrom:.long Rom_text_adrs + func (Romstart)-func (Rominit)

It can be seen clearly that Romstart is clearly positioned in RAM, and by the above calculation, the position in the ROM is calculated, and the rominit should correspond to the position of ROMINIT.S in RAM.

Volatilefuncptr Absentry;

Voidfuncptr ramfilllongs = filllongs; /*force Call to RAM */

#definefillLongs (a,b,c) ramfilllongs (a,b,c)

This defines a function pointer ramfilllongs, just a change of name for Filllongs.

Temporarily regardless of the rom_resident type of mirroring, look at the uncompress type.

(1) uncompress

((funcptr) Rom_offset (copylongs)) (Rom_text_adrs, (UINT) Rominit,

Rom_copy_size/sizeof (long));

At this point, the entire image from the ROM that starts with Rom_text_adrs is copied to the Rominit location in RAM, which is easier to understand, and Rominit should be positioned at the Ram_low_adrs point.

(2) COMPRESS

You can see that the main implementation of the two-segment copy of the program, the first paragraph is:

((funcptr) Rom_offset (copylongs)) (Rom_text_adrs, (UINT) Rominit,

(UINT) binarraystart-(UINT) rominit)/sizeof (long));

This part is a copy of the bootstrap, that is, ROMINIT.S and Bootinit compiled uncompressed target file, which is to be executed in RAM;

The second part is:

((funcptr) Rom_offset (copylongs))

(UINT *) ((UINT) Rom_text_adrs + (UINT) Binarrayend_roundoff-

(UINT) rominit), (UINT *) Binarrayend_roundoff,

(UINT) Wrs_kernel_data_end-(UINT) binarrayend)/sizeof (long));

This program actually skips the compressed VxWorks binary, copying the data segment from the top of the binary to the location of the Binarrayend_roundoff in RAM. So it appears that the compressed VxWorks code snippet is left without the decompression copy.

(3) Clear memory

Since the startup type is coldbooting first do not study the rom_resident type image, you can see that the main execution of the three-segment program, the first one is:

Filllongs (UINT *) (Sys_mem_bottom),

(UINT) Rominit-stack_save-(UINT) sys_mem_bottom)/

sizeof (long), 0);

This implements the zeroing of RAM from Sys_mem_bottom to Stack_save.

As shown in the gray section:

--------------0x00100000 = Local_mem_size = Sysmemtop ()

| |

| RAM |

| 0 Filled |

| |

|------------|= (rominit+rom_copy_size) or Binarraystart

| ROM image |

|----------- | 0x00090000 = Ram_high_adrs = Rominit

| Stack_save |

|------------|

|  | 0x00080000 = 0.5 Megabytes

| |

| |

| 0 Filled |

| |

| | 0x00001000 = Ram_adrs &ram_low_adrs

| |

| | Exc vectors, BP anchor, exc msg, bootline

| |

| |

--------------0x00000000 = Local_mem_local_adrs

The second part is for the non-compression mode uncompress, clear a yellow memory.

#if defined (uncompress)

Filllongs (UINT *) ((UINT) Rominit + rom_copy_size),

(UINT) Sys_mem_top-((UINT) rominit +rom_copy_size))

/sizeof (long), 0);

#else

The third part is for compression mode compress:

Filllongs (UINT *) Wrs_kernel_data_end,

(UINT) sys_mem_top-(UINT) wrs_kernel_data_end)/sizeof (long), 0);

#endif/*uncompress * *

Zeroing is the VxWorks data segment to Sys_mem_top's Ram area.

(4) Implementation of the next procedure

For Uncompress way, can go directly to absentry= (FUNCPTR) usrinit;

For the Compress method, perform the decompression program, the binary files from Binarraystart to binarrayend extracted, put to the Ram_dst_adrs location, this time should be located on the Ram_high_adrs.

Volatile funcptrabsuncompress = (funcptr) Uncmp_rtn;

if ((absuncompress) ((uchar*) Rom_offset (Binarraystart),

(UCHAR *) Ram_dst_adrs, binarrayend-binarraystart)! = OK)

Don't worry that the extracted files are too large to put in RAM, because there is (UINT) sys_mem_top-(UINT) Rominit so large that you can put the extracted code in place.

Absentry = (funcptr) Ram_dst_adrs; the entry address of the program is Ram_high_adrs. Finally Through (absentry) (StartType) jump to the corresponding entry function, for compress mode should also go to execute usrinit function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.