Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(187)

Side by Side Diff: arch/arch.go

Issue 85860043: code review 85860043: ogle: new arch package for architecture-dependent details (Closed)
Patch Set: Created 9 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | program/server/server.go » ('j') | program/server/server.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package arch contains architecture-specific definitions.
6 package arch
7
8 import (
9 "encoding/binary"
10 )
11
12 const MaxBreakpointSize = 4 // TODO
13
14 // Architecture defines the architecture-specific details for a given machine.
15 type Architecture struct {
16 // The size of a breakpoint instruction, in bytes.
nigeltao 2014/04/09 05:23:49 The comment convention is to start with the name o
17 BreakpointSize int
18 // The size of the int type, in bytes.
19 IntSize int
20 // The size of a pointer, in bytes.
21 PointerSize int
22 // The byte order for I/O.
23 ByteOrder binary.ByteOrder
24 BreakpointInstr []byte
nigeltao 2014/04/09 05:23:49 Would it be more consistent with a breakpoint.orig
25 }
26
27 func (a *Architecture) Int(buf []byte) int64 {
28 return int64(a.Uint(buf))
29 }
30
31 func (a *Architecture) Uint(buf []byte) uint64 {
32 if len(buf) != a.IntSize {
33 panic("uint size")
34 }
35 switch a.IntSize {
36 case 4:
37 return uint64(a.ByteOrder.Uint32(buf[:4]))
38 case 8:
39 return a.ByteOrder.Uint64(buf[:8])
40 default:
nigeltao 2014/04/09 05:23:49 Slightly shorter is to drop the default and move t
41 panic("no uint size")
nigeltao 2014/04/09 05:23:49 s/no/bad/ ?
42 }
43 }
44
45 var AMD64 = Architecture{
46 BreakpointSize: 1,
47 IntSize: 8,
48 PointerSize: 8,
49 ByteOrder: binary.LittleEndian,
50 BreakpointInstr: []byte{0xCC}, // INT 3
51 }
52
53 var X86 = Architecture{
54 BreakpointSize: 1,
55 IntSize: 4,
56 PointerSize: 4,
57 ByteOrder: binary.LittleEndian,
58 BreakpointInstr: []byte{0xCC}, // INT 3
59 }
60
61 var ARM = Architecture{
62 BreakpointSize: 4, // TODO
63 IntSize: 4,
64 PointerSize: 4,
65 ByteOrder: binary.LittleEndian,
66 BreakpointInstr: []byte{0x00, 0x00, 0x00, 0x00}, // TODO
67 }
OLDNEW
« no previous file with comments | « no previous file | program/server/server.go » ('j') | program/server/server.go » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b