summaryrefslogtreecommitdiffstats
path: root/installing-hla-on-archlinux.post
blob: 17826c83f096ee1ba46a45dd1152cef7b7c7134c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;;;;;
title: Installing HLA on Archlinux
tags: hla, archlinux, vagrant
date: 2014-12-27 21:43
format: md
;;;;;

I recently started reading
[The Art of Assembly Language, 2nd Edition](http://www.nostarch.com/assembly2.htm).
It uses High-Level Assembly language in its code examples and this
requires a special compiler, or assembler, to turn your code into
machine code.

## Fixing the PKGBUILD

The compiler, `hla`, is available on the Archlinux User Repository
[here](https://aur.archlinux.org/packages/hla/). At the time of
writing, though, that `PKGBUILD` doesn't work entirely. By default
pacman removes all static libraries from the created packages, which
took me a while to find out. Adding the following line to the
`PKGBUILD` fixes it:

    options=(staticlibs)

I also placed a comment on the AUR page, but there has been no sign
of acknowledgment so far.

## Running on x86_64

After having installed the compiler I got a lot of errors compiling
my very simple hello world application, as typed over from the
book. The gist of them was that it couldn't create 64-bit
executables, which isn't very surprising as HLA seems to be only
for x86 (32-bit) architecture. Another comment on the AUR page
helped that though. One should add the `-lmelf_i386` switch to the
`hla` command-line. So I put in my `~/.zshrc`:

    alias hla="hla -lmelf_i386"

This discovery only came after a few other attempts to install HLA.

## Alternative: Using Vagrant

Before I'd read about the `-lmelf_i386` command-line switch I was
looking at ways to run a 32-bit operating system inside my
Archlinux installation. There are a few options I'm familiar with:
lxc, Docker and Vagrant.

At first I tried to create a 32-bit Archlinux container, but the
installation script failed, so I couldn't get that started. Then I
went on to Vagrant, which worked pretty quickly.

I used the `ubuntu/trusty32` box, which can be downloaded by calling:

    vagrant box add ubuntu/trusty32

A very short `Vagrantfile`:

    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    Vagrant.configure(2) do |config|
      config.vm.box = "ubuntu/trusty32"
      config.vm.provision :shell, path: "vagrant.sh"
    end

and then the provision in `vagrant.sh`:

    wget http://www.plantation-productions.com/Webster/HighLevelAsm/HLAv2.16/linux.hla.tar.gz
    tar --directory / --extract --file linux.hla.tar.gz

    cat > /etc/profile.d/hla.sh <<EOF
    #!/usr/bin/bash

    export hlalib=/usr/hla/hlalib
    export hlainc=/usr/hla/include
    export hlatemp=/tmp
    export PATH="${PATH}:/usr/hla"
    EOF

After that you can just call `vagrant up`, wait a while and then have
fun playing around with HLA in an Ubuntu 14.04 environment.