Start learning Ucore's lab today.
According to Lab0 's documentation, the 80386 4 working modes are shown: real-address mode, Protected mode, SMM mode, virtual 8086 mode.
Figure 2-3 in the ia-32-architectures-software-developer-system-programming-manual-vol3_feb2014. Transitions among the Processor ' s Operating modes is a 4 mode FSM.
The Ucore programming method is described in section 2.6 of Lab 0: C for the OOP of C + +: interface (API). In the tip of absolute C + + chap 6: Princeple of encapsulation is On:separate "interface" and "Implementation of class".
In http://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm, interface is generally used as the base class with abstract class.
in the http://www.bottomupcs.com/abstration.html details The Linux kernal, system with large C based code. Simulate pointer by using function c+ + The Interface/class of OOP.
The function pointer in the understanding and using pointer in C refers to a drawback: " One concern regarding the use of function pointers is a potentially slower running program. The processor may is able to use branch prediction on conjunction with pipelining. "
This confirms the Ucore lab0: "Core of the object-oriented programming approach, at present, the main use of a similar C + + interface (interface) concept, that is, the implementation of the details of a certain kind of kernel subsystem (such as physical memory allocator, scheduler, file system, etc.) have a common way to operate ... The interface is represented in the C language as a set of function pointers. In C + +, which is a virtual table. ”
First review function pointer, structure in C.
1 /*2 * Function pointers in C as the interface in C + +3 * used widely in Linux kernal, or lab0 of Ucore4 * June 8,5 *6 * http://www.bottomupcs.com/abstration.html#ftn. d5e1167 */8 9#include <stdio.h>Ten One /*The API to implement*/ A structGreet_api { - int(*say_hello) (Char*name); - int(*say_goodbye) (void); the }; - - /*Our implementation of the Hello function*/ - intSAY_HELLO_FN (Char*name) { +printf"Hello%s\n", name); - return 0; + } A at /*Our implementation of the goodbye function*/ - intSAY_GOODBYE_FN (void) { -printf"goodbye\n"); - return 0; - } - in /*A struct implementing the API*/ - /* to * Designated initializers for structures + * See <c Primer plus 5th> - * The name of a function can be used to represent the address of the function the */ * structGreet_api Greet_api = {. Say_hello = Say_hello_fn,. Say_goodbye = $ SAY_GOODBYE_FN};Panax Notoginseng - /*main () doesn ' t need to know anything the * Say_hello/goodbye works, it just knows that it does*/ + intMainintargcChar*argv[]) { AGreet_api.say_hello (argv[1]); the Greet_api.say_goodbye (); + -printf"%p,%p,%p\n", Greet_api.say_hello, SAY_HELLO_FN, &say_hello_fn); $ $ //exit (0); - return 0; -}
Then you can see how Ucore uses structure of function pointer to implement a C + + interface.
The Pmm_manager inside the lab2/kern/mm/pmm.h:
1 //Pmm_manager is a physical memory management class. A Special PMM Manager-xxx_pmm_manager2 //needs to implement the methods in Pmm_manager class, then Xxx_pmm_manager can used3 //By Ucore to manage, the total physical memory space.4 structPmm_manager {5 Const Char*name;//Xxx_pmm_manager ' s name6 void(*init) (void);//Initialize internal description&management data structure7 //(free block list, number of the free block) of Xxx_pmm_manager8 void(*init_memmap) (structPage *Base, size_t N);//Setup description&management Data structcure according to9 //The initial free physical memory spaceTen structPage * (*alloc_pages) (size_t N);//allocate >=n pages, depend on the allocation algorithm One void(*free_pages) (structPage *Base, size_t N);//Free >=n pages with "base" addr of page Descriptor Structures (memlayout.h) Asize_t (*nr_free_pages) (void);//return The number of free pages - void(*check) (void);//Check the correctness of Xxx_pmm_manager - }; the - extern Const structPmm_manager *pmm_manager;
Then, the data structures commonly used in the Ucore are studied in the 2.6.2.1 bidirectional circular list. This is also used in the freelisttable of Uc/os-ii and FreeRTOS.
Note: The Ucore double linked list and the design method inside C/S is somewhat different. This is to accommodate the different functions of the doubly linked list: There are saved task table, there is a list of free memory blocks, or memory pages linked lists and so on.