
A x64 OS #1: UEFI - based2
http://kazlauskas.me/entries/x64-uefi-os-1.html
======
webkike
I had no idea UEFI booted directly into long mode... I feel like a moron who
hasn't kept up with the times, but admittedly I'm not super into kernel dev.
Can I just ignore segmentation entirely? It has always been my least favorite
part of programming on x86

~~~
byuu
> I had no idea UEFI booted directly into long mode

I was really surprised to learn that it requires PE executables and Windows'
custom x64 calling convention. I know it's just a small technical detail for
booting ... but it's kind of scary that Microsoft had so much sway in the
design of how our future PCs will boot =(

~~~
yuhong
MS even had to add ARM64 to the PE spec in order to support ARM SBSA. At least
I think the FAT LFN patents has expired by now.

~~~
DiabloD3
Microsoft has granted a patent license for FAT patents for anyone implementing
stuff required for UEFI.

------
shmerl
_> Des­pite my strong at­tach­ment to the Rust com­munity and Rust’s per­fect
suit­ab­il­ity for ker­nels1, I’ll be writ­ing the ker­nel in C. Mostly
be­cause it is un­likely people in­side the uni­ver­sity will be fa­mil­iar
with Rust, but also be­cause GNU-EFI is a C lib­rary and I can­not be bothered
to bind it. I’d surely be writ­ing it in Rust were I more ser­i­ous about the
pro­ject._

I saw an example of booting from UEFI in Rust:
[http://blog.theincredibleholk.org/blog/2013/11/18/booting-
to...](http://blog.theincredibleholk.org/blog/2013/11/18/booting-to-rust/)

~~~
hornetblack
This is quite an old version of rust[1]. I tried this a little while ago (but
got frustrated trying to link it)

[1] For example:

* ` _u16` would now be: `_ const u16` * `int` is no longer a type. * `slice::as_ptr` is now a method, so using transmute to extract the pointer from a slice is probably not ideal. * `core` is a crate that includes things like transmute so you don't need to manually include rust intrinsics etc.

~~~
shmerl
Yes, it's obviously somewhat outdated, since it's from 2013, which was before
the first release.

------
qwertyuiop924
You still can't just ignore BIOS. It might be on the deathrow, but it's still
got plenty of life in it. Hell, knowing Intel, x86 BIOS will be supported
until x86 itself keels over.

Is it okay that I fantasize about that?

~~~
userbinator
Linus Torvalds agrees with me and you, (U)EFI is an overengineered mess that
is complex enough to be an OS itself:

[http://yarchive.net/comp/linux/efi.html](http://yarchive.net/comp/linux/efi.html)

~~~
qwertyuiop924
Huh. Well, if stories are to be believed, it's STILL better than BIOS.

~~~
ori_b
Bios is wonderful because it's limited; Nobody wants to try shoving more
functionality into it. No system management, no drivers, nothing.

The bios loads your kernel, and then you get out and do your own thing. And
that's the advantage of it.

~~~
astrange
EFI drivers are great if you want to repair a machine without taking the boot
disk out.

[http://appleinsider.com/articles/11/07/20/new_macbook_airs_m...](http://appleinsider.com/articles/11/07/20/new_macbook_airs_mac_minis_feature_lion_internet_recovery_disc_less_repair)

[https://en.wikipedia.org/wiki/Target_Disk_Mode](https://en.wikipedia.org/wiki/Target_Disk_Mode)

~~~
userbinator
The ability to boot from the network has been there for traditional BIOS too:

[https://en.wikipedia.org/wiki/Preboot_Execution_Environment](https://en.wikipedia.org/wiki/Preboot_Execution_Environment)

[http://wiki.osdev.org/PXE](http://wiki.osdev.org/PXE)

~~~
voltagex_
PXE is good (someone needs to sit down with me and a bottle of rum and work
out why PXE behaves differently after a hard reboot in VirtualBox), but I've
got to hand it to Apple, Target Disk Mode is _nice_. They also had some kind
of multicast netboot-installer before most OSes.

------
e12e
In case others find it interesting, I tried to look around for any
relationship between linuxbios/seabios and uefi - and found some references
tianocore and edk/edk II:

[https://github.com/tianocore/tianocore.github.io/wiki/EDK_II...](https://github.com/tianocore/tianocore.github.io/wiki/EDK_II_Overview)

Looks like seabios is (mostly) happy being a bios (with possible plans to be
packaged as an "csm application" (I'm guessing that means being loaded from
efi)). But, s far as I can tell, for a free/open uefi toolkit, tianocore is
the project to look at.

I'm a little disappointed that I couldn't easily find a ready-to-run uefi
space invader or tetris clone... ;)

[ed: eh, I see tfa links to tianocore's ovmf code for vms... Oh, well... ]

------
digi_owl
Huh, just the other day i was pondering delivering the OS on a card/chip with
a bit of flash space for storing patches and drivers.

Right now it seems we get into a whole lot of problems because we have the OS
sitting on the same RW space as user files and programs.

~~~
sigcode
Would your idea include small form factor external media as the "card/chip"?

What would be the negatives to this approach?

I have been doing this for many years and have still not found any.

Currently I prefer RO space embedded in the kernel for the "core" OS and
mfs/tmpfs overlay for a RW, larger "additional" OS.

If RW portion crashes, the system falls back to the RO portion.

~~~
digi_owl
Well my initial thought was a PCIe card, but it could likely just as well be
an SD or such if set up right. And yeah, you can get an approximation of it
using _nix and clever mounts.

But i was thinking about having the initial OS sit on an actual ROM chip with
a flash chip next to it on the same board/die.

------
AstralStorm
Sadly, UEFI implementations are as buggy as anything else. Missing start of
Option ROMs? Invalid GPU initialization? I have hit this and more with both
Phoenix and AMI. And also security issues thanks to magic buggy Intel blobs.

At least there is a valid, but hard to compile and deploy reference
implementation.

It is funny that CSM mode is so much more polished and tested than pure UEFI
one. And that so many cards still do not provide compatible firmware.

------
dom96
That's awesome. I hope that I will get to do something similar as part of my
university degree.

------
gp7
hue­hue­hue­hue­hue is a wonderful name for a kernel

~~~
somethingsimple
I was surprised the author is not Brazilian.

~~~
Sylos
Huehuehue has kind of become a meme around the internet...

