Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What was CPU doing a few seconds after pressing the power?

2025-01-15 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: programming Technology Universe (ID:xuanyuancoding), author: Xuanyuan Wind O

I was awakened early in the morning when I was still asleep.

This is Ah Q from the No.1 workshop of CPU. Long time no see. I wonder if you miss me.

"isn't it Saturday? why do you have to work?" I was a little unhappy. I thought I could sleep in. Who knew programmers would turn on their phones during the big weekend? did you come to work overtime?

While complaining, I have to get up and work quickly.

When I came to my workshop, the small A who extracted the instruction, the Xiao Pang who analyzed the instruction and the old K who was responsible for writing back the results had all arrived. All I needed to do was to execute the instruction.

We all took our places and made preparations.

"Xiao A, report the value of each register." I told Xiao A that this is the check we must do before we start work every day.

Every time our circuit is powered on, our circuit will start the self-test and reset all the registers. If there is anything abnormal, the error will be recorded in the EAX register. If it is found that the value of EAX is not 0, it will be very bad.

"report, register confirmed:"

EAX,EBX, ECX, ESI, EDI, EBP, ESP: 0x00000000

EFLAGS: 0x00000002

CS: 0xF000

EIP: 0xFFF0

There seems to be no problem, especially the CS and IP registers, which determine where to start executing the code later.

We are a 64-bit CPU, usually working in protected mode, using virtual addresses to access memory, and the factory's memory management unit MMU is responsible for translating them into real physical addresses.

However, at this time, the page directory and page table required for virtual address translation are not ready, and MMU cannot work. At this time, we can only use 16-bit registers, work in the field address mode, use segment + base address to deal with memory, and can only use 1MB memory space at most, which is a bit cramped.

Begin to implement "is everyone ready? cheer up and get ready to start today's work!"

"Brother Q, this has just been powered on, and the guy in the memory stick should still be blank. Where are we going to carry out the instructions?" Well, Xiao An asked.

"you don't have to worry about that. On the motherboard, not far from our CPU, there is a guy named BIOS, which is a ROM chip. We have agreed with him that as soon as he is powered on, he will map to the address space. Just follow the CS:IP (0xF000:0xFFF0) to start getting instructions, and he will arrange it."

"so it is," Xiao A nodded as if he didn't understand.

Officially started to work, Xiao A skillfully got the first instruction from F000:FFF0, that is, 0xFFFF0: jmp xxxx.

Boy, it was a big jump, and we came to the middle of the BIOS guy's turf and began to execute the program he had prepared.

I have done this pile of instructions countless times, checking the units on the motherboard to see if there are any anomalies, initializing the interrupt vector table we need for work, and so on. I am already familiar with it.

"Brothers are busy." We were so busy that we found someone watching at the door. Looking back, it turned out to be several guys from workshop 2, workshop 5 and workshop 8 next door.

"you guys are so free, why don't you come and help us for a while?"

"well, you have a good idea. Your No. 1 core is a boot processor (BSP), and your treatment is better than ours. How can we take the boot job?" Huzi, from the No.2 workshop, said strangely.

I really envy them. They go to work later than our No. 1 workshop and can sleep a little longer every time.

MBR I continue to execute the code in BIOS, everything is checked, there is nothing unusual, and I'm ready to start the operating system boss.

Next, I checked the boot sequence configured in BIOS, and at the top of the list was the hard drive brother.

So I read the contents of disk 0, track 0, sector 1 of the hard drive to the 0x7C00 location in memory, which they called the master boot record MBR, with a total of 512 bytes.

According to the guy on the hard drive, this was written to him by the boss of the operating system when he installed it.

He also told me that this position is very important, there has been a virus occupied this position, and finally had no choice but to reinstall the system.

MBR

After reading the MBR, we have to check that the last two bytes must be 0x55 and 0xAA, which seems to be no problem, it is a legitimate MBR, and we jump to the location of 0x7C00 to start execution.

The operating system finally came to the territory of the operating system, under the instructions of the operating system, we switched the working mode and began to work in protected mode!

Just switched to protected mode, MMU is still unable to do address translation, we still have to use the physical address to contact memory, so we have to prepare the page directory and page table as soon as possible.

After working for a while, I finally got everything I needed. I excitedly turned on the memory paging switch and informed the MMU department to start working. Now we can use virtual addresses to access memory, which feels much better!

At this time, the guys in workshops No. 2, No. 5 and No. 8 who were watching saw this and hurried back, because they knew it was time for them to work.

We continued to execute the code of the operating system, prepared data and instructions for all the other cores of our CPU, created multiple threads, and called them up to work together. Our eight-core CPU was finally fully started, and there was a lot of excitement at once.

Later, I do not know how many instructions were executed and how many threads were created before the operating system boss ran completely and successfully completed this boot.

This is the daily routine when our CPU starts to work after the power is turned on. I can't remember how many times this is started, and I don't know how many times we can start it.

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.

Share To

IT Information

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report