3

What is the simplest way to export data from a bare-bones OS?

I’m developing some assignments for my Computer Architecture course that require students to time different segments of code as accurately as possible. My idea is to insert the code to be timed right into the "Bare Bones"/"Hello World" tutorial from the OSDev wiki (http://wiki.osdev.org/Bare_Bones), which will effectively run the code under test right inside a minimal OS kernel.

This technique works rather well; but, at the moment, my only output option is the VGA text mode. I would like to be able to save the experiment results so the students can analyze/graph the data.

I’m currently installing the “mini-OS” onto a USB flash drive and booting from the flash drive. My original idea was to use BIOS to dump the experiment data back onto the USB drive; but, it looks like calling BIOS routines from protected mode is non-trivial (i.e., requires switching to real or V86 mode).

All I need to do is dump raw binary data somewhere that another machine can read it. I don't need a file system or anything fancy like that. Is there a relatively simple way to access the USB flash drive (or some other external device), or will I need to find/write a complete USB driver or network driver stack? Or, is there a simpler solution?

This post (Real mode BIOS routine and Protected Mode) mentions PwnOS; but the link to the code is broken.

Community
  • 1
  • 1
Zack
  • 6,232
  • 8
  • 38
  • 68
  • 1
    Since you're on x86, timing on real hardware is actually hard, because of power management (including Turbo). You can use RDTSC (with a serializing instruction to prevent reordering) to count reference cycles, or hardware performance counters to count real core clock cycles. IIRC, there are some links about this in the [x86 tag wiki](http://stackoverflow.com/tags/x86/info). You can get good results on a normal OS with Hyperthreading and Turbo disabled, and CPU affinity set to keep your process on the same core. Timer interrupts can still be a factor, though. – Peter Cordes Oct 13 '16 at 16:56
  • See also http://stackoverflow.com/questions/39864416/perf-overcounting-simple-cpu-bound-loop-mysterious-kernel-work for using perf counters to only count user-space cycles. – Peter Cordes Oct 13 '16 at 17:29

1 Answers1

2

USB drivers are very hard. However, as you mentioned network drivers, you might want to look into serial ports. They are much easier to program than USB.

The osdev wiki should have enough information about this topic.

glauxosdever
  • 652
  • 4
  • 11
  • That would imply having a 2nd machine on the other end of the serial cable listening for the data, correct? – Zack Oct 13 '16 at 18:19
  • Yes, you need another machine. – glauxosdever Oct 13 '16 at 18:25
  • I forgot to mention that you can run your bare bones OS from inside an emulator. This way you can read serial output from your bare bones OS on your host OS. – glauxosdever Oct 13 '16 at 19:01
  • An emulator will work for debugging, but would defeat the purpose of the "miniOS" (unless, of course, Peter's suggestions above produce sufficiently accurate measurements). – Zack Oct 14 '16 at 14:20
  • I mentioned the possibility of running the OS from inside an emulator only because it's a way of reading serial output without having a second computer. – glauxosdever Oct 14 '16 at 14:38