Thumb
–
2 Implementation
Work
of
Memory/Time
-Related
C
S
tandard Library Functions
.
1.
Objective
You’ll understand the followin
g concepts at the ARM
assembly language level through this final project
that implement
s memory/time
-related
C standard libra
ry function
s
in Thumb
-2.•
CP
U operating modes:
user and supervisor mode
s
• System
-call
and
interrupt handling procedure
s
• C to assembler argument passing (
APCS:
ARM Procedure Call Standard)
• Stack operations to implement recursions at the assembly language level
• Buddy memory allocation
This document is quite
dense
. Please read it as soon as the fi
nal project spec. becomes available to you.
2. Project
Overview
Using the Thumb
-2 assembly language, you will implement
several functions of the C standard library
thatwill be invoked from a C program named driver.c.
See Table 1.
These functions must be cod
e in the Thumb
-2 assembly language. Some of them can be implemented
in stdlib.s
running in the unprivileged thread mode
(=
user mode)
, whereas the others need to be implemented as supervisor calls, (i.e., in the handler mode
=supervisor mode).
For more details, log in one of the CSS Linux servers and type
from the Linux shell
:man
3
function where function is either bezro, strncpy, malloc, free, signal, or alarm
—————————————————————————
Needs to be done in keilu vision software setup details in the linked files
Files needed begin on page 11/18
full details in the attachment 🙂
Thumb-2 Implementation Work of Memory/Time-Related C Standard Library Functions.
1. Objective
You’ll understand the following concepts at the ARM assembly language level through this final project
that implements memory/time-related C standard library functions in Thumb-2.
• CPU operating modes: user and supervisor modes
• System-call and interrupt handling procedures
• C to assembler argument passing (APCS: ARM Procedure Call Standard)
• Stack operations to implement recursions at the assembly language level
• Buddy memory allocation
This document is quite dense. Please read it as soon as the final project spec. becomes available to you.
2. Project Overview
Using the Thumb-2 assembly language, you will implement several functions of the C standard library that
will be invoked from a C program named driver.c. See Table 1. These functions must be code in the Thumb2
assembly language. Some of them can be implemented in stdlib.s running in the unprivileged thread mode
(=user mode), whereas the others need to be implemented as supervisor calls, (i.e., in the handler mode =
supervisor mode). For more details, log in one of the CSS Linux servers and type from the Linux shell: man
3 function where function is either bezro, strncpy, malloc, free, signal, or alarm
Table 1: C standard lib functions to be implemented in the final project
C standard lib functions
In stdlib.s SVC *2
*1
bzero( void *s, size_t n ) writes n zeroed bytes to the setring
Yes
s. If n is zero, bzero( ) does nothing.
strncpy(char *dst, const char *src, size_t len) copies
Yes
at most len characters from src into dst. It returns dst.
malloc( size_t size )
Yes
allocates size bytes of memory and returns a pointer to the allocated memory. If
successful, it returns a pointer to allocated memory. Otherwise, it returns a NULL
pointer.
free( void *ptr )
Yes
Deallocates the memory allocation pointed to by ptr. If ptr is a NULL pointer, no
operation is performed. If successful, it returns a pointer to allocated memory.
Otherwise, it returns a NULL pointer.
void (*signal( int sig, void (*func)(int))))(int);
Yes
Invokes the func procedure upon receipt of a signal. Our implementation focuses
only on SIGALRM, (whose system call number is 14.)
unsigned alarm( unsigned seconds )
sets a timer to deliver the signal SIGALRM to the calling process after the
specified number of seconds. It returns the amount of time left on the timer from
a previous call to alarm( ). If no alarm is currently set, the return value is 0.
*1: To be implemented in stdlib.s in the unprivileged thread mode
*2: To be passed as an SVC to SVC_Hander in the privileged handler mode
Yes
The driver.c we use is shown in listing 1. It tests all the above six stdlib functions. Please note that printf()
in the code will be removed when you test your assembly implementation, because we won’t implement
the printf( ) standard function.
Listing 1: driver.c program to test your implementation
#include // bzero, strncpy
#include // malloc, free
#include // signal
#include // alarm
#include // prin<
int* alarmed;
void sig_handler1( int signum ) {
*alarmed = 2;
}
void sig_handler2( int signum ) {
*alarmed = 3;
}
int main( ) {
char stringA[40] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc\0";
char stringB[40];
bzero( stringB, 40 ); strncpy(
stringB, stringA, 40 ); bzero(
stringA, 40 ); prin