Author Topic: V86 mode segmentation address calculations  (Read 2205 times)

Offline Deskman243

  • Jr. Member
  • *
  • Posts: 49
V86 mode segmentation address calculations
« on: March 04, 2023, 04:12:24 PM »
Greetings Forum

I've got more news for the OS design subjects that I have been posting recently. I have a standard model for v86 tasking here so that we can display a very simple print function. Both methods have an output however the first one was for making a custom display function (hopefully provides a stage for a virtual VGA model). So the code should run completely however my contestion is that the method3 model label does not in fact address properly(this can be shown by comparing the method3 instruction code to the other printstr_task1 call of my code).
The standard logic for 80386 segment address = ((segment stack)(16)+(address shift)) so the protected mode address is shifted before the output method and I mainly tried making a stack (VM_VIDMEM_STACK) reference to adjust the (16) component of the segment.

I'm trying to learn how this maps to the linear address here however the object files show that mov es:[VM_VIDMEM_STACK],ax does nothing. Now I kinda have run through most thoughts I can think of so I'm really hoping that anyone else here could have a look at what had happened. I'd be happy to continue this and available for responses.

Here is the code for the Makefile


Code: [Select]
[BITS 16]
;[ORG 0x7E00]


section .text
;modeblock: times 512 db 0

jmp LoadProp

;section .text

;modeblock: times 256 db 0

SizeFunction:

mov bx,0x0000_7E00

;check address arithmetic base
add bx,0x0200
mov cl,3

SizeLoop:
mov ah,0x02
mov al,3
mov ch,0
mov dh,0
int 0x13

;    jc  ReadCheck
cmp cl,5
inc cl
jmp _prep_module2

;stackplacer: times 256 dd 0
;stack:

Gdt32:
dq 0

Code32:
dw 0xffff
dw 0
db 0
db 0x9a
db 0xcf
db 0

Data32:
dw 0xffff
dw 0
db 0
db 0x92
db 0xcf
db 0

Gdt32Len: equ $-Gdt32

Gdt32Ptr: dw Gdt32Len-1
dd Gdt32

Idt32Ptr:
dw 0
dd 0



vm_module:
sub dword [vidmem_ptr],VIDEO_TEXT_ADDR
mov si,vm_str
mov ah,COLOR_ATTR_BSC

call printstr_task

.loopcheck: jmp $

printstr_task:

; push si

push ax
push es

mov byte [ss:0],0

mov sp,VIDEO_TEXT_ADDR >>4
mov es,sp
mov sp,[vidmem_ptr]

; mov dh,0h
; mov dl,[vidmem_ptr]
; mov dx,sp
; mov dh,0
; mov [VM_VIDMEM_STACK],dx
; mov [VM_VIDMEM_STACK],sp

mov [ss:0],es
shr sp,4
add sp,[ss:0]
mov es,sp

jmp gettext


output:

;Buffer loop cycling

; test es,sp
; cmp sp,[vidmem_ptr]
; jnz prop


prep:


prop:



mov sp,[VM_VIDMEM_STACK]
mov sp,VM_VIDMEM_STACK

; mov es:[VM_VIDMEM_STACK],ax
; mov [es:VM_VIDMEM_STACK],ax
; mov [es:0],ax
; mov es:[vidmem_ptr],ax


; mov [es:sp],ax

add byte [VM_VIDMEM_STACK],2

;method3
mov [es:0],ax
mov sp,es
add sp,2
mov es,sp



gettext:

mov al,byte [ds:si]

inc si


test al,al
jnz output
; jnz .prop

mov [vidmem_ptr],si

mov sp,VM_STACK_PREP

pop es
pop ax

ret


printstr_task1:

push di
push si
push ax
push es

mov di,VIDEO_TEXT_ADDR >>4
mov es,di
mov di,[vidmem_ptr]
jmp gettext_test

output_test: stosw

gettext_test:
lodsb
test al,al
jne output_test
mov [vidmem_ptr],di

pop es
pop ax
pop si
pop di

ret

_prep_module2:

cld
cli

in al,0x92
or al,2
out 0x92,al


; cli
lgdt[Gdt32Ptr]
lidt[Idt32Ptr]
mov eax,cr0
or eax,1
mov cr0,eax
jmp 0x8:protectedMode

[bits 32]

protectedMode:
mov ax,0x10
; mov ax,
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
; mov esp,edx
mov esp,PM_MODE_STACK

mov ah,COLOR_ATTR_PSC
mov al,ah
mov esi, pm_str
call printstr_pm

;jmp $

prep_stage:


mov si,0
mov ds,si
push ds
push ds
push ds
push ds

push VM_STACK_SEG
push VM_STACK_OFS
push dword 1 << FLAGS_VM_CMP

push VM_CS_SEG
push vm_module

iret



printstr_pm:

push ds
; push esi
push eax
; push ebp


mov ebp,0
jmp .gettext

.output:


mov esi,[vidmem_ptr]
add esi,ebp
mov [es:esi],ax
add ebp,2


pop esi


.gettext:

mov al,[ds:si]
add si,1

push esi
test al,al
jnz .output


.stub

dec esi

shr ebp,1

add esi,ebp


mov [vidmem_ptr],esi
pop esi

pop eax

pop ds
ret

section .data

VIDEO_TEXT_ADDR EQU 0XB8000
COLOR_ATTR_PSC EQU 0X6A
COLOR_ATTR_BSC EQU 0X5F
PM_MODE_STACK EQU 0X80000
VM_STACK_SEG EQU 0X0000
VM_STACK_OFS EQU 0X0000
VM_CS_SEG EQU 0X0000
VM_STACK_PREP EQU 0xfffa
;VM_VIDMEM_STACK EQU 0X0000
FLAGS_VM_CMP EQU 17
FLAGS_CMP1 EQU 1
FLAGS_CMP_IF EQU 9



section .data

align 4
vidmem_ptr: dd VIDEO_TEXT_ADDR
VM_VIDMEM_STACK: dw 0X0000
pm_str: db 'protected mode string ',0
pm_str_length: equ $-pm_str
vm_str: db 'virtual',0
;VM_STACK_PREP: dw ?

align 4





Code: [Select]
[BITS 16]
;[ORG 0x7c00]

section .data


VIDEO_TEXT_ADDR EQU 0XB8000
COLOR_ATTR_PSC EQU 0X2F
COLOR_ATTR_BSC EQU 0X5F
PM_MODE_STACK EQU 0X80000
VM_STACK_SEG EQU 0X0000
VM_STACK_OFS EQU 0X0000
VM_CS_SEG EQU 0X0000
FLAGS_VM_CMP EQU 17
FLAGS_CMP1 EQU 1
FLAGS_IF_CMP EQU 9


section .text

_prep_module:
    xor ax,ax   
    mov ds,ax
    mov es,ax 
    mov ss,ax
    mov sp,0x7c00

DriveIdProp:
    mov [DriveId],dl
    mov ah,0x41
    mov bx,0x55aa
    int 0x13
    jc CheckProp
    cmp bx,0xaa55
    jne CheckProp

LoadProp:
;    mov si,ReadPacket
;    mov word[si],0x10
;    mov word[si+2],5
;    mov word[si+4],0x7e00
;    mov word[si+6],0
;    mov dword[si+8],1
;    mov dword[si+0xc],0
;    mov dl,[DriveId]
mov bx,0x0000_7E00
mov cl,2
mov ah,0x02
mov al,1
mov ch,0
mov dh,0
    int 0x13
    jc  ReadCheck

    mov dl,[DriveId]
    jmp 0x7e00

ReadCheck:
CheckProp:
;    mov ah,0x13
;    mov al,1
;    mov bx,0xa
;    xor dx,dx
;    mov bp,Message
;    mov cx,MessageLen
;    int 0x10

lea si,[Message]

Print:
lodsb
test al,al
jz .loop
mov ah,0x0E
mov bx,7
int 0x10
jmp Print


.loop:
    hlt   
    jmp .loop
   
DriveId:    db 0
Message:    db "We have an error in boot process"
MessageLen: equ $-Message
ReadPacket: times 16 db 0

;times (0x1be-($-$$)) db 0
;
;    db 80h
;    db 0,2,0
;    db 0f0h
;    db 0ffh,0ffh,0ffh
;    dd 1
;    dd (20*16*63-1)
;
;    times (16*3) db 0
;
;    db 0x55
;    db 0xaa

; ld -tText 0x7E00 stage1.o -o stage1.bin
   


Code: [Select]
FILES =boot.o printstr.o

all: boot.bin stage1.bin
dd if=boot.bin of=os.img bs=512 count=1 conv=notrunc
dd if=stage1.bin of=os.img bs=512 count=3 seek=1 conv=notrunc

boot.o: boot.asm
nasm -f elf -g -o boot.o boot.asm

printstr.o: printstr.asm
nasm -f elf -g -o printstr.o printstr.asm

stage1.o: stage1.asm
nasm -f elf -g stage1.asm -o stage1.o

stage1a.bin: stage1.asm
nasm -f bin stage1.asm -o stage1a.bin


boot.bin: $(FILES)
ld -T link.ld $(FILES) -o boot.bin

stage1.bin: stage1.o
ld -g -m elf_i386 -Ttext 0x7E00 stage1.o -o stage1.bin --oformat binary
clean:
rm -rf os.img
rm -rf boot.bin
rm -rf stage1.bin
rm -rf stage1.o
rm -rf stage1a.bin


« Last Edit: March 22, 2023, 08:25:02 PM by Deskman243 »