flat assembler
Message board for the users of flat assembler.

Index > OS Construction > OS Loading Process

Author
Thread Post new topic Reply to topic
moveax41h



Joined: 18 Feb 2018
Posts: 59
moveax41h 17 Mar 2018, 22:38
Strictly speaking, what are the first few things that must occur when there is absolutely no OS on a machine yet? For example, I've been using emu8086 and while the code I've been writing is pretty close to that, I've still been writing code in DOS mode which is technically still an operating system. Even though we use interrupts like int 21h for example, these are still provided by a kernel.

So my question is, say I am handed some hardware and there is absolutely no software on it whatsoever other than perhaps a BIOS... What are the first steps? I understand a little bit about a bootloader but my question is more specifically, how do we establish the ability to do things like print a character without the interrupt to do this provided by the DOS kernel, for example? I am aware that we can define our own software interrupts by placing pointers to handlers in offsets from the ES register but even still, how does that code eventually actually print a char to the screen? The only thing I can think of is that there are some other hardware interrupts which are "built-in" that we can use sort of like in a driver but I am not sure on this and would like some clarification. Thank you.

_________________
-moveax41h
Post 17 Mar 2018, 22:38
View user's profile Send private message Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 80
alexfru 18 Mar 2018, 04:48
You learn your hardware, how it can output a character to wherever (serial port, display, etc). You then write code to do it. As simple as that.
Post 18 Mar 2018, 04:48
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 18 Mar 2018, 06:23
moveax41h wrote:
What are the first steps? I understand a little bit about a bootloader but my question is more specifically, how do we establish the ability to do things like print a character without the interrupt to do this provided by the DOS kernel, for example? I am aware that we can define our own software interrupts by placing pointers to handlers in offsets from the ES register but even still, how does that code eventually actually print a char to the screen? The only thing I can think of is that there are some other hardware interrupts which are "built-in" that we can use sort of like in a driver but I am not sure on this and would like some clarification. Thank you.

It really depends. From your question it seems you’re targeting BIOS, not UEFI, so I’ll go on with that.

The next thing the answer depends on is your target CPU mode. Since you’re talking about replacing MS-DOS services, I’ll decide you’re targeting real mode.

---
In real mode you basically have 1.75 ways to perform character output. First, you can use BIOS services provided by means of int 10h. Several of them are for your purpose, providing different levels of comfort.

The second method (half of a method, actually) is to reinvent the BIOS services partially by writing directly to the video memory and keeping track of things like, say, caret position. This way is considered to be a bit faster but, definitely, if you reinvent exactly what BIOS does the performance might be nearly the same.

Now, the third method (quarter of a method) that works for every CPU mode out there is to work directly with video card by means of I/O ports. In fact, the simplest way would still be to map video memory somewhere and write there but if you want to get rid of int 10h completely this is the way to go. Although it is the hardest one.
---

Now discarding my assumptions in backwards manner. If you’re in protected mode, you’ll have to switch to directly interfacing video card. There’re a few other means like VBE but, AFAIK, they are not supported well enough to be relied on these days. If you’re eager to output characters somewhere except the display, I/O ports are again the way to go.

In general, while you’re in real mode your helper functions are BIOS services provided by, most notably, int 10h (video), int 13h (disks) and int 16h (keyboard). If you decide not to use them or they’re unavailable (say, if you’re not in real mode anymore), you’ll have to access specific I/O ports.

UEFI is the same idea, different programming interface (and targeted for protected mode).


Last edited by DimonSoft on 19 Mar 2018, 06:37; edited 1 time in total
Post 18 Mar 2018, 06:23
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 19 Mar 2018, 02:26
And just to make things more confusing: Each set of video/disk/interfaces/etc. are different and specific for each machine. While there are some similarities for basic functions, doing anything even slightly advanced requires knowledge of the low level specific features. So you would need to download the actual manufacturers spec for each brand/make/model you need to support with your drivers. It usually can be done for most common hardware, it just require lots of effort and searching.
Post 19 Mar 2018, 02:26
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.