revert between 56095 -> 55830 in arch
[AROS.git] / arch / .unmaintained / m68k-pp-native / TxElf / TxElf.c
blob80bbc16a9aaee38de8253b81eb413b7f3dcf05c6
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/alib.h>
11 #include <dos/dos.h>
12 #include <dos/exall.h>
13 #include <dos/rdargs.h>
14 #include <dos/var.h>
15 #include <exec/memory.h>
16 #include <exec/types.h>
17 #include <exec/lists.h>
18 #include <devices/serial.h>
20 #include <aros/macros.h>
22 #include <stdio.h>
23 #include <string.h>
25 #define PARAM "FILE/A,UNIT=UNITNUM/K/N,START/S"
26 #define ARG_FILENAME 0
27 #define ARG_UNITNUM 1
28 #define ARG_START 2
29 #define TOTAL_ARGS 3
31 #define BAUDRATE 57600
33 int start_protocol(struct IOExtSer *, ULONG, char * );
35 struct Packet;
37 void free_packet(struct Packet * packet);
38 void free_all_packets(void);
40 struct List PacketList;
41 struct List PilotMemList;
43 int main(void)
45 struct RDArgs * rda;
46 IPTR * args[TOTAL_ARGS] = {NULL, NULL};
47 int unitnum = 0;
48 int baudrate = BAUDRATE;
49 struct IOExtSer * IORequest;
50 int err;
51 struct MsgPort * SerPort;
52 int flags;
53 struct Interrupt SerInterrupt;
55 NEWLIST(&PacketList);
56 NEWLIST(&PilotMemList);
58 rda = ReadArgs(PARAM, (IPTR *)args, NULL);
59 if (rda) {
60 if (NULL != args[ARG_UNITNUM])
61 unitnum = *args[ARG_UNITNUM];
63 printf("Opening serial port unit %d with %d baud.\n",
64 unitnum,
65 baudrate);
67 SerPort = CreatePort("serial port message port",0);
68 IORequest = (struct IOExtSer *)CreateExtIO(SerPort, sizeof(struct IOExtSer));
70 err = OpenDevice("serial.device",unitnum,(struct IORequest *)IORequest,flags);
72 if (0 == err) {
74 * Try to set the baudrate.
76 IORequest->IOSer.io_Command = SDCMD_SETPARAMS;
77 IORequest->io_Baud = baudrate;
78 // DoIO((struct IORequest *)IORequest);
79 if (0 == ((struct IORequest *)IORequest)->io_Error) {
81 * serial device is opened.
82 * baud rate is set.
83 * so let's start.
85 printf("All set!\n");
86 err = start_protocol(IORequest, args[ARG_START], args[ARG_FILENAME]);
87 } else {
88 printf("Could not set baudrate!\n");
90 free_all_packets();
91 CloseDevice((struct IORequest *)IORequest);
92 } else {
93 printf("Could not open serial device unit %d.\n",unitnum);
95 DeleteExtIO((struct IORequest *)IORequest);
96 FreeArgs(rda);
97 } else {
98 printf("Forgot to give a mandator argument?\n");
101 return 0;
104 #define TYPE_HANDSHAKE 0x01
105 #define TYPE_READ_MEM 0x02
106 #define TYPE_WRITE_MEM 0x03
107 #define TYPE_MEM_CONTENT 0x04
108 #define TYPE_WRITE_MEM_ACK 0x05
109 #define TYPE_GET_SPECIAL_INFO 0x06
110 #define TYPE_START_PROGRAM 0x07
111 #define TYPE_START_PROGRAM_ACK 0x08
112 #define TYPE_QUIT 0x10
114 struct Packet
116 struct Node next_packet;
117 UWORD payload_length;
118 UBYTE payload_type;
119 BYTE * payload;
120 int state;
121 UWORD pos;
124 enum {
125 GET_FRAME_BEGINNING = 0x01,
126 GET_PAYLOAD_LENGTH_HI,
127 GET_PAYLOAD_LENGTH_LO,
128 GET_TYPE,
129 GET_PAYLOAD,
130 GET_FRAME_END
133 void free_packet(struct Packet * packet)
135 if (packet->payload)
136 FreeMem(packet->payload,packet->payload_length);
137 FreeMem(packet, sizeof(struct Packet));
140 struct Packet * current_packet;
142 void free_all_packets(void)
144 struct Packet * p;
145 if (NULL != current_packet) {
146 free_packet(current_packet);
149 while (NULL != (p = (struct Packet *)RemHead(&PacketList)))
150 free_packet(p);
153 struct Packet * get_next_packet(struct IOExtSer * IORequest)
155 struct Packet * p = NULL;
156 ULONG len;
157 IORequest->IOSer.io_Command = SDCMD_QUERY;
158 DoIO((struct IORequest *)IORequest);
160 if (0 != (len = IORequest->IOSer.io_Actual)) {
161 char * buf;
162 int i;
163 // printf("Reading %ld bytes from serial port.\n",
164 // IORequest->IOSer.io_Actual);
166 buf = AllocMem(len, MEMF_ANY);
167 if (NULL != buf) {
169 IORequest->IOSer.io_Command = CMD_READ;
170 IORequest->IOSer.io_Flags = IOF_QUICK;
171 IORequest->IOSer.io_Length = len;
172 IORequest->IOSer.io_Data = buf;
174 DoIO((struct IORequest *)IORequest);
177 i = 0;
178 while (i < len) {
180 if (NULL == current_packet) {
181 current_packet = AllocMem(sizeof(struct Packet),
182 MEMF_CLEAR);
183 current_packet->state = GET_FRAME_BEGINNING;
186 switch (current_packet->state) {
187 case GET_FRAME_BEGINNING:
188 if (0x7f == buf[i])
189 current_packet->state = GET_PAYLOAD_LENGTH_HI;
190 else
191 printf("Could not find beginning of frame. Dropping byte (x%02x)!\n",
192 buf[i]);
193 i++;
194 break;
196 case GET_PAYLOAD_LENGTH_HI:
197 current_packet->payload_length = ((UWORD)buf[i]) << 8;
198 current_packet->state = GET_PAYLOAD_LENGTH_LO;
199 i++;
200 break;
202 case GET_PAYLOAD_LENGTH_LO:
203 current_packet->payload_length |= ((UWORD)buf[i]);
204 current_packet->state = GET_TYPE;
205 current_packet->payload = AllocMem(current_packet->payload_length, MEMF_ANY);
206 i++;
207 //printf("Reading packet with length %d\n",current_packet->payload_length);
208 break;
210 case GET_TYPE:
211 current_packet->payload_type = buf[i];
212 current_packet->state = GET_PAYLOAD;
213 i++;
214 break;
216 case GET_PAYLOAD:
217 while (i < len &&
218 current_packet->pos < current_packet->payload_length) {
219 if (0x7f == buf[i]) {
221 * Must not appear here!
223 //printf("Received faulty packet (x%02x). Dropping it.\n",buf[i]);
224 free_packet(current_packet);
225 current_packet = NULL;
226 break;
228 current_packet->payload[current_packet->pos++] = buf[i];
229 i++;
230 //printf("%c\n",buf[i]);
233 if (current_packet->pos == current_packet->payload_length)
234 current_packet->state = GET_FRAME_END;
235 break;
237 case GET_FRAME_END:
238 if (0x7f == buf[i]) {
239 AddTail(&PacketList,
240 &current_packet->next_packet);
241 //printf("Got a complete packet!\n");
242 } else {
243 //printf("Received faulty packet (x%02x). Dropping it.\n",buf[i]);
244 free_packet(current_packet);
245 current_packet = NULL;
247 i++;
248 current_packet = NULL;
249 break;
251 default:
252 printf("Error!\n");
253 i++;
259 * Try to get the first complete packet in the list.
261 p = (struct Packet *)RemHead(&PacketList);
262 if (NULL != p) {
263 int i = 0;
264 int c = 0;
266 //printf("Will return a packet!\n");
268 * Reconvert the payload (if necessary)
270 while (i < p->payload_length) {
271 if (0x27 == p->payload[i])
272 c++;
273 i++;
276 if (c != 0) {
278 * Un-convert the payload
280 char * pl = AllocMem(p->payload_length - c, MEMF_ANY);
281 printf("Unconverting payload!\n");
282 if (NULL != pl) {
283 int _i = 0;
284 i = 0;
285 while (i < p->payload_length) {
286 if (0x27 == p->payload[i]) {
287 if (0x28 == p->payload[i+1]) {
288 pl[_i] = 0x27;
289 } else
290 pl[_i] = 0x7f;
291 i++;
292 } else
293 pl[_i] = p->payload[i];
295 i++;
296 _i++;
299 FreeMem(p->payload, p->payload_length);
300 p->payload = pl;
301 p->payload_length -= c;
304 return p;
309 void send_packet(struct IOExtSer * IORequest, char * buffer, UWORD len, UBYTE type)
311 ULONG i = 0, c = 0;
312 char * packet;
313 while (i < len) {
315 * Count number of characters to escape.
317 if (0x7f == buffer[i] || 0x27 == buffer[i])
318 c++;
319 i++;
322 packet = AllocMem(1 + /* frame begin */
323 2 + /* length of payload indicator */
324 1 + /* type */
325 len + c + /* payload */
326 1 /* frame end */,
327 MEMF_ANY);
329 if (NULL != packet) {
330 int pos = 4;
331 packet[0] = 0x7f;
332 packet[1] = ((len+c) >> 8) & 0xff;
333 packet[2] = ((len+c) ) & 0xff;
334 packet[3] = type;
336 i = 0;
338 * convert forbidden bytes.
340 while (i < len) {
341 if (0x7f == buffer[i]) {
342 packet[pos++] = 0x27;
343 packet[pos] = 0x29; /* = 0x7f */
344 printf("Converting packet to send!\n");
345 } else if (0x27 == buffer[i]) {
346 packet[pos++] = 0x27;
347 packet[pos] = 0x28; /* = 0x27 */
348 printf("Converting packet to send!\n");
349 } else {
350 packet[pos] = buffer[i];
352 pos++;
353 i++;
356 * End marker for the packet.
358 packet[pos] = 0x7f;
361 * Send this packet
363 IORequest->IOSer.io_Command = CMD_WRITE;
364 IORequest->IOSer.io_Flags = 0;
365 IORequest->IOSer.io_Length = pos+1;
366 IORequest->IOSer.io_Data = packet;
368 DoIO((struct IORequest *)IORequest);
369 FreeMem(packet, pos+1);
375 * Do a handshake. Other side sends "AROS?", I send back "AROS!" and get back
376 * "greets!".
378 int do_handshake(struct IOExtSer * IORequest)
380 struct Packet * packet;
381 int ctr = 0;
382 BOOL found = FALSE;
384 while (ctr < 10) {
385 packet = get_next_packet(IORequest);
386 if (NULL != packet) {
387 if (0 == strncmp("AROS?",&packet->payload[0],5) &&
388 5 == packet->payload_length) {
389 printf("Got 'AROS?' Sending 'AROS!'\n");
390 free_packet(packet);
391 send_packet(IORequest,"AROS!",5, TYPE_HANDSHAKE);
392 found = TRUE;
393 break;
394 } else {
395 printf("Wrong payload: %s\n",packet->payload);
397 free_packet(packet);
399 ctr++;
400 Delay(50);
403 if (FALSE == found) {
404 return -1;
407 found = FALSE;
408 ctr = 0;
410 while (ctr < 4) {
411 packet = get_next_packet(IORequest);
412 if (NULL != packet) {
413 if (0 == strncmp("greets!",&packet->payload[0],7) &&
414 7 == packet->payload_length) {
415 free_packet(packet);
416 printf("\t\tHandshake complete!!\n");
417 found = TRUE;
418 break;
419 } else {
420 //printf("2. Wrong payload: %s\n",packet->payload);
423 free_packet(packet);
424 } else {
425 //printf("Could not get any packet at all!\n");
427 ctr++;
428 Delay(50);
431 if (TRUE == found)
432 return 0;
434 return -1;
437 struct rm {
438 ULONG addr;
439 UWORD num_bytes;
440 } /* __attribute__((packed)) */;
442 char * read_mem(struct IOExtSer * IORequest, ULONG addr, UWORD num_bytes)
444 struct rm _rm;
445 int ctr = 0;
446 int send = TRUE;
448 _rm.num_bytes = AROS_WORD2BE(num_bytes);
449 _rm.addr = AROS_LONG2BE(addr);
451 #if 0
452 printf("Sending request for memory content!\n");
453 #endif
455 while (ctr < 10) {
456 struct Packet * packet;
457 if (TRUE == send) {
458 send_packet(IORequest, (char *)&_rm, 6, TYPE_READ_MEM);
459 Delay(50);
460 } else {
461 send = FALSE;
462 Delay(20);
464 packet = get_next_packet(IORequest);
465 if (NULL != packet) {
466 if (TYPE_MEM_CONTENT == packet->payload_type &&
467 0 == memcmp(&_rm.addr,&packet->payload[0],sizeof(addr)) &&
468 packet->payload_length == sizeof(addr) + num_bytes) {
469 char * buf;
470 int i = 4;
471 #if 0
472 while (i < packet->payload_length) {
473 printf("x%02x ",(UBYTE)packet->payload[i]);
474 i++;
475 if (0 == (i % 16))
476 printf("\n");
478 printf("\n");
479 #endif
480 buf = AllocMem(packet->payload_length-4,MEMF_ANY);
481 if (NULL != buf)
482 memcpy(buf, &packet->payload[4], packet->payload_length-4);
484 free_packet(packet);
485 return buf;
486 } else {
487 //printf("%s: Wrong packet.\n",__FUNCTION__);
488 send = FALSE;
489 ctr--;
492 free_packet(packet);
493 } else {
494 //printf("Could not get any packet at all!\n");
495 send = TRUE;
497 ctr++;
499 return NULL;
502 int write_mem(struct IOExtSer * IORequest, ULONG addr, char * buf, UWORD num_bytes)
504 int ctr = 0;
505 int send = TRUE;
506 char * _buf = AllocMem(num_bytes + sizeof(addr), MEMF_ANY);
507 ULONG _addr = AROS_BE2LONG(addr);
508 if (NULL == _buf)
509 return -1;
511 memcpy(_buf, &_addr, sizeof(addr));
512 memcpy(_buf+sizeof(addr), buf, num_bytes);
513 while (ctr < 20) {
514 struct Packet * packet;
515 if (TRUE == send) {
516 send_packet(IORequest, _buf, num_bytes+sizeof(addr), TYPE_WRITE_MEM);
517 Delay(50);
518 } else {
519 send = FALSE;
520 Delay(20);
522 packet = get_next_packet(IORequest);
523 if (NULL != packet) {
524 if (TYPE_WRITE_MEM_ACK == packet->payload_type &&
525 0 == memcmp(&_addr,&packet->payload[0],sizeof(addr))) {
526 printf("\tSuccessfully wrote %d bytes starting at address 0x%x\n",num_bytes,addr);
527 free_packet(packet);
528 FreeMem(_buf, num_bytes + sizeof(addr));
529 return 0;
530 } else {
531 //printf("%s: Wrong packet.\n",__FUNCTION__);
532 send = FALSE;
533 ctr--;
536 free_packet(packet);
537 } else {
538 //printf("Could not get any packet at all!\n");
539 send = TRUE;
541 ctr++;
543 FreeMem(_buf, num_bytes + sizeof(addr));
544 return -1;
547 int send_chunk(struct IOExtSer * IORequest, ULONG addr, char * buf, UWORD num_bytes)
549 printf("Sending chunk of size %d to address %x\n",num_bytes,addr);
550 while (num_bytes > 0) {
551 UWORD send = 100;
552 if (num_bytes < send)
553 send = num_bytes;
554 if (write_mem(IORequest, addr, buf, send) < 0) {
555 printf("send_chunk failed!\n");
556 return -1;
558 addr += send;
559 buf += send;
560 num_bytes -= send;
561 printf("%d more bytes.\n",num_bytes);
563 return 0;
566 int start_program(struct IOExtSer * IORequest, ULONG addr)
568 int ctr = 0;
569 int send = TRUE;
570 ULONG _addr = AROS_BE2LONG(addr);
572 printf("Sending request to start program at address 0x%x!\n",addr);
574 while (ctr < 10) {
575 struct Packet * packet;
576 if (TRUE == send) {
577 send_packet(IORequest, (char *)&_addr, sizeof(_addr), TYPE_START_PROGRAM);
578 Delay(50);
579 } else {
580 send = FALSE;
581 Delay(20);
583 packet = get_next_packet(IORequest);
584 if (NULL != packet) {
585 if (TYPE_START_PROGRAM_ACK == packet->payload_type) {
586 printf("Sucessfully started program!\n");
587 free_packet(packet);
588 return 0;
589 } else {
590 //printf("%s: Wrong packet.\n",__FUNCTION__);
591 send = FALSE;
592 ctr--;
595 free_packet(packet);
596 } else {
597 //printf("Could not get any packet at all!\n");
598 send = TRUE;
600 ctr++;
602 return -1;
606 struct special_info
608 ULONG start;
609 ULONG end;
610 ULONG ssp;
613 int get_special_info(struct IOExtSer * IORequest, struct special_info * si)
615 int ctr = 0;
616 int send = TRUE;
618 printf("Sending request for special info!\n");
620 while (ctr < 10) {
621 struct Packet * packet;
622 if (TRUE == send) {
623 send_packet(IORequest, (char *)&ctr, 1, TYPE_GET_SPECIAL_INFO);
624 Delay(50);
625 } else {
626 send = FALSE;
627 Delay(20);
629 packet = get_next_packet(IORequest);
630 if (NULL != packet) {
631 if (TYPE_GET_SPECIAL_INFO == packet->payload_type &&
632 packet->payload_length == sizeof(struct special_info)) {
633 memcpy(si, packet->payload, packet->payload_length);
634 free_packet(packet);
635 printf("\t\tGot special info!\n");
636 return 0;
637 } else {
638 //printf("%s: Wrong packet. (%d)\n",__FUNCTION__,packet->payload_type);
639 //printf("%d-%d\n",packet->payload_length,sizeof(struct special_info));
640 ctr--;
641 send = FALSE;
644 free_packet(packet);
645 } else {
646 //printf("Could not get any packet at all!\n");
647 send = TRUE;
649 ctr++;
651 return -1;
654 struct PilotMem
656 struct Node node;
657 ULONG start;
658 ULONG end;
661 struct registers
663 UWORD GRPBASEA; /* 0xfffff100 */
664 UWORD GRPBASEB; /* 0xfffff102 */
665 UWORD GRPBASEC; /* 0xfffff104 */
666 UWORD GRPBASED; /* 0xfffff106 */
668 UWORD GRPMASKA; /* 0xfffff108 */
669 UWORD GRPMASKB; /* 0xfffff10a */
670 UWORD GRPMASKC; /* 0xfffff10c */
671 UWORD GRPMASKD; /* 0xfffff10e */
673 ULONG CSA0; /* 0xfffff110 */
674 ULONG CSA1; /* 0xfffff114 */
675 ULONG CSA2; /* 0xfffff118 */
676 ULONG CSA3; /* 0xfffff11c */
678 ULONG empty1; /* 0xfffff120 */
679 ULONG empty2; /* 0xfffff124 */
680 ULONG empty3; /* 0xfffff128 */
681 ULONG empty4; /* 0xfffff12c */
683 ULONG CSC0; /* 0xfffff130 */
684 ULONG CSC1; /* 0xfffff134 */
685 ULONG CSC2; /* 0xfffff138 */
686 ULONG CSC3; /* 0xfffff13c */
688 ULONG LSSA;
690 struct special_info SI;
691 } __attribute__((packed)) Regs;
694 * This function builds the current palm memory layout into a linked
695 * list of simple structures. Later on the relocator will look at this
696 * list and try to grab a chunk.
698 void BuildPilotMem(struct registers * reg)
700 struct PilotMem *pm;
702 pm = AllocMem(sizeof(struct PilotMem),MEMF_CLEAR);
703 #warning Should really build a much better list here!!!
704 pm->start = (AROS_LONG2BE(reg->SI.end) & 0xffff0000) + 0x4000;
705 pm->end = pm->start+0x100000;
706 AddTail(&PilotMemList, &pm->node);
709 void * GetPilotMem(ULONG size)
711 struct PilotMem * pm;
713 /* For alignment purposes add 4 to the size */
714 size += 4;
715 printf("%s: Trying to allocate %ld bytes on palm!\n",__FUNCTION__,size);
716 ForeachNode(&PilotMemList, pm) {
717 if (pm->end - pm->start + 1 >= size) {
718 void * ret;
719 if (0 == (pm->start & 0x03))
720 ret = pm->start;
721 else
722 ret = (void *)((pm->start & 0xfffffffc) + 4);
723 printf("Found a memory chunk at 0x%x\n",ret);
724 pm->start += size;
725 return ret;
727 pm = (struct PilotMem *)pm->node.ln_Succ;
729 return NULL;
732 #include "myinternalloadseg_elf.c"
734 int upload_program(struct IOExtSer * IORequest, char * name, ULONG * startaddr)
736 BPTR segs;
737 BPTR file = Open(name, MODE_OLDFILE);
739 if (file)
741 printf("Opened file!\n");
742 segs = MyInternalLoadSeg_ELF(file, NULL, NULL, IORequest, startaddr);
744 Close(file);
745 } else {
746 printf("Could not open file %s\n",name);
749 return 0;
753 int start_protocol(struct IOExtSer * IORequest, ULONG start, char * filename)
755 int err;
756 char * buf;
757 ULONG startaddr;
759 err = do_handshake(IORequest);
760 if (0 != err) {
761 printf("Handshake failed!\n");
762 return err;
765 buf = read_mem(IORequest,0xfffff100,0x40);
766 if (buf) {
767 memcpy(&Regs, buf, 0x40);
768 FreeMem(buf,0x40);
771 buf = read_mem(IORequest,0xfffffA00,0x4);
772 if (buf) {
773 memcpy(&Regs.LSSA, buf, 0x4);
774 FreeMem(buf,0x4);
777 err = get_special_info(IORequest,&Regs.SI);
779 printf("start: %lx\n",AROS_LONG2BE(Regs.SI.start));
780 printf("end: %lx\n",AROS_LONG2BE(Regs.SI.end));
781 printf("ssp: %lx\n",AROS_LONG2BE(Regs.SI.ssp));
783 printf("GRPBASEA : %x\n",AROS_WORD2BE(Regs.GRPBASEA));
784 printf("GRPBASEB : %x\n",AROS_WORD2BE(Regs.GRPBASEB));
785 printf("GRPBASEC : %x\n",AROS_WORD2BE(Regs.GRPBASEC));
786 printf("GRPBASED : %x\n",AROS_WORD2BE(Regs.GRPBASED));
788 printf("GRPMASKA : %x\n",AROS_WORD2BE(Regs.GRPMASKA));
789 printf("GRPMASKB : %x\n",AROS_WORD2BE(Regs.GRPMASKB));
790 printf("GRPMASKC : %x\n",AROS_WORD2BE(Regs.GRPMASKC));
791 printf("GRPMASKD : %x\n",AROS_WORD2BE(Regs.GRPMASKD));
793 printf("CSA0 : %lx\n",AROS_LONG2BE(Regs.CSA0));
794 printf("CSA1 : %lx\n",AROS_LONG2BE(Regs.CSA1));
795 printf("CSA2 : %lx\n",AROS_LONG2BE(Regs.CSA2));
796 printf("CSA3 : %lx\n",AROS_LONG2BE(Regs.CSA3));
798 printf("CSC0 : %lx\n",AROS_LONG2BE(Regs.CSC0));
799 printf("CSC1 : %lx\n",AROS_LONG2BE(Regs.CSC1));
800 printf("CSC2 : %lx\n",AROS_LONG2BE(Regs.CSC2));
801 printf("CSC3 : %lx\n",AROS_LONG2BE(Regs.CSC3));
803 #if 0
804 Not doing this anymore. Will do this on the palm.
806 * Disable the read only bit in the CSA1 and CSA3 register.
808 Regs.CSA1 &= AROS_LONG2BE(0xfffffff7);
809 printf("Changing CSA1 register to new value %x!\n",AROS_LONG2BE(Regs.CSA1));
810 err = write_mem(IORequest, 0xfffff110, (char *)&Regs.CSA1, sizeof(Regs.CSA1));
811 if (0 == err) {
812 printf("Successfully changed register CSA1!\n");
815 Regs.CSA3 &= AROS_LONG2BE(0xfffffff7);
816 printf("Changing CSA3 register to new value %x!\n",AROS_LONG2BE(Regs.CSA3));
817 err = write_mem(IORequest, 0xfffff110, (char *)&Regs.CSA3, sizeof(Regs.CSA3));
818 if (0 == err) {
819 printf("Successfully changed register CSA3!\n");
821 #endif
822 BuildPilotMem(&Regs);
823 printf("Trying to upload program now!\n");
824 if (0 != upload_program(IORequest,filename, &startaddr)) {
825 printf("upload_program returned error!\n");
828 if (TRUE == start)
829 start_program(IORequest, startaddr);
831 send_packet(IORequest, (char *)&err, 1, TYPE_QUIT);
833 return err;