Set Up Physical Memory Layout, Buffer Memory, Ramdisk, and

Một phần của tài liệu The art of linux kernel design (Trang 61 - 64)

2. Device Initialization and Process 0 Activation 45

2.2 Set Up Physical Memory Layout, Buffer Memory, Ramdisk, and

Second, the kernel begins to set buffer memory, ramdisk, and main memory. The CPU and the memory need to work together to execute computation. As memory is an important component in computing, the layout of the buffer and the main memory fundamentally determines the amount of memory and mode used by all processes, which will surely affect the computing speed of the process.

The layout is as follows: except for memory space occupied by the kernel code and data, the rest of the physical memory is divided into three main parts: main memory,

//Code path:init/main.c:

……

#define DRIVE_INFO (*(struct drive_info *)0x90080)//Disk parameter //table, see

//system data

#define ORIG_ROOT_DEV (*(unsigned short *)0x901FC)//root device id

……

struct drive_info {char dummy[32];} drive_info; //The structure stores //disk parameter table void main(void)

{

ROOT_DEV = ORIG_ROOT_DEV;//According to the system data written //by bootsect

drive_info = DRIVE_INFO;//the root device is floppy disk

……

}

buffer memory, and the ramdisk. The main memory is the place where the process code resides, and it also contains the data structure that the kernel uses to arrange the process;

the buffer memory is mainly used as the data transfer station between the host and periph- erals; the ramdisk is optional. If the ramdisk is to be used, the data in peripherals should be copied to the ramdisk at first. Since data operating speed in memory is higher than that in peripherals, system performance can be improved in this manner.

As discussed, the OS sets the size, location, and management mode of these three dif- ferent regions in the memory.

According to the size of the memory, the location and size of the buffer and main memory are initialized first (Figure 2.2).

Kernel

ROM BIOS

and VGA Disable

interrupt

0x00000 0x9FFFF 0xFFFFF 0x3FFFFF 0x5FFFFF 0xFFFFFF

Kernel code area Kernel data area

Kernel code area Kernel data area ROOT_DEV

(0x1a964) drive_info

(0x1dd6c)

drive_info (0x1dd6c) ROOT_DEV

(0x1a964) Before backup

After backup Machine system data (0x90000)

Machine system data (0x90000)

Mem addr Len Name

0x90000 0x90002 0x90004 0x90006 0x90007 0x90008 0x9000A 0x9000B 0x9000C

...

0x90080 0x90090 0x901FC

2 22 1 1 21 1 2 16

Cursor position

Extended memory number Display page

Display mode

Character column number Display memory

Display state

Characteristic parameter Cursor position Disk parameter table Disk parameter table Root device number 16

2

Mem addr Len Name

0x90000 0x90002 0x90004 0x90006 0x90007 0x90008 0x9000A 0x9000B 0x9000C

...

0x90080 0x90090 0x901FC

2 22 11 21 1 2 16

Cursor position

Extended memory number Display page

Display mode

Character column number

???Display memory Display state

Characteristic parameter Cursor position Disk parameter table Disk parameter table Root device number 16

2

Figure 2.1 Copy root device number and disk parameter table.

The execution code is as follows:

Memory_end is the end of effective memory; the exceeding part is not visible to the OS. Main_memory_start is the starting position of the main memory. Buffer_memory_end

Disable interrupt Based on the actual size of physical memory, the usage of memory should be designed accordingly

0xFFFFF 0x3FFFFF

0x00000 0x1FFFFF 0xBFFFFF 0xFFFFFF

>16 MB

12–16 MB

6–12 MB

<6 MB

The end of buffer The end of buffer

The end of buffer

The end of buffer

The end of physical memory

The end of physical memory

The end of physical memory The end of physical memory

Figure 2.2 The initial setting of the memory.

//Code path:init/main.c:

……

#define EXT_MEM_K (*(unsigned short *)0x90002) //Extended memory(KB) //starts from 1M

……

void main(void) {

……

memory_end = (1<<20) + (EXT_MEM_K<<10);//1M+extend memory,i.e. the //total number of memory memory_end & = 0xfffff000;//Get integer multiple of pages, ignore

//the part less than one page at the end of memory if (memory_end > 16*1024*1024)

memory_end = 16*1024*1024;

if (memory_end > 12*1024*1024)

buffer_memory_end = 4*1024*1024;

else if (memory_end > 6*1024*1024) buffer_memory_end = 2*1024*1024;

else

buffer_memory_end = 1*1024*1024;

main_memory_start = buffer_memory_end; //After the buffer is in //main memory

is the end of buffer memory. The starting position of the buffer memory will be introduced in detail in Section 2.1.13.

Tip:

There are several common data relations of left shift and right shift that should be mentioned:

<<20 or >>20 is equivalent to be multiplied or divided by 1M,

<<12 or >>12 is equivalent to be multiplied or divided by 4K (associate with the page)

<<10 or >>10 is equivalent to be multiplied or divided by 1K

Thus, 1 << 20 is 1M; EXT_MEM_K << 10 is the bytes of EXT_MEM_K (kilo- bytes of extended memory).

Một phần của tài liệu The art of linux kernel design (Trang 61 - 64)

Tải bản đầy đủ (PDF)

(524 trang)