Page 1 of 2

Allocate memory without DOS!

Posted: Wed Apr 24, 2002 11:49 am
by drasir
Hi!

I'm just trying to write my own OS and I thing i am progressing very well but i discovered a major problem.
My OS is written in Turbo Pascal and NASM. When the Bootloader loads my kernel, no DOS is present.
How can I now allocate Memory from within the kernel?
The Turbo Pascal NEW(); procedure uses the DOS call 21h to do that but hey, there is no DOS?

I need help, thanks!

Re:Allocate memory without DOS!

Posted: Wed Apr 24, 2002 12:30 pm
by ASHLEY4.
I had the same problem, My os is in turbo pascal
What you need is a program called picoDos it works like this:

PicoDOS is a program loader. This boot sector is able to load .COM files or "MZ" .EXE files.
It's useful for an OS for example: you write an EXE file and you test it under DOS. When all works good, you can use it with PicoDOS.




Services supported
Int 20h
Terminate a program (for .COM files)
Int 21h
Functions:
?00h: terminate program
?01h: read character with echo
?02h: write character
?07h: read character without echo
?09h: write string (ended with '$')
?19h: get current drive
?25h: set interrupt vector
?30h: get dos version
?35h: get interrupt vector
?48h: allocate ram memory
?4Ch: terminate program

To compile and run it: (you'll need NASM)
Unzip the file.
Put a blank disk in your drive (A), and type make.bat

This let you make your kernel a exe,you can put the kernel on a floppy and can use the above int,all other int must be bios int
I have lost the web site,but have the zip file if you want it let me know and i will email it (16 kb).

\\\///
(@@)
ASHLEY4.

Re:Allocate memory without DOS!

Posted: Wed Apr 24, 2002 3:18 pm
by Tim
In this case, PicoDOS is the OS, and your OS is a program running within it. To fully write your OS, you need to duplicate the services that PicoDOS provides (this is the fun part :)).

To start you off, here's some memory management tutorials: (they assume you're running in a 32-bit flat address space)
http://www.themoebius.org.uk/tutes/

Re:Allocate memory without DOS!

Posted: Wed Apr 24, 2002 4:59 pm
by ASHLEY4
No its a 2 stage boot loader,If you want a turbo pascal kernel(16bit)thats what you have to do.
he's a C fan ,he does not understand.
The best would be to make your own in assembly(2stage boot loader), but this will help you learn how to do it.

\\\|///
(@@)
ASHLEY4.

Re:Allocate memory without DOS!

Posted: Thu Apr 25, 2002 4:42 am
by drasir
Thanks for the quick answer but I think both of you got me wrong.
Well, I HAVE my own bootloader that is capable of loading .EXE files compiled with Turbo Pascal.
This Bootloader does not provide any 21h Functions or memory allocation funcrtions.
I want the emuzlation of these functions within my Turbo Pascal kernel.
What I really need is a procedure like the NEW or GETMEM procedure from Pascal - see I have problems with assembler and my father helped me tu create the bootsector so I can NOT rewrite PICODOS or its functions in ASM.
In fact I already know PicoDOS, i once had a Version of it but the only thing it did was just to hang...
I would be glad if you could mail me your version.

Re:Allocate memory without DOS!

Posted: Thu Apr 25, 2002 12:41 pm
by ASHLEY4
I will send you picodos, i had the same problem its the install bat (it does not copy it right)
I can not remeber how i fixed it, i'l look in to it.
You say your loader load's exe ,But in turbo pascal the "end." uses:

mov ax, 4c00h
int 21h

To end programs,how does it do this?????.
With out int 21h.

\\\\////
(@@)
ASHLEY4.

Re:Allocate memory without DOS!

Posted: Thu Apr 25, 2002 6:09 pm
by Tim
drasir: from what I remember (I used to program Turbo Pascal a lot), the TP compiler adds a lot of hidden references to code in the System unit. While it's theoretically possible to replace the System unit, I don't know of any documentation that tells you how to do it. The System unit that comes with TP contains all the DOS calls; in order to get your code to use your own OS routines, you'd have to replace all that code. I don't think it's possible to remove all references to the System unit: as you've seen, it gets used for New and GetMem.

As an alternative, you might want to try the Free Pascal compiler. Although FPC programs run in 32-bit protected mode, it's completely open and you can get it to call whatever you want. I've tried it myself and it's certainly possible to add your own OS hooks in there. The package provides sample system unit source code for you to customise.

Re:Allocate memory without DOS!

Posted: Fri Apr 26, 2002 6:47 am
by drasir
Ashley: Well infact my bootloader loads only one .exe and thats my kernel so i don't need to bother about the end function because... The program never ends...

Tim: I think it is pretty easy to replace the 21h functions.
These Functions are called by the interrupt 21h as the name says. To replace them the only thing i need to do is to write an interrupt procedure and use setintvec($21,@DOSEMU);
Now the interrupt is linked with my unit, and all DOS Calls end there.
I have written the Setintvec Procedure by myself because this is one of the very few SYSTEM functions that use DOS calls. MOST of them are BIOS Calls. The DOS Unit depends to 99% on 21h calls but not the System.TPU

Thanks anyway!

Re:Allocate memory without DOS!

Posted: Fri Apr 26, 2002 11:27 am
by ASHLEY4
On this site page 2 ,under "16bit kernel what compiler????"
This may help.
I realized after i writen it ,that the kernel did not end :-[

I gave up on a PASACL kernel and moved to ASM because of the problems, this discusion has help me clear up some of those problems .

I may give a PASCAL kernel another try :-\ as i have always been a fan of TP .

I have tryed FREE PASCAL as TIM sugested but found the following problems, it is very hard to switch from TP to FP as one is 16bit and the other 32bit there are so many little diferances that you have to change, tracking them down can be harder than learning a new language, also the EXE's are so large.

If you still want PICODOS send me your email address were i can send it to.

\\\///
(@@)
ASHLEY4.

Re:Allocate memory without DOS!

Posted: Fri Apr 26, 2002 4:05 pm
by Tim
drasir: I mean, replace the functionality of the int 21h functions. Duplicating them exactly would be too restrictive (and you'd only end up with a DOS clone in the end).

Ashley: Free Pascal is 32-bit, and as such it's a bit different to TP. But the advantages of a 32-bit environment far outweigh the any advantages of sticking with 16-bit TP. It's up to you, but if I were you I'd definitely invest the time required to adjust to the changes.

Re:Allocate memory without DOS!

Posted: Fri Apr 26, 2002 7:51 pm
by ASHLEY4
Tim:
I agree with what you say,But my idea is to make a real mode dos clone,Then run a 32bit PM OS on top of it. Rather then use freedos which is a bit buggie ,I want to make my own.

This is because no matter how good your OS is people will not use it if there is no software, by adding thing's like USB support and fat32 etc, and then 32bit PM,
People may move from dos (there's still a lot who use it).

Im a turbo pascal and asm fan,i do not like c/c++
but to me freepascal is not as good as vpascal and i would rather use DJGPP which is better made.
I find ASM more under standable than the encripted C language.

ps:like the web site 8)

\\\///
(@@)
ASHLEY4.

Re:Allocate memory without DOS!

Posted: Fri Apr 26, 2002 8:21 pm
by K.J.
You can't "run" a PMode 32bit OS on top of a 16bit real mode OS. You could make a program that "takes over" the 16bit RMode OS and then starts the 32bit PMode OS or you could make a program that runs on top of the 16bit RMode OS that turns on PMode and handles task switching etc, but it would really be a program running on the 16bit RMode OS.

K.J.

Re:Allocate memory without DOS!

Posted: Sat Apr 27, 2002 3:09 am
by drasir
Ashley: Yes, I still want PicoDOS: Please sent it to "[email protected]".
I think you got my Idea right... My intention s also to write in fact my own DOS Clone because there is a hell of software available that will run under DOS and I could as you mentioned ad USB Support or such things!
And yes C/C++ really sucks :D Just look at this syntax, thats total crap. Well I know most C Programmers would be very upset about such a statement but thats my personal view. Pascal is just the best - Structured syntax, fast compile&run, small code - all you need ;D

K.J.: Well I think you are very right but, just look at win95 and up. All this OS depended on a 16bit Kernel but they were able to do 32bit things! ??? Or ain't this the thing you are talking about?

Regards, Drasir

Re:Allocate memory without DOS!

Posted: Sat Apr 27, 2002 3:37 am
by Pype.Clicker
K.J.: Well I think you are very right but, just look at win95 and up. All this OS depended on a 16bit Kernel but they were able to do 32bit things! Or ain't this the thing you are talking about?
Well, just because it is a mix (mess?) between 16 and 32 bits programming, Windows 9x suxx! Worst ever floppy driver, bugging libraries and the like, most the problems come from there! do a pure-16bits or a pure-32bits OS, but don't fall in the pit of (16+32)>>1 programming or you will hardly escape ...

And for the C vs Pascal OS programming, are you aware that the Pascal compiler will add plenty of code for arrays, stacks, etc. boundaries checking ? ... Now, there can be flags to turn these off, but still, it seems a very weird idea to me ...

Re:Allocate memory without DOS!

Posted: Sat Apr 27, 2002 7:23 am
by drasir
:-[ Well yes I think you are right all this 16/32Bit Mix OS really suck! Thats why we all are here, aren't we? To do it better than Bill&Microsoft!
And hey what would the modern PC be without Microsoft OS's? ???
I think after all the sh*t MS gave to the PC Users
now with WinXP we got the first real kewl OS!
Don't get me wrong I am not a supporter of Microsoft or something but until know nobody has done better than MS in writing OS's.
And don't know come all and say -> "Hey, try linux thats the best"... Man I did and belive me, thats totally crap!

My comment on C wasn't only dependend on OS programming! I ment C/C++ generally. The syntax really sucks ;) You can not deny this! And for the code...
Write the same program in both languages and compile it. I bet that makes no different.

Regards, DRasir
-=You knever know=-