Newbie question about messing up in kernel mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
movsd
Posts: 1
Joined: Fri Aug 28, 2009 4:49 pm

Newbie question about messing up in kernel mode

Post by movsd »

This might be a silly question, but I've been unable to find an easy answer by googling. I'm programming and testing some (very basic) bootloader and OS code. Since I've never done anything this low-level before, this code is likely to contain a lot of bugs. My question is: how likely is it that, by such a bug, I might accidentally do (semi-)permanent damage to my computer?

Since I know that modern BIOSes can be flashed I assume that "bricking" is theoretically possible, but since I have no idea how flashing is actually done I don't know if it's at all feasible to do it by accident. Is it? (For now my OS does not do any disk output at all, so I'd think that damaging a disk would fall in the "very unlikely" category.)

So far I've only tested my OS on emulators (Bochs), which should of course be perfectly safe, but eventually I'll want to try it on a real computer...
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: Newbie question about messing up in kernel mode

Post by xvedejas »

As far as I know, the worst you could do is get stuck in a loop and overheat your computer. At least without knowing anything. I'm sure there are worse you can do, but you need to know more before you can make those mistakes :)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Newbie question about messing up in kernel mode

Post by Brendan »

Hi,

Accidentally modifying the BIOS's flash memory is extremely unlikely - you need to access the right I/O ports in the right way.

The other things you might worry about is messing up the contents of CMOS (which is easy to fix anyway), or messing up data on a storage device (e.g. a hard drive). It's extremely unlikely that this will happen accidentally, unless you're writing a device driver or file system code that is meant to modify data (but isn't meant to modify data incorrectly). Backup your data if you're writing code to write to storage devices. For floppy drives it's possible to send the heads to a track that doesn't exists (bash them against the stops), or try to read/write/seek while the motor isn't spinning, but most floppy drives will handle this for a while before any real damage occurs.

The most likely way of accidentally damaging hardware is ancient "VGA only" monitors, which tend to blow up when you set a video mode they don't support. I wouldn't worry about this too much though - most of these old monitors have already blown up (there's not many left, and even less that are actually used), and they're so crappy that blowing them up is probably a not a bad idea. ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Newbie question about messing up in kernel mode

Post by Brendan »

Hi,
xvedejas wrote:As far as I know, the worst you could do is get stuck in a loop and overheat your computer. At least without knowing anything. I'm sure there are worse you can do, but you need to know more before you can make those mistakes :)
Modern (40486 and later?) 80x86 CPUs have thermal protection - if they get too hot they shutdown. This is mostly in case the CPU fan fails, and I doubt you can cause a CPU with a working fan to overheat with software alone, even if your software is deliberately trying to do this.

However, there were some Intel CPUs (I think they're Pentium Pro or Pentium II - not sure now) that had faulty thermal sensors, which might not shutdown when they overheat. If you're using an old CPU then it's a good idea to check if the fan works... :)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: Newbie question about messing up in kernel mode

Post by whowhatwhere »

Brendan wrote:Hi,
xvedejas wrote:As far as I know, the worst you could do is get stuck in a loop and overheat your computer. At least without knowing anything. I'm sure there are worse you can do, but you need to know more before you can make those mistakes :)
Modern (40486 and later?) 80x86 CPUs have thermal protection - if they get too hot they shutdown. This is mostly in case the CPU fan fails, and I doubt you can cause a CPU with a working fan to overheat with software alone, even if your software is deliberately trying to do this.

However, there were some Intel CPUs (I think they're Pentium Pro or Pentium II - not sure now) that had faulty thermal sensors, which might not shutdown when they overheat. If you're using an old CPU then it's a good idea to check if the fan works... :)


Cheers,

Brendan
Otoh, I saw this wicked video of a Duron 1200 vapourizing into thin air when the cpu was removed.
User avatar
JackScott
Member
Member
Posts: 1032
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
GitHub: https://github.com/JackScottAU
Contact:

Re: Newbie question about messing up in kernel mode

Post by JackScott »

Yes, ever since around the 1GHz mark, there haven't really been any CPUs that can handle running without a heatsink. However, that wasn't the point Brendan was making. A properly cooled computer should be able to withstand 100% CPU load for a long time (ie indefinitely). If it can't, then it's not properly cooled.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Newbie question about messing up in kernel mode

Post by gravaera »

You could create a HDD image and use it in bochs for your initial HDD development. Once you have that right, and you're sure your code is accurate enough, then you can unleash the code onto your machine. As for me, I just boot up to my real machine anytime I make any major changes to make sure it's still running on real hardware. If something gets spoiled, then I'm not particularly bothered since it would have seemed worth it.

There are ways to avoid making mistakes on disk drivers, though: for your initial bits of development, you could do stuff like write magic numbers to several sectors, and try reading them back, etc. (All of this on your image file).
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Newbie question about messing up in kernel mode

Post by Brendan »

Hi,
berkus wrote:Older AMD CPUs didn't have thermal throttling like P4 does. Duron 1200 is quite old, ain't it?
There's thermal throttling (CPU goes slower when it gets hot) and thermal shutdown (CPU stops running when it gets too hot). Older CPUs had thermal shutdown but didn't have thermal throttling. Newer CPUs have both, with 2 temperature sensors, so that as it gets hotter the first temperature sensor triggers thermal throttling, and if it keeps getting hotter the second temperature sensor triggers thermal shutdown.

For an example of thermal shutdown, here's a video on youtube. :)

Without a heatsink there's nowhere for the heat to go and the CPU can get very hot very quickly, and it might be damaged before the temperature sensor triggers thermal shutdown. Also, I think that for some CPUs the temperature sensor is actually on the motherboard (which makes things worse because it takes longer for the heat to reach the thermal sensor).

With a heatsink (but without a working fan) it takes a while for the CPU to heat up the heatsink, which gives enough time for the temperature sensor to trigger thermal shutdown.

Side note: According to Wikipedia Duron 1200 was released on November 15, 2001.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply