;   dual.asm   --- by Vince Weaver -- 28 March 2001
;		      vince@deater.net
;   assembled with nasm [ "nasm -o dual.com dual.asm"]
;   on linux chmod +x dual.com


; THE ELF HEADER for LINUX

%push elf
BITS 32
%define %$origin	0x08048000
	org     %$origin
	db      0x7F, 'ELF'             ; e_ident
	db      1, 1, 1
        times 9 db      0
	dw 2				; e_type
        dw      3                       ; e_machine
	dd      1                       ; e_version
        dd      START 			; e_entry
        dd      phdr - $$             ; e_phoff
        dd      0                       ; e_shoff
	dd      0                       ; e_flags
	dw      0x34 ; e_ehsize
        dw      0x20			; e_phentsize
phdr:         dw      1                       ; e_phnum       ; p_type
        dw      0                       ; e_shentsize
	dw      0                       ; e_shnum ; p_offset
	dw      0			 ; e_shstrndx
	dd      $$			; p_vaddr
        dd      $$                                      ; p_paddr
	dd      _elf_filesz ; p_filesz
	dd      _elf_memsz                              ; p_memsz
	dd      _elf_phdr_flags
	dd      0x1000; p_align
_text:
	section .text
	


; the DOS stuff.
; the 0x7f,"ELF" header translates to "JG 0x147" so we cheat, because
; 0x47 [plus the 0x100 .COM offset] takes us about 3 bytes back in
; the ELF header.  Luckily those parts of the header are 
; harmless ADD commands

BITS 16
;=========================================
;Print Opening Info
;=========================================
	nop
	nop			; pad with nops so we are on
	nop			; an instruction boundary
	nop
	mov ah,0x09		; Bios string command
	mov dx,0x15B		; magic number pointing to Hello World
	int 0x21		; print string 1
	mov ah,0x4c		; exit to DOS
	int 0x21

hello_world_d	db	'Hello World!$'

BITS 32

START:

	mov eax,4		; Linux Write Syscall
	mov ebx,1		; stdout
	mov ecx,hello_world_l	; string
	mov edx,16		; string length
	int 0x80		; do syscall

	xor ebx,ebx
	mov eax,1		; exit syscall
	int 0x80

hello_world_l	db	'Hello World!',10,13,0

; end Linux stuff
_elf_filesz     equ     $ - $$

_elf_memsz      equ     $ - 0x08048000

_elf_phdr_flags equ     7

