In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
This article comes from the official account of Wechat: low concurrency programming (ID:dibingfa). Author: flash.
With a novel-reading mentality, this series will read and appreciate all the core code of Linux 0.11 from the order of code execution after boot, and understand the technical details and design ideas of the operating system.
You will follow me, watching an operating system start from nothing, step by step to achieve its complex and exquisite design, after reading this series, I hope you can sigh that the original operating system source code is this stupid thing. The following is a list of published articles. For more information about this series, you can start with the opening words.
Opening words
The first two lines of code for the first time
The second time I moved a place for myself.
The GitHub address of this series: click here to visit
-the text begins-
As we mentioned in the last book, the 512 bytes of data at the beginning of the operating system code is moved from the boot area of the hard disk to the memory 0x7c00, then immediately to the 0x90000, and then jumps here and then slightly offsets the offset address represented by the go tag.
Well, next, we will continue to focus on the position of the go tag and follow the pace of CPU.
Mov ax,cs mov ds,ax mov es,ax mov ss,ax mov sp,#0xFF00 is all operated by mov, so that's easy.
The direct meaning of this code is easy to understand, which is to copy the values of the cs register to the ds, es, and ss registers, and then give 0xFF00 to the sp register.
Review the CPU register diagram.
The cs register represents the code snippet register, and the location of the code currently executing by CPU in memory is pointed to by the set of registers cs:ip, where cs is the base address and ip is the offset address.
Because an inter-segment jump instruction was executed before, remember?
Jmpi go,0x9000 so now the value in the cs register is 0x9000 and the value in the IP register is the offset address of the go label. Then the three mov instructions assign values to the ds, es and ss registers to 0x9000, respectively.
Ds is a segment register, as we said before, when it was copied as 0x07c0, because the previous code was at 0x7c00, and now the code has been moved to 0x90000, so now it is naturally assigned to 0x9000.
Es is an extension segment register, just an extension, not the protagonist, just ignore it.
Ss is the stack segment register, followed by the stack base address register sp to represent the stack top address at this time. At this point, the sp register is assigned to 0xFF00, so the current address at the top of the stack is the address 0x9FF00 that ss:sp points to.
In fact, at this point, some of the most basic preparations for the operating system have been done. What have you done?
First, the code is moved from the hard drive to memory, and then moved from memory to the 0x90000.
Second, the data segment register ds and the code segment register cs are set to 0x9000 at this time, that is, the base address of the same memory is established for jumping code and accessing memory data, which facilitates jump and memory access, because only the offset address needs to be specified.
Third, the top address of the stack is set to 0x9FF00, which is embodied in that the stack segment register ss is 0x9000 and the stack base address register sp is 0xFF00. The stack is developing downward, and the top address 0x9FF00 of the stack is much larger than the location 0x90000 where the code is located at this time, so it is difficult to run into the location of the code when the stack goes down, so it is more secure. This is why the address at the top of the stack is set to this value, which only needs to be far away from the location of the code.
After doing all this basic work, it is time to deal with other things.
Summary, this part is actually the code segment register cs, data segment register ds, stack segment register ss and stack base register sp respectively set the value to facilitate subsequent use.
In fact, what the operating system is doing is to make a preliminary memory plan for how to access the code, how to access the data, and how to access the stack. The planning of access code and data is to set a base address, and the access stack is to point the pointer at the top of the stack to a place far away from the code location.
So, don't think about it, that's all. Then leave an assignment for everyone to draw the current memory layout and tell me where the values of the registers cs, ip, ds, ss and sp are in the memory layout.
All right, what should we do next? As we recall, we have only loaded 512 bytes of hard disk into memory, but the operating system still has a lot of code on the hard disk, so we can't leave them behind.
So guess what to do next?
The world behind is becoming more and more wonderful. If you want to know what happens in the future, let's listen to the decomposition next time.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.