osdev | Hobby OS - Following the tutorial : https : //littleosbook | Learning library
kandi X-RAY | osdev Summary
kandi X-RAY | osdev Summary
Following the tutorial:
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of osdev
osdev Key Features
osdev Examples and Code Snippets
Community Discussions
Trending Discussions on osdev
QUESTION
I get it that if a page has been accessed it'll have the Access bit set, and if has been written to, the Dirty bit will also be set. But it's unclear to me how these bits affect the TLB/TLB caching? Also OSDEV has the following paragraph
When changing the accessed or dirty bits from 1 to 0 while an entry is marked as present, it's recommended to invalidate the associated page. Otherwise, the processor may not set those bits upon subsequent read/writes due to TLB caching.
In what cases would you change the dirty and access bits from 1 to 0?
...ANSWER
Answered 2022-Mar-23 at 09:51In what cases would you change the dirty and access bits from 1 to 0?
If the OS is running low on memory it'll want to free some pages (e.g. send the page's data to swap space so it can use the physical memory for something else). Often this will be based on "least recently used", but the CPU only has 1 "accessed" flag for each page, so to work around that the OS checks the accessed flags periodically and clears them back to zero so it knows (roughly) how long ago a page was accessed and not just if it was/wasn't accessed. It's a little like "if(page->accessFlag == 1) { page->accessFlag = 0; page->time_since_access = 0; } else { page->time_since_access++; }
".
For the dirty flag, consider a read/write memory mapped file, or a write-back disk cache. A program modifies data in memory (causing the dirty flag to be set); then when the disk drive has nothing better to do the OS might find pages with the dirty flag set, write them to disk, and clear the dirty flag/s back to zero (so the same page doesn't get written to disk again for no reason next time).
How does the Dirty and Access bits affect the TLB?
It's more the opposite - the TLB effects the flags (and the flags don't effect the TLB).
When a CPU sets the dirty or accessed flags it does an atomic update of memory to guard against race conditions (e.g. other CPUs modifying or checking the same page table entry at the same time), and atomic updates are somewhat expensive. To reduce/avoid these atomic writes a CPU can (and most likely will) cache the page's accessed and dirty flags in the TLB entry so that the atomic write can be skipped if the CPU wants to set the flag/s but the TLB entry says they're already set anyway. If the TLB entry is wrong (e.g. because the OS changed the accessed or dirty flags in memory but didn't invalidate the TLB entry) then the CPU can skip atomic writes that were needed by the OS. This can cause data corruption (e.g. OS assuming that a page's contents in memory don't need to be written to disk because the dirty flag wasn't set).
QUESTION
I recently got interested in developing my own operating system for fun. While creating the OS and the drivers, I encountered several issues while making the ATA driver. One of the major issues is that if I try to request ATAPIO to read an address (in CHS) and try to get the results from the data port (0x1F0), it returns the same number each time I poll the port. Any suggestions welcome!
Link to repo (code looks better)
ata.hpp
...ANSWER
Answered 2022-Mar-15 at 20:22As it turns out, all the ATA commands need to be in 8 bit (or 1 byte) input/output. This means that all the inw() and outw() function calls should be converted into inb() and outb() function calls instead. When I made the switch, the problems disappeared!
QUESTION
My system is Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
and bios is version J51 v01.35
release data of bios 01/10/2012
So Should I believe I am using SMBIOS 2 or SMBios 3
On wiki.Osdev there are no docs for version 3 but there are for version 2 for SMBIOS
...ANSWER
Answered 2022-Mar-10 at 04:03You can find this information using dmidecode
:
QUESTION
According to OSDev, to locate the Port I/O address of ACPI timer, we first open FADT table and check entries PM Timer Block Length
and PM Timer Block Address
. In my computer, PM Timer Block Address
gives address 0x408
and it works correctly.
However, in the implementation of OVMF, the I/O address of ACPI timer is calculated as PMBA + 0x8
. I search the internet and found no information about this way of calculation.
I'm wondering are both methods to decide ACPI timer address correct? If both are correct, where can I find definitions of information about the second way of calculation?
...ANSWER
Answered 2022-Jan-18 at 09:31Firmware (e.g. OVMF) uses chipset specific methods to determine the IO port of the ACPI timer; and then constructs the FADT and fills it in so that an OS doesn't need to be chipset specific.
If you don't want to use FADT, then you can write a chipset specific driver for each chipset. For some cases (open source emulators) this may be relatively easy, and for some cases (proprietary and undocumented real hardware) this will be almost impossible.
QUESTION
I can not get ld to link a very simple program because of a truncated relocation.
...ANSWER
Answered 2021-Dec-02 at 18:44So I figured out my problem!
I missed a . in a symbol name.
QUESTION
I want to use the serial port COM1
without using the BIOS interrupt 14h, and for this purpose I am following the tutorial at osdev but I have some problems during the initialization. (I am pretty new to asm and to bios related stuff so my code may be very wrong or may be there is a need to initialize other things before I can initialize the serial port)
My current code looks like this, and should be a direct translation of their C code.
...ANSWER
Answered 2021-Oct-07 at 18:36Given the outb macro definition, NASM will expand your outb [com1+1], 0x00
macro invokation into:
QUESTION
Title says it all, my pic masking works. If i send an IRQ (key-stroke) the kernel crashes. I'm using nasm. What should i do to get the exception_handler function executed when an interrupt gets send?
idt.h
...ANSWER
Answered 2021-Sep-09 at 18:50everything was right but the gdt wasn't initialized the right way
QUESTION
I have a simple working (32-bit protected mode) kernel with clock interrupt. I can see that this interrupt is working because it prints « clock » a lot of time. I can also see that this interrupt gives back control to kernel because it prints « Kernel has stopped » on screen after few clock interrupts, like it is supposed to. Interrupts are located in same code segment as the kernel.
I did not set any TSS, but it is working. I can read on this article (https://web.archive.org/web/20160326062442/http://jamesmolloy.co.uk/tutorial_html/10.-User%20Mode.html) that when an interrupt occurs, the cpu will look into the selected TSS segment to update the registers.
How can it work if I don’t have this TSS ? Is it because when interrupts occurs the CPU will still automatically push EIP, CS, EFLAGS, EPS, SS and restore them on iret ?
If I load a single TSS, how this interrupt will know that it should use this TSS ? With ltr instruction that will take the according tss segment inside the GDT?
Not really related, but when using hardware context switching and jmp to one TSS, will it automatically jump to the previous (no next field so I’m a little bit lost) tss segment automatically when return ?
These are questions I cannot really have a clear answer for from my school courses neither osdev, or this forum.
...ANSWER
Answered 2021-Aug-27 at 10:24As Michael Petch explained in the comments, you don't need a TSS if the interrupt handler is executing at the same privilege.
The CPU will read the necessary SS:SP
pair from the TSS only if the interrupt is going to be executed in a more privileged ring w.r.t the current code's ring (e.g. a transition from ring 3 to ring 0).
This is detailed in chapter 6.12.1 of the 3rd Intel's manual:
When the processor performs a call to the exception- or interrupt-handler procedure:
If the handler procedure is going to be executed at a numerically lower privilege level, a stack switch occurs. When the stack switch occurs:
-. The segment selector and stack pointer for the stack to be used by the handler are obtained from the TSS for the currently executing task. On this new stack, the processor pushes the stack segment selector and stack pointer of the interrupted procedure.
[redacted]If the handler procedure is going to be executed at the same privilege level as the interrupted procedure: a. The processor saves the current state of the EFLAGS, CS, and EIP registers on the current stack (see Figure 6-4).
[redacted]
It's worth noting that in 64-bit mode the task switching mechanism is no longer supported.
We cannot call
or jmp
or use a task gate.
However, confusingly enough, the TSS is still used and mandatory. This structure is now used as it has been used in practice by the mainstream OSes: as a global (read: the same for every task, at least in theory) buffer where to store stack switching and other information.
Also worth noting is that in 64-bit mode the new IST mechanism is used for task switching (see section 6.14.5 of the 3rd Intel's manual).
How can it work if I don’t have this TSS ? Is it because when interrupts occurs the CPU will still automatically push EIP, CS, EFLAGS, EPS, SS and restore them on iret ?
The CPU won't use the TSS when there is no privilege level change. To understand what is pushed and in what order, see this picture below taken from Intel's manual volume 3:
If I load a single TSS, how this interrupt will know that it should use this TSS ? With ltr instruction that will take the according tss segment inside the GDT?
When an interrupt occurs and the CPU realizes that a privilege change is going to happen it will read the tr
register to reach the current TSS.
Since loading the tr
is a privilege operation, the OS is in control of what TSS will be used.
Infact, if the OS wanted to use two different TSS, A and B, for two different programs Pa and Pb, it will reload tr
each time is about to execute one of those programs.
So yes, the ltr
instruction is how the OS controls the TSS currently active.
Not really related, but when using hardware context switching and jmp to one TSS, will it automatically jump to the previous (no next field so I’m a little bit lost) tss segment automatically when return ?
A task switching, when supported, can be invoked with: jmp
, call
, int
, an interrupt, or an exception.
All of these methods but jmp
will link the current task (the one being switched out) to the new task (the one being switched in).
This is achieved through the Previous Task Link field in the TSS, the new TSS will have this field set to the old TSS selector.
The new task is said to be nested.
The CPU will also use the NT (Nested Task) flag to keep track of whenever the current task is nested or not.
If a task is nested (i.e. invoked with call
, int
, and interrupt or an exception), using the iret
instruction the CPU will read the Previous Task Link to find the suspended Task to resume.
Note that only iret
can be used, even if the task switching was done with call
(which normally pairs with ret/retf
).
This is a picture from the Manual:
QUESTION
I was disassembling an MS-DOS .com application and came across some port access which I don't understand. More precisely, via the IN
instruction, values are read from the following ports.
ANSWER
Answered 2021-Aug-25 at 09:01Your guess seems right. The code tries to set random colors. As it is part of a 256-byte intro, the focus is primarily on code size, not on portability or quality of the random numbers. Possibly this executable was originally meant for a PS/2 or EISA system, and timers 0, 3 and 5 (channel 0 and 2 of the second chip) were free-running. In case you don't have an EISA system, often aliasing will access timers 0, 0 again and 2. This program doesn't enable sound, so timer 2 would be stuck. Furthermore, the code clobbers AH as generated by the DIV instruction at 1BE by executing a MUL instruction at 1CA, so the value read from port 40h isn't used.
To undestand more than this educated guesswork, you would need to contact the author of that code. Considering the bug that AH is clobbered, it seems the code has been created at a demo party under time pressure, and not a lot of "design" went into it. It seems more like "it works well enough".
QUESTION
I'm following the babystep bootloader guide writing the code on GAS as suggested here when I run the image with qemu-system-x86_64 -machine type=pc,accel=kvm -drive 'format=raw,file=boot.bin'
it works as expected, but I'd like to change the machine type to q35
.
Here is my code:
...ANSWER
Answered 2021-Aug-12 at 00:23To fix that bug the image should have 515585 bytes or more, I don't know where this number comes from, I have tested several combinations until achieve this result, if you try one single byte less it doesn't work, but more bytes works fine.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install osdev
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page