From: Mike Gonta on
On May 4, 2:21 pm, s_dubrov...(a)yahoo.com wrote:

> ..
> start:
>   xor ax, ax
>   mov ds, ax
>   mov es, ax
>   ;mov ss, ax
>   ;mov esp, 7C00h
>
>   mov cx, 2                     ; sector 2
>   xor dh, dh                    ; side 0
>   mov bx, LOAD_ADDRESS
> ..
> .. without the stack being setup properly, I doubt it'll boot from
> floppy in any of my systems.  The default stack at bootstrap is at the
> top of the IVT, 0000:0400h in most of the rombios's I've been able to
> check, mostly dell's, phoenix bios's.  On reboot, there is another
> location, usually, in the same area.  These default stack locations
> are too small to depend on.

This is a good observation, although I don't believe it to be the
cause of the problem.
Note that before I commented out the stack initialization the full 32
bit stack pointer register is being initialized in real mode even
though only the lower 16 bits are used.
The reason for this is that when the payload returns to the boot
sector it is in 32 bit protected mode and the stack pointer is 32 bit.
This will be fine as long as the upper 16 bits are 0, in which case
the real mode segment:offset address will be the same
representation as the flat 32 bit address. However if the upper half
is something other than 0, or the BIOS stack is located in a
low memory segment other than 0, the return address will not be the
same.

I've updated the boot sector code to include the stack pointer
initialization.


http://mikegonta.com/pdBIOS32

Mike Gonta
look and see - many look but few see
From: s_dubrovich on
On May 4, 8:39 pm, Mike Gonta <mikego...(a)gmail.com> wrote:
> On May 4, 2:21 pm, s_dubrov...(a)yahoo.com wrote:
>
>
>
>
>
> > ..
> > start:
> >   xor ax, ax
> >   mov ds, ax
> >   mov es, ax
> >   ;mov ss, ax
> >   ;mov esp, 7C00h
>
> >   mov cx, 2                     ; sector 2
> >   xor dh, dh                    ; side 0
> >   mov bx, LOAD_ADDRESS
> > ..
> > .. without the stack being setup properly, I doubt it'll boot from
> > floppy in any of my systems.  The default stack at bootstrap is at the
> > top of the IVT, 0000:0400h in most of the rombios's I've been able to
> > check, mostly dell's, phoenix bios's.  On reboot, there is another
> > location, usually, in the same area.  These default stack locations
> > are too small to depend on.
>
> This is a good observation, although I don't believe it to be the
> cause of the problem.
> Note that before I commented out the stack initialization the full 32
> bit stack pointer register is being initialized in real mode even
> though only the lower 16 bits are used.
> The reason for this is that when the payload returns to the boot
> sector it is in 32 bit protected mode and the stack pointer is 32 bit.
> This will be fine as long as the upper 16 bits are 0, in which case
> the real mode segment:offset address will be the same
> representation as the flat 32 bit address. However if the upper half
> is something other than 0, or the BIOS stack is located in a
> low memory segment other than 0, the return address will not be the
> same.
>
> I've updated the boot sector code to include the stack pointer
> initialization.
>

Success! works fine.

A:\>cpuid
GenuineIntel
APIC not present

Steve

> http://mikegonta.com/pdBIOS32
>
> Mike Gonta
> look and see - many look but few see- Hide quoted text -
>
> - Show quoted text -

From: Rod Pemberton on
<s_dubrovich(a)yahoo.com> wrote in message
news:ce3fece6-ad1d-4074-be02-10ba276afc5f(a)k41g2000yqb.googlegroups.com...
> On May 4, 8:39 pm, Mike Gonta <mikego...(a)gmail.com> wrote:
> > On May 4, 2:21 pm, s_dubrov...(a)yahoo.com wrote:
> >
> > > .. without the stack being setup properly, I doubt it'll boot from
> > > floppy in any of my systems. The default stack at bootstrap is at the
> > > top of the IVT, 0000:0400h in most of the rombios's I've been able to
> > > check, mostly dell's, phoenix bios's.
> > [...]
> >
> > I've updated the boot sector code to include the stack pointer
> > initialization.
> >
>
> Success! works fine.
>

Hmm... Questions for Mike and Steve:

Mike, how much stack space does pdBIOS32 use before setting up ss and/or
(e)sp elsewhere (e.g., rm2pm)?

Steve, do you know if the Phoenix BIOS' and Dell BIOS use higher interrupt
numbers in their BIOS?

The reason I ask is because even if the IVT is set to 0000:0400h using a few
stack items shouldn't blow out the IVT. Right? From my notes, interrupts
above 0x7A aren't used anymore. There were some higher interrupts used for
BASIC ROM's PC's had them... Isn't that correct? If so, that means there
should be about 536 bytes (out of 1024) in the upper IVT that can be used
for a stack without issues...


Rod Pemberton
PS. Yes, booted on a newer machine...


From: s_dubrovich on
On May 5, 7:06 am, "Rod Pemberton" <do_not_h...(a)havenone.cmm> wrote:
> <s_dubrov...(a)yahoo.com> wrote in message
>
> news:ce3fece6-ad1d-4074-be02-10ba276afc5f(a)k41g2000yqb.googlegroups.com...
>
> > On May 4, 8:39 pm, Mike Gonta <mikego...(a)gmail.com> wrote:
> > > On May 4, 2:21 pm, s_dubrov...(a)yahoo.com wrote:
>
> > > > .. without the stack being setup properly, I doubt it'll boot from
> > > > floppy in any of my systems. The default stack at bootstrap is at the
> > > > top of the IVT, 0000:0400h in most of the rombios's I've been able to
> > > > check, mostly dell's, phoenix bios's.
> > > [...]
>
> > > I've updated the boot sector code to include the stack pointer
> > > initialization.
>
> > Success! works fine.
>
> Hmm...  Questions for Mike and Steve:
>
> Mike, how much stack space does pdBIOS32 use before setting up ss and/or
> (e)sp elsewhere (e.g., rm2pm)?
>
> Steve, do you know if the Phoenix BIOS' and Dell BIOS use higher interrupt
> numbers in their BIOS?
>
I don't know. The one way to tell is with a diagnotic bootstrap which
saves the register values on entry and can dump memory. I do know,
and can say that the region from 03C0h..03FFh is not null after
booting a win98 bootable diskette and running a program which dumps
memory. The top three words on the stack are:

0246h -flags
F000h -segm
5E6Ch -offs

> The reason I ask is because even if the IVT is set to 0000:0400h using a few
> stack items shouldn't blow out the IVT.  Right?

Right? -as in you were right that you had the green light, but you
still crashed?

>  From my notes, interrupts
> above 0x7A aren't used anymore.  There were some higher interrupts used for
> BASIC ROM's PC's had them...  Isn't that correct?

Well, there is the notion of the time context of the enviornment, that
is why I said 'diagnostic bootstrap' above.

There are some packet driver handlers that reside in the int 78h..7Fh
area. Linux at int 80h. CP/M-86 at int 0E0h..0E6h. (According to DRI
doc's, they say Intel reserved int E0h for them. This is vintage IBM
PC.) IBM's Rom Basic used from int 80h..DFh. -Only the IBM Rom Basic
would be in context at that point in the POST, except I think the
286's were the last to have basic in rom, hmm not to sure about that.

No, this issue pertains to something else, probably a NMI handler
which commands this area for its stack. Maybe the bios coder had your
thought, 'well it should be free'. 8)

> If so, that means there
> should be about 536 bytes (out of 1024) in the upper IVT that can be used
> for a stack without issues...
>

Sounds reasonable to me, except results speak differently.

Steve

> Rod Pemberton
> PS.  Yes, booted on a newer machine...

From: s_dubrovich on
On May 2, 3:12 pm, Mike Gonta <mikego...(a)gmail.com> wrote:
> pdBIOS32 is a public domain 32 bit protected mode BIOS extender.
> It uses a simple software mode switching technique, is less than 2k
> and does
> not write to or change the hard drive or the BIOS firmware.
> pdBIOS32 like the motherboard BIOS is file system independent.
> It is currently distributed as a fat12 floppy disk image.
> This image will boot and run from either a real or virtual floppy
> disk, also
> from a USB flash drive as either floppy disk or hard drive BIOS
> configuration.
> All source code is include and is written in 100% pure assembly
> language and
> can be assembled with either FASM or NASM.
>
> Original code by Mike Gonta, Public Domain 2010
>
> http://mikegonta.com/pdBIOS32
>
> Mike Gonta
> look and see - many look but few see

I've written alittle ditty to check Big Memory Services Int 15h,
AH=E801,E881, and E820. E801 subroutine works, but E820 doesn't (yet
the machine supports it). So my question is if pdBIOS32 has support
for it (I'm unsure, it seems to me that all the Int xxh are reflected
back to rm, and so it should work.) Anyway, here it is for trial..

[MAP ALL BIGMEMCK.MAP]
;;--------------------------------------------------------60
;; Program Name: BIGMEMCK.NSM By: s_dubrovich(a)yahoo.com
;; ?(C): COPYLEFT -spin, fold, mungicate it, just rename it.
;; Last: 09-May-10 05:10:01 PM
;; Prev: 03 NOV 2005 was E820.NSM
;; Init: 27 SEP 2005
;; Vers: 2r4
;; Desc: SMAP memory map Fn. Int15h AH=E8h AL=01h,20h,80h
;; Note: For pdBIOS32
;;--------------------------------------------------------60
;; NASM version 0.98.38 compiled on Sep 12 2003
;; NASM -@BIGMEMCK.MAK
;; BIGMEMCK.MAK contains:
;; -f bin
;; -O3
;; -l BIGMEMCK.lst
;; -o BIGMEMCK.bin
;; BIGMEMCK.nsm
;;--------------------------------------------------------60

struc mm_ent
.base resq 1
.len resq 1
.type resd 1
endstruc

;;--------------------------------------------------------60
;; M A I N
;;--------------------------------------------------------60
[SECTION .cseg vstart=100000h]
use32

main:
mov esp, stktop
call E801
call E881
call E820

;;---exit program---
alldone:
xor eax, eax
int 16h
int 19h

;;--------------------------------------------------------60
;; D A T A
;;--------------------------------------------------------60
[SECTION .dseg vfollows=.cseg]
Date_Mod db '09 May 2010 v. 2r1 ',0
Signon db '*** Testing INT 15h AX=E820h Big Memory '
db 'Services - System Memory Map ***',0
Fn_na db 'Sorry, unsupported Fn, Int 15h AX=E820',0
Mbase db ' <-Base ',0
Mlen db ' <-Length ',0
Mtype db ' <-Type ',0
Mtypes db ' Types: 1=Avail. to OS, 2=Not Avail., '
db '3=ACPI Avail. to OS, 4=NVS Not Avail.',0
;;
Fn_nak_E801 db 'Sorry, unsupported Fn, Int 15h AX=E801',0
Fn_ack_E801 db ' Supported Fn, Int 15h AX=E801',0
;;
Fn_nak_E881 db 'Sorry, unsupported Fn, Int 15h AX=E881',0
Fn_ack_E881 db ' Supported Fn, Int 15h AX=E881',0
;;
strEAX db 'EAX=',0
strEBX db 'EBX=',0
strECX db 'ECX=',0
strEDX db 'EDX=',0

valEAX dd 0
valEBX dd 0
valECX dd 0
valEDX dd 0

;;----EO DSeg--------
;;--EO FNL--
;; # ref sept 27 2005 comp.lang.asm.x86 #
;;Dunno if it's correct - here's what I've got. This uses dos - change
the
;;display function for bios...
;;Best,
;;Frank Kotler
;;--------------------------------------------------------60
;;----Subroutines----
;;--------------------------------------------------------60
;;section .text
;; Usage Notes:
;; - cp/m86 Fn 9 prtstr changes AX,BX,CX,DX,ES
;; - Call E820 w/ EBX continuation val=0 initially
;; -ES:DI Addr of Addr Range Descriptor
;; -ECX length of Addr Range Descriptor =>20bytes
;; -EDX 'SMAP' signature
;; On Ret from this Call - CF=0 means E820 supported
;; -EAX = 'SMAP' str
;; -ES:DI same as entry
;; -ECX = length of actual reported info bytes
;; -EBX = next continuation value, else = 0
;; -Next continuation value required for next call
;;
;;--------------------------------------------------------60
[SECTION .cseg]

;;--------------------------------------------------------60
;; Int 15h Big Memory Services ck Fn AL`01h
E801:
mov eax, 0E801h
int 15h
jc err_E801

mov [valEAX], eax
mov [valEBX], ebx
mov [valECX], ecx
mov [valEDX], edx

mov edx, Fn_ack_E801
call putstr
call newline

call dmp4regs

RET

err_E801:
mov edx, Fn_nak_E801
call putstr
call newline
RET

;;--------------------------------------------------------60
;; Int 15h Big Memory Services ck Fn AL`81h
E881:
mov eax, 0E881h
int 15h
jc err_E881

mov [valEAX], eax
mov [valEBX], ebx
mov [valECX], ecx
mov [valEDX], edx

mov edx, Fn_ack_E881
call putstr
call newline

call dmp4regs

RET

err_E881:
mov edx, Fn_nak_E881
call putstr
call newline
RET

;;--------------------------------------------------------60
;; Int 15h Big Memory Services ck Fn AL`20h
E820:
mov edx, Signon
call putstr
call newline

clc ;; just in case..
mov edi, buffer ;; offset re dseg
xor ebx, ebx
xor esi, esi ; counter
..top:
mov eax, 0E820h
mov edx, 534D4150h ; 'SMAP'
mov ecx, 20 ;; length of packet
int 15h
jc error
inc esi ; bump counter
add edi, ecx
or ebx, ebx ;; test continuation value=0
jz done
jmp short .top ;; loop, building map table
done:
mov ecx, esi ; count
mov esi, buffer

show: ;;retrieve values from table & print them.
mov eax, [esi + mm_ent.base + 4]
call showeax
call separator
mov eax, [esi + mm_ent.base]
call showeax
mov edx, Mbase
call putstr

mov eax, [esi + mm_ent.len + 4]
call showeax
call separator
mov eax, [esi + mm_ent.len]
call showeax
mov edx, Mlen
call putstr

mov eax, [esi + mm_ent.type]
call showeax
mov edx, Mtype
call putstr
call newline

add esi, mm_ent_size
loop show
;;---eoshow---

mov edx, Mtypes
call putstr

jmp exit

error: ;; report unsupported Fn
mov edx, Fn_na
call putstr
call newline

exit:
RET

;;--------------------------------------------------------60
;; U t i l i t y F n ' s
;;--------------------------------------------------------60
dmp4regs:

mov edx, strEAX
call putstr
mov eax, [valEAX]
call showeax
call virtbar

mov edx, strEBX
call putstr
mov eax, [valEBX]
call showeax
call virtbar

mov edx, strECX
call putstr
mov eax, [valECX]
call showeax
call virtbar

mov edx, strEDX
call putstr
mov eax, [valEDX]
call showeax
call newline
call newline

RET
;------------------
showeax:
push cx
mov cx, 8
..top:
rol eax, 4
push eax
and al, 0Fh
cmp al, 0Ah
sbb al, 69h
das
call putc
pop eax
loop .top
pop cx
RET
;-------------------
separator:
push ax
mov al, 27h
call putc
pop ax
RET
;-------------------
virtbar:
push ax
mov al, 7Ch
call putc
pop ax
RET
;-------------------
newline:
push ax
mov al, 13
call putc
mov al, 10
call putc
pop ax
RET
;--------------------
tab:
push ax
mov al,9
call putc
pop ax
RET
;--------------------
putc: ;; chr arrives in AL
pusha

mov ah, 0Eh ;; Fn tty
mov ebx, 0 ;; BH pg no
int 10h

popa
RET
;------------------
putstr: ;;Str Offset supplied in EDX
mov al, [edx]
cmp al, 0
jz endstr
call putc
inc edx
jmp short putstr
endstr:
RET
;; -= Last but not Least, align =-
align 16, db 0
;;--------------------------------------------------------60
;------------------
[SECTION .dseg]
buffer: TIMES 200h db 0
stkbase: TIMES 80h dw 0
stktop:
;;--------------------------------------------------------60
;;--eof--
;;--------------------------------------------------------60