code:
/* autogenerated by dtc, do not edit */

	.globl	dt_blob_start
dt_blob_start:
_dt_blob_start:
	.globl	dt_header
dt_header:
_dt_header:
	/* magic */
	.byte 0xd0; .byte 0x0d; .byte 0xfe; .byte 0xed
	/* totalsize */
	.byte	((_dt_blob_abs_end - _dt_blob_start) >> 24) & 0xff
	.byte	((_dt_blob_abs_end - _dt_blob_start) >> 16) & 0xff
	.byte	((_dt_blob_abs_end - _dt_blob_start) >> 8) & 0xff
	.byte	(_dt_blob_abs_end - _dt_blob_start) & 0xff
	/* off_dt_struct */
	.byte	((_dt_struct_start - _dt_blob_start) >> 24) & 0xff
	.byte	((_dt_struct_start - _dt_blob_start) >> 16) & 0xff
	.byte	((_dt_struct_start - _dt_blob_start) >> 8) & 0xff
	.byte	(_dt_struct_start - _dt_blob_start) & 0xff
	/* off_dt_strings */
	.byte	((_dt_strings_start - _dt_blob_start) >> 24) & 0xff
	.byte	((_dt_strings_start - _dt_blob_start) >> 16) & 0xff
	.byte	((_dt_strings_start - _dt_blob_start) >> 8) & 0xff
	.byte	(_dt_strings_start - _dt_blob_start) & 0xff
	/* off_mem_rsvmap */
	.byte	((_dt_reserve_map - _dt_blob_start) >> 24) & 0xff
	.byte	((_dt_reserve_map - _dt_blob_start) >> 16) & 0xff
	.byte	((_dt_reserve_map - _dt_blob_start) >> 8) & 0xff
	.byte	(_dt_reserve_map - _dt_blob_start) & 0xff
	/* version */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x10
	/* last_comp_version */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x10
	/* boot_cpuid_phys */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	/* size_dt_strings */
	.byte	((_dt_strings_end - _dt_strings_start) >> 24) & 0xff
	.byte	((_dt_strings_end - _dt_strings_start) >> 16) & 0xff
	.byte	((_dt_strings_end - _dt_strings_start) >> 8) & 0xff
	.byte	(_dt_strings_end - _dt_strings_start) & 0xff
	.balign	8
	.globl	dt_reserve_map
dt_reserve_map:
_dt_reserve_map:
/* Memory reserve map from source file */
	.long	0, 0
	.long	0, 0
	.globl	dt_struct_start
dt_struct_start:
_dt_struct_start:
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	""
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x54; .byte 0x68; .byte 0x65; .byte 0x63
	.byte 0x75; .byte 0x73; .byte 0x20; .byte 0x4e
	.byte 0x31; .byte 0x32; .byte 0x30; .byte 0x30
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"cpus"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"PowerPC,8347@0"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x63; .byte 0x70; .byte 0x75; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x31
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x20
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x43
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x20
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x55
	.byte 0x00; .byte 0x00; .byte 0x80; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x62
	.byte 0x00; .byte 0x00; .byte 0x80; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x6f
	.byte 0x03; .byte 0xf9; .byte 0x40; .byte 0xaa
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x82
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x90
	.byte 0x0f; .byte 0xe5; .byte 0x02; .byte 0xaa
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"memory"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x07
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x6d; .byte 0x65; .byte 0x6d; .byte 0x6f
	.byte	0x72
	.byte	0x79
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x08; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"soc8347@e0000000"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x73; .byte 0x6f; .byte 0x63; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0b
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x73; .byte 0x69; .byte 0x6d; .byte 0x70
	.byte 0x6c; .byte 0x65; .byte 0x2d; .byte 0x62
	.byte	0x75
	.byte	0x73
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0c
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xab
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0xe0; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x10; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0xe0; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x02; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x82
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"wdt@200"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x09
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x77; .byte 0x61; .byte 0x74; .byte 0x63
	.byte 0x68; .byte 0x64; .byte 0x6f; .byte 0x67
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0c
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x6d; .byte 0x70; .byte 0x63; .byte 0x38
	.byte 0x33; .byte 0x78; .byte 0x78; .byte 0x5f
	.byte 0x77; .byte 0x64; .byte 0x74; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x02; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"i2c@3000"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x73; .byte 0x6c; .byte 0x2d
	.byte 0x69; .byte 0x32; .byte 0x63; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x30; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0e
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xd9
	.balign	4
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"rtc@32"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0f
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x72; .byte 0x69; .byte 0x63; .byte 0x6f
	.byte 0x68; .byte 0x2c; .byte 0x72; .byte 0x73
	.byte 0x35; .byte 0x63; .byte 0x33; .byte 0x37
	.byte	0x32
	.byte	0x61
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x32
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"fan@2e"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0e
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x69; .byte 0x6e; .byte 0x74
	.byte 0x65; .byte 0x6b; .byte 0x2c; .byte 0x66
	.byte 0x37; .byte 0x35; .byte 0x33; .byte 0x37
	.byte	0x35
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2e
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"i2c@3100"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x73; .byte 0x6c; .byte 0x2d
	.byte 0x69; .byte 0x32; .byte 0x63; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x31; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0f
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xd9
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"usb@22000"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x73; .byte 0x6c; .byte 0x2d
	.byte 0x75; .byte 0x73; .byte 0x62; .byte 0x32
	.byte 0x2d; .byte 0x6d; .byte 0x70; .byte 0x68
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x02; .byte 0x20; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x10; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x27
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x05
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xdf
	.byte 0x75; .byte 0x6c; .byte 0x70; .byte 0x69
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xe8
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xee
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"ethernet@24000"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x6e; .byte 0x65; .byte 0x74; .byte 0x77
	.byte 0x6f; .byte 0x72; .byte 0x6b; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x05
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x54; .byte 0x53; .byte 0x45; .byte 0x43
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x67; .byte 0x69; .byte 0x61; .byte 0x6e
	.byte 0x66; .byte 0x61; .byte 0x72; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x02; .byte 0x40; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x10; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0c
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xab
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x02; .byte 0x40; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x10; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xf4
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte	0x0
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x18
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x20
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x22
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.balign	4
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"mdio@520"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x11
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x73; .byte 0x6c; .byte 0x2c
	.byte 0x67; .byte 0x69; .byte 0x61; .byte 0x6e
	.byte 0x66; .byte 0x61; .byte 0x72; .byte 0x2d
	.byte 0x6d; .byte 0x64; .byte 0x69; .byte 0x6f
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x05; .byte 0x20
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x20
	.balign	4
	.globl	phy0
phy0:
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"ethernet-phy@11"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x11
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x65; .byte 0x74; .byte 0x68; .byte 0x65
	.byte 0x72; .byte 0x6e; .byte 0x65; .byte 0x74
	.byte 0x2d; .byte 0x70; .byte 0x68; .byte 0x79
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x11
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.globl	phy0_end
phy0_end:
	.globl	phy1
phy1:
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"ethernet-phy@5"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x05
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0d
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x65; .byte 0x74; .byte 0x68; .byte 0x65
	.byte 0x72; .byte 0x6e; .byte 0x65; .byte 0x74
	.byte 0x2d; .byte 0x70; .byte 0x68; .byte 0x79
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x11
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.globl	phy1_end
phy1_end:
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"ethernet@25000"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x6e; .byte 0x65; .byte 0x74; .byte 0x77
	.byte 0x6f; .byte 0x72; .byte 0x6b; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x05
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x54; .byte 0x53; .byte 0x45; .byte 0x43
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x67; .byte 0x69; .byte 0x61; .byte 0x6e
	.byte 0x66; .byte 0x61; .byte 0x72; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x02; .byte 0x50; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x10; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x0c
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xab
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x02; .byte 0x50; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x10; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xf4
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte	0x0
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x18
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x23
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x24
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x25
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.globl	serial0
serial0:
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"serial@4500"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x07
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x73; .byte 0x65; .byte 0x72; .byte 0x69
	.byte	0x61
	.byte	0x6c
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x6e; .byte 0x73; .byte 0x31; .byte 0x36
	.byte 0x35; .byte 0x35; .byte 0x30; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x45; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x90
	.byte 0x0f; .byte 0xe5; .byte 0x02; .byte 0xaa
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x09
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.globl	serial0_end
serial0_end:
	.globl	ipic
ipic:
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"pic@700"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x1f
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x34
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0x00; .byte 0x00; .byte 0x07; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x05
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x69; .byte 0x70; .byte 0x69; .byte 0x63
	.byte	0x0
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x11
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.globl	ipic_end
ipic_end:
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"pci@e0008500"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xb2
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x10
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x45
	.byte 0x00; .byte 0x00; .byte 0xf8; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x07
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x1c
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x58
	.byte 0x00; .byte 0x00; .byte 0x80; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x14
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xc8
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xbd
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x42
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x66
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x30
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xab
	.byte 0x02; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x80; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x80; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x20; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x01; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0xe2; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x00
	.byte 0x00; .byte 0x10; .byte 0x00; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x90
	.byte 0x03; .byte 0xf9; .byte 0x40; .byte 0xaa
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x34
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x15
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x06
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x10
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x2d
	.byte 0xe0; .byte 0x00; .byte 0x85; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x00
	.byte 0xe0; .byte 0x00; .byte 0x83; .byte 0x00
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x08
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x10
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0xa0
	.byte 0x66; .byte 0x73; .byte 0x6c; .byte 0x2c
	.byte 0x6d; .byte 0x70; .byte 0x63; .byte 0x38
	.byte 0x33; .byte 0x34; .byte 0x39; .byte 0x2d
	.byte 0x70; .byte 0x63; .byte 0x69; .byte 0x00
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x04
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x21
	.byte 0x70; .byte 0x63; .byte 0x69; .byte 0x00
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_BEGIN_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x01
	.string	"chosen"
	.balign	4
	/* FDT_PROP */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x03
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x1e
	.byte 0x00; .byte 0x00; .byte 0x01; .byte 0x70
	.byte 0x2f; .byte 0x73; .byte 0x6f; .byte 0x63
	.byte 0x38; .byte 0x33; .byte 0x34; .byte 0x37
	.byte 0x40; .byte 0x65; .byte 0x30; .byte 0x30
	.byte 0x30; .byte 0x30; .byte 0x30; .byte 0x30
	.byte 0x30; .byte 0x2f; .byte 0x73; .byte 0x65
	.byte 0x72; .byte 0x69; .byte 0x61; .byte 0x6c
	.byte 0x40; .byte 0x34; .byte 0x35; .byte 0x30
	.byte	0x30
	.byte	0x0
	.balign	4
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_END_NODE */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x02
	/* FDT_END */
	.byte 0x00; .byte 0x00; .byte 0x00; .byte 0x09
	.globl	dt_struct_end
dt_struct_end:
_dt_struct_end:
	.globl	dt_strings_start
dt_strings_start:
_dt_strings_start:
	.string "model"
	.string "#address-cells"
	.string "#size-cells"
	.string "device_type"
	.string "reg"
	.string "d-cache-line-size"
	.string "i-cache-line-size"
	.string "d-cache-size"
	.string "i-cache-size"
	.string "timebase-frequency"
	.string "bus-frequency"
	.string "clock-frequency"
	.string "compatible"
	.string "ranges"
	.string "cell-index"
	.string "interrupts"
	.string "interrupt-parent"
	.string "dfsrr"
	.string "phy_type"
	.string "port0"
	.string "port1"
	.string "local-mac-address"
	.string "phy-handle"
	.string "linux,phandle"
	.string "interrupt-controller"
	.string "#interrupt-cells"
	.string "interrupt-map-mask"
	.string "interrupt-map"
	.string "bus-range"
	.string "linux,stdout-path"
	.globl	dt_strings_end
dt_strings_end:
_dt_strings_end:
	.globl	dt_blob_end
dt_blob_end:
_dt_blob_end:
	.globl	dt_blob_abs_end
dt_blob_abs_end:
_dt_blob_abs_end:


code:
/Makefile/1.4/Mon Feb 15 13:44:57 2010//TOPENBSD_5_8_BASE
/Makefile.inc/1.3/Mon Jun  9 15:01:56 2008//TOPENBSD_5_8_BASE
D/boot////
D/mbr////
D/mkboot////

path: sys/arch/socppc/stand/CVS/Entries

license: unknown


code: src/sys/arch/socppc/stand

path: sys/arch/socppc/stand/CVS/Repository


code:
#	$OpenBSD: Makefile,v 1.4 2010/02/15 13:44:57 kettenis Exp $

SUBDIR=	mkboot mbr boot

.include <bsd.subdir.mk>

path: sys/arch/socppc/stand/Makefile


code:
#	$OpenBSD: Makefile.inc,v 1.3 2008/06/09 15:01:56 deraadt Exp $

.if exists(${STANDIR}/mkboot/mkboot)
MKBOOT=${STANDIR}/mkboot/mkboot
.else
MKBOOT=${STANDIR}/mkboot/${__objdir}/mkboot
.endif

BINDIR=/usr/mdec
MANSUBDIR=socppc


path: sys/arch/socppc/stand/boot/CVS/Entries


path: sys/arch/socppc/stand/boot/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.15 2014/07/13 09:26:08 jasper Exp $

.include "${.CURDIR}/../Makefile.inc"

MAN=	boot.8
MLINKS=	boot.8 boot.conf.5

.if ${MACHINE} == "socppc"
PROG=		boot
S=		${.CURDIR}/../../../..

.PATH:		${S}/stand/boot
.PATH:		${S}/lib/libsa

CPPFLAGS+=	-D_STANDALONE
CPPFLAGS+= 	-nostdinc -I../.. -I. -I${.CURDIR} -I${S}
CPPFLAGS+=	-DCONADDR=0xe0004500UL -DCONSPEED=115200
CPPFLAGS+=	-DNS16550_FREQ=266000000 -DMACHINE_CMD=cmd_machine

COPTS+=		-ffreestanding -fno-stack-protector -ffixed-r29 -msoft-float
COPTS+=		-fno-pie

SRCS=		start.S
SRCS+=		boot.c cmd.c vars.c
SRCS+=		conf.c devopen.c exec.c machdep.c dev_socppc.c time.c
SRCS+=		clock.c ns16550.c wd.c wdc.c pciide.c wdc_obio.c fdt.c
SRCS+=		ctime.c strtol.c cmd_socppc.c

.PATH:	${S}/lib/libkern/arch/powerpc ${S}/lib/libkern
SRCS+=	getchar.c putchar.c strlcpy.c strlen.c ashrdi3.c moddi3.c

### find out what to use for libz
Z_AS=		library
.include "${S}/lib/libz/Makefile.inc"
LIBZ=		${ZLIB}

### find out what to use for libsa
SA_AS=          library
SAREL=
SA_ZLIB=	yes
USE_LOADFILE=	yes
.include "${S}/lib/libsa/Makefile.inc"
LIBSA=          ${SALIB}

STANDIR=	${.CURDIR}/..

RELOC=		0x100000
LDFLAGS=	-Ttext ${RELOC} -nopie
OBJCOPY?=	objcopy

${PROG}: ${OBJS} ${LIBSA} ${LIBZ}
	${LD} ${LDFLAGS} -o ${PROG}.elf ${OBJS} ${LIBSA} ${LIBZ}
	${OBJCOPY} -O binary ${PROG}.elf ${PROG}.bin
	${MKBOOT} -e ${RELOC} -l ${RELOC} ${PROG}.bin ${PROG}

realinstall:
	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} \
	    -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}/${PROG}
	${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} -o ${BINOWN} -g ${BINGRP} \
	    -m ${BINMODE} ${PROG}.elf ${DESTDIR}${BINDIR}/${PROG}.elf

.if !make(obj)
.BEGIN:
	@([ -h machine ] || ln -s ${.CURDIR}/../../../${MACHINE}/include machine)
	@([ -h powerpc ] || ln -s ${.CURDIR}/../../../powerpc/include powerpc)
.NOPATH: machine powerpc
CLEANFILES+=	machine powerpc
.endif

.else
NOPROG=
.endif

.include <bsd.prog.mk>

path: sys/arch/socppc/stand/boot/Makefile


code:
/*	$OpenBSD: clock.c,v 1.2 2008/06/26 05:42:13 ray Exp $	*/
/*	$NetBSD: clock.c,v 1.1 2003/06/25 17:24:22 cdi Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Manuel Bouyer.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/types.h>

#include "libsa.h"

#define DELAY_CALIBRATE	1000

void
delay(int ms)
{
	/*
	 * XXX need *real* clock calibration.
	 */
	volatile register int N = ms * DELAY_CALIBRATE;
	for (; --N;)
		;
}


code:
/*	$OpenBSD: cmd_socppc.c,v 1.1 2009/09/11 17:45:01 dms Exp $	*/

/*
 * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include "fdt.h"
#include "stand/boot/cmd.h"

int Xfdt(void);
int Xbats(void);

const struct cmd_table cmd_machine[] = {
	{ "fdt",	CMDT_CMD, Xfdt },
	{ NULL, 0 }
};

int
Xfdt(void)
{
	extern int fdtaddrsave;
	if (fdtaddrsave)
		fdt_print_tree();
	else
		printf("FDT blob not available\n");
	return 0;
}


code:
/*	$OpenBSD: conf.c,v 1.7 2013/12/28 02:53:04 deraadt Exp $	*/
/*	$NetBSD: conf.c,v 1.4 2005/12/11 12:17:06 christos Exp $	*/

/*
 * Copyright (c) 1982, 1986, 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)conf.c	8.1 (Berkeley) 6/10/93
 */

#include <sys/param.h>

#include <dev/cons.h>

#include "libsa.h"
#include <lib/libsa/ufs.h>

const char version[] = "1.1";
int	debug = 0;

/*
 * Device configuration
 */
struct devsw devsw[] = {
	{ "wd",	wdstrategy, wdopen, wdclose, noioctl },
};
int ndevs = nitems(devsw);

/*
 * Filesystem configuration
 */
struct fs_ops file_system[] = {
	{ ufs_open,    ufs_close,    ufs_read,    ufs_write,    ufs_seek,
	  ufs_stat,    ufs_readdir }
};
int nfsys = nitems(file_system);

/*
 * Console configuration
 */
struct consdev constab[] = {
	{ com_probe, com_init, com_getc, com_putc },
	{ NULL }
};
struct consdev *cn_tab;


code:
/*	$OpenBSD: dev_socppc.c,v 1.4 2014/07/13 09:26:08 jasper Exp $	*/

/*
 * Copyright (c) 2008 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <dev/cons.h>

#include "libsa.h"

const char cdevs[][4] = {
	"cn", "", "", "", "", "", "", "",
	"", "", "", "", "com"
};
const int ncdevs = nitems(cdevs);

void
devboot(dev_t dev, char *p)
{
	strlcpy(p, "wd0a", 5);
}

int
cnspeed(dev_t dev, int sp)
{
	return CONSPEED;
}

char ttyname_buf[8];

char *
ttyname(int fd)
{
	snprintf(ttyname_buf, sizeof ttyname_buf, "%s%d",
	    cdevs[major(cn_tab->cn_dev)], minor(cn_tab->cn_dev));

	return ttyname_buf;
}

dev_t
ttydev(char *name)
{
	int i, unit = -1;
	char *no = name + strlen(name) - 1;

	while (no >= name && *no >= '0' && *no <= '9')
		unit = (unit < 0 ? 0 : (unit * 10)) + *no-- - '0';
	if (no < name || unit < 0)
		return NODEV;
	for (i = 0; i < ncdevs; i++)
		if (strncmp(name, cdevs[i], no - name + 1) == 0)
			return (makedev(i, unit));
	return NODEV;
}


code:
/*	$OpenBSD: devopen.c,v 1.2 2008/06/26 05:42:13 ray Exp $	*/
/*	$NetBSD: devopen.c,v 1.1 2003/06/25 17:24:22 cdi Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Rolf Grossmann.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "libsa.h"

#define MAXDEVNAME      16

/*
 * Parse a device spec.
 *
 * [A-Za-z]*[0-9]*[A-Za-z]:file
 *    dev   uint    part
 */
int
devparse(const char *fname, int *dev, int *unit, int *part, const char **file)
{
	const char *s;

	*unit = 0;	/* default to wd0a */
	*part = 0;
	*dev  = 0;

	s = strchr(fname, ':');
	if (s != NULL) {
		int devlen;
		int i, u, p;
		struct devsw *dp;
		char devname[MAXDEVNAME];

		devlen = s - fname;
		if (devlen > MAXDEVNAME)
			return (EINVAL);

		/* extract device name */
		for (i = 0; isalpha(fname[i]) && (i < devlen); i++)
			devname[i] = fname[i];
		devname[i] = 0;

		if (!isdigit(fname[i]))
			return (EUNIT);

		/* device number */
		for (u = 0; isdigit(fname[i]) && (i < devlen); i++)
			u = u * 10 + (fname[i] - '0');

		if (!isalpha(fname[i]))
			return (EPART);

		/* partition number */
		if (i < devlen)
			p = fname[i++] - 'a';

		if (i != devlen)
			return (ENXIO);

		/* check device name */
		for (dp = devsw, i = 0; i < ndevs; dp++, i++) {
			if (dp->dv_name && !strcmp(devname, dp->dv_name))
				break;
		}

		if (i >= ndevs)
			return (ENXIO);

		*unit = u;
		*part = p;
		*dev  = i;
		fname = ++s;
	}

	*file = fname;

	return (0);
}

int
devopen(struct open_file *f, const char *fname, char **file)
{
	struct devsw *dp;
	int dev, unit, part, error;

	error = devparse(fname, &dev, &unit, &part, (const char **)file);
	if (error)
		return (error);

	dp = &devsw[dev];
	if ((void *)dp->dv_open == (void *)nodev)
		return (ENXIO);

	f->f_dev = dp;

	return (*dp->dv_open)(f, unit, part);
}


code:
/*	$OpenBSD: exec.c,v 1.3 2009/09/07 21:16:57 dms Exp $	*/

/*
 * Copyright (c) 2006 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>

#include <lib/libsa/stand.h>
#include <lib/libsa/loadfile.h>

#include <sys/reboot.h>
#include <stand/boot/cmd.h>

typedef void (*startfuncp)(int, int, u_int32_t, char *, int) __dead;

void
run_loadfile(u_long *marks, int howto)
{
	char args[512];			/* Should check size? */
	u_int32_t entry;
	char *cp;
	void *ssym, *esym;
	int l;

	snprintf(args, sizeof(args), "%s:%s -", cmd.bootdev, cmd.image);
	cp = args + strlen(args);

	*cp++ = ' ';
        *cp = '-';
        if (howto & RB_ASKNAME)
                *++cp = 'a';
        if (howto & RB_CONFIG)
                *++cp = 'c';
        if (howto & RB_SINGLE)
                *++cp = 's';
        if (howto & RB_KDB)
                *++cp = 'd';
        if (*cp == '-')
		*--cp = 0;
	else
		*++cp = 0;

	entry = marks[MARK_ENTRY];
	ssym = (void *)marks[MARK_SYM];
	esym = (void *)marks[MARK_END];

	/*
	 * Stash pointer to end of symbol table after the argument
	 * strings.
	 */
	l = strlen(args) + 1;
	bcopy(&ssym, args + l, sizeof(ssym));
	l += sizeof(ssym);
	bcopy(&esym, args + l, sizeof(esym));
	l += sizeof(esym);
	extern int fdtaddrsave;

	(*(startfuncp)(marks[MARK_ENTRY]))(fdtaddrsave, 0, entry, args, l);

	/* NOTREACHED */
}


code:
/*     $OpenBSD: fdt.c,v 1.4 2010/06/26 23:24:44 guenther Exp $       */

/*
 * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <machine/fdt.h>

#include "libsa.h"

unsigned int fdt_check_head(void *);
char	*fdt_get_str(u_int32_t);
void	*skip_property(u_int32_t *);
void	*skip_props(u_int32_t *);
void	*skip_node_name(u_int32_t *);
void	*fdt_parent_node_recurse(void *, void *);
void	*fdt_find_node_recurse(void *, char *);
void 	 fdt_print_node_recurse(void *, int);

static int tree_inited = 0;
static struct fdt tree;

unsigned int
fdt_check_head(void *fdt)
{
	struct fdt_head *fh;
	u_int32_t *ptr;

	fh = fdt;
	ptr = (u_int32_t *)fdt;

	if (fh->fh_magic != FDT_MAGIC)
		return 0;

	if (fh->fh_version > FDT_CODE_VERSION)
		return 0;

	if (*(ptr + (fh->fh_struct_off / 4)) != FDT_NODE_BEGIN)
		return 0;

	/* check for end signature on version 17 blob */
	if ((fh->fh_version >= 17) & (*(ptr + fh->fh_struct_size) != FDT_END))
		return 0;

	return fh->fh_version;
}

/*
 * Initializes internal structures of module.
 * Has to be called once, preferably in machdep.c.
 */
int
fdt_init(void *fdt)
{
	int version;

	bzero(&tree, sizeof(struct fdt));
	tree_inited = 0;

	if (!fdt)
		return 0;

	if (!(version = fdt_check_head(fdt)))
		return 0;

	tree.header = (struct fdt_head *)fdt;
	tree.tree = (char *)fdt + tree.header->fh_struct_off;
	tree.strings = (char *)fdt + tree.header->fh_strings_off;
	tree.memory = (char *)fdt + tree.header->fh_reserve_off;
	tree.version = version;

	if (version < 3) {
		if ((tree.strings < tree.tree) && (tree.tree < tree.memory))
			tree.strings_size = tree.tree - tree.strings;
		else if ((tree.strings < tree.memory) && (tree.memory <
		    tree.tree))
			tree.strings_size = tree.memory - tree.strings;
		else if ((tree.strings < tree.tree) && (tree.memory <
		    tree.strings))
			tree.strings_size = tree.tree - tree.strings;
		else if ((tree.strings < tree.memory) && (tree.tree <
		    tree.strings))
			tree.strings_size = tree.memory - tree.strings;
		else
			tree.strings_size = tree.header->fh_size -
			    (int)tree.strings;
	} else
		tree.strings_size = tree.header->fh_strings_size;

	tree.strings_size = tree.header->fh_strings_size;
	tree_inited = 1;

	return version;
}

/*
 * Retrieve string pointer from srtings table.
 */
char *
fdt_get_str(u_int32_t num)
{
	if (num > tree.strings_size)
		return NULL;
	return (tree.strings) ? (tree.strings + num) : NULL;
}

/*
 * Utility functions for skipping parts of tree.
 */
void *
skip_property(u_int32_t *ptr)
{
	u_int32_t size;

	size = *(ptr + 1);
	/* move forward by magic + size + nameid + rounded up property size */
	ptr += 3 + roundup(size, sizeof(u_int32_t)) / sizeof(u_int32_t);

	return ptr;
}

void *
skip_props(u_int32_t *ptr)
{
	while (*ptr == FDT_PROPERTY) {
		ptr = skip_property(ptr);
	}
	return ptr;
}

void *
skip_node_name(u_int32_t *ptr)
{
	/* skip name, aligned to 4 bytes, this is NULL term., so must add 1 */
	return ptr + roundup(strlen((char *)ptr) + 1,
	    sizeof(u_int32_t)) / sizeof(u_int32_t);
}

/*
 * Retrieves node property, the returned pointer is inside the fdt tree,
 * so we should not modify content pointed by it directly.
 */
int
fdt_node_property(void *node, char *name, char **out)
{
	u_int32_t *ptr;
	u_int32_t nameid;
	char *tmp;

	if (!tree_inited)
		return 0;

	ptr = (u_int32_t *)node;

	if (*ptr != FDT_NODE_BEGIN)
		return 0;

	ptr = skip_node_name(ptr + 1);

	while (*ptr == FDT_PROPERTY) {
		nameid = *(ptr + 2); /* id of name in strings table */
		tmp = fdt_get_str(nameid);
		if (!strcmp(name, tmp)) {
			*out = (char *)(ptr + 3); /* begining of the value */
			return *(ptr + 1); /* size of value */
		}
		ptr = skip_property(ptr);
	}
	return 0;
}

/*
 * Retrieves next node, skipping all the children nodes of the pointed node
 * if passed 0 wil return first node of the tree (root)
 */
void *
fdt_next_node(void *node)
{
	u_int32_t *ptr;

	if (!tree_inited)
		return NULL;

	ptr = node;

	if (!node) {
		ptr = tree.tree;
		return (*ptr == FDT_NODE_BEGIN) ? ptr : NULL;
	}

	if (*ptr != FDT_NODE_BEGIN)
		return NULL;

	ptr++;

	ptr = skip_node_name(ptr);
	ptr = skip_props(ptr);

	/* skip children */
	while (*ptr == FDT_NODE_BEGIN)
		ptr = fdt_next_node(ptr);

	return (*ptr == FDT_NODE_END) ? (ptr + 1) : NULL;
}

/*
 * Retrieves next node, skipping all the children nodes of the pointed node
 */
void *
fdt_child_node(void *node)
{
	u_int32_t *ptr;

	if (!tree_inited)
		return NULL;

	ptr = node;

	if (*ptr != FDT_NODE_BEGIN)
		return NULL;

	ptr++;

	ptr = skip_node_name(ptr);
	ptr = skip_props(ptr);
	/* check if there is a child node */
	return (*ptr == FDT_NODE_BEGIN) ? (ptr) : NULL;
}

/*
 * Retrieves node name.
 */
char *
fdt_node_name(void *node)
{
	u_int32_t *ptr;

	if (!tree_inited)
		return NULL;

	ptr = node;

	if (*ptr != FDT_NODE_BEGIN)
		return NULL;

	return (char *)(ptr + 1);
}

void *
fdt_find_node(char *name)
{
	void *node = fdt_next_node(0);
	const char *p = name;

	if (!tree_inited)
		return NULL;

	if (*p != '/')
		return NULL;

	while (*p) {
		void *child;
		const char *q;

		while (*p == '/')
			p++;
		if (*p == 0)
			return node;
		q = strchr(p, '/');
		if (q == NULL)
			q = p + strlen(p);

		for (child = fdt_child_node(node); child;
		     child = fdt_next_node(child)) {
			if (strncmp(p, fdt_node_name(child), q - p) == 0) {
				node = child;
				break;
			}
		}

		p = q;
	}

	return node;
}

void *
fdt_parent_node_recurse(void *pnode, void *child)
{
	void *node = fdt_child_node(pnode);
	void *tmp;

	while (node && (node != child)) {
		if ((tmp = fdt_parent_node_recurse(node, child)))
			return tmp;
		node = fdt_next_node(node);
	}
	return (node) ? pnode : NULL;
}

void *
fdt_parent_node(void *node)
{
	void *pnode = fdt_next_node(0);

	if (!tree_inited)
		return NULL;

	return fdt_parent_node_recurse(pnode, node);
}

/*
 * Debug methods for printing whole tree, particular odes and properies
 */
void *
fdt_print_property(void *node, int level)
{
	u_int32_t *ptr;
	char *tmp, *value;
	int cnt;
	u_int32_t nameid, size;

	ptr = (u_int32_t *)node;

	if (!tree_inited)
		return NULL;

	if (*ptr != FDT_PROPERTY)
		return ptr; /* should never happen */

	/* extract property name_id and size */
	size = *++ptr;
	nameid = *++ptr;

	for (cnt = 0; cnt < level; cnt++)
		printf("\t");

	tmp = fdt_get_str(nameid);
	printf("\t%s : ", tmp ? tmp : "NO_NAME");

	ptr++;
	value = (char *)ptr;

	if (!strcmp(tmp, "device_type") || !strcmp(tmp, "compatible") ||
	    !strcmp(tmp, "model") || !strcmp(tmp, "bootargs") ||
	    !strcmp(tmp, "linux,stdout-path")) {
		printf("%s", value);
	} else if (!strcmp(tmp, "clock-frequency") ||
	    !strcmp(tmp, "timebase-frequency")) {
		printf("%d", *((unsigned int *)value));
	} else {
		for (cnt = 0; cnt < size; cnt++) {
			if ((cnt % sizeof(u_int32_t)) == 0)
				printf(" ");
			printf("%x", value[cnt]);
		}
	}
	ptr += roundup(size, sizeof(u_int32_t)) / sizeof(u_int32_t);
	printf("\n");

	return ptr;
}

void
fdt_print_node(void *node, int level)
{
	u_int32_t *ptr;
	int cnt;

	ptr = (u_int32_t *)node;

	if (*ptr != FDT_NODE_BEGIN)
		return;

	ptr++;

	for (cnt = 0; cnt < level; cnt++)
		printf("\t");
	printf("%s :\n", fdt_node_name(node));
	ptr = skip_node_name(ptr);

	while (*ptr == FDT_PROPERTY)
		ptr = fdt_print_property(ptr, level);
}

void
fdt_print_node_recurse(void *node, int level)
{
	void *child;

	fdt_print_node(node, level);
	for (child = fdt_child_node(node); child; child = fdt_next_node(child))
		fdt_print_node_recurse(child, level + 1);
}

void
fdt_print_tree(void)
{
	fdt_print_node_recurse(fdt_next_node(0), 0);
}


code:
/*     $OpenBSD: fdt.h,v 1.3 2009/10/01 20:21:05 dms Exp $       */

/*
 * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

struct fdt_head {
	u_int32_t fh_magic;
	u_int32_t fh_size;
	u_int32_t fh_struct_off;
	u_int32_t fh_strings_off;
	u_int32_t fh_reserve_off;
	u_int32_t fh_version;
	u_int32_t fh_comp_ver;     /* last compatible version */
	u_int32_t fh_boot_cpu_id;  /* fh_version >=2 */
	u_int32_t fh_strings_size; /* fh_version >=3 */
	u_int32_t fh_struct_size;  /* fh_version >=17 */
};

struct fdt {
	struct fdt_head *header;
	void *		tree;
	void *		strings;
	void *		memory;
	int		version;
	int		strings_size;
};

#define FDT_MAGIC	0xd00dfeed
#define FDT_NODE_BEGIN	0x01
#define FDT_NODE_END	0x02
#define FDT_PROPERTY	0x03
#define FDT_NOP		0x04
#define FDT_END		0x09

#define FDT_CODE_VERSION 0x11

int	 fdt_init(void *);
void	*fdt_next_node(void *);
void	*fdt_child_node(void *);
char	*fdt_node_name(void *);
void	*fdt_find_node(char *);
int	 fdt_node_property(void *, char *, char **);
void 	*fdt_parent_node(void *);
void	*fdt_print_property(void *, int);
void 	 fdt_print_node(void *, int);
void	 fdt_print_tree(void);


code:
/*	$OpenBSD: libsa.h,v 1.2 2011/03/13 00:13:53 deraadt Exp $	*/

/*
 * Copyright (c) 2008 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <lib/libsa/stand.h>

#define DEFAULT_KERNEL_ADDRESS  0

#ifdef DEBUG
#define DPRINTF(x)      printf x;
#else
#define DPRINTF(x)
#endif

/*
 * com
 */
void com_probe(struct consdev *);
void com_init(struct consdev *);
int com_getc(dev_t);
void com_putc(dev_t, int);

/*
 * wd
 */
int wdstrategy(void *, int, daddr32_t, size_t, void *, size_t *);
int wdopen(struct open_file *, ...);
int wdclose(struct open_file *);


code:
/*	$OpenBSD: machdep.c,v 1.6 2014/03/29 18:09:30 guenther Exp $	*/

/*
 * Copyright (c) 2008 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>

#include "libsa.h"
#include "wdvar.h"
#include "fdt.h"

/*
 * RouterBOOT firmware puts its FDT at an address that is low enough
 * to conflict with bsd.rd.  So we need to relocate the FDT.  As long
 * as we have at least 32MB of memory, the 16MB boundary should be
 * fine, and leave us plenty of room for future kernel growth.
 */
#define FDTADDRSTART	0x01000000

#define RPR	0xe0000918
#define  RPR_RSTE	0x52535445
#define RCR	0xe000091c
#define  RCR_SWSR	0x00000001
#define  RCR_SWHR	0x00000002

/* defines from pciide.c and wdc_obio.c */
int     pciide_init             (struct wdc_channel*, u_int);
int     wdc_obio_init           (struct wdc_channel*, u_int);

void
machdep(void)
{
	void *node;
	char *tmp;
	int len;

	extern int consfreq;
	extern uint8_t *consaddr;

	/* set default values */
	consfreq = NS16550_FREQ;
	consaddr = (uint8_t *)CONADDR;

	/* lookup FTD for informations about console */
	node = fdt_find_node("/chosen");
	if (node) {
		char *console;
		fdt_node_property(node, "linux,stdout-path", &console);
		node = fdt_find_node(console);
		if (node) {
			len = fdt_node_property(node, "clock-frequency", &tmp);
			if (len == 4)
				consfreq = *(int *)tmp;

			len = fdt_node_property(node, "reg", &tmp);
			if (len == 8)
				consaddr = (uint8_t *)*(int *)tmp;
		}
		if (node = fdt_parent_node(node)) {
			fdt_node_property(node, "device_type", &tmp);
			if (strncmp(tmp, "soc", 3) == 0) {
				/* we are on a soc */
				len = fdt_node_property(node, "reg", &tmp);
				if (len == 8)
					consaddr += *(int *)tmp;
			}
		}
	}

	cninit();
{
	extern int (*controller_init)(struct wdc_channel *chp, u_int chan);
	extern u_int32_t pciide_base_addr;
	extern u_int32_t wdc_base_addr[];
	int *addr;
	int chnum;

	/* Thecus defaults */
	controller_init = pciide_init;
	pciide_base_addr = 0xe2000000;

	/* lookup the FDT, may have some CF there */
	chnum = 0;
	wdc_base_addr[0] = 0;
	wdc_base_addr[1] = 0;
	node = fdt_find_node("/");
	for (node = fdt_child_node(node); node; node = fdt_next_node(node)) {
		len = fdt_node_property(node, "device_type", &tmp);
		if (len && (strcmp(tmp, "rb,cf") == 0) && (chnum < 2)) {
			len = fdt_node_property(node, "reg", (char **)&addr);
			if (len == 8) {
				wdc_base_addr[chnum] = *addr;
				chnum++;
			}
		}
	}
	if (chnum)
		controller_init = wdc_obio_init;
}

}

int
main(void)
{
	extern char __bss_start[], _end[];
	extern int fdtaddrsave;

	bzero(__bss_start, _end - __bss_start);

	/* initialize FDT if the blob is available */
	if (fdtaddrsave) {
		if (fdt_init((void *)fdtaddrsave) == 0)
			fdtaddrsave = 0; /* no usable blob there */
	}

	/* relocate FDT */
	if (fdtaddrsave && fdtaddrsave < FDTADDRSTART) {
		struct fdt_head *fh = (void *)fdtaddrsave;

		bcopy((void *)fdtaddrsave, (void *)FDTADDRSTART, fh->fh_size);
		fdtaddrsave = FDTADDRSTART;
	}

	boot(0);
	return 0;
}

void
_rtt(void)
{
	uint32_t v;

	*((volatile uint32_t *)(RPR)) = RPR_RSTE;
	__asm volatile("eieio");
	*((volatile uint32_t *)(RCR)) = RCR_SWHR;

	printf("RESET FAILED\n");
	for (;;) ;
}


code:
/*	$OpenBSD: ns16550.c,v 1.2 2009/09/07 21:16:57 dms Exp $	*/
/*	$NetBSD: ns16550.c,v 1.3 2005/12/24 20:07:03 perry Exp $	*/

/*
 * Copyright (c) 2002 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed for the NetBSD Project by
 *	Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file provides console I/O routines for boards that use
 * 16550-compatible UARTs.
 */

#include <sys/types.h>

#include <dev/cons.h>
#include <dev/ic/comreg.h>

#include "libsa.h"

uint8_t *consaddr;
uint32_t consspeed;
uint32_t consfreq;

#define	INB(x)		*((volatile uint8_t *) (consaddr + (x)))
#define	OUTB(x, v)	*((volatile uint8_t *) (consaddr + (x))) = (v)
#define	ISSET(t,f)	((t) & (f))

static int
comspeed(int speed)
{
#define	divrnd(n, q)	(((n)*2/(q)+1)/2)	/* divide and round off */

	int x, err;

	if (speed <= 0)
		return (-1);
	x = divrnd((consfreq / 16), speed);
	if (x <= 0)
		return (-1);
	err = divrnd((((quad_t)consfreq) / 16) * 1000, speed * x) - 1000;
	if (err < 0)
		err = -err;
	if (err > COM_TOLERANCE)
		return (-1);
	return (x);
#undef divrnd
}

void
com_probe(struct consdev *cn)
{
	cn->cn_pri = CN_LOWPRI;
	cn->cn_dev = makedev(12, 0);
}

void
com_init(struct consdev *cn)
{
	int rate;

	OUTB(com_cfcr, LCR_DLAB);
	rate = comspeed(CONSPEED);
	OUTB(com_dlbl, rate);
	OUTB(com_dlbh, rate >> 8);
	OUTB(com_cfcr, LCR_8BITS);
	OUTB(com_mcr, MCR_DTR | MCR_RTS);
	OUTB(com_fifo,
	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
	OUTB(com_ier, 0);
}

int
com_getc(dev_t dev)
{
	uint8_t stat;

	if (dev & 0x80)
		return ISSET(stat = INB(com_lsr), LSR_RXRDY);

	while (!ISSET(stat = INB(com_lsr), LSR_RXRDY))
		/* spin */ ;
	return (INB(com_data));
}

void
com_putc(dev_t dev, int c)
{
	uint8_t stat;
	int timo;

	/* Wait for any pending transmission to finish. */
	timo = 50000;
	while (!ISSET(stat = INB(com_lsr), LSR_TXRDY) && --timo)
		/* spin */ ;

	OUTB(com_data, c);

	/* Wait for this transmission to complete. */
	timo = 1500000;
	while (!ISSET(stat = INB(com_lsr), LSR_TXRDY) && --timo)
		/* spin */ ;

	/* Clear any interrupts generated by this transmission. */
	(void) INB(com_iir);
}


code:
/*	$OpenBSD: pciide.c,v 1.3 2009/09/07 21:16:57 dms Exp $	*/
/*	$NetBSD: pciide.c,v 1.5 2005/12/11 12:17:06 christos Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/types.h>

#include "libsa.h"
#include "wdvar.h"

u_int8_t pciide_read_cmdreg(struct wdc_channel *, u_int8_t);
void pciide_write_cmdreg(struct wdc_channel *, u_int8_t, u_int8_t);
u_int8_t pciide_read_ctlreg(struct wdc_channel *, u_int8_t);
void pciide_write_ctlreg(struct wdc_channel *, u_int8_t, u_int8_t);

u_int32_t pciide_base_addr = 0;

int
pciide_init(struct wdc_channel *chp, u_int chan)
{
	u_int32_t cmdreg, ctlreg;
	int i;

	/*
	 * two channels per chip, one drive per channel
	 */
	if (chan >= PCIIDE_NUM_CHANNELS || pciide_base_addr == 0)
		return (ENXIO);
	chp->ndrives = 1;

	DPRINTF(("[pciide] channel: %d\n", chan));

	/*
	 * XXX map?
	 */
	cmdreg = pciide_base_addr + chan * 0x10;
	ctlreg = pciide_base_addr+0x8 + chan * 0x10;

	/* set up cmd regsiters */
	chp->c_cmdbase = (u_int8_t *)cmdreg;
	chp->c_data = (u_int16_t *)(cmdreg + wd_data);
	for (i = 0; i < WDC_NPORTS; i++)
		chp->c_cmdreg[i] = chp->c_cmdbase + i;
	/* set up shadow registers */
	chp->c_cmdreg[wd_status]   = chp->c_cmdreg[wd_command];
	chp->c_cmdreg[wd_features] = chp->c_cmdreg[wd_precomp];
	/* set up ctl registers */
	chp->c_ctlbase = (u_int8_t *)ctlreg;

	chp->read_cmdreg = pciide_read_cmdreg;
	chp->write_cmdreg = pciide_write_cmdreg;
	chp->read_ctlreg = pciide_read_ctlreg;
	chp->write_ctlreg = pciide_write_ctlreg;
	return (0);
}

u_int8_t
pciide_read_cmdreg(struct wdc_channel *chp, u_int8_t reg)
{
	return *chp->c_cmdreg[reg];
}

void
pciide_write_cmdreg(struct wdc_channel *chp, u_int8_t reg, u_int8_t val)
{
	*chp->c_cmdreg[reg] = val;
}

u_int8_t
pciide_read_ctlreg(struct wdc_channel *chp, u_int8_t reg)
{
	return chp->c_ctlbase[reg];
}

void
pciide_write_ctlreg(struct wdc_channel *chp, u_int8_t reg, u_int8_t val)
{
	chp->c_ctlbase[reg] = val;
}


code:
#include <machine/asm.h>

#define STACKSIZE	8192

        .globl  _C_LABEL(fdtaddrsave)
        .type   _C_LABEL(fdtaddrsave),@object
	.data
_C_LABEL(fdtaddrsave):       .long   0

ENTRY(_start)
	lis	%r1, fdtaddrsave@ha
	stw	%r3, fdtaddrsave@l(%r1)

	lis	%r1, stack@ha
	addi	%r1, %r1, stack@l
	addi	%r1, %r1, STACKSIZE

	b	_C_LABEL(main)

	.data
.lcomm	stack,STACKSIZE,8


code:
/*	$OpenBSD: time.c,v 1.3 2015/01/20 04:41:01 krw Exp $	*/
#include <sys/types.h>

#include "libsa.h"

time_t
getsecs(void)
{
	uint32_t count;

	__asm volatile ("mftb %0" : "=r" (count));
	return (count / 66666666);
}


code:
/*	$OpenBSD: wd.c,v 1.7 2013/11/05 00:51:58 krw Exp $	*/
/*	$NetBSD: wd.c,v 1.5 2005/12/11 12:17:06 christos Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Manuel Bouyer.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/types.h>
#include <sys/stdint.h>

#include "libsa.h"
#include "wdvar.h"

void	wdprobe(void);
int	wd_get_params(struct wd_softc *wd);
int	wdgetdisklabel(struct wd_softc *wd);
void	wdgetdefaultlabel(struct wd_softc *wd, struct disklabel *lp);

struct wd_softc wd_devs[NUNITS];
int wd_ndevs = -1;

void
wdprobe(void)
{
	struct wd_softc *wd = wd_devs;
	u_int chan, drive, unit = 0;

	for (chan = 0; chan < PCIIDE_NUM_CHANNELS; chan++) {
		if (wdc_init(wd, chan) != 0)
			continue;
		for (drive = 0; drive < wd->sc_channel.ndrives; drive++) {
			wd->sc_unit = unit;
			wd->sc_drive = drive;

			if (wd_get_params(wd) != 0)
				continue;

			DPRINTF(("wd%d: channel %d drive %d\n",
				unit, chan, drive));
			unit++;
			wd++;
		}
	}

	wd_ndevs = unit;
}

/*
 * Get drive parameters through 'device identify' command.
 */
int
wd_get_params(wd)
	struct wd_softc *wd;
{
	int error;
	unsigned char buf[DEV_BSIZE];

	if ((error = wdc_exec_identify(wd, buf)) != 0)
		return (error);

#if BYTE_ORDER == BIG_ENDIAN
	/*
	 * All the fields in the params structure are 16-bit integers
	 * except for the ID strings which are char strings.  The
	 * 16-bit integers are currently in memory in little-endian,
	 * regardless of architecture.  So, they need to be swapped on
	 * big-endian architectures before they are accessed through
	 * the ataparams structure.
	 *
	 * The swaps below avoid touching the char strings.
	 */
	swap16_multi((u_int16_t *)buf, 10);
	swap16_multi((u_int16_t *)buf + 20, 3);
	swap16_multi((u_int16_t *)buf + 47, DEV_BSIZE / 2 - 47);
#endif

	wd->sc_params = *(struct ataparams *)buf;

	/* 48-bit LBA addressing */
	if ((wd->sc_params.atap_cmd2_en & ATAPI_CMD2_48AD) != 0) {
		DPRINTF(("Drive supports LBA48.\n"));
#if defined(_ENABLE_LBA48)
		wd->sc_flags |= WDF_LBA48;
#endif
	}

	/* Prior to ATA-4, LBA was optional. */
	if ((wd->sc_params.atap_capabilities1 & WDC_CAP_LBA) != 0) {
		DPRINTF(("Drive supports LBA.\n"));
		wd->sc_flags |= WDF_LBA;
	}

	return (0);
}

/*
 * Initialize disk label to the default value.
 */
void
wdgetdefaultlabel(wd, lp)
	struct wd_softc *wd;
	struct disklabel *lp;
{
	memset(lp, 0, sizeof(struct disklabel));

	lp->d_secsize = DEV_BSIZE;
	lp->d_ntracks = wd->sc_params.atap_heads;
	lp->d_nsectors = wd->sc_params.atap_sectors;
	lp->d_ncylinders = wd->sc_params.atap_cylinders;
	lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;

	if (strcmp(wd->sc_params.atap_model, "ST506") == 0)
		lp->d_type = DTYPE_ST506;
	else
		lp->d_type = DTYPE_ESDI;

	strncpy(lp->d_typename, wd->sc_params.atap_model, 16);
	strncpy(lp->d_packname, "fictitious", 16);
	if (wd->sc_capacity > UINT32_MAX)
		DL_SETDSIZE(lp, UINT32_MAX);
	else
		DL_SETDSIZE(lp, wd->sc_capacity);
	lp->d_flags = 0;

	DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
	DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
	lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
	lp->d_npartitions = MAXPARTITIONS;

	lp->d_magic = DISKMAGIC;
	lp->d_magic2 = DISKMAGIC;
	lp->d_checksum = dkcksum(lp);
}

/*
 * Read disk label from the device.
 */
int
wdgetdisklabel(wd)
	struct wd_softc *wd;
{
	char *msg;
	int sector;
	size_t rsize;
	struct disklabel *lp;
	unsigned char buf[DEV_BSIZE];
	u_int16_t sig;

	wdgetdefaultlabel(wd, &wd->sc_label);

	/*
	 * Find OpenBSD Partition in DOS partition table.
	 */
	sector = 0;
	if (wdstrategy(wd, F_READ, DOSBBSECTOR, DEV_BSIZE, buf, &rsize))
		return EOFFSET;

	sig = letoh16(*(u_int16_t *)&buf[DOSMBR_SIGNATURE_OFF]);
	if (sig == DOSMBR_SIGNATURE) {
		int i;
		struct dos_partition *dp = (struct dos_partition *)buf;

		/*
		 * Lookup OpenBSD slice. If there is none, go ahead
		 * and try to read the disklabel off sector #0.
		 */

		memcpy(dp, &buf[DOSPARTOFF], NDOSPART * sizeof(*dp));
		for (i = 0; i < NDOSPART; i++) {
			if (dp[i].dp_typ == DOSPTYP_OPENBSD) {
				sector = letoh32(dp[i].dp_start);
				break;
			}
		}
	}

	if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE,
				buf, &rsize))
		return EOFFSET;

	if ((msg = getdisklabel(buf + LABELOFFSET, &wd->sc_label)))
		printf("wd%d: getdisklabel: %s\n", wd->sc_unit, msg);

	lp = &wd->sc_label;

	/* check partition */
	if ((wd->sc_part >= lp->d_npartitions) ||
	    (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) {
		DPRINTF(("illegal partition\n"));
		return (EPART);
	}

	DPRINTF(("label info: d_secsize %d, d_nsectors %d, d_ncylinders %d,"
				"d_ntracks %d, d_secpercyl %d\n",
				wd->sc_label.d_secsize,
				wd->sc_label.d_nsectors,
				wd->sc_label.d_ncylinders,
				wd->sc_label.d_ntracks,
				wd->sc_label.d_secpercyl));

	return (0);
}

/*
 * Open device (read drive parameters and disklabel)
 */
int
wdopen(struct open_file *f, ...)
{
	int error;
	va_list ap;
	u_int unit, part, drive;
	struct wd_softc *wd;

	va_start(ap, f);
	unit = va_arg(ap, u_int);
	part = va_arg(ap, u_int);
	va_end(ap);

	DPRINTF(("wdopen: wd%d%c\n", unit, 'a' + part));

	if (unit < 0 || unit >= NUNITS)
		return (ENXIO);

	if (wd_ndevs == -1)
		wdprobe();

	if (unit >= wd_ndevs)
		return (ENXIO);

	wd = &wd_devs[unit];
	wd->sc_part = part;

	if ((error = wdgetdisklabel(wd)) != 0)
		return (error);

	f->f_devdata = wd;
	return (0);
}

/*
 * Close device.
 */
int
wdclose(struct open_file *f)
{
	return 0;
}

/*
 * Read some data.
 */
int
wdstrategy(f, rw, dblk, size, buf, rsize)
	void *f;
	int rw;
	daddr32_t dblk;
	size_t size;
	void *buf;
	size_t *rsize;
{
	int i, nsect;
	daddr32_t blkno;
	struct wd_softc *wd = f;

	if (size == 0)
		return (0);

	if (rw != F_READ)
		return EOPNOTSUPP;

	nsect = howmany(size, wd->sc_label.d_secsize);
	blkno = dblk + wd->sc_label.d_partitions[wd->sc_part].p_offset;

	for (i = 0; i < nsect; i++, blkno++) {
		int error;

		if ((error = wdc_exec_read(wd, WDCC_READ, blkno, buf)) != 0)
			return (error);

		buf += wd->sc_label.d_secsize;
	}

	*rsize = size;
	return (0);
}


code:
/*	$OpenBSD: wdc.c,v 1.5 2013/03/24 18:43:47 deraadt Exp $	*/
/*	$NetBSD: wdc.c,v 1.7 2005/12/11 12:17:06 christos Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Manuel Bouyer.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>

#include "libsa.h"
#include "wdvar.h"

#define WDCDELAY	100
#define WDCNDELAY_RST	31000 * 10

static int  wdcprobe(struct wdc_channel *chp);
static int  wdc_wait_for_ready(struct wdc_channel *chp);
static int  wdc_read_block(struct wd_softc *sc, struct wdc_command *wd_c);
static int  __wdcwait_reset(struct wdc_channel *chp, int drv_mask);

int (*controller_init)(struct wdc_channel *, u_int) = 0;

/*
 * Reset the controller.
 */
static int
__wdcwait_reset(chp, drv_mask)
	struct wdc_channel *chp;
	int drv_mask;
{
	int timeout;
	u_int8_t st0, st1;

	/* wait for BSY to deassert */
	for (timeout = 0; timeout < WDCNDELAY_RST; timeout++) {
		WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM); /* master */
		delay(10);
		st0 = WDC_READ_REG(chp, wd_status);
		WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM | 0x10); /* slave */
		delay(10);
		st1 = WDC_READ_REG(chp, wd_status);

		if ((drv_mask & 0x01) == 0) {
			/* no master */
			if ((drv_mask & 0x02) != 0 && (st1 & WDCS_BSY) == 0) {
				/* No master, slave is ready, it's done */
				goto end;
			}
		} else if ((drv_mask & 0x02) == 0) {
			/* no slave */
			if ((drv_mask & 0x01) != 0 && (st0 & WDCS_BSY) == 0) {
				/* No slave, master is ready, it's done */
				goto end;
			}
		} else {
			/* Wait for both master and slave to be ready */
			if ((st0 & WDCS_BSY) == 0 && (st1 & WDCS_BSY) == 0) {
				goto end;
			}
		}

		delay(WDCDELAY);
	}

	/* Reset timed out. Maybe it's because drv_mask was not right */
	if (st0 & WDCS_BSY)
		drv_mask &= ~0x01;
	if (st1 & WDCS_BSY)
		drv_mask &= ~0x02;

end:
	return (drv_mask);
}

/* Test to see controller with at last one attached drive is there.
 * Returns a bit for each possible drive found (0x01 for drive 0,
 * 0x02 for drive 1).
 * Logic:
 * - If a status register is at 0xff, assume there is no drive here
 *   (ISA has pull-up resistors).  Similarly if the status register has
 *   the value we last wrote to the bus (for IDE interfaces without pullups).
 *   If no drive at all -> return.
 * - reset the controller, wait for it to complete (may take up to 31s !).
 *   If timeout -> return.
 */
static int
wdcprobe(chp)
	struct wdc_channel *chp;
{
	u_int8_t st0, st1, sc, sn, cl, ch;
	u_int8_t ret_value = 0x03;
	u_int8_t drive;
	int found;

	/*
	 * Sanity check to see if the wdc channel responds at all.
	 */
	WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM);
	delay(10);
	st0 = WDC_READ_REG(chp, wd_status);
	WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM | 0x10);
	delay(10);
	st1 = WDC_READ_REG(chp, wd_status);

	if (st0 == 0xff || st0 == WDSD_IBM)
		ret_value &= ~0x01;
	if (st1 == 0xff || st1 == (WDSD_IBM | 0x10))
		ret_value &= ~0x02;
	if (ret_value == 0)
		return (ENXIO);

	/* assert SRST, wait for reset to complete */
	WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM);
	delay(10);
	WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_RST | WDCTL_IDS);
	delay(1000);
	WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_IDS);
	delay(1000);
	(void) WDC_READ_REG(chp, wd_error);
	WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_4BIT);
	delay(10);

	ret_value = __wdcwait_reset(chp, ret_value);

	/* if reset failed, there's nothing here */
	if (ret_value == 0)
		return (ENXIO);

	/*
	 * Test presence of drives. First test register signatures looking for
	 * ATAPI devices. If it's not an ATAPI and reset said there may be
	 * something here assume it's ATA or OLD. Ghost will be killed later in
	 * attach routine.
	 */
	found = 0;
	for (drive = 0; drive < 2; drive++) {
		if ((ret_value & (0x01 << drive)) == 0)
			continue;
		return (0);
	}
	return (ENXIO);
}

/*
 * Initialize the device.
 */
int
wdc_init(sc, unit)
	struct wd_softc *sc;
	u_int unit;
{
	if (!controller_init)
		return (ENXIO);
	if ((*controller_init)(&sc->sc_channel, unit) != 0)
		return (ENXIO);
	if (wdcprobe(&sc->sc_channel) != 0)
		return (ENXIO);
	return (0);
}

/*
 * Wait until the device is ready.
 */
int
wdc_wait_for_ready(chp)
	struct wdc_channel *chp;
{
	u_int timeout;
	for (timeout = WDC_TIMEOUT; timeout > 0; --timeout) {
		if ((WDC_READ_REG(chp, wd_status) & (WDCS_BSY | WDCS_DRDY))
				== WDCS_DRDY)
			return (0);
	}
	return (ENXIO);
}

/*
 * Read one block off the device.
 */
int
wdc_read_block(sc, wd_c)
	struct wd_softc *sc;
	struct wdc_command *wd_c;
{
	int i;
	struct wdc_channel *chp = &sc->sc_channel;
	u_int16_t *ptr = (u_int16_t*)wd_c->data;

	if (ptr == NULL)
		return (0);

	for (i = wd_c->bcount; i > 0; i -= sizeof(u_int16_t))
		*ptr++ = WDC_READ_DATA(chp);

	return (0);
}

/*
 * Send a command to the device (CHS and LBA addressing).
 */
int
wdccommand(wd, wd_c)
	struct wd_softc *wd;
	struct wdc_command *wd_c;
{
	u_int8_t err;
	struct wdc_channel *chp = &wd->sc_channel;

#if 0
	DPRINTF(("wdccommand(%d, %d, %d, %d, %d, %d, %d)\n",
	    wd_c->drive, wd_c->r_command, wd_c->r_cyl,
	    wd_c->r_head, wd_c->r_sector, wd_c->bcount,
	    wd_c->r_precomp));
#endif

	WDC_WRITE_REG(chp, wd_precomp, wd_c->r_precomp);
	WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count);
	WDC_WRITE_REG(chp, wd_sector, wd_c->r_sector);
	WDC_WRITE_REG(chp, wd_cyl_lo, wd_c->r_cyl);
	WDC_WRITE_REG(chp, wd_cyl_hi, wd_c->r_cyl >> 8);
	WDC_WRITE_REG(chp, wd_sdh,
	    WDSD_IBM | (wd_c->drive << 4) | wd_c->r_head);
	WDC_WRITE_REG(chp, wd_command, wd_c->r_command);

	if (wdc_wait_for_ready(chp) != 0)
		return (ENXIO);

	if (WDC_READ_REG(chp, wd_status) & WDCS_ERR) {
		DPRINTF(("wd%d: error %x\n", wd->sc_unit,
		    WDC_READ_REG(chp, wd_error)));
		return (ENXIO);
	}

	return (0);
}

/*
 * Send a command to the device (LBA48 addressing).
 */
int
wdccommandext(wd, wd_c)
	struct wd_softc *wd;
	struct wdc_command *wd_c;
{
	u_int8_t err;
	struct wdc_channel *chp = &wd->sc_channel;

	/* Select drive, head, and addressing mode. */
	WDC_WRITE_REG(chp, wd_sdh, (wd_c->drive << 4) | WDSD_LBA);

	/* previous */
	WDC_WRITE_REG(chp, wd_features, 0);
	WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count >> 8);
	WDC_WRITE_REG(chp, wd_lba_hi, wd_c->r_blkno >> 40);
	WDC_WRITE_REG(chp, wd_lba_mi, wd_c->r_blkno >> 32);
	WDC_WRITE_REG(chp, wd_lba_lo, wd_c->r_blkno >> 24);

	/* current */
	WDC_WRITE_REG(chp, wd_features, 0);
	WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count);
	WDC_WRITE_REG(chp, wd_lba_hi, wd_c->r_blkno >> 16);
	WDC_WRITE_REG(chp, wd_lba_mi, wd_c->r_blkno >> 8);
	WDC_WRITE_REG(chp, wd_lba_lo, wd_c->r_blkno);

	/* Send command. */
	WDC_WRITE_REG(chp, wd_command, wd_c->r_command);

	if (wdc_wait_for_ready(chp) != 0)
		return (ENXIO);

	if (WDC_READ_REG(chp, wd_status) & WDCS_ERR) {
		DPRINTF(("wd%d: error %x\n", wd->sc_unit,
		    WDC_READ_REG(chp, wd_error)));
		return (ENXIO);
	}

	return (0);
}

/*
 * Issue 'device identify' command.
 */
int
wdc_exec_identify(wd, data)
	struct wd_softc *wd;
	void *data;
{
	int error;
	struct wdc_command wd_c;

	memset(&wd_c, 0, sizeof(wd_c));

	wd_c.drive = wd->sc_drive;
	wd_c.r_command = WDCC_IDENTIFY;
	wd_c.bcount = DEV_BSIZE;
	wd_c.data = data;

	if ((error = wdccommand(wd, &wd_c)) != 0)
		return (error);

	return wdc_read_block(wd, &wd_c);
}

/*
 * Issue 'read' command.
 */
int
wdc_exec_read(wd, cmd, blkno, data)
	struct wd_softc *wd;
	u_int8_t cmd;
	daddr32_t blkno;
	void *data;
{
	int error;
	struct wdc_command wd_c;

	memset(&wd_c, 0, sizeof(wd_c));

	if (wd->sc_flags & WDF_LBA48) {
		/* LBA48 */
		wd_c.r_blkno = blkno;
	} else if (wd->sc_flags & WDF_LBA) {
		/* LBA */
		wd_c.r_sector = (blkno >> 0) & 0xff;
		wd_c.r_cyl = (blkno >> 8) & 0xffff;
		wd_c.r_head = (blkno >> 24) & 0x0f;
		wd_c.r_head |= WDSD_LBA;
	} else {
		/* LHS */
		wd_c.r_sector = blkno % wd->sc_label.d_nsectors;
		wd_c.r_sector++;    /* Sectors begin with 1, not 0. */
		blkno /= wd->sc_label.d_nsectors;
		wd_c.r_head = blkno % wd->sc_label.d_ntracks;
		blkno /= wd->sc_label.d_ntracks;
		wd_c.r_cyl = blkno;
		wd_c.r_head |= WDSD_CHS;
	}

	wd_c.data = data;
	wd_c.r_count = 1;
	wd_c.drive = wd->sc_drive;
	wd_c.r_command = cmd;
	wd_c.bcount = wd->sc_label.d_secsize;

	if (wd->sc_flags & WDF_LBA48)
		error = wdccommandext(wd, &wd_c);
	else
		error = wdccommand(wd, &wd_c);

	if (error != 0)
		return (error);

	return wdc_read_block(wd, &wd_c);
}


code:
/*	$OpenBSD: wdc_obio.c,v 1.1 2009/09/07 21:16:57 dms Exp $	*/

/*
 * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>

#include "libsa.h"
#include "wdvar.h"

#define WDC_OBIO_REG_OFFSET	(8 << 17)
#define WDC_OBIO_AUXREG_OFFSET	(6 << 16)

u_int8_t wdc_read_cmdreg(struct wdc_channel *, u_int8_t);
void wdc_write_cmdreg(struct wdc_channel *, u_int8_t, u_int8_t);
u_int8_t wdc_read_ctlreg(struct wdc_channel *, u_int8_t);
void wdc_write_ctlreg(struct wdc_channel *, u_int8_t, u_int8_t);

u_int32_t wdc_base_addr[2];

int
wdc_obio_init(struct wdc_channel *chp, u_int chan)
{
	u_int32_t cmdreg, ctlreg;
	int i;

	/*
	 * two channels per chip, one drive per channel
	 */
	if (chan >= 2 || !wdc_base_addr[chan])
		return (ENXIO);
	chp->ndrives = 1;

	cmdreg = wdc_base_addr[chan] + WDC_OBIO_REG_OFFSET;
	ctlreg = wdc_base_addr[chan] + WDC_OBIO_AUXREG_OFFSET;

	/* set up cmd regsiters */
	chp->c_cmdbase = (u_int8_t *)cmdreg;
	chp->c_data = (u_int16_t *)(cmdreg + wd_data);
	for (i = 0; i < WDC_NPORTS; i++)
		chp->c_cmdreg[i] = chp->c_cmdbase + (i<<16);
	/* set up shadow registers */
	chp->c_cmdreg[wd_status]   = chp->c_cmdreg[wd_command];
	chp->c_cmdreg[wd_features] = chp->c_cmdreg[wd_precomp];
	/* set up ctl registers */
	chp->c_ctlbase = (u_int8_t *)ctlreg;

	chp->read_cmdreg = wdc_read_cmdreg;
	chp->write_cmdreg = wdc_write_cmdreg;
	chp->read_ctlreg = wdc_read_ctlreg;
	chp->write_ctlreg = wdc_write_ctlreg;

	return (0);
}

u_int8_t
wdc_read_cmdreg(struct wdc_channel *chp, u_int8_t reg)
{
	u_int8_t val;
	val = *chp->c_cmdreg[reg];
	if (val == 0xf9 && reg == wd_status)
		val = 0x7f;
	return val;
}

void
wdc_write_cmdreg(struct wdc_channel *chp, u_int8_t reg, u_int8_t val)
{
	*chp->c_cmdreg[reg] = val;
}

u_int8_t
wdc_read_ctlreg(struct wdc_channel *chp, u_int8_t reg)
{
	u_int8_t val;
	val = chp->c_ctlbase[reg];
	if (val == 0xf9 && reg == wd_aux_altsts)
		val = 0x7f;
	return val;
}

void
wdc_write_ctlreg(struct wdc_channel *chp, u_int8_t reg, u_int8_t val)
{
	chp->c_ctlbase[reg] = val;
}