GithubHelp home page GithubHelp logo

windowsnt / asm Goto Github PK

View Code? Open in Web Editor NEW
224.0 29.0 47.0 8 MB

Assembly Tutorial for DOS

Assembly 12.23% Batchfile 0.18% PowerShell 0.55% HTML 36.79% Makefile 2.66% C 47.09% Prolog 0.31% IDL 0.08% C++ 0.11%
assembly assembler low-level multicore assembly-tutorial system-programming protected-mode x64dbg debugging virtual-machine

asm's Introduction

Assembly Manual

Welcome to my assembly tutorials.

Articles:

Older Articles:

At the moment, the first part is implemented (Real/Protected/Long mode), the Protected Mode Virtualization (working in Bochs), the third part (test SIPI multicore, working on Bochs and VMWare) and the fourth part finished (DMMI). More to follow soon.

Instructions

  1. Edit build.bat to specify flat assembler (FASM) path.
  2. Edit startbochs.bat, startvmware.bat and startvbox.bat to locate the executables of these applications. Bochs is included in the repository.

Build and run, it will automatically start bochs/vmware/virtualbox with the included FreeDOS image. It will create a CD-ROM as D: and you can run it from d:\entry.exe, by default it is automatically run (autoexec.bat)

3rd Party Apps included

  1. DOS32A - http://dos32a.narechk.net/index_en.html
  2. 386SWAT - http://www.sudleyplace.com/swat/
  3. UDIS86 - http://udis86.sourceforge.net/ , including an open watcom C project that is used by VDEBUG and MDEBUG
  4. DPMIONE - http://www.sudleyplace.com/dpmione/
  5. QLINK - http://www.sudleyplace.com/qlink/

Tests performed

  1. Real mode test
  2. Protected mode test with or without paging
  3. Long mode test with paging and PAE
  4. Real mode thread calling
  5. Real mode thread called from protected mode
  6. Real mode thread called from long mode
  7. Protected mode thread called from real mode
  8. Long mode thread called from real mode
  9. VMX is there
  10. Spawn a Virtual Machine in Unrestricted guest mode. Paged Protected Mode guest also there.
  11. Entry /r which installs as TSR the DMMI services
  12. DPMI startup example taken from https://board.flatassembler.net/topic.php?t=7122
  13. DMMIC app runs which demonstrates DMMI, launching real mode, protected mode, long mode and virtualized protected mode threads
  14. DOS32A loads a linear executable created with FASM
  15. VDEBUG Virtualized Debugger (Not fully implemented yet)
  16. MDEBUG Multicore Debugger (Not fully implemented yet)
  17. SWITCHER multitasker (Not fully implemented yet)

DMMI

I've called it DOS Multicore Mode Interface. It is a driver which helps you develop 32 and 64 bit multicore applications for DOS, using int 0xF0. This interrupt is accessible from both real, protected and long mode. Put the function number to AH.

To check for existence, check the vector for INT 0xF0. It should not be pointing to 0 or to an IRET, ES:BX+2 should point to a dword 'dmmi'.

Int 0xF0 provides the following functions to all modes (real, protected, long)

  1. AH = 0, verify existence. Return values, AX = 0xFACE if the driver exists, DL = total CPUs, DH = virtualization support (0 none, 1 PM only, 2 Unrestricted guest). This function is accessible from real, protected and long mode.
  2. AH = 1, begin thread. BL is the CPU index (1 to max-1). The function creates a thread, depending on AL:
    • 0, begin (un)real mode thread. ES:DX = new thread seg:ofs. The thread is run with FS capable of unreal mode addressing, must use RETF to return.
    • 1, begin 32 bit protected mode thread. EDX is the linear address of the thread. The thread must return with RETF.
    • 2, begin 64 bit long mode thread. EDX holds the linear address of the code to start in 64-bit long mode. The thread must terminate with RET.
    • 3, begin virtualized thread. BH contains the virtualization mode (1 for unrestricted guest real mode thread, and 2 for protected mode), and EDX the virtualized linear stack (or in seg:ofs format if unrestricted guest). The thread must return with RETF or VMCALL.
  3. AH = 5, mutex functions. This function is accessible from all modes.
    • AL = 0 => initialize mutex to ES:DI (real) , EDI linear (protected), RDI linear (long).
    • AL = 1 => Lock mutex
    • AL = 2 => Unlock mutex
    • AL = 3 => Wait for mutex
  4. AH = 4, execute real mode interrupt. This function is accessible from all modes. AL is the interrupt number, BP holds the AX value and BX,CX,DX,SI,DI are passed to the interrupt. DS and ES are loaded from the high 16 bits of ESI and EDI.
  5. AH = 9, Switch To Mode.
    • From real mode: AL = 0 (enter unreal), AL = 2 (enter long, ECX = linear address to start. Code must set IDT found at [rax] on entry)
    • From long mode: AL = 0, go back to real, ECX = linear.

Now, if you have more than one CPU, your DOS applications/games can now directly access all 2^64 of memory and all your CPUs, while still being able to call DOS directly.

In order to avoid calling int 0xF0 directly from assembly and to make the driver compatible with higher level languages, an INT 0x21 redirection handler is installed. If you call INT 0x21 from the main thread, INT 0x21 is executed directly. If you call INT 0x21 from protected or long mode thread, then INT 0xF0 function AX = 0x0421 is executed automatically.

Virtualization Debugger

Debugging protected or long mode under DOS is next to impossible. I am now trying to create a simple DEBUG enhancement, called VDEBUG, which should be able to debug any DOS app in virtualization.

Compile it with config.asm VDEBUG = 1. This app does the following:

  • Load the debugee (int 0x21, function 0x4B01)
  • Enter long mode (int 0xf0, function 0x0902)
  • Prepare virtualization structures (int 0xf0, function 0x0801)
  • Launch an unrestricted guest VM
  • In the VM, set the trap flag so each opcode causes a VMEXIT.
  • Jump to the entry point of the debugee
  • When target process calls int 0x21 function 0x4C to terminate, control returns to the command next to the int 0x21 function 0x4B01 call. Check there if under virtual machine. If so, do VMCALL to exit.
  • Go back to real mode and exit.
  • At the moment, the implemented functions are:
    • r - (registers) - shows Control, General, Segment regs, Dissassembly and bytes using UDIS86
    • g - (go) - runs program
    • t - (trace) - traces commands
    • h - (help) - shows help
    • q - (quit) - quits

Multicore Debugger

Debugging protected or long mode under DOS is next to impossible (again). I am now trying to create a simple DEBUG enhancement, called MDEBUG, which should be able to debug any DOS app from another CPU core.

Compile it with config.asm MDEBUG = 1. This app should perform the following:

  • Jump to another core
  • Load the debugee (int 0x21, function 0x4B01)
  • Set the trap flag
  • On exception, HLT the first processor then go to the MDEBUG processor
  • On resume, send resume IPI to the first processor

This project is not yet created, but I hope that it will be here soon!

Switcher

Switcher is a DMMI client that is able to do multitasking in DOS using multiple cores and virtualization. More to follow soon!

asm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asm's Issues

[issue] When running entry.exe in Bochs, it keeps saying "No pci device with classcode ?? found at index 0 and keeps rebooting.

01643007347i[BIOS ] SMBIOS table addr=0x000f9ea0
01643009323i[BIOS ] ACPI tables: RSDP addr=0x000f9fd0 ACPI DATA addr=0x01ff0000 size=0xff8
01643012760i[BIOS ] Firmware waking vector 0x1ff00cc
01643015387i[PCI ] i440FX PMC write to PAM register 59 (TLB Flush)
01643016003i[BIOS ] bios_table_cur_addr: 0x000f9ff4
VGABios $Id: vgabios.c 226 2020-01-02 21:36:23Z vruppert $
01643145064i[BXVGA ] VBE known Display Interface b0c0
01643145083i[BXVGA ] VBE known Display Interface b0c5
01643147727i[VBIOS ] VBE Bios $Id: vbe.c 228 2020-01-02 23:09:02Z vruppert $
01646888198i[BIOS ] IDE time out
01667600545i[BIOS ] Booting from 0000:7c00
01674516561i[BIOS ] int13_harddisk: function 00, unmapped device for ELDL=80
01674522096i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
01696387547i[BIOS ] no PCI device with class code 0x010102 found at index 0
01696401463i[BIOS ] no PCI device with class code 0x010100 found at index 0
01696415320i[BIOS ] no PCI device with class code 0x010106 found at index 0
01696429175i[BIOS ] no PCI device with class code 0x010104 found at index 0
01696443033i[BIOS ] no PCI device with class code 0x01010a found at index 0
01696456888i[BIOS ] no PCI device with class code 0x010108 found at index 0
01696470746i[BIOS ] no PCI device with class code 0x01010e found at index 0
01696484602i[BIOS ] no PCI device with class code 0x01010c found at index 0
01696498459i[BIOS ] no PCI device with class code 0x010112 found at index 0
01696512314i[BIOS ] no PCI device with class code 0x010110 found at index 0
01696526171i[BIOS ] no PCI device with class code 0x010116 found at index 0
01696540026i[BIOS ] no PCI device with class code 0x010114 found at index 0
01696553884i[BIOS ] no PCI device with class code 0x01011a found at index 0
01696567739i[BIOS ] no PCI device with class code 0x010118 found at index 0
01696581597i[BIOS ] no PCI device with class code 0x01011e found at index 0
01696595453i[BIOS ] no PCI device with class code 0x01011c found at index 0
01696609310i[BIOS ] no PCI device with class code 0x010122 found at index 0
01696623226i[BIOS ] no PCI device with class code 0x010120 found at index 0
01696637083i[BIOS ] no PCI device with class code 0x010126 found at index 0
01696650938i[BIOS ] no PCI device with class code 0x010124 found at index 0
01696664796i[BIOS ] no PCI device with class code 0x01012a found at index 0
01696678651i[BIOS ] no PCI device with class code 0x010128 found at index 0
01696692509i[BIOS ] no PCI device with class code 0x01012e found at index 0
01696706365i[BIOS ] no PCI device with class code 0x01012c found at index 0
01696720222i[BIOS ] no PCI device with class code 0x010132 found at index 0
01696734077i[BIOS ] no PCI device with class code 0x010130 found at index 0
01696747934i[BIOS ] no PCI device with class code 0x010136 found at index 0
01696761789i[BIOS ] no PCI device with class code 0x010134 found at index 0
01696775647i[BIOS ] no PCI device with class code 0x01013a found at index 0
01696789502i[BIOS ] no PCI device with class code 0x010138 found at index 0
01696803360i[BIOS ] no PCI device with class code 0x01013e found at index 0
01696817216i[BIOS ] no PCI device with class code 0x01013c found at index 0
01696831073i[BIOS ] no PCI device with class code 0x010142 found at index 0
01696845002i[BIOS ] no PCI device with class code 0x010140 found at index 0
01696858846i[BIOS ] no PCI device with class code 0x010146 found at index 0
01696872701i[BIOS ] no PCI device with class code 0x010144 found at index 0
01696886559i[BIOS ] no PCI device with class code 0x01014a found at index 0
01696900414i[BIOS ] no PCI device with class code 0x010148 found at index 0
01696914272i[BIOS ] no PCI device with class code 0x01014e found at index 0
01696928128i[BIOS ] no PCI device with class code 0x01014c found at index 0
01696942001i[BIOS ] no PCI device with class code 0x010152 found at index 0
01696955840i[BIOS ] no PCI device with class code 0x010150 found at index 0
01696969697i[BIOS ] no PCI device with class code 0x010156 found at index 0
01696983552i[BIOS ] no PCI device with class code 0x010154 found at index 0
01696997410i[BIOS ] no PCI device with class code 0x01015a found at index 0
01697011265i[BIOS ] no PCI device with class code 0x010158 found at index 0
01697025123i[BIOS ] no PCI device with class code 0x01015e found at index 0
01697039003i[BIOS ] no PCI device with class code 0x01015c found at index 0
01697052836i[BIOS ] no PCI device with class code 0x010162 found at index 0
01697066752i[BIOS ] no PCI device with class code 0x010160 found at index 0
01697080609i[BIOS ] no PCI device with class code 0x010166 found at index 0
01697094464i[BIOS ] no PCI device with class code 0x010164 found at index 0
01697108322i[BIOS ] no PCI device with class code 0x01016a found at index 0
01697122177i[BIOS ] no PCI device with class code 0x010168 found at index 0
01697136035i[BIOS ] no PCI device with class code 0x01016e found at index 0
01697149891i[BIOS ] no PCI device with class code 0x01016c found at index 0
01697163748i[BIOS ] no PCI device with class code 0x010172 found at index 0
01697177603i[BIOS ] no PCI device with class code 0x010170 found at index 0
01697191460i[BIOS ] no PCI device with class code 0x010176 found at index 0
01697205315i[BIOS ] no PCI device with class code 0x010174 found at index 0
01697219173i[BIOS ] no PCI device with class code 0x01017a found at index 0
01697233028i[BIOS ] no PCI device with class code 0x010178 found at index 0
01697246886i[BIOS ] no PCI device with class code 0x01017e found at index 0
01697260742i[BIOS ] no PCI device with class code 0x01017c found at index 0
01697274599i[BIOS ] no PCI device with class code 0x010182 found at index 0
01697370100i[BIOS ] no PCI device with class code 0x010180 found at index 1
01697383957i[BIOS ] no PCI device with class code 0x010186 found at index 0
01697397812i[BIOS ] no PCI device with class code 0x010184 found at index 0
01697411670i[BIOS ] no PCI device with class code 0x01018a found at index 0
01697425525i[BIOS ] no PCI device with class code 0x010188 found at index 0
01697439383i[BIOS ] no PCI device with class code 0x01018e found at index 0
01697453239i[BIOS ] no PCI device with class code 0x01018c found at index 0
01697467096i[BIOS ] no PCI device with class code 0x010192 found at index 0
01697480951i[BIOS ] no PCI device with class code 0x010190 found at index 0
01697494808i[BIOS ] no PCI device with class code 0x010196 found at index 0
01697508724i[BIOS ] no PCI device with class code 0x010194 found at index 0
01697522582i[BIOS ] no PCI device with class code 0x01019a found at index 0
01697536437i[BIOS ] no PCI device with class code 0x010198 found at index 0
01697550295i[BIOS ] no PCI device with class code 0x01019e found at index 0
01697564151i[BIOS ] no PCI device with class code 0x01019c found at index 0
01697578009i[BIOS ] no PCI device with class code 0x0101a2 found at index 0
01697591865i[BIOS ] no PCI device with class code 0x0101a0 found at index 0
01697605723i[BIOS ] no PCI device with class code 0x0101a6 found at index 0
01697619579i[BIOS ] no PCI device with class code 0x0101a4 found at index 0
01697633438i[BIOS ] no PCI device with class code 0x0101aa found at index 0
01697647294i[BIOS ] no PCI device with class code 0x0101a8 found at index 0
01697661153i[BIOS ] no PCI device with class code 0x0101ae found at index 0
01697675010i[BIOS ] no PCI device with class code 0x0101ac found at index 0
01697688868i[BIOS ] no PCI device with class code 0x0101b2 found at index 0
01697702724i[BIOS ] no PCI device with class code 0x0101b0 found at index 0
01697716582i[BIOS ] no PCI device with class code 0x0101b6 found at index 0
01697730499i[BIOS ] no PCI device with class code 0x0101b4 found at index 0
01697744358i[BIOS ] no PCI device with class code 0x0101ba found at index 0
01697758214i[BIOS ] no PCI device with class code 0x0101b8 found at index 0
01697772073i[BIOS ] no PCI device with class code 0x0101be found at index 0
01697785930i[BIOS ] no PCI device with class code 0x0101bc found at index 0
01697799788i[BIOS ] no PCI device with class code 0x0101c2 found at index 0
01697813644i[BIOS ] no PCI device with class code 0x0101c0 found at index 0
01697827502i[BIOS ] no PCI device with class code 0x0101c6 found at index 0
01697841358i[BIOS ] no PCI device with class code 0x0101c4 found at index 0
01697855217i[BIOS ] no PCI device with class code 0x0101ca found at index 0
01697869073i[BIOS ] no PCI device with class code 0x0101c8 found at index 0
01697882932i[BIOS ] no PCI device with class code 0x0101ce found at index 0
01697896789i[BIOS ] no PCI device with class code 0x0101cc found at index 0
01697910647i[BIOS ] no PCI device with class code 0x0101d2 found at index 0
01697924503i[BIOS ] no PCI device with class code 0x0101d0 found at index 0
01697938422i[BIOS ] no PCI device with class code 0x0101d6 found at index 0
01697952278i[BIOS ] no PCI device with class code 0x0101d4 found at index 0
01697966137i[BIOS ] no PCI device with class code 0x0101da found at index 0
01697980006i[BIOS ] no PCI device with class code 0x0101d8 found at index 0
01697993852i[BIOS ] no PCI device with class code 0x0101de found at index 0
01698007709i[BIOS ] no PCI device with class code 0x0101dc found at index 0
01698021567i[BIOS ] no PCI device with class code 0x0101e2 found at index 0
01698035423i[BIOS ] no PCI device with class code 0x0101e0 found at index 0
01698049281i[BIOS ] no PCI device with class code 0x0101e6 found at index 0
01698063137i[BIOS ] no PCI device with class code 0x0101e4 found at index 0
01698077001i[BIOS ] no PCI device with class code 0x0101ea found at index 0
01698090852i[BIOS ] no PCI device with class code 0x0101e8 found at index 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.