flat assembler
Message board for the users of flat assembler.

Index > OS Construction > external jump? external call?

Author
Thread Post new topic Reply to topic
ralc



Joined: 13 Mar 2008
Posts: 4
ralc
I am probably using the wrong terms. I have searched without finding ‘external jump’ or ‘external call.’

My rudimentary operating system writes to and read from sectors selected by the user, prints the time, and has an arbitrary number generator with a game. The kernel is not approaching 64K, but I have been thinking that it would be easier to write, assemble & debug code if the kernel would run external programs (such as the read and write functions) that are now part of the kernel.
From where I stand (I should be in the shallow end of the pool, but in this I think I am well in over my head) there could be two ways of doing this:
1) Load the program from a certain sector(s) of the disk.
2) Call the program by name.

I have tried the first approach since I thought I had an idea of how to do that by modifying some code from a boot loader that loads the kernel from the second sector of a floppy (although, I am a bit confused. The comments in the boot loader code say that the kernel is to be written to the second sector, at 0800h:0000h. I thought that the second sector would be 0400:0000, which partially explains the various tries pointed out in the comments in the code below). I copied the compiled program that I want to call onto the 4th sector of the disk.

I added this code to the kernel (hoping) to load and run program:

mov ah, 02h ; read
mov al, 2 ; num. of sectors to read.
mov ch, 0 ; cylinder num
mov cl, 4 ; sector num
mov dh, 0 ; head num.
; es:bx points to receiving data
mov bx, 1000h ; also tried 0800h & 0400h
mov es, bx
mov bx, 1000h ; also tried 0800h & 0400h
int 13h ; read
jmp 1000h ; also tried 0800h & 0400h

The code compiles and the kernel works fine until I type in the command to make the external jump and press Enter. Then the kernel freezes.

Any help is appreciated.

Thank you,

RALC
Post 29 Sep 2008, 04:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
You will need a far jump (or call), that way you also load CS with the segment of the data you just loaded.
Code:
jmp far dword [some_memory_dword_that_has_the_offset_and_segment_values]    
Post 29 Sep 2008, 04:45
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello Wink
Code:
    mov     ah,02h          ; read
      mov     al,2            ; num. of sectors to read.
  mov     ch,0            ; cylinder num
      mov     cl,4            ; start to load from sector number 4
        mov     dh,0            ; head num.
        mov     dl,[Boot_Drive] ; Load Boot Drive

; es:bx points to receiving data

    mov     bx,1000h 
   mov     es,bx
       int     13h             ; read

  jmp     1000h:1000h     ; segment:offset
    


Why 1000h Question

_________________
Nil Volentibus Arduum Razz
Post 29 Sep 2008, 07:44
View user's profile Send private message Reply with quote
ralc



Joined: 13 Mar 2008
Posts: 4
ralc
I replaced jmp with jmp far.

mov ah, 02h ; read
mov al, 2 ; num. of sectors to read.
mov ch, 0 ; cylinder num
mov cl, 4 ; sector num
mov dh, 0 ; head num.
; es:bx points to receiving data
mov bx, 0400h
mov es, bx
mov bx, 0
int 13h ; read
jmp far 0800h

Now the system reboots. That is better than freezing. But I must still be leaving something out.

Thanks

RALC
Post 02 Oct 2008, 16:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Yes, you are forgetting about the segment register CS.
Post 02 Oct 2008, 16:18
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
external jumps or calls implies external memory map.
then, if you call or jump to another segment or descriptor, you will use the far pointers ONLY.

far pointers are cool and your friend.
very simple to use, as well in RM, PM, 16 & 32 bits.

to define a far pointer?

read the manual:
Code:

farpointer1616 dd Ssegment:Ooffset 
farpointer1632 dp Ssegment:Ooffset

;where Ssegment is the segment 
;and Ooffset is the offset.
;
;dd and dp directives, when defining a far pointer, will be identicall to:
farpointer1616 dw Ooffset:Ssegment
farpointer1632 dd Ooffset
dw Ssegment

    


how to use these pointers?
where to put them?

in any data segment!

Code:
call far [farpointer]      ;if hte far pointer is in ds.
call far dword[ss:ebp] ; if there is a far pointer in the stack.
call far pword [gs:esi+eax*8+100h] ; to access the far pointer from advanced structure.

of course, for jmp, it is the same!!! :D
    

now, you can play with external call/jumps.
Post 02 Oct 2008, 17:19
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.