app2.c

来自「arm ads1.2 with crack.rar」· C语言 代码 · 共 68 行

C
68
字号
/*
 * Copyright (C) ARM Limited 1999. All rights reserved.
 *
 * A toy, position-independent application using kernel
 * services at fixed addresses.
 */

#include <stdio.h>
#include "kernel.h"

/* My bss size is defined by my application header... */
extern const unsigned bss_size;


/* Describe the static base register, needed for calling services */
/* This also avoids allocating SB (=v6) to any other purpose.     */
__global_reg(6) void *sb;


/* Each instance of these services gets a separate copy of my data */
#define N_DATA  100
static int data[N_DATA];


/*
 * This "service" calls itself recursively, until it fails.
 */
static void s2_1(unsigned sub_service, void *arg)
{
    int rc, *depth;

    printf("s1_2(%u, %.8p) at %.8p, sb = %.8p\n",
        sub_service, arg, s2_1, sb);
    
    if (sub_service == 0)
    {
        depth = data;
        *depth = 0;
    }
    else
    {
        depth = (int *)arg;
        ++(*depth);
    }

    rc = kernel_Call("two.1", 255, (void *)depth);

    if (rc != KERNEL_OK)
    {
        printf("Call to \"two.1\" failed, rc = %d at depth = %d\n", rc, *depth);
    }
    if (sub_service == 0)
    {
        printf("Calls to \"two.1\" unwound successfully\n");
    }
}


/*
 * This function is referenced from the application header that
 * define bss_size and the magic string "*** Service ***".
 */
void register_services(void)
{
    kernel_Register("two.1", s2_1, bss_size);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?