flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > turbo pascal question |
Author |
|
arcangel 21 May 2011, 15:42
I´m working on a little Operative System with Turbo Pascal 6.0.
Does anybody know how to execute a program without using exec instruction? Thanks |
|||
21 May 2011, 15:42 |
|
arcangel 21 May 2011, 16:14
Enko wrote:
Thanks for replying I'm working with "Boot sector that loads and runs COM/EXE programs"http://alexfru.chat.ru/eindex.html the source code is here http://alexfru.chat.ru/programming/bootprog.zip with this I made a tiny turbo pascal kernel and I boot it from a floppy but I need that my little operating system runs a program without using exec. I can not use exec because no MS-DOS |
|||
21 May 2011, 16:14 |
|
JohnFound 22 May 2011, 07:51
You have to write your own functions that to manage the file system of the disk. Then you have to write .exe loader function, that to read the .exe file from the disk to the memory and to call its entry point. Of course you have to write some memory management functions as well.
|
|||
22 May 2011, 07:51 |
|
Dex4u 22 May 2011, 17:01
Here is a quick example of what you need to do
Code: {MZ} uses dos1, strings; var OLDHANDLER : Procedure; {$F+} Procedure int21HANDLER(Flags, CS, IP, AX, BX, CX, DX,SI, DI, DS, ES, BP: Word); Interrupt; var end_memory,top_memory:integer; DriveNumber:byte; Begin {read character with echo} IF HI(AX)=$01 THEN BEGIN ASM XOR AX, AX int 16h mov ah, 0Eh int 10h END; END; {write character} IF HI(AX)=$02 THEN BEGIN ASM mov al, dl mov ah, 0Eh int 10h END; END; {read character without echo} IF HI(AX)=$07 THEN BEGIN ASM xor ax, ax int 16h END; END; { write string; input ds:dx = string (ended with '$')} IF HI(AX)=$09 THEN BEGIN ASM { ds:dx points to string} mov si,dx { ds:si = string} cld @print_loop: lodsb { get next character} cmp al,'$' { is it $ ?} je @done { if so, we're done} mov ah,0eh { function 0eh-print character} xor bx,bx { video page 0} int 10h jmp @print_loop @done: mov ax,0e0ah int 10h mov ax,0e0dh int 10h END; END; { get current drive} IF HI(AX)=$19 THEN BEGIN DriveNumber:=0; ASM mov al,cs:[DriveNumber] END; END; {set interrupt vector} IF HI(AX)=$25 THEN BEGIN ASM cmp al, 19h { do not allow to change int 19h (for rebooting)} je @int21_error cli xor ah, ah shl ax, 2 push si push bx push es mov si, ax xor bx, bx mov es, bx mov word ptr es:[si], dx { offset} mov bx, ds mov word ptr es:[si+2], bx { segment} pop es pop bx pop si sti jmp @endit @int21_error: mov ax, 0FFFFh @endit: END; END; {get date IF HI(AX)=$2A THEN BEGIN END;} {set date IF HI(AX)=$2B THEN BEGIN END;} {get time IF HI(AX)=$2C THEN BEGIN END;} {set time IF HI(AX)=$2D THEN BEGIN END;} {jmp int21_error} {get dos version} IF HI(AX)=$30 THEN BEGIN AX:=$3031; END; {get interrupt vector} IF HI(AX)=$35 THEN BEGIN ASM push ds push si xor ah, ah shl ax, 2 mov si, ax xor bx, bx mov ds, bx mov bx, word ptr ds:[si+2] push bx mov bx, word ptr ds:[si] pop es pop si pop ds END; END; {alloc ram memory} IF HI(AX)=$48 THEN BEGIN ASM mov ax, es shr ax, 2 inc ax shl ax, 2 mov word ptr [end_memory], ax {; save (to know free memory)} int 12h {; get ram size (in KB)} { ; convert in paragraphs: (*64)} shl ax, 6 mov word ptr [top_memory], ax mov ax, word ptr cs:[end_memory] add ax, bx cmp ax, word ptr cs:[top_memory] jg @error mov word ptr cs:[top_memory], ax mov bx, word ptr cs:[top_memory] { return in bx free paragraphs} sub bx, word ptr cs:[end_memory] jmp @endit1 @error: stc mov ax, 0FFFFh @endit1: END; END; IF HI(AX)=$4C THEN BEGIN ASM push cs pop ax mov ds, ax mov es, ax mov ip,0FFFFh END; END; END; {$F-} procedure ShowText; assembler; const Msg :PChar = 'This text is shown using DOS ...INT 21h (09h) $'; asm mov dx,word ptr Msg mov ah,9 int 21h end; procedure WriteChr(Chr: Char); begin asm MOV Al, Chr PUSHA MOV Ah, 0Eh INT 10h POPA end; end; procedure next_line; begin asm MOV AH,3 INT 10h MOV AH,2 INC DH MOV DL,0 INT 10h end; end; PROCEDURE DOS_VER; BEGIN ASM mov aH, 30h int 21h mov bl,ah mov aH,0eh int 10h mov ax,0e2eh int 10h mov al,bl mov aH,0eh int 10h END; END; procedure WritelnA(Str: String); var Pos: Integer; Chr: array[0..254] of Char; begin StrPCopy(Chr, Str); for Pos := 0 to (Length(Str) - 1) do begin WriteChr(Chr[Pos]); end; next_line; end; procedure WriteA(Str: String); var Pos: Integer; Chr: array[0..254] of Char; begin StrPCopy(Chr, Str); for Pos := 0 to (Length(Str) - 1) do begin WriteChr(Chr[Pos]); end; end; procedure hold; begin asm PUSHA XOR AX,AX INT 16h POPA end; end; Procedure INSTALL_HANDLER; begin GetIntVec($21,@OLDHANDLER); SetIntVec($21,ADDR(int21HANDLER)); end; PROCEDURE CLS; BEGIN ASM mov AH,2 mov BH,0 mov DX,0 int 16 mov AH,9 mov CX,2000 mov AL,' ' mov BL,7 int 16 mov AH,2 mov BH,0 mov DX,0 int 16 END; END; begin INSTALL_HANDLER; writelnA('loading kernel 16 !'); hold; CLS; writelnA('hello world!'); hold; writelnA('DOES INT 21 09h WORK?'); HOLD; SHOWTEXT; HOLD; WriteA('The PAS-DOS Version ');DOS_VER; NEXT_LINE; hold; writelnA('press enter to reboot!'); hold; end. You need to take the asm code from bootprog for loading exe file and replace the pascal exec rtl with yours. Heres whats in the pascal rtl EXEC Code: TITLE EXEC LOCALS @@ DATA SEGMENT WORD PUBLIC EXTRN DosError:WORD,PrefixSeg:WORD SaveSP DW ? SaveSS DW ? DATA ENDS CODE SEGMENT BYTE PUBLIC ASSUME CS:CODE,DS:DATA PUBLIC Exec Exec PROC FAR PathArg EQU DWORD PTR [BP+10] CmdLineArg EQU DWORD PTR [BP+6] FileSeg2 EQU WORD PTR [BP-2] FileOfs2 EQU WORD PTR [BP-4] FileSeg1 EQU WORD PTR [BP-6] FileOfs1 EQU WORD PTR [BP-8] CmdLineSeg EQU WORD PTR [BP-10] CmdLineOfs EQU WORD PTR [BP-12] EnvironSeg EQU WORD PTR [BP-14] FileBlock1 EQU BYTE PTR [BP-30] FileBlock2 EQU BYTE PTR [BP-46] Path EQU BYTE PTR [BP-126] CmdLine EQU BYTE PTR [BP-254] PUSH BP MOV BP,SP MOV SaveSP,SP MOV SaveSS,SS SUB SP,254 MOV DS,PrefixSeg MOV AX,WORD PTR DS:2CH MOV EnvironSeg,AX PUSH SS POP ES CLD LDS SI,PathArg LEA DI,Path LODSB CMP AL,79 JB @@1 MOV AL,79 @@1: CBW XCHG AX,CX REP MOVSB XOR AL,AL STOSB LDS SI,CmdLineArg LEA DI,CmdLine LODSB CMP AL,126 JB @@2 MOV AL,126 @@2: STOSB CBW XCHG AX,CX REP MOVSB MOV AL,0DH STOSB PUSH SS POP DS LEA SI,CmdLine MOV CmdLineOfs,SI MOV CmdLineSeg,DS INC SI LEA DI,FileBlock1 MOV FileOfs1,DI MOV FileSeg1,ES MOV AX,2901H INT 21H LEA DI,FileBlock2 MOV FileOfs2,DI MOV FileSeg2,ES MOV AX,2901H INT 21H LEA DX,Path LEA BX,EnvironSeg MOV AX,4B00H INT 21H JC @@3 XOR AX,AX @@3: MOV DX,SEG DATA MOV DS,DX CLI MOV SP,SaveSP MOV SS,SaveSS STI MOV DosError,AX POP BP RET 8 Exec ENDP PUBLIC DosExitCode DosExitCode PROC FAR MOV AH,4DH INT 21H RET DosExitCode ENDP CODE ENDS END NOTE: There is another way you can do it, take a look at minidos it use bootprog for a loader and as bootprog loads its self high, you can jump to bootprog to load and run a exe. Then return to your kernel after wards. PS. Have you used the CRT trick yet ?, if you include CRT it does not use Dos for things like writeln, so you can use them in your kernel unmoded . |
|||
22 May 2011, 17:01 |
|
arcangel 22 May 2011, 20:46
Dex4u wrote: Here is a quick example of what you need to do Thanks for replying When I´m compiling the file, it gives me two errors in the dos1 and strings units. Regarding the second file, can I compile it with tasm? Where can I find the MINIDOS? What license has it got? is gpl? |
|||
22 May 2011, 20:46 |
|
ouadji 22 May 2011, 21:30
Turbo Pascal ? what's that ? has it to do with programming ? |
|||
22 May 2011, 21:30 |
|
Dex4u 23 May 2011, 01:16
You can get Minidos here: http://board.flatassembler.net/topic.php?t=5275&start=0
It's freeware you can do what you like with it.
|
|||||||||||
23 May 2011, 01:16 |
|
JohnFound 23 May 2011, 05:59
ouadji wrote:
Don't touch TurboPascal with your filthy fingers! It is cult compiler and you are too young to talk about it! BTW: arcangel, Turbo is great tool, but it is too old for any serious work. Better think about shifting to FASM, before the project become too big to be hard to be ported. In FASM you can use all your good habits from pascal programming on new, more powerful level. Last edited by JohnFound on 24 May 2011, 07:47; edited 1 time in total |
|||
23 May 2011, 05:59 |
|
arcangel 23 May 2011, 20:52
Dex4u wrote: You can get Minidos here: http://board.flatassembler.net/topic.php?t=5275&start=0 The Minidos and PassOS are very very very interesting but...Can I execute, for example, the hello.exe program on the Minidos and PassOS? Code: program hello; uses crt; begin writeln('hello word'); readln; end. |
|||
23 May 2011, 20:52 |
|
Dex4u 23 May 2011, 21:07
arcangel wrote:
You could run it on minidos, but PassOS did not have any load and run files, it was very basic. As i ended up write most of the function in inline asm, i just thought i would just write it 100% in asm. |
|||
23 May 2011, 21:07 |
|
arcangel 24 May 2011, 12:55
Dex4u wrote:
This is very very very interesting I've done a little modification and I've added the program hola.exe Could it be rewritten for others plataforms? For example, Uzebox? http://belogic.com/uzebox/index.asp I saw your project FAB, but it doesn't work. How can I write the address of the web? http://board.flatassembler.net/topic.php?t=8281 Will it work with Minidos? Thank you
|
|||||||||||
24 May 2011, 12:55 |
|
Dex4u 24 May 2011, 18:01
arcangel wrote: I saw your project FAB, but it doesn't work. How can I write the address of the web? FAB was not finished, we did not add the tcp/ip stack. The main problem is Ethernet card driver, there so many. One thing that may interest you is fasm macro, with them you can change asm into any language including pascal. Here is a basic example http://board.flatassembler.net/topic.php?t=7961 |
|||
24 May 2011, 18:01 |
|
arcangel 24 May 2011, 19:13
Dex4u wrote:
It's very interesting I am impressed with MiniDos Can I build a driver for the network card and connect to internet with lynx? Would you please guide me about it? |
|||
24 May 2011, 19:13 |
|
typedef 24 May 2011, 20:46
Turbo Pascal these days? Hahaha, that's funny...
At-least Turbo Assembler is still on these days, but Pascal, hmmm... |
|||
24 May 2011, 20:46 |
|
arcangel 25 May 2011, 19:07
typedef wrote: Turbo Pascal these days? Hahaha, that's funny... My idea is learning about it , and I think that Turbo Pascal is a good way to do it |
|||
25 May 2011, 19:07 |
|
rugxulo 26 May 2011, 18:00
It's not that crazy an idea, TP is pretty low-level already. I've seen crazier ideas. Besides, it's not the first time Pascal (or derivatives) has been used to write a full-fledged OS: see Modula-2 (Lilith), Modula-3 (SpinOS), Oberon (Oberon), etc.
|
|||
26 May 2011, 18:00 |
|
JohnFound 27 May 2011, 06:02
The big problem with TP is that it does not support protected mode compilation (I am not sure about TP7) so even if one create great OS with TP, this OS will be not possible to evolve to something more advanced and useful.
I would suggest using FreePascal, although it is not so good compiler as TP. Of course using FASM instead of any HLL is the best anyway. |
|||
27 May 2011, 06:02 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.