1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
|
\ 7.6 Client Program Debugging command group
\ 7.6.1 Registers display
: ctrace ( -- )
;
: .registers ( -- )
;
: .fregisters ( -- )
;
\ to ( param [old-name< >] -- )
\ 7.6.2 Program download and execute
variable state-valid
0 state-valid !
variable file-size
: !load-size file-size ! ;
: load-size file-size @ ;
variable file-type
0 constant elf
1 constant bootinfo
2 constant xcoff
3 constant pe
\ Array indexes and values for e_type
d# 16 constant EI_NIDENT
0 constant EI_MAG0
h# 7f constant ELFMAG0
1 constant EI_MAG1
[CHAR] E constant ELFMAG1
2 constant EI_MAG2
[CHAR] L constant ELFMAG2
3 constant EI_MAG3
[CHAR] F constant ELFMAG3
4 constant EI_CLASS
0 constant ELFCLASSNONE
1 constant ELFCLASS32
2 constant ELFCLASS64
5 constant EI_DATA
0 constant ELFDATANONE
1 constant ELFDATA2LSB
2 constant ELFDATA2MSB
6 constant EI_VERSION
0 constant EV_NONE
1 constant EV_CURRENT
\ Values for e_type
0 constant ET_NONE
1 constant ET_REL
2 constant ET_EXEC
3 constant ET_DYN
4 constant ET_CORE
\ Values for e_machine
d# 2 constant EM_SPARC
d# 3 constant EM_386
d# 6 constant EM_486
d# 18 constant EM_SPARC32PLUS
d# 20 constant EM_PPC
d# 43 constant EM_SPARCV9
/l constant Elf32_Addr
/w constant Elf32_Half
/l constant Elf32_Off
/l constant Elf32_Sword
/l constant Elf32_Word
/l constant Elf32_Size
struct ( ELF header )
EI_NIDENT field >Elf32_Ehdr.e_ident ( File identification )
Elf32_Half field >Elf32_Ehdr.e_type ( File type )
Elf32_Half field >Elf32_Ehdr.e_machine ( Machine archicture )
Elf32_Word field >Elf32_Ehdr.e_version ( ELF format version )
Elf32_Addr field >Elf32_Ehdr.e_entry ( Entry point )
Elf32_Off field >Elf32_Ehdr.e_phoff ( Program header file offset )
Elf32_Off field >Elf32_Ehdr.e_shoff ( Section header file offset )
Elf32_Word field >Elf32_Ehdr.e_flags ( Architecture specific flags )
Elf32_Half field >Elf32_Ehdr.e_ehsize ( Size of ELF header in bytes )
Elf32_Half field >Elf32_Ehdr.e_phentsize ( Size of program header entries )
Elf32_Half field >Elf32_Ehdr.e_phnum ( Number of program header entry )
Elf32_Half field >Elf32_Ehdr.e_shentsize ( Size of section header entry )
Elf32_Half field >Elf32_Ehdr.e_shnum ( Number of section header entries )
Elf32_Half field >Elf32_Ehdr.e_shstrndx ( Section name strings section )
constant /Elf32_Ehdr
: @e_ident ( base index -- byte )
swap >Elf32_Ehdr.e_ident + c@
;
: @e_type ( base -- type )
>Elf32_Ehdr.e_type w@
;
: @e_machine ( base -- type )
>Elf32_Ehdr.e_machine w@
;
: @e_entry ( base -- entry )
>Elf32_Ehdr.e_entry l@
;
: @e_phoff ( base -- poffset )
>Elf32_Ehdr.e_phoff l@
;
: @e_phnum ( base -- pnum )
>Elf32_Ehdr.e_phnum w@
;
: elf?
" load-base" evaluate
dup EI_MAG0 @e_ident
ELFMAG0 <> if drop false exit then
dup EI_MAG1 @e_ident
ELFMAG1 <> if drop false exit then
dup EI_MAG2 @e_ident
ELFMAG2 <> if drop false exit then
dup EI_MAG3 @e_ident
ELFMAG3 <> if drop false exit then
dup EI_CLASS @e_ident
[IFDEF] CONFIG_SPARC64
ELFCLASS64 <> if drop false exit then
[ELSE]
ELFCLASS32 <> if drop false exit then
[THEN]
dup EI_DATA @e_ident
" little-endian?" evaluate if
ELFDATA2LSB <> if drop false exit then
else
ELFDATA2MSB <> if drop false exit then
then
dup @e_type
ET_EXEC <> if drop false exit then ( not executable )
@e_machine
[IFDEF] CONFIG_PPC
EM_PPC <> if false exit then
[THEN]
[IFDEF] CONFIG_X86
dup
EM_386 <> if
EM_486 <> if
false exit
then
else
drop
then
[THEN]
[IFDEF] CONFIG_SPARC32
dup
EM_SPARC <> if
EM_SPARC32PLUS <> if
false exit
then
else
drop
then
[THEN]
[IFDEF] CONFIG_SPARC64
EM_SPARCV9 <> if false exit then
[THEN]
true
;
variable elf-entry
variable xcoff-entry
variable bootinfo-entry
variable bootinfo-size
: init-program-elf
elf file-type !
" /packages/elf-loader" open-dev dup if
dup
" init-program" rot $call-method
close-dev
else
drop
." /packages/elf-loader is missing" cr
then
;
: xcoff?
" load-base" evaluate w@
h# 1df <> if
false
exit
then
true
;
: init-program-xcoff
xcoff file-type !
" /packages/xcoff-loader" open-dev dup if
dup
" init-program" rot $call-method
close-dev
else
drop
." /packages/xcoff-loader is missing" cr
then
;
: pe?
false
;
: init-program-pe
pe file-type !
" /packages/pe-loader" open-dev dup if
dup
" init-program" rot $call-method
close-dev
else
drop
." /packages/pe-loader is missing" cr
then
;
: bootinfo?
" load-base" evaluate dup
" <CHRP-BOOT>" comp 0= if
drop
true
exit
then
" <chrp-boot>" comp 0= if
true
exit
then
false
;
: init-program-bootinfo
bootinfo file-type !
" /packages/bootinfo-loader" open-dev dup if
dup
" init-program" rot $call-method
close-dev
else
drop
." /packages/bootinfo-loader is missing" cr
then
;
: init-program ( -- )
elf? if
init-program-elf
exit
then
xcoff? if
init-program-xcoff
exit
then
pe? if
init-program-pe
exit
then
bootinfo? if
init-program-bootinfo
exit
then
;
: (encode-bootpath) ( "{params}<cr>" -- bootpath-str bootpath-len)
bl parse 2dup encode-string
" /chosen" (find-dev) if
" bootpath" rot (property)
then
linefeed parse encode-string
" /chosen" (find-dev) if
" bootargs" rot (property)
then
;
: load ( "{params}<cr>" -- )
(encode-bootpath)
open-dev ( ihandle )
dup 0= if
drop
exit
then
dup >r
" load-base" evaluate swap ( load-base ihandle )
dup ihandle>phandle " load" rot find-method ( xt 0|1 )
if swap call-package !load-size else cr ." Cannot find load for this package" 2drop then
r> close-dev
init-program
;
: dir ( "{paths}<cr>" -- )
linefeed parse
open-dev dup 0= if
drop
exit
then
dup
" dir" rot ['] $call-method catch
if
3drop
cr ." Cannot find dir for this package"
then
close-dev
;
: go ( -- )
state-valid @ not if exit then
elf file-type @ = if
[IFDEF] CONFIG_PPC
elf-entry @ " (go)" evaluate
[ELSE]
." go is not yet implemented"
[THEN]
else
xcoff file-type @ = if
[IFDEF] CONFIG_PPC
xcoff-entry @ " (go)" evaluate
[ELSE]
." go is not yet implemented"
[THEN]
else
bootinfo file-type @ = if
[IFDEF] CONFIG_PPC
bootinfo-entry @ bootinfo-size @ evaluate
[ELSE]
." go is not yet implemented"
[THEN]
else
." go is not yet implemented"
then
then
then
;
\ 7.6.3 Abort and resume
\ already defined !?
\ : go ( -- )
\ ;
\ 7.6.4 Disassembler
: dis ( addr -- )
;
: +dis ( -- )
;
\ 7.6.5 Breakpoints
: .bp ( -- )
;
: +bp ( addr -- )
;
: -bp ( addr -- )
;
: --bp ( -- )
;
: bpoff ( -- )
;
: step ( -- )
;
: steps ( n -- )
;
: hop ( -- )
;
: hops ( n -- )
;
\ already defined
\ : go ( -- )
\ ;
: gos ( n -- )
;
: till ( addr -- )
;
: return ( -- )
;
: .breakpoint ( -- )
;
: .step ( -- )
;
: .instruction ( -- )
;
\ 7.6.6 Symbolic debugging
: .adr ( addr -- )
;
: sym ( "name< >" -- n )
;
: sym>value ( addr len -- addr len false | n true )
;
: value>sym ( n1 -- n1 false | n2 addr len true )
;
|