Me and Pascal again...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
fbelzile
Posts: 18
Joined: Tue Dec 28, 2004 12:00 am

Me and Pascal again...

Post by fbelzile »

I'm not sure if it was on these forums that I asked a question about programming an OS in Pascal. I searched here, but didn't find anything.

Its been a long time since I posted in this forum, I have lost the intrest/gave-up in OS programming. Now, it has come back, and I think I'm more prepared than ever. I am now learning assembly, C/C++ (going over it again), and Pascal.


Anyways, I know that I can use Pascal to make a basic kernal, because I have done it before. By basic, I mean Basic, like printing stuff to the screen..

Here is what I use so far, but when the bootstrap loader loads this "program" It simply dosen't do anything.
I remember, when I got help last time, my helper told me that I had DOS interprets, he simply modified a line and it worked...

Here is my code:

Code: Select all

begin

writeln ('Hello, world.');
readln

end.

Thanks for reading this large post and answering if you do know whats wrong :)
Crazed123
Member
Member
Posts: 248
Joined: Thu Oct 21, 2004 11:00 pm

Re: Me and Pascal again...

Post by Crazed123 »

You're probably going to want to build a "blank" RTL so that your kernel can run without talking to DOS or another operating system. And if it isn't doing that currently, then I have no idea how you ever got that program to work. I/O shouldn't work when you're running on bare hardware!
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Me and Pascal again...

Post by Legend »

Yes, next step would be - implement writeln and readln! ;)
*post*
fbelzile
Posts: 18
Joined: Tue Dec 28, 2004 12:00 am

Re: Me and Pascal again...

Post by fbelzile »

Arrrhh, I wish I could find that old topic.

I remember, I used writeln and readln and it worked.

I think I'm not using the same compiler though and I might have passed argument(s) to do this sort of thing (create stand-alone binary file)

I'll be back later to tell you if I found it.
Crazed123
Member
Member
Posts: 248
Joined: Thu Oct 21, 2004 11:00 pm

Re: Me and Pascal again...

Post by Crazed123 »

As far as I know you can't create a standalone binary file without first writing a special RTL made for standalone work. This means if writeln() and readln() were actually working somebody hacked an RTL that interacted with bare hardware (probably text-mode VRAM and a simple keyboard driver) correctly. Pretty neat, but actually kind of hampering if you want to build a serious kernel.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Me and Pascal again...

Post by bubach »

You can use writeln etc with the crt unit instead of the dos one. so write something like "use crt" at the top..
This all assumes that you are just testing with a very simple bootloader and is still in realmode.
The crt unit uses BIOS instead of DOS which is default.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
fbelzile
Posts: 18
Joined: Tue Dec 28, 2004 12:00 am

Re: Me and Pascal again...

Post by fbelzile »

Ah ha! Thank-you so much bubach. That was it! :)

However, when I tried it, it still didn't work :(
I'll try some different compiler's as I'm not too sure the one I used before.

But, I know it was that line. Thanks again, I am one step closer!

I'll fill you in on how it goes ;)


EDIT:
Hey, bubach, I found the last page of the post that I was looking for.
It still never gave me the thing I was looking for. It was on the old Bona Fide OSDev forums (Found it on Google's cache, I think they are re-doing their forums). ASHLEY4 was the user that helped me. I did a bit more research, and I found that you sort of know each other at the V2_OS forums :P Funny what little research can do :)
Last edited by fbelzile on Sat Sep 24, 2005 11:00 pm, edited 1 time in total.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Me and Pascal again...

Post by bubach »

What do you compile it as? A realmode exe-file? And how do you start it, which bootloader do you use?

If you for example use old borland Pascal you can make a normal .EXE file and start it with bootprog ( a bootsector that loads realmode exe's ) from: http://alexfru.chat.ru/epm.html#bootprog

If you later wants to start with 32-bit stuff in Pascal you can visit http://mega-tokyo.com/forum/ and ask in that forum, it has atleast two Pascal os-devers.

Yup, me and ashley4 ( now called dex4u ) was active there for a while, before we started our own OS's.
He can be reached on his own forum at http://dex.forumer.com/
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
fbelzile
Posts: 18
Joined: Tue Dec 28, 2004 12:00 am

Re: Me and Pascal again...

Post by fbelzile »

What do you compile it as?
This is the exact command... (Nothing special. I use Free Pascal)

fpc test.pas

I'm compiling the same code as in my first post but with the:

uses crt;

My guess is that I'm doing something wrong here. I think what I'm doing is a 32-bit program right? How would I go about doing a real mode or 16-bit exe with Free Pascal? I've read all the available commands and I still dont have a clue :(

If you for example use old borland Pascal you can make a normal .EXE file and start it with bootprog ( a bootsector that loads realmode exe's ) from: http://alexfru.chat.ru/epm.html#bootprog
Guess what, I am using that exact bootstrap loader. Or I use this one:
http://www.cse.unl.edu/~jgompert/OS/BOOT12.ASM
If you later wants to start with 32-bit stuff in Pascal you can visit http://mega-tokyo.com/forum/ and ask in that forum, it has atleast two Pascal os-devers.
Thanks for the information :)
Yup, me and ashley4 ( now called dex4u ) was active there for a while, before we started our own OS's.
He can be reached on his own forum at http://dex.forumer.com/
Haha, I remember! He did make an OS called DexOS. He made me try it out. He made it in Pascal too :P


Thanks for all your help so far... I hope you know what the problem is.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Me and Pascal again...

Post by bubach »

FreePascal doesn't support 16-bit as far as I call tell from it's homepage.

You can do two things to get it working:

1. Download an old Borland version for free at the borland museum ( http://bdn.borland.com/article/images/20803/tp55.zip ) and try that instead.

Good 16-bit reading:
http://kerim.abshost.net/tutorials/intro.htm
http://kerim.abshost.net/tutorials/bootup.htm
http://kerim.abshost.net/tutorials/kernel.htm


2. Continue to use FreePascal, which you have to if you want a "real" 32-bit OS, and make your own functions to print to screen etc.

Maybe something like this:

Code: Select all

var
  vidmem: PChar = PChar($b8000);
  xpos: Integer = 0;
  ypos: Integer = 0;

procedure kclearscreen(); [public, alias: 'kclearscreen'];
var
  i: Integer;
begin
  for i := 0 to 3999 do
      vidmem[i] := #0;
end;

procedure kwritestr(s: PChar); [public, alias: 'kwritestr'];
var
  offset, i: Integer;
begin
  if (ypos > 24) then
      ypos := 0;

  if (xpos > 79) then
      xpos := 0;

  offset := (xpos shl 1) + (ypos * 160);
  i := 0;

  while (s[i] <> Char($0)) do
  begin
      vidmem[offset] := s[i];
      offset += 1;
      vidmem[offset] := #7;
      offset += 1;
      i += 1;
  end;

  xpos := (offset mod 160);
  ypos := (offset - xpos) div 160;
  xpos := xpos shr 1;
end;
That later can be called with:

Code: Select all

      kclearscreen();
      kwritestr('HELLO WORLD FROM FREEPASCAL');
More reading:
http://www.mega-tokyo.com/forum/index.p ... 44;start=0
http://groups.google.com/group/pascalosdev
http://www.mega-tokyo.com/forum/index.p ... 14;start=0

Hope that helps, I'm no Pascal expert...

/ Christoffer
Last edited by bubach on Mon Sep 26, 2005 11:00 pm, edited 1 time in total.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
fbelzile
Posts: 18
Joined: Tue Dec 28, 2004 12:00 am

Re: Me and Pascal again...

Post by fbelzile »

You nailed it!

That was it! It was all Free Pascal's fault. :P

I know you can program Operating System's with Free Pascal, but I guess you have to be more low-level.

Well, thank-you for all of your help. It is greatly appreciated :)
I'll take it from here :P

Best of lucks with your projects.
Post Reply