5 ms·
What’s up with the mysterious inc bp in prologues of 16-bit code? (2011)
- adamnemecek 8y agoGod I’m glad that era is over.
- userbinator 8y agoI stumbled across this while searching for something very similar, and found it very interesting that 16-bit Windows was, while most known for being cooperatively multitasked, also had what could be called cooperative virtual memory.
- sova 8y agoPlease elaborate?
- ajross 8y agoIt's in the article. Windows could unload code segments that weren't running to free space for other purposes. But those functions might be on a process call stack. So it used the otherwise irrelevant low bit of the BP register to store whether a frame was a near or far call, thus allowing the unload code to fix up the return address to allow for reloading on demand.
- sova 8y agoSo if I get this right: the stack is limited in size, and certain "frequent use" routines were labeled as "near" while others with less frequent use were labeled as "far" and there was a dynamic way to keep frequent ones in memory?
- ajross 8y agoIt's a 16 bit architecture. Any code that doesn't fit in 64k needs to be in a separate segment. In practice, the way typical C compilers managed this (there were a bunch of code generation options) was to put all the code in a single C/obj file into a separate segment. Calls within the segment were "near" and used the simple CALL/RET variants which took and pushed a 16 bit address. Others were "far" and called/returned to a tuple of an address and a segment descriptor.
- deleted 8y ago[deleted]
- pvg 8y agoOr 'automatic overlays', depending on the angle of anachronism you want to take.
- JdeBP 8y agoThe terminology of the time talked about "discardable segments" of course.
- mikequinlan 8y agoFrom 2011
- ericnyamu 8y agoA 2011 article? What are you trying to do?
- gaius 8y agoThe incredible ingenuity of those old-skool engineers. Can you imagine modern-day TDD nodejs “ninjas” trying to solve this problem under these conditions?
- mlvljr 8y agohell-ban this person, guys, what a disgusting blasphemy!
- phkahler 8y agoI think the better engineers use the MC68000 in their designs and had nothing to do with this nonsense. I started reading TFA and stopped as soon as I realized it was about a crummy abstraction that should never have happened.
- tom_ 8y agoWhy would the 68000 improve anything? My recollection is that bus error recovery was impossible, so you'd end up having to do something similar, or worse...
- cryptonector 8y agoAnd the M68000 didn't have an MMU, nor privilege management. The M68010 had support for external MMUs (and privilege management), but no built-in MMU. It wasn't until the M68020 that a built-in MMU was added. So any attempt to have virtual memory on an M68000 would have necessitated hacks not too dissimilar to the inc bp real mode Windows hack. Indeed, the Amiga OS (which also was a cooperative multi-tasking, virtual memory OS) had a segmented 64KB addressing mode precisely so as to support virtual memory even though the M68000 was properly a 32-bit CPU with 32-bit addressing. I don't know the details of how Amiga implemented virtual memory beyond that though.
- icedchai 8y agoAmiga OS was actually preemptive multitasking. It did not support virtual memory. See https://en.wikipedia.org/wiki/Exec_(Amiga) https://en.wikipedia.org/wiki/Exec_(Amiga) You may be thinking of the original MacOS.