home - Software
Semantic core - how to compose it correctly? Let's write a kernel! We create the simplest working kernel of the operating system Semantic kernel of the page.

Let's write a simple kernel that can be booted using the GRUB bootloader on an x86 system. This kernel will display a message on the screen and wait.

How does an x86 system boot?

Before we start writing the kernel, let's understand how the system boots and transfers control to the kernel.

Most processor registers already contain certain values ​​at startup. The register pointing to the address of instructions (Instruction Pointer, EIP) stores the memory address where the instruction executed by the processor lies. The default EIP is 0xFFFFFFFF0. Thus, x86 processors at the hardware level start working at address 0xFFFFFFF0. In fact, this is the last 16 bytes of the 32-bit address space. This address is called the reset vector.

Now the chipset memory map ensures that 0xFFFFFFF0 belongs to a specific part of the BIOS, not RAM. At this time, the BIOS copies itself to RAM for more quick access. Address 0xFFFFFFF0 will only contain an instruction to jump to the address in memory where a copy of the BIOS is stored.

This is how the BIOS code begins to execute. The BIOS first looks for a device that can boot from, in a preset order. A magic number is sought to determine whether the device is bootable (the 511th and 512th bytes of the first sector must be equal to 0xAA55).

When the BIOS finds a boot device, it copies the contents of the first sector of the device into RAM, starting at the physical address 0x7c00; then goes to the address and executes the downloaded code. This code is called bootloader.

The bootloader loads the kernel at a physical address 0x100000. This address is used as the starting address in all large kernels on x86 systems.

All x86 processors start out in a simple 16-bit mode called real mode. GRUB bootloader switches mode to 32-bit protected mode, setting the low bit of register CR0 to 1 . Thus, the kernel is loaded in 32-bit protected mode.

Note that in the case of the Linux kernel, GRUB sees the Linux boot protocols and loads the kernel into real mode. The kernel automatically switches to protected mode.

What do we need?

  • x86 computer;
  • Linux;
  • ld (GNU Linker);

Setting the entry point in assembler

No matter how much you would like to limit yourself to C alone, you will have to write something in assembler. We will write a small file on it that will serve as the starting point for our kernel. All it will do is call an external function written in C and stop the program flow.

How can we make sure that this code is the starting point?

We will use a linker script that links object files to create the final executable file. In this script we will explicitly indicate that we want to load data at address 0x100000.

Here is the assembler code:

;;kernel.asm bits 32 ;nasm directive - 32 bit section .text global start extern kmain ;kmain is defined in the c file start: cli ;block interrupts mov esp, stack_space ;set stack pointer call kmain hlt ;halt the CPU section .bss resb 8192 ;8KB for stack stack_space:

The first instruction, bits 32, is not an x86 assembly instruction. This is a directive to the NASM assembler that specifies code generation for a processor operating in 32-bit mode. In our case this is not necessary, but generally useful.

The section with the code begins on the second line.

global is another NASM directive that makes symbols source code global. This way the linker knows where the start symbol is - our entry point.

kmain is a function that will be defined in the kernel.c file. extern means that the function is declared somewhere else.

Then comes the start function, which calls the kmain function and stops the processor with the hlt instruction. This is why we disable interrupts in advance using the cli instruction.

Ideally, we need to allocate some memory and point to it with a stack pointer (esp). However, it looks like GRUB has already done this for us. However, you will still allocate some space in the BSS section and move the stack pointer to its beginning. We use the resb instruction, which reserves the specified number of bytes. Immediately before calling kmain, the stack pointer (esp) is set to the correct location with the mov instruction.

Kernel in C

In kernel.asm we made a call to the kmain() function. Thus, our “C” code should start execution with kmain() :

/* * kernel.c */ void kmain(void) ( const char *str = "my first kernel"; char *vidptr = (char*)0xb8000; //video mem begins here. unsigned int i = 0; unsigned int j = 0; /* this loops clears the screen * there are 25 lines each of 80 columns; each element takes 2 bytes */ while(j< 80 * 25 * 2) { /* blank character */ vidptr[j] = " "; /* attribute-byte - light grey on black screen */ vidptr = 0x07; j = j + 2; } j = 0; /* this loop writes the string to video memory */ while(str[j] != "\0") { /* the character"s ascii */ vidptr[i] = str[j]; /* attribute-byte: give character black bg and light grey fg */ vidptr = 0x07; ++j; i = i + 2; } return; }

All our kernel will do is clear the screen and display the line “my first kernel”.

First we create a vidptr pointer that points to the address 0xb8000. In protected mode, “video memory” begins from this address. To display text on the screen, we reserve 25 lines of 80 ASCII characters, starting at 0xb8000.

Each character is displayed not by the usual 8 bits, but by 16. The first byte stores the character itself, and the second - attribute-byte . It describes the formatting of the character, such as its color.

To display the green character s on a black background, we write this character in the first byte and the value 0x02 in the second. 0 means black background, 2 means green text color.

Here is the color chart:

0 - Black, 1 - Blue, 2 - Green, 3 - Cyan, 4 - Red, 5 - Magenta, 6 - Brown, 7 - Light Grey, 8 - Dark Grey, 9 - Light Blue, 10/a - Light Green, 11/b - Light Cyan, 12/c - Light Red, 13/d - Light Magenta, 14/e - Light Brown, 15/f - White.

In our kernel we will use light gray text on a black background, so our attribute byte will have the value 0x07.

In the first loop, the program prints a blank symbol over the entire 80x25 zone. This will clear the screen. In the next cycle, characters from the null-terminated string “my first kernel” with an attribute byte equal to 0x07 are written to “video memory”. This will print the string to the screen.

Connecting part

We need to assemble kernel.asm into an object file using NASM; then use GCC to compile kernel.c into another object file. They then need to be attached to the executable boot kernel.

To do this, we will use a binding script that is passed to ld as an argument.

/* * link.ld */ OUTPUT_FORMAT(elf32-i386) ENTRY(start) SECTIONS ( . = 0x100000; .text: ( *(.text) ) .data: ( *(.data) ) .bss: ( *( .bss) ) )

First we will ask output format as 32-bit Executable and Linkable Format (ELF). ELF is a standard binary file format for Unix x86 systems. ENTRY takes one argument specifying the name of the symbol that is the entry point. SECTIONS- this is the most important part. It defines the markup of our executable file. We determine how the different sections should be connected and where to place them.

In parentheses after SECTIONS, the dot (.) displays the position counter, which defaults to 0x0. It can be changed, which is what we are doing.

Let's look at the following line: .text: ( *(.text) ) . An asterisk (*) is special character, matching any file name. The expression *(.text) means all .text sections from all input files.

Thus, the linker joins all the code sections of the object files into one section of the executable file at the address in the position counter (0x100000). After this, the counter value will be equal to 0x100000 + the size of the resulting section.

The same thing happens with other sections.

Grub and Multiboot

Now all the files are ready to create the kernel. But there is one more step left.

There is a standard for loading x86 cores using a bootloader called Multiboot specification. GRUB will only boot our kernel if it meets these specifications.

Following them, the kernel should contain a header in its first 8 kilobytes. Additionally, this header must contain 3 fields, which are 4 bytes:

  • magical field: contains magic number 0x1BADB002 to identify the core.
  • field flags: we don’t need it, let’s set it to zero.
  • field checksum: if you add it with the previous two, you should get zero.

Our kernel.asm will look like this:

;;kernel.asm ;nasm directive - 32 bit bits 32 section .text ;multiboot spec align 4 dd 0x1BADB002 ;magic dd 0x00 ;flags dd - (0x1BADB002 + 0x00) ;checksum. m+f+c should be zero global start extern kmain ;kmain is defined in the c file start: cli ;block interrupts mov esp, stack_space ;set stack pointer call kmain hlt ;halt the CPU section .bss resb 8192 ;8KB for stack stack_space:

Building the core

Now we will create object files from kernel.asm and kernel.c and link them using our script.

Nasm -f elf32 kernel.asm -o kasm.o

This line will run the assembler to create the kasm.o object file in ELF-32 format.

Gcc -m32 -c kernel.c -o kc.o

The “-c” option ensures that no hidden linking occurs after compilation.

Ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o

This will run the linker with our script and create an executable called kernel.

Setting up grub and starting the kernel

GRUB requires the kernel name to satisfy the pattern kernel- . So rename the kernel. I named mine kernel-701.

Now put it in the directory /boot. To do this you will need superuser rights.

In the GRUB configuration file grub.cfg, add the following:

Title myKernel root (hd0,0) kernel /boot/kernel-701 ro

Don't forget to remove the hiddenmenu directive if present.

Restart your computer and you will see a list of kernels including yours. Select it and you will see:

This is your core! Let's add an input/output system.

P.S.

  • For any kernel tricks, it is better to use a virtual machine.
  • To run the kernel in grub2 the config should look like this: menuentry "kernel 7001" ( set root="hd0,msdos1" multiboot /boot/kernel-7001 ro )
  • if you want to use the qemu emulator, use: qemu-system-i386 -kernel kernel

The semantic core is a scary name that SEOs came up with to denote a rather simple thing. We just need to select the key queries for which we will promote our site.

And in this article I will show you how to correctly compose a semantic core so that your site quickly reaches the TOP, and does not stagnate for months. There are also “secrets” here.

And before we move on to compiling the SY, let's figure out what it is and what we should ultimately come to.

What is the semantic core in simple words

Oddly enough, but the semantic core is the usual excel file, which lists the key queries for which you (or your copywriter) will write articles for the site.

For example, this is what my semantic core looks like:

I have marked in green those key queries for which I have already written articles. Yellow - those for which I plan to write articles in the near future. And colorless cells mean that these requests will come a little later.

For each key query, I have determined the frequency, competitiveness, and come up with a “catchy” title. You should get approximately the same file. Now my CN consists of 150 keywords. This means that I am provided with “material” for at least 5 months in advance (even if I write one article a day).

Below we will talk about what you should prepare for if you suddenly decide to order the collection of the semantic core from specialists. Here I will say briefly - they will give you the same list, but only for thousands of “keys”. However, in SY it is not quantity that is important, but quality. And we will focus on this.

Why do we need a semantic core at all?

But really, why do we need this torment? You can, after all, just write quality articles and attract an audience, right? Yes, you can write, but you won’t be able to attract people.

The main mistake of 90% of bloggers is simply writing high-quality articles. I'm not kidding, they have really interesting and useful materials. But search engines don’t know about it. They are not psychics, but just robots. Accordingly, they do not rank your article in the TOP.

There is another subtle point with the title. For example, you have a very high-quality article on the topic “How to properly conduct business in a face book.” There you describe everything about Facebook in very detail and professionally. Including how to promote communities there. Your article is the highest quality, useful and interesting on the Internet on this topic. No one was lying next to you. But it still won't help you.

Why high-quality articles fall from the TOP

Imagine that your site was visited not by a robot, but by a live inspector (assessor) from Yandex. He realized that you have the coolest article. And hands put you in first place in the search results for the request “Promoting a community on Facebook.”

Do you know what will happen next? You will fly out of there very soon anyway. Because no one will click on your article, even in first place. People enter the query “Promoting a community on Facebook,” and your headline is “How to properly run a business in a face book.” Original, fresh, funny, but... not on request. People want to see exactly what they were looking for, not your creativity.

Accordingly, your article will empty its place in the TOP search results. And a living assessor, an ardent admirer of your work, can beg the authorities as much as he likes to leave you at least in the TOP 10. But it won't help. All the first places will be taken by empty articles, like the husks of sunflower seeds, that yesterday’s schoolchildren copied from each other.

But these articles will have the correct “relevant” title - “Promoting a community on Facebook from scratch” ( step by step, in 5 steps, from A to Z, free etc.) Is it offensive? Still would. Well, fight against injustice. Let's create a competent semantic core so that your articles take the well-deserved first places.

Another reason to start writing SYNOPSIS right now

There is one more thing that for some reason people don’t think much about. You need to write articles often - at least every week, and preferably 2-3 times a week - to gain more traffic and faster.

Everyone knows this, but almost no one does it. And all because they have “creative stagnation”, “they just can’t force themselves”, “they’re just lazy”. But in fact, the whole problem lies in the absence of a specific semantic core.

I entered one of my basic keys, “smm,” into the search field, and Yandex immediately gave me a dozen hints about what else might be of interest to people who are interested in “smm.” All I have to do is copy these keys into a notebook. Then I will check each of them in the same way, and collect hints on them as well.

After the first stage of collecting key words, you should end up with a text document that will contain 10-30 broad basic keys, which we will work with further.

Step #2 — Parsing basic keys in SlovoEB

Of course, if you write an article for the request “webinar” or “smm”, then a miracle will not happen. You will never be able to reach the TOP for such a broad request. We need to break the basic key into many small queries on this topic. And we will do this using a special program.

I use KeyCollector, but it's paid. You can use a free analogue - the SlovoEB program. You can download it from the official website.

The most difficult thing about working with this program is setting it up correctly. I show you how to properly set up and use Sloboeb. But in that article I focus on selecting keys for Yandex Direct.

And here let’s look step by step at the features of using this program for creating a semantic core for SEO.

First, we create a new project and name it by the broad key that you want to parse.

I usually give the project the same name as my base key to avoid confusion later. And yes, I will warn you against one more mistake. Don't try to parse all base keys at once. Then it will be very difficult for you to filter out “empty” key queries from golden grains. Let's parse one key at a time.

After creating the project, we carry out the basic operation. That is, we actually parse the key through Yandex Wordstat. To do this, click on the “Worstat” button in the program interface, enter your base key, and click “Start collection”.

For example, let's parse the base key for my blog “contextual advertising”.

After this, the process will start, and after some time the program will give us the result - up to 2000 key queries that contain “contextual advertising”.

Also, next to each request there will be a “dirty” frequency - how many times this key (+ its word forms and tails) was searched per month through Yandex. But I do not advise drawing any conclusions from these numbers.

Step #3 - Collecting the exact frequency for the keys

Dirty frequency will not show us anything. If you focus on it, then don’t be surprised when your key for 1000 requests does not bring a single click per month.

We need to identify pure frequency. And to do this, we first select all the found keys with checkmarks, and then click on the “Yandex Direct” button and start the process again. Now Slovoeb will look for the exact request frequency per month for each key.

Now we have an objective picture - how many times what query was entered by Internet users over the past month. I now propose to group all key queries by frequency to make it easier to work with them.

To do this, click on the “filter” icon in the “Frequency” column. ", and specify - filter out keys with the value "less than or equal to 10".

Now the program will show you only those requests whose frequency is less than or equal to the value “10”. You can delete these queries or copy them to another group of key queries for future use. Less than 10 is very little. Writing articles for these requests is a waste of time.

Now we need to select those key queries that will bring us more or less good traffic. And for this we need to find out one more parameter - the level of competitiveness of the request.

Step #4 — Checking the competitiveness of requests

All “keys” in this world are divided into 3 types: high-frequency (HF), mid-frequency (MF), low-frequency (LF). They can also be highly competitive (HC), moderately competitive (SC) and low competitive (LC).

As a rule, HF requests are also VC. That is, if a query is often searched on the Internet, then there are a lot of sites that want to promote it. But this is not always the case; there are happy exceptions.

The art of compiling a semantic core lies precisely in finding queries that have a high frequency and a low level of competition. It is very difficult to manually determine the level of competition.

You can focus on indicators such as the number of main pages in the TOP 10, length and quality of texts. level of trust and tits of sites in the TOP search results upon request. All of this will give you some idea of ​​how tough the competition is for rankings for this particular query.

But I recommend you use Mutagen service. It takes into account all the parameters that I mentioned above, plus a dozen more that neither you nor I have probably even heard of. After analysis, the service gives an exact value - what level of competition this request has.

Here I checked the query “setting up contextual advertising in google adwords”. Mutagen showed us that this key has a competitiveness of "more than 25" - this is the maximum value it shows. And this query has only 11 views per month. So it definitely doesn’t suit us.

We can copy all the keys that we found in Slovoeb and do a mass check in Mutagen. After that, all we have to do is look through the list and take those requests that have a lot of requests and a low level of competition.

Mutagen is a paid service. But you can do 10 checks per day for free. In addition, the cost of testing is very low. In all the time I have been working with him, I have not yet spent even 300 rubles.

By the way, about the level of competition. If you have a young site, then it is better to choose queries with a competition level of 3-5. And if you have been promoting for more than a year, then you can take 10-15.

By the way, about the frequency of requests. We now need to take the final step, which will allow you to attract a lot of traffic even for low-frequency queries.

Step #5 — Collecting “tails” for the selected keys

As has been proven and tested many times, your site will receive the bulk of traffic not from the main keywords, but from the so-called “tails”. This is when a person enters strange key queries into the search bar, with a frequency of 1-2 per month, but there are a lot of such queries.

To see the “tail”, simply go to Yandex and enter the key query of your choice into the search bar. Here's roughly what you'll see.

Now you just need to write down these additional words in a separate document and use them in your article. Moreover, there is no need to always place them next to the main key. Otherwise, search engines will see “over-optimization” and your articles will fall in search results.

Just use them in different places in your article, and then you will receive additional traffic from them as well. I would also recommend that you try to use as many word forms and synonyms as possible for your main key query.

For example, we have a request - “Setting up contextual advertising”. Here's how to reformulate it:

  • Setup = set up, make, create, run, launch, enable, place...
  • Contextual advertising = context, direct, teaser, YAN, adwords, kms. direct, adwords...

You never know exactly how people will search for information. Add all these additional words to your semantic core and use them when writing texts.

So, we collect a list of 100 - 150 key queries. If you are creating a semantic core for the first time, it may take you several weeks.

Or maybe break his eyes? Maybe there is an opportunity to delegate the compilation of FL to specialists who will do it better and faster? Yes, there are such specialists, but you don’t always need to use their services.

Is it worth ordering SY from specialists?

By and large, semantic core compilers will only give you steps 1 - 3 from our diagram. Sometimes, for a large additional fee, they will do steps 4-5 - (collecting tails and checking the competitiveness of requests).

After that, they will give you several thousand key queries that you will need to work with further.

And the question here is whether you are going to write the articles yourself, or hire copywriters for this. If you want to focus on quality rather than quantity, then you need to write it yourself. But then it won't be enough for you to just get a list of keys. You will need to choose topics that you understand well enough to write a quality article.

And here the question arises - why then do we actually need specialists in FL? Agree, parsing the base key and collecting exact frequencies (steps #1-3) is not at all difficult. This will literally take you half an hour.

The most difficult thing is to choose HF requests that have low competition. And now, as it turns out, you need HF-NCs, on which you can write a good article. This is exactly what will take you 99% of your time working on the semantic core. And no specialist will do this for you. Well, is it worth spending money on ordering such services?

When are the services of FL specialists useful?

It’s another matter if you initially plan to attract copywriters. Then you don't have to understand the subject of the request. Your copywriters won’t understand it either. They will simply take several articles on this topic and compile “their” text from them.

Such articles will be empty, miserable, almost useless. But there will be many of them. On your own, you can write a maximum of 2-3 quality articles per week. And an army of copywriters will provide you with 2-3 shitty texts a day. At the same time, they will be optimized for requests, which means they will attract some traffic.

In this case, yes, calmly hire FL specialists. Let them also draw up a technical specification for copywriters at the same time. But you understand, this will also cost some money.

Summary

Let's go over the main ideas in the article again to reinforce the information.

  • The semantic core is simply a list of key queries for which you will write articles on the site for promotion.
  • It is necessary to optimize texts for precise key queries, otherwise even your highest-quality articles will never reach the TOP.
  • SY is like a content plan for social networks. It helps you avoid falling into a “creative crisis” and always know exactly what you will write about tomorrow, the day after tomorrow and in a month.
  • To compile a semantic core, it is convenient to use the free program Slovoeb, you only need it.
  • Here are the five steps of compiling the NL: 1 - Selection of basic keys; 2 - Parsing basic keys; 3 - Collection of exact frequency for requests; 4 — Checking the competitiveness of keys; 5 – Collection of “tails”.
  • If you want to write articles yourself, then it is better to create a semantic core yourself, for yourself. Specialists in the preparation of synonyms will not be able to help you here.
  • If you want to work on quantity and use copywriters to write articles, then it is quite possible to delegate and compile the semantic core. If only there was enough money for everything.

I hope this instruction was useful to you. Save it to your favorites so as not to lose it, and share it with your friends. Don't forget to download my book. There I show you the fastest way from zero to the first million on the Internet (extract from personal experience in 10 years =)

See you later!

Yours Dmitry Novoselov

Hi all! Today's article is devoted to how to correctly assemble a semantic core (SC). If you are engaged in SEO promotion in Google and Yandex, want to increase natural traffic, increase website traffic and sales - this material is for you.

To get to the bottom of the truth, we will study the topic from “A to Z”:

In conclusion, let's look at the general rules for composing SL. So let's get started!

Semantic core: what is it and what are the queries?

The semantic core of a site (also known as the “semantic core”) is a set of words and phrases that exactly corresponds to the structure and theme of the resource. Simply put, these are the queries by which users can find a site on the Internet.

It is the correct semantic core that gives search engines and the audience a complete picture of the information presented on the resource.

For example, if a company sells ready-made postcards, then the semantic core should include the following queries: “buy a postcard”, “postcard price”, “custom postcard” and the like. But not: “how to make a postcard”, “do-it-yourself postcard”, “homemade postcards”.

Interesting to know: LSI copywriting. Will the technique replace SEO?

Classification of requests by frequency:

  • High frequency queries(HF) - the most often “hammered” into the search bar (for example, “buy a postcard”).
  • Midrange(MF) – less popular than HF keys, but also of interest to a wide audience (“buy postcard price”).
  • Low frequency(NP) – phrases that are requested very rarely (“buy an art postcard”).

It is important to note that there are no clear boundaries separating HF from SY and LF, since they vary depending on the topic. For example, for the query “origami”, the RF indicator is 600 thousand impressions per month, and for “cosmetics” – 3.5 million.

If we turn to the anatomy of the key, then the high frequency consists only of the body, the midrange and low frequencies are supplemented by a specifier and a “tail”.

When forming a semantic core, you need to use all types of frequency, but in different proportions: minimum HF, maximum LF and average amount of MF.

To make it clearer, let's draw an analogy with a tree. The trunk is the most important request on which everything rests. Thick branches located closer to the trunk are mid-frequency keys, which are also popular, but not as popular as HF. Thin branches are low-frequency words that are also used to search for the desired product/service, but rarely.

Separation of keys by competitiveness:

  • highly competitive (HC);
  • average competitive (SC);
  • low-competitive (NC).

This criterion shows how many web resources this request uses for promotion. Everything is simple here: the higher the competitiveness of the key, the more difficult it is to break through and stay in the top 10 with it. Low-competitive ones are also not worth attention, since they are not very popular on the network. The ideal option is to advance according to IC requests, with which you can realistically take first place in a stable business area.

Classification of requests according to user needs:

  • Transactional– keys associated with the action (buy, sell, upload, download).
  • Information– to obtain any information (what, how, why, how much).
  • Navigational– help you find information on a specific resource (“buy a phone socket”).

The remaining keywords, when it is difficult to understand the user’s intention, are classified into the “Other” group (for example, just the word “postcard” raises a lot of questions: “Buy? Make? Draw?”).

Why does a website need a semantic core?

Collecting a semantic core is painstaking work that requires a lot of time, effort and patience. It will not be possible to create a correct syntax that will work in just two minutes.

A completely reasonable question arises here: is it even worth spending effort on selecting a semantic core for a site? If you want your Internet project to be popular, constantly increase your customer base and, accordingly, increase the company’s profits, the answer is unequivocal: “YES.”

Because collecting the semantic core helps:

  • Increase the visibility of a web resource. Search engines Yandex, Google and others will find your site using the keywords you select and offer it to users who are interested in these queries. As a result, the influx of potential customers increases, and the chances of selling a product/service increase.
  • Avoid competitors' mistakes. When creating a syntax, an analysis of the semantic core of competitors occupying the first position in search results is necessarily performed. By studying the leading sites, you will be able to determine what queries help them stay in the top, what topics they write texts on, and what ideas are unsuccessful. During your competitor analysis, you may also come up with ideas on how to develop your business.
  • Make the site structure. It is recommended to use the semantic core as an “assistant” for creating a website structure. By collecting the complete CN, you can see all the queries that users enter when searching for your product or service. This will help you decide on the main sections of the resource. Most likely, you will need to create pages that you didn’t even think about initially. It is important to understand that the NL only suggests the interests of users. Ideally, the site structure matches the business area and contains content that meets the needs of the audience.
  • Avoid spam. After analyzing the semantic core of top competitor sites, you can determine the optimal keyword frequency. Because there is no universal indicator of query density for all pages of a resource, and everything depends on the topic and type of page, as well as the language and the key itself.

How else can you use the semantic core? To create the right content plan. Properly collected keys will suggest topics for texts and posts that are of interest to your target audience.

Conclusion. It is almost IMPOSSIBLE to create an interesting, popular and profitable Internet project without SY.

Material on topic:

Preparing to collect the semantic core for the site

Before creating the semantic core of the site, you need to perform the following steps:

I. Study the company’s activities (“brainstorming”)

Here it is important to write down ALL the services and goods that the organization offers. For example, to collect a semantic core for an online furniture store, you can use the following queries: sofa, armchair, bed, hallway, cabinet + restoration, repair. The main thing here is not to miss anything and not to add unnecessary things. Only relevant information, i.e. If the company does not sell poufs or repair furniture, these requests are not necessary.

In addition to brainstorming, you can use the services Google Analytics and Yandex.Metrika (Fig. 1) or personal accounts in Google Search Console and Yandex Webmaster (Fig. 2). They will tell you which queries are most popular among your target audience. Such assistance is available only to already operating sites.

Texts to help:

  • Advego– works on the same principle as Istio.com.

  • Simple SEO Toolsfree service for SEO analysis of the site, including the semantic core.

  • Lenartools. It works simply: load the pages from which you need to “pull” keys (max 200), click “Let’s go” - and you get a list of words that are most often used on resources.

II. To analyze the semantic core of a competitor site:

  • SEMRUSH– you need to add the resource address, select the country, click “Start Now” and get the analysis. The service is paid, but 10 free checks are provided upon registration. Also suitable for collecting keys for your own business project.

  • Searchmetrics– a very convenient tool, but it is paid and in English, so it is not available to everyone.

  • SpyWords– a service for analyzing a competitor’s activities: budget, search traffic, ads, requests. A “reduced” set of functions is available for free, and for a fee you can get a detailed picture of the progress of the company you are interested in.

  • Serpstat– a multifunctional platform that provides a report on keywords, rankings, competitors in Google and Yandex search results, backlinks etc. Suitable for selecting FL and analyzing your resource. The only negative is that the full range of services is available after paying for the tariff plan.

  • PR-CYfree program to analyze the semantic core, usability, mobile optimization, link mass and much more.

Another effective method extensions of the semantic core - use synonyms. Users can search for the same product or service in different ways, so it is important to include all alternative keys in the TL. Hints in Google and Yandex will help you find synonyms.

Advice. If the site is informational, you first need to select queries that are the main ones for this resource and for which promotion is planned. And then - seasonal. For example, for a web project about fashion trends in clothing, the key queries will be: fashion, women's, men's, children's. And, so to speak, “seasonal” - autumn, winter, spring, etc.

How to assemble a semantic core: detailed instructions

Having decided on a list of queries for your site, you can begin collecting the semantic core.

It can be done:

I. FREE using:

Wordstat Yandex

Yandex Wordstat is a very popular online service with which you can:

  • collect the semantic core of the site with statistics for the month;
  • get words similar to the query;
  • filter keywords entered from mobile devices;
  • find out statistics by city and region;
  • determine seasonal fluctuations of keys.

Big drawback: you have to “unload” the keys manually. But if you install the extension Yandex Wordstat Assistant, working with the semantic core will speed up significantly (relevant for the Opera browser).

It’s easy to use: click on “+” next to the desired key or click “add all”. Requests are automatically transferred to the extension list. After collecting the CN, you need to transfer it to the table editor and process it. Important advantages of the program: checking for duplicates, sorting (alphabet, frequency, adding), the ability to add keys manually.

Step-by-step instructions on how to use the service are given in the article: Yandex. Wordstat: how to collect key queries?

Google Ads

Keyword planner from Google, which allows you to select a semantic core online for free. The service finds keywords based on the queries of Google search engine users. To work, you must have a Google account.

The service offers:

  • find new keywords;
  • see the number of requests and forecasts.

To collect the semantic core, you need to enter a query, selecting the location and language. The program shows the average number of requests per month and the level of competition. There is also information about ad impressions and the bid to display an ad at the top of the page.

If necessary, you can set a filter by competition, average position and other criteria.

It is also possible to request a report ( step by step instructions The program shows how to do it).

To study traffic forecasting, just enter a query or a set of keys in the “See the number of queries and forecasts” window. The information will help determine the effectiveness of the strategic plan for a given budget and rate.

The “disadvantages” of the service include the following: there is no exact frequency (only the average for the month); does not show encrypted Yandex keys and hides some from Google. But it determines competition and allows you to export keywords in Excel format.

SlovoEB

This is a free version of Key Collector, which has a lot of useful features:

  • quickly collects a semantic core from the right and left columns of WordStat;
  • performs batch collection of search tips;
  • determines all types of frequency;
  • collects seasonality data;
  • allows you to perform batch collection of words and frequency from Rambler.Adstat;
  • Calculates KEI (Key Effectiveness Index).

To use the service, just enter your account information in Direct (login and password).

If you want to know more, read the article: Slovoeb (Slovoeb). Basics and instructions for use

Bukvariks

An easy-to-use and free program for collecting the semantic core, the database of which includes more than 2 billion queries.

It is distinguished by its operational operation, as well as useful features:

  • supports a large list of exception words (up to 10 thousand);
  • allows you to create and use lists of words directly when forming a sample;
  • offers to compile lists of words by multiplying several lists (Combinator);
  • removes duplicate keywords;
  • shows frequency (but only “worldwide”, without selecting a region);
  • analyzes domains (one or more, comparing SYNAL resources);
  • exported in .csv format.

The only important drawback for installation program– large “weight” (in the archived format ≈ 28 GB, in the unpacked format ≈ 100 GB). But there is an alternative - selecting SYS online.

II. PAID using programs:

Base of Maxim Pastukhov

A Russian service that contains a database of more than 1.6 billion keywords with Yandex WordStat and Direct data, as well as an English service containing more than 600 million words. It works online and helps not only in creating a semantic core, but also in launching an advertising campaign in Yandex.Direct. Its most important and important disadvantage can be safely called its high cost.

Key Collector

Perhaps the most popular and convenient tool for collecting the semantic core.

Key Collector:

  • collects keywords from the right and left columns of WordStat Yandex;
  • filters out unnecessary requests using the Stop Words option;
  • searches for duplicates and identifies seasonal keywords;
  • filters keys by frequency;
  • uploaded in Excel table format;
  • finds pages relevant to the request;
  • collects statistics from: Google Analytics, AdWords, etc.

You can evaluate how Kay Collector collects the semantic core for free in the demo version.

Rush Analytics

A service with which you can collect and cluster the semantic core.

In addition, Rush Analytics:

  • looks for hints in Youtube, Yandex and Google;
  • offers a convenient stop word filter;
  • checks indexing;
  • determines frequency;
  • checks site positions for desktops and mobiles;
  • generates technical specifications for texts, etc.

An excellent tool, but paid: no demo version and limited free checks.

Mutagen

The program collects key queries from the first 30 sites in search engine Yandex. Shows the frequency per month, the competitiveness of each search query and recommends using words with an indicator of up to 5 (since high-quality content is enough to effectively promote such keywords).

Useful article: 8 types of texts for a website - write correctly

A paid program for collecting the semantic core, but there is a free limit - 10 checks per day (available after the first replenishment of the budget, at least by 1 ruble). Open only to registered users.

Keyword Tool

A reliable service for creating a semantic core that:

  • in the free version– collects more than 750 keys for each request using Google, Youtube Bing, Amazon, eBay tips, App Store, Instagram;
  • in paid– shows the frequency of requests, competition, cost in AdWords and dynamics.

The program does not require registration.

In addition to the presented tools, there are many other services for collecting the semantic core of a site with detailed video reviews and examples. I settled on these because I think they are the most effective, simple and convenient.

Conclusion. If possible, it is advisable to purchase licenses to use paid programs, since they have much wider functionality than free analogues. But for simple collection of CN, “open” services are also quite suitable.

Clustering of the semantic core

A ready-made semantic core, as a rule, includes many keywords (for example, for the request “upholstered furniture,” services return several thousand words). What to do next with such a huge number of keywords?

The collected keys are needed:

I. Clear away “garbage”, duplicates and “dummies”

Requests with zero frequency or errors are simply deleted. To eliminate keys with unnecessary “tails,” I recommend using Excel function"Sorting and Filtering". What can be considered garbage? For example, for a commercial site, words such as “download”, “free”, etc. will be superfluous. Duplicates can also be automatically removed in Excel using the “remove duplicates” option (see examples below).

We remove keys with zero frequency:

Removing unnecessary “tails”:

Getting rid of duplicates:

II. Remove highly competitive queries

If you don’t want the “path” to the top to last for years, exclude VK keys. With such keywords, it will not be enough to just get to the first positions in the search results, but what is more important and more difficult is to try to stay there.

An example of how to determine VK-keys through the keyword planner from Google (you can leave only NK and SK through the filter):

III. Perform ungrouping of the semantic core

You can do this in two ways:

1. PAID:

  • KeyAssort– a semantic core clusterer that helps create a site structure and find niche leaders. Powered by search engines Yandex and Google. Performs ungrouping of 10 thousand requests in just a couple of minutes. You can evaluate the benefits of the service by downloading the demo version.

  • SEMparser performs automatic grouping of keys; creating a site structure; identification of leaders; generation of technical specifications for copywriters; Yandex backlight parsing; determining the geodependence and “commerciality” of queries, as well as the relevance of pages. In addition, the service checks how well the text matches the top according to SEO parameters. How it works: collect SYNOPSIS and save it in .xls or .xlsx format. You create a new project on the service, select a region, upload a file with queries - and after a few seconds you receive words sorted into semantic groups.

In addition to these services, I can also recommend Rush Analytics, whom we have already met above, and Just-Magic.

Rush Analytics:

Just-Magic:

2. FREE:

  • Manually- With using Excel and the Sort and Filter functions. To do this: set a filter, enter a query for the group (for example, “buy”, “price”), highlight the list of keys in color. Next, set up the “Custom sorting” option (in “Sorting by color”) by going to “sort within the specified range.” The final touch is to add names to the groups.

Step 1

Step 2

Step 3

Step 4

An example of an ungrouped semantic core:

  • SEOQUICK– a free online program for automatic clustering of the semantic core. To “scatter” keys into groups, just download a file with requests or add them manually and wait a minute. The tool works quickly, determining the frequency and type of key. Allows you to delete unnecessary groups and export the document in Excel format.

  • Keyword Assistant. The service works online on the principle of an Excel table, i.e. you will have to distribute the keywords manually, but it takes much less time than working in Excel.

How to cluster the semantic core and what methods to use is up to you. I believe that the way you need it can only be done manually. It's long, but effective.

After collecting and distributing the semantic core into sections, you can begin writing texts for the pages.

Read a related article with examples: How to correctly enter keywords into the text?

General rules for creating FL

To summarize, it is important to add tips that will help you assemble the correct semantic core:

The marketing statement should be designed so that it meets the needs of as many potential clients as possible.

The semantics must exactly correspond to the theme of the web project, i.e. You should focus only on targeted queries.

It is important that the finished semantic core includes only a few high-frequency keys, the rest is filled with mid- and low-frequency ones.

The semantic core should be regularly expanded to increase natural traffic.

And the most important thing: everything on the site (from keys to structure) must be done “for people”!

Conclusion. A well-assembled semantic core gives a real chance to quickly promote and maintain a site in top positions in search results.

If you doubt that you can assemble the correct semantic language, it is better to order a semantic core for the site from professionals. This will save energy, time and bring more benefits.

It will also be interesting to know: How to place and speed up the indexing of an article? 5 secrets of success

That's all. I hope the material will be useful to you in your work. I would be grateful if you share your experience and leave comments. Thank you for your attention! Until new online meetings!

Developing a kernel is rightfully considered not an easy task, but anyone can write a simple kernel. To experience the magic of kernel hacking, you just need to follow some conventions and master the assembler language. In this article we will show you how to do this.


Hello World!

Let's write a kernel that will boot via GRUB on x86-compatible systems. Our first kernel will show a message on the screen and stop there.

How x86 machines boot

Before thinking about how to write a kernel, let's look at how a computer boots up and transfers control to the kernel. Most x86 processor registers have specific values ​​after boot. The instruction pointer register (EIP) contains the address of the instruction that will be executed by the processor. Its hardcoded value is 0xFFFFFFF0. That is, the x86 processor will always start execution from the physical address 0xFFFFFFF0. This is the last 16 bytes of the 32-bit address space. This address is called the reset vector.

The memory card contained in the chipset states that address 0xFFFFFFF0 refers to a specific part of the BIOS, and not to RAM. However, the BIOS copies itself into RAM for faster access - this process is called “shadowing”, creating a shadow copy. So address 0xFFFFFFF0 will only contain an instruction to jump to the location in memory where the BIOS has copied itself.

So, the BIOS starts executing. First, it looks for devices from which it can boot in the order specified in the settings. It checks media for a "magic number" that distinguishes bootable disks from regular ones: if bytes 511 and 512 in the first sector are 0xAA55, then the disk is bootable.

Once the BIOS finds the boot device, it will copy the contents of the first sector into RAM, starting at address 0x7C00, and then move execution to that address and begin executing the code it just loaded. This code is called a bootloader.

The bootloader loads the kernel at physical address 0x100000. This is what most popular x86 kernels use.

All x86-compatible processors start out in a primitive 16-bit mode called "real mode". The GRUB bootloader switches the processor to 32-bit protected mode by setting the bottom bit of the CR0 register to one. Therefore, the kernel begins to load in 32-bit protected mode.

Note that GRUB, in the case of Linux kernels, selects the appropriate boot protocol and loads the kernel in real mode. Linux kernels automatically switch to protected mode.

What do we need

  • x86 compatible computer (obviously)
  • Linux
  • NASM assembler,
  • ld (GNU Linker),
  • GRUB.

Assembly language entry point

We would, of course, like to write everything in C, but we won’t be able to completely avoid using assembler. We will write a small file in x86 assembler that will become the starting point for our kernel. All the assembly code will do is call an external function that we will write in C, and then stop the program from executing.

How can we make assembly code the starting point for our kernel? We use a linker script that links object files and creates the final kernel executable file (I'll explain more below). In this script, we will directly indicate that we want our binary to download at address 0x100000. This is the address, as I already wrote, at which the bootloader expects to see the entry point into the kernel.

Here is the assembler code.

kernel.asm
bits 32 section .text global start extern kmain start: cli mov esp, stack_space call kmain hlt section .bss resb 8192 stack_space:

The first bits 32 instruction is not x86 assembler, but a NASM directive telling it to generate code for the processor to run in 32-bit mode. This is not necessary for our example, but it is good practice to indicate it explicitly.

The second line begins the text section, also known as the code section. All our code will go here.

global is another NASM directive, it declares the symbols in our code to be global. This will allow the linker to find the start symbol, which serves as our entry point.

kmain is a function that will be defined in our kernel.c file. extern declares that the function is declared somewhere else.

Next comes the start function, which calls kmain and stops the processor with the hlt instruction. Interrupts can wake up the processor after hlt , so we first disable interrupts with the cli (clear interrupts) instruction.

Ideally, we should allocate some amount of memory for the stack and point the stack pointer (esp) to it. GRUB seems to do this for us anyway, and at this point the stack pointer is already set. However, just in case, let's allocate some memory in the BSS section and point the stack pointer to its beginning. We use the resb instruction - it reserves memory specified in bytes. A mark is then left indicating the edge of the reserved piece of memory. Just before kmain is called, the stack pointer (esp) is directed to this area by the mov instruction.

Kernel in C

In the kernel.asm file we called the kmain() function. So in C code, execution will start from there.

kernel.c
void kmain(void) ( const char *str = "my first kernel"; char *vidptr = (char*)0xb8000; unsigned int i = 0; unsigned int j = 0; while(j< 80 * 25 * 2) { vidptr[j] = " "; vidptr = 0x07; j = j + 2; } j = 0; while(str[j] != "\0") { vidptr[i] = str[j]; vidptr = 0x07; ++j; i = i + 2; } return; }

All our kernel will do is clear the screen and print the line my first kernel.

First, we create a vidptr pointer that points to address 0xb8000. In protected mode, this is the beginning of video memory. Text screen memory is simply part of the address space. A section of memory is allocated for screen I/O, which starts at address 0xb8000; 25 lines of 80 ASCII characters are placed in it.

Each character in text memory is represented by 16 bits (2 bytes), rather than the 8 bits (1 byte) we are used to. The first byte is the ASCII code of the character, and the second byte is the attribute-byte. This is a definition of the character format, including its color.

To output the character s green on black, we need to put s in the first byte of video memory and the value 0x02 in the second byte. 0 here means black background and 2 means green color. We will use a light gray color, its code is 0x07.

In the first while loop, the program fills all 25 lines of 80 characters with empty characters with the 0x07 attribute. This will clear the screen.

In the second while loop, the null-terminated string my first kernel is written to video memory and each character receives an attribute-byte of 0x07. This should output a string.

Layout

Now we must compile kernel.asm into an object file using NASM, and then use GCC to compile kernel.c into another object file. Our task is to link these objects into an executable kernel suitable for loading. To do this, we will need to write a script for the linker (ld), which we will pass as an argument.

link.ld
OUTPUT_FORMAT(elf32-i386) ENTRY(start) SECTIONS ( . = 0x100000; .text: ( *(.text) ) .data: ( *(.data) ) .bss: ( *(.bss) ) )

Here we first set the format (OUTPUT_FORMAT) of our executable file to 32-bit ELF (Executable and Linkable Format), a standard binary format for Unix-based systems for the x86 architecture.

ENTRY takes one argument. It specifies the name of the symbol that will serve as the entry point of the executable file.

SECTIONS is the most important part for us. Here we define the layout of our executable file. We can define how the different sections will be combined and where each section will be placed.

In the curly braces that follow the SECTIONS expression, the dot indicates the location counter. It is automatically initialized to 0x0 at the beginning of the SECTIONS block, but can be changed by assigning a new value.

I wrote earlier that kernel code should start at address 0x100000. This is why we assign the position counter the value 0x100000.

Take a look at the line.text: ( *(.text) ) . The asterisk here specifies a mask that can match any file name. Accordingly, the expression *(.text) means all input .text sections in all input files.

As a result, the linker will merge all text sections of all object files into the text section of the executable file and place it at the address specified in the position counter. The code section of our executable will start at address 0x100000.

After the linker produces a text section, the position counter value will be 0x100000 plus the size of the text section. Similarly, the data and bss sections will be merged and placed at the address specified by the position counter.

GRUB and multiboot

Now all our files are ready to build the kernel. But since we will be booting the kernel using GRUB, there is one more step left.

There is a standard for loading different x86 kernels using a bootloader. This is called the "multiboot specification". GRUB will only load kernels that match it.

According to this specification, the kernel may contain a header (Multiboot header) in the first 8 kilobytes. This header must contain three fields:

  • magic- contains the “magic” number 0x1BADB002, by which the header is identified;
  • flags- this field is not important for us, you can leave it zero;
  • checksum- checksum, should give zero if added to the magic and flags fields.

Our kernel.asm file will now look like this.

kernel.asm
bits 32 section .text ;multiboot spec align 4 dd 0x1BADB002 ;magic dd 0x00 ;flags dd - (0x1BADB002 + 0x00) ;checksum global start extern kmain start: cli mov esp, stack_space call kmain hlt section .bss resb 8192 stack_space:

The dd instruction specifies a 4-byte double word.

Assembling the kernel

So, everything is ready to create an object file from kernel.asm and kernel.c and link them using our script. We write in the console:

$ nasm -f elf32 kernel.asm -o kasm.o

Using this command, the assembler will create a file kasm.o in ELF-32 bit format. Now it's GCC's turn:

$ gcc -m32 -c kernel.c -o kc.o

The -c parameter indicates that the file does not need to be linked after compilation. We will do it ourselves:

$ ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o

This command will run the linker with our script and generate an executable called kernel.

WARNING

Kernel hacking is best done in a virtual environment. To run the kernel in QEMU instead of GRUB, use the command qemu-system-i386 -kernel kernel .

Setting up GRUB and starting the kernel

GRUB requires that the name of the kernel file follow the kernel-<версия>. So let's rename the file - I'll call mine kernel-701.

Now we put the kernel in the /boot directory. This will require superuser privileges.

You will need to add something like this to the GRUB configuration file grub.cfg:

Title myKernel root (hd0,0) kernel /boot/kernel-701 ro

Don't forget to remove the hiddenmenu directive if it is included.

GRUB 2

To run the kernel we created in GRUB 2, which is supplied by default in new distributions, your config should look like this:

Menuentry "kernel 701" ( set root="hd0,msdos1" multiboot /boot/kernel-701 ro )

Thanks to Ruben Laguana for this addition.

Reboot your computer and you should see your kernel in the list! And when you select it, you will see that same line.



This is your core!

Writing a kernel with keyboard and screen support

We have completed work on a minimal kernel that boots via GRUB, runs in protected mode, and prints a single line to the screen. It's time to expand it and add a keyboard driver that will read characters from the keyboard and display them on the screen.

We will communicate with I/O devices through I/O ports. Essentially, they are just addresses on the I/O bus. There are special processor instructions for reading and writing operations.

Working with ports: reading and output

read_port: mov edx, in al, dx ret write_port: mov edx, mov al, out dx, al ret

I/O ports are accessed using the in and out instructions included in the x86 set.

In read_port, the port number is passed as an argument. When the compiler calls a function, it pushes all the arguments onto the stack. The argument is copied to the edx register using a stack pointer. The dx register is the lower 16 bits of the edx register. The in instruction here reads the port number given in dx and puts the result in al . The al register is the lower 8 bits of the eax register. You may remember from college that the values ​​returned by functions are passed through the eax register. So read_port allows us to read from I/O ports.

The write_port function works in a similar way. We take two arguments: the port number and the data that will be written. The out instruction writes data to a port.

Interrupts

Now, before we get back to writing the driver, we need to understand how the processor knows that one of the devices has performed an operation.

The simplest solution is to poll devices - continuously check their status in a circle. This is, for obvious reasons, ineffective and impractical. So this is where interrupts come into play. An interrupt is a signal sent to the processor by a device or program that indicates that an event has occurred. By using interrupts, we can avoid the need to poll devices and will only respond to events that interest us.

A chip called the Programmable Interrupt Controller (PIC) is responsible for interrupts in the x86 architecture. It handles hardware interrupts and routes and turns them into appropriate system interrupts.

When the user does something with the device, a pulse called an Interrupt Request (IRQ) is sent to the PIC chip. The PIC translates the received interrupt into a system interrupt and sends a message to the processor that it is time to stop what it is doing. Further interrupt handling is the task of the kernel.

Without PIC, we would have to poll all the devices present in the system to see if an event occurred involving any of them.

Let's look at how this works with a keyboard. The keyboard hangs on ports 0x60 and 0x64. Port 0x60 sends data (when a button is pressed), and port 0x64 sends status. However, we need to know when exactly to read these ports.

Interruptions come in handy here. When the button is pressed, the keyboard sends a PIC signal through the IRQ1 interrupt line. The PIC stores the offset value saved during its initialization. It adds the input line number to this padding to form an interrupt vector. The processor then looks up a data structure called the Interrupt Descriptor Table (IDT) to give the interrupt handler the address corresponding to its number.

The code at that address is then executed and handles the interrupt.

Set IDT

struct IDT_entry( unsigned short int offset_lowerbits; unsigned short int selector; unsigned char zero; unsigned char type_attr; unsigned short int offset_higherbits; ); struct IDT_entry IDT; VOID IDT_INIT (VOID) (UNSIGned LONG KEYboard_ADDRESS; UNSIGned LONG IDTRESS; UNSIGNED LONG IDT_PTR; KEYboard_ADDRESS = (UNSIGNED LONG) Keyboard_HANDER; .OFSET_LWERBITS = keyboard_ADDRESS & 0XFFF; ; IDT.type_attr = 0x8e; /* INTERRUPT_GATE */ IDT.offset_address & 0xffff0000 >> 16; write_port(0xA0, 0x11); 0x28); write_port(0x21, 0x00); write_port(0xA1, 0x01); write_port(0xA1, 0xff); )IDT ; idt_ptr = (sizeof (struct IDT_entry) * IDT_SIZE) + ((idt_address & 0xffff)<< 16); idt_ptr = idt_address >> 16 ;

IDT is an array of IDT_entry structures. We'll discuss binding a keyboard interrupt to a handler later, but now let's look at how the PIC works.

Modern x86 systems have two PIC chips, each with eight input lines. We'll call them PIC1 and PIC2. PIC1 receives IRQ0 to IRQ7, and PIC2 receives IRQ8 to IRQ15. PIC1 uses port 0x20 for commands and 0x21 for data, and PIC2 uses port 0xA0 for commands and 0xA1 for data.

Both PICs are initialized with eight-bit words called Initialization command words (ICW).

In protected mode, both PICs first need to issue the initialization command ICW1 (0x11). It tells the PIC to wait for three more initialization words to arrive on the data port.

These commands will pass the PIC:

  • indent vector (ICW2),
  • what are the master/slave relationships between PICs (ICW3),
  • additional information about the environment (ICW4).

The second initialization command (ICW2) is also sent to the input of each PIC. It assigns offset , which is the value to which we add the line number to get the interrupt number.

PICs allow their pins to be cascaded to each other's inputs. This is done using ICW3 and each bit represents the cascade status for the corresponding IRQ. Now we will not use cascading redirection and will set it to zero.

ICW4 sets Extra options environment. We only need to define the low bit so that the PICs know we are running in 80x86 mode.

Ta-dam! The PICs are now initialized.

Each PIC has an internal eight-bit register called the Interrupt Mask Register (IMR). It stores bitmap IRQ lines that go to the PIC. If the bit is set, the PIC ignores the request. This means that we can enable or disable a specific IRQ line by setting the corresponding value to 0 or 1.

Reading from the data port returns the value in the IMR register, while writing changes the register. In our code, after initializing the PIC, we set all bits to one, which deactivates all IRQ lines. Later we will activate the lines that correspond to keyboard interrupts. But first, let's turn it off!

If the IRQ lines are working, our PICs can receive signals on the IRQ and convert them into an interrupt number, adding offset. We need to fill out the IDT in such a way that the interrupt number coming from the keyboard matches the address of the handler function that we will write.

What interrupt number do we need to bind the keyboard handler to in the IDT?

The keyboard uses IRQ1. This is input line 1 and is processed by PIC1. We initialized PIC1 with offset 0x20 (see ICW2). To get the interrupt number, you need to add 1 and 0x20, you get 0x21. This means that the address of the keyboard handler will be tied in IDT to interrupt 0x21.

The task comes down to filling out the IDT for interrupt 0x21. We will map this interrupt to the keyboard_handler function, which we will write in the assembly file.

Each entry in the IDT consists of 64 bits. In the entry corresponding to the interrupt, we do not store the entire address of the handler function. Instead, we split it into two 16-bit pieces. The low-order bits are stored in the first 16 bits of the IDT entry, and the high-order 16 bits are stored in the last 16 bits of the entry. All this is done for compatibility with 286 processors. As you can see, Intel produces numbers like this on a regular basis and in many, many places!

In the IDT entry, we just have to register the type, thus indicating that all this is being done to catch the interrupt. We also need to set the offset of the kernel code segment. GRUB sets the GDT for us. Each GDT entry is 8 bytes long, where the kernel code descriptor is the second segment, so its offset will be 0x08 (the details are beyond the scope of this article). The interrupt gate is represented as 0x8e. The remaining 8 bits in the middle are filled with zeros. This way we will populate the IDT entry that corresponds to the keyboard interrupt.

Once we're done with the IDT mapping, we need to tell the processor where the IDT is. There is an assembly instruction called lidt for this; it takes one operand. This is a pointer to a descriptor of the structure that describes the IDT.

There are no difficulties with the descriptor. It contains the size of the IDT in bytes and its address. I used an array to make it more compact. In the same way, you can fill a descriptor using a structure.

In the idr_ptr variable we have a pointer that we pass to the lidt instruction in the load_idt() function.

Load_idt: mov edx, lidt sti ret

Additionally, the load_idt() function returns an interrupt when using the sti instruction.

With the IDT populated and loaded, we can access the keyboard IRQ using the interrupt mask we talked about earlier.

Void kb_init(void) ( write_port(0x21, 0xFD); )

0xFD is 11111101 - enable only IRQ1 (keyboard).

Function - keyboard interrupt handler

So, we have successfully bound keyboard interrupts to the keyboard_handler function by creating an IDT entry for interrupt 0x21. This function will be called every time you press a button.

Keyboard_handler: call keyboard_handler_main iretd

This function calls another function written in C and returns control using iret class instructions. We could write our entire handler here, but it’s much easier to code in C, so let’s roll over there. The iret/iretd instructions should be used instead of ret when control returns from the interrupt-handling function to the interrupted program. This instruction class raises a flag register, which is pushed onto the stack when an interrupt is called.

Void keyboard_handler_main(void) ( unsigned char status; char keycode; /* Write EOI */ write_port(0x20, 0x20); status = read_port(KEYBOARD_STATUS_PORT); /* The lower status bit will be set if the buffer is not empty */ if (status & 0x01) ( keycode = read_port(KEYBOARD_DATA_PORT); if(keycode< 0) return; vidptr = keyboard_map; vidptr = 0x07; } }

Here we first give an EOI (End Of Interrupt) signal by writing it to the PIC command port. Only then will the PIC allow further interrupt requests. We need to read two ports: data port 0x60 and command port (aka status port) 0x64.

First of all, we read port 0x64 to get the status. If the bottom bit of the status is zero, then the buffer is empty and there is no data to read. In other cases we can read data port 0x60. It will give us the code of the key pressed. Each code corresponds to one button. We use a simple character array defined in keyboard_map.h to map the codes to the corresponding characters. The symbol is then displayed on the screen using the same technique that we used in the first version of the kernel.

To keep the code simple, I only process lowercase letters from a to z and numbers from 0 to 9. You can easily add special characters, Alt, Shift and Caps Lock. You can find out that a key was pressed or released from the output of the command port and perform the appropriate action. In the same way, you can bind any keyboard shortcuts to special functions like shutdown.

Now you can build the kernel and run it on a real machine or on an emulator (QEMU) in the same way as in the first part.



 


Read:



What is an SSD and how to install it?

What is an SSD and how to install it?

The performance and lifespan of an SSD is primarily dependent on the NAND flash memory and controller firmware. They are the main components...

How to put an accent on a letter in Word

How to put an accent on a letter in Word

When working in Word, one day you will have to face the need to add an accent mark. You can, of course, highlight the stressed vowel in bold...

How to convert images to PNG format?

How to convert images to PNG format?

The JPG image format has a higher compression ratio than PNG, and therefore images with this extension have less weight. In order to reduce...

Technical problems and their solutions v

Technical problems and their solutions v

Well done, I hope it helps. Blockhead has indeed remained established since the days of OCO... Good lore scholars are in close contact with the universe....

feed-image RSS