Setting Up Dev C++

Posted on by
Difficulty level

Beginner

Jul 16, 2009 These notes explain how to compile programs written in ANSI C with OpenGL and GLUT using the Dev-C compiler. Bloodshed Dev-C is a free C compiler and development environment for Windows operating systems. Like most C compilers, it also c. 5)Now take the SDL.dll from the SDL folder you extracted (it should be inside the bin subfolder) and copy it to where you're going to make your project.You're going to put SDL.dll in the same directory as your exe when you compile it.

This page or section is a work in progress and may thus be incomplete. Its content may be changed in the near future.

This is a guide to setting up paging. It will teach you the basic concepts behind paging and how it can help you with your OS. This example will concentrate on Legacy Non-PSE Non-PAE paging (See also Setting Up Paging With PAE).

Setting Up Dev C Code

Paging is a term that refers to the management of the computer's virtual memory. If you have not yet created a physical memory manager, please read and follow Page Frame Allocation before continuing with this article.

  • 1Basic Paging

Basic Paging

Paging allows you to have more than one virtual address space mapped into the physical address space. The MMU uses what is called a Page Directory to map virtual addresses to physical addresses.


Page Directory - A table in memory which the MMU uses to find the page tables.


Each index in the Page Directory is a pointer to a Page table.


Page Table - A table in memory that describes how the MMU should translate a certain range of addresses.

Traktor pro 2 keybaord shoprtcuts.
Each index in a Page Table contains the physical memory address to which a certain page should be mapped.

Creating a Blank Page Directory

The first step is to create a blank page directory. The page directory is blank because we have not yet created any page tables where the entries in the page directory can point.

Note that all of your paging structures need to be at page-aligned addresses (i.e. being a multiple of 4096). If you have already written a page frame allocator then you can use it to allocate the first free page after your kernel for the page directory. If you have not created a proper page allocator, simply finding the first free page-aligned address after the kernel will be fine, but you should write the page frame allocator as soon as possible. Another temporary solution (used in this tutorial) is to simply declare global objects with __attribute__((align(4096))). Note that this is a GCC extension. It allows you to declare data aligned with some mark, such as 4KiB here. We can use this because we are only using one page directory and one page table. Please note that on the real world, dynamic allocation is too basic to be missing, and paging structures are constantly being added, deleted, and modified. For now, just use static objects;

Now that we have a page directory, we need to blank it. The page directory should have exactly 1024 entries. We will set each entry to not present so that if the MMU looks for that page table, it will see that it is not there (..yet. We will add the first page table in a moment).

A page is 'not present' is one which is not (intended to be) used. If the MMU finds one, it will Page Fault. Non-present pages are useful for techniques such as Lazy Loading. It's also used when a page has been swapped to disk, so the Page Fault is not interpreted as an error by the OS. To the OS, it means someone needs a page it swapped to disk, so it is restored. A page fault over a page that was never swapped is a error by which the OS has a reason to kill the process.

Creating Your First Page Table

The second step is to create a basic page table. In this example we choose to fill up the whole first page table with addresses for the MMU. Because each page is 4 kilobytes large, and because each page table has exactly 1024 entries, filling up the whole table causes us to map 4 megabytes of memory. Also, the page directory is 1024 entries long, so everything can map up to 4GiB, the full 32-bit address space. Remembered the non-present page trick? Without it, we would use 16MiB per each paging structure. A single page directory needs 4KiB, but it can map some tables as non-present, effectively removing their space needs.

Now, its time to create a new page table.

We now need to fill each index in the table with an address to which the MMU will map that page. Index 0 (zero) holds the address from where the first page will be mapped. Likewise, index 1 (one) holds the address for the second page and index 1023 holds the address of the 1024th page. That's for the first table. So, to get the page at which a certain index is mapped is as simple as (PageDirIndexOfTable * 1024) + PageTabIndexOfPage. If you multiply that by 4, you'll get the address (in KiB) at which the page will be loaded. For example, page index 123 in table index 456 will be mapped to (456 * 1024) + 123 = 467067. 467067 * 4 = 1868268 KiB = 1824.48046875 MiB = 1.781719207763671875 GiB. It's easy, right?

Put the Page Table in the Page Directory

The third step is to put the newly created page table into our blank page directory. We do this by setting the first entry in the page directory to the address of our page table.

Enable Paging

The final step is to actually enable paging. First we tell the processor where to find our page directory by putting it's address into the CR3 register. Because C code cannot directly access the computer's registers, we will need to use assembly code to access CR3. The following assembly is written for GAS. If you use a different assembler then you will need to translate between this assembly format and the format supported by your assembler.

This small assembly function takes one parameter: the address of the page directory. It then loads the address onto the CR3 register, where the MMU will find it. But wait! Paging is not still enabled. That's what we will do next. We must set the 32th bit in the CR0 register, the paging bit. This operation also requires assembly code. Once done, paging will be enabled.

Now lets call the functions!

Paging should now be enabled. Try printing something to screen like 'Hello, paging world!'. If all goes well, congratulations! You've just learned the basics of paging. But there are lots of other things to do with it. You won't be able to almost all of them for now. Just remember that you have a little friend in the CR3 register that will help you one day.

Setting Up Opencv In Dev C++

More Advanced Paging Example

Add sections on how to dynamically get and free pages..

Dev C++ Programs

Retrieved from 'https://wiki.osdev.org/index.php?title=Setting_Up_Paging&oldid=22153'

Setting Up Device Guard

  1. NOTE: The default installation path is 'C:Program Files (x86)'
  2. NOTE: For portable Devc++ adjust the instructions to your root install path
  3. 1: Download and install DevC++ (Dev-Cpp 5.11 TDM-GCC 4.9.2),
  4. https://users.cs.jmu.edu/bernstdh/web/common/help/glut-3.7.6-bin.zip
  5. 2.1: Open archive, open 'glut-3.7.6-bin' folder inside it
  6. 2.1.1: copy 'glut32.lib' to 'C:Program Files (x86)Dev-CppMinGW64lib'
  7. 2.1.2: copy 'glut32.dll' to 'C:Program Files (x86)Dev-CppMinGW64bin'
  8. 3: Download glut devpak from
  9. http://www.nigels.com/glt/devpak/glut-7.6-3.DevPak
  10. 3.1: Extract the devpak with a tool like '7zip'
  11. 3.1.1: Open the folder 'glut-7.6-3', open 'glut' folder. You should see 3 folders inside it and a devpak.
  12. 3.1.2: copy 'include' folder to 'C:Program Files (x86)Dev-CppMinGW64'
  13. 3.1.3: copy 'lib' folder to 'C:Program Files (x86)Dev-CppMinGW64'
  14. 3.1.4: copy 'Templates' folder to 'C:Program Files (x86)Dev-Cpp'
  15. 3.1.5.1: open Devc++, click 'Tools', click 'Package Manager', click 'Install', select and install 'glut.DevPackage' that was inside the devpak
  16. 4.1: click 'Tools', click 'Compiler Options'
  17. 4.2: Change Compiler set to 'TDM-GCC 4.9.2 32-bit Release'
  18. 4.3.1: check 'Add the following commands when following the linker'
  19. 4.3.2: paste this in there, with quotations include
  20. -static-libgcc 'C:Program Files (x86)Dev-CppMinGW64libglut32.lib'
  21. 4.4: click 'Directories', click 'Libraries'
  22. 4.4.1: paste this in bottom textbar and click 'Add', dont include ': 'C:Program Files (x86)Dev-CppMinGW64lib'
  23. 5: Creating GLut project:
  24. 5.1 In Devc++ click 'File', click 'New', click 'Project', click 'Multimedia', click 'glut' and click 'Ok'
  25. YOURE DONE!
  26. ps: if you get errors either the glut32.lib path is not setup properly or the glut32.dll was not copied