wslで、最小のカーネルをコンパイル

# 概要
wslで、kernel.elfのコンパイル、やってみた。

# 環境
Windows10
WSL1（WSL2じゃない）
Ubuntu18.04

# 手順

# build-essentialのインストール

```
sudo apt update

sudo apt install build-essential

```

# kernel.Sを書く。

gas　（nasmじゃない）
grubが起動できるように、multiboot_headerを書く
「hello world」を、表示する。
kernel.S

```
.code32
.globl _start
.globl multiboot_header

.text
_start:
	movl	$0xb8000, %ebx
	movl	$12, %ecx
	movl	$msg, %esi
loop:
	movb	(%esi), %al
	movb	$2, %ah
	movw	%ax, (%ebx)
	addl	$2, %ebx
	addl	$1, %esi
	subl	$1, %ecx
	jne	 	loop
	jmp	 	.

.data
multiboot_header:
	.align 	4
	.long	0x1badb002
	.long	0x0
	.long	-0x1badb002-0x0
msg:
	.ascii 	"Hello world!"

```

# Makefileを書く。

Makefile

```
all: test4.elf
test4.elf: kernel.o
	ld -melf_i386 -e_start -Ttext=0x100000 -o test4.elf kernel.o
kernel.o: kernel.S
	gcc -m32 -c -nostdlib kernel.S
clean:
    $(rm) kernel.o test4.elf
    
```

# makeする。

test4.elfが、できる。

# 確認する。

```
$ readelf -a test4.elf
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x100000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          4432 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         2
  Size of section headers:           40 (bytes)
  Number of section headers:         6
  Section header string table index: 5

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00100000 001000 000023 00  AX  0   0  1
  [ 2] .data             PROGBITS        00101024 001024 000018 00  WA  0   0  4
  [ 3] .symtab           SYMTAB          00000000 00103c 0000b0 10      4   6  4
  [ 4] .strtab           STRTAB          00000000 0010ec 00003c 00      0   0  1
  [ 5] .shstrtab         STRTAB          00000000 001128 000027 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x00100000 0x00100000 0x00023 0x00023 R E 0x1000
  LOAD           0x001024 0x00101024 0x00101024 0x00018 0x00018 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text
   01     .data

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type Intel 80386 is not currently supported.

Symbol table '.symtab' contains 11 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00100000     0 SECTION LOCAL  DEFAULT    1
     2: 00101024     0 SECTION LOCAL  DEFAULT    2
     3: 00000000     0 FILE    LOCAL  DEFAULT  ABS kernel.o
     4: 00101030     0 NOTYPE  LOCAL  DEFAULT    2 msg
     5: 0010000f     0 NOTYPE  LOCAL  DEFAULT    1 loop
     6: 00100000     0 NOTYPE  GLOBAL DEFAULT    1 _start
     7: 00101024     0 NOTYPE  GLOBAL DEFAULT    2 multiboot_header
     8: 0010103c     0 NOTYPE  GLOBAL DEFAULT    2 __bss_start
     9: 0010103c     0 NOTYPE  GLOBAL DEFAULT    2 _edata
    10: 0010103c     0 NOTYPE  GLOBAL DEFAULT    2 _end

No version information found in this file.
```


以上。