Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* bootstd.h: Bootloader system call interface |
| 2 | * |
| 3 | * (c) 1999, Rt-Control, Inc. |
| 4 | */ |
| 5 | |
| 6 | #ifndef __BOOTSTD_H__ |
| 7 | #define __BOOTSTD_H__ |
| 8 | |
| 9 | #define NR_BSC 21 /* last used bootloader system call */ |
| 10 | |
| 11 | #define __BN_reset 0 /* reset and start the bootloader */ |
| 12 | #define __BN_test 1 /* tests the system call interface */ |
| 13 | #define __BN_exec 2 /* executes a bootloader image */ |
| 14 | #define __BN_exit 3 /* terminates a bootloader image */ |
| 15 | #define __BN_program 4 /* program FLASH from a chain */ |
| 16 | #define __BN_erase 5 /* erase sector(s) of FLASH */ |
| 17 | #define __BN_open 6 |
| 18 | #define __BN_write 7 |
| 19 | #define __BN_read 8 |
| 20 | #define __BN_close 9 |
| 21 | #define __BN_mmap 10 /* map a file descriptor into memory */ |
| 22 | #define __BN_munmap 11 /* remove a file to memory mapping */ |
| 23 | #define __BN_gethwaddr 12 /* get the hardware address of my interfaces */ |
| 24 | #define __BN_getserialnum 13 /* get the serial number of this board */ |
| 25 | #define __BN_getbenv 14 /* get a bootloader envvar */ |
| 26 | #define __BN_setbenv 15 /* get a bootloader envvar */ |
| 27 | #define __BN_setpmask 16 /* set the protection mask */ |
| 28 | #define __BN_readenv 17 /* read environment variables */ |
| 29 | #define __BN_flash_chattr_range 18 |
| 30 | #define __BN_flash_erase_range 19 |
| 31 | #define __BN_flash_write_range 20 |
| 32 | |
| 33 | /* Calling conventions compatible to (uC)linux/68k |
| 34 | * We use simmilar macros to call into the bootloader as for uClinux |
| 35 | */ |
| 36 | |
| 37 | #define __bsc_return(type, res) \ |
| 38 | do { \ |
| 39 | if ((unsigned long)(res) >= (unsigned long)(-64)) { \ |
| 40 | /* let errno be a function, preserve res in %d0 */ \ |
| 41 | int __err = -(res); \ |
| 42 | errno = __err; \ |
| 43 | res = -1; \ |
| 44 | } \ |
| 45 | return (type)(res); \ |
| 46 | } while (0) |
| 47 | |
| 48 | #define _bsc0(type,name) \ |
| 49 | type name(void) \ |
| 50 | { \ |
| 51 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 52 | __asm__ __volatile__ ("trap #2" \ |
| 53 | : "=g" (__res) \ |
| 54 | : "0" (__res) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 55 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | __bsc_return(type,__res); \ |
| 57 | } |
| 58 | |
| 59 | #define _bsc1(type,name,atype,a) \ |
| 60 | type name(atype a) \ |
| 61 | { \ |
| 62 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 63 | register long __a __asm__ ("%d1") = (long)a; \ |
| 64 | __asm__ __volatile__ ("trap #2" \ |
| 65 | : "=g" (__res) \ |
| 66 | : "0" (__res), "d" (__a) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 67 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | __bsc_return(type,__res); \ |
| 69 | } |
| 70 | |
| 71 | #define _bsc2(type,name,atype,a,btype,b) \ |
| 72 | type name(atype a, btype b) \ |
| 73 | { \ |
| 74 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 75 | register long __a __asm__ ("%d1") = (long)a; \ |
| 76 | register long __b __asm__ ("%d2") = (long)b; \ |
| 77 | __asm__ __volatile__ ("trap #2" \ |
| 78 | : "=g" (__res) \ |
| 79 | : "0" (__res), "d" (__a), "d" (__b) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 80 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | __bsc_return(type,__res); \ |
| 82 | } |
| 83 | |
| 84 | #define _bsc3(type,name,atype,a,btype,b,ctype,c) \ |
| 85 | type name(atype a, btype b, ctype c) \ |
| 86 | { \ |
| 87 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 88 | register long __a __asm__ ("%d1") = (long)a; \ |
| 89 | register long __b __asm__ ("%d2") = (long)b; \ |
| 90 | register long __c __asm__ ("%d3") = (long)c; \ |
| 91 | __asm__ __volatile__ ("trap #2" \ |
| 92 | : "=g" (__res) \ |
| 93 | : "0" (__res), "d" (__a), "d" (__b), \ |
| 94 | "d" (__c) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 95 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | __bsc_return(type,__res); \ |
| 97 | } |
| 98 | |
| 99 | #define _bsc4(type,name,atype,a,btype,b,ctype,c,dtype,d) \ |
| 100 | type name(atype a, btype b, ctype c, dtype d) \ |
| 101 | { \ |
| 102 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 103 | register long __a __asm__ ("%d1") = (long)a; \ |
| 104 | register long __b __asm__ ("%d2") = (long)b; \ |
| 105 | register long __c __asm__ ("%d3") = (long)c; \ |
| 106 | register long __d __asm__ ("%d4") = (long)d; \ |
| 107 | __asm__ __volatile__ ("trap #2" \ |
| 108 | : "=g" (__res) \ |
| 109 | : "0" (__res), "d" (__a), "d" (__b), \ |
| 110 | "d" (__c), "d" (__d) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 111 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | __bsc_return(type,__res); \ |
| 113 | } |
| 114 | |
| 115 | #define _bsc5(type,name,atype,a,btype,b,ctype,c,dtype,d,etype,e) \ |
| 116 | type name(atype a, btype b, ctype c, dtype d, etype e) \ |
| 117 | { \ |
| 118 | register long __res __asm__ ("%d0") = __BN_##name; \ |
| 119 | register long __a __asm__ ("%d1") = (long)a; \ |
| 120 | register long __b __asm__ ("%d2") = (long)b; \ |
| 121 | register long __c __asm__ ("%d3") = (long)c; \ |
| 122 | register long __d __asm__ ("%d4") = (long)d; \ |
| 123 | register long __e __asm__ ("%d5") = (long)e; \ |
| 124 | __asm__ __volatile__ ("trap #2" \ |
| 125 | : "=g" (__res) \ |
| 126 | : "0" (__res), "d" (__a), "d" (__b), \ |
| 127 | "d" (__c), "d" (__d), "d" (__e) \ |
Greg Ungerer | 0aee77b | 2006-06-28 16:12:45 +1000 | [diff] [blame] | 128 | ); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | __bsc_return(type,__res); \ |
| 130 | } |
| 131 | |
| 132 | #endif /* __BOOTSTD_H__ */ |