|
Blue Forest http://www.lslnet.com at 2:08 p.m. on August 16, 2006
|
|
FreeBSD Kernel initialization code study notes (1)
|
|
FreeBSD Kernel initialization code study notes (1)
Yale Huang
Mailto : goldx@iname.com
FreeBSD Kernel initialization code study notes (1) 1
1. I386/i386/locore.s. 3
2. I386/i386/machdep.c. 4
3. Kern/init_main.c. 5
4. Summary. . . 5
All thanks to Linux, FreeBSD, and GNU utilities, such as Freeware the people who have made contributions.
Recently the FreeBSD Kernel continue studying the initialization code to tidy up a little bit of experience, please correct me.
Due to limitations of the study restricted from beginning for the i386, the other not yet covered platform; The sake of simplicity, there are no details see SMP, KDB have jumped the past, a considerable number of local knowledge is very one-sided. I also saw some of the Linux source, because the Linux source of information to learn more, this knowledge will be very useful for the study of FreeBSD. Taiwan compatriots thinker some six months ago has been written on this part of the document, a great deal of help to these files, see http://cnpa.yzu.edu.tw/~thinker/bsd_kern/, this paper extracts a lot of things in this document.
It is important to point out, from a copy of "FreeBSD startup-code study notes," until now, and I see the initialization process is starting, and the structure and function of many still do not function. I hope it will be sorted out after a rough structure in accordance with the needs and focus of interest in certain parts of a comprehensive look at the source code, I am afraid I have not the power.
I grasped months Global (http://www.tamacom.com/global/) have done a 2.4.16 Linux, FreeBSD 4.3, NetBSD 1.5.2 and Kernel 3.0 OPENBSD the cross reference. But it's good reading source code Eastern also be embedded in emacs, vi Lane use, but HTML to do so if the hard disk on the Linux 2.4.16 too much of a cross reference in the HTML 370MB-- I have them carved R, Three 700MB disc ah.
1. I386/i386/locore.s Thinker's files, the kernel from locoer.s btext started; Procedures really look like, but I could not find any specific Kernel Makefile is the text of the corresponding things, so there is little doubt. Let us here from the start now.
Locoer.s mainly done several things :
1) initialization page catalog (pde) and the page (ptd), and functions such as paging;
2) Call the i386/i386/machdep.c init386 (), re-instated gdt, ldt and slide, initialization terminal, ISA IRQ, random number generator, tss, virtual 8086 mode (vm86) and the message buffer;
3) Call the mi_startup kern/init_main.c (), "has officially entered the core Kernel" (thinker language).
Say light, it would still take a closer look at the effort, part of this initialization paging function, the need to refer to the files from beginning for the i386. I find from the website of the Inter manual can also find some Chinese from other places, "Pentium II-III, technical architecture and expansion" on the very good.
Thinker that needs some attention, I stole some lazy, there are two important, I think, on the copy (not on the number of firms) :
1) 920-923 Bank. map of the page to a page table directory, the first entry. This is a page table will be "temporary" in the page directory map twice. mainly because the actual implementation of the directive to address the physical address. When I started to enable paging, will be a gray area, so we address the values are still in the physical address map, which is not what we had hoped for the KERNBASE base. Therefore, we do this map. to enable paging, can smooth the implementation of the correct code.
2) 932-935 Bank, PDE will be installed in PDE, it is a recursive approach and make the PDE is on the second floor mapping, turn into the page table. so that the page table mapping the original PDE has become the final destination memory. We can read each page directly through a direct mapping table.
2. I386/i386/machdep.c Init386 (), a considerable number of tasks :
1), and re-instated gdt ldt. Count re-established the next slide, boot throwing away a part of the whole thing. Gdt use of the provision is the so-called soft_segment_descriptor gdt_segs from ssdtosd () converted into actual descriptor, so as to avoid a lot of spaces to operate trouble.
2) re-instated slide. Init386 () suspended all its worst first 0-255 IDTVEC (rsvd), and then to set up a 0-18 interruption and disruption descriptor 0x80, 0x80 interrupting system call. And the realization of the very system interrupt 0x80 i386/i386/exception.s China.
3) terminal initialization.
4) to set up default IRQ ISA equipment.
5) initialization random number generator.
6) Identification and CPU initialization.
7) failure to prepare TSS.
8) prepared vm86 environment, the actual allocation of space has not only prepared a corresponding table.
9) getmemsize () computer memory size. Thinker described as follows :
1971 trip getmemsize (), i386/i386/machdep.c, 1,419 firms to identify and calculate the memory is available, and reservations msgbuf. Getmemsize will set up a few global variables.
Physmem the page number actually available.
Maxmem physcial memory address to the maximum.
Phys_avail list of available mem block.
Avail_start by pmap_bootstrap ().
Avail_end largest physcial memory address is available. All this is less than the location of the distribution are essential.
10) initialization msg_buf.
11) set up a re-enter (reenter) Kernel with the door. This is the shift in the ldt LSYS5CALLS_SEL (System V Calls?) segement.h said it is "forced by intel BCS." I did not understand.
3. Kern/init_main.c It was the. Comparing with the init386 (), mi_startup () -- According to the much simpler and sysinit_elem_order system_sub_id sysinit implementation of the sequence of function. Enum:sysinit_sub_id and sysinit_elem_order sys/kernel.h definition of the two, we should pay attention to the SI_SUB_CONSOLE and SI_SUB_SWAP sysinit_sub_id no practical use. Mi_startup () Finally, it should be SI_SUB_RUN_SCHEDULER into sub id for the function. And the sub id SI_SUB_KLD to add a new function in the process of implementing the init function.
Thinker said :
"Mi_startup () linker will use the same section of the initiative to form a continuous block of data characteristics, the initial collection of all sub-system function. This macro function by SYSINIT (). sys/kernel.h, 225 firms reached. mi_startup basis of the information gathered, according to the order of the initial implementation of the sub-system function. sysinit_sub_id definition of the various sub-system implementation of the order. sys/kernel.h, 107 firms, followed by the implementation of mi_startup from small to large. If the same number of initial sub-system function, from sysinit_elem_order, sys/kernel.h, 163 firms. definition of the order of implementation. "
Sysinit the structure is more troublesome, it can be used as a symbol of a particular value end of the array (like string, but elements of a struct). Program structure is scattered when the actual transfer SYSINIT macro structure contains a function pointer, type and priority of struct and insert a section (ELF documents. A.out document processing use. " Stubs "pseudo instructions, gas understand that neither the www.info.gov.hk). This is related to operation and the format of the executable files, the operating system has only a one-off occasion, I think in general with the application or not at all.
4. Summary Mi_startup () call the init function of the many that I have read the beginning, it is estimated that the structure will be watching Kernel out of the side after I was looking at some notes bars.
Juveniles were not perverts live
|
|
|
FreeBSD startup-code study notes (reproduced)
|
|
[From the original Jjksam@smth.org Made -- The writer : gracewind (wind), FreeBSD letter : Title : FreeBSD startup-code study notes (reproduced) Shuimu Tsinghua BBS letter Station : Station (Tue Nov 27 10:56:30 2001)
FreeBSD startup-code study notes (reproduced from linuxforum.net) Yale Huang Mailto:goldx@iname.com
FreeBSD startup-code study notes 1 1. FreeBSD process started 3 2. Analysis 3 2.1. MBR 3 2.1.1. Mbr/mbr.s 3 2.1.2. Boot0/boot0.s 4 2.2. Boot2/boot1.s 4 2.3. Btx/btx/btx.s 5 2.4. Boot2/boot2.c 5 3. 5 Summary
All thanks to Linux, FreeBSD, and GNU utilities, such as Freeware the people who have made contributions.
FreeBSD days learning about the startup code (boot code), and watched "with Linux Nuclear Analysis "V," started Linux system. " Here simply to write about my own understanding of the many biased Department , And request correction on the part of the Linux boot, in the light of the "Linux Kernel Analysis," a book. This paper introduces the boot FreeBSD 4.2 code, because lxr.linux.no (a good source tisicročia Ss reference projects) is the source of the FreeBSD version. If other version is somewhat different I read at home is 4.3, this version of this paper will also talk about some of the some of the contents. If Online reading enough, we can directly access http://lxr.linux.no/freebsd/source/.
Lxr on FreeBSD 4.2 code for the start from beginning for the i386 src/ boot/i386/ are, in my home machines Contents of the document is src/sys/boot/i386/ 4.3.
1. FreeBSD start process The most typical hard disk activated process was as follows : 1) MBR (or do not have any one, I usually do not) A. Mbr/mbr.s simple mbr B. Boot Manager, a simple boot0/boot0.s 2) Sector boot2/boot1.s really started FreeBSD 3) btx/btx/btx.s system initialization, access to protected mode 4) Document and boot2/boot2.c importation Kernel Call Kernel If the software is launched, we should be the first one saved two. Also under the src/ boot/i386/ cdldr, kgzld R, liloldr several catalogs provide other forms of activated; In 4.3, is /usr/src/sys/i386/boo T there biosboot, cdbootboot, netboot, dosboot, rawboot kzipboot and several catalogs mention From different media for the launch. This paper mainly discusses started from the hard disk and floppy disk, and the focus is on 2, 3, 4 steps, and mbr Boot Manager is a common practice, nothing special.
2. Analysis 2.1. MBR 2.1.1. Mbr/mbr.s MBR, not any particular is simply looking for Active district, and Jump into time past. 2.1.2. Boot0/boot0.s A Load Manager, and similar to boot. The district shows a main menu, reading the user's choice to load the Sector and Jump past. The whole process is very clear, but which is very exciting : 290 #
Display routines # 291 292 #
293
Movb $ 294 putkey : 'F', %al # Display 295 callw putchr # 'F' Movb $ 296 '1' %al # Prepare Addb %dl 297, # digit %al Display the rest # 298 jmp putstr.1 299
300 #
Display # 301, and note that the option it is a valid option. 302 # That last point is a bit tricky. . 303 #
304 : btsw %dx putx, _MNUOPT (%bp) # Enable menu option 305 movw $item, %si # Display 306 # key callw putkey Movw %di 307, the rest %si # Display 308
Callw puts putstr # 309 : Display string 310
311 : movw $crlf putn, %si To # next line 312
Get byte # 313 putstr : lodsb 314 testb $ 0x80, %al # End of string? Yes putstr.2 # 315 jnz Callw putchr # 316 : Display char putstr.1 317 # jmp putstr Continue Andb $~0x80 putstr.2 : 318, # Clear %al MSB 319
Save : pushw %bx # 320 putchr Movw $ 321 0x7, %bx # Page:attribute 322 movb $ 0xe, %ah # BIOS : Display 323 int $ 0x10 # character 324 # Restore popw %bx To retw # 325 caller Notes count, 35 lines of code, to achieve six functions (putstr.1 and putstr.2 not).
2.2. Boot2/boot1.s Reading into Boot2 (disklabel+BTX+boot2.bin), and JUMP to BTX. If you have 4.3 source I read here, I suggest you take a look /usr/src/sys/i386/boot/biosboot/README.386BSD , This document to boot1, BTX and boot2 moves a lot, a few key shows.
2.3. Btx/btx/btx.s Dangdang stand out! Staged vital! (Of course, this is not enough and Kernel than the first. But this is the most boot China Important. ) Frankly, I do not know now what BTX is the acronym for less than Google search, also www.FreeBSD.org No. Which colleagues and they know that, taken under the wing of hope. In fact, not only is btx.s 1H part of a document btx/ Under the 1986-1991 Judge btxcsu.s, btxsys.s and btxv86.s also includes a few simple functions. Another btx/bt Xldr catalog, but btx.s btx/btxldr/btxldr.s that it is just a prototype, I do not read more. Btx.s work on the following : the main building and install a protected mode environment, such as IDT, GDT, TTS, the installation of PAGING Acer, but also to create a page (page table. I do not know whether it is useful to the page table, entering 1H 0% will be set up before boot2.c PG, I think Kernel Lane will be another to create a page table, but I did not Kernel have read?) ;btx Also defines the 0x00 - 0x10 (abnormal), 0x20-0x2f (hardware failure), 0x30 (System calls) and 0x31-0x32 (Palapa Call) for the suspension, which will be interrupted by Kernel too, but in the printed Kenerl ago, many have to rely on these suspended work to do; Finally, users btx.s switched to the mode of implementation started Boot2/boot2.c. 0x31 interruption (Palapa Call) is very important, it switched to the Palapa mode from the user mode implementation of the Palapa system call, he Going back to user mode. Boot2.c the I/O entirely interrupt 0x31.
2.4. Boot2/boot2.c As mentioned earlier, before 1H boot2.c progress in the protection mode, the user has entered the model (PG Pagination closed). B Oot2.c users is a model in the implementation of the procedure. Of course, boot2.c and ordinary procedure or different : BIN and caused direct and 1H tied boot1 (README.386BSD mentioned in the link and 1H boot1 And boot2.bin is together, and then separate, boot1 can know the exact address 1H A); No function and the integrity of the system call, and could only rely on the system call 1H. But boot2.c not work, was to show the presentation, receiving user input, the final text included specified Kernel Call 1H interruption and the pieces of 0x30 (exec) implementation Kernel. And Linux main.c, 1H + boot2.c structure is relatively simple, is still not very clear to me. Printk included in the Linux kernel before it useful. In the boot of main.c ago, I could not find where Call The register_console the printk.c. If that does not, then the output is not on the main.c See?
3. Summary The FreeBSD boot code is quite clear that a number of issues and I hope it will be left to further study kern After el find the answers
|
|