flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
edfed 05 Dec 2007, 05:01
org 100h is for the Program Segment Prefix
this header is 256 bytes long and is created at load time. .com org 100h is not only for dos, it's just a directive to create .com files, but can be used for other purposes. to load a .com file at boot, it's exactlly like for other binaries, don't make a jmp seg:100h but a call seg:100h to permit the return to bootloader. |
|||
![]() |
|
sinsi 05 Dec 2007, 05:12
A DOS .com file
- is loaded in a 64k segment at an offset of 0100 (i.e. it's a binary image with an origin of 0100) and allows no relocations or more than 1 segment (usually). - CS=DS=ES=SS, with SP=FFFE and IP=0100 - at 0000-00FF is the PSP, which DOS fills in before the jump to SEG:0100 If this is in 'OS Construction' then forget about .com files... |
|||
![]() |
|
rhyno_dagreat 05 Dec 2007, 05:29
Okay, but can you give me more info on how ot create the Program Segment Prefix and use it? Or do I not need to create it and just call that data segment at offset 100h?
|
|||
![]() |
|
edfed 05 Dec 2007, 05:31
look at this
|
|||
![]() |
|
rhyno_dagreat 05 Dec 2007, 05:32
edfed - Thanks!
sinsi - why? |
|||
![]() |
|
sinsi 05 Dec 2007, 05:45
rhyno_dagreat wrote: sinsi - why? .com files were a hangover from CP/M and are crap... but if you want to support them, then I understand why. Here's the PSP from ralf: Quote:
DOS has a function (26h) to create a PSP as well. |
|||
![]() |
|
Dex4u 05 Dec 2007, 16:07
This may help you, it's how to load a com file in your OS:
Code: ImageLoadSeg equ 60h Code: mov ax, ImageLoadSeg mov es, ax;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Setup and Run COM program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cli ; for stack adjustments mov ax, es sub ax, 10h ; "org 100h" stuff It is set out as follows: COM program defaults: cs = ds = es = ss = 50h, sp = 0, ip = 100h |
|||
![]() |
|
rhyno_dagreat 06 Dec 2007, 00:00
Dex - I was looking through the MiniDOS source, trying to figure all that out, and now it just hit me that you're subtracting 10h from 60h to get 50h which is what everything's being set to.
Thanks. So you're setting your ES, DS, SS segments to 50h, and the stack pointer to zero, and when you push something onto the stack and call "RET", it's returning to the current value on the stack, right? So the IP is returning to 100h. But how do you make sure that the code segment is 50h? Is that why you're pushing ES? like, first it returns 100h into the IP, and then 50h into CS? Or do you have to load it via a mov instruction? Sorry for my ignorance, but I'm getting most of what you're telling me. |
|||
![]() |
|
edfed 06 Dec 2007, 16:20
Code: far_pointer: .segment dw ? .offset dw 100h why don't you load the .com file at [far_pointer] instead of all this? and call far [far_pointer]? excuse me for errors, i don't know exactlly how to call a far memory pointer. ![]() |
|||
![]() |
|
Dex4u 06 Dec 2007, 18:48
The push ES makes the CS 50h and the push 100h makes the IP 100h along with the retf.
If you make the simplest com file example Code: org 100hret And opened it in a hex editor you would see something like this: Code: 0000:0000 c3 Now as you can see its got no header and the first byte is the ret, so com files are loaded to a address then a 100h is sub off the address, then the IP is set to CS:IP, so in the case CS is 50h and IP is 100h (remember the 50h is real (500h). So everthing in the PSP is put there by dos, in the above case we are just load com file in our OS so we leave the 256bytes blank. If you do a retf (realmode) it moves the words at top of stack to IP and CS and increments the SP by 4 This is differant than a far call. Note: You could load the same com file to differant address and like most coders, i am very rusty on coding in real mode. Also some set SP to 0xfffe, (remember it stores data downwards) |
|||
![]() |
|
edfed 06 Dec 2007, 20:07
if i port ORG 100h, i make some modifications, not really dangerous.
to exit a org 100h code, simply retf. or if org 100h for PM, then ret, cause of the first layer is for OS, and is at 0, or else. this layer, the PSP for MSDOS, can be what you want, 256 bytes for the link OS-APPLICATION. like a boot sector. this header can become a command line, byte 80h of psp is one exemple. then, the .com program can end with ret, this ret returns to the PSP, the PSP return to the OS. no? Code: push es push 100h ;0h if "com loader" in PSP. ;where do you remember the caller? retf ... ;come from os mov [farc.segment],ax mov [farc.offset],100h call far [farc] ;goto os ... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;far function, imported or connected org 100h ........ retf ;just remember to change the exit mechanism before compile! ;ret ;for test or dosbox ;mov ax,3 ;or old dos ;int 10h ; ;int 20h ; ;mov ax,exitcode ;for newer dos ;int 21h ;etc etc ... |
|||
![]() |
|
rhyno_dagreat 06 Dec 2007, 20:19
Thanks! This has helped tremendously.
|
|||
![]() |
|
edfed 07 Dec 2007, 06:25
very simple .com bootloader, tested with my 3Dengine ,without mouse.
Code: org 7C00h mov ax,cs mov ss,ax mov ds,ax mov [bootdrive],dl mov ax,27fh mov cx,2 mov dh,0 push word 1010h pop es mov bx,0 int 13h cmp [bootdrive],0 jl @f mov dx,3f2h mov al,0 out dx,al @@: jmp 1000h:100h times 505-($-$$) db 0 ;here need of the file system entry, extended to other sectors bootdrive db ? ;current bios drive, file system load the boot sector of with drive?. nextsectorentry dd 0 ; dw 0aa55h ;your org 100h code here simply put this code before the org 100h directive of .com programs, compile, and write the full .bin from boot sector to end of file my bootwriter or any image writer can do that, rawwrite, your own bootwriter, ... and then boot from this drive. it works. so, you can quietlly test your Real Mode interface from DOS or compatible. |
|||
![]() |
|
rhyno_dagreat 07 Dec 2007, 17:00
edfed wrote: very simple .com bootloader, tested with my 3Dengine ,without mouse. Thanks edfed! This is interesting. |
|||
![]() |
|
edfed 07 Dec 2007, 23:21
i've made an error, before to jmmp to .com code, we must set ds and ss to be at .com segment
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.