-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgootloader.go
78 lines (54 loc) · 1.36 KB
/
gootloader.go
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
package gootloader
import "C"
import (
"fmt"
"io/ioutil"
"strconv"
)
//Bootloader data structure
type Bootloader struct {
Name string
Arch int // Architecture 32 or 64
ModeBit int // Workspace mode in bits 16 or 32
Instructions []string
Loaddest int
}
const (
_ggl_Halt = "halt: hlt\n"
)
func (r *Bootloader) getName(title string) int {
println(title + r.Name)
return 1
}
func (r *Bootloader) addInstruction(instruction string) int {
r.Instructions = append(r.Instructions, instruction)
return 1
}
func (r *Bootloader) Create() int {
fmt.Println("org " + strconv.Itoa(r.Loaddest))
r.Instructions = append([]string{"org " + strconv.Itoa(r.Loaddest) + "\n"}, r.Instructions...)
r.Instructions = append([]string{"bits " + strconv.Itoa(r.ModeBit) + "\n"}, r.Instructions...)
r.addInstruction(_ggl_Halt)
r.addInstruction("times 510 - ($ - $$) db 0\n")
r.addInstruction("dw 0xAA55")
cInst := ""
for _, element := range r.Instructions {
cInst += element
}
ioutil.WriteFile("./"+r.Name+".asm", []byte(cInst), 0644)
return 1
}
func (r *Bootloader) Print(message string) int {
var loopIns = [...]string{
".loop lodsb\n",
"or al, al\n",
"jz halt\n",
"int 0x10\n",
"jmp .loop\n",
}
for _, element := range loopIns {
r.addInstruction(element)
}
r.addInstruction("msg: db \"" + message + "\", 0\n")
return 1
}