Proper shell code support for Chipcon 8051 devices.
[goodfet] / client / GoodFETCC.py
1 #!/usr/bin/env python
2 # GoodFET Client Library
3
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
5 #
6 # This code is being rewritten and refactored.  You've been warned!
7
8 import sys;
9 import binascii;
10
11 from GoodFET import GoodFET;
12 from intelhex import IntelHex;
13
14 import xml.dom.minidom, time;
15
16 class GoodFETCC(GoodFET):
17     """A GoodFET variant for use with Chipcon 8051 Zigbee SoC."""
18     APP=0x30;
19     
20     
21     
22     
23     smartrfpath="/opt/smartrf7";
24     def loadsymbols(self):
25         try: self.SRF_loadsymbols();
26         except:
27             if self.verbose>0: print "SmartRF not found at %s." % self.smartrfpath;
28     def SRF_chipdom(self,chip="cc1110", doc="register_definition.xml"):
29         fn="%s/config/xml/%s/%s" % (self.smartrfpath,chip,doc);
30         #print "Opening %s" % fn;
31         return xml.dom.minidom.parse(fn)
32         
33     def CMDrs(self,args=[]):
34         """Chip command to grab the radio state."""
35         try:
36             self.SRF_radiostate();
37         except:
38             print "Error printing radio state.";
39             print "SmartRF not found at %s." % self.smartrfpath;
40     def SRF_bitfieldstr(self,bf):
41         name="unused";
42         start=0;
43         stop=0;
44         access="";
45         reset="0x00";
46         description="";
47         for e in bf.childNodes:
48             if e.localName=="Name" and e.childNodes: name= e.childNodes[0].nodeValue;
49             elif e.localName=="Start": start=e.childNodes[0].nodeValue;
50             elif e.localName=="Stop": stop=e.childNodes[0].nodeValue;
51         return "   [%s:%s] %30s " % (start,stop,name);
52     def SRF_radiostate(self):
53         ident=self.CCident();
54         chip=self.CCversions.get(ident&0xFF00);
55         dom=self.SRF_chipdom(chip,"register_definition.xml");
56         for e in dom.getElementsByTagName("registerdefinition"):
57             for f in e.childNodes:
58                 if f.localName=="DeviceName":
59                     print "// %s RadioState" % (f.childNodes[0].nodeValue);
60                 elif f.localName=="Register":
61                     name="unknownreg";
62                     address="0xdead";
63                     description="";
64                     bitfields="";
65                     for g in f.childNodes:
66                         if g.localName=="Name":
67                             name=g.childNodes[0].nodeValue;
68                         elif g.localName=="Address":
69                             address=g.childNodes[0].nodeValue;
70                         elif g.localName=="Description":
71                             if g.childNodes:
72                                 description=g.childNodes[0].nodeValue;
73                         elif g.localName=="Bitfield":
74                             bitfields+="%17s/* %-50s */\n" % ("",self.SRF_bitfieldstr(g));
75                     #print "SFRX(%10s, %s); /* %50s */" % (name,address, description);
76                     print "%-10s=0x%02x; /* %-50s */" % (
77                         name,self.CCpeekdatabyte(eval(address)), description);
78                     if bitfields!="": print bitfields.rstrip();
79     def RF_setfreq(self,frequency):
80         """Set the frequency in Hz."""
81         #FIXME CC1110 specific
82         
83         hz=frequency;
84         freq=int(hz/396.728515625);
85         
86         freq0=freq&0xFF;
87         freq1=(freq&0xFF00)>>8;
88         freq2=(freq&0xFF0000)>>16;
89         
90         self.pokebysym("FREQ2",freq2);
91         self.pokebysym("FREQ1",freq1);
92         self.pokebysym("FREQ0",freq0);
93         
94
95     def RF_getfreq(self):
96         """Get the frequency in Hz."""
97         #FIXME CC1110 specific
98         
99         #return (2400+self.peek(0x05))*10**6
100         #self.poke(0x05,chan);
101         
102         #freq2=self.CCpeekdatabyte(0xdf09);
103         #freq1=self.CCpeekdatabyte(0xdf0a);
104         #freq0=self.CCpeekdatabyte(0xdf0b);
105         freq=0;
106         try:
107             freq2=self.peekbysym("FREQ2");
108             freq1=self.peekbysym("FREQ1");
109             freq0=self.peekbysym("FREQ0");
110             freq=(freq2<<16)+(freq1<<8)+freq0;
111         except:
112             freq=0;
113             
114         hz=freq*396.728515625;
115         
116         return hz;
117     
118     def shellcode(self,code,wait=1):
119         """Copy a block of code into RAM and execute it."""
120         i=0;
121         ram=0xF000;
122         for byte in code:
123             self.pokebyte(0xF000+i,byte);
124             i=i+1;
125         print "Code loaded, executing."
126         self.CCdebuginstr([0x02, 0xf0, 0x00]); #ljmp 0xF000
127         self.resume();
128         while wait>0 and (0==self.CCstatus()&0x20):
129             time.sleep(0.1);
130             print "Waiting for shell code to return.";
131         return;
132     def CC1110_crystal(self):
133         """Start the main crystal of the CC1110 oscillating, needed for radio use."""
134         code=[0x53, 0xBE, 0xFB, #anl SLEEP, #0xFB
135               #one:
136               0xE5, 0xBE,       #mov a,SLEEP
137               0x30, 0xE6, 0xFB, #jnb acc.6, back
138               0x53, 0xc6, 0xB8, #anl CLKCON, #0xB8
139               #two
140               0xE5, 0xC6,       #mov a,CLKCON
141               0x20, 0xE6, 0xFB, #jb acc.6, two
142               0x43, 0xBE, 0x04, #orl SLEEP, #0x04
143               0xA5,             #HALT
144               ];
145         self.shellcode(code);
146         return;
147     def RF_idle(self):
148         RFST=0xDFE1
149         self.pokebyte(RFST,0x04); #Return to idle state.
150         
151     def RF_carrier(self):
152         """Hold a carrier wave on the present frequency."""
153         
154         self.CC1110_crystal(); #FIXME, '1110 specific.
155         self.RF_idle();
156         
157         #self.resume();
158         #time.sleep(1);
159         #self.halt();
160         
161         RFST=0xDFE1;
162         
163         
164         #0a00
165         #self.pokebysym("FSCTRL1"  , 0x12)   # Frequency synthesizer control.
166         #self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
167         self.pokebysym("FSCTRL1"  , 0x0a)   # Frequency synthesizer control.
168         self.pokebysym("FSCTRL0"  , 0x00)   # Frequency synthesizer control.
169         
170         #Don't change these while the radio is active.
171         self.pokebysym("FSCAL3"   , 0xA9)   # Frequency synthesizer calibration.
172         self.pokebysym("FSCAL2"   , 0x0A)   # Frequency synthesizer calibration.
173         self.pokebysym("FSCAL1"   , 0x00)   # Frequency synthesizer calibration.
174         self.pokebysym("FSCAL0"   , 0x11)   # Frequency synthesizer calibration.
175         
176         #Ossmann's settings, not yet sure how they differ.
177         #self.pokebysym("FSCAL3"   , 0xEA)   # Frequency synthesizer calibration.
178         #self.pokebysym("FSCAL2"   , 0x2A)   # Frequency synthesizer calibration.
179         #self.pokebysym("FSCAL1"   , 0x00)   # Frequency synthesizer calibration.
180         #self.pokebysym("FSCAL0"   , 0x1F)   # Frequency synthesizer calibration.
181         
182         
183         #self.pokebysym("FREQ2"    , 0x10)   # Frequency control word, high byte.
184         #self.pokebysym("FREQ1"    , 0xEC)   # Frequency control word, middle byte.
185         #self.pokebysym("FREQ0"    , 0x4E)   # Frequency control word, low byte.
186         self.pokebysym("MDMCFG4"  , 0x86)   # Modem configuration.
187         self.pokebysym("MDMCFG3"  , 0x83)   # Modem configuration.
188         self.pokebysym("MDMCFG2"  , 0x30)   # Modem configuration.
189         self.pokebysym("MDMCFG1"  , 0x22)   # Modem configuration.
190         self.pokebysym("MDMCFG0"  , 0xF8)   # Modem configuration.
191         self.pokebysym("CHANNR"   , 0x00)   # Channel number.
192         self.pokebysym("DEVIATN"  , 0x00)   # Modem deviation setting (when FSK modulation is enabled).
193         self.pokebysym("FREND1"   , 0x56)   # Front end RX configuration.
194         
195         self.pokebysym("FREND0"   , 0x10)   # Front end RX configuration.
196         self.pokebysym("MCSM0"    , 0x14)   # Main Radio Control State Machine configuration.
197         self.pokebysym("FOCCFG"   , 0x16)   # Frequency Offset Compensation Configuration.
198         self.pokebysym("BSCFG"    , 0x6C)   # Bit synchronization Configuration.
199         
200         self.pokebysym("AGCCTRL2" , 0x03)   # AGC control.
201         self.pokebysym("AGCCTRL1" , 0x40)   # AGC control.
202         self.pokebysym("AGCCTRL0" , 0x91)   # AGC control.
203         
204         
205         
206         
207         
208         
209         self.pokebysym("TEST2"    , 0x88)   # Various test settings.
210         self.pokebysym("TEST1"    , 0x31)   # Various test settings.
211         self.pokebysym("TEST0"    , 0x09)   # Various test settings.
212         self.pokebysym("PA_TABLE0", 0xC0)   # PA output power setting.
213         self.pokebysym("PKTCTRL1" , 0x04)   # Packet automation control.
214         self.pokebysym("PKTCTRL0" , 0x22)   # Packet automation control.
215         self.pokebysym("ADDR"     , 0x00)   # Device address.
216         self.pokebysym("PKTLEN"   , 0xFF)   # Packet length.
217         
218         self.pokebysym("SYNC1",0xAA);
219         self.pokebysym("SYNC0",0xAA);
220         
221         
222                 
223         #while ((MARCSTATE & MARCSTATE_MARC_STATE) != MARC_STATE_TX); 
224         state=0;
225         
226         while((state!=0x13)):
227             self.pokebyte(RFST,0x03); #RFST=RFST_STX
228             time.sleep(0.1);
229             state=self.peekbysym("MARCSTATE")&0x1F;
230             print "state=%02x" % state;
231         print "Holding a carrier on %f MHz." % (self.RF_getfreq()/10**6);
232         
233         #Not needed, radio works when CPU is halted.
234         #self.resume();
235         
236         return;
237             
238             
239     def RF_getrssi(self):
240         """Returns the received signal strenght, with a weird offset."""
241         try:
242             rssireg=self.symbols.get("RSSI");
243             return self.CCpeekdatabyte(rssireg);
244         except:
245             if self.verbose>0: print "RSSI reg doesn't exist.";
246         try:
247             #RSSI doesn't exist on 2.4GHz devices.  Maybe RSSIL and RSSIH?
248             rssilreg=self.symbols.get("RSSIL");
249             rssil=self.CCpeekdatabyte(rssilreg);
250             rssihreg=self.symbols.get("RSSIL");
251             rssih=self.CCpeekdatabyte(rssihreg);
252             return (rssih<<8)|rssil;
253         except:
254             if self.verbose>0: print "RSSIL/RSSIH regs don't exist.";
255         
256         return 0;
257             
258     
259     def SRF_loadsymbols(self):
260         ident=self.CCident();
261         chip=self.CCversions.get(ident&0xFF00);
262         dom=self.SRF_chipdom(chip,"register_definition.xml");
263         for e in dom.getElementsByTagName("registerdefinition"):
264             for f in e.childNodes:
265                 if f.localName=="Register":
266                     name="unknownreg";
267                     address="0xdead";
268                     description="";
269                     bitfields="";
270                     for g in f.childNodes:
271                         if g.localName=="Name":
272                             name=g.childNodes[0].nodeValue;
273                         elif g.localName=="Address":
274                             address=g.childNodes[0].nodeValue;
275                         elif g.localName=="Description":
276                             if g.childNodes:
277                                 description=g.childNodes[0].nodeValue;
278                         elif g.localName=="Bitfield":
279                             bitfields+="%17s/* %-50s */\n" % ("",self.SRF_bitfieldstr(g));
280                     #print "SFRX(%10s, %s); /* %50s */" % (name,address, description);
281                     self.symbols.define(eval(address),name,description,"data");
282     def halt(self):
283         """Halt the CPU."""
284         self.CChaltcpu();
285     def CChaltcpu(self):
286         """Halt the CPU."""
287         self.writecmd(self.APP,0x86,0,self.data);
288     def resume(self):
289         self.CCreleasecpu();
290     def CCreleasecpu(self):
291         """Resume the CPU."""
292         self.writecmd(self.APP,0x87,0,self.data);
293     def test(self):
294         self.CCreleasecpu();
295         self.CChaltcpu();
296         #print "Status: %s" % self.CCstatusstr();
297         
298         #Grab ident three times, should be equal.
299         ident1=self.CCident();
300         ident2=self.CCident();
301         ident3=self.CCident();
302         if(ident1!=ident2 or ident2!=ident3):
303             print "Error, repeated ident attempts unequal."
304             print "%04x, %04x, %04x" % (ident1, ident2, ident3);
305         
306         #Single step, printing PC.
307         print "Tracing execution at startup."
308         for i in range(1,15):
309             pc=self.CCgetPC();
310             byte=self.CCpeekcodebyte(i);
311             #print "PC=%04x, %02x" % (pc, byte);
312             self.CCstep_instr();
313         
314         print "Verifying that debugging a NOP doesn't affect the PC."
315         for i in range(1,15):
316             pc=self.CCgetPC();
317             self.CCdebuginstr([0x00]);
318             if(pc!=self.CCgetPC()):
319                 print "ERROR: PC changed during CCdebuginstr([NOP])!";
320         
321         print "Checking pokes to XRAM."
322         for i in range(0xf000,0xf020):
323             self.CCpokedatabyte(i,0xde);
324             if(self.CCpeekdatabyte(i)!=0xde):
325                 print "Error in XDATA at 0x%04x" % i;
326         
327         #print "Status: %s." % self.CCstatusstr();
328         #Exit debugger
329         self.stop();
330         print "Done.";
331
332     def setup(self):
333         """Move the FET into the CC2430/CC2530 application."""
334         #print "Initializing Chipcon.";
335         self.writecmd(self.APP,0x10,0,self.data);
336     def CCrd_config(self):
337         """Read the config register of a Chipcon."""
338         self.writecmd(self.APP,0x82,0,self.data);
339         return ord(self.data[0]);
340     def CCwr_config(self,config):
341         """Write the config register of a Chipcon."""
342         self.writecmd(self.APP,0x81,1,[config&0xFF]);
343     def CClockchip(self):
344         """Set the flash lock bit in info mem."""
345         self.writecmd(self.APP, 0x9A, 0, None);
346     def lock(self):
347         """Set the flash lock bit in info mem."""
348         self.CClockchip();
349     
350
351     CCversions={0x0100:"cc1110",
352                 0x1100:"cc1111",
353                 0x8500:"cc2430",
354                 0x8900:"cc2431",
355                 0x8100:"cc2510",
356                 0x9100:"cc2511",
357                 0xA500:"cc2530", #page 52 of SWRU191
358                 0xB500:"cc2531",
359                 0xFF00:"CCmissing"};
360     CCpagesizes={0x01: 1024, #"CC1110",
361                  0x11: 1024, #"CC1111",
362                  0x85: 2048, #"CC2430",
363                  0x89: 2048, #"CC2431",
364                  0x81: 1024, #"CC2510",
365                  0x91: 1024, #"CC2511",
366                  0xA5: 2048, #"CC2530", #page 52 of SWRU191
367                  0xB5: 2048, #"CC2531",
368                  0xFF: 0    } #"CCmissing"};
369     def infostring(self):
370         return self.CCidentstr();
371     def CCidentstr(self):
372         ident=self.CCident();
373         chip=self.CCversions.get(ident&0xFF00);
374         pagesize=self.CCpagesizes.get(ident>0xFF);
375         try:
376             return "%s/r%0.4x/ps0x%0.4x" % (chip, ident, pagesize); 
377         except:
378             return "%04x" % ident;
379     def CCident(self):
380         """Get a chipcon's ID."""
381         self.writecmd(self.APP,0x8B,0,None);
382         chip=ord(self.data[0]);
383         rev=ord(self.data[1]);
384         return (chip<<8)+rev;
385     def CCpagesize(self):
386         """Get a chipcon's ID."""
387         self.writecmd(self.APP,0x8B,0,None);
388         chip=ord(self.data[0]);
389         size=self.CCpagesizes.get(chip);
390         if(size<10):
391             print "ERROR: Pagesize undefined.";
392             print "chip=%0.4x" %chip;
393             sys.exit(1);
394             #return 2048;
395         return size;
396     def getpc(self):
397         return self.CCgetPC();
398     def CCgetPC(self):
399         """Get a chipcon's PC."""
400         self.writecmd(self.APP,0x83,0,None);
401         hi=ord(self.data[0]);
402         lo=ord(self.data[1]);
403         return (hi<<8)+lo;
404     def CCcmd(self,phrase):
405         self.writecmd(self.APP,0x00,len(phrase),phrase);
406         val=ord(self.data[0]);
407         print "Got %02x" % val;
408         return val;
409     def CCdebuginstr(self,instr):
410         self.writecmd(self.APP,0x88,len(instr),instr);
411         return ord(self.data[0]);
412     def peekblock(self,adr,length,memory="vn"):
413         """Return a block of data."""
414         data=[adr&0xff, (adr&0xff00)>>8,
415               length&0xFF,(length&0xFF00)>>8];
416         self.writecmd(self.APP,0x91,4,data);
417         return [ord(x) for x in self.data]
418     def peek8(self,address, memory="code"):
419         if(memory=="code" or memory=="flash" or memory=="vn"):
420             return self.CCpeekcodebyte(address);
421         elif(memory=="data" or memory=="xdata" or memory=="ram"):
422             return self.CCpeekdatabyte(address);
423         elif(memory=="idata" or memory=="iram"):
424             return self.CCpeekirambyte(address);
425         print "%s is an unknown memory." % memory;
426         return 0xdead;
427     def CCpeekcodebyte(self,adr):
428         """Read the contents of code memory at an address."""
429         self.data=[adr&0xff, (adr&0xff00)>>8];
430         self.writecmd(self.APP,0x90,2,self.data);
431         return ord(self.data[0]);
432     def CCpeekdatabyte(self,adr):
433         """Read the contents of data memory at an address."""
434         self.data=[adr&0xff, (adr&0xff00)>>8];
435         self.writecmd(self.APP,0x91, 2, self.data);
436         return ord(self.data[0]);
437     def CCpeekirambyte(self,adr):
438         """Read the contents of IRAM at an address."""
439         self.data=[adr&0xff];
440         self.writecmd(self.APP,0x02, 1, self.data);
441         return ord(self.data[0]);
442     def CCpeekiramword(self,adr):
443         """Read the little-endian contents of IRAM at an address."""
444         return self.CCpeekirambyte(adr)+(
445             self.CCpeekirambyte(adr+1)<<8);
446     def CCpokeiramword(self,adr,val):
447         self.CCpokeirambyte(adr,val&0xff);
448         self.CCpokeirambyte(adr+1,(val>>8)&0xff);
449     def CCpokeirambyte(self,adr,val):
450         """Write the contents of IRAM at an address."""
451         self.data=[adr&0xff, val&0xff];
452         self.writecmd(self.APP,0x02, 2, self.data);
453         return ord(self.data[0]);
454     def pokebyte(self,adr,val,mem="data"):
455         if mem!="data":
456             print "FIXME: poking of non data bytes not yet supported.";
457         self.CCpokedatabyte(adr,val);
458     def CCpokedatabyte(self,adr,val):
459         """Write a byte to data memory."""
460         self.data=[adr&0xff, (adr&0xff00)>>8, val];
461         self.writecmd(self.APP, 0x92, 3, self.data);
462         return ord(self.data[0]);
463     def CCchiperase(self):
464         """Erase all of the target's memory."""
465         self.writecmd(self.APP,0x80,0,None);
466     def erase(self):
467         """Erase all of the target's memory."""
468         self.CCchiperase();
469         self.start();
470     
471     def CCstatus(self):
472         """Check the status."""
473         self.writecmd(self.APP,0x84,0,None);
474         return ord(self.data[0])
475     #Same as CC2530
476     CCstatusbits={0x80 : "erase_busy",
477                   0x40 : "pcon_idle",
478                   0x20 : "cpu_halted",
479                   0x10 : "pm0",
480                   0x08 : "halt_status",
481                   0x04 : "locked",
482                   0x02 : "oscstable",
483                   0x01 : "overflow"
484                   };
485     CCconfigbits={0x20 : "soft_power_mode",   #new for CC2530
486                   0x08 : "timers_off",
487                   0x04 : "dma_pause",
488                   0x02 : "timer_suspend",
489                   0x01 : "sel_flash_info_page" #stricken from CC2530
490                   };
491                   
492     def status(self):
493         """Check the status as a string."""
494         status=self.CCstatus();
495         str="";
496         i=1;
497         while i<0x100:
498             if(status&i):
499                 str="%s %s" %(self.CCstatusbits[i],str);
500             i*=2;
501         return str;
502     def start(self):
503         """Start debugging."""
504         self.setup();
505         self.writecmd(self.APP,0x20,0,self.data);
506         ident=self.CCidentstr();
507         #print "Target identifies as %s." % ident;
508         #print "Status: %s." % self.status();
509         self.CCreleasecpu();
510         self.CChaltcpu();
511         #Get SmartRF Studio regs if they exist.
512         self.loadsymbols(); 
513         
514     def stop(self):
515         """Stop debugging."""
516         self.writecmd(self.APP,0x21,0,self.data);
517     def CCstep_instr(self):
518         """Step one instruction."""
519         self.writecmd(self.APP,0x89,0,self.data);
520     def CCeraseflashbuffer(self):
521         """Erase the 2kB flash buffer"""
522         self.writecmd(self.APP,0x99);
523     def CCflashpage(self,adr):
524         """Flash 2kB a page of flash from 0xF000 in XDATA"""
525         data=[adr&0xFF,
526               (adr>>8)&0xFF,
527               (adr>>16)&0xFF,
528               (adr>>24)&0xFF];
529         print "Flashing buffer to 0x%06x" % adr;
530         self.writecmd(self.APP,0x95,4,data);
531     
532     def setsecret(self,value):
533         """Set a secret word for later retreival.  Used by glitcher."""
534         page = 0x0000;
535         pagelen = self.CCpagesize(); #Varies by chip.
536         print "page=%04x, pagelen=%04x" % (page,pagelen);
537         
538         self.CCeraseflashbuffer();
539         print "Setting secret to %x" % value;
540         self.CCpokedatabyte(0xF000,value);
541         self.CCpokedatabyte(0xF800,value);
542         print "Setting secret to %x==%x" % (value,
543                                             self.CCpeekdatabyte(0xf000));
544         self.CCflashpage(0);
545         print "code[0]=%x" % self.CCpeekcodebyte(0);
546     def getsecret(self):
547         """Get a secret word.  Used by glitcher."""
548         secret=self.CCpeekcodebyte(0);
549         #print "Got secret %02x" % secret;
550         return secret;
551     
552     def dump(self,file,start=0,stop=0xffff):
553         """Dump an intel hex file from code memory."""
554         print "Dumping code from %04x to %04x as %s." % (start,stop,file);
555         h = IntelHex(None);
556         i=start;
557         while i<=stop:
558             h[i]=self.CCpeekcodebyte(i);
559             if(i%0x100==0):
560                 print "Dumped %04x."%i;
561                 h.write_hex_file(file); #buffer to disk.
562             i+=1;
563         h.write_hex_file(file);
564
565     def flash(self,file):
566         """Flash an intel hex file to code memory."""
567         print "Flashing %s" % file;
568         
569         h = IntelHex(file);
570         page = 0x0000;
571         pagelen = self.CCpagesize(); #Varies by chip.
572         
573         #print "page=%04x, pagelen=%04x" % (page,pagelen);
574         
575         bcount = 0;
576         
577         #Wipe the RAM buffer for the next flash page.
578         self.CCeraseflashbuffer();
579         for i in h._buf.keys():
580             while(i>=page+pagelen):
581                 if bcount>0:
582                     self.CCflashpage(page);
583                     #client.CCeraseflashbuffer();
584                     bcount=0;
585                     print "Flashed page at %06x" % page
586                 page+=pagelen;
587                     
588             #Place byte into buffer.
589             self.CCpokedatabyte(0xF000+i-page,
590                                 h[i]);
591             bcount+=1;
592             if(i%0x100==0):
593                 print "Buffering %04x toward %06x" % (i,page);
594         #last page
595         self.CCflashpage(page);
596         print "Flashed final page at %06x" % page;
597