Annotation of nono/vm/zram.cpp, revision 1.1.1.4

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "zram.h"
                      8: 
                      9: //
                     10: // 3ポート共有 RAM
                     11: //
                     12: // ZRAM はロングワード単位でホストバイトオーダ配置なので、
                     13: // バイトアクセス、ワードアクセス時は HLB(), HLW() マクロ使用のこと。
                     14: //
                     15: 
1.1.1.2   root       16: std::unique_ptr<ZRAMDevice> gZRAM;
1.1       root       17: 
                     18: ZRAMDevice::ZRAMDevice()
1.1.1.4 ! root       19:        : inherited("ZRAM")
1.1       root       20: {
                     21:        devaddr = 0x71000000;
                     22:        devlen = 128 * 1024;
                     23: 
1.1.1.2   root       24:        ram.reset(new uint8[devlen]);
1.1       root       25: }
                     26: 
                     27: ZRAMDevice::~ZRAMDevice()
                     28: {
                     29: }
                     30: 
1.1.1.2   root       31: // アドレスデコーダ
                     32: inline uint64
                     33: ZRAMDevice::Decoder(uint32 addr) const
                     34: {
                     35:        // たぶん 128KB で折り返しイメージが見えるはず。要確認。
                     36:        return addr % devlen;
                     37: }
1.1       root       38: 
                     39: uint64
                     40: ZRAMDevice::Read8(uint32 addr)
                     41: {
                     42:        std::unique_lock<std::mutex> lock(mtx);
                     43: 
1.1.1.2   root       44:        uint32 offset = Decoder(addr);
                     45:        uint32 data = ram[HLB(offset)];
1.1       root       46:        return data;
                     47: }
                     48: 
                     49: uint64
                     50: ZRAMDevice::Read16(uint32 addr)
                     51: {
                     52:        std::unique_lock<std::mutex> lock(mtx);
                     53: 
1.1.1.2   root       54:        uint32 offset = Decoder(addr);
                     55:        uint32 data = *(uint16 *)&ram[HLW(offset)];
1.1       root       56:        return data;
                     57: }
                     58: 
                     59: uint64
                     60: ZRAMDevice::Read32(uint32 addr)
                     61: {
                     62:        std::unique_lock<std::mutex> lock(mtx);
                     63: 
1.1.1.2   root       64:        uint32 offset = Decoder(addr);
                     65:        uint32 data = *(uint32 *)&ram[offset];
1.1       root       66:        return data;
                     67: }
                     68: 
                     69: uint64
                     70: ZRAMDevice::Write8(uint32 addr, uint32 data)
                     71: {
                     72:        std::unique_lock<std::mutex> lock(mtx);
                     73: 
1.1.1.2   root       74:        uint32 offset = Decoder(addr);
                     75:        ram[HLB(offset)] = data;
1.1       root       76:        return 0;
                     77: }
                     78: 
                     79: uint64
                     80: ZRAMDevice::Write16(uint32 addr, uint32 data)
                     81: {
                     82:        std::unique_lock<std::mutex> lock(mtx);
                     83: 
1.1.1.2   root       84:        uint32 offset = Decoder(addr);
                     85:        *(uint16 *)&ram[HLW(offset)] = data;
1.1       root       86:        return 0;
                     87: }
                     88: 
                     89: uint64
                     90: ZRAMDevice::Write32(uint32 addr, uint32 data)
                     91: {
                     92:        std::unique_lock<std::mutex> lock(mtx);
                     93: 
1.1.1.2   root       94:        uint32 offset = Decoder(addr);
                     95:        *(uint32 *)&ram[offset] = data;
1.1       root       96:        return 0;
                     97: }
                     98: 
                     99: uint64
                    100: ZRAMDevice::Peek8(uint32 addr)
                    101: {
                    102:        std::unique_lock<std::mutex> lock(mtx);
                    103: 
1.1.1.2   root      104:        uint32 offset = Decoder(addr);
                    105:        return ram[HLB(offset)];
1.1       root      106: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.