AlgorithMan-de / wyoos

Source codes for the "Write your own Operating System" video-series on YouTube
http://wyoos.org
GNU General Public License v3.0
719 stars 222 forks source link

Probable bug in gdt.cpp #4

Open sorjon02 opened 7 years ago

sorjon02 commented 7 years ago

Line 35 in gdt.cpp reads: "if (limit <= 65536)". This is a reference to a memory adress, and a memory adress always start at 0. I recognize the number 65536 as 2^16 so the correct line should probably be "if (limit < 65536)", allowing for memory address from 0 to 65535. Please examine the code and check if I have noticed a bona fide bug.

mpetch commented 6 years ago

Not a bug from what I can tell. The GDT and IDT have a limit that is unique. The value 1 needs to be subtracted from the real limit (per the Intel documentation). GDT and IDT are designed so that a limit of 0 isn't possible. He checks that the pre-adjusted limit <= 65536. 65536 will be stored as 65536-1 (65535).