# # 16-bit real mode code for x86/PC-Computers, as executed on boot time and/or MS-DOS. # # as -32 -march=i486 -o egagembg.o egagembg.a # as -16 -march=i8086 -mabi=¿DOS? -o egagembg.obj egagembg.a # ... the standard version of «as« does not support, # look4 the FreeDOS Binutils package. # However ›man as‹ says: # When the ".arch" directive is used with -march, the ".arch" directive will take precedent. # .o, .a, .so, ›plainname‹° ... Executable and Linkable Format (ELF); Unix, Linux, Free/OpenBSD # .obj, .lib, .dll, .exe Portable Executable (PE) and Executable and Linkable Format (ELF) * # ° like ›wordpad‹, * DOS, OS/2, Windows, g`-«as«: https://www.gnu.org/software/binutils/ # ELF is documented in section 4 of the SV ABI, # System V, first Unix, System-V semaphores, see man-page.) # ABI = Application Binary Interface # COFF is documented as part of the PE spec # .code16 # .code16 and .code32 would be used to switch between generating 16-bit and 32-bit machine code # as possible with differently typed segment selectors in protected mode. Protected mode code # that was written for the 80286 will be 16bit and reside in 16-bit code segments. Newer machine # code for such a DOS Extender or Operating System will be 32-bit, like f.i. at OS/2 v2, # Version 1 of OS/2 was 16-bit 80286 protected mode and you can still use all the system calls # from once before in a newer program. # “operand size override prefixes“ are generated when accessing a 16-bit value from 32-bit mode or # vice-versa, AFAIK. # .code16, .code32: ... set the default size for code and data for all upcoming machine instructions # to be translated (There is not only a »operand size override prefix« (1-Byte), # but also an address override prefix, for a JMP, CALL, etc. into other code/text segments.). # .arch i386 .intel_syntax noprefix .arch i8086 # The .intel_syntax directive is a machine dependent feature, available from the 80386er on. # Trick here to use .intel_syntax for the elder 8086/8088 is to switch back to the elder machine model # but expect & experience that you can write your assembly instructions with Intel instead of AT&T syntax. # .code16 would not be needed from-at-a_now-on, because the 8086/8088 were 16bit only. #.section mytext, "M", @progbits, 16 # M would be a merged section, diffrent .a files can contribute to it, # there are also subsections, read the GAS (GNU Assembler »as«) Doku. for this. # real mode segments must be 16-Byte aligned, remember the Segment Address is shifted by 4 bit, # i.e. multiplied by 16 before the Offset is added, 0xB800:0000 # The .text section gives standard attributes And is the usual or most times only code segment. # .text is a system given name, user-specified names can not be called ".text". # A @nobits segment would just be an allocation entity in the object (.o, intermediate file before # linking) or elf-file (executable as /bin/csh), there is no predefinged data or code then. #.set comfile, 1 .balign 16 .section .text .ifdef comfile .print "compiling as .com file, starting at address 100h" .ORG 0x100 .endif .global _start # If You used this assembly file not as direct-inline for a Grub/Lilo-ChainExec or to write # at floppy/hard disk address 00000, but to create an OS/2, DOS or Unix executable, then # there is the requirement to declare a globally known starting symbol where the program # execution of you DOS/Win/OS_2-.exe should start after the operating system has initialized # things to run within its own fittichen★/environment. _start: mov %ax, 0xB800 mov %es, %ax xor %di, %di mov %cx, 80*25 mov %ax, 177+(7+16)*256 repne StosW .ifndef comfile spinloop: hlt # halt status of the CPU: wait until an interrupt comes (that isn`t masked/blocked) # ... or until the power button of your computer is pressed. jmp spinloop; # There is no operating system running, so waiting until the power button of the computer # shall be the only option here. What else to do, make crash? ret # Programs like gdb, the gnu debugger panic if your last command is not something like that, # thinking this can´t be the main program. Ret would return from the main program which # in C +stdlib/-startupfiles is nothing more than a usual procedure called from some other # OS and std-lib initialization code. .else mov %ax, 0x4C00 # AH=4C quit program, AL=00 errorlevel the program returns, csh: »echo $?« int 0x21 # software interrupt, that is used to make MS-DOS system calls. .endif .end # ================================================================================== # ---------------------------------------------------------------------------------- # everything from here on is ignored!!!, and may it not be written as a comment !! # saved comments section: ★ Fittich:de = pinion feathers:en, what a Glucke:de sitting_hen:en has to keep its young warm and shielded. Was die Mutterhenne tut nennt man zé Theuthsch auch »hudern«. For instructions how to compile and make this file work look at the end of the file:: : tail -n25 egagembg.s ./runme; gdb -q egagembgd -x commands.gdb ./runme; gdb -q egagembgd -ex "break 62" -ex "layout regs" -ex "run;" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DosBox: Z:\> CLS ... clear the screen Z:\> mount h ~/projects Drive H is mounted as local directory /home/usr/projects Z:\> h: H:\> dir /w /p/ ... /w ~ wide listing, more than one file entry per line ... /p ~ pause, ask for a key-press at every result page, shorter than »dir /w | more« H:\> cd txtb800 ... no difference between small and capital letters for directories as well as files ... a file or directory name can be up to eight characters long, plus optional three characters after the dot, usually used for the file extension, so DOS uses .htm instead of .html, and: .jpg instead of .jpeg H:\> dir *.com H:\> egagem.com DosBox and the keyboard: default keyboard is US-american, the same as you will have at the Grub- or Lilo Bootloader‼, a nice oportunity to practice finding the most common special character keys, your language-local keyboard usually has them on a very different key! „~“ ... the very upper left key directly below [ESC], it´s the tilde. (de,auch:Schlangl) „:” ... the colon: middle letter key row, the first non-letter key. „/” ... slash, as used instead of minus under Unix to state optional program arguments to an executable bottom letter key row, the symbol key directly before the shift key (2produce capital instead of small letters, de:Umschalttaste) „*“ ... the asterisk or star, [Shift]-[8], dos programs and command.com directives usually interprete it as wildcard, here: all files (and dirs) with extension “.com”. The one-character wildcard is „?“, same position as the slash “/”, very often used is /? at DOS instead of -h or --help under Unix. Programs proted from Unix may still use -x. Note that under Linux the shell (bash, csh) is the program that expands *.dat, not like with command.com/MSDOS where the invoked program, like f.i. xcopy, type does that. note: [Y] and [Z] are swapped between the German and US/English keyboard »» /usr/share/X11/xkb differs between QWERTY and QWERTZ keyboards. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ How to inspect object files: > objdump -h egagembg.o egagembg.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000013 00000000 00000000 00000040 2**4 1 .data 00000000 00000000 00000000 00000053 2**0 ... > objdump -j .text -sd -Mi8086 egagembg.o egagembg.o: file format elf32-i386 Contents of section .text: 0000 b800b88e c031ffb9 d007b8b1 17f2abf4 .....1.......... 0010 ebfdc3 ... Disassembly of section .text: 00000000 <_start>: 0: b8 00 b8 mov $0xb800,%ax 3: 8e c0 mov %ax,%es ... # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ How it should/shall have worked to make a floppy or disk image of the 19-Byte clear screen code of egagem.bin. Note that for egagem.com the cursor disappears, the DOSBox screen output functions don´t expect that the text screen disappears, so press a few times [Return] to scroll it away. read:: http://wiki.osdev.org/MBR_(x86) cp egagembg.bin egagembg.img dd if=WarpBootElm-1.img bs=19 skip=1 of=egagembg.img seek=11 77607+1 Datensätze ein 77607+1 Datensätze aus 1474541 Bytes (1,5 MB, 1,4 MiB) kopiert, 0,211621 s, 7,0 MB/s > file egagembg.img egagembg.img: DOS floppy 1440k > od -An -txC egagembg.bin | head b8 00 b8 8e c0 31 ff b9 d0 07 b8 b1 17 f2 ab f4 eb fd c3 > od -An -txC egagembg.img | head -n3 b8 00 b8 8e c0 31 ff b9 d0 07 b8 b1 17 f2 ab f4 eb fd c3 40 0b f0 09 00 12 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 a3 4e 4f 20 4e 41 > sudo mount -o loop egagembg.img tmp/ mount: /home/elm/projects/txtb800/tmp: Falscher Dateisystemtyp, ungültige Optionen, der Superblock von /dev/loop0 ist beschädigt, fehlende Kodierungsseite oder ein anderer Fehler. ... according to wiki.osdev.org that must have worked(!) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ as --32 -g -o egagembg.o egagembg.s; # 16bit and 32bit assembly are somewhat similar, apart from the length of inline values like # $800 and [more fancy] addressing modes the same command can be read as 32bit or 16bit. ld -m elf_i386 --strip-discarded egagembg.o -o egagembgd # would produce a Linux executable; that can not be 16bit, though. objdump -Mi8086 -d egagembg[.o] or: objdump -Mdata16,code16 -d egagembg[.o] objcopy --target objcopy -j .text -O binary egagembg.o egagembg.bin file egagembg.bin -> data objdump -j .text -sd -Mi8086 egagembg.o od -An -txC egagembg.bin qemu-system-i386 -machine isapc -no-fd-bootchk -fda egagembg.bin & as --32 -g -defsym comfile=1 -o egagem.o egagembg.s; # -g includes debugging symbols for gdb, the GNU Debugger objcopy -O pe-i386 egagem.o egagem.obj ld -m i386pe --no-strip-discarded egagem.obj -o egagem.com # .com file are a DOS & CPM special feature, programs that only comprise 64K of memory. # It is guaranteed that a .com is a DOS program and not for OS/2 or Windows. ... now use DosBox to run the program as described above iff egagem.com waited three seconds, you could start it from wineconsole as well. # .exe file needed own stack and data segment # also: as --target-help ld --target-help