| 1 |
package template |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strings" |
| 6 |
"unicode" |
| 7 |
|
| 8 |
"review.coreboot.org/coreboot.git/util/intelp2m/logs" |
| 9 |
"review.coreboot.org/coreboot.git/util/intelp2m/platforms/common/register/bits" |
| 10 |
) |
| 11 |
|
| 12 |
func token(c rune) bool { |
| 13 |
return c != '_' && c != '#' && !unicode.IsLetter(c) && !unicode.IsNumber(c) |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
func Apply(line string) (function string, id string, dw0 uint32, dw1 uint32, err error) { |
| 25 |
|
| 26 |
|
| 27 |
slices := strings.FieldsFunc(line, token) |
| 28 |
number := len(slices) |
| 29 |
if number >= 4 { |
| 30 |
var val uint64 |
| 31 |
fmt.Sscanf(slices[1], "0x%x", &val) |
| 32 |
dw0 = uint32(val & 0xffffffff) |
| 33 |
dw1 = uint32(val >> 32) |
| 34 |
id = slices[2] |
| 35 |
function = slices[3] |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
for i := 4; i < len(slices); i++ { |
| 40 |
function += "/" + slices[i] |
| 41 |
} |
| 42 |
|
| 43 |
dw1 &^= bits.DW1[bits.DW1InterruptSelect] |
| 44 |
return function, id, dw0, dw1, nil |
| 45 |
} |
| 46 |
logs.Errorf("template: more than %d elements are needed", number) |
| 47 |
return "", "", 0, 0, fmt.Errorf("template error") |
| 48 |
} |