//: Core data structures for simulating the SubX VM (subset of an x86 processor) //: //: At the lowest level ("level 1") of abstraction, SubX executes x86 //: instructions provided in the form of an array of bytes, loaded into memory //: starting at a specific address. //:: registers //: assume segment registers are hard-coded to 0 //: no floating-point, MMX, etc. yet :(before "End Types") enum { EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, NUM_INT_REGISTERS, }; union reg { int32_t i; uint32_t u; }; :(before "End Globals") reg Reg[NUM_INT_REGISTERS] = { {0} }; uint32_t EIP = 1; // preserve null pointer :(before "End Reset") bzero(Reg, sizeof(Reg)); EIP = 1; // preserve null pointer :(before "End Help Contents") cerr << " registers\n"; :(before "End Help Texts") put_new(Help, "registers", "SubX currently supports eight 32-bit integer registers. From 0 to 7, they are:\n" " EAX ECX EDX EBX ESP EBP ESI EDI\n" "ESP contains the top of the stack.\n" "\n" "-- 8-bit registers\n" "Some instructions operate on eight *overlapping* 8-bit registers.\n" "From 0 to 7, they are:\n" " AL CL DL BL AH CH DH BH\n" "The 8-bit registers overlap with the 32-bit ones. AL is the lowest signicant byte\n" "of EAX, AH is the second lowest significant byte, and so on.\n" "\n" "For example, if EBX contains 0x11223344, then BL contains 0x44, and BH contains 0x33.\n" "\n" "There is no way to access bytes within ESP, EBP, ESI or EDI.\n" "\n" "For complete details consult the IA-32 software developer's manual, volume 2,\n" "table 2-2, \"32-bit addressing forms with the ModR/M byte\".\n" "It is included in this repository as 'modrm.pdf'.\n" "The register encodings are described in the top row of the table, but you'll need\n" "to spend some time with it.\n" "\n" "-- flag registers\n" "Various instructions (particularly 'compare') modify one or more of three 1-bit 'flag'\n" "registers, as a side-effect:\n" "- the sign flag (SF): usually set if an arithmetic result is negative, or\n" " reset if not.\n" "- the zero flag (ZF): usually set if a result is zero, or reset if not.\n" "- the overflow flag (OF): usually set if an arithmetic result overflows.\n" "The flag bits are read by conditional jumps.\n" "\n" "For complete details on how different instructions update the flags, consult the IA-32\n" "manual (volume 2). There's various versions of it online, such as https://c9x.me/x86,\n" "though of course you'll need to be careful to ignore instructions and flag registers\n" "that SubX doesn't support.\n" "\n" "It isn't simple, but if this is the processor you have running on your computer,\n" "might as well get good at it.\n" ); :(before "End Globals") // the subset of x86 flag registers we care about bool SF = false; // sign flag bool ZF = false; // zero flag bool OF = false; // overflow flag :(before "End Reset") SF = ZF = OF = false; //: how the flag registers are updated after each instruction :(before "End Includes") // Combine 'arg1' and 'arg2' with arithmetic operation 'op' and store the // result in 'arg1', then update flags. // beware: no side-effects in args #define BINARY_ARITHMETIC_OP(op, arg1, arg2) { \ /* arg1 and arg2 must be signed */ \ int64_t tmp = arg1 op arg2; \ arg1 = arg1 op arg2; \ trace(Callstack_depth+1, "run") << "storing 0x" << HEXWORD << arg1 << end(); \ SF = (arg1 < 0); \ ZF = (arg1 == 0); \ OF = (arg1 != tmp); \ } // Combine 'arg1' and 'arg2' with bitwise operation 'op' and store the result // in 'arg1', then update flags. #define BINARY_BITWISE_OP(op, arg1, arg2) { \ /* arg1 and arg2 must be unsigned */ \ arg1 = arg1 op arg2; \ trace(Callstack_depth+1, "run") << "storing 0x" << HEXWORD << arg1 << end(); \ SF = (arg1 >> 31); \ ZF = (arg1 == 0); \ OF = false; \ } //:: simulated RAM :(before "End Types") const uint32_t SEGMENT_ALIGNMENT = 0x1000000; // 16MB inline uint32_t align_upwards(uint32_t x, uint32_t align) { return (x+align-1) & -(align); } // Like in real-world Linux, we'll allocate RAM for our programs in disjoint // slabs called VMAs or Virtual Memory Areas. struct vma { uint32_t start; // inclusive uint32_t end; // exclusive vector _data; vma(uint32_t s, uint32_t e) :start(s), end(e) {} vma(uint32_t s) :start(s), end(align_upwards(s+1, SEGMENT_ALIGNMENT)) {} bool match(uint32_t a) { return a >= start && a < end; } bool match32(uint32_t a) { return a >= start && a+4 <= end; } uint8_t& data(uint32_t a) { assert(match(a)); uint3
dwm - dynamic window manager
============================
dwm is an extremely fast, small, and dynamic window manager for X.


Requirements
------------
In order to build dwm you need the Xlib header files.


Installation
------------
Edit config.mk to match your local setup (dwm is installed into
the /usr/local namespace by default).

Afterwards enter the following command to build and install dwm (if
necessary as root):

    make clean install

If you are going to use the default bluegray color scheme it is highly
recommended to also install the bluegray files shipped in the dextra package.


Running dwm
-----------
Add the following line to your .xinitrc to start dwm using startx:

    exec dwm

In order to connect dwm to a specific display, make sure that
the DISPLAY environment variable is set correctly, e.g.:

    DISPLAY=foo.bar:1 exec dwm

(This will start dwm on display :1 of the host foo.bar.)

In order to display status info in the bar, you can do something
like this in your .xinitrc:

    while true
    do
        echo `date` `uptime | sed 's/.*,//'`
        sleep 1
    done | dwm


Configuration
-------------
The configuration of dwm is done by creating a custom config.h
and (re)compiling the source code.
exit(1); } } inline uint8_t next() { return read_mem_u8(EIP++); } void dump_registers() { ostringstream out; out << "registers: "; for (int i = 0; i < NUM_INT_REGISTERS; ++i) { if (i > 0) out << "; "; out << " " << i << ": " << std::hex << std::setw(8) << std::setfill('_') << Reg[i].u; } out << " -- SF: " << SF << "; ZF: " << ZF << "; OF: " << OF; trace(Callstack_depth+1, "run") << out.str() << end(); } // debugging info from a later layer string call_label(uint8_t op) { if (op != 0xe8) return ""; // End Trace Call Instruction return "/call"; } //: start tracking supported opcodes :(before "End Globals") map Name; map Name_0f; map Name_f3; map Name_f3_0f; :(before "End One-time Setup") init_op_names(); :(code) void init_op_names() { put(Name, "f4", "halt (hlt)"); // End Initialize Op Names } :(before "End Help Special-cases(key)") if (key == "opcodes") { cerr << "Opcodes currently supported by SubX:\n"; for (map::iterator p = Name.begin(); p != Name.end(); ++p) cerr << " " << p->first << ": " << p->second << '\n'; for (map::iterator p = Name_0f.begin(); p != Name_0f.end(); ++p) cerr << " 0f " << p->first << ": " << p->second << '\n'; for (map::iterator p = Name_f3.begin(); p != Name_f3.end(); ++p) cerr << " f3 " << p->first << ": " << p->second << '\n'; for (map::iterator p = Name_f3_0f.begin(); p != Name_f3_0f.end(); ++p) cerr << " f3 0f " << p->first << ": " << p->second << '\n'; cerr << "Run `subx help instructions` for details on words like 'r32' and 'disp8'.\n" "For complete details on these instructions, consult the IA-32 manual (volume 2).\n" "There's various versions of it online, such as https://c9x.me/x86.\n" "The mnemonics in brackets will help you locate each instruction.\n"; return 0; } :(before "End Help Contents") cerr << " opcodes\n"; //: Helpers for managing trace depths //: //: We're going to use trace depths primarily to segment code running at //: different frames of the call stack. This will make it easy for the trace //: browser to collapse over entire calls. //: //: Errors will be at depth 0. //: Warnings will be at depth 1. //: SubX instructions will occupy depth 2 and up to Max_depth, organized by //: stack frames. Each instruction's internal details will be one level deeper //: than its 'main' depth. So 'call' instruction details will be at the same //: depth as the instructions of the function it calls. :(before "End Globals") extern const int Initial_callstack_depth = 2; int Callstack_depth = Initial_callstack_depth; :(before "End Reset") Callstack_depth = Initial_callstack_depth; :(before "End Includes") #include #define HEXBYTE std::hex << std::setw(2) << std::setfill('0') #define HEXWORD std::hex << std::setw(8) << std::setfill('0') // ugly that iostream doesn't print uint8_t as an integer #define NUM(X) static_cast(X) #include