flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Problem with doing intersegmental syscalls :( HELP!!!!!!

Author
Thread Post new topic Reply to topic
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
So, I have got two kernels,
One is the main one called from my own second stage bootloader known as NTLOAD.SYS, as APOS16.SYS (Kernel Filename),
Now that I need to extend my kernel API and keeping my kernel size limited, I've got to do intersegmental syscalls like :
Code:
; Assuming I'm in segment 0x2000
; I would do this
jmp 0x3000:0x0000
jmp 0x3000:0x0003
jmp 0x3000:0x0004
; and so on........
    

Basically I would load a file called BOOTDRV.SYS which contains these calls,
Now I have written some code but they don't seem to work.
My Kernel Caller,
Code:
; Load the BOOTDRV.SYS (Boot Drivers) in memory at 0x3000
        ; First Initialize the FDD
        call init_FDD
        ; Set up segments
        cli                             ; Clear interrupts
        mov ax, 0
        mov ss, ax                      
        mov sp, 0FFFFh
        sti                             
        cld                             
        mov ax,2000h                    
        mov ds, ax                      
        mov es, ax                      
        mov fs, ax                      
        mov ax,0x3000 ; ---> Reserved for BOOTDRV.SYS
        mov gs,ax
        call load_kernel
        call os_command_line ; Start the Interface
load_kernel:
        mov ax, .pos16_sys
        mov cx, 28768
        call os_load_file
        jc os_fatal_error
        push es
        push 0x3000
        pop es
        mov si, 28768
        mov di, 0
        mov cx, bx
        rep movsb
        mov ax, 0000h
        mov es, ax
        mov word [es:0014h], 0x3000
        mov word [es:0016h], .BOOT_BREAK
        mov word [es:006Ch], 0x3000 
        mov word [es:006Eh], .BOOT_BREAK
        pop es
        ret
        .pos16_sys db 'BOOTDRV.SYS',0
.BOOT_BREAK:
        cli
        pop ax
        pop ax
        push 2000h
        push os_command_line
        sti
        iret
    

And here's how my extended kernel looks like :
Code:
; POS16 Extended API
jmp os_lol ; 0x3000:0x0000
SEGMENT_RETURN:
        pushf
        pop word [gs:flags_tmp]
        cmp byte [gs:internal_call], 1
        jge .internal_return
        mov word [gs:return_ax_tmp], ax
        mov ax, fs
        mov ds, ax
        mov es, ax
        pop ax
        push 0x2000
        push ax
        mov ax, [gs:return_ax_tmp]
        push word [gs:flags_tmp]
        popf
        retf
        .internal_return:
                ret
flags_tmp                       dw 0
internal_call                   dw 0            ; cancels os_return
return_ax_tmp                   dw 0
os_lol:
        mov ah,0x0E
        jmp .loop
.loop:
        lodsb
        cmp al,0
        je .done
        int 10h
.done:
        jmp SEGMENT_RETURN
    

And I perform the call like this :
Code:
ext_print equ 3000h:0000h
mov si,lol2
call ext_print
jmp back_2_interface
lol2 db 'LOL! Printed from the Extended Kernel',0
    

When I execute this my OS halts and then the screen is almost unreadable?
Is there something wrong?[/code]

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 17 Nov 2013, 11:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17624
Location: In your JS exploiting you and your system
revolution
Seem rather complicated. Perhaps instead you can try something like this:
Code:
mov si,text
mov ax,cs
mov ds,ax
call 0x3000:ext_print
jmp $
text: db 'Hello World!',0

;... skip to segment 0x3000
org 0
ext_print:
        call    int_print
        retf

int_print:
        ; 'int 0x10' printing code goes here
        ret    
Post 18 Nov 2013, 01:36
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.