OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: int86() C command
PostPosted: Sun Jan 31, 2021 9:54 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
Can I use the following to print to my printer on an Intel64 system?:

Code:
void printchar(char c){

  union REGS regs;

  regs.h.ah=0x00; //print character function
  regs.h.al=c; //character to print
  regs.x.dx=0x00; //print port to print to (LPT1)
  int86(0x17,&regs,&regs); //interrupt

}

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Sun Jan 31, 2021 10:02 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
No, int86 was used on old DOS systems for C code to access the BIOS. Nowadays, the world has moved on from real mode and the BIOS.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Sun Jan 31, 2021 12:13 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Well you can if you implement int86() :P

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Sun Jan 31, 2021 12:30 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
kzinti wrote:
Well you can if you implement int86() :P
And have a BIOS interface (or CSM in UEFI mode).

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Tue Feb 02, 2021 8:29 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hi,

If interested, int86 was the original inspiration for this function in our boot loader here. Its been a while since I wrote this type of code but IIRC it would look something like:
Code:
void printchar(char c){
  REGS regs;
  _ah (regs.eax) = 0x00;
  _al (regs.eax) = c;
  _dx (regs.edx) = 0x00;
  io_services (0x17,&regs,&regs);
}

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Tue Feb 16, 2021 5:15 am 
Offline
Member
Member
User avatar

Joined: Thu Jun 04, 2009 11:12 pm
Posts: 281
Hi Pavel,
That looks like legacy code and makes only sense when using real mode. ( int86 is part of the old dos turbo C++ library if I remember correctly). While you would be able to get it to work in a i64 using some sort of emulation layer ( dos box , boxed wine etc ). It is not recommended. All modern operating system provide an API for printing ( I/O ) in general. It would simply be best to use them instead.

--Thomas


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Tue Feb 16, 2021 7:47 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
PavelCheckov wrote:
Can I use the following to print to my printer on an Intel64 system?
Under special circumstances, yes. But even when you could, I wouldn't recommend it, as it would be extremely slow, plus you probably won't have Teletype video mode anyway, only pixel-based graphics on modern machines (only a few BIOS implements that and only for some video modes. Chances are that that BIOS int won't work). Check out PC Screen Font or consider using a minimalistic library such as Scalable Screen Font instead.

For printing not on screen but to somewhere else, you should use IO ports. It's not that difficult, parallel port is very easy to program in particular. However again, chances are good that your modern Intel64 machine doesn't have an LPT port in the first place...
Thomas wrote:
That looks like legacy code and makes only sense when using real mode.
Not really, you could switch modes temporarily.
Thomas wrote:
int86 is part of the old dos turbo C++ library if I remember correctly
Also in Minix (see source line 8861). It switches to real mode, does the BIOS call and then switches back to protmode. The caller of int86() is none the wiser. You could implement something like that in long mode too, but BIOS must exists in the first place of course (and the machine must have an LPT peripheral which is unlikely these days).

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: int86() C command
PostPosted: Fri Feb 19, 2021 4:47 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
Thomas wrote:
Hi Pavel,
int86 is part of the old dos turbo C++ library if I remember correctly


I like looking through old C programming books, and trying to follow the tutorials today.

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 29 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