OpenBSD – Hello World in x64 Assembly

This past week I’ve been learning x86 assembly language on an old laptop, purely because I couldn’t get anything running on my x64 OpenBSD machine. My 64 bit helloworld.s was as follows:

section .data

 msg db "Hello world!", 10
 len equ $-msg

;syscalls
 %define SYS_exit 1
 %define SYS_write 4

section .text

global _start
_start:

 mov rax, SYS_write
 mov rdi, 1 ;stdout
 mov rsi, msg
 mov rdx, len

 syscall

 mov rax, SYS_exit
 xor rdi, rdi

 syscall

Giving the errors:

jon@OpenBsD:~/dev/asm;$ nasm -f elf64 -o helloworld.o helloworld.s
jon@OpenBsD:~/dev/asm;$ ld -o helloworld helloworld.o
ld: warning: creating a DT_TEXTREL in a shared object.
jon@OpenBsD:~/dev/asm;$ yasm -f elf64 -o helloworld.o helloworld.s
jon@OpenBsD:~/dev/asm;$ ld -o helloworld helloworld.o 
ld: helloworld.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
helloworld.o: could not read symbols: Bad value

I did search /usr/src for any assembly files I could straight up copy and test, but I didn’t find anything suitable, however the code looks fine and as the assembler didn’t throw out any errors I’m thinking this to be an issue with the linker.

Running ld with the verbose flag we are shown the options for available architectures:

jon@OpenBsD:~>$ ld -V
GNU ld version 2.17
  Supported emulations:
   elf_x86_64_obsd
   elf_i386_obsd
   elf_i386

Continue reading “OpenBSD – Hello World in x64 Assembly”

OpenBSD (6.0) Home Router

Something about using the black box my ISP provided to control my whole network just didn’t sit right with me, so I decided to ditch it and make my own using the  industrie’s go-to firewall operating system: OpenBSD.

I started with an Alix2d2, a single board x86 machine with low power consumption, and a BT OpenReach modem. Both pre-owned and picked up on Ebay for very reasonable prices, I also had to buy a null modem cable to connect to the Alix, a Ralink RT2561T MiniPCI WLAN module and antenna  for wireless connectivity.

The only way to  install the operating system onto the Alix (apart from copying a snapshot onto the memory card) is a network install, so we will need to setup tftpd and dhcpd.

TFTPD Setup

38400 in the default baud rate for the alix2d2 so I’ve set that in the boot.conf

# mkdir -p /tftpboot/etc
# cd /tftpdboot
# wget http://mirror.bytemark.co.uk/pub/OpenBSD/6.0/i386/bsd.rd
# wget http://mirror.bytemark.co.uk/pub/OpenBSD/6.0/i386/pxeboot
# echo "stty com0 38400
set tty com0
boot tftp:/bsd.rd" >> etc/boot.conf
# tftpd /tftpboot

/etc/dhcpd.conf

The box we’re installing from is 192.168.1.10.

 option domain-name-servers 192.168.1.1;
subnet 192.168.1.0 netmask 255.255.255.0 {
 filename "pxeboot";
 range 192.168.1.8 192.168.1.254;
 option routers 192.168.1.10;
 option broadcast-address 192.168.1.10;
 option subnet-mask 255.255.255.0;

After restarting  dhcpd we are ready to start installing, connect the Alix to the box you’re installing from, connect the null modem cable and boot it up.

Continue reading “OpenBSD (6.0) Home Router”