1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
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
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
15 /*******************************************************************
16 * Wrapper for romfs_lookup.
19 * R3 = address of filename string
20 * R4 = address of struct romfs_t
21 * 0: file size (return)
23 * 10: fileaddr (return and input: tells if first search)
24 * 18: nextfile (return)
28 * - set filename and rombase, on return 0 file properties are stored
29 * in romfs_t else struct not valid
32 * - clear romfs_t (important!)
33 * - set filename = NULL and rombase and call returns first file
34 * with properties in romfs_t including next-file pointer
35 * - if nextpointer is non-zero then just the next file is returned
45 * Potentially modifies the following registers:
55 printf("Build: "__TIME__" "__DATE__" \n");
58 memset((void*) &rfs, 0, sizeof(struct romfs_t));
59 printf(" No. File Data Size Name\n");
61 while (romfs_stat(NULL, &rfs) == 0) {
63 printf(" %02d: %08X %08X %7d %s\n",
64 i, rfs.fileaddr, rfs.datap,
68 printf("Error in reading ROMFS\n");
73 *******************************************************************/
74 #define RFS_T_SIZE 0x00
75 #define RFS_T_FLAGS 0x08
76 #define RFS_T_FILEADDR 0x10
77 #define RFS_T_NEXT 0x18
78 #define RFS_T_NAME 0x20
79 #define RFS_T_DATA 0x28
81 #define RFS_H_NEXT 0x00
82 #define RFS_H_SIZE 0x08
83 #define RFS_H_FLAGS 0x10
84 #define RFS_H_DATA 0x18
85 #define RFS_H_NAME 0x20
87 ENTRY(romfs_stat_file)
88 /* save link register and romfs_t pointer */
92 /* if filename R3 is 0 then its a listing request */
93 /* if not then just continue to lookup name */
94 /* save R4 to R8 which is the address of header */
101 /* if file found then go to romfs_fill_properties */
102 /* else return 1 to caller */
104 beq romfs_fill_properties
108 /* check if fileaddr == 0, in this case its */
109 /* the first search on this handle, so return all */
110 /* info for file at rombase (R8=R4) */
111 ld r6, RFS_T_FILEADDR(r4)
115 beq romfs_fill_properties
117 /* check if next file != 0 by looking into */
118 /* romfs_t, if not then return (next = 0) 1 */
120 ld r4, RFS_T_NEXT(r4)
125 /* now next file is available so move R8 to next */
129 romfs_fill_properties:
130 /* set properties in romfs_t takes R8 as address */
131 /* to file header and R16 as address of romfs_t */
133 std r8, RFS_T_FILEADDR(r16)
135 ld r4, RFS_H_NEXT(r8)
138 beq $ + (2 * 4) /* =0 so add no rombase */
140 std r4, RFS_T_NEXT(r16)
142 ld r4, RFS_H_SIZE(r8)
143 std r4, RFS_T_SIZE(r16)
144 ld r4, RFS_H_FLAGS(r8)
145 std r4, RFS_T_FLAGS(r16)
147 ld r4, RFS_H_DATA(r8)
149 std r4, RFS_T_DATA(r16)
151 addi r4, r8, RFS_H_NAME
152 std r4, RFS_T_NAME(r16)
156 /* restore romfs_t pointer and link register */
162 /*******************************************************************
163 * Copies the data of file referenced by name string to address
164 * requires root address of filesystem.
165 * FIXME: ignores flags
168 * R3 = address of filename string
170 * R5 = destination address
173 * <Success>: R3 = 0, R6 = size, <FileNotFound>: R3 = 1
176 * Potentially modifies the following registers:
177 * ctr, r15, r16, r17, r18
179 * Uses the following calls with subsequent register modification:
181 *******************************************************************/
182 ASM_ENTRY(romfs_load)
186 /* lookup file, input regs */
187 /* are already set */
188 /* if not found, just return */
195 blr /* abort, not found */
197 /* save data size for return */
198 /* found, copy data */
199 /* data size is in R6 */
203 addi r16, r16, -1 /* dest */
204 addi r5, r5, -1 /* source*/
206 /* data is expected to be */
213 /* restore size, keep padding */
214 /* restore target address */
220 /*******************************************************************
221 * looks up a file based on filename
224 * R3 = address of filename string
230 * R4 = address of file header
231 * R5 = address of data (real address)
233 * R7 = flags for file
237 * Potentially modifies the following registers:
238 * R3, R4, R5, R6, R7, R8, R9
240 * Uses the following calls with subsequent register modification:
242 *******************************************************************/
243 ASM_ENTRY(romfs_lookup)
247 /* save current file base */
249 /* name to look for */
253 addi r5, r5, (4 /* elems */ * 8 /* elem-size */)
254 mr r11, r5 /* for namematch */
258 bne romfs_lookup_match
260 /* load next pointer */
261 /* check if next is 0 */
262 /* apply root-offset */
266 bne romfs_lookup_next
267 /* last file reached, abort */
272 /* here the name did match */
273 /* r4 is still usable here and */
274 /* pointing to the initial file */
275 /* load r5 with data ptr */
276 /* load r6 with data size */
277 /* load r7 with flags */
278 /* get abs addr of data */
281 ld r5, (3 * 8)(r4) /* data */
282 ld r6, (1 * 8)(r4) /* len */
283 ld r7, (2 * 8)(r4) /* flags */
288 /*******************************************************************
289 * compares two strings in memory,
290 * both must be null-terminated and 8-byte aligned
297 * <Match>: R12 = 0 <NoMatch>: R12 = 1
299 * Potentially modifies the following registers:
300 * R10, R11, r12, r13, r14
301 *******************************************************************/
307 * load chars as 8byte chunk from current pos, name is
308 * always 8 byte aligned :)
311 ldu r13, 8(r10) /* A */
312 ldu r14, 8(r11) /* B */
319 1: andi. r14, r14, 0xff
325 /*******************************************************************
326 * wrapper for romfs_lookup
327 * this function saves the registers from r13 - r15 on the stack
329 * restores the saved registers
331 * the return parameters are copied to (r5) and (r5) has to
333 *******************************************************************/
334 ENTRY(c_romfs_lookup)
335 stdu r1,-0x50(r1) # allocate space on stack
337 mflr r0 # save link register
340 std r15,0x38(r1) # save r15
341 std r14,0x40(r1) # save r14
342 std r13,0x48(r1) # and r13
344 mr r15,r5 # save the pointer for the return value
346 bl romfs_lookup # do the thing
348 ld r0,0x30(r1) # restore link register
351 std r4,0x00(r15) # copy return values
352 std r5,0x08(r15) # to the return pointer
356 ld r13,0x48(r1) # restore registers from stack
360 addi r1,r1,0x50 # cleanup stack