Development stupid questions

Started by scrax, June 27, 2012, 12:30:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Pelican

Quote from: Floont on December 29, 2012, 11:10:11 PM
The % sign in C is the modulus operator.  Your code is calculating 0x4860 (18528 decimal) mod 0xff (255 decimal), which is 0xa8 (168 decimal).  What you actually want is the low byte of auto_iso_range, which can be retrieved either by changing 0xff to 0x100 in your existing code or simply using the & operator instead of the "%" operator (my preference), i.e. raw2iso(auto_iso_range & 0xff).
Yes, you are right, thank you!
I've figured out last night...
EOS 7D Mark II, EOS 7D, EOS 5, EOS 100 + lenses (10mm to 300mm), 600EX, 550EX, YN600EX x 3
EOScard, EOS DSLR firmwares, ARMu, NiControl, etc.: http://pel.hu/down

meeok

Seems like a waste to start a new thread... so here is my question:

Why doesn't %15s work when %s does?
snprintf(buf,1024,"%15s : %08X", "My Register", data);
I understand our stdio.c is a bit hacked but the underlying function is still canon... surely it implements this feature?


nanomad

EOS 1100D | EOS 650 (No, I didn't forget the D) | Ye Olde Canon EF Lenses ('87): 50 f/1.8 - 28 f/2.8 - 70-210 f/4 | EF-S 18-55 f/3.5-5.6 | Metz 36 AF-5

1%

I've got another stupid question.

Why am I getting assertions when conditions like this are met:

ASSERT(len == 0x2f);

Isn't 2f the correct length, that's what everything else is using.

or this

ASSERT(buf[0] == 1 || buf[0] == 5 || buf[0] == 10);
   



meeok

static int8_t some_cfn[0x2f];
PROP_HANDLER(0x80010007)
{
    ASSERT(len == 0x2f);
    memcpy(some_cfn, buf, 0x2f);
}

Can we have more context?

1%

I'm working on the 6D port and these asserts keep getting dropped.

One is from shoot.c the other is from 5dIII cfn that works for 6D too.

In that second one it looks like the length is supposed to be 2f so why does it assert? Or is len not 2f and that's why it asserts?

a1ex

The one with 1/5/10 is LiveView zoom; does the 6D use other values? (print them).

The 2f is camera-specific; print it and change it. If it's in CFn, just hardcode the new length.

meeok

Quote from: meeok on January 03, 2013, 04:22:09 PM
Why doesn't %15s work when %s does?
snprintf(buf,1024,"%15s : %08X", "My Register", data);
I understand our stdio.c is a bit hacked but the underlying function is still canon... surely it implements this feature?
What I ended up using:
void debug_intercept()
{
static int fidx = 0;
char name[30];
snprintf(name,30,CARD_DRIVE"dm%d.log",fidx);
if (!buf) {
buf = alloc_dma_memory(BUF_SIZE);
}
len = dump_cache(buf,BUF_SIZE);
dump_seg(buf, len, name);
NotifyBox(5000, "Saved %d bytes in %s.", len, name);
fidx++;
    beep();
}
static uint32_t dump_data(char* buf, uint32_t max_len, char* header, uint32_t data) {
if (!buf || !header) return 0;
/*uint32_t len1 = snprintf(buf, max_len, "                      : %08X ", data);
*(snprintf(buf,22,"%s",header)+buf)=":";*/
[b]#define SPACE10 "          "
uint32_t len1 = snprintf(buf, max_len, SPACE10 SPACE10 SPACE10 " : %08X ", data);
for (uint32_t i = 0; i <= len1 && header[i]; i++) buf[i] = header[i];[/b]
buf += len1;
uint32_t len2 = snprintf(buf,max_len-len1,"XXXX,XXXX XXXX,XXXX XXXX,XXXX XXXX,XXXX\n");
    for (int i = MIN(39-1,len2); i >= 0; i--) {
        *(buf+i) = ((data & 0x1) != 0) ? '1' : '0';
        data >>= 1;
        if (((i)%5) == 0) i--;
    }
    return len1 + len2;
}


static uint32_t dump_cache(char* buf, uint32_t max_len) {
if (!buf) return 0;

uint32_t data;
uint32_t len = 0;


#define dump_cacheMRC(op1, cIdx, cIdx2, op2, name) \
{asm volatile ("MRC p15, "#op1", %0, c"#cIdx", c"#cIdx2", "#op2 : "=r"(data)); \
len += dump_data(buf+len, max_len-len, #op1":c"#cIdx",c"#cIdx2":"#op2" "name, data);}

dump_cacheMRC(0,0,0,0, "ID");
dump_cacheMRC(0,0,0,1, "Cache Type");
dump_cacheMRC(0,0,0,2, "TCM Size");

dump_cacheMRC(0,1,0,0, "Control");

dump_cacheMRC(0,2,0,0, "DCache Cfg");
dump_cacheMRC(0,2,0,1, "ICache Cfg");

dump_cacheMRC(0,3,0,0, "Wr Buf Ctl");

dump_cacheMRC(0,5,0,0, "AccPerm D");
dump_cacheMRC(0,5,0,1, "AccPerm I");
dump_cacheMRC(0,5,0,2, "AccPerm Dx");
dump_cacheMRC(0,5,0,3, "AccPerm Ix");

dump_cacheMRC(0,6,0,0, "Protection");
dump_cacheMRC(0,6,1,0, "Protection");
dump_cacheMRC(0,6,2,0, "Protection");
dump_cacheMRC(0,6,3,0, "Protection");
dump_cacheMRC(0,6,4,0, "Protection");
dump_cacheMRC(0,6,5,0, "Protection");
dump_cacheMRC(0,6,6,0, "Protection");
dump_cacheMRC(0,6,7,0, "Protection");

dump_cacheMRC(0,7,5,0, "IC  Flush");
dump_cacheMRC(0,7,5,1, "IC1 Flush");
dump_cacheMRC(0,7,13,1,"IC Preftch");
dump_cacheMRC(0,7,6,0, "DC  Flush");
dump_cacheMRC(0,7,6,1, "DC1 Flush");
dump_cacheMRC(0,7,10,1,"DC  Clean");
dump_cacheMRC(0,7,14,1,"DC1 C/F");
dump_cacheMRC(0,7,10,2,"DC1 Clean");
dump_cacheMRC(0,7,14,2,"DC1 C/F");
dump_cacheMRC(0,7,10,4,"Drain");
dump_cacheMRC(0,7,0,4, "Sleep");
dump_cacheMRC(0,15,8,2,"SleepOld");

dump_cacheMRC(0,9,0,0, "DC Lock");
dump_cacheMRC(0,9,0,1, "IC Lock");
dump_cacheMRC(0,9,1,0, "DTCM");
dump_cacheMRC(0,9,1,1, "ITCM");

dump_cacheMRC(0,13,0,1,"PID");
dump_cacheMRC(0,13,1,1,"PID Old");

dump_cacheMRC(0,15,0,1,"TAG B Ctl");
dump_cacheMRC(1,15,1,1,"TCM B Ctl");
dump_cacheMRC(2,15,1,1,"CRM B Ctl");
dump_cacheMRC(0,15,0,2,"ITAG B Add");
dump_cacheMRC(0,15,0,3,"ITAG B Gen");
dump_cacheMRC(0,15,0,6,"DTAG B Add");
dump_cacheMRC(0,15,0,7,"DTAG B Gen");
dump_cacheMRC(1,15,0,2,"ITCM B Add");
dump_cacheMRC(1,15,0,3,"ITCM B Gen");
dump_cacheMRC(1,15,0,6,"DTCM B Add");
dump_cacheMRC(1,15,0,7,"DTCM B Gen");
dump_cacheMRC(2,15,0,2,"ICRM B Add");
dump_cacheMRC(2,15,0,3,"ICRM B Gen");
dump_cacheMRC(2,15,0,6,"DCRM B Add");
dump_cacheMRC(2,15,0,7,"DCRM B Gen");

dump_cacheMRC(0,15,0,0,"Test State");

dump_cacheMRC(3,15,0,0,"C Dbg Idx");
dump_cacheMRC(3,15,1,0,"I TAG");
dump_cacheMRC(3,15,2,0,"D TAG");
dump_cacheMRC(3,15,3,0,"I Cache");
dump_cacheMRC(3,15,4,0,"D Cache");

dump_cacheMRC(1,15,1,0,"Trace Ctrl");

#undef dump_cacheMRC

return len;
}

Let me know if it is worth committing.

1%

ASSERT(len == 0x2f); - Not sure how to find the correct button code. Used event spy but af button, half shutter and star key give same event. What should I set them to to get the correct button code.

ASSERT(buf[0] == 1 || buf[0] == 5 || buf[0] == 10);- fixed. Camera has "X1" zoom mode that is supposed to be 1:1? It gives value of 129.

How do I find Frame ISO offsets? What functions should I look in. I'd like to get HDR working. Dunno how much more can get enabled only running the the small allocate memory. I tried jumping to the second memory pool but I think GUI task and slightly different setup prevent it from happening. Those register values in init_task_patched_for_600D are 0 in the 6D firmware. Even finding the right offsets led to camera booting without any GUI (but still taking pics, hheheh)

meeok


void draw_page_number(int page)
{
char pg[3];
snprintf(pg, sizeof(pg), "%3d", page);
bfnt_puts(pg, 650+(page<10 ? 14 : page<100 ? 4 : 0) , 2, COLOR_FG_NONLV, COLOR_BG);
}


My understanding is that snprintf will dump sizeof(pg)=3 characters in to pg. It will then write a 4th character of '\0'.
Does that mean "char pg[3];" allocates an array of length 3 or 4?
An integer array would logically be only 3 elements long. Hence with the char situation I think snprintf would overflow the array. Is this correct?

Bonus question: Would pg be allocated on the stack? Since no other variables were initialised would it overwrite the return address?

nanomad

Quote from: meeok on January 06, 2013, 03:03:14 PM
Does that mean "char pg[3];" allocates an array of length 3 or 4?
An integer array would logically be only 3 elements long. Hence with the char situation I think snprintf would overflow the array. Is this correct?
Correct, it's a common C mistake
EOS 1100D | EOS 650 (No, I didn't forget the D) | Ye Olde Canon EF Lenses ('87): 50 f/1.8 - 28 f/2.8 - 70-210 f/4 | EF-S 18-55 f/3.5-5.6 | Metz 36 AF-5

g3gg0

Quote from: meeok on January 06, 2013, 03:03:14 PM
Bonus question: Would pg be allocated on the stack? Since no other variables were initialised would it overwrite the return address?

yes, its on stack and yes, it will overwrite return address or R0,.... partially ;)
(it depends on the compiler output, if it saves R0, ...on stack)
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

meeok

Quote from: g3gg0 on January 06, 2013, 03:45:34 PM
yes, its on stack and yes, it will overwrite return address or R0,.... partially ;)
(it depends on the compiler output, if it saves R0, ...on stack)
Quote from: nanomad on January 06, 2013, 03:32:40 PM
Correct, it's a common C mistake
Thanks
There is a LOT of this in the code. I'm surprised ML doesn't crash instantly. Or are we missing something?

.text
#define NSTUB(addr,name) \
.global name; \
name = addr
NSTUB(0xFF2C12A8, shamem_read)

Am I correct in assuming assembly defined functions such as shamem_read don't have any kind of type safety? shamem_read(x,45678,"gfdfgs")  compiles :-/

a1ex

For assembly functions, you can define a prototype in dryos.h and get type safety. If not, it uses an implicit declarations (all parameters are int).

Edit: did some tests for snprintf, it doesn't behave as described in http://pubs.opengroup.org/onlinepubs/9699919799/functions/snprintf.html


    char x[4];
    snprintf(x, sizeof(x), "%d", 1234);
    printf("'%s'\n", x);


gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) displays '123'.

ML displays '1234'.

Edit 2: snprintf now behaves correctly :)

meeok

Nice a1ex.

Is alexdu still around? Last commit to https://github.com/alexdu/ARM-console was 6months ago.

g3gg0

alexdu changed his gender and his name and is called now a1lex ;P
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

meeok

Quote from: g3gg0 on January 10, 2013, 12:49:34 PM
alexdu changed his gender and his name and is called now a1lex ;P
Excellent! So any pointers on getting ARM_Console running?

I'm having memory problems: My virtual machine with 1GB of memory is crying.

With regards to function naming etc: Are there any updates that I've missed? I don't want to reinvent the wheel.

nanomad

My VM with 4 gigs gives up when analyzing EOSM+650D. I feel your pain  :'(

The best suggestion is to stick with Ubuntu 10.01 (or something like that). ARM-Console works fine there (I spent too much time figuring out how to run it on a newer distro and just gave up)
EOS 1100D | EOS 650 (No, I didn't forget the D) | Ye Olde Canon EF Lenses ('87): 50 f/1.8 - 28 f/2.8 - 70-210 f/4 | EF-S 18-55 f/3.5-5.6 | Metz 36 AF-5

eduperez

Quote from: nanomad on January 06, 2013, 03:32:40 PM
Correct, it's a common C mistake

Quote from: meeok on January 06, 2013, 04:21:57 PM
There is a LOT of this in the code. I'm surprised ML doesn't crash instantly. Or are we missing something?

The compiler probably aligns every variable to a 4-byte boundary; so while the fourth byte is not properly reserved, it is not used, either.

meeok

Anyone have function names etc for 550D.119?

1%

I got console running on mint 13. I think you need 2 older versions of some python things.

Anyways, the function naming can be done automatically with a script from a1ex.

My 16GB quad didn't do any better than my 4gb core2 32 bit. It will take days... took a long time to do the 6D firmware. Some functions are too big or lead the emulator to dead ends so I had to watch it and occasionally ctrl-C when it got stuck. I'm guessing if you just prod around on individual functions they'll either decompile or get stuck. Some stuff says too comlex or just cuts off in the HTML. I tried re-doing some of those for 600D and it sometimes did better but usually not. It will also overwrite HTML if you do this so unless you're just doing one function or have a backup, be careful to not lose days of work.

scrax

I'm having a little problem showing Kelvin values with this code:
bfnt_puts( lens_info.kelvin, 300, 166, fc, bg);
instead of numbers I got characters on screen, so probably it needs something like this:
int str = convert_to_string(lens_info.kelvin);
bfnt_puts( str, 300, 166, fc, bg);


but I don't know the correct name for convert_to_string or for the right way to do this.
Any help?
[/s]

solved:

                        char msg[6];
                        snprintf(msg, sizeof(msg), "%d", lens_info.kelvin);
                        bfnt_puts("Kelvin", 320, 111, fc, bg);
                        bfnt_puts(msg, 300, 166, fc, bg);

How it is now was before:


now time to center it better
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-

eduperez

Quote from: scrax on February 03, 2013, 01:28:48 PM
I'm having a little problem showing Kelvin values with this code:
bfnt_puts( lens_info.kelvin, 300, 166, fc, bg);
instead of numbers I got characters on screen, so probably it needs something like this:
int str = convert_to_string(lens_info.kelvin);
bfnt_puts( str, 300, 166, fc, bg);


but I don't know the correct name for convert_to_string or for the right way to do this.
Any help?

What you need is bmp_printf:

bmp_printf(uint32_t fontspec, int x, int y, const char *fmt, ...);

First parameters should be familiar to you; then comes a string with the output format, and then the values you want to print. The format follows the standard for the "printf" family. For example:

bmp_printf(FONT_SMALL, 0, 0, "%i", lens_info.kevin);

should do what you need (but I haven't tested it myself, however).

scrax

Quote from: eduperez on February 03, 2013, 01:53:55 PM
What you need is bmp_printf:

bmp_printf(uint32_t fontspec, int x, int y, const char *fmt, ...);

First parameters should be familiar to you; then comes a string with the output format, and then the values you want to print. The format follows the standard for the "printf" family. For example:

bmp_printf(FONT_SMALL, 0, 0, "%i", lens_info.kevin);

should do what you need (but I haven't tested it myself, however).
Thank's Edu,
Yes with this I have the numbers like in the screenshoot, but I wanted to have the more rounded and bigger one like Kelvin text, that's why I want to use bfnt_puts

Is there maybe a FONT_HUGE or some fontspec that works without use bfnt_puts?

that worked for me:

                        char msg[6];
                        snprintf(msg, sizeof(msg), "%d", lens_info.kelvin);
                        bfnt_puts("Kelvin", 320, 111, fc, bg);
                        bfnt_puts(msg, 300, 166, fc, bg);
I'm using ML2.3 for photography with:
EOS 600DML | EOS 400Dplus | EOS 5D MLbeta5- EF 100mm f/2.8 USM Macro  - EF-S 17-85mm f4-5.6 IS USM - EF 70-200mm f/4 L USM - 580EXII - OsX, PS, LR, RawTherapee, LightZone -no video experience-