OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Nov 14, 2019 8:58 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 12:15 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
back to bother here with my ignorance. the problem I have is that I try to give color to the text, but it does not work (nothing works to me I think I am cursed) ...

clrscr function
Code:
__asm__ __volatile__ ("mov $0x0700, %ax\n\t" // Scrolls the text
                               "int $0x10");


Also, if I want to change back and fore color, doesn't works:
mov $0x70, %bh\n\t

btw, how I can change cursor position, and draw a pixel (and how change his color)
I am doing this in C using inline assembly


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 12:33 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 271
What's your compiler? The code looks like GCC, but GCC can't create code for 16-bit real mode. And the code makes no sense in any other mode.

In any case, GCC has advanced assembly capabilities. According to RBIL, the function you are running requires CX and DX to be set up as well. Which you could do like this:

Code:
asm ("int 0x10" : : "a"(0x700), "b"(0x70), "c"(0), "d"(0x1950));


The double underscores are only necessary if you might compile the code in strict-compliance mode ("-std=c99" and the like). The double underscores on the volatile are never necessary (it's already a keyword). The volatile is only necessary if the asm block has an output and side effects you want to happen even if the assignment of the output is redundant. You might need a memory clobber, though (Google for "gcc clobber list").

HTH!


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 12:52 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
my compiler is i686-elf-gcc. I try to avoid the "advanced" GCC inline assembly because is complex, and I can't understand how it works-


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 1:45 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
konniskatt wrote:
back to bother here with my ignorance. the problem I have is that I try to give color to the text, but it does not work (nothing works to me I think I am cursed) ...

clrscr function
Code:
__asm__ __volatile__ ("mov $0x0700, %ax\n\t" // Scrolls the text
                               "int $0x10");


Also, if I want to change back and fore color, doesn't works:
mov $0x70, %bh\n\t

btw, how I can change cursor position, and draw a pixel (and how change his color)?
I am doing this in C using inline assembly


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 2:11 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1496
Location: Athens, GA, USA
konniskatt wrote:
my compiler is i686-elf-gcc. I try to avoid the "advanced" GCC inline assembly because is complex, and I can't understand how it works-


That's impossible - GCC doesn't produce real mode code, period.

How are you booting this system? If you are using GRUB (or most other common boot loaders), or are running on any UEFI system, then your system will already be in a protected mode before it even loads your OS. If this is the case, then you would need to leave protected mode to run real mode code, or else set up a Virtual 8086 mode (which is a lot of work, will require you to have a fully functional protected OS before proceeding, and won't run at all on an x86-64 system - which is to say, anything newer than 2009 or so).

Just to make things clear: you cannot run MS-DOS code on modern PCs directly, period. They simply don't support the things you'd need. Any MS-DOS program - or any other 16-bit program, even one for Windows in 286 protected mode - which is running on a 64-bit UEFI PC is running in emulation. While earlier x86-64 CPUs running in 32-bit protected mode were able to run V86 modes, my understanding is that the newer ones simply don't have V86 mode anymore, even when in a protected-mode OS rather than a long-mode one.

Furthermore, the legacy BIOS - in the form of the UEFI Compatibility Support Module - now has a fixed End-Of-Life of 2020. After that, no new Intel chipsets will support it, at all. Very likely, support for real mode itself will be discontinued in the CPUs at that time as well. Some speculate that even protected-mode will go away, with only 64-bit long mode still available as the primary mode and a 'virtual protected mode' similar to virtual 8086 mode for running 32-bit Windows programs.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
μή εἶναι βασιλικήν ἀτραπόν ἐπί γεωμετρίαν
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 2:42 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
I use my own bootloader. And I KNOW that BIOS is obsolete. I was making a real mode OS just because I am beginner, but now I see that this is too complex.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 2:52 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1496
Location: Athens, GA, USA
konniskatt wrote:
I use my own bootloader. And I KNOW that BIOS is obsolete. I was making a real mode OS just because I am beginner, but now I see that this is too complex.


Please don't feel the need to give up entirely; put it off for a while, perhaps, take some time to learn more, certainly, but it isn't something you need to give up on for good. OS dev is demanding, which is why we recommend having several years of programming under your belt before trying. There's no need to rush.

I will say that at this point, a real mode OS probably presents more challenges than a protected mode one would.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
μή εἶναι βασιλικήν ἀτραπόν ἐπί γεωμετρίαν
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Last edited by Schol-R-LEA on Sun Dec 16, 2018 3:11 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 3:08 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 271
konniskatt wrote:
I use my own bootloader. And I KNOW that BIOS is obsolete. I was making a real mode OS just because I am beginner, but now I see that this is too complex.


No matter what you use, you are going to have to read a whole lot of documentation. For BIOS functions, RBIL is going to be your best bet. In particular, have a look at this: http://www.ctyme.com/intr/rb-0087.htm

However, transitioning to 32-bit mode and then 64-bit mode is not actually all that hard, and then you can manage cursor position entriely in software.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 3:11 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1496
Location: Athens, GA, USA
The following is a 'boilerplate' series of links given to most new OS-Dev members.


The first thing I want to say is this: if you aren't already using version control for all software projects you are working on, drop everything and start to do that now. Set up a VCS such as Git, Subversion, Mercurial, Bazaar, or what have you - which you use is less important than the fact that you need to use it. Similarly, setting up your repos on an offsite host such as Gitlab, Github, Sourceforge, CloudForge, or BitBucket should be the very first thing you do whenever you start a new project, no matter how large or small it is.

If nothing else, it makes it easy to share your code with us on the forum, as you can just post a link, rather than pasting oodles and oodles of code into a post.

Once you have that out of the way (if you didn't already), you can start to consider the OS specific issues.

If you haven't already, I would strongly advise you to read the introductory material in the wiki:


After this, go through the material on the practical aspects of
running an OS-dev project:

I strongly suggest that you read through these pages in detail, along with the appropriate ones to follow, before doing any actual development. These pages should ensure that you have at least the basic groundwork for learning about OS dev covered.

This brings you to your first big decision: which platform, or platforms, to target. Commonly options include:
  • x86 - the CPU architecture of the stock PC desktops and laptops, and the system which remains the 'default' for OS dev on this group. However, it is notoriously quirky, especially regarding Memory Segmentation, and the sharp divisions between 16-bit Real Mode, 16-bit and 32-bit Protected Modes, and 64-bit Long Mode.
  • ARM - a RISC architecture widely used on mobile devices and for 'Internet of Things' and 'Maker' equipment, including the popular Raspberry Pi and Beagleboard single board computers. While it is generally seen as easier to work with that x86, most notably in the much less severe differences in between the 32-bit and 64-bit modes and the lack of memory segmentation, the wiki and other resources don't cover it nearly as well (though this is changing over time as it becomes more commonly targeted).
  • MIPS, another RISC design which is slightly older than ARM. It is one of the first RISC design to come out, being part of the reason the idea caught on, and is even simpler than ARM in terms of programming, though a bit tedious when it comes to assembly programming. While it was widely used in workstations and game consoles in the 1990s, it has declined significantly due to mismanagement by the owners of the design, and is mostly seen in devices such as routers. There are a handful of System on Chip single-board computers that use it, such as the Creator Board and the Onion Omega2, and manufacturers in both China and Russia have licensed the ISA with the idea of breaking their dependence on Intel. Finding good information on the instruction set is easy, as it is widely used in courses on assembly language and computer architecture and there are several emulators that run MIPS code, but finding usable information on the actual hardware systems using it is often difficult at best.
  • RISC-V is an up and coming open source hardware ISA, but so far is Not Ready For Prime Time. This may change in the next few years, though.

You then need to decide which language to use for the kernel. I gather you are using C, which is the usual recommendation. However, you then need to choose the compiler, assembler, linker, build tool, and support utilities to use - what is called the 'toolchain' for your OS.

For most platforms, there aren't many to choose from, and the obvious choice would be GCC and the Binutils toolchain due to their ubiquity. However, on the Intel x86 platform, it isn't as simple, as there are several other toolchains which are in widespread use for it, the most notable being the Microsoft one - a very familiar one to Windows programmers, but one which presents problems in OSDev. The biggest issue with Visual Studio, and with proprietary toolchains in general, is that using it rules out the possibility of your OS being "self-hosting" - that is to say, being able to develop your OS in the OS itself, something most OSdevs do want to eventually be able to do. The fact that Porting GCC to your OS is feasible, whereas porting proprietary x86 toolchains isn't, is a big factor in the use Binutils and GCC, as it their deep connection to Linux and other Unix derivatives.

Regardless of the high-level language you use for OS dev (if any), you will still need to use assembly language, which means choosing an assembler. If you are using Binutils and GCC, the obvious choice would be GAS, but for x86 especially, there are other assemblers which many OSdevs prefer, such as Netwide Assembler (NASM) and Flat Assembler (FASM).

The important thing here is that assembly language syntax varies more among the x86 assemblers than it does for most other platforms, with the biggest difference being that between the Intel syntax used in the majority of x86 assemblers, and the AT&T syntax used in GAS. You can see an overview of the differences on the somewhat misnamed wiki page Opcode syntax.

It is still important to understand that the various Intel syntax assemblers - NASM, FASM, and YASM among others - have differences in how they handle indexing, in the directives they use, and in their support for features such as macros and defining data structures. While most of these follow the general syntax of Microsoft Assembler (MASM), they all diverge from it in various ways.

Once you know which platform you are targeting, and the toolchain you want to use, you need to understand them. You should read up on the core technologies for the platform. Assuming that you are targeting the PC architecture, this would include:

This leads to the next big decision: which Bootloader to use. There are a number of different standard bootloaders for x86, with the most prominent being GRUB. We strong recommend against Rolling Your Own Bootloader, but it is an option as well.

You need to consider what kind of File System to use. Common ones used when starting out in OS dev include:

We generally don't recommend designing your own, but as with boot loaders, it is a possibility as well.

While this is a lot of reading, it simply reflects the due diligence that any OS-devver needs to go through in order to get anywhere. OS development, even as a simple project, is not amenable to the Stack Overflow cut-and-paste model of software development; you really need to understand a fair amount of the concepts and principles before writing any code, and the examples given in tutorials and forum posts generally are exactly that. Copying an existing code snippet without at least a basic idea of what it is doing simply won't do. While learning itself is an iterative process - you learn one thing, try it out, see what worked and what didn't, read some more, etc. - in this case a basic foundation is needed at the start. Without a solid understanding of at least some of the core ideas before starting, you simply can't get very far in OS dev.

Hopefully, this won't scare you off; it isn't nearly as bad as it sounds. It just takes a lot of patience and a bit of effort, a little at a time.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
μή εἶναι βασιλικήν ἀτραπόν ἐπί γεωμετρίαν
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 3:41 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1496
Location: Athens, GA, USA
Oops, I think I added this after you saw that last post, so here it is again: If you aren't already using version control for all software projects you are working on, drop everything and start to do that now. Set up a VCS such as Git, Subversion, Mercurial, Bazaar, or what have you - which you use is less important than the fact that you need to use it. Similarly, setting up your repos on an offsite host such as Gitlab, Github, Sourceforge, CloudForge, or BitBucket should be the very first thing you do whenever you start a new project, no matter how large or small it is.

If nothing else, it makes it easy to share your code with us on the forum, as you can just post a link, rather than pasting oodles and oodles of code into a post.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
μή εἶναι βασιλικήν ἀτραπόν ἐπί γεωμετρίαν
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 8:09 pm 
Offline
Member
Member

Joined: Wed Dec 12, 2018 12:16 pm
Posts: 119
Thanks Schol-R-LEA for answer.
Now I'm rewriting all my code, and convert my OS to a protected mode one.
(I'm having (again) some problems with the linker *sigh*, but I will try to solve by myself)
Now I understand why protected mode is easier than real.
and, sorry for my bad english.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Sun Dec 16, 2018 9:24 pm 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1677
Schol-R-LEA wrote:
That's impossible - GCC doesn't produce real mode code, period.

GCC can produce code that will run in real mode. It's very limited, but not impossible.

Schol-R-LEA wrote:
Just to make things clear: you cannot run MS-DOS code on modern PCs directly, period. They simply don't support the things you'd need. Any MS-DOS program - or any other 16-bit program, even one for Windows in 286 protected mode - which is running on a 64-bit UEFI PC is running in emulation. While earlier x86-64 CPUs running in 32-bit protected mode were able to run V86 modes, my understanding is that the newer ones simply don't have V86 mode anymore, even when in a protected-mode OS rather than a long-mode one.

This is a common misconception. The CPUs themselves are still perfectly capable of running in all of the 16-bit modes; the only limitation is that you can't have 16-bit code in ring 3 while you have 64-bit code in ring 0.


Top
 Profile  
 
 Post subject: Re: colors and cursor position not working
PostPosted: Mon Dec 17, 2018 10:27 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 271
Octocontrabass wrote:
This is a common misconception. The CPUs themselves are still perfectly capable of running in all of the 16-bit modes; the only limitation is that you can't have 16-bit code in ring 3 while you have 64-bit code in ring 0.


Yes, you can. You only need a code segment with D=0 and L=0. However, this mix leads to interesting times in conjunction with interrupts. Research "espfix" for a thorough discussion of the topic.

Also, it is impossible to mix real and protected modes (it always was, but V8086 mode helped). And since 16-bit protected mode never took off, 16-bit compatibility mode is unlikely to be helpful, except for simulating Win32s (aka Win16).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: MSN [Bot] and 9 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group