Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create minimal Linux/BusyBox configs for running v86 #213

Closed
humphd opened this issue Jun 7, 2018 · 12 comments
Closed

Create minimal Linux/BusyBox configs for running v86 #213

humphd opened this issue Jun 7, 2018 · 12 comments

Comments

@humphd
Copy link

humphd commented Jun 7, 2018

I'm trying to build an optimal, minimal kernel and BusyBox command set for using v86 using buildroot. Since the v86 hardware is pretty much set, and since running in the browser means I'm not going to extend it at runtime (i.e., don't need tons of drivers), I'm trying to strip down everything I don't need. I'm also trying to align the hardware/cpu/etc with what I can turn on/off in the kernel config.

I'm aware of the 9p docs, and https://github.com/ysangkok/build-v86-9p-linux. However, if people here have some knowledge of this process, what to enable/disable, it would be great to either document it in this bug, or for a base v86_defconfig to get created.

@humphd
Copy link
Author

humphd commented Jun 8, 2018

Documenting as I go, please correct me if I'm wrong.

Based on the cpu definition docs, it seems like buildroot's Target Options should be:

  • Target Architecture: i386
  • Target Architecture Variant: pentium mobile

See https://github.com/buildroot/buildroot/blob/master/arch/Config.in.x86#L55-L59, which defines x86 with SSE and MMX.

@copy
Copy link
Owner

copy commented Jun 12, 2018

Good idea! Let me know about your findings.

A few thoughts:

  • v86 doesn't support all mmx/sse instructions (mostly those operating on floating point numbers). In my experience, applications usually detect mmx/sse support at runtime from cpuid, but compilers may emit mmx/sse instructions if they are configured so
  • v86 does support a few newer instructions with their own cpuid feature bits, like rdrand, popcnt and cmpxchg8, but these are likely detected by cpuid and not at compile time
  • For performance reasons, it's probably a good idea to set HZ to a lower value, such as CONFIG_HZ_100
  • rep movsb, rep stosb, etc. are much faster on v86 than loops, so if you find a configuration that makes the kernel to choose this implementation your memcpy and memset will be faster

@BelleNottelling
Copy link
Contributor

This is something I've wanted to do, but not really known how, @humphd if you could share the final result that would be great! 😁

@humphd
Copy link
Author

humphd commented Jun 12, 2018

I spent the weekend on this and got it working and automated within docker, see humphd/next#83. This defines a custom "board" for v86 with the various tweaks I need (I've got most hardware disabled, plan 9 enabled, and customizations to the startup scripts in /etc).

My build is 4.9M (kernel + rootfs bundled as an ISO), and starts-up with 8M of RAM in use. I'm probably satisfied with this, and won't tweak it too much more, except to research a few of the things you mention above (I did see the CONFIG_HZ_100 in https://github.com/buildroot/buildroot/blob/master/arch/Config.in.x86#L55-L59 already).

Taking what I did for my PR and generalizing it for v86 (i.e., not disabling all the stuff I turned off, or having multiple linux.config versions that let people choose between some various options) would be pretty easy. I'm not sure if you'd want a PR here too, or a separate repo?

When I started playing with v86, I didn't know how to use buildroot, and was forced to try different existing images, each of which had some of what I needed, but not the rest. Now that I understand how it works, it seems like you could spec out a bunch of configurations that work well on v86, and then automate their builds so people can use or tweak.

If any of this is interesting to you, let me know and I'll help make it happen.

@humphd
Copy link
Author

humphd commented Jun 21, 2018

Continuing to work on this, and it's going well. I've run into an issue, which I suspect might be due to v86 and/or how I'm configuring my kernel to work on v86. I have a package I'm building in buildroot that uses ncurses, and it dies when I run it with Illegal instruction. In /var/log/messages I see this:

Jun 21 01:48:13 buildroot kern.info kernel: [  283.355664] traps: nled[711] trap invalid opcode ip:b7f1d9e8 sp:bff37250 error:0 in libncurses.so.6.0[b7f0c000+35000]

@copy any thoughts on this?

@humphd
Copy link
Author

humphd commented Jun 21, 2018

Solved! Changing from Pentium M to Pentium Pro for the Linux Processor config solved it. As you said above, there must be some issues with MMX, SSE, or other bits that the Pentium M was doing that Pentium Pro isn't.

Do you agree that Pentium Pro makes the most sense, considering others in this list? https://github.com/torvalds/linux/blob/master/arch/x86/Kconfig.cpu

@copy
Copy link
Owner

copy commented Jun 21, 2018

Do you agree that Pentium Pro makes the most sense, considering others in this list?

Yes, although I'm not an expert with particular Intel CPUs.

Could you send me the failing Linux image anyway? My guess is that the problem was a floating point SSE1 instruction, but I want to have a quick look just in case it's something simple to implement.

Taking what I did for my PR and generalizing it for v86 (i.e., not disabling all the stuff I turned off, or having multiple linux.config versions that let people choose between some various options) would be pretty easy. I'm not sure if you'd want a PR here too, or a separate repo?

I think having one or a few fine-tuned configs in this repo would be cool. Preferably in a new directory (misc or so).

@humphd
Copy link
Author

humphd commented Jun 21, 2018

Here's the an ISO for the Linux image that crashes. When it boots, run nled. There's not much in there for debugging, but in case it's helpful, here it is.

v86-linux.iso.zip

@copy
Copy link
Owner

copy commented Jun 21, 2018

Indeed the compiler generates F30F2C / CVTTSS2SI for nled, which is one of the floating point instructions we haven't implemented yet.

@humphd
Copy link
Author

humphd commented Feb 7, 2019

Finally got around to splitting out this work into a separate repo, if people want to do their own: https://github.com/humphd/browser-vm

@humphd
Copy link
Author

humphd commented Apr 24, 2019

Also finally finished up the demo that uses all of this stuff:

❤️ v86. Thanks for all the help answering my questions.

@copy
Copy link
Owner

copy commented Jan 4, 2021

@humphd FYI, there's complete SSE2 support now. I also went ahead and linked the browser-vm repo in the readme.

@copy copy closed this as completed Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants