|
<<<sh-lilo sequence>>>
Apr. 25, 2001
Masahiro ABE<mailto:[email protected]>
(C) 2001 A&D; Co., Ltd. <http://www.aandd.co.jp>
--------------------------------------------------------------------------------
0. Table of contents
1. Preface
2. What is sh-lilo?
3. Memory Map
4. Sequence of System Start-up
4.1 First Stage Loader - start (first.S)
4.2 Second Stage Loader - start (second.c)
--------------------------------------------------------------------------------
1. Preface
This document is the result of analysis of execution sequence of "sh-lilo" by
reading source code. "sh-lilo" is used as LILO(LInux LOader) among GNU/Linux on
SuperH project.
This is written based on source code of sh-lilo (2025/11/26).
This document must contain many wrong, misunderstood information because of
lack of knowledge of the author. When you find them, please kindly notify me.
This document is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. Author assumes no responsibility to the contents of this document.
Anyone can display and/or copy the document for any purpose.
All explanation is based on the case that SolutionEngine(MS7750SE01) of Hitachi
ULSI Systems Co. Ltd., is used and executed from CompactFlash
I would like to appreciate everyone on the GNU/Linux on SuperH project, and
especially Mr. NIIBE Yutaka who is the author of sh-ipl+g.
--------------------------------------------------------------------------------
2. What is sh-lilo?
sh-lilo is a code fragment, used as a kernel loader on GNU/Linux on SuperH
system. It is located at MBR(Master Boot Record) of IDE hard disk or Compact
Flash and /boot/boot.b
MBR has the first stage loader. boot.b has the second stage loader.
(Actually boot.b contains both first and secont loaders, but first stage loader
is copied to MBR by lilo, and executed there.)
(???Is second stage loader really executed in boot.b???)
--------------------------------------------------------------------------------
3. Memory Map
first.S contains information about memory map as a comment. It is like this:
Contents Offset Size Offset in first.S
--------------------------------------------------------------------------------
Code of 1st stage loader 0x0000 - 01ff 0x0200 ---
Stack area 0x0200 - 0fff 0x0e00 ---
Code of 2nd stage loader 0x1000 - 1fff 0x1000 ---
Reserved 0x2000 - 2fff 0x1000 ---
Map information 0x3000 - 31ff 0x0200 ---
1st descriptor table 0x3200 - 33ff 0x0200 24
2nd descriptor table 0x3400 - 35ff 0x0200 29
Default command line 0x3600 - 37ff 0x0200 34
Keyboard translation table 0x3800 - 39ff 0x0200 47
Message table 0x3a00 - 3bff 0x0200 40 + 2
"Offset in first.S" is the offset to the information that specify each sector,
embedded int 1st stage loader and written to MBR. "start"(second.c) uses this
information to load each sector from secondary storage.
Here is the summary of memory map, together with the one of sh-ipl+g.
external mem. P1 area media contents
0x 0000 0000 0x 8000 0000----------------------------------------------------
FlashROM code of start(entry.S)
0x 0000 0100 0x 8000 0100 --------------------------------
exception handler(general_exception)
0x 0000 0400 0x 8000 0400 --------------------------------
exception handler(tlb_miss)
0x 0000 0600 0x 8000 0600 --------------------------------
exception handler(interrupt)
exception handling table
actual handler code
code of main.c
0x 0400 0000 0x 8400 0000----------------------------------------------------
0x 0c00 0000 0x 8c00 0000----------------------------------------------------
RAM global variable of sh-ipl+g
0x 0c00 0a00 0x 8c00 0a00 --------------------------------
stack area of sh-ipl+g
0x 0c00 0f00 0x 8c00 0f00 --------------------------------
0x 0c00 1000 0x 8c00 1000 --------------------------------
Parameters for the kernel
0x 0c00 1100 0x 8c00 1100 --------------------------------
Command line for the kernel
0x 0c00 2000 0x 8c00 2000 --------------------------------
0x 0c20 0000 0x 8c20 0000 --------------------------------
code of lilo 1st stage loader
0x 0c20 0200 0x 8c20 0200 --------------------------------
lilo stack area
0x 0c20 1000 0x 8c20 1000 --------------------------------
code of lilo 2nd stage loader
0x 0c20 2000 0x 8c20 2000 --------------------------------
lilo reserved area
0x 0c20 3000 0x 8c20 3000 --------------------------------
lilo map information
0x 0c20 3200 0x 8c20 3200 --------------------------------
lilo 1st descriptor table
0x 0c20 3400 0x 8c20 3400 --------------------------------
lilo 2nd descriptor table
0x 0c20 3600 0x 8c20 3600 --------------------------------
lilo Default command line
0x 0c20 3800 0x 8c20 3800 --------------------------------
lilo Keyboard translation table
0x 0c20 3a00 0x 8c20 3a00 --------------------------------
lilo Message table
0x 0c20 3c00 0x 8c20 3c00 --------------------------------
0x 0c21 0000 0x 8c21 0000 --------------------------------
Kernel will be loaded here
0x 1000 0000 0x 9000 0000----------------------------------------------------
--------------------------------------------------------------------------------
4. Sequence of System Start-up
IPL(Initial Program Loader), like sh-ipl+g, reads MBR into certain address of
memory, and jumps into there for execution.
when lilo command is executed, 1st stage loader of sh-lilo is written to MBR.
So, control starts at 1st stage loader code.
4.1 First Stage Loader - start (first.S)
1st stage loader must fit into single sector size in MBR, and can't do much job
by itself. It simply loads 2nd stage loader from certain location of disk into
memory.
Here is the flow of control.
-Calculate the address where 1st stage loader loaded, and store it in r12
-r15=r12+0x1000, set the stack area
-enable cache by BIOS call
-output "L" char by BIOS call
-load 2nd stage loader from the disk into r12+1000 area
-flush cache by BIOS call
-jump to 2nd stage loader, pass r12 as argument
4.2 Second Stage Loader - start (second.c)
Function start() gets executed as a 2nd stage loader since second.lds specifies
as "ENTRY(start)". Control flows like this.
-output "I" char by BIOS call
-load 1st descriptor table into offset 0x3200
-load 2nd descriptor table into offset 0x3400
-output "L" char by BIOS call
-load default command line into offset 0x3600
-load keyboard translation table into offset 0x3800
-output "O" char by BIOS call
-output "boot:" string by BIOS call
-output "first-image\n" string by BIOS call
-output "Loading " string by BIOS call
-output image name in desc. table by BIOS call
-load kernel image into offset 0x10000, using map info (using offset 0x3000 area)
"." is output for each map info, and "done.\n" when all image gets loaded
-prepare parameters for the kernel in offset -0x1ff000
-prepare command line for the kernel in offset -0x1fef00
-flush cache
-jump to offset 0x1000, thus starts execution of loaded kernel image
|
|