Getting started with low level programming

Programming, for all ages and all languages.
Post Reply
Freek
Posts: 2
Joined: Wed Sep 03, 2014 4:30 am

Getting started with low level programming

Post by Freek »

Hi there,

I am a programmer and I have experience with high-level languages like C# and Java, but for a while I've been very interested in low-level programming. Or even better: Bare metal computing.

However, I don't have a clue on how to get started with this kind of stuff. I know real bare-metal programming is not really possible on modern computers (correct me if I'm wrong) so I was thinking about getting as low-level as it can get. I think that is the stuff you guys on this forum do all the time so that's why I've come here.

I was as less as possible layers between me and the hardware, so basically I want to write code that can be executed without an operating system.

Actually making an OS sounds very interesting to me, but it's not directly what I aim for, and I think I'm by far not ready for that.

I don't necessarily want to program a modern computer. Some other device like an old phone or something would be cool to (even cooler maybe?) but I guess it's even harder to access the lower level on those kinds of devices.

Does anyone have some tips for me? Fun things to try or advice to get me started with low-level computing?

Anything is welcome!
My thanks is advance,
Freek
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Getting started with low level programming

Post by Brendan »

Hi,
Freek wrote:However, I don't have a clue on how to get started with this kind of stuff. I know real bare-metal programming is not really possible on modern computers (correct me if I'm wrong) so I was thinking about getting as low-level as it can get. I think that is the stuff you guys on this forum do all the time so that's why I've come here.
You can do "bare metal" on modern computers. People have even done raw machine code (because assembly language was too high level for them(!?) )..
Freek wrote:I was as less as possible layers between me and the hardware, so basically I want to write code that can be executed without an operating system.
Those layers are "layers of abstraction". You can write your own, or you can live without them. However, when you have to write device drivers for all the different storage devices and code to support all the different file systems in every single application, you'll quickly realise how silly life is without those abstractions, and (whether it's in the form of a binary with an API like a kernel, or in source code form like a library, or in some other form) you will end up writing your own "layers of abstraction".
Freek wrote:I don't necessarily want to program a modern computer. Some other device like an old phone or something would be cool to (even cooler maybe?) but I guess it's even harder to access the lower level on those kinds of devices.

Does anyone have some tips for me? Fun things to try or advice to get me started with low-level computing?
If you can't test your code, then you're screwed. What hardware do you have to test on? Are you willing to buy something else (e.g. maybe something like beagle board)? What would people use the application for, and what hardware are those people likely to have (or will you provide the hardware and software as a unified "thing")?


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.
Freek
Posts: 2
Joined: Wed Sep 03, 2014 4:30 am

Re: Getting started with low level programming

Post by Freek »

Thanks for your reply.
You can do "bare metal" on modern computers. People have even done raw machine code (because assembly language was too high level for them(!?) )..
Ok. Well I'm sure assembly is good enough for me. (:

Code: Select all

Those layers are "layers of abstraction". You can write your own, or you can live without them. However, when you have to write device drivers for all the different storage devices and code to support all the different file systems in every single application, you'll quickly realise how silly life is without those abstractions, and (whether it's in the form of a binary with an API like a kernel, or in source code form like a library, or in some other form) you will end up writing your own "layers of abstraction".
So those layers of abstraction are basically for portability? I don't think I should be worrying about that just yet.
What hardware do you have to test on? Are you willing to buy something else (e.g. maybe something like beagle board)? What would people use the application for, and what hardware are those people likely to have (or will you provide the hardware and software as a unified "thing")?
I'm not planning on writing applications that people are going to use for anything yet. It's more like experimenting for fun. I have an old laptop witch I don't need for anything else. Would that work?

I'll look in the the BeagleBoard thing. From what I've seen so far I assume it's something like the Raspberry PI?

Freek
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Getting started with low level programming

Post by Brendan »

Hi,
Freek wrote:
Those layers are "layers of abstraction". You can write your own, or you can live without them. However, when you have to write device drivers for all the different storage devices and code to support all the different file systems in every single application, you'll quickly realise how silly life is without those abstractions, and (whether it's in the form of a binary with an API like a kernel, or in source code form like a library, or in some other form) you will end up writing your own "layers of abstraction".
So those layers of abstraction are basically for portability? I don't think I should be worrying about that just yet.
They're more for extensibility and project maintenance. For example, rather than having an application that talks directly to the hard disk controller (and breaks as soon as the storage device is something different and has to be rewritten), you could have an application that uses a "storage device driver API" (and a device driver that implements that API) and then write more "storage device drivers" whenever you like without breaking anything.
Freek wrote:
What hardware do you have to test on? Are you willing to buy something else (e.g. maybe something like beagle board)? What would people use the application for, and what hardware are those people likely to have (or will you provide the hardware and software as a unified "thing")?
I'm not planning on writing applications that people are going to use for anything yet. It's more like experimenting for fun. I have an old laptop witch I don't need for anything else. Would that work?
That could work fine.
Freek wrote:I'll look in the the BeagleBoard thing. From what I've seen so far I assume it's something like the Raspberry PI?
Yes, it's very similar (in concept) to Raspberry PI - basically, a cheap ARM thing slapped on a low cost development board for people to experiment with.


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
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Getting started with low level programming

Post by SpyderTL »

Freek wrote:I am a programmer and I have experience with high-level languages like C# and Java, but for a while I've been very interested in low-level programming. Or even better: Bare metal computing.

However, I don't have a clue on how to get started with this kind of stuff.
The most "bare-metal" you can possibly get is writing bytes to a floppy disk, and inserting it into a machine and turning it on. (You just need to know what all those bytes "mean" to the computer running it.)

You would be insane to go this route.

With that being said, here is a link to how I did it. :wink:

https://ozone.codeplex.com

Here as a lengthy discussion thread on my project:
http://forum.osdev.org/viewtopic.php?f=15&t=27971

In short, I am using XML, XSD, and XSLT files to convert XML elements into bytes that are written out to disk. I've enumerated all (or most) of the CPU instructions for several platforms, including x86, Commodore 64, Nintendo Entertainment System, Super NES, GameBoy, GameBoy Advance, Atari 2600, Raspberry Pi, Java JVM, and .NET CLR. I have sample projects for most of these showing how to get started, but I've focused most of my time toward x86 32-bit development.

I created all of this as an alternative to using ASM, when I discovered that there are no good development IDEs out there for ASM development. Using XML has the advantage of having a large list of editors that provide a lot of the functionality that you would get in a modern development environment / language -- Tooltips, documentation, autocomplete, intellisense, namespaces, jump-to declaration, etc.

So, if you are looking for something higher-level than writing byte codes in a hex editor, but lower level than ASM instructions, you may want to take a look. Especially if you are not already an expert in Assembly language. You may find it easier to learn than the console based ASM compilers from 30 years ago.

I should also mention that there are a few OS projects on this site that are written in pure Java and/or pure C#. You may want to consider going this route, instead.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Getting started with low level programming

Post by b.zaar »

Freek wrote: I have an old laptop witch I don't need for anything else. Would that work?
Install FreeDOS, it's a simple OS that doesn't provide protection like the modern OS's.

Programming in DOS is the closest you'll get to direct hardware control while still having a memory and filesystem library. Using DPMI you can easily switch to protected mode and have a large address space and using VBE you can use frame buffers for writing straight to video. If you wanted to have lower level disk access you could use the BIOS for sector reads and writes or you could write directly using the FDC and DMA.

There is plenty of old documentation and here's something to give you an idea of the devices you can control in DOS.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Getting started with low level programming

Post by Combuster »

b.zaar wrote:
Freek wrote: I have an old laptop witch I don't need for anything else. Would that work?
Install FreeDOS, it's a simple OS that doesn't provide protection like the modern OS's.
Or simpler, DOSBox, because you don't need to reboot that :wink: (although a VM might be a more accurate choice).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: Getting started with low level programming

Post by Muazzam »

Combuster wrote:Or simpler, DOSBox, because you don't need to reboot that :wink: (although a VM might be a more accurate choice).
Why not install real DOS (with rufus) on USB stick and boot from it? Also, DOS is closest to Hardware and Boots faster.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Getting started with low level programming

Post by bluemoon »

muazzam wrote:
Combuster wrote:Or simpler, DOSBox, because you don't need to reboot that :wink: (although a VM might be a more accurate choice).
Why not install real DOS (with rufus) on USB stick and boot from it? Also, DOS is closest to Hardware and Boots faster.
Combuster wrote: because you don't need to reboot that.

Also, DOS does not necessary boot faster (than other OS) if you count the stuff done with config.sys and autoexec.bat, especially the long pause with cdrom driver.
And I doubt loading DOS from USB stick (i.e. BIOS disk service) would be faster than loading dosbox on top of DMA and cache-enabled OS.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Getting started with low level programming

Post by b.zaar »

Combuster wrote:
b.zaar wrote:
Freek wrote: I have an old laptop witch I don't need for anything else. Would that work?
Install FreeDOS, it's a simple OS that doesn't provide protection like the modern OS's.
Or simpler, DOSBox, because you don't need to reboot that :wink: (although a VM might be a more accurate choice).
Who would use DOSBox for anything useful? =)
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Getting started with low level programming

Post by alexfru »

b.zaar wrote:Who would use DOSBox for anything useful? =)
Just because you don't have anything useful to run or debug in DOS/DOSBox, it doesn't mean nobody else does. I, for one, have been running the DOS version of my compiler under it. I need to test the DOS version of my standard C library and DOSBox helps me do that. I'm sure there are useful programs that were never ported to Windows and Linux that people still want to run, be it old games or something else.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Getting started with low level programming

Post by b.zaar »

Yeah sorry it was sarcasm. I'm working on BoxOn, an emulator forked from DOSBox.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
seuti
Member
Member
Posts: 74
Joined: Tue Aug 19, 2014 1:20 pm

Re: Getting started with low level programming

Post by seuti »

b.zaar wrote:
Combuster wrote:
b.zaar wrote:
Install FreeDOS, it's a simple OS that doesn't provide protection like the modern OS's.
Or simpler, DOSBox, because you don't need to reboot that :wink: (although a VM might be a more accurate choice).
Who would use DOSBox for anything useful? =)
I use DOSBox to play Sim Tower :-)
Post Reply