@@ -235,3 +235,193 @@ macro_rules! svc6 {
235235 retval
236236 } }
237237}
238+
239+ /// Generate an HVC call with the given argument.
240+ #[ macro_export]
241+ macro_rules! hvc {
242+ ( $r0: expr) => {
243+ unsafe {
244+ core:: arch:: asm!( "hvc {arg}" , arg = const $r0, out( "lr" ) _) ;
245+ }
246+ }
247+ }
248+
249+ /// Generate an HVC call with 1 parameters
250+ ///
251+ /// Puts the first argument in the instruction, and the parameter in r0. Gives you back
252+ /// the value left in `r0` by the handler.
253+ ///
254+ /// ```rust,ignore
255+ /// const HYPERCALL_FOO: u32 = 0x100;
256+ /// let result = hvc1!(0x00, HYPERCALL_FOO);
257+ /// ```
258+ #[ macro_export]
259+ macro_rules! hvc1 {
260+ ( $num: expr, $arg0: expr) => { {
261+ let retval: u32 ;
262+ let arg0: u32 = $arg0;
263+ unsafe {
264+ core:: arch:: asm!(
265+ // Do the Hyper-call
266+ "hvc {arg}" ,
267+ arg = const $num,
268+ inout( "r0" ) arg0 => retval) ;
269+ }
270+ retval
271+ } }
272+ }
273+
274+ /// Generate an HVC call with 2 parameters
275+ ///
276+ /// Puts the first argument in the instruction, and the parameters in r0-r1. Gives you back
277+ /// the value left in `r0` by the handler.
278+ ///
279+ /// ```rust,ignore
280+ /// const HYPERCALL_FOO: u32 = 0x100;
281+ /// let result = hvc2!(0x00, HYPERCALL_FOO, 1);
282+ /// ```
283+ #[ macro_export]
284+ macro_rules! hvc2 {
285+ ( $num: expr, $arg0: expr, $arg1: expr) => { {
286+ let retval: u32 ;
287+ let arg0: u32 = $arg0;
288+ let arg1: u32 = $arg1;
289+ unsafe {
290+ core:: arch:: asm!(
291+ // Do the Hyper-call
292+ "hvc {arg}" ,
293+ arg = const $num,
294+ inout( "r0" ) arg0 => retval,
295+ in( "r1" ) arg1) ;
296+ }
297+ retval
298+ } }
299+ }
300+
301+ /// Generate an HVC call with 3 parameters
302+ ///
303+ /// Puts the first argument in the instruction, and the parameters in r0-r2. Gives you back
304+ /// the value left in `r0` by the handler.
305+ ///
306+ /// ```rust,ignore
307+ /// const HYPERCALL_FOO: u32 = 0x100;
308+ /// let result = hvc3!(0x00, HYPERCALL_FOO, 1, 2);
309+ /// ```
310+ #[ macro_export]
311+ macro_rules! hvc3 {
312+ ( $num: expr, $arg0: expr, $arg1: expr, $arg2: expr) => { {
313+ let retval: u32 ;
314+ let arg0: u32 = $arg0;
315+ let arg1: u32 = $arg1;
316+ let arg2: u32 = $arg2;
317+ unsafe {
318+ core:: arch:: asm!(
319+ // Do the Hyper-call
320+ "hvc {arg}" ,
321+ arg = const $num,
322+ inout( "r0" ) arg0 => retval,
323+ in( "r1" ) arg1,
324+ in( "r2" ) arg2) ;
325+ }
326+ retval
327+ } }
328+ }
329+
330+ /// Generate an HVC call with 4 parameters
331+ ///
332+ /// Puts the first argument in the instruction, and the parameters in r0-r3. Gives you back
333+ /// the value left in `r0` by the handler.
334+ ///
335+ /// ```rust,ignore
336+ /// const HYPERCALL_FOO: u32 = 0x100;
337+ /// let result = hvc4!(0x00, HYPERCALL_FOO, 1, 2, 3);
338+ /// ```
339+ #[ macro_export]
340+ macro_rules! hvc4 {
341+ ( $num: expr, $arg0: expr, $arg1: expr, $arg2: expr, $arg3: expr) => { {
342+ let retval: u32 ;
343+ let arg0: u32 = $arg0;
344+ let arg1: u32 = $arg1;
345+ let arg2: u32 = $arg2;
346+ let arg3: u32 = $arg3;
347+ unsafe {
348+ core:: arch:: asm!(
349+ // Do the Hyper-call
350+ "hvc {arg}" ,
351+ arg = const $num,
352+ inout( "r0" ) arg0 => retval,
353+ in( "r1" ) arg1,
354+ in( "r2" ) arg2,
355+ in( "r3" ) arg3) ;
356+ }
357+ retval
358+ } }
359+ }
360+
361+ /// Generate an HVC call with 5 parameters
362+ ///
363+ /// Puts the first argument in the instruction, and the parameters in r0-r4. Gives you back
364+ /// the value left in `r0` by the handler.
365+ ///
366+ /// ```rust,ignore
367+ /// const HYPERCALL_FOO: u32 = 0x100;
368+ /// let result = hvc5!(0x00, HYPERCALL_FOO, 1, 2, 3, 4);
369+ /// ```
370+ #[ macro_export]
371+ macro_rules! hvc5 {
372+ ( $num: expr, $arg0: expr, $arg1: expr, $arg2: expr, $arg3: expr, $arg4: expr) => { {
373+ let retval: u32 ;
374+ let arg0: u32 = $arg0;
375+ let arg1: u32 = $arg1;
376+ let arg2: u32 = $arg2;
377+ let arg3: u32 = $arg3;
378+ let arg4: u32 = $arg4;
379+ unsafe {
380+ core:: arch:: asm!(
381+ // Do the Hyper-call
382+ "hvc {arg}" ,
383+ arg = const $num,
384+ inout( "r0" ) arg0 => retval,
385+ in( "r1" ) arg1,
386+ in( "r2" ) arg2,
387+ in( "r3" ) arg3,
388+ in( "r4" ) arg4) ;
389+ }
390+ retval
391+ } }
392+ }
393+
394+ /// Generate an HVC call with 6 parameters
395+ ///
396+ /// Puts the first argument in the instruction, and the parameters in r0-r5. Gives you back
397+ /// the value left in `r0` by the handler.
398+ ///
399+ /// ```rust,ignore
400+ /// const HYPERCALL_FOO: u32 = 0x100;
401+ /// let result = hvc6!(0x00, HYPERCALL_FOO, 1, 2, 3, 4, 5);
402+ /// ```
403+ #[ macro_export]
404+ macro_rules! hvc6 {
405+ ( $num: expr, $arg0: expr, $arg1: expr, $arg2: expr, $arg3: expr, $arg4: expr, $arg5: expr) => { {
406+ let retval: u32 ;
407+ let arg0: u32 = $arg0;
408+ let arg1: u32 = $arg1;
409+ let arg2: u32 = $arg2;
410+ let arg3: u32 = $arg3;
411+ let arg4: u32 = $arg4;
412+ let arg5: u32 = $arg5;
413+ unsafe {
414+ core:: arch:: asm!(
415+ // Do the Hyper-call
416+ "hvc {arg}" ,
417+ arg = const $num,
418+ inout( "r0" ) arg0 => retval,
419+ in( "r1" ) arg1,
420+ in( "r2" ) arg2,
421+ in( "r3" ) arg3,
422+ in( "r4" ) arg4,
423+ in( "r5" ) arg5) ;
424+ }
425+ retval
426+ } }
427+ }
0 commit comments