Annotation of qemu/roms/SLOF/board-js2x/slof/OF.fs, revision 1.1.1.3

1.1       root        1: \ *****************************************************************************
                      2: \ * Copyright (c) 2004, 2008 IBM Corporation
                      3: \ * All rights reserved.
                      4: \ * This program and the accompanying materials
                      5: \ * are made available under the terms of the BSD License
                      6: \ * which accompanies this distribution, and is available at
                      7: \ * http://www.opensource.org/licenses/bsd-license.php
                      8: \ *
                      9: \ * Contributors:
                     10: \ *     IBM Corporation - initial implementation
                     11: \ ****************************************************************************/
                     12: 
                     13: \ The master file.  Everything else is included into here.
                     14: 
                     15: hex
                     16: 
                     17: ' ll-cr to cr
                     18: 
                     19: \ as early as possible we want to know if it is js20, js21 or bimini
                     20: \ u3 = js20; u4 = js21/bimini
                     21: \ the difference if bimini or js21 will be done later depending if
                     22: \ obsidian or citrine is found
                     23: \ f8000000 is probably the place of the u3/u4 version
                     24: f8000000 rl@ CONSTANT uni-n-version
                     25: uni-n-version 4 rshift  dup 3 = CONSTANT u3?  4 = CONSTANT u4?
                     26: \ if (f4000682 >> 4) == 1... it is a bimini...
                     27: f4000682 rb@ 4 rshift 1 = CONSTANT bimini?
                     28: 
                     29: \ to decide wether vga initialisation using bios emulation should be attempted,
                     30: \ we need to know wether a vga-device was found during pci-scan.
                     31: \ If it is found, this value will be set to the device's phandle
                     32: 0 value vga-device-node?
                     33: 
                     34: \ planar-id reads back GPIO 29 30 31 and returns it as one value
                     35: \ if planar-id >= 5 it should be GA2 else it is GA1 (JS20 only)
                     36: defer planar-id  ( -- planar-id )
                     37: 
                     38: : (planar-id)  ( -- planar-id)
                     39:    \ default implementation of planar-id just returns 8
                     40:    \ the highest possible planar id for JS20 is 7
                     41:    8
                     42: ;
                     43: 
                     44: ' (planar-id) to planar-id
                     45: 
                     46: #include "header.fs"
                     47: 
                     48: \ I/O accesses.
                     49: #include "io.fs"
                     50: 
                     51: \ XXX: Enable first UART on JS20, scripts forget to do this.  Sigh.
                     52: 3 7 siocfg!  1 30 siocfg!
                     53: 
                     54: #include "serial.fs"
                     55: 
                     56: cr
                     57: 
                     58: #include "base.fs"
                     59: 
                     60: \ Little-endian accesses.  Also known as `wrong-endian'.
                     61: #include <little-endian.fs>
                     62: 
                     63: \ do not free-mem if address is not within the heap
                     64: \ workaround for NVIDIA card
                     65: : free-mem  (  addr len -- )
                     66:    over heap-start heap-end within  IF
                     67:       free-mem
                     68:    ELSE
                     69:       2drop
                     70:    THEN
                     71: ;
                     72: 
                     73: : #join  ( lo hi #bits -- x )  lshift or ;
                     74: : #split ( x #bits -- lo hi )  2dup rshift dup >r swap lshift xor r> ;
                     75: 
                     76: : blink ;
                     77: 
                     78: : reset-dual-emit ;
                     79: 
                     80: : console-clean-fifo ;
                     81: 
                     82: : bootmsg-nvupdate ;
                     83: 
                     84: : asm-cout 2drop drop ;
                     85: 
                     86: #include "logging.fs"
                     87: 
                     88: : log-string 2drop ;
                     89: 
                     90: #include "bootmsg.fs"
                     91: 
                     92: 000 cp
                     93: 
                     94: \ disable the nvram logging until we know if we are
                     95: \ running from ram/takeover/js20 or in normal mode on js21
                     96: : (nvramlog-write-byte)  drop ;
                     97: ' (nvramlog-write-byte) to nvramlog-write-byte
                     98: 
                     99: #include "exception.fs"
                    100: 
                    101: : mm-log-warning 2drop ;
                    102: 
                    103: : write-mm-log ( data length type -- status )
                    104:        3drop 0
                    105: ;
                    106: 
                    107: 080 cp
                    108: 
                    109: #include "rtc.fs"
                    110: 
                    111: 100 cp
                    112: 
                    113: \ Input line editing.
                    114: #include "accept.fs"
                    115: 
                    116: 120 cp
                    117: 
                    118: #include "dump.fs"
                    119: 
                    120: cistack ciregs >r1 ! \ kernel wants a stack :-)
                    121: 
                    122: #include "romfs.fs"
                    123: 
                    124: 140 cp
                    125: #include "flash.fs"
                    126: 
                    127: \ 1 temp; 0 perm; let's default to temp
                    128: 1 VALUE flashside?
                    129: 
                    130: \ claim the memory used by copy of the flash
                    131: flash-header  IF
                    132:    romfs-base dup flash-image-size 0 claim drop
                    133: THEN
                    134: 
                    135: s" bootinfo" romfs-lookup drop c + l@ CONSTANT start-addr
                    136: start-addr flash-addr <> CONSTANT takeover?
                    137: 
                    138: takeover? u3? or 0=  IF
                    139:    \ we want nvram logging to work
                    140:    ['] .nvramlog-write-byte to nvramlog-write-byte
                    141: THEN
                    142: 
                    143: 160 cp
                    144: 
                    145: u4? IF f8002100 rl@ 0= ELSE false THEN  ?INCLUDE u4-mem.fs
                    146: u3?  IF
                    147:    planar-id 5 >=  IF
                    148:       40000 to nvram-size
                    149:    ELSE
                    150:       \ change nvram-size to 8000 for GA1 blades
                    151:       8000 to nvram-size
                    152:    THEN
                    153: THEN
                    154: 
                    155: 
                    156: takeover?  IF
                    157:    \ potentially comming from phype
                    158:    u4?  IF
                    159:       \ takeover on JS21 is using some nvram area
                    160:       \ which might be available
                    161:       \ on JS20 the nvram is too small and
                    162:       \ we just overwrite the nvram
                    163:       sec-nvram-base to nvram-base
                    164:    THEN
                    165:    sec-nvram-size to nvram-size
                    166:    \ in takeover mode the nvram is probably not mapped
                    167:    \ to the exact location where the nvram starts
                    168:    \ doing a small check to see if we have a partition
                    169:    \ starting with 70; this test is far from perfect but
                    170:    \ takeover is not the most common mode of running slof
                    171:    nvram-base rb@ 70 <>  IF  0 nvram-base rb!  THEN
                    172: THEN
                    173: 
                    174: 200 cp
                    175: 
                    176: #include <slof-logo.fs>
                    177: #include <banner.fs>
                    178: 
                    179: : .banner .slof-logo .banner ;
                    180: 
                    181: \ Get the secondary CPUs into our own spinloop.
                    182: f8000050 rl@ CONSTANT master-cpu
                    183: \ cr .( The master cpu is #) master-cpu .
                    184: 
                    185: VARIABLE cpu-mask
                    186: : get-slave ( n -- online? )
                    187:   0 3ff8 ! 18 lshift 30000000 or 48003f02 over l! icbi 10000 0 DO LOOP 3ff8 @ ;
                    188: : mark-online ( n -- )  1 swap lshift cpu-mask @ or cpu-mask ! ;
                    189: : get-slaves  40 0 DO i get-slave IF i mark-online THEN LOOP ;
                    190: : cpu-report  ( -- )
                    191:    cpu-mask @ 40 0  DO  dup 1 and  IF  ." #" i .  THEN  1 rshift  LOOP  drop
                    192: ;
                    193: 
                    194: 220 cp
                    195: master-cpu mark-online get-slaves
                    196: 
                    197: DEFER disable-watchdog ( -- )
                    198: DEFER find-boot-sector ( -- )
                    199: 
                    200: 
                    201: 240 cp
                    202: \ Timebase frequency, in Hz.
                    203: \ -1 VALUE tb-frequency
                    204: d# 14318378 VALUE tb-frequency   \ default value - needed for "ms" to work
                    205: -1 VALUE cpu-frequency
                    206: 
                    207: #include "helper.fs"
                    208: 260 cp
                    209: 
                    210: #include <timebase.fs>
                    211: 
1.1.1.3 ! root      212: 270 cp
        !           213: 
        !           214: #include <fcode/evaluator.fs>
        !           215: 
1.1       root      216: 280 cp
                    217: 
                    218: \ rtas-config is not used
                    219: 0 CONSTANT rtas-config
                    220: 
                    221: #include "rtas.fs"
                    222: 290 cp
                    223: s" update_flash.fs" included
                    224: 2a0 cp
                    225: cpu-mask @ rtas-fetch-cpus drop
                    226: 
                    227: : of-start-cpu rtas-start-cpu ;
                    228: 
                    229: ' power-off to halt
                    230: ' rtas-system-reboot to reboot
                    231: 
                    232: : other-firmware  rtas-get-flashside 0= IF 1 ELSE 0 THEN rtas-set-flashside reboot ;
                    233: : disable-boot-watchdog rtas-stop-bootwatchdog drop ;
                    234: ' disable-boot-watchdog to disable-watchdog
                    235: 
                    236: true value bmc?
                    237: false value debug-boot?
                    238: 
                    239: \ for JS21/Bimini try to detect BMC... if kcs (io @ca8) status is not ff...
                    240: u4? IF ca8 4 + io-c@ ff = IF false to bmc? true to debug-boot? THEN THEN
                    241: 
                    242: VARIABLE memnode
                    243: 
                    244: \ Hook to help loading our secondary boot loader.
                    245: DEFER disk-read ( lba cnt addr -- )
                    246: 0 VALUE disk-off
                    247: 
                    248: create vpd-cb 24 allot
                    249: create vpd-bootlist 4 allot
                    250: 2c0 cp
                    251: #include "ipmi-vpd.fs"
                    252: 2e0 cp
                    253: #include <quiesce.fs>
                    254: 300 cp
                    255: #include <usb/usb-static.fs>
                    256: 320 cp
                    257: #include <scsi-loader.fs>
                    258: #include <root.fs>
                    259: 360 cp
                    260: #include "tree.fs"
                    261: 
                    262: : .system-information  ( -- )
                    263:    s"                   " type cr
                    264:    s" SYSTEM INFORMATION" type cr
                    265:    s"  Processor  = " type s" cpu" get-chosen  IF
                    266:       drop l@ >r pvr@ s" pvr>name" r> $call-method type
                    267:       s"  @ " type cpu-frequency d# 1000000 /
                    268:       decimal . hex s" MHz" type
                    269:    THEN  cr s"  I/O Bridge = " type u3?  IF
                    270:       s" U3"  ELSE  s" U4"  THEN type
                    271:    f8000000 rl@ 4 rshift s"  (" type 1 0.r s" ." type
                    272:    f8000000 rl@ f and 1 0.r s" )" type cr
                    273:    s"  SMP Size   = " type cpu-mask @ cnt-bits 1 0.r
                    274:    s"  (" type cpu-report 8 emit s" )" type
                    275:    cr s"  Boot-Date  = " type .date cr
                    276:    s"  Memory     = " type s" memory" get-chosen  IF
                    277:       drop l@ s" mem-report" rot $call-method  THEN
                    278:    cr s"  Board Type = " type u3?  IF
                    279:       s" JS20(GA" type planar-id 5 >=  IF
                    280:          s" 2)" ELSE s" 1)" THEN type
                    281:    ELSE bimini?  IF  s" Bimini"  ELSE  s" JS21"  THEN  type  THEN
                    282:    s"  (" type .vpd-machine-type [char] / emit
                    283:    .vpd-machine-serial [char] / emit
                    284:    .vpd-hw-revision 8 emit  s" )" type cr
                    285:    s"  MFG Date   = " type .vpd-manufacturer-date cr
                    286:    s"  Part No.   = " type .vpd-part-number cr
                    287:    s"  FRU No.    = " type .vpd-fru-number cr
                    288:    s"  FRU Serial = " type .vpd-cardprefix-serial .vpd-card-serial cr
                    289:    s"  UUID       = " type .vpd-uuid cr
                    290:    s"  Flashside  = " type rtas-get-flashside 0=  IF
                    291:       ." 0 (permanent)"
                    292:    ELSE
                    293:       ." 1 (temporary)" THEN cr
                    294:    s"  Version    = " type 
                    295:    takeover?  IF
                    296:       romfs-base 38 + a type
                    297:    ELSE
                    298:       slof-build-id here swap rmove 
                    299:       here slof-build-id nip type cr
                    300:       s"  Build Date = " type bdate2human type
                    301:    THEN
                    302:    cr cr
                    303: ;
                    304: 
                    305: 800 cp
                    306: 
                    307: #include "nvram.fs"
                    308: takeover? not u4? and  IF
                    309:    \ if were are not in takeover mode the nvram should look
                    310:    \ something like this:
                    311:    \ type  size  name
                    312:    \ ========================
                    313:    \  51  20000  ibm,CPU0log
                    314:    \  51   5000  ibm,CPU1log
                    315:    \  70   1000  common
                    316:    \  7f  da000  <free-space>
                    317:    \ the partition with the type 51 should have been added
                    318:    \ by LLFW... if it does not exist then something went
                    319:    \ wrong and we just destroy the whole thing
                    320:    51 get-nvram-partition IF  0 0 nvram-c!  ELSE  2drop  THEN
                    321: THEN
                    322: 
                    323: 880 cp
                    324: 
                    325: \ dmesg/dmesg2 not available if running in takeover/ram mode or on js20
                    326: : dmesg  ( -- )  u3? takeover? or 0=  IF  dmesg  THEN ;
                    327: : dmesg2  ( -- )  u3? takeover? or 0=  IF  dmesg2  THEN ;
                    328: 
                    329: #include "envvar.fs"
                    330: check-for-nvramrc
                    331: 
                    332: 8a0 cp
                    333: \ The client interface.
                    334: #include "client.fs"
                    335: \ ELF binary file format.
                    336: #include "elf.fs"
                    337: #include <loaders.fs>
                    338: 
1.1.1.3 ! root      339: 8a8 cp
        !           340: 
1.1       root      341: \ check wether a VGA device was found during pci scan, if it was
                    342: \ try to initialize it and create the needed device-nodes
                    343: 0 value biosemu-vmem
                    344: 100000 value biosemu-vmem-size
                    345: 0 value screen-info
                    346: 
1.1.1.3 ! root      347: : init-vga-devices  ( -- )
        !           348:    vga-device-node? 0= use-biosemu? 0= OR IF
        !           349:       EXIT
        !           350:    THEN
1.1       root      351:    s" VGA Device found: " type vga-device-node? node>path type s"  initializing..." type cr
                    352:    \ claim virtual memory for biosemu of 1MB
                    353:    biosemu-vmem-size 4 claim to biosemu-vmem
                    354:    \ claim memory for screen-info struct (140 bytes)
                    355:    d# 140 4 claim to screen-info
                    356:    \ remember current-node (it might be node 0 so we cannot use get-node)
                    357:    current-node @
                    358:    \ change into vga device node
                    359:    vga-device-node? set-node
                    360:    \ run biosemu to initialize the vga card
                    361:    \ s" Time before biosemu:" type .date cr
                    362:    vga-device-node? node>path ( pathstr len )
                    363:    s" biosemu " biosemu-vmem $cathex ( pathstr len paramstr len )
                    364:    20 char-cat \ add a space ( pathstr len paramstr len )
                    365:    biosemu-vmem-size $cathex \ add VMEM Size ( pathstr len paramstr len )
                    366:    20 char-cat \ add a space ( pathstr len paramstr len )
                    367:    2swap $cat ( paramstr+path len )
                    368:    biosemu-debug 0<> IF
                    369:       20 char-cat biosemu-debug $cathex \ add biosemu-debug as param
                    370:       ( paramstr+path+biosemu-debug len )
                    371:    THEN
1.1.1.3 ! root      372:    .(client-exec) IF
        !           373:       ." biosemu client exec failed!" cr
        !           374:       set-node                          \ restore old current-node
        !           375:       EXIT
        !           376:    THEN
1.1       root      377:    \ s" Time after biosemu:" type .date cr
                    378:    s" VGA initialization: detecting displays..." type cr
                    379:    \ try to get info for two monitors
                    380:    2 0 DO 
                    381:       \ setup screen-info struct as input to get_vbe_info
                    382:       s" DDC" 0 char-cat screen-info swap move \ null-terminated "DDC" as signature
                    383:       d# 140 screen-info 4 + w! \ reserved size in bytes (see claim above)
                    384:       i screen-info 6 + c! \ monitor number
                    385:       \ 320 screen-info 7 + w! \ max. screen width (800)
                    386:       500 screen-info 7 + w! \ max. screen width (1280)
                    387:       \ following line would be the right thing to do, however environment seems not setup yet...
                    388:       \ screen-#columns char-width * 500 min 280 max screen-info 7 + w! \ max. screen width, calculated from environment variable screen-#columns, but max. 1280, min. 640...
                    389:       8 screen-info 9 + c! \ requested color depth (8bpp)
                    390:       \ d# 16 screen-info 9 + c! \ requested color depth (16bpp)
                    391:       \ execute get_vbe_info from load-base
                    392:       \ s" Time before client exec:" type .date cr
                    393:       \ since node>path overwrites strings created with s" 
                    394:       \ we need to call it before assembling the parameter string
                    395:       vga-device-node? node>path ( pathstr len )
                    396:       s" get_vbe_info " biosemu-vmem $cathex ( pathstr len paramstr len )
                    397:       20 char-cat \ add a space ( pathstr len paramstr len )
                    398:       biosemu-vmem-size $cathex \ add VMEM Size ( pathstr len paramstr len )
                    399:       20 char-cat \ add a space ( pathstr len paramstr len )
                    400:       2swap $cat ( paramstr+path len )
                    401:       20 char-cat
1.1.1.2   root      402:       screen-info $cathex
1.1.1.3 ! root      403:       .(client-exec) 0=
1.1       root      404:       \ s" Time after client exec:" type .date cr
1.1.1.3 ! root      405:       screen-info c@ 0<> AND IF
1.1       root      406:         s"   display " type i . s" found..." type 
                    407:         \ screen found
                    408:         \ create device entry
                    409:         get-node node>name \ get current nodes name (e.g. "vga") ( str len )
                    410:         i \ put display-num on the stack ( str len displaynum )
                    411:         new-device \ create new device
                    412:            s" vga-display.fs" included
                    413:         finish-device
                    414:         s" created." type cr
                    415:       THEN
                    416:    LOOP
                    417:    \ return to where we were before changing to vga device node
                    418:    set-node
                    419:    \ release the claimed memory
                    420:    screen-info d# 140 release 
                    421:    biosemu-vmem biosemu-vmem-size release
                    422: 
                    423:    s" VGA initialization done." type cr
1.1.1.3 ! root      424: ;
        !           425: 
        !           426: init-vga-devices
1.1       root      427: 
                    428: : enable-framebuffer-output  ( -- )
                    429: \ enable output on framebuffer
                    430:    s" screen" find-alias ?dup  IF
                    431:       \ we need to open/close the screen device once
                    432:       \ before "ticking" display-emit to emit
                    433:       open-dev close-node
                    434:       s" display-emit" $find  IF 
                    435:          to emit 
                    436:       ELSE
                    437:          2drop
                    438:       THEN
                    439:    THEN
                    440: ;
                    441: 
                    442: enable-framebuffer-output
                    443: 
                    444: 8b0 cp
                    445: 
                    446: \ do not let the usb scan overwrite the atapi cdrom alias
                    447: pci-cdrom-num TO cdrom-alias-num
                    448: usb-scan
                    449: 
                    450: : create-aliases  ( -- )
                    451:    s" net" s" net1" find-alias ?dup  IF  set-alias ELSE 2drop  THEN
                    452:    s" disk" s" disk0" find-alias ?dup  IF  set-alias  ELSE  2drop  THEN
                    453:    s" cdrom" s" cdrom0" find-alias ?dup  IF  set-alias  ELSE  2drop  THEN
                    454: ;
                    455: 
                    456: create-aliases
                    457: 
                    458: 8ff cp
                    459: 
                    460: .system-information
                    461: 
                    462: : directserial
                    463: u3? IF
                    464:        s" /ht/isa/serial@3f8" io
                    465: ELSE
                    466:        s" direct-serial?" evaluate IF s" /ht/isa/serial@2f8" io ELSE s" /ht/isa/serial@3f8" io THEN
                    467: THEN
                    468: ;
                    469: 
                    470: directserial
                    471:   
                    472: \ on bimini we want to automatically enable screen and keyboard, if they are detected...
                    473: bimini? IF
                    474:    key? IF
                    475:       cr ."    input available on current console input device, not switching input / output." cr
                    476:    ELSE
                    477:       \ this enables the framebuffer as primary output device
                    478:       s" screen" find-alias  IF  drop
                    479:          s" screen" output
                    480:          \ at this point serial output is theoretically disabled
                    481:          ."    screen detected and set as default output device" cr
                    482:       THEN
                    483:       \ enable USB keyboard
                    484:       s" keyboard" find-alias  IF  drop
                    485:          s" keyboard" input
                    486:          \ at this point serial input is disabled
                    487:          ."    keyboard detected and set as default input device" cr cr cr
                    488:          s"   Press 's' to enter Open Firmware." type cr
                    489:          500 ms
                    490:       THEN
                    491:    THEN
                    492: THEN
                    493: 
                    494: : .flashside
                    495:    cr ." The currently active flashside is: "
                    496:    rtas-get-flashside 0= IF ." 0 (permanent)" ELSE
                    497:    ." 1 (temporary)" THEN
                    498: ;
                    499: 
                    500: bmc? IF  disable-watchdog  THEN
                    501: 
                    502: : flashsave  ( "{filename}" -- rc )
                    503:   (parse-line) dup 0> IF
                    504:     s" netsave "             \ command
                    505:     get-flash-base $cathex   \ Flash base addr
                    506:     s"  400000 " $cat        \ Flash size (4MB)
                    507:     2swap $cat               \ add parameters from (parse-line)
                    508:     evaluate
                    509:   ELSE
                    510:     cr
                    511:     ." Usage: flashsave [bootp|dhcp,]filename[,siaddr][,ciaddr][,giaddr][,bootp-retries][,tftp-retries][,use_ci]"
                    512:     cr 2drop
                    513:   THEN
                    514: ;
                    515: 
                    516: #include <vpd-bootlist.fs>
                    517: 
                    518: \ for the blades we read the bootlist from the VPD
                    519: bimini? takeover? or 0=  IF  ['] vpd-boot-import to read-bootlist  THEN
                    520: 
                    521: \ for the bimini, we try to boot from disk, if it exists, 
                    522: \ only if "boot-device" is not set in the nvram
                    523: : bimini-bootlist
                    524:    \ check nvram
                    525:    s" boot-device" evaluate swap drop ( boot-device-strlen )
                    526:    0= IF
                    527:       \ no boot-device set in NVRAM, check if disk is available and set it...
                    528:       \ clear boot-device list
                    529:       0 0 set-boot-device
                    530:       s" disk" find-alias ?dup IF
                    531:          \ alias found, use it as default
                    532:          add-boot-device
                    533:       THEN
                    534:    THEN
                    535: ;
                    536: 
                    537: bimini? IF ['] bimini-bootlist to read-bootlist THEN
                    538: 
                    539: #include <start-up.fs>
                    540: 
                    541: #include <boot.fs>
                    542: 
                    543: cr .(   Welcome to Open Firmware)
                    544: cr
                    545: #include "copyright-oss.fs"
                    546: cr
                    547: 
                    548: \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
                    549: ' start-it CATCH drop
                    550: 
                    551: #include <history.fs>
                    552: nvram-history? [IF]
                    553: ." loading shell history .. "
                    554: history-load
                    555: ." done" cr
                    556: [THEN]
                    557: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.