1.
For example # DEFINE _ Library __
There is nothing behind it. What's the use ???
Observe the File Include/unistd. h and you will see # ifdef _ Library __2.
The fork () function generates a new process.
The new process should also start from the current place fork.
3.
C language external variables and external functions
4.
System Call, Embedded Assembly, inline function, C language assembly, mutual call,
5. What is the underline Of the label in assembly language?
Variable definition is a basic problem in mixed programming. C Programs and Assembler-Defined variables can be accessed between each other. When defining a variable in an assembler, you must prefix the variable with an underscore (_) and then use. Global as the global variable. In the C program, it must be described as the extern variable.
Arrays and pointers commonly used in C language can also be easily defined and accessed in Assembler programs. For example, it is used in assembly language. usect defines the global variable _ ac_rslt, which occupies 6*32 characters. It is described as a 6*32 16-bit unsigned two-digit array in the C program. Of course, in assembler, the data storage format must meet the requirements of C for the two-dimensional array data storage format. That is, in the memory, from the low address to the high address, the content of the two-dimensional array is placed in the memory from the first line. In fact, this array definition can also be seen as a pointer definition.
Assembler:
_ Ac_rslt. usect "addata", (6*32)
. Global _ ac_rslt
C program:
Extern int16u ac_rslt [6] [32];
(Extern int16u * ac_rslt ;)
6.
Scheduling implementation principle
Then, call the schedule () function in the system status.
7.
Each program has a kernel stack segment and a user stack segment.
8.
The boot program cannot directly move the program to address 0 because the BIOS Interrupt Processing Program was used to move data from the boot disk to the memory at the beginning. In this case, the disconnection table is stored at address 0.
9. How do I give control from the kernel state to the user State process?
Simulate the interrupt return action and use the iret command.
10. Observe the simplest operating system.
First, the BIOS is responsible for loading the starting part of the kernel into the memory, then the boot is responsible for loading other parts, and then completing some initialization in the mode, then jumping to the program to start running, and setting the interrupt processing program, set the descriptor table. The content of the descriptor table is saved with the TSS attribute of the task, that is, the code position of the task.
Go to the first process and complete the switchover through clock interruption.
The operating system creation process can be as follows:
Write an operating system and place the executable code in the first sector of the boot disk.
Restart the computer, set the BIOS interface, and set the floppy disk as the first boot device. Insert a floppy disk and start the computer from the floppy disk.
11.
Seg cs! Indicates that the next statement is operated in the CIDR Block indicated by the CS segment register.
12. 64 K units related to kernel image reading.
The image file is read in 64 KB, but it does not mean that the kernel image is not stored continuously from the hard disk to the memory. First, because the size of a hard disk is 512 bytes, it is exactly the factor of 64 K. Second, when the kernel bootsect reads data, it is necessary to determine whether it is approaching 64 K. If it exceeds the 64 K, it will calculate how many pieces can be read and then read.
13. What is the relationship between page tables and page Directory items in Linux memory and the storage of kernel internal codes ?? Does it cause a conflict, overwrite it, or start with separation?
The data structures such as gdt and LDT in head. s are also the content of the system image.
For more information, see Linux kernel full notes> p33.
How does the interrupt processing function in Linux reflect the transition from user State to kernel state? Which function implements this function? /
The Int command will trigger the switchover (the switch to interrupt the service program address should be implemented by hardware or BIOS ):
Who changed the code segments, data segments, and stack segments to point them to the kernel state?
As the running level changes, it will switch from the kernel stack in the TSS content that tr points. Remember that the conditions for changing the content of the Shadow register of each register segment are as follows:
Iret command and ret.
INT and iret performed the opposite action.
When executing the int command, the following operations are actually completed:
(1) Since int commands are transferred between different priorities, the core stack information (SS and ESP) with high priority is obtained from TSS (Task status segment) first );
(2) Keep the low-priority stack information (SS and ESP) to the high-priority stack (that is, the core stack;
(3) Push eflags, external CS, and EIP into the high-priority stack (core stack.
(4) Load CS and EIP through IDT (Control Transfer to interrupt processing function)
Then it enters the system_call function that interrupts 0x80.
14. The interrupt handler no_error_code In the ASM. s file: Medium
Push $0
What is the role of Lea 44 (% ESP) and % edX?
Parameters of the interrupt processing function.
15. The paging starts from 0x100000. Does the paging mechanism be used when the kernel is running?
Head. lines p198 in S, with paging code set, put the four page tables of the kernel into the page Directory and fill in the content of the four page tables, finally, the base address register of the page Directory is set to S3. then CR1 is modified to set the PG flag to 1 to enable the paging mechanism.
16. How does one setuid (int uid)> _ syscall _-> setuid (int uid) to pass the parameter transfer method called by the system to the corresponding C processing function? How does a similar interrupt processing C function obtain its parameters?
Observe the kenel/ASM. s file and you can see two inbound stack operations, but the C function of Interrupt Processing has two identical parameters.
Other methods are required for system calls.
The details should be as follows:
_ System_call:
CMPL $ nr_system_calls-1, % eax
Ja bad_sys_call
Push % DS
Push % es
Push % FS
Pushl % edX
Pushl % ECx # Push % EBX, % ECx, % edX as parameters
Pushl % EBX # To the system call
Movl $0x10, % edX # Set up ds, es to kernel space
MoV % dx, % DS
MoV % dx, % es
Movl $0x17, % edX # fs points to local data space
MoV % dx, % FS
Call _ sys_call_table (, % eax, 4)
17. In the showtask function in kenel/sched. C (char *) (p + 1) [I], which address represents the data?
P + 1 does not add one to the number of pointers, but indicates skipping the space pointing to the type length from the current position. For Win32 int, It is 4 bytes;
In addition, the kernel stack is used from the end of the page, so this calculation is correct in the idle stack zone.
The pointer array is defined as int * P [10].
18. Why is it easier for kenel/sched. C to put the floppy drive program here to use the clock?
How to monitor the running time of each process and where the counter is worth modifying? Which interrupt handles the system's scheduled processing?
Do_timer calls schedule;
In this program, do_timer is not executed for the kernel state.
In schedinit (), set_intr_gate (0x20, & timer_interrupt );
Timer_interrupt is located in sytemcall. s
19. How does the knenl/signal. C Signal Processing Mechanism generate signals, store signals, and notify other programs of signals?
There are two sources for the occurrence of a signal event.
One is the hardware (for example, when we press the keyboard), the other is the software (for example, we use system functions or
). The four most commonly used system functions are kill, raise, alarm, and Setit.
The timer function. setitimer function we will learn again in the chapter on timer usage.
This program modifies the signal data structure of other programs (this data structure is saved, but how does other programs know their own data changes?
The signal receiver processes the signal when the system call is completed. For details, see kenel/system_call.s, line 119.
Are all programs called by the system? If a process does not have a system call, how does one handle the signal? What is the time when a system call occurred?
The program runs in the kernel state. For example, if the clock is interrupted, schedule () is called.
You can refer to the interrupt handler for clock interruption timer_interrupt in kenel/system_call.s to find that it is also required for JMP ret_from_sys_call; that is, the signal handler must be executed.
20. How does sigaction save multiple signals?
The sigaction [32] variable in the task_struct structure in include/Linux/sched. h stores the data structure of all signals. init_task variable contains 32 signal initialization.
The signa variable is a bitmap of all 32 signals.
What are the advantages of sig_action () over traditional signal processing signal?
21. how to read and write hard disks?
When a program needs to read and write data, it first sends an application to the buffer management program. If the buffer zone already exists, it directly returns the buffer header pointer to the program and wakes up the program process. Otherwise, ll_rw_block () will be called ().
How can I ensure that all requests are processed in the request list?
Ll_rw_block () uses make_request (); then, in make_request (), add_request () is called to add the request to the Request queue; In add_request (), do_hd_request (); do_hd_request () is called () hd_out () is called to send read and write commands to the Controller. when the process is completed, the interrupt handler is read_intr () and write_intr (), and the two programs call do_hd_request () again (), ensure that all requests can be processed. Refer to the P202 page
22. Why is the master device number called the master device?
The number of sub-or sub-device numbers varies according to the type.
23. When Linux/kenel/blk_dev/BLK. H is included, we can find that define will be performed based on majar_nr.
So before include BLK. H, define majar_nr exists.
24. How do I insert other data into a read request? How can we ensure that the current pointer is not modified in disorder?
Ll_rw_block (). The request is processed only when the request column is empty. Otherwise, only the insert operation is performed.
25. Why is the elevator algorithm just compared? How can we ensure orderliness?
Because all inserts are compared in the same way, it is guaranteed that all the requests before insertion are stored in sequence.
26. Important Thoughts and concepts of Linux
Hardware operation request-to-Column
Program self-copy, system boot
Process Scheduler
System Call
Vector table
Privileged level
27. Get started with the simplest operating system 0.01 and understand an operating system
In early Linux, how did I implement development, program installation, and program execution? A. Out File
28. encapsulate a network client program into a system call and add it to the kernel code.
Compile the kernel to generate the kernel image file, and then install the kernel ?????????????
Convert the formats of executable files.
29. Is a page exception in the Linux Kernel triggered by hardware or software? What is the basis for allocating the physical page size of a process in the kernel? Does exchange refer to internal exchanges in the process or page exchanges at the entire system level?
Page missing interruption is triggered by the CPU.
30. Are the operating procedures related to the file system included by the operating system or the file system?
31. Understanding of Linux virtual memory management, and relationships between concepts such as Cs + EIP, PC, segment selector, segment descriptor, gdt, LDT, page directory, and page table.
Linux Virtual Memory Management: when a program is written, it uses a virtual address or logical address, represented by Cs + EIP;
Virtual Address> linear address> physical address
Cs + EIP is obtained when the program is executed;
Then CS stores the segment selection character;
According to the segment selection operator, you need to find the segment descriptor based on the first address saved by LDT and gdt, and then load it to the Shadow register, which contains the segment base address and segment length and permission information, obtain the linear address based on the information;
Then, based on the paging principle, locate the page Directory, page table, and offset to obtain the physical address.
Commands are stored in the IR (command register). By default, the EIP address is auto-incremented in Cs + EIP. The EIP value can be modified only when the transfer occurs.
For Linux, the linear address is occupied by all processes, and the I process occupies the place where N * 64 m starts.
How can we ensure global sharing of gdt and local independence of LDT? How do I reference them and the code that reflects the sharing of the kernel?
Is the switch operation switched using redirection?
How can I ensure that the same virtual address is not converted to the same physical address, or whether the program can have the same virtual address? When is the so-called virtual address obtained? Is it allocated during compilation or runtime?
Is paging supported by the operating system or hardware? Where is the hardware support reflected?
Paging should be supported by hardware. In the control register, one digit is used to identify whether paging management is enabled. MMU is used to provide paging support.
However, for paging, the operating system also needs to support memory management,
32. How does uboot implement automatic updates? Cover yourself?
In fact, during uboot execution, it is necessary to load from permanent memory (such as flash) into the memory.
If we only copy data to the memory, it can only exist under power supply.
To implement the UPDATE function, you need to copy the new uboot version to flash instead of memory. The uboot in execution is in memory, so it is not a self-overwriting method.
33. When creating a page table, does the process allocate space to all the page tables? How can I find the address of the page on the hard disk when a page is interrupted?
34. What are the features of Memory Management in linux0.11? What new method is used after linux0.99?
In linux0.11, simplified measures are adopted to facilitate memory management. All processes share one page Directory, which means they share the same linear address space. The linear address space must not overlap. linux0.11 uses the following method to avoid overlap.
When assigning a linear address to a process, use the following method: 64 m + nR * 64 m. NR indicates the task number.
After linux0.99, the memory address space usage has changed. Each process can use a 4 GB virtual address space.
Besides, the segment storage is bypassed, that is, all processes point to the code segment and data segment descriptor in the same gdt. LDT is basically not used. All the code segments point to the same base address 0x00000000.
At the same time, three-level ing is adopted logically, while 386 is physical polar ing. The first-level ing in the middle is bypassed by setting the number of bits of PMD to 1.
From the above, we can find out how to ensure that the same linear address is mapped to different physical addresses.
1. The process uses different page Directory tables.
2. The process uses different segment descriptors to make the segment base address different.