OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 11:46 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Using inline assembly and int10h AH=13h to print messages
PostPosted: Mon Mar 05, 2018 8:29 pm 
Offline
Member
Member

Joined: Thu May 25, 2017 10:41 pm
Posts: 29
I am trying to use the BIOS (interrupt 0x10 AH=0x13) to print a message to the screen, but it does not work.
The color is correctly printed but the text does not appear.
Here is my function so far:
Code:
void __attribute__((noinline)) printa(const char* s, uint8_t x, uint8_t y, uint8_t color) {
   __asm__ __volatile__ ("int $0x10" : : "a"(0x1301), "b"(color), "c"(strlen(s)), "d"((uint16_t)x << 8 | y), "bp"(s));
}

I call this function like so:
Code:
printa("asdfasdfasdfasd", 5, 5, 0x14);

I don't use inline assembly often, so any help would be appreciated.
Here is what the result looks like so far:
Image


Top
 Profile  
 
 Post subject: Re: Using inline assembly and int10h AH=13h to print message
PostPosted: Tue Mar 06, 2018 11:07 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
If I correctly understand what you are trying to do, then am sorry to say that it never will work. BIOS interrupts only operate in real mode, and since you appear to be using GCC as your compiler (based on the inline assembly syntax you are using), the system isn't going to be in real mode.

GCC cannot target real mode at all - it only produces 32-bit protected mode or 64-bit long mode object code - meaning that if the code in question is running at all, it has to be running in p-mode, meaning the BIOS is useless to you without either dropping back to real mode (which means the generated C code won't run) or using virtualization or emulation to run real mode code (and again, the C code generated by that compiler won't run in that sandbox, making the BIOS call impossible.

Now, I could be mistaken here; you might be using a real mode compiler with a similar inline assembly syntax, for example. But based on what I am seeing, there won't be any way to make this work as it is.

usually, my recommendation is to write a set of basic routines that write directly to the video text buffer, as described in the wiki pages Text UI, Printing To Screen, and Text Mode Cursor (I would also recommend reading VESA Video Modes and How do I set a graphics mode, but I suspect you already have). It not all that much more work, really, and given the limitations of the BIOS text handling, it is something you would need to do eventually anyway.

However, looking back over your posting history, I am pretty sure you have already done that before (since you had functions for printing strings when you were working on the PS/2 keyboard handler and when you asked about V86 mode), which leads me to the question of, why did you want to use the BIOS here?

Also, just out of curiosity, what boot loader are you using? Presumably, if you had rolled your own loader, you knew you were in p-mode, but if you were using (for example) GRUB, well, we do get people who didn't realize that GRUB boots into protected mode before. I am pretty sure (based on your previous posts) that you do know you are in p-mode, but didn't know GCC didn't compile for real mode, but I definitely would like more information here.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
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: Using inline assembly and int10h AH=13h to print message
PostPosted: Tue Mar 06, 2018 11:23 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
thumble wrote:
I am trying to use the BIOS

Why do you want to use the BIOS instead of switching to protected mode (or long mode) and handling the display functions yourself?

thumble wrote:
Code:
"bp"(s)

This tells the compiler to use either BX (b) or an effective address (p) for the operand. It does not tell the compiler to use BP.

Schol-R-LEA wrote:
GCC cannot target real mode at all

Yes it can, although not very well. The resulting binary requires a flat memory model and a 32-bit CPU.


Top
 Profile  
 
 Post subject: Re: Using inline assembly and int10h AH=13h to print message
PostPosted: Tue Mar 13, 2018 12:59 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
I am not sure if GCC C compiler supports 16 bit code, but I am 100% sure that you can write real mode code in GNU Assembler as well in NASM and YASM. In GAS use .code16 directive and in NASM and YASM it's [bits 16]. You can make it work with inline asm but you REALLY have to know what you're doing. If you are trying to use BIOS from protected or long mode it is not going to work unless you use VM86 or switch back to real mode (I am not sure if you can even do that in long mode).


Top
 Profile  
 
 Post subject: Re: Using inline assembly and int10h AH=13h to print message
PostPosted: Wed Mar 14, 2018 1:03 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
pvc wrote:
I am not sure if GCC C compiler supports 16 bit code

There's some work in progress to add real mode support in GCC (thread).
There's also my compiler suitable for (un)real mode boot loaders.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot] and 801 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