{"id":23560,"date":"2023-04-21T02:21:55","date_gmt":"2023-04-21T02:21:55","guid":{"rendered":"https:\/\/www.booksofall.com\/es\/?post_type=product&#038;p=23560"},"modified":"2023-04-21T02:21:55","modified_gmt":"2023-04-21T02:21:55","slug":"the-little-book-about-os-development-2","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/","title":{"rendered":"The little book about OS development"},"content":{"rendered":"<h2>Chapter 2 &#8211; First Steps<\/h2>\n<p>Developing an <a href=\"https:\/\/www.techtarget.com\/whatis\/definition\/operating-system-OS\">operating system (OS)<\/a> is no easy task, and the question \u201cHow do I even begin to solve this problem?\u201d is likely to come up several times during the course of the project for different problems. This chapter will help you set up your development environment and booting a very small (and primitive) operating system.<\/p>\n<h3>Tools<\/h3>\n<h4>Quick Setup<\/h4>\n<p>We (the authors) have used <a href=\"https:\/\/ubuntu.com\/\">Ubuntu<\/a>\u00a0 as the operating system for doing OS development, running it both physically and virtually (using the virtual machine <a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox<\/a> ). A quick way to get everything up and running is to use the same setup as we did, since we know that these tools work with the samples provided in this book. Once Ubuntu is installed, either physical or virtual, the following packages should be installed using apt-get:<\/p>\n<p>sudo apt-get install build-essential nasm genisoimage bochs bochs-sdl<\/p>\n<h4>Programming Languages<\/h4>\n<p>The operating system will be developed using the C programming language, using GCC . We use C because developing an OS requires a very precise control of the generated code and direct access to memory. Other languages that provide the same features can also be used, but this book will only cover C. The code will make use of one type attribute that is specific for GCC:<\/p>\n<p>__attribute__((packed))<\/p>\n<p>This attribute allows us to ensure that the compiler uses a memory layout for a struct exactly as we define it in the code. This is explained in more detail in the next chapter. Due to this attribute, the example code might be hard to compile using a C compiler other than GCC. For writing assembly code, we have chosen <a href=\"https:\/\/cs.lmu.edu\/~ray\/notes\/nasmtutorial\/\">NASM<\/a>\u00a0 as the assembler, since we prefer NASM\u2019s syntax over <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_Assembler\">GNU Assembler<\/a>. Bash\u00a0 will be used as the scripting language throughout the book.<\/p>\n<h4>Host Operating System<\/h4>\n<p>All the code examples assumes that the code is being compiled on a UNIX like operating system. All code examples have been successfully compiled using Ubuntu\u00a0 versions 11.04 and 11.10.<\/p>\n<h4>Build System<\/h4>\n<p>Make [13] has been used when constructing the Makefile examples.<\/p>\n<h4>Virtual Machine<\/h4>\n<p>When developing an OS it is very convenient to be able to run your code in a\u00a0<i>virtual machine\u00a0<\/i>instead of on a physical computer, since starting your OS in a virtual machine is much faster than getting your OS onto a physical medium and then running it on a physical machine. Bochs\u00a0 is an emulator for the x86 (IA-32) platform which is well suited for OS development due to its debugging features. Other popular choices are <a href=\"https:\/\/www.qemu.org\/\">QEMU<\/a>\u00a0 and VirtualBox . This book uses Bochs. By using a virtual machine we cannot ensure that our OS works on real, physical hardware. The environment simulated by the virtual machine is designed to be very similar to their physical counterparts, and the OS can be tested on one by just copying the executable to a CD and finding a suitable machine.<\/p>\n<h4>Booting<\/h4>\n<p>Booting an operating system consists of transferring control along a chain of small programs, each one more \u201cpowerful\u201d than the previous one, where the operating system is the last \u201cprogram\u201d. See the following figure for an example of the boot process:<\/p>\n<p id=\"kHVevRt\"><img loading=\"lazy\" decoding=\"async\" width=\"621\" height=\"123\" class=\"alignnone size-full wp-image-23565 \" src=\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/img_6441f0272dd25.png\" alt=\"\" \/><\/p>\n<p>Figure 2.1: An example of the boot process. Each box is a program.<\/p>\n<h4>BIOS<\/h4>\n<p>When the PC is turned on, the computer will start a small program that adheres to the\u00a0<a href=\"https:\/\/www.gartner.com\/en\/information-technology\/glossary\/bios-basic-inputoutput-system\"><i>Basic Input Output System\u00a0<\/i>(BIOS)<\/a>\u00a0 standard. This program is usually stored on a read only memory chip on the motherboard of the PC. The original role of the BIOS program was to export some library functions for printing to the screen, reading keyboard input etc. Modern operating systems do not use the BIOS\u2019 functions, they use drivers that interact directly with the hardware, bypassing the BIOS. Today, BIOS mainly runs some early diagnostics (power-on-self-test) and then transfers control to the bootloader.<\/p>\n<h4>The Bootloader<\/h4>\n<p>The BIOS program will transfer control of the PC to a program called a\u00a0<i>bootloader<\/i>. The bootloader\u2019s task is to transfer control to us, the operating system developers, and our code. However, due to some restrictions1 of the hardware and because of backward compatibility, the bootloader is often split into two parts: the first part of the bootloader will transfer control to the second part, which finally gives control of the PC to the operating system. Writing a bootloader involves writing a lot of low-level code that interacts with the BIOS. Therefore, an existing bootloader will be used: the <a href=\"https:\/\/www.gnu.org\/software\/grub\/\">GNU GRand Unified Bootloader (GRUB)<\/a> . Using GRUB, the operating system can be built as an ordinary ELF\u00a0 executable, which will be loaded by GRUB into the correct memory location. The compilation of the kernel requires that the code is laid out in memory in a specific way (how to compile the kernel will be discussed later in this chapter).<\/p>\n<h4>The Operating System<\/h4>\n<p>GRUB will transfer control to the operating system by jumping to a position in memory. Before the jump, GRUB will look for a magic number to ensure that it is actually jumping to an OS and not some random code. This magic number is part of the\u00a0<i>multiboot specification <\/i>\u00a0which GRUB adheres to. Once GRUB has made the jump, the OS has full control of the computer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/the-little-book-about-os-development-1bs0xd7mp6?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23566,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now."},"product_brand":[],"product_cat":[270],"product_tag":[],"class_list":{"0":"post-23560","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-operating-systems","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The little book about OS development - BooksOfAll Spanish<\/title>\n<meta name=\"description\" content=\"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The little book about OS development - BooksOfAll Spanish\" \/>\n<meta property=\"og:description\" content=\"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Spanish\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/\",\"url\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/\",\"name\":\"The little book about OS development - BooksOfAll Spanish\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg\",\"datePublished\":\"2023-04-21T02:21:55+00:00\",\"description\":\"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"The little book about OS development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/es\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"The little book about OS development\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#website\",\"url\":\"https:\/\/www.booksofall.com\/es\/\",\"name\":\"BooksOfAll Spanish\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/es\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#organization\",\"name\":\"BooksOfAll Spanish\",\"url\":\"https:\/\/www.booksofall.com\/es\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Spanish\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The little book about OS development - BooksOfAll Spanish","description":"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/","og_locale":"es_ES","og_type":"article","og_title":"The little book about OS development - BooksOfAll Spanish","og_description":"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.","og_url":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/","og_site_name":"BooksOfAll Spanish","og_image":[{"url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg","twitter_misc":{"Tiempo de lectura":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/","url":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/","name":"The little book about OS development - BooksOfAll Spanish","isPartOf":{"@id":"https:\/\/www.booksofall.com\/es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg","datePublished":"2023-04-21T02:21:55+00:00","description":"Building a operating system is not an easy task. There are many things we need to decide before we start. Learn more in this book now.","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#primaryimage","url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg","contentUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/04\/The-little-book-about-OS-development-cover.jpg","width":"827","height":"1169","caption":"The little book about OS development"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/es\/the-little-book-about-os-development-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/es\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/es\/categories\/"},{"@type":"ListItem","position":3,"name":"The little book about OS development"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/es\/#website","url":"https:\/\/www.booksofall.com\/es\/","name":"BooksOfAll Spanish","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/es\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/es\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/es\/#organization","name":"BooksOfAll Spanish","url":"https:\/\/www.booksofall.com\/es\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Spanish"},"image":{"@id":"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product\/23560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/media\/23566"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/media?parent=23560"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_brand?post=23560"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_cat?post=23560"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_tag?post=23560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}