A quick follow up to building DLL’s

Another slight issue I’ve found with the SLiRP code, is that it expects to be able to call two functions (slirp_can_output and slirp_output). The snag here is that DLL’s expect to be SELF CONTAINED… So how can you have a DLL that needs to call functions from your program?

Void pointers!

So let’s make this more… involved.

dll.c

void (*bob)(int xy);

__declspec(dllexport) int hi(void)
{
(*bob)(12);
return 3;
}

__declspec(dllexport) void Register(void *p)
{
bob=p;
}

test.c

extern void Register(void *p);

void XX(int xy)
{
printf(“XX %d\n”,xy);
}

void main(void)
{
int j;
Register(XX);
j=hi();

printf(“%d\n”,j);
}

And let’s build it…

c:\temp\dll>cl /c /LD dll.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80×86
Copyright (C) Microsoft Corporation. All rights reserved.

dll.c

c:\temp\dll>link /DLL dll.obj
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library dll.lib and object dll.exp

c:\temp\dll>cl test.c dll.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80×86
Copyright (C) Microsoft Corporation. All rights reserved.

test.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj
dll.lib

c:\temp\dll>test
XX 12
3

So as we can see, the main procedure runs the ‘register’ procedure to tell the dll that the ‘bob’ procedure will infact be XX. Now when the dll invokes it’s ‘hi’ function it can call the XX function from the exe. Now if I were a better programer, I’d use the DLLMain code to make sure that all my virtual void functions cause some kind of ‘readable’ panic message when called so you don’t get the default reaper… Because naturally if you run the dll code without the register function it’ll crash in a not so great manner.

But I’ll leave that as an exercise to the reader.

I’ve made some good progress on the SIMH thing, Ive got the non networked versions & the libpcap stuff building with Visual C++ 2008… I was thinking about using that 2010 RC but that just seems wrong…. But for now all I’ll have to do is apply this logic to the slirp dll, and get building the VC version for linking, and the Mingw version for actual operation….

Build a DLL

Well this is leading up to a new release of my SIMH projects. The issue that I’ve had with the SLiRP code (usermode NAT) is that it only works when built with GCC, and ONLY when you have no optimizations. Naturally you will loose all optimizations with SIMH if you build the entire project like that. And of course you cannot use Visual C++ to build SIMH, because while it’s faster they use different object files.

So while thinking about what a bummer it is, and how to try to debug SLiRP with Visual Studio, today I had a ‘better’ idea. Well ‘better’ in that I can do this way quicker.

Instead I’ll build SLiRP as a DLL, and have Visual C++ call that!

Ok, now that sounds crazy, but the first thing I’d need is a simple ‘test’ case. First let’s build a dll in MinGW. It took a bit of googling but then I found this super simple example.

dll.c

__declspec(dllexport) int hi(void)
{
return 3;
}

Ok, it doesn’t do that much, but you get the idea. Now we have to compile this with MinGW.

gcc -c dll.c
gcc -shared -o test.dll dll.o

Ok, now this will first compile the C file into an object file, then the linker will set it up as a DLL. Notice that I’m not building the ‘.a’ export file for this DLL. Visual C++ wouldn’t like it anyways, so I don’t need it.

Next, using Visual C++ (I would *assume* just about every version can do this..) I re-build the DLL to create the export library. Yes I know this is weird, but it is the quickest way I know to do this.

cl /c /LD dll.c
link /DLL dll.obj

Cool, now we’ve built dll.c as a DLL under both MinGW & Visual C++. Now for a ‘test’ program to drive our ‘staticly linked’ dynamic link library.

test.c

void main(void)
{
int j=hi();
printf(“%d\n”,j);
}

Ok, now with that out of the way, let’s compile & link!

cl test.c dll.lib

Cool, now we’ll have a test.exe!

Let’s run it!

c:\msys\1.0\src\dlltest>cl test.c dll.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80×86
Copyright (C) Microsoft Corporation. All rights reserved.

test.c
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj
dll.lib

c:\msys\1.0\src\dlltest>test
3

Wow that was exciting! Now for the people paying attention, you’ll remember that the test.exe was linked against dll.lib which was built with the Microsoft compiler, and is calling the Microsoft generated dll.dll. Yes you are correct. But always test with a known positive, before you throw in the negative I say…

c:\msys\1.0\src\dlltest>move test.dll dll.dll
Overwrite c:\msys\1.0\src\dlltest\dll.dll? (Yes/No/All): y
1 file(s) moved.

c:\msys\1.0\src\dlltest>test
3

Holy crap! It worked!!!!

That’s right, now I have built a very simple test program that’ll call a DLL function built with MinGW!

And that, is how you can get around a kooky problem where some programs build with one version of a compiler tweaked one way, and you want to use those bits in another program built another way.

Just ask any language refugee from the 1980’s how hard this was to do on the PC platform.. While VMS had a common library spec for all languages, not every platform (MS-DOS,UNIX) was as lucky. But with the rise of things like Windows with DLL’s, and of course NT thanks to the VMS crew it’s in modern systems today.

Let me tell you, linking Quick Basic to C was… not all that much fun. And Turbo C++ was right out!

Anyways I’ll leave you with this much, and at the worst case, much like making bootable CD’s, it’s a good note for me to find this stuff later when I need it.

SHOWSTOPPER!

show-stopper-coverI was browsing around at a book store, and I came across the book “SHOWSTOPPER” the breakneck race to create Windows NT and the next generation at Microsoft.

If you have ever lived through the Windows NT 3.x days you’ll find this a very interesting read. It goes into the big personalities, and of course covers the working habits of Dave Cutler… Although it does paint him in some really odd colors, mostly as an antisocial kind of dictator pushing people to produce the largest program Microsoft had ever produced at the time.

But there is no doubt, Cutler could not have written Windows NT at Digital, as DEC was too fond of hardware lockins (look at VMS & Ultrix/True64). And it does cover the major animosity of Cutler towards DEC with the cancellation of the Prisim/Mica projects, and then the later “I told you so” moment when DEC licensed Windows NT from Microsoft (although other reports claim that DEC threatened MS with a lawsuit, and MS gave them access to NT, along with some money…). Apparently the mantra was “Dec could have had NT for free”..

There is also coverage of the culture clash of what happened when Microsoft had absorbed the Prisim & Mica engineering teams from DEC, and how they did not get along with Microsoft staff, and even did their best to poke holes in the current offerings of MS-DOS & OS/2 as either a toy, or a joke.

One thing I found interesting, is that the book mentions the WLO project, as the foundation for what would be the ‘Win32’ system. WLO if you remember was a port of the Windows Libraries to OS/2. It was very interesting in that Windows, OS/2 and even MS-DOS & Win16 via WOW were all not part of the main Windows NT group, but rather ‘tacked on’.

However it is quite interesting that the design decisions made for a very portable and modular operating system, that survived it’s original CPU & platform being changed 1/4th the way through development, and then the removal of the primary API.

Another thing that was interesting was some of the ‘fixes’ for the too slow, too big that would plague the early versions of NT, was the idea of demand paging portions of the kernel.. I for one would go insane with the blue screens about paging non page-able areas or some other VM error… But the truth was NT was written by people who came from a minicomputer world, and as the book made evident from time to time, they did NOT use PC’s.

Needless to say, the book was somewhat spot on, in that it’d take 10+ years for computers to catch up to what Windows NT was written for. I for one can remember trying to run this on a 386sx-16 and it was horrible… But if you install it on a Pentium II the 3.x series simply FLIES… And in emulation on modern machines it has incredible performance.

While Windows NT 3.1 was no doubt a 1.0 release, 3.5 was a 2.0. The x86 optimizations really payed off, and kicking out the Spider TCP/IP stack, and bringing in the new MS stack helped a LOT. There is no doubt back in 1994 as SLIP & PPP accounts were becoming more common place, Windows NT 3.5’s networking was the easiest to configure and use. Linux back then really was in it’s infancy, and the dialup scripts for pap/chap/pppd were… a nightmare.

“Dogfooding” was another interesting, and necessary thing as once NT was able to start running programs it was important to make people start using it as quickly as possible to shake out bugs in the system. Its also interesting to note the reluctance of the kernel team to deal with the graphical part of NT, and how the first versions were text only. Another weird part was how the security in Windows NT was an after effect, of the internal networking group cooking up what eventually became the domain & trust model. Not to mention how NTFS almost didn’t make it because the filesystem people (all two of them!) were so busy making sure HPFS worked correctly.

There is no doubt that such a ‘ground up’ OS of this magnitude hasn’t been attempted since 1988. It took Microsoft 5 years to get Windows NT out the door, but there is no doubt looking around in the year 2010, Windows NT has a long life ahead of it.

For those interested, you can find it on amazon.

So I was looking in the UK for ACORN

and other old kit… I came up with nothing..

Does anyone know any stores, that sell ancient stuff, like megadrives, acorns, BBC micros etc?

There must be somewhere in the British Isles….

Also I’m wondering if I should check prices for Russia in the Summer, or Japan in the Winter……

I think I need a vacation from this vacation.

BKUNIX

Somehow on my trying to remember how to enable scsi on the i386 qemu, I came across this fun project… Bkunix. No it’s *NOT* BURGER KING Unix… But rather a port of LSX-UNIX to the Soviet Elektronika BK computer.

The BK’s were sold as personal computers in the Soviet Union, and were cloned from the DEC LSI PDP11’s.

Later on, with the source being available, a project has been started by Sergey Vakulenko and Leonid Broukhis to port the LSX to the BK’s. What is neat about this, is that the entire system is built with a set of cross tools, to produce the kernel & userland utilities.

And the best part is that you can run it in an emulator! You can download it here. Just don’t over expect the MINI & LSX UNIX’s were meant to run on tiny machines with as little as 40kb of ram. However given such a small constraint, it’s very impressive to see it in operation.

bkunix

bkunix

And yes, the kernel is 18kb!

Just got a DEC AlphaServer 800…

All 100lb of it. It is HEAVY.

Anyways, long story short, after hauling it around Financial District, and Times Square, it’s now safe and installing Windows NT 4.0 Terminal Server.

AlphaServer 800

AlphaServer 800

It’s got a single 5/500 CPU, along with 256MB of ram, and 2x 36gig disks. I’ll have to check to see if I have any ram that’ll fit it. I may very well turn it into a public access thing too….. But we’ll see.

DEC Legacy Event

Well I just found out about a “DEC Legacy Event” being held in the UK. Sadly I already booked tickets to the UK *this* month not the correct one… But then who knows… 😉

From the site:

The DEC Legacy Event that will take place on the 17th & 18th April 2010 in Windermere, UK.

The purpose of the event is to bring together people with an interest in the company Digital Equipment Corporation and their legacy of hardware, software and ethos. There will be both vintage DEC computer hardware and software and more recent HP hardware and software being demonstrated at the event.

I suppose this would have been the place to get some win terminals going, and have multi-user access into a VMS system running on SIMH on an Alpha…

Oh well…

At any rate they promise to upload video from the aftermath, and they’ve got up some interesting promo pics

DDOS fun…

Well it seems at some point China has decided they don’t like me, and they are now DDOS’ing my server… Or they have some bot net that is OBSESSED with Windows NT 3.1 servicepack 3 for the i386…

So as much as I don’t want to, I’ll end up blocking China, Taiwan, Hong Kong from my server…. Oh well.

One can only speculate what on earth they find so interesting.

If anyone is interested, you can find a script here, that’ll add a list of IP addresses into a block list for IIS.

Then it’s just a matter of downloading a table of IP addresses. I’m using these guys right now… I just downloaded the csv version, ran it through access, and used that to create some queries for some tables, then ran that data through some minor C program I ended up writing to massage the netmasks into something the script would like. It’s not “nice” but it works. Then afterwards since they keep on downloading the same file, I just extract my IIS logs into access which has the IP address set as a primary key, then I’m just making /24’s of each one that does so….

Sigh, I don’t get why they are doing it, but they are getting a whole lot of 403’s now.

DJGPP on DOSBOX…

Well I was originally looking around at the new & exciting 16bit support for HX, but so far I’m having little luck… It seems all the ‘cool’ OS/2 stuff it should do just crashes out on me…

I’m hoping to get something going eventually.

In the meantime, I had to check to see if an old MS-DOS favorite, DJGPP was still around.. And not only is it still there, but they now support GCC 4.42!

DJGPP, is simply put a port of GCC to MS-DOS. The best part, is that the compiler, libraries, and even the dos extender are all FREE. The sad thing is that DJGPP hit popularity around the mid 90’s with the rise of Windows 95, and the internet… Kind of killing 32bit MS-DOS applications… However Quake 1 shipped as a djgpp/cwsdpmi application… I’m sure there are others.

So at any rate, I was intrigued that it was still around, so I fired up DOSBox, then downloaded the zips according to the zip picker, read the readme, setup the environment, and I was off and away compiling my trivial hello world.

Sadly for me, I couldn’t sleep, so I then just grabbed the f2c/dungeon stuff and did a compile… I only had to tweak a few things, mostly a garbled long file name thing, but in no time… It was running.

 

I did manage to crash dosbox building the libf2c, but luckily changing gcc to use the -O0 (no optimizations) it was able to build the library… It’s kind of sad generating a 150kb ‘hello world’ type application, but thats the price for essentially statically linking everything….

MS-DOS isn’t the most modern thing out there…. I always wonder if those kids writing a 32bit ms-dos like os ever got anywhere…

Updated Qemu for MIPS emulation

Today I found out that the latest ‘git’ repository version can run Windows NT in color, and with corrected mouse support! The NVRAM is still corrupting and you’ll have to fix the time/date but a usable mouse, and being able to see what you are doing go a long way!

I’ve put the updated binaries here.

If you feel adventurous you too can compile the emulator, I’ve downloaded todays snapshot to here in the off chance this won’t be build able for some time.

I don’t know if there is any good way to enable sound, but things like Visual C++ 4.0 & Quake 1 are usable in that you can actually see what is going on!

Here’s a screen shot of my NT 4.0 workstation….

Qemu MIPS Windows NT color

Qemu MIPS Windows NT color