* updating a hardware cursor with assembly and ada
@ 2008-03-06 17:07 cl1
2008-03-06 17:26 ` Georg Bauhaus
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: cl1 @ 2008-03-06 17:07 UTC (permalink / raw)
I an trying to learn some operating system development. I have it
booting and printing text to the screen. However, I have an issue with
updating the hardware cursor. It does not update. I can provide the
whole sources if need be, but i believe i am missunderstanding
something in Ada. The tutorial I am learning from is written in C and
for the most part its pretty easy converting it to ada. The code i'm
having an issue with follows. The important parts are outportb in the
c files and Update_Cursor in the vga package body.
// this is the way the tutorial updated the hardware cursor. My
version is
// in the Vga package called Update_Cursor
// void move_csr(void)
// {
// unsigned temp;
// temp = csr_y * 80 + csr_x; // csr_y and csr_x are global
variables
//
// outportb(0x3D4, 14);
// outportb(0x3D5, temp >> 8);
// outportb(0x3D4, 15);
// outportb(0x3D5, temp);
// }
// port.h
#ifndef __PORT_H
#define __PORT_H
extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, usigned char _data);
// port.c
#include "port.h"
unsigned char inportb (unsigned short _port)
{
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
unsigned char outportb (unsigned short _port, unsigned char _data)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
-- vga.ads
package Vga is
-----------------------------------------------------------------------------
type Color is (
Black, -- 0000
Blue, -- 0001
Green, -- 0010
Cyan, -- 0011
Red, -- 0100
Magenta, -- 0101
Brown, -- 0110
Light_Grey, -- 0111
Dark_Grey, -- 1000
Light_Blue, -- 1001
Light_Green, -- 1010
Light_Cyan, -- 1011
Light_Red, -- 1100
Light_Magenta, -- 1101
Light_Brown, -- 1110
White); -- 1111
for Color use (
Black => 16#0#,
Blue => 16#1#,
Green => 16#2#,
Cyan => 16#3#,
Red => 16#4#,
Magenta => 16#5#,
Brown => 16#6#,
Light_Grey => 16#7#,
Dark_Grey => 16#8#,
Light_Blue => 16#9#,
Light_Green => 16#A#,
Light_Cyan => 16#B#,
Light_Red => 16#C#,
Light_Magenta => 16#D#,
Light_Brown => 16#E#,
White => 16#F#);
for Color'Size use 4;
-----------------------------------------------------------------------------
subtype Background_Color is Color range Color'First..Light_Grey;
subtype Row is Positive range Positive'First..25;
subtype Column is Positive range Positive'First..80;
-----------------------------------------------------------------------------
type Video_Console is
record
Foreground : Color := White;
Background : Background_Color := Black;
Row : Vga.Row := Vga.Row'First;
Column : Vga.Column := Vga.Column'First;
end record;
procedure Clear(Console : in out Video_Console);
procedure Put(Console : in out Video_Console; S : String);
-----------------------------------------------------------------------------
end Vga;
-- vga.adb
with System;
package body Vga is
-----------------------------------------------------------------------------
type Video_Character is
record
Foreground : Color;
Background : Background_Color;
Glyph : Character;
end record;
for Video_Character use
record
Foreground at 0 range 8..11;
Background at 0 range 12..15;
Glyph at 0 range 0..7;
end record;
for Video_Character'Size use 16;
-----------------------------------------------------------------------------
Video_Memory : array (Row'Range, Column'Range) of Video_Character;
for Video_Memory'Address use System'To_Address (16#000B8000#);
pragma Import (Ada, Video_Memory);
-----------------------------------------------------------------------------
procedure Update_Cursor (Console : Video_Console) is
procedure OutportB (Port : Natural; Data : Natural);
pragma Import(C, OutportB, "outportB");
Data : Natural := Console.Column * 80 + Console.Row;
begin
OutportB ( 16#3D4#, 14);
OutportB ( 16#3D5#, Data / 2 ** 8);
OutportB ( 16#3D4#, 15);
OutportB ( 16#3D5#, Data);
end Update_Cursor;
-----------------------------------------------------------------------------
procedure Clear (Console : in out Video_Console) is
Clear_Character : Video_Character := (
Foreground => Console.Foreground,
Background => Console.Background,
Glyph => ' ');
begin
for R in Row'Range loop
for C in Column'Range loop
Video_Memory (R, C) := Clear_Character;
end loop;
end loop;
Console.Row := Row'First;
Console.Column := Column'First;
Update_Cursor(Console);
end Clear;
-----------------------------------------------------------------------------
procedure Put (Console : in out Video_Console;
C : Character) is
V : Video_Character := (
Foreground => Console.Foreground,
Background => Console.Background,
Glyph => C);
Tmp : Positive := Console.Column + 1;
begin
Video_Memory(Console.Row, Console.Column) := V;
if Tmp > Column'Last then
Console.Column := Column'First;
Console.Row := Row'Succ(Console.Row);
else
Console.Column := Column'Succ(Console.Column);
end if;
Update_Cursor(Console);
end Put;
-----------------------------------------------------------------------------
procedure Put (Console : in out Video_Console; S : String) is
begin
for I in S'Range loop
Put (Console, S (I));
end loop;
end Put;
-----------------------------------------------------------------------------
end Vga;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
@ 2008-03-06 17:26 ` Georg Bauhaus
2008-03-06 17:51 ` cl1
2008-03-06 19:39 ` Jeffrey R. Carter
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Georg Bauhaus @ 2008-03-06 17:26 UTC (permalink / raw)
cl1 schrieb:
> unsigned char outportb (unsigned short _port, unsigned char _data)
> {
> __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
> }
> -----------------------------------------------------------------------------
> procedure Update_Cursor (Console : Video_Console) is
> procedure OutportB (Port : Natural; Data : Natural);
Does type Natural match C type unsigned short on your system?
(Just a guess.) Maybe Interfaces.Unsigned_N is better choice.
> pragma Import(C, OutportB, "outportB");
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:26 ` Georg Bauhaus
@ 2008-03-06 17:51 ` cl1
2008-03-06 21:31 ` Adam Beneschan
0 siblings, 1 reply; 11+ messages in thread
From: cl1 @ 2008-03-06 17:51 UTC (permalink / raw)
On Mar 6, 11:26 am, Georg Bauhaus <rm.tsoh-plus.nicif-
bauh...@maps.futureapps.de> wrote:
> cl1 schrieb:
>
> > unsigned char outportb (unsigned short _port, unsigned char _data)
> > {
> > __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
> > }
> > -----------------------------------------------------------------------------
> > procedure Update_Cursor (Console : Video_Console) is
> > procedure OutportB (Port : Natural; Data : Natural);
>
> Does type Natural match C type unsigned short on your system?
If it didn't, what problem would this pose?
> (Just a guess.) Maybe Interfaces.Unsigned_N is better choice.
I have no runtime (this is os development code). I don't know if i can
use the Interfaces packages in gnat with out it. I tried to implement
Unsigned_16 with out the operations and the compiler complained about
not having primitive operations defined on the part where i was doing
Data : Unsigned_16 := Console.Column * 80 + Console.Row; even when
Column and Row were of type Unsigned_16;
>
>
>
> > pragma Import(C, OutportB, "outportB");- Hide quoted text -
>
> - Show quoted text -
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
2008-03-06 17:26 ` Georg Bauhaus
@ 2008-03-06 19:39 ` Jeffrey R. Carter
2008-03-06 20:08 ` Gautier
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Jeffrey R. Carter @ 2008-03-06 19:39 UTC (permalink / raw)
cl1 wrote:
> unsigned char outportb (unsigned short _port, unsigned char _data)
> procedure OutportB (Port : Natural; Data : Natural);
> pragma Import(C, OutportB, "outportB");
I would recommend using the types in Interfaces.C and its children rather than
the predefined types.
You should give the C name in the pragma Import exactly as it appears in C:
"outportb".
--
Jeff Carter
"Saving keystrokes is the job of the text editor,
not the programming language."
Preben Randhol
64
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
2008-03-06 17:26 ` Georg Bauhaus
2008-03-06 19:39 ` Jeffrey R. Carter
@ 2008-03-06 20:08 ` Gautier
2008-03-06 20:14 ` Gautier
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Gautier @ 2008-03-06 20:08 UTC (permalink / raw)
If it can help, you can look at the packages in dos_paqs.zip
here: http://www.mysunrise.ch/users/gdm/gsoft.htm
in the ./biblio directory.
You have:
- PC_TextScreen for text console
- VGA_Graphics for VGA
For examples of machine code insertions (GNAT flavour), look for "asm" in the
Ada files.
In other directories you have also Super-VGA (VESA) and sound card libraries.
HTH
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
` (2 preceding siblings ...)
2008-03-06 20:08 ` Gautier
@ 2008-03-06 20:14 ` Gautier
2008-03-06 22:54 ` Ludovic Brenta
2008-03-07 15:26 ` cl1
2008-03-07 19:01 ` cl1
5 siblings, 1 reply; 11+ messages in thread
From: Gautier @ 2008-03-06 20:14 UTC (permalink / raw)
If it can help, you can look at the packages in dos_paqs.zip
here: http://homepage.sunrise.ch/mysunrise/gdm/locaux.htm
in the ./biblio directory.
You have:
- PC_TextScreen for text console
- VGA_Graphics for VGA
For examples of machine code insertions (GNAT flavour), look for "asm" in the
Ada files.
In other directories you have also Super-VGA (./svga_lib) and sound card
libraries (./sb_lib).
HTH
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:51 ` cl1
@ 2008-03-06 21:31 ` Adam Beneschan
0 siblings, 0 replies; 11+ messages in thread
From: Adam Beneschan @ 2008-03-06 21:31 UTC (permalink / raw)
On Mar 6, 9:51 am, cl1 <charles.w.lamb...@gmail.com> wrote:
> On Mar 6, 11:26 am, Georg Bauhaus <rm.tsoh-plus.nicif-
>
> bauh...@maps.futureapps.de> wrote:
> > cl1 schrieb:
>
> > > unsigned char outportb (unsigned short _port, unsigned char _data)
> > > {
> > > __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
> > > }
> > > -----------------------------------------------------------------------------
> > > procedure Update_Cursor (Console : Video_Console) is
> > > procedure OutportB (Port : Natural; Data : Natural);
>
> > Does type Natural match C type unsigned short on your system?
>
> If it didn't, what problem would this pose?
Assuming Natural is 32 bits (I don't really know): If the code
generated for your Ada program thinks it's passing two 32-bit integers
as parameters, but the runtime code is expecting a 16-bit integer and
an 8-bit integer as parameters, the runtime code may not use correct
values for the parameters.
> > (Just a guess.) Maybe Interfaces.Unsigned_N is better choice.
>
> I have no runtime (this is os development code). I don't know if i can
> use the Interfaces packages in gnat with out it. I tried to implement
> Unsigned_16 with out the operations and the compiler complained about
> not having primitive operations defined on the part where i was doing
> Data : Unsigned_16 := Console.Column * 80 + Console.Row; even when
> Column and Row were of type Unsigned_16;
The operations "*" and "+" aren't automatically available, unless you
do something to make them visible. Try "use type
Interfaces.Unsigned_16;".
-- Adam
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 20:14 ` Gautier
@ 2008-03-06 22:54 ` Ludovic Brenta
0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Brenta @ 2008-03-06 22:54 UTC (permalink / raw)
Gautier <gautier@fakeaddress.nil> writes:
> If it can help, you can look at the packages in dos_paqs.zip
> here: http://homepage.sunrise.ch/mysunrise/gdm/locaux.htm
> in the ./biblio directory.
> You have:
> - PC_TextScreen for text console
> - VGA_Graphics for VGA
> For examples of machine code insertions (GNAT flavour), look for "asm" in the
> Ada files.
> In other directories you have also Super-VGA (./svga_lib) and sound
> card libraries (./sb_lib).
> HTH
> ______________________________________________________________
> Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
> Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
>
> NB: For a direct answer, e-mail address on the Web site!
See also Lovelace OS:
http://www.ada-france.org:8081/revision/file/2707659158a6d459d8b83cb80437efe12f4aeea4/src/boards/x86/lovelace-outb.adb
http://www.ada-france.org:8081/revision/file/2707659158a6d459d8b83cb80437efe12f4aeea4/src/boards/qemu_x86/lovelace-stage1-console.adb
PS. Feel free to join the OS Lovelace project, see http://www.lovelace.fr.
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
` (3 preceding siblings ...)
2008-03-06 20:14 ` Gautier
@ 2008-03-07 15:26 ` cl1
2008-03-07 19:01 ` cl1
5 siblings, 0 replies; 11+ messages in thread
From: cl1 @ 2008-03-07 15:26 UTC (permalink / raw)
Thank you all for the advice. I haven't had a chance to try any of it,
but now I have several options to look at. I guess I just need to
figure out what i do and do not have access to at boot time. Based on
the suggestions I recieved, it is not quite as limited as i had
originally thought.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
` (4 preceding siblings ...)
2008-03-07 15:26 ` cl1
@ 2008-03-07 19:01 ` cl1
2008-03-07 20:16 ` Ludovic Brenta
5 siblings, 1 reply; 11+ messages in thread
From: cl1 @ 2008-03-07 19:01 UTC (permalink / raw)
Okay I have updated the Update_Cursor method with the following
implementation, However I am getting the error:
i386-elf-gcc -fno-pic -c -nostdinc -ffunction-sections -fdata-sections
-I. -gnato -gnatp -gnatE vga.adb
vga.adb:3:06: "System.Machine_Code" is not a predefined library unit
I know the error message means there is no System.Machine_Code that it
can find. What i don't know is if there is a flag, or something i can
do to get access to it. I'm really lost at this point, because there
is no way i can implement that package with my current knowledge.
with System;
with Interfaces;
with System.Machine_Code;
package body Vga is
...
-----------------------------------------------------------------------------
procedure Update_Cursor (Console : Video_Console) is
use Interfaces;
use System.Machine_Code;
Data : Unsigned_16 := Console.Column * 80 + Console.Row;
OutB : String := "outb 140x3D4, 14" & NL & "outb %0, 0x3D5";
Part1 : Unsigned_8 :=
Ada.Unchecked_Conversion(Shift_Right(Data));
Part2 : Unsigned_8 := Ada.Unchecked_Conversion(Data);
begin
Asm (Template => "outb 14, 0x3D4" & NL
& "outb %0, 0x3D5" & NL
& "outb 15, 0x3D4" & NL
& "outb %1, ox3D5",
Input => (Unsigned_8'Asm_Input(Part1),
Unsigned_8'Asm_Input(Part2));
end Update_Cursor;
-----------------------------------------------------------------------------
...
end Vga;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: updating a hardware cursor with assembly and ada
2008-03-07 19:01 ` cl1
@ 2008-03-07 20:16 ` Ludovic Brenta
0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Brenta @ 2008-03-07 20:16 UTC (permalink / raw)
cl1 writes:
> Okay I have updated the Update_Cursor method with the following
> implementation, However I am getting the error:
>
> i386-elf-gcc -fno-pic -c -nostdinc -ffunction-sections -fdata-sections
> -I. -gnato -gnatp -gnatE vga.adb
> vga.adb:3:06: "System.Machine_Code" is not a predefined library unit
>
> I know the error message means there is no System.Machine_Code that
> it can find. What i don't know is if there is a flag, or something i
> can do to get access to it. I'm really lost at this point, because
> there is no way i can implement that package with my current
> knowledge.
System.Machine_Code is normally part of the standard library. Since
you don't have one, you have two possible solutions:
1) write your own minimalistic run-time library, consisting at least
of System and System.Machine_Code (you can copy GNAT's library if
you want to). BTW, the compiler requires a package System that
describes the target architecture.
2) Write procedure Update_Cursor directly in assembly language (as
opposed to inline assembly in an Ada source file).
HTH
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-03-07 20:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-06 17:07 updating a hardware cursor with assembly and ada cl1
2008-03-06 17:26 ` Georg Bauhaus
2008-03-06 17:51 ` cl1
2008-03-06 21:31 ` Adam Beneschan
2008-03-06 19:39 ` Jeffrey R. Carter
2008-03-06 20:08 ` Gautier
2008-03-06 20:14 ` Gautier
2008-03-06 22:54 ` Ludovic Brenta
2008-03-07 15:26 ` cl1
2008-03-07 19:01 ` cl1
2008-03-07 20:16 ` Ludovic Brenta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox