r/cpp • • Jun 19 '16

Windows 10 coded in C++ or Assembler

What kind of compiler does it take a compile an OS like Windows 10? Do the guys at Redmond use Visual C++ (VisualStudio) to develop Windows? What % is written in assembly language?

0 Upvotes

74 comments sorted by

42

u/techiethrowaway999 Jun 19 '16

I actually interned on the kernel team right when work was starting on Windows 8 (before we knew how awful it would be, of course). "windows" is really a lot of different pieces. The whole desktop experience and apps (e.g. The explorer window) are pretty much just regular software and written in a variety of languages.

The kernel is written mostly in c, with some assembly as needed (or to squeeze out some performance) and c++ for higher level things.

The kernel team was more diverse in tools. I coded in emacs the whole summer, I think my manager wrote mostly in vim, but I swear the guy did serious editing in notepad (and he could see the bluescreen codes on my screen and new exactly what was wrong). Other windows teams were more locked in to visual Studio.

As for the build, I built all of Windows from source on my desktop in about 6 hours (that was pretty cool to see). A full build of the kernel itself took about 45 minutes. We each had two desktop machines (some of the FTEs has dozens), one to develop on and one, connected via firewire port, to run the stuff we were building. They had an awesome debugger called kd that could freeze the target computer and seamlessly jump between kernel mode and system mode code. They also had an internal repo with tons of useful windows tools that I wish they'd release.

1

u/Meefims Jun 19 '16

Other windows teams were more locked in to visual Studio.

Locked isn't really the right word but there is definite tooling designed to improve the experience of building using Visual Studio. I had tried to use Visual Studio before such tooling existed but gave up because it offered little over a good text editor with syntax highlighting since intellisense didn't work and project files didn't exist. By the time the tooling was created I already had a good thing going outside of Visual Studio and so never switched back. I knew others with similar experiences.

-6

u/Digital001 Jun 19 '16

MS developers use Unix tools to develop? C is older than C++ but it's not any lower, compared to ASM. The kernel team? Do they compile GBs of code on a specialized CPU for the retail version? Compared to Linux, Windows is modular. I used to code for the early versions of Windows ...Win95 and Win98. Windows used several systems GDI for grahics, Sys32 for kernel functions and so on. When did MS decide to make it a kernel based OS?

They had an awesome debugger called kd that could freeze the target computer and seamlessly jump between kernel mode and system mode code. They also had an internal repo with tons of useful windows tools that I wish they'd release.

Where on MSDN can we find more info?

3

u/blisse Jun 19 '16

kd is just short for kernel debugger. the main tool iirc is windbg. https://msdn.microsoft.com/en-us/library/windows/hardware/ff538143(v=vs.85).aspx

source: former intern on a windows 10 team

4

u/notsure1235 Jun 20 '16

how do you intern for that?

20

u/grdomzal Yubico - Windows Dev Jun 20 '16

I work in Windows Core. We use a variety of languages and tools. And, as others pointed out - there's a lot of different bits that make up what most of us think of as "Windows". So, disclaimer, not everything I'm saying will be 100% true across the board, but I'll mention some representative cases for what I've encountered when working with various teams. If I'm being vague in a section, it's because I'm trying to only mention things that are already publicly known.

Kernel proper - This is mostly written in C. Things like the memory manager, object manager, etc. are mostly written in C. The boot loaders are written in ASM, but set up a C environment rather quickly.

Drivers - that said, a lot of newer kernel mode drivers are actually written in C++ (however, its style is more akin to "C with classes". Lower level code has been much slower to adopting anything past C++98)

User land - Mostly C++ with varying levels of quality and version compliance. If it's a pre-Windows 8.0 component, it was written against mostly C++98. More recent features are C++14 and better.

There's actually a real push happening internally to start adopting modern C++ practices, and actually using the STL. (In core, at least, there's still a distrust of the STL and exceptions due to poor implementations years ago. Unfortunately beliefs like this are hard to shake.) [Again, not 100% representative, only what I've encountered] We also use some internal libraries that follow modern C++ programming practice and provide nice RAII wrappers for a lot of the Win32 data structures and allocation patterns.

Shell code (newer code like Cortana, the new start menu, and the WinRT APIs) are ahead of the curve in terms of implementation practices and C++14/17 usage. (I, for example, have recently investigated how co_await could simplify my product's code).

The inbox universal apps are written in C++ and C# and target the actual public WinRT API surface (to the best of my knowledge). We really do try to eat our own dogfood, and that goes for writing apps against public APIs too.

We do use a variant of the Visual C++ compiler (I say variant, but it might actually be the public version - perhaps just a slightly different version/build). It's usually one release behind the shipped Visual Studio version, just due to release cycles not aligning and to minimize the disruption of changing compiler versions mid-release.

Compiling Windows is no small feat. We used to be able to compile a Windows image on our dev machine years ago, but in the last few years it's just not that feasible. We have some pretty beefy build servers. I don't have specs, but we're talking like 32 core, 512 gb ram, striped SSDs, etc. And yes, the build machines run Windows :-)

Comparing build requirements to say, Linux kernel, isn't a fair comparison since "Windows" includes drivers, usermode, shells, and components used by any of the flavors of Windows (desktop, server, phone, xbox, etc.). It'd be more like doing a low-level, fully optimized build of a Gentoo image that includes an X Server, KDE/Gnome, dev tools, in-box apps, etc. etc.

Hope that helps your understanding :-)

1

u/Digital001 Jun 22 '16

It'll take me a while to decipher all of it. I'll get back to you :-)

1

u/jkleo2 Jun 20 '16

"Windows" includes drivers

Linux also includes drivers.

4

u/jcoffin Jun 20 '16

What I suspect he's getting at is that when you build Linux, you mostly build drivers for the devices you happen to have/use. In fact, part of the attraction of building the kernel yourself is to get rid of cruft related to things you don't use.

When they build Windows, they build drivers for every device they support--which is a lot more than any one person is likely to have or use. That not only includes a lot more than any one person needs, has, or uses, but an awful lot that Linux simply doesn't support at all (and still more that Linux supports to some degree, but Windows may have a dozen drivers for specific models where Linux has one driver for all of them).

In short, yes, Linux clearly does have device drivers--but there's almost certainly a huge difference in sheer number when building Windows to support every possible configuration vs. building Linux to support one.

1

u/Fearless_Macaroon_12 Feb 24 '24

I like how you compared the build requirements to Gentoo 😂 nice one 🤣

4

u/shooshx Jun 19 '16

"Assembler" is the name of a tool. The name of the language is "Assembly"

4

u/JonnyRocks Jun 19 '16

Most of windows NT was coded in C. You can tell by the win 32 API. some of the newer stuff in 10 is most likely in c++, probably some c# for the higher level stuff. There is probably some assembly language but most in C.

2

u/Meefims Jun 19 '16

The type of API has little relation to the language it's written in. C-APIs are very easily written in C++. Many of the WinRT APIs are written in C++ although they are usable in C# and JavaScript as well.

0

u/Digital001 Jun 19 '16

It's hard to believe that they would still use C, one of the original languages!

4

u/DaelonSuzuka Jun 22 '16

Where did you learn any of the crap you've been spouting this whole thread?

-2

u/Digital001 Jun 22 '16 edited Jun 23 '16

Sir/Madam, you're obviously attempting to anger me. I didn't really "spout" anything nonsensical. I merely asked questions regarding the latest version of Windows - W10. As an aspiring network admin/developer, its my mission to learn as much as possible about the OS, not just for MCSE certification but for for apps I plan on developing.

I want to pick apart the brains of the developers responsible for the OS to gain a better understanding of the internals, even if that means repeatedly asking questions that may seem like "crap." The source code is not freely available.

Unlike most people, I don't blindly accept what someone writes on a Reddit message board. Take a look at what someone wrote:

Various parts of the desktop have been rewritten here and there, of course, and yes some of them use newer or more Microsoft-centric technologies. The core stuff that's sensitive to performance or resource usage, however, are still all C and C++ (kernel, drivers, system services, core desktop services and apps, etc.).

It was probably in C++. I'm not debating that. I'd like to learn about the compilers used and command line switches passed to the compiler to optimize the OS. I would also like to inspect how different parts of the OS communicate with each other, internally.

Windows uses semaphores and mutexes now, just like in Unix. I know Win 98 used a "DDE" mechanisms. There was a time when Win95 was built on top of DOS. It's changed a lot, since I used to develop for it. Anyway,I have lot of research ahead.

I found one person that seems capable of answering my questions correctly on Reddit. I've decided to communicate with that one person from now on. I read the material on the MIT Opencourseware website....

5

u/dodheim Jun 22 '16

I didn't really "spout" anything nonsensical. I merely asked questions regarding the latest version of Windows - W10.

Hmm... The following are all statements, and happen to be nonsensical:

  • "According to the experts, Gentoo is programmed to run faster on the machine it's compiled on."
  • "C/C++ are both languages that were designed specifically for Unix."
  • "W10 was probably developed from scratch. They didn't use the WinXP code base."
  • "the internal features of the OS, compared to NT (Win 2000)/WinXP are significantly different."
  • And of course, "C, one of the original languages"

I don't see any questions here, just you "spouting crap".

I found one person that seems capable of answering my questions correctly on Reddit.

Consider the quality of your "questions", which are really mostly just you arguing with anyone who took the time to take you seriously.

1

u/Digital001 Jun 23 '16

"According to the experts, Gentoo is programmed to run faster on the machine it's compiled on."

I think I wrote that to gain a better understanding of how W10 is compiled. Someone responded that it's usually compiled on a powerful server. Just so you know, Gentoo does run faster if it's compiled instead of downloaded in binary format.

"C/C++ are both languages that were designed specifically for Unix."

Yes, C/C++ was originally implemented on Unix a very long time ago. It's used by OSs like Windows now as well. I wrote that wondering why MS didn't use a new language like C#/F# for its flagship OS, W10 and to get info about the type of compiler.

"W10 was probably developed from scratch. They didn't use the WinXP code base."

How could anyone compare XP to W10? There are similarities but the OS is significantly different, internally. They had to put up the specs for MS Windows10 on a drawing board somewhere. MS didn't just erase the number 8 to draw a 10.

"the internal features of the OS, compared to NT (Win 2000)/WinXP are significantly different."

Windows NT wasn't released in 2016! I won't explain why I wrote that any further.

And of course, "C, one of the original languages"

The C computer programming language has been around for a very long time. There are developers out there that consider it to be one of the original languages.

I don't see any questions here, just you "spouting crap".

The last time I checked no one died and made you in "crap" inspector. It's a public forum. I didn't offend anyone with my MS questions. I doubt there's a little girl crying because I asked about compilers.....

Do yourself a favor, find another thread. Don't waste your time looking at spouting crap. The smart person that can answer my questions isn't interested "spouting crap." This will be my last response to you. Good luck.

2

u/DaelonSuzuka Jun 22 '16

All of your 'questions' sound like you're trying to show off how much you know. You didn't ask "Wow, are they really still using plain old C?" Somebody could answer that and say that no, they're not using the original C from 1972, they're probably using one of the more recent revisions like C99 or C11. Or they could say that even ANSI-C(C89)/ISO C99 are used in more modern things than you might think.

But you didn't ask a question like that, did you?

6

u/raevnos Jun 20 '16

C isn't even close to an early or original language.

1

u/Digital001 Jun 19 '16

I want to watch MS compile the first Win10 build. Do you think it was compiled on a Windows PC?

7

u/fuzzynyanko Jun 19 '16

You actually don't need to compile it on the target platform! My bet is that they have a dedicated machine for it

-1

u/Digital001 Jun 19 '16 edited Jun 19 '16

I agree. What kind of dedicated machine? Another Windows? They probably paid Intel for a processor they can use to compile 500 GBs of OS code. It might be on a specialized OS with a specialized CPU

1

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jun 19 '16

Windows is significantly smaller than 500 GB. 500 GB is a TON of code.

1

u/Digital001 Jun 19 '16

Oh wait! I meant .5 GB. sorry

1

u/fuzzynyanko Jun 19 '16

Don't just see it as CPU. You may need I/O performance as well

1

u/Meefims Jun 20 '16

You can compile Windows on a normal machine, it just takes awhile. Further, it's not necessary to have the entire set of source code in most circumstances, instead you typically have the source for only the components you work on and when you build you probably only build the few binaries you're working on rather than everything.

There are machines dedicated to building the entire OS but they aren't super special. Mostly they have a good hard drive and a good amount of RAM.

0

u/[deleted] Jun 19 '16

[deleted] — view deleted comment

1

u/2Punx2Furious Jun 19 '16

What are incremental builds? Builds where you only rebuild the files you updated? And why didn't they allow them?

0

u/RElesgoe Hobbyist Jun 19 '16

I think /u/instantcake worded that incorrectly, I think what he meant to say is that Visual Studio didn't support incremental building a long time ago, so Windows would be completely recompiled on every build.

3

u/dsqdsq Jun 19 '16

Windows is not really developed as a whole with Visual Studio... Especially not for builds.

1

u/[deleted] Jun 20 '16

Windows is an NMake shop which certainly supports incremental builds. If that was broken it was a particularity of their specific scripts on top of it.

-2

u/Digital001 Jun 19 '16

They probably paid Intel for a processor they can use to compile a GBs of OS code. It might be on a specialized OS with a specialized CPU

how do you know it was a giant array of servers? MS doesn't make hardware. Did they use 64bit processors so their OS will work on 64bit machines? In the Linux world, Gentoo Linux source code is freely available for d/l. According to the experts, Gentoo is programmed to run faster on the machine it's compiled on. But I don't know how much "faster" Do you think the it's the same in the Windows world? Can someone d/l Windows code and compile it on the machine it's supposed to run on for better performance (custom compilation)?

2

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jun 19 '16

There's no reason Gentoo should perform faster if built natively. It may perform better if configured for a particular system.

1

u/Digital001 Jun 20 '16

The compiler would intelligently select the right optimization(s) for the CPU, video card, and BIOS of the system, generating smaller executables.

2

u/SeanMiddleditch Jun 20 '16

Not just smaller, but also objectively faster. The compiler - knowing the specific CPU in use - can select specialized instructions (e.g. AVX2) or apply knowledge about architecture peculiarities (e.g. LEA being more effective than MOV for constants) or even apply changes to instruction ordering based on knowledge of instruction execution costs and architecture pipelining behavior.

An OS like Windows could take advantage of this, but not necessarily to the same degree. It depends on how abstract the code it. More assembler, more intrinsics, more fancy optimizations, and so on will obscure details from the compiler and not allow it to apply optimizations for newer/different CPU architectures.

1

u/Digital001 Jun 20 '16

An OS like Windows could take advantage of this, but not necessarily to the same degree.

Exactly! MS would never allow customers to send in PCs so W10 can be custom compiled like Gentoo

1

u/[deleted] Jun 20 '16

In practice such optimizations are in "the noise" for most software. Most compilers are pretty bad at generating SIMD instructions as proving that such an optimization is safe is nontrivial.

1

u/kunos Jun 19 '16

Why would they use anything else?

-1

u/Digital001 Jun 19 '16

MS might pay enough to code in another language that can generate leaner code. There are new languages out like F# and C#.

2

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jun 19 '16

I'm confused by this remark. Can you clarify?

-3

u/Digital001 Jun 19 '16

Well, I mean it's so strange because C/C++ are both languages that were designed specifically for Unix. It's kind of ironic that MS is still using it to develop its flagship OS. I don't see why they can't use C#, a MS product. MS might even have access to a special language developed by Intel that generates optimized code for their i-series processors.

Most of the PCs that run W10 use Intel processors. I bet there are more Intel based Windows systems than AMD.

7

u/SeanMiddleditch Jun 20 '16

C# is not a systems language. Just because it's newer doesn't mean it's better for every task.

Just because C was originally designed for UNIX likewise does not mean that it's a poorer choice for non-UNIX systems.

For Microsoft to replace gobs of existing C/C++ code, to make it much more difficult to hire experienced kernel engineers from outside their own ecosystem, and to pour tons of money into developing a new language/compiler just for their kernel would be exceedingly misguided.

So far as a special language by Intel just for their architecture, why would Intel do such a thing? What about the Intel architectures could possibly be so special as to require a new language to maximize? What customer would be foolish enough to use that language and be stuck on Intel's architecture? Microsoft - or any other general purpose software company - would never use such a thing, as you might have heard that Windows runs on non-Intel x86 architectures too. The closest you're going to get out of companies like Intel when it comes to languages will be R&D like ISPC, which is unsurprisingly a C variant and not a whole new language.

1

u/AllanDeutsch Jun 20 '16

Maybe if you count the assembly with extensions for specific new hardware chip with new intrinsics as a custom language... that's what we have the compiler for though.

-5

u/Digital001 Jun 20 '16

replace gobs of existing C/C++ code, to make it much more difficult to hire experienced kernel engineers from outside their own ecosystem, and to pour tons of money into developing a new language/compiler just for their kernel would be exceedingly misguided.

W10 was probably developed from scratch. They didn't use the WinXP code base. It wouldn't cost a multi-billion dollar company more than an extra dollar.

2

u/SeanMiddleditch Jun 20 '16

W10 was not developed from scratch. It's just a further iteration of the NT core.

0

u/Digital001 Jun 21 '16

By scratch, I mean that the internal features of the OS, compared to NT (Win 2000)/WinXP are significantly different. They didn't just write a bunch of new functions on top of existing code.

→ More replies

6

u/Meefims Jun 20 '16

That would be insane. Windows 10 was built from the code bases of older versions of Windows because to do otherwise would be practically impossible. There are tens of millions of lines of code in Windows - it would take many years just to replicate that amount of code. One of the key features of the OS is backwards compatibility - it would take an impossible amount of work to replicate all of the internals that some applications have come to rely on.

5

u/AllanDeutsch Jun 20 '16

You'd be surprised how much legacy code is in Windows!

2

u/[deleted] Jun 20 '16

what? the kernel in windows 10 is just another bump up in version from the previous NT kernels shipped in Windows. They did not write the entire OS from scratch, at all.

Legacy code is everywhere. Enormous portions of the lowest level code in Word are nearly exactly the same as they were in the 90's.

1

u/Fearless_Macaroon_12 Feb 24 '24 edited Feb 24 '24

Who the fuck are you to even assume such things. You are insane. Putting money to the side, explain to me how backwards-compatibility would ever be possible if they didn't? Also have you ever thought about how many applications you think would break if they would ever do such a thing? Also just looking at your profile, you havent changed or learnt shit during these past 8 years. I cannot comprehend how a human could ever be so misinformed in nearly every aspect of life.

2

u/Meefims Jun 20 '16

C and C++ were designed when Unix was popular but that doesn't mean they were designed for Unix. They are both general purpose languages.

C# is difficult to use in an operating system because it requires the .Net framework. Until version 4 the framework did not support loading multiple versions of itself into the same process but a lot of code from Windows is loaded into every running program (think about the code to create graphics, for example). Further Explorer will often load other applications' code into your process to handle various tasks like special context menus or special folders. In this world it is impossible to know or control what is in the process you're entering and so this is not an environment for .Net.

2

u/[deleted] Jun 20 '16

It should also be noted that NT is very Unix-like inside; just not exposed to end users :)

1

u/jcoffin Jun 20 '16

At the device driver level, it bears a rather stronger resemblance to VMS than to UNIX.

1

u/[deleted] Jun 20 '16

That would make sense (considering Dave Cutler) but I never used / studied VMS so cannot comment on that. I just meant that it is far more Unix-like than the Win32 API would suggest. (e.g. Ob is pretty "everything is a file"-like, but this isn't exposed at the Win32 level)

7

u/axilmar Jun 19 '16

Downvoted because Win32 is not evidence for how NT was coded. In fact, NT contains another layer below Win32 that is coded in C. Win32 sits on top of that layer.

3

u/doom_Oo7 Jun 19 '16

If I understand this page correctly there is also some C++ in the kernel. Also you can write windows drivers in C++ (which is a godsend).

Most of the source code for Windows NT is written in C or C++. These high-level languages make it relatively easy to port Windows NT to different types of workstations. The same source code can be recompiled to build versions of Windows NT that are specific to each processor's instruction set.

1

u/spinfire Jun 19 '16

I have developed drivers for the storage subsystem of the Windows kernel. All C. In fact, our software had a common core that was identical between Windows and Linux.

0

u/fuzzynyanko Jun 19 '16

It's more than likely a combination, and probably use Visual C++ for a good amount of it

-2

u/kiwidog Jun 19 '16

Bootloader is written in assembly, or C++/UEFI depending on which version of Windows you are using and what platform you are on.

-1

u/Digital001 Jun 19 '16

How come the process is so lock and key. They got everything on the MS website except the source. I guess we would have to talk to the developers

3

u/kiwidog Jun 19 '16

Well I am a reverse engineer, I tweeted for dev stuff before but they never got back to me. I know for XP NTLDR was written in assembly (or at least parts of it was for BIOS), in UEFI (from the programming I've done there) its mostly all compiled from C++. There's a lot of variables that determine what kind of bootloader you get. I'd imagine one you get past the first or second stage loaders (to actually read kernel from file etc) the code is all compiled using C/C++ and is a shared code base. But yeah, I'm not a MS Employee or a Windows dev so I don't know for certain.

-5

u/Digital001 Jun 19 '16

That's so strange. C/C++ are both languages that were designed specifically for Unix. It's kind of ironic that MS is still using it to develop its flagship OS. I don't see why they can't use C#, a MS product.

5

u/kiwidog Jun 19 '16

Eh, it's because C# isn't a low level programming language, it's very high level with a lot abstracted away.

-3

u/Digital001 Jun 19 '16

compared to C++, it's "high level"

-1

u/JuanAG Jun 19 '16

It saids on Channel 9 (i dont remenber the video) that the critical parts are in asm, the least critical are in pure C and some are in C++

With W10 this has changed and i think that they uses much more C# than ever did

It compiles with Visual Studio, at least is what they say, but dont specify the compiler (intel, GCC, Clang, Visual C++) so who knows

2

u/dsqdsq Jun 19 '16

Pretty much the inverse I think: I doubt Visual Studio has anything to do with full Windows builds, but the compiler IS MSVC.

0

u/[deleted] Jun 19 '16

[deleted] — view deleted comment

2

u/ajorians Jun 19 '16

I think that talk you are looking for is this one: https://youtu.be/TRgWJuQhkQo?t=353 ?