VxWorks startup code romstart () function analysis
Daniellee_ustb
QQ: 382899443
I haven't learned VxWorks for several days, so I really feel a bit regretful. Every time you stop your dream runway for various reasons, the road to work is full of embarrassment. Fortunately, the serial server and the completion of key verification have come to an end for the moment and continue to study hard. Today, I went to a multiplexing company to learn about their products and thought they were doing very well. It can be seen that they could not reach such a high level of technology without years of accumulation. The same is true for individuals. If you are too lazy, slow down, and don't want to run on the long-distance race Road, nothing can be done. You only need to stick to what you think is right, so you don't regret it.
Start to study the romstart () function in bootinit. C.
When rominit. S is executed to ldr pc, L $ _ rstrtinrom, it will jump to this position to execute:
L $ _ rstrtinrom:. Long rom_text_adrs + func (romstart)-func (rominit)
It can be seen that romstart is clearly positioned in Ram. By using the above calculation, the position of rominit in ROM is calculated. 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 to change the name of filllongs.
Check whether the image of the rom_resident type is uncompress.
(1) uncompress
(Funcptr) rom_offset (copylongs) (rom_text_adrs, (uint) rominit,
Rom_copy_size/sizeof (long ));
In this case, copy the entire image from rom_text_adrs to the rominit location in Ram, which is easy to understand. At this time, rominit should be located at ram_low_adrs.
(2) compress
We can see that two program copies are implemented. The first section is:
(Funcptr) rom_offset (copylongs) (rom_text_adrs, (uint) rominit,
(Uint) binarraystart-(uint) rominit)/sizeof (long ));
This part is to copy Bootstrap, that is, rominit. s and the target file that is not compressed after bootinit is compiled. This part should 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 skips the compressed VxWorks binary file and copies the data segment from binarrayend_roundoff at the top of the binary to the position of binarrayend_roundoff in Ram. In this case, the compressed VxWorks code segment is not decompressed and copied.
(3) clear memory
Since the start type is coldbooting, we will not study the rom_resident image first. We can see that three procedures are executed. The first one is:
Filllongs (uint *) (sys_mem_bottom ),
(Uint) rominit-stack_save-(uint) sys_mem_bottom )/
Sizeof (long), 0 );
This enables Ram to be cleared from sys_mem_bottom to stack_save.
Gray:
-------------- 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 uncompress in non-compression mode, the yellow memory segment is cleared.
# 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 compress:
Filllongs (uint *) wrs_kernel_data_end,
(Uint) sys_mem_top-(uint) wrs_kernel_data_end)/sizeof (long), 0 );
# Endif/* uncompress */
It is cleared from the VxWorks data segment to the ram zone of sys_mem_top.
(4) execute the next program
For the uncompress mode, you can directly go to absentry = (funcptr) usrinit; To execute;
For compress mode, run the decompression program to extract the binary file from binarraystart to binarrayend and place it to the ram_dst_adrs location. In this case, you should locate ram_high_adrs.
Volatile funcptrabsuncompress = (funcptr) uncmp_rtn;
If (absuncompress) (uchar *) rom_offset (binarraystart ),
(Uchar *) ram_dst_adrs, binarrayend-binarraystart )! = OK)
There is no need to worry that the extracted files are too large to be stored in Ram, because the unzipped code can be stored in a place as large as (uint) sys_mem_top-(uint) rominit.
Absentry = (funcptr) ram_dst_adrs; at this time, the entry address of the program is ram_high_adrs.
Finally, jump to the corresponding entry function through (absentry) (starttype). For compress mode, you should also execute the usrinit function.