]> wirehaze git hosting - ppos.git/blob - ppos/hardware/cpu.h

wirehaze git hosting

tasks implementation (ongoing)
[ppos.git] / ppos / hardware / cpu.h
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
4
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
7
8 // Emula vários mecanismos de uma CPU:
9 // - interrupções virtuais
10 // - temporizador virtual
11 // - Wait for Interrupt
12 // - desligamento do hardware
13
14 #ifndef __HW_CPU__
15 #define __HW_CPU__
16
17 // Interrupções virtuais
18 #define IRQ_RESERVED 0 // reservada (não usar)
19 #define IRQ_TIMER 1 // IRQ gerada pelo temporizador
20 #define IRQ_DISK 2 // IRQ gerada pelo controlador de disco
21 #define IRQ_UART 3 // IRQ gerada pela UART (serial)
22 #define IRQ_NET 4 // IRQ gerada pela interface de rede
23
24 // Define a função de tratamento de uma IRQ; a função "handle"
25 // será chamada sempre que a IRQ indicada ocorrer.
26 // Retorno: ERROR ou NOERROR
27 int hw_irq_handle(int irq, void (*handle)(int));
28
29 // Habilita (enable != 0) ou desabilita (enable == 0) as IRQs.
30 void hw_irq_enable(int enable);
31
32 // Arma o temporizador para disparar após "first" ms e depois
33 // repetir a cada "next" ms. Se first == next == 0, desarma-o.
34 // Ao disparar, o temporizador gera a IRq IRQ_TIMER.
35 // Retorno: ERROR ou NOERROR
36 int hw_timer (int first, int next);
37
38 // "Wait for Interrupt": suspende a CPU até a próxima IRq,
39 // para economizar energia.
40 void hw_wfi();
41
42 // Desliga o hardware; se error != 0, encerra com status de erro
43 // (útil quando depurar com o GDB).
44 void hw_poweroff(int error);
45
46 #endif